OSDN Git Service

Patch to fix -mcpu=G5 interface to EH runtime library.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-linux-fsu.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-1994, Florida State University            --
10 --             Copyright (C) 1995-2004, 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.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a GNU/Linux (FSU THREADS) version of this package.
36
37 --  This package encapsulates all direct interfaces to OS services
38 --  that are needed by children of System.
39
40 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
42
43 with Interfaces.C;
44 with Unchecked_Conversion;
45
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-lgthreads");
50    pragma Linker_Options ("-lmalloc");
51
52    subtype int            is Interfaces.C.int;
53    subtype short          is Interfaces.C.short;
54    subtype long           is Interfaces.C.long;
55    subtype unsigned       is Interfaces.C.unsigned;
56    subtype unsigned_short is Interfaces.C.unsigned_short;
57    subtype unsigned_long  is Interfaces.C.unsigned_long;
58    subtype unsigned_char  is Interfaces.C.unsigned_char;
59    subtype plain_char     is Interfaces.C.plain_char;
60    subtype size_t         is Interfaces.C.size_t;
61
62    -----------
63    -- Errno --
64    -----------
65
66    function errno return int;
67    pragma Import (C, errno, "__get_errno");
68
69    EAGAIN    : constant := 11;
70    EINTR     : constant := 4;
71    EINVAL    : constant := 22;
72    ENOMEM    : constant := 12;
73    ETIMEDOUT : constant := 110;
74
75    -------------
76    -- Signals --
77    -------------
78
79    Max_Interrupt : constant := 31;
80    type Signal is new int range 0 .. Max_Interrupt;
81    for Signal'Size use int'Size;
82
83    SIGHUP     : constant := 1; --  hangup
84    SIGINT     : constant := 2; --  interrupt (rubout)
85    SIGQUIT    : constant := 3; --  quit (ASCD FS)
86    SIGILL     : constant := 4; --  illegal instruction (not reset)
87    SIGTRAP    : constant := 5; --  trace trap (not reset)
88    SIGIOT     : constant := 6; --  IOT instruction
89    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
90    SIGFPE     : constant := 8; --  floating point exception
91    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
92    SIGBUS     : constant := 7; --  bus error
93    SIGSEGV    : constant := 11; --  segmentation violation
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 := 10; --  user defined signal 1
98    SIGUSR2    : constant := 12; --  user defined signal 2
99    SIGCLD     : constant := 17; --  alias for SIGCHLD
100    SIGCHLD    : constant := 17; --  child status change
101    SIGPWR     : constant := 30; --  power-fail restart
102    SIGWINCH   : constant := 28; --  window size change
103    SIGURG     : constant := 23; --  urgent condition on IO channel
104    SIGPOLL    : constant := 29; --  pollable event occurred
105    SIGIO      : constant := 29; --  I/O now possible (4.2 BSD)
106    SIGLOST    : constant := 29; --  File lock lost
107    SIGSTOP    : constant := 19; --  stop (cannot be caught or ignored)
108    SIGTSTP    : constant := 20; --  user stop requested from tty
109    SIGCONT    : constant := 18; --  stopped process has been continued
110    SIGTTIN    : constant := 21; --  background tty read attempted
111    SIGTTOU    : constant := 22; --  background tty write attempted
112    SIGVTALRM  : constant := 26; --  virtual timer expired
113    SIGPROF    : constant := 27; --  profiling timer expired
114    SIGXCPU    : constant := 24; --  CPU time limit exceeded
115    SIGXFSZ    : constant := 25; --  filesize limit exceeded
116    SIGUNUSED  : constant := 31; --  unused signal (GNU/Linux)
117    SIGSTKFLT  : constant := 16; --  coprocessor stack fault (GNU/Linux)
118
119    SIGADAABORT : constant := SIGABRT;
120    --  Change this if you want to use another signal for task abort.
121    --  SIGTERM might be a good one.
122
123    type Signal_Set is array (Natural range <>) of Signal;
124
125    Unmasked    : constant Signal_Set :=
126      (SIGTRAP, SIGBUS, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
127
128    Reserved    : constant Signal_Set :=
129      (SIGKILL, SIGSTOP, SIGALRM, SIGVTALRM, SIGUNUSED);
130
131    type sigset_t is private;
132
133    function sigaddset (set : access sigset_t; sig : Signal) return int;
134    pragma Import (C, sigaddset, "sigaddset");
135
136    function sigdelset (set : access sigset_t; sig : Signal) return int;
137    pragma Import (C, sigdelset, "sigdelset");
138
139    function sigfillset (set : access sigset_t) return int;
140    pragma Import (C, sigfillset, "sigfillset");
141
142    function sigismember (set : access sigset_t; sig : Signal) return int;
143    pragma Import (C, sigismember, "sigismember");
144
145    function sigemptyset (set : access sigset_t) return int;
146    pragma Import (C, sigemptyset, "sigemptyset");
147
148    type struct_sigaction is record
149       sa_handler  : System.Address;
150       sa_mask     : sigset_t;
151       sa_flags    : unsigned_long;
152       sa_restorer : System.Address;
153    end record;
154    pragma Convention (C, struct_sigaction);
155    type struct_sigaction_ptr is access all struct_sigaction;
156
157    type Machine_State is record
158       eip : unsigned_long;
159       ebx : unsigned_long;
160       esp : unsigned_long;
161       ebp : unsigned_long;
162       esi : unsigned_long;
163       edi : unsigned_long;
164    end record;
165    type Machine_State_Ptr is access all Machine_State;
166
167    SA_SIGINFO  : constant := 16#04#;
168
169    SIG_BLOCK   : constant := 0;
170    SIG_UNBLOCK : constant := 1;
171    SIG_SETMASK : constant := 2;
172
173    SIG_DFL : constant := 0;
174    SIG_IGN : constant := 1;
175
176    function sigaction
177      (sig  : Signal;
178       act  : struct_sigaction_ptr;
179       oact : struct_sigaction_ptr) return int;
180    pragma Import (C, sigaction, "sigaction");
181
182    ----------
183    -- Time --
184    ----------
185
186    Time_Slice_Supported : constant Boolean := False;
187    --  Indicates wether time slicing is supported (i.e FSU threads have been
188    --  compiled with DEF_RR)
189
190    type timespec is private;
191
192    type clockid_t is private;
193
194    CLOCK_REALTIME : constant clockid_t;
195
196    function clock_gettime
197      (clock_id : clockid_t;
198       tp       : access timespec) return int;
199    pragma Import (C, clock_gettime, "clock_gettime");
200
201    function To_Duration (TS : timespec) return Duration;
202    pragma Inline (To_Duration);
203
204    function To_Timespec (D : Duration) return timespec;
205    pragma Inline (To_Timespec);
206
207    type struct_timeval is private;
208
209    function To_Duration (TV : struct_timeval) return Duration;
210    pragma Inline (To_Duration);
211
212    function To_Timeval (D : Duration) return struct_timeval;
213    pragma Inline (To_Timeval);
214
215    -------------------------
216    -- Priority Scheduling --
217    -------------------------
218
219    SCHED_FIFO  : constant := 0;
220    SCHED_RR    : constant := 1;
221    SCHED_OTHER : constant := 2;
222
223    -------------
224    -- Process --
225    -------------
226
227    type pid_t is private;
228
229    function kill (pid : pid_t; sig : Signal) return int;
230    pragma Import (C, kill, "kill");
231
232    function getpid return pid_t;
233    pragma Import (C, getpid, "getpid");
234
235    ---------
236    -- LWP --
237    ---------
238
239    function lwp_self return System.Address;
240    --  lwp_self does not exist on this thread library, revert to pthread_self
241    --  which is the closest approximation (with getpid). This function is
242    --  needed to share 7staprop.adb across POSIX-like targets.
243    pragma Import (C, lwp_self, "pthread_self");
244
245    -------------
246    -- Threads --
247    -------------
248
249    type Thread_Body is access
250      function (arg : System.Address) return System.Address;
251
252    function Thread_Body_Access is new
253      Unchecked_Conversion (System.Address, Thread_Body);
254
255    type pthread_t           is private;
256    subtype Thread_Id        is pthread_t;
257
258    type pthread_mutex_t     is limited private;
259    type pthread_cond_t      is limited private;
260    type pthread_attr_t      is limited private;
261    type pthread_mutexattr_t is limited private;
262    type pthread_condattr_t  is limited private;
263    type pthread_key_t       is private;
264
265    PTHREAD_CREATE_DETACHED : constant := 1;
266
267    -----------
268    -- Stack --
269    -----------
270
271    Stack_Base_Available : constant Boolean := False;
272    --  Indicates wether the stack base is available on this target.
273    --  This allows us to share s-osinte.adb between all the FSU run time.
274    --  Note that this value can only be true if pthread_t has a complete
275    --  definition that corresponds exactly to the C header files.
276
277    function Get_Stack_Base (thread : pthread_t) return Address;
278    pragma Inline (Get_Stack_Base);
279    --  returns the stack base of the specified thread.
280    --  Only call this function when Stack_Base_Available is True.
281
282    function Get_Page_Size return size_t;
283    function Get_Page_Size return Address;
284    pragma Import (C, Get_Page_Size, "getpagesize");
285    --  returns the size of a page, or 0 if this is not relevant on this
286    --  target
287
288    PROT_NONE  : constant := 0;
289    PROT_READ  : constant := 1;
290    PROT_WRITE : constant := 2;
291    PROT_EXEC  : constant := 4;
292    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
293
294    PROT_ON    : constant := PROT_NONE;
295    PROT_OFF   : constant := PROT_ALL;
296
297    function mprotect (addr : Address; len : size_t; prot : int) return int;
298    pragma Import (C, mprotect);
299
300    ---------------------------------------
301    -- Nonstandard Thread Initialization --
302    ---------------------------------------
303
304    procedure pthread_init;
305    --  FSU_THREADS requires pthread_init, which is nonstandard
306    --  and this should be invoked during the elaboration of s-taprop.adb
307    pragma Import (C, pthread_init, "pthread_init");
308
309    -------------------------
310    -- POSIX.1c  Section 3 --
311    -------------------------
312
313    function sigwait
314      (set : access sigset_t;
315       sig : access Signal) return int;
316    pragma Inline (sigwait);
317    --  FSU_THREADS has a nonstandard sigwait
318
319    function pthread_kill
320      (thread : pthread_t;
321       sig    : Signal) return int;
322    pragma Import (C, pthread_kill, "pthread_kill");
323
324    --  FSU threads does not have pthread_sigmask. Instead, it uses
325    --  sigprocmask to do the signal handling when the thread library is
326    --  sucked in.
327
328    type sigset_t_ptr is access all sigset_t;
329
330    function pthread_sigmask
331      (how  : int;
332       set  : sigset_t_ptr;
333       oset : sigset_t_ptr) return int;
334    pragma Import (C, pthread_sigmask, "sigprocmask");
335
336    --------------------------
337    -- POSIX.1c  Section 11 --
338    --------------------------
339
340    function pthread_mutexattr_init
341      (attr : access pthread_mutexattr_t) return int;
342    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
343
344    function pthread_mutexattr_destroy
345      (attr : access pthread_mutexattr_t) return int;
346    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
347
348    function pthread_mutex_init
349      (mutex : access pthread_mutex_t;
350       attr  : access pthread_mutexattr_t) return int;
351    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
352
353    function pthread_mutex_destroy
354      (mutex : access pthread_mutex_t) return  int;
355    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
356
357    function pthread_mutex_lock
358      (mutex : access pthread_mutex_t) return int;
359    pragma Inline (pthread_mutex_lock);
360    --  FSU_THREADS has nonstandard pthread_mutex_lock
361
362    function pthread_mutex_unlock
363      (mutex : access pthread_mutex_t) return int;
364    pragma Inline (pthread_mutex_unlock);
365    --  FSU_THREADS has nonstandard pthread_mutex_lock
366
367    function pthread_condattr_init
368      (attr : access pthread_condattr_t) return int;
369    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
370
371    function pthread_condattr_destroy
372      (attr : access pthread_condattr_t) return int;
373    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
374
375    function pthread_cond_init
376      (cond : access pthread_cond_t;
377       attr : access pthread_condattr_t) return int;
378    pragma Import (C, pthread_cond_init, "pthread_cond_init");
379
380    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
381    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
382
383    function pthread_cond_signal (cond : access pthread_cond_t) return int;
384    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
385
386    function pthread_cond_wait
387      (cond  : access pthread_cond_t;
388       mutex : access pthread_mutex_t) return int;
389    pragma Inline (pthread_cond_wait);
390    --  FSU_THREADS has a nonstandard pthread_cond_wait
391
392    function pthread_cond_timedwait
393      (cond    : access pthread_cond_t;
394       mutex   : access pthread_mutex_t;
395       abstime : access timespec) return int;
396    pragma Inline (pthread_cond_timedwait);
397    --  FSU_THREADS has a nonstandard pthread_cond_timedwait
398
399    Relative_Timed_Wait : constant Boolean := False;
400    --  pthread_cond_timedwait requires an absolute delay time
401
402    --------------------------
403    -- POSIX.1c  Section 13 --
404    --------------------------
405
406    PTHREAD_PRIO_NONE    : constant := 0;
407    PTHREAD_PRIO_PROTECT : constant := 2;
408    PTHREAD_PRIO_INHERIT : constant := 1;
409
410    function pthread_mutexattr_setprotocol
411      (attr     : access pthread_mutexattr_t;
412       protocol : int) return int;
413    pragma Import (C, pthread_mutexattr_setprotocol);
414
415    function pthread_mutexattr_setprioceiling
416      (attr        : access pthread_mutexattr_t;
417       prioceiling : int) return int;
418    pragma Import
419      (C, pthread_mutexattr_setprioceiling,
420       "pthread_mutexattr_setprio_ceiling");
421
422    type struct_sched_param is record
423       sched_priority : int;  --  scheduling priority
424    end record;
425
426    function pthread_setschedparam
427      (thread : pthread_t;
428       policy : int;
429       param  : access struct_sched_param) return int;
430    pragma Inline (pthread_setschedparam);
431    --  FSU_THREADS does not have pthread_setschedparam
432
433    function pthread_attr_setscope
434      (attr            : access pthread_attr_t;
435       contentionscope : int) return int;
436    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
437
438    function pthread_attr_setinheritsched
439      (attr         : access pthread_attr_t;
440       inheritsched : int) return int;
441    pragma Import (C, pthread_attr_setinheritsched);
442
443    function pthread_attr_setschedpolicy
444      (attr   : access pthread_attr_t;
445       policy : int) return int;
446    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
447
448    function sched_yield return int;
449    pragma Inline (sched_yield);
450    --  FSU_THREADS does not have sched_yield;
451
452    ---------------------------
453    -- P1003.1c - Section 16 --
454    ---------------------------
455
456    function pthread_attr_init (attributes : access pthread_attr_t) return int;
457    pragma Import (C, pthread_attr_init, "pthread_attr_init");
458
459    function pthread_attr_destroy
460      (attributes : access pthread_attr_t) return int;
461    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
462
463    function pthread_attr_setdetachstate
464      (attr        : access pthread_attr_t;
465       detachstate : int) return int;
466    pragma Inline (pthread_attr_setdetachstate);
467    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
468
469    function pthread_attr_setstacksize
470      (attr      : access pthread_attr_t;
471       stacksize : size_t) return int;
472    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
473
474    function pthread_create
475      (thread        : access pthread_t;
476       attributes    : access pthread_attr_t;
477       start_routine : Thread_Body;
478       arg           : System.Address) return int;
479    pragma Import (C, pthread_create, "pthread_create");
480
481    procedure pthread_exit (status : System.Address);
482    pragma Import (C, pthread_exit, "pthread_exit");
483
484    function pthread_self return pthread_t;
485    pragma Import (C, pthread_self, "pthread_self");
486
487    --------------------------
488    -- POSIX.1c  Section 17 --
489    --------------------------
490
491    function pthread_setspecific
492      (key   : pthread_key_t;
493       value : System.Address) return int;
494    pragma Import (C, pthread_setspecific, "pthread_setspecific");
495
496    function pthread_getspecific (key : pthread_key_t) return System.Address;
497    pragma Inline (pthread_getspecific);
498    --  FSU_THREADS has a nonstandard pthread_getspecific
499
500    type destructor_pointer is access procedure (arg : System.Address);
501
502    function pthread_key_create
503      (key        : access pthread_key_t;
504       destructor : destructor_pointer) return int;
505    pragma Import (C, pthread_key_create, "pthread_key_create");
506
507 private
508
509    type sigset_t is array (0 .. 31) of unsigned_long;
510    pragma Convention (C, sigset_t);
511    --  This is for GNU libc version 2 but should be backward compatible with
512    --  other libc where sigset_t is smaller.
513
514    type pid_t is new int;
515
516    type time_t is new long;
517
518    type timespec is record
519       tv_sec  : time_t;
520       tv_nsec : long;
521    end record;
522    pragma Convention (C, timespec);
523
524    type clockid_t is new int;
525    CLOCK_REALTIME : constant clockid_t := 0;
526
527    type struct_timeval is record
528       tv_sec  : long;
529       tv_usec : long;
530    end record;
531    pragma Convention (C, struct_timeval);
532
533    type pthread_attr_t is record
534       flags           : int;
535       stacksize       : int;
536       contentionscope : int;
537       inheritsched    : int;
538       detachstate     : int;
539       sched           : int;
540       prio            : int;
541       starttime       : timespec;
542       deadline        : timespec;
543       period          : timespec;
544    end record;
545    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
546
547    type pthread_condattr_t is record
548       flags : int;
549    end record;
550    pragma Convention (C, pthread_condattr_t);
551
552    type pthread_mutexattr_t is record
553       flags        : int;
554       prio_ceiling : int;
555       protocol     : int;
556    end record;
557    pragma Convention (C, pthread_mutexattr_t);
558
559    type sigjmp_buf is array (Integer range 0 .. 38) of int;
560
561    type pthread_t_struct is record
562       context    : sigjmp_buf;
563       pbody      : sigjmp_buf;
564       errno      : int;
565       ret        : int;
566       stack_base : System.Address;
567    end record;
568    pragma Convention (C, pthread_t_struct);
569
570    type pthread_t is access all pthread_t_struct;
571
572    type queue_t is record
573       head : System.Address;
574       tail : System.Address;
575    end record;
576    pragma Convention (C, queue_t);
577
578    type pthread_mutex_t is record
579       queue                 : queue_t;
580       lock                  : plain_char;
581       owner                 : System.Address;
582       flags                 : int;
583       prio_ceiling          : int;
584       protocol              : int;
585       prev_max_ceiling_prio : int;
586    end record;
587    pragma Convention (C, pthread_mutex_t);
588
589    type pthread_cond_t is record
590       queue        : queue_t;
591       flags        : int;
592       waiters      : int;
593       mutex        : System.Address;
594    end record;
595    pragma Convention (C, pthread_cond_t);
596
597    type pthread_key_t is new int;
598
599 end System.OS_Interface;