(extendsfdf2): Add pattern accidentally deleted when cirrus instructions were
[official-gcc.git] / gcc / ada / 5cosinte.ads
blob8c142f4955df72766d1372c2a79e2286e0d94348
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) 1998-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. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This is a AIX (FSU THREADS) version of this package.
37 -- This package encapsulates all direct interfaces to OS services
38 -- that are needed by children of System.
40 -- PLEASE DO NOT add any with-clauses to this package
41 -- or remove the pragma Elaborate_Body.
42 -- It is designed to be a bottom-level (leaf) package.
44 with Interfaces.C;
45 package System.OS_Interface is
46 pragma Preelaborate;
47 -- pragma Elaborate_Body;
49 pragma Linker_Options ("-lgthreads");
50 pragma Linker_Options ("-lmalloc");
52 subtype int is Interfaces.C.int;
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 ETIMEDOUT : constant := 78;
75 -------------
76 -- Signals --
77 -------------
79 Max_Interrupt : constant := 63;
80 type Signal is new int range 0 .. Max_Interrupt;
81 for Signal'Size use int'Size;
83 SIGHUP : constant := 1; -- hangup
84 SIGINT : constant := 2; -- interrupt (rubout)
85 SIGQUIT : constant := 3; -- quit (ASCD FS)
86 SIGILL : constant := 4; -- illegal instruction (not reset)
87 SIGTRAP : constant := 5; -- trace trap (not reset)
88 SIGIOT : constant := 6; -- IOT instruction
89 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
90 SIGEMT : constant := 7; -- EMT instruction
91 SIGFPE : constant := 8; -- floating point exception
92 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
93 SIGBUS : constant := 10; -- bus error
94 SIGSEGV : constant := 11; -- segmentation violation
95 SIGSYS : constant := 12; -- bad argument to system call
96 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
97 SIGALRM : constant := 14; -- alarm clock
98 SIGTERM : constant := 15; -- software termination signal from kill
99 SIGUSR1 : constant := 30; -- user defined signal 1
100 SIGUSR2 : constant := 31; -- user defined signal 2
101 SIGCLD : constant := 20; -- alias for SIGCHLD
102 SIGCHLD : constant := 20; -- child status change
103 SIGPWR : constant := 29; -- power-fail restart
104 SIGWINCH : constant := 28; -- window size change
105 SIGURG : constant := 16; -- urgent condition on IO channel
106 SIGPOLL : constant := 23; -- pollable event occurred
107 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
109 SIGTSTP : constant := 18; -- user stop requested from tty
110 SIGCONT : constant := 19; -- stopped process has been continued
111 SIGTTIN : constant := 21; -- background tty read attempted
112 SIGTTOU : constant := 22; -- background tty write attempted
113 SIGVTALRM : constant := 34; -- virtual timer expired
114 SIGPROF : constant := 32; -- profiling timer expired
115 SIGXCPU : constant := 24; -- CPU time limit exceeded
116 SIGXFSZ : constant := 25; -- filesize limit exceeded
117 SIGWAITING : constant := 39; -- m:n scheduling
119 -- the following signals are AIX specific
120 SIGMSG : constant := 27; -- input data is in the ring buffer
121 SIGDANGER : constant := 33; -- system crash imminent
122 SIGMIGRATE : constant := 35; -- migrate process
123 SIGPRE : constant := 36; -- programming exception
124 SIGVIRT : constant := 37; -- AIX virtual time alarm
125 SIGALRM1 : constant := 38; -- m:n condition variables
126 SIGKAP : constant := 60; -- keep alive poll from native keyboard
127 SIGGRANT : constant := SIGKAP; -- monitor mode granted
128 SIGRETRACT : constant := 61; -- monitor mode should be relinguished
129 SIGSOUND : constant := 62; -- sound control has completed
130 SIGSAK : constant := 63; -- secure attention key
132 SIGADAABORT : constant := SIGABRT;
134 type Signal_Set is array (Natural range <>) of Signal;
136 Unmasked : constant Signal_Set :=
137 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
138 Reserved : constant Signal_Set :=
139 (SIGKILL, SIGSTOP, SIGALRM, SIGWAITING);
141 type sigset_t is private;
143 function sigaddset (set : access sigset_t; sig : Signal) return int;
144 pragma Import (C, sigaddset, "sigaddset");
146 function sigdelset (set : access sigset_t; sig : Signal) return int;
147 pragma Import (C, sigdelset, "sigdelset");
149 function sigfillset (set : access sigset_t) return int;
150 pragma Import (C, sigfillset, "sigfillset");
152 function sigismember (set : access sigset_t; sig : Signal) return int;
153 pragma Import (C, sigismember, "sigismember");
155 function sigemptyset (set : access sigset_t) return int;
156 pragma Import (C, sigemptyset, "sigemptyset");
158 type struct_sigaction is record
159 sa_handler : System.Address;
160 sa_mask : sigset_t;
161 sa_flags : int;
162 end record;
163 pragma Convention (C, struct_sigaction);
164 type struct_sigaction_ptr is access all struct_sigaction;
166 SIG_BLOCK : constant := 0;
167 SIG_UNBLOCK : constant := 1;
168 SIG_SETMASK : constant := 2;
170 SIG_DFL : constant := 0;
171 SIG_IGN : constant := 1;
173 function sigaction
174 (sig : Signal;
175 act : struct_sigaction_ptr;
176 oact : struct_sigaction_ptr) return int;
177 pragma Import (C, sigaction, "_internal_sigaction");
179 ----------
180 -- Time --
181 ----------
183 Time_Slice_Supported : constant Boolean := True;
184 -- Indicates wether time slicing is supported (i.e FSU threads have been
185 -- compiled with DEF_RR)
187 type timespec is private;
189 type clockid_t is private;
191 CLOCK_REALTIME : constant clockid_t;
193 function clock_gettime
194 (clock_id : clockid_t;
195 tp : access timespec) return int;
196 pragma Import (C, clock_gettime, "clock_gettime");
198 function To_Duration (TS : timespec) return Duration;
199 pragma Inline (To_Duration);
201 function To_Timespec (D : Duration) return timespec;
202 pragma Inline (To_Timespec);
204 type struct_timeval is private;
206 function To_Duration (TV : struct_timeval) return Duration;
207 pragma Inline (To_Duration);
209 function To_Timeval (D : Duration) return struct_timeval;
210 pragma Inline (To_Timeval);
212 -------------------------
213 -- Priority Scheduling --
214 -------------------------
216 SCHED_FIFO : constant := 0;
217 SCHED_RR : constant := 1;
218 SCHED_OTHER : constant := 2;
220 -------------
221 -- Process --
222 -------------
224 type pid_t is private;
226 function kill (pid : pid_t; sig : Signal) return int;
227 pragma Import (C, kill, "kill");
229 function getpid return pid_t;
230 pragma Import (C, getpid, "getpid");
232 ---------
233 -- LWP --
234 ---------
236 function lwp_self return System.Address;
237 -- lwp_self does not exist on this thread library, revert to pthread_self
238 -- which is the closest approximation (with getpid). This function is
239 -- needed to share 7staprop.adb across POSIX-like targets.
240 pragma Import (C, lwp_self, "pthread_self");
242 -------------
243 -- Threads --
244 -------------
246 type Thread_Body is access
247 function (arg : System.Address) return System.Address;
248 type pthread_t is private;
249 subtype Thread_Id is pthread_t;
251 type pthread_mutex_t is limited private;
252 type pthread_cond_t is limited private;
253 type pthread_attr_t is limited private;
254 type pthread_mutexattr_t is limited private;
255 type pthread_condattr_t is limited private;
256 type pthread_key_t is private;
258 PTHREAD_CREATE_DETACHED : constant := 1;
260 -----------
261 -- Stack --
262 -----------
264 Stack_Base_Available : constant Boolean := True;
265 -- Indicates wether the stack base is available on this target.
266 -- This allows us to share s-osinte.adb between all the FSU run time.
267 -- Note that this value can only be true if pthread_t has a complete
268 -- definition that corresponds exactly to the C header files.
270 function Get_Stack_Base (thread : pthread_t) return Address;
271 pragma Inline (Get_Stack_Base);
272 -- returns the stack base of the specified thread.
273 -- Only call this function when Stack_Base_Available is True.
275 function Get_Page_Size return size_t;
276 function Get_Page_Size return Address;
277 pragma Import (C, Get_Page_Size, "getpagesize");
278 -- returns the size of a page, or 0 if this is not relevant on this
279 -- target
281 PROT_NONE : constant := 0;
282 PROT_READ : constant := 1;
283 PROT_WRITE : constant := 2;
284 PROT_EXEC : constant := 4;
285 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
287 PROT_ON : constant := PROT_READ;
288 PROT_OFF : constant := PROT_ALL;
290 function mprotect (addr : Address; len : size_t; prot : int) return int;
291 pragma Import (C, mprotect);
293 ---------------------------------------
294 -- Nonstandard Thread Initialization --
295 ---------------------------------------
297 procedure pthread_init;
298 -- FSU_THREADS requires pthread_init, which is nonstandard
299 -- and this should be invoked during the elaboration of s-taprop.adb
300 pragma Import (C, pthread_init, "pthread_init");
302 -------------------------
303 -- POSIX.1c Section 3 --
304 -------------------------
306 function sigwait
307 (set : access sigset_t;
308 sig : access Signal) return int;
309 -- FSU_THREADS has a nonstandard sigwait
311 function pthread_kill
312 (thread : pthread_t;
313 sig : Signal) return int;
314 pragma Import (C, pthread_kill, "pthread_kill");
316 -- FSU threads does not have pthread_sigmask. Instead, it redefines
317 -- sigprocmask and then uses a special syscall API to call the system
318 -- version. Doing syscalls on AiX is very difficult, so we rename the
319 -- pthread version instead.
321 type sigset_t_ptr is access all sigset_t;
323 function pthread_sigmask
324 (how : int;
325 set : sigset_t_ptr;
326 oset : sigset_t_ptr) return int;
327 pragma Import (C, pthread_sigmask, "_internal_sigprocmask");
329 --------------------------
330 -- POSIX.1c Section 11 --
331 --------------------------
333 function pthread_mutexattr_init
334 (attr : access pthread_mutexattr_t) return int;
335 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
337 function pthread_mutexattr_destroy
338 (attr : access pthread_mutexattr_t) return int;
339 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
341 function pthread_mutex_init
342 (mutex : access pthread_mutex_t;
343 attr : access pthread_mutexattr_t) return int;
344 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
346 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
347 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
349 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
350 -- FSU_THREADS has nonstandard pthread_mutex_lock
352 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
353 -- FSU_THREADS has nonstandard pthread_mutex_lock
355 function pthread_condattr_init
356 (attr : access pthread_condattr_t) return int;
357 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
359 function pthread_condattr_destroy
360 (attr : access pthread_condattr_t) return int;
361 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
363 function pthread_cond_init
364 (cond : access pthread_cond_t;
365 attr : access pthread_condattr_t) return int;
366 pragma Import (C, pthread_cond_init, "pthread_cond_init");
368 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
369 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
371 function pthread_cond_signal (cond : access pthread_cond_t) return int;
372 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
374 function pthread_cond_wait
375 (cond : access pthread_cond_t;
376 mutex : access pthread_mutex_t) return int;
377 -- FSU_THREADS has a nonstandard pthread_cond_wait
379 function pthread_cond_timedwait
380 (cond : access pthread_cond_t;
381 mutex : access pthread_mutex_t;
382 abstime : access timespec) return int;
383 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
385 Relative_Timed_Wait : constant Boolean := False;
386 -- pthread_cond_timedwait requires an absolute delay time
388 --------------------------
389 -- POSIX.1c Section 13 --
390 --------------------------
392 PTHREAD_PRIO_NONE : constant := 0;
393 PTHREAD_PRIO_PROTECT : constant := 2;
394 PTHREAD_PRIO_INHERIT : constant := 1;
396 function pthread_mutexattr_setprotocol
397 (attr : access pthread_mutexattr_t;
398 protocol : int) return int;
399 pragma Import (C, pthread_mutexattr_setprotocol);
401 function pthread_mutexattr_setprioceiling
402 (attr : access pthread_mutexattr_t;
403 prioceiling : int) return int;
404 pragma Import
405 (C, pthread_mutexattr_setprioceiling,
406 "pthread_mutexattr_setprio_ceiling");
408 type struct_sched_param is record
409 sched_priority : int; -- scheduling priority
410 end record;
412 function pthread_setschedparam
413 (thread : pthread_t;
414 policy : int;
415 param : access struct_sched_param) return int;
416 -- FSU_THREADS does not have pthread_setschedparam
418 function pthread_attr_setscope
419 (attr : access pthread_attr_t;
420 contentionscope : int) return int;
421 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
423 function pthread_attr_setinheritsched
424 (attr : access pthread_attr_t;
425 inheritsched : int) return int;
426 pragma Import (C, pthread_attr_setinheritsched);
428 function pthread_attr_setschedpolicy
429 (attr : access pthread_attr_t;
430 policy : int) return int;
431 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
433 function sched_yield return int;
434 -- FSU_THREADS does not have sched_yield;
436 ---------------------------
437 -- P1003.1c - Section 16 --
438 ---------------------------
440 function pthread_attr_init (attributes : access pthread_attr_t) return int;
441 pragma Import (C, pthread_attr_init, "pthread_attr_init");
443 function pthread_attr_destroy
444 (attributes : access pthread_attr_t) return int;
445 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
447 function pthread_attr_setdetachstate
448 (attr : access pthread_attr_t;
449 detachstate : int) return int;
450 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
452 function pthread_attr_setstacksize
453 (attr : access pthread_attr_t;
454 stacksize : size_t) return int;
455 pragma Import (C, pthread_attr_setstacksize);
457 function pthread_create
458 (thread : access pthread_t;
459 attributes : access pthread_attr_t;
460 start_routine : Thread_Body;
461 arg : System.Address) return int;
462 pragma Import (C, pthread_create, "pthread_create");
464 procedure pthread_exit (status : System.Address);
465 pragma Import (C, pthread_exit, "pthread_exit");
467 function pthread_self return pthread_t;
468 pragma Import (C, pthread_self, "pthread_self");
470 --------------------------
471 -- POSIX.1c Section 17 --
472 --------------------------
474 function pthread_setspecific
475 (key : pthread_key_t;
476 value : System.Address) return int;
477 pragma Import (C, pthread_setspecific, "pthread_setspecific");
479 function pthread_getspecific (key : pthread_key_t) return System.Address;
480 -- FSU_THREADS has a nonstandard pthread_getspecific
482 type destructor_pointer is access procedure (arg : System.Address);
484 function pthread_key_create
485 (key : access pthread_key_t;
486 destructor : destructor_pointer) return int;
487 pragma Import (C, pthread_key_create, "pthread_key_create");
489 private
491 type sigset_t is record
492 losigs : unsigned_long;
493 hisigs : unsigned_long;
494 end record;
495 pragma Convention (C_Pass_By_Copy, sigset_t);
497 type pid_t is new int;
499 type time_t is new long;
501 type timespec is record
502 tv_sec : time_t;
503 tv_nsec : long;
504 end record;
505 pragma Convention (C, timespec);
507 type clockid_t is new int;
508 CLOCK_REALTIME : constant clockid_t := 0;
510 type struct_timeval is record
511 tv_sec : long;
512 tv_usec : long;
513 end record;
514 pragma Convention (C, struct_timeval);
516 type pthread_attr_t is record
517 flags : int;
518 stacksize : int;
519 contentionscope : int;
520 inheritsched : int;
521 detachstate : int;
522 sched : int;
523 prio : int;
524 starttime : timespec;
525 deadline : timespec;
526 period : timespec;
527 end record;
528 pragma Convention (C_Pass_By_Copy, pthread_attr_t);
530 type pthread_condattr_t is record
531 flags : int;
532 end record;
533 pragma Convention (C, pthread_condattr_t);
535 type pthread_mutexattr_t is record
536 flags : int;
537 prio_ceiling : int;
538 protocol : int;
539 end record;
540 pragma Convention (C, pthread_mutexattr_t);
542 type sigjmp_buf is array (Integer range 0 .. 63) of int;
544 type pthread_t_struct is record
545 context : sigjmp_buf;
546 pbody : sigjmp_buf;
547 errno : int;
548 ret : int;
549 stack_base : System.Address;
550 end record;
551 pragma Convention (C, pthread_t_struct);
553 type pthread_t is access all pthread_t_struct;
555 type queue_t is record
556 head : System.Address;
557 tail : System.Address;
558 end record;
559 pragma Convention (C, queue_t);
561 type pthread_mutex_t is record
562 queue : queue_t;
563 lock : plain_char;
564 owner : System.Address;
565 flags : int;
566 prio_ceiling : int;
567 protocol : int;
568 prev_max_ceiling_prio : int;
569 end record;
570 pragma Convention (C, pthread_mutex_t);
572 type pthread_cond_t is record
573 queue : queue_t;
574 flags : int;
575 waiters : int;
576 mutex : System.Address;
577 end record;
578 pragma Convention (C, pthread_cond_t);
580 type pthread_key_t is new int;
582 end System.OS_Interface;