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) 1992-2001, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This is a DOS/DJGPPv2 (FSU THREAD) version of this package.
36 -- This package encapsulates all direct interfaces to OS services
37 -- that are needed by children of System.
39 -- PLEASE DO NOT add any with-clauses to this package
40 -- or remove the pragma Elaborate_Body.
41 -- It is designed to be a bottom-level (leaf) package.
44 package System
.OS_Interface
is
48 -- A short name for libgthreads.a to keep Mike Feldman happy.
50 pragma Linker_Options
("-lgthre");
52 subtype int
is Interfaces
.C
.int
;
53 subtype short
is Interfaces
.C
.short
;
54 subtype long
is Interfaces
.C
.long
;
55 subtype unsigned
is Interfaces
.C
.unsigned
;
56 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
57 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
58 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
59 subtype plain_char
is Interfaces
.C
.plain_char
;
60 subtype size_t
is Interfaces
.C
.size_t
;
66 function errno
return int
;
67 pragma Import
(C
, errno
, "__get_errno");
69 EAGAIN
: constant := 5;
70 EINTR
: constant := 13;
71 EINVAL
: constant := 14;
72 ENOMEM
: constant := 25;
78 Max_Interrupt
: constant := 319;
79 type Signal
is new int
range 0 .. Max_Interrupt
;
81 SIGHUP
: constant := 294; -- hangup
82 SIGINT
: constant := 295; -- interrupt (rubout)
83 SIGQUIT
: constant := 298; -- quit (ASCD FS)
84 SIGILL
: constant := 290; -- illegal instruction (not reset)
85 SIGABRT
: constant := 288; -- used by abort
86 SIGFPE
: constant := 289; -- floating point exception
87 SIGKILL
: constant := 296; -- kill (cannot be caught or ignored)
88 SIGSEGV
: constant := 291; -- segmentation violation
89 SIGPIPE
: constant := 297; -- write on a pipe with no one to read it
90 SIGALRM
: constant := 293; -- alarm clock
91 SIGTERM
: constant := 292; -- software termination signal from kill
92 SIGUSR1
: constant := 299; -- user defined signal 1
93 SIGUSR2
: constant := 300; -- user defined signal 2
94 SIGBUS
: constant := 0;
96 SIGADAABORT
: constant := SIGABRT
;
98 type Signal_Set
is array (Natural range <>) of Signal
;
100 Unmasked
: constant Signal_Set
:= (SIGTRAP
, SIGALRM
);
101 Reserved
: constant Signal_Set
:= (0 .. 0 => SIGSTOP
);
103 type sigset_t
is private;
105 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
106 pragma Import
(C
, sigaddset
, "sigaddset");
108 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
109 pragma Import
(C
, sigdelset
, "sigdelset");
111 function sigfillset
(set
: access sigset_t
) return int
;
112 pragma Import
(C
, sigfillset
, "sigfillset");
114 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
115 pragma Import
(C
, sigismember
, "sigismember");
117 function sigemptyset
(set
: access sigset_t
) return int
;
118 pragma Import
(C
, sigemptyset
, "sigemptyset");
120 type struct_sigaction
is record
122 sa_handler
: System
.Address
;
125 pragma Convention
(C
, struct_sigaction
);
126 type struct_sigaction_ptr
is access all struct_sigaction
;
128 SIG_BLOCK
: constant := 1;
129 SIG_UNBLOCK
: constant := 3;
130 SIG_SETMASK
: constant := 2;
132 SIG_DFL
: constant := 0;
133 SIG_IGN
: constant := -1;
137 act
: struct_sigaction_ptr
;
138 oact
: struct_sigaction_ptr
) return int
;
139 pragma Import
(C
, sigaction
, "sigaction");
145 Time_Slice_Supported
: constant Boolean := False;
146 -- Indicates wether time slicing is supported (i.e FSU threads have been
147 -- compiled with DEF_RR)
149 type timespec
is private;
151 function nanosleep
(rqtp
, rmtp
: access timespec
) return int
;
152 -- FSU_THREADS has nonstandard nanosleep
153 type clockid_t
is private;
155 CLOCK_REALTIME
: constant clockid_t
;
157 function clock_gettime
158 (clock_id
: clockid_t
;
159 tp
: access timespec
) return int
;
160 pragma Import
(C
, clock_gettime
, "clock_gettime");
162 function To_Duration
(TS
: timespec
) return Duration;
163 pragma Inline
(To_Duration
);
165 function To_Timespec
(D
: Duration) return timespec
;
166 pragma Inline
(To_Timespec
);
168 type struct_timeval
is private;
170 function To_Duration
(TV
: struct_timeval
) return Duration;
171 pragma Inline
(To_Duration
);
173 function To_Timeval
(D
: Duration) return struct_timeval
;
174 pragma Inline
(To_Timeval
);
176 -------------------------
177 -- Priority Scheduling --
178 -------------------------
180 SCHED_FIFO
: constant := 0;
181 SCHED_RR
: constant := 1;
182 SCHED_OTHER
: constant := 2;
188 type pid_t
is private;
190 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
191 pragma Import
(C
, kill
, "kill");
193 function getpid
return pid_t
;
194 pragma Import
(C
, getpid
, "getpid");
200 function lwp_self
return System
.Address
;
201 -- lwp_self does not exist on this thread library, revert to pthread_self
202 -- which is the closest approximation (with getpid). This function is
203 -- needed to share 7staprop.adb across POSIX-like targets.
204 pragma Import
(C
, lwp_self
, "pthread_self");
210 type Thread_Body
is access
211 function (arg
: System
.Address
) return System
.Address
;
213 type pthread_t
is private;
214 subtype Thread_Id
is pthread_t
;
216 type pthread_mutex_t
is limited private;
217 type pthread_cond_t
is limited private;
218 type pthread_attr_t
is limited private;
219 type pthread_mutexattr_t
is limited private;
220 type pthread_condattr_t
is limited private;
221 type pthread_key_t
is private;
223 PTHREAD_CREATE_DETACHED
: constant := 1;
229 Stack_Base_Available
: constant Boolean := False;
230 -- Indicates wether the stack base is available on this target.
231 -- This allows us to share s-osinte.adb between all the FSU run time.
232 -- Note that this value can only be true if pthread_t has a complete
233 -- definition that corresponds exactly to the C header files.
235 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
236 pragma Inline
(Get_Stack_Base
);
237 -- returns the stack base of the specified thread.
238 -- Only call this function when Stack_Base_Available is True.
240 function Get_Page_Size
return size_t
;
241 function Get_Page_Size
return Address
;
242 pragma Import
(C
, Get_Page_Size
, "getpagesize");
243 -- returns the size of a page, or 0 if this is not relevant on this
246 PROT_NONE
: constant := 0;
247 PROT_READ
: constant := 1;
248 PROT_WRITE
: constant := 2;
249 PROT_EXEC
: constant := 4;
250 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
;
252 PROT_ON
: constant := PROT_NONE
;
253 PROT_OFF
: constant := PROT_ALL
;
256 (addr
: Address
; len
: size_t
; prot
: int
) return int
;
257 pragma Import
(C
, mprotect
);
259 ---------------------------------------
260 -- Nonstandard Thread Initialization --
261 ---------------------------------------
263 procedure pthread_init
;
264 -- FSU_THREADS requires pthread_init, which is nonstandard
265 -- and this should be invoked during the elaboration of s-taprop.adb
266 pragma Import
(C
, pthread_init
, "pthread_init");
268 -------------------------
269 -- POSIX.1c Section 3 --
270 -------------------------
272 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
273 -- FSU_THREADS has a nonstandard sigwait
275 function pthread_kill
(thread
: pthread_t
; sig
: Signal
) return int
;
276 pragma Import
(C
, pthread_kill
, "pthread_kill");
278 type sigset_t_ptr
is access all sigset_t
;
280 function pthread_sigmask
283 oset
: sigset_t_ptr
) return int
;
284 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
286 --------------------------
287 -- POSIX.1c Section 11 --
288 --------------------------
290 function pthread_mutexattr_init
291 (attr
: access pthread_mutexattr_t
) return int
;
292 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
294 function pthread_mutexattr_destroy
295 (attr
: access pthread_mutexattr_t
) return int
;
296 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
298 function pthread_mutex_init
299 (mutex
: access pthread_mutex_t
;
300 attr
: access pthread_mutexattr_t
) return int
;
301 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
303 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
304 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
306 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
307 -- FSU_THREADS has nonstandard pthread_mutex_lock
309 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
310 -- FSU_THREADS has nonstandard pthread_mutex_lock
312 function pthread_condattr_init
313 (attr
: access pthread_condattr_t
) return int
;
314 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
316 function pthread_condattr_destroy
317 (attr
: access pthread_condattr_t
) return int
;
318 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
320 function pthread_cond_init
321 (cond
: access pthread_cond_t
;
322 attr
: access pthread_condattr_t
) return int
;
323 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
325 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
326 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
328 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
329 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
331 function pthread_cond_wait
332 (cond
: access pthread_cond_t
;
333 mutex
: access pthread_mutex_t
) return int
;
334 -- FSU_THREADS has a nonstandard pthread_cond_wait
336 function pthread_cond_timedwait
337 (cond
: access pthread_cond_t
;
338 mutex
: access pthread_mutex_t
;
339 abstime
: access timespec
) return int
;
340 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
342 Relative_Timed_Wait
: constant Boolean := False;
343 -- pthread_cond_timedwait requires an absolute delay time
345 --------------------------
346 -- POSIX.1c Section 13 --
347 --------------------------
349 PTHREAD_PRIO_NONE
: constant := 0;
350 PTHREAD_PRIO_PROTECT
: constant := 2;
351 PTHREAD_PRIO_INHERIT
: constant := 1;
353 function pthread_mutexattr_setprotocol
354 (attr
: access pthread_mutexattr_t
;
355 protocol
: int
) return int
;
356 pragma Import
(C
, pthread_mutexattr_setprotocol
);
358 function pthread_mutexattr_setprioceiling
359 (attr
: access pthread_mutexattr_t
;
360 prioceiling
: int
) return int
;
361 pragma Import
(C
, pthread_mutexattr_setprioceiling
);
363 type struct_sched_param
is record
364 sched_priority
: int
; -- scheduling priority
367 function pthread_setschedparam
370 param
: access struct_sched_param
) return int
;
371 -- FSU_THREADS does not have pthread_setschedparam
373 function pthread_attr_setscope
374 (attr
: access pthread_attr_t
;
375 contentionscope
: int
) return int
;
376 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
378 function pthread_attr_setinheritsched
379 (attr
: access pthread_attr_t
;
380 inheritsched
: int
) return int
;
381 pragma Import
(C
, pthread_attr_setinheritsched
);
383 function pthread_attr_setschedpolicy
384 (attr
: access pthread_attr_t
;
385 policy
: int
) return int
;
386 pragma Import
(C
, pthread_attr_setschedpolicy
, "pthread_attr_setsched");
388 function sched_yield
return int
;
389 -- FSU_THREADS does not have sched_yield;
391 ---------------------------
392 -- P1003.1c - Section 16 --
393 ---------------------------
395 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
396 pragma Import
(C
, pthread_attr_init
);
398 function pthread_attr_destroy
399 (attributes
: access pthread_attr_t
) return int
;
400 pragma Import
(C
, pthread_attr_destroy
);
402 function pthread_attr_setdetachstate
403 (attr
: access pthread_attr_t
;
404 detachstate
: int
) return int
;
405 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
407 function pthread_attr_setstacksize
408 (attr
: access pthread_attr_t
;
409 stacksize
: size_t
) return int
;
410 pragma Import
(C
, pthread_attr_setstacksize
);
412 function pthread_create
413 (thread
: access pthread_t
;
414 attributes
: access pthread_attr_t
;
415 start_routine
: Thread_Body
;
416 arg
: System
.Address
) return int
;
417 pragma Import
(C
, pthread_create
);
419 procedure pthread_exit
(status
: System
.Address
);
420 pragma Import
(C
, pthread_exit
, "pthread_exit");
422 function pthread_self
return pthread_t
;
423 pragma Import
(C
, pthread_self
, "pthread_self");
425 --------------------------
426 -- POSIX.1c Section 17 --
427 --------------------------
429 function pthread_setspecific
430 (key
: pthread_key_t
;
431 value
: System
.Address
) return int
;
432 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
434 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
435 -- FSU_THREADS has a nonstandard pthread_getspecific
437 type destructor_pointer
is access procedure (arg
: System
.Address
);
439 function pthread_key_create
440 (key
: access pthread_key_t
;
441 destructor
: destructor_pointer
) return int
;
442 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
446 type bits_arr_t
is array (Integer range 1 .. 10) of long
;
447 type sigset_t
is record
451 type pid_t
is new int
;
453 type time_t
is new long
;
455 type timespec
is record
459 pragma Convention
(C
, timespec
);
461 type clockid_t
is new int
;
462 CLOCK_REALTIME
: constant clockid_t
:= 0;
464 type struct_timeval
is record
468 pragma Convention
(C
, struct_timeval
);
470 type pthread_attr_t
is record
473 contentionscope
: int
;
478 starttime
: timespec
;
482 pragma Convention
(C
, pthread_attr_t
);
484 type pthread_condattr_t
is record
487 pragma Convention
(C
, pthread_condattr_t
);
489 type pthread_mutexattr_t
is record
494 pragma Convention
(C
, pthread_mutexattr_t
);
496 type sigjmp_buf
is array (Integer range 0 .. 43) of int
;
498 type pthread_t_struct
is record
499 context
: sigjmp_buf
;
503 stack_base
: System
.Address
;
505 pragma Convention
(C
, pthread_t_struct
);
507 type pthread_t
is access all pthread_t_struct
;
509 type queue_t
is record
510 head
: System
.Address
;
511 tail
: System
.Address
;
513 pragma Convention
(C
, queue_t
);
515 type pthread_mutex_t
is record
518 owner
: System
.Address
;
522 prev_max_ceiling_prio
: int
;
524 pragma Convention
(C
, pthread_mutex_t
);
526 type pthread_cond_t
is record
530 mutex
: System
.Address
;
532 pragma Convention
(C
, pthread_cond_t
);
534 type pthread_key_t
is new int
;
536 end System
.OS_Interface
;