OSDN Git Service

* approved by rth
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5hosinte.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) 1997-2001, Florida State University            --
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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com).                                  --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 --  This is the HP-UX 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
42 --  or remove the pragma Elaborate_Body.
43 --  It is designed to be a bottom-level (leaf) package.
44
45 with Interfaces.C;
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-lcma");
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
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    ETIME     : constant := 52;
73    ETIMEDOUT : constant := 238;
74
75    FUNC_ERR : constant := -1;
76
77    -------------
78    -- Signals --
79    -------------
80
81    Max_Interrupt : constant := 44;
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 instruction
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 argument to 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 alarm
107    SIGPROF    : constant := 21; --  profiling timer alarm
108    SIGIO      : constant := 22; --  asynchronous I/O
109    SIGPOLL    : constant := 22; --  pollable event occurred
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; --  remote lock lost  (NFS)
118    SIGDIL     : constant := 32; --  DIL signal
119    SIGXCPU    : constant := 33; --  CPU time limit exceeded (setrlimit)
120    SIGXFSZ    : constant := 34; --  file size limit exceeded (setrlimit)
121
122    SIGADAABORT : constant := SIGABRT;
123    --  Note: on other targets, we usually use SIGABRT, but on HP/UX, it
124    --  appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
125
126    type Signal_Set is array (Natural range <>) of Signal;
127
128    Unmasked    : constant Signal_Set :=
129      (SIGBUS, SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP);
130
131    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
132
133    type sigset_t is private;
134
135    type isr_address is access procedure (sig : int);
136
137    function intr_attach (sig : int; handler : isr_address) return long;
138
139    Intr_Attach_Reset : constant Boolean := True;
140    --  True if intr_attach is reset after an interrupt handler is called
141
142    function sigaddset (set : access sigset_t; sig : Signal) return int;
143    pragma Import (C, sigaddset, "sigaddset");
144
145    function sigdelset (set : access sigset_t; sig : Signal) return int;
146    pragma Import (C, sigdelset, "sigdelset");
147
148    function sigfillset (set : access sigset_t) return int;
149    pragma Import (C, sigfillset, "sigfillset");
150
151    function sigismember (set : access sigset_t; sig : Signal) return int;
152    pragma Import (C, sigismember, "sigismember");
153
154    function sigemptyset (set : access sigset_t) return int;
155    pragma Import (C, sigemptyset, "sigemptyset");
156
157    type Signal_Handler is access procedure (signo : Signal);
158
159    type struct_sigaction is record
160       sa_handler : System.Address;
161       sa_mask    : sigset_t;
162       sa_flags   : int;
163    end record;
164    pragma Convention (C, struct_sigaction);
165    type struct_sigaction_ptr is access all struct_sigaction;
166
167    SA_RESTART  : constant  := 16#40#;
168
169    SIG_BLOCK   : constant  := 0;
170    SIG_UNBLOCK : constant  := 1;
171    SIG_SETMASK : constant  := 2;
172
173    SIG_DFL : constant := 0;
174    SIG_IGN : constant := 1;
175    SIG_ERR : constant := -1;
176
177    function sigaction
178      (sig  : Signal;
179       act  : struct_sigaction_ptr;
180       oact : struct_sigaction_ptr) return int;
181    pragma Import (C, sigaction, "sigaction");
182
183    ----------
184    -- Time --
185    ----------
186
187    type timespec is private;
188
189    function nanosleep (rqtp, rmtp : access timespec) return int;
190    pragma Import (C, nanosleep);
191
192    type clockid_t is private;
193
194    CLOCK_REALTIME : constant clockid_t;
195
196    function Clock_Gettime
197      (Clock_Id : clockid_t; 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_timeval is private;
207
208    function To_Duration (TV : struct_timeval) return Duration;
209    pragma Inline (To_Duration);
210
211    function To_Timeval (D : Duration) return struct_timeval;
212    pragma Inline (To_Timeval);
213
214    -------------------------
215    -- Priority Scheduling --
216    -------------------------
217
218    SCHED_FIFO  : constant := 0;
219    SCHED_RR    : constant := 1;
220    SCHED_OTHER : constant := 2;
221
222    -------------
223    -- Process --
224    -------------
225
226    type pid_t is private;
227
228    function kill (pid : pid_t; sig : Signal) return int;
229    pragma Import (C, kill, "kill");
230
231    function getpid return pid_t;
232    pragma Import (C, getpid, "getpid");
233
234    -------------
235    -- Threads --
236    -------------
237
238    type Thread_Body is access
239      function (arg : System.Address) return System.Address;
240    type pthread_t           is private;
241    subtype Thread_Id        is pthread_t;
242
243    type pthread_mutex_t     is limited private;
244    type pthread_cond_t      is limited private;
245    type pthread_attr_t      is limited private;
246    type pthread_mutexattr_t is limited private;
247    type pthread_condattr_t  is limited private;
248    type pthread_key_t       is private;
249
250    -----------
251    -- Stack --
252    -----------
253
254    function Get_Stack_Base (thread : pthread_t) return Address;
255    pragma Inline (Get_Stack_Base);
256    --  This is a dummy procedure to share some GNULLI files
257
258    ---------------------------------------
259    -- Nonstandard Thread Initialization --
260    ---------------------------------------
261
262    procedure pthread_init;
263    pragma Inline (pthread_init);
264    --  This is a dummy procedure to share some GNULLI files
265
266    -------------------------
267    -- POSIX.1c  Section 3 --
268    -------------------------
269
270    function sigwait (set : access sigset_t) return int;
271    pragma Import (C, sigwait, "cma_sigwait");
272
273    function sigwait
274      (set : access sigset_t;
275       sig : access Signal) return int;
276    pragma Inline (sigwait);
277    --  DCE_THREADS has a nonstandard sigwait
278
279    function pthread_kill
280      (thread : pthread_t;
281       sig    : Signal) return int;
282    pragma Inline (pthread_kill);
283    --  DCE_THREADS doesn't have pthread_kill
284
285    type sigset_t_ptr is access all sigset_t;
286
287    function pthread_sigmask
288      (how  : int;
289       set  : sigset_t_ptr;
290       oset : sigset_t_ptr) return int;
291    --  DCE THREADS does not have pthread_sigmask. Instead, it uses
292    --  sigprocmask to do the signal handling when the thread library is
293    --  sucked in.
294    pragma Import (C, pthread_sigmask, "sigprocmask");
295
296    --------------------------
297    -- POSIX.1c  Section 11 --
298    --------------------------
299
300    function pthread_mutexattr_init
301      (attr : access pthread_mutexattr_t) return int;
302    --  DCE_THREADS has a nonstandard pthread_mutexattr_init.
303
304    function pthread_mutexattr_destroy
305      (attr : access pthread_mutexattr_t) return int;
306    --  DCE_THREADS has a nonstandard pthread_mutexattr_destroy
307
308    function pthread_mutex_init
309      (mutex : access pthread_mutex_t;
310       attr  : access pthread_mutexattr_t) return int;
311    --  DCE_THREADS has a nonstandard pthread_mutex_init
312
313    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
314    --  DCE_THREADS has a nonstandard pthread_mutex_destroy
315
316    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
317    pragma Inline (pthread_mutex_lock);
318    --  DCE_THREADS has nonstandard pthread_mutex_lock
319
320    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
321    pragma Inline (pthread_mutex_unlock);
322    --  DCE_THREADS has nonstandard pthread_mutex_lock
323
324    function pthread_condattr_init
325      (attr : access pthread_condattr_t) return int;
326    --  DCE_THREADS has nonstandard pthread_condattr_init
327
328    function pthread_condattr_destroy
329      (attr : access pthread_condattr_t) return int;
330    --  DCE_THREADS has nonstandard pthread_condattr_destroy
331
332    function pthread_cond_init
333      (cond : access pthread_cond_t;
334       attr : access pthread_condattr_t) return int;
335    --  DCE_THREADS has nonstandard pthread_cond_init
336
337    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
338    --  DCE_THREADS has nonstandard pthread_cond_destroy
339
340    function pthread_cond_signal (cond : access pthread_cond_t) return int;
341    pragma Inline (pthread_cond_signal);
342    --  DCE_THREADS has nonstandard pthread_cond_signal
343
344    function pthread_cond_wait
345      (cond  : access pthread_cond_t;
346       mutex : access pthread_mutex_t) return int;
347    pragma Inline (pthread_cond_wait);
348    --  DCE_THREADS has a nonstandard pthread_cond_wait
349
350    function pthread_cond_timedwait
351      (cond    : access pthread_cond_t;
352       mutex   : access pthread_mutex_t;
353       abstime : access timespec) return int;
354    pragma Inline (pthread_cond_timedwait);
355    --  DCE_THREADS has a nonstandard pthread_cond_timedwait
356
357    --------------------------
358    -- POSIX.1c  Section 13 --
359    --------------------------
360
361    type struct_sched_param is record
362       sched_priority : int;  --  scheduling priority
363    end record;
364
365    function pthread_setschedparam
366      (thread : pthread_t;
367       policy : int;
368       param  : access struct_sched_param) return int;
369    pragma Inline (pthread_setschedparam);
370    --  DCE_THREADS has a nonstandard pthread_setschedparam
371
372    function sched_yield return int;
373    pragma Inline (sched_yield);
374    --  DCE_THREADS has a nonstandard sched_yield
375
376    ---------------------------
377    -- P1003.1c - Section 16 --
378    ---------------------------
379
380    function pthread_attr_init (attributes : access pthread_attr_t) return int;
381    pragma Inline (pthread_attr_init);
382    --  DCE_THREADS has a nonstandard pthread_attr_init
383
384    function pthread_attr_destroy
385      (attributes : access pthread_attr_t) return int;
386    pragma Inline (pthread_attr_destroy);
387    --  DCE_THREADS has a nonstandard pthread_attr_destroy
388
389    function pthread_attr_setstacksize
390      (attr      : access pthread_attr_t;
391       stacksize : size_t) return int;
392    pragma Inline (pthread_attr_setstacksize);
393    --  DCE_THREADS has a nonstandard pthread_attr_setstacksize
394
395    function pthread_create
396      (thread        : access pthread_t;
397       attributes    : access pthread_attr_t;
398       start_routine : Thread_Body;
399       arg           : System.Address) return int;
400    pragma Inline (pthread_create);
401    --  DCE_THREADS has a nonstandard pthread_create
402
403    procedure pthread_detach (thread : access pthread_t);
404    pragma Import (C, pthread_detach);
405
406    procedure pthread_exit (status : System.Address);
407    pragma Import (C, pthread_exit, "pthread_exit");
408
409    function pthread_self return pthread_t;
410    pragma Import (C, pthread_self, "pthread_self");
411
412    --------------------------
413    -- POSIX.1c  Section 17 --
414    --------------------------
415
416    function pthread_setspecific
417      (key   : pthread_key_t;
418       value : System.Address) return int;
419    pragma Inline (pthread_setspecific);
420    --  DCE_THREADS has a nonstandard pthread_setspecific
421
422    function pthread_getspecific (key : pthread_key_t) return System.Address;
423    pragma Inline (pthread_getspecific);
424    --  DCE_THREADS has a nonstandard pthread_getspecific
425
426    type destructor_pointer is access procedure (arg : System.Address);
427
428    function pthread_key_create
429      (key        : access pthread_key_t;
430       destructor : destructor_pointer) return int;
431    pragma Inline (pthread_key_create);
432    --  DCE_THREADS has a nonstandard pthread_key_create
433
434 private
435
436    type array_type_1 is array (Integer range 0 .. 7) of unsigned_long;
437    type sigset_t is record
438       X_X_sigbits : array_type_1;
439    end record;
440    pragma Convention (C, sigset_t);
441
442    type pid_t is new int;
443
444    type time_t is new long;
445
446    type timespec is record
447       tv_sec  : time_t;
448       tv_nsec : long;
449    end record;
450    pragma Convention (C, timespec);
451
452    type clockid_t is new int;
453    CLOCK_REALTIME : constant clockid_t := 1;
454
455    type struct_timeval is record
456       tv_sec  : time_t;
457       tv_usec : time_t;
458    end record;
459    pragma Convention (C, struct_timeval);
460
461    type cma_t_address is new System.Address;
462
463    type cma_t_handle is record
464       field1 : cma_t_address;
465       field2 : Short_Integer;
466       field3 : Short_Integer;
467    end record;
468    for cma_t_handle'Size use 64;
469
470    type pthread_attr_t is new cma_t_handle;
471    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
472
473    type pthread_condattr_t is new cma_t_handle;
474    pragma Convention (C_Pass_By_Copy, pthread_condattr_t);
475
476    type pthread_mutexattr_t is new cma_t_handle;
477    pragma Convention (C_Pass_By_Copy, pthread_mutexattr_t);
478
479    type pthread_t is new cma_t_handle;
480    pragma Convention (C_Pass_By_Copy, pthread_t);
481
482    type pthread_mutex_t is new cma_t_handle;
483    pragma Convention (C_Pass_By_Copy, pthread_mutex_t);
484
485    type pthread_cond_t is new cma_t_handle;
486    pragma Convention (C_Pass_By_Copy, pthread_cond_t);
487
488    type pthread_key_t is new int;
489
490 end System.OS_Interface;