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 --
9 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2004, 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 Darwin pthreads version of this package.
37 -- This package includes 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 subtype int
is Interfaces
.C
.int
;
49 subtype short
is Interfaces
.C
.short
;
50 subtype long
is Interfaces
.C
.long
;
51 subtype unsigned
is Interfaces
.C
.unsigned
;
52 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
53 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
54 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
55 subtype plain_char
is Interfaces
.C
.plain_char
;
56 subtype size_t
is Interfaces
.C
.size_t
;
62 function errno
return int
;
63 pragma Import
(C
, errno
, "__get_errno");
65 EINTR
: constant := 4;
66 ENOMEM
: constant := 12;
67 EINVAL
: constant := 22;
68 EAGAIN
: constant := 35;
69 ETIMEDOUT
: constant := 60;
75 Max_Interrupt
: constant := 31;
76 type Signal
is new int
range 0 .. Max_Interrupt
;
77 for Signal
'Size use int
'Size;
79 SIGHUP
: constant := 1; -- hangup
80 SIGINT
: constant := 2; -- interrupt (rubout)
81 SIGQUIT
: constant := 3; -- quit (ASCD FS)
82 SIGILL
: constant := 4; -- illegal instruction (not reset)
83 SIGTRAP
: constant := 5; -- trace trap (not reset)
84 SIGIOT
: constant := 6; -- IOT instruction
85 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
86 SIGEMT
: constant := 7; -- EMT instruction
87 SIGFPE
: constant := 8; -- floating point exception
88 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
89 SIGBUS
: constant := 10; -- bus error
90 SIGSEGV
: constant := 11; -- segmentation violation
91 SIGSYS
: constant := 12; -- bad argument to system call
92 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
93 SIGALRM
: constant := 14; -- alarm clock
94 SIGTERM
: constant := 15; -- software termination signal from kill
95 SIGURG
: constant := 16; -- urgent condition on IO channel
96 SIGSTOP
: constant := 17; -- stop (cannot be caught or ignored)
97 SIGTSTP
: constant := 18; -- user stop requested from tty
98 SIGCONT
: constant := 19; -- stopped process has been continued
99 SIGCHLD
: constant := 20; -- child status change
100 SIGTTIN
: constant := 21; -- background tty read attempted
101 SIGTTOU
: constant := 22; -- background tty write attempted
102 SIGIO
: constant := 23; -- I/O possible (Solaris SIGPOLL alias)
103 SIGXCPU
: constant := 24; -- CPU time limit exceeded
104 SIGXFSZ
: constant := 25; -- filesize limit exceeded
105 SIGVTALRM
: constant := 26; -- virtual timer expired
106 SIGPROF
: constant := 27; -- profiling timer expired
107 SIGWINCH
: constant := 28; -- window size change
108 SIGINFO
: constant := 29; -- information request
109 SIGUSR1
: constant := 30; -- user defined signal 1
110 SIGUSR2
: constant := 31; -- user defined signal 2
112 SIGADAABORT
: constant := SIGABRT
;
113 -- Change this if you want to use another signal for task abort.
114 -- SIGTERM might be a good one.
116 type Signal_Set
is array (Natural range <>) of Signal
;
118 Unmasked
: constant Signal_Set
:=
119 (SIGTTIN
, SIGTTOU
, SIGSTOP
, SIGTSTP
);
121 Reserved
: constant Signal_Set
:=
124 type sigset_t
is private;
126 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
127 pragma Import
(C
, sigaddset
, "sigaddset");
129 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
130 pragma Import
(C
, sigdelset
, "sigdelset");
132 function sigfillset
(set
: access sigset_t
) return int
;
133 pragma Import
(C
, sigfillset
, "sigfillset");
135 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
136 pragma Import
(C
, sigismember
, "sigismember");
138 function sigemptyset
(set
: access sigset_t
) return int
;
139 pragma Import
(C
, sigemptyset
, "sigemptyset");
141 type siginfo_t
is private;
142 type ucontext_t
is private;
144 type Signal_Handler
is access procedure
146 info
: access siginfo_t
;
147 context
: access ucontext_t
);
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 := 1;
158 SIG_UNBLOCK
: constant := 2;
159 SIG_SETMASK
: constant := 3;
161 SIG_DFL
: constant := 0;
162 SIG_IGN
: constant := 1;
164 SA_SIGINFO
: constant := 16#
0040#
;
168 act
: struct_sigaction_ptr
;
169 oact
: struct_sigaction_ptr
) return int
;
170 pragma Import
(C
, sigaction
, "sigaction");
176 Time_Slice_Supported
: constant Boolean := True;
177 -- Indicates wether time slicing is supported.
179 type timespec
is private;
181 type clockid_t
is private;
183 CLOCK_REALTIME
: constant clockid_t
;
185 function clock_gettime
186 (clock_id
: clockid_t
;
187 tp
: access timespec
) return int
;
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_timeval
is private;
197 function To_Duration
(TV
: struct_timeval
) return Duration;
198 pragma Inline
(To_Duration
);
200 function To_Timeval
(D
: Duration) return struct_timeval
;
201 pragma Inline
(To_Timeval
);
203 -------------------------
204 -- Priority Scheduling --
205 -------------------------
207 SCHED_OTHER
: constant := 1;
208 SCHED_RR
: constant := 2;
209 SCHED_FIFO
: constant := 4;
215 type pid_t
is private;
217 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
218 pragma Import
(C
, kill
, "kill");
220 function getpid
return pid_t
;
221 pragma Import
(C
, getpid
, "getpid");
227 function lwp_self
return System
.Address
;
228 -- lwp_self does not exist on this thread library, revert to pthread_self
229 -- which is the closest approximation (with getpid). This function is
230 -- needed to share 7staprop.adb across POSIX-like targets.
231 pragma Import
(C
, lwp_self
, "pthread_self");
237 type Thread_Body
is access
238 function (arg
: System
.Address
) return System
.Address
;
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 type pthread_mutex_ptr
is access all pthread_mutex_t
;
250 type pthread_cond_ptr
is access all pthread_cond_t
;
252 PTHREAD_CREATE_DETACHED
: constant := 2;
258 Stack_Base_Available
: constant Boolean := False;
259 -- Indicates wether the stack base is available on this target.
260 -- This allows us to share s-osinte.adb between all the FSU run time.
261 -- Note that this value can only be true if pthread_t has a complete
262 -- definition that corresponds exactly to the C header files.
264 function Get_Stack_Base
(thread
: pthread_t
) return System
.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 System
.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_NONE
;
282 PROT_OFF
: constant := PROT_ALL
;
284 function mprotect
(addr
: System
.Address
;
286 prot
: int
) return int
;
287 pragma Import
(C
, mprotect
);
289 ---------------------------------------
290 -- Nonstandard Thread Initialization --
291 ---------------------------------------
293 procedure pthread_init
;
295 -------------------------
296 -- POSIX.1c Section 3 --
297 -------------------------
299 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
300 pragma Import
(C
, sigwait
, "sigwait");
302 function pthread_kill
(thread
: pthread_t
; sig
: Signal
) return int
;
303 pragma Import
(C
, pthread_kill
, "pthread_kill");
305 type sigset_t_ptr
is access all sigset_t
;
307 function pthread_sigmask
310 oset
: sigset_t_ptr
) return int
;
311 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
313 --------------------------
314 -- POSIX.1c Section 11 --
315 --------------------------
317 function pthread_mutexattr_init
318 (attr
: access pthread_mutexattr_t
) return int
;
319 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
321 function pthread_mutexattr_destroy
322 (attr
: access pthread_mutexattr_t
) return int
;
323 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
325 function pthread_mutex_init
326 (mutex
: access pthread_mutex_t
;
327 attr
: access pthread_mutexattr_t
) return int
;
328 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
330 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
331 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
333 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
334 pragma Import
(C
, pthread_mutex_lock
, "pthread_mutex_lock");
336 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
337 pragma Import
(C
, pthread_mutex_unlock
, "pthread_mutex_unlock");
339 function pthread_condattr_init
340 (attr
: access pthread_condattr_t
) return int
;
341 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
343 function pthread_condattr_destroy
344 (attr
: access pthread_condattr_t
) return int
;
345 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
347 function pthread_cond_init
348 (cond
: access pthread_cond_t
;
349 attr
: access pthread_condattr_t
) return int
;
350 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
352 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
353 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
355 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
356 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
358 function pthread_cond_wait
359 (cond
: access pthread_cond_t
;
360 mutex
: access pthread_mutex_t
) return int
;
361 pragma Import
(C
, pthread_cond_wait
, "pthread_cond_wait");
363 function pthread_cond_timedwait
364 (cond
: access pthread_cond_t
;
365 mutex
: access pthread_mutex_t
;
366 abstime
: access timespec
) return int
;
367 pragma Import
(C
, pthread_cond_timedwait
, "pthread_cond_timedwait");
369 Relative_Timed_Wait
: constant Boolean := False;
370 -- pthread_cond_timedwait requires an absolute delay time
372 --------------------------
373 -- POSIX.1c Section 13 --
374 --------------------------
376 PTHREAD_PRIO_NONE
: constant := 0;
377 PTHREAD_PRIO_INHERIT
: constant := 1;
378 PTHREAD_PRIO_PROTECT
: constant := 2;
380 function pthread_mutexattr_setprotocol
381 (attr
: access pthread_mutexattr_t
;
382 protocol
: int
) return int
;
384 (C
, pthread_mutexattr_setprotocol
, "pthread_mutexattr_setprotocol");
386 function pthread_mutexattr_setprioceiling
387 (attr
: access pthread_mutexattr_t
;
388 prioceiling
: int
) return int
;
390 (C
, pthread_mutexattr_setprioceiling
,
391 "pthread_mutexattr_setprioceiling");
393 type struct_sched_param
is record
394 sched_priority
: int
; -- scheduling priority
397 function pthread_setschedparam
400 param
: access struct_sched_param
) return int
;
401 pragma Import
(C
, pthread_setschedparam
, "pthread_setschedparam");
403 function pthread_attr_setscope
404 (attr
: access pthread_attr_t
;
405 contentionscope
: int
) return int
;
406 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
408 function pthread_attr_setinheritsched
409 (attr
: access pthread_attr_t
;
410 inheritsched
: int
) return int
;
412 (C
, pthread_attr_setinheritsched
, "pthread_attr_setinheritsched");
414 function pthread_attr_setschedpolicy
415 (attr
: access pthread_attr_t
;
416 policy
: int
) return int
;
417 pragma Import
(C
, pthread_attr_setschedpolicy
, "pthread_attr_setsched");
419 function sched_yield
return int
;
421 ---------------------------
422 -- P1003.1c - Section 16 --
423 ---------------------------
425 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
426 pragma Import
(C
, pthread_attr_init
, "pthread_attr_init");
428 function pthread_attr_destroy
429 (attributes
: access pthread_attr_t
) return int
;
430 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
432 function pthread_attr_setdetachstate
433 (attr
: access pthread_attr_t
;
434 detachstate
: int
) return int
;
436 (C
, pthread_attr_setdetachstate
, "pthread_attr_setdetachstate");
438 function pthread_attr_setstacksize
439 (attr
: access pthread_attr_t
;
440 stacksize
: size_t
) return int
;
442 (C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
444 function pthread_create
445 (thread
: access pthread_t
;
446 attributes
: access pthread_attr_t
;
447 start_routine
: Thread_Body
;
448 arg
: System
.Address
) return int
;
449 pragma Import
(C
, pthread_create
, "pthread_create");
451 procedure pthread_exit
(status
: System
.Address
);
452 pragma Import
(C
, pthread_exit
, "pthread_exit");
454 function pthread_self
return pthread_t
;
455 pragma Import
(C
, pthread_self
, "pthread_self");
457 --------------------------
458 -- POSIX.1c Section 17 --
459 --------------------------
461 function pthread_setspecific
462 (key
: pthread_key_t
;
463 value
: System
.Address
) return int
;
464 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
466 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
467 pragma Import
(C
, pthread_getspecific
, "pthread_getspecific");
469 type destructor_pointer
is access procedure (arg
: System
.Address
);
471 function pthread_key_create
472 (key
: access pthread_key_t
;
473 destructor
: destructor_pointer
) return int
;
474 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
478 type array_type_1
is array (Integer range 0 .. 3) of unsigned_long
;
479 type sigset_t
is record
480 X_X_sigbits
: array_type_1
;
482 pragma Convention
(C
, sigset_t
);
484 type pid_t
is new long
;
486 type time_t
is new long
;
488 type timespec
is record
492 pragma Convention
(C
, timespec
);
494 type clockid_t
is new int
;
495 CLOCK_REALTIME
: constant clockid_t
:= 0;
497 type struct_timeval
is record
501 pragma Convention
(C
, struct_timeval
);
504 -- Darwin specific signal implementation
506 type Pad_Type
is array (0 .. 7) of int
;
507 type siginfo_t
is record
508 si_signo
: int
; -- signal number
509 si_errno
: int
; -- errno association
510 si_code
: int
; -- signal code
511 si_pid
: int
; -- sending process
512 si_uid
: unsigned
; -- sender's ruid
513 si_status
: int
; -- exit value
514 si_addr
: System
.Address
; -- faulting instruction
515 si_value
: System
.Address
; -- signal value
516 si_band
: long
; -- band event for SIGPOLL
517 pad
: Pad_Type
; -- RFU
519 pragma Convention
(C
, siginfo_t
);
521 type stack_t
is record
522 ss_sp
: System
.Address
;
526 pragma Convention
(C
, stack_t
);
528 type mcontext_t
is new System
.Address
;
530 type ucontext_t
is record
532 uc_sigmask
: sigset_t
; -- Signal Mask Used By This Context
533 uc_stack
: stack_t
; -- Stack Used By This Context
534 uc_link
: System
.Address
; -- Pointer To Resuming Context
535 uc_mcsize
: size_t
; -- Size of The Machine Context
536 uc_mcontext
: mcontext_t
; -- Machine Specific Context
538 pragma Convention
(C
, ucontext_t
);
541 -- Darwin specific pthread implementation
543 type pthread_t
is new System
.Address
;
545 type pthread_lock_t
is new long
;
547 type sched_param_pad
is array (0 .. 3) of plain_char
;
548 type sched_param
is record
549 sched_priority
: int
;
550 opaque
: sched_param_pad
;
552 pragma Convention
(C
, sched_param
);
553 type boolean_t
is new int
;
555 type pthread_attr_t
is record
557 lock
: pthread_lock_t
;
562 stackaddr
: System
.Address
;
564 freeStackOnExit
: boolean_t
;
566 pragma Convention
(C
, pthread_attr_t
);
568 type pthread_mutexattr_t
is record
573 pragma Convention
(C
, pthread_mutexattr_t
);
575 type mach_port_t
is new unsigned_long
;
577 type pthread_mutex_t
is record
579 lock
: pthread_lock_t
;
584 next
: pthread_mutex_ptr
;
585 prev
: pthread_mutex_ptr
;
586 busy
: pthread_cond_ptr
;
590 pragma Convention
(C
, pthread_mutex_t
);
592 type pthread_condattr_t
is record
596 pragma Convention
(C
, pthread_condattr_t
);
598 type pthread_cond_t
is record
600 lock
: pthread_lock_t
;
602 next
: pthread_cond_ptr
;
603 prev
: pthread_cond_ptr
;
604 busy
: pthread_mutex_ptr
;
608 pragma Convention
(C
, pthread_cond_t
);
610 type pthread_once_t
is record
612 lock
: pthread_lock_t
;
614 pragma Convention
(C
, pthread_once_t
);
616 type rwlockattr_rfu_array
is array (0 .. 1) of int
;
618 type pthread_rwlockattr_t
is record
621 rfu
: rwlockattr_rfu_array
;
623 pragma Convention
(C
, pthread_rwlockattr_t
);
625 type rwlock_rfu_array
is array (0 .. 2) of int
;
627 type pthread_rwlock_t
is record
629 lock
: pthread_mutex_t
;
631 read_signal
: pthread_cond_t
;
632 write_signal
: pthread_cond_t
;
635 rfu
: rwlock_rfu_array
;
637 pragma Convention
(C
, pthread_rwlock_t
);
639 type pthread_key_t
is new unsigned_long
;
641 end System
.OS_Interface
;