OSDN Git Service

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