1------------------------------------------------------------------------------
2--                                                                          --
3--                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
4--                                                                          --
5--                   S Y S T E M . O S _ I N T E R F A C E                  --
6--                                                                          --
7--                                  S p e c                                 --
8--                                                                          --
9--             Copyright (C) 1991-1994, Florida State University            --
10--          Copyright (C) 1995-2014, Free Software Foundation, Inc.         --
11--                                                                          --
12-- GNAT is free software;  you can  redistribute it  and/or modify it under --
13-- terms of the  GNU General Public License as published  by the Free Soft- --
14-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
15-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
18--                                                                          --
19-- As a special exception under Section 7 of GPL version 3, you are granted --
20-- additional permissions described in the GCC Runtime Library Exception,   --
21-- version 3.1, as published by the Free Software Foundation.               --
22--                                                                          --
23-- You should have received a copy of the GNU General Public License and    --
24-- a copy of the GCC Runtime Library Exception along with this program;     --
25-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
26-- <http://www.gnu.org/licenses/>.                                          --
27--                                                                          --
28-- GNARL was developed by the GNARL team at Florida State University.       --
29-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
30--                                                                          --
31------------------------------------------------------------------------------
32
33--  This is a GNU/Linux (GNU/LinuxThreads) version of this package
34
35--  This package encapsulates all direct interfaces to OS services
36--  that are needed by the tasking run-time (libgnarl).
37
38--  PLEASE DO NOT add any with-clauses to this package or remove the pragma
39--  Preelaborate. This package is designed to be a bottom-level (leaf) package.
40
41with Ada.Unchecked_Conversion;
42with Interfaces.C;
43with System.Linux;
44with System.OS_Constants;
45
46package System.OS_Interface is
47   pragma Preelaborate;
48
49   pragma Linker_Options ("-lpthread");
50
51   subtype int            is Interfaces.C.int;
52   subtype char           is Interfaces.C.char;
53   subtype short          is Interfaces.C.short;
54   subtype long           is Interfaces.C.long;
55   subtype unsigned       is Interfaces.C.unsigned;
56   subtype unsigned_short is Interfaces.C.unsigned_short;
57   subtype unsigned_long  is Interfaces.C.unsigned_long;
58   subtype unsigned_char  is Interfaces.C.unsigned_char;
59   subtype plain_char     is Interfaces.C.plain_char;
60   subtype size_t         is Interfaces.C.size_t;
61
62   -----------
63   -- Errno --
64   -----------
65
66   function errno return int;
67   pragma Import (C, errno, "__get_errno");
68
69   EAGAIN    : constant := System.Linux.EAGAIN;
70   EINTR     : constant := System.Linux.EINTR;
71   EINVAL    : constant := System.Linux.EINVAL;
72   ENOMEM    : constant := System.Linux.ENOMEM;
73   EPERM     : constant := System.Linux.EPERM;
74   ETIMEDOUT : constant := System.Linux.ETIMEDOUT;
75
76   -------------
77   -- Signals --
78   -------------
79
80   Max_Interrupt : constant := 63;
81   type Signal is new int range 0 .. Max_Interrupt;
82   for Signal'Size use int'Size;
83
84   SIGHUP     : constant := System.Linux.SIGHUP;
85   SIGINT     : constant := System.Linux.SIGINT;
86   SIGQUIT    : constant := System.Linux.SIGQUIT;
87   SIGILL     : constant := System.Linux.SIGILL;
88   SIGTRAP    : constant := System.Linux.SIGTRAP;
89   SIGIOT     : constant := System.Linux.SIGIOT;
90   SIGABRT    : constant := System.Linux.SIGABRT;
91   SIGFPE     : constant := System.Linux.SIGFPE;
92   SIGKILL    : constant := System.Linux.SIGKILL;
93   SIGBUS     : constant := System.Linux.SIGBUS;
94   SIGSEGV    : constant := System.Linux.SIGSEGV;
95   SIGPIPE    : constant := System.Linux.SIGPIPE;
96   SIGALRM    : constant := System.Linux.SIGALRM;
97   SIGTERM    : constant := System.Linux.SIGTERM;
98   SIGUSR1    : constant := System.Linux.SIGUSR1;
99   SIGUSR2    : constant := System.Linux.SIGUSR2;
100   SIGCLD     : constant := System.Linux.SIGCLD;
101   SIGCHLD    : constant := System.Linux.SIGCHLD;
102   SIGPWR     : constant := System.Linux.SIGPWR;
103   SIGWINCH   : constant := System.Linux.SIGWINCH;
104   SIGURG     : constant := System.Linux.SIGURG;
105   SIGPOLL    : constant := System.Linux.SIGPOLL;
106   SIGIO      : constant := System.Linux.SIGIO;
107   SIGLOST    : constant := System.Linux.SIGLOST;
108   SIGSTOP    : constant := System.Linux.SIGSTOP;
109   SIGTSTP    : constant := System.Linux.SIGTSTP;
110   SIGCONT    : constant := System.Linux.SIGCONT;
111   SIGTTIN    : constant := System.Linux.SIGTTIN;
112   SIGTTOU    : constant := System.Linux.SIGTTOU;
113   SIGVTALRM  : constant := System.Linux.SIGVTALRM;
114   SIGPROF    : constant := System.Linux.SIGPROF;
115   SIGXCPU    : constant := System.Linux.SIGXCPU;
116   SIGXFSZ    : constant := System.Linux.SIGXFSZ;
117   SIGUNUSED  : constant := System.Linux.SIGUNUSED;
118   SIGSTKFLT  : constant := System.Linux.SIGSTKFLT;
119   SIGLTHRRES : constant := System.Linux.SIGLTHRRES;
120   SIGLTHRCAN : constant := System.Linux.SIGLTHRCAN;
121   SIGLTHRDBG : constant := System.Linux.SIGLTHRDBG;
122
123   SIGADAABORT : constant := SIGABRT;
124   --  Change this to use another signal for task abort. SIGTERM might be a
125   --  good one.
126
127   type Signal_Set is array (Natural range <>) of Signal;
128
129   Unmasked : constant Signal_Set := (
130      SIGTRAP,
131      --  To enable debugging on multithreaded applications, mark SIGTRAP to
132      --  be kept unmasked.
133
134      SIGBUS,
135
136      SIGTTIN, SIGTTOU, SIGTSTP,
137      --  Keep these three signals unmasked so that background processes and IO
138      --  behaves as normal "C" applications
139
140      SIGPROF,
141      --  To avoid confusing the profiler
142
143      SIGKILL, SIGSTOP,
144      --  These two signals actually can't be masked (POSIX won't allow it)
145
146      SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
147      --  These three signals are used by GNU/LinuxThreads starting from glibc
148      --  2.1 (future 2.2).
149
150   Reserved : constant Signal_Set := (SIGVTALRM, SIGUNUSED);
151   --  Not clear why these two signals are reserved. Perhaps they are not
152   --  supported by this version of GNU/Linux ???
153
154   type sigset_t is private;
155
156   function sigaddset (set : access sigset_t; sig : Signal) return int;
157   pragma Import (C, sigaddset, "sigaddset");
158
159   function sigdelset (set : access sigset_t; sig : Signal) return int;
160   pragma Import (C, sigdelset, "sigdelset");
161
162   function sigfillset (set : access sigset_t) return int;
163   pragma Import (C, sigfillset, "sigfillset");
164
165   function sigismember (set : access sigset_t; sig : Signal) return int;
166   pragma Import (C, sigismember, "sigismember");
167
168   function sigemptyset (set : access sigset_t) return int;
169   pragma Import (C, sigemptyset, "sigemptyset");
170
171   type union_type_3 is new String (1 .. 116);
172   type siginfo_t is record
173      si_signo : int;
174      si_code  : int;
175      si_errno : int;
176      X_data   : union_type_3;
177   end record;
178   pragma Convention (C, siginfo_t);
179
180   type struct_sigaction is record
181      sa_handler  : System.Address;
182      sa_mask     : sigset_t;
183      sa_flags    : Interfaces.C.unsigned_long;
184      sa_restorer : System.Address;
185   end record;
186   pragma Convention (C, struct_sigaction);
187
188   type struct_sigaction_ptr is access all struct_sigaction;
189
190   type Machine_State is record
191      eip : unsigned_long;
192      ebx : unsigned_long;
193      esp : unsigned_long;
194      ebp : unsigned_long;
195      esi : unsigned_long;
196      edi : unsigned_long;
197   end record;
198   type Machine_State_Ptr is access all Machine_State;
199
200   SA_SIGINFO : constant := System.Linux.SA_SIGINFO;
201   SA_ONSTACK : constant := System.Linux.SA_ONSTACK;
202
203   SIG_BLOCK   : constant := 0;
204   SIG_UNBLOCK : constant := 1;
205   SIG_SETMASK : constant := 2;
206
207   SIG_DFL : constant := 0;
208   SIG_IGN : constant := 1;
209
210   function sigaction
211     (sig  : Signal;
212      act  : struct_sigaction_ptr;
213      oact : struct_sigaction_ptr) return int;
214   pragma Import (C, sigaction, "sigaction");
215
216   ----------
217   -- Time --
218   ----------
219
220   subtype time_t   is System.Linux.time_t;
221   subtype timespec is System.Linux.timespec;
222   subtype timeval  is System.Linux.timeval;
223
224   function To_Duration (TS : timespec) return Duration;
225   pragma Inline (To_Duration);
226
227   function To_Timespec (D : Duration) return timespec;
228   pragma Inline (To_Timespec);
229
230   function sysconf (name : int) return long;
231   pragma Import (C, sysconf);
232
233   SC_CLK_TCK          : constant := 2;
234   SC_NPROCESSORS_ONLN : constant := 84;
235
236   -------------------------
237   -- Priority Scheduling --
238   -------------------------
239
240   SCHED_OTHER : constant := 0;
241   SCHED_FIFO  : constant := 1;
242   SCHED_RR    : constant := 2;
243
244   function To_Target_Priority
245     (Prio : System.Any_Priority) return Interfaces.C.int;
246   --  Maps System.Any_Priority to a POSIX priority
247
248   -------------
249   -- Process --
250   -------------
251
252   type pid_t is private;
253
254   function kill (pid : pid_t; sig : Signal) return int;
255   pragma Import (C, kill, "kill");
256
257   function getpid return pid_t;
258   pragma Import (C, getpid, "getpid");
259
260   PR_SET_NAME : constant := 15;
261
262   function prctl
263     (option                 : int;
264      arg2, arg3, arg4, arg5 : unsigned_long := 0) return int;
265   pragma Import (C, prctl);
266
267   -------------
268   -- Threads --
269   -------------
270
271   type Thread_Body is access
272     function (arg : System.Address) return System.Address;
273   pragma Convention (C, Thread_Body);
274
275   function Thread_Body_Access is new
276     Ada.Unchecked_Conversion (System.Address, Thread_Body);
277
278   type pthread_t is new unsigned_long;
279   subtype Thread_Id is pthread_t;
280
281   function To_pthread_t is
282     new Ada.Unchecked_Conversion (unsigned_long, pthread_t);
283
284   type pthread_mutex_t      is limited private;
285   type pthread_rwlock_t     is limited private;
286   type pthread_cond_t       is limited private;
287   type pthread_attr_t       is limited private;
288   type pthread_mutexattr_t  is limited private;
289   type pthread_rwlockattr_t is limited private;
290   type pthread_condattr_t   is limited private;
291   type pthread_key_t        is private;
292
293   PTHREAD_CREATE_DETACHED : constant := 1;
294
295   -----------
296   -- Stack --
297   -----------
298
299   type stack_t is record
300      ss_sp    : System.Address;
301      ss_flags : int;
302      ss_size  : size_t;
303   end record;
304   pragma Convention (C, stack_t);
305
306   function sigaltstack
307     (ss  : not null access stack_t;
308      oss : access stack_t) return int;
309   pragma Import (C, sigaltstack, "sigaltstack");
310
311   Alternate_Stack : aliased System.Address;
312   pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
313   --  The alternate signal stack for stack overflows
314
315   Alternate_Stack_Size : constant := 16 * 1024;
316   --  This must be in keeping with init.c:__gnat_alternate_stack
317
318   function Get_Stack_Base (thread : pthread_t) return Address;
319   pragma Inline (Get_Stack_Base);
320   --  This is a dummy procedure to share some GNULLI files
321
322   ---------------------------------------
323   -- Nonstandard Thread Initialization --
324   ---------------------------------------
325
326   procedure pthread_init;
327   pragma Inline (pthread_init);
328   --  This is a dummy procedure to share some GNULLI files
329
330   -------------------------
331   -- POSIX.1c  Section 3 --
332   -------------------------
333
334   function sigwait (set : access sigset_t; sig : access Signal) return int;
335   pragma Import (C, sigwait, "sigwait");
336
337   function pthread_kill (thread : pthread_t; sig : Signal) return int;
338   pragma Import (C, pthread_kill, "pthread_kill");
339
340   function pthread_sigmask
341     (how  : int;
342      set  : access sigset_t;
343      oset : access sigset_t) return int;
344   pragma Import (C, pthread_sigmask, "pthread_sigmask");
345
346   --------------------------
347   -- POSIX.1c  Section 11 --
348   --------------------------
349
350   function pthread_mutexattr_init
351     (attr : access pthread_mutexattr_t) return int;
352   pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
353
354   function pthread_mutexattr_destroy
355     (attr : access pthread_mutexattr_t) return int;
356   pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
357
358   function pthread_mutex_init
359     (mutex : access pthread_mutex_t;
360      attr  : access pthread_mutexattr_t) return int;
361   pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
362
363   function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
364   pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
365
366   function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
367   pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
368
369   function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
370   pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
371
372   function pthread_rwlockattr_init
373     (attr : access pthread_rwlockattr_t) return int;
374   pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init");
375
376   function pthread_rwlockattr_destroy
377     (attr : access pthread_rwlockattr_t) return int;
378   pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy");
379
380   PTHREAD_RWLOCK_PREFER_READER_NP              : constant := 0;
381   PTHREAD_RWLOCK_PREFER_WRITER_NP              : constant := 1;
382   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2;
383
384   function pthread_rwlockattr_setkind_np
385     (attr : access pthread_rwlockattr_t;
386      pref : int) return int;
387   pragma Import
388     (C, pthread_rwlockattr_setkind_np, "pthread_rwlockattr_setkind_np");
389
390   function pthread_rwlock_init
391     (mutex : access pthread_rwlock_t;
392      attr  : access pthread_rwlockattr_t) return int;
393   pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init");
394
395   function pthread_rwlock_destroy
396     (mutex : access pthread_rwlock_t) return int;
397   pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy");
398
399   function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int;
400   pragma Import (C, pthread_rwlock_rdlock, "pthread_rwlock_rdlock");
401
402   function pthread_rwlock_wrlock (mutex : access pthread_rwlock_t) return int;
403   pragma Import (C, pthread_rwlock_wrlock, "pthread_rwlock_wrlock");
404
405   function pthread_rwlock_unlock (mutex : access pthread_rwlock_t) return int;
406   pragma Import (C, pthread_rwlock_unlock, "pthread_rwlock_unlock");
407
408   function pthread_condattr_init
409     (attr : access pthread_condattr_t) return int;
410   pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
411
412   function pthread_condattr_destroy
413     (attr : access pthread_condattr_t) return int;
414   pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
415
416   function pthread_cond_init
417     (cond : access pthread_cond_t;
418      attr : access pthread_condattr_t) return int;
419   pragma Import (C, pthread_cond_init, "pthread_cond_init");
420
421   function pthread_cond_destroy (cond : access pthread_cond_t) return int;
422   pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
423
424   function pthread_cond_signal (cond : access pthread_cond_t) return int;
425   pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
426
427   function pthread_cond_wait
428     (cond  : access pthread_cond_t;
429      mutex : access pthread_mutex_t) return int;
430   pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
431
432   function pthread_cond_timedwait
433     (cond    : access pthread_cond_t;
434      mutex   : access pthread_mutex_t;
435      abstime : access timespec) return int;
436   pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
437
438   --------------------------
439   -- POSIX.1c  Section 13 --
440   --------------------------
441
442   type struct_sched_param is record
443      sched_priority : int;  --  scheduling priority
444   end record;
445   pragma Convention (C, struct_sched_param);
446
447   function pthread_setschedparam
448     (thread : pthread_t;
449      policy : int;
450      param  : access struct_sched_param) return int;
451   pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
452
453   function pthread_attr_setschedpolicy
454     (attr   : access pthread_attr_t;
455      policy : int) return int;
456   pragma Import
457     (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
458
459   function sched_yield return int;
460   pragma Import (C, sched_yield, "sched_yield");
461
462   ---------------------------
463   -- P1003.1c - Section 16 --
464   ---------------------------
465
466   function pthread_attr_init
467     (attributes : access pthread_attr_t) return int;
468   pragma Import (C, pthread_attr_init, "pthread_attr_init");
469
470   function pthread_attr_destroy
471     (attributes : access pthread_attr_t) return int;
472   pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
473
474   function pthread_attr_setdetachstate
475     (attr        : access pthread_attr_t;
476      detachstate : int) return int;
477   pragma Import
478     (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
479
480   function pthread_attr_setstacksize
481     (attr      : access pthread_attr_t;
482      stacksize : size_t) return int;
483   pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
484
485   function pthread_create
486     (thread        : access pthread_t;
487      attributes    : access pthread_attr_t;
488      start_routine : Thread_Body;
489      arg           : System.Address) return int;
490   pragma Import (C, pthread_create, "pthread_create");
491
492   procedure pthread_exit (status : System.Address);
493   pragma Import (C, pthread_exit, "pthread_exit");
494
495   function pthread_self return pthread_t;
496   pragma Import (C, pthread_self, "pthread_self");
497
498   function lwp_self return System.Address;
499   pragma Import (C, lwp_self, "__gnat_lwp_self");
500
501   --------------------------
502   -- POSIX.1c  Section 17 --
503   --------------------------
504
505   function pthread_setspecific
506     (key   : pthread_key_t;
507      value : System.Address) return int;
508   pragma Import (C, pthread_setspecific, "pthread_setspecific");
509
510   function pthread_getspecific (key : pthread_key_t) return System.Address;
511   pragma Import (C, pthread_getspecific, "pthread_getspecific");
512
513   type destructor_pointer is access procedure (arg : System.Address);
514   pragma Convention (C, destructor_pointer);
515
516   function pthread_key_create
517     (key        : access pthread_key_t;
518      destructor : destructor_pointer) return int;
519   pragma Import (C, pthread_key_create, "pthread_key_create");
520
521   CPU_SETSIZE : constant := 1_024;
522   --  Size of the cpu_set_t mask on most linux systems (SUSE 11 uses 4_096).
523   --  This is kept for backward compatibility (System.Task_Info uses it), but
524   --  the run-time library does no longer rely on static masks, using
525   --  dynamically allocated masks instead.
526
527   type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
528   for bit_field'Size use CPU_SETSIZE;
529   pragma Pack (bit_field);
530   pragma Convention (C, bit_field);
531
532   type cpu_set_t is record
533      bits : bit_field;
534   end record;
535   pragma Convention (C, cpu_set_t);
536
537   type cpu_set_t_ptr is access all cpu_set_t;
538   --  In the run-time library we use this pointer because the size of type
539   --  cpu_set_t varies depending on the glibc version. Hence, objects of type
540   --  cpu_set_t are allocated dynamically using the number of processors
541   --  available in the target machine (value obtained at execution time).
542
543   function CPU_ALLOC (count : size_t) return cpu_set_t_ptr;
544   pragma Import (C, CPU_ALLOC, "__gnat_cpu_alloc");
545   --  Wrapper around the CPU_ALLOC C macro
546
547   function CPU_ALLOC_SIZE (count : size_t) return size_t;
548   pragma Import (C, CPU_ALLOC_SIZE, "__gnat_cpu_alloc_size");
549   --  Wrapper around the CPU_ALLOC_SIZE C macro
550
551   procedure CPU_FREE (cpuset : cpu_set_t_ptr);
552   pragma Import (C, CPU_FREE, "__gnat_cpu_free");
553   --  Wrapper around the CPU_FREE C macro
554
555   procedure CPU_ZERO (count : size_t; cpuset : cpu_set_t_ptr);
556   pragma Import (C, CPU_ZERO, "__gnat_cpu_zero");
557   --  Wrapper around the CPU_ZERO_S C macro
558
559   procedure CPU_SET (cpu : int; count : size_t; cpuset : cpu_set_t_ptr);
560   pragma Import (C, CPU_SET, "__gnat_cpu_set");
561   --  Wrapper around the CPU_SET_S C macro
562
563   function pthread_setaffinity_np
564     (thread     : pthread_t;
565      cpusetsize : size_t;
566      cpuset     : cpu_set_t_ptr) return int;
567   pragma Import (C, pthread_setaffinity_np, "pthread_setaffinity_np");
568   pragma Weak_External (pthread_setaffinity_np);
569   --  Use a weak symbol because this function may be available or not,
570   --  depending on the version of the system.
571
572   function pthread_attr_setaffinity_np
573     (attr       : access pthread_attr_t;
574      cpusetsize : size_t;
575      cpuset     : cpu_set_t_ptr) return int;
576   pragma Import (C, pthread_attr_setaffinity_np,
577                    "pthread_attr_setaffinity_np");
578   pragma Weak_External (pthread_attr_setaffinity_np);
579   --  Use a weak symbol because this function may be available or not,
580   --  depending on the version of the system.
581
582private
583
584   type sigset_t is
585     array (0 .. OS_Constants.SIZEOF_sigset - 1) of unsigned_char;
586   pragma Convention (C, sigset_t);
587   for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment;
588
589   pragma Warnings (Off);
590   for struct_sigaction use record
591      sa_handler at Linux.sa_handler_pos range 0 .. Standard'Address_Size - 1;
592      sa_mask    at Linux.sa_mask_pos    range 0 .. 1023;
593      sa_flags   at Linux.sa_flags_pos
594        range 0 .. Interfaces.C.unsigned_long'Size - 1;
595   end record;
596   --  We intentionally leave sa_restorer unspecified and let the compiler
597   --  append it after the last field, so disable corresponding warning.
598   pragma Warnings (On);
599
600   type pid_t is new int;
601
602   type unsigned_long_long_t is mod 2 ** 64;
603   --  Local type only used to get the alignment of this type below
604
605   subtype char_array is Interfaces.C.char_array;
606
607   type pthread_attr_t is record
608      Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE);
609   end record;
610   pragma Convention (C, pthread_attr_t);
611   for pthread_attr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
612
613   type pthread_condattr_t is record
614      Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE);
615   end record;
616   pragma Convention (C, pthread_condattr_t);
617   for pthread_condattr_t'Alignment use Interfaces.C.int'Alignment;
618
619   type pthread_mutexattr_t is record
620      Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE);
621   end  record;
622   pragma Convention (C, pthread_mutexattr_t);
623   for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment;
624
625   type pthread_mutex_t is record
626      Data : char_array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE);
627   end record;
628   pragma Convention (C, pthread_mutex_t);
629   for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment;
630
631   type pthread_rwlockattr_t is record
632      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
633   end record;
634   pragma Convention (C, pthread_rwlockattr_t);
635   for pthread_rwlockattr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
636
637   type pthread_rwlock_t is record
638      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCK_SIZE);
639   end record;
640   pragma Convention (C, pthread_rwlock_t);
641   for pthread_rwlock_t'Alignment use Interfaces.C.unsigned_long'Alignment;
642
643   type pthread_cond_t is record
644      Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE);
645   end record;
646   pragma Convention (C, pthread_cond_t);
647   for pthread_cond_t'Alignment use unsigned_long_long_t'Alignment;
648
649   type pthread_key_t is new unsigned;
650
651end System.OS_Interface;
652