2005-12-26 Anthony Green <green@redhat.com>
[official-gcc.git] / gcc / ada / s-osinte-solaris-posix.ads
blob5beb96707213d4c9b607c4262d108408b85bb25d
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-2005, 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 a Solaris (POSIX 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 or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
43 with Interfaces.C;
44 with Unchecked_Conversion;
46 package System.OS_Interface is
47 pragma Preelaborate;
49 pragma Linker_Options ("-lposix4");
50 pragma Linker_Options ("-lpthread");
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 := 145;
75 -------------
76 -- Signals --
77 -------------
79 Max_Interrupt : constant := 45;
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 := 16; -- user defined signal 1
100 SIGUSR2 : constant := 17; -- user defined signal 2
101 SIGCLD : constant := 18; -- alias for SIGCHLD
102 SIGCHLD : constant := 18; -- child status change
103 SIGPWR : constant := 19; -- power-fail restart
104 SIGWINCH : constant := 20; -- window size change
105 SIGURG : constant := 21; -- urgent condition on IO channel
106 SIGPOLL : constant := 22; -- pollable event occurred
107 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
109 SIGTSTP : constant := 24; -- user stop requested from tty
110 SIGCONT : constant := 25; -- stopped process has been continued
111 SIGTTIN : constant := 26; -- background tty read attempted
112 SIGTTOU : constant := 27; -- background tty write attempted
113 SIGVTALRM : constant := 28; -- virtual timer expired
114 SIGPROF : constant := 29; -- profiling timer expired
115 SIGXCPU : constant := 30; -- CPU time limit exceeded
116 SIGXFSZ : constant := 31; -- filesize limit exceeded
117 SIGWAITING : constant := 32; -- process's lwps blocked (Solaris)
118 SIGLWP : constant := 33; -- used by thread library (Solaris)
119 SIGFREEZE : constant := 34; -- used by CPR (Solaris)
120 SIGTHAW : constant := 35; -- used by CPR (Solaris)
121 SIGCANCEL : constant := 36; -- thread cancellation signal (libthread)
123 SIGADAABORT : constant := SIGABRT;
125 type Signal_Set is array (Natural range <>) of Signal;
127 Unmasked : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
129 -- Following signals should not be disturbed.
130 -- See c-posix-signals.c in FLORIST
132 Reserved : constant Signal_Set :=
133 (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL);
135 type sigset_t is private;
137 function sigaddset (set : access sigset_t; sig : Signal) return int;
138 pragma Import (C, sigaddset, "sigaddset");
140 function sigdelset (set : access sigset_t; sig : Signal) return int;
141 pragma Import (C, sigdelset, "sigdelset");
143 function sigfillset (set : access sigset_t) return int;
144 pragma Import (C, sigfillset, "sigfillset");
146 function sigismember (set : access sigset_t; sig : Signal) return int;
147 pragma Import (C, sigismember, "sigismember");
149 function sigemptyset (set : access sigset_t) return int;
150 pragma Import (C, sigemptyset, "sigemptyset");
152 type struct_sigaction is record
153 sa_flags : int;
154 sa_handler : System.Address;
155 sa_mask : sigset_t;
156 sa_resv1 : int;
157 sa_resv2 : int;
158 end record;
159 pragma Convention (C, struct_sigaction);
160 type struct_sigaction_ptr is access all struct_sigaction;
162 SA_SIGINFO : constant := 16#0008#;
164 SIG_BLOCK : constant := 1;
165 SIG_UNBLOCK : constant := 2;
166 SIG_SETMASK : constant := 3;
168 SIG_DFL : constant := 0;
169 SIG_IGN : constant := 1;
171 function sigaction
172 (sig : Signal;
173 act : struct_sigaction_ptr;
174 oact : struct_sigaction_ptr) return int;
175 pragma Import (C, sigaction, "sigaction");
177 ----------
178 -- Time --
179 ----------
181 Time_Slice_Supported : constant Boolean := True;
182 -- Indicates wether time slicing is supported
184 type timespec is private;
186 type clockid_t is private;
188 CLOCK_REALTIME : constant clockid_t;
190 function clock_gettime
191 (clock_id : clockid_t;
192 tp : access timespec) return int;
193 pragma Import (C, clock_gettime, "clock_gettime");
195 function To_Duration (TS : timespec) return Duration;
196 pragma Inline (To_Duration);
198 function To_Timespec (D : Duration) return timespec;
199 pragma Inline (To_Timespec);
201 type struct_timeval is private;
203 function To_Duration (TV : struct_timeval) return Duration;
204 pragma Inline (To_Duration);
206 function To_Timeval (D : Duration) return struct_timeval;
207 pragma Inline (To_Timeval);
209 -------------------------
210 -- Priority Scheduling --
211 -------------------------
213 SCHED_FIFO : constant := 1;
214 SCHED_RR : constant := 2;
215 SCHED_OTHER : constant := 0;
217 -------------
218 -- Process --
219 -------------
221 type pid_t is private;
223 function kill (pid : pid_t; sig : Signal) return int;
224 pragma Import (C, kill, "kill");
226 function getpid return pid_t;
227 pragma Import (C, getpid, "getpid");
229 ---------
230 -- LWP --
231 ---------
233 function lwp_self return System.Address;
234 pragma Import (C, lwp_self, "_lwp_self");
236 -------------
237 -- Threads --
238 -------------
240 type Thread_Body is access
241 function (arg : System.Address) return System.Address;
243 function Thread_Body_Access is new
244 Unchecked_Conversion (System.Address, Thread_Body);
246 type pthread_t is private;
247 subtype Thread_Id is pthread_t;
249 type pthread_mutex_t is limited private;
250 type pthread_cond_t is limited private;
251 type pthread_attr_t is limited private;
252 type pthread_mutexattr_t is limited private;
253 type pthread_condattr_t is limited private;
254 type pthread_key_t is private;
256 PTHREAD_CREATE_DETACHED : constant := 16#40#;
258 -----------
259 -- Stack --
260 -----------
262 Stack_Base_Available : constant Boolean := False;
263 -- Indicates wether the stack base is available on this target.
265 function Get_Stack_Base (thread : pthread_t) return Address;
266 pragma Inline (Get_Stack_Base);
267 -- returns the stack base of the specified thread.
268 -- Only call this function when Stack_Base_Available is True.
270 function Get_Page_Size return size_t;
271 function Get_Page_Size return Address;
272 pragma Import (C, Get_Page_Size, "getpagesize");
273 -- returns the size of a page, or 0 if this is not relevant on this
274 -- target
276 PROT_NONE : constant := 0;
277 PROT_READ : constant := 1;
278 PROT_WRITE : constant := 2;
279 PROT_EXEC : constant := 4;
280 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
282 PROT_ON : constant := PROT_READ;
283 PROT_OFF : constant := PROT_ALL;
285 function mprotect (addr : Address; len : size_t; prot : int) return int;
286 pragma Import (C, mprotect);
288 ---------------------------------------
289 -- Nonstandard Thread Initialization --
290 ---------------------------------------
292 procedure pthread_init;
293 -- This is a dummy procedure to share some GNULLI files
295 -------------------------
296 -- POSIX.1c Section 3 --
297 -------------------------
299 function sigwait
300 (set : access sigset_t;
301 sig : access Signal) return int;
302 pragma Import (C, sigwait, "__posix_sigwait");
304 function pthread_kill
305 (thread : pthread_t;
306 sig : Signal) return int;
307 pragma Import (C, pthread_kill, "pthread_kill");
309 type sigset_t_ptr is access all sigset_t;
311 function pthread_sigmask
312 (how : int;
313 set : sigset_t_ptr;
314 oset : sigset_t_ptr) return int;
315 pragma Import (C, pthread_sigmask, "pthread_sigmask");
317 --------------------------
318 -- POSIX.1c Section 11 --
319 --------------------------
321 function pthread_mutexattr_init
322 (attr : access pthread_mutexattr_t) return int;
323 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
325 function pthread_mutexattr_destroy
326 (attr : access pthread_mutexattr_t) return int;
327 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
329 function pthread_mutex_init
330 (mutex : access pthread_mutex_t;
331 attr : access pthread_mutexattr_t) return int;
332 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
334 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
335 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
337 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
338 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
340 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
341 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
343 function pthread_condattr_init
344 (attr : access pthread_condattr_t) return int;
345 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
347 function pthread_condattr_destroy
348 (attr : access pthread_condattr_t) return int;
349 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
351 function pthread_cond_init
352 (cond : access pthread_cond_t;
353 attr : access pthread_condattr_t) return int;
354 pragma Import (C, pthread_cond_init, "pthread_cond_init");
356 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
357 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
359 function pthread_cond_signal (cond : access pthread_cond_t) return int;
360 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
362 function pthread_cond_wait
363 (cond : access pthread_cond_t;
364 mutex : access pthread_mutex_t) return int;
365 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
367 function pthread_cond_timedwait
368 (cond : access pthread_cond_t;
369 mutex : access pthread_mutex_t;
370 abstime : access timespec) return int;
371 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
373 Relative_Timed_Wait : constant Boolean := False;
374 -- pthread_cond_timedwait requires an absolute delay time
376 --------------------------
377 -- POSIX.1c Section 13 --
378 --------------------------
380 PTHREAD_PRIO_NONE : constant := 0;
381 PTHREAD_PRIO_INHERIT : constant := 16#10#;
382 PTHREAD_PRIO_PROTECT : constant := 16#20#;
384 function pthread_mutexattr_setprotocol
385 (attr : access pthread_mutexattr_t;
386 protocol : int) return int;
387 pragma Import (C, pthread_mutexattr_setprotocol);
389 function pthread_mutexattr_setprioceiling
390 (attr : access pthread_mutexattr_t;
391 prioceiling : int) return int;
392 pragma Import (C, pthread_mutexattr_setprioceiling);
394 type Array_8_Int is array (0 .. 7) of int;
395 type struct_sched_param is record
396 sched_priority : int;
397 sched_pad : Array_8_Int;
398 end record;
400 function pthread_setschedparam
401 (thread : pthread_t;
402 policy : int;
403 param : access struct_sched_param) return int;
404 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
406 function pthread_attr_setscope
407 (attr : access pthread_attr_t;
408 contentionscope : int) return int;
409 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
411 function pthread_attr_setinheritsched
412 (attr : access pthread_attr_t;
413 inheritsched : int) return int;
414 pragma Import (C, pthread_attr_setinheritsched);
416 function pthread_attr_setschedpolicy
417 (attr : access pthread_attr_t;
418 policy : int) return int;
419 pragma Import (C, pthread_attr_setschedpolicy);
421 function sched_yield return int;
422 pragma Import (C, sched_yield, "sched_yield");
424 ---------------------------
425 -- P1003.1c - Section 16 --
426 ---------------------------
428 function pthread_attr_init (attributes : access pthread_attr_t) return int;
429 pragma Import (C, pthread_attr_init, "pthread_attr_init");
431 function pthread_attr_destroy
432 (attributes : access pthread_attr_t) return int;
433 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
435 function pthread_attr_setdetachstate
436 (attr : access pthread_attr_t;
437 detachstate : int) return int;
438 pragma Import (C, pthread_attr_setdetachstate);
440 function pthread_attr_setstacksize
441 (attr : access pthread_attr_t;
442 stacksize : size_t) return int;
443 pragma Import (C, pthread_attr_setstacksize);
445 function pthread_create
446 (thread : access pthread_t;
447 attributes : access pthread_attr_t;
448 start_routine : Thread_Body;
449 arg : System.Address) return int;
450 pragma Import (C, pthread_create, "pthread_create");
452 procedure pthread_exit (status : System.Address);
453 pragma Import (C, pthread_exit, "pthread_exit");
455 function pthread_self return pthread_t;
456 pragma Import (C, pthread_self, "pthread_self");
458 --------------------------
459 -- POSIX.1c Section 17 --
460 --------------------------
462 function pthread_setspecific
463 (key : pthread_key_t;
464 value : System.Address) return int;
465 pragma Import (C, pthread_setspecific, "pthread_setspecific");
467 function pthread_getspecific (key : pthread_key_t) return System.Address;
468 pragma Import (C, pthread_getspecific, "pthread_getspecific");
470 type destructor_pointer is access procedure (arg : System.Address);
472 function pthread_key_create
473 (key : access pthread_key_t;
474 destructor : destructor_pointer) return int;
475 pragma Import (C, pthread_key_create, "pthread_key_create");
477 private
479 type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
480 type sigset_t is record
481 X_X_sigbits : array_type_1;
482 end record;
483 pragma Convention (C, sigset_t);
485 type pid_t is new long;
487 type time_t is new long;
489 type timespec is record
490 tv_sec : time_t;
491 tv_nsec : long;
492 end record;
493 pragma Convention (C, timespec);
495 type clockid_t is new int;
496 CLOCK_REALTIME : constant clockid_t := 0;
498 type struct_timeval is record
499 tv_sec : time_t;
500 tv_usec : time_t;
501 end record;
502 pragma Convention (C, struct_timeval);
504 type pthread_attr_t is record
505 pthread_attrp : System.Address;
506 end record;
507 pragma Convention (C, pthread_attr_t);
509 type pthread_condattr_t is record
510 pthread_condattrp : System.Address;
511 end record;
512 pragma Convention (C, pthread_condattr_t);
514 type pthread_mutexattr_t is record
515 pthread_mutexattrp : System.Address;
516 end record;
517 pragma Convention (C, pthread_mutexattr_t);
519 type pthread_t is new unsigned;
521 type uint64_t is mod 2 ** 64;
523 type pthread_mutex_t is record
524 pthread_mutex_flags : uint64_t;
525 pthread_mutex_owner64 : uint64_t;
526 pthread_mutex_data : uint64_t;
527 end record;
528 pragma Convention (C, pthread_mutex_t);
529 type pthread_mutex_t_ptr is access pthread_mutex_t;
531 type pthread_cond_t is record
532 pthread_cond_flags : uint64_t;
533 pthread_cond_data : uint64_t;
534 end record;
535 pragma Convention (C, pthread_cond_t);
537 type pthread_key_t is new unsigned;
539 end System.OS_Interface;