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