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) 1997-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 AIX (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
("-lpthreads");
49 pragma Linker_Options
("-lc_r");
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 := 78;
78 Max_Interrupt
: constant := 63;
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 := 30; -- user defined signal 1
99 SIGUSR2
: constant := 31; -- user defined signal 2
100 SIGCLD
: constant := 20; -- alias for SIGCHLD
101 SIGCHLD
: constant := 20; -- child status change
102 SIGPWR
: constant := 29; -- power-fail restart
103 SIGWINCH
: constant := 28; -- window size change
104 SIGURG
: constant := 16; -- urgent condition on IO channel
105 SIGPOLL
: constant := 23; -- pollable event occurred
106 SIGIO
: constant := 23; -- I/O possible (Solaris SIGPOLL alias)
107 SIGSTOP
: constant := 17; -- stop (cannot be caught or ignored)
108 SIGTSTP
: constant := 18; -- user stop requested from tty
109 SIGCONT
: constant := 19; -- stopped process has been continued
110 SIGTTIN
: constant := 21; -- background tty read attempted
111 SIGTTOU
: constant := 22; -- background tty write attempted
112 SIGVTALRM
: constant := 34; -- virtual timer expired
113 SIGPROF
: constant := 32; -- profiling timer expired
114 SIGXCPU
: constant := 24; -- CPU time limit exceeded
115 SIGXFSZ
: constant := 25; -- filesize limit exceeded
116 SIGWAITING
: constant := 39; -- m:n scheduling
118 -- the following signals are AIX specific
119 SIGMSG
: constant := 27; -- input data is in the ring buffer
120 SIGDANGER
: constant := 33; -- system crash imminent
121 SIGMIGRATE
: constant := 35; -- migrate process
122 SIGPRE
: constant := 36; -- programming exception
123 SIGVIRT
: constant := 37; -- AIX virtual time alarm
124 SIGALRM1
: constant := 38; -- m:n condition variables
125 SIGKAP
: constant := 60; -- keep alive poll from native keyboard
126 SIGGRANT
: constant := SIGKAP
; -- monitor mode granted
127 SIGRETRACT
: constant := 61; -- monitor mode should be relinguished
128 SIGSOUND
: constant := 62; -- sound control has completed
129 SIGSAK
: constant := 63; -- secure attention key
131 SIGADAABORT
: constant := SIGTERM
;
132 -- Note: on other targets, we usually use SIGABRT, but on AiX, it
133 -- appears that SIGABRT can't be used in sigwait(), so we use SIGTERM.
135 type Signal_Set
is array (Natural range <>) of Signal
;
137 Unmasked
: constant Signal_Set
:=
138 (SIGTRAP
, SIGTTIN
, SIGTTOU
, SIGTSTP
, SIGPROF
);
139 Reserved
: constant Signal_Set
:= (SIGABRT
, SIGKILL
, SIGSTOP
);
141 type sigset_t
is private;
143 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
144 pragma Import
(C
, sigaddset
, "sigaddset");
146 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
147 pragma Import
(C
, sigdelset
, "sigdelset");
149 function sigfillset
(set
: access sigset_t
) return int
;
150 pragma Import
(C
, sigfillset
, "sigfillset");
152 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
153 pragma Import
(C
, sigismember
, "sigismember");
155 function sigemptyset
(set
: access sigset_t
) return int
;
156 pragma Import
(C
, sigemptyset
, "sigemptyset");
158 type struct_sigaction
is record
159 sa_handler
: System
.Address
;
163 pragma Convention
(C
, struct_sigaction
);
164 type struct_sigaction_ptr
is access all struct_sigaction
;
167 SIG_BLOCK
: constant := 0;
168 SIG_UNBLOCK
: constant := 1;
169 SIG_SETMASK
: constant := 2;
171 SIG_DFL
: constant := 0;
172 SIG_IGN
: constant := 1;
176 act
: struct_sigaction_ptr
;
177 oact
: struct_sigaction_ptr
) return int
;
178 pragma Import
(C
, sigaction
, "sigaction");
184 Time_Slice_Supported
: constant Boolean := False;
185 -- Indicates wether time slicing is supported
187 type timespec
is private;
189 type clockid_t
is private;
191 CLOCK_REALTIME
: constant clockid_t
;
193 function clock_gettime
194 (clock_id
: clockid_t
;
195 tp
: access timespec
) return int
;
196 -- AiX threads don't have clock_gettime
197 -- We instead use gettimeofday()
199 function To_Duration
(TS
: timespec
) return Duration;
200 pragma Inline
(To_Duration
);
202 function To_Timespec
(D
: Duration) return timespec
;
203 pragma Inline
(To_Timespec
);
205 type struct_timezone
is record
206 tz_minuteswest
: int
;
209 pragma Convention
(C
, struct_timezone
);
210 type struct_timezone_ptr
is access all struct_timezone
;
212 type struct_timeval
is private;
213 -- This is needed on systems that do not have clock_gettime()
214 -- but do have gettimeofday().
216 function To_Duration
(TV
: struct_timeval
) return Duration;
217 pragma Inline
(To_Duration
);
219 function To_Timeval
(D
: Duration) return struct_timeval
;
220 pragma Inline
(To_Timeval
);
222 -------------------------
223 -- Priority Scheduling --
224 -------------------------
226 SCHED_FIFO
: constant := 1;
227 SCHED_RR
: constant := 2;
228 SCHED_OTHER
: constant := 0;
234 type pid_t
is private;
236 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
237 pragma Import
(C
, kill
, "kill");
239 function getpid
return pid_t
;
240 pragma Import
(C
, getpid
, "getpid");
246 function lwp_self
return System
.Address
;
247 pragma Import
(C
, lwp_self
, "thread_self");
253 type Thread_Body
is access
254 function (arg
: System
.Address
) return System
.Address
;
255 type pthread_t
is private;
256 subtype Thread_Id
is pthread_t
;
258 type pthread_mutex_t
is limited private;
259 type pthread_cond_t
is limited private;
260 type pthread_attr_t
is limited private;
261 type pthread_mutexattr_t
is limited private;
262 type pthread_condattr_t
is limited private;
263 type pthread_key_t
is private;
265 PTHREAD_CREATE_DETACHED
: constant := 1;
271 Stack_Base_Available
: constant Boolean := False;
272 -- Indicates wether the stack base is available on this target.
274 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
275 pragma Inline
(Get_Stack_Base
);
276 -- returns the stack base of the specified thread.
277 -- Only call this function when Stack_Base_Available is True.
279 function Get_Page_Size
return size_t
;
280 function Get_Page_Size
return Address
;
281 pragma Import
(C
, Get_Page_Size
, "getpagesize");
282 -- returns the size of a page, or 0 if this is not relevant on this
285 PROT_NONE
: constant := 0;
286 PROT_READ
: constant := 1;
287 PROT_WRITE
: constant := 2;
288 PROT_EXEC
: constant := 4;
289 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
;
291 PROT_ON
: constant := PROT_READ
;
292 PROT_OFF
: constant := PROT_ALL
;
294 function mprotect
(addr
: Address
; len
: size_t
; prot
: int
) return int
;
295 pragma Import
(C
, mprotect
);
297 ---------------------------------------
298 -- Nonstandard Thread Initialization --
299 ---------------------------------------
301 -- Though not documented, pthread_init *must* be called before any other
304 procedure pthread_init
;
305 pragma Import
(C
, pthread_init
, "pthread_init");
307 -------------------------
308 -- POSIX.1c Section 3 --
309 -------------------------
312 (set
: access sigset_t
;
313 sig
: access Signal
) return int
;
314 pragma Import
(C
, sigwait
, "sigwait");
316 function pthread_kill
318 sig
: Signal
) return int
;
319 pragma Import
(C
, pthread_kill
, "pthread_kill");
321 type sigset_t_ptr
is access all sigset_t
;
323 function pthread_sigmask
326 oset
: sigset_t_ptr
) return int
;
327 pragma Import
(C
, pthread_sigmask
, "sigthreadmask");
329 --------------------------
330 -- POSIX.1c Section 11 --
331 --------------------------
333 function pthread_mutexattr_init
334 (attr
: access pthread_mutexattr_t
) return int
;
335 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
337 function pthread_mutexattr_destroy
338 (attr
: access pthread_mutexattr_t
) return int
;
339 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
341 function pthread_mutex_init
342 (mutex
: access pthread_mutex_t
;
343 attr
: access pthread_mutexattr_t
) return int
;
344 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
346 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
347 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
349 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
350 pragma Import
(C
, pthread_mutex_lock
, "pthread_mutex_lock");
352 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
353 pragma Import
(C
, pthread_mutex_unlock
, "pthread_mutex_unlock");
355 function pthread_condattr_init
356 (attr
: access pthread_condattr_t
) return int
;
357 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
359 function pthread_condattr_destroy
360 (attr
: access pthread_condattr_t
) return int
;
361 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
363 function pthread_cond_init
364 (cond
: access pthread_cond_t
;
365 attr
: access pthread_condattr_t
) return int
;
366 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
368 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
369 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
371 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
372 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
374 function pthread_cond_wait
375 (cond
: access pthread_cond_t
;
376 mutex
: access pthread_mutex_t
) return int
;
377 pragma Import
(C
, pthread_cond_wait
, "pthread_cond_wait");
379 function pthread_cond_timedwait
380 (cond
: access pthread_cond_t
;
381 mutex
: access pthread_mutex_t
;
382 abstime
: access timespec
) return int
;
383 pragma Import
(C
, pthread_cond_timedwait
, "pthread_cond_timedwait");
385 Relative_Timed_Wait
: constant Boolean := False;
386 -- pthread_cond_timedwait requires an absolute delay time
388 ----------------------------
389 -- POSIX.1c Section 13 --
390 ----------------------------
392 PTHREAD_PRIO_NONE
: constant := 0;
393 PTHREAD_PRIO_PROTECT
: constant := 0;
394 PTHREAD_PRIO_INHERIT
: constant := 0;
396 function pthread_mutexattr_setprotocol
397 (attr
: access pthread_mutexattr_t
;
398 protocol
: int
) return int
;
399 pragma Import
(C
, pthread_mutexattr_setprotocol
);
401 function pthread_mutexattr_setprioceiling
402 (attr
: access pthread_mutexattr_t
;
403 prioceiling
: int
) return int
;
404 pragma Import
(C
, pthread_mutexattr_setprioceiling
);
406 type Array_5_Int
is array (0 .. 5) of int
;
407 type struct_sched_param
is record
408 sched_priority
: int
;
410 sched_reserved
: Array_5_Int
;
413 function pthread_setschedparam
416 param
: access struct_sched_param
) return int
;
417 pragma Import
(C
, pthread_setschedparam
, "pthread_setschedparam");
419 function pthread_attr_setscope
420 (attr
: access pthread_attr_t
;
421 contentionscope
: int
) return int
;
422 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
424 function pthread_attr_setinheritsched
425 (attr
: access pthread_attr_t
;
426 inheritsched
: int
) return int
;
427 pragma Import
(C
, pthread_attr_setinheritsched
);
429 function pthread_attr_setschedpolicy
430 (attr
: access pthread_attr_t
;
431 policy
: int
) return int
;
432 pragma Import
(C
, pthread_attr_setschedpolicy
);
434 function pthread_attr_setschedparam
435 (attr
: access pthread_attr_t
;
436 sched_param
: int
) return int
;
437 pragma Import
(C
, pthread_attr_setschedparam
);
439 function sched_yield
return int
;
440 -- AiX have a nonstandard sched_yield.
442 ---------------------------
443 -- P1003.1c - Section 16 --
444 ---------------------------
446 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
447 pragma Import
(C
, pthread_attr_init
, "pthread_attr_init");
449 function pthread_attr_destroy
450 (attributes
: access pthread_attr_t
) return int
;
451 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
453 function pthread_attr_setdetachstate
454 (attr
: access pthread_attr_t
;
455 detachstate
: int
) return int
;
456 pragma Import
(C
, pthread_attr_setdetachstate
);
458 function pthread_attr_setstacksize
459 (attr
: access pthread_attr_t
;
460 stacksize
: size_t
) return int
;
461 pragma Import
(C
, pthread_attr_setstacksize
);
463 function pthread_create
464 (thread
: access pthread_t
;
465 attributes
: access pthread_attr_t
;
466 start_routine
: Thread_Body
;
467 arg
: System
.Address
)
469 pragma Import
(C
, pthread_create
, "pthread_create");
471 procedure pthread_exit
(status
: System
.Address
);
472 pragma Import
(C
, pthread_exit
, "pthread_exit");
474 function pthread_self
return pthread_t
;
475 pragma Import
(C
, pthread_self
, "pthread_self");
477 --------------------------
478 -- POSIX.1c Section 17 --
479 --------------------------
481 function pthread_setspecific
482 (key
: pthread_key_t
;
483 value
: System
.Address
) return int
;
484 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
486 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
487 pragma Import
(C
, pthread_getspecific
, "pthread_getspecific");
489 type destructor_pointer
is access
490 procedure (arg
: System
.Address
);
492 function pthread_key_create
493 (key
: access pthread_key_t
;
494 destructor
: destructor_pointer
) return int
;
495 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
499 type sigset_t
is record
500 losigs
: unsigned_long
;
501 hisigs
: unsigned_long
;
503 pragma Convention
(C_Pass_By_Copy
, sigset_t
);
505 type pid_t
is new int
;
507 type time_t
is new long
;
509 type timespec
is record
513 pragma Convention
(C
, timespec
);
515 type clockid_t
is new int
;
516 CLOCK_REALTIME
: constant clockid_t
:= 0;
518 type struct_timeval
is record
522 pragma Convention
(C
, struct_timeval
);
524 type pthread_attr_t
is new System
.Address
;
525 pragma Convention
(C
, pthread_attr_t
);
526 -- typedef struct __pt_attr *pthread_attr_t;
528 type pthread_condattr_t
is new System
.Address
;
529 pragma Convention
(C
, pthread_condattr_t
);
530 -- typedef struct __pt_attr *pthread_condattr_t;
532 type pthread_mutexattr_t
is new System
.Address
;
533 pragma Convention
(C
, pthread_mutexattr_t
);
534 -- typedef struct __pt_attr *pthread_mutexattr_t;
536 type pthread_t
is new System
.Address
;
537 pragma Convention
(C
, pthread_t
);
538 -- typedef void *pthread_t;
541 type ptq_queue_ptr
is access all ptq_queue
;
543 type ptq_queue
is record
544 ptq_next
: ptq_queue_ptr
;
545 ptq_prev
: ptq_queue_ptr
;
548 type Array_3_Int
is array (0 .. 3) of int
;
549 type pthread_mutex_t
is record
555 ptmtx_owner
: pthread_t
;
557 attr
: pthread_attr_t
;
560 reserved
: Array_3_Int
;
562 pragma Convention
(C
, pthread_mutex_t
);
563 type pthread_mutex_t_ptr
is access pthread_mutex_t
;
565 type pthread_cond_t
is record
569 ptcv_waiters
: ptq_queue
;
571 attr
: pthread_attr_t
;
572 mutex
: pthread_mutex_t_ptr
;
576 pragma Convention
(C
, pthread_cond_t
);
578 type pthread_key_t
is new unsigned
;
580 end System
.OS_Interface
;