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 --
10 -- Copyright (C) 1998-2001, 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, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, 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
38 -- that are needed by children of System.
40 -- PLEASE DO NOT add any with-clauses to this package
41 -- or remove the pragma Elaborate_Body.
42 -- It is designed to be a bottom-level (leaf) package.
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
90 SIGEMT
: constant := 7; -- EMT instruction
91 SIGFPE
: constant := 8; -- floating point exception
92 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
93 SIGBUS
: constant := 10; -- bus error
94 SIGSEGV
: constant := 11; -- segmentation violation
95 SIGSYS
: constant := 12; -- bad argument to system call
96 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
97 SIGALRM
: constant := 14; -- alarm clock
98 SIGTERM
: constant := 15; -- software termination signal from kill
99 SIGUSR1
: constant := 16; -- user defined signal 1
100 SIGUSR2
: constant := 17; -- user defined signal 2
101 SIGCLD
: constant := 18; -- alias for SIGCHLD
102 SIGCHLD
: constant := 18; -- child status change
103 SIGPWR
: constant := 19; -- power-fail restart
104 SIGWINCH
: constant := 20; -- window size change
105 SIGURG
: constant := 21; -- urgent condition on IO channel
106 SIGPOLL
: constant := 22; -- pollable event occurred
107 SIGIO
: constant := 22; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP
: constant := 23; -- stop (cannot be caught or ignored)
109 SIGTSTP
: constant := 24; -- user stop requested from tty
110 SIGCONT
: constant := 25; -- stopped process has been continued
111 SIGTTIN
: constant := 26; -- background tty read attempted
112 SIGTTOU
: constant := 27; -- background tty write attempted
113 SIGVTALRM
: constant := 28; -- virtual timer expired
114 SIGPROF
: constant := 29; -- profiling timer expired
115 SIGXCPU
: constant := 30; -- CPU time limit exceeded
116 SIGXFSZ
: constant := 31; -- filesize limit exceeded
117 SIGK32
: constant := 32; -- reserved for kernel (IRIX)
118 SIGCKPT
: constant := 33; -- Checkpoint warning
119 SIGRESTART
: constant := 34; -- Restart warning
120 SIGUME
: constant := 35; -- Uncorrectable memory error
121 -- Signals defined for Posix 1003.1c.
122 SIGPTINTR
: constant := 47;
123 SIGPTRESCHED
: constant := 48;
124 -- Posix 1003.1b signals
125 SIGRTMIN
: constant := 49; -- Posix 1003.1b signals
126 SIGRTMAX
: constant := 64; -- Posix 1003.1b signals
128 type sigset_t
is private;
129 type sigset_t_ptr
is access all sigset_t
;
131 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
132 pragma Import
(C
, sigaddset
, "sigaddset");
134 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
135 pragma Import
(C
, sigdelset
, "sigdelset");
137 function sigfillset
(set
: access sigset_t
) return int
;
138 pragma Import
(C
, sigfillset
, "sigfillset");
140 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
141 pragma Import
(C
, sigismember
, "sigismember");
143 function sigemptyset
(set
: access sigset_t
) return int
;
144 pragma Import
(C
, sigemptyset
, "sigemptyset");
146 type array_type_2
is array (Integer range 0 .. 1) of int
;
147 type struct_sigaction
is record
149 sa_handler
: System
.Address
;
151 sa_resv
: array_type_2
;
153 pragma Convention
(C
, struct_sigaction
);
155 type struct_sigaction_ptr
is access all struct_sigaction
;
157 SIG_BLOCK
: constant := 1;
158 SIG_UNBLOCK
: constant := 2;
159 SIG_SETMASK
: constant := 3;
161 SIG_DFL
: constant := 0;
162 SIG_IGN
: constant := 1;
166 act
: struct_sigaction_ptr
;
167 oact
: struct_sigaction_ptr
:= null) return int
;
168 pragma Import
(C
, sigaction
, "sigaction");
174 type timespec
is private;
175 type timespec_ptr
is access all timespec
;
177 type clockid_t
is private;
179 CLOCK_REALTIME
: constant clockid_t
;
180 CLOCK_SGI_FAST
: constant clockid_t
;
181 CLOCK_SGI_CYCLE
: constant clockid_t
;
183 SGI_CYCLECNTR_SIZE
: constant := 165;
185 function syssgi
(request
: Interfaces
.C
.int
) return Interfaces
.C
.ptrdiff_t
;
186 pragma Import
(C
, syssgi
, "syssgi");
188 function clock_gettime
189 (clock_id
: clockid_t
;
190 tp
: access timespec
) return int
;
191 pragma Import
(C
, clock_gettime
, "clock_gettime");
193 function clock_getres
194 (clock_id
: clockid_t
;
195 tp
: access timespec
) return int
;
196 pragma Import
(C
, clock_getres
, "clock_getres");
198 function To_Duration
(TS
: timespec
) return Duration;
199 pragma Inline
(To_Duration
);
201 function To_Timespec
(D
: Duration) return timespec
;
202 pragma Inline
(To_Timespec
);
204 type struct_timeval
is private;
206 function To_Duration
(TV
: struct_timeval
) return Duration;
207 pragma Inline
(To_Duration
);
209 function To_Timeval
(D
: Duration) return struct_timeval
;
210 pragma Inline
(To_Timeval
);
212 -------------------------
213 -- Priority Scheduling --
214 -------------------------
216 SCHED_FIFO
: constant := 1;
217 SCHED_RR
: constant := 2;
218 SCHED_TS
: constant := 3;
219 SCHED_OTHER
: constant := 3;
220 SCHED_NP
: constant := 4;
222 function sched_get_priority_min
(Policy
: int
) return int
;
223 pragma Import
(C
, sched_get_priority_min
, "sched_get_priority_min");
225 function sched_get_priority_max
(Policy
: int
) return int
;
226 pragma Import
(C
, sched_get_priority_max
, "sched_get_priority_max");
232 type pid_t
is private;
234 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
235 pragma Import
(C
, kill
, "kill");
237 function getpid
return pid_t
;
238 pragma Import
(C
, getpid
, "getpid");
244 type Thread_Body
is access
245 function (arg
: System
.Address
) return System
.Address
;
246 type pthread_t
is private;
247 subtype Thread_Id
is pthread_t
;
249 type pthread_mutex_t
is limited private;
250 type pthread_cond_t
is limited private;
251 type pthread_attr_t
is limited private;
252 type pthread_mutexattr_t
is limited private;
253 type pthread_condattr_t
is limited private;
254 type pthread_key_t
is private;
256 PTHREAD_CREATE_DETACHED
: constant := 1;
258 ---------------------------------------
259 -- Nonstandard Thread Initialization --
260 ---------------------------------------
262 procedure pthread_init
;
263 pragma Inline
(pthread_init
);
264 -- This is a dummy procedure to share some GNULLI files
266 -------------------------
267 -- POSIX.1c Section 3 --
268 -------------------------
271 (set
: access sigset_t
;
272 sig
: access Signal
) return int
;
273 pragma Import
(C
, sigwait
, "sigwait");
275 function pthread_kill
277 sig
: Signal
) return int
;
278 pragma Import
(C
, pthread_kill
, "pthread_kill");
280 function pthread_sigmask
283 oset
: sigset_t_ptr
) return int
;
284 pragma Import
(C
, pthread_sigmask
, "pthread_sigmask");
286 --------------------------
287 -- POSIX.1c Section 11 --
288 --------------------------
290 function pthread_mutexattr_init
291 (attr
: access pthread_mutexattr_t
) return int
;
292 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
294 function pthread_mutexattr_destroy
295 (attr
: access pthread_mutexattr_t
) return int
;
296 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
298 function pthread_mutex_init
299 (mutex
: access pthread_mutex_t
;
300 attr
: access pthread_mutexattr_t
) return int
;
301 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
303 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
304 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
306 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
307 pragma Import
(C
, pthread_mutex_lock
, "pthread_mutex_lock");
309 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
310 pragma Import
(C
, pthread_mutex_unlock
, "pthread_mutex_unlock");
312 function pthread_condattr_init
313 (attr
: access pthread_condattr_t
) return int
;
314 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
316 function pthread_condattr_destroy
317 (attr
: access pthread_condattr_t
) return int
;
318 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
320 function pthread_cond_init
321 (cond
: access pthread_cond_t
;
322 attr
: access pthread_condattr_t
) return int
;
323 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
325 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
326 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
328 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
329 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
331 function pthread_cond_wait
332 (cond
: access pthread_cond_t
;
333 mutex
: access pthread_mutex_t
) return int
;
334 pragma Import
(C
, pthread_cond_wait
, "pthread_cond_wait");
336 function pthread_cond_timedwait
337 (cond
: access pthread_cond_t
;
338 mutex
: access pthread_mutex_t
;
339 abstime
: access timespec
) return int
;
340 pragma Import
(C
, pthread_cond_timedwait
, "pthread_cond_timedwait");
342 --------------------------
343 -- POSIX.1c Section 13 --
344 --------------------------
346 PTHREAD_PRIO_NONE
: constant := 0;
347 PTHREAD_PRIO_PROTECT
: constant := 2;
348 PTHREAD_PRIO_INHERIT
: constant := 1;
350 function pthread_mutexattr_setprotocol
351 (attr
: access pthread_mutexattr_t
;
352 protocol
: int
) return int
;
353 pragma Import
(C
, pthread_mutexattr_setprotocol
);
355 function pthread_mutexattr_setprioceiling
356 (attr
: access pthread_mutexattr_t
;
357 prioceiling
: int
) return int
;
358 pragma Import
(C
, pthread_mutexattr_setprioceiling
);
360 type struct_sched_param
is record
361 sched_priority
: int
;
363 pragma Convention
(C
, struct_sched_param
);
365 function pthread_setschedparam
368 param
: access struct_sched_param
)
370 pragma Import
(C
, pthread_setschedparam
, "pthread_setschedparam");
372 function pthread_attr_setscope
373 (attr
: access pthread_attr_t
;
374 contentionscope
: int
) return int
;
375 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
377 function pthread_attr_setinheritsched
378 (attr
: access pthread_attr_t
;
379 inheritsched
: int
) return int
;
381 (C
, pthread_attr_setinheritsched
, "pthread_attr_setinheritsched");
383 function pthread_attr_setschedpolicy
384 (attr
: access pthread_attr_t
;
385 policy
: int
) return int
;
386 pragma Import
(C
, pthread_attr_setschedpolicy
);
388 function pthread_attr_setschedparam
389 (attr
: access pthread_attr_t
;
390 sched_param
: access struct_sched_param
)
392 pragma Import
(C
, pthread_attr_setschedparam
, "pthread_attr_setschedparam");
394 function sched_yield
return int
;
395 pragma Import
(C
, sched_yield
, "sched_yield");
397 ---------------------------
398 -- P1003.1c - Section 16 --
399 ---------------------------
401 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
402 pragma Import
(C
, pthread_attr_init
, "pthread_attr_init");
404 function pthread_attr_destroy
405 (attributes
: access pthread_attr_t
) return int
;
406 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
408 function pthread_attr_setdetachstate
409 (attr
: access pthread_attr_t
;
410 detachstate
: int
) return int
;
411 pragma Import
(C
, pthread_attr_setdetachstate
);
413 function pthread_attr_setstacksize
414 (attr
: access pthread_attr_t
;
415 stacksize
: size_t
) return int
;
416 pragma Import
(C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
418 function pthread_create
419 (thread
: access pthread_t
;
420 attributes
: access pthread_attr_t
;
421 start_routine
: Thread_Body
;
422 arg
: System
.Address
) return int
;
423 pragma Import
(C
, pthread_create
, "pthread_create");
425 procedure pthread_exit
(status
: System
.Address
);
426 pragma Import
(C
, pthread_exit
, "pthread_exit");
428 function pthread_self
return pthread_t
;
429 pragma Import
(C
, pthread_self
, "pthread_self");
431 --------------------------
432 -- POSIX.1c Section 17 --
433 --------------------------
435 function pthread_setspecific
436 (key
: pthread_key_t
;
437 value
: System
.Address
) return int
;
438 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
440 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
441 pragma Import
(C
, pthread_getspecific
, "pthread_getspecific");
443 type destructor_pointer
is access procedure (arg
: System
.Address
);
445 function pthread_key_create
446 (key
: access pthread_key_t
;
447 destructor
: destructor_pointer
) return int
;
448 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
450 ---------------------------------------------------------------
451 -- Non portable SGI 6.5 additions to the pthread interface --
452 -- must be executed from within the context of a system --
454 ---------------------------------------------------------------
456 function pthread_setrunon_np
(cpu
: int
) return int
;
457 pragma Import
(C
, pthread_setrunon_np
, "pthread_setrunon_np");
461 type array_type_1
is array (Integer range 0 .. 3) of unsigned
;
462 type sigset_t
is record
463 X_X_sigbits
: array_type_1
;
465 pragma Convention
(C
, sigset_t
);
467 type pid_t
is new long
;
469 type time_t
is new long
;
471 type timespec
is record
475 pragma Convention
(C
, timespec
);
477 type clockid_t
is new int
;
478 CLOCK_REALTIME
: constant clockid_t
:= 1;
479 CLOCK_SGI_CYCLE
: constant clockid_t
:= 2;
480 CLOCK_SGI_FAST
: constant clockid_t
:= 3;
482 type struct_timeval
is record
486 pragma Convention
(C
, struct_timeval
);
488 type array_type_9
is array (Integer range 0 .. 4) of long
;
489 type pthread_attr_t
is record
490 X_X_D
: array_type_9
;
492 pragma Convention
(C
, pthread_attr_t
);
494 type array_type_8
is array (Integer range 0 .. 1) of long
;
495 type pthread_condattr_t
is record
496 X_X_D
: array_type_8
;
498 pragma Convention
(C
, pthread_condattr_t
);
500 type array_type_7
is array (Integer range 0 .. 1) of long
;
501 type pthread_mutexattr_t
is record
502 X_X_D
: array_type_7
;
504 pragma Convention
(C
, pthread_mutexattr_t
);
506 type pthread_t
is new unsigned
;
508 type array_type_10
is array (Integer range 0 .. 7) of long
;
509 type pthread_mutex_t
is record
510 X_X_D
: array_type_10
;
512 pragma Convention
(C
, pthread_mutex_t
);
514 type array_type_11
is array (Integer range 0 .. 7) of long
;
515 type pthread_cond_t
is record
516 X_X_D
: array_type_11
;
518 pragma Convention
(C
, pthread_cond_t
);
520 type pthread_key_t
is new int
;
522 end System
.OS_Interface
;