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 --
10 -- Copyright (C) 1992-2001, 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 a DOS/DJGPPv2 (FSU THREAD) 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
41 -- or remove the pragma Elaborate_Body.
42 -- It is designed to be a bottom-level (leaf) package.
45 package System.OS_Interface is
49 -- A short name for libgthreads.a to keep Mike Feldman happy.
51 pragma Linker_Options ("-lgthre");
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 := 5;
71 EINTR : constant := 13;
72 EINVAL : constant := 14;
73 ENOMEM : constant := 25;
79 Max_Interrupt : constant := 319;
80 type Signal is new int range 0 .. Max_Interrupt;
82 SIGHUP : constant := 294; -- hangup
83 SIGINT : constant := 295; -- interrupt (rubout)
84 SIGQUIT : constant := 298; -- quit (ASCD FS)
85 SIGILL : constant := 290; -- illegal instruction (not reset)
86 SIGABRT : constant := 288; -- used by abort
87 SIGFPE : constant := 289; -- floating point exception
88 SIGKILL : constant := 296; -- kill (cannot be caught or ignored)
89 SIGSEGV : constant := 291; -- segmentation violation
90 SIGPIPE : constant := 297; -- write on a pipe with no one to read it
91 SIGALRM : constant := 293; -- alarm clock
92 SIGTERM : constant := 292; -- software termination signal from kill
93 SIGUSR1 : constant := 299; -- user defined signal 1
94 SIGUSR2 : constant := 300; -- user defined signal 2
95 SIGBUS : constant := 0;
97 SIGADAABORT : constant := SIGABRT;
99 type Signal_Set is array (Natural range <>) of Signal;
101 Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM);
102 Reserved : constant Signal_Set := (0 .. 0 => SIGSTOP);
104 type sigset_t is private;
106 function sigaddset (set : access sigset_t; sig : Signal) return int;
107 pragma Import (C, sigaddset, "sigaddset");
109 function sigdelset (set : access sigset_t; sig : Signal) return int;
110 pragma Import (C, sigdelset, "sigdelset");
112 function sigfillset (set : access sigset_t) return int;
113 pragma Import (C, sigfillset, "sigfillset");
115 function sigismember (set : access sigset_t; sig : Signal) return int;
116 pragma Import (C, sigismember, "sigismember");
118 function sigemptyset (set : access sigset_t) return int;
119 pragma Import (C, sigemptyset, "sigemptyset");
121 type struct_sigaction is record
123 sa_handler : System.Address;
126 pragma Convention (C, struct_sigaction);
127 type struct_sigaction_ptr is access all struct_sigaction;
129 SIG_BLOCK : constant := 1;
130 SIG_UNBLOCK : constant := 3;
131 SIG_SETMASK : constant := 2;
133 SIG_DFL : constant := 0;
134 SIG_IGN : constant := -1;
138 act : struct_sigaction_ptr;
139 oact : struct_sigaction_ptr) return int;
140 pragma Import (C, sigaction, "sigaction");
146 Time_Slice_Supported : constant Boolean := False;
147 -- Indicates wether time slicing is supported (i.e FSU threads have been
148 -- compiled with DEF_RR)
150 type timespec is private;
152 function nanosleep (rqtp, rmtp : access timespec) return int;
153 -- FSU_THREADS has nonstandard nanosleep
154 type clockid_t is private;
156 CLOCK_REALTIME : constant clockid_t;
158 function clock_gettime
159 (clock_id : clockid_t;
160 tp : access timespec) return int;
161 pragma Import (C, clock_gettime, "clock_gettime");
163 function To_Duration (TS : timespec) return Duration;
164 pragma Inline (To_Duration);
166 function To_Timespec (D : Duration) return timespec;
167 pragma Inline (To_Timespec);
169 type struct_timeval is private;
171 function To_Duration (TV : struct_timeval) return Duration;
172 pragma Inline (To_Duration);
174 function To_Timeval (D : Duration) return struct_timeval;
175 pragma Inline (To_Timeval);
177 -------------------------
178 -- Priority Scheduling --
179 -------------------------
181 SCHED_FIFO : constant := 0;
182 SCHED_RR : constant := 1;
183 SCHED_OTHER : constant := 2;
189 type pid_t is private;
191 function kill (pid : pid_t; sig : Signal) return int;
192 pragma Import (C, kill, "kill");
194 function getpid return pid_t;
195 pragma Import (C, getpid, "getpid");
201 function lwp_self return System.Address;
202 -- lwp_self does not exist on this thread library, revert to pthread_self
203 -- which is the closest approximation (with getpid). This function is
204 -- needed to share 7staprop.adb across POSIX-like targets.
205 pragma Import (C, lwp_self, "pthread_self");
211 type Thread_Body is access
212 function (arg : System.Address) return System.Address;
214 type pthread_t is private;
215 subtype Thread_Id is pthread_t;
217 type pthread_mutex_t is limited private;
218 type pthread_cond_t is limited private;
219 type pthread_attr_t is limited private;
220 type pthread_mutexattr_t is limited private;
221 type pthread_condattr_t is limited private;
222 type pthread_key_t is private;
224 PTHREAD_CREATE_DETACHED : constant := 1;
230 Stack_Base_Available : constant Boolean := False;
231 -- Indicates wether the stack base is available on this target.
232 -- This allows us to share s-osinte.adb between all the FSU run time.
233 -- Note that this value can only be true if pthread_t has a complete
234 -- definition that corresponds exactly to the C header files.
236 function Get_Stack_Base (thread : pthread_t) return Address;
237 pragma Inline (Get_Stack_Base);
238 -- returns the stack base of the specified thread.
239 -- Only call this function when Stack_Base_Available is True.
241 function Get_Page_Size return size_t;
242 function Get_Page_Size return Address;
243 pragma Import (C, Get_Page_Size, "getpagesize");
244 -- returns the size of a page, or 0 if this is not relevant on this
247 PROT_NONE : constant := 0;
248 PROT_READ : constant := 1;
249 PROT_WRITE : constant := 2;
250 PROT_EXEC : constant := 4;
251 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
253 PROT_ON : constant := PROT_NONE;
254 PROT_OFF : constant := PROT_ALL;
257 (addr : Address; len : size_t; prot : int) return int;
258 pragma Import (C, mprotect);
260 ---------------------------------------
261 -- Nonstandard Thread Initialization --
262 ---------------------------------------
264 procedure pthread_init;
265 -- FSU_THREADS requires pthread_init, which is nonstandard
266 -- and this should be invoked during the elaboration of s-taprop.adb
267 pragma Import (C, pthread_init, "pthread_init");
269 -------------------------
270 -- POSIX.1c Section 3 --
271 -------------------------
273 function sigwait (set : access sigset_t; sig : access Signal) return int;
274 -- FSU_THREADS has a nonstandard sigwait
276 function pthread_kill (thread : pthread_t; sig : Signal) return int;
277 pragma Import (C, pthread_kill, "pthread_kill");
279 type sigset_t_ptr is access all sigset_t;
281 function pthread_sigmask
284 oset : sigset_t_ptr) return int;
285 pragma Import (C, pthread_sigmask, "sigprocmask");
287 --------------------------
288 -- POSIX.1c Section 11 --
289 --------------------------
291 function pthread_mutexattr_init
292 (attr : access pthread_mutexattr_t) return int;
293 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
295 function pthread_mutexattr_destroy
296 (attr : access pthread_mutexattr_t) return int;
297 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
299 function pthread_mutex_init
300 (mutex : access pthread_mutex_t;
301 attr : access pthread_mutexattr_t) return int;
302 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
304 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
305 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
307 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
308 -- FSU_THREADS has nonstandard pthread_mutex_lock
310 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
311 -- FSU_THREADS has nonstandard pthread_mutex_lock
313 function pthread_condattr_init
314 (attr : access pthread_condattr_t) return int;
315 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
317 function pthread_condattr_destroy
318 (attr : access pthread_condattr_t) return int;
319 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
321 function pthread_cond_init
322 (cond : access pthread_cond_t;
323 attr : access pthread_condattr_t) return int;
324 pragma Import (C, pthread_cond_init, "pthread_cond_init");
326 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
327 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
329 function pthread_cond_signal (cond : access pthread_cond_t) return int;
330 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
332 function pthread_cond_wait
333 (cond : access pthread_cond_t;
334 mutex : access pthread_mutex_t) return int;
335 -- FSU_THREADS has a nonstandard pthread_cond_wait
337 function pthread_cond_timedwait
338 (cond : access pthread_cond_t;
339 mutex : access pthread_mutex_t;
340 abstime : access timespec) return int;
341 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
343 Relative_Timed_Wait : constant Boolean := False;
344 -- pthread_cond_timedwait requires an absolute delay time
346 --------------------------
347 -- POSIX.1c Section 13 --
348 --------------------------
350 PTHREAD_PRIO_NONE : constant := 0;
351 PTHREAD_PRIO_PROTECT : constant := 2;
352 PTHREAD_PRIO_INHERIT : constant := 1;
354 function pthread_mutexattr_setprotocol
355 (attr : access pthread_mutexattr_t;
356 protocol : int) return int;
357 pragma Import (C, pthread_mutexattr_setprotocol);
359 function pthread_mutexattr_setprioceiling
360 (attr : access pthread_mutexattr_t;
361 prioceiling : int) return int;
362 pragma Import (C, pthread_mutexattr_setprioceiling);
364 type struct_sched_param is record
365 sched_priority : int; -- scheduling priority
368 function pthread_setschedparam
371 param : access struct_sched_param) return int;
372 -- FSU_THREADS does not have pthread_setschedparam
374 function pthread_attr_setscope
375 (attr : access pthread_attr_t;
376 contentionscope : int) return int;
377 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
379 function pthread_attr_setinheritsched
380 (attr : access pthread_attr_t;
381 inheritsched : int) return int;
382 pragma Import (C, pthread_attr_setinheritsched);
384 function pthread_attr_setschedpolicy
385 (attr : access pthread_attr_t;
386 policy : int) return int;
387 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
389 function sched_yield return int;
390 -- FSU_THREADS does not have sched_yield;
392 ---------------------------
393 -- P1003.1c - Section 16 --
394 ---------------------------
396 function pthread_attr_init (attributes : access pthread_attr_t) return int;
397 pragma Import (C, pthread_attr_init);
399 function pthread_attr_destroy
400 (attributes : access pthread_attr_t) return int;
401 pragma Import (C, pthread_attr_destroy);
403 function pthread_attr_setdetachstate
404 (attr : access pthread_attr_t;
405 detachstate : int) return int;
406 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
408 function pthread_attr_setstacksize
409 (attr : access pthread_attr_t;
410 stacksize : size_t) return int;
411 pragma Import (C, pthread_attr_setstacksize);
413 function pthread_create
414 (thread : access pthread_t;
415 attributes : access pthread_attr_t;
416 start_routine : Thread_Body;
417 arg : System.Address) return int;
418 pragma Import (C, pthread_create);
420 procedure pthread_exit (status : System.Address);
421 pragma Import (C, pthread_exit, "pthread_exit");
423 function pthread_self return pthread_t;
424 pragma Import (C, pthread_self, "pthread_self");
426 --------------------------
427 -- POSIX.1c Section 17 --
428 --------------------------
430 function pthread_setspecific
431 (key : pthread_key_t;
432 value : System.Address) return int;
433 pragma Import (C, pthread_setspecific, "pthread_setspecific");
435 function pthread_getspecific (key : pthread_key_t) return System.Address;
436 -- FSU_THREADS has a nonstandard pthread_getspecific
438 type destructor_pointer is access procedure (arg : System.Address);
440 function pthread_key_create
441 (key : access pthread_key_t;
442 destructor : destructor_pointer) return int;
443 pragma Import (C, pthread_key_create, "pthread_key_create");
447 type bits_arr_t is array (Integer range 1 .. 10) of long;
448 type sigset_t is record
452 type pid_t is new int;
454 type time_t is new long;
456 type timespec is record
460 pragma Convention (C, timespec);
462 type clockid_t is new int;
463 CLOCK_REALTIME : constant clockid_t := 0;
465 type struct_timeval is record
469 pragma Convention (C, struct_timeval);
471 type pthread_attr_t is record
474 contentionscope : int;
479 starttime : timespec;
483 pragma Convention (C, pthread_attr_t);
485 type pthread_condattr_t is record
488 pragma Convention (C, pthread_condattr_t);
490 type pthread_mutexattr_t is record
495 pragma Convention (C, pthread_mutexattr_t);
497 type sigjmp_buf is array (Integer range 0 .. 43) of int;
499 type pthread_t_struct is record
500 context : sigjmp_buf;
504 stack_base : System.Address;
506 pragma Convention (C, pthread_t_struct);
508 type pthread_t is access all pthread_t_struct;
510 type queue_t is record
511 head : System.Address;
512 tail : System.Address;
514 pragma Convention (C, queue_t);
516 type pthread_mutex_t is record
519 owner : System.Address;
523 prev_max_ceiling_prio : int;
525 pragma Convention (C, pthread_mutex_t);
527 type pthread_cond_t is record
531 mutex : System.Address;
533 pragma Convention (C, pthread_cond_t);
535 type pthread_key_t is new int;
537 end System.OS_Interface;