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 --
11 -- Copyright (C) 1997-2001, Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This is a Sun OS (FSU THREADS) version of this package.
39 -- This package encapsulates all direct interfaces to OS services
40 -- that are needed by children of System.
42 -- PLEASE DO NOT add any with-clauses to this package
43 -- or remove the pragma Elaborate_Body.
44 -- It is designed to be a bottom-level (leaf) package.
47 package System
.OS_Interface
is
50 pragma Linker_Options
("-lgthreads");
51 pragma Linker_Options
("-lmalloc");
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 ETIMEDOUT
: constant := 60;
80 Max_Interrupt
: constant := 31;
81 type Signal
is new int
range 0 .. Max_Interrupt
;
82 for Signal
'Size use int
'Size;
84 SIGHUP
: constant := 1; -- hangup
85 SIGINT
: constant := 2; -- interrupt (rubout)
86 SIGQUIT
: constant := 3; -- quit (ASCD FS)
87 SIGILL
: constant := 4; -- illegal instruction (not reset)
88 SIGTRAP
: constant := 5; -- trace trap (not reset)
89 SIGIOT
: constant := 6; -- IOT instruction
90 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
91 SIGEMT
: constant := 7; -- EMT instruction
92 SIGFPE
: constant := 8; -- floating point exception
93 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
94 SIGBUS
: constant := 10; -- bus error
95 SIGSEGV
: constant := 11; -- segmentation violation
96 SIGSYS
: constant := 12; -- bad argument to system call
97 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
98 SIGALRM
: constant := 14; -- alarm clock
99 SIGTERM
: constant := 15; -- software termination signal from kill
100 SIGUSR1
: constant := 30; -- user defined signal 1
101 SIGUSR2
: constant := 31; -- user defined signal 2
102 SIGCLD
: constant := 20; -- alias for SIGCHLD
103 SIGCHLD
: constant := 20; -- child status change
104 SIGWINCH
: constant := 28; -- window size change
105 SIGURG
: constant := 16; -- urgent condition on IO channel
106 SIGPOLL
: constant := 23; -- pollable event occurred
107 SIGIO
: constant := 23; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP
: constant := 17; -- stop (cannot be caught or ignored)
109 SIGTSTP
: constant := 18; -- user stop requested from tty
110 SIGCONT
: constant := 19; -- stopped process has been continued
111 SIGTTIN
: constant := 21; -- background tty read attempted
112 SIGTTOU
: constant := 22; -- background tty write attempted
113 SIGVTALRM
: constant := 26; -- virtual timer expired
114 SIGPROF
: constant := 27; -- profiling timer expired
115 SIGXCPU
: constant := 24; -- CPU time limit exceeded
116 SIGXFSZ
: constant := 25; -- filesize limit exceeded
118 type sigset_t
is private;
120 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
121 pragma Import
(C
, sigaddset
, "sigaddset");
123 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
124 pragma Import
(C
, sigdelset
, "sigdelset");
126 function sigfillset
(set
: access sigset_t
) return int
;
127 pragma Import
(C
, sigfillset
, "sigfillset");
129 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
130 pragma Import
(C
, sigismember
, "sigismember");
132 function sigemptyset
(set
: access sigset_t
) return int
;
133 pragma Import
(C
, sigemptyset
, "sigemptyset");
135 type struct_sigaction
is record
136 sa_handler
: System
.Address
;
140 pragma Convention
(C
, struct_sigaction
);
141 type struct_sigaction_ptr
is access all struct_sigaction
;
143 SIG_BLOCK
: constant := 1;
144 SIG_UNBLOCK
: constant := 2;
145 SIG_SETMASK
: constant := 4;
147 SIG_DFL
: constant := 0;
148 SIG_IGN
: constant := 1;
152 act
: struct_sigaction_ptr
;
153 oact
: struct_sigaction_ptr
) return int
;
154 pragma Import
(C
, sigaction
, "sigaction");
160 Time_Slice_Supported
: constant Boolean := False;
161 -- Indicates wether time slicing is supported (i.e FSU threads have been
162 -- compiled with DEF_RR)
164 type timespec
is private;
166 type clockid_t
is private;
168 CLOCK_REALTIME
: constant clockid_t
;
170 function clock_gettime
171 (clock_id
: clockid_t
;
172 tp
: access timespec
) return int
;
173 pragma Import
(C
, clock_gettime
, "clock_gettime");
175 function To_Duration
(TS
: timespec
) return Duration;
176 pragma Inline
(To_Duration
);
178 function To_Timespec
(D
: Duration) return timespec
;
179 pragma Inline
(To_Timespec
);
181 type struct_timeval
is private;
183 function To_Duration
(TV
: struct_timeval
) return Duration;
184 pragma Inline
(To_Duration
);
186 function To_Timeval
(D
: Duration) return struct_timeval
;
187 pragma Inline
(To_Timeval
);
189 -------------------------
190 -- Priority Scheduling --
191 -------------------------
193 SCHED_FIFO
: constant := 0;
194 SCHED_RR
: constant := 1;
195 SCHED_OTHER
: constant := 2;
201 type pid_t
is private;
203 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
204 pragma Import
(C
, kill
, "kill");
206 function getpid
return pid_t
;
207 pragma Import
(C
, getpid
, "getpid");
213 function lwp_self
return System
.Address
;
214 -- lwp_self does not exist on this thread library, revert to pthread_self
215 -- which is the closest approximation (with getpid). This function is
216 -- needed to share 7staprop.adb across POSIX-like targets.
217 pragma Import
(C
, lwp_self
, "pthread_self");
223 type Thread_Body
is access
224 function (arg
: System
.Address
) return System
.Address
;
225 type pthread_t
is private;
226 subtype Thread_Id
is pthread_t
;
228 type pthread_mutex_t
is limited private;
229 type pthread_cond_t
is limited private;
230 type pthread_attr_t
is limited private;
231 type pthread_mutexattr_t
is limited private;
232 type pthread_condattr_t
is limited private;
233 type pthread_key_t
is private;
235 PTHREAD_CREATE_DETACHED
: constant := 1;
241 Stack_Base_Available
: constant Boolean := False;
242 -- Indicates wether the stack base is available on this target.
243 -- This allows us to share s-osinte.adb between all the FSU run time.
244 -- Note that this value can only be true if pthread_t has a complete
245 -- definition that corresponds exactly to the C header files.
247 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
248 pragma Inline
(Get_Stack_Base
);
249 -- returns the stack base of the specified thread.
250 -- Only call this function when Stack_Base_Available is True.
252 function Get_Page_Size
return size_t
;
253 function Get_Page_Size
return Address
;
254 pragma Import
(C
, Get_Page_Size
, "getpagesize");
255 -- returns the size of a page, or 0 if this is not relevant on this
258 PROT_NONE
: constant := 0;
259 PROT_READ
: constant := 1;
260 PROT_WRITE
: constant := 2;
261 PROT_EXEC
: constant := 4;
262 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
;
264 PROT_ON
: constant := PROT_NONE
;
265 PROT_OFF
: constant := PROT_ALL
;
267 function mprotect
(addr
: Address
; len
: size_t
; prot
: int
) return int
;
268 pragma Import
(C
, mprotect
);
270 ---------------------------------------
271 -- Nonstandard Thread Initialization --
272 ---------------------------------------
273 -- FSU_THREADS requires pthread_init, which is nonstandard
274 -- and this should be invoked during the elaboration of s-taprop.adb
275 procedure pthread_init
;
276 pragma Import
(C
, pthread_init
, "pthread_init");
278 -------------------------
279 -- POSIX.1c Section 3 --
280 -------------------------
282 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
283 -- FSU_THREADS has a nonstandard sigwait
285 function pthread_kill
(thread
: pthread_t
; sig
: Signal
) return int
;
286 pragma Import
(C
, pthread_kill
, "pthread_kill");
288 -- FSU threads does not have pthread_sigmask. Instead, it uses
289 -- sigprocmask to do the signal handling when the thread library is
292 type sigset_t_ptr
is access all sigset_t
;
294 function pthread_sigmask
297 oset
: sigset_t_ptr
) return int
;
298 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
300 --------------------------
301 -- POSIX.1c Section 11 --
302 --------------------------
304 function pthread_mutexattr_init
305 (attr
: access pthread_mutexattr_t
) return int
;
306 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
308 function pthread_mutexattr_destroy
309 (attr
: access pthread_mutexattr_t
) return int
;
310 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
312 function pthread_mutex_init
313 (mutex
: access pthread_mutex_t
;
314 attr
: access pthread_mutexattr_t
) return int
;
315 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
317 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
318 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
320 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
321 -- FSU_THREADS has nonstandard pthread_mutex_lock
323 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
324 -- FSU_THREADS has nonstandard pthread_mutex_lock
326 function pthread_condattr_init
327 (attr
: access pthread_condattr_t
) return int
;
328 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
330 function pthread_condattr_destroy
331 (attr
: access pthread_condattr_t
) return int
;
332 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
334 function pthread_cond_init
335 (cond
: access pthread_cond_t
;
336 attr
: access pthread_condattr_t
) return int
;
337 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
339 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
340 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
342 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
343 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
345 function pthread_cond_wait
346 (cond
: access pthread_cond_t
;
347 mutex
: access pthread_mutex_t
) return int
;
348 -- FSU_THREADS has a nonstandard pthread_cond_wait
350 function pthread_cond_timedwait
351 (cond
: access pthread_cond_t
;
352 mutex
: access pthread_mutex_t
;
353 abstime
: access timespec
) return int
;
354 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
356 Relative_Timed_Wait
: constant Boolean := False;
357 -- pthread_cond_timedwait requires an absolute delay time
359 --------------------------
360 -- POSIX.1c Section 13 --
361 --------------------------
363 PTHREAD_PRIO_NONE
: constant := 0;
364 PTHREAD_PRIO_PROTECT
: constant := 2;
365 PTHREAD_PRIO_INHERIT
: constant := 1;
367 function pthread_mutexattr_setprotocol
368 (attr
: access pthread_mutexattr_t
;
369 protocol
: int
) return int
;
370 pragma Import
(C
, pthread_mutexattr_setprotocol
);
372 function pthread_mutexattr_setprioceiling
373 (attr
: access pthread_mutexattr_t
;
374 prioceiling
: int
) return int
;
376 (C
, pthread_mutexattr_setprioceiling
,
377 "pthread_mutexattr_setprio_ceiling");
379 type struct_sched_param
is record
380 sched_priority
: int
; -- scheduling priority
383 function pthread_setschedparam
386 param
: access struct_sched_param
) return int
;
387 -- FSU_THREADS does not have pthread_setschedparam
389 function pthread_attr_setscope
390 (attr
: access pthread_attr_t
;
391 contentionscope
: int
) return int
;
392 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
394 function pthread_attr_setinheritsched
395 (attr
: access pthread_attr_t
;
396 inheritsched
: int
) return int
;
397 pragma Import
(C
, pthread_attr_setinheritsched
);
399 function pthread_attr_setschedpolicy
400 (attr
: access pthread_attr_t
;
401 policy
: int
) return int
;
402 pragma Import
(C
, pthread_attr_setschedpolicy
, "pthread_attr_setsched");
404 function pthread_attr_setschedparam
405 (attr
: access pthread_attr_t
;
406 sched_param
: int
) return int
;
407 pragma Import
(C
, pthread_attr_setschedparam
, "pthread_attr_setschedparam");
409 function sched_yield
return int
;
410 -- FSU_THREADS does not have sched_yield;
412 ---------------------------
413 -- P1003.1c - Section 16 --
414 ---------------------------
416 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
417 pragma Import
(C
, pthread_attr_init
, "pthread_attr_init");
419 function pthread_attr_destroy
420 (attributes
: access pthread_attr_t
) return int
;
421 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
423 function pthread_attr_setdetachstate
424 (attr
: access pthread_attr_t
;
425 detachstate
: int
) return int
;
426 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
428 function pthread_attr_setstacksize
429 (attr
: access pthread_attr_t
;
430 stacksize
: size_t
) return int
;
431 pragma Import
(C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
433 function pthread_create
434 (thread
: access pthread_t
;
435 attributes
: access pthread_attr_t
;
436 start_routine
: Thread_Body
;
437 arg
: System
.Address
) return int
;
438 pragma Import
(C
, pthread_create
, "pthread_create");
440 procedure pthread_exit
(status
: System
.Address
);
441 pragma Import
(C
, pthread_exit
, "pthread_exit");
443 function pthread_self
return pthread_t
;
444 pragma Import
(C
, pthread_self
, "pthread_self");
446 --------------------------
447 -- POSIX.1c Section 17 --
448 --------------------------
450 function pthread_setspecific
451 (key
: pthread_key_t
;
452 value
: System
.Address
) return int
;
453 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
455 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
456 -- FSU_THREADS has a nonstandard pthread_getspecific
458 type destructor_pointer
is access procedure (arg
: System
.Address
);
460 function pthread_key_create
461 (key
: access pthread_key_t
;
462 destructor
: destructor_pointer
)
464 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
468 type sigset_t
is new int
;
470 type pid_t
is new int
;
472 type time_t
is new long
;
474 type timespec
is record
478 pragma Convention
(C
, timespec
);
480 type clockid_t
is new int
;
481 CLOCK_REALTIME
: constant clockid_t
:= 0;
483 type struct_timeval
is record
487 pragma Convention
(C
, struct_timeval
);
489 type pthread_attr_t
is record
492 contentionscope
: int
;
497 starttime
: timespec
;
501 pragma Convention
(C
, pthread_attr_t
);
503 type pthread_condattr_t
is record
506 pragma Convention
(C
, pthread_condattr_t
);
508 type pthread_mutexattr_t
is record
513 pragma Convention
(C
, pthread_mutexattr_t
);
515 type sigjmp_buf
is array (Integer range 0 .. 9) of int
;
517 type pthread_t_struct
is record
518 context
: sigjmp_buf
;
522 stack_base
: System
.Address
;
524 pragma Convention
(C
, pthread_t_struct
);
526 type pthread_t
is access all pthread_t_struct
;
528 type queue_t
is record
529 head
: System
.Address
;
530 tail
: System
.Address
;
532 pragma Convention
(C
, queue_t
);
534 type pthread_mutex_t
is record
537 owner
: System
.Address
;
541 prev_max_ceiling_prio
: int
;
543 pragma Convention
(C
, pthread_mutex_t
);
545 type pthread_cond_t
is record
549 mutex
: System
.Address
;
551 pragma Convention
(C
, pthread_cond_t
);
553 type pthread_key_t
is new int
;
555 end System
.OS_Interface
;