PR c++/11808
[official-gcc.git] / gcc / ada / 5iosinte.ads
blobe112c8cdaf5f2daf7d9cfa90fe449f56606206bc
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) 1992-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 ------------------------------------------------------------------------------
34 -- This is a GNU/Linux (GNU/LinuxThreads) version of this package.
36 -- This package encapsulates all direct interfaces to OS services
37 -- that are needed by children of System.
39 -- PLEASE DO NOT add any with-clauses to this package
40 -- or remove the pragma Elaborate_Body.
41 -- It is designed to be a bottom-level (leaf) package.
43 with Interfaces.C;
44 package System.OS_Interface is
45 pragma Preelaborate;
47 pragma Linker_Options ("-lpthread");
49 subtype int is Interfaces.C.int;
50 subtype char is Interfaces.C.char;
51 subtype short is Interfaces.C.short;
52 subtype long is Interfaces.C.long;
53 subtype unsigned is Interfaces.C.unsigned;
54 subtype unsigned_short is Interfaces.C.unsigned_short;
55 subtype unsigned_long is Interfaces.C.unsigned_long;
56 subtype unsigned_char is Interfaces.C.unsigned_char;
57 subtype plain_char is Interfaces.C.plain_char;
58 subtype size_t is Interfaces.C.size_t;
60 -----------
61 -- Errno --
62 -----------
64 function errno return int;
65 pragma Import (C, errno, "__get_errno");
67 EAGAIN : constant := 11;
68 EINTR : constant := 4;
69 EINVAL : constant := 22;
70 ENOMEM : constant := 12;
71 EPERM : constant := 1;
72 ETIMEDOUT : constant := 110;
74 -------------
75 -- Signals --
76 -------------
78 Max_Interrupt : constant := 63;
79 type Signal is new int range 0 .. Max_Interrupt;
80 for Signal'Size use int'Size;
82 SIGHUP : constant := 1; -- hangup
83 SIGINT : constant := 2; -- interrupt (rubout)
84 SIGQUIT : constant := 3; -- quit (ASCD FS)
85 SIGILL : constant := 4; -- illegal instruction (not reset)
86 SIGTRAP : constant := 5; -- trace trap (not reset)
87 SIGIOT : constant := 6; -- IOT instruction
88 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
89 SIGFPE : constant := 8; -- floating point exception
90 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
91 SIGBUS : constant := 7; -- bus error
92 SIGSEGV : constant := 11; -- segmentation violation
93 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
94 SIGALRM : constant := 14; -- alarm clock
95 SIGTERM : constant := 15; -- software termination signal from kill
96 SIGUSR1 : constant := 10; -- user defined signal 1
97 SIGUSR2 : constant := 12; -- user defined signal 2
98 SIGCLD : constant := 17; -- alias for SIGCHLD
99 SIGCHLD : constant := 17; -- child status change
100 SIGPWR : constant := 30; -- power-fail restart
101 SIGWINCH : constant := 28; -- window size change
102 SIGURG : constant := 23; -- urgent condition on IO channel
103 SIGPOLL : constant := 29; -- pollable event occurred
104 SIGIO : constant := 29; -- I/O now possible (4.2 BSD)
105 SIGLOST : constant := 29; -- File lock lost
106 SIGSTOP : constant := 19; -- stop (cannot be caught or ignored)
107 SIGTSTP : constant := 20; -- user stop requested from tty
108 SIGCONT : constant := 18; -- stopped process has been continued
109 SIGTTIN : constant := 21; -- background tty read attempted
110 SIGTTOU : constant := 22; -- background tty write attempted
111 SIGVTALRM : constant := 26; -- virtual timer expired
112 SIGPROF : constant := 27; -- profiling timer expired
113 SIGXCPU : constant := 24; -- CPU time limit exceeded
114 SIGXFSZ : constant := 25; -- filesize limit exceeded
115 SIGUNUSED : constant := 31; -- unused signal (GNU/Linux)
116 SIGSTKFLT : constant := 16; -- coprocessor stack fault (Linux)
117 SIGLTHRRES : constant := 32; -- GNU/LinuxThreads restart signal
118 SIGLTHRCAN : constant := 33; -- GNU/LinuxThreads cancel signal
119 SIGLTHRDBG : constant := 34; -- GNU/LinuxThreads debugger signal
121 SIGADAABORT : constant := SIGABRT;
122 -- Change this if you want to use another signal for task abort.
123 -- SIGTERM might be a good one.
125 type Signal_Set is array (Natural range <>) of Signal;
127 Unmasked : constant Signal_Set := (
128 SIGTRAP,
129 -- To enable debugging on multithreaded applications, mark SIGTRAP to
130 -- be kept unmasked.
132 SIGBUS,
134 SIGTTIN, SIGTTOU, SIGTSTP,
135 -- Keep these three signals unmasked so that background processes
136 -- and IO behaves as normal "C" applications
138 SIGPROF,
139 -- To avoid confusing the profiler
141 SIGKILL, SIGSTOP,
142 -- These two signals actually cannot be masked;
143 -- POSIX simply won't allow it.
145 SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
146 -- These three signals are used by GNU/LinuxThreads starting from
147 -- glibc 2.1 (future 2.2).
149 Reserved : constant Signal_Set :=
150 -- I am not sure why the following two signals are reserved.
151 -- I guess they are not supported by this version of GNU/Linux.
152 (SIGVTALRM, SIGUNUSED);
154 type sigset_t is private;
156 function sigaddset (set : access sigset_t; sig : Signal) return int;
157 pragma Import (C, sigaddset, "sigaddset");
159 function sigdelset (set : access sigset_t; sig : Signal) return int;
160 pragma Import (C, sigdelset, "sigdelset");
162 function sigfillset (set : access sigset_t) return int;
163 pragma Import (C, sigfillset, "sigfillset");
165 function sigismember (set : access sigset_t; sig : Signal) return int;
166 pragma Import (C, sigismember, "sigismember");
168 function sigemptyset (set : access sigset_t) return int;
169 pragma Import (C, sigemptyset, "sigemptyset");
171 type union_type_3 is new String (1 .. 116);
172 type siginfo_t is record
173 si_signo : int;
174 si_code : int;
175 si_errno : int;
176 X_data : union_type_3;
177 end record;
178 pragma Convention (C, siginfo_t);
180 type struct_sigaction is record
181 sa_handler : System.Address;
182 sa_mask : sigset_t;
183 sa_flags : unsigned_long;
184 sa_restorer : System.Address;
185 end record;
186 pragma Convention (C, struct_sigaction);
187 type struct_sigaction_ptr is access all struct_sigaction;
189 type Machine_State is record
190 eip : unsigned_long;
191 ebx : unsigned_long;
192 esp : unsigned_long;
193 ebp : unsigned_long;
194 esi : unsigned_long;
195 edi : unsigned_long;
196 end record;
197 type Machine_State_Ptr is access all Machine_State;
199 SIG_BLOCK : constant := 0;
200 SIG_UNBLOCK : constant := 1;
201 SIG_SETMASK : constant := 2;
203 SIG_DFL : constant := 0;
204 SIG_IGN : constant := 1;
206 function sigaction
207 (sig : Signal;
208 act : struct_sigaction_ptr;
209 oact : struct_sigaction_ptr) return int;
210 pragma Import (C, sigaction, "sigaction");
212 ----------
213 -- Time --
214 ----------
216 type timespec is private;
218 function To_Duration (TS : timespec) return Duration;
219 pragma Inline (To_Duration);
221 function To_Timespec (D : Duration) return timespec;
222 pragma Inline (To_Timespec);
224 type struct_timeval is private;
226 function To_Duration (TV : struct_timeval) return Duration;
227 pragma Inline (To_Duration);
229 function To_Timeval (D : Duration) return struct_timeval;
230 pragma Inline (To_Timeval);
232 function gettimeofday
233 (tv : access struct_timeval;
234 tz : System.Address := System.Null_Address) return int;
235 pragma Import (C, gettimeofday, "gettimeofday");
237 function sysconf (name : int) return long;
238 pragma Import (C, sysconf);
240 SC_CLK_TCK : constant := 2;
242 -------------------------
243 -- Priority Scheduling --
244 -------------------------
246 SCHED_OTHER : constant := 0;
247 SCHED_FIFO : constant := 1;
248 SCHED_RR : constant := 2;
250 -------------
251 -- Process --
252 -------------
254 type pid_t is private;
256 function kill (pid : pid_t; sig : Signal) return int;
257 pragma Import (C, kill, "kill");
259 function getpid return pid_t;
260 pragma Import (C, getpid, "getpid");
262 -------------
263 -- Threads --
264 -------------
266 type Thread_Body is access
267 function (arg : System.Address) return System.Address;
268 type pthread_t is private;
269 subtype Thread_Id is pthread_t;
271 type pthread_mutex_t is limited private;
272 type pthread_cond_t is limited private;
273 type pthread_attr_t is limited private;
274 type pthread_mutexattr_t is limited private;
275 type pthread_condattr_t is limited private;
276 type pthread_key_t is private;
278 PTHREAD_CREATE_DETACHED : constant := 1;
280 -----------
281 -- Stack --
282 -----------
284 function Get_Stack_Base (thread : pthread_t) return Address;
285 pragma Inline (Get_Stack_Base);
286 -- This is a dummy procedure to share some GNULLI files
288 ---------------------------------------
289 -- Nonstandard Thread Initialization --
290 ---------------------------------------
292 procedure pthread_init;
293 pragma Inline (pthread_init);
294 -- This is a dummy procedure to share some GNULLI files
296 -------------------------
297 -- POSIX.1c Section 3 --
298 -------------------------
300 function sigwait (set : access sigset_t; sig : access Signal) return int;
301 pragma Import (C, sigwait, "sigwait");
303 function pthread_kill (thread : pthread_t; sig : Signal) return int;
304 pragma Import (C, pthread_kill, "pthread_kill");
306 type sigset_t_ptr is access all sigset_t;
308 function pthread_sigmask
309 (how : int;
310 set : sigset_t_ptr;
311 oset : sigset_t_ptr) return int;
312 pragma Import (C, pthread_sigmask, "pthread_sigmask");
314 --------------------------
315 -- POSIX.1c Section 11 --
316 --------------------------
318 function pthread_mutexattr_init
319 (attr : access pthread_mutexattr_t) return int;
320 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
322 function pthread_mutexattr_destroy
323 (attr : access pthread_mutexattr_t) return int;
324 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
326 function pthread_mutex_init
327 (mutex : access pthread_mutex_t;
328 attr : access pthread_mutexattr_t) return int;
329 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
331 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
332 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
334 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
335 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
337 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
338 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
340 function pthread_condattr_init
341 (attr : access pthread_condattr_t) return int;
342 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
344 function pthread_condattr_destroy
345 (attr : access pthread_condattr_t) return int;
346 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
348 function pthread_cond_init
349 (cond : access pthread_cond_t;
350 attr : access pthread_condattr_t) return int;
351 pragma Import (C, pthread_cond_init, "pthread_cond_init");
353 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
354 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
356 function pthread_cond_signal (cond : access pthread_cond_t) return int;
357 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
359 function pthread_cond_wait
360 (cond : access pthread_cond_t;
361 mutex : access pthread_mutex_t) return int;
362 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
364 function pthread_cond_timedwait
365 (cond : access pthread_cond_t;
366 mutex : access pthread_mutex_t;
367 abstime : access timespec) return int;
368 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
370 --------------------------
371 -- POSIX.1c Section 13 --
372 --------------------------
374 type struct_sched_param is record
375 sched_priority : int; -- scheduling priority
376 end record;
377 pragma Convention (C, struct_sched_param);
379 function pthread_setschedparam
380 (thread : pthread_t;
381 policy : int;
382 param : access struct_sched_param) return int;
383 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
385 function pthread_attr_setschedpolicy
386 (attr : access pthread_attr_t;
387 policy : int) return int;
388 pragma Import
389 (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
391 function sched_yield return int;
392 pragma Import (C, sched_yield, "sched_yield");
394 ---------------------------
395 -- P1003.1c - Section 16 --
396 ---------------------------
398 function pthread_attr_init
399 (attributes : access pthread_attr_t) return int;
400 pragma Import (C, pthread_attr_init, "pthread_attr_init");
402 function pthread_attr_destroy
403 (attributes : access pthread_attr_t) return int;
404 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
406 function pthread_attr_setdetachstate
407 (attr : access pthread_attr_t;
408 detachstate : int) return int;
409 pragma Import
410 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
412 function pthread_attr_setstacksize
413 (attr : access pthread_attr_t;
414 stacksize : size_t) return int;
415 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
417 function pthread_create
418 (thread : access pthread_t;
419 attributes : access pthread_attr_t;
420 start_routine : Thread_Body;
421 arg : System.Address) return int;
422 pragma Import (C, pthread_create, "pthread_create");
424 procedure pthread_exit (status : System.Address);
425 pragma Import (C, pthread_exit, "pthread_exit");
427 function pthread_self return pthread_t;
428 pragma Import (C, pthread_self, "pthread_self");
430 --------------------------
431 -- POSIX.1c Section 17 --
432 --------------------------
434 function pthread_setspecific
435 (key : pthread_key_t;
436 value : System.Address) return int;
437 pragma Import (C, pthread_setspecific, "pthread_setspecific");
439 function pthread_getspecific (key : pthread_key_t) return System.Address;
440 pragma Import (C, pthread_getspecific, "pthread_getspecific");
442 type destructor_pointer is access procedure (arg : System.Address);
444 function pthread_key_create
445 (key : access pthread_key_t;
446 destructor : destructor_pointer) return int;
447 pragma Import (C, pthread_key_create, "pthread_key_create");
449 private
451 type sigset_t is array (0 .. 127) of unsigned_char;
452 pragma Convention (C, sigset_t);
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, 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_fast_lock is record
496 status : long;
497 spinlock : int;
498 end record;
499 pragma Convention (C, struct_pthread_fast_lock);
501 type pthread_mutex_t is record
502 m_reserved : int;
503 m_count : int;
504 m_owner : System.Address;
505 m_kind : int;
506 m_lock : struct_pthread_fast_lock;
507 end record;
508 pragma Convention (C, pthread_mutex_t);
510 type pthread_cond_t is array (0 .. 47) of unsigned_char;
511 pragma Convention (C, pthread_cond_t);
513 type pthread_key_t is new unsigned;
515 end System.OS_Interface;