OSDN Git Service

2007-12-06 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-hpux.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 a HPUX 11.0 (Native THREADS) 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 --  This package encapsulates all direct interfaces to OS services
41 --  that are needed by children of System.
42
43 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
44 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
45
46 with Interfaces.C;
47 with Ada.Unchecked_Conversion;
48
49 package System.OS_Interface is
50    pragma Preelaborate;
51
52    pragma Linker_Options ("-lpthread");
53
54    subtype int            is Interfaces.C.int;
55    subtype short          is Interfaces.C.short;
56    subtype long           is Interfaces.C.long;
57    subtype unsigned       is Interfaces.C.unsigned;
58    subtype unsigned_short is Interfaces.C.unsigned_short;
59    subtype unsigned_long  is Interfaces.C.unsigned_long;
60    subtype unsigned_char  is Interfaces.C.unsigned_char;
61    subtype plain_char     is Interfaces.C.plain_char;
62    subtype size_t         is Interfaces.C.size_t;
63
64    -----------
65    -- Errno --
66    -----------
67
68    function errno return int;
69    pragma Import (C, errno, "__get_errno");
70
71    EAGAIN    : constant := 11;
72    EINTR     : constant := 4;
73    EINVAL    : constant := 22;
74    ENOMEM    : constant := 12;
75    ETIMEDOUT : constant := 238;
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    SIGCANCEL  : constant := 35; --  used for pthread cancellation.
122    SIGGFAULT  : constant := 36; --  Graphics framebuffer fault
123
124    SIGADAABORT : constant := SIGABRT;
125    --  Note: on other targets, we usually use SIGABRT, but on HPUX, it
126    --  appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
127
128    type Signal_Set is array (Natural range <>) of Signal;
129
130    Unmasked    : constant Signal_Set :=
131      (SIGABRT, SIGPIPE, SIGBUS, SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF,
132       SIGALRM, SIGVTALRM, SIGIO, SIGCHLD);
133
134    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
135
136    type sigset_t is private;
137
138    function sigaddset (set : access sigset_t; sig : Signal) return int;
139    pragma Import (C, sigaddset, "sigaddset");
140
141    function sigdelset (set : access sigset_t; sig : Signal) return int;
142    pragma Import (C, sigdelset, "sigdelset");
143
144    function sigfillset (set : access sigset_t) return int;
145    pragma Import (C, sigfillset, "sigfillset");
146
147    function sigismember (set : access sigset_t; sig : Signal) return int;
148    pragma Import (C, sigismember, "sigismember");
149
150    function sigemptyset (set : access sigset_t) return int;
151    pragma Import (C, sigemptyset, "sigemptyset");
152
153    type struct_sigaction is record
154       sa_handler : System.Address;
155       sa_mask    : sigset_t;
156       sa_flags   : int;
157    end record;
158    pragma Convention (C, struct_sigaction);
159    type struct_sigaction_ptr is access all struct_sigaction;
160
161    SA_SIGINFO  : constant := 16#10#;
162
163    SIG_BLOCK   : constant := 0;
164    SIG_UNBLOCK : constant := 1;
165    SIG_SETMASK : constant := 2;
166
167    SIG_DFL : constant := 0;
168    SIG_IGN : constant := 1;
169
170    function sigaction
171      (sig  : Signal;
172       act  : struct_sigaction_ptr;
173       oact : struct_sigaction_ptr) return int;
174    pragma Import (C, sigaction, "sigaction");
175
176    ----------
177    -- Time --
178    ----------
179
180    Time_Slice_Supported : constant Boolean := True;
181    --  Indicates wether time slicing is supported
182
183    type timespec is private;
184
185    type clockid_t is private;
186
187    CLOCK_REALTIME : constant clockid_t;
188
189    function clock_gettime
190      (clock_id : clockid_t;
191       tp       : access timespec) return int;
192    pragma Import (C, clock_gettime, "clock_gettime");
193
194    function clock_getres
195      (clock_id : clockid_t;
196       res      : access timespec) return int;
197    pragma Import (C, clock_getres, "clock_getres");
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_timezone is record
206       tz_minuteswest : int;
207       tz_dsttime     : int;
208    end record;
209    pragma Convention (C, struct_timezone);
210    type struct_timezone_ptr is access all struct_timezone;
211
212    type struct_timeval is private;
213    --  This is needed on systems that do not have clock_gettime()
214    --  but do have gettimeofday().
215
216    function To_Duration (TV : struct_timeval) return Duration;
217    pragma Inline (To_Duration);
218
219    function To_Timeval (D : Duration) return struct_timeval;
220    pragma Inline (To_Timeval);
221
222    -------------------------
223    -- Priority Scheduling --
224    -------------------------
225
226    SCHED_FIFO  : constant := 0;
227    SCHED_RR    : constant := 1;
228    SCHED_OTHER : constant := 2;
229
230    function To_Target_Priority
231      (Prio : System.Any_Priority) return Interfaces.C.int;
232    --  Maps System.Any_Priority to a POSIX priority
233
234    -------------
235    -- Process --
236    -------------
237
238    type pid_t is private;
239
240    function kill (pid : pid_t; sig : Signal) return int;
241    pragma Import (C, kill, "kill");
242
243    function getpid return pid_t;
244    pragma Import (C, getpid, "getpid");
245
246    ---------
247    -- LWP --
248    ---------
249
250    function lwp_self return System.Address;
251    pragma Import (C, lwp_self, "_lwp_self");
252
253    -------------
254    -- Threads --
255    -------------
256
257    type Thread_Body is access
258      function (arg : System.Address) return System.Address;
259    pragma Convention (C, Thread_Body);
260
261    function Thread_Body_Access is new
262      Ada.Unchecked_Conversion (System.Address, Thread_Body);
263
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 := 16#de#;
275
276    PTHREAD_SCOPE_PROCESS : constant := 2;
277    PTHREAD_SCOPE_SYSTEM  : constant := 1;
278
279    -----------
280    -- Stack --
281    -----------
282
283    Stack_Base_Available : constant Boolean := False;
284    --  Indicates wether the stack base is available on this target
285
286    function Get_Stack_Base (thread : pthread_t) return Address;
287    pragma Inline (Get_Stack_Base);
288    --  returns the stack base of the specified thread.
289    --  Only call this function when Stack_Base_Available is True.
290
291    function Get_Page_Size return size_t;
292    function Get_Page_Size return Address;
293    pragma Import (C, Get_Page_Size, "getpagesize");
294    --  returns the size of a page, or 0 if this is not relevant on this
295    --  target
296
297    PROT_NONE  : constant := 0;
298    PROT_READ  : constant := 1;
299    PROT_WRITE : constant := 2;
300    PROT_EXEC  : constant := 4;
301    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
302
303    PROT_ON    : constant := PROT_READ;
304    PROT_OFF   : constant := PROT_ALL;
305
306    function mprotect (addr : Address; len : size_t; prot : int) return int;
307    pragma Import (C, mprotect);
308
309    ---------------------------------------
310    -- Nonstandard Thread Initialization --
311    ---------------------------------------
312
313    procedure pthread_init;
314    pragma Inline (pthread_init);
315    --  This is a dummy procedure to share some GNULLI files
316
317    -------------------------
318    -- POSIX.1c  Section 3 --
319    -------------------------
320
321    function sigwait
322      (set : access sigset_t;
323       sig : access Signal) return int;
324    pragma Import (C, sigwait, "sigwait");
325
326    function pthread_kill
327      (thread : pthread_t;
328       sig    : Signal) return int;
329    pragma Import (C, pthread_kill, "pthread_kill");
330
331    function pthread_sigmask
332      (how  : int;
333       set  : access sigset_t;
334       oset : access sigset_t) return int;
335    pragma Import (C, pthread_sigmask, "pthread_sigmask");
336
337    --------------------------
338    -- POSIX.1c  Section 11 --
339    --------------------------
340
341    function pthread_mutexattr_init
342      (attr : access pthread_mutexattr_t) return int;
343    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
344
345    function pthread_mutexattr_destroy
346      (attr : access pthread_mutexattr_t) return int;
347    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
348
349    function pthread_mutex_init
350      (mutex : access pthread_mutex_t;
351       attr  : access pthread_mutexattr_t) return int;
352    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
353
354    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
355    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
356
357    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
358    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
359
360    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
361    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
362
363    function pthread_condattr_init
364      (attr : access pthread_condattr_t) return int;
365    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
366
367    function pthread_condattr_destroy
368      (attr : access pthread_condattr_t) return int;
369    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
370
371    function pthread_cond_init
372      (cond : access pthread_cond_t;
373       attr : access pthread_condattr_t) return int;
374    pragma Import (C, pthread_cond_init, "pthread_cond_init");
375
376    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
377    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
378
379    function pthread_cond_signal (cond : access pthread_cond_t) return int;
380    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
381
382    function pthread_cond_wait
383      (cond  : access pthread_cond_t;
384       mutex : access pthread_mutex_t) return int;
385    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
386
387    function pthread_cond_timedwait
388      (cond    : access pthread_cond_t;
389       mutex   : access pthread_mutex_t;
390       abstime : access timespec) return int;
391    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
392
393    Relative_Timed_Wait : constant Boolean := False;
394    --  pthread_cond_timedwait requires an absolute delay time
395
396    --------------------------
397    -- POSIX.1c  Section 13 --
398    --------------------------
399
400    PTHREAD_PRIO_NONE    : constant := 16#100#;
401    PTHREAD_PRIO_PROTECT : constant := 16#200#;
402    PTHREAD_PRIO_INHERIT : constant := 16#400#;
403
404    function pthread_mutexattr_setprotocol
405      (attr     : access pthread_mutexattr_t;
406       protocol : int) return int;
407    pragma Import (C, pthread_mutexattr_setprotocol);
408
409    function pthread_mutexattr_setprioceiling
410      (attr     : access pthread_mutexattr_t;
411       prioceiling : int) return int;
412    pragma Import (C, pthread_mutexattr_setprioceiling);
413
414    type Array_7_Int is array (0 .. 6) of int;
415    type struct_sched_param is record
416       sched_priority : int;
417       sched_reserved : Array_7_Int;
418    end record;
419
420    function pthread_setschedparam
421      (thread : pthread_t;
422       policy : int;
423       param  : access struct_sched_param)
424      return int;
425    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
426
427    function pthread_attr_setscope
428      (attr            : access pthread_attr_t;
429       contentionscope : int) return int;
430    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
431
432    function pthread_attr_setinheritsched
433      (attr         : access pthread_attr_t;
434       inheritsched : int) return int;
435    pragma Import (C, pthread_attr_setinheritsched);
436
437    function pthread_attr_setschedpolicy
438      (attr   : access pthread_attr_t;
439       policy : int) return int;
440    pragma Import (C, pthread_attr_setschedpolicy);
441
442    function sched_yield return int;
443    pragma Import (C, sched_yield, "sched_yield");
444
445    --------------------------
446    -- P1003.1c  Section 16 --
447    --------------------------
448
449    function pthread_attr_init
450      (attributes : access pthread_attr_t) return int;
451    pragma Import (C, pthread_attr_init, "__pthread_attr_init_system");
452
453    function pthread_attr_destroy
454      (attributes : access pthread_attr_t) return int;
455    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
456
457    function pthread_attr_setdetachstate
458      (attr        : access pthread_attr_t;
459       detachstate : int) return int;
460    pragma Import (C, pthread_attr_setdetachstate);
461
462    function pthread_attr_setstacksize
463      (attr      : access pthread_attr_t;
464       stacksize : size_t) return int;
465    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
466
467    function pthread_create
468      (thread        : access pthread_t;
469       attributes    : access pthread_attr_t;
470       start_routine : Thread_Body;
471       arg           : System.Address) return int;
472    pragma Import (C, pthread_create, "__pthread_create_system");
473
474    procedure pthread_exit (status : System.Address);
475    pragma Import (C, pthread_exit, "pthread_exit");
476
477    function pthread_self return pthread_t;
478    pragma Import (C, pthread_self, "pthread_self");
479
480    --------------------------
481    -- POSIX.1c  Section 17 --
482    --------------------------
483
484    function pthread_setspecific
485      (key   : pthread_key_t;
486       value : System.Address) return int;
487    pragma Import (C, pthread_setspecific, "pthread_setspecific");
488
489    function pthread_getspecific (key : pthread_key_t) return System.Address;
490    pragma Import (C, pthread_getspecific, "pthread_getspecific");
491
492    type destructor_pointer is access procedure (arg : System.Address);
493    pragma Convention (C, destructor_pointer);
494
495    function pthread_key_create
496      (key        : access pthread_key_t;
497       destructor : destructor_pointer) return int;
498    pragma Import (C, pthread_key_create, "pthread_key_create");
499
500 private
501
502    type unsigned_int_array_8 is array (0 .. 7) of unsigned;
503    type sigset_t is record
504       sigset : unsigned_int_array_8;
505    end record;
506    pragma Convention (C_Pass_By_Copy, sigset_t);
507
508    type pid_t is new int;
509
510    type time_t is new long;
511
512    type timespec is record
513       tv_sec  : time_t;
514       tv_nsec : long;
515    end record;
516    pragma Convention (C, timespec);
517
518    type clockid_t is new int;
519    CLOCK_REALTIME : constant clockid_t := 1;
520
521    type struct_timeval is record
522       tv_sec  : time_t;
523       tv_usec : time_t;
524    end record;
525    pragma Convention (C, struct_timeval);
526
527    type pthread_attr_t is new int;
528    type pthread_condattr_t is new int;
529    type pthread_mutexattr_t is new int;
530    type pthread_t is new int;
531
532    type short_array is array (Natural range <>) of short;
533    type int_array is array (Natural range <>) of int;
534
535    type pthread_mutex_t is record
536       m_short : short_array (0 .. 1);
537       m_int   : int;
538       m_int1  : int_array (0 .. 3);
539       m_pad   : int;
540
541       m_ptr : int;
542       --  actually m_ptr is a void*, and on 32 bit ABI, m_pad is added so that
543       --  this field takes 64 bits. On 64 bit ABI, m_pad is gone, and m_ptr is
544       --  a 64 bit void*. Assume int'Size = 32.
545
546       m_int2   : int_array (0 .. 1);
547       m_int3   : int_array (0 .. 3);
548       m_short2 : short_array (0 .. 1);
549       m_int4   : int_array (0 .. 4);
550       m_int5   : int_array (0 .. 1);
551    end record;
552    for pthread_mutex_t'Alignment use System.Address'Alignment;
553    pragma Convention (C, pthread_mutex_t);
554
555    type pthread_cond_t is record
556       c_short : short_array (0 .. 1);
557       c_int   : int;
558       c_int1  : int_array (0 .. 3);
559       m_pad   : int;
560       m_ptr   : int;  --  see comment in pthread_mutex_t
561       c_int2  : int_array (0 .. 1);
562       c_int3  : int_array (0 .. 1);
563       c_int4  : int_array (0 .. 1);
564    end record;
565    for pthread_cond_t'Alignment use System.Address'Alignment;
566    pragma Convention (C, pthread_cond_t);
567
568    type pthread_key_t is new int;
569
570 end System.OS_Interface;