1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #ifndef _SYS_MMAN_H 41 #define _SYS_MMAN_H 42 43 #pragma ident "%Z%%M% %I% %E% SMI" 44 45 #include <sys/feature_tests.h> 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /* 52 * Protections are chosen from these bits, or-ed together. 53 * Note - not all implementations literally provide all possible 54 * combinations. PROT_WRITE is often implemented as (PROT_READ | 55 * PROT_WRITE) and (PROT_EXECUTE as PROT_READ | PROT_EXECUTE). 56 * However, no implementation will permit a write to succeed 57 * where PROT_WRITE has not been set. Also, no implementation will 58 * allow any access to succeed where prot is specified as PROT_NONE. 59 */ 60 #define PROT_READ 0x1 /* pages can be read */ 61 #define PROT_WRITE 0x2 /* pages can be written */ 62 #define PROT_EXEC 0x4 /* pages can be executed */ 63 64 #ifdef _KERNEL 65 #define PROT_USER 0x8 /* pages are user accessable */ 66 #define PROT_ZFOD (PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER) 67 #define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER) 68 #endif /* _KERNEL */ 69 70 #define PROT_NONE 0x0 /* pages cannot be accessed */ 71 72 /* sharing types: must choose either SHARED or PRIVATE */ 73 #define MAP_SHARED 1 /* share changes */ 74 #define MAP_PRIVATE 2 /* changes are private */ 75 #define MAP_TYPE 0xf /* mask for share type */ 76 77 /* other flags to mmap (or-ed in to MAP_SHARED or MAP_PRIVATE) */ 78 #define MAP_FIXED 0x10 /* user assigns address */ 79 #define MAP_NORESERVE 0x40 /* don't reserve needed swap area */ 80 #define MAP_ANON 0x100 /* map anonymous pages directly */ 81 #define MAP_ANONYMOUS MAP_ANON /* (source compatibility) */ 82 #define MAP_ALIGN 0x200 /* addr specifies alignment */ 83 #define MAP_TEXT 0x400 /* map code segment */ 84 #define MAP_INITDATA 0x800 /* map data segment */ 85 86 #ifdef _KERNEL 87 #define _MAP_TEXTREPL 0x1000 88 #endif /* _KERNEL */ 89 90 /* these flags not yet implemented */ 91 #define MAP_RENAME 0x20 /* rename private pages to file */ 92 93 #if (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) 94 /* these flags are used by memcntl */ 95 #define PROC_TEXT (PROT_EXEC | PROT_READ) 96 #define PROC_DATA (PROT_READ | PROT_WRITE | PROT_EXEC) 97 #define SHARED 0x10 98 #define PRIVATE 0x20 99 #define VALID_ATTR (PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE) 100 #endif /* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) */ 101 102 #if (_POSIX_C_SOURCE <= 2) || defined(_XPG4_2) 103 #ifdef _KERNEL 104 #define PROT_EXCL 0x20 105 #define _MAP_LOW32 0x80 /* force mapping in lower 4G of address space */ 106 #endif /* _KERNEL */ 107 108 /* 109 * For the sake of backward object compatibility, we use the _MAP_NEW flag. 110 * This flag will be automatically or'ed in by the C library for all 111 * new mmap calls. Previous binaries with old mmap calls will continue 112 * to get 0 or -1 for return values. New mmap calls will get the mapped 113 * address as the return value if successful and -1 on errors. By default, 114 * new mmap calls automatically have the kernel assign the map address 115 * unless the MAP_FIXED flag is given. 116 */ 117 #define _MAP_NEW 0x80000000 /* users should not need to use this */ 118 #endif /* (_POSIX_C_SOURCE <= 2) */ 119 120 #if !defined(_ASM) && !defined(_KERNEL) 121 122 #include <sys/types.h> 123 124 /* 125 * large file compilation environment setup 126 * 127 * In the LP64 compilation environment, map large file interfaces 128 * back to native versions where possible. 129 */ 130 131 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 132 #ifdef __PRAGMA_REDEFINE_EXTNAME 133 #pragma redefine_extname mmap mmap64 134 #else 135 #define mmap mmap64 136 #endif 137 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */ 138 139 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE) 140 #ifdef __PRAGMA_REDEFINE_EXTNAME 141 #pragma redefine_extname mmap64 mmap 142 #else 143 #define mmap64 mmap 144 #endif 145 #endif /* _LP64 && _LARGEFILE64_SOURCE */ 146 147 #ifdef __PRAGMA_REDEFINE_EXTNAME 148 #pragma redefine_extname getpagesizes getpagesizes2 149 #else 150 #define getpagesizes getpagesizes2 151 #endif 152 153 /* 154 * Except for old binaries mmap() will return the resultant 155 * address of mapping on success and (caddr_t)-1 on error. 156 */ 157 #ifdef __STDC__ 158 #if (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 159 extern void *mmap(void *, size_t, int, int, int, off_t); 160 extern int munmap(void *, size_t); 161 extern int mprotect(void *, size_t, int); 162 extern int msync(void *, size_t, int); 163 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__) 164 extern int mlock(const void *, size_t); 165 extern int munlock(const void *, size_t); 166 #endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2))... */ 167 /* transitional large file interface version */ 168 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 169 !defined(__PRAGMA_REDEFINE_EXTNAME)) 170 extern void *mmap64(void *, size_t, int, int, int, off64_t); 171 #endif /* _LARGEFILE64_SOURCE... */ 172 #else /* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */ 173 extern caddr_t mmap(caddr_t, size_t, int, int, int, off_t); 174 extern int munmap(caddr_t, size_t); 175 extern int mprotect(caddr_t, size_t, int); 176 extern int msync(caddr_t, size_t, int); 177 extern int mlock(caddr_t, size_t); 178 extern int munlock(caddr_t, size_t); 179 extern int mincore(caddr_t, size_t, char *); 180 extern int memcntl(caddr_t, size_t, int, caddr_t, int, int); 181 extern int madvise(caddr_t, size_t, int); 182 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 183 extern int getpagesizes(size_t *, int); 184 extern int getpagesizes2(size_t *, int); 185 /* guard visibility of uint64_t */ 186 #if defined(_INT64_TYPE) 187 extern int meminfo(const uint64_t *, int, const uint_t *, int, uint64_t *, 188 uint_t *); 189 #endif /* defined(_INT64_TYPE) */ 190 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 191 /* transitional large file interface version */ 192 #ifdef _LARGEFILE64_SOURCE 193 extern caddr_t mmap64(caddr_t, size_t, int, int, int, off64_t); 194 #endif 195 #endif /* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */ 196 197 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__) 198 extern int mlockall(int); 199 extern int munlockall(void); 200 extern int shm_open(const char *, int, mode_t); 201 extern int shm_unlink(const char *); 202 #endif 203 204 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 205 extern int posix_madvise(void *, size_t, int); 206 #endif 207 208 /* mmap failure value */ 209 #define MAP_FAILED ((void *) -1) 210 211 #else /* __STDC__ */ 212 extern caddr_t mmap(); 213 extern int munmap(); 214 extern int mprotect(); 215 extern int mincore(); 216 extern int memcntl(); 217 extern int msync(); 218 extern int madvise(); 219 extern int posix_madvise(); 220 extern int getpagesizes(); 221 extern int getpagesizes2(); 222 extern int mlock(); 223 extern int mlockall(); 224 extern int munlock(); 225 extern int munlockall(); 226 extern int meminfo(); 227 extern int shm_open(); 228 extern int shm_unlink(); 229 230 /* transitional large file interface version */ 231 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 232 !defined(__PRAGMA_REDEFINE_EXTNAME)) 233 extern caddr_t mmap64(); 234 #endif /* _LARGEFILE64_SOURCE... */ 235 #endif /* __STDC__ */ 236 237 238 #endif /* !_ASM && !_KERNEL */ 239 240 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 241 #if !defined(_ASM) 242 /* 243 * structure for memcntl hat advise operations. 244 */ 245 struct memcntl_mha { 246 uint_t mha_cmd; /* command(s) */ 247 uint_t mha_flags; 248 size_t mha_pagesize; 249 }; 250 251 #if defined(_SYSCALL32) 252 struct memcntl_mha32 { 253 uint_t mha_cmd; /* command(s) */ 254 uint_t mha_flags; 255 size32_t mha_pagesize; 256 }; 257 #endif /* _SYSCALL32 */ 258 #endif /* !defined(_ASM) */ 259 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 260 261 #if (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__) 262 /* advice to madvise */ 263 #define MADV_NORMAL 0 /* no further special treatment */ 264 #define MADV_RANDOM 1 /* expect random page references */ 265 #define MADV_SEQUENTIAL 2 /* expect sequential page references */ 266 #define MADV_WILLNEED 3 /* will need these pages */ 267 #define MADV_DONTNEED 4 /* don't need these pages */ 268 #define MADV_FREE 5 /* contents can be freed */ 269 #define MADV_ACCESS_DEFAULT 6 /* default access */ 270 #define MADV_ACCESS_LWP 7 /* next LWP to access heavily */ 271 #define MADV_ACCESS_MANY 8 /* many processes to access heavily */ 272 #endif /* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */ 273 274 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 275 /* advice to posix_madvise */ 276 /* these values must be kept in sync with the MADV_* values, above */ 277 #define POSIX_MADV_NORMAL 0 /* MADV_NORMAL */ 278 #define POSIX_MADV_RANDOM 1 /* MADV_RANDOM */ 279 #define POSIX_MADV_SEQUENTIAL 2 /* MADV_SEQUENTIAL */ 280 #define POSIX_MADV_WILLNEED 3 /* MADV_WILLNEED */ 281 #define POSIX_MADV_DONTNEED 4 /* MADV_DONTNEED */ 282 #endif 283 284 /* flags to msync */ 285 #define MS_OLDSYNC 0x0 /* old value of MS_SYNC */ 286 /* modified for UNIX98 compliance */ 287 #define MS_SYNC 0x4 /* wait for msync */ 288 #define MS_ASYNC 0x1 /* return immediately */ 289 #define MS_INVALIDATE 0x2 /* invalidate caches */ 290 291 #if (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__) 292 /* functions to mctl */ 293 #define MC_SYNC 1 /* sync with backing store */ 294 #define MC_LOCK 2 /* lock pages in memory */ 295 #define MC_UNLOCK 3 /* unlock pages from memory */ 296 #define MC_ADVISE 4 /* give advice to management */ 297 #define MC_LOCKAS 5 /* lock address space in memory */ 298 #define MC_UNLOCKAS 6 /* unlock address space from memory */ 299 #define MC_HAT_ADVISE 7 /* advise hat map size */ 300 301 /* sub-commands for MC_HAT_ADVISE */ 302 #define MHA_MAPSIZE_VA 0x1 /* set preferred page size */ 303 #define MHA_MAPSIZE_BSSBRK 0x2 /* set preferred page size */ 304 /* for last bss adjacent to */ 305 /* brk area and brk area itself */ 306 #define MHA_MAPSIZE_STACK 0x4 /* set preferred page size */ 307 /* processes main stack */ 308 309 #endif /* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */ 310 311 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__) 312 /* flags to mlockall */ 313 #define MCL_CURRENT 0x1 /* lock current mappings */ 314 #define MCL_FUTURE 0x2 /* lock future mappings */ 315 #endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE)) || defined(__EXTENSIONS__) */ 316 317 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 318 319 /* definitions for meminfosys syscall */ 320 #define MISYS_MEMINFO 0x0 321 322 #if !defined(_ASM) && defined(__STDC__) 323 324 #if defined(_INT64_TYPE) 325 /* private structure for meminfo */ 326 typedef struct meminfo { 327 const uint64_t *mi_inaddr; /* array of input addresses */ 328 const uint_t *mi_info_req; /* array of types of info requested */ 329 uint64_t *mi_outdata; /* array of results are placed */ 330 uint_t *mi_validity; /* array of bitwise result codes */ 331 int mi_info_count; /* number of pieces of info requested */ 332 } meminfo_t; 333 #endif /* defined(_INT64_TYPE) */ 334 335 #if defined(_SYSCALL32) 336 typedef struct meminfo32 { 337 caddr32_t mi_inaddr; /* array of input addresses */ 338 caddr32_t mi_info_req; /* array of types of information requested */ 339 caddr32_t mi_outdata; /* array of results are placed */ 340 caddr32_t mi_validity; /* array of bitwise result codes */ 341 int32_t mi_info_count; /* number of pieces of information requested */ 342 } meminfo32_t; 343 #endif /* defined(_SYSCALL32) */ 344 345 #endif /* !defined(_ASM) && defined(__STDC__) */ 346 347 /* 348 * info_req request type definitions for meminfo 349 * request types starting with MEMINFO_V are used for Virtual addresses 350 * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical 351 * addresses 352 */ 353 #define MEMINFO_SHIFT 16 354 #define MEMINFO_MASK (0xFF << MEMINFO_SHIFT) 355 #define MEMINFO_VPHYSICAL (0x01 << MEMINFO_SHIFT) /* get physical addr */ 356 #define MEMINFO_VLGRP (0x02 << MEMINFO_SHIFT) /* get lgroup */ 357 #define MEMINFO_VPAGESIZE (0x03 << MEMINFO_SHIFT) /* size of phys page */ 358 #define MEMINFO_VREPLCNT (0x04 << MEMINFO_SHIFT) /* no. of replica */ 359 #define MEMINFO_VREPL (0x05 << MEMINFO_SHIFT) /* physical replica */ 360 #define MEMINFO_VREPL_LGRP (0x06 << MEMINFO_SHIFT) /* lgrp of replica */ 361 #define MEMINFO_PLGRP (0x07 << MEMINFO_SHIFT) /* lgroup for paddr */ 362 363 /* maximum number of addresses meminfo() can process at a time */ 364 #define MAX_MEMINFO_CNT 256 365 366 /* maximum number of request types */ 367 #define MAX_MEMINFO_REQ 31 368 369 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 370 371 #ifdef __cplusplus 372 } 373 #endif 374 375 #endif /* _SYS_MMAN_H */ 376