OSDN Git Service

* g++.old-deja/g++.benjamin/16077.C: Adjust warnings.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5iosinte.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 --                                                                          --
10 --          Copyright (C) 1991-2001 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 (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
41 --  or remove the pragma Elaborate_Body.
42 --  It is designed to be a bottom-level (leaf) package.
43
44 with Interfaces.C;
45 package System.OS_Interface is
46    pragma Preelaborate;
47
48    pragma Linker_Options ("-lpthread");
49
50    subtype int            is Interfaces.C.int;
51    subtype char           is Interfaces.C.char;
52    subtype short          is Interfaces.C.short;
53    subtype long           is Interfaces.C.long;
54    subtype unsigned       is Interfaces.C.unsigned;
55    subtype unsigned_short is Interfaces.C.unsigned_short;
56    subtype unsigned_long  is Interfaces.C.unsigned_long;
57    subtype unsigned_char  is Interfaces.C.unsigned_char;
58    subtype plain_char     is Interfaces.C.plain_char;
59    subtype size_t         is Interfaces.C.size_t;
60
61    -----------
62    -- Errno --
63    -----------
64
65    function errno return int;
66    pragma Import (C, errno, "__get_errno");
67
68    EAGAIN    : constant := 11;
69    EINTR     : constant := 4;
70    EINVAL    : constant := 22;
71    ENOMEM    : constant := 12;
72    EPERM     : constant := 1;
73    ETIMEDOUT : constant := 110;
74
75    -------------
76    -- Signals --
77    -------------
78
79    Max_Interrupt : constant := 63;
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 (Linux)
118    SIGLTHRRES : constant := 32; --  GNU/LinuxThreads restart signal
119    SIGLTHRCAN : constant := 33; --  GNU/LinuxThreads cancel signal
120    SIGLTHRDBG : constant := 34; --  GNU/LinuxThreads debugger signal
121
122    SIGADAABORT : constant := SIGABRT;
123    --  Change this if you want to use another signal for task abort.
124    --  SIGTERM might be a good one.
125
126    type Signal_Set is array (Natural range <>) of Signal;
127
128    Unmasked    : constant Signal_Set := (
129       SIGTRAP,
130       --  To enable debugging on multithreaded applications, mark SIGTRAP to
131       --  be kept unmasked.
132
133       SIGBUS,
134
135       SIGTTIN, SIGTTOU, SIGTSTP,
136       --  Keep these three signals unmasked so that background processes
137       --  and IO behaves as normal "C" applications
138
139       SIGPROF,
140       --  To avoid confusing the profiler
141
142       SIGKILL, SIGSTOP,
143       --  These two signals actually cannot be masked;
144       --  POSIX simply won't allow it.
145
146       SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
147       --  These three signals are used by GNU/LinuxThreads starting from
148       --  glibc 2.1 (future 2.2).
149
150    Reserved    : constant Signal_Set :=
151    --  I am not sure why the following two signals are reserved.
152    --  I guess they are not supported by this version of GNU/Linux.
153      (SIGVTALRM, SIGUNUSED);
154
155    type sigset_t is private;
156
157    function sigaddset (set : access sigset_t; sig : Signal) return int;
158    pragma Import (C, sigaddset, "sigaddset");
159
160    function sigdelset (set : access sigset_t; sig : Signal) return int;
161    pragma Import (C, sigdelset, "sigdelset");
162
163    function sigfillset (set : access sigset_t) return int;
164    pragma Import (C, sigfillset, "sigfillset");
165
166    function sigismember (set : access sigset_t; sig : Signal) return int;
167    pragma Import (C, sigismember, "sigismember");
168
169    function sigemptyset (set : access sigset_t) return int;
170    pragma Import (C, sigemptyset, "sigemptyset");
171
172    type union_type_3 is new String (1 .. 116);
173    type siginfo_t is record
174       si_signo : int;
175       si_code  : int;
176       si_errno : int;
177       X_data   : union_type_3;
178    end record;
179    pragma Convention (C, siginfo_t);
180
181    type struct_sigaction is record
182       sa_handler   : System.Address;
183       sa_mask      : sigset_t;
184       sa_flags     : unsigned_long;
185       sa_restorer  : System.Address;
186    end record;
187    pragma Convention (C, struct_sigaction);
188    type struct_sigaction_ptr is access all struct_sigaction;
189
190    type Machine_State is record
191       eip : unsigned_long;
192       ebx : unsigned_long;
193       esp : unsigned_long;
194       ebp : unsigned_long;
195       esi : unsigned_long;
196       edi : unsigned_long;
197    end record;
198    type Machine_State_Ptr is access all Machine_State;
199
200    SIG_BLOCK   : constant := 0;
201    SIG_UNBLOCK : constant := 1;
202    SIG_SETMASK : constant := 2;
203
204    SIG_DFL : constant := 0;
205    SIG_IGN : constant := 1;
206
207    function sigaction
208      (sig  : Signal;
209       act  : struct_sigaction_ptr;
210       oact : struct_sigaction_ptr) return int;
211    pragma Import (C, sigaction, "sigaction");
212
213    ----------
214    -- Time --
215    ----------
216
217    type timespec is private;
218
219    function To_Duration (TS : timespec) return Duration;
220    pragma Inline (To_Duration);
221
222    function To_Timespec (D : Duration) return timespec;
223    pragma Inline (To_Timespec);
224
225    type struct_timeval is private;
226
227    function To_Duration (TV : struct_timeval) return Duration;
228    pragma Inline (To_Duration);
229
230    function To_Timeval (D : Duration) return struct_timeval;
231    pragma Inline (To_Timeval);
232
233    function gettimeofday
234      (tv : access struct_timeval;
235       tz : System.Address := System.Null_Address) return int;
236    pragma Import (C, gettimeofday, "gettimeofday");
237
238    -------------------------
239    -- Priority Scheduling --
240    -------------------------
241
242    SCHED_OTHER : constant := 0;
243    SCHED_FIFO  : constant := 1;
244    SCHED_RR    : constant := 2;
245
246    -------------
247    -- Process --
248    -------------
249
250    type pid_t is private;
251
252    function kill (pid : pid_t; sig : Signal) return int;
253    pragma Import (C, kill, "kill");
254
255    function getpid return pid_t;
256    pragma Import (C, getpid, "getpid");
257
258    -------------
259    -- Threads --
260    -------------
261
262    type Thread_Body is access
263      function (arg : System.Address) return System.Address;
264    type pthread_t           is private;
265    subtype Thread_Id        is pthread_t;
266
267    type pthread_mutex_t     is limited private;
268    type pthread_cond_t      is limited private;
269    type pthread_attr_t      is limited private;
270    type pthread_mutexattr_t is limited private;
271    type pthread_condattr_t  is limited private;
272    type pthread_key_t       is private;
273
274    PTHREAD_CREATE_DETACHED : constant := 1;
275
276    -----------
277    -- Stack --
278    -----------
279
280    function Get_Stack_Base (thread : pthread_t) return Address;
281    pragma Inline (Get_Stack_Base);
282    --  This is a dummy procedure to share some GNULLI files
283
284    ---------------------------------------
285    -- Nonstandard Thread Initialization --
286    ---------------------------------------
287
288    procedure pthread_init;
289    pragma Inline (pthread_init);
290    --  This is a dummy procedure to share some GNULLI files
291
292    -------------------------
293    -- POSIX.1c  Section 3 --
294    -------------------------
295
296    function sigwait (set : access sigset_t; sig : access Signal) return int;
297    pragma Import (C, sigwait, "sigwait");
298
299    function pthread_kill (thread : pthread_t; sig : Signal) return int;
300    pragma Import (C, pthread_kill, "pthread_kill");
301
302    type sigset_t_ptr is access all sigset_t;
303
304    function pthread_sigmask
305      (how  : int;
306       set  : sigset_t_ptr;
307       oset : sigset_t_ptr) return int;
308    pragma Import (C, pthread_sigmask, "pthread_sigmask");
309
310    --------------------------
311    -- POSIX.1c  Section 11 --
312    --------------------------
313
314    function pthread_mutexattr_init
315      (attr : access pthread_mutexattr_t) return int;
316    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
317
318    function pthread_mutexattr_destroy
319      (attr : access pthread_mutexattr_t) return int;
320    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
321
322    function pthread_mutex_init
323      (mutex : access pthread_mutex_t;
324       attr  : access pthread_mutexattr_t) return int;
325    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
326
327    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
328    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
329
330    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
331    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
332
333    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
334    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
335
336    function pthread_condattr_init
337      (attr : access pthread_condattr_t) return int;
338    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
339
340    function pthread_condattr_destroy
341      (attr : access pthread_condattr_t) return int;
342    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
343
344    function pthread_cond_init
345      (cond : access pthread_cond_t;
346       attr : access pthread_condattr_t) return int;
347    pragma Import (C, pthread_cond_init, "pthread_cond_init");
348
349    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
350    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
351
352    function pthread_cond_signal (cond : access pthread_cond_t) return int;
353    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
354
355    function pthread_cond_wait
356      (cond  : access pthread_cond_t;
357       mutex : access pthread_mutex_t) return int;
358    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
359
360    function pthread_cond_timedwait
361      (cond    : access pthread_cond_t;
362       mutex   : access pthread_mutex_t;
363       abstime : access timespec) return int;
364    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
365
366    --------------------------
367    -- POSIX.1c  Section 13 --
368    --------------------------
369
370    type struct_sched_param is record
371       sched_priority : int;  --  scheduling priority
372    end record;
373    pragma Convention (C, struct_sched_param);
374
375    function pthread_setschedparam
376      (thread : pthread_t;
377       policy : int;
378       param  : access struct_sched_param) return int;
379    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
380
381    function pthread_attr_setschedpolicy
382      (attr   : access pthread_attr_t;
383       policy : int) return int;
384    pragma Import
385      (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
386
387    function sched_yield return int;
388    pragma Import (C, sched_yield, "sched_yield");
389
390    ---------------------------
391    -- P1003.1c - Section 16 --
392    ---------------------------
393
394    function pthread_attr_init
395      (attributes : access pthread_attr_t) return int;
396    pragma Import (C, pthread_attr_init, "pthread_attr_init");
397
398    function pthread_attr_destroy
399      (attributes : access pthread_attr_t) return int;
400    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
401
402    function pthread_attr_setdetachstate
403      (attr        : access pthread_attr_t;
404       detachstate : int) return int;
405    pragma Import
406      (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
407
408    function pthread_attr_setstacksize
409      (attr      : access pthread_attr_t;
410       stacksize : size_t) return int;
411    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
412
413    function pthread_create
414      (thread        : access pthread_t;
415       attributes    : access pthread_attr_t;
416       start_routine : Thread_Body;
417       arg           : System.Address) return int;
418    pragma Import (C, pthread_create, "pthread_create");
419
420    procedure pthread_exit (status : System.Address);
421    pragma Import (C, pthread_exit, "pthread_exit");
422
423    function pthread_self return pthread_t;
424    pragma Import (C, pthread_self, "pthread_self");
425
426    --------------------------
427    -- POSIX.1c  Section 17 --
428    --------------------------
429
430    function pthread_setspecific
431      (key   : pthread_key_t;
432       value : System.Address) return int;
433    pragma Import (C, pthread_setspecific, "pthread_setspecific");
434
435    function pthread_getspecific (key : pthread_key_t) return System.Address;
436    pragma Import (C, pthread_getspecific, "pthread_getspecific");
437
438    type destructor_pointer is access procedure (arg : System.Address);
439
440    function pthread_key_create
441      (key        : access pthread_key_t;
442       destructor : destructor_pointer) return int;
443    pragma Import (C, pthread_key_create, "pthread_key_create");
444
445 private
446
447    type sigset_t is array (0 .. 31) of unsigned_long;
448    pragma Convention (C, sigset_t);
449    for sigset_t'Size use 1024;
450    --  This is for GNU libc version 2 but should be backward compatible with
451    --  other libc where sigset_t is smaller.
452
453    type pid_t is new int;
454
455    type time_t is new long;
456
457    type timespec is record
458       tv_sec  : time_t;
459       tv_nsec : long;
460    end record;
461    pragma Convention (C, timespec);
462
463    type struct_timeval is record
464       tv_sec  : time_t;
465       tv_usec : time_t;
466    end record;
467    pragma Convention (C, struct_timeval);
468
469    type pthread_attr_t is record
470       detachstate   : int;
471       schedpolicy   : int;
472       schedparam    : struct_sched_param;
473       inheritsched  : int;
474       scope         : int;
475       guardsize     : size_t;
476       stackaddr_set : int;
477       stackaddr     : System.Address;
478       stacksize     : size_t;
479    end record;
480    pragma Convention (C_Pass_By_Copy, 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_t is new unsigned_long;
493
494    type struct_pthread_queue is record
495       head : System.Address;
496       tail : System.Address;
497    end record;
498    pragma Convention (C, struct_pthread_queue);
499
500    type pthread_mutex_t is record
501       m_spinlock : int;
502       m_count    : int;
503       m_owner    : System.Address;
504       m_kind     : int;
505       m_waiting  : struct_pthread_queue;
506    end record;
507    pragma Convention (C, pthread_mutex_t);
508
509    type pthread_cond_t is record
510       c_spinlock : int;
511       c_waiting  : struct_pthread_queue;
512    end record;
513    pragma Convention (C, pthread_cond_t);
514
515    type pthread_key_t is new unsigned;
516
517 end System.OS_Interface;