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) 1998-2002 Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This is the DEC Unix 4.0/5.1 version of this package.
36 -- This package encapsulates all direct interfaces to OS services
37 -- that are needed by children of System.
39 -- PLEASE DO NOT add any with-clauses to this package
40 -- It is designed to be a bottom-level (leaf) package.
43 package System
.OS_Interface
is
46 pragma Linker_Options
("-lpthread");
47 pragma Linker_Options
("-lmach");
48 pragma Linker_Options
("-lexc");
49 pragma Linker_Options
("-lrt");
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
;
60 subtype char_array
is Interfaces
.C
.char_array
;
66 function errno
return int
;
67 pragma Import
(C
, errno
, "_Geterrno");
69 EAGAIN
: constant := 35;
70 EINTR
: constant := 4;
71 EINVAL
: constant := 22;
72 ENOMEM
: constant := 12;
73 ETIMEDOUT
: constant := 60;
79 Max_Interrupt
: constant := 48;
80 type Signal
is new int
range 0 .. Max_Interrupt
;
81 for Signal
'Size use int
'Size;
83 SIGHUP
: constant := 1; -- hangup
84 SIGINT
: constant := 2; -- interrupt (rubout)
85 SIGQUIT
: constant := 3; -- quit (ASCD FS)
86 SIGILL
: constant := 4; -- illegal instruction (not reset)
87 SIGTRAP
: constant := 5; -- trace trap (not reset)
88 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
89 SIGIOT
: constant := 6; -- abort (terminate) process
90 SIGLOST
: constant := 6; -- old BSD signal ??
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 SIGURG
: constant := 16; -- urgent condition on IO channel
101 SIGIOINT
: constant := 16; -- printer to backend error signal
102 SIGSTOP
: constant := 17; -- stop (cannot be caught or ignored)
103 SIGTSTP
: constant := 18; -- user stop requested from tty
104 SIGCONT
: constant := 19; -- stopped process has been continued
105 SIGCHLD
: constant := 20; -- child status change
106 SIGTTIN
: constant := 21; -- background tty read attempted
107 SIGTTOU
: constant := 22; -- background tty write attempted
108 SIGPOLL
: constant := 23; -- I/O possible, or completed
109 SIGIO
: constant := 23; -- STREAMS version of SIGPOLL
110 SIGAIO
: constant := 23; -- base lan i/o
111 SIGPTY
: constant := 23; -- pty i/o
112 SIGXCPU
: constant := 24; -- CPU time limit exceeded
113 SIGXFSZ
: constant := 25; -- filesize limit exceeded
114 SIGVTALRM
: constant := 26; -- virtual timer expired
115 SIGPROF
: constant := 27; -- profiling timer expired
116 SIGWINCH
: constant := 28; -- window size change
117 SIGINFO
: constant := 29; -- information request
118 SIGPWR
: constant := 29; -- Power Fail/Restart -- SVID3/SVR4
119 SIGUSR1
: constant := 30; -- user defined signal 1
120 SIGUSR2
: constant := 31; -- user defined signal 2
121 SIGRESV
: constant := 32; -- reserved by Digital for future use
123 SIGADAABORT
: constant := SIGABRT
;
125 type Signal_Set
is array (Natural range <>) of Signal
;
127 Unmasked
: constant Signal_Set
:= (0 .. 0 => SIGTRAP
);
128 Reserved
: constant Signal_Set
:= (SIGALRM
, SIGABRT
, SIGKILL
, SIGSTOP
);
130 type sigset_t
is private;
132 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
133 pragma Import
(C
, sigaddset
);
135 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
136 pragma Import
(C
, sigdelset
);
138 function sigfillset
(set
: access sigset_t
) return int
;
139 pragma Import
(C
, sigfillset
);
141 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
142 pragma Import
(C
, sigismember
);
144 function sigemptyset
(set
: access sigset_t
) return int
;
145 pragma Import
(C
, sigemptyset
);
147 type union_type_3
is new String (1 .. 116);
148 type siginfo_t
is record
152 X_data
: union_type_3
;
154 for siginfo_t
'Size use 8 * 128;
155 pragma Convention
(C
, siginfo_t
);
157 type struct_sigaction
is record
158 sa_handler
: System
.Address
;
163 pragma Convention
(C
, struct_sigaction
);
164 type struct_sigaction_ptr
is access all struct_sigaction
;
166 SIG_BLOCK
: constant := 1;
167 SIG_UNBLOCK
: constant := 2;
168 SIG_SETMASK
: constant := 3;
170 SIG_DFL
: constant := 0;
171 SIG_IGN
: constant := 1;
173 SA_NODEFER
: constant := 8;
174 SA_SIGINFO
: constant := 16#
40#
;
178 act
: struct_sigaction_ptr
;
179 oact
: struct_sigaction_ptr
) return int
;
180 pragma Import
(C
, sigaction
);
186 type timespec
is private;
188 function nanosleep
(rqtp
, rmtp
: access timespec
) return int
;
189 pragma Import
(C
, nanosleep
);
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 pragma Import
(C
, clock_gettime
);
200 function To_Duration
(TS
: timespec
) return Duration;
201 pragma Inline
(To_Duration
);
203 function To_Timespec
(D
: Duration) return timespec
;
204 pragma Inline
(To_Timespec
);
206 type struct_timezone
is record
207 tz_minuteswest
: int
;
210 pragma Convention
(C
, struct_timezone
);
211 type struct_timeval
is private;
212 -- This is needed on systems that do not have clock_gettime()
213 -- but do have gettimeofday().
215 function To_Duration
(TV
: struct_timeval
) return Duration;
216 pragma Inline
(To_Duration
);
218 function To_Timeval
(D
: Duration) return struct_timeval
;
219 pragma Inline
(To_Timeval
);
221 -------------------------
222 -- Priority Scheduling --
223 -------------------------
225 SCHED_FIFO
: constant := 1;
226 SCHED_RR
: constant := 2;
227 SCHED_OTHER
: constant := 3;
228 SCHED_LFI
: constant := 5;
234 type pid_t
is private;
236 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
237 pragma Import
(C
, kill
);
239 function getpid
return pid_t
;
240 pragma Import
(C
, getpid
);
242 BIND_NO_INHERIT
: constant := 1;
246 cpu_mask
: unsigned_long
;
247 flag
: unsigned_long
:= BIND_NO_INHERIT
) return int
;
248 pragma Import
(C
, bind_to_cpu
);
254 type Thread_Body
is access
255 function (arg
: System
.Address
) return System
.Address
;
256 type pthread_t
is private;
257 subtype Thread_Id
is pthread_t
;
259 type pthread_mutex_t
is limited private;
260 type pthread_cond_t
is limited private;
261 type pthread_attr_t
is limited private;
262 type pthread_mutexattr_t
is limited private;
263 type pthread_condattr_t
is limited private;
264 type pthread_key_t
is private;
266 PTHREAD_CREATE_DETACHED
: constant := 1;
268 PTHREAD_SCOPE_PROCESS
: constant := 0;
269 PTHREAD_SCOPE_SYSTEM
: constant := 1;
271 PTHREAD_EXPLICIT_SCHED
: constant := 1;
273 ---------------------------------------
274 -- Nonstandard Thread Initialization --
275 ---------------------------------------
277 procedure pthread_init
;
278 pragma Inline
(pthread_init
);
279 -- This is a dummy procedure to share some GNULLI files
281 ---------------------------
282 -- POSIX.1c Section 3 --
283 ---------------------------
286 (set
: access sigset_t
;
287 sig
: access Signal
) return int
;
288 pragma Import
(C
, sigwait
, "__sigwaitd10");
290 function pthread_kill
292 sig
: Signal
) return int
;
293 pragma Import
(C
, pthread_kill
);
295 type sigset_t_ptr
is access all sigset_t
;
297 function pthread_sigmask
300 oset
: sigset_t_ptr
) return int
;
301 pragma Import
(C
, pthread_sigmask
);
303 ----------------------------
304 -- POSIX.1c Section 11 --
305 ----------------------------
307 function pthread_mutexattr_init
(attr
: access pthread_mutexattr_t
)
309 pragma Import
(C
, pthread_mutexattr_init
);
311 function pthread_mutexattr_destroy
312 (attr
: access pthread_mutexattr_t
) return int
;
313 pragma Import
(C
, pthread_mutexattr_destroy
);
315 function pthread_mutex_init
316 (mutex
: access pthread_mutex_t
;
317 attr
: access pthread_mutexattr_t
) return int
;
318 pragma Import
(C
, pthread_mutex_init
, "__pthread_mutex_init");
320 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
321 pragma Import
(C
, pthread_mutex_destroy
, "__pthread_mutex_destroy");
323 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
324 pragma Import
(C
, pthread_mutex_lock
, "__pthread_mutex_lock");
326 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
327 pragma Import
(C
, pthread_mutex_unlock
, "__pthread_mutex_unlock");
329 function pthread_condattr_init
330 (attr
: access pthread_condattr_t
) return int
;
331 pragma Import
(C
, pthread_condattr_init
);
333 function pthread_condattr_destroy
334 (attr
: access pthread_condattr_t
) return int
;
335 pragma Import
(C
, pthread_condattr_destroy
);
337 function pthread_cond_init
338 (cond
: access pthread_cond_t
;
339 attr
: access pthread_condattr_t
) return int
;
340 pragma Import
(C
, pthread_cond_init
, "__pthread_cond_init");
342 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
343 pragma Import
(C
, pthread_cond_destroy
, "__pthread_cond_destroy");
345 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
346 pragma Import
(C
, pthread_cond_signal
, "__pthread_cond_signal");
348 function pthread_cond_wait
349 (cond
: access pthread_cond_t
;
350 mutex
: access pthread_mutex_t
) return int
;
351 pragma Import
(C
, pthread_cond_wait
, "__pthread_cond_wait");
353 function pthread_cond_timedwait
354 (cond
: access pthread_cond_t
;
355 mutex
: access pthread_mutex_t
;
356 abstime
: access timespec
) return int
;
357 pragma Import
(C
, pthread_cond_timedwait
, "__pthread_cond_timedwait");
359 ----------------------------
360 -- POSIX.1c Section 13 --
361 ----------------------------
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
; -- scheduling priority
377 function pthread_setschedparam
380 param
: access struct_sched_param
) return int
;
381 pragma Import
(C
, pthread_setschedparam
);
383 function pthread_attr_setscope
384 (attr
: access pthread_attr_t
;
385 contentionscope
: int
) return int
;
386 pragma Import
(C
, pthread_attr_setscope
);
388 function pthread_attr_setinheritsched
389 (attr
: access pthread_attr_t
;
390 inheritsched
: int
) return int
;
391 pragma Import
(C
, pthread_attr_setinheritsched
,
392 "__pthread_attr_setinheritsched");
394 function pthread_attr_setschedpolicy
395 (attr
: access pthread_attr_t
; policy
: int
) return int
;
396 pragma Import
(C
, pthread_attr_setschedpolicy
);
398 function pthread_attr_setschedparam
399 (attr
: access pthread_attr_t
;
400 sched_param
: access struct_sched_param
) return int
;
401 pragma Import
(C
, pthread_attr_setschedparam
);
403 function sched_yield
return int
;
404 pragma Import
(C
, sched_yield
);
406 ---------------------------
407 -- P1003.1c - Section 16 --
408 ---------------------------
410 function pthread_attr_init
(attributes
: access pthread_attr_t
)
412 pragma Import
(C
, pthread_attr_init
);
414 function pthread_attr_destroy
(attributes
: access pthread_attr_t
)
416 pragma Import
(C
, pthread_attr_destroy
);
418 function pthread_attr_setdetachstate
419 (attr
: access pthread_attr_t
;
420 detachstate
: int
) return int
;
421 pragma Import
(C
, pthread_attr_setdetachstate
);
423 function pthread_attr_setstacksize
424 (attr
: access pthread_attr_t
;
425 stacksize
: size_t
) return int
;
426 pragma Import
(C
, pthread_attr_setstacksize
, "__pthread_attr_setstacksize");
428 function pthread_create
429 (thread
: access pthread_t
;
430 attributes
: access pthread_attr_t
;
431 start_routine
: Thread_Body
;
432 arg
: System
.Address
) return int
;
433 pragma Import
(C
, pthread_create
, "__pthread_create");
435 procedure pthread_exit
(status
: System
.Address
);
436 pragma Import
(C
, pthread_exit
, "__pthread_exit");
438 function pthread_self
return pthread_t
;
439 pragma Inline
(pthread_self
);
441 --------------------------
442 -- POSIX.1c Section 17 --
443 --------------------------
445 function pthread_setspecific
446 (key
: pthread_key_t
; value
: System
.Address
) return int
;
447 pragma Import
(C
, pthread_setspecific
, "__pthread_setspecific");
449 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
450 pragma Import
(C
, pthread_getspecific
, "__pthread_getspecific");
452 type destructor_pointer
is access procedure (arg
: System
.Address
);
454 function pthread_key_create
455 (key
: access pthread_key_t
;
456 destructor
: destructor_pointer
) return int
;
457 pragma Import
(C
, pthread_key_create
);
461 type sigset_t
is new unsigned_long
;
463 type pid_t
is new int
;
465 type time_t
is new int
;
467 type timespec
is record
471 pragma Convention
(C
, timespec
);
473 type clockid_t
is new int
;
474 CLOCK_REALTIME
: constant clockid_t
:= 1;
476 type struct_timeval
is record
480 pragma Convention
(C
, struct_timeval
);
482 type unsigned_long_array
is array (Natural range <>) of unsigned_long
;
484 type pthread_t
is new System
.Address
;
486 type pthread_cond_t
is record
489 name
: System
.Address
;
491 reserved1
: unsigned
;
492 sequence
: unsigned_long
;
493 block
: System
.Address
;
495 pragma Convention
(C
, pthread_cond_t
);
497 type pthread_attr_t
is record
499 name
: System
.Address
;
501 reserved
: unsigned_long_array
(0 .. 18);
503 pragma Convention
(C
, pthread_attr_t
);
505 type pthread_mutex_t
is record
508 name
: System
.Address
;
511 sequence
: unsigned_long
;
512 owner
: unsigned_long
;
513 block
: System
.Address
;
515 for pthread_mutex_t
'Size use 8 * 48;
516 pragma Convention
(C
, pthread_mutex_t
);
518 type pthread_mutexattr_t
is record
520 reserved
: unsigned_long_array
(0 .. 14);
522 pragma Convention
(C
, pthread_mutexattr_t
);
524 type pthread_condattr_t
is record
526 reserved
: unsigned_long_array
(0 .. 12);
528 pragma Convention
(C
, pthread_condattr_t
);
530 type pthread_key_t
is new unsigned
;
532 end System
.OS_Interface
;