1 /** 2 * D header file for POSIX. 3 * 4 * Copyright: Copyright Sean Kelly 2005 - 2009. 5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 * Authors: Sean Kelly, 7 Alex Rønne Petersen 8 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition 9 */ 10 11 /* Copyright Sean Kelly 2005 - 2009. 12 * Distributed under the Boost Software License, Version 1.0. 13 * (See accompanying file LICENSE or copy at 14 * http://www.boost.org/LICENSE_1_0.txt) 15 */ 16 module core.sys.posix.sys.types; 17 18 import core.sys.posix.config; 19 import core.stdc.stdint; 20 public import core.stdc.stddef; 21 22 version (OSX) 23 version = Darwin; 24 else version (iOS) 25 version = Darwin; 26 else version (TVOS) 27 version = Darwin; 28 else version (WatchOS) 29 version = Darwin; 30 31 version (Posix): 32 extern (C): 33 34 // 35 // bits/typesizes.h -- underlying types for *_t. 36 // 37 /* 38 __syscall_slong_t 39 __syscall_ulong_t 40 */ 41 version (CRuntime_Glibc) 42 { 43 version (X86_64) 44 { 45 version (D_X32) 46 { 47 // X32 kernel interface is 64-bit. 48 alias long slong_t; 49 alias ulong ulong_t; 50 } 51 else 52 { 53 alias c_long slong_t; 54 alias c_ulong ulong_t; 55 } 56 } 57 else 58 { 59 alias c_long slong_t; 60 alias c_ulong ulong_t; 61 } 62 } 63 else 64 { 65 alias c_long slong_t; 66 alias c_ulong ulong_t; 67 } 68 69 // 70 // Required 71 // 72 /* 73 blkcnt_t 74 blksize_t 75 dev_t 76 gid_t 77 ino_t 78 mode_t 79 nlink_t 80 off_t 81 pid_t 82 size_t 83 ssize_t 84 time_t 85 uid_t 86 */ 87 88 version (linux) 89 { 90 static if ( __USE_FILE_OFFSET64 ) 91 { 92 alias long blkcnt_t; 93 alias ulong ino_t; 94 alias long off_t; 95 } 96 else 97 { 98 alias slong_t blkcnt_t; 99 alias ulong_t ino_t; 100 alias slong_t off_t; 101 } 102 alias slong_t blksize_t; 103 alias ulong dev_t; 104 alias uint gid_t; 105 alias uint mode_t; 106 alias ulong_t nlink_t; 107 alias int pid_t; 108 //size_t (defined in core.stdc.stddef) 109 alias c_long ssize_t; 110 alias uint uid_t; 111 112 version (CRuntime_Musl) 113 { 114 /** 115 * Musl versions before v1.2.0 (up to v1.1.24) had different 116 * definitions for `time_t` for 32 bits. 117 * This was changed to always be 64 bits in v1.2.0: 118 * https://musl.libc.org/time64.html 119 * This change was only for 32 bits system and 120 * didn't affect 64 bits systems 121 * 122 * To check previous definitions, `grep` for `time_t` in `arch/`, 123 * and the result should be (in v1.1.24): 124 * --- 125 * // arch/riscv64/bits/alltypes.h.in:20:TYPEDEF long time_t; 126 * // arch/s390x/bits/alltypes.h.in:17:TYPEDEF long time_t; 127 * // arch/sh/bits/alltypes.h.in:21:TYPEDEF long time_t; 128 * --- 129 * 130 * In order to be compatible with old versions of Musl, 131 * one can recompile druntime with `CRuntime_Musl_Pre_Time64`. 132 */ 133 version (D_X32) 134 alias long time_t; 135 else version (CRuntime_Musl_Pre_Time64) 136 alias c_long time_t; 137 else 138 alias long time_t; 139 } 140 else 141 { 142 alias slong_t time_t; 143 } 144 } 145 else version (Darwin) 146 { 147 alias long blkcnt_t; 148 alias int blksize_t; 149 alias int dev_t; 150 alias uint gid_t; 151 alias ulong ino_t; 152 alias ushort mode_t; 153 alias ushort nlink_t; 154 alias long off_t; 155 alias int pid_t; 156 //size_t (defined in core.stdc.stddef) 157 alias c_long ssize_t; 158 alias c_long time_t; 159 alias uint uid_t; 160 } 161 else version (FreeBSD) 162 { 163 import core.sys.freebsd.config; 164 165 // https://github.com/freebsd/freebsd/blob/master/sys/sys/_types.h 166 alias long blkcnt_t; 167 alias uint blksize_t; 168 169 static if (__FreeBSD_version >= 1200000) 170 { 171 alias ulong dev_t; 172 alias ulong ino_t; 173 alias ulong nlink_t; 174 } 175 else 176 { 177 alias uint dev_t; 178 alias uint ino_t; 179 alias ushort nlink_t; 180 } 181 182 alias uint gid_t; 183 alias ushort mode_t; 184 alias long off_t; 185 alias int pid_t; 186 //size_t (defined in core.stdc.stddef) 187 alias c_long ssize_t; 188 alias c_long time_t; 189 alias uint uid_t; 190 alias uint fflags_t; 191 } 192 else version (NetBSD) 193 { 194 alias long blkcnt_t; 195 alias int blksize_t; 196 alias ulong dev_t; 197 alias uint gid_t; 198 alias ulong ino_t; 199 alias uint mode_t; 200 alias uint nlink_t; 201 alias ulong off_t; 202 alias int pid_t; 203 //size_t (defined in core.stdc.stddef) 204 alias c_long ssize_t; 205 alias c_long time_t; 206 alias uint uid_t; 207 } 208 else version (OpenBSD) 209 { 210 alias char* caddr_t; 211 alias long blkcnt_t; 212 alias int blksize_t; 213 alias int dev_t; 214 alias uint gid_t; 215 alias ulong ino_t; 216 alias uint mode_t; 217 alias uint nlink_t; 218 alias long off_t; 219 alias int pid_t; 220 //size_t (defined in core.stdc.stddef) 221 alias c_long ssize_t; 222 alias long time_t; 223 alias uint uid_t; 224 } 225 else version (DragonFlyBSD) 226 { 227 alias long blkcnt_t; 228 alias long blksize_t; 229 alias uint dev_t; 230 alias uint gid_t; 231 alias long ino_t; 232 alias ushort mode_t; 233 alias uint nlink_t; 234 alias long off_t; //__off_t (defined in /usr/include/sys/stdint.h -> core.stdc.stddef) 235 alias int pid_t; // size_t (defined in /usr/include/sys/stdint.h -> core.stdc.stddef) 236 alias c_long ssize_t; 237 alias long time_t; 238 alias uint uid_t; 239 } 240 else version (Solaris) 241 { 242 alias char* caddr_t; 243 alias c_long daddr_t; 244 alias short cnt_t; 245 246 static if (__USE_FILE_OFFSET64) 247 { 248 alias long blkcnt_t; 249 alias ulong ino_t; 250 alias long off_t; 251 } 252 else 253 { 254 alias c_long blkcnt_t; 255 alias c_ulong ino_t; 256 alias c_long off_t; 257 } 258 259 version (D_LP64) 260 { 261 alias blkcnt_t blkcnt64_t; 262 alias ino_t ino64_t; 263 alias off_t off64_t; 264 } 265 else 266 { 267 alias long blkcnt64_t; 268 alias ulong ino64_t; 269 alias long off64_t; 270 } 271 272 alias uint blksize_t; 273 alias c_ulong dev_t; 274 alias uid_t gid_t; 275 alias uint mode_t; 276 alias uint nlink_t; 277 alias int pid_t; 278 alias c_long ssize_t; 279 alias c_long time_t; 280 alias uint uid_t; 281 } 282 else 283 { 284 static assert(false, "Unsupported platform"); 285 } 286 287 // 288 // XOpen (XSI) 289 // 290 /* 291 clock_t 292 fsblkcnt_t 293 fsfilcnt_t 294 id_t 295 key_t 296 suseconds_t 297 useconds_t 298 */ 299 300 version (linux) 301 { 302 static if ( __USE_FILE_OFFSET64 ) 303 { 304 alias ulong fsblkcnt_t; 305 alias ulong fsfilcnt_t; 306 } 307 else 308 { 309 alias ulong_t fsblkcnt_t; 310 alias ulong_t fsfilcnt_t; 311 } 312 alias slong_t clock_t; 313 alias uint id_t; 314 alias int key_t; 315 alias slong_t suseconds_t; 316 alias uint useconds_t; 317 } 318 else version (Darwin) 319 { 320 alias uint fsblkcnt_t; 321 alias uint fsfilcnt_t; 322 alias c_long clock_t; 323 alias uint id_t; 324 alias int key_t; 325 alias int suseconds_t; 326 alias uint useconds_t; 327 } 328 else version (FreeBSD) 329 { 330 alias ulong fsblkcnt_t; 331 alias ulong fsfilcnt_t; 332 alias c_long clock_t; 333 alias long id_t; 334 alias c_long key_t; 335 alias c_long suseconds_t; 336 alias uint useconds_t; 337 } 338 else version (NetBSD) 339 { 340 alias ulong fsblkcnt_t; 341 alias ulong fsfilcnt_t; 342 alias c_long clock_t; 343 alias long id_t; 344 alias c_long key_t; 345 alias c_long suseconds_t; 346 alias uint useconds_t; 347 } 348 else version (OpenBSD) 349 { 350 alias ulong fsblkcnt_t; 351 alias ulong fsfilcnt_t; 352 alias long clock_t; 353 alias uint id_t; 354 alias c_long key_t; 355 alias c_long suseconds_t; 356 alias uint useconds_t; 357 } 358 else version (DragonFlyBSD) 359 { 360 alias ulong fsblkcnt_t; 361 alias ulong fsfilcnt_t; 362 alias c_long clock_t; 363 alias long id_t; 364 alias c_long key_t; 365 alias c_long suseconds_t; 366 alias uint useconds_t; 367 } 368 else version (Solaris) 369 { 370 static if (__USE_FILE_OFFSET64) 371 { 372 alias ulong fsblkcnt_t; 373 alias ulong fsfilcnt_t; 374 } 375 else 376 { 377 alias c_ulong fsblkcnt_t; 378 alias c_ulong fsfilcnt_t; 379 } 380 381 alias c_long clock_t; 382 alias int id_t; 383 alias int key_t; 384 alias c_long suseconds_t; 385 alias uint useconds_t; 386 387 alias id_t taskid_t; 388 alias id_t projid_t; 389 alias id_t poolid_t; 390 alias id_t zoneid_t; 391 alias id_t ctid_t; 392 } 393 else 394 { 395 static assert(false, "Unsupported platform"); 396 } 397 398 // 399 // Thread (THR) 400 // 401 /* 402 pthread_attr_t 403 pthread_cond_t 404 pthread_condattr_t 405 pthread_key_t 406 pthread_mutex_t 407 pthread_mutexattr_t 408 pthread_once_t 409 pthread_rwlock_t 410 pthread_rwlockattr_t 411 pthread_t 412 */ 413 414 version (CRuntime_Glibc) 415 { 416 version (X86) 417 { 418 enum __SIZEOF_PTHREAD_ATTR_T = 36; 419 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 420 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 421 enum __SIZEOF_PTHREAD_COND_T = 48; 422 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 423 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 424 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 425 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 426 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 427 } 428 else version (X86_64) 429 { 430 static if (__WORDSIZE == 64) 431 { 432 enum __SIZEOF_PTHREAD_ATTR_T = 56; 433 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 434 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 435 enum __SIZEOF_PTHREAD_COND_T = 48; 436 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 437 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 438 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 439 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 440 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 441 } 442 else 443 { 444 enum __SIZEOF_PTHREAD_ATTR_T = 32; 445 enum __SIZEOF_PTHREAD_MUTEX_T = 32; 446 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 447 enum __SIZEOF_PTHREAD_COND_T = 48; 448 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 449 enum __SIZEOF_PTHREAD_RWLOCK_T = 44; 450 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 451 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 452 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 453 } 454 } 455 else version (AArch64) 456 { 457 enum __SIZEOF_PTHREAD_ATTR_T = 64; 458 enum __SIZEOF_PTHREAD_MUTEX_T = 48; 459 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 8; 460 enum __SIZEOF_PTHREAD_COND_T = 48; 461 enum __SIZEOF_PTHREAD_CONDATTR_T = 8; 462 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 463 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 464 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 465 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 8; 466 } 467 else version (ARM) 468 { 469 enum __SIZEOF_PTHREAD_ATTR_T = 36; 470 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 471 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 472 enum __SIZEOF_PTHREAD_COND_T = 48; 473 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 474 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 475 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 476 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 477 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 478 } 479 else version (HPPA) 480 { 481 enum __SIZEOF_PTHREAD_ATTR_T = 36; 482 enum __SIZEOF_PTHREAD_MUTEX_T = 48; 483 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 484 enum __SIZEOF_PTHREAD_COND_T = 48; 485 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 486 enum __SIZEOF_PTHREAD_RWLOCK_T = 64; 487 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 488 enum __SIZEOF_PTHREAD_BARRIER_T = 48; 489 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 490 } 491 else version (IA64) 492 { 493 enum __SIZEOF_PTHREAD_ATTR_T = 56; 494 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 495 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 496 enum __SIZEOF_PTHREAD_COND_T = 48; 497 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 498 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 499 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 500 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 501 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 502 } 503 else version (MIPS32) 504 { 505 enum __SIZEOF_PTHREAD_ATTR_T = 36; 506 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 507 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 508 enum __SIZEOF_PTHREAD_COND_T = 48; 509 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 510 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 511 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 512 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 513 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 514 } 515 else version (MIPS64) 516 { 517 enum __SIZEOF_PTHREAD_ATTR_T = 56; 518 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 519 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 520 enum __SIZEOF_PTHREAD_COND_T = 48; 521 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 522 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 523 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 524 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 525 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 526 } 527 else version (PPC) 528 { 529 enum __SIZEOF_PTHREAD_ATTR_T = 36; 530 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 531 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 532 enum __SIZEOF_PTHREAD_COND_T = 48; 533 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 534 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 535 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 536 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 537 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 538 } 539 else version (PPC64) 540 { 541 enum __SIZEOF_PTHREAD_ATTR_T = 56; 542 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 543 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 544 enum __SIZEOF_PTHREAD_COND_T = 48; 545 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 546 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 547 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 548 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 549 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 550 } 551 else version (RISCV32) 552 { 553 enum __SIZEOF_PTHREAD_ATTR_T = 36; 554 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 555 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 556 enum __SIZEOF_PTHREAD_COND_T = 48; 557 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 558 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 559 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 560 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 561 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 562 } 563 else version (RISCV64) 564 { 565 enum __SIZEOF_PTHREAD_ATTR_T = 56; 566 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 567 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 568 enum __SIZEOF_PTHREAD_COND_T = 48; 569 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 570 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 571 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 572 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 573 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 574 } 575 else version (SPARC) 576 { 577 enum __SIZEOF_PTHREAD_ATTR_T = 36; 578 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 579 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 580 enum __SIZEOF_PTHREAD_COND_T = 48; 581 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 582 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 583 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 584 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 585 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 586 } 587 else version (SPARC64) 588 { 589 enum __SIZEOF_PTHREAD_ATTR_T = 56; 590 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 591 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 592 enum __SIZEOF_PTHREAD_COND_T = 48; 593 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 594 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 595 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 596 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 597 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 598 } 599 else version (S390) 600 { 601 enum __SIZEOF_PTHREAD_ATTR_T = 36; 602 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 603 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 604 enum __SIZEOF_PTHREAD_COND_T = 48; 605 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 606 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 607 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 608 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 609 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 610 } 611 else version (SystemZ) 612 { 613 enum __SIZEOF_PTHREAD_ATTR_T = 56; 614 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 615 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 616 enum __SIZEOF_PTHREAD_COND_T = 48; 617 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 618 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 619 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 620 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 621 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 622 } 623 else 624 { 625 static assert (false, "Unsupported platform"); 626 } 627 628 union pthread_attr_t 629 { 630 byte[__SIZEOF_PTHREAD_ATTR_T] __size; 631 c_long __align; 632 } 633 634 private alias int __atomic_lock_t; 635 636 private struct _pthread_fastlock 637 { 638 c_long __status; 639 __atomic_lock_t __spinlock; 640 } 641 642 private alias void* _pthread_descr; 643 644 union pthread_cond_t 645 { 646 byte[__SIZEOF_PTHREAD_COND_T] __size; 647 long __align; 648 } 649 650 union pthread_condattr_t 651 { 652 byte[__SIZEOF_PTHREAD_CONDATTR_T] __size; 653 int __align; 654 } 655 656 alias uint pthread_key_t; 657 658 union pthread_mutex_t 659 { 660 byte[__SIZEOF_PTHREAD_MUTEX_T] __size; 661 c_long __align; 662 } 663 664 union pthread_mutexattr_t 665 { 666 byte[__SIZEOF_PTHREAD_MUTEXATTR_T] __size; 667 int __align; 668 } 669 670 alias int pthread_once_t; 671 672 struct pthread_rwlock_t 673 { 674 byte[__SIZEOF_PTHREAD_RWLOCK_T] __size; 675 c_long __align; 676 } 677 678 struct pthread_rwlockattr_t 679 { 680 byte[__SIZEOF_PTHREAD_RWLOCKATTR_T] __size; 681 c_long __align; 682 } 683 684 alias c_ulong pthread_t; 685 } 686 else version (CRuntime_Musl) 687 { 688 version (D_LP64) 689 { 690 union pthread_attr_t 691 { 692 int[14] __i; 693 ulong[7] __s; 694 } 695 696 union pthread_cond_t 697 { 698 int[12] __i; 699 void*[6] __p; 700 } 701 702 union pthread_mutex_t 703 { 704 int[10] __i; 705 void*[5] __p; 706 } 707 708 union pthread_rwlock_t 709 { 710 int[14] __i; 711 void*[7] __p; 712 } 713 } 714 else 715 { 716 union pthread_attr_t 717 { 718 int[9] __i; 719 uint[9] __s; 720 } 721 722 union pthread_cond_t 723 { 724 int[12] __i; 725 void*[12] __p; 726 } 727 728 union pthread_mutex_t 729 { 730 int[6] __i; 731 void*[6] __p; 732 } 733 734 union pthread_rwlock_t 735 { 736 int[8] __i; 737 void*[8] __p; 738 } 739 } 740 741 struct pthread_rwlockattr_t 742 { 743 uint[2] __attr; 744 } 745 746 alias uint pthread_key_t; 747 748 struct pthread_condattr_t 749 { 750 uint __attr; 751 } 752 753 struct pthread_mutexattr_t 754 { 755 uint __attr; 756 } 757 758 alias int pthread_once_t; 759 760 alias c_ulong pthread_t; 761 } 762 else version (Darwin) 763 { 764 version (D_LP64) 765 { 766 enum __PTHREAD_SIZE__ = 8176; 767 enum __PTHREAD_ATTR_SIZE__ = 56; 768 enum __PTHREAD_MUTEXATTR_SIZE__ = 8; 769 enum __PTHREAD_MUTEX_SIZE__ = 56; 770 enum __PTHREAD_CONDATTR_SIZE__ = 8; 771 enum __PTHREAD_COND_SIZE__ = 40; 772 enum __PTHREAD_ONCE_SIZE__ = 8; 773 enum __PTHREAD_RWLOCK_SIZE__ = 192; 774 enum __PTHREAD_RWLOCKATTR_SIZE__ = 16; 775 } 776 else 777 { 778 enum __PTHREAD_SIZE__ = 4088; 779 enum __PTHREAD_ATTR_SIZE__ = 36; 780 enum __PTHREAD_MUTEXATTR_SIZE__ = 8; 781 enum __PTHREAD_MUTEX_SIZE__ = 40; 782 enum __PTHREAD_CONDATTR_SIZE__ = 4; 783 enum __PTHREAD_COND_SIZE__ = 24; 784 enum __PTHREAD_ONCE_SIZE__ = 4; 785 enum __PTHREAD_RWLOCK_SIZE__ = 124; 786 enum __PTHREAD_RWLOCKATTR_SIZE__ = 12; 787 } 788 789 struct pthread_handler_rec 790 { 791 void function(void*) __routine; 792 void* __arg; 793 pthread_handler_rec* __next; 794 } 795 796 struct pthread_attr_t 797 { 798 c_long __sig; 799 byte[__PTHREAD_ATTR_SIZE__] __opaque; 800 } 801 802 struct pthread_cond_t 803 { 804 c_long __sig; 805 byte[__PTHREAD_COND_SIZE__] __opaque; 806 } 807 808 struct pthread_condattr_t 809 { 810 c_long __sig; 811 byte[__PTHREAD_CONDATTR_SIZE__] __opaque; 812 } 813 814 alias c_ulong pthread_key_t; 815 816 struct pthread_mutex_t 817 { 818 c_long __sig; 819 byte[__PTHREAD_MUTEX_SIZE__] __opaque; 820 } 821 822 struct pthread_mutexattr_t 823 { 824 c_long __sig; 825 byte[__PTHREAD_MUTEXATTR_SIZE__] __opaque; 826 } 827 828 struct pthread_once_t 829 { 830 c_long __sig; 831 byte[__PTHREAD_ONCE_SIZE__] __opaque; 832 } 833 834 struct pthread_rwlock_t 835 { 836 c_long __sig; 837 byte[__PTHREAD_RWLOCK_SIZE__] __opaque; 838 } 839 840 struct pthread_rwlockattr_t 841 { 842 c_long __sig; 843 byte[__PTHREAD_RWLOCKATTR_SIZE__] __opaque; 844 } 845 846 private struct _opaque_pthread_t 847 { 848 c_long __sig; 849 pthread_handler_rec* __cleanup_stack; 850 byte[__PTHREAD_SIZE__] __opaque; 851 } 852 853 alias _opaque_pthread_t* pthread_t; 854 } 855 else version (FreeBSD) 856 { 857 alias int lwpid_t; 858 859 alias void* pthread_attr_t; 860 alias void* pthread_cond_t; 861 alias void* pthread_condattr_t; 862 alias void* pthread_key_t; 863 alias void* pthread_mutex_t; 864 alias void* pthread_mutexattr_t; 865 alias void* pthread_once_t; 866 alias void* pthread_rwlock_t; 867 alias void* pthread_rwlockattr_t; 868 alias void* pthread_t; 869 } 870 else version (NetBSD) 871 { 872 struct pthread_queue_t { 873 void* ptqh_first; 874 void** ptqh_last; 875 } 876 877 alias lwpid_t = int; 878 alias pthread_spin_t = ubyte; 879 struct pthread_attr_t { 880 uint pta_magic; 881 int pta_flags; 882 void* pta_private; 883 } 884 struct pthread_spinlock_t { 885 uint pts_magic; 886 pthread_spin_t pts_spin; 887 int pts_flags; 888 } 889 struct pthread_cond_t { 890 uint ptc_magic; 891 pthread_spin_t ptc_lock; 892 pthread_queue_t ptc_waiters; 893 pthread_mutex_t *ptc_mutex; 894 void* ptc_private; 895 } 896 struct pthread_condattr_t { 897 uint ptca_magic; 898 void *ptca_private; 899 } 900 struct pthread_mutex_t { 901 uint ptm_magic; 902 pthread_spin_t ptm_errorcheck; 903 ubyte[3] ptm_pad1; 904 pthread_spin_t ptm_interlock; 905 ubyte[3] ptm_pad2; 906 pthread_t ptm_owner; 907 void* ptm_waiters; 908 uint ptm_recursed; 909 void* ptm_spare2; 910 } 911 struct pthread_mutexattr_t{ 912 uint ptma_magic; 913 void* ptma_private; 914 } 915 struct pthread_once_t{ 916 pthread_mutex_t pto_mutex; 917 int pto_done; 918 } 919 struct pthread_rwlock_t{ 920 uint ptr_magic; 921 922 pthread_spin_t ptr_interlock; 923 924 pthread_queue_t ptr_rblocked; 925 pthread_queue_t ptr_wblocked; 926 uint ptr_nreaders; 927 pthread_t ptr_owner; 928 void *ptr_private; 929 } 930 struct pthread_rwlockattr_t{ 931 uint ptra_magic; 932 void* ptra_private; 933 } 934 935 alias uint pthread_key_t; 936 alias void* pthread_t; 937 } 938 else version (OpenBSD) 939 { 940 alias void* pthread_attr_t; 941 alias void* pthread_cond_t; 942 alias void* pthread_condattr_t; 943 alias int pthread_key_t; 944 alias void* pthread_mutex_t; 945 alias void* pthread_mutexattr_t; 946 947 private struct pthread_once 948 { 949 int state; 950 pthread_mutex_t mutex; 951 } 952 alias pthread_once pthread_once_t; 953 954 alias void* pthread_rwlock_t; 955 alias void* pthread_rwlockattr_t; 956 alias void* pthread_t; 957 } 958 else version (DragonFlyBSD) 959 { 960 alias int lwpid_t; 961 962 alias void* pthread_attr_t; 963 alias void* pthread_cond_t; 964 alias void* pthread_condattr_t; 965 alias void* pthread_key_t; 966 alias void* pthread_mutex_t; 967 alias void* pthread_mutexattr_t; 968 969 private struct pthread_once 970 { 971 int state; 972 pthread_mutex_t mutex; 973 } 974 alias pthread_once pthread_once_t; 975 976 alias void* pthread_rwlock_t; 977 alias void* pthread_rwlockattr_t; 978 alias void* pthread_t; 979 } 980 else version (Solaris) 981 { 982 alias uint pthread_t; 983 984 struct pthread_attr_t 985 { 986 void* __pthread_attrp; 987 } 988 989 struct pthread_cond_t 990 { 991 struct ___pthread_cond_flags 992 { 993 ubyte[4] __pthread_cond_flags; 994 ushort __pthread_cond_type; 995 ushort __pthread_cond_magic; 996 } 997 998 ___pthread_cond_flags __pthread_cond_flags; 999 ulong __pthread_cond_data; 1000 } 1001 1002 struct pthread_condattr_t 1003 { 1004 void* __pthread_condattrp; 1005 } 1006 1007 struct pthread_rwlock_t 1008 { 1009 int __pthread_rwlock_readers; 1010 ushort __pthread_rwlock_type; 1011 ushort __pthread_rwlock_magic; 1012 pthread_mutex_t __pthread_rwlock_mutex; 1013 pthread_cond_t __pthread_rwlock_readercv; 1014 pthread_cond_t __pthread_rwlock_writercv; 1015 } 1016 1017 struct pthread_rwlockattr_t 1018 { 1019 void* __pthread_rwlockattrp; 1020 } 1021 1022 struct pthread_mutex_t 1023 { 1024 struct ___pthread_mutex_flags 1025 { 1026 ushort __pthread_mutex_flag1; 1027 ubyte __pthread_mutex_flag2; 1028 ubyte __pthread_mutex_ceiling; 1029 ushort __pthread_mutex_type; 1030 ushort __pthread_mutex_magic; 1031 } 1032 1033 ___pthread_mutex_flags __pthread_mutex_flags; 1034 1035 union ___pthread_mutex_lock 1036 { 1037 struct ___pthread_mutex_lock64 1038 { 1039 ubyte[8] __pthread_mutex_pad; 1040 } 1041 1042 ___pthread_mutex_lock64 __pthread_mutex_lock64; 1043 1044 struct ___pthread_mutex_lock32 1045 { 1046 uint __pthread_ownerpid; 1047 uint __pthread_lockword; 1048 } 1049 1050 ___pthread_mutex_lock32 __pthread_mutex_lock32; 1051 ulong __pthread_mutex_owner64; 1052 } 1053 1054 ___pthread_mutex_lock __pthread_mutex_lock; 1055 ulong __pthread_mutex_data; 1056 } 1057 1058 struct pthread_mutexattr_t 1059 { 1060 void* __pthread_mutexattrp; 1061 } 1062 1063 struct pthread_once_t 1064 { 1065 ulong[4] __pthread_once_pad; 1066 } 1067 1068 alias uint pthread_key_t; 1069 } 1070 else version (CRuntime_Bionic) 1071 { 1072 struct pthread_attr_t 1073 { 1074 uint flags; 1075 void* stack_base; 1076 size_t stack_size; 1077 size_t guard_size; 1078 int sched_policy; 1079 int sched_priority; 1080 version (D_LP64) char[16] __reserved = 0; 1081 } 1082 1083 struct pthread_cond_t 1084 { 1085 version (D_LP64) 1086 int[12] __private; 1087 else 1088 int[1] __private; 1089 } 1090 1091 alias c_long pthread_condattr_t; 1092 alias int pthread_key_t; 1093 1094 struct pthread_mutex_t 1095 { 1096 version (D_LP64) 1097 int[10] __private; 1098 else 1099 int[1] __private; 1100 } 1101 1102 alias c_long pthread_mutexattr_t; 1103 alias int pthread_once_t; 1104 1105 struct pthread_rwlock_t 1106 { 1107 version (D_LP64) 1108 int[14] __private; 1109 else 1110 int[10] __private; 1111 } 1112 1113 alias c_long pthread_rwlockattr_t; 1114 alias c_long pthread_t; 1115 } 1116 else version (CRuntime_UClibc) 1117 { 1118 version (X86_64) 1119 { 1120 enum __SIZEOF_PTHREAD_ATTR_T = 56; 1121 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 1122 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 1123 enum __SIZEOF_PTHREAD_COND_T = 48; 1124 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 1125 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 1126 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 1127 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 1128 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 1129 } 1130 else version (MIPS32) 1131 { 1132 enum __SIZEOF_PTHREAD_ATTR_T = 36; 1133 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 1134 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 1135 enum __SIZEOF_PTHREAD_COND_T = 48; 1136 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 1137 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 1138 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 1139 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 1140 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 1141 } 1142 else version (MIPS64) 1143 { 1144 enum __SIZEOF_PTHREAD_ATTR_T = 56; 1145 enum __SIZEOF_PTHREAD_MUTEX_T = 40; 1146 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 1147 enum __SIZEOF_PTHREAD_COND_T = 48; 1148 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 1149 enum __SIZEOF_PTHREAD_RWLOCK_T = 56; 1150 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 1151 enum __SIZEOF_PTHREAD_BARRIER_T = 32; 1152 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 1153 } 1154 else version (ARM) 1155 { 1156 enum __SIZEOF_PTHREAD_ATTR_T = 36; 1157 enum __SIZEOF_PTHREAD_MUTEX_T = 24; 1158 enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4; 1159 enum __SIZEOF_PTHREAD_COND_T = 48; 1160 enum __SIZEOF_PTHREAD_COND_COMPAT_T = 12; 1161 enum __SIZEOF_PTHREAD_CONDATTR_T = 4; 1162 enum __SIZEOF_PTHREAD_RWLOCK_T = 32; 1163 enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; 1164 enum __SIZEOF_PTHREAD_BARRIER_T = 20; 1165 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4; 1166 } 1167 else 1168 { 1169 static assert (false, "Architecture unsupported"); 1170 } 1171 1172 union pthread_attr_t 1173 { 1174 byte[__SIZEOF_PTHREAD_ATTR_T] __size; 1175 c_long __align; 1176 } 1177 1178 union pthread_cond_t 1179 { 1180 struct data 1181 { 1182 int __lock; 1183 uint __futex; 1184 ulong __total_seq; 1185 ulong __wakeup_seq; 1186 ulong __woken_seq; 1187 void *__mutex; 1188 uint __nwaiters; 1189 uint __broadcast_seq; 1190 } data __data; 1191 byte[__SIZEOF_PTHREAD_COND_T] __size; 1192 long __align; 1193 } 1194 1195 union pthread_condattr_t 1196 { 1197 byte[__SIZEOF_PTHREAD_CONDATTR_T] __size; 1198 c_long __align; 1199 } 1200 1201 alias uint pthread_key_t; 1202 1203 struct __pthread_slist_t 1204 { 1205 __pthread_slist_t* __next; 1206 } 1207 1208 union pthread_mutex_t 1209 { 1210 struct __pthread_mutex_s 1211 { 1212 int __lock; 1213 uint __count; 1214 int __owner; 1215 /* KIND must stay at this position in the structure to maintain 1216 binary compatibility. */ 1217 int __kind; 1218 uint __nusers; 1219 union 1220 { 1221 int __spins; 1222 __pthread_slist_t __list; 1223 } 1224 } 1225 __pthread_mutex_s __data; 1226 byte[__SIZEOF_PTHREAD_MUTEX_T] __size; 1227 c_long __align; 1228 } 1229 1230 union pthread_mutexattr_t 1231 { 1232 byte[__SIZEOF_PTHREAD_MUTEXATTR_T] __size; 1233 c_long __align; 1234 } 1235 1236 alias int pthread_once_t; 1237 1238 struct pthread_rwlock_t 1239 { 1240 struct data 1241 { 1242 int __lock; 1243 uint __nr_readers; 1244 uint __readers_wakeup; 1245 uint __writer_wakeup; 1246 uint __nr_readers_queued; 1247 uint __nr_writers_queued; 1248 version (BigEndian) 1249 { 1250 ubyte __pad1; 1251 ubyte __pad2; 1252 ubyte __shared; 1253 ubyte __flags; 1254 } 1255 else 1256 { 1257 ubyte __flags; 1258 ubyte __shared; 1259 ubyte __pad1; 1260 ubyte __pad2; 1261 } 1262 int __writer; 1263 } data __data; 1264 byte[__SIZEOF_PTHREAD_RWLOCK_T] __size; 1265 c_long __align; 1266 } 1267 1268 struct pthread_rwlockattr_t 1269 { 1270 byte[__SIZEOF_PTHREAD_RWLOCKATTR_T] __size; 1271 c_long __align; 1272 } 1273 1274 alias c_ulong pthread_t; 1275 } 1276 else 1277 { 1278 static assert(false, "Unsupported platform"); 1279 } 1280 1281 // 1282 // Barrier (BAR) 1283 // 1284 /* 1285 pthread_barrier_t 1286 pthread_barrierattr_t 1287 */ 1288 1289 version (CRuntime_Glibc) 1290 { 1291 struct pthread_barrier_t 1292 { 1293 byte[__SIZEOF_PTHREAD_BARRIER_T] __size; 1294 c_long __align; 1295 } 1296 1297 struct pthread_barrierattr_t 1298 { 1299 byte[__SIZEOF_PTHREAD_BARRIERATTR_T] __size; 1300 int __align; 1301 } 1302 } 1303 else version (FreeBSD) 1304 { 1305 alias void* pthread_barrier_t; 1306 alias void* pthread_barrierattr_t; 1307 } 1308 else version (NetBSD) 1309 { 1310 alias void* pthread_barrier_t; 1311 alias void* pthread_barrierattr_t; 1312 } 1313 else version (OpenBSD) 1314 { 1315 alias void* pthread_barrier_t; 1316 alias void* pthread_barrierattr_t; 1317 } 1318 else version (DragonFlyBSD) 1319 { 1320 alias void* pthread_barrier_t; 1321 alias void* pthread_barrierattr_t; 1322 } 1323 else version (Darwin) 1324 { 1325 } 1326 else version (Solaris) 1327 { 1328 struct pthread_barrier_t 1329 { 1330 uint __pthread_barrier_count; 1331 uint __pthread_barrier_current; 1332 ulong __pthread_barrier_cycle; 1333 ulong __pthread_barrier_reserved; 1334 pthread_mutex_t __pthread_barrier_lock; 1335 pthread_cond_t __pthread_barrier_cond; 1336 } 1337 1338 struct pthread_barrierattr_t 1339 { 1340 void* __pthread_barrierattrp; 1341 } 1342 } 1343 else version (CRuntime_Bionic) 1344 { 1345 } 1346 else version (CRuntime_Musl) 1347 { 1348 version (D_LP64) 1349 { 1350 union pthread_barrier_t 1351 { 1352 int[8] __i; 1353 void*[4] __p; 1354 } 1355 } 1356 else 1357 { 1358 union pthread_barrier_t 1359 { 1360 int[5] __i; 1361 void*[5] __p; 1362 } 1363 } 1364 1365 struct pthread_barrierattr_t 1366 { 1367 uint __attr; 1368 } 1369 } 1370 else version (CRuntime_UClibc) 1371 { 1372 struct pthread_barrier_t 1373 { 1374 byte[__SIZEOF_PTHREAD_BARRIER_T] __size; 1375 c_long __align; 1376 } 1377 1378 struct pthread_barrierattr_t 1379 { 1380 byte[__SIZEOF_PTHREAD_BARRIERATTR_T] __size; 1381 int __align; 1382 } 1383 } 1384 else 1385 { 1386 static assert(false, "Unsupported platform"); 1387 } 1388 1389 // 1390 // Spin (SPN) 1391 // 1392 /* 1393 pthread_spinlock_t 1394 */ 1395 1396 version (CRuntime_Glibc) 1397 { 1398 alias int pthread_spinlock_t; // volatile 1399 } 1400 else version (FreeBSD) 1401 { 1402 alias void* pthread_spinlock_t; 1403 } 1404 else version (NetBSD) 1405 { 1406 //already defined 1407 } 1408 else version (OpenBSD) 1409 { 1410 alias void* pthread_spinlock_t; 1411 } 1412 else version (DragonFlyBSD) 1413 { 1414 alias void* pthread_spinlock_t; 1415 } 1416 else version (Solaris) 1417 { 1418 alias pthread_mutex_t pthread_spinlock_t; 1419 } 1420 else version (CRuntime_UClibc) 1421 { 1422 alias int pthread_spinlock_t; // volatile 1423 } 1424 else version (CRuntime_Musl) 1425 { 1426 alias int pthread_spinlock_t; 1427 } 1428 1429 // 1430 // Timer (TMR) 1431 // 1432 /* 1433 clockid_t 1434 timer_t 1435 */ 1436 1437 // 1438 // Trace (TRC) 1439 // 1440 /* 1441 trace_attr_t 1442 trace_event_id_t 1443 trace_event_set_t 1444 trace_id_t 1445 */