2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / 5rosinte.ads
blob710176c12226f3875081af453aae41aa97d36729
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . O S _ I N T E R F A C E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1997-2003 Free Software Foundation, Inc. --
10 -- --
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. --
21 -- --
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. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 -- The GNARL files that were developed for RTEMS are maintained by On-Line --
33 -- Applications Research Corporation (http://www.oarcorp.com) in coopera- --
34 -- tion with Ada Core Technologies Inc. and Florida State University. --
35 -- --
36 ------------------------------------------------------------------------------
38 -- This is the RTEMS version of this package
40 -- These are guesses based on what I think the GNARL team will want to
41 -- call the rtems configurations. We use CPU-rtems for the rtems
42 -- configurations.
44 -- This package encapsulates all direct interfaces to OS services
45 -- that are needed by children of System.
47 -- PLEASE DO NOT add any with-clauses to this package
48 -- or remove the pragma Elaborate_Body.
49 -- It is designed to be a bottom-level (leaf) package.
51 with Interfaces.C;
52 package System.OS_Interface is
53 pragma Preelaborate;
55 -- This interface assumes that "unsigned" is a 32-bit entity. This
56 -- will correspond to RTEMS object ids.
58 subtype rtems_id is Interfaces.C.unsigned;
60 subtype int is Interfaces.C.int;
61 subtype short is Interfaces.C.short;
62 subtype long is Interfaces.C.long;
63 subtype unsigned is Interfaces.C.unsigned;
64 subtype unsigned_short is Interfaces.C.unsigned_short;
65 subtype unsigned_long is Interfaces.C.unsigned_long;
66 subtype unsigned_char is Interfaces.C.unsigned_char;
67 subtype plain_char is Interfaces.C.plain_char;
68 subtype size_t is Interfaces.C.size_t;
70 -----------
71 -- Errno --
72 -----------
74 function errno return int;
75 pragma Import (C, errno, "__get_errno");
77 EAGAIN : constant := 11;
78 EINTR : constant := 4;
79 EINVAL : constant := 22;
80 ENOMEM : constant := 12;
81 ETIMEDOUT : constant := 116;
83 -------------
84 -- Signals --
85 -------------
87 Max_Interrupt : constant := 31;
88 type Signal is new int range 0 .. Max_Interrupt;
90 SIGXCPU : constant := 0; -- XCPU
91 SIGHUP : constant := 1; -- hangup
92 SIGINT : constant := 2; -- interrupt (rubout)
93 SIGQUIT : constant := 3; -- quit (ASCD FS)
94 SIGILL : constant := 4; -- illegal instruction (not reset)
95 SIGTRAP : constant := 5; -- trace trap (not reset)
96 SIGIOT : constant := 6; -- IOT instruction
97 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
98 SIGEMT : constant := 7; -- EMT instruction
99 SIGFPE : constant := 8; -- floating point exception
100 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
101 SIGBUS : constant := 10; -- bus error
102 SIGSEGV : constant := 11; -- segmentation violation
103 SIGSYS : constant := 12; -- bad argument to system call
104 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
105 SIGALRM : constant := 14; -- alarm clock
106 SIGTERM : constant := 15; -- software termination signal from kill
107 SIGUSR1 : constant := 16; -- user defined signal 1
108 SIGUSR2 : constant := 17; -- user defined signal 2
110 SIGADAABORT : constant := SIGABRT;
112 type Signal_Set is array (Natural range <>) of Signal;
114 Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT);
115 Reserved : constant Signal_Set := (1 .. 1 => SIGKILL);
117 type sigset_t is private;
119 function sigaddset (set : access sigset_t; sig : Signal) return int;
120 pragma Import (C, sigaddset, "sigaddset");
122 function sigdelset (set : access sigset_t; sig : Signal) return int;
123 pragma Import (C, sigdelset, "sigdelset");
125 function sigfillset (set : access sigset_t) return int;
126 pragma Import (C, sigfillset, "sigfillset");
128 function sigismember (set : access sigset_t; sig : Signal) return int;
129 pragma Import (C, sigismember, "sigismember");
131 function sigemptyset (set : access sigset_t) return int;
132 pragma Import (C, sigemptyset, "sigemptyset");
134 type struct_sigaction is record
135 sa_flags : int;
136 sa_mask : sigset_t;
137 sa_handler : System.Address;
138 end record;
139 pragma Convention (C, struct_sigaction);
140 type struct_sigaction_ptr is access all struct_sigaction;
142 SIG_BLOCK : constant := 1;
143 SIG_UNBLOCK : constant := 2;
144 SIG_SETMASK : constant := 3;
146 SIG_DFL : constant := 0;
147 SIG_IGN : constant := 1;
149 function sigaction
150 (sig : Signal;
151 act : struct_sigaction_ptr;
152 oact : struct_sigaction_ptr) return int;
153 pragma Import (C, sigaction, "sigaction");
155 ----------
156 -- Time --
157 ----------
159 Time_Slice_Supported : constant Boolean := True;
160 -- Indicates wether time slicing is supported (i.e SCHED_RR is supported)
162 type timespec is private;
164 type clockid_t is private;
166 CLOCK_REALTIME : constant clockid_t;
168 function clock_gettime
169 (clock_id : clockid_t;
170 tp : access timespec) return int;
171 pragma Import (C, clock_gettime, "clock_gettime");
173 function To_Duration (TS : timespec) return Duration;
174 pragma Inline (To_Duration);
176 function To_Timespec (D : Duration) return timespec;
177 pragma Inline (To_Timespec);
179 type struct_timeval is private;
181 function To_Duration (TV : struct_timeval) return Duration;
182 pragma Inline (To_Duration);
184 function To_Timeval (D : Duration) return struct_timeval;
185 pragma Inline (To_Timeval);
187 -------------------------
188 -- Priority Scheduling --
189 -------------------------
191 SCHED_FIFO : constant := 1;
192 SCHED_RR : constant := 2;
193 SCHED_OTHER : constant := 0;
195 -------------
196 -- Process --
197 -------------
199 type pid_t is private;
201 function kill (pid : pid_t; sig : Signal) return int;
202 pragma Import (C, kill, "kill");
204 function getpid return pid_t;
205 pragma Import (C, getpid, "getpid");
207 ---------
208 -- LWP --
209 ---------
211 function lwp_self return System.Address;
212 -- lwp_self does not exist on this thread library, revert to pthread_self
213 -- which is the closest approximation (with getpid). This function is
214 -- needed to share 7staprop.adb across POSIX-like targets.
215 pragma Import (C, lwp_self, "pthread_self");
217 -------------
218 -- Threads --
219 -------------
221 type Thread_Body is access
222 function (arg : System.Address) return System.Address;
224 type pthread_t is private;
225 subtype Thread_Id is pthread_t;
227 type pthread_mutex_t is limited private;
228 type pthread_cond_t is limited private;
229 type pthread_attr_t is limited private;
230 type pthread_mutexattr_t is limited private;
231 type pthread_condattr_t is limited private;
232 type pthread_key_t is private;
234 PTHREAD_CREATE_DETACHED : constant := 0;
236 -----------
237 -- Stack --
238 -----------
240 Stack_Base_Available : constant Boolean := False;
241 -- Indicates wether the stack base is available on this target.
242 -- This allows us to share s-osinte.adb between all the FSU/RTEMS
243 -- 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 -- These two functions are only needed to share s-taprop.adb with
253 -- FSU threads.
255 function Get_Page_Size return size_t;
256 function Get_Page_Size return Address;
257 -- returns the size of a page, or 0 if this is not relevant on this
258 -- target (which is the case for RTEMS)
260 PROT_ON : constant := 0;
261 PROT_OFF : constant := 0;
263 function mprotect (addr : Address; len : size_t; prot : int) return int;
264 -- Do nothing on RTEMS.
266 -----------------------------------------
267 -- Nonstandard Thread Initialization --
268 -----------------------------------------
270 procedure pthread_init;
271 -- FSU_THREADS requires pthread_init, which is nonstandard
272 -- and this should be invoked during the elaboration of s-taprop.adb
274 -- RTEMS does not require this so we provide an empty Ada body.
276 -------------------------
277 -- POSIX.1c Section 3 --
278 -------------------------
280 function sigwait
281 (set : access sigset_t;
282 sig : access Signal) return int;
283 pragma Import (C, sigwait, "sigwait");
285 function pthread_kill
286 (thread : pthread_t;
287 sig : Signal) return int;
288 pragma Import (C, pthread_kill, "pthread_kill");
290 type sigset_t_ptr is access all sigset_t;
292 function pthread_sigmask
293 (how : int;
294 set : sigset_t_ptr;
295 oset : sigset_t_ptr) return int;
296 pragma Import (C, pthread_sigmask, "pthread_sigmask");
298 ----------------------------
299 -- POSIX.1c Section 11 --
300 ----------------------------
302 function pthread_mutexattr_init
303 (attr : access pthread_mutexattr_t) return int;
304 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
306 function pthread_mutexattr_destroy
307 (attr : access pthread_mutexattr_t) return int;
308 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
310 function pthread_mutex_init
311 (mutex : access pthread_mutex_t;
312 attr : access pthread_mutexattr_t) return int;
313 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
315 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
316 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
318 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
319 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
321 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
322 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
324 function pthread_condattr_init
325 (attr : access pthread_condattr_t) return int;
326 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
328 function pthread_condattr_destroy
329 (attr : access pthread_condattr_t) return int;
330 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
332 function pthread_cond_init
333 (cond : access pthread_cond_t;
334 attr : access pthread_condattr_t) return int;
335 pragma Import (C, pthread_cond_init, "pthread_cond_init");
337 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
338 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
340 function pthread_cond_signal (cond : access pthread_cond_t) return int;
341 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
343 function pthread_cond_wait
344 (cond : access pthread_cond_t;
345 mutex : access pthread_mutex_t) return int;
346 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
348 function pthread_cond_timedwait
349 (cond : access pthread_cond_t;
350 mutex : access pthread_mutex_t;
351 abstime : access timespec) return int;
352 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
354 Relative_Timed_Wait : constant Boolean := False;
355 -- pthread_cond_timedwait requires an absolute delay time
357 --------------------------
358 -- POSIX.1c Section 13 --
359 --------------------------
361 PTHREAD_PRIO_NONE : constant := 0;
362 PTHREAD_PRIO_PROTECT : constant := 2;
363 PTHREAD_PRIO_INHERIT : constant := 1;
365 function pthread_mutexattr_setprotocol
366 (attr : access pthread_mutexattr_t;
367 protocol : int) return int;
368 pragma Import (C, pthread_mutexattr_setprotocol);
370 function pthread_mutexattr_setprioceiling
371 (attr : access pthread_mutexattr_t;
372 prioceiling : int) return int;
373 pragma Import
374 (C, pthread_mutexattr_setprioceiling,
375 "pthread_mutexattr_setprioceiling");
377 type struct_sched_param is record
378 sched_priority : int;
379 ss_low_priority : timespec;
380 ss_replenish_period : timespec;
381 ss_initial_budget : timespec;
382 end record;
383 pragma Convention (C, struct_sched_param);
385 function pthread_setschedparam
386 (thread : pthread_t;
387 policy : int;
388 param : access struct_sched_param) return int;
389 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
391 function pthread_attr_setscope
392 (attr : access pthread_attr_t;
393 contentionscope : int) return int;
394 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
396 function pthread_attr_setinheritsched
397 (attr : access pthread_attr_t;
398 inheritsched : int) return int;
399 pragma Import (C, pthread_attr_setinheritsched);
401 function pthread_attr_setschedpolicy
402 (attr : access pthread_attr_t;
403 policy : int) return int;
404 pragma Import (C, pthread_attr_setschedpolicy);
406 function pthread_attr_setschedparam
407 (attr : access pthread_attr_t;
408 sched_param : int) return int;
409 pragma Import (C, pthread_attr_setschedparam);
411 function sched_yield return int;
412 pragma Import (C, sched_yield, "sched_yield");
414 ---------------------------
415 -- P1003.1c - Section 16 --
416 ---------------------------
418 function pthread_attr_init (attributes : access pthread_attr_t) return int;
419 pragma Import (C, pthread_attr_init, "pthread_attr_init");
421 function pthread_attr_destroy
422 (attributes : access pthread_attr_t) return int;
423 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
425 function pthread_attr_setdetachstate
426 (attr : access pthread_attr_t;
427 detachstate : int) return int;
428 pragma Import (C, pthread_attr_setdetachstate);
430 function pthread_attr_setstacksize
431 (attr : access pthread_attr_t;
432 stacksize : size_t) return int;
433 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
435 function pthread_create
436 (thread : access pthread_t;
437 attributes : access pthread_attr_t;
438 start_routine : Thread_Body;
439 arg : System.Address) return int;
440 pragma Import (C, pthread_create, "pthread_create");
442 procedure pthread_exit (status : System.Address);
443 pragma Import (C, pthread_exit, "pthread_exit");
445 function pthread_self return pthread_t;
446 pragma Import (C, pthread_self, "pthread_self");
448 --------------------------
449 -- POSIX.1c Section 17 --
450 --------------------------
452 function pthread_setspecific
453 (key : pthread_key_t;
454 value : System.Address) return int;
455 pragma Import (C, pthread_setspecific, "pthread_setspecific");
457 function pthread_getspecific (key : pthread_key_t) return System.Address;
458 pragma Import (C, pthread_getspecific, "pthread_getspecific");
460 type destructor_pointer is access procedure (arg : System.Address);
462 function pthread_key_create
463 (key : access pthread_key_t;
464 destructor : destructor_pointer) return int;
465 pragma Import (C, pthread_key_create, "pthread_key_create");
467 private
469 type sigset_t is new int;
471 type pid_t is new int;
473 type time_t is new long;
475 type timespec is record
476 tv_sec : time_t;
477 tv_nsec : long;
478 end record;
479 pragma Convention (C, timespec);
481 type clockid_t is new rtems_id;
482 CLOCK_REALTIME : constant clockid_t := 1;
484 type struct_timeval is record
485 tv_sec : int;
486 tv_usec : int;
487 end record;
488 pragma Convention (C, struct_timeval);
490 type pthread_attr_t is record
491 is_initialized : int;
492 stackaddr : System.Address;
493 stacksize : int;
494 contentionscope : int;
495 inheritsched : int;
496 schedpolicy : int;
497 schedparam : struct_sched_param;
498 cputime_clocked_allowed : int;
499 deatchstate : int;
500 end record;
501 pragma Convention (C, pthread_attr_t);
503 type pthread_condattr_t is record
504 flags : int;
505 end record;
506 pragma Convention (C, pthread_condattr_t);
508 type pthread_mutexattr_t is record
509 is_initialized : int;
510 process_shared : int;
511 prio_ceiling : int;
512 protocol : int;
513 recursive : int;
514 end record;
515 pragma Convention (C, pthread_mutexattr_t);
517 type pthread_t is new rtems_id;
519 type pthread_mutex_t is new rtems_id;
521 type pthread_cond_t is new rtems_id;
523 type pthread_key_t is new rtems_id;
525 end System.OS_Interface;