OSDN Git Service

2003-10-22 Arnaud Charlet <charlet@act-europe.fr>
[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 --             Copyright (C) 1991-1994, Florida State University            --
10 --             Copyright (C) 1995-2003, Ada Core Technologies               --
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 the HP-UX 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 ("-lcma");
49
50    subtype int            is Interfaces.C.int;
51    subtype short          is Interfaces.C.short;
52    subtype long           is Interfaces.C.long;
53    subtype unsigned       is Interfaces.C.unsigned;
54    subtype unsigned_short is Interfaces.C.unsigned_short;
55    subtype unsigned_long  is Interfaces.C.unsigned_long;
56    subtype unsigned_char  is Interfaces.C.unsigned_char;
57    subtype plain_char     is Interfaces.C.plain_char;
58    subtype size_t         is Interfaces.C.size_t;
59
60    -----------
61    -- Errno --
62    -----------
63
64    function errno return int;
65    pragma Import (C, errno, "__get_errno");
66
67    EAGAIN    : constant := 11;
68    EINTR     : constant := 4;
69    EINVAL    : constant := 22;
70    ENOMEM    : constant := 12;
71    ETIME     : constant := 52;
72    ETIMEDOUT : constant := 238;
73
74    FUNC_ERR : constant := -1;
75
76    -------------
77    -- Signals --
78    -------------
79
80    Max_Interrupt : constant := 44;
81    type Signal is new int range 0 .. Max_Interrupt;
82    for Signal'Size use int'Size;
83
84    SIGHUP     : constant := 1; --  hangup
85    SIGINT     : constant := 2; --  interrupt (rubout)
86    SIGQUIT    : constant := 3; --  quit (ASCD FS)
87    SIGILL     : constant := 4; --  illegal instruction (not reset)
88    SIGTRAP    : constant := 5; --  trace trap (not reset)
89    SIGIOT     : constant := 6; --  IOT instruction
90    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
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    SIGUSR1    : constant := 16; --  user defined signal 1
101    SIGUSR2    : constant := 17; --  user defined signal 2
102    SIGCLD     : constant := 18; --  alias for SIGCHLD
103    SIGCHLD    : constant := 18; --  child status change
104    SIGPWR     : constant := 19; --  power-fail restart
105    SIGVTALRM  : constant := 20; --  virtual timer alarm
106    SIGPROF    : constant := 21; --  profiling timer alarm
107    SIGIO      : constant := 22; --  asynchronous I/O
108    SIGPOLL    : constant := 22; --  pollable event occurred
109    SIGWINCH   : constant := 23; --  window size change
110    SIGSTOP    : constant := 24; --  stop (cannot be caught or ignored)
111    SIGTSTP    : constant := 25; --  user stop requested from tty
112    SIGCONT    : constant := 26; --  stopped process has been continued
113    SIGTTIN    : constant := 27; --  background tty read attempted
114    SIGTTOU    : constant := 28; --  background tty write attempted
115    SIGURG     : constant := 29; --  urgent condition on IO channel
116    SIGLOST    : constant := 30; --  remote lock lost  (NFS)
117    SIGDIL     : constant := 32; --  DIL signal
118    SIGXCPU    : constant := 33; --  CPU time limit exceeded (setrlimit)
119    SIGXFSZ    : constant := 34; --  file size limit exceeded (setrlimit)
120
121    SIGADAABORT : constant := SIGABRT;
122    --  Note: on other targets, we usually use SIGABRT, but on HP/UX, it
123    --  appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
124
125    type Signal_Set is array (Natural range <>) of Signal;
126
127    Unmasked    : constant Signal_Set :=
128      (SIGBUS, SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP);
129
130    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
131
132    type sigset_t is private;
133
134    type isr_address is access procedure (sig : int);
135
136    function intr_attach (sig : int; handler : isr_address) return long;
137
138    Intr_Attach_Reset : constant Boolean := True;
139    --  True if intr_attach is reset after an interrupt handler is called
140
141    function sigaddset (set : access sigset_t; sig : Signal) return int;
142    pragma Import (C, sigaddset, "sigaddset");
143
144    function sigdelset (set : access sigset_t; sig : Signal) return int;
145    pragma Import (C, sigdelset, "sigdelset");
146
147    function sigfillset (set : access sigset_t) return int;
148    pragma Import (C, sigfillset, "sigfillset");
149
150    function sigismember (set : access sigset_t; sig : Signal) return int;
151    pragma Import (C, sigismember, "sigismember");
152
153    function sigemptyset (set : access sigset_t) return int;
154    pragma Import (C, sigemptyset, "sigemptyset");
155
156    type Signal_Handler is access procedure (signo : Signal);
157
158    type struct_sigaction is record
159       sa_handler : System.Address;
160       sa_mask    : sigset_t;
161       sa_flags   : int;
162    end record;
163    pragma Convention (C, struct_sigaction);
164    type struct_sigaction_ptr is access all struct_sigaction;
165
166    SA_RESTART  : constant  := 16#40#;
167
168    SIG_BLOCK   : constant  := 0;
169    SIG_UNBLOCK : constant  := 1;
170    SIG_SETMASK : constant  := 2;
171
172    SIG_DFL : constant := 0;
173    SIG_IGN : constant := 1;
174    SIG_ERR : constant := -1;
175
176    function sigaction
177      (sig  : Signal;
178       act  : struct_sigaction_ptr;
179       oact : struct_sigaction_ptr) return int;
180    pragma Import (C, sigaction, "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; Tp : access timespec) return int;
197    pragma Import (C, Clock_Gettime);
198
199    function To_Duration (TS : timespec) return Duration;
200    pragma Inline (To_Duration);
201
202    function To_Timespec (D : Duration) return timespec;
203    pragma Inline (To_Timespec);
204
205    type struct_timeval is private;
206
207    function To_Duration (TV : struct_timeval) return Duration;
208    pragma Inline (To_Duration);
209
210    function To_Timeval (D : Duration) return struct_timeval;
211    pragma Inline (To_Timeval);
212
213    -------------------------
214    -- Priority Scheduling --
215    -------------------------
216
217    SCHED_FIFO  : constant := 0;
218    SCHED_RR    : constant := 1;
219    SCHED_OTHER : constant := 2;
220
221    -------------
222    -- Process --
223    -------------
224
225    type pid_t is private;
226
227    function kill (pid : pid_t; sig : Signal) return int;
228    pragma Import (C, kill, "kill");
229
230    function getpid return pid_t;
231    pragma Import (C, getpid, "getpid");
232
233    -------------
234    -- Threads --
235    -------------
236
237    type Thread_Body is access
238      function (arg : System.Address) return System.Address;
239    type pthread_t           is private;
240    subtype Thread_Id        is pthread_t;
241
242    type pthread_mutex_t     is limited private;
243    type pthread_cond_t      is limited private;
244    type pthread_attr_t      is limited private;
245    type pthread_mutexattr_t is limited private;
246    type pthread_condattr_t  is limited private;
247    type pthread_key_t       is private;
248
249    -----------
250    -- Stack --
251    -----------
252
253    function Get_Stack_Base (thread : pthread_t) return Address;
254    pragma Inline (Get_Stack_Base);
255    --  This is a dummy procedure to share some GNULLI files
256
257    ---------------------------------------
258    -- Nonstandard Thread Initialization --
259    ---------------------------------------
260
261    procedure pthread_init;
262    pragma Inline (pthread_init);
263    --  This is a dummy procedure to share some GNULLI files
264
265    -------------------------
266    -- POSIX.1c  Section 3 --
267    -------------------------
268
269    function sigwait (set : access sigset_t) return int;
270    pragma Import (C, sigwait, "cma_sigwait");
271
272    function sigwait
273      (set : access sigset_t;
274       sig : access Signal) return int;
275    pragma Inline (sigwait);
276    --  DCE_THREADS has a nonstandard sigwait
277
278    function pthread_kill
279      (thread : pthread_t;
280       sig    : Signal) return int;
281    pragma Inline (pthread_kill);
282    --  DCE_THREADS doesn't have pthread_kill
283
284    type sigset_t_ptr is access all sigset_t;
285
286    function pthread_sigmask
287      (how  : int;
288       set  : sigset_t_ptr;
289       oset : sigset_t_ptr) return int;
290    --  DCE THREADS does not have pthread_sigmask. Instead, it uses
291    --  sigprocmask to do the signal handling when the thread library is
292    --  sucked in.
293    pragma Import (C, pthread_sigmask, "sigprocmask");
294
295    --------------------------
296    -- POSIX.1c  Section 11 --
297    --------------------------
298
299    function pthread_mutexattr_init
300      (attr : access pthread_mutexattr_t) return int;
301    --  DCE_THREADS has a nonstandard pthread_mutexattr_init.
302
303    function pthread_mutexattr_destroy
304      (attr : access pthread_mutexattr_t) return int;
305    --  DCE_THREADS has a nonstandard pthread_mutexattr_destroy
306
307    function pthread_mutex_init
308      (mutex : access pthread_mutex_t;
309       attr  : access pthread_mutexattr_t) return int;
310    --  DCE_THREADS has a nonstandard pthread_mutex_init
311
312    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
313    --  DCE_THREADS has a nonstandard pthread_mutex_destroy
314
315    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
316    pragma Inline (pthread_mutex_lock);
317    --  DCE_THREADS has nonstandard pthread_mutex_lock
318
319    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
320    pragma Inline (pthread_mutex_unlock);
321    --  DCE_THREADS has nonstandard pthread_mutex_lock
322
323    function pthread_condattr_init
324      (attr : access pthread_condattr_t) return int;
325    --  DCE_THREADS has nonstandard pthread_condattr_init
326
327    function pthread_condattr_destroy
328      (attr : access pthread_condattr_t) return int;
329    --  DCE_THREADS has nonstandard pthread_condattr_destroy
330
331    function pthread_cond_init
332      (cond : access pthread_cond_t;
333       attr : access pthread_condattr_t) return int;
334    --  DCE_THREADS has nonstandard pthread_cond_init
335
336    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
337    --  DCE_THREADS has nonstandard pthread_cond_destroy
338
339    function pthread_cond_signal (cond : access pthread_cond_t) return int;
340    pragma Inline (pthread_cond_signal);
341    --  DCE_THREADS has nonstandard pthread_cond_signal
342
343    function pthread_cond_wait
344      (cond  : access pthread_cond_t;
345       mutex : access pthread_mutex_t) return int;
346    pragma Inline (pthread_cond_wait);
347    --  DCE_THREADS has a nonstandard pthread_cond_wait
348
349    function pthread_cond_timedwait
350      (cond    : access pthread_cond_t;
351       mutex   : access pthread_mutex_t;
352       abstime : access timespec) return int;
353    pragma Inline (pthread_cond_timedwait);
354    --  DCE_THREADS has a nonstandard pthread_cond_timedwait
355
356    --------------------------
357    -- POSIX.1c  Section 13 --
358    --------------------------
359
360    type struct_sched_param is record
361       sched_priority : int;  --  scheduling priority
362    end record;
363
364    function pthread_setschedparam
365      (thread : pthread_t;
366       policy : int;
367       param  : access struct_sched_param) return int;
368    pragma Inline (pthread_setschedparam);
369    --  DCE_THREADS has a nonstandard pthread_setschedparam
370
371    function sched_yield return int;
372    pragma Inline (sched_yield);
373    --  DCE_THREADS has a nonstandard sched_yield
374
375    ---------------------------
376    -- P1003.1c - Section 16 --
377    ---------------------------
378
379    function pthread_attr_init (attributes : access pthread_attr_t) return int;
380    pragma Inline (pthread_attr_init);
381    --  DCE_THREADS has a nonstandard pthread_attr_init
382
383    function pthread_attr_destroy
384      (attributes : access pthread_attr_t) return int;
385    pragma Inline (pthread_attr_destroy);
386    --  DCE_THREADS has a nonstandard pthread_attr_destroy
387
388    function pthread_attr_setstacksize
389      (attr      : access pthread_attr_t;
390       stacksize : size_t) return int;
391    pragma Inline (pthread_attr_setstacksize);
392    --  DCE_THREADS has a nonstandard pthread_attr_setstacksize
393
394    function pthread_create
395      (thread        : access pthread_t;
396       attributes    : access pthread_attr_t;
397       start_routine : Thread_Body;
398       arg           : System.Address) return int;
399    pragma Inline (pthread_create);
400    --  DCE_THREADS has a nonstandard pthread_create
401
402    procedure pthread_detach (thread : access pthread_t);
403    pragma Import (C, pthread_detach);
404
405    procedure pthread_exit (status : System.Address);
406    pragma Import (C, pthread_exit, "pthread_exit");
407
408    function pthread_self return pthread_t;
409    pragma Import (C, pthread_self, "pthread_self");
410
411    --------------------------
412    -- POSIX.1c  Section 17 --
413    --------------------------
414
415    function pthread_setspecific
416      (key   : pthread_key_t;
417       value : System.Address) return int;
418    pragma Inline (pthread_setspecific);
419    --  DCE_THREADS has a nonstandard pthread_setspecific
420
421    function pthread_getspecific (key : pthread_key_t) return System.Address;
422    pragma Inline (pthread_getspecific);
423    --  DCE_THREADS has a nonstandard pthread_getspecific
424
425    type destructor_pointer is access procedure (arg : System.Address);
426
427    function pthread_key_create
428      (key        : access pthread_key_t;
429       destructor : destructor_pointer) return int;
430    pragma Inline (pthread_key_create);
431    --  DCE_THREADS has a nonstandard pthread_key_create
432
433 private
434
435    type array_type_1 is array (Integer range 0 .. 7) of unsigned_long;
436    type sigset_t is record
437       X_X_sigbits : array_type_1;
438    end record;
439    pragma Convention (C, sigset_t);
440
441    type pid_t is new int;
442
443    type time_t is new long;
444
445    type timespec is record
446       tv_sec  : time_t;
447       tv_nsec : long;
448    end record;
449    pragma Convention (C, timespec);
450
451    type clockid_t is new int;
452    CLOCK_REALTIME : constant clockid_t := 1;
453
454    type struct_timeval is record
455       tv_sec  : time_t;
456       tv_usec : time_t;
457    end record;
458    pragma Convention (C, struct_timeval);
459
460    type cma_t_address is new System.Address;
461
462    type cma_t_handle is record
463       field1 : cma_t_address;
464       field2 : Short_Integer;
465       field3 : Short_Integer;
466    end record;
467    for cma_t_handle'Size use 64;
468
469    type pthread_attr_t is new cma_t_handle;
470    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
471
472    type pthread_condattr_t is new cma_t_handle;
473    pragma Convention (C_Pass_By_Copy, pthread_condattr_t);
474
475    type pthread_mutexattr_t is new cma_t_handle;
476    pragma Convention (C_Pass_By_Copy, pthread_mutexattr_t);
477
478    type pthread_t is new cma_t_handle;
479    pragma Convention (C_Pass_By_Copy, pthread_t);
480
481    type pthread_mutex_t is new cma_t_handle;
482    pragma Convention (C_Pass_By_Copy, pthread_mutex_t);
483
484    type pthread_cond_t is new cma_t_handle;
485    pragma Convention (C_Pass_By_Copy, pthread_cond_t);
486
487    type pthread_key_t is new int;
488
489 end System.OS_Interface;