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 --
11 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This is a AIX (FSU THREADS) version of this package.
39 -- This package encapsulates all direct interfaces to OS services
40 -- that are needed by children of System.
42 -- PLEASE DO NOT add any with-clauses to this package
43 -- or remove the pragma Elaborate_Body.
44 -- It is designed to be a bottom-level (leaf) package.
47 package System.OS_Interface is
49 -- pragma Elaborate_Body;
51 pragma Linker_Options ("-lgthreads");
52 pragma Linker_Options ("-lmalloc");
54 subtype int is Interfaces.C.int;
55 subtype short is Interfaces.C.short;
56 subtype long is Interfaces.C.long;
57 subtype unsigned is Interfaces.C.unsigned;
58 subtype unsigned_short is Interfaces.C.unsigned_short;
59 subtype unsigned_long is Interfaces.C.unsigned_long;
60 subtype unsigned_char is Interfaces.C.unsigned_char;
61 subtype plain_char is Interfaces.C.plain_char;
62 subtype size_t is Interfaces.C.size_t;
68 function errno return int;
69 pragma Import (C, errno, "__get_errno");
71 EAGAIN : constant := 11;
72 EINTR : constant := 4;
73 EINVAL : constant := 22;
74 ENOMEM : constant := 12;
75 ETIMEDOUT : constant := 78;
81 Max_Interrupt : constant := 63;
82 type Signal is new int range 0 .. Max_Interrupt;
83 for Signal'Size use int'Size;
85 SIGHUP : constant := 1; -- hangup
86 SIGINT : constant := 2; -- interrupt (rubout)
87 SIGQUIT : constant := 3; -- quit (ASCD FS)
88 SIGILL : constant := 4; -- illegal instruction (not reset)
89 SIGTRAP : constant := 5; -- trace trap (not reset)
90 SIGIOT : constant := 6; -- IOT instruction
91 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
92 SIGEMT : constant := 7; -- EMT instruction
93 SIGFPE : constant := 8; -- floating point exception
94 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
95 SIGBUS : constant := 10; -- bus error
96 SIGSEGV : constant := 11; -- segmentation violation
97 SIGSYS : constant := 12; -- bad argument to system call
98 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
99 SIGALRM : constant := 14; -- alarm clock
100 SIGTERM : constant := 15; -- software termination signal from kill
101 SIGUSR1 : constant := 30; -- user defined signal 1
102 SIGUSR2 : constant := 31; -- user defined signal 2
103 SIGCLD : constant := 20; -- alias for SIGCHLD
104 SIGCHLD : constant := 20; -- child status change
105 SIGPWR : constant := 29; -- power-fail restart
106 SIGWINCH : constant := 28; -- window size change
107 SIGURG : constant := 16; -- urgent condition on IO channel
108 SIGPOLL : constant := 23; -- pollable event occurred
109 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
110 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
111 SIGTSTP : constant := 18; -- user stop requested from tty
112 SIGCONT : constant := 19; -- stopped process has been continued
113 SIGTTIN : constant := 21; -- background tty read attempted
114 SIGTTOU : constant := 22; -- background tty write attempted
115 SIGVTALRM : constant := 34; -- virtual timer expired
116 SIGPROF : constant := 32; -- profiling timer expired
117 SIGXCPU : constant := 24; -- CPU time limit exceeded
118 SIGXFSZ : constant := 25; -- filesize limit exceeded
119 SIGWAITING : constant := 39; -- m:n scheduling
121 -- the following signals are AIX specific
122 SIGMSG : constant := 27; -- input data is in the ring buffer
123 SIGDANGER : constant := 33; -- system crash imminent
124 SIGMIGRATE : constant := 35; -- migrate process
125 SIGPRE : constant := 36; -- programming exception
126 SIGVIRT : constant := 37; -- AIX virtual time alarm
127 SIGALRM1 : constant := 38; -- m:n condition variables
128 SIGKAP : constant := 60; -- keep alive poll from native keyboard
129 SIGGRANT : constant := SIGKAP; -- monitor mode granted
130 SIGRETRACT : constant := 61; -- monitor mode should be relinguished
131 SIGSOUND : constant := 62; -- sound control has completed
132 SIGSAK : constant := 63; -- secure attention key
134 SIGADAABORT : constant := SIGABRT;
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 :=
141 (SIGKILL, SIGSTOP, SIGALRM, SIGWAITING);
143 type sigset_t is private;
145 function sigaddset (set : access sigset_t; sig : Signal) return int;
146 pragma Import (C, sigaddset, "sigaddset");
148 function sigdelset (set : access sigset_t; sig : Signal) return int;
149 pragma Import (C, sigdelset, "sigdelset");
151 function sigfillset (set : access sigset_t) return int;
152 pragma Import (C, sigfillset, "sigfillset");
154 function sigismember (set : access sigset_t; sig : Signal) return int;
155 pragma Import (C, sigismember, "sigismember");
157 function sigemptyset (set : access sigset_t) return int;
158 pragma Import (C, sigemptyset, "sigemptyset");
160 type struct_sigaction is record
161 sa_handler : System.Address;
165 pragma Convention (C, struct_sigaction);
166 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;
177 act : struct_sigaction_ptr;
178 oact : struct_sigaction_ptr) return int;
179 pragma Import (C, sigaction, "_internal_sigaction");
185 Time_Slice_Supported : constant Boolean := True;
186 -- Indicates wether time slicing is supported (i.e FSU threads have been
187 -- compiled with DEF_RR)
189 type timespec is private;
191 type clockid_t is private;
193 CLOCK_REALTIME : constant clockid_t;
195 function clock_gettime
196 (clock_id : clockid_t;
197 tp : access timespec) return int;
198 pragma Import (C, clock_gettime, "clock_gettime");
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_timeval is private;
208 function To_Duration (TV : struct_timeval) return Duration;
209 pragma Inline (To_Duration);
211 function To_Timeval (D : Duration) return struct_timeval;
212 pragma Inline (To_Timeval);
214 -------------------------
215 -- Priority Scheduling --
216 -------------------------
218 SCHED_FIFO : constant := 0;
219 SCHED_RR : constant := 1;
220 SCHED_OTHER : constant := 2;
226 type pid_t is private;
228 function kill (pid : pid_t; sig : Signal) return int;
229 pragma Import (C, kill, "kill");
231 function getpid return pid_t;
232 pragma Import (C, getpid, "getpid");
238 function lwp_self return System.Address;
239 -- lwp_self does not exist on this thread library, revert to pthread_self
240 -- which is the closest approximation (with getpid). This function is
241 -- needed to share 7staprop.adb across POSIX-like targets.
242 pragma Import (C, lwp_self, "pthread_self");
248 type Thread_Body is access
249 function (arg : System.Address) return System.Address;
250 type pthread_t is private;
251 subtype Thread_Id is pthread_t;
253 type pthread_mutex_t is limited private;
254 type pthread_cond_t is limited private;
255 type pthread_attr_t is limited private;
256 type pthread_mutexattr_t is limited private;
257 type pthread_condattr_t is limited private;
258 type pthread_key_t is private;
260 PTHREAD_CREATE_DETACHED : constant := 1;
266 Stack_Base_Available : constant Boolean := True;
267 -- Indicates wether the stack base is available on this target.
268 -- This allows us to share s-osinte.adb between all the FSU run time.
269 -- Note that this value can only be true if pthread_t has a complete
270 -- definition that corresponds exactly to the C header files.
272 function Get_Stack_Base (thread : pthread_t) return Address;
273 pragma Inline (Get_Stack_Base);
274 -- returns the stack base of the specified thread.
275 -- Only call this function when Stack_Base_Available is True.
277 function Get_Page_Size return size_t;
278 function Get_Page_Size return Address;
279 pragma Import (C, Get_Page_Size, "getpagesize");
280 -- returns the size of a page, or 0 if this is not relevant on this
283 PROT_NONE : constant := 0;
284 PROT_READ : constant := 1;
285 PROT_WRITE : constant := 2;
286 PROT_EXEC : constant := 4;
287 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
289 PROT_ON : constant := PROT_READ;
290 PROT_OFF : constant := PROT_ALL;
292 function mprotect (addr : Address; len : size_t; prot : int) return int;
293 pragma Import (C, mprotect);
295 ---------------------------------------
296 -- Nonstandard Thread Initialization --
297 ---------------------------------------
299 procedure pthread_init;
300 -- FSU_THREADS requires pthread_init, which is nonstandard
301 -- and this should be invoked during the elaboration of s-taprop.adb
302 pragma Import (C, pthread_init, "pthread_init");
304 -------------------------
305 -- POSIX.1c Section 3 --
306 -------------------------
309 (set : access sigset_t;
310 sig : access Signal) return int;
311 -- FSU_THREADS has a nonstandard sigwait
313 function pthread_kill
315 sig : Signal) return int;
316 pragma Import (C, pthread_kill, "pthread_kill");
318 -- FSU threads does not have pthread_sigmask. Instead, it redefines
319 -- sigprocmask and then uses a special syscall API to call the system
320 -- version. Doing syscalls on AiX is very difficult, so we rename the
321 -- pthread version instead.
323 type sigset_t_ptr is access all sigset_t;
325 function pthread_sigmask
328 oset : sigset_t_ptr) return int;
329 pragma Import (C, pthread_sigmask, "_internal_sigprocmask");
331 --------------------------
332 -- POSIX.1c Section 11 --
333 --------------------------
335 function pthread_mutexattr_init
336 (attr : access pthread_mutexattr_t) return int;
337 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
339 function pthread_mutexattr_destroy
340 (attr : access pthread_mutexattr_t) return int;
341 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
343 function pthread_mutex_init
344 (mutex : access pthread_mutex_t;
345 attr : access pthread_mutexattr_t) return int;
346 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
348 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
349 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
351 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
352 -- FSU_THREADS has nonstandard pthread_mutex_lock
354 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
355 -- FSU_THREADS has nonstandard pthread_mutex_lock
357 function pthread_condattr_init
358 (attr : access pthread_condattr_t) return int;
359 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
361 function pthread_condattr_destroy
362 (attr : access pthread_condattr_t) return int;
363 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
365 function pthread_cond_init
366 (cond : access pthread_cond_t;
367 attr : access pthread_condattr_t) return int;
368 pragma Import (C, pthread_cond_init, "pthread_cond_init");
370 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
371 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
373 function pthread_cond_signal (cond : access pthread_cond_t) return int;
374 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
376 function pthread_cond_wait
377 (cond : access pthread_cond_t;
378 mutex : access pthread_mutex_t) return int;
379 -- FSU_THREADS has a nonstandard pthread_cond_wait
381 function pthread_cond_timedwait
382 (cond : access pthread_cond_t;
383 mutex : access pthread_mutex_t;
384 abstime : access timespec) return int;
385 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
387 Relative_Timed_Wait : constant Boolean := False;
388 -- pthread_cond_timedwait requires an absolute delay time
390 --------------------------
391 -- POSIX.1c Section 13 --
392 --------------------------
394 PTHREAD_PRIO_NONE : constant := 0;
395 PTHREAD_PRIO_PROTECT : constant := 2;
396 PTHREAD_PRIO_INHERIT : constant := 1;
398 function pthread_mutexattr_setprotocol
399 (attr : access pthread_mutexattr_t;
400 protocol : int) return int;
401 pragma Import (C, pthread_mutexattr_setprotocol);
403 function pthread_mutexattr_setprioceiling
404 (attr : access pthread_mutexattr_t;
405 prioceiling : int) return int;
407 (C, pthread_mutexattr_setprioceiling,
408 "pthread_mutexattr_setprio_ceiling");
410 type struct_sched_param is record
411 sched_priority : int; -- scheduling priority
414 function pthread_setschedparam
417 param : access struct_sched_param) return int;
418 -- FSU_THREADS does not have 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, "pthread_attr_setsched");
435 function sched_yield return int;
436 -- FSU_THREADS does not have sched_yield;
438 ---------------------------
439 -- P1003.1c - Section 16 --
440 ---------------------------
442 function pthread_attr_init (attributes : access pthread_attr_t) return int;
443 pragma Import (C, pthread_attr_init, "pthread_attr_init");
445 function pthread_attr_destroy
446 (attributes : access pthread_attr_t) return int;
447 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
449 function pthread_attr_setdetachstate
450 (attr : access pthread_attr_t;
451 detachstate : int) return int;
452 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
454 function pthread_attr_setstacksize
455 (attr : access pthread_attr_t;
456 stacksize : size_t) return int;
457 pragma Import (C, pthread_attr_setstacksize);
459 function pthread_create
460 (thread : access pthread_t;
461 attributes : access pthread_attr_t;
462 start_routine : Thread_Body;
463 arg : System.Address) return int;
464 pragma Import (C, pthread_create, "pthread_create");
466 procedure pthread_exit (status : System.Address);
467 pragma Import (C, pthread_exit, "pthread_exit");
469 function pthread_self return pthread_t;
470 pragma Import (C, pthread_self, "pthread_self");
472 --------------------------
473 -- POSIX.1c Section 17 --
474 --------------------------
476 function pthread_setspecific
477 (key : pthread_key_t;
478 value : System.Address) return int;
479 pragma Import (C, pthread_setspecific, "pthread_setspecific");
481 function pthread_getspecific (key : pthread_key_t) return System.Address;
482 -- FSU_THREADS has a nonstandard pthread_getspecific
484 type destructor_pointer is access procedure (arg : System.Address);
486 function pthread_key_create
487 (key : access pthread_key_t;
488 destructor : destructor_pointer) return int;
489 pragma Import (C, pthread_key_create, "pthread_key_create");
493 type sigset_t is record
494 losigs : unsigned_long;
495 hisigs : unsigned_long;
497 pragma Convention (C_Pass_By_Copy, sigset_t);
499 type pid_t is new int;
501 type time_t is new long;
503 type timespec is record
507 pragma Convention (C, timespec);
509 type clockid_t is new int;
510 CLOCK_REALTIME : constant clockid_t := 0;
512 type struct_timeval is record
516 pragma Convention (C, struct_timeval);
518 type pthread_attr_t is record
521 contentionscope : int;
526 starttime : timespec;
530 pragma Convention (C_Pass_By_Copy, pthread_attr_t);
532 type pthread_condattr_t is record
535 pragma Convention (C, pthread_condattr_t);
537 type pthread_mutexattr_t is record
542 pragma Convention (C, pthread_mutexattr_t);
544 type sigjmp_buf is array (Integer range 0 .. 63) of int;
546 type pthread_t_struct is record
547 context : sigjmp_buf;
551 stack_base : System.Address;
553 pragma Convention (C, pthread_t_struct);
555 type pthread_t is access all pthread_t_struct;
557 type queue_t is record
558 head : System.Address;
559 tail : System.Address;
561 pragma Convention (C, queue_t);
563 type pthread_mutex_t is record
566 owner : System.Address;
570 prev_max_ceiling_prio : int;
572 pragma Convention (C, pthread_mutex_t);
574 type pthread_cond_t is record
578 mutex : System.Address;
580 pragma Convention (C, pthread_cond_t);
582 type pthread_key_t is new int;
584 end System.OS_Interface;