PR c++/11509
[official-gcc.git] / gcc / ada / 5cosinte.ads
blob88dab8b21433ea1dde161db9e6482971220535a7
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) 1998-2001 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 AIX (FSU THREADS) 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;
46 -- pragma Elaborate_Body;
48 pragma Linker_Options ("-lgthreads");
49 pragma Linker_Options ("-lmalloc");
51 subtype int is Interfaces.C.int;
52 subtype short is Interfaces.C.short;
53 subtype long is Interfaces.C.long;
54 subtype unsigned is Interfaces.C.unsigned;
55 subtype unsigned_short is Interfaces.C.unsigned_short;
56 subtype unsigned_long is Interfaces.C.unsigned_long;
57 subtype unsigned_char is Interfaces.C.unsigned_char;
58 subtype plain_char is Interfaces.C.plain_char;
59 subtype size_t is Interfaces.C.size_t;
61 -----------
62 -- Errno --
63 -----------
65 function errno return int;
66 pragma Import (C, errno, "__get_errno");
68 EAGAIN : constant := 11;
69 EINTR : constant := 4;
70 EINVAL : constant := 22;
71 ENOMEM : constant := 12;
72 ETIMEDOUT : constant := 78;
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 SIGEMT : constant := 7; -- EMT instruction
90 SIGFPE : constant := 8; -- floating point exception
91 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
92 SIGBUS : constant := 10; -- bus error
93 SIGSEGV : constant := 11; -- segmentation violation
94 SIGSYS : constant := 12; -- bad argument to system call
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 := 30; -- user defined signal 1
99 SIGUSR2 : constant := 31; -- user defined signal 2
100 SIGCLD : constant := 20; -- alias for SIGCHLD
101 SIGCHLD : constant := 20; -- child status change
102 SIGPWR : constant := 29; -- power-fail restart
103 SIGWINCH : constant := 28; -- window size change
104 SIGURG : constant := 16; -- urgent condition on IO channel
105 SIGPOLL : constant := 23; -- pollable event occurred
106 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
107 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
108 SIGTSTP : constant := 18; -- user stop requested from tty
109 SIGCONT : constant := 19; -- stopped process has been continued
110 SIGTTIN : constant := 21; -- background tty read attempted
111 SIGTTOU : constant := 22; -- background tty write attempted
112 SIGVTALRM : constant := 34; -- virtual timer expired
113 SIGPROF : constant := 32; -- profiling timer expired
114 SIGXCPU : constant := 24; -- CPU time limit exceeded
115 SIGXFSZ : constant := 25; -- filesize limit exceeded
116 SIGWAITING : constant := 39; -- m:n scheduling
118 -- the following signals are AIX specific
119 SIGMSG : constant := 27; -- input data is in the ring buffer
120 SIGDANGER : constant := 33; -- system crash imminent
121 SIGMIGRATE : constant := 35; -- migrate process
122 SIGPRE : constant := 36; -- programming exception
123 SIGVIRT : constant := 37; -- AIX virtual time alarm
124 SIGALRM1 : constant := 38; -- m:n condition variables
125 SIGKAP : constant := 60; -- keep alive poll from native keyboard
126 SIGGRANT : constant := SIGKAP; -- monitor mode granted
127 SIGRETRACT : constant := 61; -- monitor mode should be relinguished
128 SIGSOUND : constant := 62; -- sound control has completed
129 SIGSAK : constant := 63; -- secure attention key
131 SIGADAABORT : constant := SIGABRT;
133 type Signal_Set is array (Natural range <>) of Signal;
135 Unmasked : constant Signal_Set :=
136 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
137 Reserved : constant Signal_Set :=
138 (SIGKILL, SIGSTOP, SIGALRM, SIGWAITING);
140 type sigset_t is private;
142 function sigaddset (set : access sigset_t; sig : Signal) return int;
143 pragma Import (C, sigaddset, "sigaddset");
145 function sigdelset (set : access sigset_t; sig : Signal) return int;
146 pragma Import (C, sigdelset, "sigdelset");
148 function sigfillset (set : access sigset_t) return int;
149 pragma Import (C, sigfillset, "sigfillset");
151 function sigismember (set : access sigset_t; sig : Signal) return int;
152 pragma Import (C, sigismember, "sigismember");
154 function sigemptyset (set : access sigset_t) return int;
155 pragma Import (C, sigemptyset, "sigemptyset");
157 type struct_sigaction is record
158 sa_handler : System.Address;
159 sa_mask : sigset_t;
160 sa_flags : int;
161 end record;
162 pragma Convention (C, struct_sigaction);
163 type struct_sigaction_ptr is access all struct_sigaction;
165 SIG_BLOCK : constant := 0;
166 SIG_UNBLOCK : constant := 1;
167 SIG_SETMASK : constant := 2;
169 SIG_DFL : constant := 0;
170 SIG_IGN : constant := 1;
172 function sigaction
173 (sig : Signal;
174 act : struct_sigaction_ptr;
175 oact : struct_sigaction_ptr) return int;
176 pragma Import (C, sigaction, "_internal_sigaction");
178 ----------
179 -- Time --
180 ----------
182 Time_Slice_Supported : constant Boolean := True;
183 -- Indicates wether time slicing is supported (i.e FSU threads have been
184 -- compiled with DEF_RR)
186 type timespec is private;
188 type clockid_t is private;
190 CLOCK_REALTIME : constant clockid_t;
192 function clock_gettime
193 (clock_id : clockid_t;
194 tp : access timespec) return int;
195 pragma Import (C, clock_gettime, "clock_gettime");
197 function To_Duration (TS : timespec) return Duration;
198 pragma Inline (To_Duration);
200 function To_Timespec (D : Duration) return timespec;
201 pragma Inline (To_Timespec);
203 type struct_timeval is private;
205 function To_Duration (TV : struct_timeval) return Duration;
206 pragma Inline (To_Duration);
208 function To_Timeval (D : Duration) return struct_timeval;
209 pragma Inline (To_Timeval);
211 -------------------------
212 -- Priority Scheduling --
213 -------------------------
215 SCHED_FIFO : constant := 0;
216 SCHED_RR : constant := 1;
217 SCHED_OTHER : constant := 2;
219 -------------
220 -- Process --
221 -------------
223 type pid_t is private;
225 function kill (pid : pid_t; sig : Signal) return int;
226 pragma Import (C, kill, "kill");
228 function getpid return pid_t;
229 pragma Import (C, getpid, "getpid");
231 ---------
232 -- LWP --
233 ---------
235 function lwp_self return System.Address;
236 -- lwp_self does not exist on this thread library, revert to pthread_self
237 -- which is the closest approximation (with getpid). This function is
238 -- needed to share 7staprop.adb across POSIX-like targets.
239 pragma Import (C, lwp_self, "pthread_self");
241 -------------
242 -- Threads --
243 -------------
245 type Thread_Body is access
246 function (arg : System.Address) return System.Address;
247 type pthread_t is private;
248 subtype Thread_Id is pthread_t;
250 type pthread_mutex_t is limited private;
251 type pthread_cond_t is limited private;
252 type pthread_attr_t is limited private;
253 type pthread_mutexattr_t is limited private;
254 type pthread_condattr_t is limited private;
255 type pthread_key_t is private;
257 PTHREAD_CREATE_DETACHED : constant := 1;
259 -----------
260 -- Stack --
261 -----------
263 Stack_Base_Available : constant Boolean := True;
264 -- Indicates wether the stack base is available on this target.
265 -- This allows us to share s-osinte.adb between all the FSU run time.
266 -- Note that this value can only be true if pthread_t has a complete
267 -- definition that corresponds exactly to the C header files.
269 function Get_Stack_Base (thread : pthread_t) return Address;
270 pragma Inline (Get_Stack_Base);
271 -- returns the stack base of the specified thread.
272 -- Only call this function when Stack_Base_Available is True.
274 function Get_Page_Size return size_t;
275 function Get_Page_Size return Address;
276 pragma Import (C, Get_Page_Size, "getpagesize");
277 -- returns the size of a page, or 0 if this is not relevant on this
278 -- target
280 PROT_NONE : constant := 0;
281 PROT_READ : constant := 1;
282 PROT_WRITE : constant := 2;
283 PROT_EXEC : constant := 4;
284 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
286 PROT_ON : constant := PROT_READ;
287 PROT_OFF : constant := PROT_ALL;
289 function mprotect (addr : Address; len : size_t; prot : int) return int;
290 pragma Import (C, mprotect);
292 ---------------------------------------
293 -- Nonstandard Thread Initialization --
294 ---------------------------------------
296 procedure pthread_init;
297 -- FSU_THREADS requires pthread_init, which is nonstandard
298 -- and this should be invoked during the elaboration of s-taprop.adb
299 pragma Import (C, pthread_init, "pthread_init");
301 -------------------------
302 -- POSIX.1c Section 3 --
303 -------------------------
305 function sigwait
306 (set : access sigset_t;
307 sig : access Signal) return int;
308 -- FSU_THREADS has a nonstandard sigwait
310 function pthread_kill
311 (thread : pthread_t;
312 sig : Signal) return int;
313 pragma Import (C, pthread_kill, "pthread_kill");
315 -- FSU threads does not have pthread_sigmask. Instead, it redefines
316 -- sigprocmask and then uses a special syscall API to call the system
317 -- version. Doing syscalls on AiX is very difficult, so we rename the
318 -- pthread version instead.
320 type sigset_t_ptr is access all sigset_t;
322 function pthread_sigmask
323 (how : int;
324 set : sigset_t_ptr;
325 oset : sigset_t_ptr) return int;
326 pragma Import (C, pthread_sigmask, "_internal_sigprocmask");
328 --------------------------
329 -- POSIX.1c Section 11 --
330 --------------------------
332 function pthread_mutexattr_init
333 (attr : access pthread_mutexattr_t) return int;
334 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
336 function pthread_mutexattr_destroy
337 (attr : access pthread_mutexattr_t) return int;
338 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
340 function pthread_mutex_init
341 (mutex : access pthread_mutex_t;
342 attr : access pthread_mutexattr_t) return int;
343 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
345 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
346 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
348 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
349 -- FSU_THREADS has nonstandard pthread_mutex_lock
351 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
352 -- FSU_THREADS has nonstandard pthread_mutex_lock
354 function pthread_condattr_init
355 (attr : access pthread_condattr_t) return int;
356 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
358 function pthread_condattr_destroy
359 (attr : access pthread_condattr_t) return int;
360 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
362 function pthread_cond_init
363 (cond : access pthread_cond_t;
364 attr : access pthread_condattr_t) return int;
365 pragma Import (C, pthread_cond_init, "pthread_cond_init");
367 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
368 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
370 function pthread_cond_signal (cond : access pthread_cond_t) return int;
371 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
373 function pthread_cond_wait
374 (cond : access pthread_cond_t;
375 mutex : access pthread_mutex_t) return int;
376 -- FSU_THREADS has a nonstandard pthread_cond_wait
378 function pthread_cond_timedwait
379 (cond : access pthread_cond_t;
380 mutex : access pthread_mutex_t;
381 abstime : access timespec) return int;
382 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
384 Relative_Timed_Wait : constant Boolean := False;
385 -- pthread_cond_timedwait requires an absolute delay time
387 --------------------------
388 -- POSIX.1c Section 13 --
389 --------------------------
391 PTHREAD_PRIO_NONE : constant := 0;
392 PTHREAD_PRIO_PROTECT : constant := 2;
393 PTHREAD_PRIO_INHERIT : constant := 1;
395 function pthread_mutexattr_setprotocol
396 (attr : access pthread_mutexattr_t;
397 protocol : int) return int;
398 pragma Import (C, pthread_mutexattr_setprotocol);
400 function pthread_mutexattr_setprioceiling
401 (attr : access pthread_mutexattr_t;
402 prioceiling : int) return int;
403 pragma Import
404 (C, pthread_mutexattr_setprioceiling,
405 "pthread_mutexattr_setprio_ceiling");
407 type struct_sched_param is record
408 sched_priority : int; -- scheduling priority
409 end record;
411 function pthread_setschedparam
412 (thread : pthread_t;
413 policy : int;
414 param : access struct_sched_param) return int;
415 -- FSU_THREADS does not have pthread_setschedparam
417 function pthread_attr_setscope
418 (attr : access pthread_attr_t;
419 contentionscope : int) return int;
420 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
422 function pthread_attr_setinheritsched
423 (attr : access pthread_attr_t;
424 inheritsched : int) return int;
425 pragma Import (C, pthread_attr_setinheritsched);
427 function pthread_attr_setschedpolicy
428 (attr : access pthread_attr_t;
429 policy : int) return int;
430 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
432 function sched_yield return int;
433 -- FSU_THREADS does not have sched_yield;
435 ---------------------------
436 -- P1003.1c - Section 16 --
437 ---------------------------
439 function pthread_attr_init (attributes : access pthread_attr_t) return int;
440 pragma Import (C, pthread_attr_init, "pthread_attr_init");
442 function pthread_attr_destroy
443 (attributes : access pthread_attr_t) return int;
444 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
446 function pthread_attr_setdetachstate
447 (attr : access pthread_attr_t;
448 detachstate : int) return int;
449 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
451 function pthread_attr_setstacksize
452 (attr : access pthread_attr_t;
453 stacksize : size_t) return int;
454 pragma Import (C, pthread_attr_setstacksize);
456 function pthread_create
457 (thread : access pthread_t;
458 attributes : access pthread_attr_t;
459 start_routine : Thread_Body;
460 arg : System.Address) return int;
461 pragma Import (C, pthread_create, "pthread_create");
463 procedure pthread_exit (status : System.Address);
464 pragma Import (C, pthread_exit, "pthread_exit");
466 function pthread_self return pthread_t;
467 pragma Import (C, pthread_self, "pthread_self");
469 --------------------------
470 -- POSIX.1c Section 17 --
471 --------------------------
473 function pthread_setspecific
474 (key : pthread_key_t;
475 value : System.Address) return int;
476 pragma Import (C, pthread_setspecific, "pthread_setspecific");
478 function pthread_getspecific (key : pthread_key_t) return System.Address;
479 -- FSU_THREADS has a nonstandard pthread_getspecific
481 type destructor_pointer is access procedure (arg : System.Address);
483 function pthread_key_create
484 (key : access pthread_key_t;
485 destructor : destructor_pointer) return int;
486 pragma Import (C, pthread_key_create, "pthread_key_create");
488 private
490 type sigset_t is record
491 losigs : unsigned_long;
492 hisigs : unsigned_long;
493 end record;
494 pragma Convention (C_Pass_By_Copy, sigset_t);
496 type pid_t is new int;
498 type time_t is new long;
500 type timespec is record
501 tv_sec : time_t;
502 tv_nsec : long;
503 end record;
504 pragma Convention (C, timespec);
506 type clockid_t is new int;
507 CLOCK_REALTIME : constant clockid_t := 0;
509 type struct_timeval is record
510 tv_sec : long;
511 tv_usec : long;
512 end record;
513 pragma Convention (C, struct_timeval);
515 type pthread_attr_t is record
516 flags : int;
517 stacksize : int;
518 contentionscope : int;
519 inheritsched : int;
520 detachstate : int;
521 sched : int;
522 prio : int;
523 starttime : timespec;
524 deadline : timespec;
525 period : timespec;
526 end record;
527 pragma Convention (C_Pass_By_Copy, pthread_attr_t);
529 type pthread_condattr_t is record
530 flags : int;
531 end record;
532 pragma Convention (C, pthread_condattr_t);
534 type pthread_mutexattr_t is record
535 flags : int;
536 prio_ceiling : int;
537 protocol : int;
538 end record;
539 pragma Convention (C, pthread_mutexattr_t);
541 type sigjmp_buf is array (Integer range 0 .. 63) of int;
543 type pthread_t_struct is record
544 context : sigjmp_buf;
545 pbody : sigjmp_buf;
546 errno : int;
547 ret : int;
548 stack_base : System.Address;
549 end record;
550 pragma Convention (C, pthread_t_struct);
552 type pthread_t is access all pthread_t_struct;
554 type queue_t is record
555 head : System.Address;
556 tail : System.Address;
557 end record;
558 pragma Convention (C, queue_t);
560 type pthread_mutex_t is record
561 queue : queue_t;
562 lock : plain_char;
563 owner : System.Address;
564 flags : int;
565 prio_ceiling : int;
566 protocol : int;
567 prev_max_ceiling_prio : int;
568 end record;
569 pragma Convention (C, pthread_mutex_t);
571 type pthread_cond_t is record
572 queue : queue_t;
573 flags : int;
574 waiters : int;
575 mutex : System.Address;
576 end record;
577 pragma Convention (C, pthread_cond_t);
579 type pthread_key_t is new int;
581 end System.OS_Interface;