OSDN Git Service

PR c++/27714
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-linux-alpha.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-2006, 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,  51  Franklin  Street,  Fifth  Floor, --
21 -- Boston, MA 02110-1301, 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 (GNU/LinuxThreads) 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 ("-lpthread");
50
51    subtype int            is Interfaces.C.int;
52    subtype char           is Interfaces.C.char;
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 := 35;
70    EINTR     : constant := 4;
71    EINVAL    : constant := 22;
72    ENOMEM    : constant := 12;
73    EPERM     : constant := 1;
74    ETIMEDOUT : constant := 60;
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    SIGFPE     : constant := 8; --  floating point exception
92    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
93    SIGBUS     : constant := 10; --  bus error
94    SIGSEGV    : constant := 11; --  segmentation violation
95    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
96    SIGALRM    : constant := 14; --  alarm clock
97    SIGTERM    : constant := 15; --  software termination signal from kill
98    SIGURG     : constant := 16; --  urgent condition on IO channel
99    SIGSTOP    : constant := 17; --  stop (cannot be caught or ignored)
100    SIGTSTP    : constant := 18; --  user stop requested from tty
101    SIGCONT    : constant := 19; --  stopped process has been continued
102    SIGCLD     : constant := 20; --  alias for SIGCHLD
103    SIGCHLD    : constant := 20; --  child status change
104    SIGTTIN    : constant := 21; --  background tty read attempted
105    SIGTTOU    : constant := 22; --  background tty write attempted
106    SIGIO      : constant := 23; --  I/O now possible (4.2 BSD)
107    SIGPOLL    : constant := 23; --  pollable event occurred
108    SIGXCPU    : constant := 24; --  CPU time limit exceeded
109    SIGXFSZ    : constant := 25; --  filesize limit exceeded
110    SIGVTALRM  : constant := 26; --  virtual timer expired
111    SIGPROF    : constant := 27; --  profiling timer expired
112    SIGWINCH   : constant := 28; --  window size change
113    SIGPWR     : constant := 29; --  power-fail restart
114    SIGUSR1    : constant := 30; --  user defined signal 1
115    SIGUSR2    : constant := 31; --  user defined signal 2
116
117    SIGLTHRRES : constant := 32; --  GNU/LinuxThreads restart signal
118    SIGLTHRCAN : constant := 33; --  GNU/LinuxThreads cancel signal
119    SIGLTHRDBG : constant := 34; --  GNU/LinuxThreads debugger signal
120
121    SIGADAABORT : constant := SIGABRT;
122    --  Change this if you want to use another signal for task abort.
123    --  SIGTERM might be a good one.
124
125    SIGUNUSED  : constant := 0;
126    SIGSTKFLT  : constant := 0;
127    SIGLOST    : constant := 0;
128    --  These don't exist for Linux/Alpha.  The constants are present
129    --  so that we can continue to use a-intnam-linux.ads.
130
131    type Signal_Set is array (Natural range <>) of Signal;
132
133    Unmasked    : constant Signal_Set := (
134       SIGTRAP,
135       --  To enable debugging on multithreaded applications, mark SIGTRAP to
136       --  be kept unmasked.
137
138       SIGBUS,
139
140       SIGTTIN, SIGTTOU, SIGTSTP,
141       --  Keep these three signals unmasked so that background processes
142       --  and IO behaves as normal "C" applications
143
144       SIGPROF,
145       --  To avoid confusing the profiler
146
147       SIGKILL, SIGSTOP,
148       --  These two signals actually cannot be masked;
149       --  POSIX simply won't allow it.
150
151       SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
152       --  These three signals are used by GNU/LinuxThreads starting from
153       --  glibc 2.1 (future 2.2).
154
155    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
156
157    type sigset_t is private;
158
159    function sigaddset (set : access sigset_t; sig : Signal) return int;
160    pragma Import (C, sigaddset, "sigaddset");
161
162    function sigdelset (set : access sigset_t; sig : Signal) return int;
163    pragma Import (C, sigdelset, "sigdelset");
164
165    function sigfillset (set : access sigset_t) return int;
166    pragma Import (C, sigfillset, "sigfillset");
167
168    function sigismember (set : access sigset_t; sig : Signal) return int;
169    pragma Import (C, sigismember, "sigismember");
170
171    function sigemptyset (set : access sigset_t) return int;
172    pragma Import (C, sigemptyset, "sigemptyset");
173
174    type union_type_3 is new String (1 .. 116);
175    type siginfo_t is record
176       si_signo : int;
177       si_code  : int;
178       si_errno : int;
179       X_data   : union_type_3;
180    end record;
181    pragma Convention (C, siginfo_t);
182
183    type struct_sigaction is record
184       sa_handler   : System.Address;
185       sa_mask      : sigset_t;
186       sa_flags     : unsigned_long;
187    end record;
188    pragma Convention (C, struct_sigaction);
189    type struct_sigaction_ptr is access all struct_sigaction;
190
191    type Machine_State is record
192      dummy : unsigned_long;
193    end record;
194    type Machine_State_Ptr is access all Machine_State;
195
196    SA_SIGINFO  : constant := 16#40#;
197
198    SIG_BLOCK   : constant := 0;
199    SIG_UNBLOCK : constant := 1;
200    SIG_SETMASK : constant := 2;
201
202    SIG_DFL : constant := 0;
203    SIG_IGN : constant := 1;
204
205    function sigaction
206      (sig  : Signal;
207       act  : struct_sigaction_ptr;
208       oact : struct_sigaction_ptr) return int;
209    pragma Import (C, sigaction, "sigaction");
210
211    ----------
212    -- Time --
213    ----------
214
215    type timespec is private;
216
217    function To_Duration (TS : timespec) return Duration;
218    pragma Inline (To_Duration);
219
220    function To_Timespec (D : Duration) return timespec;
221    pragma Inline (To_Timespec);
222
223    type struct_timeval is private;
224
225    function To_Duration (TV : struct_timeval) return Duration;
226    pragma Inline (To_Duration);
227
228    function To_Timeval (D : Duration) return struct_timeval;
229    pragma Inline (To_Timeval);
230
231    function gettimeofday
232      (tv : access struct_timeval;
233       tz : System.Address := System.Null_Address) return int;
234    pragma Import (C, gettimeofday, "gettimeofday");
235
236    function sysconf (name : int) return long;
237    pragma Import (C, sysconf);
238
239    SC_CLK_TCK : constant := 2;
240
241    -------------------------
242    -- Priority Scheduling --
243    -------------------------
244
245    SCHED_OTHER : constant := 0;
246    SCHED_FIFO  : constant := 1;
247    SCHED_RR    : constant := 2;
248
249    -------------
250    -- Process --
251    -------------
252
253    type pid_t is private;
254
255    function kill (pid : pid_t; sig : Signal) return int;
256    pragma Import (C, kill, "kill");
257
258    function getpid return pid_t;
259    pragma Import (C, getpid, "getpid");
260
261    -------------
262    -- Threads --
263    -------------
264
265    type Thread_Body is access
266      function (arg : System.Address) return System.Address;
267
268    function Thread_Body_Access is new
269      Unchecked_Conversion (System.Address, Thread_Body);
270
271    type pthread_t is new unsigned_long;
272    subtype Thread_Id        is pthread_t;
273
274    function To_pthread_t is new Unchecked_Conversion
275      (unsigned_long, pthread_t);
276
277    type pthread_mutex_t     is limited private;
278    type pthread_cond_t      is limited private;
279    type pthread_attr_t      is limited private;
280    type pthread_mutexattr_t is limited private;
281    type pthread_condattr_t  is limited private;
282    type pthread_key_t       is private;
283
284    PTHREAD_CREATE_DETACHED : constant := 1;
285
286    -----------
287    -- Stack --
288    -----------
289
290    function Get_Stack_Base (thread : pthread_t) return Address;
291    pragma Inline (Get_Stack_Base);
292    --  This is a dummy procedure to share some GNULLI files
293
294    ---------------------------------------
295    -- Nonstandard Thread Initialization --
296    ---------------------------------------
297
298    procedure pthread_init;
299    pragma Inline (pthread_init);
300    --  This is a dummy procedure to share some GNULLI files
301
302    -------------------------
303    -- POSIX.1c  Section 3 --
304    -------------------------
305
306    function sigwait (set : access sigset_t; sig : access Signal) return int;
307    pragma Import (C, sigwait, "sigwait");
308
309    function pthread_kill (thread : pthread_t; sig : Signal) return int;
310    pragma Import (C, pthread_kill, "pthread_kill");
311
312    function pthread_sigmask
313      (how  : int;
314       set  : access sigset_t;
315       oset : access sigset_t) return int;
316    pragma Import (C, pthread_sigmask, "pthread_sigmask");
317
318    --------------------------
319    -- POSIX.1c  Section 11 --
320    --------------------------
321
322    function pthread_mutexattr_init
323      (attr : access pthread_mutexattr_t) return int;
324    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
325
326    function pthread_mutexattr_destroy
327      (attr : access pthread_mutexattr_t) return int;
328    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
329
330    function pthread_mutex_init
331      (mutex : access pthread_mutex_t;
332       attr  : access pthread_mutexattr_t) return int;
333    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
334
335    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
336    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
337
338    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
339    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
340
341    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
342    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
343
344    function pthread_condattr_init
345      (attr : access pthread_condattr_t) return int;
346    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
347
348    function pthread_condattr_destroy
349      (attr : access pthread_condattr_t) return int;
350    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
351
352    function pthread_cond_init
353      (cond : access pthread_cond_t;
354       attr : access pthread_condattr_t) return int;
355    pragma Import (C, pthread_cond_init, "pthread_cond_init");
356
357    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
358    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
359
360    function pthread_cond_signal (cond : access pthread_cond_t) return int;
361    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
362
363    function pthread_cond_wait
364      (cond  : access pthread_cond_t;
365       mutex : access pthread_mutex_t) return int;
366    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
367
368    function pthread_cond_timedwait
369      (cond    : access pthread_cond_t;
370       mutex   : access pthread_mutex_t;
371       abstime : access timespec) return int;
372    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
373
374    --------------------------
375    -- POSIX.1c  Section 13 --
376    --------------------------
377
378    type struct_sched_param is record
379       sched_priority : int;  --  scheduling priority
380    end record;
381    pragma Convention (C, struct_sched_param);
382
383    function pthread_setschedparam
384      (thread : pthread_t;
385       policy : int;
386       param  : access struct_sched_param) return int;
387    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
388
389    function pthread_attr_setschedpolicy
390      (attr   : access pthread_attr_t;
391       policy : int) return int;
392    pragma Import
393      (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
394
395    function sched_yield return int;
396    pragma Import (C, sched_yield, "sched_yield");
397
398    ---------------------------
399    -- P1003.1c - Section 16 --
400    ---------------------------
401
402    function pthread_attr_init
403      (attributes : access pthread_attr_t) return int;
404    pragma Import (C, pthread_attr_init, "pthread_attr_init");
405
406    function pthread_attr_destroy
407      (attributes : access pthread_attr_t) return int;
408    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
409
410    function pthread_attr_setdetachstate
411      (attr        : access pthread_attr_t;
412       detachstate : int) return int;
413    pragma Import
414      (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
415
416    function pthread_attr_setstacksize
417      (attr      : access pthread_attr_t;
418       stacksize : size_t) return int;
419    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
420
421    function pthread_create
422      (thread        : access pthread_t;
423       attributes    : access pthread_attr_t;
424       start_routine : Thread_Body;
425       arg           : System.Address) return int;
426    pragma Import (C, pthread_create, "pthread_create");
427
428    procedure pthread_exit (status : System.Address);
429    pragma Import (C, pthread_exit, "pthread_exit");
430
431    function pthread_self return pthread_t;
432    pragma Import (C, pthread_self, "pthread_self");
433
434    --------------------------
435    -- POSIX.1c  Section 17 --
436    --------------------------
437
438    function pthread_setspecific
439      (key   : pthread_key_t;
440       value : System.Address) return int;
441    pragma Import (C, pthread_setspecific, "pthread_setspecific");
442
443    function pthread_getspecific (key : pthread_key_t) return System.Address;
444    pragma Import (C, pthread_getspecific, "pthread_getspecific");
445
446    type destructor_pointer is access procedure (arg : System.Address);
447
448    function pthread_key_create
449      (key        : access pthread_key_t;
450       destructor : destructor_pointer) return int;
451    pragma Import (C, pthread_key_create, "pthread_key_create");
452
453 private
454
455    type sigset_t is record
456       dum0, dum1, dum2, dum3, dum4, dum5, dum6, dum7 : unsigned_long;
457       dum8, dum9, dum10, dum11, dum12, dum13, dum14, dum15 : unsigned_long;
458    end record;
459    pragma Convention (C, sigset_t);
460
461    type pid_t is new int;
462
463    type time_t is new long;
464
465    type timespec is record
466       tv_sec  : time_t;
467       tv_nsec : long;
468    end record;
469    pragma Convention (C, timespec);
470
471    type struct_timeval is record
472       tv_sec  : time_t;
473       tv_usec : time_t;
474    end record;
475    pragma Convention (C, struct_timeval);
476
477    type pthread_attr_t is record
478       dum0, dum1, dum2, dum3, dum4, dum5, dum6 : unsigned_long;
479    end record;
480    pragma Convention (C, pthread_attr_t);
481
482    type pthread_condattr_t is record
483       dummy : int;
484    end record;
485    pragma Convention (C, pthread_condattr_t);
486
487    type pthread_mutexattr_t is record
488       mutexkind : int;
489    end record;
490    pragma Convention (C, pthread_mutexattr_t);
491
492    type pthread_mutex_t is record
493       dum0, dum1, dum2, dum3, dum4 : unsigned_long;
494    end record;
495    pragma Convention (C, pthread_mutex_t);
496
497    type pthread_cond_t is record
498       dum0, dum1, dum2, dum3, dum4, dum5 : unsigned_long;
499    end record;
500    pragma Convention (C, pthread_cond_t);
501
502    type pthread_key_t is new unsigned;
503
504 end System.OS_Interface;