Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / 5posinte.ads
blob155bf0254b645047345012faeab488ba5bb92dab
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) 1997-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 OpenNT/Interix (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;
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 := 60;
74 -------------
75 -- Signals --
76 -------------
78 Max_Interrupt : constant := 31;
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 := 0; -- 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 := 16; -- user defined signal 1
99 SIGUSR2 : constant := 17; -- user defined signal 2
100 SIGCLD : constant := 18; -- alias for SIGCHLD
101 SIGCHLD : constant := 18; -- child status change
102 SIGPWR : constant := 0; -- power-fail restart
103 SIGWINCH : constant := 20; -- window size change
104 SIGURG : constant := 21; -- urgent condition on IO channel
105 SIGPOLL : constant := 22; -- pollable event occurred
106 SIGIO : constant := 19; -- I/O possible (Solaris SIGPOLL alias)
107 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
108 SIGTSTP : constant := 24; -- user stop requested from tty
109 SIGCONT : constant := 25; -- stopped process has been continued
110 SIGTTIN : constant := 26; -- background tty read attempted
111 SIGTTOU : constant := 27; -- background tty write attempted
112 SIGVTALRM : constant := 28; -- virtual timer expired
113 SIGPROF : constant := 29; -- profiling timer expired
114 SIGXCPU : constant := 30; -- CPU time limit exceeded
115 SIGXFSZ : constant := 31; -- filesize limit exceeded
117 SIGADAABORT : constant := SIGABRT;
119 type Signal_Set is array (Natural range <>) of Signal;
121 Unmasked : constant Signal_Set :=
122 (SIGTRAP, SIGALRM, SIGVTALRM, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
124 Reserved : constant Signal_Set := (SIGKILL, SIGSTOP);
126 type sigset_t is private;
128 function sigaddset (set : access sigset_t; sig : Signal) return int;
129 pragma Import (C, sigaddset, "sigaddset");
131 function sigdelset (set : access sigset_t; sig : Signal) return int;
132 pragma Import (C, sigdelset, "sigdelset");
134 function sigfillset (set : access sigset_t) return int;
135 pragma Import (C, sigfillset, "sigfillset");
137 function sigismember (set : access sigset_t; sig : Signal) return int;
138 pragma Import (C, sigismember, "sigismember");
140 function sigemptyset (set : access sigset_t) return int;
141 pragma Import (C, sigemptyset, "sigemptyset");
143 type struct_sigaction is record
144 sa_handler : System.Address;
145 sa_mask : sigset_t;
146 sa_flags : int;
147 sa_restorer : System.Address;
148 end record;
149 pragma Convention (C, struct_sigaction);
150 type struct_sigaction_ptr is access all struct_sigaction;
152 SIG_BLOCK : constant := 1;
153 SIG_UNBLOCK : constant := 2;
154 SIG_SETMASK : constant := 3;
156 SIG_DFL : constant := 0;
157 SIG_IGN : constant := 1;
159 function sigaction
160 (sig : Signal;
161 act : struct_sigaction_ptr;
162 oact : struct_sigaction_ptr) return int;
163 -- FSU pthreads redefines sigaction and then uses a special syscall
164 -- API to call the system version. Doing syscalls on OpenNT is very
165 -- difficult, so we rename the pthread version instead.
166 pragma Import (C, sigaction, "pthread_wrapper_sigaction");
168 ----------
169 -- Time --
170 ----------
172 Time_Slice_Supported : constant Boolean := False;
173 -- Indicates wether time slicing is supported (i.e FSU threads have been
174 -- compiled with DEF_RR)
176 type timespec is private;
178 type clockid_t is private;
180 CLOCK_REALTIME : constant clockid_t;
182 function clock_gettime
183 (clock_id : clockid_t;
184 tp : access timespec) return int;
185 pragma Import (C, clock_gettime, "clock_gettime");
187 function To_Duration (TS : timespec) return Duration;
188 pragma Inline (To_Duration);
190 function To_Timespec (D : Duration) return timespec;
191 pragma Inline (To_Timespec);
193 type struct_timeval is private;
195 function To_Duration (TV : struct_timeval) return Duration;
196 pragma Inline (To_Duration);
198 function To_Timeval (D : Duration) return struct_timeval;
199 pragma Inline (To_Timeval);
201 -------------------------
202 -- Priority Scheduling --
203 -------------------------
205 SCHED_FIFO : constant := 0;
206 SCHED_RR : constant := 1;
207 SCHED_OTHER : constant := 2;
209 -------------
210 -- Process --
211 -------------
213 type pid_t is private;
215 function kill (pid : pid_t; sig : Signal) return int;
216 pragma Import (C, kill, "kill");
218 function getpid return pid_t;
219 pragma Import (C, getpid, "getpid");
221 ---------
222 -- LWP --
223 ---------
225 function lwp_self return System.Address;
226 -- lwp_self does not exist on this thread library, revert to pthread_self
227 -- which is the closest approximation (with getpid). This function is
228 -- needed to share 7staprop.adb across POSIX-like targets.
229 pragma Import (C, lwp_self, "pthread_self");
231 -------------
232 -- Threads --
233 -------------
235 type Thread_Body is access
236 function (arg : System.Address) return System.Address;
237 type pthread_t is private;
238 subtype Thread_Id is pthread_t;
240 type pthread_mutex_t is limited private;
241 type pthread_cond_t is limited private;
242 type pthread_attr_t is limited private;
243 type pthread_mutexattr_t is limited private;
244 type pthread_condattr_t is limited private;
245 type pthread_key_t is private;
247 PTHREAD_CREATE_DETACHED : constant := 1;
248 PTHREAD_CREATE_JOINABLE : constant := 0;
250 -----------
251 -- Stack --
252 -----------
254 Stack_Base_Available : constant Boolean := False;
255 -- Indicates wether the stack base is available on this target.
256 -- This allows us to share s-osinte.adb between all the FSU run time.
257 -- Note that this value can only be true if pthread_t has a complete
258 -- definition that corresponds exactly to the C header files.
260 function Get_Stack_Base (thread : pthread_t) return Address;
261 pragma Inline (Get_Stack_Base);
262 -- returns the stack base of the specified thread.
263 -- Only call this function when Stack_Base_Available is True.
265 function Get_Page_Size return size_t;
266 function Get_Page_Size return Address;
267 pragma Import (C, Get_Page_Size, "getpagesize");
268 -- returns the size of a page, or 0 if this is not relevant on this
269 -- target
271 PROT_NONE : constant := 0;
272 PROT_READ : constant := 1;
273 PROT_WRITE : constant := 2;
274 PROT_EXEC : constant := 4;
275 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
277 PROT_ON : constant := PROT_NONE;
278 PROT_OFF : constant := PROT_ALL;
280 function mprotect (addr : Address; len : size_t; prot : int) return int;
281 pragma Import (C, mprotect);
283 ---------------------------------------
284 -- Nonstandard Thread Initialization --
285 ---------------------------------------
287 procedure pthread_init;
288 -- FSU_THREADS requires pthread_init, which is nonstandard
289 -- and this should be invoked during the elaboration of s-taprop.adb
290 pragma Import (C, pthread_init, "pthread_init");
292 -------------------------
293 -- POSIX.1c Section 3 --
294 -------------------------
296 function sigwait
297 (set : access sigset_t;
298 sig : access Signal) return int;
299 -- FSU_THREADS has a nonstandard sigwait
301 function pthread_kill
302 (thread : pthread_t;
303 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_wrapper_sigprocmask");
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 -- FSU_THREADS has nonstandard pthread_mutex_lock
337 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
338 -- FSU_THREADS has nonstandard pthread_mutex_lock
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 -- FSU_THREADS has a nonstandard 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 -- FSU_THREADS has a nonstandard pthread_cond_timedwait
370 Relative_Timed_Wait : constant Boolean := False;
371 -- pthread_cond_timedwait requires an absolute delay time
373 --------------------------
374 -- POSIX.1c Section 13 --
375 --------------------------
377 PTHREAD_PRIO_NONE : constant := 0;
378 PTHREAD_PRIO_PROTECT : constant := 2;
379 PTHREAD_PRIO_INHERIT : constant := 1;
381 function pthread_mutexattr_setprotocol
382 (attr : access pthread_mutexattr_t;
383 protocol : int) return int;
384 pragma Import (C, pthread_mutexattr_setprotocol);
386 function pthread_mutexattr_setprioceiling
387 (attr : access pthread_mutexattr_t;
388 prioceiling : int) return int;
389 pragma Import
390 (C, pthread_mutexattr_setprioceiling,
391 "pthread_mutexattr_setprio_ceiling");
393 type struct_sched_param is record
394 sched_priority : int; -- scheduling priority
395 end record;
397 function pthread_setschedparam
398 (thread : pthread_t;
399 policy : int;
400 param : access struct_sched_param) return int;
401 -- FSU_THREADS does not have pthread_setschedparam
403 function pthread_attr_setscope
404 (attr : access pthread_attr_t;
405 contentionscope : int) return int;
406 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
408 function pthread_attr_setinheritsched
409 (attr : access pthread_attr_t;
410 inheritsched : int) return int;
411 pragma Import (C, pthread_attr_setinheritsched);
413 function pthread_attr_setschedpolicy
414 (attr : access pthread_attr_t;
415 policy : int) return int;
416 pragma Import
417 (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
419 function sched_yield return int;
420 -- FSU_THREADS does not have sched_yield;
422 ---------------------------
423 -- P1003.1c - Section 16 --
424 ---------------------------
426 function pthread_attr_init (attributes : access pthread_attr_t) return int;
427 pragma Import (C, pthread_attr_init, "pthread_attr_init");
429 function pthread_attr_destroy
430 (attributes : access pthread_attr_t) return int;
431 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
433 function pthread_attr_setdetachstate
434 (attr : access pthread_attr_t;
435 detachstate : int) return int;
436 -- FSU_THREADS has a nonstandard pthread_attr_setdetachstate
438 function pthread_attr_setstacksize
439 (attr : access pthread_attr_t;
440 stacksize : size_t) return int;
441 pragma Import (C, pthread_attr_setstacksize);
443 function pthread_create
444 (thread : access pthread_t;
445 attributes : access pthread_attr_t;
446 start_routine : Thread_Body;
447 arg : System.Address) return int;
448 pragma Import (C, pthread_create, "pthread_create");
450 procedure pthread_exit (status : System.Address);
451 pragma Import (C, pthread_exit, "pthread_exit");
453 function pthread_self return pthread_t;
454 pragma Import (C, pthread_self, "pthread_self");
456 --------------------------
457 -- POSIX.1c Section 17 --
458 --------------------------
460 function pthread_setspecific
461 (key : pthread_key_t;
462 value : System.Address) return int;
463 pragma Import (C, pthread_setspecific, "pthread_setspecific");
465 function pthread_getspecific (key : pthread_key_t) return System.Address;
466 -- FSU_THREADS has a nonstandard pthread_getspecific
468 type destructor_pointer is access procedure (arg : System.Address);
470 function pthread_key_create
471 (key : access pthread_key_t;
472 destructor : destructor_pointer) return int;
473 pragma Import (C, pthread_key_create, "pthread_key_create");
475 private
477 type sigset_t is new unsigned_long;
478 pragma Convention (C, sigset_t);
480 type pid_t is new int;
482 subtype time_t is long;
484 type timespec is record
485 tv_sec : time_t;
486 tv_nsec : long;
487 end record;
488 pragma Convention (C, timespec);
490 type clockid_t is new int;
491 CLOCK_REALTIME : constant clockid_t := 0;
493 type struct_timeval is record
494 tv_sec : time_t;
495 tv_usec : long;
496 end record;
497 pragma Convention (C, struct_timeval);
499 type pthread_attr_t is record
500 flags : int;
501 stacksize : int;
502 contentionscope : int;
503 inheritsched : int;
504 detachstate : int;
505 sched : int;
506 prio : int;
507 starttime : timespec;
508 deadline : timespec;
509 period : timespec;
510 end record;
511 pragma Convention (C_Pass_By_Copy, pthread_attr_t);
513 type pthread_condattr_t is record
514 flags : int;
515 end record;
516 pragma Convention (C, pthread_condattr_t);
518 type pthread_mutexattr_t is record
519 flags : int;
520 prio_ceiling : int;
521 protocol : int;
522 end record;
523 pragma Convention (C, pthread_mutexattr_t);
525 type sigjmp_buf is array (Integer range 0 .. 17) of int;
527 type pthread_t_struct is record
528 context : sigjmp_buf;
529 pbody : sigjmp_buf;
530 errno : int;
531 ret : int;
532 stack_base : System.Address;
533 end record;
534 pragma Convention (C, pthread_t_struct);
536 type pthread_t is access all pthread_t_struct;
538 type queue_t is record
539 head : System.Address;
540 tail : System.Address;
541 end record;
542 pragma Convention (C, queue_t);
544 type pthread_mutex_t is record
545 queue : queue_t;
546 lock : plain_char;
547 owner : System.Address;
548 flags : int;
549 prio_ceiling : int;
550 protocol : int;
551 prev_max_ceiling_prio : int;
552 end record;
553 pragma Convention (C, pthread_mutex_t);
555 type pthread_cond_t is record
556 queue : queue_t;
557 flags : int;
558 waiters : int;
559 mutex : System.Address;
560 end record;
561 pragma Convention (C, pthread_cond_t);
563 type pthread_key_t is new int;
565 end System.OS_Interface;