FreeBSD/Linux Kernel Cross Reference
sys/sys/mman.h
1 /* $NetBSD: mman.h,v 1.62 2019/12/06 19:37:43 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)mman.h 8.2 (Berkeley) 1/9/95
32 */
33
34 #ifndef _SYS_MMAN_H_
35 #define _SYS_MMAN_H_
36
37 #include <sys/featuretest.h>
38
39 #include <machine/ansi.h>
40
41 #ifdef _BSD_SIZE_T_
42 typedef _BSD_SIZE_T_ size_t;
43 #undef _BSD_SIZE_T_
44 #endif
45
46 #include <sys/ansi.h>
47
48 #ifndef mode_t
49 typedef __mode_t mode_t;
50 #define mode_t __mode_t
51 #endif
52
53 #ifndef off_t
54 typedef __off_t off_t; /* file offset */
55 #define off_t __off_t
56 #endif
57
58
59 /*
60 * Protections are chosen from these bits, or-ed together
61 */
62 #define PROT_NONE 0x00 /* no permissions */
63 #define PROT_READ 0x01 /* pages can be read */
64 #define PROT_WRITE 0x02 /* pages can be written */
65 #define PROT_EXEC 0x04 /* pages can be executed */
66
67 #ifdef _NETBSD_SOURCE
68 /*
69 * PAX mprotect prohibits setting protection bits
70 * missing from the original mmap call unless explicitly
71 * requested with PROT_MPROTECT.
72 */
73 #define PROT_MPROTECT(x) ((x) << 3)
74 #define PROT_MPROTECT_EXTRACT(x) (((x) >> 3) & 0x7)
75 #endif
76
77 /*
78 * Flags contain sharing type and options.
79 * Sharing types; choose one.
80 */
81 #define MAP_SHARED 0x0001 /* share changes */
82 #define MAP_PRIVATE 0x0002 /* changes are private */
83 /* old MAP_COPY 0x0004 "copy" region at mmap time */
84
85 /*
86 * Other flags
87 */
88 #define MAP_REMAPDUP 0x0004 /* mremap only: duplicate the mapping */
89 #define MAP_FIXED 0x0010 /* map addr must be exactly as requested */
90 #define MAP_RENAME 0x0020 /* Sun: rename private pages to file */
91 #define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */
92 #define MAP_INHERIT 0x0080 /* region is retained after exec */
93 #define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */
94 #define MAP_TRYFIXED 0x0400 /* attempt hint address, even within break */
95 #define MAP_WIRED 0x0800 /* mlock() mapping when it is established */
96
97 /*
98 * Mapping type
99 */
100 #define MAP_FILE 0x0000 /* map from file (default) */
101 #define MAP_ANONYMOUS 0x1000 /* allocated from memory, swap space */
102 #define MAP_ANON MAP_ANONYMOUS
103 #define MAP_STACK 0x2000 /* allocated from memory, swap space (stack) */
104
105 /*
106 * Alignment (expressed in log2). Must be >= log2(PAGE_SIZE) and
107 * < # bits in a pointer (32 or 64).
108 */
109 #define MAP_ALIGNED(n) ((int)((unsigned int)(n) << MAP_ALIGNMENT_SHIFT))
110 #define MAP_ALIGNMENT_SHIFT 24
111 #define MAP_ALIGNMENT_MASK MAP_ALIGNED(0xff)
112 #define MAP_ALIGNMENT_64KB MAP_ALIGNED(16) /* 2^16 */
113 #define MAP_ALIGNMENT_16MB MAP_ALIGNED(24) /* 2^24 */
114 #define MAP_ALIGNMENT_4GB MAP_ALIGNED(32) /* 2^32 */
115 #define MAP_ALIGNMENT_1TB MAP_ALIGNED(40) /* 2^40 */
116 #define MAP_ALIGNMENT_256TB MAP_ALIGNED(48) /* 2^48 */
117 #define MAP_ALIGNMENT_64PB MAP_ALIGNED(56) /* 2^56 */
118
119 #ifdef _NETBSD_SOURCE
120 #define MAP_FMT "\177\020" \
121 "b\0" "SHARED\0" \
122 "b\1" "PRIVATE\0" \
123 "b\2" "COPY\0" \
124 "b\4" "FIXED\0" \
125 "b\5" "RENAME\0" \
126 "b\6" "NORESERVE\0" \
127 "b\7" "INHERIT\0" \
128 "b\11" "HASSEMAPHORE\0" \
129 "b\12" "TRYFIXED\0" \
130 "b\13" "WIRED\0" \
131 "F\14\1\0" \
132 ":\0" "FILE\0" \
133 ":\1" "ANONYMOUS\0" \
134 "b\15" "STACK\0" \
135 "F\3\010\0" \
136 ":\000" "ALIGN=NONE\0" \
137 ":\012" "ALIGN=1KB\0" \
138 ":\013" "ALIGN=2KB\0" \
139 ":\014" "ALIGN=4KB\0" \
140 ":\015" "ALIGN=8KB\0" \
141 ":\016" "ALIGN=16KB\0" \
142 ":\017" "ALIGN=32KB\0" \
143 ":\020" "ALIGN=64KB\0" \
144 ":\021" "ALIGN=128KB\0" \
145 ":\022" "ALIGN=256KB\0" \
146 ":\023" "ALIGN=512KB\0" \
147 ":\024" "ALIGN=1MB\0" \
148 ":\025" "ALIGN=2MB\0" \
149 ":\026" "ALIGN=4MB\0" \
150 ":\027" "ALIGN=8MB\0" \
151 ":\030" "ALIGN=16MB\0" \
152 ":\034" "ALIGN=256MB\0" \
153 ":\040" "ALIGN=4GB\0" \
154 ":\044" "ALIGN=64GB\0" \
155 ":\050" "ALIGN=1TB\0" \
156 ":\054" "ALIGN=16TB\0" \
157 ":\060" "ALIGN=256TB\0" \
158 ":\064" "ALIGN=4PB\0" \
159 ":\070" "ALIGN=64PB\0" \
160 ":\074" "ALIGN=256PB\0" \
161 "*" "ALIGN=2^%ju\0"
162 #endif
163
164 /*
165 * Error indicator returned by mmap(2)
166 */
167 #define MAP_FAILED ((void *) -1) /* mmap() failed */
168
169 /*
170 * Flags to msync
171 */
172 #define MS_ASYNC 0x01 /* perform asynchronous writes */
173 #define MS_INVALIDATE 0x02 /* invalidate cached data */
174 #define MS_SYNC 0x04 /* perform synchronous writes */
175
176 /*
177 * Flags to mlockall
178 */
179 #define MCL_CURRENT 0x01 /* lock all pages currently mapped */
180 #define MCL_FUTURE 0x02 /* lock all pages mapped in the future */
181
182 /*
183 * POSIX memory advisory values.
184 * Note: keep consistent with the original definitions below.
185 */
186 #define POSIX_MADV_NORMAL 0 /* No further special treatment */
187 #define POSIX_MADV_RANDOM 1 /* Expect random page references */
188 #define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references */
189 #define POSIX_MADV_WILLNEED 3 /* Will need these pages */
190 #define POSIX_MADV_DONTNEED 4 /* Don't need these pages */
191
192 #if defined(_NETBSD_SOURCE)
193 /*
194 * Original advice values, equivalent to POSIX definitions,
195 * and few implementation-specific ones.
196 */
197 #define MADV_NORMAL POSIX_MADV_NORMAL
198 #define MADV_RANDOM POSIX_MADV_RANDOM
199 #define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
200 #define MADV_WILLNEED POSIX_MADV_WILLNEED
201 #define MADV_DONTNEED POSIX_MADV_DONTNEED
202 #define MADV_SPACEAVAIL 5 /* Insure that resources are reserved */
203 #define MADV_FREE 6 /* Pages are empty, free them */
204
205 /*
206 * Flags to minherit
207 */
208 #define MAP_INHERIT_SHARE 0 /* share with child */
209 #define MAP_INHERIT_COPY 1 /* copy into child */
210 #define MAP_INHERIT_NONE 2 /* absent from child */
211 #define MAP_INHERIT_DONATE_COPY 3 /* copy and delete -- not
212 implemented in UVM */
213 #define MAP_INHERIT_ZERO 4 /* zero in child */
214 #define MAP_INHERIT_DEFAULT MAP_INHERIT_COPY
215 #endif
216
217 #ifndef _KERNEL
218
219 #include <sys/cdefs.h>
220
221 __BEGIN_DECLS
222 void * mmap(void *, size_t, int, int, int, off_t);
223 int munmap(void *, size_t);
224 int mprotect(void *, size_t, int);
225 #ifndef __LIBC12_SOURCE__
226 int msync(void *, size_t, int) __RENAME(__msync13);
227 #endif
228 int mlock(const void *, size_t);
229 int munlock(const void *, size_t);
230 int mlockall(int);
231 int munlockall(void);
232 #if defined(_NETBSD_SOURCE)
233 int madvise(void *, size_t, int);
234 int mincore(void *, size_t, char *);
235 int minherit(void *, size_t, int);
236 void * mremap(void *, size_t, void *, size_t, int);
237 #endif
238 int posix_madvise(void *, size_t, int);
239 int shm_open(const char *, int, mode_t);
240 int shm_unlink(const char *);
241 __END_DECLS
242
243 #endif /* !_KERNEL */
244
245 #endif /* !_SYS_MMAN_H_ */
Cache object: f1083815b14b3b180b30b4e5fab529dc
|