OSDN Git Service

* gcc-interface/ada-tree.def: Fix formatting nits.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-linux.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNAT 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-2008, 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 the tasking run-time (libgnarl).
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 Ada.Unchecked_Conversion;
44 with Interfaces.C;
45 with System.Linux;
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 := System.Linux.EAGAIN;
71    EINTR     : constant := System.Linux.EINTR;
72    EINVAL    : constant := System.Linux.EINVAL;
73    ENOMEM    : constant := System.Linux.ENOMEM;
74    EPERM     : constant := System.Linux.EPERM;
75    ETIMEDOUT : constant := System.Linux.ETIMEDOUT;
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 := System.Linux.SIGHUP;
86    SIGINT     : constant := System.Linux.SIGINT;
87    SIGQUIT    : constant := System.Linux.SIGQUIT;
88    SIGILL     : constant := System.Linux.SIGILL;
89    SIGTRAP    : constant := System.Linux.SIGTRAP;
90    SIGIOT     : constant := System.Linux.SIGIOT;
91    SIGABRT    : constant := System.Linux.SIGABRT;
92    SIGFPE     : constant := System.Linux.SIGFPE;
93    SIGKILL    : constant := System.Linux.SIGKILL;
94    SIGBUS     : constant := System.Linux.SIGBUS;
95    SIGSEGV    : constant := System.Linux.SIGSEGV;
96    SIGPIPE    : constant := System.Linux.SIGPIPE;
97    SIGALRM    : constant := System.Linux.SIGALRM;
98    SIGTERM    : constant := System.Linux.SIGTERM;
99    SIGUSR1    : constant := System.Linux.SIGUSR1;
100    SIGUSR2    : constant := System.Linux.SIGUSR2;
101    SIGCLD     : constant := System.Linux.SIGCLD;
102    SIGCHLD    : constant := System.Linux.SIGCHLD;
103    SIGPWR     : constant := System.Linux.SIGPWR;
104    SIGWINCH   : constant := System.Linux.SIGWINCH;
105    SIGURG     : constant := System.Linux.SIGURG;
106    SIGPOLL    : constant := System.Linux.SIGPOLL;
107    SIGIO      : constant := System.Linux.SIGIO;
108    SIGLOST    : constant := System.Linux.SIGLOST;
109    SIGSTOP    : constant := System.Linux.SIGSTOP;
110    SIGTSTP    : constant := System.Linux.SIGTSTP;
111    SIGCONT    : constant := System.Linux.SIGCONT;
112    SIGTTIN    : constant := System.Linux.SIGTTIN;
113    SIGTTOU    : constant := System.Linux.SIGTTOU;
114    SIGVTALRM  : constant := System.Linux.SIGVTALRM;
115    SIGPROF    : constant := System.Linux.SIGPROF;
116    SIGXCPU    : constant := System.Linux.SIGXCPU;
117    SIGXFSZ    : constant := System.Linux.SIGXFSZ;
118    SIGUNUSED  : constant := System.Linux.SIGUNUSED;
119    SIGSTKFLT  : constant := System.Linux.SIGSTKFLT;
120    SIGLTHRRES : constant := System.Linux.SIGLTHRRES;
121    SIGLTHRCAN : constant := System.Linux.SIGLTHRCAN;
122    SIGLTHRDBG : constant := System.Linux.SIGLTHRDBG;
123
124    SIGADAABORT : constant := SIGABRT;
125    --  Change this if you want to use another signal for task abort.
126    --  SIGTERM might be a good one.
127
128    type Signal_Set is array (Natural range <>) of Signal;
129
130    Unmasked    : constant Signal_Set := (
131       SIGTRAP,
132       --  To enable debugging on multithreaded applications, mark SIGTRAP to
133       --  be kept unmasked.
134
135       SIGBUS,
136
137       SIGTTIN, SIGTTOU, SIGTSTP,
138       --  Keep these three signals unmasked so that background processes
139       --  and IO behaves as normal "C" applications
140
141       SIGPROF,
142       --  To avoid confusing the profiler
143
144       SIGKILL, SIGSTOP,
145       --  These two signals actually cannot be masked;
146       --  POSIX simply won't allow it.
147
148       SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
149       --  These three signals are used by GNU/LinuxThreads starting from
150       --  glibc 2.1 (future 2.2).
151
152    Reserved    : constant Signal_Set :=
153    --  I am not sure why the following two signals are reserved.
154    --  I guess they are not supported by this version of GNU/Linux.
155      (SIGVTALRM, SIGUNUSED);
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    : Interfaces.C.unsigned_long;
187       sa_restorer : System.Address;
188    end record;
189    pragma Convention (C, struct_sigaction);
190
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 := System.Linux.SA_SIGINFO;
204    SA_ONSTACK : constant := System.Linux.SA_ONSTACK;
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    type stack_t is record
305       ss_sp    : System.Address;
306       ss_flags : int;
307       ss_size  : size_t;
308    end record;
309    pragma Convention (C, stack_t);
310
311    function sigaltstack
312      (ss  : not null access stack_t;
313       oss : access stack_t) return int;
314    pragma Import (C, sigaltstack, "sigaltstack");
315
316    Alternate_Stack : aliased System.Address;
317    pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
318    --  The alternate signal stack for stack overflows
319
320    Alternate_Stack_Size : constant := 16 * 1024;
321    --  This must be in keeping with init.c:__gnat_alternate_stack
322
323    function Get_Stack_Base (thread : pthread_t) return Address;
324    pragma Inline (Get_Stack_Base);
325    --  This is a dummy procedure to share some GNULLI files
326
327    ---------------------------------------
328    -- Nonstandard Thread Initialization --
329    ---------------------------------------
330
331    procedure pthread_init;
332    pragma Inline (pthread_init);
333    --  This is a dummy procedure to share some GNULLI files
334
335    -------------------------
336    -- POSIX.1c  Section 3 --
337    -------------------------
338
339    function sigwait (set : access sigset_t; sig : access Signal) return int;
340    pragma Import (C, sigwait, "sigwait");
341
342    function pthread_kill (thread : pthread_t; sig : Signal) return int;
343    pragma Import (C, pthread_kill, "pthread_kill");
344
345    function pthread_sigmask
346      (how  : int;
347       set  : access sigset_t;
348       oset : access sigset_t) return int;
349    pragma Import (C, pthread_sigmask, "pthread_sigmask");
350
351    --------------------------
352    -- POSIX.1c  Section 11 --
353    --------------------------
354
355    function pthread_mutexattr_init
356      (attr : access pthread_mutexattr_t) return int;
357    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
358
359    function pthread_mutexattr_destroy
360      (attr : access pthread_mutexattr_t) return int;
361    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
362
363    function pthread_mutex_init
364      (mutex : access pthread_mutex_t;
365       attr  : access pthread_mutexattr_t) return int;
366    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
367
368    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
369    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
370
371    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
372    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
373
374    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
375    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
376
377    function pthread_condattr_init
378      (attr : access pthread_condattr_t) return int;
379    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
380
381    function pthread_condattr_destroy
382      (attr : access pthread_condattr_t) return int;
383    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
384
385    function pthread_cond_init
386      (cond : access pthread_cond_t;
387       attr : access pthread_condattr_t) return int;
388    pragma Import (C, pthread_cond_init, "pthread_cond_init");
389
390    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
391    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
392
393    function pthread_cond_signal (cond : access pthread_cond_t) return int;
394    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
395
396    function pthread_cond_wait
397      (cond  : access pthread_cond_t;
398       mutex : access pthread_mutex_t) return int;
399    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
400
401    function pthread_cond_timedwait
402      (cond    : access pthread_cond_t;
403       mutex   : access pthread_mutex_t;
404       abstime : access timespec) return int;
405    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
406
407    --------------------------
408    -- POSIX.1c  Section 13 --
409    --------------------------
410
411    type struct_sched_param is record
412       sched_priority : int;  --  scheduling priority
413    end record;
414    pragma Convention (C, struct_sched_param);
415
416    function pthread_setschedparam
417      (thread : pthread_t;
418       policy : int;
419       param  : access struct_sched_param) return int;
420    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
421
422    function pthread_attr_setschedpolicy
423      (attr   : access pthread_attr_t;
424       policy : int) return int;
425    pragma Import
426      (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
427
428    function sched_yield return int;
429    pragma Import (C, sched_yield, "sched_yield");
430
431    ---------------------------
432    -- P1003.1c - Section 16 --
433    ---------------------------
434
435    function pthread_attr_init
436      (attributes : access pthread_attr_t) return int;
437    pragma Import (C, pthread_attr_init, "pthread_attr_init");
438
439    function pthread_attr_destroy
440      (attributes : access pthread_attr_t) return int;
441    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
442
443    function pthread_attr_setdetachstate
444      (attr        : access pthread_attr_t;
445       detachstate : int) return int;
446    pragma Import
447      (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
448
449    function pthread_attr_setstacksize
450      (attr      : access pthread_attr_t;
451       stacksize : size_t) return int;
452    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
453
454    function pthread_create
455      (thread        : access pthread_t;
456       attributes    : access pthread_attr_t;
457       start_routine : Thread_Body;
458       arg           : System.Address) return int;
459    pragma Import (C, pthread_create, "pthread_create");
460
461    procedure pthread_exit (status : System.Address);
462    pragma Import (C, pthread_exit, "pthread_exit");
463
464    function pthread_self return pthread_t;
465    pragma Import (C, pthread_self, "pthread_self");
466
467    function lwp_self return System.Address;
468    pragma Import (C, lwp_self, "__gnat_lwp_self");
469
470    --------------------------
471    -- POSIX.1c  Section 17 --
472    --------------------------
473
474    function pthread_setspecific
475      (key   : pthread_key_t;
476       value : System.Address) return int;
477    pragma Import (C, pthread_setspecific, "pthread_setspecific");
478
479    function pthread_getspecific (key : pthread_key_t) return System.Address;
480    pragma Import (C, pthread_getspecific, "pthread_getspecific");
481
482    type destructor_pointer is access procedure (arg : System.Address);
483    pragma Convention (C, destructor_pointer);
484
485    function pthread_key_create
486      (key        : access pthread_key_t;
487       destructor : destructor_pointer) return int;
488    pragma Import (C, pthread_key_create, "pthread_key_create");
489
490    CPU_SETSIZE : constant := 1_024;
491
492    type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
493    for bit_field'Size use CPU_SETSIZE;
494    pragma Pack (bit_field);
495    pragma Convention (C, bit_field);
496
497    type cpu_set_t is record
498       bits : bit_field;
499    end record;
500    pragma Convention (C, cpu_set_t);
501
502    function pthread_setaffinity_np
503      (thread     : pthread_t;
504       cpusetsize : size_t;
505       cpuset     : access cpu_set_t) return int;
506    pragma Import (C, pthread_setaffinity_np, "__gnat_pthread_setaffinity_np");
507
508 private
509
510    type sigset_t is array (0 .. 127) of Interfaces.C.unsigned_char;
511    pragma Convention (C, sigset_t);
512    for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment;
513
514    pragma Warnings (Off);
515    for struct_sigaction use record
516       sa_handler at                  0 range 0 .. Standard'Address_Size - 1;
517       sa_mask    at Linux.sa_mask_pos  range 0 .. 1023;
518       sa_flags   at Linux.sa_flags_pos range 0 .. Standard'Address_Size - 1;
519    end record;
520    --  We intentionally leave sa_restorer unspecified and let the compiler
521    --  append it after the last field, so disable corresponding warning.
522    pragma Warnings (On);
523
524    type pid_t is new int;
525
526    type time_t is new long;
527
528    type timespec is record
529       tv_sec  : time_t;
530       tv_nsec : long;
531    end record;
532    pragma Convention (C, timespec);
533
534    type struct_timeval is record
535       tv_sec  : time_t;
536       tv_usec : time_t;
537    end record;
538    pragma Convention (C, struct_timeval);
539
540    type pthread_attr_t is record
541       detachstate   : int;
542       schedpolicy   : int;
543       schedparam    : struct_sched_param;
544       inheritsched  : int;
545       scope         : int;
546       guardsize     : size_t;
547       stackaddr_set : int;
548       stackaddr     : System.Address;
549       stacksize     : size_t;
550    end record;
551    pragma Convention (C, pthread_attr_t);
552
553    type pthread_condattr_t is record
554       dummy : int;
555    end record;
556    pragma Convention (C, pthread_condattr_t);
557
558    type pthread_mutexattr_t is record
559       mutexkind : int;
560    end record;
561    pragma Convention (C, pthread_mutexattr_t);
562
563    type pthread_mutex_t is new System.Linux.pthread_mutex_t;
564
565    type pthread_cond_t is array (0 .. 47) of unsigned_char;
566    pragma Convention (C, pthread_cond_t);
567
568    type pthread_key_t is new unsigned;
569
570 end System.OS_Interface;