]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/mman.h
xnu-7195.81.3.tar.gz
[apple/xnu.git] / bsd / sys / mman.h
CommitLineData
1c79356b 1/*
f427ee49 2 * Copyright (c) 2000-2020 Apple Computer, Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*-
30 * Copyright (c) 1982, 1986, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)mman.h 8.1 (Berkeley) 6/2/93
62 */
63
91447636
A
64/*
65 * Currently unsupported:
66 *
67 * [TYM] POSIX_TYPED_MEM_ALLOCATE
68 * [TYM] POSIX_TYPED_MEM_ALLOCATE_CONTIG
69 * [TYM] POSIX_TYPED_MEM_MAP_ALLOCATABLE
70 * [TYM] struct posix_typed_mem_info
71 * [TYM] posix_mem_offset()
72 * [TYM] posix_typed_mem_get_info()
73 * [TYM] posix_typed_mem_open()
74 */
75
0a7de745 76#ifndef _SYS_MMAN_H_
1c79356b
A
77#define _SYS_MMAN_H_
78
9bccf70c 79#include <sys/appleapiopts.h>
91447636
A
80#include <sys/cdefs.h>
81
82#include <sys/_types.h>
83
84/*
85 * [various] The mode_t, off_t, and size_t types shall be defined as
86 * described in <sys/types.h>
87 */
39236c6e
A
88#include <sys/_types/_mode_t.h>
89#include <sys/_types/_off_t.h>
90#include <sys/_types/_size_t.h>
1c79356b 91
f427ee49
A
92#ifndef KERNEL
93#if __DARWIN_C_LEVEL >= 200809L
94#include <Availability.h>
95#endif /* __DARWIN_C_LEVEL */
96#endif /* KERNEL */
97
1c79356b
A
98/*
99 * Protections are chosen from these bits, or-ed together
100 */
0a7de745
A
101#define PROT_NONE 0x00 /* [MC2] no permissions */
102#define PROT_READ 0x01 /* [MC2] pages can be read */
103#define PROT_WRITE 0x02 /* [MC2] pages can be written */
104#define PROT_EXEC 0x04 /* [MC2] pages can be executed */
1c79356b
A
105
106/*
107 * Flags contain sharing type and options.
108 * Sharing types; choose one.
109 */
0a7de745
A
110#define MAP_SHARED 0x0001 /* [MF|SHM] share changes */
111#define MAP_PRIVATE 0x0002 /* [MF|SHM] changes are private */
2d21ac55 112#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
113#define MAP_COPY MAP_PRIVATE /* Obsolete */
114#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b
A
115
116/*
117 * Other flags
118 */
0a7de745 119#define MAP_FIXED 0x0010 /* [MF|SHM] interpret addr exactly */
2d21ac55 120#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
121#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */
122#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */
123#define MAP_RESERVED0080 0x0080 /* previously unimplemented MAP_INHERIT */
124#define MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change file size */
125#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */
126#define MAP_NOCACHE 0x0400 /* don't cache pages for this mapping */
127#define MAP_JIT 0x0800 /* Allocate a region that will be used for JIT purposes */
3e170ce0
A
128
129/*
130 * Mapping type
131 */
0a7de745
A
132#define MAP_FILE 0x0000 /* map from file (default) */
133#define MAP_ANON 0x1000 /* allocated from memory, swap space */
134#define MAP_ANONYMOUS MAP_ANON
3e170ce0
A
135
136/*
137 * The MAP_RESILIENT_* flags can be used when the caller wants to map some
138 * possibly unreliable memory and be able to access it safely, possibly
139 * getting the wrong contents rather than raising any exception.
140 * For safety reasons, such mappings have to be read-only (PROT_READ access
141 * only).
142 *
143 * MAP_RESILIENT_CODESIGN:
0a7de745 144 * accessing this mapping will not generate code-signing violations,
3e170ce0
A
145 * even if the contents are tainted.
146 * MAP_RESILIENT_MEDIA:
147 * accessing this mapping will not generate an exception if the contents
148 * are not available (unreachable removable or remote media, access beyond
149 * end-of-file, ...). Missing contents will be replaced with zeroes.
150 */
0a7de745
A
151#define MAP_RESILIENT_CODESIGN 0x2000 /* no code-signing failures */
152#define MAP_RESILIENT_MEDIA 0x4000 /* no backing-store failures */
3e170ce0 153
f427ee49
A
154#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
155#define MAP_32BIT 0x8000 /* Return virtual addresses <4G only */
156#endif /* defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500 */
157
158
159/*
160 * Flags used to support translated processes.
161 */
162#define MAP_TRANSLATED_ALLOW_EXECUTE 0x20000 /* allow execute in translated processes */
163
164#define MAP_UNIX03 0x40000 /* UNIX03 compliance */
cb323159 165
0a7de745 166#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b 167
1c79356b
A
168/*
169 * Process memory locking
170 */
0a7de745
A
171#define MCL_CURRENT 0x0001 /* [ML] Lock only current memory */
172#define MCL_FUTURE 0x0002 /* [ML] Lock all future memory as well */
1c79356b
A
173
174/*
175 * Error return from mmap()
176 */
0a7de745 177#define MAP_FAILED ((void *)-1) /* [MF|SHM] mmap failed */
1c79356b
A
178
179/*
180 * msync() flags
181 */
0a7de745
A
182#define MS_ASYNC 0x0001 /* [MF|SIO] return immediately */
183#define MS_INVALIDATE 0x0002 /* [MF|SIO] invalidate all cached data */
184#define MS_SYNC 0x0010 /* [MF|SIO] msync synchronously */
1c79356b 185
2d21ac55 186#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1c79356b
A
187#define MS_KILLPAGES 0x0004 /* invalidate pages, leave mapped */
188#define MS_DEACTIVATE 0x0008 /* deactivate pages, leave mapped */
1c79356b 189
0a7de745 190#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
91447636 191
1c79356b
A
192
193/*
194 * Advice to madvise
195 */
0a7de745
A
196#define POSIX_MADV_NORMAL 0 /* [MC1] no further special treatment */
197#define POSIX_MADV_RANDOM 1 /* [MC1] expect random page refs */
198#define POSIX_MADV_SEQUENTIAL 2 /* [MC1] expect sequential page refs */
199#define POSIX_MADV_WILLNEED 3 /* [MC1] will need these pages */
200#define POSIX_MADV_DONTNEED 4 /* [MC1] dont need these pages */
91447636 201
2d21ac55 202#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
203#define MADV_NORMAL POSIX_MADV_NORMAL
204#define MADV_RANDOM POSIX_MADV_RANDOM
205#define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
206#define MADV_WILLNEED POSIX_MADV_WILLNEED
207#define MADV_DONTNEED POSIX_MADV_DONTNEED
208#define MADV_FREE 5 /* pages unneeded, discard contents */
209#define MADV_ZERO_WIRED_PAGES 6 /* zero the wired pages that have not been unwired before the entry is deleted */
210#define MADV_FREE_REUSABLE 7 /* pages can be reused (by anyone) */
211#define MADV_FREE_REUSE 8 /* caller wants to reuse those pages */
212#define MADV_CAN_REUSE 9
213#define MADV_PAGEOUT 10 /* page out now (internal only) */
1c79356b
A
214
215/*
216 * Return bits from mincore
217 */
0a7de745
A
218#define MINCORE_INCORE 0x1 /* Page is incore */
219#define MINCORE_REFERENCED 0x2 /* Page has been referenced by us */
220#define MINCORE_MODIFIED 0x4 /* Page has been modified by us */
221#define MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */
222#define MINCORE_MODIFIED_OTHER 0x10 /* Page has been modified */
5ba3f43e
A
223#define MINCORE_PAGED_OUT 0x20 /* Page has been paged out */
224#define MINCORE_COPIED 0x40 /* Page has been copied */
225#define MINCORE_ANONYMOUS 0x80 /* Page belongs to an anonymous object */
0a7de745 226#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b 227
f427ee49
A
228#ifdef PRIVATE
229
230/*
231 * Crypt ID for decryption flow
232 */
233#define CRYPTID_NO_ENCRYPTION 0 /* File is unencrypted */
234#define CRYPTID_APP_ENCRYPTION 1 /* App binary is encrypted */
235#define CRYPTID_MODEL_ENCRYPTION 2 /* ML Model is encrypted */
236
237/*
238 * Model encryption header
239 */
240typedef struct {
241 __uint64_t version;
242 __uint64_t originalSize;
243 __uint64_t reserved[4];
244} model_encryption_header_t;
245
246#endif /* #ifdef PRIVATE */
247
1c79356b 248
91447636 249#ifndef KERNEL
1c79356b
A
250
251__BEGIN_DECLS
91447636 252/* [ML] */
0a7de745
A
253int mlockall(int);
254int munlockall(void);
91447636 255/* [MR] */
0a7de745 256int mlock(const void *, size_t);
91447636 257#ifndef _MMAP
0a7de745 258#define _MMAP
91447636 259/* [MC3]*/
0a7de745 260void * mmap(void *, size_t, int, int, int, off_t) __DARWIN_ALIAS(mmap);
1c79356b 261#endif
91447636 262/* [MPR] */
0a7de745 263int mprotect(void *, size_t, int) __DARWIN_ALIAS(mprotect);
91447636 264/* [MF|SIO] */
0a7de745 265int msync(void *, size_t, int) __DARWIN_ALIAS_C(msync);
91447636 266/* [MR] */
0a7de745 267int munlock(const void *, size_t);
91447636 268/* [MC3]*/
0a7de745 269int munmap(void *, size_t) __DARWIN_ALIAS(munmap);
91447636 270/* [SHM] */
0a7de745
A
271int shm_open(const char *, int, ...);
272int shm_unlink(const char *);
91447636 273/* [ADV] */
0a7de745 274int posix_madvise(void *, size_t, int);
91447636 275
2d21ac55 276#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
277int madvise(void *, size_t, int);
278int mincore(const void *, size_t, char *);
279int minherit(void *, size_t, int);
1c79356b 280#endif
fe8ab488
A
281
282#ifdef PRIVATE
283int mremap_encrypted(void *, size_t, __uint32_t, __uint32_t, __uint32_t);
284#endif
285
1c79356b
A
286__END_DECLS
287
0a7de745 288#else /* KERNEL */
b0d623f7 289#ifdef XNU_KERNEL_PRIVATE
0a7de745 290void pshm_cache_init(void); /* for bsd_init() */
2d21ac55 291void pshm_lock_init(void);
91447636
A
292
293/*
294 * XXX routine exported by posix_shm.c, but never used there, only used in
295 * XXX kern_mman.c in the implementation of mmap().
296 */
297struct mmap_args;
298struct fileproc;
299int pshm_mmap(struct proc *p, struct mmap_args *uap, user_addr_t *retval,
0a7de745 300 struct fileproc *fp, off_t pageoff);
91447636
A
301/* Really need to overhaul struct fileops to avoid this... */
302struct pshmnode;
2d21ac55
A
303struct stat;
304int pshm_stat(struct pshmnode *pnode, void *ub, int isstat64);
91447636 305struct fileproc;
b0d623f7 306int pshm_truncate(struct proc *p, struct fileproc *fp, int fd, off_t length, int32_t *retval);
91447636 307
b0d623f7 308#endif /* XNU_KERNEL_PRIVATE */
91447636 309#endif /* KERNEL */
1c79356b 310#endif /* !_SYS_MMAN_H_ */