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; // non-standard
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 version (LoongArch64)
624     {
625         enum __SIZEOF_PTHREAD_ATTR_T = 56;
626         enum __SIZEOF_PTHREAD_MUTEX_T = 40;
627         enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
628         enum __SIZEOF_PTHREAD_COND_T = 48;
629         enum __SIZEOF_PTHREAD_CONDATTR_T = 4;
630         enum __SIZEOF_PTHREAD_RWLOCK_T = 56;
631         enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
632         enum __SIZEOF_PTHREAD_BARRIER_T = 32;
633         enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
634     }
635     else
636     {
637         static assert (false, "Unsupported platform");
638     }
639 
640     union pthread_attr_t
641     {
642         byte[__SIZEOF_PTHREAD_ATTR_T] __size;
643         c_long __align;
644     }
645 
646     private alias int __atomic_lock_t;
647 
648     private struct _pthread_fastlock
649     {
650         c_long          __status;
651         __atomic_lock_t __spinlock;
652     }
653 
654     private alias void* _pthread_descr;
655 
656     union pthread_cond_t
657     {
658         byte[__SIZEOF_PTHREAD_COND_T] __size;
659         long  __align;
660     }
661 
662     union pthread_condattr_t
663     {
664         byte[__SIZEOF_PTHREAD_CONDATTR_T] __size;
665         int __align;
666     }
667 
668     alias uint pthread_key_t;
669 
670     union pthread_mutex_t
671     {
672         byte[__SIZEOF_PTHREAD_MUTEX_T] __size;
673         c_long __align;
674     }
675 
676     union pthread_mutexattr_t
677     {
678         byte[__SIZEOF_PTHREAD_MUTEXATTR_T] __size;
679         int __align;
680     }
681 
682     alias int pthread_once_t;
683 
684     struct pthread_rwlock_t
685     {
686         byte[__SIZEOF_PTHREAD_RWLOCK_T] __size;
687         c_long __align;
688     }
689 
690     struct pthread_rwlockattr_t
691     {
692         byte[__SIZEOF_PTHREAD_RWLOCKATTR_T] __size;
693         c_long __align;
694     }
695 
696     alias c_ulong pthread_t;
697 }
698 else version (CRuntime_Musl)
699 {
700     version (D_LP64)
701     {
702         union pthread_attr_t
703         {
704             int[14] __i;
705             ulong[7] __s;
706         }
707 
708         union pthread_cond_t
709         {
710             int[12] __i;
711             void*[6] __p;
712         }
713 
714         union pthread_mutex_t
715         {
716             int[10] __i;
717             void*[5] __p;
718         }
719 
720         union pthread_rwlock_t
721         {
722             int[14] __i;
723             void*[7] __p;
724         }
725     }
726     else
727     {
728         union pthread_attr_t
729         {
730             int[9] __i;
731             uint[9] __s;
732         }
733 
734         union pthread_cond_t
735         {
736             int[12] __i;
737             void*[12] __p;
738         }
739 
740         union pthread_mutex_t
741         {
742             int[6] __i;
743             void*[6] __p;
744         }
745 
746         union pthread_rwlock_t
747         {
748             int[8] __i;
749             void*[8] __p;
750         }
751     }
752 
753     struct pthread_rwlockattr_t
754     {
755         uint[2] __attr;
756     }
757 
758     alias uint pthread_key_t;
759 
760     struct pthread_condattr_t
761     {
762         uint __attr;
763     }
764 
765     struct pthread_mutexattr_t
766     {
767         uint __attr;
768     }
769 
770     alias int pthread_once_t;
771 
772     alias c_ulong pthread_t;
773 }
774 else version (Darwin)
775 {
776     version (D_LP64)
777     {
778         enum __PTHREAD_SIZE__               = 8176;
779         enum __PTHREAD_ATTR_SIZE__          = 56;
780         enum __PTHREAD_MUTEXATTR_SIZE__     = 8;
781         enum __PTHREAD_MUTEX_SIZE__         = 56;
782         enum __PTHREAD_CONDATTR_SIZE__      = 8;
783         enum __PTHREAD_COND_SIZE__          = 40;
784         enum __PTHREAD_ONCE_SIZE__          = 8;
785         enum __PTHREAD_RWLOCK_SIZE__        = 192;
786         enum __PTHREAD_RWLOCKATTR_SIZE__    = 16;
787     }
788     else
789     {
790         enum __PTHREAD_SIZE__               = 4088;
791         enum __PTHREAD_ATTR_SIZE__          = 36;
792         enum __PTHREAD_MUTEXATTR_SIZE__     = 8;
793         enum __PTHREAD_MUTEX_SIZE__         = 40;
794         enum __PTHREAD_CONDATTR_SIZE__      = 4;
795         enum __PTHREAD_COND_SIZE__          = 24;
796         enum __PTHREAD_ONCE_SIZE__          = 4;
797         enum __PTHREAD_RWLOCK_SIZE__        = 124;
798         enum __PTHREAD_RWLOCKATTR_SIZE__    = 12;
799     }
800 
801     struct pthread_handler_rec
802     {
803       void function(void*)  __routine;
804       void*                 __arg;
805       pthread_handler_rec*  __next;
806     }
807 
808     struct pthread_attr_t
809     {
810         c_long                              __sig;
811         byte[__PTHREAD_ATTR_SIZE__]         __opaque;
812     }
813 
814     struct pthread_cond_t
815     {
816         c_long                              __sig;
817         byte[__PTHREAD_COND_SIZE__]         __opaque;
818     }
819 
820     struct pthread_condattr_t
821     {
822         c_long                              __sig;
823         byte[__PTHREAD_CONDATTR_SIZE__]     __opaque;
824     }
825 
826     alias c_ulong pthread_key_t;
827 
828     struct pthread_mutex_t
829     {
830         c_long                              __sig;
831         byte[__PTHREAD_MUTEX_SIZE__]        __opaque;
832     }
833 
834     struct pthread_mutexattr_t
835     {
836         c_long                              __sig;
837         byte[__PTHREAD_MUTEXATTR_SIZE__]    __opaque;
838     }
839 
840     struct pthread_once_t
841     {
842         c_long                              __sig;
843         byte[__PTHREAD_ONCE_SIZE__]         __opaque;
844     }
845 
846     struct pthread_rwlock_t
847     {
848         c_long                              __sig;
849         byte[__PTHREAD_RWLOCK_SIZE__]       __opaque;
850     }
851 
852     struct pthread_rwlockattr_t
853     {
854         c_long                              __sig;
855         byte[__PTHREAD_RWLOCKATTR_SIZE__]   __opaque;
856     }
857 
858     private struct _opaque_pthread_t
859     {
860         c_long                  __sig;
861         pthread_handler_rec*    __cleanup_stack;
862         byte[__PTHREAD_SIZE__]  __opaque;
863     }
864 
865     alias _opaque_pthread_t* pthread_t;
866 }
867 else version (FreeBSD)
868 {
869     alias int lwpid_t; // non-standard
870 
871     alias void* pthread_attr_t;
872     alias void* pthread_cond_t;
873     alias void* pthread_condattr_t;
874     alias void* pthread_key_t;
875     alias void* pthread_mutex_t;
876     alias void* pthread_mutexattr_t;
877     alias void* pthread_once_t;
878     alias void* pthread_rwlock_t;
879     alias void* pthread_rwlockattr_t;
880     alias void* pthread_t;
881 }
882 else version (NetBSD)
883 {
884    struct pthread_queue_t {
885          void*  ptqh_first;
886          void** ptqh_last;
887    }
888 
889     alias lwpid_t = int;
890     alias pthread_spin_t = ubyte;
891     struct pthread_attr_t {
892         uint    pta_magic;
893         int     pta_flags;
894         void*   pta_private;
895     }
896     struct  pthread_spinlock_t {
897         uint    pts_magic;
898         pthread_spin_t  pts_spin;
899         int             pts_flags;
900     }
901     struct pthread_cond_t {
902         uint    ptc_magic;
903         pthread_spin_t  ptc_lock;
904         pthread_queue_t ptc_waiters;
905         pthread_mutex_t *ptc_mutex;
906         void*   ptc_private;
907     }
908     struct pthread_condattr_t {
909         uint    ptca_magic;
910         void    *ptca_private;
911     }
912     struct pthread_mutex_t {
913         uint ptm_magic;
914         pthread_spin_t  ptm_errorcheck;
915         ubyte[3]         ptm_pad1;
916         pthread_spin_t  ptm_interlock;
917         ubyte[3] ptm_pad2;
918         pthread_t ptm_owner;
919         void* ptm_waiters;
920         uint  ptm_recursed;
921         void* ptm_spare2;
922     }
923     struct pthread_mutexattr_t{
924         uint    ptma_magic;
925         void*   ptma_private;
926     }
927     struct pthread_once_t{
928         pthread_mutex_t pto_mutex;
929         int     pto_done;
930     }
931     struct pthread_rwlock_t{
932         uint    ptr_magic;
933 
934         pthread_spin_t  ptr_interlock;
935 
936         pthread_queue_t ptr_rblocked;
937         pthread_queue_t ptr_wblocked;
938         uint    ptr_nreaders;
939         pthread_t ptr_owner;
940         void    *ptr_private;
941     }
942     struct pthread_rwlockattr_t{
943         uint    ptra_magic;
944         void*   ptra_private;
945     }
946 
947     alias uint pthread_key_t;
948     alias void* pthread_t;
949 }
950 else version (OpenBSD)
951 {
952     alias void* pthread_attr_t;
953     alias void* pthread_cond_t;
954     alias void* pthread_condattr_t;
955     alias int   pthread_key_t;
956     alias void* pthread_mutex_t;
957     alias void* pthread_mutexattr_t;
958 
959     private struct pthread_once
960     {
961         int state;
962         pthread_mutex_t mutex;
963     }
964     alias pthread_once pthread_once_t;
965 
966     alias void* pthread_rwlock_t;
967     alias void* pthread_rwlockattr_t;
968     alias void* pthread_t;
969 }
970 else version (DragonFlyBSD)
971 {
972     alias int lwpid_t;
973 
974     alias void* pthread_attr_t;
975     alias void* pthread_cond_t;
976     alias void* pthread_condattr_t;
977     alias void* pthread_key_t;
978     alias void* pthread_mutex_t;
979     alias void* pthread_mutexattr_t;
980 
981     private struct pthread_once
982     {
983         int state;
984         pthread_mutex_t mutex;
985     }
986     alias pthread_once pthread_once_t;
987 
988     alias void* pthread_rwlock_t;
989     alias void* pthread_rwlockattr_t;
990     alias void* pthread_t;
991 }
992 else version (Solaris)
993 {
994     alias uint pthread_t;
995 
996     struct pthread_attr_t
997     {
998         void* __pthread_attrp;
999     }
1000 
1001     struct pthread_cond_t
1002     {
1003         struct ___pthread_cond_flags
1004         {
1005             ubyte[4] __pthread_cond_flags;
1006             ushort __pthread_cond_type;
1007             ushort __pthread_cond_magic;
1008         }
1009 
1010         ___pthread_cond_flags __pthread_cond_flags;
1011         ulong __pthread_cond_data;
1012     }
1013 
1014     struct pthread_condattr_t
1015     {
1016         void* __pthread_condattrp;
1017     }
1018 
1019     struct pthread_rwlock_t
1020     {
1021         int __pthread_rwlock_readers;
1022         ushort __pthread_rwlock_type;
1023         ushort __pthread_rwlock_magic;
1024         pthread_mutex_t __pthread_rwlock_mutex;
1025         pthread_cond_t __pthread_rwlock_readercv;
1026         pthread_cond_t __pthread_rwlock_writercv;
1027     }
1028 
1029     struct pthread_rwlockattr_t
1030     {
1031         void* __pthread_rwlockattrp;
1032     }
1033 
1034     struct pthread_mutex_t
1035     {
1036         struct ___pthread_mutex_flags
1037         {
1038             ushort __pthread_mutex_flag1;
1039             ubyte __pthread_mutex_flag2;
1040             ubyte __pthread_mutex_ceiling;
1041             ushort __pthread_mutex_type;
1042             ushort __pthread_mutex_magic;
1043         }
1044 
1045         ___pthread_mutex_flags __pthread_mutex_flags;
1046 
1047         union ___pthread_mutex_lock
1048         {
1049             struct ___pthread_mutex_lock64
1050             {
1051                 ubyte[8] __pthread_mutex_pad;
1052             }
1053 
1054             ___pthread_mutex_lock64 __pthread_mutex_lock64;
1055 
1056             struct ___pthread_mutex_lock32
1057             {
1058                 uint __pthread_ownerpid;
1059                 uint __pthread_lockword;
1060             }
1061 
1062             ___pthread_mutex_lock32 __pthread_mutex_lock32;
1063             ulong __pthread_mutex_owner64;
1064         }
1065 
1066         ___pthread_mutex_lock __pthread_mutex_lock;
1067         ulong __pthread_mutex_data;
1068     }
1069 
1070     struct pthread_mutexattr_t
1071     {
1072         void* __pthread_mutexattrp;
1073     }
1074 
1075     struct pthread_once_t
1076     {
1077         ulong[4] __pthread_once_pad;
1078     }
1079 
1080     alias uint pthread_key_t;
1081 }
1082 else version (CRuntime_Bionic)
1083 {
1084     struct pthread_attr_t
1085     {
1086         uint    flags;
1087         void*   stack_base;
1088         size_t  stack_size;
1089         size_t  guard_size;
1090         int     sched_policy;
1091         int     sched_priority;
1092         version (D_LP64) char[16] __reserved = 0;
1093     }
1094 
1095     struct pthread_cond_t
1096     {
1097         version (D_LP64)
1098             int[12] __private;
1099         else
1100             int[1] __private;
1101     }
1102 
1103     alias c_long pthread_condattr_t;
1104     alias int    pthread_key_t;
1105 
1106     struct pthread_mutex_t
1107     {
1108         version (D_LP64)
1109             int[10] __private;
1110         else
1111             int[1] __private;
1112     }
1113 
1114     alias c_long pthread_mutexattr_t;
1115     alias int    pthread_once_t;
1116 
1117     struct pthread_rwlock_t
1118     {
1119         version (D_LP64)
1120             int[14] __private;
1121         else
1122             int[10] __private;
1123     }
1124 
1125     alias c_long pthread_rwlockattr_t;
1126     alias c_long pthread_t;
1127 }
1128 else version (CRuntime_UClibc)
1129 {
1130      version (X86_64)
1131      {
1132         enum __SIZEOF_PTHREAD_ATTR_T        = 56;
1133         enum __SIZEOF_PTHREAD_MUTEX_T       = 40;
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      = 56;
1138         enum __SIZEOF_PTHREAD_RWLOCKATTR_T  = 8;
1139         enum __SIZEOF_PTHREAD_BARRIER_T     = 32;
1140         enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
1141      }
1142      else version (MIPS32)
1143      {
1144         enum __SIZEOF_PTHREAD_ATTR_T        = 36;
1145         enum __SIZEOF_PTHREAD_MUTEX_T       = 24;
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      = 32;
1150         enum __SIZEOF_PTHREAD_RWLOCKATTR_T  = 8;
1151         enum __SIZEOF_PTHREAD_BARRIER_T     = 20;
1152         enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
1153      }
1154      else version (MIPS64)
1155      {
1156         enum __SIZEOF_PTHREAD_ATTR_T        = 56;
1157         enum __SIZEOF_PTHREAD_MUTEX_T       = 40;
1158         enum __SIZEOF_PTHREAD_MUTEXATTR_T   = 4;
1159         enum __SIZEOF_PTHREAD_COND_T        = 48;
1160         enum __SIZEOF_PTHREAD_CONDATTR_T    = 4;
1161         enum __SIZEOF_PTHREAD_RWLOCK_T      = 56;
1162         enum __SIZEOF_PTHREAD_RWLOCKATTR_T  = 8;
1163         enum __SIZEOF_PTHREAD_BARRIER_T     = 32;
1164         enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
1165      }
1166      else version (ARM)
1167      {
1168         enum __SIZEOF_PTHREAD_ATTR_T = 36;
1169         enum __SIZEOF_PTHREAD_MUTEX_T = 24;
1170         enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
1171         enum __SIZEOF_PTHREAD_COND_T = 48;
1172         enum __SIZEOF_PTHREAD_COND_COMPAT_T = 12;
1173         enum __SIZEOF_PTHREAD_CONDATTR_T = 4;
1174         enum __SIZEOF_PTHREAD_RWLOCK_T = 32;
1175         enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
1176         enum __SIZEOF_PTHREAD_BARRIER_T = 20;
1177         enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
1178      }
1179      else
1180      {
1181         static assert (false, "Architecture unsupported");
1182      }
1183 
1184     union pthread_attr_t
1185     {
1186         byte[__SIZEOF_PTHREAD_ATTR_T] __size;
1187         c_long __align;
1188     }
1189 
1190     union pthread_cond_t
1191     {
1192         struct data
1193         {
1194             int __lock;
1195             uint __futex;
1196             ulong __total_seq;
1197             ulong __wakeup_seq;
1198             ulong __woken_seq;
1199             void *__mutex;
1200             uint __nwaiters;
1201             uint __broadcast_seq;
1202         } data __data;
1203         byte[__SIZEOF_PTHREAD_COND_T] __size;
1204         long  __align;
1205     }
1206 
1207     union pthread_condattr_t
1208     {
1209         byte[__SIZEOF_PTHREAD_CONDATTR_T] __size;
1210         c_long __align;
1211     }
1212 
1213     alias uint pthread_key_t;
1214 
1215     struct __pthread_slist_t
1216     {
1217       __pthread_slist_t* __next;
1218     }
1219 
1220     union pthread_mutex_t
1221     {
1222       struct __pthread_mutex_s
1223       {
1224         int __lock;
1225         uint __count;
1226         int __owner;
1227         /* KIND must stay at this position in the structure to maintain
1228            binary compatibility.  */
1229         int __kind;
1230         uint __nusers;
1231         union
1232         {
1233           int __spins;
1234           __pthread_slist_t __list;
1235         }
1236       }
1237       __pthread_mutex_s __data;
1238         byte[__SIZEOF_PTHREAD_MUTEX_T] __size;
1239         c_long __align;
1240     }
1241 
1242     union pthread_mutexattr_t
1243     {
1244         byte[__SIZEOF_PTHREAD_MUTEXATTR_T] __size;
1245         c_long __align;
1246     }
1247 
1248     alias int pthread_once_t;
1249 
1250     struct pthread_rwlock_t
1251     {
1252         struct data
1253         {
1254             int __lock;
1255             uint __nr_readers;
1256             uint __readers_wakeup;
1257             uint __writer_wakeup;
1258             uint __nr_readers_queued;
1259             uint __nr_writers_queued;
1260             version (BigEndian)
1261             {
1262                 ubyte __pad1;
1263                 ubyte __pad2;
1264                 ubyte __shared;
1265                 ubyte __flags;
1266             }
1267             else
1268             {
1269                 ubyte __flags;
1270                 ubyte __shared;
1271                 ubyte __pad1;
1272                 ubyte __pad2;
1273             }
1274             int __writer;
1275         } data __data;
1276         byte[__SIZEOF_PTHREAD_RWLOCK_T] __size;
1277         c_long __align;
1278     }
1279 
1280     struct pthread_rwlockattr_t
1281     {
1282         byte[__SIZEOF_PTHREAD_RWLOCKATTR_T] __size;
1283         c_long __align;
1284     }
1285 
1286     alias c_ulong pthread_t;
1287 }
1288 else
1289 {
1290     static assert(false, "Unsupported platform");
1291 }
1292 
1293 //
1294 // Barrier (BAR)
1295 //
1296 /*
1297 pthread_barrier_t
1298 pthread_barrierattr_t
1299 */
1300 
1301 version (CRuntime_Glibc)
1302 {
1303     struct pthread_barrier_t
1304     {
1305         byte[__SIZEOF_PTHREAD_BARRIER_T] __size;
1306         c_long __align;
1307     }
1308 
1309     struct pthread_barrierattr_t
1310     {
1311         byte[__SIZEOF_PTHREAD_BARRIERATTR_T] __size;
1312         int __align;
1313     }
1314 }
1315 else version (FreeBSD)
1316 {
1317     alias void* pthread_barrier_t;
1318     alias void* pthread_barrierattr_t;
1319 }
1320 else version (NetBSD)
1321 {
1322     alias void* pthread_barrier_t;
1323     alias void* pthread_barrierattr_t;
1324 }
1325 else version (OpenBSD)
1326 {
1327     alias void* pthread_barrier_t;
1328     alias void* pthread_barrierattr_t;
1329 }
1330 else version (DragonFlyBSD)
1331 {
1332     alias void* pthread_barrier_t;
1333     alias void* pthread_barrierattr_t;
1334 }
1335 else version (Darwin)
1336 {
1337 }
1338 else version (Solaris)
1339 {
1340     struct pthread_barrier_t
1341     {
1342         uint __pthread_barrier_count;
1343         uint __pthread_barrier_current;
1344         ulong __pthread_barrier_cycle;
1345         ulong __pthread_barrier_reserved;
1346         pthread_mutex_t __pthread_barrier_lock;
1347         pthread_cond_t __pthread_barrier_cond;
1348     }
1349 
1350     struct pthread_barrierattr_t
1351     {
1352         void* __pthread_barrierattrp;
1353     }
1354 }
1355 else version (CRuntime_Bionic)
1356 {
1357 }
1358 else version (CRuntime_Musl)
1359 {
1360     version (D_LP64)
1361     {
1362         union pthread_barrier_t
1363         {
1364             int[8] __i;
1365             void*[4] __p;
1366         }
1367     }
1368     else
1369     {
1370         union pthread_barrier_t
1371         {
1372             int[5] __i;
1373             void*[5] __p;
1374         }
1375     }
1376 
1377     struct pthread_barrierattr_t
1378     {
1379         uint __attr;
1380     }
1381 }
1382 else version (CRuntime_UClibc)
1383 {
1384     struct pthread_barrier_t
1385     {
1386         byte[__SIZEOF_PTHREAD_BARRIER_T] __size;
1387         c_long __align;
1388     }
1389 
1390     struct pthread_barrierattr_t
1391     {
1392         byte[__SIZEOF_PTHREAD_BARRIERATTR_T] __size;
1393         int __align;
1394     }
1395 }
1396 else
1397 {
1398     static assert(false, "Unsupported platform");
1399 }
1400 
1401 //
1402 // Spin (SPN)
1403 //
1404 /*
1405 pthread_spinlock_t
1406 */
1407 
1408 version (CRuntime_Glibc)
1409 {
1410     alias int pthread_spinlock_t; // volatile
1411 }
1412 else version (FreeBSD)
1413 {
1414     alias void* pthread_spinlock_t;
1415 }
1416 else version (NetBSD)
1417 {
1418     //already defined
1419 }
1420 else version (OpenBSD)
1421 {
1422     alias void* pthread_spinlock_t;
1423 }
1424 else version (DragonFlyBSD)
1425 {
1426     alias void* pthread_spinlock_t;
1427 }
1428 else version (Solaris)
1429 {
1430     alias pthread_mutex_t pthread_spinlock_t;
1431 }
1432 else version (CRuntime_UClibc)
1433 {
1434     alias int pthread_spinlock_t; // volatile
1435 }
1436 else version (CRuntime_Musl)
1437 {
1438     alias int pthread_spinlock_t;
1439 }
1440 
1441 //
1442 // Timer (TMR)
1443 //
1444 /*
1445 clockid_t
1446 timer_t
1447 */
1448 
1449 //
1450 // Trace (TRC)
1451 //
1452 /*
1453 trace_attr_t
1454 trace_event_id_t
1455 trace_event_set_t
1456 trace_id_t
1457 */