Update concepts branch to revision 131834
[official-gcc.git] / gcc / ada / s-osinte-hpux.ads
blob0fc5ef1db54ed9c1ca6637a635cdfd1b44d42330
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-2008, 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 ------------------------------------------------------------------------------
35 -- This is a HPUX 11.0 (Native THREADS) version of this package
37 -- This package encapsulates all direct interfaces to OS services that are
38 -- needed by the tasking run-time (libgnarl).
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.
43 with Ada.Unchecked_Conversion;
45 with Interfaces.C;
47 package System.OS_Interface is
48 pragma Preelaborate;
50 pragma Linker_Options ("-lpthread");
52 subtype int is Interfaces.C.int;
53 subtype short is Interfaces.C.short;
54 subtype long is Interfaces.C.long;
55 subtype unsigned is Interfaces.C.unsigned;
56 subtype unsigned_short is Interfaces.C.unsigned_short;
57 subtype unsigned_long is Interfaces.C.unsigned_long;
58 subtype unsigned_char is Interfaces.C.unsigned_char;
59 subtype plain_char is Interfaces.C.plain_char;
60 subtype size_t is Interfaces.C.size_t;
62 -----------
63 -- Errno --
64 -----------
66 function errno return int;
67 pragma Import (C, errno, "__get_errno");
69 EAGAIN : constant := 11;
70 EINTR : constant := 4;
71 EINVAL : constant := 22;
72 ENOMEM : constant := 12;
73 ETIMEDOUT : constant := 238;
75 -------------
76 -- Signals --
77 -------------
79 Max_Interrupt : constant := 44;
80 type Signal is new int range 0 .. Max_Interrupt;
81 for Signal'Size use int'Size;
83 SIGHUP : constant := 1; -- hangup
84 SIGINT : constant := 2; -- interrupt (rubout)
85 SIGQUIT : constant := 3; -- quit (ASCD FS)
86 SIGILL : constant := 4; -- illegal instruction (not reset)
87 SIGTRAP : constant := 5; -- trace trap (not reset)
88 SIGIOT : constant := 6; -- IOT instruction
89 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
90 SIGEMT : constant := 7; -- EMT instruction
91 SIGFPE : constant := 8; -- floating point exception
92 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
93 SIGBUS : constant := 10; -- bus error
94 SIGSEGV : constant := 11; -- segmentation violation
95 SIGSYS : constant := 12; -- bad argument to system call
96 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
97 SIGALRM : constant := 14; -- alarm clock
98 SIGTERM : constant := 15; -- software termination signal from kill
99 SIGUSR1 : constant := 16; -- user defined signal 1
100 SIGUSR2 : constant := 17; -- user defined signal 2
101 SIGCLD : constant := 18; -- alias for SIGCHLD
102 SIGCHLD : constant := 18; -- child status change
103 SIGPWR : constant := 19; -- power-fail restart
104 SIGVTALRM : constant := 20; -- virtual timer alarm
105 SIGPROF : constant := 21; -- profiling timer alarm
106 SIGIO : constant := 22; -- asynchronous I/O
107 SIGPOLL : constant := 22; -- pollable event occurred
108 SIGWINCH : constant := 23; -- window size change
109 SIGSTOP : constant := 24; -- stop (cannot be caught or ignored)
110 SIGTSTP : constant := 25; -- user stop requested from tty
111 SIGCONT : constant := 26; -- stopped process has been continued
112 SIGTTIN : constant := 27; -- background tty read attempted
113 SIGTTOU : constant := 28; -- background tty write attempted
114 SIGURG : constant := 29; -- urgent condition on IO channel
115 SIGLOST : constant := 30; -- remote lock lost (NFS)
116 SIGDIL : constant := 32; -- DIL signal
117 SIGXCPU : constant := 33; -- CPU time limit exceeded (setrlimit)
118 SIGXFSZ : constant := 34; -- file size limit exceeded (setrlimit)
119 SIGCANCEL : constant := 35; -- used for pthread cancellation.
120 SIGGFAULT : constant := 36; -- Graphics framebuffer fault
122 SIGADAABORT : constant := SIGABRT;
123 -- Note: on other targets, we usually use SIGABRT, but on HPUX, it
124 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
126 type Signal_Set is array (Natural range <>) of Signal;
128 Unmasked : constant Signal_Set :=
129 (SIGABRT, SIGPIPE, SIGBUS, SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF,
130 SIGALRM, SIGVTALRM, SIGIO, SIGCHLD);
132 Reserved : constant Signal_Set := (SIGKILL, SIGSTOP);
134 type sigset_t is private;
136 function sigaddset (set : access sigset_t; sig : Signal) return int;
137 pragma Import (C, sigaddset, "sigaddset");
139 function sigdelset (set : access sigset_t; sig : Signal) return int;
140 pragma Import (C, sigdelset, "sigdelset");
142 function sigfillset (set : access sigset_t) return int;
143 pragma Import (C, sigfillset, "sigfillset");
145 function sigismember (set : access sigset_t; sig : Signal) return int;
146 pragma Import (C, sigismember, "sigismember");
148 function sigemptyset (set : access sigset_t) return int;
149 pragma Import (C, sigemptyset, "sigemptyset");
151 type struct_sigaction is record
152 sa_handler : System.Address;
153 sa_mask : sigset_t;
154 sa_flags : int;
155 end record;
156 pragma Convention (C, struct_sigaction);
157 type struct_sigaction_ptr is access all struct_sigaction;
159 SA_SIGINFO : constant := 16#10#;
160 SA_ONSTACK : constant := 16#01#;
162 SIG_BLOCK : constant := 0;
163 SIG_UNBLOCK : constant := 1;
164 SIG_SETMASK : constant := 2;
166 SIG_DFL : constant := 0;
167 SIG_IGN : constant := 1;
169 function sigaction
170 (sig : Signal;
171 act : struct_sigaction_ptr;
172 oact : struct_sigaction_ptr) return int;
173 pragma Import (C, sigaction, "sigaction");
175 ----------
176 -- Time --
177 ----------
179 Time_Slice_Supported : constant Boolean := True;
180 -- Indicates whether time slicing is supported
182 type timespec is private;
184 type clockid_t is private;
186 CLOCK_REALTIME : constant clockid_t;
188 function clock_gettime
189 (clock_id : clockid_t;
190 tp : access timespec) return int;
191 pragma Import (C, clock_gettime, "clock_gettime");
193 function clock_getres
194 (clock_id : clockid_t;
195 res : access timespec) return int;
196 pragma Import (C, clock_getres, "clock_getres");
198 function To_Duration (TS : timespec) return Duration;
199 pragma Inline (To_Duration);
201 function To_Timespec (D : Duration) return timespec;
202 pragma Inline (To_Timespec);
204 type struct_timezone is record
205 tz_minuteswest : int;
206 tz_dsttime : int;
207 end record;
208 pragma Convention (C, struct_timezone);
209 type struct_timezone_ptr is access all struct_timezone;
211 type struct_timeval is private;
212 -- This is needed on systems that do not have clock_gettime()
213 -- but do have gettimeofday().
215 function To_Duration (TV : struct_timeval) return Duration;
216 pragma Inline (To_Duration);
218 function To_Timeval (D : Duration) return struct_timeval;
219 pragma Inline (To_Timeval);
221 -------------------------
222 -- Priority Scheduling --
223 -------------------------
225 SCHED_FIFO : constant := 0;
226 SCHED_RR : constant := 1;
227 SCHED_OTHER : constant := 2;
229 function To_Target_Priority
230 (Prio : System.Any_Priority) return Interfaces.C.int;
231 -- Maps System.Any_Priority to a POSIX priority
233 -------------
234 -- Process --
235 -------------
237 type pid_t is private;
239 function kill (pid : pid_t; sig : Signal) return int;
240 pragma Import (C, kill, "kill");
242 function getpid return pid_t;
243 pragma Import (C, getpid, "getpid");
245 ---------
246 -- LWP --
247 ---------
249 function lwp_self return System.Address;
250 pragma Import (C, lwp_self, "_lwp_self");
252 -------------
253 -- Threads --
254 -------------
256 type Thread_Body is access
257 function (arg : System.Address) return System.Address;
258 pragma Convention (C, Thread_Body);
260 function Thread_Body_Access is new
261 Ada.Unchecked_Conversion (System.Address, Thread_Body);
263 type pthread_t is private;
264 subtype Thread_Id is pthread_t;
266 type pthread_mutex_t is limited private;
267 type pthread_cond_t is limited private;
268 type pthread_attr_t is limited private;
269 type pthread_mutexattr_t is limited private;
270 type pthread_condattr_t is limited private;
271 type pthread_key_t is private;
273 PTHREAD_CREATE_DETACHED : constant := 16#de#;
275 PTHREAD_SCOPE_PROCESS : constant := 2;
276 PTHREAD_SCOPE_SYSTEM : constant := 1;
278 -----------
279 -- Stack --
280 -----------
282 type stack_t is record
283 ss_sp : System.Address;
284 ss_flags : int;
285 ss_size : size_t;
286 end record;
287 pragma Convention (C, stack_t);
289 function sigaltstack
290 (ss : not null access stack_t;
291 oss : access stack_t) return int;
292 pragma Import (C, sigaltstack, "sigaltstack");
294 Alternate_Stack : aliased System.Address;
295 pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
296 -- The alternate signal stack for stack overflows
298 Alternate_Stack_Size : constant := 16 * 1024;
299 -- This must be in keeping with init.c:__gnat_alternate_stack
301 Stack_Base_Available : constant Boolean := False;
302 -- Indicates whether the stack base is available on this target
304 function Get_Stack_Base (thread : pthread_t) return Address;
305 pragma Inline (Get_Stack_Base);
306 -- Returns the stack base of the specified thread. Only call this function
307 -- when Stack_Base_Available is True.
309 function Get_Page_Size return size_t;
310 function Get_Page_Size return Address;
311 pragma Import (C, Get_Page_Size, "getpagesize");
312 -- Returns the size of a page, or 0 if this is not relevant on this target
314 PROT_NONE : constant := 0;
315 PROT_READ : constant := 1;
316 PROT_WRITE : constant := 2;
317 PROT_EXEC : constant := 4;
318 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
319 PROT_ON : constant := PROT_READ;
320 PROT_OFF : constant := PROT_ALL;
322 function mprotect (addr : Address; len : size_t; prot : int) return int;
323 pragma Import (C, mprotect);
325 ---------------------------------------
326 -- Nonstandard Thread Initialization --
327 ---------------------------------------
329 procedure pthread_init;
330 pragma Inline (pthread_init);
331 -- This is a dummy procedure to share some GNULLI files
333 -------------------------
334 -- POSIX.1c Section 3 --
335 -------------------------
337 function sigwait
338 (set : access sigset_t;
339 sig : access Signal) return int;
340 pragma Import (C, sigwait, "sigwait");
342 function pthread_kill
343 (thread : pthread_t;
344 sig : Signal) return int;
345 pragma Import (C, pthread_kill, "pthread_kill");
347 function pthread_sigmask
348 (how : int;
349 set : access sigset_t;
350 oset : access sigset_t) return int;
351 pragma Import (C, pthread_sigmask, "pthread_sigmask");
353 --------------------------
354 -- POSIX.1c Section 11 --
355 --------------------------
357 function pthread_mutexattr_init
358 (attr : access pthread_mutexattr_t) return int;
359 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
361 function pthread_mutexattr_destroy
362 (attr : access pthread_mutexattr_t) return int;
363 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
365 function pthread_mutex_init
366 (mutex : access pthread_mutex_t;
367 attr : access pthread_mutexattr_t) return int;
368 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
370 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
371 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
373 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
374 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
376 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
377 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
379 function pthread_condattr_init
380 (attr : access pthread_condattr_t) return int;
381 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
383 function pthread_condattr_destroy
384 (attr : access pthread_condattr_t) return int;
385 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
387 function pthread_cond_init
388 (cond : access pthread_cond_t;
389 attr : access pthread_condattr_t) return int;
390 pragma Import (C, pthread_cond_init, "pthread_cond_init");
392 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
393 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
395 function pthread_cond_signal (cond : access pthread_cond_t) return int;
396 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
398 function pthread_cond_wait
399 (cond : access pthread_cond_t;
400 mutex : access pthread_mutex_t) return int;
401 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
403 function pthread_cond_timedwait
404 (cond : access pthread_cond_t;
405 mutex : access pthread_mutex_t;
406 abstime : access timespec) return int;
407 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
409 Relative_Timed_Wait : constant Boolean := False;
410 -- pthread_cond_timedwait requires an absolute delay time
412 --------------------------
413 -- POSIX.1c Section 13 --
414 --------------------------
416 PTHREAD_PRIO_NONE : constant := 16#100#;
417 PTHREAD_PRIO_PROTECT : constant := 16#200#;
418 PTHREAD_PRIO_INHERIT : constant := 16#400#;
420 function pthread_mutexattr_setprotocol
421 (attr : access pthread_mutexattr_t;
422 protocol : int) return int;
423 pragma Import (C, pthread_mutexattr_setprotocol);
425 function pthread_mutexattr_setprioceiling
426 (attr : access pthread_mutexattr_t;
427 prioceiling : int) return int;
428 pragma Import (C, pthread_mutexattr_setprioceiling);
430 type Array_7_Int is array (0 .. 6) of int;
431 type struct_sched_param is record
432 sched_priority : int;
433 sched_reserved : Array_7_Int;
434 end record;
436 function pthread_setschedparam
437 (thread : pthread_t;
438 policy : int;
439 param : access struct_sched_param)
440 return int;
441 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
443 function pthread_attr_setscope
444 (attr : access pthread_attr_t;
445 contentionscope : int) return int;
446 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
448 function pthread_attr_setinheritsched
449 (attr : access pthread_attr_t;
450 inheritsched : int) return int;
451 pragma Import (C, pthread_attr_setinheritsched);
453 function pthread_attr_setschedpolicy
454 (attr : access pthread_attr_t;
455 policy : int) return int;
456 pragma Import (C, pthread_attr_setschedpolicy);
458 function sched_yield return int;
459 pragma Import (C, sched_yield, "sched_yield");
461 --------------------------
462 -- P1003.1c Section 16 --
463 --------------------------
465 function pthread_attr_init
466 (attributes : access pthread_attr_t) return int;
467 pragma Import (C, pthread_attr_init, "__pthread_attr_init_system");
469 function pthread_attr_destroy
470 (attributes : access pthread_attr_t) return int;
471 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
473 function pthread_attr_setdetachstate
474 (attr : access pthread_attr_t;
475 detachstate : int) return int;
476 pragma Import (C, pthread_attr_setdetachstate);
478 function pthread_attr_setstacksize
479 (attr : access pthread_attr_t;
480 stacksize : size_t) return int;
481 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
483 function pthread_create
484 (thread : access pthread_t;
485 attributes : access pthread_attr_t;
486 start_routine : Thread_Body;
487 arg : System.Address) return int;
488 pragma Import (C, pthread_create, "__pthread_create_system");
490 procedure pthread_exit (status : System.Address);
491 pragma Import (C, pthread_exit, "pthread_exit");
493 function pthread_self return pthread_t;
494 pragma Import (C, pthread_self, "pthread_self");
496 --------------------------
497 -- POSIX.1c Section 17 --
498 --------------------------
500 function pthread_setspecific
501 (key : pthread_key_t;
502 value : System.Address) return int;
503 pragma Import (C, pthread_setspecific, "pthread_setspecific");
505 function pthread_getspecific (key : pthread_key_t) return System.Address;
506 pragma Import (C, pthread_getspecific, "pthread_getspecific");
508 type destructor_pointer is access procedure (arg : System.Address);
509 pragma Convention (C, destructor_pointer);
511 function pthread_key_create
512 (key : access pthread_key_t;
513 destructor : destructor_pointer) return int;
514 pragma Import (C, pthread_key_create, "pthread_key_create");
516 private
518 type unsigned_int_array_8 is array (0 .. 7) of unsigned;
519 type sigset_t is record
520 sigset : unsigned_int_array_8;
521 end record;
522 pragma Convention (C_Pass_By_Copy, sigset_t);
524 type pid_t is new int;
526 type time_t is new long;
528 type timespec is record
529 tv_sec : time_t;
530 tv_nsec : long;
531 end record;
532 pragma Convention (C, timespec);
534 type clockid_t is new int;
535 CLOCK_REALTIME : constant clockid_t := 1;
537 type struct_timeval is record
538 tv_sec : time_t;
539 tv_usec : time_t;
540 end record;
541 pragma Convention (C, struct_timeval);
543 type pthread_attr_t is new int;
544 type pthread_condattr_t is new int;
545 type pthread_mutexattr_t is new int;
546 type pthread_t is new int;
548 type short_array is array (Natural range <>) of short;
549 type int_array is array (Natural range <>) of int;
551 type pthread_mutex_t is record
552 m_short : short_array (0 .. 1);
553 m_int : int;
554 m_int1 : int_array (0 .. 3);
555 m_pad : int;
557 m_ptr : int;
558 -- actually m_ptr is a void*, and on 32 bit ABI, m_pad is added so that
559 -- this field takes 64 bits. On 64 bit ABI, m_pad is gone, and m_ptr is
560 -- a 64 bit void*. Assume int'Size = 32.
562 m_int2 : int_array (0 .. 1);
563 m_int3 : int_array (0 .. 3);
564 m_short2 : short_array (0 .. 1);
565 m_int4 : int_array (0 .. 4);
566 m_int5 : int_array (0 .. 1);
567 end record;
568 for pthread_mutex_t'Alignment use System.Address'Alignment;
569 pragma Convention (C, pthread_mutex_t);
571 type pthread_cond_t is record
572 c_short : short_array (0 .. 1);
573 c_int : int;
574 c_int1 : int_array (0 .. 3);
575 m_pad : int;
576 m_ptr : int; -- see comment in pthread_mutex_t
577 c_int2 : int_array (0 .. 1);
578 c_int3 : int_array (0 .. 1);
579 c_int4 : int_array (0 .. 1);
580 end record;
581 for pthread_cond_t'Alignment use System.Address'Alignment;
582 pragma Convention (C, pthread_cond_t);
584 type pthread_key_t is new int;
586 end System.OS_Interface;