1 ------------------------------------------------------------------------------
3 -- GNAT 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-2005, 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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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 OpenNT/Interix (FSU 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 or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
44 with Unchecked_Conversion
;
46 package System
.OS_Interface
is
49 pragma Linker_Options
("-lgthreads");
50 pragma Linker_Options
("-lmalloc");
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 := 11;
70 EINTR
: constant := 4;
71 EINVAL
: constant := 22;
72 ENOMEM
: constant := 12;
73 ETIMEDOUT
: constant := 60;
79 Max_Interrupt
: constant := 31;
80 type Signal
is new int
range 0 .. Max_Interrupt
;
81 for Signal
'Size use int
'Size;
83 SIGHUP
: constant := 1; -- hangup
84 SIGINT
: constant := 2; -- interrupt (rubout)
85 SIGQUIT
: constant := 3; -- quit (ASCD FS)
86 SIGILL
: constant := 4; -- illegal instruction (not reset)
87 SIGTRAP
: constant := 5; -- trace trap (not reset)
88 SIGIOT
: constant := 6; -- IOT instruction
89 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
90 SIGEMT
: constant := 0; -- 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 SIGUSR1
: constant := 16; -- user defined signal 1
100 SIGUSR2
: constant := 17; -- user defined signal 2
101 SIGCLD
: constant := 18; -- alias for SIGCHLD
102 SIGCHLD
: constant := 18; -- child status change
103 SIGPWR
: constant := 0; -- power-fail restart
104 SIGWINCH
: constant := 20; -- window size change
105 SIGURG
: constant := 21; -- urgent condition on IO channel
106 SIGPOLL
: constant := 22; -- pollable event occurred
107 SIGIO
: constant := 19; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP
: constant := 23; -- stop (cannot be caught or ignored)
109 SIGTSTP
: constant := 24; -- user stop requested from tty
110 SIGCONT
: constant := 25; -- stopped process has been continued
111 SIGTTIN
: constant := 26; -- background tty read attempted
112 SIGTTOU
: constant := 27; -- background tty write attempted
113 SIGVTALRM
: constant := 28; -- virtual timer expired
114 SIGPROF
: constant := 29; -- profiling timer expired
115 SIGXCPU
: constant := 30; -- CPU time limit exceeded
116 SIGXFSZ
: constant := 31; -- filesize limit exceeded
118 SIGADAABORT
: constant := SIGABRT
;
120 type Signal_Set
is array (Natural range <>) of Signal
;
122 Unmasked
: constant Signal_Set
:=
123 (SIGTRAP
, SIGALRM
, SIGVTALRM
, SIGTTIN
, SIGTTOU
, SIGTSTP
, SIGPROF
);
125 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
);
127 type sigset_t
is private;
129 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
130 pragma Import
(C
, sigaddset
, "sigaddset");
132 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
133 pragma Import
(C
, sigdelset
, "sigdelset");
135 function sigfillset
(set
: access sigset_t
) return int
;
136 pragma Import
(C
, sigfillset
, "sigfillset");
138 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
139 pragma Import
(C
, sigismember
, "sigismember");
141 function sigemptyset
(set
: access sigset_t
) return int
;
142 pragma Import
(C
, sigemptyset
, "sigemptyset");
144 type struct_sigaction
is record
145 sa_handler
: System
.Address
;
148 sa_restorer
: System
.Address
;
150 pragma Convention
(C
, struct_sigaction
);
151 type struct_sigaction_ptr
is access all struct_sigaction
;
153 SIG_BLOCK
: constant := 1;
154 SIG_UNBLOCK
: constant := 2;
155 SIG_SETMASK
: constant := 3;
157 SIG_DFL
: constant := 0;
158 SIG_IGN
: constant := 1;
160 SA_SIGINFO
: constant := 0;
161 -- Dummy constant for a sa_flags bit. A proper definition is needed only
162 -- for the GCC/ZCX EH scheme (see System.Interrupt_Management).
166 act
: struct_sigaction_ptr
;
167 oact
: struct_sigaction_ptr
) return int
;
168 -- FSU pthreads redefines sigaction and then uses a special syscall
169 -- API to call the system version. Doing syscalls on OpenNT is very
170 -- difficult, so we rename the pthread version instead.
171 pragma Import
(C
, sigaction
, "pthread_wrapper_sigaction");
177 Time_Slice_Supported
: constant Boolean := False;
178 -- Indicates wether time slicing is supported (i.e FSU threads have been
179 -- compiled with DEF_RR)
181 type timespec
is private;
183 type clockid_t
is private;
185 CLOCK_REALTIME
: constant clockid_t
;
187 function clock_gettime
188 (clock_id
: clockid_t
;
189 tp
: access timespec
) return int
;
190 pragma Import
(C
, clock_gettime
, "clock_gettime");
192 function To_Duration
(TS
: timespec
) return Duration;
193 pragma Inline
(To_Duration
);
195 function To_Timespec
(D
: Duration) return timespec
;
196 pragma Inline
(To_Timespec
);
198 type struct_timeval
is private;
200 function To_Duration
(TV
: struct_timeval
) return Duration;
201 pragma Inline
(To_Duration
);
203 function To_Timeval
(D
: Duration) return struct_timeval
;
204 pragma Inline
(To_Timeval
);
206 -------------------------
207 -- Priority Scheduling --
208 -------------------------
210 SCHED_FIFO
: constant := 0;
211 SCHED_RR
: constant := 1;
212 SCHED_OTHER
: constant := 2;
218 type pid_t
is private;
220 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
221 pragma Import
(C
, kill
, "kill");
223 function getpid
return pid_t
;
224 pragma Import
(C
, getpid
, "getpid");
230 function lwp_self
return System
.Address
;
231 -- lwp_self does not exist on this thread library, revert to pthread_self
232 -- which is the closest approximation (with getpid). This function is
233 -- needed to share 7staprop.adb across POSIX-like targets.
234 pragma Import
(C
, lwp_self
, "pthread_self");
240 type Thread_Body
is access
241 function (arg
: System
.Address
) return System
.Address
;
243 function Thread_Body_Access
is new
244 Unchecked_Conversion
(System
.Address
, Thread_Body
);
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 pthread_attr_t
is limited private;
252 type pthread_mutexattr_t
is limited private;
253 type pthread_condattr_t
is limited private;
254 type pthread_key_t
is private;
256 PTHREAD_CREATE_DETACHED
: constant := 1;
257 PTHREAD_CREATE_JOINABLE
: constant := 0;
263 Stack_Base_Available
: constant Boolean := False;
264 -- Indicates wether the stack base is available on this target.
265 -- This allows us to share s-osinte.adb between all the FSU run time.
266 -- Note that this value can only be true if pthread_t has a complete
267 -- definition that corresponds exactly to the C header files.
269 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
270 pragma Inline
(Get_Stack_Base
);
271 -- returns the stack base of the specified thread.
272 -- Only call this function when Stack_Base_Available is True.
274 function Get_Page_Size
return size_t
;
275 function Get_Page_Size
return Address
;
276 pragma Import
(C
, Get_Page_Size
, "getpagesize");
277 -- returns the size of a page, or 0 if this is not relevant on this
280 PROT_NONE
: constant := 0;
281 PROT_READ
: constant := 1;
282 PROT_WRITE
: constant := 2;
283 PROT_EXEC
: constant := 4;
284 PROT_ALL
: constant := PROT_READ
+ PROT_WRITE
+ PROT_EXEC
;
286 PROT_ON
: constant := PROT_NONE
;
287 PROT_OFF
: constant := PROT_ALL
;
289 function mprotect
(addr
: Address
; len
: size_t
; prot
: int
) return int
;
290 pragma Import
(C
, mprotect
);
292 ---------------------------------------
293 -- Nonstandard Thread Initialization --
294 ---------------------------------------
296 procedure pthread_init
;
297 -- FSU_THREADS requires pthread_init, which is nonstandard
298 -- and this should be invoked during the elaboration of s-taprop.adb
299 pragma Import
(C
, pthread_init
, "pthread_init");
301 -------------------------
302 -- POSIX.1c Section 3 --
303 -------------------------
306 (set
: access sigset_t
;
307 sig
: access Signal
) return int
;
308 -- FSU_THREADS has a nonstandard sigwait
310 function pthread_kill
312 sig
: Signal
) return int
;
313 pragma Import
(C
, pthread_kill
, "pthread_kill");
315 type sigset_t_ptr
is access all sigset_t
;
317 function pthread_sigmask
320 oset
: sigset_t_ptr
) return int
;
321 pragma Import
(C
, pthread_sigmask
, "pthread_wrapper_sigprocmask");
323 --------------------------
324 -- POSIX.1c Section 11 --
325 --------------------------
327 function pthread_mutexattr_init
328 (attr
: access pthread_mutexattr_t
) return int
;
329 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
331 function pthread_mutexattr_destroy
332 (attr
: access pthread_mutexattr_t
) return int
;
333 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
335 function pthread_mutex_init
336 (mutex
: access pthread_mutex_t
;
337 attr
: access pthread_mutexattr_t
) return int
;
338 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
340 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
341 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
343 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
344 -- FSU_THREADS has nonstandard pthread_mutex_lock
346 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
347 -- FSU_THREADS has nonstandard pthread_mutex_lock
349 function pthread_condattr_init
350 (attr
: access pthread_condattr_t
) return int
;
351 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
353 function pthread_condattr_destroy
354 (attr
: access pthread_condattr_t
) return int
;
355 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
357 function pthread_cond_init
358 (cond
: access pthread_cond_t
;
359 attr
: access pthread_condattr_t
) return int
;
360 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
362 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
363 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
365 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
366 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
368 function pthread_cond_wait
369 (cond
: access pthread_cond_t
;
370 mutex
: access pthread_mutex_t
) return int
;
371 -- FSU_THREADS has a nonstandard pthread_cond_wait
373 function pthread_cond_timedwait
374 (cond
: access pthread_cond_t
;
375 mutex
: access pthread_mutex_t
;
376 abstime
: access timespec
) return int
;
377 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
379 Relative_Timed_Wait
: constant Boolean := False;
380 -- pthread_cond_timedwait requires an absolute delay time
382 --------------------------
383 -- POSIX.1c Section 13 --
384 --------------------------
386 PTHREAD_PRIO_NONE
: constant := 0;
387 PTHREAD_PRIO_PROTECT
: constant := 2;
388 PTHREAD_PRIO_INHERIT
: constant := 1;
390 function pthread_mutexattr_setprotocol
391 (attr
: access pthread_mutexattr_t
;
392 protocol
: int
) return int
;
393 pragma Import
(C
, pthread_mutexattr_setprotocol
);
395 function pthread_mutexattr_setprioceiling
396 (attr
: access pthread_mutexattr_t
;
397 prioceiling
: int
) return int
;
399 (C
, pthread_mutexattr_setprioceiling
,
400 "pthread_mutexattr_setprio_ceiling");
402 type struct_sched_param
is record
403 sched_priority
: int
; -- scheduling priority
406 function pthread_setschedparam
409 param
: access struct_sched_param
) return int
;
410 -- FSU_THREADS does not have pthread_setschedparam
412 function pthread_attr_setscope
413 (attr
: access pthread_attr_t
;
414 contentionscope
: int
) return int
;
415 pragma Import
(C
, pthread_attr_setscope
, "pthread_attr_setscope");
417 function pthread_attr_setinheritsched
418 (attr
: access pthread_attr_t
;
419 inheritsched
: int
) return int
;
420 pragma Import
(C
, pthread_attr_setinheritsched
);
422 function pthread_attr_setschedpolicy
423 (attr
: access pthread_attr_t
;
424 policy
: int
) return int
;
426 (C
, pthread_attr_setschedpolicy
, "pthread_attr_setsched");
428 function sched_yield
return int
;
429 -- FSU_THREADS does not have sched_yield;
431 ---------------------------
432 -- P1003.1c - Section 16 --
433 ---------------------------
435 function pthread_attr_init
(attributes
: access pthread_attr_t
) return int
;
436 pragma Import
(C
, pthread_attr_init
, "pthread_attr_init");
438 function pthread_attr_destroy
439 (attributes
: access pthread_attr_t
) return int
;
440 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
442 function pthread_attr_setdetachstate
443 (attr
: access pthread_attr_t
;
444 detachstate
: int
) return int
;
445 -- FSU_THREADS has a nonstandard 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
);
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 Import
(C
, pthread_create
, "pthread_create");
459 procedure pthread_exit
(status
: System
.Address
);
460 pragma Import
(C
, pthread_exit
, "pthread_exit");
462 function pthread_self
return pthread_t
;
463 pragma Import
(C
, pthread_self
, "pthread_self");
465 --------------------------
466 -- POSIX.1c Section 17 --
467 --------------------------
469 function pthread_setspecific
470 (key
: pthread_key_t
;
471 value
: System
.Address
) return int
;
472 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
474 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
475 -- FSU_THREADS has a nonstandard pthread_getspecific
477 type destructor_pointer
is access procedure (arg
: System
.Address
);
479 function pthread_key_create
480 (key
: access pthread_key_t
;
481 destructor
: destructor_pointer
) return int
;
482 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
486 type sigset_t
is new unsigned_long
;
487 pragma Convention
(C
, sigset_t
);
489 type pid_t
is new int
;
491 subtype time_t
is long
;
493 type timespec
is record
497 pragma Convention
(C
, timespec
);
499 type clockid_t
is new int
;
500 CLOCK_REALTIME
: constant clockid_t
:= 0;
502 type struct_timeval
is record
506 pragma Convention
(C
, struct_timeval
);
508 type pthread_attr_t
is record
511 contentionscope
: int
;
516 starttime
: timespec
;
520 pragma Convention
(C_Pass_By_Copy
, pthread_attr_t
);
522 type pthread_condattr_t
is record
525 pragma Convention
(C
, pthread_condattr_t
);
527 type pthread_mutexattr_t
is record
532 pragma Convention
(C
, pthread_mutexattr_t
);
534 type sigjmp_buf
is array (Integer range 0 .. 17) of int
;
536 type pthread_t_struct
is record
537 context
: sigjmp_buf
;
541 stack_base
: System
.Address
;
543 pragma Convention
(C
, pthread_t_struct
);
545 type pthread_t
is access all pthread_t_struct
;
547 type queue_t
is record
548 head
: System
.Address
;
549 tail
: System
.Address
;
551 pragma Convention
(C
, queue_t
);
553 type pthread_mutex_t
is record
556 owner
: System
.Address
;
560 prev_max_ceiling_prio
: int
;
562 pragma Convention
(C
, pthread_mutex_t
);
564 type pthread_cond_t
is record
568 mutex
: System
.Address
;
570 pragma Convention
(C
, pthread_cond_t
);
572 type pthread_key_t
is new int
;
574 end System
.OS_Interface
;