* make.adb:
[platform/upstream/gcc.git] / gcc / ada / 5cosinte.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.18 $
10 --                                                                          --
11 --          Copyright (C) 1998-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 (FSU 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    --  pragma Elaborate_Body;
50
51    pragma Linker_Options ("-lgthreads");
52    pragma Linker_Options ("-lmalloc");
53
54    subtype int            is Interfaces.C.int;
55    subtype short          is Interfaces.C.short;
56    subtype long           is Interfaces.C.long;
57    subtype unsigned       is Interfaces.C.unsigned;
58    subtype unsigned_short is Interfaces.C.unsigned_short;
59    subtype unsigned_long  is Interfaces.C.unsigned_long;
60    subtype unsigned_char  is Interfaces.C.unsigned_char;
61    subtype plain_char     is Interfaces.C.plain_char;
62    subtype size_t         is Interfaces.C.size_t;
63
64    -----------
65    -- Errno --
66    -----------
67
68    function errno return int;
69    pragma Import (C, errno, "__get_errno");
70
71    EAGAIN    : constant := 11;
72    EINTR     : constant := 4;
73    EINVAL    : constant := 22;
74    ENOMEM    : constant := 12;
75    ETIMEDOUT : constant := 78;
76
77    -------------
78    -- Signals --
79    -------------
80
81    Max_Interrupt : constant := 63;
82    type Signal is new int range 0 .. Max_Interrupt;
83    for Signal'Size use int'Size;
84
85    SIGHUP      : constant := 1; --  hangup
86    SIGINT      : constant := 2; --  interrupt (rubout)
87    SIGQUIT     : constant := 3; --  quit (ASCD FS)
88    SIGILL      : constant := 4; --  illegal instruction (not reset)
89    SIGTRAP     : constant := 5; --  trace trap (not reset)
90    SIGIOT      : constant := 6; --  IOT instruction
91    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
92    SIGEMT      : constant := 7; --  EMT instruction
93    SIGFPE      : constant := 8; --  floating point exception
94    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
95    SIGBUS      : constant := 10; --  bus error
96    SIGSEGV     : constant := 11; --  segmentation violation
97    SIGSYS      : constant := 12; --  bad argument to system call
98    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
99    SIGALRM     : constant := 14; --  alarm clock
100    SIGTERM     : constant := 15; --  software termination signal from kill
101    SIGUSR1     : constant := 30; --  user defined signal 1
102    SIGUSR2     : constant := 31; --  user defined signal 2
103    SIGCLD      : constant := 20; --  alias for SIGCHLD
104    SIGCHLD     : constant := 20; --  child status change
105    SIGPWR      : constant := 29; --  power-fail restart
106    SIGWINCH    : constant := 28; --  window size change
107    SIGURG      : constant := 16; --  urgent condition on IO channel
108    SIGPOLL     : constant := 23; --  pollable event occurred
109    SIGIO       : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
110    SIGSTOP     : constant := 17; --  stop (cannot be caught or ignored)
111    SIGTSTP     : constant := 18; --  user stop requested from tty
112    SIGCONT     : constant := 19; --  stopped process has been continued
113    SIGTTIN     : constant := 21; --  background tty read attempted
114    SIGTTOU     : constant := 22; --  background tty write attempted
115    SIGVTALRM   : constant := 34; --  virtual timer expired
116    SIGPROF     : constant := 32; --  profiling timer expired
117    SIGXCPU     : constant := 24; --  CPU time limit exceeded
118    SIGXFSZ     : constant := 25; --  filesize limit exceeded
119    SIGWAITING  : constant := 39; --  m:n scheduling
120
121    --  the following signals are AIX specific
122    SIGMSG      : constant := 27; -- input data is in the ring buffer
123    SIGDANGER   : constant := 33; -- system crash imminent
124    SIGMIGRATE  : constant := 35; -- migrate process
125    SIGPRE      : constant := 36; -- programming exception
126    SIGVIRT     : constant := 37; -- AIX virtual time alarm
127    SIGALRM1    : constant := 38; -- m:n condition variables
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 := SIGABRT;
135
136    type Signal_Set is array (Natural range <>) of Signal;
137
138    Unmasked    : constant Signal_Set :=
139      (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
140    Reserved    : constant Signal_Set :=
141      (SIGKILL, SIGSTOP, SIGALRM, SIGWAITING);
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    SIG_BLOCK   : constant := 0;
169    SIG_UNBLOCK : constant := 1;
170    SIG_SETMASK : constant := 2;
171
172    SIG_DFL : constant := 0;
173    SIG_IGN : constant := 1;
174
175    function sigaction
176      (sig  : Signal;
177       act  : struct_sigaction_ptr;
178       oact : struct_sigaction_ptr) return int;
179    pragma Import (C, sigaction, "_internal_sigaction");
180
181    ----------
182    -- Time --
183    ----------
184
185    Time_Slice_Supported : constant Boolean := True;
186    --  Indicates wether time slicing is supported (i.e FSU threads have been
187    --  compiled with DEF_RR)
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    pragma Import (C, clock_gettime, "clock_gettime");
199
200    function To_Duration (TS : timespec) return Duration;
201    pragma Inline (To_Duration);
202
203    function To_Timespec (D : Duration) return timespec;
204    pragma Inline (To_Timespec);
205
206    type struct_timeval is private;
207
208    function To_Duration (TV : struct_timeval) return Duration;
209    pragma Inline (To_Duration);
210
211    function To_Timeval (D : Duration) return struct_timeval;
212    pragma Inline (To_Timeval);
213
214    -------------------------
215    -- Priority Scheduling --
216    -------------------------
217
218    SCHED_FIFO  : constant := 0;
219    SCHED_RR    : constant := 1;
220    SCHED_OTHER : constant := 2;
221
222    -------------
223    -- Process --
224    -------------
225
226    type pid_t is private;
227
228    function kill (pid : pid_t; sig : Signal) return int;
229    pragma Import (C, kill, "kill");
230
231    function getpid return pid_t;
232    pragma Import (C, getpid, "getpid");
233
234    ---------
235    -- LWP --
236    ---------
237
238    function lwp_self return System.Address;
239    --  lwp_self does not exist on this thread library, revert to pthread_self
240    --  which is the closest approximation (with getpid). This function is
241    --  needed to share 7staprop.adb across POSIX-like targets.
242    pragma Import (C, lwp_self, "pthread_self");
243
244    -------------
245    -- Threads --
246    -------------
247
248    type Thread_Body is access
249      function (arg : System.Address) return System.Address;
250    type pthread_t           is private;
251    subtype Thread_Id        is pthread_t;
252
253    type pthread_mutex_t     is limited private;
254    type pthread_cond_t      is limited private;
255    type pthread_attr_t      is limited private;
256    type pthread_mutexattr_t is limited private;
257    type pthread_condattr_t  is limited private;
258    type pthread_key_t       is private;
259
260    PTHREAD_CREATE_DETACHED : constant := 1;
261
262    -----------
263    -- Stack --
264    -----------
265
266    Stack_Base_Available : constant Boolean := True;
267    --  Indicates wether the stack base is available on this target.
268    --  This allows us to share s-osinte.adb between all the FSU run time.
269    --  Note that this value can only be true if pthread_t has a complete
270    --  definition that corresponds exactly to the C header files.
271
272    function Get_Stack_Base (thread : pthread_t) return Address;
273    pragma Inline (Get_Stack_Base);
274    --  returns the stack base of the specified thread.
275    --  Only call this function when Stack_Base_Available is True.
276
277    function Get_Page_Size return size_t;
278    function Get_Page_Size return Address;
279    pragma Import (C, Get_Page_Size, "getpagesize");
280    --  returns the size of a page, or 0 if this is not relevant on this
281    --  target
282
283    PROT_NONE  : constant := 0;
284    PROT_READ  : constant := 1;
285    PROT_WRITE : constant := 2;
286    PROT_EXEC  : constant := 4;
287    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
288
289    PROT_ON    : constant := PROT_READ;
290    PROT_OFF   : constant := PROT_ALL;
291
292    function mprotect (addr : Address; len : size_t; prot : int) return int;
293    pragma Import (C, mprotect);
294
295    ---------------------------------------
296    -- Nonstandard Thread Initialization --
297    ---------------------------------------
298
299    procedure pthread_init;
300    --  FSU_THREADS requires pthread_init, which is nonstandard
301    --  and this should be invoked during the elaboration of s-taprop.adb
302    pragma Import (C, pthread_init, "pthread_init");
303
304    -------------------------
305    -- POSIX.1c  Section 3 --
306    -------------------------
307
308    function sigwait
309      (set : access sigset_t;
310       sig : access Signal) return int;
311    --  FSU_THREADS has a nonstandard sigwait
312
313    function pthread_kill
314      (thread : pthread_t;
315       sig    : Signal) return int;
316    pragma Import (C, pthread_kill, "pthread_kill");
317
318    --  FSU threads does not have pthread_sigmask. Instead, it redefines
319    --  sigprocmask and then uses a special syscall API to call the system
320    --  version. Doing syscalls on AiX is very difficult, so we rename the
321    --  pthread version instead.
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, "_internal_sigprocmask");
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    --  FSU_THREADS has nonstandard pthread_mutex_lock
353
354    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
355    --  FSU_THREADS has nonstandard pthread_mutex_lock
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    --  FSU_THREADS has a nonstandard 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    --  FSU_THREADS has a nonstandard 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 := 2;
396    PTHREAD_PRIO_INHERIT : constant := 1;
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
407      (C, pthread_mutexattr_setprioceiling,
408          "pthread_mutexattr_setprio_ceiling");
409
410    type struct_sched_param is record
411       sched_priority : int;  --  scheduling priority
412    end record;
413
414    function pthread_setschedparam
415      (thread : pthread_t;
416       policy : int;
417       param  : access struct_sched_param) return int;
418    --  FSU_THREADS does not have pthread_setschedparam
419
420    function pthread_attr_setscope
421      (attr            : access pthread_attr_t;
422       contentionscope : int) return int;
423    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
424
425    function pthread_attr_setinheritsched
426      (attr         : access pthread_attr_t;
427       inheritsched : int) return int;
428    pragma Import (C, pthread_attr_setinheritsched);
429
430    function pthread_attr_setschedpolicy
431      (attr   : access pthread_attr_t;
432       policy : int) return int;
433    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
434
435    function sched_yield return int;
436    --  FSU_THREADS does not have sched_yield;
437
438    ---------------------------
439    -- P1003.1c - Section 16 --
440    ---------------------------
441
442    function pthread_attr_init (attributes : access pthread_attr_t) return int;
443    pragma Import (C, pthread_attr_init, "pthread_attr_init");
444
445    function pthread_attr_destroy
446      (attributes : access pthread_attr_t) return int;
447    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
448
449    function pthread_attr_setdetachstate
450      (attr        : access pthread_attr_t;
451       detachstate : int) return int;
452    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
453
454    function pthread_attr_setstacksize
455      (attr      : access pthread_attr_t;
456       stacksize : size_t) return int;
457    pragma Import (C, pthread_attr_setstacksize);
458
459    function pthread_create
460      (thread        : access pthread_t;
461       attributes    : access pthread_attr_t;
462       start_routine : Thread_Body;
463       arg           : System.Address) return int;
464    pragma Import (C, pthread_create, "pthread_create");
465
466    procedure pthread_exit (status : System.Address);
467    pragma Import (C, pthread_exit, "pthread_exit");
468
469    function pthread_self return pthread_t;
470    pragma Import (C, pthread_self, "pthread_self");
471
472    --------------------------
473    -- POSIX.1c  Section 17 --
474    --------------------------
475
476    function pthread_setspecific
477      (key   : pthread_key_t;
478       value : System.Address) return int;
479    pragma Import (C, pthread_setspecific, "pthread_setspecific");
480
481    function pthread_getspecific (key : pthread_key_t) return System.Address;
482    --  FSU_THREADS has a nonstandard pthread_getspecific
483
484    type destructor_pointer is access procedure (arg : System.Address);
485
486    function pthread_key_create
487      (key        : access pthread_key_t;
488       destructor : destructor_pointer) return int;
489    pragma Import (C, pthread_key_create, "pthread_key_create");
490
491 private
492
493    type sigset_t is record
494       losigs : unsigned_long;
495       hisigs : unsigned_long;
496    end record;
497    pragma Convention (C_Pass_By_Copy, sigset_t);
498
499    type pid_t is new int;
500
501    type time_t is new long;
502
503    type timespec is record
504       tv_sec  : time_t;
505       tv_nsec : long;
506    end record;
507    pragma Convention (C, timespec);
508
509    type clockid_t is new int;
510    CLOCK_REALTIME : constant clockid_t := 0;
511
512    type struct_timeval is record
513       tv_sec  : long;
514       tv_usec : long;
515    end record;
516    pragma Convention (C, struct_timeval);
517
518    type pthread_attr_t is record
519       flags           : int;
520       stacksize       : int;
521       contentionscope : int;
522       inheritsched    : int;
523       detachstate     : int;
524       sched           : int;
525       prio            : int;
526       starttime       : timespec;
527       deadline        : timespec;
528       period          : timespec;
529    end record;
530    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
531
532    type pthread_condattr_t is record
533       flags : int;
534    end record;
535    pragma Convention (C, pthread_condattr_t);
536
537    type pthread_mutexattr_t is record
538       flags        : int;
539       prio_ceiling : int;
540       protocol     : int;
541    end record;
542    pragma Convention (C, pthread_mutexattr_t);
543
544    type sigjmp_buf is array (Integer range 0 .. 63) of int;
545
546    type pthread_t_struct is record
547       context    : sigjmp_buf;
548       pbody      : sigjmp_buf;
549       errno      : int;
550       ret        : int;
551       stack_base : System.Address;
552    end record;
553    pragma Convention (C, pthread_t_struct);
554
555    type pthread_t is access all pthread_t_struct;
556
557    type queue_t is record
558       head : System.Address;
559       tail : System.Address;
560    end record;
561    pragma Convention (C, queue_t);
562
563    type pthread_mutex_t is record
564       queue        : queue_t;
565       lock         : plain_char;
566       owner        : System.Address;
567       flags        : int;
568       prio_ceiling : int;
569       protocol     : int;
570       prev_max_ceiling_prio  : int;
571    end record;
572    pragma Convention (C, pthread_mutex_t);
573
574    type pthread_cond_t is record
575       queue   : queue_t;
576       flags   : int;
577       waiters : int;
578       mutex   : System.Address;
579    end record;
580    pragma Convention (C, pthread_cond_t);
581
582    type pthread_key_t is new int;
583
584 end System.OS_Interface;