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-2010, Free Software Foundation, Inc. --
12 -- GNAT 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 3, or (at your option) any later ver- --
15 -- sion. GNAT 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. --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception, --
21 -- version 3.1, as published by the Free Software Foundation. --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
31 ------------------------------------------------------------------------------
33 -- This is the SGI Pthreads version of this package
35 -- This package encapsulates all direct interfaces to OS services that are
36 -- needed by the tasking run-time (libgnarl).
38 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
41 with Ada.Unchecked_Conversion;
45 package System.OS_Interface is
49 pragma Linker_Options ("-lpthread");
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;
65 function errno return int;
66 pragma Import (C, errno, "__get_errno");
68 EINTR : constant := 4; -- interrupted system call
69 EAGAIN : constant := 11; -- No more processes
70 ENOMEM : constant := 12; -- Not enough core
71 EINVAL : constant := 22; -- Invalid argument
72 ETIMEDOUT : constant := 145; -- Connection timed out
78 Max_Interrupt : constant := 64;
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 SIGK32 : constant := 32; -- reserved for kernel (IRIX)
117 SIGCKPT : constant := 33; -- Checkpoint warning
118 SIGRESTART : constant := 34; -- Restart warning
119 SIGUME : constant := 35; -- Uncorrectable memory error
120 -- Signals defined for Posix 1003.1c
121 SIGPTINTR : constant := 47;
122 SIGPTRESCHED : constant := 48;
123 -- Posix 1003.1b signals
124 SIGRTMIN : constant := 49; -- Posix 1003.1b signals
125 SIGRTMAX : constant := 64; -- Posix 1003.1b signals
127 type sigset_t is private;
129 function sigaddset (set : access sigset_t; sig : Signal) return int;
130 pragma Import (C, sigaddset, "sigaddset");
132 function sigdelset (set : access sigset_t; sig : Signal) return int;
133 pragma Import (C, sigdelset, "sigdelset");
135 function sigfillset (set : access sigset_t) return int;
136 pragma Import (C, sigfillset, "sigfillset");
138 function sigismember (set : access sigset_t; sig : Signal) return int;
139 pragma Import (C, sigismember, "sigismember");
141 function sigemptyset (set : access sigset_t) return int;
142 pragma Import (C, sigemptyset, "sigemptyset");
144 type array_type_2 is array (Integer range 0 .. 1) of int;
145 type struct_sigaction is record
147 sa_handler : System.Address;
149 sa_resv : array_type_2;
151 pragma Convention (C, struct_sigaction);
153 type struct_sigaction_ptr is access all struct_sigaction;
155 SIG_BLOCK : constant := 1;
156 SIG_UNBLOCK : constant := 2;
157 SIG_SETMASK : constant := 3;
159 SIG_DFL : constant := 0;
160 SIG_IGN : constant := 1;
164 act : struct_sigaction_ptr;
165 oact : struct_sigaction_ptr := null) return int;
166 pragma Import (C, sigaction, "sigaction");
172 type timespec is private;
173 type timespec_ptr is access all timespec;
175 type clockid_t is private;
177 CLOCK_REALTIME : constant clockid_t;
178 CLOCK_SGI_FAST : constant clockid_t;
179 CLOCK_SGI_CYCLE : constant clockid_t;
181 SGI_CYCLECNTR_SIZE : constant := 165;
183 function syssgi (request : Interfaces.C.int) return Interfaces.C.ptrdiff_t;
184 pragma Import (C, syssgi, "syssgi");
186 function clock_gettime
187 (clock_id : clockid_t;
188 tp : access timespec) return int;
189 pragma Import (C, clock_gettime, "clock_gettime");
191 function clock_getres
192 (clock_id : clockid_t;
193 tp : access timespec) return int;
194 pragma Import (C, clock_getres, "clock_getres");
196 function To_Duration (TS : timespec) return Duration;
197 pragma Inline (To_Duration);
199 function To_Timespec (D : Duration) return timespec;
200 pragma Inline (To_Timespec);
202 -------------------------
203 -- Priority Scheduling --
204 -------------------------
206 SCHED_FIFO : constant := 1;
207 SCHED_RR : constant := 2;
208 SCHED_TS : constant := 3;
209 SCHED_OTHER : constant := 3;
210 SCHED_NP : constant := 4;
212 function sched_get_priority_min (Policy : int) return int;
213 pragma Import (C, sched_get_priority_min, "sched_get_priority_min");
215 function sched_get_priority_max (Policy : int) return int;
216 pragma Import (C, sched_get_priority_max, "sched_get_priority_max");
222 type pid_t is private;
224 function kill (pid : pid_t; sig : Signal) return int;
225 pragma Import (C, kill, "kill");
227 function getpid return pid_t;
228 pragma Import (C, getpid, "getpid");
234 type Thread_Body is access
235 function (arg : System.Address) return System.Address;
236 pragma Convention (C, Thread_Body);
238 function Thread_Body_Access is new
239 Ada.Unchecked_Conversion (System.Address, Thread_Body);
241 type pthread_t is private;
242 subtype Thread_Id is pthread_t;
244 type pthread_mutex_t is limited private;
245 type pthread_cond_t is limited private;
246 type pthread_attr_t is limited private;
247 type pthread_mutexattr_t is limited private;
248 type pthread_condattr_t is limited private;
249 type pthread_key_t is private;
251 PTHREAD_CREATE_DETACHED : constant := 1;
257 Alternate_Stack_Size : constant := 0;
258 -- No alternate signal stack is used on this platform
260 ---------------------------------------
261 -- Nonstandard Thread Initialization --
262 ---------------------------------------
264 procedure pthread_init;
265 pragma Inline (pthread_init);
266 -- This is a dummy procedure to share some GNULLI files
268 -------------------------
269 -- POSIX.1c Section 3 --
270 -------------------------
273 (set : access sigset_t;
274 sig : access Signal) return int;
275 pragma Import (C, sigwait, "sigwait");
277 function pthread_kill
279 sig : Signal) return int;
280 pragma Import (C, pthread_kill, "pthread_kill");
282 function pthread_sigmask
284 set : access sigset_t;
285 oset : access sigset_t) return int;
286 pragma Import (C, pthread_sigmask, "pthread_sigmask");
288 --------------------------
289 -- POSIX.1c Section 11 --
290 --------------------------
292 function pthread_mutexattr_init
293 (attr : access pthread_mutexattr_t) return int;
294 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
296 function pthread_mutexattr_destroy
297 (attr : access pthread_mutexattr_t) return int;
298 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
300 function pthread_mutex_init
301 (mutex : access pthread_mutex_t;
302 attr : access pthread_mutexattr_t) return int;
303 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
305 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
306 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
308 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
309 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
311 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
312 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
314 function pthread_condattr_init
315 (attr : access pthread_condattr_t) return int;
316 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
318 function pthread_condattr_destroy
319 (attr : access pthread_condattr_t) return int;
320 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
322 function pthread_cond_init
323 (cond : access pthread_cond_t;
324 attr : access pthread_condattr_t) return int;
325 pragma Import (C, pthread_cond_init, "pthread_cond_init");
327 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
328 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
330 function pthread_cond_signal (cond : access pthread_cond_t) return int;
331 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
333 function pthread_cond_wait
334 (cond : access pthread_cond_t;
335 mutex : access pthread_mutex_t) return int;
336 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
338 function pthread_cond_timedwait
339 (cond : access pthread_cond_t;
340 mutex : access pthread_mutex_t;
341 abstime : access timespec) return int;
342 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
344 --------------------------
345 -- POSIX.1c Section 13 --
346 --------------------------
348 PTHREAD_PRIO_NONE : constant := 0;
349 PTHREAD_PRIO_PROTECT : constant := 2;
350 PTHREAD_PRIO_INHERIT : constant := 1;
352 function pthread_mutexattr_setprotocol
353 (attr : access pthread_mutexattr_t;
354 protocol : int) return int;
355 pragma Import (C, pthread_mutexattr_setprotocol);
357 function pthread_mutexattr_setprioceiling
358 (attr : access pthread_mutexattr_t;
359 prioceiling : int) return int;
360 pragma Import (C, pthread_mutexattr_setprioceiling);
362 type struct_sched_param is record
363 sched_priority : int;
365 pragma Convention (C, struct_sched_param);
367 function pthread_setschedparam
370 param : access struct_sched_param)
372 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
374 function pthread_attr_setscope
375 (attr : access pthread_attr_t;
376 contentionscope : int) return int;
377 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
379 function pthread_attr_setinheritsched
380 (attr : access pthread_attr_t;
381 inheritsched : int) return int;
383 (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
385 function pthread_attr_setschedpolicy
386 (attr : access pthread_attr_t;
387 policy : int) return int;
388 pragma Import (C, pthread_attr_setschedpolicy);
390 function pthread_attr_setschedparam
391 (attr : access pthread_attr_t;
392 sched_param : access struct_sched_param)
394 pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam");
396 function sched_yield return int;
397 pragma Import (C, sched_yield, "sched_yield");
399 ---------------------------
400 -- P1003.1c - Section 16 --
401 ---------------------------
403 function pthread_attr_init (attributes : access pthread_attr_t) return int;
404 pragma Import (C, pthread_attr_init, "pthread_attr_init");
406 function pthread_attr_destroy
407 (attributes : access pthread_attr_t) return int;
408 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
410 function pthread_attr_setdetachstate
411 (attr : access pthread_attr_t;
412 detachstate : int) return int;
413 pragma Import (C, pthread_attr_setdetachstate);
415 function pthread_attr_setstacksize
416 (attr : access pthread_attr_t;
417 stacksize : size_t) return int;
418 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
420 function pthread_create
421 (thread : access pthread_t;
422 attributes : access pthread_attr_t;
423 start_routine : Thread_Body;
424 arg : System.Address) return int;
425 pragma Import (C, pthread_create, "pthread_create");
427 procedure pthread_exit (status : System.Address);
428 pragma Import (C, pthread_exit, "pthread_exit");
430 function pthread_self return pthread_t;
431 pragma Import (C, pthread_self, "pthread_self");
433 --------------------------
434 -- POSIX.1c Section 17 --
435 --------------------------
437 function pthread_setspecific
438 (key : pthread_key_t;
439 value : System.Address) return int;
440 pragma Import (C, pthread_setspecific, "pthread_setspecific");
442 function pthread_getspecific (key : pthread_key_t) return System.Address;
443 pragma Import (C, pthread_getspecific, "pthread_getspecific");
445 type destructor_pointer is access procedure (arg : System.Address);
446 pragma Convention (C, destructor_pointer);
448 function pthread_key_create
449 (key : access pthread_key_t;
450 destructor : destructor_pointer) return int;
451 pragma Import (C, pthread_key_create, "pthread_key_create");
457 -- Non portable SGI 6.5 additions to the pthread interface must be
458 -- executed from within the context of a system scope task.
460 function pthread_setrunon_np (cpu : int) return int;
461 pragma Import (C, pthread_setrunon_np, "pthread_setrunon_np");
465 type array_type_1 is array (Integer range 0 .. 3) of unsigned;
466 type sigset_t is record
467 X_X_sigbits : array_type_1;
469 pragma Convention (C, sigset_t);
471 type pid_t is new long;
473 type time_t is new long;
475 type timespec is record
479 pragma Convention (C, timespec);
481 type clockid_t is new int;
482 CLOCK_REALTIME : constant clockid_t := 1;
483 CLOCK_SGI_CYCLE : constant clockid_t := 2;
484 CLOCK_SGI_FAST : constant clockid_t := 3;
486 type array_type_9 is array (Integer range 0 .. 4) of long;
487 type pthread_attr_t is record
488 X_X_D : array_type_9;
490 pragma Convention (C, pthread_attr_t);
492 type array_type_8 is array (Integer range 0 .. 1) of long;
493 type pthread_condattr_t is record
494 X_X_D : array_type_8;
496 pragma Convention (C, pthread_condattr_t);
498 type array_type_7 is array (Integer range 0 .. 1) of long;
499 type pthread_mutexattr_t is record
500 X_X_D : array_type_7;
502 pragma Convention (C, pthread_mutexattr_t);
504 type pthread_t is new unsigned;
506 type array_type_10 is array (Integer range 0 .. 7) of long;
507 type pthread_mutex_t is record
508 X_X_D : array_type_10;
510 pragma Convention (C, pthread_mutex_t);
512 type array_type_11 is array (Integer range 0 .. 7) of long;
513 type pthread_cond_t is record
514 X_X_D : array_type_11;
516 pragma Convention (C, pthread_cond_t);
518 type pthread_key_t is new int;
520 end System.OS_Interface;