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