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-2024, 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 HP-UX version of this package
35 -- This package encapsulates all direct interfaces to OS services
36 -- that are 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 with System
.Parameters
;
47 package System
.OS_Interface
is
50 pragma Linker_Options
("-lcma");
52 subtype int
is Interfaces
.C
.int
;
53 subtype short
is Interfaces
.C
.short
;
54 subtype long
is Interfaces
.C
.long
;
55 subtype unsigned
is Interfaces
.C
.unsigned
;
56 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
57 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
58 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
59 subtype plain_char
is Interfaces
.C
.plain_char
;
60 subtype size_t
is Interfaces
.C
.size_t
;
66 function errno
return int
;
67 pragma Import
(C
, errno
, "__get_errno");
69 EAGAIN
: constant := 11;
70 EINTR
: constant := 4;
71 EINVAL
: constant := 22;
72 ENOMEM
: constant := 12;
73 ETIME
: constant := 52;
74 ETIMEDOUT
: constant := 238;
76 FUNC_ERR
: constant := -1;
82 Max_Interrupt
: constant := 44;
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 SIGIOT
: constant := 6; -- IOT instruction
92 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
93 SIGEMT
: constant := 7; -- EMT instruction
94 SIGFPE
: constant := 8; -- floating point exception
95 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
96 SIGBUS
: constant := 10; -- bus error
97 SIGSEGV
: constant := 11; -- segmentation violation
98 SIGSYS
: constant := 12; -- bad argument to system call
99 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
100 SIGALRM
: constant := 14; -- alarm clock
101 SIGTERM
: constant := 15; -- software termination signal from kill
102 SIGUSR1
: constant := 16; -- user defined signal 1
103 SIGUSR2
: constant := 17; -- user defined signal 2
104 SIGCLD
: constant := 18; -- alias for SIGCHLD
105 SIGCHLD
: constant := 18; -- child status change
106 SIGPWR
: constant := 19; -- power-fail restart
107 SIGVTALRM
: constant := 20; -- virtual timer alarm
108 SIGPROF
: constant := 21; -- profiling timer alarm
109 SIGIO
: constant := 22; -- asynchronous I/O
110 SIGPOLL
: constant := 22; -- pollable event occurred
111 SIGWINCH
: constant := 23; -- window size change
112 SIGSTOP
: constant := 24; -- stop (cannot be caught or ignored)
113 SIGTSTP
: constant := 25; -- user stop requested from tty
114 SIGCONT
: constant := 26; -- stopped process has been continued
115 SIGTTIN
: constant := 27; -- background tty read attempted
116 SIGTTOU
: constant := 28; -- background tty write attempted
117 SIGURG
: constant := 29; -- urgent condition on IO channel
118 SIGLOST
: constant := 30; -- remote lock lost (NFS)
119 SIGDIL
: constant := 32; -- DIL signal
120 SIGXCPU
: constant := 33; -- CPU time limit exceeded (setrlimit)
121 SIGXFSZ
: constant := 34; -- file size limit exceeded (setrlimit)
123 SIGADAABORT
: constant := SIGABRT
;
124 -- Note: on other targets, we usually use SIGABRT, but on HP/UX, it
125 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
127 type Signal_Set
is array (Natural range <>) of Signal
;
129 Unmasked
: constant Signal_Set
:=
130 (SIGBUS
, SIGTRAP
, SIGTTIN
, SIGTTOU
, SIGTSTP
);
132 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
);
134 type sigset_t
is private;
136 type isr_address
is access procedure (sig
: int
);
137 pragma Convention
(C
, isr_address
);
139 function intr_attach
(sig
: int
; handler
: isr_address
) return long
;
141 Intr_Attach_Reset
: constant Boolean := True;
142 -- True if intr_attach is reset after an interrupt handler is called
144 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
145 pragma Import
(C
, sigaddset
, "sigaddset");
147 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
148 pragma Import
(C
, sigdelset
, "sigdelset");
150 function sigfillset
(set
: access sigset_t
) return int
;
151 pragma Import
(C
, sigfillset
, "sigfillset");
153 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
154 pragma Import
(C
, sigismember
, "sigismember");
156 function sigemptyset
(set
: access sigset_t
) return int
;
157 pragma Import
(C
, sigemptyset
, "sigemptyset");
159 type Signal_Handler
is access procedure (signo
: Signal
);
161 type struct_sigaction
is record
162 sa_handler
: System
.Address
;
166 pragma Convention
(C
, struct_sigaction
);
167 type struct_sigaction_ptr
is access all struct_sigaction
;
169 SA_RESTART
: constant := 16#
40#
;
170 SA_SIGINFO
: constant := 16#
10#
;
171 SA_ONSTACK
: constant := 16#
01#
;
173 SIG_BLOCK
: constant := 0;
174 SIG_UNBLOCK
: constant := 1;
175 SIG_SETMASK
: constant := 2;
177 SIG_DFL
: constant := 0;
178 SIG_IGN
: constant := 1;
179 SIG_ERR
: constant := -1;
183 act
: struct_sigaction_ptr
;
184 oact
: struct_sigaction_ptr
) return int
;
185 pragma Import
(C
, sigaction
, "sigaction");
191 type timespec
is private;
193 function nanosleep
(rqtp
, rmtp
: access timespec
) return int
;
194 pragma Import
(C
, nanosleep
);
196 type clockid_t
is new int
;
198 function Clock_Gettime
199 (Clock_Id
: clockid_t
; Tp
: access timespec
) return int
;
200 pragma Import
(C
, Clock_Gettime
);
202 function To_Duration
(TS
: timespec
) return Duration;
203 pragma Inline
(To_Duration
);
205 function To_Timespec
(D
: Duration) return timespec
;
206 pragma Inline
(To_Timespec
);
208 -------------------------
209 -- Priority Scheduling --
210 -------------------------
212 SCHED_FIFO
: constant := 0;
213 SCHED_RR
: constant := 1;
214 SCHED_OTHER
: constant := 2;
220 type pid_t
is private;
222 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
223 pragma Import
(C
, kill
, "kill");
225 function getpid
return pid_t
;
226 pragma Import
(C
, getpid
, "getpid");
232 type Thread_Body
is access
233 function (arg
: System
.Address
) return System
.Address
;
234 pragma Convention
(C
, Thread_Body
);
236 function Thread_Body_Access
is new
237 Ada
.Unchecked_Conversion
(System
.Address
, Thread_Body
);
239 type pthread_t
is private;
240 subtype Thread_Id
is pthread_t
;
242 type pthread_mutex_t
is limited private;
243 type pthread_cond_t
is limited private;
244 type pthread_attr_t
is limited private;
245 type pthread_mutexattr_t
is limited private;
246 type pthread_condattr_t
is limited private;
247 type pthread_key_t
is private;
249 -- Read/Write lock not supported on HPUX. To add support both types
250 -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
251 -- with the associated routines pthread_rwlock_[init/destroy] and
252 -- pthread_rwlock_[rdlock/wrlock/unlock].
254 subtype pthread_rwlock_t
is pthread_mutex_t
;
255 subtype pthread_rwlockattr_t
is pthread_mutexattr_t
;
261 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
262 pragma Inline
(Get_Stack_Base
);
263 -- This is a dummy procedure to share some GNULLI files
265 ---------------------------------------
266 -- Nonstandard Thread Initialization --
267 ---------------------------------------
269 procedure pthread_init
;
270 pragma Inline
(pthread_init
);
271 -- This is a dummy procedure to share some GNULLI files
273 -------------------------
274 -- POSIX.1c Section 3 --
275 -------------------------
277 function sigwait
(set
: access sigset_t
) return int
;
278 pragma Import
(C
, sigwait
, "cma_sigwait");
281 (set
: access sigset_t
;
282 sig
: access Signal
) return int
;
283 pragma Inline
(sigwait
);
284 -- DCE_THREADS has a nonstandard sigwait
286 function pthread_kill
288 sig
: Signal
) return int
;
289 pragma Inline
(pthread_kill
);
290 -- DCE_THREADS doesn't have pthread_kill
292 function pthread_sigmask
294 set
: access sigset_t
;
295 oset
: access sigset_t
) return int
;
296 -- DCE THREADS does not have pthread_sigmask. Instead, it uses sigprocmask
297 -- to do the signal handling when the thread library is sucked in.
298 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
300 --------------------------
301 -- POSIX.1c Section 11 --
302 --------------------------
304 function pthread_mutexattr_init
305 (attr
: access pthread_mutexattr_t
) return int
;
306 -- DCE_THREADS has a nonstandard pthread_mutexattr_init
308 function pthread_mutexattr_destroy
309 (attr
: access pthread_mutexattr_t
) return int
;
310 -- DCE_THREADS has a nonstandard pthread_mutexattr_destroy
312 function pthread_mutex_init
313 (mutex
: access pthread_mutex_t
;
314 attr
: access pthread_mutexattr_t
) return int
;
315 -- DCE_THREADS has a nonstandard pthread_mutex_init
317 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
318 -- DCE_THREADS has a nonstandard pthread_mutex_destroy
320 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
321 pragma Inline
(pthread_mutex_lock
);
322 -- DCE_THREADS has nonstandard pthread_mutex_lock
324 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
325 pragma Inline
(pthread_mutex_unlock
);
326 -- DCE_THREADS has nonstandard pthread_mutex_lock
328 function pthread_condattr_init
329 (attr
: access pthread_condattr_t
) return int
;
330 -- DCE_THREADS has nonstandard pthread_condattr_init
332 function pthread_condattr_destroy
333 (attr
: access pthread_condattr_t
) return int
;
334 -- DCE_THREADS has nonstandard pthread_condattr_destroy
336 function pthread_cond_init
337 (cond
: access pthread_cond_t
;
338 attr
: access pthread_condattr_t
) return int
;
339 -- DCE_THREADS has nonstandard pthread_cond_init
341 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
342 -- DCE_THREADS has nonstandard pthread_cond_destroy
344 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
345 pragma Inline
(pthread_cond_signal
);
346 -- DCE_THREADS has nonstandard pthread_cond_signal
348 function pthread_cond_wait
349 (cond
: access pthread_cond_t
;
350 mutex
: access pthread_mutex_t
) return int
;
351 pragma Inline
(pthread_cond_wait
);
352 -- DCE_THREADS has a nonstandard pthread_cond_wait
354 function pthread_cond_timedwait
355 (cond
: access pthread_cond_t
;
356 mutex
: access pthread_mutex_t
;
357 abstime
: access timespec
) return int
;
358 pragma Inline
(pthread_cond_timedwait
);
359 -- DCE_THREADS has a nonstandard pthread_cond_timedwait
361 --------------------------
362 -- POSIX.1c Section 13 --
363 --------------------------
365 type struct_sched_param
is record
366 sched_priority
: int
; -- scheduling priority
369 function pthread_setschedparam
372 param
: access struct_sched_param
) return int
;
373 pragma Inline
(pthread_setschedparam
);
374 -- DCE_THREADS has a nonstandard pthread_setschedparam
376 function sched_yield
return int
;
377 pragma Inline
(sched_yield
);
378 -- DCE_THREADS has a nonstandard sched_yield
380 ---------------------------
381 -- P1003.1c - Section 16 --
382 ---------------------------
384 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
385 pragma Inline
(pthread_attr_init
);
386 -- DCE_THREADS has a nonstandard pthread_attr_init
388 function pthread_attr_destroy
389 (attributes
: access pthread_attr_t
) return int
;
390 pragma Inline
(pthread_attr_destroy
);
391 -- DCE_THREADS has a nonstandard pthread_attr_destroy
393 function pthread_attr_setstacksize
394 (attr
: access pthread_attr_t
;
395 stacksize
: size_t
) return int
;
396 pragma Inline
(pthread_attr_setstacksize
);
397 -- DCE_THREADS has a nonstandard pthread_attr_setstacksize
399 function pthread_create
400 (thread
: access pthread_t
;
401 attributes
: access pthread_attr_t
;
402 start_routine
: Thread_Body
;
403 arg
: System
.Address
) return int
;
404 pragma Inline
(pthread_create
);
405 -- DCE_THREADS has a nonstandard pthread_create
407 procedure pthread_detach
(thread
: access pthread_t
);
408 pragma Import
(C
, pthread_detach
);
410 procedure pthread_exit
(status
: System
.Address
);
411 pragma Import
(C
, pthread_exit
, "pthread_exit");
413 function pthread_self
return pthread_t
;
414 pragma Import
(C
, pthread_self
, "pthread_self");
416 --------------------------
417 -- POSIX.1c Section 17 --
418 --------------------------
420 function pthread_setspecific
421 (key
: pthread_key_t
;
422 value
: System
.Address
) return int
;
423 pragma Inline
(pthread_setspecific
);
424 -- DCE_THREADS has a nonstandard pthread_setspecific
426 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
427 pragma Inline
(pthread_getspecific
);
428 -- DCE_THREADS has a nonstandard pthread_getspecific
430 type destructor_pointer
is access procedure (arg
: System
.Address
);
431 pragma Convention
(C
, destructor_pointer
);
433 function pthread_key_create
434 (key
: access pthread_key_t
;
435 destructor
: destructor_pointer
) return int
;
436 pragma Inline
(pthread_key_create
);
437 -- DCE_THREADS has a nonstandard pthread_key_create
441 type array_type_1
is array (Integer range 0 .. 7) of unsigned_long
;
442 type sigset_t
is record
443 X_X_sigbits
: array_type_1
;
445 pragma Convention
(C
, sigset_t
);
447 type pid_t
is new int
;
449 type time_t
is range -2 ** (System
.Parameters
.time_t_bits
- 1)
450 .. 2 ** (System
.Parameters
.time_t_bits
- 1) - 1;
452 type timespec
is record
456 pragma Convention
(C
, timespec
);
458 CLOCK_REALTIME
: constant clockid_t
:= 1;
460 type cma_t_address
is new System
.Address
;
462 type cma_t_handle
is record
463 field1
: cma_t_address
;
464 field2
: Short_Integer;
465 field3
: Short_Integer;
467 for cma_t_handle
'Size use 64;
469 type pthread_attr_t
is new cma_t_handle
;
470 pragma Convention
(C_Pass_By_Copy
, pthread_attr_t
);
472 type pthread_condattr_t
is new cma_t_handle
;
473 pragma Convention
(C_Pass_By_Copy
, pthread_condattr_t
);
475 type pthread_mutexattr_t
is new cma_t_handle
;
476 pragma Convention
(C_Pass_By_Copy
, pthread_mutexattr_t
);
478 type pthread_t
is new cma_t_handle
;
479 pragma Convention
(C_Pass_By_Copy
, pthread_t
);
481 type pthread_mutex_t
is new cma_t_handle
;
482 pragma Convention
(C_Pass_By_Copy
, pthread_mutex_t
);
484 type pthread_cond_t
is new cma_t_handle
;
485 pragma Convention
(C_Pass_By_Copy
, pthread_cond_t
);
487 type pthread_key_t
is new int
;
489 end System
.OS_Interface
;