OSDN Git Service

* raise.c (get_action_description_for): Fix typo in last change.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5losinte.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) 1991-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 GNU/Linux (FSU 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 ("-lgthreads");
48    pragma Linker_Options ("-lmalloc");
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 := 110;
72
73    -------------
74    -- Signals --
75    -------------
76
77    Max_Interrupt : constant := 31;
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    SIGFPE     : constant := 8; --  floating point exception
89    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
90    SIGBUS     : constant := 7; --  bus error
91    SIGSEGV    : constant := 11; --  segmentation violation
92    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
93    SIGALRM    : constant := 14; --  alarm clock
94    SIGTERM    : constant := 15; --  software termination signal from kill
95    SIGUSR1    : constant := 10; --  user defined signal 1
96    SIGUSR2    : constant := 12; --  user defined signal 2
97    SIGCLD     : constant := 17; --  alias for SIGCHLD
98    SIGCHLD    : constant := 17; --  child status change
99    SIGPWR     : constant := 30; --  power-fail restart
100    SIGWINCH   : constant := 28; --  window size change
101    SIGURG     : constant := 23; --  urgent condition on IO channel
102    SIGPOLL    : constant := 29; --  pollable event occurred
103    SIGIO      : constant := 29; --  I/O now possible (4.2 BSD)
104    SIGLOST    : constant := 29; --  File lock lost
105    SIGSTOP    : constant := 19; --  stop (cannot be caught or ignored)
106    SIGTSTP    : constant := 20; --  user stop requested from tty
107    SIGCONT    : constant := 18; --  stopped process has been continued
108    SIGTTIN    : constant := 21; --  background tty read attempted
109    SIGTTOU    : constant := 22; --  background tty write attempted
110    SIGVTALRM  : constant := 26; --  virtual timer expired
111    SIGPROF    : constant := 27; --  profiling timer expired
112    SIGXCPU    : constant := 24; --  CPU time limit exceeded
113    SIGXFSZ    : constant := 25; --  filesize limit exceeded
114    SIGUNUSED  : constant := 31; --  unused signal (GNU/Linux)
115    SIGSTKFLT  : constant := 16; --  coprocessor stack fault (GNU/Linux)
116
117    SIGADAABORT : constant := SIGABRT;
118    --  Change this if you want to use another signal for task abort.
119    --  SIGTERM might be a good one.
120
121    type Signal_Set is array (Natural range <>) of Signal;
122
123    Unmasked    : constant Signal_Set :=
124      (SIGTRAP, SIGBUS, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
125
126    Reserved    : constant Signal_Set :=
127      (SIGKILL, SIGSTOP, SIGALRM, SIGVTALRM, SIGUNUSED);
128
129    type sigset_t is private;
130
131    function sigaddset (set : access sigset_t; sig : Signal) return int;
132    pragma Import (C, sigaddset, "sigaddset");
133
134    function sigdelset (set : access sigset_t; sig : Signal) return int;
135    pragma Import (C, sigdelset, "sigdelset");
136
137    function sigfillset (set : access sigset_t) return int;
138    pragma Import (C, sigfillset, "sigfillset");
139
140    function sigismember (set : access sigset_t; sig : Signal) return int;
141    pragma Import (C, sigismember, "sigismember");
142
143    function sigemptyset (set : access sigset_t) return int;
144    pragma Import (C, sigemptyset, "sigemptyset");
145
146    type struct_sigaction is record
147       sa_handler  : System.Address;
148       sa_mask     : sigset_t;
149       sa_flags    : unsigned_long;
150       sa_restorer : System.Address;
151    end record;
152    pragma Convention (C, struct_sigaction);
153    type struct_sigaction_ptr is access all struct_sigaction;
154
155    type Machine_State is record
156       eip : unsigned_long;
157       ebx : unsigned_long;
158       esp : unsigned_long;
159       ebp : unsigned_long;
160       esi : unsigned_long;
161       edi : unsigned_long;
162    end record;
163    type Machine_State_Ptr is access all Machine_State;
164
165    SIG_BLOCK   : constant := 0;
166    SIG_UNBLOCK : constant := 1;
167    SIG_SETMASK : constant := 2;
168
169    SIG_DFL : constant := 0;
170    SIG_IGN : constant := 1;
171
172    function sigaction
173      (sig  : Signal;
174       act  : struct_sigaction_ptr;
175       oact : struct_sigaction_ptr) return int;
176    pragma Import (C, sigaction, "sigaction");
177
178    ----------
179    -- Time --
180    ----------
181
182    Time_Slice_Supported : constant Boolean := False;
183    --  Indicates wether time slicing is supported (i.e FSU threads have been
184    --  compiled with DEF_RR)
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    pragma Import (C, clock_gettime, "clock_gettime");
196
197    function To_Duration (TS : timespec) return Duration;
198    pragma Inline (To_Duration);
199
200    function To_Timespec (D : Duration) return timespec;
201    pragma Inline (To_Timespec);
202
203    type struct_timeval is private;
204
205    function To_Duration (TV : struct_timeval) return Duration;
206    pragma Inline (To_Duration);
207
208    function To_Timeval (D : Duration) return struct_timeval;
209    pragma Inline (To_Timeval);
210
211    -------------------------
212    -- Priority Scheduling --
213    -------------------------
214
215    SCHED_FIFO  : constant := 0;
216    SCHED_RR    : constant := 1;
217    SCHED_OTHER : constant := 2;
218
219    -------------
220    -- Process --
221    -------------
222
223    type pid_t is private;
224
225    function kill (pid : pid_t; sig : Signal) return int;
226    pragma Import (C, kill, "kill");
227
228    function getpid return pid_t;
229    pragma Import (C, getpid, "getpid");
230
231    ---------
232    -- LWP --
233    ---------
234
235    function lwp_self return System.Address;
236    --  lwp_self does not exist on this thread library, revert to pthread_self
237    --  which is the closest approximation (with getpid). This function is
238    --  needed to share 7staprop.adb across POSIX-like targets.
239    pragma Import (C, lwp_self, "pthread_self");
240
241    -------------
242    -- Threads --
243    -------------
244
245    type Thread_Body is access
246      function (arg : System.Address) return System.Address;
247    type pthread_t           is private;
248    subtype Thread_Id        is pthread_t;
249
250    type pthread_mutex_t     is limited private;
251    type pthread_cond_t      is limited private;
252    type pthread_attr_t      is limited private;
253    type pthread_mutexattr_t is limited private;
254    type pthread_condattr_t  is limited private;
255    type pthread_key_t       is private;
256
257    PTHREAD_CREATE_DETACHED : constant := 1;
258
259    -----------
260    -- Stack --
261    -----------
262
263    Stack_Base_Available : constant Boolean := False;
264    --  Indicates wether the stack base is available on this target.
265    --  This allows us to share s-osinte.adb between all the FSU run time.
266    --  Note that this value can only be true if pthread_t has a complete
267    --  definition that corresponds exactly to the C header files.
268
269    function Get_Stack_Base (thread : pthread_t) return Address;
270    pragma Inline (Get_Stack_Base);
271    --  returns the stack base of the specified thread.
272    --  Only call this function when Stack_Base_Available is True.
273
274    function Get_Page_Size return size_t;
275    function Get_Page_Size return Address;
276    pragma Import (C, Get_Page_Size, "getpagesize");
277    --  returns the size of a page, or 0 if this is not relevant on this
278    --  target
279
280    PROT_NONE  : constant := 0;
281    PROT_READ  : constant := 1;
282    PROT_WRITE : constant := 2;
283    PROT_EXEC  : constant := 4;
284    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
285
286    PROT_ON    : constant := PROT_NONE;
287    PROT_OFF   : constant := PROT_ALL;
288
289    function mprotect (addr : Address; len : size_t; prot : int) return int;
290    pragma Import (C, mprotect);
291
292    ---------------------------------------
293    -- Nonstandard Thread Initialization --
294    ---------------------------------------
295
296    procedure pthread_init;
297    --  FSU_THREADS requires pthread_init, which is nonstandard
298    --  and this should be invoked during the elaboration of s-taprop.adb
299    pragma Import (C, pthread_init, "pthread_init");
300
301    -------------------------
302    -- POSIX.1c  Section 3 --
303    -------------------------
304
305    function sigwait
306      (set : access sigset_t;
307       sig : access Signal) return int;
308    pragma Inline (sigwait);
309    --  FSU_THREADS has a nonstandard sigwait
310
311    function pthread_kill
312      (thread : pthread_t;
313       sig    : Signal) return int;
314    pragma Import (C, pthread_kill, "pthread_kill");
315
316    --  FSU threads does not have pthread_sigmask. Instead, it uses
317    --  sigprocmask to do the signal handling when the thread library is
318    --  sucked in.
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, "sigprocmask");
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
346      (mutex : access pthread_mutex_t) return  int;
347    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
348
349    function pthread_mutex_lock
350      (mutex : access pthread_mutex_t) return int;
351    pragma Inline (pthread_mutex_lock);
352    --  FSU_THREADS has nonstandard pthread_mutex_lock
353
354    function pthread_mutex_unlock
355      (mutex : access pthread_mutex_t) return int;
356    pragma Inline (pthread_mutex_unlock);
357    --  FSU_THREADS has nonstandard pthread_mutex_lock
358
359    function pthread_condattr_init
360      (attr : access pthread_condattr_t) return int;
361    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
362
363    function pthread_condattr_destroy
364      (attr : access pthread_condattr_t) return int;
365    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
366
367    function pthread_cond_init
368      (cond : access pthread_cond_t;
369       attr : access pthread_condattr_t) return int;
370    pragma Import (C, pthread_cond_init, "pthread_cond_init");
371
372    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
373    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
374
375    function pthread_cond_signal (cond : access pthread_cond_t) return int;
376    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
377
378    function pthread_cond_wait
379      (cond  : access pthread_cond_t;
380       mutex : access pthread_mutex_t) return int;
381    pragma Inline (pthread_cond_wait);
382    --  FSU_THREADS has a nonstandard pthread_cond_wait
383
384    function pthread_cond_timedwait
385      (cond    : access pthread_cond_t;
386       mutex   : access pthread_mutex_t;
387       abstime : access timespec) return int;
388    pragma Inline (pthread_cond_timedwait);
389    --  FSU_THREADS has a nonstandard pthread_cond_timedwait
390
391    Relative_Timed_Wait : constant Boolean := False;
392    --  pthread_cond_timedwait requires an absolute delay time
393
394    --------------------------
395    -- POSIX.1c  Section 13 --
396    --------------------------
397
398    PTHREAD_PRIO_NONE    : constant := 0;
399    PTHREAD_PRIO_PROTECT : constant := 2;
400    PTHREAD_PRIO_INHERIT : constant := 1;
401
402    function pthread_mutexattr_setprotocol
403      (attr     : access pthread_mutexattr_t;
404       protocol : int) return int;
405    pragma Import (C, pthread_mutexattr_setprotocol);
406
407    function pthread_mutexattr_setprioceiling
408      (attr        : access pthread_mutexattr_t;
409       prioceiling : int) return int;
410    pragma Import
411      (C, pthread_mutexattr_setprioceiling,
412       "pthread_mutexattr_setprio_ceiling");
413
414    type struct_sched_param is record
415       sched_priority : int;  --  scheduling priority
416    end record;
417
418    function pthread_setschedparam
419      (thread : pthread_t;
420       policy : int;
421       param  : access struct_sched_param) return int;
422    pragma Inline (pthread_setschedparam);
423    --  FSU_THREADS does not have pthread_setschedparam
424
425    function pthread_attr_setscope
426      (attr            : access pthread_attr_t;
427       contentionscope : int) return int;
428    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
429
430    function pthread_attr_setinheritsched
431      (attr         : access pthread_attr_t;
432       inheritsched : int) return int;
433    pragma Import (C, pthread_attr_setinheritsched);
434
435    function pthread_attr_setschedpolicy
436      (attr   : access pthread_attr_t;
437       policy : int) return int;
438    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
439
440    function sched_yield return int;
441    pragma Inline (sched_yield);
442    --  FSU_THREADS does not have 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 Inline (pthread_attr_setdetachstate);
459    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
460
461    function pthread_attr_setstacksize
462      (attr      : access pthread_attr_t;
463       stacksize : size_t) return int;
464    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
465
466    function pthread_create
467      (thread        : access pthread_t;
468       attributes    : access pthread_attr_t;
469       start_routine : Thread_Body;
470       arg           : System.Address) 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 Inline (pthread_getspecific);
490    --  FSU_THREADS has a nonstandard pthread_getspecific
491
492    type destructor_pointer is access 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 array (0 .. 31) of unsigned_long;
502    pragma Convention (C, sigset_t);
503    --  This is for GNU libc version 2 but should be backward compatible with
504    --  other libc where sigset_t is smaller.
505
506    type pid_t is new int;
507
508    type time_t is new long;
509
510    type timespec is record
511       tv_sec  : time_t;
512       tv_nsec : long;
513    end record;
514    pragma Convention (C, timespec);
515
516    type clockid_t is new int;
517    CLOCK_REALTIME : constant clockid_t := 0;
518
519    type struct_timeval is record
520       tv_sec  : long;
521       tv_usec : long;
522    end record;
523    pragma Convention (C, struct_timeval);
524
525    type pthread_attr_t is record
526       flags           : int;
527       stacksize       : int;
528       contentionscope : int;
529       inheritsched    : int;
530       detachstate     : int;
531       sched           : int;
532       prio            : int;
533       starttime       : timespec;
534       deadline        : timespec;
535       period          : timespec;
536    end record;
537    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
538
539    type pthread_condattr_t is record
540       flags : int;
541    end record;
542    pragma Convention (C, pthread_condattr_t);
543
544    type pthread_mutexattr_t is record
545       flags        : int;
546       prio_ceiling : int;
547       protocol     : int;
548    end record;
549    pragma Convention (C, pthread_mutexattr_t);
550
551    type sigjmp_buf is array (Integer range 0 .. 38) of int;
552
553    type pthread_t_struct is record
554       context    : sigjmp_buf;
555       pbody      : sigjmp_buf;
556       errno      : int;
557       ret        : int;
558       stack_base : System.Address;
559    end record;
560    pragma Convention (C, pthread_t_struct);
561
562    type pthread_t is access all pthread_t_struct;
563
564    type queue_t is record
565       head : System.Address;
566       tail : System.Address;
567    end record;
568    pragma Convention (C, queue_t);
569
570    type pthread_mutex_t is record
571       queue                 : queue_t;
572       lock                  : plain_char;
573       owner                 : System.Address;
574       flags                 : int;
575       prio_ceiling          : int;
576       protocol              : int;
577       prev_max_ceiling_prio : int;
578    end record;
579    pragma Convention (C, pthread_mutex_t);
580
581    type pthread_cond_t is record
582       queue        : queue_t;
583       flags        : int;
584       waiters      : int;
585       mutex        : System.Address;
586    end record;
587    pragma Convention (C, pthread_cond_t);
588
589    type pthread_key_t is new int;
590
591 end System.OS_Interface;