1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
9 -- Copyright (C) 1997-2003, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 -- This is a Solaris (FSU THREADS) version of this package.
36 -- This package includes all direct interfaces to OS services
37 -- that are needed by children of System.
39 -- PLEASE DO NOT add any with-clauses to this package
40 -- or remove the pragma Elaborate_Body.
41 -- It is designed to be a bottom-level (leaf) package.
44 package System.OS_Interface is
47 pragma Linker_Options ("-lgthreads");
48 pragma Linker_Options ("-lmalloc");
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;
64 function errno return int;
65 pragma Import (C, errno, "__get_errno");
67 EAGAIN : constant := 11;
68 EINTR : constant := 4;
69 EINVAL : constant := 22;
70 ENOMEM : constant := 12;
71 ETIMEDOUT : constant := 145;
77 Max_Interrupt : constant := 45;
78 type Signal is new int range 0 .. Max_Interrupt;
79 for Signal'Size use int'Size;
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 SIGWINCH : constant := 20; -- window size change
103 SIGURG : constant := 21; -- urgent condition on IO channel
104 SIGPOLL : constant := 22; -- pollable event occurred
105 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
106 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
107 SIGTSTP : constant := 24; -- user stop requested from tty
108 SIGCONT : constant := 25; -- stopped process has been continued
109 SIGTTIN : constant := 26; -- background tty read attempted
110 SIGTTOU : constant := 27; -- background tty write attempted
111 SIGVTALRM : constant := 28; -- virtual timer expired
112 SIGPROF : constant := 29; -- profiling timer expired
113 SIGXCPU : constant := 30; -- CPU time limit exceeded
114 SIGXFSZ : constant := 31; -- filesize limit exceeded
115 SIGWAITING : constant := 32; -- process's lwps blocked (Solaris)
116 SIGLWP : constant := 33; -- used by thread library (Solaris)
117 SIGFREEZE : constant := 34; -- used by CPR (Solaris)
118 SIGTHAW : constant := 35; -- used by CPR (Solaris)
119 SIGCANCEL : constant := 36; -- used for thread cancel (Solaris)
120 SIGRTMIN : constant := 38; -- first (highest-priority) realtime signal
121 SIGRTMAX : constant := 45; -- last (lowest-priority) realtime signal
123 type Signal_Set is array (Natural range <>) of Signal;
125 Unmasked : constant Signal_Set :=
126 (SIGTRAP, SIGLWP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
128 Reserved : constant Signal_Set :=
129 (SIGKILL, SIGSTOP, SIGALRM, SIGVTALRM, SIGWAITING, SIGRTMAX);
131 type sigset_t is private;
133 function sigaddset (set : access sigset_t; sig : Signal) return int;
134 pragma Import (C, sigaddset, "sigaddset");
136 function sigdelset (set : access sigset_t; sig : Signal) return int;
137 pragma Import (C, sigdelset, "sigdelset");
139 function sigfillset (set : access sigset_t) return int;
140 pragma Import (C, sigfillset, "sigfillset");
142 function sigismember (set : access sigset_t; sig : Signal) return int;
143 pragma Import (C, sigismember, "sigismember");
145 function sigemptyset (set : access sigset_t) return int;
146 pragma Import (C, sigemptyset, "sigemptyset");
148 type union_type_3 is new String (1 .. 116);
149 type siginfo_t is record
153 X_data : union_type_3;
155 pragma Convention (C, siginfo_t);
157 -- The types mcontext_t and gregset_t are part of the ucontext_t
158 -- information, which is specific to Solaris2.4 for SPARC
159 -- The ucontext_t info seems to be used by the handler
160 -- for SIGSEGV to decide whether it is a Storage_Error (stack overflow) or
161 -- a Constraint_Error (bad pointer). The original code that did this
162 -- is suspect, so it is not clear whether we really need this part of
163 -- the signal context information, or perhaps something else.
164 -- More analysis is needed, after which these declarations may need to
167 EMT_TAGOVF : constant := 1; -- tag overflow
168 FPE_INTDIV : constant := 1; -- integer divide by zero
169 FPE_INTOVF : constant := 2; -- integer overflow
170 FPE_FLTDIV : constant := 3; -- floating point divide by zero
171 FPE_FLTOVF : constant := 4; -- floating point overflow
172 FPE_FLTUND : constant := 5; -- floating point underflow
173 FPE_FLTRES : constant := 6; -- floating point inexact result
174 FPE_FLTINV : constant := 7; -- invalid floating point operation
175 FPE_FLTSUB : constant := 8; -- subscript out of range
177 SEGV_MAPERR : constant := 1; -- address not mapped to object
178 SEGV_ACCERR : constant := 2; -- invalid permissions
180 BUS_ADRALN : constant := 1; -- invalid address alignment
181 BUS_ADRERR : constant := 2; -- non-existent physical address
182 BUS_OBJERR : constant := 3; -- object specific hardware error
184 ILL_ILLOPC : constant := 1; -- illegal opcode
185 ILL_ILLOPN : constant := 2; -- illegal operand
186 ILL_ILLADR : constant := 3; -- illegal addressing mode
187 ILL_ILLTRP : constant := 4; -- illegal trap
188 ILL_PRVOPC : constant := 5; -- privileged opcode
189 ILL_PRVREG : constant := 6; -- privileged register
190 ILL_COPROC : constant := 7; -- co-processor
191 ILL_BADSTK : constant := 8; -- bad stack
193 type greg_t is new int;
195 type gregset_t is array (Integer range 0 .. 18) of greg_t;
197 REG_O0 : constant := 11;
198 -- index of saved register O0 in ucontext.uc_mcontext.gregs array
200 type union_type_2 is new String (1 .. 128);
201 type record_type_1 is record
202 fpu_fr : union_type_2;
203 fpu_q : System.Address;
205 fpu_qcnt : unsigned_char;
206 fpu_q_entrysize : unsigned_char;
207 fpu_en : unsigned_char;
209 pragma Convention (C, record_type_1);
210 type array_type_7 is array (Integer range 0 .. 20) of long;
211 type mcontext_t is record
213 gwins : System.Address;
214 fpregs : record_type_1;
215 filler : array_type_7;
217 pragma Convention (C, mcontext_t);
219 type record_type_2 is record
220 ss_sp : System.Address;
224 pragma Convention (C, record_type_2);
225 type array_type_8 is array (Integer range 0 .. 22) of long;
226 type ucontext_t is record
227 uc_flags : unsigned_long;
228 uc_link : System.Address;
229 uc_sigmask : sigset_t;
230 uc_stack : record_type_2;
231 uc_mcontext : mcontext_t;
232 uc_filler : array_type_8;
234 pragma Convention (C, ucontext_t);
236 type Signal_Handler is access procedure
238 info : access siginfo_t;
239 context : access ucontext_t);
241 type union_type_1 is new plain_char;
242 type array_type_2 is array (Integer range 0 .. 1) of int;
243 type struct_sigaction is record
245 sa_handler : System.Address;
247 sa_resv : array_type_2;
249 pragma Convention (C, struct_sigaction);
250 type struct_sigaction_ptr is access all struct_sigaction;
252 SA_SIGINFO : constant := 16#08#;
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;
263 act : struct_sigaction_ptr;
264 oact : struct_sigaction_ptr) return int;
265 pragma Import (C, sigaction, "sigaction");
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;
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");
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");
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;
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
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
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;
484 (C, pthread_mutexattr_setprioceiling,
485 "pthread_mutexattr_setprio_ceiling");
487 type struct_sched_param is record
488 sched_priority : int; -- scheduling priority
491 function pthread_setschedparam
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");
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;
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
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
593 pragma Convention (C, struct_timeval);
595 type pthread_attr_t is record
598 contentionscope : int;
603 starttime : timespec;
607 pragma Convention (C, pthread_attr_t);
609 type pthread_condattr_t is record
612 pragma Convention (C, pthread_condattr_t);
614 type pthread_mutexattr_t is 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;
628 stack_base : System.Address;
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;
638 pragma Convention (C, queue_t);
640 type pthread_mutex_t is record
643 owner : System.Address;
647 prev_max_ceiling_prio : int;
649 pragma Convention (C, pthread_mutex_t);
651 type pthread_cond_t is record
655 mutex : System.Address;
657 pragma Convention (C, pthread_cond_t);
659 type pthread_key_t is new int;
661 end System.OS_Interface;