Remove some compile time warnings about duplicate definitions.
[official-gcc.git] / gcc / ada / 5losinte.ads
blob1bc31b4433ea9e943ed76e13e30fa588409ed2c4
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 -- $Revision$
10 -- --
11 -- Copyright (C) 1991-2001 Free Software Foundation, Inc. --
12 -- --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
34 -- --
35 ------------------------------------------------------------------------------
37 -- This is a GNU/Linux (FSU THREADS) version of this package.
39 -- This package encapsulates all direct interfaces to OS services
40 -- that are needed by children of System.
42 -- PLEASE DO NOT add any with-clauses to this package
43 -- or remove the pragma Elaborate_Body.
44 -- It is designed to be a bottom-level (leaf) package.
46 with Interfaces.C;
47 package System.OS_Interface is
48 pragma Preelaborate;
50 pragma Linker_Options ("-lgthreads");
51 pragma Linker_Options ("-lmalloc");
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;
63 -----------
64 -- Errno --
65 -----------
67 function errno return int;
68 pragma Import (C, errno, "__get_errno");
70 EAGAIN : constant := 11;
71 EINTR : constant := 4;
72 EINVAL : constant := 22;
73 ENOMEM : constant := 12;
74 ETIMEDOUT : constant := 110;
76 -------------
77 -- Signals --
78 -------------
80 Max_Interrupt : constant := 31;
81 type Signal is new int range 0 .. Max_Interrupt;
82 for Signal'Size use int'Size;
84 SIGHUP : constant := 1; -- hangup
85 SIGINT : constant := 2; -- interrupt (rubout)
86 SIGQUIT : constant := 3; -- quit (ASCD FS)
87 SIGILL : constant := 4; -- illegal instruction (not reset)
88 SIGTRAP : constant := 5; -- trace trap (not reset)
89 SIGIOT : constant := 6; -- IOT instruction
90 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
91 SIGFPE : constant := 8; -- floating point exception
92 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
93 SIGBUS : constant := 7; -- bus error
94 SIGSEGV : constant := 11; -- segmentation violation
95 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
96 SIGALRM : constant := 14; -- alarm clock
97 SIGTERM : constant := 15; -- software termination signal from kill
98 SIGUSR1 : constant := 10; -- user defined signal 1
99 SIGUSR2 : constant := 12; -- user defined signal 2
100 SIGCLD : constant := 17; -- alias for SIGCHLD
101 SIGCHLD : constant := 17; -- child status change
102 SIGPWR : constant := 30; -- power-fail restart
103 SIGWINCH : constant := 28; -- window size change
104 SIGURG : constant := 23; -- urgent condition on IO channel
105 SIGPOLL : constant := 29; -- pollable event occurred
106 SIGIO : constant := 29; -- I/O now possible (4.2 BSD)
107 SIGLOST : constant := 29; -- File lock lost
108 SIGSTOP : constant := 19; -- stop (cannot be caught or ignored)
109 SIGTSTP : constant := 20; -- user stop requested from tty
110 SIGCONT : constant := 18; -- stopped process has been continued
111 SIGTTIN : constant := 21; -- background tty read attempted
112 SIGTTOU : constant := 22; -- background tty write attempted
113 SIGVTALRM : constant := 26; -- virtual timer expired
114 SIGPROF : constant := 27; -- profiling timer expired
115 SIGXCPU : constant := 24; -- CPU time limit exceeded
116 SIGXFSZ : constant := 25; -- filesize limit exceeded
117 SIGUNUSED : constant := 31; -- unused signal (GNU/Linux)
118 SIGSTKFLT : constant := 16; -- coprocessor stack fault (GNU/Linux)
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, SIGBUS, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
129 Reserved : constant Signal_Set :=
130 (SIGKILL, SIGSTOP, SIGALRM, SIGVTALRM, SIGUNUSED);
132 type sigset_t is private;
134 function sigaddset (set : access sigset_t; sig : Signal) return int;
135 pragma Import (C, sigaddset, "sigaddset");
137 function sigdelset (set : access sigset_t; sig : Signal) return int;
138 pragma Import (C, sigdelset, "sigdelset");
140 function sigfillset (set : access sigset_t) return int;
141 pragma Import (C, sigfillset, "sigfillset");
143 function sigismember (set : access sigset_t; sig : Signal) return int;
144 pragma Import (C, sigismember, "sigismember");
146 function sigemptyset (set : access sigset_t) return int;
147 pragma Import (C, sigemptyset, "sigemptyset");
149 type struct_sigaction is record
150 sa_handler : System.Address;
151 sa_mask : sigset_t;
152 sa_flags : unsigned_long;
153 sa_restorer : System.Address;
154 end record;
155 pragma Convention (C, struct_sigaction);
156 type struct_sigaction_ptr is access all struct_sigaction;
158 type Machine_State is record
159 eip : unsigned_long;
160 ebx : unsigned_long;
161 esp : unsigned_long;
162 ebp : unsigned_long;
163 esi : unsigned_long;
164 edi : unsigned_long;
165 end record;
166 type Machine_State_Ptr is access all Machine_State;
168 SIG_BLOCK : constant := 0;
169 SIG_UNBLOCK : constant := 1;
170 SIG_SETMASK : constant := 2;
172 SIG_DFL : constant := 0;
173 SIG_IGN : constant := 1;
175 function sigaction
176 (sig : Signal;
177 act : struct_sigaction_ptr;
178 oact : struct_sigaction_ptr) return int;
179 pragma Import (C, sigaction, "sigaction");
181 ----------
182 -- Time --
183 ----------
185 Time_Slice_Supported : constant Boolean := False;
186 -- Indicates wether time slicing is supported (i.e FSU threads have been
187 -- compiled with DEF_RR)
189 type timespec is private;
191 type clockid_t is private;
193 CLOCK_REALTIME : constant clockid_t;
195 function clock_gettime
196 (clock_id : clockid_t;
197 tp : access timespec) return int;
198 pragma Import (C, clock_gettime, "clock_gettime");
200 function To_Duration (TS : timespec) return Duration;
201 pragma Inline (To_Duration);
203 function To_Timespec (D : Duration) return timespec;
204 pragma Inline (To_Timespec);
206 type struct_timeval is private;
208 function To_Duration (TV : struct_timeval) return Duration;
209 pragma Inline (To_Duration);
211 function To_Timeval (D : Duration) return struct_timeval;
212 pragma Inline (To_Timeval);
214 -------------------------
215 -- Priority Scheduling --
216 -------------------------
218 SCHED_FIFO : constant := 0;
219 SCHED_RR : constant := 1;
220 SCHED_OTHER : constant := 2;
222 -------------
223 -- Process --
224 -------------
226 type pid_t is private;
228 function kill (pid : pid_t; sig : Signal) return int;
229 pragma Import (C, kill, "kill");
231 function getpid return pid_t;
232 pragma Import (C, getpid, "getpid");
234 ---------
235 -- LWP --
236 ---------
238 function lwp_self return System.Address;
239 -- lwp_self does not exist on this thread library, revert to pthread_self
240 -- which is the closest approximation (with getpid). This function is
241 -- needed to share 7staprop.adb across POSIX-like targets.
242 pragma Import (C, lwp_self, "pthread_self");
244 -------------
245 -- Threads --
246 -------------
248 type Thread_Body is access
249 function (arg : System.Address) return System.Address;
250 type pthread_t is private;
251 subtype Thread_Id is pthread_t;
253 type pthread_mutex_t is limited private;
254 type pthread_cond_t is limited private;
255 type pthread_attr_t is limited private;
256 type pthread_mutexattr_t is limited private;
257 type pthread_condattr_t is limited private;
258 type pthread_key_t is private;
260 PTHREAD_CREATE_DETACHED : constant := 1;
262 -----------
263 -- Stack --
264 -----------
266 Stack_Base_Available : constant Boolean := False;
267 -- Indicates wether the stack base is available on this target.
268 -- This allows us to share s-osinte.adb between all the FSU run time.
269 -- Note that this value can only be true if pthread_t has a complete
270 -- definition that corresponds exactly to the C header files.
272 function Get_Stack_Base (thread : pthread_t) return Address;
273 pragma Inline (Get_Stack_Base);
274 -- returns the stack base of the specified thread.
275 -- Only call this function when Stack_Base_Available is True.
277 function Get_Page_Size return size_t;
278 function Get_Page_Size return Address;
279 pragma Import (C, Get_Page_Size, "getpagesize");
280 -- returns the size of a page, or 0 if this is not relevant on this
281 -- target
283 PROT_NONE : constant := 0;
284 PROT_READ : constant := 1;
285 PROT_WRITE : constant := 2;
286 PROT_EXEC : constant := 4;
287 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
289 PROT_ON : constant := PROT_NONE;
290 PROT_OFF : constant := PROT_ALL;
292 function mprotect (addr : Address; len : size_t; prot : int) return int;
293 pragma Import (C, mprotect);
295 ---------------------------------------
296 -- Nonstandard Thread Initialization --
297 ---------------------------------------
299 procedure pthread_init;
300 -- FSU_THREADS requires pthread_init, which is nonstandard
301 -- and this should be invoked during the elaboration of s-taprop.adb
302 pragma Import (C, pthread_init, "pthread_init");
304 -------------------------
305 -- POSIX.1c Section 3 --
306 -------------------------
308 function sigwait
309 (set : access sigset_t;
310 sig : access Signal) return int;
311 pragma Inline (sigwait);
312 -- FSU_THREADS has a nonstandard sigwait
314 function pthread_kill
315 (thread : pthread_t;
316 sig : Signal) return int;
317 pragma Import (C, pthread_kill, "pthread_kill");
319 -- FSU threads does not have pthread_sigmask. Instead, it uses
320 -- sigprocmask to do the signal handling when the thread library is
321 -- sucked in.
323 type sigset_t_ptr is access all sigset_t;
325 function pthread_sigmask
326 (how : int;
327 set : sigset_t_ptr;
328 oset : sigset_t_ptr) return int;
329 pragma Import (C, pthread_sigmask, "sigprocmask");
331 --------------------------
332 -- POSIX.1c Section 11 --
333 --------------------------
335 function pthread_mutexattr_init
336 (attr : access pthread_mutexattr_t) return int;
337 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
339 function pthread_mutexattr_destroy
340 (attr : access pthread_mutexattr_t) return int;
341 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
343 function pthread_mutex_init
344 (mutex : access pthread_mutex_t;
345 attr : access pthread_mutexattr_t) return int;
346 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
348 function pthread_mutex_destroy
349 (mutex : access pthread_mutex_t) return int;
350 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
352 function pthread_mutex_lock
353 (mutex : access pthread_mutex_t) return int;
354 pragma Inline (pthread_mutex_lock);
355 -- FSU_THREADS has nonstandard pthread_mutex_lock
357 function pthread_mutex_unlock
358 (mutex : access pthread_mutex_t) return int;
359 pragma Inline (pthread_mutex_unlock);
360 -- FSU_THREADS has nonstandard pthread_mutex_lock
362 function pthread_condattr_init
363 (attr : access pthread_condattr_t) return int;
364 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
366 function pthread_condattr_destroy
367 (attr : access pthread_condattr_t) return int;
368 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
370 function pthread_cond_init
371 (cond : access pthread_cond_t;
372 attr : access pthread_condattr_t) return int;
373 pragma Import (C, pthread_cond_init, "pthread_cond_init");
375 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
376 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
378 function pthread_cond_signal (cond : access pthread_cond_t) return int;
379 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
381 function pthread_cond_wait
382 (cond : access pthread_cond_t;
383 mutex : access pthread_mutex_t) return int;
384 pragma Inline (pthread_cond_wait);
385 -- FSU_THREADS has a nonstandard pthread_cond_wait
387 function pthread_cond_timedwait
388 (cond : access pthread_cond_t;
389 mutex : access pthread_mutex_t;
390 abstime : access timespec) return int;
391 pragma Inline (pthread_cond_timedwait);
392 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
394 Relative_Timed_Wait : constant Boolean := False;
395 -- pthread_cond_timedwait requires an absolute delay time
397 --------------------------
398 -- POSIX.1c Section 13 --
399 --------------------------
401 PTHREAD_PRIO_NONE : constant := 0;
402 PTHREAD_PRIO_PROTECT : constant := 2;
403 PTHREAD_PRIO_INHERIT : constant := 1;
405 function pthread_mutexattr_setprotocol
406 (attr : access pthread_mutexattr_t;
407 protocol : int) return int;
408 pragma Import (C, pthread_mutexattr_setprotocol);
410 function pthread_mutexattr_setprioceiling
411 (attr : access pthread_mutexattr_t;
412 prioceiling : int) return int;
413 pragma Import
414 (C, pthread_mutexattr_setprioceiling,
415 "pthread_mutexattr_setprio_ceiling");
417 type struct_sched_param is record
418 sched_priority : int; -- scheduling priority
419 end record;
421 function pthread_setschedparam
422 (thread : pthread_t;
423 policy : int;
424 param : access struct_sched_param) return int;
425 pragma Inline (pthread_setschedparam);
426 -- FSU_THREADS does not have pthread_setschedparam
428 function pthread_attr_setscope
429 (attr : access pthread_attr_t;
430 contentionscope : int) return int;
431 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
433 function pthread_attr_setinheritsched
434 (attr : access pthread_attr_t;
435 inheritsched : int) return int;
436 pragma Import (C, pthread_attr_setinheritsched);
438 function pthread_attr_setschedpolicy
439 (attr : access pthread_attr_t;
440 policy : int) return int;
441 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
443 function sched_yield return int;
444 pragma Inline (sched_yield);
445 -- FSU_THREADS does not have sched_yield;
447 ---------------------------
448 -- P1003.1c - Section 16 --
449 ---------------------------
451 function pthread_attr_init (attributes : access pthread_attr_t) return int;
452 pragma Import (C, pthread_attr_init, "pthread_attr_init");
454 function pthread_attr_destroy
455 (attributes : access pthread_attr_t) return int;
456 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
458 function pthread_attr_setdetachstate
459 (attr : access pthread_attr_t;
460 detachstate : int) return int;
461 pragma Inline (pthread_attr_setdetachstate);
462 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
464 function pthread_attr_setstacksize
465 (attr : access pthread_attr_t;
466 stacksize : size_t) return int;
467 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
469 function pthread_create
470 (thread : access pthread_t;
471 attributes : access pthread_attr_t;
472 start_routine : Thread_Body;
473 arg : System.Address) return int;
474 pragma Import (C, pthread_create, "pthread_create");
476 procedure pthread_exit (status : System.Address);
477 pragma Import (C, pthread_exit, "pthread_exit");
479 function pthread_self return pthread_t;
480 pragma Import (C, pthread_self, "pthread_self");
482 --------------------------
483 -- POSIX.1c Section 17 --
484 --------------------------
486 function pthread_setspecific
487 (key : pthread_key_t;
488 value : System.Address) return int;
489 pragma Import (C, pthread_setspecific, "pthread_setspecific");
491 function pthread_getspecific (key : pthread_key_t) return System.Address;
492 pragma Inline (pthread_getspecific);
493 -- FSU_THREADS has a nonstandard pthread_getspecific
495 type destructor_pointer is access procedure (arg : System.Address);
497 function pthread_key_create
498 (key : access pthread_key_t;
499 destructor : destructor_pointer) return int;
500 pragma Import (C, pthread_key_create, "pthread_key_create");
502 private
504 type sigset_t is array (0 .. 31) of unsigned_long;
505 pragma Convention (C, sigset_t);
506 -- This is for GNU libc version 2 but should be backward compatible with
507 -- other libc where sigset_t is smaller.
509 type pid_t is new int;
511 type time_t is new long;
513 type timespec is record
514 tv_sec : time_t;
515 tv_nsec : long;
516 end record;
517 pragma Convention (C, timespec);
519 type clockid_t is new int;
520 CLOCK_REALTIME : constant clockid_t := 0;
522 type struct_timeval is record
523 tv_sec : long;
524 tv_usec : long;
525 end record;
526 pragma Convention (C, struct_timeval);
528 type pthread_attr_t is record
529 flags : int;
530 stacksize : int;
531 contentionscope : int;
532 inheritsched : int;
533 detachstate : int;
534 sched : int;
535 prio : int;
536 starttime : timespec;
537 deadline : timespec;
538 period : timespec;
539 end record;
540 pragma Convention (C_Pass_By_Copy, pthread_attr_t);
542 type pthread_condattr_t is record
543 flags : int;
544 end record;
545 pragma Convention (C, pthread_condattr_t);
547 type pthread_mutexattr_t is record
548 flags : int;
549 prio_ceiling : int;
550 protocol : int;
551 end record;
552 pragma Convention (C, pthread_mutexattr_t);
554 type sigjmp_buf is array (Integer range 0 .. 38) of int;
556 type pthread_t_struct is record
557 context : sigjmp_buf;
558 pbody : sigjmp_buf;
559 errno : int;
560 ret : int;
561 stack_base : System.Address;
562 end record;
563 pragma Convention (C, pthread_t_struct);
565 type pthread_t is access all pthread_t_struct;
567 type queue_t is record
568 head : System.Address;
569 tail : System.Address;
570 end record;
571 pragma Convention (C, queue_t);
573 type pthread_mutex_t is record
574 queue : queue_t;
575 lock : plain_char;
576 owner : System.Address;
577 flags : int;
578 prio_ceiling : int;
579 protocol : int;
580 prev_max_ceiling_prio : int;
581 end record;
582 pragma Convention (C, pthread_mutex_t);
584 type pthread_cond_t is record
585 queue : queue_t;
586 flags : int;
587 waiters : int;
588 mutex : System.Address;
589 end record;
590 pragma Convention (C, pthread_cond_t);
592 type pthread_key_t is new int;
594 end System.OS_Interface;