FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / 5tosinte.ads
blob872a579167dee617e1337e43557d055a6dbb62fc
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. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This is a Solaris (FSU THREADS) version of this package.
37 -- This package includes all direct interfaces to OS services
38 -- that are needed by children of System.
40 -- PLEASE DO NOT add any with-clauses to this package
41 -- or remove the pragma Elaborate_Body.
42 -- It is designed to be a bottom-level (leaf) package.
44 with Interfaces.C;
45 package System.OS_Interface is
46 pragma Preelaborate;
48 pragma Linker_Options ("-lgthreads");
49 pragma Linker_Options ("-lmalloc");
51 subtype int is Interfaces.C.int;
52 subtype short is Interfaces.C.short;
53 subtype long is Interfaces.C.long;
54 subtype unsigned is Interfaces.C.unsigned;
55 subtype unsigned_short is Interfaces.C.unsigned_short;
56 subtype unsigned_long is Interfaces.C.unsigned_long;
57 subtype unsigned_char is Interfaces.C.unsigned_char;
58 subtype plain_char is Interfaces.C.plain_char;
59 subtype size_t is Interfaces.C.size_t;
61 -----------
62 -- Errno --
63 -----------
65 function errno return int;
66 pragma Import (C, errno, "__get_errno");
68 EAGAIN : constant := 11;
69 EINTR : constant := 4;
70 EINVAL : constant := 22;
71 ENOMEM : constant := 12;
72 ETIMEDOUT : constant := 145;
74 -------------
75 -- Signals --
76 -------------
78 Max_Interrupt : constant := 45;
79 type Signal is new int range 0 .. Max_Interrupt;
80 for Signal'Size use int'Size;
82 SIGHUP : constant := 1; -- hangup
83 SIGINT : constant := 2; -- interrupt (rubout)
84 SIGQUIT : constant := 3; -- quit (ASCD FS)
85 SIGILL : constant := 4; -- illegal instruction (not reset)
86 SIGTRAP : constant := 5; -- trace trap (not reset)
87 SIGIOT : constant := 6; -- IOT instruction
88 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
89 SIGEMT : constant := 7; -- EMT instruction
90 SIGFPE : constant := 8; -- floating point exception
91 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
92 SIGBUS : constant := 10; -- bus error
93 SIGSEGV : constant := 11; -- segmentation violation
94 SIGSYS : constant := 12; -- bad argument to system call
95 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
96 SIGALRM : constant := 14; -- alarm clock
97 SIGTERM : constant := 15; -- software termination signal from kill
98 SIGUSR1 : constant := 16; -- user defined signal 1
99 SIGUSR2 : constant := 17; -- user defined signal 2
100 SIGCLD : constant := 18; -- alias for SIGCHLD
101 SIGCHLD : constant := 18; -- child status change
102 SIGPWR : constant := 19; -- power-fail restart
103 SIGWINCH : constant := 20; -- window size change
104 SIGURG : constant := 21; -- urgent condition on IO channel
105 SIGPOLL : constant := 22; -- pollable event occurred
106 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
107 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
108 SIGTSTP : constant := 24; -- user stop requested from tty
109 SIGCONT : constant := 25; -- stopped process has been continued
110 SIGTTIN : constant := 26; -- background tty read attempted
111 SIGTTOU : constant := 27; -- background tty write attempted
112 SIGVTALRM : constant := 28; -- virtual timer expired
113 SIGPROF : constant := 29; -- profiling timer expired
114 SIGXCPU : constant := 30; -- CPU time limit exceeded
115 SIGXFSZ : constant := 31; -- filesize limit exceeded
116 SIGWAITING : constant := 32; -- process's lwps blocked (Solaris)
117 SIGLWP : constant := 33; -- used by thread library (Solaris)
118 SIGFREEZE : constant := 34; -- used by CPR (Solaris)
119 SIGTHAW : constant := 35; -- used by CPR (Solaris)
120 SIGCANCEL : constant := 36; -- used for thread cancel (Solaris)
121 SIGRTMIN : constant := 38; -- first (highest-priority) realtime signal
122 SIGRTMAX : constant := 45; -- last (lowest-priority) realtime signal
124 type Signal_Set is array (Natural range <>) of Signal;
126 Unmasked : constant Signal_Set :=
127 (SIGTRAP, SIGLWP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
129 Reserved : constant Signal_Set :=
130 (SIGKILL, SIGSTOP, SIGALRM, SIGVTALRM, SIGWAITING, SIGRTMAX);
132 type sigset_t is private;
134 function sigaddset (set : access sigset_t; sig : Signal) return int;
135 pragma Import (C, sigaddset, "sigaddset");
137 function sigdelset (set : access sigset_t; sig : Signal) return int;
138 pragma Import (C, sigdelset, "sigdelset");
140 function sigfillset (set : access sigset_t) return int;
141 pragma Import (C, sigfillset, "sigfillset");
143 function sigismember (set : access sigset_t; sig : Signal) return int;
144 pragma Import (C, sigismember, "sigismember");
146 function sigemptyset (set : access sigset_t) return int;
147 pragma Import (C, sigemptyset, "sigemptyset");
149 type union_type_3 is new String (1 .. 116);
150 type siginfo_t is record
151 si_signo : int;
152 si_code : int;
153 si_errno : int;
154 X_data : union_type_3;
155 end record;
156 pragma Convention (C, siginfo_t);
158 -- The types mcontext_t and gregset_t are part of the ucontext_t
159 -- information, which is specific to Solaris2.4 for SPARC
160 -- The ucontext_t info seems to be used by the handler
161 -- for SIGSEGV to decide whether it is a Storage_Error (stack overflow) or
162 -- a Constraint_Error (bad pointer). The original code that did this
163 -- is suspect, so it is not clear whether we really need this part of
164 -- the signal context information, or perhaps something else.
165 -- More analysis is needed, after which these declarations may need to
166 -- be changed.
168 EMT_TAGOVF : constant := 1; -- tag overflow
169 FPE_INTDIV : constant := 1; -- integer divide by zero
170 FPE_INTOVF : constant := 2; -- integer overflow
171 FPE_FLTDIV : constant := 3; -- floating point divide by zero
172 FPE_FLTOVF : constant := 4; -- floating point overflow
173 FPE_FLTUND : constant := 5; -- floating point underflow
174 FPE_FLTRES : constant := 6; -- floating point inexact result
175 FPE_FLTINV : constant := 7; -- invalid floating point operation
176 FPE_FLTSUB : constant := 8; -- subscript out of range
178 SEGV_MAPERR : constant := 1; -- address not mapped to object
179 SEGV_ACCERR : constant := 2; -- invalid permissions
181 BUS_ADRALN : constant := 1; -- invalid address alignment
182 BUS_ADRERR : constant := 2; -- non-existent physical address
183 BUS_OBJERR : constant := 3; -- object specific hardware error
185 ILL_ILLOPC : constant := 1; -- illegal opcode
186 ILL_ILLOPN : constant := 2; -- illegal operand
187 ILL_ILLADR : constant := 3; -- illegal addressing mode
188 ILL_ILLTRP : constant := 4; -- illegal trap
189 ILL_PRVOPC : constant := 5; -- privileged opcode
190 ILL_PRVREG : constant := 6; -- privileged register
191 ILL_COPROC : constant := 7; -- co-processor
192 ILL_BADSTK : constant := 8; -- bad stack
194 type greg_t is new int;
196 type gregset_t is array (Integer range 0 .. 18) of greg_t;
198 REG_O0 : constant := 11;
199 -- index of saved register O0 in ucontext.uc_mcontext.gregs array
201 type union_type_2 is new String (1 .. 128);
202 type record_type_1 is record
203 fpu_fr : union_type_2;
204 fpu_q : System.Address;
205 fpu_fsr : unsigned;
206 fpu_qcnt : unsigned_char;
207 fpu_q_entrysize : unsigned_char;
208 fpu_en : unsigned_char;
209 end record;
210 pragma Convention (C, record_type_1);
211 type array_type_7 is array (Integer range 0 .. 20) of long;
212 type mcontext_t is record
213 gregs : gregset_t;
214 gwins : System.Address;
215 fpregs : record_type_1;
216 filler : array_type_7;
217 end record;
218 pragma Convention (C, mcontext_t);
220 type record_type_2 is record
221 ss_sp : System.Address;
222 ss_size : int;
223 ss_flags : int;
224 end record;
225 pragma Convention (C, record_type_2);
226 type array_type_8 is array (Integer range 0 .. 22) of long;
227 type ucontext_t is record
228 uc_flags : unsigned_long;
229 uc_link : System.Address;
230 uc_sigmask : sigset_t;
231 uc_stack : record_type_2;
232 uc_mcontext : mcontext_t;
233 uc_filler : array_type_8;
234 end record;
235 pragma Convention (C, ucontext_t);
237 type Signal_Handler is access procedure
238 (signo : Signal;
239 info : access siginfo_t;
240 context : access ucontext_t);
242 type union_type_1 is new plain_char;
243 type array_type_2 is array (Integer range 0 .. 1) of int;
244 type struct_sigaction is record
245 sa_flags : int;
246 sa_handler : System.Address;
247 sa_mask : sigset_t;
248 sa_resv : array_type_2;
249 end record;
250 pragma Convention (C, struct_sigaction);
251 type struct_sigaction_ptr is access all struct_sigaction;
253 SIG_BLOCK : constant := 1;
254 SIG_UNBLOCK : constant := 2;
255 SIG_SETMASK : constant := 3;
257 SIG_DFL : constant := 0;
258 SIG_IGN : constant := 1;
260 function sigaction
261 (sig : Signal;
262 act : struct_sigaction_ptr;
263 oact : struct_sigaction_ptr) return int;
264 pragma Import (C, sigaction, "sigaction");
266 ----------
267 -- Time --
268 ----------
270 Time_Slice_Supported : constant Boolean := False;
271 -- Indicates wether time slicing is supported (i.e FSU threads have been
272 -- compiled with DEF_RR)
274 type timespec is private;
276 type clockid_t is private;
278 CLOCK_REALTIME : constant clockid_t;
280 function clock_gettime
281 (clock_id : clockid_t;
282 tp : access timespec) return int;
283 pragma Import (C, clock_gettime, "clock_gettime");
285 function To_Duration (TS : timespec) return Duration;
286 pragma Inline (To_Duration);
288 function To_Timespec (D : Duration) return timespec;
289 pragma Inline (To_Timespec);
291 type struct_timeval is private;
293 function To_Duration (TV : struct_timeval) return Duration;
294 pragma Inline (To_Duration);
296 function To_Timeval (D : Duration) return struct_timeval;
297 pragma Inline (To_Timeval);
299 -------------------------
300 -- Priority Scheduling --
301 -------------------------
303 SCHED_FIFO : constant := 0;
304 SCHED_RR : constant := 1;
305 SCHED_OTHER : constant := 2;
307 -------------
308 -- Process --
309 -------------
311 type pid_t is private;
313 function kill (pid : pid_t; sig : Signal) return int;
314 pragma Import (C, kill, "kill");
316 function getpid return pid_t;
317 pragma Import (C, getpid, "getpid");
319 ---------
320 -- LWP --
321 ---------
323 function lwp_self return System.Address;
324 -- lwp_self does not exist on this thread library, revert to pthread_self
325 -- which is the closest approximation (with getpid). This function is
326 -- needed to share 7staprop.adb across POSIX-like targets.
327 pragma Import (C, lwp_self, "pthread_self");
329 -------------
330 -- Threads --
331 -------------
333 type Thread_Body is access
334 function (arg : System.Address) return System.Address;
335 type pthread_t is private;
336 subtype Thread_Id is pthread_t;
338 type pthread_mutex_t is limited private;
339 type pthread_cond_t is limited private;
340 type pthread_attr_t is limited private;
341 type pthread_mutexattr_t is limited private;
342 type pthread_condattr_t is limited private;
343 type pthread_key_t is private;
345 PTHREAD_CREATE_DETACHED : constant := 1;
347 -----------
348 -- Stack --
349 -----------
351 Stack_Base_Available : constant Boolean := False;
352 -- Indicates wether the stack base is available on this target.
353 -- This allows us to share s-osinte.adb between all the FSU run time.
354 -- Note that this value can only be true if pthread_t has a complete
355 -- definition that corresponds exactly to the C header files.
357 function Get_Stack_Base (thread : pthread_t) return Address;
358 pragma Inline (Get_Stack_Base);
359 -- returns the stack base of the specified thread.
360 -- Only call this function when Stack_Base_Available is True.
362 function Get_Page_Size return size_t;
363 function Get_Page_Size return Address;
364 pragma Import (C, Get_Page_Size, "getpagesize");
365 -- returns the size of a page, or 0 if this is not relevant on this
366 -- target
368 PROT_NONE : constant := 0;
369 PROT_READ : constant := 1;
370 PROT_WRITE : constant := 2;
371 PROT_EXEC : constant := 4;
372 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
374 PROT_ON : constant := PROT_NONE;
375 PROT_OFF : constant := PROT_ALL;
377 function mprotect (addr : Address; len : size_t; prot : int) return int;
378 pragma Import (C, mprotect);
380 ---------------------------------------
381 -- Nonstandard Thread Initialization --
382 ---------------------------------------
384 procedure pthread_init;
385 -- FSU_THREADS requires pthread_init, which is nonstandard
386 -- and this should be invoked during the elaboration of s-taprop.adb
387 pragma Import (C, pthread_init, "pthread_init");
389 -------------------------
390 -- POSIX.1c Section 3 --
391 -------------------------
393 function sigwait (set : access sigset_t; sig : access Signal) return int;
394 -- FSU_THREADS has a nonstandard sigwait
396 function pthread_kill (thread : pthread_t; sig : Signal) return int;
397 pragma Import (C, pthread_kill, "pthread_kill");
399 type sigset_t_ptr is access all sigset_t;
401 function pthread_sigmask
402 (how : int;
403 set : sigset_t_ptr;
404 oset : sigset_t_ptr) return int;
405 pragma Import (C, pthread_sigmask, "sigprocmask");
407 --------------------------
408 -- POSIX.1c Section 11 --
409 --------------------------
411 function pthread_mutexattr_init
412 (attr : access pthread_mutexattr_t) return int;
413 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
415 function pthread_mutexattr_destroy
416 (attr : access pthread_mutexattr_t) return int;
417 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
419 function pthread_mutex_init
420 (mutex : access pthread_mutex_t;
421 attr : access pthread_mutexattr_t) return int;
422 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
424 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
425 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
427 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
428 -- FSU_THREADS has nonstandard pthread_mutex_lock
430 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
431 -- FSU_THREADS has nonstandard pthread_mutex_lock
433 function pthread_condattr_init
434 (attr : access pthread_condattr_t) return int;
435 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
437 function pthread_condattr_destroy
438 (attr : access pthread_condattr_t) return int;
439 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
441 function pthread_cond_init
442 (cond : access pthread_cond_t;
443 attr : access pthread_condattr_t) return int;
444 pragma Import (C, pthread_cond_init, "pthread_cond_init");
446 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
447 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
449 function pthread_cond_signal (cond : access pthread_cond_t) return int;
450 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
452 function pthread_cond_wait
453 (cond : access pthread_cond_t;
454 mutex : access pthread_mutex_t) return int;
455 -- FSU_THREADS has a nonstandard pthread_cond_wait
457 function pthread_cond_timedwait
458 (cond : access pthread_cond_t;
459 mutex : access pthread_mutex_t;
460 abstime : access timespec) return int;
461 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
463 Relative_Timed_Wait : constant Boolean := False;
464 -- pthread_cond_timedwait requires an absolute delay time
466 --------------------------
467 -- POSIX.1c Section 13 --
468 --------------------------
470 PTHREAD_PRIO_NONE : constant := 0;
471 PTHREAD_PRIO_PROTECT : constant := 2;
472 PTHREAD_PRIO_INHERIT : constant := 1;
474 function pthread_mutexattr_setprotocol
475 (attr : access pthread_mutexattr_t;
476 protocol : int) return int;
477 pragma Import (C, pthread_mutexattr_setprotocol);
479 function pthread_mutexattr_setprioceiling
480 (attr : access pthread_mutexattr_t;
481 prioceiling : int) return int;
482 pragma Import
483 (C, pthread_mutexattr_setprioceiling,
484 "pthread_mutexattr_setprio_ceiling");
486 type struct_sched_param is record
487 sched_priority : int; -- scheduling priority
488 end record;
490 function pthread_setschedparam
491 (thread : pthread_t;
492 policy : int;
493 param : access struct_sched_param) return int;
494 -- FSU_THREADS does not have pthread_setschedparam
496 function pthread_attr_setscope
497 (attr : access pthread_attr_t;
498 contentionscope : int) return int;
499 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
501 function pthread_attr_setinheritsched
502 (attr : access pthread_attr_t;
503 inheritsched : int) return int;
504 pragma Import (C, pthread_attr_setinheritsched);
506 function pthread_attr_setschedpolicy
507 (attr : access pthread_attr_t;
508 policy : int) return int;
509 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
511 function sched_yield return int;
512 -- FSU_THREADS does not have sched_yield;
514 ---------------------------
515 -- P1003.1c - Section 16 --
516 ---------------------------
518 function pthread_attr_init (attributes : access pthread_attr_t) return int;
519 pragma Import (C, pthread_attr_init, "pthread_attr_init");
521 function pthread_attr_destroy
522 (attributes : access pthread_attr_t) return int;
523 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
525 function pthread_attr_setdetachstate
526 (attr : access pthread_attr_t;
527 detachstate : int) return int;
528 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
530 function pthread_attr_setstacksize
531 (attr : access pthread_attr_t;
532 stacksize : size_t) return int;
533 pragma Import (C, pthread_attr_setstacksize);
535 function pthread_create
536 (thread : access pthread_t;
537 attributes : access pthread_attr_t;
538 start_routine : Thread_Body;
539 arg : System.Address) return int;
540 pragma Import (C, pthread_create, "pthread_create");
542 procedure pthread_exit (status : System.Address);
543 pragma Import (C, pthread_exit, "pthread_exit");
545 function pthread_self return pthread_t;
546 pragma Import (C, pthread_self, "pthread_self");
548 --------------------------
549 -- POSIX.1c Section 17 --
550 --------------------------
552 function pthread_setspecific
553 (key : pthread_key_t;
554 value : System.Address) return int;
555 pragma Import (C, pthread_setspecific, "pthread_setspecific");
557 function pthread_getspecific (key : pthread_key_t) return System.Address;
558 -- FSU_THREADS has a nonstandard pthread_getspecific
560 type destructor_pointer is access procedure (arg : System.Address);
562 function pthread_key_create
563 (key : access pthread_key_t;
564 destructor : destructor_pointer) return int;
565 pragma Import (C, pthread_key_create, "pthread_key_create");
567 private
569 type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
570 type sigset_t is record
571 X_X_sigbits : array_type_1;
572 end record;
573 pragma Convention (C, sigset_t);
575 type pid_t is new long;
577 type time_t is new long;
579 type timespec is record
580 tv_sec : time_t;
581 tv_nsec : long;
582 end record;
583 pragma Convention (C, timespec);
585 type clockid_t is new int;
586 CLOCK_REALTIME : constant clockid_t := 0;
588 type struct_timeval is record
589 tv_sec : long;
590 tv_usec : long;
591 end record;
592 pragma Convention (C, struct_timeval);
594 type pthread_attr_t is record
595 flags : int;
596 stacksize : int;
597 contentionscope : int;
598 inheritsched : int;
599 detachstate : int;
600 sched : int;
601 prio : int;
602 starttime : timespec;
603 deadline : timespec;
604 period : timespec;
605 end record;
606 pragma Convention (C, pthread_attr_t);
608 type pthread_condattr_t is record
609 flags : int;
610 end record;
611 pragma Convention (C, pthread_condattr_t);
613 type pthread_mutexattr_t is record
614 flags : int;
615 prio_ceiling : int;
616 protocol : int;
617 end record;
618 pragma Convention (C, pthread_mutexattr_t);
620 type sigjmp_buf is array (Integer range 0 .. 18) of int;
622 type pthread_t_struct is record
623 context : sigjmp_buf;
624 pbody : sigjmp_buf;
625 errno : int;
626 ret : int;
627 stack_base : System.Address;
628 end record;
629 pragma Convention (C, pthread_t_struct);
631 type pthread_t is access all pthread_t_struct;
633 type queue_t is record
634 head : System.Address;
635 tail : System.Address;
636 end record;
637 pragma Convention (C, queue_t);
639 type pthread_mutex_t is record
640 queue : queue_t;
641 lock : plain_char;
642 owner : System.Address;
643 flags : int;
644 prio_ceiling : int;
645 protocol : int;
646 prev_max_ceiling_prio : int;
647 end record;
648 pragma Convention (C, pthread_mutex_t);
650 type pthread_cond_t is record
651 queue : queue_t;
652 flags : int;
653 waiters : int;
654 mutex : System.Address;
655 end record;
656 pragma Convention (C, pthread_cond_t);
658 type pthread_key_t is new int;
660 end System.OS_Interface;