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