OSDN Git Service

25733820e192dae23b43dce38a19ba68437e1721
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5aosinte.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) 1998-2002 Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNARL is free software; you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This is the DEC Unix 4.0/5.1 version of this package.
35
36 --  This package encapsulates all direct interfaces to OS services
37 --  that are needed by children of System.
38
39 --  PLEASE DO NOT add any with-clauses to this package
40 --  It is designed to be a bottom-level (leaf) package.
41
42 with Interfaces.C;
43 package System.OS_Interface is
44    pragma Preelaborate;
45
46    pragma Linker_Options ("-lpthread");
47    pragma Linker_Options ("-lmach");
48    pragma Linker_Options ("-lexc");
49    pragma Linker_Options ("-lrt");
50
51    subtype int            is Interfaces.C.int;
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    subtype char_array     is Interfaces.C.char_array;
61
62    -----------
63    -- Errno --
64    -----------
65
66    function errno return int;
67    pragma Import (C, errno, "_Geterrno");
68
69    EAGAIN    : constant := 35;
70    EINTR     : constant := 4;
71    EINVAL    : constant := 22;
72    ENOMEM    : constant := 12;
73    ETIMEDOUT : constant := 60;
74
75    -------------
76    -- Signals --
77    -------------
78
79    Max_Interrupt : constant := 48;
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    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
89    SIGIOT     : constant := 6; --  abort (terminate) process
90    SIGLOST    : constant := 6; --  old BSD signal ??
91    SIGEMT     : constant := 7; --  EMT instruction
92    SIGFPE     : constant := 8; --  floating point exception
93    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
94    SIGBUS     : constant := 10; --  bus error
95    SIGSEGV    : constant := 11; --  segmentation violation
96    SIGSYS     : constant := 12; --  bad argument to system call
97    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
98    SIGALRM    : constant := 14; --  alarm clock
99    SIGTERM    : constant := 15; --  software termination signal from kill
100    SIGURG     : constant := 16; --  urgent condition on IO channel
101    SIGIOINT   : constant := 16; --  printer to backend error signal
102    SIGSTOP    : constant := 17; --  stop (cannot be caught or ignored)
103    SIGTSTP    : constant := 18; --  user stop requested from tty
104    SIGCONT    : constant := 19; --  stopped process has been continued
105    SIGCHLD    : constant := 20; --  child status change
106    SIGTTIN    : constant := 21; --  background tty read attempted
107    SIGTTOU    : constant := 22; --  background tty write attempted
108    SIGPOLL    : constant := 23; --  I/O possible, or completed
109    SIGIO      : constant := 23; --  STREAMS version of SIGPOLL
110    SIGAIO     : constant := 23; --  base lan i/o
111    SIGPTY     : constant := 23; --  pty i/o
112    SIGXCPU    : constant := 24; --  CPU time limit exceeded
113    SIGXFSZ    : constant := 25; --  filesize limit exceeded
114    SIGVTALRM  : constant := 26; --  virtual timer expired
115    SIGPROF    : constant := 27; --  profiling timer expired
116    SIGWINCH   : constant := 28; --  window size change
117    SIGINFO    : constant := 29; --  information request
118    SIGPWR     : constant := 29; --  Power Fail/Restart -- SVID3/SVR4
119    SIGUSR1    : constant := 30; --  user defined signal 1
120    SIGUSR2    : constant := 31; --  user defined signal 2
121    SIGRESV    : constant := 32; --  reserved by Digital for future use
122
123    SIGADAABORT : constant := SIGABRT;
124
125    type Signal_Set is array (Natural range <>) of Signal;
126
127    Unmasked    : constant Signal_Set := (0 .. 0 => SIGTRAP);
128    Reserved    : constant Signal_Set := (SIGALRM, SIGABRT, SIGKILL, SIGSTOP);
129
130    type sigset_t is private;
131
132    function sigaddset (set : access sigset_t; sig : Signal) return int;
133    pragma Import (C, sigaddset);
134
135    function sigdelset (set : access sigset_t; sig : Signal) return int;
136    pragma Import (C, sigdelset);
137
138    function sigfillset (set : access sigset_t) return int;
139    pragma Import (C, sigfillset);
140
141    function sigismember (set : access sigset_t; sig : Signal) return int;
142    pragma Import (C, sigismember);
143
144    function sigemptyset (set : access sigset_t) return int;
145    pragma Import (C, sigemptyset);
146
147    type union_type_3 is new String (1 .. 116);
148    type siginfo_t is record
149       si_signo     : int;
150       si_errno     : int;
151       si_code      : int;
152       X_data       : union_type_3;
153    end record;
154    for siginfo_t'Size use 8 * 128;
155    pragma Convention (C, siginfo_t);
156
157    type struct_sigaction is record
158       sa_handler : System.Address;
159       sa_mask    : sigset_t;
160       sa_flags   : int;
161       sa_signo   : int;
162    end record;
163    pragma Convention (C, struct_sigaction);
164    type struct_sigaction_ptr is access all struct_sigaction;
165
166    SIG_BLOCK   : constant := 1;
167    SIG_UNBLOCK : constant := 2;
168    SIG_SETMASK : constant := 3;
169
170    SIG_DFL : constant := 0;
171    SIG_IGN : constant := 1;
172
173    SA_NODEFER : constant := 8;
174    SA_SIGINFO : constant := 16#40#;
175
176    function sigaction
177      (sig  : Signal;
178       act  : struct_sigaction_ptr;
179       oact : struct_sigaction_ptr) return int;
180    pragma Import (C, sigaction);
181
182    ----------
183    -- Time --
184    ----------
185
186    type timespec is private;
187
188    function nanosleep (rqtp, rmtp : access timespec)  return int;
189    pragma Import (C, nanosleep);
190
191    type clockid_t is private;
192
193    CLOCK_REALTIME : constant clockid_t;
194
195    function clock_gettime
196      (clock_id : clockid_t;
197       tp       : access timespec) return int;
198    pragma Import (C, clock_gettime);
199
200    function To_Duration (TS : timespec) return Duration;
201    pragma Inline (To_Duration);
202
203    function To_Timespec (D : Duration) return timespec;
204    pragma Inline (To_Timespec);
205
206    type struct_timezone is record
207       tz_minuteswest : int;
208       tz_dsttime     : int;
209    end record;
210    pragma Convention (C, struct_timezone);
211    type struct_timeval is private;
212    --  This is needed on systems that do not have clock_gettime()
213    --  but do have gettimeofday().
214
215    function To_Duration (TV : struct_timeval) return Duration;
216    pragma Inline (To_Duration);
217
218    function To_Timeval (D : Duration) return struct_timeval;
219    pragma Inline (To_Timeval);
220
221    -------------------------
222    -- Priority Scheduling --
223    -------------------------
224
225    SCHED_FIFO  : constant := 1;
226    SCHED_RR    : constant := 2;
227    SCHED_OTHER : constant := 3;
228    SCHED_LFI   : constant := 5;
229
230    -------------
231    -- Process --
232    -------------
233
234    type pid_t is private;
235
236    function kill (pid : pid_t; sig : Signal) return int;
237    pragma Import (C, kill);
238
239    function getpid return pid_t;
240    pragma Import (C, getpid);
241
242    BIND_NO_INHERIT  : constant := 1;
243
244    function bind_to_cpu
245      (pid       : pid_t;
246       cpu_mask  : unsigned_long;
247       flag      : unsigned_long := BIND_NO_INHERIT) return int;
248    pragma Import (C, bind_to_cpu);
249
250    -------------
251    -- Threads --
252    -------------
253
254    type Thread_Body is access
255      function (arg : System.Address) return System.Address;
256    type pthread_t           is private;
257    subtype Thread_Id        is pthread_t;
258
259    type pthread_mutex_t     is limited private;
260    type pthread_cond_t      is limited private;
261    type pthread_attr_t      is limited private;
262    type pthread_mutexattr_t is limited private;
263    type pthread_condattr_t  is limited private;
264    type pthread_key_t       is private;
265
266    PTHREAD_CREATE_DETACHED : constant := 1;
267
268    PTHREAD_SCOPE_PROCESS : constant := 0;
269    PTHREAD_SCOPE_SYSTEM  : constant := 1;
270
271    PTHREAD_EXPLICIT_SCHED : constant := 1;
272
273    ---------------------------------------
274    -- Nonstandard Thread Initialization --
275    ---------------------------------------
276
277    procedure pthread_init;
278    pragma Inline (pthread_init);
279    --  This is a dummy procedure to share some GNULLI files
280
281    ---------------------------
282    --  POSIX.1c  Section 3  --
283    ---------------------------
284
285    function sigwait
286      (set : access sigset_t;
287       sig : access Signal) return int;
288    pragma Import (C, sigwait, "__sigwaitd10");
289
290    function pthread_kill
291      (thread : pthread_t;
292       sig    : Signal) return int;
293    pragma Import (C, pthread_kill);
294
295    type sigset_t_ptr is access all sigset_t;
296
297    function pthread_sigmask
298      (how  : int;
299       set  : sigset_t_ptr;
300       oset : sigset_t_ptr) return int;
301    pragma Import (C, pthread_sigmask);
302
303    ----------------------------
304    --  POSIX.1c  Section 11  --
305    ----------------------------
306
307    function pthread_mutexattr_init (attr : access pthread_mutexattr_t)
308      return int;
309    pragma Import (C, pthread_mutexattr_init);
310
311    function pthread_mutexattr_destroy
312      (attr : access pthread_mutexattr_t) return int;
313    pragma Import (C, pthread_mutexattr_destroy);
314
315    function pthread_mutex_init
316      (mutex : access pthread_mutex_t;
317       attr  : access pthread_mutexattr_t) return int;
318    pragma Import (C, pthread_mutex_init, "__pthread_mutex_init");
319
320    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
321    pragma Import (C, pthread_mutex_destroy, "__pthread_mutex_destroy");
322
323    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
324    pragma Import (C, pthread_mutex_lock, "__pthread_mutex_lock");
325
326    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
327    pragma Import (C, pthread_mutex_unlock, "__pthread_mutex_unlock");
328
329    function pthread_condattr_init
330      (attr : access pthread_condattr_t) return int;
331    pragma Import (C, pthread_condattr_init);
332
333    function pthread_condattr_destroy
334      (attr : access pthread_condattr_t) return int;
335    pragma Import (C, pthread_condattr_destroy);
336
337    function pthread_cond_init
338      (cond : access pthread_cond_t;
339       attr : access pthread_condattr_t) return int;
340    pragma Import (C, pthread_cond_init, "__pthread_cond_init");
341
342    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
343    pragma Import (C, pthread_cond_destroy, "__pthread_cond_destroy");
344
345    function pthread_cond_signal (cond : access pthread_cond_t) return int;
346    pragma Import (C, pthread_cond_signal, "__pthread_cond_signal");
347
348    function pthread_cond_wait
349      (cond  : access pthread_cond_t;
350       mutex : access pthread_mutex_t) return  int;
351    pragma Import (C, pthread_cond_wait, "__pthread_cond_wait");
352
353    function pthread_cond_timedwait
354      (cond    : access pthread_cond_t;
355       mutex   : access pthread_mutex_t;
356       abstime : access timespec) return int;
357    pragma Import (C, pthread_cond_timedwait, "__pthread_cond_timedwait");
358
359    ----------------------------
360    --  POSIX.1c  Section 13  --
361    ----------------------------
362
363    function pthread_mutexattr_setprotocol
364      (attr     : access pthread_mutexattr_t;
365       protocol : int) return int;
366    pragma Import (C, pthread_mutexattr_setprotocol);
367
368    function pthread_mutexattr_setprioceiling
369      (attr     : access pthread_mutexattr_t;
370       prioceiling : int) return int;
371    pragma Import (C, pthread_mutexattr_setprioceiling);
372
373    type struct_sched_param is record
374       sched_priority : int;  --  scheduling priority
375    end record;
376
377    function pthread_setschedparam
378      (thread : pthread_t;
379       policy : int;
380       param  : access struct_sched_param) return int;
381    pragma Import (C, pthread_setschedparam);
382
383    function pthread_attr_setscope
384      (attr            : access pthread_attr_t;
385       contentionscope : int) return int;
386    pragma Import (C, pthread_attr_setscope);
387
388    function pthread_attr_setinheritsched
389      (attr            : access pthread_attr_t;
390       inheritsched    : int) return int;
391    pragma Import (C, pthread_attr_setinheritsched,
392      "__pthread_attr_setinheritsched");
393
394    function pthread_attr_setschedpolicy
395      (attr : access pthread_attr_t; policy : int) return int;
396    pragma Import (C, pthread_attr_setschedpolicy);
397
398    function pthread_attr_setschedparam
399      (attr        : access pthread_attr_t;
400       sched_param : access struct_sched_param) return int;
401    pragma Import (C, pthread_attr_setschedparam);
402
403    function sched_yield return int;
404    pragma Import (C, sched_yield);
405
406    ---------------------------
407    -- P1003.1c - Section 16 --
408    ---------------------------
409
410    function pthread_attr_init (attributes : access pthread_attr_t)
411      return int;
412    pragma Import (C, pthread_attr_init);
413
414    function pthread_attr_destroy (attributes : access pthread_attr_t)
415      return int;
416    pragma Import (C, pthread_attr_destroy);
417
418    function pthread_attr_setdetachstate
419      (attr        : access pthread_attr_t;
420       detachstate : int) return int;
421    pragma Import (C, pthread_attr_setdetachstate);
422
423    function pthread_attr_setstacksize
424      (attr      : access pthread_attr_t;
425       stacksize : size_t) return int;
426    pragma Import (C, pthread_attr_setstacksize, "__pthread_attr_setstacksize");
427
428    function pthread_create
429      (thread        : access pthread_t;
430       attributes    : access pthread_attr_t;
431       start_routine : Thread_Body;
432       arg           : System.Address) return int;
433    pragma Import (C, pthread_create, "__pthread_create");
434
435    procedure pthread_exit (status : System.Address);
436    pragma Import (C, pthread_exit, "__pthread_exit");
437
438    function pthread_self return pthread_t;
439    pragma Inline (pthread_self);
440
441    --------------------------
442    -- POSIX.1c  Section 17 --
443    --------------------------
444
445    function pthread_setspecific
446      (key : pthread_key_t; value : System.Address) return int;
447    pragma Import (C, pthread_setspecific, "__pthread_setspecific");
448
449    function pthread_getspecific (key : pthread_key_t) return System.Address;
450    pragma Import (C, pthread_getspecific, "__pthread_getspecific");
451
452    type destructor_pointer is access procedure (arg : System.Address);
453
454    function pthread_key_create
455      (key        : access pthread_key_t;
456       destructor : destructor_pointer) return int;
457    pragma Import (C, pthread_key_create);
458
459 private
460
461    type sigset_t is new unsigned_long;
462
463    type pid_t is new int;
464
465    type time_t is new int;
466
467    type timespec is record
468       tv_sec  : time_t;
469       tv_nsec : long;
470    end record;
471    pragma Convention (C, timespec);
472
473    type clockid_t is new int;
474    CLOCK_REALTIME : constant clockid_t := 1;
475
476    type struct_timeval is record
477       tv_sec  : time_t;
478       tv_usec : time_t;
479    end record;
480    pragma Convention (C, struct_timeval);
481
482    type unsigned_long_array is array (Natural range <>) of unsigned_long;
483
484    type pthread_t is new System.Address;
485
486    type pthread_cond_t is record
487       state     : unsigned;
488       valid     : unsigned;
489       name      : System.Address;
490       arg       : unsigned;
491       reserved1 : unsigned;
492       sequence  : unsigned_long;
493       block     : System.Address;
494    end record;
495    pragma Convention (C, pthread_cond_t);
496
497    type pthread_attr_t is record
498       valid    : long;
499       name     : System.Address;
500       arg      : unsigned_long;
501       reserved : unsigned_long_array (0 .. 18);
502    end record;
503    pragma Convention (C, pthread_attr_t);
504
505    type pthread_mutex_t is record
506       lock     : unsigned;
507       valid    : unsigned;
508       name     : System.Address;
509       arg      : unsigned;
510       depth    : unsigned;
511       sequence : unsigned_long;
512       owner    : unsigned_long;
513       block    : System.Address;
514    end record;
515    for pthread_mutex_t'Size use 8 * 48;
516    pragma Convention (C, pthread_mutex_t);
517
518    type pthread_mutexattr_t is record
519       valid    : long;
520       reserved : unsigned_long_array (0 .. 14);
521    end record;
522    pragma Convention (C, pthread_mutexattr_t);
523
524    type pthread_condattr_t is record
525       valid    : long;
526       reserved : unsigned_long_array (0 .. 12);
527    end record;
528    pragma Convention (C, pthread_condattr_t);
529
530    type pthread_key_t is new unsigned;
531
532 end System.OS_Interface;