Add hppa-openbsd target
[official-gcc.git] / gcc / ada / 5bosinte.ads
blob21a83272cdfdd47c71ed8051e4289a144a99c8e1
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 -- --
10 -- Copyright (C) 1997-2001 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, 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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This is a AIX (Native THREADS) version of this package.
38 -- This package encapsulates all direct interfaces to OS services
39 -- that are needed by children of System.
41 -- PLEASE DO NOT add any with-clauses to this package
42 -- or remove the pragma Elaborate_Body.
43 -- It is designed to be a bottom-level (leaf) package.
45 with Interfaces.C;
46 package System.OS_Interface is
47 pragma Preelaborate;
49 pragma Linker_Options ("-lpthreads");
50 pragma Linker_Options ("-lc_r");
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 := 78;
75 -------------
76 -- Signals --
77 -------------
79 Max_Interrupt : constant := 63;
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 := 30; -- user defined signal 1
100 SIGUSR2 : constant := 31; -- user defined signal 2
101 SIGCLD : constant := 20; -- alias for SIGCHLD
102 SIGCHLD : constant := 20; -- child status change
103 SIGPWR : constant := 29; -- power-fail restart
104 SIGWINCH : constant := 28; -- window size change
105 SIGURG : constant := 16; -- urgent condition on IO channel
106 SIGPOLL : constant := 23; -- pollable event occurred
107 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
109 SIGTSTP : constant := 18; -- user stop requested from tty
110 SIGCONT : constant := 19; -- stopped process has been continued
111 SIGTTIN : constant := 21; -- background tty read attempted
112 SIGTTOU : constant := 22; -- background tty write attempted
113 SIGVTALRM : constant := 34; -- virtual timer expired
114 SIGPROF : constant := 32; -- profiling timer expired
115 SIGXCPU : constant := 24; -- CPU time limit exceeded
116 SIGXFSZ : constant := 25; -- filesize limit exceeded
117 SIGWAITING : constant := 39; -- m:n scheduling
119 -- the following signals are AIX specific
120 SIGMSG : constant := 27; -- input data is in the ring buffer
121 SIGDANGER : constant := 33; -- system crash imminent
122 SIGMIGRATE : constant := 35; -- migrate process
123 SIGPRE : constant := 36; -- programming exception
124 SIGVIRT : constant := 37; -- AIX virtual time alarm
125 SIGALRM1 : constant := 38; -- m:n condition variables
126 SIGKAP : constant := 60; -- keep alive poll from native keyboard
127 SIGGRANT : constant := SIGKAP; -- monitor mode granted
128 SIGRETRACT : constant := 61; -- monitor mode should be relinguished
129 SIGSOUND : constant := 62; -- sound control has completed
130 SIGSAK : constant := 63; -- secure attention key
132 SIGADAABORT : constant := SIGTERM;
133 -- Note: on other targets, we usually use SIGABRT, but on AiX, it
134 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
136 type Signal_Set is array (Natural range <>) of Signal;
138 Unmasked : constant Signal_Set :=
139 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
140 Reserved : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP);
142 type sigset_t is private;
144 function sigaddset (set : access sigset_t; sig : Signal) return int;
145 pragma Import (C, sigaddset, "sigaddset");
147 function sigdelset (set : access sigset_t; sig : Signal) return int;
148 pragma Import (C, sigdelset, "sigdelset");
150 function sigfillset (set : access sigset_t) return int;
151 pragma Import (C, sigfillset, "sigfillset");
153 function sigismember (set : access sigset_t; sig : Signal) return int;
154 pragma Import (C, sigismember, "sigismember");
156 function sigemptyset (set : access sigset_t) return int;
157 pragma Import (C, sigemptyset, "sigemptyset");
159 type struct_sigaction is record
160 sa_handler : System.Address;
161 sa_mask : sigset_t;
162 sa_flags : int;
163 end record;
164 pragma Convention (C, struct_sigaction);
165 type struct_sigaction_ptr is access all struct_sigaction;
168 SIG_BLOCK : constant := 0;
169 SIG_UNBLOCK : constant := 1;
170 SIG_SETMASK : constant := 2;
172 SIG_DFL : constant := 0;
173 SIG_IGN : constant := 1;
175 function sigaction
176 (sig : Signal;
177 act : struct_sigaction_ptr;
178 oact : struct_sigaction_ptr) return int;
179 pragma Import (C, sigaction, "sigaction");
181 ----------
182 -- Time --
183 ----------
185 Time_Slice_Supported : constant Boolean := False;
186 -- Indicates wether time slicing is supported
188 type timespec is private;
190 type clockid_t is private;
192 CLOCK_REALTIME : constant clockid_t;
194 function clock_gettime
195 (clock_id : clockid_t;
196 tp : access timespec) return int;
197 -- AiX threads don't have clock_gettime
198 -- We instead use gettimeofday()
200 function To_Duration (TS : timespec) return Duration;
201 pragma Inline (To_Duration);
203 function To_Timespec (D : Duration) return timespec;
204 pragma Inline (To_Timespec);
206 type struct_timezone is record
207 tz_minuteswest : int;
208 tz_dsttime : int;
209 end record;
210 pragma Convention (C, struct_timezone);
211 type struct_timezone_ptr is access all struct_timezone;
213 type struct_timeval is private;
214 -- This is needed on systems that do not have clock_gettime()
215 -- but do have gettimeofday().
217 function To_Duration (TV : struct_timeval) return Duration;
218 pragma Inline (To_Duration);
220 function To_Timeval (D : Duration) return struct_timeval;
221 pragma Inline (To_Timeval);
223 -------------------------
224 -- Priority Scheduling --
225 -------------------------
227 SCHED_FIFO : constant := 1;
228 SCHED_RR : constant := 2;
229 SCHED_OTHER : constant := 0;
231 -------------
232 -- Process --
233 -------------
235 type pid_t is private;
237 function kill (pid : pid_t; sig : Signal) return int;
238 pragma Import (C, kill, "kill");
240 function getpid return pid_t;
241 pragma Import (C, getpid, "getpid");
243 ---------
244 -- LWP --
245 ---------
247 function lwp_self return System.Address;
248 pragma Import (C, lwp_self, "thread_self");
250 -------------
251 -- Threads --
252 -------------
254 type Thread_Body is access
255 function (arg : System.Address) return System.Address;
256 type pthread_t is private;
257 subtype Thread_Id is pthread_t;
259 type pthread_mutex_t is limited private;
260 type pthread_cond_t is limited private;
261 type pthread_attr_t is limited private;
262 type pthread_mutexattr_t is limited private;
263 type pthread_condattr_t is limited private;
264 type pthread_key_t is private;
266 PTHREAD_CREATE_DETACHED : constant := 1;
268 -----------
269 -- Stack --
270 -----------
272 Stack_Base_Available : constant Boolean := False;
273 -- Indicates wether the stack base is available on this target.
275 function Get_Stack_Base (thread : pthread_t) return Address;
276 pragma Inline (Get_Stack_Base);
277 -- returns the stack base of the specified thread.
278 -- Only call this function when Stack_Base_Available is True.
280 function Get_Page_Size return size_t;
281 function Get_Page_Size return Address;
282 pragma Import (C, Get_Page_Size, "getpagesize");
283 -- returns the size of a page, or 0 if this is not relevant on this
284 -- target
286 PROT_NONE : constant := 0;
287 PROT_READ : constant := 1;
288 PROT_WRITE : constant := 2;
289 PROT_EXEC : constant := 4;
290 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
292 PROT_ON : constant := PROT_READ;
293 PROT_OFF : constant := PROT_ALL;
295 function mprotect (addr : Address; len : size_t; prot : int) return int;
296 pragma Import (C, mprotect);
298 ---------------------------------------
299 -- Nonstandard Thread Initialization --
300 ---------------------------------------
302 -- Though not documented, pthread_init *must* be called before any other
303 -- pthread call
305 procedure pthread_init;
306 pragma Import (C, pthread_init, "pthread_init");
308 -------------------------
309 -- POSIX.1c Section 3 --
310 -------------------------
312 function sigwait
313 (set : access sigset_t;
314 sig : access Signal) return int;
315 pragma Import (C, sigwait, "sigwait");
317 function pthread_kill
318 (thread : pthread_t;
319 sig : Signal) return int;
320 pragma Import (C, pthread_kill, "pthread_kill");
322 type sigset_t_ptr is access all sigset_t;
324 function pthread_sigmask
325 (how : int;
326 set : sigset_t_ptr;
327 oset : sigset_t_ptr) return int;
328 pragma Import (C, pthread_sigmask, "sigthreadmask");
330 --------------------------
331 -- POSIX.1c Section 11 --
332 --------------------------
334 function pthread_mutexattr_init
335 (attr : access pthread_mutexattr_t) return int;
336 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
338 function pthread_mutexattr_destroy
339 (attr : access pthread_mutexattr_t) return int;
340 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
342 function pthread_mutex_init
343 (mutex : access pthread_mutex_t;
344 attr : access pthread_mutexattr_t) return int;
345 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
347 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
348 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
350 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
351 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
353 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
354 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
356 function pthread_condattr_init
357 (attr : access pthread_condattr_t) return int;
358 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
360 function pthread_condattr_destroy
361 (attr : access pthread_condattr_t) return int;
362 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
364 function pthread_cond_init
365 (cond : access pthread_cond_t;
366 attr : access pthread_condattr_t) return int;
367 pragma Import (C, pthread_cond_init, "pthread_cond_init");
369 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
370 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
372 function pthread_cond_signal (cond : access pthread_cond_t) return int;
373 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
375 function pthread_cond_wait
376 (cond : access pthread_cond_t;
377 mutex : access pthread_mutex_t) return int;
378 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
380 function pthread_cond_timedwait
381 (cond : access pthread_cond_t;
382 mutex : access pthread_mutex_t;
383 abstime : access timespec) return int;
384 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
386 Relative_Timed_Wait : constant Boolean := False;
387 -- pthread_cond_timedwait requires an absolute delay time
389 ----------------------------
390 -- POSIX.1c Section 13 --
391 ----------------------------
393 PTHREAD_PRIO_NONE : constant := 0;
394 PTHREAD_PRIO_PROTECT : constant := 0;
395 PTHREAD_PRIO_INHERIT : constant := 0;
397 function pthread_mutexattr_setprotocol
398 (attr : access pthread_mutexattr_t;
399 protocol : int) return int;
400 pragma Import (C, pthread_mutexattr_setprotocol);
402 function pthread_mutexattr_setprioceiling
403 (attr : access pthread_mutexattr_t;
404 prioceiling : int) return int;
405 pragma Import (C, pthread_mutexattr_setprioceiling);
407 type Array_5_Int is array (0 .. 5) of int;
408 type struct_sched_param is record
409 sched_priority : int;
410 sched_policy : int;
411 sched_reserved : Array_5_Int;
412 end record;
414 function pthread_setschedparam
415 (thread : pthread_t;
416 policy : int;
417 param : access struct_sched_param) return int;
418 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
420 function pthread_attr_setscope
421 (attr : access pthread_attr_t;
422 contentionscope : int) return int;
423 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
425 function pthread_attr_setinheritsched
426 (attr : access pthread_attr_t;
427 inheritsched : int) return int;
428 pragma Import (C, pthread_attr_setinheritsched);
430 function pthread_attr_setschedpolicy
431 (attr : access pthread_attr_t;
432 policy : int) return int;
433 pragma Import (C, pthread_attr_setschedpolicy);
435 function pthread_attr_setschedparam
436 (attr : access pthread_attr_t;
437 sched_param : int) return int;
438 pragma Import (C, pthread_attr_setschedparam);
440 function sched_yield return int;
441 -- AiX have a nonstandard sched_yield.
443 ---------------------------
444 -- P1003.1c - Section 16 --
445 ---------------------------
447 function pthread_attr_init (attributes : access pthread_attr_t) return int;
448 pragma Import (C, pthread_attr_init, "pthread_attr_init");
450 function pthread_attr_destroy
451 (attributes : access pthread_attr_t) return int;
452 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
454 function pthread_attr_setdetachstate
455 (attr : access pthread_attr_t;
456 detachstate : int) return int;
457 pragma Import (C, pthread_attr_setdetachstate);
459 function pthread_attr_setstacksize
460 (attr : access pthread_attr_t;
461 stacksize : size_t) return int;
462 pragma Import (C, pthread_attr_setstacksize);
464 function pthread_create
465 (thread : access pthread_t;
466 attributes : access pthread_attr_t;
467 start_routine : Thread_Body;
468 arg : System.Address)
469 return int;
470 pragma Import (C, pthread_create, "pthread_create");
472 procedure pthread_exit (status : System.Address);
473 pragma Import (C, pthread_exit, "pthread_exit");
475 function pthread_self return pthread_t;
476 pragma Import (C, pthread_self, "pthread_self");
478 --------------------------
479 -- POSIX.1c Section 17 --
480 --------------------------
482 function pthread_setspecific
483 (key : pthread_key_t;
484 value : System.Address) return int;
485 pragma Import (C, pthread_setspecific, "pthread_setspecific");
487 function pthread_getspecific (key : pthread_key_t) return System.Address;
488 pragma Import (C, pthread_getspecific, "pthread_getspecific");
490 type destructor_pointer is access
491 procedure (arg : System.Address);
493 function pthread_key_create
494 (key : access pthread_key_t;
495 destructor : destructor_pointer) return int;
496 pragma Import (C, pthread_key_create, "pthread_key_create");
498 private
500 type sigset_t is record
501 losigs : unsigned_long;
502 hisigs : unsigned_long;
503 end record;
504 pragma Convention (C_Pass_By_Copy, sigset_t);
506 type pid_t is new int;
508 type time_t is new long;
510 type timespec is record
511 tv_sec : time_t;
512 tv_nsec : long;
513 end record;
514 pragma Convention (C, timespec);
516 type clockid_t is new int;
517 CLOCK_REALTIME : constant clockid_t := 0;
519 type struct_timeval is record
520 tv_sec : long;
521 tv_usec : long;
522 end record;
523 pragma Convention (C, struct_timeval);
525 type pthread_attr_t is new System.Address;
526 pragma Convention (C, pthread_attr_t);
527 -- typedef struct __pt_attr *pthread_attr_t;
529 type pthread_condattr_t is new System.Address;
530 pragma Convention (C, pthread_condattr_t);
531 -- typedef struct __pt_attr *pthread_condattr_t;
533 type pthread_mutexattr_t is new System.Address;
534 pragma Convention (C, pthread_mutexattr_t);
535 -- typedef struct __pt_attr *pthread_mutexattr_t;
537 type pthread_t is new System.Address;
538 pragma Convention (C, pthread_t);
539 -- typedef void *pthread_t;
541 type ptq_queue;
542 type ptq_queue_ptr is access all ptq_queue;
544 type ptq_queue is record
545 ptq_next : ptq_queue_ptr;
546 ptq_prev : ptq_queue_ptr;
547 end record;
549 type Array_3_Int is array (0 .. 3) of int;
550 type pthread_mutex_t is record
551 link : ptq_queue;
552 ptmtx_lock : int;
553 ptmtx_flags : long;
554 protocol : int;
555 prioceiling : int;
556 ptmtx_owner : pthread_t;
557 mtx_id : int;
558 attr : pthread_attr_t;
559 mtx_kind : int;
560 lock_cpt : int;
561 reserved : Array_3_Int;
562 end record;
563 pragma Convention (C, pthread_mutex_t);
564 type pthread_mutex_t_ptr is access pthread_mutex_t;
566 type pthread_cond_t is record
567 link : ptq_queue;
568 ptcv_lock : int;
569 ptcv_flags : long;
570 ptcv_waiters : ptq_queue;
571 cv_id : int;
572 attr : pthread_attr_t;
573 mutex : pthread_mutex_t_ptr;
574 cptwait : int;
575 reserved : int;
576 end record;
577 pragma Convention (C, pthread_cond_t);
579 type pthread_key_t is new unsigned;
581 end System.OS_Interface;