OSDN Git Service

2008-03-26 Javier Miranda <miranda@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-2008, 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 that are
39 --  needed by the tasking run-time (libgnarl).
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 Ada.Unchecked_Conversion;
45
46 with Interfaces.C;
47
48 package System.OS_Interface is
49    pragma Preelaborate;
50
51    pragma Linker_Options ("-lpthread");
52
53    subtype int            is Interfaces.C.int;
54    subtype char           is Interfaces.C.char;
55    subtype short          is Interfaces.C.short;
56    subtype long           is Interfaces.C.long;
57    subtype unsigned       is Interfaces.C.unsigned;
58    subtype unsigned_short is Interfaces.C.unsigned_short;
59    subtype unsigned_long  is Interfaces.C.unsigned_long;
60    subtype unsigned_char  is Interfaces.C.unsigned_char;
61    subtype plain_char     is Interfaces.C.plain_char;
62    subtype size_t         is Interfaces.C.size_t;
63
64    -----------
65    -- Errno --
66    -----------
67
68    function errno return int;
69    pragma Import (C, errno, "__get_errno");
70
71    EAGAIN    : constant := 11;
72    EINTR     : constant := 4;
73    EINVAL    : constant := 22;
74    ENOMEM    : constant := 12;
75    EPERM     : constant := 1;
76    ETIMEDOUT : constant := 238;
77
78    -------------
79    -- Signals --
80    -------------
81
82    Max_Interrupt : constant := 63;
83    type Signal is new int range 0 .. Max_Interrupt;
84    for Signal'Size use int'Size;
85
86    SIGHUP     : constant := 1; --  hangup
87    SIGINT     : constant := 2; --  interrupt (rubout)
88    SIGQUIT    : constant := 3; --  quit (ASCD FS)
89    SIGILL     : constant := 4; --  illegal instruction (not reset)
90    SIGTRAP    : constant := 5; --  trace trap (not reset)
91    SIGIOT     : constant := 6; --  IOT instruction
92    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
93    SIGEMT     : constant := 7; --  EMT
94    SIGFPE     : constant := 8; --  floating point exception
95    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
96    SIGBUS     : constant := 10; --  bus error
97    SIGSEGV    : constant := 11; --  segmentation violation
98    SIGSYS     : constant := 12; --  bad system call
99    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
100    SIGALRM    : constant := 14; --  alarm clock
101    SIGTERM    : constant := 15; --  software termination signal from kill
102    SIGUSR1    : constant := 16; --  user defined signal 1
103    SIGUSR2    : constant := 17; --  user defined signal 2
104    SIGCLD     : constant := 18; --  alias for SIGCHLD
105    SIGCHLD    : constant := 18; --  child status change
106    SIGPWR     : constant := 19; --  power-fail restart
107    SIGVTALRM  : constant := 20; --  virtual timer expired
108    SIGPROF    : constant := 21; --  profiling timer expired
109    SIGPOLL    : constant := 22; --  pollable event occurred
110    SIGIO      : constant := 22; --  I/O now possible (4.2 BSD)
111    SIGWINCH   : constant := 23; --  window size change
112    SIGSTOP    : constant := 24; --  stop (cannot be caught or ignored)
113    SIGTSTP    : constant := 25; --  user stop requested from tty
114    SIGCONT    : constant := 26; --  stopped process has been continued
115    SIGTTIN    : constant := 27; --  background tty read attempted
116    SIGTTOU    : constant := 28; --  background tty write attempted
117    SIGURG     : constant := 29; --  urgent condition on IO channel
118    SIGLOST    : constant := 30; --  File lock lost
119    SIGUNUSED  : constant := 31; --  unused signal (GNU/Linux)
120    SIGXCPU    : constant := 33; --  CPU time limit exceeded
121    SIGXFSZ    : constant := 34; --  filesize limit exceeded
122    SIGSTKFLT  : constant := 36; --  coprocessor stack fault (Linux)
123    SIGLTHRRES : constant := 37; --  GNU/LinuxThreads restart signal
124    SIGLTHRCAN : constant := 38; --  GNU/LinuxThreads cancel signal
125    SIGLTHRDBG : constant := 39; --  GNU/LinuxThreads debugger signal
126
127    SIGADAABORT : constant := SIGABRT;
128    --  Change this if you want to use another signal for task abort.
129    --  SIGTERM might be a good one.
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 :=
156    --  I am not sure why the following two signals are reserved.
157    --  I guess they are not supported by this version of GNU/Linux.
158      (SIGVTALRM, SIGUNUSED);
159
160    type sigset_t is private;
161
162    function sigaddset (set : access sigset_t; sig : Signal) return int;
163    pragma Import (C, sigaddset, "sigaddset");
164
165    function sigdelset (set : access sigset_t; sig : Signal) return int;
166    pragma Import (C, sigdelset, "sigdelset");
167
168    function sigfillset (set : access sigset_t) return int;
169    pragma Import (C, sigfillset, "sigfillset");
170
171    function sigismember (set : access sigset_t; sig : Signal) return int;
172    pragma Import (C, sigismember, "sigismember");
173
174    function sigemptyset (set : access sigset_t) return int;
175    pragma Import (C, sigemptyset, "sigemptyset");
176
177    type union_type_3 is new String (1 .. 116);
178    type siginfo_t is record
179       si_signo : int;
180       si_code  : int;
181       si_errno : int;
182       X_data   : union_type_3;
183    end record;
184    pragma Convention (C, siginfo_t);
185
186    type struct_sigaction is record
187       sa_handler   : System.Address;
188       sa_flags     : unsigned_long;
189       sa_mask      : sigset_t;
190    end record;
191    pragma Convention (C, struct_sigaction);
192    type struct_sigaction_ptr is access all struct_sigaction;
193
194    type Machine_State is record
195       eip : unsigned_long;
196       ebx : unsigned_long;
197       esp : unsigned_long;
198       ebp : unsigned_long;
199       esi : unsigned_long;
200       edi : unsigned_long;
201    end record;
202    type Machine_State_Ptr is access all Machine_State;
203
204    SA_SIGINFO  : constant := 16;
205
206    SIG_BLOCK   : constant := 0;
207    SIG_UNBLOCK : constant := 1;
208    SIG_SETMASK : constant := 2;
209
210    SIG_DFL : constant := 0;
211    SIG_IGN : constant := 1;
212
213    function sigaction
214      (sig  : Signal;
215       act  : struct_sigaction_ptr;
216       oact : struct_sigaction_ptr) return int;
217    pragma Import (C, sigaction, "sigaction");
218
219    ----------
220    -- Time --
221    ----------
222
223    type timespec is private;
224
225    function To_Duration (TS : timespec) return Duration;
226    pragma Inline (To_Duration);
227
228    function To_Timespec (D : Duration) return timespec;
229    pragma Inline (To_Timespec);
230
231    type struct_timeval is private;
232
233    function To_Duration (TV : struct_timeval) return Duration;
234    pragma Inline (To_Duration);
235
236    function To_Timeval (D : Duration) return struct_timeval;
237    pragma Inline (To_Timeval);
238
239    function gettimeofday
240      (tv : access struct_timeval;
241       tz : System.Address := System.Null_Address) return int;
242    pragma Import (C, gettimeofday, "gettimeofday");
243
244    function sysconf (name : int) return long;
245    pragma Import (C, sysconf);
246
247    SC_CLK_TCK : constant := 2;
248    SC_NPROCESSORS_ONLN : constant := 84;
249
250    -------------------------
251    -- Priority Scheduling --
252    -------------------------
253
254    SCHED_OTHER : constant := 0;
255    SCHED_FIFO  : constant := 1;
256    SCHED_RR    : constant := 2;
257
258    function To_Target_Priority
259      (Prio : System.Any_Priority) return Interfaces.C.int;
260    --  Maps System.Any_Priority to a POSIX priority
261
262    -------------
263    -- Process --
264    -------------
265
266    type pid_t is private;
267
268    function kill (pid : pid_t; sig : Signal) return int;
269    pragma Import (C, kill, "kill");
270
271    function getpid return pid_t;
272    pragma Import (C, getpid, "getpid");
273
274    -------------
275    -- Threads --
276    -------------
277
278    type Thread_Body is access
279      function (arg : System.Address) return System.Address;
280    pragma Convention (C, Thread_Body);
281
282    function Thread_Body_Access is new
283      Ada.Unchecked_Conversion (System.Address, Thread_Body);
284
285    type pthread_t is new unsigned_long;
286    subtype Thread_Id        is pthread_t;
287
288    function To_pthread_t is new Ada.Unchecked_Conversion
289      (unsigned_long, pthread_t);
290
291    type pthread_mutex_t     is limited private;
292    type pthread_cond_t      is limited private;
293    type pthread_attr_t      is limited private;
294    type pthread_mutexattr_t is limited private;
295    type pthread_condattr_t  is limited private;
296    type pthread_key_t       is private;
297
298    PTHREAD_CREATE_DETACHED : constant := 1;
299
300    -----------
301    -- Stack --
302    -----------
303
304    function Get_Stack_Base (thread : pthread_t) return Address;
305    pragma Inline (Get_Stack_Base);
306    --  This is a dummy procedure to share some GNULLI files
307
308    ---------------------------------------
309    -- Nonstandard Thread Initialization --
310    ---------------------------------------
311
312    procedure pthread_init;
313    pragma Inline (pthread_init);
314    --  This is a dummy procedure to share some GNULLI files
315
316    -------------------------
317    -- POSIX.1c  Section 3 --
318    -------------------------
319
320    function sigwait (set : access sigset_t; sig : access Signal) return int;
321    pragma Import (C, sigwait, "sigwait");
322
323    function pthread_kill (thread : pthread_t; sig : Signal) return int;
324    pragma Import (C, pthread_kill, "pthread_kill");
325
326    function pthread_sigmask
327      (how  : int;
328       set  : access sigset_t;
329       oset : access sigset_t) return int;
330    pragma Import (C, pthread_sigmask, "pthread_sigmask");
331
332    --------------------------
333    -- POSIX.1c  Section 11 --
334    --------------------------
335
336    function pthread_mutexattr_init
337      (attr : access pthread_mutexattr_t) return int;
338    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
339
340    function pthread_mutexattr_destroy
341      (attr : access pthread_mutexattr_t) return int;
342    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
343
344    function pthread_mutex_init
345      (mutex : access pthread_mutex_t;
346       attr  : access pthread_mutexattr_t) return int;
347    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
348
349    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
350    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
351
352    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
353    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
354
355    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
356    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
357
358    function pthread_condattr_init
359      (attr : access pthread_condattr_t) return int;
360    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
361
362    function pthread_condattr_destroy
363      (attr : access pthread_condattr_t) return int;
364    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
365
366    function pthread_cond_init
367      (cond : access pthread_cond_t;
368       attr : access pthread_condattr_t) return int;
369    pragma Import (C, pthread_cond_init, "pthread_cond_init");
370
371    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
372    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
373
374    function pthread_cond_signal (cond : access pthread_cond_t) return int;
375    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
376
377    function pthread_cond_wait
378      (cond  : access pthread_cond_t;
379       mutex : access pthread_mutex_t) return int;
380    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
381
382    function pthread_cond_timedwait
383      (cond    : access pthread_cond_t;
384       mutex   : access pthread_mutex_t;
385       abstime : access timespec) return int;
386    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
387
388    --------------------------
389    -- POSIX.1c  Section 13 --
390    --------------------------
391
392    type struct_sched_param is record
393       sched_priority : int;  --  scheduling priority
394    end record;
395    pragma Convention (C, struct_sched_param);
396
397    function pthread_setschedparam
398      (thread : pthread_t;
399       policy : int;
400       param  : access struct_sched_param) return int;
401    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
402
403    function pthread_attr_setschedpolicy
404      (attr   : access pthread_attr_t;
405       policy : int) return int;
406    pragma Import
407      (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
408
409    function sched_yield return int;
410    pragma Import (C, sched_yield, "sched_yield");
411
412    ---------------------------
413    -- P1003.1c - Section 16 --
414    ---------------------------
415
416    function pthread_attr_init
417      (attributes : access pthread_attr_t) return int;
418    pragma Import (C, pthread_attr_init, "pthread_attr_init");
419
420    function pthread_attr_destroy
421      (attributes : access pthread_attr_t) return int;
422    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
423
424    function pthread_attr_setdetachstate
425      (attr        : access pthread_attr_t;
426       detachstate : int) return int;
427    pragma Import
428      (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
429
430    function pthread_attr_setstacksize
431      (attr      : access pthread_attr_t;
432       stacksize : size_t) return int;
433    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
434
435    function pthread_create
436      (thread        : access pthread_t;
437       attributes    : access pthread_attr_t;
438       start_routine : Thread_Body;
439       arg           : System.Address) return int;
440    pragma Import (C, pthread_create, "pthread_create");
441
442    procedure pthread_exit (status : System.Address);
443    pragma Import (C, pthread_exit, "pthread_exit");
444
445    function pthread_self return pthread_t;
446    pragma Import (C, pthread_self, "pthread_self");
447
448    --------------------------
449    -- POSIX.1c  Section 17 --
450    --------------------------
451
452    function pthread_setspecific
453      (key   : pthread_key_t;
454       value : System.Address) return int;
455    pragma Import (C, pthread_setspecific, "pthread_setspecific");
456
457    function pthread_getspecific (key : pthread_key_t) return System.Address;
458    pragma Import (C, pthread_getspecific, "pthread_getspecific");
459
460    type destructor_pointer is access procedure (arg : System.Address);
461    pragma Convention (C, destructor_pointer);
462
463    function pthread_key_create
464      (key        : access pthread_key_t;
465       destructor : destructor_pointer) return int;
466    pragma Import (C, pthread_key_create, "pthread_key_create");
467
468    CPU_SETSIZE : constant := 1_024;
469
470    type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
471    for bit_field'Size use CPU_SETSIZE;
472    pragma Pack (bit_field);
473    pragma Convention (C, bit_field);
474
475    type cpu_set_t is record
476       bits : bit_field;
477    end record;
478    pragma Convention (C, cpu_set_t);
479
480    function pthread_setaffinity_np
481      (thread     : pthread_t;
482       cpusetsize : size_t;
483       cpuset     : access cpu_set_t) return int;
484    pragma Import (C, pthread_setaffinity_np, "__gnat_pthread_setaffinity_np");
485
486 private
487
488    type sigset_t is array (0 .. 31) of unsigned_long;
489    pragma Convention (C, sigset_t);
490
491    type pid_t is new int;
492
493    type time_t is new long;
494
495    type timespec is record
496       tv_sec  : time_t;
497       tv_nsec : long;
498    end record;
499    pragma Convention (C, timespec);
500
501    type struct_timeval is record
502       tv_sec  : time_t;
503       tv_usec : time_t;
504    end record;
505    pragma Convention (C, struct_timeval);
506
507    type pthread_attr_t is record
508       detachstate   : int;
509       schedpolicy   : int;
510       schedparam    : struct_sched_param;
511       inheritsched  : int;
512       scope         : int;
513       guardsize     : size_t;
514       stackaddr_set : int;
515       stackaddr     : System.Address;
516       stacksize     : size_t;
517    end record;
518    pragma Convention (C, pthread_attr_t);
519
520    type pthread_condattr_t is record
521       dummy : int;
522    end record;
523    pragma Convention (C, pthread_condattr_t);
524
525    type pthread_mutexattr_t is record
526       mutexkind : int;
527    end record;
528    pragma Convention (C, pthread_mutexattr_t);
529
530    type lock_array is array (1 .. 4) of int;
531    type atomic_lock_t is record
532       lock : lock_array;
533    end record;
534    pragma Convention (C, atomic_lock_t);
535    --  ??? Alignment should be 16 but this is larger than BIGGEST_ALIGNMENT.
536    --  This causes an erroneous pointer value to sometimes be passed to free
537    --  during deallocation.  See PR ada/24533 for more details.
538    for atomic_lock_t'Alignment use 8;
539
540    type struct_pthread_fast_lock is record
541       spinlock : atomic_lock_t;
542       status   : long;
543    end record;
544    pragma Convention (C, struct_pthread_fast_lock);
545
546    type pthread_mutex_t is record
547       m_reserved : int;
548       m_count    : int;
549       m_owner    : System.Address;
550       m_kind     : int;
551       m_lock     : struct_pthread_fast_lock;
552    end record;
553    pragma Convention (C, pthread_mutex_t);
554
555    type pthread_cond_t is array (0 .. 47) of unsigned_char;
556    pragma Convention (C, pthread_cond_t);
557
558    type pthread_key_t is new unsigned;
559
560 end System.OS_Interface;