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) 1999-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 LynxOS (Native) 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
47 pragma Linker_Options
("-mthreads");
49 subtype int
is Interfaces
.C
.int
;
50 subtype char
is Interfaces
.C
.char
;
51 subtype short
is Interfaces
.C
.short
;
52 subtype long
is Interfaces
.C
.long
;
53 subtype unsigned
is Interfaces
.C
.unsigned
;
54 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
55 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
56 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
57 subtype plain_char
is Interfaces
.C
.plain_char
;
58 subtype size_t
is Interfaces
.C
.size_t
;
64 function errno
return int
;
65 pragma Import
(C
, errno
, "__get_errno");
67 EAGAIN
: constant := 11;
68 EINTR
: constant := 4;
69 EINVAL
: constant := 22;
70 ENOMEM
: constant := 12;
71 ETIMEDOUT
: constant := 60;
77 Max_Interrupt
: constant := 63;
78 type Signal
is new int
range 0 .. Max_Interrupt
;
79 for Signal
'Size use int
'Size;
81 SIGHUP
: constant := 1; -- hangup
82 SIGINT
: constant := 2; -- interrupt (rubout)
83 SIGQUIT
: constant := 3; -- quit (ASCD FS)
84 SIGILL
: constant := 4; -- illegal instruction (not reset)
85 SIGTRAP
: constant := 5; -- trace trap (not reset)
86 SIGBRK
: constant := 6; -- break
87 SIGIOT
: constant := 6; -- IOT instruction
88 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
89 SIGCORE
: constant := 7; -- kill with core dump
90 SIGEMT
: constant := 7; -- EMT instruction
91 SIGFPE
: constant := 8; -- floating point exception
92 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
93 SIGBUS
: constant := 10; -- bus error
94 SIGSEGV
: constant := 11; -- segmentation violation
95 SIGSYS
: constant := 12; -- bad argument to system call
96 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
97 SIGALRM
: constant := 14; -- alarm clock
98 SIGTERM
: constant := 15; -- software termination signal from kill
99 SIGURG
: constant := 16; -- urgent condition on IO channel
100 SIGSTOP
: constant := 17; -- stop (cannot be caught or ignored)
101 SIGTSTP
: constant := 18; -- user stop requested from tty
102 SIGCONT
: constant := 19; -- stopped process has been continued
103 SIGCLD
: constant := 20; -- alias for SIGCHLD
104 SIGCHLD
: constant := 20; -- child status change
105 SIGTTIN
: constant := 21; -- background tty read attempted
106 SIGTTOU
: constant := 22; -- background tty write attempted
107 SIGIO
: constant := 23; -- I/O possible (Solaris SIGPOLL alias)
108 SIGPOLL
: constant := 23; -- pollable event occurred
109 SIGXCPU
: constant := 24; -- CPU time limit exceeded
110 SIGXFSZ
: constant := 25; -- filesize limit exceeded
111 SIGVTALRM
: constant := 26; -- virtual timer expired
112 SIGPROF
: constant := 27; -- profiling timer expired
113 SIGWINCH
: constant := 28; -- window size change
114 SIGLOST
: constant := 29; -- SUN 4.1 compatibility
115 SIGUSR1
: constant := 30; -- user defined signal 1
116 SIGUSR2
: constant := 31; -- user defined signal 2
117 SIGPRIO
: constant := 32; -- sent to a process with its priority or
120 SIGADAABORT
: constant := SIGABRT
;
121 -- Change this if you want to use another signal for task abort.
122 -- SIGTERM might be a good one.
124 type Signal_Set
is array (Natural range <>) of Signal
;
126 Unmasked
: constant Signal_Set
:=
127 (SIGTRAP
, SIGTTIN
, SIGTTOU
, SIGTSTP
, SIGPROF
);
128 Reserved
: constant Signal_Set
:= (SIGABRT
, SIGKILL
, SIGSTOP
, SIGPRIO
);
130 type sigset_t
is private;
132 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
133 pragma Import
(C
, sigaddset
, "sigaddset");
135 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
136 pragma Import
(C
, sigdelset
, "sigdelset");
138 function sigfillset
(set
: access sigset_t
) return int
;
139 pragma Import
(C
, sigfillset
, "sigfillset");
141 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
142 pragma Import
(C
, sigismember
, "sigismember");
144 function sigemptyset
(set
: access sigset_t
) return int
;
145 pragma Import
(C
, sigemptyset
, "sigemptyset");
147 type struct_sigaction
is record
148 sa_handler
: System
.Address
;
152 pragma Convention
(C
, struct_sigaction
);
153 type struct_sigaction_ptr
is access all struct_sigaction
;
155 SIG_BLOCK
: constant := 0;
156 SIG_UNBLOCK
: constant := 1;
157 SIG_SETMASK
: constant := 2;
159 SIG_DFL
: constant := 0;
160 SIG_IGN
: constant := 1;
164 act
: struct_sigaction_ptr
;
165 oact
: struct_sigaction_ptr
) return int
;
166 pragma Import
(C
, sigaction
, "sigaction");
172 Time_Slice_Supported
: constant Boolean := True;
173 -- Indicates wether time slicing is supported
175 type timespec
is private;
177 type clockid_t
is private;
179 CLOCK_REALTIME
: constant clockid_t
;
181 function clock_gettime
182 (clock_id
: clockid_t
;
183 tp
: access timespec
) return int
;
184 pragma Inline
(clock_gettime
);
185 -- LynxOS has non standard clock_gettime
187 function To_Duration
(TS
: timespec
) return Duration;
188 pragma Inline
(To_Duration
);
190 function To_Timespec
(D
: Duration) return timespec
;
191 pragma Inline
(To_Timespec
);
193 type struct_timezone
is record
194 tz_minuteswest
: int
;
197 pragma Convention
(C
, struct_timezone
);
198 type struct_timezone_ptr
is access all struct_timezone
;
200 type struct_timeval
is private;
201 -- This is needed on systems that do not have clock_gettime()
202 -- but do have gettimeofday().
204 function To_Duration
(TV
: struct_timeval
) return Duration;
205 pragma Inline
(To_Duration
);
207 function To_Timeval
(D
: Duration) return struct_timeval
;
208 pragma Inline
(To_Timeval
);
210 -------------------------
211 -- Priority Scheduling --
212 -------------------------
214 SCHED_FIFO
: constant := 16#
00200000#
;
215 SCHED_RR
: constant := 16#
00100000#
;
216 SCHED_OTHER
: constant := 16#
00400000#
;
222 type pid_t
is private;
224 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
225 pragma Import
(C
, kill
, "kill");
227 function getpid
return pid_t
;
228 pragma Import
(C
, getpid
, "getpid");
234 function lwp_self
return System
.Address
;
235 -- lwp_self does not exist on this thread library, revert to pthread_self
236 -- which is the closest approximation (with getpid). This function is
237 -- needed to share 7staprop.adb across POSIX-like targets.
238 pragma Import
(C
, lwp_self
, "pthread_self");
244 type Thread_Body
is access
245 function (arg
: System
.Address
) return System
.Address
;
246 type pthread_t
is private;
247 subtype Thread_Id
is pthread_t
;
249 type pthread_mutex_t
is limited private;
250 type pthread_cond_t
is limited private;
251 type st_t
is limited private;
252 type pthread_attr_t
is limited private;
253 type pthread_mutexattr_t
is limited private;
254 type pthread_condattr_t
is limited private;
255 type pthread_key_t
is private;
257 PTHREAD_CREATE_DETACHED
: constant := 0;
263 Stack_Base_Available
: constant Boolean := False;
264 -- Indicates wether the stack base is available on this target.
266 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
267 pragma Inline
(Get_Stack_Base
);
268 -- returns the stack base of the specified thread.
269 -- Only call this function when Stack_Base_Available is True.
271 function Get_Page_Size
return size_t
;
272 function Get_Page_Size
return Address
;
273 pragma Import
(C
, Get_Page_Size
, "getpagesize");
274 -- returns the size of a page, or 0 if this is not relevant on this
277 PROT_NONE
: constant := 0;
278 PROT_READ
: constant := 1;
279 PROT_WRITE
: constant := 2;
280 PROT_EXEC
: constant := 4;
281 PROT_USER
: constant := 8;
282 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
+ PROT_USER
;
284 PROT_ON
: constant := PROT_READ
;
285 PROT_OFF
: constant := PROT_ALL
;
287 function mprotect
(addr
: Address
; len
: size_t
; prot
: int
) return int
;
288 pragma Import
(C
, mprotect
);
290 -------------------------
291 -- POSIX.1c Section 3 --
292 -------------------------
295 (set
: access sigset_t
;
296 sig
: access Signal
) return int
;
297 pragma Inline
(sigwait
);
298 -- LynxOS has non standard sigwait
300 function pthread_kill
(thread
: pthread_t
; sig
: Signal
) return int
;
301 pragma Import
(C
, pthread_kill
, "pthread_kill");
303 type sigset_t_ptr
is access all sigset_t
;
305 function pthread_sigmask
308 oset
: sigset_t_ptr
) return int
;
309 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
311 --------------------------
312 -- POSIX.1c Section 11 --
313 --------------------------
315 function pthread_mutexattr_init
316 (attr
: access pthread_mutexattr_t
) return int
;
317 pragma Inline
(pthread_mutexattr_init
);
318 -- LynxOS has a nonstandard pthread_mutexattr_init
320 function pthread_mutexattr_destroy
321 (attr
: access pthread_mutexattr_t
) return int
;
322 pragma Inline
(pthread_mutexattr_destroy
);
323 -- Lynxos has a nonstandard pthread_mutexattr_destroy
325 function pthread_mutex_init
326 (mutex
: access pthread_mutex_t
;
327 attr
: access pthread_mutexattr_t
) return int
;
328 pragma Inline
(pthread_mutex_init
);
329 -- LynxOS has a nonstandard pthread_mutex_init
331 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
332 pragma Inline
(pthread_mutex_destroy
);
333 -- LynxOS has a nonstandard pthread_mutex_destroy
335 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
336 pragma Inline
(pthread_mutex_lock
);
337 -- LynxOS has a nonstandard pthread_mutex_lock
339 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
340 pragma Inline
(pthread_mutex_unlock
);
341 -- LynxOS has a nonstandard pthread_mutex_unlock
343 function pthread_condattr_init
344 (attr
: access pthread_condattr_t
) return int
;
345 pragma Inline
(pthread_condattr_init
);
346 -- LynxOS has a nonstandard pthread_condattr_init
348 function pthread_condattr_destroy
349 (attr
: access pthread_condattr_t
) return int
;
350 pragma Inline
(pthread_condattr_destroy
);
351 -- LynxOS has a nonstandard pthread_condattr_destroy
353 function pthread_cond_init
354 (cond
: access pthread_cond_t
;
355 attr
: access pthread_condattr_t
) return int
;
356 pragma Inline
(pthread_cond_init
);
357 -- LynxOS has a non standard pthread_cond_init
359 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
360 pragma Inline
(pthread_cond_destroy
);
361 -- LynxOS has a nonstandard pthread_cond_destroy
363 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
364 pragma Inline
(pthread_cond_signal
);
365 -- LynxOS has a nonstandard pthread_cond_signal
367 function pthread_cond_wait
368 (cond
: access pthread_cond_t
;
369 mutex
: access pthread_mutex_t
) return int
;
370 pragma Inline
(pthread_cond_wait
);
371 -- LynxOS has a nonstandard pthread_cond_wait
373 function pthread_cond_timedwait
374 (cond
: access pthread_cond_t
;
375 mutex
: access pthread_mutex_t
;
376 reltime
: access timespec
) return int
;
377 pragma Inline
(pthread_cond_timedwait
);
378 -- LynxOS has a nonstandard pthrad_cond_timedwait
380 Relative_Timed_Wait
: constant Boolean := True;
381 -- pthread_cond_timedwait requires a relative delay time
383 --------------------------
384 -- POSIX.1c Section 13 --
385 --------------------------
387 PTHREAD_PRIO_NONE
: constant := 0;
388 PTHREAD_PRIO_INHERIT
: constant := 0;
389 PTHREAD_PRIO_PROTECT
: constant := 0;
391 type struct_sched_param
is record
392 sched_priority
: int
; -- scheduling priority
395 function pthread_setschedparam
398 param
: access struct_sched_param
) return int
;
399 pragma Inline
(pthread_setschedparam
);
400 -- LynxOS doesn't have pthread_setschedparam.
401 -- Instead, use pthread_setscheduler
403 function pthread_mutexattr_setprotocol
404 (attr
: access pthread_mutexattr_t
;
405 protocol
: int
) return int
;
406 pragma Inline
(pthread_mutexattr_setprotocol
);
407 -- LynxOS doesn't have pthread_mutexattr_setprotocol
409 function pthread_mutexattr_setprioceiling
410 (attr
: access pthread_mutexattr_t
;
411 prioceiling
: int
) return int
;
412 pragma Inline
(pthread_mutexattr_setprioceiling
);
413 -- LynxOS doesn't have pthread_mutexattr_setprioceiling
415 function pthread_attr_setscope
416 (attr
: access pthread_attr_t
;
417 contentionscope
: int
) return int
;
418 -- LynxOS doesn't have pthread_attr_setscope: all threads have system scope
419 pragma Inline
(pthread_attr_setscope
);
421 function pthread_attr_setschedpolicy
422 (attr
: access pthread_attr_t
;
423 policy
: int
) return int
;
424 pragma Import
(C
, pthread_attr_setschedpolicy
, "pthread_attr_setsched");
426 function sched_yield
return int
;
427 -- pragma Import (C, sched_yield, "sched_yield");
428 pragma Inline
(sched_yield
);
430 ---------------------------
431 -- P1003.1c - Section 16 --
432 ---------------------------
434 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
435 pragma Import
(C
, pthread_attr_init
, "pthread_attr_create");
437 function pthread_attr_destroy
438 (attributes
: access pthread_attr_t
) return int
;
439 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_delete");
441 function pthread_attr_setdetachstate
442 (attr
: access pthread_attr_t
;
443 detachstate
: int
) return int
;
444 pragma Inline
(pthread_attr_setdetachstate
);
445 -- LynxOS doesn't have pthread_attr_setdetachstate
447 function pthread_attr_setstacksize
448 (attr
: access pthread_attr_t
;
449 stacksize
: size_t
) return int
;
450 pragma Import
(C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
452 function pthread_create
453 (thread
: access pthread_t
;
454 attributes
: access pthread_attr_t
;
455 start_routine
: Thread_Body
;
456 arg
: System
.Address
) return int
;
457 pragma Inline
(pthread_create
);
458 -- LynxOS has a non standard pthread_create
460 procedure pthread_exit
(status
: System
.Address
);
461 pragma Import
(C
, pthread_exit
, "pthread_exit");
463 function pthread_self
return pthread_t
;
464 pragma Import
(C
, pthread_self
, "pthread_self");
466 --------------------------
467 -- POSIX.1c Section 17 --
468 --------------------------
470 function pthread_setspecific
471 (key
: pthread_key_t
;
472 value
: System
.Address
) return int
;
473 pragma Inline
(pthread_setspecific
);
474 -- LynxOS has a non standard pthread_setspecific
476 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
477 pragma Inline
(pthread_getspecific
);
478 -- LynxOS has a non standard pthread_getspecific
480 type destructor_pointer
is access procedure (arg
: System
.Address
);
482 function pthread_key_create
483 (key
: access pthread_key_t
;
484 destructor
: destructor_pointer
) return int
;
485 pragma Inline
(pthread_key_create
);
486 -- LynxOS has a non standard pthread_keycreate
488 procedure pthread_init
;
489 -- This is a dummy procedure to share some GNULLI files
493 type sigbit_array
is array (1 .. 2) of long
;
494 type sigset_t
is record
495 sa_sigbits
: sigbit_array
;
497 pragma Convention
(C_Pass_By_Copy
, sigset_t
);
499 type pid_t
is new long
;
501 type time_t
is new long
;
503 type timespec
is record
507 pragma Convention
(C
, timespec
);
509 type clockid_t
is new unsigned_char
;
510 CLOCK_REALTIME
: constant clockid_t
:= 0;
512 type struct_timeval
is record
516 pragma Convention
(C
, struct_timeval
);
525 pragma Convention
(C
, st_t
);
527 type pthread_attr_t
is record
529 pthread_attr_scope
: int
; -- ignored
531 pragma Convention
(C
, pthread_attr_t
);
533 type pthread_condattr_t
is new int
;
535 type pthread_mutexattr_t
is new int
;
537 type tid_t
is new short
;
538 type pthread_t
is new tid_t
;
540 type synch_ptr
is access all pthread_mutex_t
;
541 type pthread_mutex_t
is record
547 pragma Convention
(C
, pthread_mutex_t
);
549 type pthread_cond_t
is new pthread_mutex_t
;
551 type pthread_key_t
is new int
;
553 end System
.OS_Interface
;