* MAINTAINERS: (Write After Approval): Add myself.
[official-gcc.git] / gcc / ada / 5iosinte.ads
blob0144a8a0ab31af6a9b64686ffd5d27a1e21873e4
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 -- --
10 -- Copyright (C) 1991-2001 Free Software Foundation, Inc. --
11 -- --
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. --
22 -- --
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. --
29 -- --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This is a GNU/Linux (GNU/LinuxThreads) version of this package.
38 -- This package encapsulates all direct interfaces to OS services
39 -- that are needed by children of System.
41 -- PLEASE DO NOT add any with-clauses to this package
42 -- or remove the pragma Elaborate_Body.
43 -- It is designed to be a bottom-level (leaf) package.
45 with Interfaces.C;
46 package System.OS_Interface is
47 pragma Preelaborate;
49 pragma Linker_Options ("-lpthread");
51 subtype int is Interfaces.C.int;
52 subtype char is Interfaces.C.char;
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;
62 -----------
63 -- Errno --
64 -----------
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 EPERM : constant := 1;
74 ETIMEDOUT : constant := 110;
76 -------------
77 -- Signals --
78 -------------
80 Max_Interrupt : constant := 63;
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 (Linux)
119 SIGLTHRRES : constant := 32; -- GNU/LinuxThreads restart signal
120 SIGLTHRCAN : constant := 33; -- GNU/LinuxThreads cancel signal
121 SIGLTHRDBG : constant := 34; -- GNU/LinuxThreads debugger signal
123 SIGADAABORT : constant := SIGABRT;
124 -- Change this if you want to use another signal for task abort.
125 -- SIGTERM might be a good one.
127 type Signal_Set is array (Natural range <>) of Signal;
129 Unmasked : constant Signal_Set := (
130 SIGTRAP,
131 -- To enable debugging on multithreaded applications, mark SIGTRAP to
132 -- be kept unmasked.
134 SIGBUS,
136 SIGTTIN, SIGTTOU, SIGTSTP,
137 -- Keep these three signals unmasked so that background processes
138 -- and IO behaves as normal "C" applications
140 SIGPROF,
141 -- To avoid confusing the profiler
143 SIGKILL, SIGSTOP,
144 -- These two signals actually cannot be masked;
145 -- POSIX simply won't allow it.
147 SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
148 -- These three signals are used by GNU/LinuxThreads starting from
149 -- glibc 2.1 (future 2.2).
151 Reserved : constant Signal_Set :=
152 -- I am not sure why the following two signals are reserved.
153 -- I guess they are not supported by this version of GNU/Linux.
154 (SIGVTALRM, SIGUNUSED);
156 type sigset_t is private;
158 function sigaddset (set : access sigset_t; sig : Signal) return int;
159 pragma Import (C, sigaddset, "sigaddset");
161 function sigdelset (set : access sigset_t; sig : Signal) return int;
162 pragma Import (C, sigdelset, "sigdelset");
164 function sigfillset (set : access sigset_t) return int;
165 pragma Import (C, sigfillset, "sigfillset");
167 function sigismember (set : access sigset_t; sig : Signal) return int;
168 pragma Import (C, sigismember, "sigismember");
170 function sigemptyset (set : access sigset_t) return int;
171 pragma Import (C, sigemptyset, "sigemptyset");
173 type union_type_3 is new String (1 .. 116);
174 type siginfo_t is record
175 si_signo : int;
176 si_code : int;
177 si_errno : int;
178 X_data : union_type_3;
179 end record;
180 pragma Convention (C, siginfo_t);
182 type struct_sigaction is record
183 sa_handler : System.Address;
184 sa_mask : sigset_t;
185 sa_flags : unsigned_long;
186 sa_restorer : System.Address;
187 end record;
188 pragma Convention (C, struct_sigaction);
189 type struct_sigaction_ptr is access all struct_sigaction;
191 type Machine_State is record
192 eip : unsigned_long;
193 ebx : unsigned_long;
194 esp : unsigned_long;
195 ebp : unsigned_long;
196 esi : unsigned_long;
197 edi : unsigned_long;
198 end record;
199 type Machine_State_Ptr is access all Machine_State;
201 SIG_BLOCK : constant := 0;
202 SIG_UNBLOCK : constant := 1;
203 SIG_SETMASK : constant := 2;
205 SIG_DFL : constant := 0;
206 SIG_IGN : constant := 1;
208 function sigaction
209 (sig : Signal;
210 act : struct_sigaction_ptr;
211 oact : struct_sigaction_ptr) return int;
212 pragma Import (C, sigaction, "sigaction");
214 ----------
215 -- Time --
216 ----------
218 type timespec is private;
220 function To_Duration (TS : timespec) return Duration;
221 pragma Inline (To_Duration);
223 function To_Timespec (D : Duration) return timespec;
224 pragma Inline (To_Timespec);
226 type struct_timeval is private;
228 function To_Duration (TV : struct_timeval) return Duration;
229 pragma Inline (To_Duration);
231 function To_Timeval (D : Duration) return struct_timeval;
232 pragma Inline (To_Timeval);
234 function gettimeofday
235 (tv : access struct_timeval;
236 tz : System.Address := System.Null_Address) return int;
237 pragma Import (C, gettimeofday, "gettimeofday");
239 -------------------------
240 -- Priority Scheduling --
241 -------------------------
243 SCHED_OTHER : constant := 0;
244 SCHED_FIFO : constant := 1;
245 SCHED_RR : constant := 2;
247 -------------
248 -- Process --
249 -------------
251 type pid_t is private;
253 function kill (pid : pid_t; sig : Signal) return int;
254 pragma Import (C, kill, "kill");
256 function getpid return pid_t;
257 pragma Import (C, getpid, "getpid");
259 -------------
260 -- Threads --
261 -------------
263 type Thread_Body is access
264 function (arg : System.Address) return System.Address;
265 type pthread_t is private;
266 subtype Thread_Id is pthread_t;
268 type pthread_mutex_t is limited private;
269 type pthread_cond_t is limited private;
270 type pthread_attr_t is limited private;
271 type pthread_mutexattr_t is limited private;
272 type pthread_condattr_t is limited private;
273 type pthread_key_t is private;
275 PTHREAD_CREATE_DETACHED : constant := 1;
277 -----------
278 -- Stack --
279 -----------
281 function Get_Stack_Base (thread : pthread_t) return Address;
282 pragma Inline (Get_Stack_Base);
283 -- This is a dummy procedure to share some GNULLI files
285 ---------------------------------------
286 -- Nonstandard Thread Initialization --
287 ---------------------------------------
289 procedure pthread_init;
290 pragma Inline (pthread_init);
291 -- This is a dummy procedure to share some GNULLI files
293 -------------------------
294 -- POSIX.1c Section 3 --
295 -------------------------
297 function sigwait (set : access sigset_t; sig : access Signal) return int;
298 pragma Import (C, sigwait, "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
306 (how : int;
307 set : sigset_t_ptr;
308 oset : sigset_t_ptr) return int;
309 pragma Import (C, pthread_sigmask, "pthread_sigmask");
311 --------------------------
312 -- POSIX.1c Section 11 --
313 --------------------------
315 function pthread_mutexattr_init
316 (attr : access pthread_mutexattr_t) return int;
317 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
319 function pthread_mutexattr_destroy
320 (attr : access pthread_mutexattr_t) return int;
321 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
323 function pthread_mutex_init
324 (mutex : access pthread_mutex_t;
325 attr : access pthread_mutexattr_t) return int;
326 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
328 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
329 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
331 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
332 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
334 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
335 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
337 function pthread_condattr_init
338 (attr : access pthread_condattr_t) return int;
339 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
341 function pthread_condattr_destroy
342 (attr : access pthread_condattr_t) return int;
343 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
345 function pthread_cond_init
346 (cond : access pthread_cond_t;
347 attr : access pthread_condattr_t) return int;
348 pragma Import (C, pthread_cond_init, "pthread_cond_init");
350 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
351 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
353 function pthread_cond_signal (cond : access pthread_cond_t) return int;
354 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
356 function pthread_cond_wait
357 (cond : access pthread_cond_t;
358 mutex : access pthread_mutex_t) return int;
359 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
361 function pthread_cond_timedwait
362 (cond : access pthread_cond_t;
363 mutex : access pthread_mutex_t;
364 abstime : access timespec) return int;
365 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
367 --------------------------
368 -- POSIX.1c Section 13 --
369 --------------------------
371 type struct_sched_param is record
372 sched_priority : int; -- scheduling priority
373 end record;
374 pragma Convention (C, struct_sched_param);
376 function pthread_setschedparam
377 (thread : pthread_t;
378 policy : int;
379 param : access struct_sched_param) return int;
380 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
382 function pthread_attr_setschedpolicy
383 (attr : access pthread_attr_t;
384 policy : int) return int;
385 pragma Import
386 (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
388 function sched_yield return int;
389 pragma Import (C, sched_yield, "sched_yield");
391 ---------------------------
392 -- P1003.1c - Section 16 --
393 ---------------------------
395 function pthread_attr_init
396 (attributes : access pthread_attr_t) return int;
397 pragma Import (C, pthread_attr_init, "pthread_attr_init");
399 function pthread_attr_destroy
400 (attributes : access pthread_attr_t) return int;
401 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
403 function pthread_attr_setdetachstate
404 (attr : access pthread_attr_t;
405 detachstate : int) return int;
406 pragma Import
407 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
409 function pthread_attr_setstacksize
410 (attr : access pthread_attr_t;
411 stacksize : size_t) return int;
412 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
414 function pthread_create
415 (thread : access pthread_t;
416 attributes : access pthread_attr_t;
417 start_routine : Thread_Body;
418 arg : System.Address) return int;
419 pragma Import (C, pthread_create, "pthread_create");
421 procedure pthread_exit (status : System.Address);
422 pragma Import (C, pthread_exit, "pthread_exit");
424 function pthread_self return pthread_t;
425 pragma Import (C, pthread_self, "pthread_self");
427 --------------------------
428 -- POSIX.1c Section 17 --
429 --------------------------
431 function pthread_setspecific
432 (key : pthread_key_t;
433 value : System.Address) return int;
434 pragma Import (C, pthread_setspecific, "pthread_setspecific");
436 function pthread_getspecific (key : pthread_key_t) return System.Address;
437 pragma Import (C, pthread_getspecific, "pthread_getspecific");
439 type destructor_pointer is access procedure (arg : System.Address);
441 function pthread_key_create
442 (key : access pthread_key_t;
443 destructor : destructor_pointer) return int;
444 pragma Import (C, pthread_key_create, "pthread_key_create");
446 private
448 type sigset_t is array (0 .. 31) of unsigned_long;
449 pragma Convention (C, sigset_t);
450 for sigset_t'Size use 1024;
451 -- This is for GNU libc version 2 but should be backward compatible with
452 -- other libc where sigset_t is smaller.
454 type pid_t is new int;
456 type time_t is new long;
458 type timespec is record
459 tv_sec : time_t;
460 tv_nsec : long;
461 end record;
462 pragma Convention (C, timespec);
464 type struct_timeval is record
465 tv_sec : time_t;
466 tv_usec : time_t;
467 end record;
468 pragma Convention (C, struct_timeval);
470 type pthread_attr_t is record
471 detachstate : int;
472 schedpolicy : int;
473 schedparam : struct_sched_param;
474 inheritsched : int;
475 scope : int;
476 guardsize : size_t;
477 stackaddr_set : int;
478 stackaddr : System.Address;
479 stacksize : size_t;
480 end record;
481 pragma Convention (C_Pass_By_Copy, pthread_attr_t);
483 type pthread_condattr_t is record
484 dummy : int;
485 end record;
486 pragma Convention (C, pthread_condattr_t);
488 type pthread_mutexattr_t is record
489 mutexkind : int;
490 end record;
491 pragma Convention (C, pthread_mutexattr_t);
493 type pthread_t is new unsigned_long;
495 type struct_pthread_queue is record
496 head : System.Address;
497 tail : System.Address;
498 end record;
499 pragma Convention (C, struct_pthread_queue);
501 type pthread_mutex_t is record
502 m_spinlock : int;
503 m_count : int;
504 m_owner : System.Address;
505 m_kind : int;
506 m_waiting : struct_pthread_queue;
507 end record;
508 pragma Convention (C, pthread_mutex_t);
510 type pthread_cond_t is record
511 c_spinlock : int;
512 c_waiting : struct_pthread_queue;
513 end record;
514 pragma Convention (C, pthread_cond_t);
516 type pthread_key_t is new unsigned;
518 end System.OS_Interface;