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