2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / s-osinte-solaris-posix.ads
blobae318060ccd235db4d35804dda2cb81d281b69d2
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-2008, 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 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 ("-lposix4");
51 pragma Linker_Options ("-lpthread");
53 -- The following is needed to allow --enable-threads=solaris
55 pragma Linker_Options ("-lthread");
57 subtype int is Interfaces.C.int;
58 subtype short is Interfaces.C.short;
59 subtype long is Interfaces.C.long;
60 subtype unsigned is Interfaces.C.unsigned;
61 subtype unsigned_short is Interfaces.C.unsigned_short;
62 subtype unsigned_long is Interfaces.C.unsigned_long;
63 subtype unsigned_char is Interfaces.C.unsigned_char;
64 subtype plain_char is Interfaces.C.plain_char;
65 subtype size_t is Interfaces.C.size_t;
67 -----------
68 -- Errno --
69 -----------
71 function errno return int;
72 pragma Import (C, errno, "__get_errno");
74 EAGAIN : constant := 11;
75 EINTR : constant := 4;
76 EINVAL : constant := 22;
77 ENOMEM : constant := 12;
78 ETIMEDOUT : constant := 145;
80 -------------
81 -- Signals --
82 -------------
84 Max_Interrupt : constant := 45;
85 type Signal is new int range 0 .. Max_Interrupt;
86 for Signal'Size use int'Size;
88 SIGHUP : constant := 1; -- hangup
89 SIGINT : constant := 2; -- interrupt (rubout)
90 SIGQUIT : constant := 3; -- quit (ASCD FS)
91 SIGILL : constant := 4; -- illegal instruction (not reset)
92 SIGTRAP : constant := 5; -- trace trap (not reset)
93 SIGIOT : constant := 6; -- IOT instruction
94 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
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 SIGUSR1 : constant := 16; -- user defined signal 1
105 SIGUSR2 : constant := 17; -- user defined signal 2
106 SIGCLD : constant := 18; -- alias for SIGCHLD
107 SIGCHLD : constant := 18; -- child status change
108 SIGPWR : constant := 19; -- power-fail restart
109 SIGWINCH : constant := 20; -- window size change
110 SIGURG : constant := 21; -- urgent condition on IO channel
111 SIGPOLL : constant := 22; -- pollable event occurred
112 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
113 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
114 SIGTSTP : constant := 24; -- user stop requested from tty
115 SIGCONT : constant := 25; -- stopped process has been continued
116 SIGTTIN : constant := 26; -- background tty read attempted
117 SIGTTOU : constant := 27; -- background tty write attempted
118 SIGVTALRM : constant := 28; -- virtual timer expired
119 SIGPROF : constant := 29; -- profiling timer expired
120 SIGXCPU : constant := 30; -- CPU time limit exceeded
121 SIGXFSZ : constant := 31; -- filesize limit exceeded
122 SIGWAITING : constant := 32; -- process's lwps blocked (Solaris)
123 SIGLWP : constant := 33; -- used by thread library (Solaris)
124 SIGFREEZE : constant := 34; -- used by CPR (Solaris)
125 SIGTHAW : constant := 35; -- used by CPR (Solaris)
126 SIGCANCEL : constant := 36; -- thread cancellation signal (libthread)
128 SIGADAABORT : constant := SIGABRT;
130 type Signal_Set is array (Natural range <>) of Signal;
132 Unmasked : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
134 -- Following signals should not be disturbed.
135 -- See c-posix-signals.c in FLORIST
137 Reserved : constant Signal_Set :=
138 (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL);
140 type sigset_t is private;
142 function sigaddset (set : access sigset_t; sig : Signal) return int;
143 pragma Import (C, sigaddset, "sigaddset");
145 function sigdelset (set : access sigset_t; sig : Signal) return int;
146 pragma Import (C, sigdelset, "sigdelset");
148 function sigfillset (set : access sigset_t) return int;
149 pragma Import (C, sigfillset, "sigfillset");
151 function sigismember (set : access sigset_t; sig : Signal) return int;
152 pragma Import (C, sigismember, "sigismember");
154 function sigemptyset (set : access sigset_t) return int;
155 pragma Import (C, sigemptyset, "sigemptyset");
157 type struct_sigaction is record
158 sa_flags : int;
159 sa_handler : System.Address;
160 sa_mask : sigset_t;
161 sa_resv1 : int;
162 sa_resv2 : int;
163 end record;
164 pragma Convention (C, struct_sigaction);
165 type struct_sigaction_ptr is access all struct_sigaction;
167 SA_SIGINFO : constant := 16#0008#;
168 SA_ONSTACK : constant := 16#0001#;
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 function sigaction
178 (sig : Signal;
179 act : struct_sigaction_ptr;
180 oact : struct_sigaction_ptr) return int;
181 pragma Import (C, sigaction, "sigaction");
183 ----------
184 -- Time --
185 ----------
187 Time_Slice_Supported : constant Boolean := True;
188 -- Indicates whether time slicing is supported
190 type timespec is private;
192 type clockid_t is private;
194 CLOCK_REALTIME : constant clockid_t;
196 function clock_gettime
197 (clock_id : clockid_t;
198 tp : access timespec) return int;
199 pragma Import (C, clock_gettime, "clock_gettime");
201 function To_Duration (TS : timespec) return Duration;
202 pragma Inline (To_Duration);
204 function To_Timespec (D : Duration) return timespec;
205 pragma Inline (To_Timespec);
207 type struct_timeval is private;
209 function To_Duration (TV : struct_timeval) return Duration;
210 pragma Inline (To_Duration);
212 function To_Timeval (D : Duration) return struct_timeval;
213 pragma Inline (To_Timeval);
215 -------------------------
216 -- Priority Scheduling --
217 -------------------------
219 SCHED_FIFO : constant := 1;
220 SCHED_RR : constant := 2;
221 SCHED_OTHER : constant := 0;
223 function To_Target_Priority
224 (Prio : System.Any_Priority) return Interfaces.C.int;
225 -- Maps System.Any_Priority to a POSIX priority
227 -------------
228 -- Process --
229 -------------
231 type pid_t is private;
233 function kill (pid : pid_t; sig : Signal) return int;
234 pragma Import (C, kill, "kill");
236 function getpid return pid_t;
237 pragma Import (C, getpid, "getpid");
239 ---------
240 -- LWP --
241 ---------
243 function lwp_self return System.Address;
244 pragma Import (C, lwp_self, "_lwp_self");
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 := 16#40#;
269 PTHREAD_SCOPE_PROCESS : constant := 0;
270 PTHREAD_SCOPE_SYSTEM : constant := 1;
272 -----------
273 -- Stack --
274 -----------
276 type stack_t is record
277 ss_sp : System.Address;
278 ss_size : size_t;
279 ss_flags : int;
280 end record;
281 pragma Convention (C, stack_t);
283 function sigaltstack
284 (ss : not null access stack_t;
285 oss : access stack_t) return int;
286 pragma Import (C, sigaltstack, "sigaltstack");
288 Alternate_Stack : aliased System.Address;
289 -- This is a dummy definition, never used (Alternate_Stack_Size is null)
291 Alternate_Stack_Size : constant := 0;
292 -- No alternate signal stack is used on this platform
294 Stack_Base_Available : constant Boolean := False;
295 -- Indicates whether the stack base is available on this target
297 function Get_Stack_Base (thread : pthread_t) return Address;
298 pragma Inline (Get_Stack_Base);
299 -- Returns the stack base of the specified thread. Only call this function
300 -- when Stack_Base_Available is True.
302 function Get_Page_Size return size_t;
303 function Get_Page_Size return Address;
304 pragma Import (C, Get_Page_Size, "getpagesize");
305 -- Returns the size of a page, or 0 if this is not relevant on this target
307 PROT_NONE : constant := 0;
308 PROT_READ : constant := 1;
309 PROT_WRITE : constant := 2;
310 PROT_EXEC : constant := 4;
311 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
312 PROT_ON : constant := PROT_READ;
313 PROT_OFF : constant := PROT_ALL;
315 function mprotect (addr : Address; len : size_t; prot : int) return int;
316 pragma Import (C, mprotect);
318 ---------------------------------------
319 -- Nonstandard Thread Initialization --
320 ---------------------------------------
322 procedure pthread_init;
323 -- This is a dummy procedure to share some GNULLI files
325 -------------------------
326 -- POSIX.1c Section 3 --
327 -------------------------
329 function sigwait
330 (set : access sigset_t;
331 sig : access Signal) return int;
332 pragma Import (C, sigwait, "__posix_sigwait");
334 function pthread_kill
335 (thread : pthread_t;
336 sig : Signal) return int;
337 pragma Import (C, pthread_kill, "pthread_kill");
339 function pthread_sigmask
340 (how : int;
341 set : access sigset_t;
342 oset : access sigset_t) return int;
343 pragma Import (C, pthread_sigmask, "pthread_sigmask");
345 --------------------------
346 -- POSIX.1c Section 11 --
347 --------------------------
349 function pthread_mutexattr_init
350 (attr : access pthread_mutexattr_t) return int;
351 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
353 function pthread_mutexattr_destroy
354 (attr : access pthread_mutexattr_t) return int;
355 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
357 function pthread_mutex_init
358 (mutex : access pthread_mutex_t;
359 attr : access pthread_mutexattr_t) return int;
360 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
362 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
363 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
365 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
366 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
368 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
369 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
371 function pthread_condattr_init
372 (attr : access pthread_condattr_t) return int;
373 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
375 function pthread_condattr_destroy
376 (attr : access pthread_condattr_t) return int;
377 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
379 function pthread_cond_init
380 (cond : access pthread_cond_t;
381 attr : access pthread_condattr_t) return int;
382 pragma Import (C, pthread_cond_init, "pthread_cond_init");
384 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
385 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
387 function pthread_cond_signal (cond : access pthread_cond_t) return int;
388 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
390 function pthread_cond_wait
391 (cond : access pthread_cond_t;
392 mutex : access pthread_mutex_t) return int;
393 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
395 function pthread_cond_timedwait
396 (cond : access pthread_cond_t;
397 mutex : access pthread_mutex_t;
398 abstime : access timespec) return int;
399 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
401 Relative_Timed_Wait : constant Boolean := False;
402 -- pthread_cond_timedwait requires an absolute delay time
404 --------------------------
405 -- POSIX.1c Section 13 --
406 --------------------------
408 PTHREAD_PRIO_NONE : constant := 0;
409 PTHREAD_PRIO_INHERIT : constant := 16#10#;
410 PTHREAD_PRIO_PROTECT : constant := 16#20#;
412 function pthread_mutexattr_setprotocol
413 (attr : access pthread_mutexattr_t;
414 protocol : int) return int;
415 pragma Import (C, pthread_mutexattr_setprotocol);
417 function pthread_mutexattr_setprioceiling
418 (attr : access pthread_mutexattr_t;
419 prioceiling : int) return int;
420 pragma Import (C, pthread_mutexattr_setprioceiling);
422 type Array_8_Int is array (0 .. 7) of int;
423 type struct_sched_param is record
424 sched_priority : int;
425 sched_pad : Array_8_Int;
426 end record;
428 function pthread_setschedparam
429 (thread : pthread_t;
430 policy : int;
431 param : access struct_sched_param) return int;
432 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
434 function pthread_attr_setscope
435 (attr : access pthread_attr_t;
436 contentionscope : int) return int;
437 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
439 function pthread_attr_setinheritsched
440 (attr : access pthread_attr_t;
441 inheritsched : int) return int;
442 pragma Import (C, pthread_attr_setinheritsched);
444 function pthread_attr_setschedpolicy
445 (attr : access pthread_attr_t;
446 policy : int) return int;
447 pragma Import (C, pthread_attr_setschedpolicy);
449 function sched_yield return int;
450 pragma Import (C, sched_yield, "sched_yield");
452 ---------------------------
453 -- P1003.1c - Section 16 --
454 ---------------------------
456 function pthread_attr_init (attributes : access pthread_attr_t) return int;
457 pragma Import (C, pthread_attr_init, "pthread_attr_init");
459 function pthread_attr_destroy
460 (attributes : access pthread_attr_t) return int;
461 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
463 function pthread_attr_setdetachstate
464 (attr : access pthread_attr_t;
465 detachstate : int) return int;
466 pragma Import (C, pthread_attr_setdetachstate);
468 function pthread_attr_setstacksize
469 (attr : access pthread_attr_t;
470 stacksize : size_t) return int;
471 pragma Import (C, pthread_attr_setstacksize);
473 function pthread_create
474 (thread : access pthread_t;
475 attributes : access pthread_attr_t;
476 start_routine : Thread_Body;
477 arg : System.Address) return int;
478 pragma Import (C, pthread_create, "pthread_create");
480 procedure pthread_exit (status : System.Address);
481 pragma Import (C, pthread_exit, "pthread_exit");
483 function pthread_self return pthread_t;
484 pragma Import (C, pthread_self, "pthread_self");
486 --------------------------
487 -- POSIX.1c Section 17 --
488 --------------------------
490 function pthread_setspecific
491 (key : pthread_key_t;
492 value : System.Address) return int;
493 pragma Import (C, pthread_setspecific, "pthread_setspecific");
495 function pthread_getspecific (key : pthread_key_t) return System.Address;
496 pragma Import (C, pthread_getspecific, "pthread_getspecific");
498 type destructor_pointer is access procedure (arg : System.Address);
499 pragma Convention (C, destructor_pointer);
501 function pthread_key_create
502 (key : access pthread_key_t;
503 destructor : destructor_pointer) return int;
504 pragma Import (C, pthread_key_create, "pthread_key_create");
506 private
508 type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
509 type sigset_t is record
510 X_X_sigbits : array_type_1;
511 end record;
512 pragma Convention (C, sigset_t);
514 type pid_t is new long;
516 type time_t is new long;
518 type timespec is record
519 tv_sec : time_t;
520 tv_nsec : long;
521 end record;
522 pragma Convention (C, timespec);
524 type clockid_t is new int;
525 CLOCK_REALTIME : constant clockid_t := 0;
527 type struct_timeval is record
528 tv_sec : time_t;
529 tv_usec : time_t;
530 end record;
531 pragma Convention (C, struct_timeval);
533 type pthread_attr_t is record
534 pthread_attrp : System.Address;
535 end record;
536 pragma Convention (C, pthread_attr_t);
538 type pthread_condattr_t is record
539 pthread_condattrp : System.Address;
540 end record;
541 pragma Convention (C, pthread_condattr_t);
543 type pthread_mutexattr_t is record
544 pthread_mutexattrp : System.Address;
545 end record;
546 pragma Convention (C, pthread_mutexattr_t);
548 type pthread_t is new unsigned;
550 type uint64_t is mod 2 ** 64;
552 type pthread_mutex_t is record
553 pthread_mutex_flags : uint64_t;
554 pthread_mutex_owner64 : uint64_t;
555 pthread_mutex_data : uint64_t;
556 end record;
557 pragma Convention (C, pthread_mutex_t);
558 type pthread_mutex_t_ptr is access pthread_mutex_t;
560 type pthread_cond_t is record
561 pthread_cond_flags : uint64_t;
562 pthread_cond_data : uint64_t;
563 end record;
564 pragma Convention (C, pthread_cond_t);
566 type pthread_key_t is new unsigned;
568 end System.OS_Interface;