* sh.h (REG_CLASS_FROM_LETTER): Change to:
[official-gcc.git] / gcc / ada / 5mosinte.ads
blob17ed7f51025e632b20c769ecdac4eeb93d35807a
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) 1997-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 MACOS (FSU THREAD) 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 ("-lgthreads");
49 subtype int is Interfaces.C.int;
50 subtype short is Interfaces.C.short;
51 subtype long is Interfaces.C.long;
52 subtype unsigned is Interfaces.C.unsigned;
53 subtype unsigned_short is Interfaces.C.unsigned_short;
54 subtype unsigned_long is Interfaces.C.unsigned_long;
55 subtype unsigned_char is Interfaces.C.unsigned_char;
56 subtype plain_char is Interfaces.C.plain_char;
57 subtype size_t is Interfaces.C.size_t;
59 -----------
60 -- Errno --
61 -----------
63 function errno return int;
64 pragma Import (C, errno, "__get_errno");
66 EAGAIN : constant := 35;
67 EINTR : constant := 4;
68 EINVAL : constant := 22;
69 ENOMEM : constant := 12;
70 ETIMEDOUT : constant := 60;
72 -------------
73 -- Signals --
74 -------------
76 Max_Interrupt : constant := 31;
77 type Signal is new int range 0 .. Max_Interrupt;
78 for Signal'Size use int'Size;
80 SIGHUP : constant := 1; -- hangup
81 SIGINT : constant := 2; -- interrupt (rubout)
82 SIGQUIT : constant := 3; -- quit (ASCD FS)
83 SIGILL : constant := 4; -- illegal instruction (not reset)
84 SIGTRAP : constant := 5; -- trace trap (not reset)
85 SIGIOT : constant := 6; -- IOT instruction
86 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
87 SIGEMT : constant := 7; -- EMT instruction
88 SIGFPE : constant := 8; -- floating point exception
89 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
90 SIGBUS : constant := 10; -- bus error
91 SIGSEGV : constant := 11; -- segmentation violation
92 SIGSYS : constant := 12; -- bad argument to system call
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 := 30; -- user defined signal 1
97 SIGUSR2 : constant := 31; -- user defined signal 2
98 SIGCLD : constant := 20; -- alias for SIGCHLD
99 SIGCHLD : constant := 20; -- child status change
100 SIGWINCH : constant := 28; -- window size change
101 SIGURG : constant := 16; -- urgent condition on IO channel
102 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
103 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
104 SIGTSTP : constant := 18; -- user stop requested from tty
105 SIGCONT : constant := 19; -- stopped process has been continued
106 SIGTTIN : constant := 21; -- background tty read attempted
107 SIGTTOU : constant := 22; -- background tty write attempted
108 SIGVTALRM : constant := 26; -- virtual timer expired
109 SIGPROF : constant := 27; -- profiling timer expired
110 SIGXCPU : constant := 24; -- CPU time limit exceeded
111 SIGXFSZ : constant := 25; -- filesize limit exceeded
113 SIGADAABORT : constant := SIGABRT;
115 type Signal_Set is array (Natural range <>) of Signal;
117 Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT, SIGCHLD);
118 Reserved : constant Signal_Set := (SIGKILL, SIGSTOP);
120 type sigset_t is private;
122 function sigaddset (set : access sigset_t; sig : Signal) return int;
123 pragma Import (C, sigaddset, "sigaddset");
125 function sigdelset (set : access sigset_t; sig : Signal) return int;
126 pragma Import (C, sigdelset, "sigdelset");
128 function sigfillset (set : access sigset_t) return int;
129 pragma Import (C, sigfillset, "sigfillset");
131 function sigismember (set : access sigset_t; sig : Signal) return int;
132 pragma Import (C, sigismember, "sigismember");
134 function sigemptyset (set : access sigset_t) return int;
135 pragma Import (C, sigemptyset, "sigemptyset");
137 type struct_sigaction is record
138 sa_handler : System.Address;
139 sa_mask : sigset_t;
140 sa_flags : int;
141 end record;
142 pragma Convention (C, struct_sigaction);
143 type struct_sigaction_ptr is access all struct_sigaction;
145 SIG_BLOCK : constant := 1;
146 SIG_UNBLOCK : constant := 2;
147 SIG_SETMASK : constant := 3;
149 SIG_DFL : constant := 0;
150 SIG_IGN : constant := 1;
152 function sigaction
153 (sig : Signal;
154 act : struct_sigaction_ptr;
155 oact : struct_sigaction_ptr) return int;
156 pragma Import (C, sigaction, "sigaction");
158 ----------
159 -- Time --
160 ----------
162 Time_Slice_Supported : constant Boolean := False;
163 -- Indicates wether time slicing is supported (i.e FSU threads have been
164 -- compiled with DEF_RR)
166 type timespec is private;
168 type clockid_t is private;
170 CLOCK_REALTIME : constant clockid_t;
172 function clock_gettime
173 (clock_id : clockid_t;
174 tp : access timespec) return int;
175 pragma Import (C, clock_gettime, "clock_gettime");
177 function To_Duration (TS : timespec) return Duration;
178 pragma Inline (To_Duration);
180 function To_Timespec (D : Duration) return timespec;
181 pragma Inline (To_Timespec);
183 type struct_timeval is private;
185 function To_Duration (TV : struct_timeval) return Duration;
186 pragma Inline (To_Duration);
188 function To_Timeval (D : Duration) return struct_timeval;
189 pragma Inline (To_Timeval);
191 -------------------------
192 -- Priority Scheduling --
193 -------------------------
195 SCHED_FIFO : constant := 0;
196 SCHED_RR : constant := 1;
197 SCHED_OTHER : constant := 2;
199 -------------
200 -- Process --
201 -------------
203 type pid_t is private;
205 function kill (pid : pid_t; sig : Signal) return int;
206 pragma Import (C, kill, "kill");
208 function getpid return pid_t;
209 pragma Import (C, getpid, "getpid");
211 ---------
212 -- LWP --
213 ---------
215 function lwp_self return System.Address;
216 -- lwp_self does not exist on this thread library, revert to pthread_self
217 -- which is the closest approximation (with getpid). This function is
218 -- needed to share 7staprop.adb across POSIX-like targets.
219 pragma Import (C, lwp_self, "pthread_self");
221 -------------
222 -- Threads --
223 -------------
225 type Thread_Body is access
226 function (arg : System.Address) return System.Address;
228 type pthread_t is private;
229 subtype Thread_Id is pthread_t;
231 type pthread_mutex_t is limited private;
232 type pthread_cond_t is limited private;
233 type pthread_attr_t is limited private;
234 type pthread_mutexattr_t is limited private;
235 type pthread_condattr_t is limited private;
236 type pthread_key_t is private;
238 PTHREAD_CREATE_DETACHED : constant := 1;
240 -----------
241 -- Stack --
242 -----------
244 Stack_Base_Available : constant Boolean := False;
245 -- Indicates wether the stack base is available on this target.
246 -- This allows us to share s-osinte.adb between all the FSU run time.
247 -- Note that this value can only be true if pthread_t has a complete
248 -- definition that corresponds exactly to the C header files.
250 function Get_Stack_Base (thread : pthread_t) return Address;
251 pragma Inline (Get_Stack_Base);
252 -- returns the stack base of the specified thread.
253 -- Only call this function when Stack_Base_Available is True.
255 function Get_Page_Size return size_t;
256 function Get_Page_Size return Address;
257 pragma Import (C, Get_Page_Size, "getpagesize");
258 -- returns the size of a page, or 0 if this is not relevant on this
259 -- target
261 PROT_NONE : constant := 0;
262 PROT_READ : constant := 1;
263 PROT_WRITE : constant := 2;
264 PROT_EXEC : constant := 4;
265 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
267 PROT_ON : constant := PROT_NONE;
268 PROT_OFF : constant := PROT_ALL;
270 function mprotect (addr : Address; len : size_t; prot : int) return int;
271 pragma Import (C, mprotect);
273 ---------------------------------------
274 -- Nonstandard Thread Initialization --
275 ---------------------------------------
277 procedure pthread_init;
278 -- FSU_THREADS requires pthread_init, which is nonstandard
279 -- and this should be invoked during the elaboration of s-taprop.adb
280 pragma Import (C, pthread_init, "pthread_init");
282 -------------------------
283 -- POSIX.1c Section 3 --
284 -------------------------
286 function sigwait
287 (set : access sigset_t;
288 sig : access Signal) return int;
289 -- FSU_THREADS has a nonstandard sigwait
291 function pthread_kill
292 (thread : pthread_t;
293 sig : Signal) return int;
294 pragma Import (C, pthread_kill, "pthread_kill");
296 type sigset_t_ptr is access all sigset_t;
298 function pthread_sigmask
299 (how : int;
300 set : sigset_t_ptr;
301 oset : sigset_t_ptr)
302 return int;
303 pragma Import (C, pthread_sigmask, "sigprocmask");
305 --------------------------
306 -- POSIX.1c Section 11 --
307 --------------------------
309 function pthread_mutexattr_init
310 (attr : access pthread_mutexattr_t) return int;
311 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
313 function pthread_mutexattr_destroy
314 (attr : access pthread_mutexattr_t) return int;
315 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
317 function pthread_mutex_init
318 (mutex : access pthread_mutex_t;
319 attr : access pthread_mutexattr_t) return int;
320 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
322 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
323 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
325 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
326 -- FSU_THREADS has nonstandard pthread_mutex_lock
328 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
329 -- FSU_THREADS has nonstandard pthread_mutex_lock
331 function pthread_condattr_init
332 (attr : access pthread_condattr_t) return int;
333 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
335 function pthread_condattr_destroy
336 (attr : access pthread_condattr_t) return int;
337 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
339 function pthread_cond_init
340 (cond : access pthread_cond_t;
341 attr : access pthread_condattr_t) return int;
342 pragma Import (C, pthread_cond_init, "pthread_cond_init");
344 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
345 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
347 function pthread_cond_signal (cond : access pthread_cond_t) return int;
348 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
350 function pthread_cond_wait
351 (cond : access pthread_cond_t;
352 mutex : access pthread_mutex_t) return int;
353 -- FSU_THREADS has a nonstandard pthread_cond_wait
355 function pthread_cond_timedwait
356 (cond : access pthread_cond_t;
357 mutex : access pthread_mutex_t;
358 abstime : access timespec) return int;
359 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
361 Relative_Timed_Wait : constant Boolean := False;
362 -- pthread_cond_timedwait requires an absolute delay time
364 --------------------------
365 -- POSIX.1c Section 13 --
366 --------------------------
368 PTHREAD_PRIO_NONE : constant := 0;
369 PTHREAD_PRIO_PROTECT : constant := 2;
370 PTHREAD_PRIO_INHERIT : constant := 1;
372 function pthread_mutexattr_setprotocol
373 (attr : access pthread_mutexattr_t;
374 protocol : int) return int;
375 pragma Import (C, pthread_mutexattr_setprotocol);
377 function pthread_mutexattr_setprioceiling
378 (attr : access pthread_mutexattr_t;
379 prioceiling : int) return int;
380 pragma Import
381 (C, pthread_mutexattr_setprioceiling,
382 "pthread_mutexattr_setprio_ceiling");
384 type struct_sched_param is record
385 sched_priority : int; -- scheduling priority
386 end record;
388 function pthread_setschedparam
389 (thread : pthread_t;
390 policy : int;
391 param : access struct_sched_param) return int;
392 -- FSU_THREADS does not have pthread_setschedparam
394 function pthread_attr_setscope
395 (attr : access pthread_attr_t;
396 contentionscope : int) return int;
397 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
399 function pthread_attr_setinheritsched
400 (attr : access pthread_attr_t;
401 inheritsched : int) return int;
402 pragma Import (C, pthread_attr_setinheritsched);
404 function pthread_attr_setschedpolicy
405 (attr : access pthread_attr_t;
406 policy : int) return int;
407 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
409 function pthread_attr_setschedparam
410 (attr : access pthread_attr_t;
411 sched_param : int) return int;
412 pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam");
414 function sched_yield return int;
415 -- FSU_THREADS does not have sched_yield;
417 ---------------------------
418 -- P1003.1c - Section 16 --
419 ---------------------------
421 function pthread_attr_init (attributes : access pthread_attr_t) return int;
422 pragma Import (C, pthread_attr_init, "pthread_attr_init");
424 function pthread_attr_destroy
425 (attributes : access pthread_attr_t) return int;
426 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
428 function pthread_attr_setdetachstate
429 (attr : access pthread_attr_t;
430 detachstate : int) return int;
431 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
433 function pthread_attr_setstacksize
434 (attr : access pthread_attr_t;
435 stacksize : size_t) return int;
436 pragma Import (C, pthread_attr_setstacksize);
438 function pthread_create
439 (thread : access pthread_t;
440 attributes : access pthread_attr_t;
441 start_routine : Thread_Body;
442 arg : System.Address) return int;
443 pragma Import (C, pthread_create, "pthread_create");
445 procedure pthread_exit (status : System.Address);
446 pragma Import (C, pthread_exit, "pthread_exit");
448 function pthread_self return pthread_t;
449 pragma Import (C, pthread_self, "pthread_self");
451 --------------------------
452 -- POSIX.1c Section 17 --
453 --------------------------
455 function pthread_setspecific
456 (key : pthread_key_t;
457 value : System.Address) return int;
458 pragma Import (C, pthread_setspecific, "pthread_setspecific");
460 function pthread_getspecific (key : pthread_key_t) return System.Address;
461 -- FSU_THREADS has a nonstandard pthread_getspecific
463 type destructor_pointer is access procedure (arg : System.Address);
465 function pthread_key_create
466 (key : access pthread_key_t;
467 destructor : destructor_pointer) return int;
468 pragma Import (C, pthread_key_create, "pthread_key_create");
470 private
472 type sigset_t is new int;
474 type pid_t is new int;
476 type time_t is new long;
478 type timespec is record
479 tv_sec : time_t;
480 tv_nsec : long;
481 end record;
482 pragma Convention (C, timespec);
484 type clockid_t is new int;
485 CLOCK_REALTIME : constant clockid_t := 0;
487 type struct_timeval is record
488 tv_sec : long;
489 tv_usec : long;
490 end record;
491 pragma Convention (C, struct_timeval);
493 type pthread_attr_t is record
494 flags : int;
495 stacksize : int;
496 contentionscope : int;
497 inheritsched : int;
498 detachstate : int;
499 sched : int;
500 prio : int;
501 starttime : timespec;
502 deadline : timespec;
503 period : timespec;
504 end record;
505 pragma Convention (C, pthread_attr_t);
507 type pthread_condattr_t is record
508 flags : int;
509 end record;
510 pragma Convention (C, pthread_condattr_t);
512 type pthread_mutexattr_t is record
513 flags : int;
514 prio_ceiling : int;
515 protocol : int;
516 end record;
517 pragma Convention (C, pthread_mutexattr_t);
519 type sigjmp_buf is array (Integer range 0 .. 9) of int;
521 type pthread_t_struct is record
522 context : sigjmp_buf;
523 pbody : sigjmp_buf;
524 errno : int;
525 ret : int;
526 stack_base : System.Address;
527 end record;
528 pragma Convention (C, pthread_t_struct);
530 type pthread_t is access all pthread_t_struct;
532 type queue_t is record
533 head : System.Address;
534 tail : System.Address;
535 end record;
536 pragma Convention (C, queue_t);
538 type pthread_mutex_t is record
539 queue : queue_t;
540 lock : plain_char;
541 owner : System.Address;
542 flags : int;
543 prio_ceiling : int;
544 protocol : int;
545 prev_max_ceiling_prio : int;
546 end record;
547 pragma Convention (C, pthread_mutex_t);
549 type pthread_cond_t is record
550 queue : queue_t;
551 flags : int;
552 waiters : int;
553 mutex : System.Address;
554 end record;
555 pragma Convention (C, pthread_cond_t);
557 type pthread_key_t is new int;
559 end System.OS_Interface;