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 --
9 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2004, 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 DEC Unix 4.0/5.1 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 or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
44 with Unchecked_Conversion
;
46 package System
.OS_Interface
is
49 pragma Linker_Options
("-lpthread");
50 pragma Linker_Options
("-lmach");
51 pragma Linker_Options
("-lexc");
52 pragma Linker_Options
("-lrt");
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
;
63 subtype char_array
is Interfaces
.C
.char_array
;
69 function errno
return int
;
70 pragma Import
(C
, errno
, "_Geterrno");
72 EAGAIN
: constant := 35;
73 EINTR
: constant := 4;
74 EINVAL
: constant := 22;
75 ENOMEM
: constant := 12;
76 ETIMEDOUT
: constant := 60;
82 Max_Interrupt
: constant := 48;
83 type Signal
is new int
range 0 .. Max_Interrupt
;
84 for Signal
'Size use int
'Size;
86 SIGHUP
: constant := 1; -- hangup
87 SIGINT
: constant := 2; -- interrupt (rubout)
88 SIGQUIT
: constant := 3; -- quit (ASCD FS)
89 SIGILL
: constant := 4; -- illegal instruction (not reset)
90 SIGTRAP
: constant := 5; -- trace trap (not reset)
91 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
92 SIGIOT
: constant := 6; -- abort (terminate) process
93 SIGLOST
: constant := 6; -- old BSD signal ??
94 SIGEMT
: constant := 7; -- EMT instruction
95 SIGFPE
: constant := 8; -- floating point exception
96 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
97 SIGBUS
: constant := 10; -- bus error
98 SIGSEGV
: constant := 11; -- segmentation violation
99 SIGSYS
: constant := 12; -- bad argument to system call
100 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
101 SIGALRM
: constant := 14; -- alarm clock
102 SIGTERM
: constant := 15; -- software termination signal from kill
103 SIGURG
: constant := 16; -- urgent condition on IO channel
104 SIGIOINT
: constant := 16; -- printer to backend error signal
105 SIGSTOP
: constant := 17; -- stop (cannot be caught or ignored)
106 SIGTSTP
: constant := 18; -- user stop requested from tty
107 SIGCONT
: constant := 19; -- stopped process has been continued
108 SIGCHLD
: constant := 20; -- child status change
109 SIGTTIN
: constant := 21; -- background tty read attempted
110 SIGTTOU
: constant := 22; -- background tty write attempted
111 SIGPOLL
: constant := 23; -- I/O possible, or completed
112 SIGIO
: constant := 23; -- STREAMS version of SIGPOLL
113 SIGAIO
: constant := 23; -- base lan i/o
114 SIGPTY
: constant := 23; -- pty i/o
115 SIGXCPU
: constant := 24; -- CPU time limit exceeded
116 SIGXFSZ
: constant := 25; -- filesize limit exceeded
117 SIGVTALRM
: constant := 26; -- virtual timer expired
118 SIGPROF
: constant := 27; -- profiling timer expired
119 SIGWINCH
: constant := 28; -- window size change
120 SIGINFO
: constant := 29; -- information request
121 SIGPWR
: constant := 29; -- Power Fail/Restart -- SVID3/SVR4
122 SIGUSR1
: constant := 30; -- user defined signal 1
123 SIGUSR2
: constant := 31; -- user defined signal 2
124 SIGRESV
: constant := 32; -- reserved by Digital for future use
126 SIGADAABORT
: constant := SIGABRT
;
128 type Signal_Set
is array (Natural range <>) of Signal
;
130 Unmasked
: constant Signal_Set
:= (0 .. 0 => SIGTRAP
);
131 Reserved
: constant Signal_Set
:= (SIGALRM
, SIGABRT
, SIGKILL
, SIGSTOP
);
133 type sigset_t
is private;
135 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
136 pragma Import
(C
, sigaddset
);
138 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
139 pragma Import
(C
, sigdelset
);
141 function sigfillset
(set
: access sigset_t
) return int
;
142 pragma Import
(C
, sigfillset
);
144 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
145 pragma Import
(C
, sigismember
);
147 function sigemptyset
(set
: access sigset_t
) return int
;
148 pragma Import
(C
, sigemptyset
);
150 type union_type_3
is new String (1 .. 116);
151 type siginfo_t
is record
155 X_data
: union_type_3
;
157 for siginfo_t
'Size use 8 * 128;
158 pragma Convention
(C
, siginfo_t
);
160 type struct_sigaction
is record
161 sa_handler
: System
.Address
;
166 pragma Convention
(C
, struct_sigaction
);
167 type struct_sigaction_ptr
is access all struct_sigaction
;
169 SIG_BLOCK
: constant := 1;
170 SIG_UNBLOCK
: constant := 2;
171 SIG_SETMASK
: constant := 3;
173 SIG_DFL
: constant := 0;
174 SIG_IGN
: constant := 1;
176 SA_NODEFER
: constant := 8;
177 SA_SIGINFO
: constant := 16#
40#
;
181 act
: struct_sigaction_ptr
;
182 oact
: struct_sigaction_ptr
) return int
;
183 pragma Import
(C
, sigaction
);
189 type timespec
is private;
191 function nanosleep
(rqtp
, rmtp
: access timespec
) return int
;
192 pragma Import
(C
, nanosleep
);
194 type clockid_t
is private;
196 CLOCK_REALTIME
: constant clockid_t
;
198 function clock_gettime
199 (clock_id
: clockid_t
;
200 tp
: access timespec
) return int
;
201 pragma Import
(C
, clock_gettime
);
203 function To_Duration
(TS
: timespec
) return Duration;
204 pragma Inline
(To_Duration
);
206 function To_Timespec
(D
: Duration) return timespec
;
207 pragma Inline
(To_Timespec
);
209 type struct_timezone
is record
210 tz_minuteswest
: int
;
213 pragma Convention
(C
, 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 := 3;
231 SCHED_LFI
: constant := 5;
237 type pid_t
is private;
239 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
240 pragma Import
(C
, kill
);
242 function getpid
return pid_t
;
243 pragma Import
(C
, getpid
);
245 BIND_NO_INHERIT
: constant := 1;
249 cpu_mask
: unsigned_long
;
250 flag
: unsigned_long
:= BIND_NO_INHERIT
) return int
;
251 pragma Import
(C
, bind_to_cpu
);
257 type Thread_Body
is access
258 function (arg
: System
.Address
) return System
.Address
;
260 function Thread_Body_Access
is new
261 Unchecked_Conversion
(System
.Address
, Thread_Body
);
263 type pthread_t
is private;
264 subtype Thread_Id
is pthread_t
;
266 type pthread_mutex_t
is limited private;
267 type pthread_cond_t
is limited private;
268 type pthread_attr_t
is limited private;
269 type pthread_mutexattr_t
is limited private;
270 type pthread_condattr_t
is limited private;
271 type pthread_key_t
is private;
273 PTHREAD_CREATE_DETACHED
: constant := 1;
275 PTHREAD_SCOPE_PROCESS
: constant := 0;
276 PTHREAD_SCOPE_SYSTEM
: constant := 1;
278 PTHREAD_EXPLICIT_SCHED
: constant := 1;
280 ---------------------------------------
281 -- Nonstandard Thread Initialization --
282 ---------------------------------------
284 procedure pthread_init
;
285 pragma Inline
(pthread_init
);
286 -- This is a dummy procedure to share some GNULLI files
288 -------------------------
289 -- POSIX.1c Section 3 --
290 -------------------------
293 (set
: access sigset_t
;
294 sig
: access Signal
) return int
;
295 pragma Import
(C
, sigwait
, "__sigwaitd10");
297 function pthread_kill
299 sig
: Signal
) return int
;
300 pragma Import
(C
, pthread_kill
);
302 type sigset_t_ptr
is access all sigset_t
;
304 function pthread_sigmask
307 oset
: sigset_t_ptr
) return int
;
308 pragma Import
(C
, pthread_sigmask
);
310 --------------------------
311 -- POSIX.1c Section 11 --
312 --------------------------
314 function pthread_mutexattr_init
(attr
: access pthread_mutexattr_t
)
316 pragma Import
(C
, pthread_mutexattr_init
);
318 function pthread_mutexattr_destroy
319 (attr
: access pthread_mutexattr_t
) return int
;
320 pragma Import
(C
, pthread_mutexattr_destroy
);
322 function pthread_mutex_init
323 (mutex
: access pthread_mutex_t
;
324 attr
: access pthread_mutexattr_t
) return int
;
325 pragma Import
(C
, pthread_mutex_init
, "__pthread_mutex_init");
327 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
328 pragma Import
(C
, pthread_mutex_destroy
, "__pthread_mutex_destroy");
330 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
331 pragma Import
(C
, pthread_mutex_lock
, "__pthread_mutex_lock");
333 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
334 pragma Import
(C
, pthread_mutex_unlock
, "__pthread_mutex_unlock");
336 function pthread_condattr_init
337 (attr
: access pthread_condattr_t
) return int
;
338 pragma Import
(C
, pthread_condattr_init
);
340 function pthread_condattr_destroy
341 (attr
: access pthread_condattr_t
) return int
;
342 pragma Import
(C
, pthread_condattr_destroy
);
344 function pthread_cond_init
345 (cond
: access pthread_cond_t
;
346 attr
: access pthread_condattr_t
) return int
;
347 pragma Import
(C
, pthread_cond_init
, "__pthread_cond_init");
349 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
350 pragma Import
(C
, pthread_cond_destroy
, "__pthread_cond_destroy");
352 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
353 pragma Import
(C
, pthread_cond_signal
, "__pthread_cond_signal");
355 function pthread_cond_wait
356 (cond
: access pthread_cond_t
;
357 mutex
: access pthread_mutex_t
) return int
;
358 pragma Import
(C
, pthread_cond_wait
, "__pthread_cond_wait");
360 function pthread_cond_timedwait
361 (cond
: access pthread_cond_t
;
362 mutex
: access pthread_mutex_t
;
363 abstime
: access timespec
) return int
;
364 pragma Import
(C
, pthread_cond_timedwait
, "__pthread_cond_timedwait");
366 --------------------------
367 -- POSIX.1c Section 13 --
368 --------------------------
370 function pthread_mutexattr_setprotocol
371 (attr
: access pthread_mutexattr_t
;
372 protocol
: int
) return int
;
373 pragma Import
(C
, pthread_mutexattr_setprotocol
);
375 function pthread_mutexattr_setprioceiling
376 (attr
: access pthread_mutexattr_t
;
377 prioceiling
: int
) return int
;
378 pragma Import
(C
, pthread_mutexattr_setprioceiling
);
380 type struct_sched_param
is record
381 sched_priority
: int
; -- scheduling priority
384 function pthread_setschedparam
387 param
: access struct_sched_param
) return int
;
388 pragma Import
(C
, pthread_setschedparam
);
390 function pthread_attr_setscope
391 (attr
: access pthread_attr_t
;
392 contentionscope
: int
) return int
;
393 pragma Import
(C
, pthread_attr_setscope
);
395 function pthread_attr_setinheritsched
396 (attr
: access pthread_attr_t
;
397 inheritsched
: int
) return int
;
398 pragma Import
(C
, pthread_attr_setinheritsched
,
399 "__pthread_attr_setinheritsched");
401 function pthread_attr_setschedpolicy
402 (attr
: access pthread_attr_t
; policy
: int
) return int
;
403 pragma Import
(C
, pthread_attr_setschedpolicy
);
405 function pthread_attr_setschedparam
406 (attr
: access pthread_attr_t
;
407 sched_param
: access struct_sched_param
) return int
;
408 pragma Import
(C
, pthread_attr_setschedparam
);
410 function sched_yield
return int
;
411 pragma Import
(C
, sched_yield
);
413 --------------------------
414 -- P1003.1c Section 16 --
415 --------------------------
417 function pthread_attr_init
(attributes
: access pthread_attr_t
)
419 pragma Import
(C
, pthread_attr_init
);
421 function pthread_attr_destroy
(attributes
: access pthread_attr_t
)
423 pragma Import
(C
, pthread_attr_destroy
);
425 function pthread_attr_setdetachstate
426 (attr
: access pthread_attr_t
;
427 detachstate
: int
) return int
;
428 pragma Import
(C
, pthread_attr_setdetachstate
);
430 function pthread_attr_setstacksize
431 (attr
: access pthread_attr_t
;
432 stacksize
: size_t
) return int
;
433 pragma Import
(C
, pthread_attr_setstacksize
, "__pthread_attr_setstacksize");
435 function pthread_create
436 (thread
: access pthread_t
;
437 attributes
: access pthread_attr_t
;
438 start_routine
: Thread_Body
;
439 arg
: System
.Address
) return int
;
440 pragma Import
(C
, pthread_create
, "__pthread_create");
442 procedure pthread_exit
(status
: System
.Address
);
443 pragma Import
(C
, pthread_exit
, "__pthread_exit");
445 function pthread_self
return pthread_t
;
446 pragma Inline
(pthread_self
);
448 --------------------------
449 -- POSIX.1c Section 17 --
450 --------------------------
452 function pthread_setspecific
453 (key
: pthread_key_t
; value
: System
.Address
) return int
;
454 pragma Import
(C
, pthread_setspecific
, "__pthread_setspecific");
456 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
457 pragma Import
(C
, pthread_getspecific
, "__pthread_getspecific");
459 type destructor_pointer
is access procedure (arg
: System
.Address
);
461 function pthread_key_create
462 (key
: access pthread_key_t
;
463 destructor
: destructor_pointer
) return int
;
464 pragma Import
(C
, pthread_key_create
);
468 type sigset_t
is new unsigned_long
;
470 type pid_t
is new int
;
472 type time_t
is new int
;
474 type timespec
is record
478 pragma Convention
(C
, timespec
);
480 type clockid_t
is new int
;
481 CLOCK_REALTIME
: constant clockid_t
:= 1;
483 type struct_timeval
is record
487 pragma Convention
(C
, struct_timeval
);
489 type unsigned_long_array
is array (Natural range <>) of unsigned_long
;
491 type pthread_t
is new System
.Address
;
493 type pthread_cond_t
is record
496 name
: System
.Address
;
498 reserved1
: unsigned
;
499 sequence
: unsigned_long
;
500 block
: System
.Address
;
502 pragma Convention
(C
, pthread_cond_t
);
504 type pthread_attr_t
is record
506 name
: System
.Address
;
508 reserved
: unsigned_long_array
(0 .. 18);
510 pragma Convention
(C
, pthread_attr_t
);
512 type pthread_mutex_t
is record
515 name
: System
.Address
;
518 sequence
: unsigned_long
;
519 owner
: unsigned_long
;
520 block
: System
.Address
;
522 for pthread_mutex_t
'Size use 8 * 48;
523 pragma Convention
(C
, pthread_mutex_t
);
525 type pthread_mutexattr_t
is record
527 reserved
: unsigned_long_array
(0 .. 14);
529 pragma Convention
(C
, pthread_mutexattr_t
);
531 type pthread_condattr_t
is record
533 reserved
: unsigned_long_array
(0 .. 12);
535 pragma Convention
(C
, pthread_condattr_t
);
537 type pthread_key_t
is new unsigned
;
539 end System
.OS_Interface
;