OSDN Git Service

* approved by rth
[pf3gnuchains/gcc-fork.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 --                                                                          --
10 --          Copyright (C) 1998-2001 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,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, 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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com).                                  --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 --  This is a AIX (FSU THREADS) version of this package.
37
38 --  This package encapsulates all direct interfaces to OS services
39 --  that are needed by children of System.
40
41 --  PLEASE DO NOT add any with-clauses to this package
42 --  or remove the pragma Elaborate_Body.
43 --  It is designed to be a bottom-level (leaf) package.
44
45 with Interfaces.C;
46 package System.OS_Interface is
47    pragma Preelaborate;
48    --  pragma Elaborate_Body;
49
50    pragma Linker_Options ("-lgthreads");
51    pragma Linker_Options ("-lmalloc");
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 := SIGABRT;
134
135    type Signal_Set is array (Natural range <>) of Signal;
136
137    Unmasked    : constant Signal_Set :=
138      (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
139    Reserved    : constant Signal_Set :=
140      (SIGKILL, SIGSTOP, SIGALRM, SIGWAITING);
141
142    type sigset_t is private;
143
144    function sigaddset (set : access sigset_t; sig : Signal) return int;
145    pragma Import (C, sigaddset, "sigaddset");
146
147    function sigdelset (set : access sigset_t; sig : Signal) return int;
148    pragma Import (C, sigdelset, "sigdelset");
149
150    function sigfillset (set : access sigset_t) return int;
151    pragma Import (C, sigfillset, "sigfillset");
152
153    function sigismember (set : access sigset_t; sig : Signal) return int;
154    pragma Import (C, sigismember, "sigismember");
155
156    function sigemptyset (set : access sigset_t) return int;
157    pragma Import (C, sigemptyset, "sigemptyset");
158
159    type struct_sigaction is record
160       sa_handler : System.Address;
161       sa_mask    : sigset_t;
162       sa_flags   : int;
163    end record;
164    pragma Convention (C, struct_sigaction);
165    type struct_sigaction_ptr is access all struct_sigaction;
166
167    SIG_BLOCK   : constant := 0;
168    SIG_UNBLOCK : constant := 1;
169    SIG_SETMASK : constant := 2;
170
171    SIG_DFL : constant := 0;
172    SIG_IGN : constant := 1;
173
174    function sigaction
175      (sig  : Signal;
176       act  : struct_sigaction_ptr;
177       oact : struct_sigaction_ptr) return int;
178    pragma Import (C, sigaction, "_internal_sigaction");
179
180    ----------
181    -- Time --
182    ----------
183
184    Time_Slice_Supported : constant Boolean := True;
185    --  Indicates wether time slicing is supported (i.e FSU threads have been
186    --  compiled with DEF_RR)
187
188    type timespec is private;
189
190    type clockid_t is private;
191
192    CLOCK_REALTIME : constant clockid_t;
193
194    function clock_gettime
195      (clock_id : clockid_t;
196       tp       : access timespec) return int;
197    pragma Import (C, clock_gettime, "clock_gettime");
198
199    function To_Duration (TS : timespec) return Duration;
200    pragma Inline (To_Duration);
201
202    function To_Timespec (D : Duration) return timespec;
203    pragma Inline (To_Timespec);
204
205    type struct_timeval is private;
206
207    function To_Duration (TV : struct_timeval) return Duration;
208    pragma Inline (To_Duration);
209
210    function To_Timeval (D : Duration) return struct_timeval;
211    pragma Inline (To_Timeval);
212
213    -------------------------
214    -- Priority Scheduling --
215    -------------------------
216
217    SCHED_FIFO  : constant := 0;
218    SCHED_RR    : constant := 1;
219    SCHED_OTHER : constant := 2;
220
221    -------------
222    -- Process --
223    -------------
224
225    type pid_t is private;
226
227    function kill (pid : pid_t; sig : Signal) return int;
228    pragma Import (C, kill, "kill");
229
230    function getpid return pid_t;
231    pragma Import (C, getpid, "getpid");
232
233    ---------
234    -- LWP --
235    ---------
236
237    function lwp_self return System.Address;
238    --  lwp_self does not exist on this thread library, revert to pthread_self
239    --  which is the closest approximation (with getpid). This function is
240    --  needed to share 7staprop.adb across POSIX-like targets.
241    pragma Import (C, lwp_self, "pthread_self");
242
243    -------------
244    -- Threads --
245    -------------
246
247    type Thread_Body is access
248      function (arg : System.Address) return System.Address;
249    type pthread_t           is private;
250    subtype Thread_Id        is pthread_t;
251
252    type pthread_mutex_t     is limited private;
253    type pthread_cond_t      is limited private;
254    type pthread_attr_t      is limited private;
255    type pthread_mutexattr_t is limited private;
256    type pthread_condattr_t  is limited private;
257    type pthread_key_t       is private;
258
259    PTHREAD_CREATE_DETACHED : constant := 1;
260
261    -----------
262    -- Stack --
263    -----------
264
265    Stack_Base_Available : constant Boolean := True;
266    --  Indicates wether the stack base is available on this target.
267    --  This allows us to share s-osinte.adb between all the FSU run time.
268    --  Note that this value can only be true if pthread_t has a complete
269    --  definition that corresponds exactly to the C header files.
270
271    function Get_Stack_Base (thread : pthread_t) return Address;
272    pragma Inline (Get_Stack_Base);
273    --  returns the stack base of the specified thread.
274    --  Only call this function when Stack_Base_Available is True.
275
276    function Get_Page_Size return size_t;
277    function Get_Page_Size return Address;
278    pragma Import (C, Get_Page_Size, "getpagesize");
279    --  returns the size of a page, or 0 if this is not relevant on this
280    --  target
281
282    PROT_NONE  : constant := 0;
283    PROT_READ  : constant := 1;
284    PROT_WRITE : constant := 2;
285    PROT_EXEC  : constant := 4;
286    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
287
288    PROT_ON    : constant := PROT_READ;
289    PROT_OFF   : constant := PROT_ALL;
290
291    function mprotect (addr : Address; len : size_t; prot : int) return int;
292    pragma Import (C, mprotect);
293
294    ---------------------------------------
295    -- Nonstandard Thread Initialization --
296    ---------------------------------------
297
298    procedure pthread_init;
299    --  FSU_THREADS requires pthread_init, which is nonstandard
300    --  and this should be invoked during the elaboration of s-taprop.adb
301    pragma Import (C, pthread_init, "pthread_init");
302
303    -------------------------
304    -- POSIX.1c  Section 3 --
305    -------------------------
306
307    function sigwait
308      (set : access sigset_t;
309       sig : access Signal) return int;
310    --  FSU_THREADS has a nonstandard sigwait
311
312    function pthread_kill
313      (thread : pthread_t;
314       sig    : Signal) return int;
315    pragma Import (C, pthread_kill, "pthread_kill");
316
317    --  FSU threads does not have pthread_sigmask. Instead, it redefines
318    --  sigprocmask and then uses a special syscall API to call the system
319    --  version. Doing syscalls on AiX is very difficult, so we rename the
320    --  pthread version instead.
321
322    type sigset_t_ptr is access all sigset_t;
323
324    function pthread_sigmask
325      (how  : int;
326       set  : sigset_t_ptr;
327       oset : sigset_t_ptr) return int;
328    pragma Import (C, pthread_sigmask, "_internal_sigprocmask");
329
330    --------------------------
331    -- POSIX.1c  Section 11 --
332    --------------------------
333
334    function pthread_mutexattr_init
335      (attr : access pthread_mutexattr_t) return int;
336    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
337
338    function pthread_mutexattr_destroy
339      (attr : access pthread_mutexattr_t) return int;
340    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
341
342    function pthread_mutex_init
343      (mutex : access pthread_mutex_t;
344       attr  : access pthread_mutexattr_t) return int;
345    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
346
347    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
348    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
349
350    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
351    --  FSU_THREADS has nonstandard pthread_mutex_lock
352
353    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
354    --  FSU_THREADS has nonstandard pthread_mutex_lock
355
356    function pthread_condattr_init
357      (attr : access pthread_condattr_t) return int;
358    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
359
360    function pthread_condattr_destroy
361      (attr : access pthread_condattr_t) return int;
362    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
363
364    function pthread_cond_init
365      (cond : access pthread_cond_t;
366       attr : access pthread_condattr_t) return int;
367    pragma Import (C, pthread_cond_init, "pthread_cond_init");
368
369    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
370    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
371
372    function pthread_cond_signal (cond : access pthread_cond_t) return int;
373    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
374
375    function pthread_cond_wait
376      (cond  : access pthread_cond_t;
377       mutex : access pthread_mutex_t) return int;
378    --  FSU_THREADS has a nonstandard pthread_cond_wait
379
380    function pthread_cond_timedwait
381      (cond    : access pthread_cond_t;
382       mutex   : access pthread_mutex_t;
383       abstime : access timespec) return int;
384    --  FSU_THREADS has a nonstandard pthread_cond_timedwait
385
386    Relative_Timed_Wait : constant Boolean := False;
387    --  pthread_cond_timedwait requires an absolute delay time
388
389    --------------------------
390    -- POSIX.1c  Section 13 --
391    --------------------------
392
393    PTHREAD_PRIO_NONE    : constant := 0;
394    PTHREAD_PRIO_PROTECT : constant := 2;
395    PTHREAD_PRIO_INHERIT : constant := 1;
396
397    function pthread_mutexattr_setprotocol
398      (attr     : access pthread_mutexattr_t;
399       protocol : int) return int;
400    pragma Import (C, pthread_mutexattr_setprotocol);
401
402    function pthread_mutexattr_setprioceiling
403      (attr        : access pthread_mutexattr_t;
404       prioceiling : int) return int;
405    pragma Import
406      (C, pthread_mutexattr_setprioceiling,
407          "pthread_mutexattr_setprio_ceiling");
408
409    type struct_sched_param is record
410       sched_priority : int;  --  scheduling priority
411    end record;
412
413    function pthread_setschedparam
414      (thread : pthread_t;
415       policy : int;
416       param  : access struct_sched_param) return int;
417    --  FSU_THREADS does not have pthread_setschedparam
418
419    function pthread_attr_setscope
420      (attr            : access pthread_attr_t;
421       contentionscope : int) return int;
422    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
423
424    function pthread_attr_setinheritsched
425      (attr         : access pthread_attr_t;
426       inheritsched : int) return int;
427    pragma Import (C, pthread_attr_setinheritsched);
428
429    function pthread_attr_setschedpolicy
430      (attr   : access pthread_attr_t;
431       policy : int) return int;
432    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
433
434    function sched_yield return int;
435    --  FSU_THREADS does not have sched_yield;
436
437    ---------------------------
438    -- P1003.1c - Section 16 --
439    ---------------------------
440
441    function pthread_attr_init (attributes : access pthread_attr_t) return int;
442    pragma Import (C, pthread_attr_init, "pthread_attr_init");
443
444    function pthread_attr_destroy
445      (attributes : access pthread_attr_t) return int;
446    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
447
448    function pthread_attr_setdetachstate
449      (attr        : access pthread_attr_t;
450       detachstate : int) return int;
451    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
452
453    function pthread_attr_setstacksize
454      (attr      : access pthread_attr_t;
455       stacksize : size_t) return int;
456    pragma Import (C, pthread_attr_setstacksize);
457
458    function pthread_create
459      (thread        : access pthread_t;
460       attributes    : access pthread_attr_t;
461       start_routine : Thread_Body;
462       arg           : System.Address) return int;
463    pragma Import (C, pthread_create, "pthread_create");
464
465    procedure pthread_exit (status : System.Address);
466    pragma Import (C, pthread_exit, "pthread_exit");
467
468    function pthread_self return pthread_t;
469    pragma Import (C, pthread_self, "pthread_self");
470
471    --------------------------
472    -- POSIX.1c  Section 17 --
473    --------------------------
474
475    function pthread_setspecific
476      (key   : pthread_key_t;
477       value : System.Address) return int;
478    pragma Import (C, pthread_setspecific, "pthread_setspecific");
479
480    function pthread_getspecific (key : pthread_key_t) return System.Address;
481    --  FSU_THREADS has a nonstandard pthread_getspecific
482
483    type destructor_pointer is access procedure (arg : System.Address);
484
485    function pthread_key_create
486      (key        : access pthread_key_t;
487       destructor : destructor_pointer) return int;
488    pragma Import (C, pthread_key_create, "pthread_key_create");
489
490 private
491
492    type sigset_t is record
493       losigs : unsigned_long;
494       hisigs : unsigned_long;
495    end record;
496    pragma Convention (C_Pass_By_Copy, sigset_t);
497
498    type pid_t is new int;
499
500    type time_t is new long;
501
502    type timespec is record
503       tv_sec  : time_t;
504       tv_nsec : long;
505    end record;
506    pragma Convention (C, timespec);
507
508    type clockid_t is new int;
509    CLOCK_REALTIME : constant clockid_t := 0;
510
511    type struct_timeval is record
512       tv_sec  : long;
513       tv_usec : long;
514    end record;
515    pragma Convention (C, struct_timeval);
516
517    type pthread_attr_t is record
518       flags           : int;
519       stacksize       : int;
520       contentionscope : int;
521       inheritsched    : int;
522       detachstate     : int;
523       sched           : int;
524       prio            : int;
525       starttime       : timespec;
526       deadline        : timespec;
527       period          : timespec;
528    end record;
529    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
530
531    type pthread_condattr_t is record
532       flags : int;
533    end record;
534    pragma Convention (C, pthread_condattr_t);
535
536    type pthread_mutexattr_t is record
537       flags        : int;
538       prio_ceiling : int;
539       protocol     : int;
540    end record;
541    pragma Convention (C, pthread_mutexattr_t);
542
543    type sigjmp_buf is array (Integer range 0 .. 63) of int;
544
545    type pthread_t_struct is record
546       context    : sigjmp_buf;
547       pbody      : sigjmp_buf;
548       errno      : int;
549       ret        : int;
550       stack_base : System.Address;
551    end record;
552    pragma Convention (C, pthread_t_struct);
553
554    type pthread_t is access all pthread_t_struct;
555
556    type queue_t is record
557       head : System.Address;
558       tail : System.Address;
559    end record;
560    pragma Convention (C, queue_t);
561
562    type pthread_mutex_t is record
563       queue        : queue_t;
564       lock         : plain_char;
565       owner        : System.Address;
566       flags        : int;
567       prio_ceiling : int;
568       protocol     : int;
569       prev_max_ceiling_prio  : int;
570    end record;
571    pragma Convention (C, pthread_mutex_t);
572
573    type pthread_cond_t is record
574       queue   : queue_t;
575       flags   : int;
576       waiters : int;
577       mutex   : System.Address;
578    end record;
579    pragma Convention (C, pthread_cond_t);
580
581    type pthread_key_t is new int;
582
583 end System.OS_Interface;