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) 1997-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 (Native 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
50 pragma Linker_Options ("-lpthreads");
51 pragma Linker_Options ("-lc_r");
53 subtype int is Interfaces.C.int;
54 subtype short is Interfaces.C.short;
55 subtype long is Interfaces.C.long;
56 subtype unsigned is Interfaces.C.unsigned;
57 subtype unsigned_short is Interfaces.C.unsigned_short;
58 subtype unsigned_long is Interfaces.C.unsigned_long;
59 subtype unsigned_char is Interfaces.C.unsigned_char;
60 subtype plain_char is Interfaces.C.plain_char;
61 subtype size_t is Interfaces.C.size_t;
67 function errno return int;
68 pragma Import (C, errno, "__get_errno");
70 EAGAIN : constant := 11;
71 EINTR : constant := 4;
72 EINVAL : constant := 22;
73 ENOMEM : constant := 12;
74 ETIMEDOUT : constant := 78;
80 Max_Interrupt : constant := 63;
81 type Signal is new int range 0 .. Max_Interrupt;
82 for Signal'Size use int'Size;
84 SIGHUP : constant := 1; -- hangup
85 SIGINT : constant := 2; -- interrupt (rubout)
86 SIGQUIT : constant := 3; -- quit (ASCD FS)
87 SIGILL : constant := 4; -- illegal instruction (not reset)
88 SIGTRAP : constant := 5; -- trace trap (not reset)
89 SIGIOT : constant := 6; -- IOT instruction
90 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
91 SIGEMT : constant := 7; -- EMT instruction
92 SIGFPE : constant := 8; -- floating point exception
93 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
94 SIGBUS : constant := 10; -- bus error
95 SIGSEGV : constant := 11; -- segmentation violation
96 SIGSYS : constant := 12; -- bad argument to system call
97 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
98 SIGALRM : constant := 14; -- alarm clock
99 SIGTERM : constant := 15; -- software termination signal from kill
100 SIGUSR1 : constant := 30; -- user defined signal 1
101 SIGUSR2 : constant := 31; -- user defined signal 2
102 SIGCLD : constant := 20; -- alias for SIGCHLD
103 SIGCHLD : constant := 20; -- child status change
104 SIGPWR : constant := 29; -- power-fail restart
105 SIGWINCH : constant := 28; -- window size change
106 SIGURG : constant := 16; -- urgent condition on IO channel
107 SIGPOLL : constant := 23; -- pollable event occurred
108 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
109 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
110 SIGTSTP : constant := 18; -- user stop requested from tty
111 SIGCONT : constant := 19; -- stopped process has been continued
112 SIGTTIN : constant := 21; -- background tty read attempted
113 SIGTTOU : constant := 22; -- background tty write attempted
114 SIGVTALRM : constant := 34; -- virtual timer expired
115 SIGPROF : constant := 32; -- profiling timer expired
116 SIGXCPU : constant := 24; -- CPU time limit exceeded
117 SIGXFSZ : constant := 25; -- filesize limit exceeded
118 SIGWAITING : constant := 39; -- m:n scheduling
120 -- the following signals are AIX specific
121 SIGMSG : constant := 27; -- input data is in the ring buffer
122 SIGDANGER : constant := 33; -- system crash imminent
123 SIGMIGRATE : constant := 35; -- migrate process
124 SIGPRE : constant := 36; -- programming exception
125 SIGVIRT : constant := 37; -- AIX virtual time alarm
126 SIGALRM1 : constant := 38; -- m:n condition variables
127 SIGKAP : constant := 60; -- keep alive poll from native keyboard
128 SIGGRANT : constant := SIGKAP; -- monitor mode granted
129 SIGRETRACT : constant := 61; -- monitor mode should be relinguished
130 SIGSOUND : constant := 62; -- sound control has completed
131 SIGSAK : constant := 63; -- secure attention key
133 SIGADAABORT : constant := SIGTERM;
134 -- Note: on other targets, we usually use SIGABRT, but on AiX, it
135 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
137 type Signal_Set is array (Natural range <>) of Signal;
139 Unmasked : constant Signal_Set :=
140 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
141 Reserved : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP);
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;
169 SIG_BLOCK : constant := 0;
170 SIG_UNBLOCK : constant := 1;
171 SIG_SETMASK : constant := 2;
173 SIG_DFL : constant := 0;
174 SIG_IGN : constant := 1;
178 act : struct_sigaction_ptr;
179 oact : struct_sigaction_ptr) return int;
180 pragma Import (C, sigaction, "sigaction");
186 Time_Slice_Supported : constant Boolean := False;
187 -- Indicates wether time slicing is supported
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 -- AiX threads don't have clock_gettime
199 -- We instead use gettimeofday()
201 function To_Duration (TS : timespec) return Duration;
202 pragma Inline (To_Duration);
204 function To_Timespec (D : Duration) return timespec;
205 pragma Inline (To_Timespec);
207 type struct_timezone is record
208 tz_minuteswest : int;
211 pragma Convention (C, struct_timezone);
212 type struct_timezone_ptr is access all struct_timezone;
214 type struct_timeval is private;
215 -- This is needed on systems that do not have clock_gettime()
216 -- but do have gettimeofday().
218 function To_Duration (TV : struct_timeval) return Duration;
219 pragma Inline (To_Duration);
221 function To_Timeval (D : Duration) return struct_timeval;
222 pragma Inline (To_Timeval);
224 -------------------------
225 -- Priority Scheduling --
226 -------------------------
228 SCHED_FIFO : constant := 1;
229 SCHED_RR : constant := 2;
230 SCHED_OTHER : constant := 0;
236 type pid_t is private;
238 function kill (pid : pid_t; sig : Signal) return int;
239 pragma Import (C, kill, "kill");
241 function getpid return pid_t;
242 pragma Import (C, getpid, "getpid");
248 function lwp_self return System.Address;
249 pragma Import (C, lwp_self, "thread_self");
255 type Thread_Body is access
256 function (arg : System.Address) return System.Address;
257 type pthread_t is private;
258 subtype Thread_Id is pthread_t;
260 type pthread_mutex_t is limited private;
261 type pthread_cond_t is limited private;
262 type pthread_attr_t is limited private;
263 type pthread_mutexattr_t is limited private;
264 type pthread_condattr_t is limited private;
265 type pthread_key_t is private;
267 PTHREAD_CREATE_DETACHED : constant := 1;
273 Stack_Base_Available : constant Boolean := False;
274 -- Indicates wether the stack base is available on this target.
276 function Get_Stack_Base (thread : pthread_t) return Address;
277 pragma Inline (Get_Stack_Base);
278 -- returns the stack base of the specified thread.
279 -- Only call this function when Stack_Base_Available is True.
281 function Get_Page_Size return size_t;
282 function Get_Page_Size return Address;
283 pragma Import (C, Get_Page_Size, "getpagesize");
284 -- returns the size of a page, or 0 if this is not relevant on this
287 PROT_NONE : constant := 0;
288 PROT_READ : constant := 1;
289 PROT_WRITE : constant := 2;
290 PROT_EXEC : constant := 4;
291 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
293 PROT_ON : constant := PROT_READ;
294 PROT_OFF : constant := PROT_ALL;
296 function mprotect (addr : Address; len : size_t; prot : int) return int;
297 pragma Import (C, mprotect);
299 ---------------------------------------
300 -- Nonstandard Thread Initialization --
301 ---------------------------------------
303 -- Though not documented, pthread_init *must* be called before any other
306 procedure pthread_init;
307 pragma Import (C, pthread_init, "pthread_init");
309 -------------------------
310 -- POSIX.1c Section 3 --
311 -------------------------
314 (set : access sigset_t;
315 sig : access Signal) return int;
316 pragma Import (C, sigwait, "sigwait");
318 function pthread_kill
320 sig : Signal) return int;
321 pragma Import (C, pthread_kill, "pthread_kill");
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, "sigthreadmask");
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 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
354 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
355 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
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 pragma Import (C, pthread_cond_wait, "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 pragma Import (C, pthread_cond_timedwait, "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 := 0;
396 PTHREAD_PRIO_INHERIT : constant := 0;
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;
406 pragma Import (C, pthread_mutexattr_setprioceiling);
408 type Array_5_Int is array (0 .. 5) of int;
409 type struct_sched_param is record
410 sched_priority : int;
412 sched_reserved : Array_5_Int;
415 function pthread_setschedparam
418 param : access struct_sched_param) return int;
419 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
421 function pthread_attr_setscope
422 (attr : access pthread_attr_t;
423 contentionscope : int) return int;
424 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
426 function pthread_attr_setinheritsched
427 (attr : access pthread_attr_t;
428 inheritsched : int) return int;
429 pragma Import (C, pthread_attr_setinheritsched);
431 function pthread_attr_setschedpolicy
432 (attr : access pthread_attr_t;
433 policy : int) return int;
434 pragma Import (C, pthread_attr_setschedpolicy);
436 function pthread_attr_setschedparam
437 (attr : access pthread_attr_t;
438 sched_param : int) return int;
439 pragma Import (C, pthread_attr_setschedparam);
441 function sched_yield return int;
442 -- AiX have a nonstandard sched_yield.
444 ---------------------------
445 -- P1003.1c - Section 16 --
446 ---------------------------
448 function pthread_attr_init (attributes : access pthread_attr_t) return int;
449 pragma Import (C, pthread_attr_init, "pthread_attr_init");
451 function pthread_attr_destroy
452 (attributes : access pthread_attr_t) return int;
453 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
455 function pthread_attr_setdetachstate
456 (attr : access pthread_attr_t;
457 detachstate : int) return int;
458 pragma Import (C, pthread_attr_setdetachstate);
460 function pthread_attr_setstacksize
461 (attr : access pthread_attr_t;
462 stacksize : size_t) return int;
463 pragma Import (C, pthread_attr_setstacksize);
465 function pthread_create
466 (thread : access pthread_t;
467 attributes : access pthread_attr_t;
468 start_routine : Thread_Body;
469 arg : System.Address)
471 pragma Import (C, pthread_create, "pthread_create");
473 procedure pthread_exit (status : System.Address);
474 pragma Import (C, pthread_exit, "pthread_exit");
476 function pthread_self return pthread_t;
477 pragma Import (C, pthread_self, "pthread_self");
479 --------------------------
480 -- POSIX.1c Section 17 --
481 --------------------------
483 function pthread_setspecific
484 (key : pthread_key_t;
485 value : System.Address) return int;
486 pragma Import (C, pthread_setspecific, "pthread_setspecific");
488 function pthread_getspecific (key : pthread_key_t) return System.Address;
489 pragma Import (C, pthread_getspecific, "pthread_getspecific");
491 type destructor_pointer is access
492 procedure (arg : System.Address);
494 function pthread_key_create
495 (key : access pthread_key_t;
496 destructor : destructor_pointer) return int;
497 pragma Import (C, pthread_key_create, "pthread_key_create");
501 type sigset_t is record
502 losigs : unsigned_long;
503 hisigs : unsigned_long;
505 pragma Convention (C_Pass_By_Copy, sigset_t);
507 type pid_t is new int;
509 type time_t is new long;
511 type timespec is record
515 pragma Convention (C, timespec);
517 type clockid_t is new int;
518 CLOCK_REALTIME : constant clockid_t := 0;
520 type struct_timeval is record
524 pragma Convention (C, struct_timeval);
526 type pthread_attr_t is new System.Address;
527 pragma Convention (C, pthread_attr_t);
528 -- typedef struct __pt_attr *pthread_attr_t;
530 type pthread_condattr_t is new System.Address;
531 pragma Convention (C, pthread_condattr_t);
532 -- typedef struct __pt_attr *pthread_condattr_t;
534 type pthread_mutexattr_t is new System.Address;
535 pragma Convention (C, pthread_mutexattr_t);
536 -- typedef struct __pt_attr *pthread_mutexattr_t;
538 type pthread_t is new System.Address;
539 pragma Convention (C, pthread_t);
540 -- typedef void *pthread_t;
543 type ptq_queue_ptr is access all ptq_queue;
545 type ptq_queue is record
546 ptq_next : ptq_queue_ptr;
547 ptq_prev : ptq_queue_ptr;
550 type Array_3_Int is array (0 .. 3) of int;
551 type pthread_mutex_t is record
557 ptmtx_owner : pthread_t;
559 attr : pthread_attr_t;
562 reserved : Array_3_Int;
564 pragma Convention (C, pthread_mutex_t);
565 type pthread_mutex_t_ptr is access pthread_mutex_t;
567 type pthread_cond_t is record
571 ptcv_waiters : ptq_queue;
573 attr : pthread_attr_t;
574 mutex : pthread_mutex_t_ptr;
578 pragma Convention (C, pthread_cond_t);
580 type pthread_key_t is new unsigned;
582 end System.OS_Interface;