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
;
46 with System
.Parameters
;
48 package System
.OS_Interface
is
51 pragma Linker_Options
("-lcma");
53 subtype int
is Interfaces
.C
.int
;
54 subtype short
is Interfaces
.C
.short
;
55 subtype long
is Interfaces
.C
.long
;
56 subtype unsigned
is Interfaces
.C
.unsigned
;
57 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
58 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
59 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
60 subtype plain_char
is Interfaces
.C
.plain_char
;
61 subtype size_t
is Interfaces
.C
.size_t
;
67 function errno
return int
;
68 pragma Import
(C
, errno
, "__get_errno");
70 EAGAIN
: constant := 11;
71 EINTR
: constant := 4;
72 EINVAL
: constant := 22;
73 ENOMEM
: constant := 12;
74 ETIME
: constant := 52;
75 ETIMEDOUT
: constant := 238;
77 FUNC_ERR
: constant := -1;
83 Max_Interrupt
: constant := 44;
84 type Signal
is new int
range 0 .. Max_Interrupt
;
85 for Signal
'Size use int
'Size;
87 SIGHUP
: constant := 1; -- hangup
88 SIGINT
: constant := 2; -- interrupt (rubout)
89 SIGQUIT
: constant := 3; -- quit (ASCD FS)
90 SIGILL
: constant := 4; -- illegal instruction (not reset)
91 SIGTRAP
: constant := 5; -- trace trap (not reset)
92 SIGIOT
: constant := 6; -- IOT instruction
93 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
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 SIGUSR1
: constant := 16; -- user defined signal 1
104 SIGUSR2
: constant := 17; -- user defined signal 2
105 SIGCLD
: constant := 18; -- alias for SIGCHLD
106 SIGCHLD
: constant := 18; -- child status change
107 SIGPWR
: constant := 19; -- power-fail restart
108 SIGVTALRM
: constant := 20; -- virtual timer alarm
109 SIGPROF
: constant := 21; -- profiling timer alarm
110 SIGIO
: constant := 22; -- asynchronous I/O
111 SIGPOLL
: constant := 22; -- pollable event occurred
112 SIGWINCH
: constant := 23; -- window size change
113 SIGSTOP
: constant := 24; -- stop (cannot be caught or ignored)
114 SIGTSTP
: constant := 25; -- user stop requested from tty
115 SIGCONT
: constant := 26; -- stopped process has been continued
116 SIGTTIN
: constant := 27; -- background tty read attempted
117 SIGTTOU
: constant := 28; -- background tty write attempted
118 SIGURG
: constant := 29; -- urgent condition on IO channel
119 SIGLOST
: constant := 30; -- remote lock lost (NFS)
120 SIGDIL
: constant := 32; -- DIL signal
121 SIGXCPU
: constant := 33; -- CPU time limit exceeded (setrlimit)
122 SIGXFSZ
: constant := 34; -- file size limit exceeded (setrlimit)
124 SIGADAABORT
: constant := SIGABRT
;
125 -- Note: on other targets, we usually use SIGABRT, but on HP/UX, it
126 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
128 type Signal_Set
is array (Natural range <>) of Signal
;
130 Unmasked
: constant Signal_Set
:=
131 (SIGBUS
, SIGTRAP
, SIGTTIN
, SIGTTOU
, SIGTSTP
);
133 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
);
135 type sigset_t
is private;
137 type isr_address
is access procedure (sig
: int
);
138 pragma Convention
(C
, isr_address
);
140 function intr_attach
(sig
: int
; handler
: isr_address
) return long
;
142 Intr_Attach_Reset
: constant Boolean := True;
143 -- True if intr_attach is reset after an interrupt handler is called
145 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
146 pragma Import
(C
, sigaddset
, "sigaddset");
148 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
149 pragma Import
(C
, sigdelset
, "sigdelset");
151 function sigfillset
(set
: access sigset_t
) return int
;
152 pragma Import
(C
, sigfillset
, "sigfillset");
154 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
155 pragma Import
(C
, sigismember
, "sigismember");
157 function sigemptyset
(set
: access sigset_t
) return int
;
158 pragma Import
(C
, sigemptyset
, "sigemptyset");
160 type Signal_Handler
is access procedure (signo
: Signal
);
162 type struct_sigaction
is record
163 sa_handler
: System
.Address
;
167 pragma Convention
(C
, struct_sigaction
);
168 type struct_sigaction_ptr
is access all struct_sigaction
;
170 SA_RESTART
: constant := 16#
40#
;
171 SA_SIGINFO
: constant := 16#
10#
;
172 SA_ONSTACK
: constant := 16#
01#
;
174 SIG_BLOCK
: constant := 0;
175 SIG_UNBLOCK
: constant := 1;
176 SIG_SETMASK
: constant := 2;
178 SIG_DFL
: constant := 0;
179 SIG_IGN
: constant := 1;
180 SIG_ERR
: constant := -1;
184 act
: struct_sigaction_ptr
;
185 oact
: struct_sigaction_ptr
) return int
;
186 pragma Import
(C
, sigaction
, "sigaction");
192 type timespec
is private;
194 function nanosleep
(rqtp
, rmtp
: access timespec
) return int
;
195 pragma Import
(C
, nanosleep
);
197 type clockid_t
is new int
;
199 function Clock_Gettime
200 (Clock_Id
: clockid_t
; 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 -------------------------
210 -- Priority Scheduling --
211 -------------------------
213 SCHED_FIFO
: constant := 0;
214 SCHED_RR
: constant := 1;
215 SCHED_OTHER
: constant := 2;
221 type pid_t
is private;
223 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
224 pragma Import
(C
, kill
, "kill");
226 function getpid
return pid_t
;
227 pragma Import
(C
, getpid
, "getpid");
233 type Thread_Body
is access
234 function (arg
: System
.Address
) return System
.Address
;
235 pragma Convention
(C
, Thread_Body
);
237 function Thread_Body_Access
is new
238 Ada
.Unchecked_Conversion
(System
.Address
, Thread_Body
);
240 type pthread_t
is private;
241 subtype Thread_Id
is pthread_t
;
243 subtype pthread_mutex_t
is System
.OS_Locks
.pthread_mutex_t
;
244 type pthread_cond_t
is limited private;
245 type pthread_attr_t
is limited private;
246 type pthread_mutexattr_t
is limited private;
247 type pthread_condattr_t
is limited private;
248 type pthread_key_t
is private;
250 -- Read/Write lock not supported on HPUX. To add support both types
251 -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
252 -- with the associated routines pthread_rwlock_[init/destroy] and
253 -- pthread_rwlock_[rdlock/wrlock/unlock].
255 subtype pthread_rwlock_t
is pthread_mutex_t
;
256 subtype pthread_rwlockattr_t
is pthread_mutexattr_t
;
262 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
263 pragma Inline
(Get_Stack_Base
);
264 -- This is a dummy procedure to share some GNULLI files
266 ---------------------------------------
267 -- Nonstandard Thread Initialization --
268 ---------------------------------------
270 procedure pthread_init
;
271 pragma Inline
(pthread_init
);
272 -- This is a dummy procedure to share some GNULLI files
274 -------------------------
275 -- POSIX.1c Section 3 --
276 -------------------------
278 function sigwait
(set
: access sigset_t
) return int
;
279 pragma Import
(C
, sigwait
, "cma_sigwait");
282 (set
: access sigset_t
;
283 sig
: access Signal
) return int
;
284 pragma Inline
(sigwait
);
285 -- DCE_THREADS has a nonstandard sigwait
287 function pthread_kill
289 sig
: Signal
) return int
;
290 pragma Inline
(pthread_kill
);
291 -- DCE_THREADS doesn't have pthread_kill
293 function pthread_sigmask
295 set
: access sigset_t
;
296 oset
: access sigset_t
) return int
;
297 -- DCE THREADS does not have pthread_sigmask. Instead, it uses sigprocmask
298 -- to do the signal handling when the thread library is sucked in.
299 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
301 --------------------------
302 -- POSIX.1c Section 11 --
303 --------------------------
305 function pthread_mutexattr_init
306 (attr
: access pthread_mutexattr_t
) return int
;
307 -- DCE_THREADS has a nonstandard pthread_mutexattr_init
309 function pthread_mutexattr_destroy
310 (attr
: access pthread_mutexattr_t
) return int
;
311 -- DCE_THREADS has a nonstandard pthread_mutexattr_destroy
313 function pthread_mutex_init
314 (mutex
: access pthread_mutex_t
;
315 attr
: access pthread_mutexattr_t
) return int
;
316 -- DCE_THREADS has a nonstandard pthread_mutex_init
318 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
319 -- DCE_THREADS has a nonstandard pthread_mutex_destroy
321 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
322 pragma Inline
(pthread_mutex_lock
);
323 -- DCE_THREADS has nonstandard pthread_mutex_lock
325 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
326 pragma Inline
(pthread_mutex_unlock
);
327 -- DCE_THREADS has nonstandard pthread_mutex_lock
329 function pthread_condattr_init
330 (attr
: access pthread_condattr_t
) return int
;
331 -- DCE_THREADS has nonstandard pthread_condattr_init
333 function pthread_condattr_destroy
334 (attr
: access pthread_condattr_t
) return int
;
335 -- DCE_THREADS has nonstandard pthread_condattr_destroy
337 function pthread_cond_init
338 (cond
: access pthread_cond_t
;
339 attr
: access pthread_condattr_t
) return int
;
340 -- DCE_THREADS has nonstandard pthread_cond_init
342 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
343 -- DCE_THREADS has nonstandard pthread_cond_destroy
345 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
346 pragma Inline
(pthread_cond_signal
);
347 -- DCE_THREADS has nonstandard pthread_cond_signal
349 function pthread_cond_wait
350 (cond
: access pthread_cond_t
;
351 mutex
: access pthread_mutex_t
) return int
;
352 pragma Inline
(pthread_cond_wait
);
353 -- DCE_THREADS has a nonstandard pthread_cond_wait
355 function pthread_cond_timedwait
356 (cond
: access pthread_cond_t
;
357 mutex
: access pthread_mutex_t
;
358 abstime
: access timespec
) return int
;
359 pragma Inline
(pthread_cond_timedwait
);
360 -- DCE_THREADS has a nonstandard pthread_cond_timedwait
362 --------------------------
363 -- POSIX.1c Section 13 --
364 --------------------------
366 type struct_sched_param
is record
367 sched_priority
: int
; -- scheduling priority
370 function pthread_setschedparam
373 param
: access struct_sched_param
) return int
;
374 pragma Inline
(pthread_setschedparam
);
375 -- DCE_THREADS has a nonstandard pthread_setschedparam
377 function sched_yield
return int
;
378 pragma Inline
(sched_yield
);
379 -- DCE_THREADS has a nonstandard sched_yield
381 ---------------------------
382 -- P1003.1c - Section 16 --
383 ---------------------------
385 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
386 pragma Inline
(pthread_attr_init
);
387 -- DCE_THREADS has a nonstandard pthread_attr_init
389 function pthread_attr_destroy
390 (attributes
: access pthread_attr_t
) return int
;
391 pragma Inline
(pthread_attr_destroy
);
392 -- DCE_THREADS has a nonstandard pthread_attr_destroy
394 function pthread_attr_setstacksize
395 (attr
: access pthread_attr_t
;
396 stacksize
: size_t
) return int
;
397 pragma Inline
(pthread_attr_setstacksize
);
398 -- DCE_THREADS has a nonstandard pthread_attr_setstacksize
400 function pthread_create
401 (thread
: access pthread_t
;
402 attributes
: access pthread_attr_t
;
403 start_routine
: Thread_Body
;
404 arg
: System
.Address
) return int
;
405 pragma Inline
(pthread_create
);
406 -- DCE_THREADS has a nonstandard pthread_create
408 procedure pthread_detach
(thread
: access pthread_t
);
409 pragma Import
(C
, pthread_detach
);
411 procedure pthread_exit
(status
: System
.Address
);
412 pragma Import
(C
, pthread_exit
, "pthread_exit");
414 function pthread_self
return pthread_t
;
415 pragma Import
(C
, pthread_self
, "pthread_self");
417 --------------------------
418 -- POSIX.1c Section 17 --
419 --------------------------
421 function pthread_setspecific
422 (key
: pthread_key_t
;
423 value
: System
.Address
) return int
;
424 pragma Inline
(pthread_setspecific
);
425 -- DCE_THREADS has a nonstandard pthread_setspecific
427 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
428 pragma Inline
(pthread_getspecific
);
429 -- DCE_THREADS has a nonstandard pthread_getspecific
431 type destructor_pointer
is access procedure (arg
: System
.Address
);
432 pragma Convention
(C
, destructor_pointer
);
434 function pthread_key_create
435 (key
: access pthread_key_t
;
436 destructor
: destructor_pointer
) return int
;
437 pragma Inline
(pthread_key_create
);
438 -- DCE_THREADS has a nonstandard pthread_key_create
442 type array_type_1
is array (Integer range 0 .. 7) of unsigned_long
;
443 type sigset_t
is record
444 X_X_sigbits
: array_type_1
;
446 pragma Convention
(C
, sigset_t
);
448 type pid_t
is new int
;
450 type time_t
is range -2 ** (System
.Parameters
.time_t_bits
- 1)
451 .. 2 ** (System
.Parameters
.time_t_bits
- 1) - 1;
453 type timespec
is record
457 pragma Convention
(C
, timespec
);
459 CLOCK_REALTIME
: constant clockid_t
:= 1;
461 type cma_t_address
is new System
.Address
;
463 type cma_t_handle
is record
464 field1
: cma_t_address
;
465 field2
: Short_Integer;
466 field3
: Short_Integer;
468 for cma_t_handle
'Size use 64;
470 type pthread_attr_t
is new cma_t_handle
;
471 pragma Convention
(C_Pass_By_Copy
, pthread_attr_t
);
473 type pthread_condattr_t
is new cma_t_handle
;
474 pragma Convention
(C_Pass_By_Copy
, pthread_condattr_t
);
476 type pthread_mutexattr_t
is new cma_t_handle
;
477 pragma Convention
(C_Pass_By_Copy
, pthread_mutexattr_t
);
479 type pthread_t
is new cma_t_handle
;
480 pragma Convention
(C_Pass_By_Copy
, pthread_t
);
482 type pthread_cond_t
is new cma_t_handle
;
483 pragma Convention
(C_Pass_By_Copy
, pthread_cond_t
);
485 type pthread_key_t
is new int
;
487 end System
.OS_Interface
;