OSDN Git Service

2011-08-05 Yannick Moy <moy@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-2010, Free Software Foundation, Inc.       --
11 --                                                                          --
12 -- GNAT 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 3,  or (at your option) any later ver- --
15 -- sion.  GNAT 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.                                     --
18 --                                                                          --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception,   --
21 -- version 3.1, as published by the Free Software Foundation.               --
22 --                                                                          --
23 -- You should have received a copy of the GNU General Public License and    --
24 -- a copy of the GCC Runtime Library Exception along with this program;     --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
26 -- <http://www.gnu.org/licenses/>.                                          --
27 --                                                                          --
28 -- GNARL was developed by the GNARL team at Florida State University.       --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
30 --                                                                          --
31 ------------------------------------------------------------------------------
32
33 --  This is a HPUX 11.0 (Native THREADS) version of this package
34
35 --  This package encapsulates all direct interfaces to OS services that are
36 --  needed by the tasking run-time (libgnarl).
37
38 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
40
41 with Ada.Unchecked_Conversion;
42
43 with Interfaces.C;
44
45 package System.OS_Interface is
46    pragma Preelaborate;
47
48    pragma Linker_Options ("-lpthread");
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    ETIMEDOUT : constant := 238;
72
73    -------------
74    -- Signals --
75    -------------
76
77    Max_Interrupt : constant := 44;
78    type Signal is new int range 0 .. Max_Interrupt;
79    for Signal'Size use int'Size;
80
81    SIGHUP     : constant := 1; --  hangup
82    SIGINT     : constant := 2; --  interrupt (rubout)
83    SIGQUIT    : constant := 3; --  quit (ASCD FS)
84    SIGILL     : constant := 4; --  illegal instruction (not reset)
85    SIGTRAP    : constant := 5; --  trace trap (not reset)
86    SIGIOT     : constant := 6; --  IOT instruction
87    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the future
88    SIGEMT     : constant := 7; --  EMT instruction
89    SIGFPE     : constant := 8; --  floating point exception
90    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
91    SIGBUS     : constant := 10; --  bus error
92    SIGSEGV    : constant := 11; --  segmentation violation
93    SIGSYS     : constant := 12; --  bad argument to system call
94    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
95    SIGALRM    : constant := 14; --  alarm clock
96    SIGTERM    : constant := 15; --  software termination signal from kill
97    SIGUSR1    : constant := 16; --  user defined signal 1
98    SIGUSR2    : constant := 17; --  user defined signal 2
99    SIGCLD     : constant := 18; --  alias for SIGCHLD
100    SIGCHLD    : constant := 18; --  child status change
101    SIGPWR     : constant := 19; --  power-fail restart
102    SIGVTALRM  : constant := 20; --  virtual timer alarm
103    SIGPROF    : constant := 21; --  profiling timer alarm
104    SIGIO      : constant := 22; --  asynchronous I/O
105    SIGPOLL    : constant := 22; --  pollable event occurred
106    SIGWINCH   : constant := 23; --  window size change
107    SIGSTOP    : constant := 24; --  stop (cannot be caught or ignored)
108    SIGTSTP    : constant := 25; --  user stop requested from tty
109    SIGCONT    : constant := 26; --  stopped process has been continued
110    SIGTTIN    : constant := 27; --  background tty read attempted
111    SIGTTOU    : constant := 28; --  background tty write attempted
112    SIGURG     : constant := 29; --  urgent condition on IO channel
113    SIGLOST    : constant := 30; --  remote lock lost  (NFS)
114    SIGDIL     : constant := 32; --  DIL signal
115    SIGXCPU    : constant := 33; --  CPU time limit exceeded (setrlimit)
116    SIGXFSZ    : constant := 34; --  file size limit exceeded (setrlimit)
117    SIGCANCEL  : constant := 35; --  used for pthread cancellation.
118    SIGGFAULT  : constant := 36; --  Graphics framebuffer fault
119
120    SIGADAABORT : constant := SIGABRT;
121    --  Note: on other targets, we usually use SIGABRT, but on HPUX, it
122    --  appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
123    --  Do we use SIGTERM or SIGABRT???
124
125    type Signal_Set is array (Natural range <>) of Signal;
126
127    Unmasked    : constant Signal_Set :=
128      (SIGABRT, SIGPIPE, SIGBUS, SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF,
129       SIGALRM, SIGVTALRM, SIGIO, SIGCHLD);
130
131    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
132
133    type sigset_t is private;
134
135    function sigaddset (set : access sigset_t; sig : Signal) return int;
136    pragma Import (C, sigaddset, "sigaddset");
137
138    function sigdelset (set : access sigset_t; sig : Signal) return int;
139    pragma Import (C, sigdelset, "sigdelset");
140
141    function sigfillset (set : access sigset_t) return int;
142    pragma Import (C, sigfillset, "sigfillset");
143
144    function sigismember (set : access sigset_t; sig : Signal) return int;
145    pragma Import (C, sigismember, "sigismember");
146
147    function sigemptyset (set : access sigset_t) return int;
148    pragma Import (C, sigemptyset, "sigemptyset");
149
150    type struct_sigaction is record
151       sa_handler : System.Address;
152       sa_mask    : sigset_t;
153       sa_flags   : int;
154    end record;
155    pragma Convention (C, struct_sigaction);
156    type struct_sigaction_ptr is access all struct_sigaction;
157
158    SA_SIGINFO : constant := 16#10#;
159    SA_ONSTACK : constant := 16#01#;
160
161    SIG_BLOCK   : constant := 0;
162    SIG_UNBLOCK : constant := 1;
163    SIG_SETMASK : constant := 2;
164
165    SIG_DFL : constant := 0;
166    SIG_IGN : constant := 1;
167
168    function sigaction
169      (sig  : Signal;
170       act  : struct_sigaction_ptr;
171       oact : struct_sigaction_ptr) return int;
172    pragma Import (C, sigaction, "sigaction");
173
174    ----------
175    -- Time --
176    ----------
177
178    Time_Slice_Supported : constant Boolean := True;
179    --  Indicates whether time slicing is supported
180
181    type timespec is private;
182
183    type clockid_t is private;
184
185    CLOCK_REALTIME : constant clockid_t;
186
187    function clock_gettime
188      (clock_id : clockid_t;
189       tp       : access timespec) return int;
190    pragma Import (C, clock_gettime, "clock_gettime");
191
192    function clock_getres
193      (clock_id : clockid_t;
194       res      : access timespec) return int;
195    pragma Import (C, clock_getres, "clock_getres");
196
197    function To_Duration (TS : timespec) return Duration;
198    pragma Inline (To_Duration);
199
200    function To_Timespec (D : Duration) return timespec;
201    pragma Inline (To_Timespec);
202
203    type struct_timezone is record
204       tz_minuteswest : int;
205       tz_dsttime     : int;
206    end record;
207    pragma Convention (C, struct_timezone);
208    type struct_timezone_ptr is access all struct_timezone;
209
210    -------------------------
211    -- Priority Scheduling --
212    -------------------------
213
214    SCHED_FIFO  : constant := 0;
215    SCHED_RR    : constant := 1;
216    SCHED_OTHER : constant := 2;
217
218    function To_Target_Priority
219      (Prio : System.Any_Priority) return Interfaces.C.int;
220    --  Maps System.Any_Priority to a POSIX priority
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    -- LWP --
236    ---------
237
238    function lwp_self return System.Address;
239    pragma Import (C, lwp_self, "_lwp_self");
240
241    -------------
242    -- Threads --
243    -------------
244
245    type Thread_Body is access
246      function (arg : System.Address) return System.Address;
247    pragma Convention (C, Thread_Body);
248
249    function Thread_Body_Access is new
250      Ada.Unchecked_Conversion (System.Address, Thread_Body);
251
252    type pthread_t           is private;
253    subtype Thread_Id        is pthread_t;
254
255    type pthread_mutex_t     is limited private;
256    type pthread_cond_t      is limited private;
257    type pthread_attr_t      is limited private;
258    type pthread_mutexattr_t is limited private;
259    type pthread_condattr_t  is limited private;
260    type pthread_key_t       is private;
261
262    PTHREAD_CREATE_DETACHED : constant := 16#de#;
263
264    PTHREAD_SCOPE_PROCESS : constant := 2;
265    PTHREAD_SCOPE_SYSTEM  : constant := 1;
266
267    -----------
268    -- Stack --
269    -----------
270
271    type stack_t is record
272       ss_sp    : System.Address;
273       ss_flags : int;
274       ss_size  : size_t;
275    end record;
276    pragma Convention (C, stack_t);
277
278    function sigaltstack
279      (ss  : not null access stack_t;
280       oss : access stack_t) return int;
281    pragma Import (C, sigaltstack, "sigaltstack");
282
283    Alternate_Stack : aliased System.Address;
284    pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
285    --  The alternate signal stack for stack overflows
286
287    Alternate_Stack_Size : constant := 16 * 1024;
288    --  This must be in keeping with init.c:__gnat_alternate_stack
289
290    Stack_Base_Available : constant Boolean := False;
291    --  Indicates whether the stack base is available on this target
292
293    function Get_Stack_Base (thread : pthread_t) return Address;
294    pragma Inline (Get_Stack_Base);
295    --  Returns the stack base of the specified thread. Only call this function
296    --  when Stack_Base_Available is True.
297
298    function Get_Page_Size return size_t;
299    function Get_Page_Size return Address;
300    pragma Import (C, Get_Page_Size, "getpagesize");
301    --  Returns the size of a page
302
303    PROT_NONE  : constant := 0;
304    PROT_READ  : constant := 1;
305    PROT_WRITE : constant := 2;
306    PROT_EXEC  : constant := 4;
307    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
308    PROT_ON    : constant := PROT_READ;
309    PROT_OFF   : constant := PROT_ALL;
310
311    function mprotect (addr : Address; len : size_t; prot : int) return int;
312    pragma Import (C, mprotect);
313
314    ---------------------------------------
315    -- Nonstandard Thread Initialization --
316    ---------------------------------------
317
318    procedure pthread_init;
319    pragma Inline (pthread_init);
320    --  This is a dummy procedure to share some GNULLI files
321
322    -------------------------
323    -- POSIX.1c  Section 3 --
324    -------------------------
325
326    function sigwait
327      (set : access sigset_t;
328       sig : access Signal) return int;
329    pragma Import (C, sigwait, "sigwait");
330
331    function pthread_kill
332      (thread : pthread_t;
333       sig    : Signal) return int;
334    pragma Import (C, pthread_kill, "pthread_kill");
335
336    function pthread_sigmask
337      (how  : int;
338       set  : access sigset_t;
339       oset : access sigset_t) return int;
340    pragma Import (C, pthread_sigmask, "pthread_sigmask");
341
342    --------------------------
343    -- POSIX.1c  Section 11 --
344    --------------------------
345
346    function pthread_mutexattr_init
347      (attr : access pthread_mutexattr_t) return int;
348    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
349
350    function pthread_mutexattr_destroy
351      (attr : access pthread_mutexattr_t) return int;
352    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
353
354    function pthread_mutex_init
355      (mutex : access pthread_mutex_t;
356       attr  : access pthread_mutexattr_t) return int;
357    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
358
359    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
360    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
361
362    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
363    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
364
365    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
366    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
367
368    function pthread_condattr_init
369      (attr : access pthread_condattr_t) return int;
370    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
371
372    function pthread_condattr_destroy
373      (attr : access pthread_condattr_t) return int;
374    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
375
376    function pthread_cond_init
377      (cond : access pthread_cond_t;
378       attr : access pthread_condattr_t) return int;
379    pragma Import (C, pthread_cond_init, "pthread_cond_init");
380
381    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
382    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
383
384    function pthread_cond_signal (cond : access pthread_cond_t) return int;
385    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
386
387    function pthread_cond_wait
388      (cond  : access pthread_cond_t;
389       mutex : access pthread_mutex_t) return int;
390    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
391
392    function pthread_cond_timedwait
393      (cond    : access pthread_cond_t;
394       mutex   : access pthread_mutex_t;
395       abstime : access timespec) return int;
396    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
397
398    Relative_Timed_Wait : constant Boolean := False;
399    --  pthread_cond_timedwait requires an absolute delay time
400
401    --------------------------
402    -- POSIX.1c  Section 13 --
403    --------------------------
404
405    PTHREAD_PRIO_NONE    : constant := 16#100#;
406    PTHREAD_PRIO_PROTECT : constant := 16#200#;
407    PTHREAD_PRIO_INHERIT : constant := 16#400#;
408
409    function pthread_mutexattr_setprotocol
410      (attr     : access pthread_mutexattr_t;
411       protocol : int) return int;
412    pragma Import (C, pthread_mutexattr_setprotocol);
413
414    function pthread_mutexattr_setprioceiling
415      (attr     : access pthread_mutexattr_t;
416       prioceiling : int) return int;
417    pragma Import (C, pthread_mutexattr_setprioceiling);
418
419    type Array_7_Int is array (0 .. 6) of int;
420    type struct_sched_param is record
421       sched_priority : int;
422       sched_reserved : Array_7_Int;
423    end record;
424
425    function pthread_setschedparam
426      (thread : pthread_t;
427       policy : int;
428       param  : access struct_sched_param)
429      return int;
430    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
431
432    function pthread_attr_setscope
433      (attr            : access pthread_attr_t;
434       contentionscope : int) return int;
435    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
436
437    function pthread_attr_setinheritsched
438      (attr         : access pthread_attr_t;
439       inheritsched : int) return int;
440    pragma Import (C, pthread_attr_setinheritsched);
441
442    function pthread_attr_setschedpolicy
443      (attr   : access pthread_attr_t;
444       policy : int) return int;
445    pragma Import (C, pthread_attr_setschedpolicy);
446
447    function sched_yield return int;
448    pragma Import (C, sched_yield, "sched_yield");
449
450    --------------------------
451    -- P1003.1c  Section 16 --
452    --------------------------
453
454    function pthread_attr_init
455      (attributes : access pthread_attr_t) return int;
456    pragma Import (C, pthread_attr_init, "__pthread_attr_init_system");
457
458    function pthread_attr_destroy
459      (attributes : access pthread_attr_t) return int;
460    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
461
462    function pthread_attr_setdetachstate
463      (attr        : access pthread_attr_t;
464       detachstate : int) return int;
465    pragma Import (C, pthread_attr_setdetachstate);
466
467    function pthread_attr_setstacksize
468      (attr      : access pthread_attr_t;
469       stacksize : size_t) return int;
470    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
471
472    function pthread_create
473      (thread        : access pthread_t;
474       attributes    : access pthread_attr_t;
475       start_routine : Thread_Body;
476       arg           : System.Address) return int;
477    pragma Import (C, pthread_create, "__pthread_create_system");
478
479    procedure pthread_exit (status : System.Address);
480    pragma Import (C, pthread_exit, "pthread_exit");
481
482    function pthread_self return pthread_t;
483    pragma Import (C, pthread_self, "pthread_self");
484
485    --------------------------
486    -- POSIX.1c  Section 17 --
487    --------------------------
488
489    function pthread_setspecific
490      (key   : pthread_key_t;
491       value : System.Address) return int;
492    pragma Import (C, pthread_setspecific, "pthread_setspecific");
493
494    function pthread_getspecific (key : pthread_key_t) return System.Address;
495    pragma Import (C, pthread_getspecific, "pthread_getspecific");
496
497    type destructor_pointer is access procedure (arg : System.Address);
498    pragma Convention (C, destructor_pointer);
499
500    function pthread_key_create
501      (key        : access pthread_key_t;
502       destructor : destructor_pointer) return int;
503    pragma Import (C, pthread_key_create, "pthread_key_create");
504
505 private
506
507    type unsigned_int_array_8 is array (0 .. 7) of unsigned;
508    type sigset_t is record
509       sigset : unsigned_int_array_8;
510    end record;
511    pragma Convention (C_Pass_By_Copy, sigset_t);
512
513    type pid_t is new int;
514
515    type time_t is new long;
516
517    type timespec is record
518       tv_sec  : time_t;
519       tv_nsec : long;
520    end record;
521    pragma Convention (C, timespec);
522
523    type clockid_t is new int;
524    CLOCK_REALTIME : constant clockid_t := 1;
525
526    type pthread_attr_t is new int;
527    type pthread_condattr_t is new int;
528    type pthread_mutexattr_t is new int;
529    type pthread_t is new int;
530
531    type short_array is array (Natural range <>) of short;
532    type int_array is array (Natural range <>) of int;
533
534    type pthread_mutex_t is record
535       m_short : short_array (0 .. 1);
536       m_int   : int;
537       m_int1  : int_array (0 .. 3);
538       m_pad   : int;
539
540       m_ptr : int;
541       --  actually m_ptr is a void*, and on 32 bit ABI, m_pad is added so that
542       --  this field takes 64 bits. On 64 bit ABI, m_pad is gone, and m_ptr is
543       --  a 64 bit void*. Assume int'Size = 32.
544
545       m_int2   : int_array (0 .. 1);
546       m_int3   : int_array (0 .. 3);
547       m_short2 : short_array (0 .. 1);
548       m_int4   : int_array (0 .. 4);
549       m_int5   : int_array (0 .. 1);
550    end record;
551    for pthread_mutex_t'Alignment use System.Address'Alignment;
552    pragma Convention (C, pthread_mutex_t);
553
554    type pthread_cond_t is record
555       c_short : short_array (0 .. 1);
556       c_int   : int;
557       c_int1  : int_array (0 .. 3);
558       m_pad   : int;
559       m_ptr   : int;  --  see comment in pthread_mutex_t
560       c_int2  : int_array (0 .. 1);
561       c_int3  : int_array (0 .. 1);
562       c_int4  : int_array (0 .. 1);
563    end record;
564    for pthread_cond_t'Alignment use System.Address'Alignment;
565    pragma Convention (C, pthread_cond_t);
566
567    type pthread_key_t is new int;
568
569 end System.OS_Interface;