OSDN Git Service

2007-12-06 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-aix.ads
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-2007, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNARL 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 2,  or (at your option) any later ver- --
15 -- sion. GNARL 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.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
20 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
21 -- Boston, MA 02110-1301, USA.                                              --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNARL was developed by the GNARL team at Florida State University.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a AIX (Native THREADS) version of this package
36
37 --  This package encapsulates all direct interfaces to OS services that are
38 --  needed by children of System.
39
40 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
42
43 with Interfaces.C;
44 with Ada.Unchecked_Conversion;
45
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-pthread");
50    --  This implies -lpthreads + other things depending on the GCC
51    --  configuration, such as the selection of a proper libgcc variant
52    --  for table-based exception handling when it is available.
53
54    pragma Linker_Options ("-lc_r");
55
56    subtype int            is Interfaces.C.int;
57    subtype short          is Interfaces.C.short;
58    subtype long           is Interfaces.C.long;
59    subtype unsigned       is Interfaces.C.unsigned;
60    subtype unsigned_short is Interfaces.C.unsigned_short;
61    subtype unsigned_long  is Interfaces.C.unsigned_long;
62    subtype unsigned_char  is Interfaces.C.unsigned_char;
63    subtype plain_char     is Interfaces.C.plain_char;
64    subtype size_t         is Interfaces.C.size_t;
65
66    -----------
67    -- Errno --
68    -----------
69
70    function errno return int;
71    pragma Import (C, errno, "__get_errno");
72
73    EAGAIN    : constant := 11;
74    EINTR     : constant := 4;
75    EINVAL    : constant := 22;
76    ENOMEM    : constant := 12;
77    ETIMEDOUT : constant := 78;
78
79    -------------
80    -- Signals --
81    -------------
82
83    Max_Interrupt : constant := 63;
84    type Signal is new int range 0 .. Max_Interrupt;
85    for Signal'Size use int'Size;
86
87    SIGHUP      : constant := 1; --  hangup
88    SIGINT      : constant := 2; --  interrupt (rubout)
89    SIGQUIT     : constant := 3; --  quit (ASCD FS)
90    SIGILL      : constant := 4; --  illegal instruction (not reset)
91    SIGTRAP     : constant := 5; --  trace trap (not reset)
92    SIGIOT      : constant := 6; --  IOT instruction
93    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
94    SIGEMT      : constant := 7; --  EMT instruction
95    SIGFPE      : constant := 8; --  floating point exception
96    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
97    SIGBUS      : constant := 10; --  bus error
98    SIGSEGV     : constant := 11; --  segmentation violation
99    SIGSYS      : constant := 12; --  bad argument to system call
100    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
101    SIGALRM     : constant := 14; --  alarm clock
102    SIGTERM     : constant := 15; --  software termination signal from kill
103    SIGUSR1     : constant := 30; --  user defined signal 1
104    SIGUSR2     : constant := 31; --  user defined signal 2
105    SIGCLD      : constant := 20; --  alias for SIGCHLD
106    SIGCHLD     : constant := 20; --  child status change
107    SIGPWR      : constant := 29; --  power-fail restart
108    SIGWINCH    : constant := 28; --  window size change
109    SIGURG      : constant := 16; --  urgent condition on IO channel
110    SIGPOLL     : constant := 23; --  pollable event occurred
111    SIGIO       : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
112    SIGSTOP     : constant := 17; --  stop (cannot be caught or ignored)
113    SIGTSTP     : constant := 18; --  user stop requested from tty
114    SIGCONT     : constant := 19; --  stopped process has been continued
115    SIGTTIN     : constant := 21; --  background tty read attempted
116    SIGTTOU     : constant := 22; --  background tty write attempted
117    SIGVTALRM   : constant := 34; --  virtual timer expired
118    SIGPROF     : constant := 32; --  profiling timer expired
119    SIGXCPU     : constant := 24; --  CPU time limit exceeded
120    SIGXFSZ     : constant := 25; --  filesize limit exceeded
121    SIGWAITING  : constant := 39; --  m:n scheduling
122
123    --  The following signals are AIX specific
124
125    SIGMSG      : constant := 27; -- input data is in the ring buffer
126    SIGDANGER   : constant := 33; -- system crash imminent
127    SIGMIGRATE  : constant := 35; -- migrate process
128    SIGPRE      : constant := 36; -- programming exception
129    SIGVIRT     : constant := 37; -- AIX virtual time alarm
130    SIGALRM1    : constant := 38; -- m:n condition variables
131    SIGCPUFAIL  : constant := 59; -- Predictive De-configuration of Processors
132    SIGKAP      : constant := 60; -- keep alive poll from native keyboard
133    SIGGRANT    : constant := SIGKAP; -- monitor mode granted
134    SIGRETRACT  : constant := 61; -- monitor mode should be relinguished
135    SIGSOUND    : constant := 62; -- sound control has completed
136    SIGSAK      : constant := 63; -- secure attention key
137
138    SIGADAABORT : constant := SIGEMT;
139    --  Note: on other targets, we usually use SIGABRT, but on AIX, it appears
140    --  that SIGABRT can't be used in sigwait(), so we use SIGEMT.
141    --  SIGEMT is "Emulator Trap Instruction" from the PDP-11, and does not
142    --  have a standardized usage.
143
144    type Signal_Set is array (Natural range <>) of Signal;
145
146    Unmasked : constant Signal_Set :=
147                 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
148    Reserved : constant Signal_Set :=
149                 (SIGABRT, SIGKILL, SIGSTOP, SIGALRM1, SIGWAITING, SIGCPUFAIL);
150
151    type sigset_t is private;
152
153    function sigaddset (set : access sigset_t; sig : Signal) return int;
154    pragma Import (C, sigaddset, "sigaddset");
155
156    function sigdelset (set : access sigset_t; sig : Signal) return int;
157    pragma Import (C, sigdelset, "sigdelset");
158
159    function sigfillset (set : access sigset_t) return int;
160    pragma Import (C, sigfillset, "sigfillset");
161
162    function sigismember (set : access sigset_t; sig : Signal) return int;
163    pragma Import (C, sigismember, "sigismember");
164
165    function sigemptyset (set : access sigset_t) return int;
166    pragma Import (C, sigemptyset, "sigemptyset");
167
168    type struct_sigaction is record
169       sa_handler : System.Address;
170       sa_mask    : sigset_t;
171       sa_flags   : int;
172    end record;
173    pragma Convention (C, struct_sigaction);
174    type struct_sigaction_ptr is access all struct_sigaction;
175
176    SA_SIGINFO  : constant := 16#0100#;
177
178    SIG_BLOCK   : constant := 0;
179    SIG_UNBLOCK : constant := 1;
180    SIG_SETMASK : constant := 2;
181
182    SIG_DFL : constant := 0;
183    SIG_IGN : constant := 1;
184
185    function sigaction
186      (sig  : Signal;
187       act  : struct_sigaction_ptr;
188       oact : struct_sigaction_ptr) return int;
189    pragma Import (C, sigaction, "sigaction");
190
191    ----------
192    -- Time --
193    ----------
194
195    Time_Slice_Supported : constant Boolean := True;
196    --  Indicates whether time slicing is supported
197
198    type timespec is private;
199
200    type clockid_t is private;
201
202    CLOCK_REALTIME : constant clockid_t;
203
204    function clock_gettime
205      (clock_id : clockid_t;
206       tp       : access timespec) return int;
207    --  AIX threads don't have clock_gettime, so use gettimeofday() instead
208
209    function To_Duration (TS : timespec) return Duration;
210    pragma Inline (To_Duration);
211
212    function To_Timespec (D : Duration) return timespec;
213    pragma Inline (To_Timespec);
214
215    type struct_timezone is record
216       tz_minuteswest : int;
217       tz_dsttime     : int;
218    end record;
219    pragma Convention (C, struct_timezone);
220    type struct_timezone_ptr is access all struct_timezone;
221
222    type struct_timeval is private;
223    --  This is needed on systems that do not have clock_gettime() but do have
224    --  gettimeofday().
225
226    function To_Duration (TV : struct_timeval) return Duration;
227    pragma Inline (To_Duration);
228
229    function To_Timeval (D : Duration) return struct_timeval;
230    pragma Inline (To_Timeval);
231
232    -------------------------
233    -- Priority Scheduling --
234    -------------------------
235
236    SCHED_FIFO  : constant := 1;
237    SCHED_RR    : constant := 2;
238    SCHED_OTHER : constant := 0;
239
240    function To_Target_Priority
241      (Prio : System.Any_Priority) return Interfaces.C.int;
242    --  Maps System.Any_Priority to a POSIX priority
243
244    -------------
245    -- Process --
246    -------------
247
248    type pid_t is private;
249
250    function kill (pid : pid_t; sig : Signal) return int;
251    pragma Import (C, kill, "kill");
252
253    function getpid return pid_t;
254    pragma Import (C, getpid, "getpid");
255
256    ---------
257    -- LWP --
258    ---------
259
260    function lwp_self return System.Address;
261    pragma Import (C, lwp_self, "thread_self");
262
263    -------------
264    -- Threads --
265    -------------
266
267    type Thread_Body is access
268      function (arg : System.Address) return System.Address;
269    pragma Convention (C, Thread_Body);
270
271    function Thread_Body_Access is new
272      Ada.Unchecked_Conversion (System.Address, Thread_Body);
273
274    type pthread_t           is private;
275    subtype Thread_Id        is pthread_t;
276
277    type pthread_mutex_t     is limited private;
278    type pthread_cond_t      is limited private;
279    type pthread_attr_t      is limited private;
280    type pthread_mutexattr_t is limited private;
281    type pthread_condattr_t  is limited private;
282    type pthread_key_t       is private;
283
284    PTHREAD_CREATE_DETACHED : constant := 1;
285
286    PTHREAD_SCOPE_PROCESS : constant := 1;
287    PTHREAD_SCOPE_SYSTEM  : constant := 0;
288
289    -----------
290    -- Stack --
291    -----------
292
293    Stack_Base_Available : constant Boolean := False;
294    --  Indicates wether the stack base is available on this target
295
296    function Get_Stack_Base (thread : pthread_t) return Address;
297    pragma Inline (Get_Stack_Base);
298    --  Returns the stack base of the specified thread. Only call this function
299    --  when Stack_Base_Available is True.
300
301    function Get_Page_Size return size_t;
302    function Get_Page_Size return Address;
303    pragma Import (C, Get_Page_Size, "getpagesize");
304    --  Returns the size of a page, or 0 if this is not relevant on this target
305
306    PROT_NONE  : constant := 0;
307    PROT_READ  : constant := 1;
308    PROT_WRITE : constant := 2;
309    PROT_EXEC  : constant := 4;
310    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
311
312    PROT_ON    : constant := PROT_READ;
313    PROT_OFF   : constant := PROT_ALL;
314
315    function mprotect (addr : Address; len : size_t; prot : int) return int;
316    pragma Import (C, mprotect);
317
318    ---------------------------------------
319    -- Nonstandard Thread Initialization --
320    ---------------------------------------
321
322    --  Though not documented, pthread_init *must* be called before any other
323    --  pthread call.
324
325    procedure pthread_init;
326    pragma Import (C, pthread_init, "pthread_init");
327
328    -------------------------
329    -- POSIX.1c  Section 3 --
330    -------------------------
331
332    function sigwait
333      (set : access sigset_t;
334       sig : access Signal) return int;
335    pragma Import (C, sigwait, "sigwait");
336
337    function pthread_kill
338      (thread : pthread_t;
339       sig    : Signal) return int;
340    pragma Import (C, pthread_kill, "pthread_kill");
341
342    function pthread_sigmask
343      (how  : int;
344       set  : access sigset_t;
345       oset : access sigset_t) return int;
346    pragma Import (C, pthread_sigmask, "sigthreadmask");
347
348    --------------------------
349    -- POSIX.1c  Section 11 --
350    --------------------------
351
352    function pthread_mutexattr_init
353      (attr : access pthread_mutexattr_t) return int;
354    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
355
356    function pthread_mutexattr_destroy
357      (attr : access pthread_mutexattr_t) return int;
358    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
359
360    function pthread_mutex_init
361      (mutex : access pthread_mutex_t;
362       attr  : access pthread_mutexattr_t) return int;
363    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
364
365    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
366    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
367
368    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
369    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
370
371    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
372    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
373
374    function pthread_condattr_init
375      (attr : access pthread_condattr_t) return int;
376    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
377
378    function pthread_condattr_destroy
379      (attr : access pthread_condattr_t) return int;
380    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
381
382    function pthread_cond_init
383      (cond : access pthread_cond_t;
384       attr : access pthread_condattr_t) return int;
385    pragma Import (C, pthread_cond_init, "pthread_cond_init");
386
387    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
388    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
389
390    function pthread_cond_signal (cond : access pthread_cond_t) return int;
391    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
392
393    function pthread_cond_wait
394      (cond  : access pthread_cond_t;
395       mutex : access pthread_mutex_t) return int;
396    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
397
398    function pthread_cond_timedwait
399      (cond    : access pthread_cond_t;
400       mutex   : access pthread_mutex_t;
401       abstime : access timespec) return int;
402    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
403
404    Relative_Timed_Wait : constant Boolean := False;
405    --  pthread_cond_timedwait requires an absolute delay time
406
407    --------------------------
408    -- POSIX.1c  Section 13 --
409    --------------------------
410
411    PTHREAD_PRIO_PROTECT : constant := 2;
412
413    function PTHREAD_PRIO_INHERIT return int;
414    --  Return value of C macro PTHREAD_PRIO_INHERIT. This function is needed
415    --  since the value is different between AIX versions.
416
417    function pthread_mutexattr_setprotocol
418      (attr     : access pthread_mutexattr_t;
419       protocol : int) return int;
420    pragma Import (C, pthread_mutexattr_setprotocol);
421
422    function pthread_mutexattr_setprioceiling
423      (attr        : access pthread_mutexattr_t;
424       prioceiling : int) return int;
425    pragma Import (C, pthread_mutexattr_setprioceiling);
426
427    type Array_5_Int is array (0 .. 5) of int;
428    type struct_sched_param is record
429       sched_priority : int;
430       sched_policy   : int;
431       sched_reserved : Array_5_Int;
432    end record;
433
434    function pthread_setschedparam
435      (thread : pthread_t;
436       policy : int;
437       param  : access struct_sched_param) return int;
438    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
439
440    function pthread_attr_setscope
441      (attr            : access pthread_attr_t;
442       contentionscope : int) return int;
443    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
444
445    function pthread_attr_setinheritsched
446      (attr            : access pthread_attr_t;
447       inheritsched : int) return int;
448    pragma Import (C, pthread_attr_setinheritsched);
449
450    function pthread_attr_setschedpolicy
451      (attr   : access pthread_attr_t;
452       policy : int) return int;
453    pragma Import (C, pthread_attr_setschedpolicy);
454
455    function pthread_attr_setschedparam
456      (attr        : access pthread_attr_t;
457       sched_param : int) return int;
458    pragma Import (C, pthread_attr_setschedparam);
459
460    function sched_yield return int;
461    --  AIX have a nonstandard sched_yield
462
463    --------------------------
464    -- P1003.1c  Section 16 --
465    --------------------------
466
467    function pthread_attr_init (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 (C, pthread_attr_setdetachstate);
478
479    function pthread_attr_setstacksize
480      (attr      : access pthread_attr_t;
481       stacksize : size_t) return int;
482    pragma Import (C, pthread_attr_setstacksize);
483
484    function pthread_create
485      (thread        : access pthread_t;
486       attributes    : access pthread_attr_t;
487       start_routine : Thread_Body;
488       arg           : System.Address)
489      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    --------------------------
499    -- POSIX.1c  Section 17 --
500    --------------------------
501
502    function pthread_setspecific
503      (key   : pthread_key_t;
504       value : System.Address) return int;
505    pragma Import (C, pthread_setspecific, "pthread_setspecific");
506
507    function pthread_getspecific (key : pthread_key_t) return System.Address;
508    pragma Import (C, pthread_getspecific, "pthread_getspecific");
509
510    type destructor_pointer is access procedure (arg : System.Address);
511    pragma Convention (C, destructor_pointer);
512
513    function pthread_key_create
514      (key        : access pthread_key_t;
515       destructor : destructor_pointer) return int;
516    pragma Import (C, pthread_key_create, "pthread_key_create");
517
518 private
519    type sigset_t is record
520       losigs : unsigned_long;
521       hisigs : unsigned_long;
522    end record;
523    pragma Convention (C_Pass_By_Copy, sigset_t);
524
525    type pid_t is new int;
526
527    type time_t is new long;
528
529    type timespec is record
530       tv_sec  : time_t;
531       tv_nsec : long;
532    end record;
533    pragma Convention (C, timespec);
534
535    type clockid_t is new int;
536    CLOCK_REALTIME : constant clockid_t := 0;
537
538    type struct_timeval is record
539       tv_sec  : long;
540       tv_usec : long;
541    end record;
542    pragma Convention (C, struct_timeval);
543
544    type pthread_attr_t is new System.Address;
545    pragma Convention (C, pthread_attr_t);
546    --  typedef struct __pt_attr        *pthread_attr_t;
547
548    type pthread_condattr_t is new System.Address;
549    pragma Convention (C, pthread_condattr_t);
550    --  typedef struct __pt_attr        *pthread_condattr_t;
551
552    type pthread_mutexattr_t is new System.Address;
553    pragma Convention (C, pthread_mutexattr_t);
554    --  typedef struct __pt_attr        *pthread_mutexattr_t;
555
556    type pthread_t is new System.Address;
557    pragma Convention (C, pthread_t);
558    --  typedef void    *pthread_t;
559
560    type ptq_queue;
561    type ptq_queue_ptr is access all ptq_queue;
562
563    type ptq_queue is record
564       ptq_next : ptq_queue_ptr;
565       ptq_prev : ptq_queue_ptr;
566    end record;
567
568    type Array_3_Int is array (0 .. 3) of int;
569    type pthread_mutex_t is record
570         link        : ptq_queue;
571         ptmtx_lock  : int;
572         ptmtx_flags : long;
573         protocol    : int;
574         prioceiling : int;
575         ptmtx_owner : pthread_t;
576         mtx_id      : int;
577         attr        : pthread_attr_t;
578         mtx_kind    : int;
579         lock_cpt    : int;
580         reserved    : Array_3_Int;
581    end record;
582    pragma Convention (C, pthread_mutex_t);
583    type pthread_mutex_t_ptr is access pthread_mutex_t;
584
585    type pthread_cond_t is record
586       link         : ptq_queue;
587       ptcv_lock    : int;
588       ptcv_flags   : long;
589       ptcv_waiters : ptq_queue;
590       cv_id        : int;
591       attr         : pthread_attr_t;
592       mutex        : pthread_mutex_t_ptr;
593       cptwait      : int;
594       reserved     : int;
595    end record;
596    pragma Convention (C, pthread_cond_t);
597
598    type pthread_key_t is new unsigned;
599
600 end System.OS_Interface;