OSDN Git Service

2007-06-11 Bob Duff <duff@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-linux-hppa.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 --                          (GNU/Linux-HPPA Version)                        --
9 --                                                                          --
10 --             Copyright (C) 1991-1994, Florida State University            --
11 --             Copyright (C) 1995-2007, Free Software Foundation, Inc.      --
12 --                                                                          --
13 -- GNARL is free software; you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
21 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
22 -- Boston, MA 02110-1301, USA.                                              --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNARL was developed by the GNARL team at Florida State University.       --
32 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 --  This is a GNU/Linux (GNU/LinuxThreads) 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 or remove the pragma
42 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
43
44 with Interfaces.C;
45 with Ada.Unchecked_Conversion;
46
47 package System.OS_Interface is
48    pragma Preelaborate;
49
50    pragma Linker_Options ("-lpthread");
51
52    subtype int            is Interfaces.C.int;
53    subtype char           is Interfaces.C.char;
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    EPERM     : constant := 1;
75    ETIMEDOUT : constant := 238;
76
77    -------------
78    -- Signals --
79    -------------
80
81    Max_Interrupt : constant := 63;
82    type Signal is new int range 0 .. Max_Interrupt;
83    for Signal'Size use int'Size;
84
85    SIGHUP     : constant := 1; --  hangup
86    SIGINT     : constant := 2; --  interrupt (rubout)
87    SIGQUIT    : constant := 3; --  quit (ASCD FS)
88    SIGILL     : constant := 4; --  illegal instruction (not reset)
89    SIGTRAP    : constant := 5; --  trace trap (not reset)
90    SIGIOT     : constant := 6; --  IOT instruction
91    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
92    SIGEMT     : constant := 7; --  EMT
93    SIGFPE     : constant := 8; --  floating point exception
94    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
95    SIGBUS     : constant := 10; --  bus error
96    SIGSEGV    : constant := 11; --  segmentation violation
97    SIGSYS     : constant := 12; --  bad system call
98    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
99    SIGALRM    : constant := 14; --  alarm clock
100    SIGTERM    : constant := 15; --  software termination signal from kill
101    SIGUSR1    : constant := 16; --  user defined signal 1
102    SIGUSR2    : constant := 17; --  user defined signal 2
103    SIGCLD     : constant := 18; --  alias for SIGCHLD
104    SIGCHLD    : constant := 18; --  child status change
105    SIGPWR     : constant := 19; --  power-fail restart
106    SIGVTALRM  : constant := 20; --  virtual timer expired
107    SIGPROF    : constant := 21; --  profiling timer expired
108    SIGPOLL    : constant := 22; --  pollable event occurred
109    SIGIO      : constant := 22; --  I/O now possible (4.2 BSD)
110    SIGWINCH   : constant := 23; --  window size change
111    SIGSTOP    : constant := 24; --  stop (cannot be caught or ignored)
112    SIGTSTP    : constant := 25; --  user stop requested from tty
113    SIGCONT    : constant := 26; --  stopped process has been continued
114    SIGTTIN    : constant := 27; --  background tty read attempted
115    SIGTTOU    : constant := 28; --  background tty write attempted
116    SIGURG     : constant := 29; --  urgent condition on IO channel
117    SIGLOST    : constant := 30; --  File lock lost
118    SIGUNUSED  : constant := 31; --  unused signal (GNU/Linux)
119    SIGXCPU    : constant := 33; --  CPU time limit exceeded
120    SIGXFSZ    : constant := 34; --  filesize limit exceeded
121    SIGSTKFLT  : constant := 36; --  coprocessor stack fault (Linux)
122    SIGLTHRRES : constant := 37; --  GNU/LinuxThreads restart signal
123    SIGLTHRCAN : constant := 38; --  GNU/LinuxThreads cancel signal
124    SIGLTHRDBG : constant := 39; --  GNU/LinuxThreads debugger signal
125
126    SIGADAABORT : constant := SIGABRT;
127    --  Change this if you want to use another signal for task abort.
128    --  SIGTERM might be a good one.
129
130    type Signal_Set is array (Natural range <>) of Signal;
131
132    Unmasked    : constant Signal_Set := (
133       SIGTRAP,
134       --  To enable debugging on multithreaded applications, mark SIGTRAP to
135       --  be kept unmasked.
136
137       SIGBUS,
138
139       SIGTTIN, SIGTTOU, SIGTSTP,
140       --  Keep these three signals unmasked so that background processes
141       --  and IO behaves as normal "C" applications
142
143       SIGPROF,
144       --  To avoid confusing the profiler
145
146       SIGKILL, SIGSTOP,
147       --  These two signals actually cannot be masked;
148       --  POSIX simply won't allow it.
149
150       SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
151       --  These three signals are used by GNU/LinuxThreads starting from
152       --  glibc 2.1 (future 2.2).
153
154    Reserved    : constant Signal_Set :=
155    --  I am not sure why the following two signals are reserved.
156    --  I guess they are not supported by this version of GNU/Linux.
157      (SIGVTALRM, SIGUNUSED);
158
159    type sigset_t is private;
160
161    function sigaddset (set : access sigset_t; sig : Signal) return int;
162    pragma Import (C, sigaddset, "sigaddset");
163
164    function sigdelset (set : access sigset_t; sig : Signal) return int;
165    pragma Import (C, sigdelset, "sigdelset");
166
167    function sigfillset (set : access sigset_t) return int;
168    pragma Import (C, sigfillset, "sigfillset");
169
170    function sigismember (set : access sigset_t; sig : Signal) return int;
171    pragma Import (C, sigismember, "sigismember");
172
173    function sigemptyset (set : access sigset_t) return int;
174    pragma Import (C, sigemptyset, "sigemptyset");
175
176    type union_type_3 is new String (1 .. 116);
177    type siginfo_t is record
178       si_signo : int;
179       si_code  : int;
180       si_errno : int;
181       X_data   : union_type_3;
182    end record;
183    pragma Convention (C, siginfo_t);
184
185    type struct_sigaction is record
186       sa_handler   : System.Address;
187       sa_flags     : unsigned_long;
188       sa_mask      : sigset_t;
189    end record;
190    pragma Convention (C, struct_sigaction);
191    type struct_sigaction_ptr is access all struct_sigaction;
192
193    type Machine_State is record
194       eip : unsigned_long;
195       ebx : unsigned_long;
196       esp : unsigned_long;
197       ebp : unsigned_long;
198       esi : unsigned_long;
199       edi : unsigned_long;
200    end record;
201    type Machine_State_Ptr is access all Machine_State;
202
203    SA_SIGINFO  : constant := 16;
204
205    SIG_BLOCK   : constant := 0;
206    SIG_UNBLOCK : constant := 1;
207    SIG_SETMASK : constant := 2;
208
209    SIG_DFL : constant := 0;
210    SIG_IGN : constant := 1;
211
212    function sigaction
213      (sig  : Signal;
214       act  : struct_sigaction_ptr;
215       oact : struct_sigaction_ptr) return int;
216    pragma Import (C, sigaction, "sigaction");
217
218    ----------
219    -- Time --
220    ----------
221
222    type timespec is private;
223
224    function To_Duration (TS : timespec) return Duration;
225    pragma Inline (To_Duration);
226
227    function To_Timespec (D : Duration) return timespec;
228    pragma Inline (To_Timespec);
229
230    type struct_timeval is private;
231
232    function To_Duration (TV : struct_timeval) return Duration;
233    pragma Inline (To_Duration);
234
235    function To_Timeval (D : Duration) return struct_timeval;
236    pragma Inline (To_Timeval);
237
238    function gettimeofday
239      (tv : access struct_timeval;
240       tz : System.Address := System.Null_Address) return int;
241    pragma Import (C, gettimeofday, "gettimeofday");
242
243    function sysconf (name : int) return long;
244    pragma Import (C, sysconf);
245
246    SC_CLK_TCK : constant := 2;
247
248    -------------------------
249    -- Priority Scheduling --
250    -------------------------
251
252    SCHED_OTHER : constant := 0;
253    SCHED_FIFO  : constant := 1;
254    SCHED_RR    : constant := 2;
255
256    function To_Target_Priority
257      (Prio : System.Any_Priority) return Interfaces.C.int;
258    --  Maps System.Any_Priority to a POSIX priority.
259
260    -------------
261    -- Process --
262    -------------
263
264    type pid_t is private;
265
266    function kill (pid : pid_t; sig : Signal) return int;
267    pragma Import (C, kill, "kill");
268
269    function getpid return pid_t;
270    pragma Import (C, getpid, "getpid");
271
272    -------------
273    -- Threads --
274    -------------
275
276    type Thread_Body is access
277      function (arg : System.Address) return System.Address;
278
279    function Thread_Body_Access is new
280      Ada.Unchecked_Conversion (System.Address, Thread_Body);
281
282    type pthread_t is new unsigned_long;
283    subtype Thread_Id        is pthread_t;
284
285    function To_pthread_t is new Ada.Unchecked_Conversion
286      (unsigned_long, pthread_t);
287
288    type pthread_mutex_t     is limited private;
289    type pthread_cond_t      is limited private;
290    type pthread_attr_t      is limited private;
291    type pthread_mutexattr_t is limited private;
292    type pthread_condattr_t  is limited private;
293    type pthread_key_t       is private;
294
295    PTHREAD_CREATE_DETACHED : constant := 1;
296
297    -----------
298    -- Stack --
299    -----------
300
301    function Get_Stack_Base (thread : pthread_t) return Address;
302    pragma Inline (Get_Stack_Base);
303    --  This is a dummy procedure to share some GNULLI files
304
305    ---------------------------------------
306    -- Nonstandard Thread Initialization --
307    ---------------------------------------
308
309    procedure pthread_init;
310    pragma Inline (pthread_init);
311    --  This is a dummy procedure to share some GNULLI files
312
313    -------------------------
314    -- POSIX.1c  Section 3 --
315    -------------------------
316
317    function sigwait (set : access sigset_t; sig : access Signal) return int;
318    pragma Import (C, sigwait, "sigwait");
319
320    function pthread_kill (thread : pthread_t; sig : Signal) return int;
321    pragma Import (C, pthread_kill, "pthread_kill");
322
323    function pthread_sigmask
324      (how  : int;
325       set  : access sigset_t;
326       oset : access sigset_t) return int;
327    pragma Import (C, pthread_sigmask, "pthread_sigmask");
328
329    --------------------------
330    -- POSIX.1c  Section 11 --
331    --------------------------
332
333    function pthread_mutexattr_init
334      (attr : access pthread_mutexattr_t) return int;
335    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
336
337    function pthread_mutexattr_destroy
338      (attr : access pthread_mutexattr_t) return int;
339    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
340
341    function pthread_mutex_init
342      (mutex : access pthread_mutex_t;
343       attr  : access pthread_mutexattr_t) return int;
344    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
345
346    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
347    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
348
349    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
350    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
351
352    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
353    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
354
355    function pthread_condattr_init
356      (attr : access pthread_condattr_t) return int;
357    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
358
359    function pthread_condattr_destroy
360      (attr : access pthread_condattr_t) return int;
361    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
362
363    function pthread_cond_init
364      (cond : access pthread_cond_t;
365       attr : access pthread_condattr_t) return int;
366    pragma Import (C, pthread_cond_init, "pthread_cond_init");
367
368    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
369    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
370
371    function pthread_cond_signal (cond : access pthread_cond_t) return int;
372    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
373
374    function pthread_cond_wait
375      (cond  : access pthread_cond_t;
376       mutex : access pthread_mutex_t) return int;
377    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
378
379    function pthread_cond_timedwait
380      (cond    : access pthread_cond_t;
381       mutex   : access pthread_mutex_t;
382       abstime : access timespec) return int;
383    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
384
385    --------------------------
386    -- POSIX.1c  Section 13 --
387    --------------------------
388
389    type struct_sched_param is record
390       sched_priority : int;  --  scheduling priority
391    end record;
392    pragma Convention (C, struct_sched_param);
393
394    function pthread_setschedparam
395      (thread : pthread_t;
396       policy : int;
397       param  : access struct_sched_param) return int;
398    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
399
400    function pthread_attr_setschedpolicy
401      (attr   : access pthread_attr_t;
402       policy : int) return int;
403    pragma Import
404      (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
405
406    function sched_yield return int;
407    pragma Import (C, sched_yield, "sched_yield");
408
409    ---------------------------
410    -- P1003.1c - Section 16 --
411    ---------------------------
412
413    function pthread_attr_init
414      (attributes : access pthread_attr_t) return int;
415    pragma Import (C, pthread_attr_init, "pthread_attr_init");
416
417    function pthread_attr_destroy
418      (attributes : access pthread_attr_t) return int;
419    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
420
421    function pthread_attr_setdetachstate
422      (attr        : access pthread_attr_t;
423       detachstate : int) return int;
424    pragma Import
425      (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
426
427    function pthread_attr_setstacksize
428      (attr      : access pthread_attr_t;
429       stacksize : size_t) return int;
430    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
431
432    function pthread_create
433      (thread        : access pthread_t;
434       attributes    : access pthread_attr_t;
435       start_routine : Thread_Body;
436       arg           : System.Address) return int;
437    pragma Import (C, pthread_create, "pthread_create");
438
439    procedure pthread_exit (status : System.Address);
440    pragma Import (C, pthread_exit, "pthread_exit");
441
442    function pthread_self return pthread_t;
443    pragma Import (C, pthread_self, "pthread_self");
444
445    --------------------------
446    -- POSIX.1c  Section 17 --
447    --------------------------
448
449    function pthread_setspecific
450      (key   : pthread_key_t;
451       value : System.Address) return int;
452    pragma Import (C, pthread_setspecific, "pthread_setspecific");
453
454    function pthread_getspecific (key : pthread_key_t) return System.Address;
455    pragma Import (C, pthread_getspecific, "pthread_getspecific");
456
457    type destructor_pointer is access procedure (arg : System.Address);
458
459    function pthread_key_create
460      (key        : access pthread_key_t;
461       destructor : destructor_pointer) return int;
462    pragma Import (C, pthread_key_create, "pthread_key_create");
463
464 private
465
466    type sigset_t is array (0 .. 31) of unsigned_long;
467    pragma Convention (C, sigset_t);
468
469    type pid_t is new int;
470
471    type time_t is new long;
472
473    type timespec is record
474       tv_sec  : time_t;
475       tv_nsec : long;
476    end record;
477    pragma Convention (C, timespec);
478
479    type struct_timeval is record
480       tv_sec  : time_t;
481       tv_usec : time_t;
482    end record;
483    pragma Convention (C, struct_timeval);
484
485    type pthread_attr_t is record
486       detachstate   : int;
487       schedpolicy   : int;
488       schedparam    : struct_sched_param;
489       inheritsched  : int;
490       scope         : int;
491       guardsize     : size_t;
492       stackaddr_set : int;
493       stackaddr     : System.Address;
494       stacksize     : size_t;
495    end record;
496    pragma Convention (C, pthread_attr_t);
497
498    type pthread_condattr_t is record
499       dummy : int;
500    end record;
501    pragma Convention (C, pthread_condattr_t);
502
503    type pthread_mutexattr_t is record
504       mutexkind : int;
505    end record;
506    pragma Convention (C, pthread_mutexattr_t);
507
508    type lock_array is array (1 .. 4) of int;
509    type atomic_lock_t is record
510       lock : lock_array;
511    end record;
512    pragma Convention (C, atomic_lock_t);
513    --  ??? Alignment should be 16 but this is larger than BIGGEST_ALIGNMENT.
514    --  This causes an erroneous pointer value to sometimes be passed to free
515    --  during deallocation.  See PR ada/24533 for more details.
516    for atomic_lock_t'Alignment use 8;
517
518    type struct_pthread_fast_lock is record
519       spinlock : atomic_lock_t;
520       status   : long;
521    end record;
522    pragma Convention (C, struct_pthread_fast_lock);
523
524    type pthread_mutex_t is record
525       m_reserved : int;
526       m_count    : int;
527       m_owner    : System.Address;
528       m_kind     : int;
529       m_lock     : struct_pthread_fast_lock;
530    end record;
531    pragma Convention (C, pthread_mutex_t);
532
533    type pthread_cond_t is array (0 .. 47) of unsigned_char;
534    pragma Convention (C, pthread_cond_t);
535
536    type pthread_key_t is new unsigned;
537
538 end System.OS_Interface;