OSDN Git Service

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