Print this page
7029 want per-process exploit mitigation features (secflags)
7030 want basic address space layout randomization (aslr)
7031 noexec_user_stack should be a secflag
7032 want a means to forbid mappings around NULL.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/mman.h
+++ new/usr/src/uts/common/sys/mman.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /* Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
23 23 /*
24 24 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25 25 *
26 26 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 * Copyright 2015 Joyent, Inc. All rights reserved.
29 29 */
30 30
31 31 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
32 32 /* All Rights Reserved */
33 33
34 34 /*
35 35 * University Copyright- Copyright (c) 1982, 1986, 1988
36 36 * The Regents of the University of California
37 37 * All Rights Reserved
38 38 *
39 39 * University Acknowledgment- Portions of this document are derived from
40 40 * software developed by the University of California, Berkeley, and its
41 41 * contributors.
42 42 */
43 43
44 44 #ifndef _SYS_MMAN_H
45 45 #define _SYS_MMAN_H
46 46
47 47 #include <sys/feature_tests.h>
48 48
49 49 #ifdef __cplusplus
50 50 extern "C" {
51 51 #endif
52 52
53 53 #if !defined(_ASM) && !defined(_KERNEL)
54 54 #include <sys/types.h>
55 55 #endif /* !_ASM && !_KERNEL */
56 56
57 57 /*
58 58 * Protections are chosen from these bits, or-ed together.
59 59 * Note - not all implementations literally provide all possible
60 60 * combinations. PROT_WRITE is often implemented as (PROT_READ |
61 61 * PROT_WRITE) and (PROT_EXECUTE as PROT_READ | PROT_EXECUTE).
62 62 * However, no implementation will permit a write to succeed
63 63 * where PROT_WRITE has not been set. Also, no implementation will
64 64 * allow any access to succeed where prot is specified as PROT_NONE.
65 65 */
66 66 #define PROT_READ 0x1 /* pages can be read */
67 67 #define PROT_WRITE 0x2 /* pages can be written */
68 68 #define PROT_EXEC 0x4 /* pages can be executed */
69 69
70 70 #ifdef _KERNEL
71 71 #define PROT_USER 0x8 /* pages are user accessable */
72 72 #define PROT_ZFOD (PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
73 73 #define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
74 74 #endif /* _KERNEL */
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
75 75
76 76 #define PROT_NONE 0x0 /* pages cannot be accessed */
77 77
78 78 /* sharing types: must choose either SHARED or PRIVATE */
79 79 #define MAP_SHARED 1 /* share changes */
80 80 #define MAP_PRIVATE 2 /* changes are private */
81 81 #define MAP_TYPE 0xf /* mask for share type */
82 82
83 83 /* other flags to mmap (or-ed in to MAP_SHARED or MAP_PRIVATE) */
84 84 #define MAP_FIXED 0x10 /* user assigns address */
85 +/* Not implemented */
86 +#define MAP_RENAME 0x20 /* rename private pages to file */
85 87 #define MAP_NORESERVE 0x40 /* don't reserve needed swap area */
88 +/* Note that 0x80 is _MAP_LOW32, defined below */
86 89 #define MAP_ANON 0x100 /* map anonymous pages directly */
87 90 #define MAP_ANONYMOUS MAP_ANON /* (source compatibility) */
88 91 #define MAP_ALIGN 0x200 /* addr specifies alignment */
89 92 #define MAP_TEXT 0x400 /* map code segment */
90 93 #define MAP_INITDATA 0x800 /* map data segment */
91 94
92 95 #ifdef _KERNEL
93 96 #define _MAP_TEXTREPL 0x1000
97 +#define _MAP_RANDOMIZE 0x2000
94 98 #endif /* _KERNEL */
95 99
96 -/* these flags not yet implemented */
97 -#define MAP_RENAME 0x20 /* rename private pages to file */
98 -
99 100 #if (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2)
100 101 /* these flags are used by memcntl */
101 102 #define PROC_TEXT (PROT_EXEC | PROT_READ)
102 103 #define PROC_DATA (PROT_READ | PROT_WRITE | PROT_EXEC)
103 104 #define SHARED 0x10
104 105 #define PRIVATE 0x20
105 106 #define VALID_ATTR (PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE)
106 107 #endif /* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) */
107 108
108 109 #if (_POSIX_C_SOURCE <= 2) || defined(_XPG4_2)
109 110 #ifdef _KERNEL
110 111 #define PROT_EXCL 0x20
111 112 #endif /* _KERNEL */
112 113
113 114 #define _MAP_LOW32 0x80 /* force mapping in lower 4G of address space */
114 115 #define MAP_32BIT _MAP_LOW32
115 116
116 117 /*
117 118 * For the sake of backward object compatibility, we use the _MAP_NEW flag.
118 119 * This flag will be automatically or'ed in by the C library for all
119 120 * new mmap calls. Previous binaries with old mmap calls will continue
120 121 * to get 0 or -1 for return values. New mmap calls will get the mapped
121 122 * address as the return value if successful and -1 on errors. By default,
122 123 * new mmap calls automatically have the kernel assign the map address
123 124 * unless the MAP_FIXED flag is given.
124 125 */
125 126 #define _MAP_NEW 0x80000000 /* users should not need to use this */
126 127 #endif /* (_POSIX_C_SOURCE <= 2) */
127 128
128 129
129 130 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
130 131 /* External flags for mmapobj syscall (Exclusive of MAP_* flags above) */
131 132 #define MMOBJ_PADDING 0x10000
132 133 #define MMOBJ_INTERPRET 0x20000
133 134
134 135 #define MMOBJ_ALL_FLAGS (MMOBJ_PADDING | MMOBJ_INTERPRET)
135 136
136 137 /*
137 138 * Values for mr_flags field of mmapobj_result_t below.
138 139 * The bottom 16 bits are mutually exclusive and thus only one
139 140 * of them can be set at a time. Use MR_GET_TYPE below to check this value.
140 141 * The top 16 bits are used for flags which are not mutually exclusive and
141 142 * thus more than one of these flags can be set for a given mmapobj_result_t.
142 143 *
143 144 * MR_PADDING being set indicates that this memory range represents the user
144 145 * requested padding.
145 146 *
146 147 * MR_HDR_ELF being set indicates that the ELF header of the mapped object
147 148 * is mapped at mr_addr + mr_offset.
148 149 *
149 150 * MR_HDR_AOUT being set indicates that the AOUT (4.x) header of the mapped
150 151 * object is mapped at mr_addr + mr_offset.
151 152 */
152 153
153 154 /*
154 155 * External flags for mr_flags field below.
155 156 */
156 157 #define MR_PADDING 0x1
157 158 #define MR_HDR_ELF 0x2
158 159 #define MR_HDR_AOUT 0x3
159 160
160 161 /*
161 162 * Internal flags for mr_flags field below.
162 163 */
163 164 #ifdef _KERNEL
164 165 #define MR_RESV 0x80000000 /* overmapped /dev/null */
165 166 #endif /* _KERNEL */
166 167
167 168 #define MR_TYPE_MASK 0x0000ffff
168 169 #define MR_GET_TYPE(val) ((val) & MR_TYPE_MASK)
169 170
170 171 #if !defined(_ASM)
171 172 typedef struct mmapobj_result {
172 173 caddr_t mr_addr; /* mapping address */
173 174 size_t mr_msize; /* mapping size */
174 175 size_t mr_fsize; /* file size */
175 176 size_t mr_offset; /* offset into file */
176 177 uint_t mr_prot; /* the protections provided */
177 178 uint_t mr_flags; /* info on the mapping */
178 179 } mmapobj_result_t;
179 180
180 181 #if defined(_KERNEL) || defined(_SYSCALL32)
181 182 typedef struct mmapobj_result32 {
182 183 caddr32_t mr_addr; /* mapping address */
183 184 size32_t mr_msize; /* mapping size */
184 185 size32_t mr_fsize; /* file size */
185 186 size32_t mr_offset; /* offset into file */
186 187 uint_t mr_prot; /* the protections provided */
187 188 uint_t mr_flags; /* info on the mapping */
188 189 } mmapobj_result32_t;
189 190 #endif /* defined(_KERNEL) || defined(_SYSCALL32) */
190 191 #endif /* !defined(_ASM) */
191 192 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
192 193
193 194 #if !defined(_ASM) && !defined(_KERNEL)
194 195 /*
195 196 * large file compilation environment setup
196 197 *
197 198 * In the LP64 compilation environment, map large file interfaces
198 199 * back to native versions where possible.
199 200 */
200 201
201 202 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
202 203 #ifdef __PRAGMA_REDEFINE_EXTNAME
203 204 #pragma redefine_extname mmap mmap64
204 205 #else
205 206 #define mmap mmap64
206 207 #endif
207 208 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
208 209
209 210 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
210 211 #ifdef __PRAGMA_REDEFINE_EXTNAME
211 212 #pragma redefine_extname mmap64 mmap
212 213 #else
213 214 #define mmap64 mmap
214 215 #endif
215 216 #endif /* _LP64 && _LARGEFILE64_SOURCE */
216 217
217 218 #ifdef __PRAGMA_REDEFINE_EXTNAME
218 219 #pragma redefine_extname getpagesizes getpagesizes2
219 220 #else
220 221 #define getpagesizes getpagesizes2
221 222 #endif
222 223
223 224 /*
224 225 * Except for old binaries mmap() will return the resultant
225 226 * address of mapping on success and (caddr_t)-1 on error.
226 227 */
227 228 #if (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
228 229 extern void *mmap(void *, size_t, int, int, int, off_t);
229 230 extern int munmap(void *, size_t);
230 231 extern int mprotect(void *, size_t, int);
231 232 extern int msync(void *, size_t, int);
232 233 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
233 234 extern int mlock(const void *, size_t);
234 235 extern int munlock(const void *, size_t);
235 236 #endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2))... */
236 237 /* transitional large file interface version */
237 238 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
238 239 !defined(__PRAGMA_REDEFINE_EXTNAME))
239 240 extern void *mmap64(void *, size_t, int, int, int, off64_t);
240 241 #endif /* _LARGEFILE64_SOURCE... */
241 242 #else /* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */
242 243 extern caddr_t mmap(caddr_t, size_t, int, int, int, off_t);
243 244 extern int munmap(caddr_t, size_t);
244 245 extern int mprotect(caddr_t, size_t, int);
245 246 extern int msync(caddr_t, size_t, int);
246 247 extern int mlock(caddr_t, size_t);
247 248 extern int munlock(caddr_t, size_t);
248 249 extern int mincore(caddr_t, size_t, char *);
249 250 extern int memcntl(caddr_t, size_t, int, caddr_t, int, int);
250 251 extern int madvise(caddr_t, size_t, int);
251 252 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
252 253 extern int getpagesizes(size_t *, int);
253 254 extern int getpagesizes2(size_t *, int);
254 255 extern int mmapobj(int, uint_t, mmapobj_result_t *, uint_t *, void *);
255 256 /* guard visibility of uint64_t */
256 257 #if defined(_INT64_TYPE)
257 258 extern int meminfo(const uint64_t *, int, const uint_t *, int, uint64_t *,
258 259 uint_t *);
259 260 #endif /* defined(_INT64_TYPE) */
260 261 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
261 262 /* transitional large file interface version */
262 263 #ifdef _LARGEFILE64_SOURCE
263 264 extern caddr_t mmap64(caddr_t, size_t, int, int, int, off64_t);
264 265 #endif
265 266 #endif /* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */
266 267
267 268 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
268 269 extern int mlockall(int);
269 270 extern int munlockall(void);
270 271 extern int shm_open(const char *, int, mode_t);
271 272 extern int shm_unlink(const char *);
272 273 #endif
273 274
274 275 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
275 276 extern int posix_madvise(void *, size_t, int);
276 277 #endif
277 278
278 279 /* mmap failure value */
279 280 #define MAP_FAILED ((void *) -1)
280 281
281 282
282 283 #endif /* !_ASM && !_KERNEL */
283 284
284 285 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
285 286 #if !defined(_ASM)
286 287 /*
287 288 * structure for memcntl hat advise operations.
288 289 */
289 290 struct memcntl_mha {
290 291 uint_t mha_cmd; /* command(s) */
291 292 uint_t mha_flags;
292 293 size_t mha_pagesize;
293 294 };
294 295
295 296 #if defined(_SYSCALL32)
296 297 struct memcntl_mha32 {
297 298 uint_t mha_cmd; /* command(s) */
298 299 uint_t mha_flags;
299 300 size32_t mha_pagesize;
300 301 };
301 302 #endif /* _SYSCALL32 */
302 303 #endif /* !defined(_ASM) */
303 304 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
304 305
305 306 #if (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
306 307 /*
307 308 * advice to madvise
308 309 *
309 310 * Note, if more than 4 bits worth of advice (eg. 16) are specified then
310 311 * changes will be necessary to the struct vpage.
311 312 */
312 313 #define MADV_NORMAL 0 /* no further special treatment */
313 314 #define MADV_RANDOM 1 /* expect random page references */
314 315 #define MADV_SEQUENTIAL 2 /* expect sequential page references */
315 316 #define MADV_WILLNEED 3 /* will need these pages */
316 317 #define MADV_DONTNEED 4 /* don't need these pages */
317 318 #define MADV_FREE 5 /* contents can be freed */
318 319 #define MADV_ACCESS_DEFAULT 6 /* default access */
319 320 #define MADV_ACCESS_LWP 7 /* next LWP to access heavily */
320 321 #define MADV_ACCESS_MANY 8 /* many processes to access heavily */
321 322 #define MADV_PURGE 9 /* contents will be purged */
322 323
323 324 #endif /* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */
324 325
325 326 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
326 327 /* advice to posix_madvise */
327 328 /* these values must be kept in sync with the MADV_* values, above */
328 329 #define POSIX_MADV_NORMAL 0 /* MADV_NORMAL */
329 330 #define POSIX_MADV_RANDOM 1 /* MADV_RANDOM */
330 331 #define POSIX_MADV_SEQUENTIAL 2 /* MADV_SEQUENTIAL */
331 332 #define POSIX_MADV_WILLNEED 3 /* MADV_WILLNEED */
332 333 #define POSIX_MADV_DONTNEED 4 /* MADV_DONTNEED */
333 334 #endif
334 335
335 336 /* flags to msync */
336 337 #define MS_OLDSYNC 0x0 /* old value of MS_SYNC */
337 338 /* modified for UNIX98 compliance */
338 339 #define MS_SYNC 0x4 /* wait for msync */
339 340 #define MS_ASYNC 0x1 /* return immediately */
340 341 #define MS_INVALIDATE 0x2 /* invalidate caches */
341 342
342 343 #if (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
343 344 /* functions to mctl */
344 345 #define MC_SYNC 1 /* sync with backing store */
345 346 #define MC_LOCK 2 /* lock pages in memory */
346 347 #define MC_UNLOCK 3 /* unlock pages from memory */
347 348 #define MC_ADVISE 4 /* give advice to management */
348 349 #define MC_LOCKAS 5 /* lock address space in memory */
349 350 #define MC_UNLOCKAS 6 /* unlock address space from memory */
350 351 #define MC_HAT_ADVISE 7 /* advise hat map size */
351 352 #define MC_INHERIT_ZERO 8 /* zero out regions on fork() */
352 353
353 354 /* sub-commands for MC_HAT_ADVISE */
354 355 #define MHA_MAPSIZE_VA 0x1 /* set preferred page size */
355 356 #define MHA_MAPSIZE_BSSBRK 0x2 /* set preferred page size */
356 357 /* for last bss adjacent to */
357 358 /* brk area and brk area itself */
358 359 #define MHA_MAPSIZE_STACK 0x4 /* set preferred page size */
359 360 /* processes main stack */
360 361
361 362 #endif /* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */
362 363
363 364 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
364 365 /* flags to mlockall */
365 366 #define MCL_CURRENT 0x1 /* lock current mappings */
366 367 #define MCL_FUTURE 0x2 /* lock future mappings */
367 368 #endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE)) || defined(__EXTENSIONS__) */
368 369
369 370 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
370 371
371 372 /* definitions for meminfosys syscall */
372 373 #define MISYS_MEMINFO 0x0
373 374
374 375 #if !defined(_ASM)
375 376
376 377 #if defined(_INT64_TYPE)
377 378 /* private structure for meminfo */
378 379 typedef struct meminfo {
379 380 const uint64_t *mi_inaddr; /* array of input addresses */
380 381 const uint_t *mi_info_req; /* array of types of info requested */
381 382 uint64_t *mi_outdata; /* array of results are placed */
382 383 uint_t *mi_validity; /* array of bitwise result codes */
383 384 int mi_info_count; /* number of pieces of info requested */
384 385 } meminfo_t;
385 386 #endif /* defined(_INT64_TYPE) */
386 387
387 388 #if defined(_SYSCALL32)
388 389 typedef struct meminfo32 {
389 390 caddr32_t mi_inaddr; /* array of input addresses */
390 391 caddr32_t mi_info_req; /* array of types of information requested */
391 392 caddr32_t mi_outdata; /* array of results are placed */
392 393 caddr32_t mi_validity; /* array of bitwise result codes */
393 394 int32_t mi_info_count; /* number of pieces of information requested */
394 395 } meminfo32_t;
395 396 #endif /* defined(_SYSCALL32) */
396 397
397 398 #endif /* !defined(_ASM) */
398 399
399 400 /*
400 401 * info_req request type definitions for meminfo
401 402 * request types starting with MEMINFO_V are used for Virtual addresses
402 403 * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical
403 404 * addresses
404 405 */
405 406 #define MEMINFO_SHIFT 16
406 407 #define MEMINFO_MASK (0xFF << MEMINFO_SHIFT)
407 408 #define MEMINFO_VPHYSICAL (0x01 << MEMINFO_SHIFT) /* get physical addr */
408 409 #define MEMINFO_VLGRP (0x02 << MEMINFO_SHIFT) /* get lgroup */
409 410 #define MEMINFO_VPAGESIZE (0x03 << MEMINFO_SHIFT) /* size of phys page */
410 411 #define MEMINFO_VREPLCNT (0x04 << MEMINFO_SHIFT) /* no. of replica */
411 412 #define MEMINFO_VREPL (0x05 << MEMINFO_SHIFT) /* physical replica */
412 413 #define MEMINFO_VREPL_LGRP (0x06 << MEMINFO_SHIFT) /* lgrp of replica */
413 414 #define MEMINFO_PLGRP (0x07 << MEMINFO_SHIFT) /* lgroup for paddr */
414 415
415 416 /* maximum number of addresses meminfo() can process at a time */
416 417 #define MAX_MEMINFO_CNT 256
417 418
418 419 /* maximum number of request types */
419 420 #define MAX_MEMINFO_REQ 31
420 421
421 422 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
422 423
423 424 #ifdef __cplusplus
424 425 }
425 426 #endif
426 427
427 428 #endif /* _SYS_MMAN_H */
↓ open down ↓ |
319 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX