OSDN Git Service

2007-12-06 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-hpux-dce.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-2007, 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 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 or remove the pragma
41 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
42
43 with Interfaces.C;
44 with Ada.Unchecked_Conversion;
45
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    pragma Convention (C, isr_address);
137
138    function intr_attach (sig : int; handler : isr_address) return long;
139
140    Intr_Attach_Reset : constant Boolean := True;
141    --  True if intr_attach is reset after an interrupt handler is called
142
143    function sigaddset (set : access sigset_t; sig : Signal) return int;
144    pragma Import (C, sigaddset, "sigaddset");
145
146    function sigdelset (set : access sigset_t; sig : Signal) return int;
147    pragma Import (C, sigdelset, "sigdelset");
148
149    function sigfillset (set : access sigset_t) return int;
150    pragma Import (C, sigfillset, "sigfillset");
151
152    function sigismember (set : access sigset_t; sig : Signal) return int;
153    pragma Import (C, sigismember, "sigismember");
154
155    function sigemptyset (set : access sigset_t) return int;
156    pragma Import (C, sigemptyset, "sigemptyset");
157
158    type Signal_Handler is access procedure (signo : Signal);
159
160    type struct_sigaction is record
161       sa_handler : System.Address;
162       sa_mask    : sigset_t;
163       sa_flags   : int;
164    end record;
165    pragma Convention (C, struct_sigaction);
166    type struct_sigaction_ptr is access all struct_sigaction;
167
168    SA_RESTART  : constant  := 16#40#;
169    SA_SIGINFO  : constant  := 16#10#;
170
171    SIG_BLOCK   : constant  := 0;
172    SIG_UNBLOCK : constant  := 1;
173    SIG_SETMASK : constant  := 2;
174
175    SIG_DFL : constant := 0;
176    SIG_IGN : constant := 1;
177    SIG_ERR : constant := -1;
178
179    function sigaction
180      (sig  : Signal;
181       act  : struct_sigaction_ptr;
182       oact : struct_sigaction_ptr) return int;
183    pragma Import (C, sigaction, "sigaction");
184
185    ----------
186    -- Time --
187    ----------
188
189    type timespec is private;
190
191    function nanosleep (rqtp, rmtp : access timespec) return int;
192    pragma Import (C, nanosleep);
193
194    type clockid_t is private;
195
196    CLOCK_REALTIME : constant clockid_t;
197
198    function Clock_Gettime
199      (Clock_Id : clockid_t; Tp : access timespec) return int;
200    pragma Import (C, Clock_Gettime);
201
202    function To_Duration (TS : timespec) return Duration;
203    pragma Inline (To_Duration);
204
205    function To_Timespec (D : Duration) return timespec;
206    pragma Inline (To_Timespec);
207
208    type struct_timeval is private;
209
210    function To_Duration (TV : struct_timeval) return Duration;
211    pragma Inline (To_Duration);
212
213    function To_Timeval (D : Duration) return struct_timeval;
214    pragma Inline (To_Timeval);
215
216    -------------------------
217    -- Priority Scheduling --
218    -------------------------
219
220    SCHED_FIFO  : constant := 0;
221    SCHED_RR    : constant := 1;
222    SCHED_OTHER : constant := 2;
223
224    -------------
225    -- Process --
226    -------------
227
228    type pid_t is private;
229
230    function kill (pid : pid_t; sig : Signal) return int;
231    pragma Import (C, kill, "kill");
232
233    function getpid return pid_t;
234    pragma Import (C, getpid, "getpid");
235
236    -------------
237    -- Threads --
238    -------------
239
240    type Thread_Body is access
241      function (arg : System.Address) return System.Address;
242    pragma Convention (C, Thread_Body);
243
244    function Thread_Body_Access is new
245      Ada.Unchecked_Conversion (System.Address, Thread_Body);
246
247    type pthread_t           is private;
248    subtype Thread_Id        is pthread_t;
249
250    type pthread_mutex_t     is limited private;
251    type pthread_cond_t      is limited private;
252    type pthread_attr_t      is limited private;
253    type pthread_mutexattr_t is limited private;
254    type pthread_condattr_t  is limited private;
255    type pthread_key_t       is private;
256
257    -----------
258    -- Stack --
259    -----------
260
261    function Get_Stack_Base (thread : pthread_t) return Address;
262    pragma Inline (Get_Stack_Base);
263    --  This is a dummy procedure to share some GNULLI files
264
265    ---------------------------------------
266    -- Nonstandard Thread Initialization --
267    ---------------------------------------
268
269    procedure pthread_init;
270    pragma Inline (pthread_init);
271    --  This is a dummy procedure to share some GNULLI files
272
273    -------------------------
274    -- POSIX.1c  Section 3 --
275    -------------------------
276
277    function sigwait (set : access sigset_t) return int;
278    pragma Import (C, sigwait, "cma_sigwait");
279
280    function sigwait
281      (set : access sigset_t;
282       sig : access Signal) return int;
283    pragma Inline (sigwait);
284    --  DCE_THREADS has a nonstandard sigwait
285
286    function pthread_kill
287      (thread : pthread_t;
288       sig    : Signal) return int;
289    pragma Inline (pthread_kill);
290    --  DCE_THREADS doesn't have pthread_kill
291
292    function pthread_sigmask
293      (how  : int;
294       set  : access sigset_t;
295       oset : access sigset_t) return int;
296    --  DCE THREADS does not have pthread_sigmask. Instead, it uses sigprocmask
297    --  to do the signal handling when the thread library is sucked in.
298    pragma Import (C, pthread_sigmask, "sigprocmask");
299
300    --------------------------
301    -- POSIX.1c  Section 11 --
302    --------------------------
303
304    function pthread_mutexattr_init
305      (attr : access pthread_mutexattr_t) return int;
306    --  DCE_THREADS has a nonstandard pthread_mutexattr_init
307
308    function pthread_mutexattr_destroy
309      (attr : access pthread_mutexattr_t) return int;
310    --  DCE_THREADS has a nonstandard pthread_mutexattr_destroy
311
312    function pthread_mutex_init
313      (mutex : access pthread_mutex_t;
314       attr  : access pthread_mutexattr_t) return int;
315    --  DCE_THREADS has a nonstandard pthread_mutex_init
316
317    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
318    --  DCE_THREADS has a nonstandard pthread_mutex_destroy
319
320    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
321    pragma Inline (pthread_mutex_lock);
322    --  DCE_THREADS has nonstandard pthread_mutex_lock
323
324    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
325    pragma Inline (pthread_mutex_unlock);
326    --  DCE_THREADS has nonstandard pthread_mutex_lock
327
328    function pthread_condattr_init
329      (attr : access pthread_condattr_t) return int;
330    --  DCE_THREADS has nonstandard pthread_condattr_init
331
332    function pthread_condattr_destroy
333      (attr : access pthread_condattr_t) return int;
334    --  DCE_THREADS has nonstandard pthread_condattr_destroy
335
336    function pthread_cond_init
337      (cond : access pthread_cond_t;
338       attr : access pthread_condattr_t) return int;
339    --  DCE_THREADS has nonstandard pthread_cond_init
340
341    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
342    --  DCE_THREADS has nonstandard pthread_cond_destroy
343
344    function pthread_cond_signal (cond : access pthread_cond_t) return int;
345    pragma Inline (pthread_cond_signal);
346    --  DCE_THREADS has nonstandard 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 Inline (pthread_cond_wait);
352    --  DCE_THREADS has a nonstandard pthread_cond_wait
353
354    function pthread_cond_timedwait
355      (cond    : access pthread_cond_t;
356       mutex   : access pthread_mutex_t;
357       abstime : access timespec) return int;
358    pragma Inline (pthread_cond_timedwait);
359    --  DCE_THREADS has a nonstandard pthread_cond_timedwait
360
361    --------------------------
362    -- POSIX.1c  Section 13 --
363    --------------------------
364
365    type struct_sched_param is record
366       sched_priority : int;  --  scheduling priority
367    end record;
368
369    function pthread_setschedparam
370      (thread : pthread_t;
371       policy : int;
372       param  : access struct_sched_param) return int;
373    pragma Inline (pthread_setschedparam);
374    --  DCE_THREADS has a nonstandard pthread_setschedparam
375
376    function sched_yield return int;
377    pragma Inline (sched_yield);
378    --  DCE_THREADS has a nonstandard sched_yield
379
380    ---------------------------
381    -- P1003.1c - Section 16 --
382    ---------------------------
383
384    function pthread_attr_init (attributes : access pthread_attr_t) return int;
385    pragma Inline (pthread_attr_init);
386    --  DCE_THREADS has a nonstandard pthread_attr_init
387
388    function pthread_attr_destroy
389      (attributes : access pthread_attr_t) return int;
390    pragma Inline (pthread_attr_destroy);
391    --  DCE_THREADS has a nonstandard pthread_attr_destroy
392
393    function pthread_attr_setstacksize
394      (attr      : access pthread_attr_t;
395       stacksize : size_t) return int;
396    pragma Inline (pthread_attr_setstacksize);
397    --  DCE_THREADS has a nonstandard pthread_attr_setstacksize
398
399    function pthread_create
400      (thread        : access pthread_t;
401       attributes    : access pthread_attr_t;
402       start_routine : Thread_Body;
403       arg           : System.Address) return int;
404    pragma Inline (pthread_create);
405    --  DCE_THREADS has a nonstandard pthread_create
406
407    procedure pthread_detach (thread : access pthread_t);
408    pragma Import (C, pthread_detach);
409
410    procedure pthread_exit (status : System.Address);
411    pragma Import (C, pthread_exit, "pthread_exit");
412
413    function pthread_self return pthread_t;
414    pragma Import (C, pthread_self, "pthread_self");
415
416    --------------------------
417    -- POSIX.1c  Section 17 --
418    --------------------------
419
420    function pthread_setspecific
421      (key   : pthread_key_t;
422       value : System.Address) return int;
423    pragma Inline (pthread_setspecific);
424    --  DCE_THREADS has a nonstandard pthread_setspecific
425
426    function pthread_getspecific (key : pthread_key_t) return System.Address;
427    pragma Inline (pthread_getspecific);
428    --  DCE_THREADS has a nonstandard pthread_getspecific
429
430    type destructor_pointer is access procedure (arg : System.Address);
431    pragma Convention (C, destructor_pointer);
432
433    function pthread_key_create
434      (key        : access pthread_key_t;
435       destructor : destructor_pointer) return int;
436    pragma Inline (pthread_key_create);
437    --  DCE_THREADS has a nonstandard pthread_key_create
438
439 private
440
441    type array_type_1 is array (Integer range 0 .. 7) of unsigned_long;
442    type sigset_t is record
443       X_X_sigbits : array_type_1;
444    end record;
445    pragma Convention (C, sigset_t);
446
447    type pid_t is new int;
448
449    type time_t is new long;
450
451    type timespec is record
452       tv_sec  : time_t;
453       tv_nsec : long;
454    end record;
455    pragma Convention (C, timespec);
456
457    type clockid_t is new int;
458    CLOCK_REALTIME : constant clockid_t := 1;
459
460    type struct_timeval is record
461       tv_sec  : time_t;
462       tv_usec : time_t;
463    end record;
464    pragma Convention (C, struct_timeval);
465
466    type cma_t_address is new System.Address;
467
468    type cma_t_handle is record
469       field1 : cma_t_address;
470       field2 : Short_Integer;
471       field3 : Short_Integer;
472    end record;
473    for cma_t_handle'Size use 64;
474
475    type pthread_attr_t is new cma_t_handle;
476    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
477
478    type pthread_condattr_t is new cma_t_handle;
479    pragma Convention (C_Pass_By_Copy, pthread_condattr_t);
480
481    type pthread_mutexattr_t is new cma_t_handle;
482    pragma Convention (C_Pass_By_Copy, pthread_mutexattr_t);
483
484    type pthread_t is new cma_t_handle;
485    pragma Convention (C_Pass_By_Copy, pthread_t);
486
487    type pthread_mutex_t is new cma_t_handle;
488    pragma Convention (C_Pass_By_Copy, pthread_mutex_t);
489
490    type pthread_cond_t is new cma_t_handle;
491    pragma Convention (C_Pass_By_Copy, pthread_cond_t);
492
493    type pthread_key_t is new int;
494
495 end System.OS_Interface;