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) 1999-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 a HPUX 11.0 (Native THREADS) 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
48 pragma Linker_Options
("-lpthread");
50 subtype int
is Interfaces
.C
.int
;
51 subtype short
is Interfaces
.C
.short
;
52 subtype long
is Interfaces
.C
.long
;
53 subtype unsigned
is Interfaces
.C
.unsigned
;
54 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
55 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
56 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
57 subtype plain_char
is Interfaces
.C
.plain_char
;
58 subtype size_t
is Interfaces
.C
.size_t
;
64 function errno
return int
;
65 pragma Import
(C
, errno
, "__get_errno");
67 EAGAIN
: constant := 11;
68 EINTR
: constant := 4;
69 EINVAL
: constant := 22;
70 ENOMEM
: constant := 12;
71 ETIMEDOUT
: constant := 238;
77 Max_Interrupt
: constant := 44;
78 type Signal
is new int
range 0 .. Max_Interrupt
;
79 for Signal
'Size use int
'Size;
81 SIGHUP
: constant := 1; -- hangup
82 SIGINT
: constant := 2; -- interrupt (rubout)
83 SIGQUIT
: constant := 3; -- quit (ASCD FS)
84 SIGILL
: constant := 4; -- illegal instruction (not reset)
85 SIGTRAP
: constant := 5; -- trace trap (not reset)
86 SIGIOT
: constant := 6; -- IOT instruction
87 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
88 SIGEMT
: constant := 7; -- EMT instruction
89 SIGFPE
: constant := 8; -- floating point exception
90 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
91 SIGBUS
: constant := 10; -- bus error
92 SIGSEGV
: constant := 11; -- segmentation violation
93 SIGSYS
: constant := 12; -- bad argument to system call
94 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
95 SIGALRM
: constant := 14; -- alarm clock
96 SIGTERM
: constant := 15; -- software termination signal from kill
97 SIGUSR1
: constant := 16; -- user defined signal 1
98 SIGUSR2
: constant := 17; -- user defined signal 2
99 SIGCLD
: constant := 18; -- alias for SIGCHLD
100 SIGCHLD
: constant := 18; -- child status change
101 SIGPWR
: constant := 19; -- power-fail restart
102 SIGVTALRM
: constant := 20; -- virtual timer alarm
103 SIGPROF
: constant := 21; -- profiling timer alarm
104 SIGIO
: constant := 22; -- asynchronous I/O
105 SIGPOLL
: constant := 22; -- pollable event occurred
106 SIGWINCH
: constant := 23; -- window size change
107 SIGSTOP
: constant := 24; -- stop (cannot be caught or ignored)
108 SIGTSTP
: constant := 25; -- user stop requested from tty
109 SIGCONT
: constant := 26; -- stopped process has been continued
110 SIGTTIN
: constant := 27; -- background tty read attempted
111 SIGTTOU
: constant := 28; -- background tty write attempted
112 SIGURG
: constant := 29; -- urgent condition on IO channel
113 SIGLOST
: constant := 30; -- remote lock lost (NFS)
114 SIGDIL
: constant := 32; -- DIL signal
115 SIGXCPU
: constant := 33; -- CPU time limit exceeded (setrlimit)
116 SIGXFSZ
: constant := 34; -- file size limit exceeded (setrlimit)
117 SIGCANCEL
: constant := 35; -- used for pthread cancellation.
118 SIGGFAULT
: constant := 36; -- Graphics framebuffer fault
120 SIGADAABORT
: constant := SIGABRT
;
121 -- Note: on other targets, we usually use SIGABRT, but on HPUX, it
122 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
124 type Signal_Set
is array (Natural range <>) of Signal
;
126 Unmasked
: constant Signal_Set
:=
127 (SIGABRT
, SIGPIPE
, SIGBUS
, SIGTRAP
, SIGTTIN
, SIGTTOU
, SIGTSTP
, SIGPROF
,
128 SIGALRM
, SIGVTALRM
, SIGIO
, SIGCHLD
);
130 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
);
132 type sigset_t
is private;
134 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
135 pragma Import
(C
, sigaddset
, "sigaddset");
137 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
138 pragma Import
(C
, sigdelset
, "sigdelset");
140 function sigfillset
(set
: access sigset_t
) return int
;
141 pragma Import
(C
, sigfillset
, "sigfillset");
143 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
144 pragma Import
(C
, sigismember
, "sigismember");
146 function sigemptyset
(set
: access sigset_t
) return int
;
147 pragma Import
(C
, sigemptyset
, "sigemptyset");
149 type struct_sigaction
is record
150 sa_handler
: System
.Address
;
154 pragma Convention
(C
, struct_sigaction
);
155 type struct_sigaction_ptr
is access all struct_sigaction
;
157 SIG_BLOCK
: constant := 0;
158 SIG_UNBLOCK
: constant := 1;
159 SIG_SETMASK
: constant := 2;
161 SIG_DFL
: constant := 0;
162 SIG_IGN
: constant := 1;
166 act
: struct_sigaction_ptr
;
167 oact
: struct_sigaction_ptr
) return int
;
168 pragma Import
(C
, sigaction
, "sigaction");
174 Time_Slice_Supported
: constant Boolean := True;
175 -- Indicates wether time slicing is supported
177 type timespec
is private;
179 type clockid_t
is private;
181 CLOCK_REALTIME
: constant clockid_t
;
183 function clock_gettime
184 (clock_id
: clockid_t
;
185 tp
: access timespec
) return int
;
186 pragma Import
(C
, clock_gettime
, "clock_gettime");
188 function To_Duration
(TS
: timespec
) return Duration;
189 pragma Inline
(To_Duration
);
191 function To_Timespec
(D
: Duration) return timespec
;
192 pragma Inline
(To_Timespec
);
194 type struct_timezone
is record
195 tz_minuteswest
: int
;
198 pragma Convention
(C
, struct_timezone
);
199 type struct_timezone_ptr
is access all struct_timezone
;
201 type struct_timeval
is private;
202 -- This is needed on systems that do not have clock_gettime()
203 -- but do have gettimeofday().
205 function To_Duration
(TV
: struct_timeval
) return Duration;
206 pragma Inline
(To_Duration
);
208 function To_Timeval
(D
: Duration) return struct_timeval
;
209 pragma Inline
(To_Timeval
);
211 -------------------------
212 -- Priority Scheduling --
213 -------------------------
215 SCHED_FIFO
: constant := 0;
216 SCHED_RR
: constant := 1;
217 SCHED_OTHER
: constant := 2;
223 type pid_t
is private;
225 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
226 pragma Import
(C
, kill
, "kill");
228 function getpid
return pid_t
;
229 pragma Import
(C
, getpid
, "getpid");
235 function lwp_self
return System
.Address
;
236 pragma Import
(C
, lwp_self
, "_lwp_self");
242 type Thread_Body
is access
243 function (arg
: System
.Address
) return System
.Address
;
244 type pthread_t
is private;
245 subtype Thread_Id
is pthread_t
;
247 type pthread_mutex_t
is limited private;
248 type pthread_cond_t
is limited private;
249 type pthread_attr_t
is limited private;
250 type pthread_mutexattr_t
is limited private;
251 type pthread_condattr_t
is limited private;
252 type pthread_key_t
is private;
254 PTHREAD_CREATE_DETACHED
: constant := 16#de#
;
260 Stack_Base_Available
: constant Boolean := False;
261 -- Indicates wether the stack base is available on this target.
263 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
264 pragma Inline
(Get_Stack_Base
);
265 -- returns the stack base of the specified thread.
266 -- Only call this function when Stack_Base_Available is True.
268 function Get_Page_Size
return size_t
;
269 function Get_Page_Size
return Address
;
270 pragma Import
(C
, Get_Page_Size
, "getpagesize");
271 -- returns the size of a page, or 0 if this is not relevant on this
274 PROT_NONE
: constant := 0;
275 PROT_READ
: constant := 1;
276 PROT_WRITE
: constant := 2;
277 PROT_EXEC
: constant := 4;
278 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
;
280 PROT_ON
: constant := PROT_READ
;
281 PROT_OFF
: constant := PROT_ALL
;
283 function mprotect
(addr
: Address
; len
: size_t
; prot
: int
) return int
;
284 pragma Import
(C
, mprotect
);
286 ---------------------------------------
287 -- Nonstandard Thread Initialization --
288 ---------------------------------------
290 procedure pthread_init
;
291 pragma Inline
(pthread_init
);
292 -- This is a dummy procedure to share some GNULLI files
294 -------------------------
295 -- POSIX.1c Section 3 --
296 -------------------------
299 (set
: access sigset_t
;
300 sig
: access Signal
) return int
;
301 pragma Import
(C
, sigwait
, "sigwait");
303 function pthread_kill
305 sig
: Signal
) return int
;
306 pragma Import
(C
, pthread_kill
, "pthread_kill");
308 type sigset_t_ptr
is access all sigset_t
;
310 function pthread_sigmask
313 oset
: sigset_t_ptr
) return int
;
314 pragma Import
(C
, pthread_sigmask
, "pthread_sigmask");
316 --------------------------
317 -- POSIX.1c Section 11 --
318 --------------------------
320 function pthread_mutexattr_init
321 (attr
: access pthread_mutexattr_t
) return int
;
322 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
324 function pthread_mutexattr_destroy
325 (attr
: access pthread_mutexattr_t
) return int
;
326 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
328 function pthread_mutex_init
329 (mutex
: access pthread_mutex_t
;
330 attr
: access pthread_mutexattr_t
) return int
;
331 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
333 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
334 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
336 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
337 pragma Import
(C
, pthread_mutex_lock
, "pthread_mutex_lock");
339 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
340 pragma Import
(C
, pthread_mutex_unlock
, "pthread_mutex_unlock");
342 function pthread_condattr_init
343 (attr
: access pthread_condattr_t
) return int
;
344 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
346 function pthread_condattr_destroy
347 (attr
: access pthread_condattr_t
) return int
;
348 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
350 function pthread_cond_init
351 (cond
: access pthread_cond_t
;
352 attr
: access pthread_condattr_t
) return int
;
353 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
355 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
356 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
358 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
359 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
361 function pthread_cond_wait
362 (cond
: access pthread_cond_t
;
363 mutex
: access pthread_mutex_t
) return int
;
364 pragma Import
(C
, pthread_cond_wait
, "pthread_cond_wait");
366 function pthread_cond_timedwait
367 (cond
: access pthread_cond_t
;
368 mutex
: access pthread_mutex_t
;
369 abstime
: access timespec
) return int
;
370 pragma Import
(C
, pthread_cond_timedwait
, "pthread_cond_timedwait");
372 Relative_Timed_Wait
: constant Boolean := False;
373 -- pthread_cond_timedwait requires an absolute delay time
375 ----------------------------
376 -- POSIX.1c Section 13 --
377 ----------------------------
379 PTHREAD_PRIO_NONE
: constant := 16#
100#
;
380 PTHREAD_PRIO_PROTECT
: constant := 16#
200#
;
381 PTHREAD_PRIO_INHERIT
: constant := 16#
400#
;
383 function pthread_mutexattr_setprotocol
384 (attr
: access pthread_mutexattr_t
;
385 protocol
: int
) return int
;
386 pragma Import
(C
, pthread_mutexattr_setprotocol
);
388 function pthread_mutexattr_setprioceiling
389 (attr
: access pthread_mutexattr_t
;
390 prioceiling
: int
) return int
;
391 pragma Import
(C
, pthread_mutexattr_setprioceiling
);
393 type Array_7_Int
is array (0 .. 6) of int
;
394 type struct_sched_param
is record
395 sched_priority
: int
;
396 sched_reserved
: Array_7_Int
;
399 function pthread_setschedparam
402 param
: access struct_sched_param
)
404 pragma Import
(C
, pthread_setschedparam
, "pthread_setschedparam");
406 function pthread_attr_setscope
407 (attr
: access pthread_attr_t
;
408 contentionscope
: int
) return int
;
409 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
411 function pthread_attr_setinheritsched
412 (attr
: access pthread_attr_t
;
413 inheritsched
: int
) return int
;
414 pragma Import
(C
, pthread_attr_setinheritsched
);
416 function pthread_attr_setschedpolicy
417 (attr
: access pthread_attr_t
;
418 policy
: int
) return int
;
419 pragma Import
(C
, pthread_attr_setschedpolicy
);
421 function sched_yield
return int
;
422 pragma Import
(C
, sched_yield
, "sched_yield");
424 ---------------------------
425 -- P1003.1c - Section 16 --
426 ---------------------------
428 function pthread_attr_init
429 (attributes
: access pthread_attr_t
) return int
;
430 pragma Import
(C
, pthread_attr_init
, "__pthread_attr_init_system");
432 function pthread_attr_destroy
433 (attributes
: access pthread_attr_t
) return int
;
434 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
436 function pthread_attr_setdetachstate
437 (attr
: access pthread_attr_t
;
438 detachstate
: int
) return int
;
439 pragma Import
(C
, pthread_attr_setdetachstate
);
441 function pthread_attr_setstacksize
442 (attr
: access pthread_attr_t
;
443 stacksize
: size_t
) return int
;
444 pragma Import
(C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
446 function pthread_create
447 (thread
: access pthread_t
;
448 attributes
: access pthread_attr_t
;
449 start_routine
: Thread_Body
;
450 arg
: System
.Address
) return int
;
451 pragma Import
(C
, pthread_create
, "__pthread_create_system");
453 procedure pthread_exit
(status
: System
.Address
);
454 pragma Import
(C
, pthread_exit
, "pthread_exit");
456 function pthread_self
return pthread_t
;
457 pragma Import
(C
, pthread_self
, "pthread_self");
459 --------------------------
460 -- POSIX.1c Section 17 --
461 --------------------------
463 function pthread_setspecific
464 (key
: pthread_key_t
;
465 value
: System
.Address
) return int
;
466 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
468 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
469 pragma Import
(C
, pthread_getspecific
, "pthread_getspecific");
471 type destructor_pointer
is access procedure (arg
: System
.Address
);
473 function pthread_key_create
474 (key
: access pthread_key_t
;
475 destructor
: destructor_pointer
) return int
;
476 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
480 type unsigned_int_array_8
is array (0 .. 7) of unsigned
;
481 type sigset_t
is record
482 sigset
: unsigned_int_array_8
;
484 pragma Convention
(C_Pass_By_Copy
, sigset_t
);
486 type pid_t
is new int
;
488 type time_t
is new long
;
490 type timespec
is record
494 pragma Convention
(C
, timespec
);
496 type clockid_t
is new int
;
497 CLOCK_REALTIME
: constant clockid_t
:= 1;
499 type struct_timeval
is record
503 pragma Convention
(C
, struct_timeval
);
505 type pthread_attr_t
is new int
;
506 type pthread_condattr_t
is new int
;
507 type pthread_mutexattr_t
is new int
;
508 type pthread_t
is new int
;
510 type short_array
is array (Natural range <>) of short
;
511 type int_array
is array (Natural range <>) of int
;
513 type pthread_mutex_t
is record
514 m_short
: short_array
(0 .. 1);
516 m_int1
: int_array
(0 .. 3);
517 m_pad
: int
; -- needed for 32 bit ABI, but *not* for 64 bit
518 m_ptr
: System
.Address
;
519 m_int2
: int_array
(0 .. 1);
520 m_int3
: int_array
(0 .. 3);
521 m_short2
: short_array
(0 .. 1);
522 m_int4
: int_array
(0 .. 4);
523 m_int5
: int_array
(0 .. 1);
525 pragma Convention
(C
, pthread_mutex_t
);
527 type pthread_cond_t
is record
528 c_short
: short_array
(0 .. 1);
530 c_int1
: int_array
(0 .. 3);
531 m_pad
: int
; -- needed for 32 bit ABI, but *not* for 64 bit
532 m_ptr
: System
.Address
;
533 c_int2
: int_array
(0 .. 1);
534 c_int3
: int_array
(0 .. 1);
535 c_int4
: int_array
(0 .. 1);
537 pragma Convention
(C
, pthread_cond_t
);
539 type pthread_key_t
is new int
;
541 end System
.OS_Interface
;