1 ------------------------------------------------------------------------------
3 -- GNAT 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) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2008, Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
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. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
33 ------------------------------------------------------------------------------
35 -- This is the SGI Pthreads version of this package
37 -- This package encapsulates all direct interfaces to OS services that are
38 -- needed by the tasking run-time (libgnarl).
40 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
43 with Ada.Unchecked_Conversion;
47 package System.OS_Interface is
51 pragma Linker_Options ("-lpthread");
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 EINTR : constant := 4; -- interrupted system call
71 EAGAIN : constant := 11; -- No more processes
72 ENOMEM : constant := 12; -- Not enough core
73 EINVAL : constant := 22; -- Invalid argument
74 ETIMEDOUT : constant := 145; -- Connection timed out
80 Max_Interrupt : constant := 64;
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
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 := 16; -- user defined signal 1
102 SIGUSR2 : constant := 17; -- user defined signal 2
103 SIGCLD : constant := 18; -- alias for SIGCHLD
104 SIGCHLD : constant := 18; -- child status change
105 SIGPWR : constant := 19; -- power-fail restart
106 SIGWINCH : constant := 20; -- window size change
107 SIGURG : constant := 21; -- urgent condition on IO channel
108 SIGPOLL : constant := 22; -- pollable event occurred
109 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
110 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
111 SIGTSTP : constant := 24; -- user stop requested from tty
112 SIGCONT : constant := 25; -- stopped process has been continued
113 SIGTTIN : constant := 26; -- background tty read attempted
114 SIGTTOU : constant := 27; -- background tty write attempted
115 SIGVTALRM : constant := 28; -- virtual timer expired
116 SIGPROF : constant := 29; -- profiling timer expired
117 SIGXCPU : constant := 30; -- CPU time limit exceeded
118 SIGXFSZ : constant := 31; -- filesize limit exceeded
119 SIGK32 : constant := 32; -- reserved for kernel (IRIX)
120 SIGCKPT : constant := 33; -- Checkpoint warning
121 SIGRESTART : constant := 34; -- Restart warning
122 SIGUME : constant := 35; -- Uncorrectable memory error
123 -- Signals defined for Posix 1003.1c
124 SIGPTINTR : constant := 47;
125 SIGPTRESCHED : constant := 48;
126 -- Posix 1003.1b signals
127 SIGRTMIN : constant := 49; -- Posix 1003.1b signals
128 SIGRTMAX : constant := 64; -- Posix 1003.1b signals
130 type sigset_t is private;
132 function sigaddset (set : access sigset_t; sig : Signal) return int;
133 pragma Import (C, sigaddset, "sigaddset");
135 function sigdelset (set : access sigset_t; sig : Signal) return int;
136 pragma Import (C, sigdelset, "sigdelset");
138 function sigfillset (set : access sigset_t) return int;
139 pragma Import (C, sigfillset, "sigfillset");
141 function sigismember (set : access sigset_t; sig : Signal) return int;
142 pragma Import (C, sigismember, "sigismember");
144 function sigemptyset (set : access sigset_t) return int;
145 pragma Import (C, sigemptyset, "sigemptyset");
147 type array_type_2 is array (Integer range 0 .. 1) of int;
148 type struct_sigaction is record
150 sa_handler : System.Address;
152 sa_resv : array_type_2;
154 pragma Convention (C, struct_sigaction);
156 type struct_sigaction_ptr is access all struct_sigaction;
158 SIG_BLOCK : constant := 1;
159 SIG_UNBLOCK : constant := 2;
160 SIG_SETMASK : constant := 3;
162 SIG_DFL : constant := 0;
163 SIG_IGN : constant := 1;
167 act : struct_sigaction_ptr;
168 oact : struct_sigaction_ptr := null) return int;
169 pragma Import (C, sigaction, "sigaction");
175 type timespec is private;
176 type timespec_ptr is access all timespec;
178 type clockid_t is private;
180 CLOCK_REALTIME : constant clockid_t;
181 CLOCK_SGI_FAST : constant clockid_t;
182 CLOCK_SGI_CYCLE : constant clockid_t;
184 SGI_CYCLECNTR_SIZE : constant := 165;
186 function syssgi (request : Interfaces.C.int) return Interfaces.C.ptrdiff_t;
187 pragma Import (C, syssgi, "syssgi");
189 function clock_gettime
190 (clock_id : clockid_t;
191 tp : access timespec) return int;
192 pragma Import (C, clock_gettime, "clock_gettime");
194 function clock_getres
195 (clock_id : clockid_t;
196 tp : access timespec) return int;
197 pragma Import (C, clock_getres, "clock_getres");
199 function To_Duration (TS : timespec) return Duration;
200 pragma Inline (To_Duration);
202 function To_Timespec (D : Duration) return timespec;
203 pragma Inline (To_Timespec);
205 type struct_timeval is private;
207 function To_Duration (TV : struct_timeval) return Duration;
208 pragma Inline (To_Duration);
210 function To_Timeval (D : Duration) return struct_timeval;
211 pragma Inline (To_Timeval);
213 -------------------------
214 -- Priority Scheduling --
215 -------------------------
217 SCHED_FIFO : constant := 1;
218 SCHED_RR : constant := 2;
219 SCHED_TS : constant := 3;
220 SCHED_OTHER : constant := 3;
221 SCHED_NP : constant := 4;
223 function sched_get_priority_min (Policy : int) return int;
224 pragma Import (C, sched_get_priority_min, "sched_get_priority_min");
226 function sched_get_priority_max (Policy : int) return int;
227 pragma Import (C, sched_get_priority_max, "sched_get_priority_max");
233 type pid_t is private;
235 function kill (pid : pid_t; sig : Signal) return int;
236 pragma Import (C, kill, "kill");
238 function getpid return pid_t;
239 pragma Import (C, getpid, "getpid");
245 type Thread_Body is access
246 function (arg : System.Address) return System.Address;
247 pragma Convention (C, Thread_Body);
249 function Thread_Body_Access is new
250 Ada.Unchecked_Conversion (System.Address, Thread_Body);
252 type pthread_t is private;
253 subtype Thread_Id is pthread_t;
255 type pthread_mutex_t is limited private;
256 type pthread_cond_t is limited private;
257 type pthread_attr_t is limited private;
258 type pthread_mutexattr_t is limited private;
259 type pthread_condattr_t is limited private;
260 type pthread_key_t is private;
262 PTHREAD_CREATE_DETACHED : constant := 1;
268 Alternate_Stack_Size : constant := 0;
269 -- No alternate signal stack is used on this platform
271 ---------------------------------------
272 -- Nonstandard Thread Initialization --
273 ---------------------------------------
275 procedure pthread_init;
276 pragma Inline (pthread_init);
277 -- This is a dummy procedure to share some GNULLI files
279 -------------------------
280 -- POSIX.1c Section 3 --
281 -------------------------
284 (set : access sigset_t;
285 sig : access Signal) return int;
286 pragma Import (C, sigwait, "sigwait");
288 function pthread_kill
290 sig : Signal) return int;
291 pragma Import (C, pthread_kill, "pthread_kill");
293 function pthread_sigmask
295 set : access sigset_t;
296 oset : access sigset_t) return int;
297 pragma Import (C, pthread_sigmask, "pthread_sigmask");
299 --------------------------
300 -- POSIX.1c Section 11 --
301 --------------------------
303 function pthread_mutexattr_init
304 (attr : access pthread_mutexattr_t) return int;
305 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
307 function pthread_mutexattr_destroy
308 (attr : access pthread_mutexattr_t) return int;
309 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
311 function pthread_mutex_init
312 (mutex : access pthread_mutex_t;
313 attr : access pthread_mutexattr_t) return int;
314 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
316 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
317 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
319 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
320 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
322 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
323 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
325 function pthread_condattr_init
326 (attr : access pthread_condattr_t) return int;
327 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
329 function pthread_condattr_destroy
330 (attr : access pthread_condattr_t) return int;
331 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
333 function pthread_cond_init
334 (cond : access pthread_cond_t;
335 attr : access pthread_condattr_t) return int;
336 pragma Import (C, pthread_cond_init, "pthread_cond_init");
338 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
339 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
341 function pthread_cond_signal (cond : access pthread_cond_t) return int;
342 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
344 function pthread_cond_wait
345 (cond : access pthread_cond_t;
346 mutex : access pthread_mutex_t) return int;
347 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
349 function pthread_cond_timedwait
350 (cond : access pthread_cond_t;
351 mutex : access pthread_mutex_t;
352 abstime : access timespec) return int;
353 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
355 --------------------------
356 -- POSIX.1c Section 13 --
357 --------------------------
359 PTHREAD_PRIO_NONE : constant := 0;
360 PTHREAD_PRIO_PROTECT : constant := 2;
361 PTHREAD_PRIO_INHERIT : constant := 1;
363 function pthread_mutexattr_setprotocol
364 (attr : access pthread_mutexattr_t;
365 protocol : int) return int;
366 pragma Import (C, pthread_mutexattr_setprotocol);
368 function pthread_mutexattr_setprioceiling
369 (attr : access pthread_mutexattr_t;
370 prioceiling : int) return int;
371 pragma Import (C, pthread_mutexattr_setprioceiling);
373 type struct_sched_param is record
374 sched_priority : int;
376 pragma Convention (C, struct_sched_param);
378 function pthread_setschedparam
381 param : access struct_sched_param)
383 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
385 function pthread_attr_setscope
386 (attr : access pthread_attr_t;
387 contentionscope : int) return int;
388 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
390 function pthread_attr_setinheritsched
391 (attr : access pthread_attr_t;
392 inheritsched : int) return int;
394 (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
396 function pthread_attr_setschedpolicy
397 (attr : access pthread_attr_t;
398 policy : int) return int;
399 pragma Import (C, pthread_attr_setschedpolicy);
401 function pthread_attr_setschedparam
402 (attr : access pthread_attr_t;
403 sched_param : access struct_sched_param)
405 pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam");
407 function sched_yield return int;
408 pragma Import (C, sched_yield, "sched_yield");
410 ---------------------------
411 -- P1003.1c - Section 16 --
412 ---------------------------
414 function pthread_attr_init (attributes : access pthread_attr_t) return int;
415 pragma Import (C, pthread_attr_init, "pthread_attr_init");
417 function pthread_attr_destroy
418 (attributes : access pthread_attr_t) return int;
419 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
421 function pthread_attr_setdetachstate
422 (attr : access pthread_attr_t;
423 detachstate : int) return int;
424 pragma Import (C, pthread_attr_setdetachstate);
426 function pthread_attr_setstacksize
427 (attr : access pthread_attr_t;
428 stacksize : size_t) return int;
429 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
431 function pthread_create
432 (thread : access pthread_t;
433 attributes : access pthread_attr_t;
434 start_routine : Thread_Body;
435 arg : System.Address) return int;
436 pragma Import (C, pthread_create, "pthread_create");
438 procedure pthread_exit (status : System.Address);
439 pragma Import (C, pthread_exit, "pthread_exit");
441 function pthread_self return pthread_t;
442 pragma Import (C, pthread_self, "pthread_self");
444 --------------------------
445 -- POSIX.1c Section 17 --
446 --------------------------
448 function pthread_setspecific
449 (key : pthread_key_t;
450 value : System.Address) return int;
451 pragma Import (C, pthread_setspecific, "pthread_setspecific");
453 function pthread_getspecific (key : pthread_key_t) return System.Address;
454 pragma Import (C, pthread_getspecific, "pthread_getspecific");
456 type destructor_pointer is access procedure (arg : System.Address);
457 pragma Convention (C, destructor_pointer);
459 function pthread_key_create
460 (key : access pthread_key_t;
461 destructor : destructor_pointer) return int;
462 pragma Import (C, pthread_key_create, "pthread_key_create");
468 -- Non portable SGI 6.5 additions to the pthread interface must be
469 -- executed from within the context of a system scope task.
471 function pthread_setrunon_np (cpu : int) return int;
472 pragma Import (C, pthread_setrunon_np, "pthread_setrunon_np");
476 type array_type_1 is array (Integer range 0 .. 3) of unsigned;
477 type sigset_t is record
478 X_X_sigbits : array_type_1;
480 pragma Convention (C, sigset_t);
482 type pid_t is new long;
484 type time_t is new long;
486 type timespec is record
490 pragma Convention (C, timespec);
492 type clockid_t is new int;
493 CLOCK_REALTIME : constant clockid_t := 1;
494 CLOCK_SGI_CYCLE : constant clockid_t := 2;
495 CLOCK_SGI_FAST : constant clockid_t := 3;
497 type struct_timeval is record
501 pragma Convention (C, struct_timeval);
503 type array_type_9 is array (Integer range 0 .. 4) of long;
504 type pthread_attr_t is record
505 X_X_D : array_type_9;
507 pragma Convention (C, pthread_attr_t);
509 type array_type_8 is array (Integer range 0 .. 1) of long;
510 type pthread_condattr_t is record
511 X_X_D : array_type_8;
513 pragma Convention (C, pthread_condattr_t);
515 type array_type_7 is array (Integer range 0 .. 1) of long;
516 type pthread_mutexattr_t is record
517 X_X_D : array_type_7;
519 pragma Convention (C, pthread_mutexattr_t);
521 type pthread_t is new unsigned;
523 type array_type_10 is array (Integer range 0 .. 7) of long;
524 type pthread_mutex_t is record
525 X_X_D : array_type_10;
527 pragma Convention (C, pthread_mutex_t);
529 type array_type_11 is array (Integer range 0 .. 7) of long;
530 type pthread_cond_t is record
531 X_X_D : array_type_11;
533 pragma Convention (C, pthread_cond_t);
535 type pthread_key_t is new int;
537 end System.OS_Interface;