gcc/
[official-gcc.git] / gcc / ada / s-osinte-tru64.ads
blobe893eedb3993eff74e4de335bdcb0c92eb80af0c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2009, 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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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 the Tru64 version of this package
37 -- This package encapsulates all direct interfaces to OS services
38 -- that are needed by the tasking run-time (libgnarl).
40 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
43 with Interfaces.C;
45 with Ada.Unchecked_Conversion;
47 package System.OS_Interface is
48 pragma Preelaborate;
50 pragma Linker_Options ("-lpthread");
51 pragma Linker_Options ("-lmach");
52 pragma Linker_Options ("-lexc");
53 pragma Linker_Options ("-lrt");
55 subtype int is Interfaces.C.int;
56 subtype short is Interfaces.C.short;
57 subtype long is Interfaces.C.long;
58 subtype unsigned is Interfaces.C.unsigned;
59 subtype unsigned_short is Interfaces.C.unsigned_short;
60 subtype unsigned_long is Interfaces.C.unsigned_long;
61 subtype unsigned_char is Interfaces.C.unsigned_char;
62 subtype plain_char is Interfaces.C.plain_char;
63 subtype size_t is Interfaces.C.size_t;
64 subtype char_array is Interfaces.C.char_array;
66 -----------
67 -- Errno --
68 -----------
70 function errno return int;
71 pragma Import (C, errno, "_Geterrno");
73 EAGAIN : constant := 35;
74 EINTR : constant := 4;
75 EINVAL : constant := 22;
76 ENOMEM : constant := 12;
77 ETIMEDOUT : constant := 60;
79 -------------
80 -- Signals --
81 -------------
83 Max_Interrupt : constant := 48;
84 type Signal is new int range 0 .. Max_Interrupt;
85 for Signal'Size use int'Size;
87 SIGHUP : constant := 1; -- hangup
88 SIGINT : constant := 2; -- interrupt (rubout)
89 SIGQUIT : constant := 3; -- quit (ASCD FS)
90 SIGILL : constant := 4; -- illegal instruction (not reset)
91 SIGTRAP : constant := 5; -- trace trap (not reset)
92 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
93 SIGIOT : constant := 6; -- abort (terminate) process
94 SIGLOST : constant := 6; -- old BSD signal ??
95 SIGEMT : constant := 7; -- EMT instruction
96 SIGFPE : constant := 8; -- floating point exception
97 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
98 SIGBUS : constant := 10; -- bus error
99 SIGSEGV : constant := 11; -- segmentation violation
100 SIGSYS : constant := 12; -- bad argument to system call
101 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
102 SIGALRM : constant := 14; -- alarm clock
103 SIGTERM : constant := 15; -- software termination signal from kill
104 SIGURG : constant := 16; -- urgent condition on IO channel
105 SIGIOINT : constant := 16; -- printer to backend error signal
106 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
107 SIGTSTP : constant := 18; -- user stop requested from tty
108 SIGCONT : constant := 19; -- stopped process has been continued
109 SIGCHLD : constant := 20; -- child status change
110 SIGTTIN : constant := 21; -- background tty read attempted
111 SIGTTOU : constant := 22; -- background tty write attempted
112 SIGPOLL : constant := 23; -- I/O possible, or completed
113 SIGIO : constant := 23; -- STREAMS version of SIGPOLL
114 SIGAIO : constant := 23; -- base lan i/o
115 SIGPTY : constant := 23; -- pty i/o
116 SIGXCPU : constant := 24; -- CPU time limit exceeded
117 SIGXFSZ : constant := 25; -- filesize limit exceeded
118 SIGVTALRM : constant := 26; -- virtual timer expired
119 SIGPROF : constant := 27; -- profiling timer expired
120 SIGWINCH : constant := 28; -- window size change
121 SIGINFO : constant := 29; -- information request
122 SIGPWR : constant := 29; -- Power Fail/Restart -- SVID3/SVR4
123 SIGUSR1 : constant := 30; -- user defined signal 1
124 SIGUSR2 : constant := 31; -- user defined signal 2
125 SIGRESV : constant := 32; -- reserved by Digital for future use
127 SIGADAABORT : constant := SIGABRT;
129 type Signal_Set is array (Natural range <>) of Signal;
131 Unmasked : constant Signal_Set := (0 .. 0 => SIGTRAP);
132 Reserved : constant Signal_Set := (SIGALRM, SIGABRT, SIGKILL, SIGSTOP);
134 type sigset_t is private;
136 function sigaddset (set : access sigset_t; sig : Signal) return int;
137 pragma Import (C, sigaddset);
139 function sigdelset (set : access sigset_t; sig : Signal) return int;
140 pragma Import (C, sigdelset);
142 function sigfillset (set : access sigset_t) return int;
143 pragma Import (C, sigfillset);
145 function sigismember (set : access sigset_t; sig : Signal) return int;
146 pragma Import (C, sigismember);
148 function sigemptyset (set : access sigset_t) return int;
149 pragma Import (C, sigemptyset);
151 type union_type_3 is new String (1 .. 116);
152 type siginfo_t is record
153 si_signo : int;
154 si_errno : int;
155 si_code : int;
156 X_data : union_type_3;
157 end record;
158 for siginfo_t'Size use 8 * 128;
159 pragma Convention (C, siginfo_t);
161 type struct_sigaction is record
162 sa_handler : System.Address;
163 sa_mask : sigset_t;
164 sa_flags : int;
165 sa_signo : int;
166 end record;
167 pragma Convention (C, struct_sigaction);
168 type struct_sigaction_ptr is access all struct_sigaction;
170 SIG_BLOCK : constant := 1;
171 SIG_UNBLOCK : constant := 2;
172 SIG_SETMASK : constant := 3;
174 SIG_DFL : constant := 0;
175 SIG_IGN : constant := 1;
177 SA_NODEFER : constant := 8;
178 SA_SIGINFO : constant := 16#40#;
179 SA_ONSTACK : constant := 16#01#;
181 function sigaction
182 (sig : Signal;
183 act : struct_sigaction_ptr;
184 oact : struct_sigaction_ptr) return int;
185 pragma Import (C, sigaction);
187 ----------
188 -- Time --
189 ----------
191 type timespec is private;
193 function nanosleep (rqtp, rmtp : access timespec) return int;
194 pragma Import (C, nanosleep);
196 type clockid_t is private;
198 CLOCK_REALTIME : constant clockid_t;
200 function clock_gettime
201 (clock_id : clockid_t;
202 tp : access timespec) return int;
203 pragma Import (C, clock_gettime);
205 function To_Duration (TS : timespec) return Duration;
206 pragma Inline (To_Duration);
208 function To_Timespec (D : Duration) return timespec;
209 pragma Inline (To_Timespec);
211 type struct_timezone is record
212 tz_minuteswest : int;
213 tz_dsttime : int;
214 end record;
215 pragma Convention (C, struct_timezone);
217 -------------------------
218 -- Priority Scheduling --
219 -------------------------
221 SCHED_FIFO : constant := 1;
222 SCHED_RR : constant := 2;
223 SCHED_OTHER : constant := 3;
224 SCHED_LFI : constant := 5;
226 -------------
227 -- Process --
228 -------------
230 type pid_t is private;
232 function kill (pid : pid_t; sig : Signal) return int;
233 pragma Import (C, kill);
235 function getpid return pid_t;
236 pragma Import (C, getpid);
238 BIND_NO_INHERIT : constant := 1;
240 function bind_to_cpu
241 (pid : pid_t;
242 cpu_mask : unsigned_long;
243 flag : unsigned_long := BIND_NO_INHERIT) return int;
244 pragma Import (C, bind_to_cpu);
246 -------------
247 -- Threads --
248 -------------
250 type Thread_Body is access
251 function (arg : System.Address) return System.Address;
252 pragma Convention (C, Thread_Body);
254 function Thread_Body_Access is new
255 Ada.Unchecked_Conversion (System.Address, Thread_Body);
257 type pthread_t is private;
258 subtype Thread_Id is pthread_t;
260 type pthread_mutex_t is limited private;
261 type pthread_cond_t is limited private;
262 type pthread_attr_t is limited private;
263 type pthread_mutexattr_t is limited private;
264 type pthread_condattr_t is limited private;
265 type pthread_key_t is private;
267 PTHREAD_CREATE_DETACHED : constant := 1;
269 PTHREAD_SCOPE_PROCESS : constant := 0;
270 PTHREAD_SCOPE_SYSTEM : constant := 1;
272 PTHREAD_EXPLICIT_SCHED : constant := 1;
274 -----------
275 -- Stack --
276 -----------
278 Stack_Base_Available : constant Boolean := False;
279 -- Indicates if the stack base is available on this target
281 function Get_Stack_Base (thread : pthread_t) return Address;
282 pragma Inline (Get_Stack_Base);
283 -- Returns the stack base of the specified thread. Only call this function
284 -- when Stack_Base_Available is True.
286 function Get_Page_Size return size_t;
287 function Get_Page_Size return Address;
288 pragma Import (C, Get_Page_Size, "getpagesize");
289 -- Returns the size of a page
291 PROT_NONE : constant := 0;
292 PROT_READ : constant := 1;
293 PROT_WRITE : constant := 2;
294 PROT_EXEC : constant := 4;
295 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
297 PROT_ON : constant := PROT_READ;
298 PROT_OFF : constant := PROT_ALL;
300 function mprotect (addr : Address; len : size_t; prot : int) return int;
301 pragma Import (C, mprotect);
303 procedure Hide_Unhide_Yellow_Zone (Hide : Boolean);
304 -- Every thread except the initial one features an overflow warning area
305 -- (called the Yellow Zone) which is just above the overflow guard area
306 -- on the stack (called the Red Zone). During task execution, we want
307 -- signals from the Red Zone, so we need to hide the Yellow Zone. This
308 -- procedure is called at the start of task execution (with Hide set True)
309 -- to hide the Yellow Zone, and at the end of task execution (with Hide
310 -- set False) to unhide the Yellow Zone.
312 ---------------------------------------
313 -- Nonstandard Thread Initialization --
314 ---------------------------------------
316 procedure pthread_init;
317 pragma Inline (pthread_init);
318 -- This is a dummy procedure to share some GNULLI files
320 -------------------------
321 -- POSIX.1c Section 3 --
322 -------------------------
324 function sigwait
325 (set : access sigset_t;
326 sig : access Signal) return int;
327 pragma Import (C, sigwait, "__sigwaitd10");
329 function pthread_kill
330 (thread : pthread_t;
331 sig : Signal) return int;
332 pragma Import (C, pthread_kill);
334 function pthread_sigmask
335 (how : int;
336 set : access sigset_t;
337 oset : access sigset_t) return int;
338 pragma Import (C, pthread_sigmask);
340 --------------------------
341 -- POSIX.1c Section 11 --
342 --------------------------
344 function pthread_mutexattr_init (attr : access pthread_mutexattr_t)
345 return int;
346 pragma Import (C, pthread_mutexattr_init);
348 function pthread_mutexattr_destroy
349 (attr : access pthread_mutexattr_t) return int;
350 pragma Import (C, pthread_mutexattr_destroy);
352 function pthread_mutex_init
353 (mutex : access pthread_mutex_t;
354 attr : access pthread_mutexattr_t) return int;
355 pragma Import (C, pthread_mutex_init, "__pthread_mutex_init");
357 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
358 pragma Import (C, pthread_mutex_destroy, "__pthread_mutex_destroy");
360 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
361 pragma Import (C, pthread_mutex_lock, "__pthread_mutex_lock");
363 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
364 pragma Import (C, pthread_mutex_unlock, "__pthread_mutex_unlock");
366 function pthread_condattr_init
367 (attr : access pthread_condattr_t) return int;
368 pragma Import (C, pthread_condattr_init);
370 function pthread_condattr_destroy
371 (attr : access pthread_condattr_t) return int;
372 pragma Import (C, pthread_condattr_destroy);
374 function pthread_cond_init
375 (cond : access pthread_cond_t;
376 attr : access pthread_condattr_t) return int;
377 pragma Import (C, pthread_cond_init, "__pthread_cond_init");
379 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
380 pragma Import (C, pthread_cond_destroy, "__pthread_cond_destroy");
382 function pthread_cond_signal (cond : access pthread_cond_t) return int;
383 pragma Import (C, pthread_cond_signal, "__pthread_cond_signal");
385 function pthread_cond_wait
386 (cond : access pthread_cond_t;
387 mutex : access pthread_mutex_t) return int;
388 pragma Import (C, pthread_cond_wait, "__pthread_cond_wait");
390 function pthread_cond_timedwait
391 (cond : access pthread_cond_t;
392 mutex : access pthread_mutex_t;
393 abstime : access timespec) return int;
394 pragma Import (C, pthread_cond_timedwait, "__pthread_cond_timedwait");
396 --------------------------
397 -- POSIX.1c Section 13 --
398 --------------------------
400 function pthread_mutexattr_setprotocol
401 (attr : access pthread_mutexattr_t;
402 protocol : int) return int;
403 pragma Import (C, pthread_mutexattr_setprotocol);
405 function pthread_mutexattr_setprioceiling
406 (attr : access pthread_mutexattr_t;
407 prioceiling : int) return int;
408 pragma Import (C, pthread_mutexattr_setprioceiling);
410 type struct_sched_param is record
411 sched_priority : int; -- scheduling priority
412 end record;
414 function pthread_setschedparam
415 (thread : pthread_t;
416 policy : int;
417 param : access struct_sched_param) return int;
418 pragma Import (C, pthread_setschedparam);
420 function pthread_attr_setscope
421 (attr : access pthread_attr_t;
422 contentionscope : int) return int;
423 pragma Import (C, pthread_attr_setscope);
425 function pthread_attr_setinheritsched
426 (attr : access pthread_attr_t;
427 inheritsched : int) return int;
428 pragma Import (C, pthread_attr_setinheritsched,
429 "__pthread_attr_setinheritsched");
431 function pthread_attr_setschedpolicy
432 (attr : access pthread_attr_t; policy : int) return int;
433 pragma Import (C, pthread_attr_setschedpolicy);
435 function pthread_attr_setschedparam
436 (attr : access pthread_attr_t;
437 sched_param : access struct_sched_param) return int;
438 pragma Import (C, pthread_attr_setschedparam);
440 function sched_yield return int;
441 pragma Import (C, sched_yield);
443 --------------------------
444 -- P1003.1c Section 16 --
445 --------------------------
447 function pthread_attr_init (attributes : access pthread_attr_t)
448 return int;
449 pragma Import (C, pthread_attr_init);
451 function pthread_attr_destroy (attributes : access pthread_attr_t)
452 return int;
453 pragma Import (C, pthread_attr_destroy);
455 function pthread_attr_setdetachstate
456 (attr : access pthread_attr_t;
457 detachstate : int) return int;
458 pragma Import (C, pthread_attr_setdetachstate);
460 function pthread_attr_setstacksize
461 (attr : access pthread_attr_t;
462 stacksize : size_t) return int;
463 pragma Import (C, pthread_attr_setstacksize, "__pthread_attr_setstacksize");
465 function pthread_create
466 (thread : access pthread_t;
467 attributes : access pthread_attr_t;
468 start_routine : Thread_Body;
469 arg : System.Address) return int;
470 pragma Import (C, pthread_create, "__pthread_create");
472 procedure pthread_exit (status : System.Address);
473 pragma Import (C, pthread_exit, "__pthread_exit");
475 function pthread_self return pthread_t;
476 pragma Inline (pthread_self);
478 --------------------------
479 -- POSIX.1c Section 17 --
480 --------------------------
482 function pthread_setspecific
483 (key : pthread_key_t; value : System.Address) return int;
484 pragma Import (C, pthread_setspecific, "__pthread_setspecific");
486 function pthread_getspecific (key : pthread_key_t) return System.Address;
487 pragma Import (C, pthread_getspecific, "__pthread_getspecific");
489 type destructor_pointer is access procedure (arg : System.Address);
490 pragma Convention (C, destructor_pointer);
492 function pthread_key_create
493 (key : access pthread_key_t;
494 destructor : destructor_pointer) return int;
495 pragma Import (C, pthread_key_create);
497 private
499 type sigset_t is new unsigned_long;
501 type pid_t is new int;
503 type time_t is new int;
505 type timespec is record
506 tv_sec : time_t;
507 tv_nsec : long;
508 end record;
509 pragma Convention (C, timespec);
511 type clockid_t is new int;
512 CLOCK_REALTIME : constant clockid_t := 1;
514 type unsigned_long_array is array (Natural range <>) of unsigned_long;
516 type pthread_t is new System.Address;
518 type pthread_teb_t is record
519 reserved1 : System.Address;
520 reserved2 : System.Address;
521 size : unsigned_short;
522 version : unsigned_char;
523 reserved3 : unsigned_char;
524 external : unsigned_char;
525 reserved4 : char_array (0 .. 1);
526 creator : unsigned_char;
527 sequence : unsigned_long;
528 reserved5 : unsigned_long_array (0 .. 1);
529 per_kt_area : System.Address;
530 stack_base : System.Address;
531 stack_reserve : System.Address;
532 stack_yellow : System.Address;
533 stack_guard : System.Address;
534 stack_size : unsigned_long;
535 tsd_values : System.Address;
536 tsd_count : unsigned_long;
537 reserved6 : unsigned;
538 reserved7 : unsigned;
539 thread_flags : unsigned;
540 thd_errno : int;
541 stack_hiwater : System.Address;
542 home_rad : unsigned_long;
543 end record;
544 pragma Convention (C, pthread_teb_t);
546 type pthread_cond_t is record
547 state : unsigned;
548 valid : unsigned;
549 name : System.Address;
550 arg : unsigned;
551 reserved1 : unsigned;
552 sequence : unsigned_long;
553 block : System.Address;
554 end record;
555 pragma Convention (C, pthread_cond_t);
557 type pthread_attr_t is record
558 valid : long;
559 name : System.Address;
560 arg : unsigned_long;
561 reserved : unsigned_long_array (0 .. 18);
562 end record;
563 pragma Convention (C, pthread_attr_t);
565 type pthread_mutex_t is record
566 lock : unsigned;
567 valid : unsigned;
568 name : System.Address;
569 arg : unsigned;
570 depth : unsigned;
571 sequence : unsigned_long;
572 owner : unsigned_long;
573 block : System.Address;
574 end record;
575 for pthread_mutex_t'Size use 8 * 48;
576 pragma Convention (C, pthread_mutex_t);
578 type pthread_mutexattr_t is record
579 valid : long;
580 reserved : unsigned_long_array (0 .. 14);
581 end record;
582 pragma Convention (C, pthread_mutexattr_t);
584 type pthread_condattr_t is record
585 valid : long;
586 reserved : unsigned_long_array (0 .. 12);
587 end record;
588 pragma Convention (C, pthread_condattr_t);
590 type pthread_key_t is new unsigned;
592 end System.OS_Interface;