1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 module tango.stdc.posix.sys.types;
10 
11 private import tango.stdc.posix.config;
12 private import tango.stdc.stdint;
13 public import tango.stdc.stddef; // for size_t
14 public import tango.stdc.time;   // for clock_t, time_t
15 
16 extern (C):
17 
18 //
19 // Required
20 //
21 /*
22 blkcnt_t
23 blksize_t
24 dev_t
25 gid_t
26 ino_t
27 mode_t
28 nlink_t
29 off_t
30 pid_t
31 size_t
32 ssize_t
33 time_t
34 uid_t
35 */
36 
37 version( linux )
38 {
39     alias c_ulong   ino_t;
40     static if( __USE_LARGEFILE64 )
41     {
42       alias long      off_t;      // actually C header's off64_t in this mode
43       alias long      blkcnt_t;   // actually C header's blkcnt64_t in this mode
44       alias ulong     ino64_t;
45       alias ino64_t   inol_t;
46     }
47     else
48     {
49       alias c_long    off_t;
50       alias c_long    blkcnt_t;
51       alias ino_t   inol_t;
52     }
53     alias ulong     dev_t;
54     alias uint      mode_t;
55     alias c_ulong   nlink_t;
56     alias uint      uid_t;
57     alias uint      gid_t;
58     alias c_long    blksize_t;
59     alias int       pid_t;
60     //size_t (defined in tango.stdc.stddef)
61     alias ptrdiff_t ssize_t;
62     //time_t (defined in tango.stdc.time)
63 }
64 else version( darwin )
65 {
66     alias long      blkcnt_t;
67     alias int       blksize_t;
68     alias int       dev_t;
69     alias uint      gid_t;
70     alias uint      ino_t;
71     alias ino_t     inol_t;
72     alias ushort    mode_t;
73     alias ushort    nlink_t;
74     alias long      off_t;
75     alias int       pid_t;
76     //size_t (defined in tango.stdc.stddef)
77     alias ptrdiff_t  ssize_t;
78     //time_t (defined in tango.stdc.time)
79     alias uint      uid_t;
80 }
81 else version( FreeBSD )
82 {
83     alias long      blkcnt_t;
84     alias uint      blksize_t;
85     alias uint      dev_t;
86     alias uint      gid_t;
87     alias uint      ino_t;
88     alias ino_t     inol_t;
89     alias ushort    mode_t;
90     alias ushort    nlink_t;
91     alias long      off_t;
92     alias int       pid_t;
93     //size_t (defined in tango.stdc.stddef)
94     alias ptrdiff_t ssize_t;
95     //time_t (defined in tango.stdc.time)
96     alias uint      uid_t;
97     alias uint      fflags_t;
98 }
99 else version( solaris )
100 {
101     alias c_ulong   ino_t;
102     static if( __USE_LARGEFILE64 )
103     {
104       alias long      off_t;
105       alias long      blkcnt_t;
106       alias ulong     ino64_t;
107       alias ino64_t   inol_t;
108     }
109     else
110     {
111       alias c_long    off_t;
112       alias c_long    blkcnt_t;
113       alias ino_t     inol_t;
114     }
115     alias int       blksize_t;
116     alias c_ulong   dev_t;
117     alias uint      mode_t;
118     alias uint      nlink_t;
119     alias uint      uid_t;
120     alias uint      gid_t;
121     alias int       pid_t;
122     //size_t (defined in tango.stdc.stddef)
123     alias ptrdiff_t ssize_t;
124     //time_t (defined in tango.stdc.time)
125 
126 
127     alias char*     caddr_t;    /* ?<core address> type */
128     alias c_long    daddr_t;    /* <disk address> type */
129     alias short     cnt_t;      /* ?<count> type */
130 }
131 //
132 // XOpen (XSI)
133 //
134 /*
135 clock_t
136 fsblkcnt_t
137 fsfilcnt_t
138 id_t
139 key_t
140 suseconds_t
141 useconds_t
142 */
143 
144 version( linux )
145 {
146   static if( __USE_LARGEFILE64 )
147   {
148     alias ulong     fsblkcnt_t;
149     alias ulong     fsfilcnt_t;
150   }
151   else
152   {
153     alias c_ulong   fsblkcnt_t;
154     alias c_ulong   fsfilcnt_t;
155   }
156     // clock_t (defined in tango.stdc.time)
157     alias uint      id_t;
158     alias int       key_t;
159     alias c_long    suseconds_t;
160     alias uint      useconds_t;
161 }
162 else version( darwin )
163 {
164     //clock_t
165     alias uint  fsblkcnt_t;
166     alias uint  fsfilcnt_t;
167     alias uint  id_t;
168     // key_t
169     alias int   suseconds_t;
170     alias uint  useconds_t;
171 }
172 else version( FreeBSD )
173 {
174     //clock_t
175     alias ulong     fsblkcnt_t;
176     alias ulong     fsfilcnt_t;
177     alias long      id_t;
178     alias c_long    key_t;
179     alias c_long    suseconds_t;
180     alias uint      useconds_t;
181 }
182 else version( solaris )
183 {
184   static if( __USE_LARGEFILE64 )
185   {
186     alias ulong     fsblkcnt_t;
187     alias ulong     fsfilcnt_t;
188   }
189   else
190   {
191     alias c_ulong   fsblkcnt_t;
192     alias c_ulong   fsfilcnt_t;
193   }
194     // clock_t (defined in tango.stdc.time)
195     alias int       id_t;
196     alias int       key_t;
197     alias c_long    suseconds_t;
198     alias uint      useconds_t;
199 }
200 
201 //
202 // Thread (THR)
203 //
204 /*
205 pthread_attr_t
206 pthread_cond_t
207 pthread_condattr_t
208 pthread_key_t
209 pthread_mutex_t
210 pthread_mutexattr_t
211 pthread_once_t
212 pthread_rwlock_t
213 pthread_rwlockattr_t
214 pthread_t
215 */
216 
217 version( linux )
218 {
219     private struct __sched_param
220     {
221         int __sched_priority;
222     }
223 
224     struct pthread_attr_t
225     {
226         int             __detachstate;
227         int             __schedpolicy;
228         __sched_param   __schedparam;
229         int             __inheritsched;
230         int             __scope;
231         size_t          __guardsize;
232         int             __stackaddr_set;
233         void*           __stackaddr;
234         size_t          __stacksize;
235     }
236 
237     private alias int __atomic_lock_t;
238 
239     private struct _pthread_fastlock
240     {
241         c_long          __status;
242         __atomic_lock_t __spinlock;
243     }
244 
245     private alias void* _pthread_descr;
246 
247     private alias long __pthread_cond_align_t;
248 
249     struct pthread_cond_t
250     {
251         _pthread_fastlock       __c_lock;
252         _pthread_descr          __c_waiting;
253         char[48 -
254              _pthread_fastlock.sizeof -
255              _pthread_descr.sizeof -
256              __pthread_cond_align_t.sizeof]
257                                 __padding;
258         __pthread_cond_align_t  __align;
259     }
260 
261     struct pthread_condattr_t
262     {
263         int __dummy;
264     }
265 
266     alias uint pthread_key_t;
267 
268     struct pthread_mutex_t
269     {
270         int                 __m_reserved;
271         int                 __m_count;
272         _pthread_descr      __m_owner;
273         int                 __m_kind;
274         _pthread_fastlock   __m_lock;
275     }
276 
277     struct pthread_mutexattr_t
278     {
279         int __mutexkind;
280     }
281 
282     alias int pthread_once_t;
283 
284     struct pthread_rwlock_t
285     {
286         _pthread_fastlock   __rw_lock;
287         int                 __rw_readers;
288         _pthread_descr      __rw_writer;
289         _pthread_descr      __rw_read_waiting;
290         _pthread_descr      __rw_write_waiting;
291         int                 __rw_kind;
292         int                 __rw_pshared;
293     }
294 
295     struct pthread_rwlockattr_t
296     {
297         int __lockkind;
298         int __pshared;
299     }
300 
301     alias c_ulong pthread_t;
302 }
303 else version( darwin )
304 {
305     private
306     {
307         static if ((void*).sizeof>int.sizeof)
308         {
309             // version( LP64 )
310             const __PTHREAD_SIZE__              = 1168;
311             const __PTHREAD_ATTR_SIZE__         = 56;
312             const __PTHREAD_MUTEXATTR_SIZE__    = 8;
313             const __PTHREAD_MUTEX_SIZE__        = 56;
314             const __PTHREAD_CONDATTR_SIZE__     = 8;
315             const __PTHREAD_COND_SIZE__         = 40;
316             const __PTHREAD_ONCE_SIZE__         = 8;
317             const __PTHREAD_RWLOCK_SIZE__       = 192;
318             const __PTHREAD_RWLOCKATTR_SIZE__   = 16;
319         }
320         else
321         {
322             const __PTHREAD_SIZE__              = 596;
323             const __PTHREAD_ATTR_SIZE__         = 36;
324             const __PTHREAD_MUTEXATTR_SIZE__    = 8;
325             const __PTHREAD_MUTEX_SIZE__        = 40;
326             const __PTHREAD_CONDATTR_SIZE__     = 4;
327             const __PTHREAD_COND_SIZE__         = 24;
328             const __PTHREAD_ONCE_SIZE__         = 4;
329             const __PTHREAD_RWLOCK_SIZE__       = 124;
330             const __PTHREAD_RWLOCKATTR_SIZE__   = 12;
331         }
332     }
333 
334     struct pthread_handler_rec
335     {
336       void function(void*)  __routine;
337       void*                 __arg;
338       pthread_handler_rec*  __next;
339     }
340 
341     struct pthread_attr_t
342     {
343         c_long                              __sig;
344         byte[__PTHREAD_ATTR_SIZE__]         __opaque;
345     }
346 
347     struct pthread_cond_t
348     {
349         c_long                              __sig;
350         byte[__PTHREAD_COND_SIZE__]         __opaque;
351     }
352 
353     struct pthread_condattr_t
354     {
355         c_long                              __sig;
356         byte[__PTHREAD_CONDATTR_SIZE__]     __opaque;
357     }
358 
359     alias c_ulong pthread_key_t;
360 
361     struct pthread_mutex_t
362     {
363         c_long                              __sig;
364         byte[__PTHREAD_MUTEX_SIZE__]        __opaque;
365     }
366 
367     struct pthread_mutexattr_t
368     {
369         c_long                              __sig;
370         byte[__PTHREAD_MUTEXATTR_SIZE__]    __opaque;
371     }
372 
373     struct pthread_once_t
374     {
375         c_long                              __sig;
376         byte[__PTHREAD_ONCE_SIZE__]         __opaque;
377     }
378 
379     struct pthread_rwlock_t
380     {
381         c_long                              __sig;
382         byte[__PTHREAD_RWLOCK_SIZE__]       __opaque;
383     }
384 
385     struct pthread_rwlockattr_t
386     {
387         c_long                             __sig;
388         byte[__PTHREAD_RWLOCKATTR_SIZE__]   __opaque;
389     }
390 
391     private struct _opaque_pthread_t
392     {
393         c_long                  __sig;
394         pthread_handler_rec*    __cleanup_stack;
395         byte[__PTHREAD_SIZE__]  __opaque;
396     }
397 
398     alias _opaque_pthread_t* pthread_t;
399 }
400 else version( FreeBSD )
401 {
402     alias int lwpid_t;
403 
404     alias void* pthread_attr_t;
405     alias void* pthread_cond_t;
406     alias void* pthread_condattr_t;
407     alias void* pthread_key_t;
408     alias void* pthread_mutex_t;
409     alias void* pthread_mutexattr_t;
410     alias void* pthread_once_t;
411     alias void* pthread_rwlock_t;
412     alias void* pthread_rwlockattr_t;
413     alias void* pthread_t;
414 }
415 else version( solaris )
416 {   
417     struct pthread_attr_t {
418         void* __pthread_attrp;
419     }
420     
421     struct pthread_cond_t {
422         struct __pthread_cond_flags {
423             uint8_t[4]  __pthread_cond_flag;
424             uint16_t    __pthread_cond_type;
425             uint16_t    __pthread_cond_magic;
426         }
427         private upad64_t __pthread_cond_data;
428     }
429     
430     struct pthread_condattr_t {
431         void* __pthread_condattrp;
432     }
433     
434     alias uint pthread_key_t;
435     
436     struct pthread_mutex_t {
437         struct __pthread_mutex_flags {
438             uint16_t    __pthread_mutex_flag1;
439             uint8_t     __pthread_mutex_flag2;
440             uint8_t     __pthread_mutex_ceiling;
441             uint16_t    __pthread_mutex_type;
442             uint16_t    __pthread_mutex_magic;
443         }
444         union __pthread_mutex_lock {
445             struct __pthread_mutex_lock64 {
446                 uint8_t[8] __pthread_mutex_pad;
447             }
448             struct __pthread_mutex_lock32 {
449                 uint32_t __pthread_ownerpid;
450                 uint32_t __pthread_lockword;
451             }
452             private upad64_t __pthread_mutex_owner64;
453         }
454         private upad64_t __pthread_mutex_data;
455     }
456     
457     struct pthread_mutexattr_t {
458         void* __pthread_mutexattrp;
459     }
460     
461     struct pthread_once_t {
462         private upad64_t[4] __pthread_once_pad;
463     }
464     
465     struct pthread_rwlock_t {
466         int32_t     __pthread_rwlock_readers;
467         uint16_t    __pthread_rwlock_type;
468         uint16_t    __pthread_rwlock_magic;
469         pthread_mutex_t __pthread_rwlock_mutex;
470         pthread_cond_t  __pthread_rwlock_readercv;
471         pthread_cond_t  __pthread_rwlock_writercv;
472     }
473     
474     struct pthread_rwlockattr_t {
475         void* __pthread_rwlockattrp;
476     }
477     
478     alias uint pthread_t;
479 }
480 
481 //
482 // Barrier (BAR)
483 //
484 /*
485 pthread_barrier_t
486 pthread_barrierattr_t
487 */
488 
489 version( linux )
490 {
491     struct pthread_barrier_t
492     {
493         _pthread_fastlock   __ba_lock;
494         int                 __ba_required;
495         int                 __ba_present;
496         _pthread_descr      __ba_waiting;
497     }
498 
499     struct pthread_barrierattr_t
500     {
501         int __pshared;
502     }
503 }
504 else version( darwin )
505 {
506     // NOTE: The following definitions are Tango-specific because darwin does
507     //       not support them directly.
508 
509     struct pthread_barrier_t
510     {
511         pthread_mutex_t b_lock;
512         pthread_cond_t  b_cond;
513         int             b_count;
514         int             b_waiters;
515         int             b_generation;
516     }
517 
518     struct pthread_barrierattr_t
519     {
520         int             pshared;
521     }
522 }
523 else version( FreeBSD )
524 {
525     alias void* pthread_barrier_t;
526     alias void* pthread_barrierattr_t;
527 }
528 else version ( solaris )
529 {
530     struct pthread_barrier_t {
531         uint32_t        __pthread_barrier_count;
532         uint32_t        __pthread_barrier_current;
533         upad64_t        __pthread_barrier_cycle;
534         upad64_t        __pthread_barrier_reserved;
535         pthread_mutex_t __pthread_barrier_lock;
536         pthread_cond_t  __pthread_barrier_cond;
537     }
538     
539     struct pthread_barrierattr_t {
540         void* __pthread_barrierattrp;
541     }
542 }
543 
544 //
545 // Spin (SPN)
546 //
547 /*
548 pthread_spinlock_t
549 */
550 
551 version( linux )
552 {
553     alias int pthread_spinlock_t; // volatile
554 }
555 else version( darwin )
556 {
557     version (LDC)
558         alias void* pthread_spinlock_t;
559         
560     else
561         struct pthread_spinlock_t;
562 }
563 else version( FreeBSD )
564 {
565     alias void* pthread_spinlock_t;
566 }
567 else version ( solaris )
568 {
569     alias pthread_mutex_t pthread_spinlock_t;
570 }
571 
572 //
573 // Timer (TMR)
574 //
575 /*
576 clockid_t
577 timer_t
578 */
579 
580 //
581 // Trace (TRC)
582 //
583 /*
584 trace_attr_t
585 trace_event_id_t
586 trace_event_set_t
587 trace_id_t
588 */