1 /** 2 * D header file for GNU/Linux 3 * 4 * Authors: Martin Nowak 5 */ 6 module core.sys.linux.sys.mman; 7 8 version (linux): 9 extern (C): 10 nothrow: 11 @nogc: 12 13 version (ARM) version = ARM_Any; 14 version (AArch64) version = ARM_Any; 15 version (HPPA) version = HPPA_Any; 16 version (HPPA64) version = HPPA_Any; 17 version (MIPS32) version = MIPS_Any; 18 version (MIPS64) version = MIPS_Any; 19 version (PPC) version = PPC_Any; 20 version (PPC64) version = PPC_Any; 21 version (RISCV32) version = RISCV_Any; 22 version (RISCV64) version = RISCV_Any; 23 version (S390) version = IBMZ_Any; 24 version (SPARC) version = SPARC_Any; 25 version (SPARC64) version = SPARC_Any; 26 version (SystemZ) version = IBMZ_Any; 27 version (X86) version = X86_Any; 28 version (X86_64) version = X86_Any; 29 30 public import core.sys.posix.sys.mman; 31 import core.sys.linux.config; 32 33 // <bits/mman.h> 34 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/powerpc/bits/mman.h 35 version (PPC_Any) 36 { 37 enum PROT_SAO = 0x10; 38 39 static if (_DEFAULT_SOURCE) enum 40 { 41 MAP_GROWSDOWN = 0x00100, 42 MAP_DENYWRITE = 0x00800, 43 MAP_EXECUTABLE = 0x01000, 44 MAP_LOCKED = 0x00080, 45 MAP_NORESERVE = 0x00040, 46 MAP_POPULATE = 0x08000, 47 MAP_NONBLOCK = 0x10000, 48 MAP_STACK = 0x20000, 49 MAP_HUGETLB = 0x40000, 50 } 51 52 // in core.sys.posix.sys.mman 53 // enum 54 // { 55 // MCL_CURRENT = 0x2000, 56 // MCL_FUTURE = 0x4000, 57 // } 58 } 59 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/riscv/bits/mman.h 60 else version (RISCV_Any) 61 { 62 static if (_DEFAULT_SOURCE) enum 63 { 64 MAP_GROWSDOWN = 0x00100, 65 MAP_DENYWRITE = 0x00800, 66 MAP_EXECUTABLE = 0x01000, 67 MAP_LOCKED = 0x02000, 68 MAP_NORESERVE = 0x04000, 69 MAP_POPULATE = 0x08000, 70 MAP_NONBLOCK = 0x10000, 71 MAP_STACK = 0x20000, 72 MAP_HUGETLB = 0x40000, 73 MAP_SYNC = 0x80000, 74 MAP_FIXED_NOREPLACE = 0x100000, 75 } 76 77 // in core.sys.posix.sys.mman 78 // enum 79 // { 80 // MCL_CURRENT = 0x2000, 81 // MCL_FUTURE = 0x4000, 82 // } 83 } 84 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/s390/bits/mman.h 85 else version (IBMZ_Any) 86 { 87 static if (_DEFAULT_SOURCE) enum 88 { 89 MAP_GROWSDOWN = 0x00100, 90 MAP_DENYWRITE = 0x00800, 91 MAP_EXECUTABLE = 0x01000, 92 MAP_LOCKED = 0x02000, 93 MAP_NORESERVE = 0x04000, 94 MAP_POPULATE = 0x08000, 95 MAP_NONBLOCK = 0x10000, 96 MAP_STACK = 0x20000, 97 MAP_HUGETLB = 0x40000, 98 } 99 } 100 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sh/bits/mman.h 101 else version (SH) 102 { 103 static if (_DEFAULT_SOURCE) enum 104 { 105 MAP_GROWSDOWN = 0x0100, 106 MAP_DENYWRITE = 0x0800, 107 MAP_EXECUTABLE = 0x1000, 108 MAP_LOCKED = 0x2000, 109 MAP_NORESERVE = 0x4000, 110 MAP_POPULATE = 0x8000, 111 MAP_NONBLOCK = 0x10000, 112 MAP_STACK = 0x20000, 113 MAP_HUGETLB = 0x40000, 114 } 115 } 116 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sparc/bits/mman.h 117 else version (SPARC_Any) 118 { 119 static if (_DEFAULT_SOURCE) enum 120 { 121 MAP_GROWSDOWN = 0x0200, 122 MAP_DENYWRITE = 0x0800, 123 MAP_EXECUTABLE = 0x1000, 124 MAP_LOCKED = 0x0100, 125 MAP_NORESERVE = 0x0040, 126 _MAP_NEW = 0x80000000, 127 MAP_POPULATE = 0x8000, 128 MAP_NONBLOCK = 0x10000, 129 MAP_STACK = 0x20000, 130 MAP_HUGETLB = 0x40000, 131 } 132 133 // in core.sys.posix.sys.mman 134 // enum 135 // { 136 // MCL_CURRENT = 0x2000, 137 // MCL_FUTURE = 0x4000, 138 // } 139 } 140 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86/bits/mman.h 141 else version (X86_Any) 142 { 143 static if (_DEFAULT_SOURCE) enum MAP_32BIT = 0x40; 144 145 static if (_DEFAULT_SOURCE) enum 146 { 147 MAP_GROWSDOWN = 0x00100, 148 MAP_DENYWRITE = 0x00800, 149 MAP_EXECUTABLE = 0x01000, 150 MAP_LOCKED = 0x02000, 151 MAP_NORESERVE = 0x04000, 152 MAP_POPULATE = 0x08000, 153 MAP_NONBLOCK = 0x10000, 154 MAP_STACK = 0x20000, 155 MAP_HUGETLB = 0x40000, 156 } 157 } 158 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/bits/mman.h 159 else version (AArch64) 160 { 161 static if (_DEFAULT_SOURCE) enum 162 { 163 MAP_GROWSDOWN = 0x00100, 164 MAP_DENYWRITE = 0x00800, 165 MAP_EXECUTABLE = 0x01000, 166 MAP_LOCKED = 0x02000, 167 MAP_NORESERVE = 0x04000, 168 MAP_POPULATE = 0x08000, 169 MAP_NONBLOCK = 0x10000, 170 MAP_STACK = 0x20000, 171 MAP_HUGETLB = 0x40000, 172 } 173 } 174 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/alpha/bits/mman.h 175 else version (Alpha) 176 { 177 enum 178 { 179 PROT_READ = 0x1, 180 PROT_WRITE = 0x2, 181 PROT_EXEC = 0x4, 182 PROT_NONE = 0x0, 183 PROT_GROWSDOWN = 0x01000000, 184 PROT_GROWSUP = 0x02000000, 185 } 186 187 enum MAP_SHARED = 0x01; 188 enum MAP_PRIVATE = 0x02; 189 static if (_DEFAULT_SOURCE) 190 enum MAP_TYPE = 0x0f; 191 192 enum MAP_FIXED = 0x10; 193 static if (_DEFAULT_SOURCE) enum 194 { 195 MAP_FILE = 0, 196 MAP_ANONYMOUS = MAP_ANON, 197 // in core.sys.posix.sys.mman 198 // MAP_ANON = MAP_ANONYMOUS, 199 MAP_HUGE_SHIFT = 26, 200 MAP_HUGE_MASK = 0x3f, 201 } 202 203 static if (_DEFAULT_SOURCE) enum 204 { 205 MAP_GROWSDOWN = 0x01000, 206 MAP_DENYWRITE = 0x02000, 207 MAP_EXECUTABLE = 0x04000, 208 MAP_LOCKED = 0x08000, 209 MAP_NORESERVE = 0x10000, 210 MAP_POPULATE = 0x20000, 211 MAP_NONBLOCK = 0x40000, 212 MAP_STACK = 0x80000, 213 MAP_HUGETLB = 0x100000, 214 } 215 216 // in core.sys.posix.sys.mman 217 // enum 218 // { 219 // MS_ASYNC = 1, 220 // MS_SYNC = 2, 221 // MS_INVALIDATE = 4, 222 // } 223 224 // in core.sys.posix.sys.mman 225 // enum 226 // { 227 // MCL_CURRENT = 8192, 228 // MCL_FUTURE = 16384, 229 // } 230 231 static if (_GNU_SOURCE) enum 232 { 233 MREMAP_MAYMOVE = 1, 234 MREMAP_FIXED = 2, 235 } 236 237 static if (_DEFAULT_SOURCE) enum 238 { 239 MADV_NORMAL = 0, 240 MADV_RANDOM = 1, 241 MADV_SEQUENTIAL = 2, 242 MADV_WILLNEED = 3, 243 MADV_DONTNEED = 6, 244 MADV_REMOVE = 9, 245 MADV_DONTFORK = 10, 246 MADV_DOFORK = 11, 247 MADV_MERGEABLE = 12, 248 MADV_UNMERGEABLE = 13, 249 MADV_HUGEPAGE = 14, 250 MADV_NOHUGEPAGE = 15, 251 MADV_DONTDUMP = 16, 252 MADV_DODUMP = 17, 253 MADV_HWPOISON = 100, 254 } 255 256 // in core.sys.posix.sys.mman 257 // static if (_XOPEN_SOURCE >= 600) enum 258 // { 259 // POSIX_MADV_NORMAL = 0, 260 // POSIX_MADV_RANDOM = 1, 261 // POSIX_MADV_SEQUENTIAL = 2, 262 // POSIX_MADV_WILLNEED = 3, 263 // POSIX_MADV_DONTNEED = 6, 264 // } 265 } 266 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/arm/bits/mman.h 267 else version (ARM) 268 { 269 static if (_DEFAULT_SOURCE) enum 270 { 271 MAP_GROWSDOWN = 0x00100, 272 MAP_DENYWRITE = 0x00800, 273 MAP_EXECUTABLE = 0x01000, 274 MAP_LOCKED = 0x02000, 275 MAP_NORESERVE = 0x04000, 276 MAP_POPULATE = 0x08000, 277 MAP_NONBLOCK = 0x10000, 278 MAP_STACK = 0x20000, 279 MAP_HUGETLB = 0x40000, 280 } 281 } 282 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/hppa/bits/mman.h 283 else version (HPPA_Any) 284 { 285 enum 286 { 287 PROT_READ = 0x1, 288 PROT_WRITE = 0x2, 289 PROT_EXEC = 0x4, 290 PROT_NONE = 0x0, 291 PROT_GROWSDOWN = 0x01000000, 292 PROT_GROWSUP = 0x02000000, 293 } 294 295 enum MAP_SHARED = 0x01; 296 enum MAP_PRIVATE = 0x02; 297 static if (_DEFAULT_SOURCE) 298 enum MAP_TYPE = 0x0f; 299 300 enum MAP_FIXED = 0x04; 301 static if (_DEFAULT_SOURCE) enum 302 { 303 MAP_FILE = 0, 304 MAP_ANONYMOUS = MAP_ANON, 305 // in core.sys.posix.sys.mman 306 // MAP_ANON = MAP_ANONYMOUS, 307 MAP_VARIABLE = 0, 308 MAP_HUGE_SHIFT = 26, 309 MAP_HUGE_MASK = 0x3f, 310 } 311 312 static if (_DEFAULT_SOURCE) enum 313 { 314 MAP_DENYWRITE = 0x0800, 315 MAP_EXECUTABLE = 0x1000, 316 MAP_LOCKED = 0x2000, 317 MAP_NORESERVE = 0x4000, 318 MAP_GROWSDOWN = 0x8000, 319 MAP_POPULATE = 0x10000, 320 MAP_NONBLOCK = 0x20000, 321 } 322 323 // in core.sys.posix.sys.mman 324 // enum 325 // { 326 // MS_ASYNC = 1, 327 // MS_SYNC = 2, 328 // MS_INVALIDATE = 4, 329 // } 330 331 // in core.sys.posix.sys.mman 332 // enum 333 // { 334 // MCL_CURRENT = 1, 335 // MCL_FUTURE = 2, 336 // } 337 338 static if (_GNU_SOURCE) enum 339 { 340 MREMAP_MAYMOVE = 1, 341 MREMAP_FIXED = 2, 342 } 343 344 static if (_DEFAULT_SOURCE) enum 345 { 346 MADV_NORMAL = 0, 347 MADV_RANDOM = 1, 348 MADV_SEQUENTIAL = 2, 349 MADV_WILLNEED = 3, 350 MADV_DONTNEED = 4, 351 MADV_SPACEAVAIL = 5, 352 MADV_VPS_PURGE = 6, 353 MADV_VPS_INHERIT = 7, 354 MADV_REMOVE = 9, 355 MADV_DONTFORK = 10, 356 MADV_DOFORK = 11, 357 MADV_MERGEABLE = 65, 358 MADV_UNMERGEABLE = 66, 359 MADV_HUGEPAGE = 67, 360 MADV_NOHUGEPAGE = 68, 361 MADV_DONTDUMP = 69, 362 } 363 364 deprecated("MADV_*_PAGES are gone and never had any effect") enum 365 { 366 MADV_4K_PAGES = 12, 367 MADV_16K_PAGES = 14, 368 MADV_64K_PAGES = 16, 369 MADV_256K_PAGES = 18, 370 MADV_1M_PAGES = 20, 371 MADV_4M_PAGES = 22, 372 MADV_16M_PAGES = 24, 373 MADV_64M_PAGES = 26, 374 } 375 376 // in core.sys.posix.sys.mman 377 // static if (_XOPEN_SOURCE >= 600) enum 378 // { 379 // POSIX_MADV_NORMAL = 0, 380 // POSIX_MADV_RANDOM = 1, 381 // POSIX_MADV_SEQUENTIAL = 2, 382 // POSIX_MADV_WILLNEED = 3, 383 // POSIX_MADV_DONTNEED = 4, 384 // } 385 } 386 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/ia64/bits/mman.h 387 else version (IA64) 388 { 389 static if (_DEFAULT_SOURCE) enum 390 { 391 MAP_GROWSDOWN = 0x00100, 392 MAP_GROWSUP = 0x00200, 393 MAP_DENYWRITE = 0x00800, 394 MAP_EXECUTABLE = 0x01000, 395 MAP_LOCKED = 0x02000, 396 MAP_NORESERVE = 0x04000, 397 MAP_POPULATE = 0x08000, 398 MAP_NONBLOCK = 0x10000, 399 MAP_STACK = 0x20000, 400 MAP_HUGETLB = 0x40000, 401 } 402 } 403 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/m68k/bits/mman.h 404 else version (M68K) 405 { 406 static if (_DEFAULT_SOURCE) enum 407 { 408 MAP_GROWSDOWN = 0x00100, 409 MAP_DENYWRITE = 0x00800, 410 MAP_EXECUTABLE = 0x01000, 411 MAP_LOCKED = 0x02000, 412 MAP_NORESERVE = 0x04000, 413 MAP_POPULATE = 0x08000, 414 MAP_NONBLOCK = 0x10000, 415 MAP_STACK = 0x20000, 416 MAP_HUGETLB = 0x40000, 417 } 418 } 419 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/mman.h 420 else version (MIPS_Any) 421 { 422 static if (_DEFAULT_SOURCE) enum 423 { 424 MAP_NORESERVE = 0x0400, 425 MAP_GROWSDOWN = 0x1000, 426 MAP_DENYWRITE = 0x2000, 427 MAP_EXECUTABLE = 0x4000, 428 MAP_LOCKED = 0x8000, 429 MAP_POPULATE = 0x10000, 430 MAP_NONBLOCK = 0x20000, 431 MAP_STACK = 0x40000, 432 MAP_HUGETLB = 0x80000, 433 } 434 } 435 else version (LoongArch64) 436 { 437 static if (_DEFAULT_SOURCE) enum 438 { 439 MAP_GROWSDOWN = 0x00100, 440 MAP_DENYWRITE = 0x00800, 441 MAP_EXECUTABLE = 0x01000, 442 MAP_LOCKED = 0x02000, 443 MAP_NORESERVE = 0x04000, 444 MAP_POPULATE = 0x08000, 445 MAP_NONBLOCK = 0x10000, 446 MAP_STACK = 0x20000, 447 MAP_HUGETLB = 0x40000, 448 MAP_SYNC = 0x80000, 449 MAP_FIXED_NOREPLACE = 0x100000, 450 } 451 452 // in core.sys.posix.sys.mman 453 // enum 454 // { 455 // MCL_CURRENT = 0x1, 456 // MCL_FUTURE = 0x2, 457 // } 458 } 459 else 460 { 461 static assert(0, "unimplemented"); 462 } 463 464 465 // <bits/mman-linux.h> 466 // https://sourceware.org/git/?p=glibc.git;a=blob;f=bits/mman-linux.h 467 version (Alpha) 468 { 469 } 470 else version (HPPA_Any) 471 { 472 } 473 else 474 { 475 // in core.sys.posix.sys.mman 476 // enum PROT_READ = 0x1; 477 // enum PROT_WRITE = 0x2; 478 // enum PROT_EXEC = 0x4; 479 // enum PROT_NONE = 0x0; 480 481 enum PROT_GROWSDOWN = 0x01000000; 482 enum PROT_GROWSUP = 0x02000000; 483 484 enum MAP_SHARED = 0x01; 485 enum MAP_PRIVATE = 0x02; 486 static if (_DEFAULT_SOURCE) 487 enum MAP_TYPE = 0x0f; 488 489 enum MAP_FIXED = 0x10; 490 static if (_DEFAULT_SOURCE) enum 491 { 492 MAP_FILE = 0, 493 MAP_ANONYMOUS = MAP_ANON, 494 // in core.sys.posix.sys.mman 495 // MAP_ANON = 0xXX, 496 MAP_HUGE_SHIFT = 26, 497 MAP_HUGE_MASK = 0x3f, 498 } 499 500 // in core.sys.posix.sys.mman 501 // enum 502 // { 503 // MS_ASYNC = 1, 504 // MS_SYNC = 4, 505 // MS_INVALIDATE = 2, 506 // } 507 508 static if (_GNU_SOURCE) enum 509 { 510 MREMAP_MAYMOVE = 1, 511 MREMAP_FIXED = 2, 512 } 513 514 static if (_DEFAULT_SOURCE) enum 515 { 516 MADV_NORMAL = 0, 517 MADV_RANDOM = 1, 518 MADV_SEQUENTIAL = 2, 519 MADV_WILLNEED = 3, 520 MADV_DONTNEED = 4, 521 MADV_REMOVE = 9, 522 MADV_DONTFORK = 10, 523 MADV_DOFORK = 11, 524 MADV_MERGEABLE = 12, 525 MADV_UNMERGEABLE = 13, 526 MADV_HUGEPAGE = 14, 527 MADV_NOHUGEPAGE = 15, 528 MADV_DONTDUMP = 16, 529 MADV_DODUMP = 17, 530 MADV_HWPOISON = 100, 531 } 532 533 // in core.sys.posix.sys.mman 534 // static if (_XOPEN_SOURCE >= 600) enum 535 // { 536 // POSIX_MADV_NORMAL = 0, 537 // POSIX_MADV_RANDOM = 1, 538 // POSIX_MADV_SEQUENTIAL = 2, 539 // POSIX_MADV_WILLNEED = 3, 540 // POSIX_MADV_DONTNEED = 4, 541 // } 542 543 // in core.sys.posix.sys.mman 544 // enum 545 // { 546 // 547 // MCL_CURRENT = 1, 548 // MCL_FUTURE = 2, 549 // } 550 } 551 552 // Workaround https://issues.dlang.org/show_bug.cgi?id=17883 553 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sparc/bits/mman.h 554 version (SPARC_Any) 555 { 556 static if (_DEFAULT_SOURCE) enum MAP_RENAME = MAP_ANONYMOUS; 557 } 558 // http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/mman.h 559 else version (MIPS_Any) 560 { 561 static if (_DEFAULT_SOURCE) enum MAP_RENAME = MAP_ANONYMOUS; 562 } 563 564 // http://sourceware.org/git/?p=glibc.git;a=blob;f=misc/sys/mman.h 565 // in core.sys.posix.sys.mman 566 // static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, off_t); 567 // static if (__USE_FILE_OFFSET64) 568 // alias mmap64 mmap; 569 // else 570 // void* mmap(void*, size_t, int, int, int, off_t); 571 // int munmap(void*, size_t); 572 // int mprotect(void *__addr, size_t __len, int __prot); 573 // int msync(void *__addr, size_t __len, int __flags); 574 static if (_DEFAULT_SOURCE) int madvise(void *__addr, size_t __len, int __advice); 575 // static if (_XOPEN_SOURCE >= 600) int posix_madvise(void *__addr, size_t __len, int __advice); 576 // int mlock(const(void) *__addr, size_t __len); 577 // int munlock(const(void) *__addr, size_t __len); 578 // int mlockall(int __flags); 579 // int munlockall(); 580 static if (_DEFAULT_SOURCE) int mincore(void *__start, size_t __len, ubyte *__vec); 581 static if (_GNU_SOURCE) void *mremap(void *__addr, size_t __old_len, size_t __new_len, int __flags, ...); 582 static if (_GNU_SOURCE) int remap_file_pages(void *__start, size_t __size, int __prot, size_t __pgoff, int __flags); 583 // int shm_open(in char *__name, int __oflag, mode_t __mode); 584 // int shm_unlink(in char *__name);