]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mman.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / sys / mman.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
31 /*-
32 * Copyright (c) 1982, 1986, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * @(#)mman.h 8.1 (Berkeley) 6/2/93
64 */
65
66 /*
67 * Currently unsupported:
68 *
69 * [TYM] POSIX_TYPED_MEM_ALLOCATE
70 * [TYM] POSIX_TYPED_MEM_ALLOCATE_CONTIG
71 * [TYM] POSIX_TYPED_MEM_MAP_ALLOCATABLE
72 * [TYM] struct posix_typed_mem_info
73 * [TYM] posix_mem_offset()
74 * [TYM] posix_typed_mem_get_info()
75 * [TYM] posix_typed_mem_open()
76 */
77
78 #ifndef _SYS_MMAN_H_
79 #define _SYS_MMAN_H_
80
81 #include <sys/appleapiopts.h>
82 #include <sys/cdefs.h>
83
84 #include <sys/_types.h>
85
86 /*
87 * [various] The mode_t, off_t, and size_t types shall be defined as
88 * described in <sys/types.h>
89 */
90 #ifndef _MODE_T
91 typedef __darwin_mode_t mode_t;
92 #define _MODE_T
93 #endif
94
95 #ifndef _OFF_T
96 typedef __darwin_off_t off_t;
97 #define _OFF_T
98 #endif
99
100 #ifndef _SIZE_T
101 #define _SIZE_T
102 typedef __darwin_size_t size_t;
103 #endif
104
105
106 /*
107 * Protections are chosen from these bits, or-ed together
108 */
109 #define PROT_NONE 0x00 /* [MC2] no permissions */
110 #define PROT_READ 0x01 /* [MC2] pages can be read */
111 #define PROT_WRITE 0x02 /* [MC2] pages can be written */
112 #define PROT_EXEC 0x04 /* [MC2] pages can be executed */
113
114 /*
115 * Flags contain sharing type and options.
116 * Sharing types; choose one.
117 */
118 #define MAP_SHARED 0x0001 /* [MF|SHM] share changes */
119 #define MAP_PRIVATE 0x0002 /* [MF|SHM] changes are private */
120 #ifndef _POSIX_C_SOURCE
121 #define MAP_COPY MAP_PRIVATE /* Obsolete */
122 #endif /* !_POSIX_C_SOURCE */
123
124 /*
125 * Other flags
126 */
127 #define MAP_FIXED 0x0010 /* [MF|SHM] interpret addr exactly */
128 #ifndef _POSIX_C_SOURCE
129 #define MAP_RENAME 0x0020 /* Sun: rename private pages to file */
130 #define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */
131 #define MAP_RESERVED0080 0x0080 /* previously unimplemented MAP_INHERIT */
132 #define MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change file size */
133 #define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */
134 #endif /* !_POSIX_C_SOURCE */
135
136 /*
137 * Process memory locking
138 */
139 #define MCL_CURRENT 0x0001 /* [ML] Lock only current memory */
140 #define MCL_FUTURE 0x0002 /* [ML] Lock all future memory as well */
141
142 /*
143 * Error return from mmap()
144 */
145 #define MAP_FAILED ((void *)-1) /* [MF|SHM] mmap failed */
146
147 /*
148 * msync() flags
149 */
150 #define MS_ASYNC 0x0001 /* [MF|SIO] return immediately */
151 #define MS_INVALIDATE 0x0002 /* [MF|SIO] invalidate all cached data */
152 #define MS_SYNC 0x0010 /* [MF|SIO] msync synchronously */
153
154 #ifndef _POSIX_C_SOURCE
155 #define MS_KILLPAGES 0x0004 /* invalidate pages, leave mapped */
156 #define MS_DEACTIVATE 0x0008 /* deactivate pages, leave mapped */
157
158 /*
159 * Mapping type
160 */
161 #define MAP_FILE 0x0000 /* map from file (default) */
162 #define MAP_ANON 0x1000 /* allocated from memory, swap space */
163 #endif /* !_POSIX_C_SOURCE */
164
165
166 /*
167 * Advice to madvise
168 */
169 #define POSIX_MADV_NORMAL 0 /* [MC1] no further special treatment */
170 #define POSIX_MADV_RANDOM 1 /* [MC1] expect random page refs */
171 #define POSIX_MADV_SEQUENTIAL 2 /* [MC1] expect sequential page refs */
172 #define POSIX_MADV_WILLNEED 3 /* [MC1] will need these pages */
173 #define POSIX_MADV_DONTNEED 4 /* [MC1] dont need these pages */
174
175 #ifndef _POSIX_C_SOURCE
176 #define MADV_NORMAL POSIX_MADV_NORMAL
177 #define MADV_RANDOM POSIX_MADV_RANDOM
178 #define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
179 #define MADV_WILLNEED POSIX_MADV_WILLNEED
180 #define MADV_DONTNEED POSIX_MADV_DONTNEED
181 #define MADV_FREE 5 /* pages unneeded, discard contents */
182
183 /*
184 * Return bits from mincore
185 */
186 #define MINCORE_INCORE 0x1 /* Page is incore */
187 #define MINCORE_REFERENCED 0x2 /* Page has been referenced by us */
188 #define MINCORE_MODIFIED 0x4 /* Page has been modified by us */
189 #define MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */
190 #define MINCORE_MODIFIED_OTHER 0x10 /* Page has been modified */
191 #endif /* !_POSIX_C_SOURCE */
192
193
194 #ifndef KERNEL
195
196 __BEGIN_DECLS
197 /* [ML] */
198 int mlockall(int);
199 int munlockall(void);
200 /* [MR] */
201 int mlock(const void *, size_t);
202 #ifndef _MMAP
203 #define _MMAP
204 /* [MC3]*/
205 void * mmap(void *, size_t, int, int, int, off_t) __DARWIN_ALIAS(mmap);
206 #endif
207 /* [MPR] */
208 int mprotect(void *, size_t, int) __DARWIN_ALIAS(mprotect);
209 /* [MF|SIO] */
210 int msync(void *, size_t, int) __DARWIN_ALIAS(msync);
211 /* [MR] */
212 int munlock(const void *, size_t);
213 /* [MC3]*/
214 int munmap(void *, size_t) __DARWIN_ALIAS(munmap);
215 /* [SHM] */
216 int shm_open(const char *, int, ...);
217 int shm_unlink(const char *);
218 /* [ADV] */
219 int posix_madvise(void *, size_t, int);
220
221 #ifndef _POSIX_C_SOURCE
222 int madvise(void *, size_t, int);
223 int mincore(const void *, size_t, char *);
224 int minherit(void *, size_t, int);
225 #endif
226 __END_DECLS
227
228 #else /* KERNEL */
229
230 void pshm_cache_init(void); /* for bsd_init() */
231
232 /*
233 * XXX routine exported by posix_shm.c, but never used there, only used in
234 * XXX kern_mman.c in the implementation of mmap().
235 */
236 struct mmap_args;
237 struct fileproc;
238 int pshm_mmap(struct proc *p, struct mmap_args *uap, user_addr_t *retval,
239 struct fileproc *fp, off_t pageoff);
240 /* Really need to overhaul struct fileops to avoid this... */
241 struct pshmnode;
242 int pshm_stat(struct pshmnode *pnode, struct stat *sb);
243 struct fileproc;
244 int pshm_truncate(struct proc *p, struct fileproc *fp, int fd, off_t length, register_t *retval);
245
246 #endif /* KERNEL */
247 #endif /* !_SYS_MMAN_H_ */