Merged with mainline at revision 128810.
[official-gcc.git] / gcc / ada / s-osinte-solaris.ads
blob88b99b735df790be5f3567a82530b2f48518933d
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-2007, 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 (native) version of this package
37 -- This package includes 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 Ada.Unchecked_Conversion;
46 package System.OS_Interface is
47 pragma Preelaborate;
49 pragma Linker_Options ("-lposix4");
50 pragma Linker_Options ("-lthread");
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 ETIME : constant := 62;
74 ETIMEDOUT : constant := 145;
76 -------------
77 -- Signals --
78 -------------
80 Max_Interrupt : constant := 45;
81 type Signal is new int range 0 .. Max_Interrupt;
82 for Signal'Size use int'Size;
84 SIGHUP : constant := 1; -- hangup
85 SIGINT : constant := 2; -- interrupt (rubout)
86 SIGQUIT : constant := 3; -- quit (ASCD FS)
87 SIGILL : constant := 4; -- illegal instruction (not reset)
88 SIGTRAP : constant := 5; -- trace trap (not reset)
89 SIGIOT : constant := 6; -- IOT instruction
90 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
91 SIGEMT : constant := 7; -- EMT instruction
92 SIGFPE : constant := 8; -- floating point exception
93 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
94 SIGBUS : constant := 10; -- bus error
95 SIGSEGV : constant := 11; -- segmentation violation
96 SIGSYS : constant := 12; -- bad argument to system call
97 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
98 SIGALRM : constant := 14; -- alarm clock
99 SIGTERM : constant := 15; -- software termination signal from kill
100 SIGUSR1 : constant := 16; -- user defined signal 1
101 SIGUSR2 : constant := 17; -- user defined signal 2
102 SIGCLD : constant := 18; -- alias for SIGCHLD
103 SIGCHLD : constant := 18; -- child status change
104 SIGPWR : constant := 19; -- power-fail restart
105 SIGWINCH : constant := 20; -- window size change
106 SIGURG : constant := 21; -- urgent condition on IO channel
107 SIGPOLL : constant := 22; -- pollable event occurred
108 SIGIO : constant := 22; -- I/O possible (Solaris SIGPOLL alias)
109 SIGSTOP : constant := 23; -- stop (cannot be caught or ignored)
110 SIGTSTP : constant := 24; -- user stop requested from tty
111 SIGCONT : constant := 25; -- stopped process has been continued
112 SIGTTIN : constant := 26; -- background tty read attempted
113 SIGTTOU : constant := 27; -- background tty write attempted
114 SIGVTALRM : constant := 28; -- virtual timer expired
115 SIGPROF : constant := 29; -- profiling timer expired
116 SIGXCPU : constant := 30; -- CPU time limit exceeded
117 SIGXFSZ : constant := 31; -- filesize limit exceeded
118 SIGWAITING : constant := 32; -- process's lwps blocked (Solaris)
119 SIGLWP : constant := 33; -- used by thread library (Solaris)
120 SIGFREEZE : constant := 34; -- used by CPR (Solaris)
121 SIGTHAW : constant := 35; -- used by CPR (Solaris)
122 SIGCANCEL : constant := 36; -- thread cancellation signal (libthread)
124 type Signal_Set is array (Natural range <>) of Signal;
126 Unmasked : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
128 -- Following signals should not be disturbed.
129 -- See c-posix-signals.c in FLORIST.
131 Reserved : constant Signal_Set :=
132 (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL, SIGTRAP, SIGSEGV);
134 type sigset_t is private;
136 function sigaddset (set : access sigset_t; sig : Signal) return int;
137 pragma Import (C, sigaddset, "sigaddset");
139 function sigdelset (set : access sigset_t; sig : Signal) return int;
140 pragma Import (C, sigdelset, "sigdelset");
142 function sigfillset (set : access sigset_t) return int;
143 pragma Import (C, sigfillset, "sigfillset");
145 function sigismember (set : access sigset_t; sig : Signal) return int;
146 pragma Import (C, sigismember, "sigismember");
148 function sigemptyset (set : access sigset_t) return int;
149 pragma Import (C, sigemptyset, "sigemptyset");
151 type union_type_3 is new String (1 .. 116);
152 type siginfo_t is record
153 si_signo : int;
154 si_code : int;
155 si_errno : int;
156 X_data : union_type_3;
157 end record;
158 pragma Convention (C, siginfo_t);
160 -- The types mcontext_t and gregset_t are part of the ucontext_t
161 -- information, which is specific to Solaris2.4 for SPARC
162 -- The ucontext_t info seems to be used by the handler
163 -- for SIGSEGV to decide whether it is a Storage_Error (stack overflow) or
164 -- a Constraint_Error (bad pointer). The original code that did this
165 -- is suspect, so it is not clear whether we really need this part of
166 -- the signal context information, or perhaps something else.
167 -- More analysis is needed, after which these declarations may need to
168 -- be changed.
170 FPE_INTDIV : constant := 1; -- integer divide by zero
171 FPE_INTOVF : constant := 2; -- integer overflow
172 FPE_FLTDIV : constant := 3; -- floating point divide by zero
173 FPE_FLTOVF : constant := 4; -- floating point overflow
174 FPE_FLTUND : constant := 5; -- floating point underflow
175 FPE_FLTRES : constant := 6; -- floating point inexact result
176 FPE_FLTINV : constant := 7; -- invalid floating point operation
177 FPE_FLTSUB : constant := 8; -- subscript out of range
179 type greg_t is new int;
181 type gregset_t is array (0 .. 18) of greg_t;
183 type union_type_2 is new String (1 .. 128);
184 type record_type_1 is record
185 fpu_fr : union_type_2;
186 fpu_q : System.Address;
187 fpu_fsr : unsigned;
188 fpu_qcnt : unsigned_char;
189 fpu_q_entrysize : unsigned_char;
190 fpu_en : unsigned_char;
191 end record;
192 pragma Convention (C, record_type_1);
194 type array_type_7 is array (Integer range 0 .. 20) of long;
195 type mcontext_t is record
196 gregs : gregset_t;
197 gwins : System.Address;
198 fpregs : record_type_1;
199 filler : array_type_7;
200 end record;
201 pragma Convention (C, mcontext_t);
203 type record_type_2 is record
204 ss_sp : System.Address;
205 ss_size : int;
206 ss_flags : int;
207 end record;
208 pragma Convention (C, record_type_2);
210 type array_type_8 is array (Integer range 0 .. 22) of long;
211 type ucontext_t is record
212 uc_flags : unsigned_long;
213 uc_link : System.Address;
214 uc_sigmask : sigset_t;
215 uc_stack : record_type_2;
216 uc_mcontext : mcontext_t;
217 uc_filler : array_type_8;
218 end record;
219 pragma Convention (C, ucontext_t);
221 type Signal_Handler is access procedure
222 (signo : Signal;
223 info : access siginfo_t;
224 context : access ucontext_t);
226 type union_type_1 is new plain_char;
227 type array_type_2 is array (Integer range 0 .. 1) of int;
228 type struct_sigaction is record
229 sa_flags : int;
230 sa_handler : System.Address;
231 sa_mask : sigset_t;
232 sa_resv : array_type_2;
233 end record;
234 pragma Convention (C, struct_sigaction);
235 type struct_sigaction_ptr is access all struct_sigaction;
237 SIG_BLOCK : constant := 1;
238 SIG_UNBLOCK : constant := 2;
239 SIG_SETMASK : constant := 3;
241 SIG_DFL : constant := 0;
242 SIG_IGN : constant := 1;
244 function sigaction
245 (sig : Signal;
246 act : struct_sigaction_ptr;
247 oact : struct_sigaction_ptr) return int;
248 pragma Import (C, sigaction, "sigaction");
250 ----------
251 -- Time --
252 ----------
254 type timespec is private;
256 type clockid_t is private;
258 CLOCK_REALTIME : constant clockid_t;
260 function clock_gettime
261 (clock_id : clockid_t; tp : access timespec) return int;
262 pragma Import (C, clock_gettime, "clock_gettime");
264 function clock_getres
265 (clock_id : clockid_t; res : access timespec) return int;
266 pragma Import (C, clock_getres, "clock_getres");
268 function To_Duration (TS : timespec) return Duration;
269 pragma Inline (To_Duration);
271 function To_Timespec (D : Duration) return timespec;
272 pragma Inline (To_Timespec);
274 type struct_timeval is private;
275 -- This is needed on systems that do not have clock_gettime()
276 -- but do have gettimeofday().
278 function To_Duration (TV : struct_timeval) return Duration;
279 pragma Inline (To_Duration);
281 function To_Timeval (D : Duration) return struct_timeval;
282 pragma Inline (To_Timeval);
284 -------------
285 -- Process --
286 -------------
288 type pid_t is private;
290 function kill (pid : pid_t; sig : Signal) return int;
291 pragma Import (C, kill, "kill");
293 function getpid return pid_t;
294 pragma Import (C, getpid, "getpid");
296 -------------
297 -- Threads --
298 -------------
300 type Thread_Body is access
301 function (arg : System.Address) return System.Address;
303 function Thread_Body_Access is new
304 Ada.Unchecked_Conversion (System.Address, Thread_Body);
306 THR_DETACHED : constant := 64;
307 THR_BOUND : constant := 1;
308 THR_NEW_LWP : constant := 2;
309 USYNC_THREAD : constant := 0;
311 type thread_t is new unsigned;
312 subtype Thread_Id is thread_t;
313 -- These types should be commented ???
315 function To_thread_t is new Ada.Unchecked_Conversion (Integer, thread_t);
317 type mutex_t is limited private;
319 type cond_t is limited private;
321 type thread_key_t is private;
323 function thr_create
324 (stack_base : System.Address;
325 stack_size : size_t;
326 start_routine : Thread_Body;
327 arg : System.Address;
328 flags : int;
329 new_thread : access thread_t) return int;
330 pragma Import (C, thr_create, "thr_create");
332 function thr_min_stack return size_t;
333 pragma Import (C, thr_min_stack, "thr_min_stack");
335 function thr_self return thread_t;
336 pragma Import (C, thr_self, "thr_self");
338 function mutex_init
339 (mutex : access mutex_t;
340 mtype : int;
341 arg : System.Address) return int;
342 pragma Import (C, mutex_init, "mutex_init");
344 function mutex_destroy (mutex : access mutex_t) return int;
345 pragma Import (C, mutex_destroy, "mutex_destroy");
347 function mutex_lock (mutex : access mutex_t) return int;
348 pragma Import (C, mutex_lock, "mutex_lock");
350 function mutex_unlock (mutex : access mutex_t) return int;
351 pragma Import (C, mutex_unlock, "mutex_unlock");
353 function cond_init
354 (cond : access cond_t;
355 ctype : int;
356 arg : int) return int;
357 pragma Import (C, cond_init, "cond_init");
359 function cond_wait
360 (cond : access cond_t; mutex : access mutex_t) return int;
361 pragma Import (C, cond_wait, "cond_wait");
363 function cond_timedwait
364 (cond : access cond_t;
365 mutex : access mutex_t;
366 abstime : access timespec) return int;
367 pragma Import (C, cond_timedwait, "cond_timedwait");
369 function cond_signal (cond : access cond_t) return int;
370 pragma Import (C, cond_signal, "cond_signal");
372 function cond_destroy (cond : access cond_t) return int;
373 pragma Import (C, cond_destroy, "cond_destroy");
375 function thr_setspecific
376 (key : thread_key_t; value : System.Address) return int;
377 pragma Import (C, thr_setspecific, "thr_setspecific");
379 function thr_getspecific
380 (key : thread_key_t;
381 value : access System.Address) return int;
382 pragma Import (C, thr_getspecific, "thr_getspecific");
384 function thr_keycreate
385 (key : access thread_key_t; destructor : System.Address) return int;
386 pragma Import (C, thr_keycreate, "thr_keycreate");
388 function thr_setprio (thread : thread_t; priority : int) return int;
389 pragma Import (C, thr_setprio, "thr_setprio");
391 procedure thr_exit (status : System.Address);
392 pragma Import (C, thr_exit, "thr_exit");
394 function thr_setconcurrency (new_level : int) return int;
395 pragma Import (C, thr_setconcurrency, "thr_setconcurrency");
397 function sigwait (set : access sigset_t; sig : access Signal) return int;
398 pragma Import (C, sigwait, "__posix_sigwait");
400 function thr_kill (thread : thread_t; sig : Signal) return int;
401 pragma Import (C, thr_kill, "thr_kill");
403 function thr_sigsetmask
404 (how : int;
405 set : access sigset_t;
406 oset : access sigset_t) return int;
407 pragma Import (C, thr_sigsetmask, "thr_sigsetmask");
409 function pthread_sigmask
410 (how : int;
411 set : access sigset_t;
412 oset : access sigset_t) return int;
413 pragma Import (C, pthread_sigmask, "thr_sigsetmask");
415 function thr_suspend (target_thread : thread_t) return int;
416 pragma Import (C, thr_suspend, "thr_suspend");
418 function thr_continue (target_thread : thread_t) return int;
419 pragma Import (C, thr_continue, "thr_continue");
421 procedure thr_yield;
422 pragma Import (C, thr_yield, "thr_yield");
424 ---------
425 -- LWP --
426 ---------
428 P_PID : constant := 0;
429 P_LWPID : constant := 8;
431 PC_GETCID : constant := 0;
432 PC_GETCLINFO : constant := 1;
433 PC_SETPARMS : constant := 2;
434 PC_GETPARMS : constant := 3;
435 PC_ADMIN : constant := 4;
437 PC_CLNULL : constant := -1;
439 RT_NOCHANGE : constant := -1;
440 RT_TQINF : constant := -2;
441 RT_TQDEF : constant := -3;
443 PC_CLNMSZ : constant := 16;
445 PC_VERSION : constant := 1;
447 type lwpid_t is new int;
449 type pri_t is new short;
451 type id_t is new long;
453 P_MYID : constant := -1;
454 -- The specified LWP or process is the current one
456 type struct_pcinfo is record
457 pc_cid : id_t;
458 pc_clname : String (1 .. PC_CLNMSZ);
459 rt_maxpri : short;
460 end record;
461 pragma Convention (C, struct_pcinfo);
463 type struct_pcparms is record
464 pc_cid : id_t;
465 rt_pri : pri_t;
466 rt_tqsecs : long;
467 rt_tqnsecs : long;
468 end record;
469 pragma Convention (C, struct_pcparms);
471 function priocntl
472 (ver : int;
473 id_type : int;
474 id : lwpid_t;
475 cmd : int;
476 arg : System.Address) return Interfaces.C.long;
477 pragma Import (C, priocntl, "__priocntl");
479 function lwp_self return lwpid_t;
480 pragma Import (C, lwp_self, "_lwp_self");
482 type processorid_t is new int;
483 type processorid_t_ptr is access all processorid_t;
485 -- Constants for function processor_bind
487 PBIND_QUERY : constant processorid_t := -2;
488 -- The processor bindings are not changed
490 PBIND_NONE : constant processorid_t := -1;
491 -- The processor bindings of the specified LWPs are cleared
493 -- Flags for function p_online
495 PR_OFFLINE : constant int := 1;
496 -- Processor is offline, as quiet as possible
498 PR_ONLINE : constant int := 2;
499 -- Processor online
501 PR_STATUS : constant int := 3;
502 -- Value passed to p_online to request status
504 function p_online (processorid : processorid_t; flag : int) return int;
505 pragma Import (C, p_online, "p_online");
507 function processor_bind
508 (id_type : int;
509 id : id_t;
510 proc_id : processorid_t;
511 obind : processorid_t_ptr) return int;
512 pragma Import (C, processor_bind, "processor_bind");
514 procedure pthread_init;
515 -- Dummy procedure to share s-intman.adb with other Solaris targets
517 private
519 type array_type_1 is array (0 .. 3) of unsigned_long;
520 type sigset_t is record
521 X_X_sigbits : array_type_1;
522 end record;
523 pragma Convention (C, sigset_t);
525 type pid_t is new long;
527 type time_t is new long;
529 type timespec is record
530 tv_sec : time_t;
531 tv_nsec : long;
532 end record;
533 pragma Convention (C, timespec);
535 type clockid_t is new int;
536 CLOCK_REALTIME : constant clockid_t := 0;
538 type struct_timeval is record
539 tv_sec : long;
540 tv_usec : long;
541 end record;
542 pragma Convention (C, struct_timeval);
544 type array_type_9 is array (0 .. 3) of unsigned_char;
545 type record_type_3 is record
546 flag : array_type_9;
547 Xtype : unsigned_long;
548 end record;
549 pragma Convention (C, record_type_3);
551 type mutex_t is record
552 flags : record_type_3;
553 lock : String (1 .. 8);
554 data : String (1 .. 8);
555 end record;
556 pragma Convention (C, mutex_t);
558 type cond_t is record
559 flag : array_type_9;
560 Xtype : unsigned_long;
561 data : String (1 .. 8);
562 end record;
563 pragma Convention (C, cond_t);
565 type thread_key_t is new unsigned;
567 end System.OS_Interface;