Add hppa-openbsd target
[official-gcc.git] / gcc / ada / 5tosinte.ads
blob3ae9057afe0e0dfa219291eb9018cfb709100ceb
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-2002, 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 Solaris (FSU THREADS) version of this package.
38 -- This package includes 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 ("-lgthreads");
50 pragma Linker_Options ("-lmalloc");
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 := 145;
75 -------------
76 -- Signals --
77 -------------
79 Max_Interrupt : constant := 45;
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 SIGWINCH : constant := 20; -- window size change
105 SIGURG : constant := 21; -- urgent condition on IO channel
106 SIGPOLL : constant := 22; -- pollable event occurred
107 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
109 SIGTSTP : constant := 24; -- user stop requested from tty
110 SIGCONT : constant := 25; -- stopped process has been continued
111 SIGTTIN : constant := 26; -- background tty read attempted
112 SIGTTOU : constant := 27; -- background tty write attempted
113 SIGVTALRM : constant := 28; -- virtual timer expired
114 SIGPROF : constant := 29; -- profiling timer expired
115 SIGXCPU : constant := 30; -- CPU time limit exceeded
116 SIGXFSZ : constant := 31; -- filesize limit exceeded
117 SIGWAITING : constant := 32; -- process's lwps blocked (Solaris)
118 SIGLWP : constant := 33; -- used by thread library (Solaris)
119 SIGFREEZE : constant := 34; -- used by CPR (Solaris)
120 SIGTHAW : constant := 35; -- used by CPR (Solaris)
121 SIGCANCEL : constant := 36; -- used for thread cancel (Solaris)
122 SIGRTMIN : constant := 38; -- first (highest-priority) realtime signal
123 SIGRTMAX : constant := 45; -- last (lowest-priority) realtime signal
125 type Signal_Set is array (Natural range <>) of Signal;
127 Unmasked : constant Signal_Set :=
128 (SIGTRAP, SIGLWP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
130 Reserved : constant Signal_Set :=
131 (SIGKILL, SIGSTOP, SIGALRM, SIGVTALRM, SIGWAITING, SIGRTMAX);
133 type sigset_t is private;
135 function sigaddset (set : access sigset_t; sig : Signal) return int;
136 pragma Import (C, sigaddset, "sigaddset");
138 function sigdelset (set : access sigset_t; sig : Signal) return int;
139 pragma Import (C, sigdelset, "sigdelset");
141 function sigfillset (set : access sigset_t) return int;
142 pragma Import (C, sigfillset, "sigfillset");
144 function sigismember (set : access sigset_t; sig : Signal) return int;
145 pragma Import (C, sigismember, "sigismember");
147 function sigemptyset (set : access sigset_t) return int;
148 pragma Import (C, sigemptyset, "sigemptyset");
150 type union_type_3 is new String (1 .. 116);
151 type siginfo_t is record
152 si_signo : int;
153 si_code : int;
154 si_errno : int;
155 X_data : union_type_3;
156 end record;
157 pragma Convention (C, siginfo_t);
159 -- The types mcontext_t and gregset_t are part of the ucontext_t
160 -- information, which is specific to Solaris2.4 for SPARC
161 -- The ucontext_t info seems to be used by the handler
162 -- for SIGSEGV to decide whether it is a Storage_Error (stack overflow) or
163 -- a Constraint_Error (bad pointer). The original code that did this
164 -- is suspect, so it is not clear whether we really need this part of
165 -- the signal context information, or perhaps something else.
166 -- More analysis is needed, after which these declarations may need to
167 -- be changed.
169 EMT_TAGOVF : constant := 1; -- tag overflow
170 FPE_INTDIV : constant := 1; -- integer divide by zero
171 FPE_INTOVF : constant := 2; -- integer overflow
172 FPE_FLTDIV : constant := 3; -- floating point divide by zero
173 FPE_FLTOVF : constant := 4; -- floating point overflow
174 FPE_FLTUND : constant := 5; -- floating point underflow
175 FPE_FLTRES : constant := 6; -- floating point inexact result
176 FPE_FLTINV : constant := 7; -- invalid floating point operation
177 FPE_FLTSUB : constant := 8; -- subscript out of range
179 SEGV_MAPERR : constant := 1; -- address not mapped to object
180 SEGV_ACCERR : constant := 2; -- invalid permissions
182 BUS_ADRALN : constant := 1; -- invalid address alignment
183 BUS_ADRERR : constant := 2; -- non-existent physical address
184 BUS_OBJERR : constant := 3; -- object specific hardware error
186 ILL_ILLOPC : constant := 1; -- illegal opcode
187 ILL_ILLOPN : constant := 2; -- illegal operand
188 ILL_ILLADR : constant := 3; -- illegal addressing mode
189 ILL_ILLTRP : constant := 4; -- illegal trap
190 ILL_PRVOPC : constant := 5; -- privileged opcode
191 ILL_PRVREG : constant := 6; -- privileged register
192 ILL_COPROC : constant := 7; -- co-processor
193 ILL_BADSTK : constant := 8; -- bad stack
195 type greg_t is new int;
197 type gregset_t is array (Integer range 0 .. 18) of greg_t;
199 REG_O0 : constant := 11;
200 -- index of saved register O0 in ucontext.uc_mcontext.gregs array
202 type union_type_2 is new String (1 .. 128);
203 type record_type_1 is record
204 fpu_fr : union_type_2;
205 fpu_q : System.Address;
206 fpu_fsr : unsigned;
207 fpu_qcnt : unsigned_char;
208 fpu_q_entrysize : unsigned_char;
209 fpu_en : unsigned_char;
210 end record;
211 pragma Convention (C, record_type_1);
212 type array_type_7 is array (Integer range 0 .. 20) of long;
213 type mcontext_t is record
214 gregs : gregset_t;
215 gwins : System.Address;
216 fpregs : record_type_1;
217 filler : array_type_7;
218 end record;
219 pragma Convention (C, mcontext_t);
221 type record_type_2 is record
222 ss_sp : System.Address;
223 ss_size : int;
224 ss_flags : int;
225 end record;
226 pragma Convention (C, record_type_2);
227 type array_type_8 is array (Integer range 0 .. 22) of long;
228 type ucontext_t is record
229 uc_flags : unsigned_long;
230 uc_link : System.Address;
231 uc_sigmask : sigset_t;
232 uc_stack : record_type_2;
233 uc_mcontext : mcontext_t;
234 uc_filler : array_type_8;
235 end record;
236 pragma Convention (C, ucontext_t);
238 type Signal_Handler is access procedure
239 (signo : Signal;
240 info : access siginfo_t;
241 context : access ucontext_t);
243 type union_type_1 is new plain_char;
244 type array_type_2 is array (Integer range 0 .. 1) of int;
245 type struct_sigaction is record
246 sa_flags : int;
247 sa_handler : System.Address;
248 sa_mask : sigset_t;
249 sa_resv : array_type_2;
250 end record;
251 pragma Convention (C, struct_sigaction);
252 type struct_sigaction_ptr is access all struct_sigaction;
254 SIG_BLOCK : constant := 1;
255 SIG_UNBLOCK : constant := 2;
256 SIG_SETMASK : constant := 3;
258 SIG_DFL : constant := 0;
259 SIG_IGN : constant := 1;
261 function sigaction
262 (sig : Signal;
263 act : struct_sigaction_ptr;
264 oact : struct_sigaction_ptr) return int;
265 pragma Import (C, sigaction, "sigaction");
267 ----------
268 -- Time --
269 ----------
271 Time_Slice_Supported : constant Boolean := False;
272 -- Indicates wether time slicing is supported (i.e FSU threads have been
273 -- compiled with DEF_RR)
275 type timespec is private;
277 type clockid_t is private;
279 CLOCK_REALTIME : constant clockid_t;
281 function clock_gettime
282 (clock_id : clockid_t;
283 tp : access timespec) return int;
284 pragma Import (C, clock_gettime, "clock_gettime");
286 function To_Duration (TS : timespec) return Duration;
287 pragma Inline (To_Duration);
289 function To_Timespec (D : Duration) return timespec;
290 pragma Inline (To_Timespec);
292 type struct_timeval is private;
294 function To_Duration (TV : struct_timeval) return Duration;
295 pragma Inline (To_Duration);
297 function To_Timeval (D : Duration) return struct_timeval;
298 pragma Inline (To_Timeval);
300 -------------------------
301 -- Priority Scheduling --
302 -------------------------
304 SCHED_FIFO : constant := 0;
305 SCHED_RR : constant := 1;
306 SCHED_OTHER : constant := 2;
308 -------------
309 -- Process --
310 -------------
312 type pid_t is private;
314 function kill (pid : pid_t; sig : Signal) return int;
315 pragma Import (C, kill, "kill");
317 function getpid return pid_t;
318 pragma Import (C, getpid, "getpid");
320 ---------
321 -- LWP --
322 ---------
324 function lwp_self return System.Address;
325 -- lwp_self does not exist on this thread library, revert to pthread_self
326 -- which is the closest approximation (with getpid). This function is
327 -- needed to share 7staprop.adb across POSIX-like targets.
328 pragma Import (C, lwp_self, "pthread_self");
330 -------------
331 -- Threads --
332 -------------
334 type Thread_Body is access
335 function (arg : System.Address) return System.Address;
336 type pthread_t is private;
337 subtype Thread_Id is pthread_t;
339 type pthread_mutex_t is limited private;
340 type pthread_cond_t is limited private;
341 type pthread_attr_t is limited private;
342 type pthread_mutexattr_t is limited private;
343 type pthread_condattr_t is limited private;
344 type pthread_key_t is private;
346 PTHREAD_CREATE_DETACHED : constant := 1;
348 -----------
349 -- Stack --
350 -----------
352 Stack_Base_Available : constant Boolean := False;
353 -- Indicates wether the stack base is available on this target.
354 -- This allows us to share s-osinte.adb between all the FSU run time.
355 -- Note that this value can only be true if pthread_t has a complete
356 -- definition that corresponds exactly to the C header files.
358 function Get_Stack_Base (thread : pthread_t) return Address;
359 pragma Inline (Get_Stack_Base);
360 -- returns the stack base of the specified thread.
361 -- Only call this function when Stack_Base_Available is True.
363 function Get_Page_Size return size_t;
364 function Get_Page_Size return Address;
365 pragma Import (C, Get_Page_Size, "getpagesize");
366 -- returns the size of a page, or 0 if this is not relevant on this
367 -- target
369 PROT_NONE : constant := 0;
370 PROT_READ : constant := 1;
371 PROT_WRITE : constant := 2;
372 PROT_EXEC : constant := 4;
373 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
375 PROT_ON : constant := PROT_NONE;
376 PROT_OFF : constant := PROT_ALL;
378 function mprotect (addr : Address; len : size_t; prot : int) return int;
379 pragma Import (C, mprotect);
381 ---------------------------------------
382 -- Nonstandard Thread Initialization --
383 ---------------------------------------
385 procedure pthread_init;
386 -- FSU_THREADS requires pthread_init, which is nonstandard
387 -- and this should be invoked during the elaboration of s-taprop.adb
388 pragma Import (C, pthread_init, "pthread_init");
390 -------------------------
391 -- POSIX.1c Section 3 --
392 -------------------------
394 function sigwait (set : access sigset_t; sig : access Signal) return int;
395 -- FSU_THREADS has a nonstandard sigwait
397 function pthread_kill (thread : pthread_t; sig : Signal) return int;
398 pragma Import (C, pthread_kill, "pthread_kill");
400 type sigset_t_ptr is access all sigset_t;
402 function pthread_sigmask
403 (how : int;
404 set : sigset_t_ptr;
405 oset : sigset_t_ptr) return int;
406 pragma Import (C, pthread_sigmask, "sigprocmask");
408 --------------------------
409 -- POSIX.1c Section 11 --
410 --------------------------
412 function pthread_mutexattr_init
413 (attr : access pthread_mutexattr_t) return int;
414 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
416 function pthread_mutexattr_destroy
417 (attr : access pthread_mutexattr_t) return int;
418 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
420 function pthread_mutex_init
421 (mutex : access pthread_mutex_t;
422 attr : access pthread_mutexattr_t) return int;
423 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
425 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
426 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
428 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
429 -- FSU_THREADS has nonstandard pthread_mutex_lock
431 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
432 -- FSU_THREADS has nonstandard pthread_mutex_lock
434 function pthread_condattr_init
435 (attr : access pthread_condattr_t) return int;
436 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
438 function pthread_condattr_destroy
439 (attr : access pthread_condattr_t) return int;
440 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
442 function pthread_cond_init
443 (cond : access pthread_cond_t;
444 attr : access pthread_condattr_t) return int;
445 pragma Import (C, pthread_cond_init, "pthread_cond_init");
447 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
448 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
450 function pthread_cond_signal (cond : access pthread_cond_t) return int;
451 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
453 function pthread_cond_wait
454 (cond : access pthread_cond_t;
455 mutex : access pthread_mutex_t) return int;
456 -- FSU_THREADS has a nonstandard pthread_cond_wait
458 function pthread_cond_timedwait
459 (cond : access pthread_cond_t;
460 mutex : access pthread_mutex_t;
461 abstime : access timespec) return int;
462 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
464 Relative_Timed_Wait : constant Boolean := False;
465 -- pthread_cond_timedwait requires an absolute delay time
467 --------------------------
468 -- POSIX.1c Section 13 --
469 --------------------------
471 PTHREAD_PRIO_NONE : constant := 0;
472 PTHREAD_PRIO_PROTECT : constant := 2;
473 PTHREAD_PRIO_INHERIT : constant := 1;
475 function pthread_mutexattr_setprotocol
476 (attr : access pthread_mutexattr_t;
477 protocol : int) return int;
478 pragma Import (C, pthread_mutexattr_setprotocol);
480 function pthread_mutexattr_setprioceiling
481 (attr : access pthread_mutexattr_t;
482 prioceiling : int) return int;
483 pragma Import
484 (C, pthread_mutexattr_setprioceiling,
485 "pthread_mutexattr_setprio_ceiling");
487 type struct_sched_param is record
488 sched_priority : int; -- scheduling priority
489 end record;
491 function pthread_setschedparam
492 (thread : pthread_t;
493 policy : int;
494 param : access struct_sched_param) return int;
495 -- FSU_THREADS does not have pthread_setschedparam
497 function pthread_attr_setscope
498 (attr : access pthread_attr_t;
499 contentionscope : int) return int;
500 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
502 function pthread_attr_setinheritsched
503 (attr : access pthread_attr_t;
504 inheritsched : int) return int;
505 pragma Import (C, pthread_attr_setinheritsched);
507 function pthread_attr_setschedpolicy
508 (attr : access pthread_attr_t;
509 policy : int) return int;
510 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
512 function sched_yield return int;
513 -- FSU_THREADS does not have sched_yield;
515 ---------------------------
516 -- P1003.1c - Section 16 --
517 ---------------------------
519 function pthread_attr_init (attributes : access pthread_attr_t) return int;
520 pragma Import (C, pthread_attr_init, "pthread_attr_init");
522 function pthread_attr_destroy
523 (attributes : access pthread_attr_t) return int;
524 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
526 function pthread_attr_setdetachstate
527 (attr : access pthread_attr_t;
528 detachstate : int) return int;
529 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
531 function pthread_attr_setstacksize
532 (attr : access pthread_attr_t;
533 stacksize : size_t) return int;
534 pragma Import (C, pthread_attr_setstacksize);
536 function pthread_create
537 (thread : access pthread_t;
538 attributes : access pthread_attr_t;
539 start_routine : Thread_Body;
540 arg : System.Address) return int;
541 pragma Import (C, pthread_create, "pthread_create");
543 procedure pthread_exit (status : System.Address);
544 pragma Import (C, pthread_exit, "pthread_exit");
546 function pthread_self return pthread_t;
547 pragma Import (C, pthread_self, "pthread_self");
549 --------------------------
550 -- POSIX.1c Section 17 --
551 --------------------------
553 function pthread_setspecific
554 (key : pthread_key_t;
555 value : System.Address) return int;
556 pragma Import (C, pthread_setspecific, "pthread_setspecific");
558 function pthread_getspecific (key : pthread_key_t) return System.Address;
559 -- FSU_THREADS has a nonstandard pthread_getspecific
561 type destructor_pointer is access procedure (arg : System.Address);
563 function pthread_key_create
564 (key : access pthread_key_t;
565 destructor : destructor_pointer) return int;
566 pragma Import (C, pthread_key_create, "pthread_key_create");
568 private
570 type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
571 type sigset_t is record
572 X_X_sigbits : array_type_1;
573 end record;
574 pragma Convention (C, sigset_t);
576 type pid_t is new long;
578 type time_t is new long;
580 type timespec is record
581 tv_sec : time_t;
582 tv_nsec : long;
583 end record;
584 pragma Convention (C, timespec);
586 type clockid_t is new int;
587 CLOCK_REALTIME : constant clockid_t := 0;
589 type struct_timeval is record
590 tv_sec : long;
591 tv_usec : long;
592 end record;
593 pragma Convention (C, struct_timeval);
595 type pthread_attr_t is record
596 flags : int;
597 stacksize : int;
598 contentionscope : int;
599 inheritsched : int;
600 detachstate : int;
601 sched : int;
602 prio : int;
603 starttime : timespec;
604 deadline : timespec;
605 period : timespec;
606 end record;
607 pragma Convention (C, pthread_attr_t);
609 type pthread_condattr_t is record
610 flags : int;
611 end record;
612 pragma Convention (C, pthread_condattr_t);
614 type pthread_mutexattr_t is record
615 flags : int;
616 prio_ceiling : int;
617 protocol : int;
618 end record;
619 pragma Convention (C, pthread_mutexattr_t);
621 type sigjmp_buf is array (Integer range 0 .. 18) of int;
623 type pthread_t_struct is record
624 context : sigjmp_buf;
625 pbody : sigjmp_buf;
626 errno : int;
627 ret : int;
628 stack_base : System.Address;
629 end record;
630 pragma Convention (C, pthread_t_struct);
632 type pthread_t is access all pthread_t_struct;
634 type queue_t is record
635 head : System.Address;
636 tail : System.Address;
637 end record;
638 pragma Convention (C, queue_t);
640 type pthread_mutex_t is record
641 queue : queue_t;
642 lock : plain_char;
643 owner : System.Address;
644 flags : int;
645 prio_ceiling : int;
646 protocol : int;
647 prev_max_ceiling_prio : int;
648 end record;
649 pragma Convention (C, pthread_mutex_t);
651 type pthread_cond_t is record
652 queue : queue_t;
653 flags : int;
654 waiters : int;
655 mutex : System.Address;
656 end record;
657 pragma Convention (C, pthread_cond_t);
659 type pthread_key_t is new int;
661 end System.OS_Interface;