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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This is a HPUX 11.0 (Native THREADS) version of this package.
38 -- This package encapsulates all direct interfaces to OS services
39 -- that are needed by children of System.
41 -- PLEASE DO NOT add any with-clauses to this package
42 -- or remove the pragma Elaborate_Body.
43 -- It is designed to be a bottom-level (leaf) package.
46 package System
.OS_Interface
is
49 pragma Linker_Options
("-lpthread");
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
;
65 function errno
return int
;
66 pragma Import
(C
, errno
, "__get_errno");
68 EAGAIN
: constant := 11;
69 EINTR
: constant := 4;
70 EINVAL
: constant := 22;
71 ENOMEM
: constant := 12;
72 ETIMEDOUT
: constant := 238;
78 Max_Interrupt
: constant := 44;
79 type Signal
is new int
range 0 .. Max_Interrupt
;
80 for Signal
'Size use int
'Size;
82 SIGHUP
: constant := 1; -- hangup
83 SIGINT
: constant := 2; -- interrupt (rubout)
84 SIGQUIT
: constant := 3; -- quit (ASCD FS)
85 SIGILL
: constant := 4; -- illegal instruction (not reset)
86 SIGTRAP
: constant := 5; -- trace trap (not reset)
87 SIGIOT
: constant := 6; -- IOT instruction
88 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
89 SIGEMT
: constant := 7; -- EMT instruction
90 SIGFPE
: constant := 8; -- floating point exception
91 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
92 SIGBUS
: constant := 10; -- bus error
93 SIGSEGV
: constant := 11; -- segmentation violation
94 SIGSYS
: constant := 12; -- bad argument to system call
95 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
96 SIGALRM
: constant := 14; -- alarm clock
97 SIGTERM
: constant := 15; -- software termination signal from kill
98 SIGUSR1
: constant := 16; -- user defined signal 1
99 SIGUSR2
: constant := 17; -- user defined signal 2
100 SIGCLD
: constant := 18; -- alias for SIGCHLD
101 SIGCHLD
: constant := 18; -- child status change
102 SIGPWR
: constant := 19; -- power-fail restart
103 SIGVTALRM
: constant := 20; -- virtual timer alarm
104 SIGPROF
: constant := 21; -- profiling timer alarm
105 SIGIO
: constant := 22; -- asynchronous I/O
106 SIGPOLL
: constant := 22; -- pollable event occurred
107 SIGWINCH
: constant := 23; -- window size change
108 SIGSTOP
: constant := 24; -- stop (cannot be caught or ignored)
109 SIGTSTP
: constant := 25; -- user stop requested from tty
110 SIGCONT
: constant := 26; -- stopped process has been continued
111 SIGTTIN
: constant := 27; -- background tty read attempted
112 SIGTTOU
: constant := 28; -- background tty write attempted
113 SIGURG
: constant := 29; -- urgent condition on IO channel
114 SIGLOST
: constant := 30; -- remote lock lost (NFS)
115 SIGDIL
: constant := 32; -- DIL signal
116 SIGXCPU
: constant := 33; -- CPU time limit exceeded (setrlimit)
117 SIGXFSZ
: constant := 34; -- file size limit exceeded (setrlimit)
118 SIGCANCEL
: constant := 35; -- used for pthread cancellation.
119 SIGGFAULT
: constant := 36; -- Graphics framebuffer fault
121 SIGADAABORT
: constant := SIGABRT
;
122 -- Note: on other targets, we usually use SIGABRT, but on HPUX, it
123 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
125 type Signal_Set
is array (Natural range <>) of Signal
;
127 Unmasked
: constant Signal_Set
:=
128 (SIGABRT
, SIGPIPE
, SIGBUS
, SIGTRAP
, SIGTTIN
, SIGTTOU
, SIGTSTP
, SIGPROF
,
129 SIGALRM
, SIGVTALRM
, SIGIO
, SIGCHLD
);
131 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
);
133 type sigset_t
is private;
135 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
136 pragma Import
(C
, sigaddset
, "sigaddset");
138 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
139 pragma Import
(C
, sigdelset
, "sigdelset");
141 function sigfillset
(set
: access sigset_t
) return int
;
142 pragma Import
(C
, sigfillset
, "sigfillset");
144 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
145 pragma Import
(C
, sigismember
, "sigismember");
147 function sigemptyset
(set
: access sigset_t
) return int
;
148 pragma Import
(C
, sigemptyset
, "sigemptyset");
150 type struct_sigaction
is record
151 sa_handler
: System
.Address
;
155 pragma Convention
(C
, struct_sigaction
);
156 type struct_sigaction_ptr
is access all struct_sigaction
;
158 SIG_BLOCK
: constant := 0;
159 SIG_UNBLOCK
: constant := 1;
160 SIG_SETMASK
: constant := 2;
162 SIG_DFL
: constant := 0;
163 SIG_IGN
: constant := 1;
167 act
: struct_sigaction_ptr
;
168 oact
: struct_sigaction_ptr
) return int
;
169 pragma Import
(C
, sigaction
, "sigaction");
175 Time_Slice_Supported
: constant Boolean := True;
176 -- Indicates wether time slicing is supported
178 type timespec
is private;
180 type clockid_t
is private;
182 CLOCK_REALTIME
: constant clockid_t
;
184 function clock_gettime
185 (clock_id
: clockid_t
;
186 tp
: access timespec
) return int
;
187 pragma Import
(C
, clock_gettime
, "clock_gettime");
189 function To_Duration
(TS
: timespec
) return Duration;
190 pragma Inline
(To_Duration
);
192 function To_Timespec
(D
: Duration) return timespec
;
193 pragma Inline
(To_Timespec
);
195 type struct_timezone
is record
196 tz_minuteswest
: int
;
199 pragma Convention
(C
, struct_timezone
);
200 type struct_timezone_ptr
is access all struct_timezone
;
202 type struct_timeval
is private;
203 -- This is needed on systems that do not have clock_gettime()
204 -- but do have gettimeofday().
206 function To_Duration
(TV
: struct_timeval
) return Duration;
207 pragma Inline
(To_Duration
);
209 function To_Timeval
(D
: Duration) return struct_timeval
;
210 pragma Inline
(To_Timeval
);
212 -------------------------
213 -- Priority Scheduling --
214 -------------------------
216 SCHED_FIFO
: constant := 0;
217 SCHED_RR
: constant := 1;
218 SCHED_OTHER
: constant := 2;
224 type pid_t
is private;
226 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
227 pragma Import
(C
, kill
, "kill");
229 function getpid
return pid_t
;
230 pragma Import
(C
, getpid
, "getpid");
236 function lwp_self
return System
.Address
;
237 pragma Import
(C
, lwp_self
, "_lwp_self");
243 type Thread_Body
is access
244 function (arg
: System
.Address
) return System
.Address
;
245 type pthread_t
is private;
246 subtype Thread_Id
is pthread_t
;
248 type pthread_mutex_t
is limited private;
249 type pthread_cond_t
is limited private;
250 type pthread_attr_t
is limited private;
251 type pthread_mutexattr_t
is limited private;
252 type pthread_condattr_t
is limited private;
253 type pthread_key_t
is private;
255 PTHREAD_CREATE_DETACHED
: constant := 16#de#
;
261 Stack_Base_Available
: constant Boolean := False;
262 -- Indicates wether the stack base is available on this target.
264 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
265 pragma Inline
(Get_Stack_Base
);
266 -- returns the stack base of the specified thread.
267 -- Only call this function when Stack_Base_Available is True.
269 function Get_Page_Size
return size_t
;
270 function Get_Page_Size
return Address
;
271 pragma Import
(C
, Get_Page_Size
, "getpagesize");
272 -- returns the size of a page, or 0 if this is not relevant on this
275 PROT_NONE
: constant := 0;
276 PROT_READ
: constant := 1;
277 PROT_WRITE
: constant := 2;
278 PROT_EXEC
: constant := 4;
279 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
;
281 PROT_ON
: constant := PROT_READ
;
282 PROT_OFF
: constant := PROT_ALL
;
284 function mprotect
(addr
: Address
; len
: size_t
; prot
: int
) return int
;
285 pragma Import
(C
, mprotect
);
287 ---------------------------------------
288 -- Nonstandard Thread Initialization --
289 ---------------------------------------
291 procedure pthread_init
;
292 pragma Inline
(pthread_init
);
293 -- This is a dummy procedure to share some GNULLI files
295 -------------------------
296 -- POSIX.1c Section 3 --
297 -------------------------
300 (set
: access sigset_t
;
301 sig
: access Signal
) return int
;
302 pragma Import
(C
, sigwait
, "sigwait");
304 function pthread_kill
306 sig
: Signal
) return int
;
307 pragma Import
(C
, pthread_kill
, "pthread_kill");
309 type sigset_t_ptr
is access all sigset_t
;
311 function pthread_sigmask
314 oset
: sigset_t_ptr
) return int
;
315 pragma Import
(C
, pthread_sigmask
, "pthread_sigmask");
317 --------------------------
318 -- POSIX.1c Section 11 --
319 --------------------------
321 function pthread_mutexattr_init
322 (attr
: access pthread_mutexattr_t
) return int
;
323 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
325 function pthread_mutexattr_destroy
326 (attr
: access pthread_mutexattr_t
) return int
;
327 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
329 function pthread_mutex_init
330 (mutex
: access pthread_mutex_t
;
331 attr
: access pthread_mutexattr_t
) return int
;
332 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
334 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
335 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
337 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
338 pragma Import
(C
, pthread_mutex_lock
, "pthread_mutex_lock");
340 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
341 pragma Import
(C
, pthread_mutex_unlock
, "pthread_mutex_unlock");
343 function pthread_condattr_init
344 (attr
: access pthread_condattr_t
) return int
;
345 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
347 function pthread_condattr_destroy
348 (attr
: access pthread_condattr_t
) return int
;
349 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
351 function pthread_cond_init
352 (cond
: access pthread_cond_t
;
353 attr
: access pthread_condattr_t
) return int
;
354 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
356 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
357 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
359 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
360 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
362 function pthread_cond_wait
363 (cond
: access pthread_cond_t
;
364 mutex
: access pthread_mutex_t
) return int
;
365 pragma Import
(C
, pthread_cond_wait
, "pthread_cond_wait");
367 function pthread_cond_timedwait
368 (cond
: access pthread_cond_t
;
369 mutex
: access pthread_mutex_t
;
370 abstime
: access timespec
) return int
;
371 pragma Import
(C
, pthread_cond_timedwait
, "pthread_cond_timedwait");
373 Relative_Timed_Wait
: constant Boolean := False;
374 -- pthread_cond_timedwait requires an absolute delay time
376 ----------------------------
377 -- POSIX.1c Section 13 --
378 ----------------------------
380 PTHREAD_PRIO_NONE
: constant := 16#
100#
;
381 PTHREAD_PRIO_PROTECT
: constant := 16#
200#
;
382 PTHREAD_PRIO_INHERIT
: constant := 16#
400#
;
384 function pthread_mutexattr_setprotocol
385 (attr
: access pthread_mutexattr_t
;
386 protocol
: int
) return int
;
387 pragma Import
(C
, pthread_mutexattr_setprotocol
);
389 function pthread_mutexattr_setprioceiling
390 (attr
: access pthread_mutexattr_t
;
391 prioceiling
: int
) return int
;
392 pragma Import
(C
, pthread_mutexattr_setprioceiling
);
394 type Array_7_Int
is array (0 .. 6) of int
;
395 type struct_sched_param
is record
396 sched_priority
: int
;
397 sched_reserved
: Array_7_Int
;
400 function pthread_setschedparam
403 param
: access struct_sched_param
)
405 pragma Import
(C
, pthread_setschedparam
, "pthread_setschedparam");
407 function pthread_attr_setscope
408 (attr
: access pthread_attr_t
;
409 contentionscope
: int
) return int
;
410 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
412 function pthread_attr_setinheritsched
413 (attr
: access pthread_attr_t
;
414 inheritsched
: int
) return int
;
415 pragma Import
(C
, pthread_attr_setinheritsched
);
417 function pthread_attr_setschedpolicy
418 (attr
: access pthread_attr_t
;
419 policy
: int
) return int
;
420 pragma Import
(C
, pthread_attr_setschedpolicy
);
422 function sched_yield
return int
;
423 pragma Import
(C
, sched_yield
, "sched_yield");
425 ---------------------------
426 -- P1003.1c - Section 16 --
427 ---------------------------
429 function pthread_attr_init
430 (attributes
: access pthread_attr_t
) return int
;
431 pragma Import
(C
, pthread_attr_init
, "__pthread_attr_init_system");
433 function pthread_attr_destroy
434 (attributes
: access pthread_attr_t
) return int
;
435 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
437 function pthread_attr_setdetachstate
438 (attr
: access pthread_attr_t
;
439 detachstate
: int
) return int
;
440 pragma Import
(C
, pthread_attr_setdetachstate
);
442 function pthread_attr_setstacksize
443 (attr
: access pthread_attr_t
;
444 stacksize
: size_t
) return int
;
445 pragma Import
(C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
447 function pthread_create
448 (thread
: access pthread_t
;
449 attributes
: access pthread_attr_t
;
450 start_routine
: Thread_Body
;
451 arg
: System
.Address
) return int
;
452 pragma Import
(C
, pthread_create
, "__pthread_create_system");
454 procedure pthread_exit
(status
: System
.Address
);
455 pragma Import
(C
, pthread_exit
, "pthread_exit");
457 function pthread_self
return pthread_t
;
458 pragma Import
(C
, pthread_self
, "pthread_self");
460 --------------------------
461 -- POSIX.1c Section 17 --
462 --------------------------
464 function pthread_setspecific
465 (key
: pthread_key_t
;
466 value
: System
.Address
) return int
;
467 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
469 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
470 pragma Import
(C
, pthread_getspecific
, "pthread_getspecific");
472 type destructor_pointer
is access procedure (arg
: System
.Address
);
474 function pthread_key_create
475 (key
: access pthread_key_t
;
476 destructor
: destructor_pointer
) return int
;
477 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
481 type unsigned_int_array_8
is array (0 .. 7) of unsigned
;
482 type sigset_t
is record
483 sigset
: unsigned_int_array_8
;
485 pragma Convention
(C_Pass_By_Copy
, sigset_t
);
487 type pid_t
is new int
;
489 type time_t
is new long
;
491 type timespec
is record
495 pragma Convention
(C
, timespec
);
497 type clockid_t
is new int
;
498 CLOCK_REALTIME
: constant clockid_t
:= 1;
500 type struct_timeval
is record
504 pragma Convention
(C
, struct_timeval
);
506 type pthread_attr_t
is new int
;
507 type pthread_condattr_t
is new int
;
508 type pthread_mutexattr_t
is new int
;
509 type pthread_t
is new int
;
511 type short_array
is array (Natural range <>) of short
;
512 type int_array
is array (Natural range <>) of int
;
514 type pthread_mutex_t
is record
515 m_short
: short_array
(0 .. 1);
517 m_int1
: int_array
(0 .. 3);
518 m_pad
: int
; -- needed for 32 bit ABI, but *not* for 64 bit
519 m_ptr
: System
.Address
;
520 m_int2
: int_array
(0 .. 1);
521 m_int3
: int_array
(0 .. 3);
522 m_short2
: short_array
(0 .. 1);
523 m_int4
: int_array
(0 .. 4);
524 m_int5
: int_array
(0 .. 1);
526 pragma Convention
(C
, pthread_mutex_t
);
528 type pthread_cond_t
is record
529 c_short
: short_array
(0 .. 1);
531 c_int1
: int_array
(0 .. 3);
532 m_pad
: int
; -- needed for 32 bit ABI, but *not* for 64 bit
533 m_ptr
: System
.Address
;
534 c_int2
: int_array
(0 .. 1);
535 c_int3
: int_array
(0 .. 1);
536 c_int4
: int_array
(0 .. 1);
538 pragma Convention
(C
, pthread_cond_t
);
540 type pthread_key_t
is new int
;
542 end System
.OS_Interface
;