OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-solaris.ads
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 ------------------------------------------------------------------------------
34
35 --  This is a Solaris (native) version of this package
36
37 --  This package includes all direct interfaces to OS services
38 --  that are needed by children of System.
39
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.
42
43 with Interfaces.C;
44 with Ada.Unchecked_Conversion;
45
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-lposix4");
50    pragma Linker_Options ("-lthread");
51
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;
61
62    -----------
63    -- Errno --
64    -----------
65
66    function errno return int;
67    pragma Import (C, errno, "__get_errno");
68
69    EAGAIN    : constant := 11;
70    EINTR     : constant := 4;
71    EINVAL    : constant := 22;
72    ENOMEM    : constant := 12;
73    ETIME     : constant := 62;
74    ETIMEDOUT : constant := 145;
75
76    -------------
77    -- Signals --
78    -------------
79
80    Max_Interrupt : constant := 45;
81    type Signal is new int range 0 .. Max_Interrupt;
82    for Signal'Size use int'Size;
83
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)
123
124    type Signal_Set is array (Natural range <>) of Signal;
125
126    Unmasked : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
127
128    --  Following signals should not be disturbed.
129    --  See c-posix-signals.c in FLORIST.
130
131    Reserved : constant Signal_Set :=
132      (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL, SIGTRAP, SIGSEGV);
133
134    type sigset_t is private;
135
136    function sigaddset (set : access sigset_t; sig : Signal) return int;
137    pragma Import (C, sigaddset, "sigaddset");
138
139    function sigdelset (set : access sigset_t; sig : Signal) return int;
140    pragma Import (C, sigdelset, "sigdelset");
141
142    function sigfillset (set : access sigset_t) return int;
143    pragma Import (C, sigfillset, "sigfillset");
144
145    function sigismember (set : access sigset_t; sig : Signal) return int;
146    pragma Import (C, sigismember, "sigismember");
147
148    function sigemptyset (set : access sigset_t) return int;
149    pragma Import (C, sigemptyset, "sigemptyset");
150
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);
159
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.
169
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
178
179    type greg_t is new int;
180
181    type gregset_t is array (0 .. 18) of greg_t;
182
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);
193
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);
202
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);
209
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);
220
221    type Signal_Handler is access procedure
222      (signo   : Signal;
223       info    : access siginfo_t;
224       context : access ucontext_t);
225
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;
236
237    SIG_BLOCK   : constant := 1;
238    SIG_UNBLOCK : constant := 2;
239    SIG_SETMASK : constant := 3;
240
241    SIG_DFL : constant := 0;
242    SIG_IGN : constant := 1;
243
244    function sigaction
245      (sig  : Signal;
246       act  : struct_sigaction_ptr;
247       oact : struct_sigaction_ptr) return int;
248    pragma Import (C, sigaction, "sigaction");
249
250    ----------
251    -- Time --
252    ----------
253
254    type timespec is private;
255
256    type clockid_t is private;
257
258    CLOCK_REALTIME : constant clockid_t;
259
260    function clock_gettime
261      (clock_id : clockid_t; tp : access timespec) return int;
262    pragma Import (C, clock_gettime, "clock_gettime");
263
264    function clock_getres
265      (clock_id : clockid_t; res : access timespec) return int;
266    pragma Import (C, clock_getres, "clock_getres");
267
268    function To_Duration (TS : timespec) return Duration;
269    pragma Inline (To_Duration);
270
271    function To_Timespec (D : Duration) return timespec;
272    pragma Inline (To_Timespec);
273
274    type struct_timeval is private;
275    --  This is needed on systems that do not have clock_gettime()
276    --  but do have gettimeofday().
277
278    function To_Duration (TV : struct_timeval) return Duration;
279    pragma Inline (To_Duration);
280
281    function To_Timeval (D : Duration) return struct_timeval;
282    pragma Inline (To_Timeval);
283
284    -------------
285    -- Process --
286    -------------
287
288    type pid_t is private;
289
290    function kill (pid : pid_t; sig : Signal) return int;
291    pragma Import (C, kill, "kill");
292
293    function getpid return pid_t;
294    pragma Import (C, getpid, "getpid");
295
296    -------------
297    -- Threads --
298    -------------
299
300    type Thread_Body is access
301      function (arg : System.Address) return System.Address;
302    pragma Convention (C, Thread_Body);
303
304    function Thread_Body_Access is new
305      Ada.Unchecked_Conversion (System.Address, Thread_Body);
306
307    THR_DETACHED  : constant := 64;
308    THR_BOUND     : constant := 1;
309    THR_NEW_LWP   : constant := 2;
310    USYNC_THREAD  : constant := 0;
311
312    type thread_t is new unsigned;
313    subtype Thread_Id is thread_t;
314    --  These types should be commented ???
315
316    function To_thread_t is new Ada.Unchecked_Conversion (Integer, thread_t);
317
318    type mutex_t is limited private;
319
320    type cond_t is limited private;
321
322    type thread_key_t is private;
323
324    function thr_create
325      (stack_base    : System.Address;
326       stack_size    : size_t;
327       start_routine : Thread_Body;
328       arg           : System.Address;
329       flags         : int;
330       new_thread    : access thread_t) return int;
331    pragma Import (C, thr_create, "thr_create");
332
333    function thr_min_stack return size_t;
334    pragma Import (C, thr_min_stack, "thr_min_stack");
335
336    function thr_self return thread_t;
337    pragma Import (C, thr_self, "thr_self");
338
339    function mutex_init
340      (mutex : access mutex_t;
341       mtype : int;
342       arg   : System.Address) return int;
343    pragma Import (C, mutex_init, "mutex_init");
344
345    function mutex_destroy (mutex : access mutex_t) return int;
346    pragma Import (C, mutex_destroy, "mutex_destroy");
347
348    function mutex_lock (mutex : access mutex_t) return int;
349    pragma Import (C, mutex_lock, "mutex_lock");
350
351    function mutex_unlock (mutex : access mutex_t) return int;
352    pragma Import (C, mutex_unlock, "mutex_unlock");
353
354    function cond_init
355      (cond  : access cond_t;
356       ctype : int;
357       arg   : int) return int;
358    pragma Import (C, cond_init, "cond_init");
359
360    function cond_wait
361      (cond : access cond_t; mutex : access mutex_t) return int;
362    pragma Import (C, cond_wait, "cond_wait");
363
364    function cond_timedwait
365      (cond    : access cond_t;
366       mutex   : access mutex_t;
367       abstime : access timespec) return int;
368    pragma Import (C, cond_timedwait, "cond_timedwait");
369
370    function cond_signal (cond : access cond_t) return int;
371    pragma Import (C, cond_signal, "cond_signal");
372
373    function cond_destroy (cond : access cond_t) return int;
374    pragma Import (C, cond_destroy, "cond_destroy");
375
376    function thr_setspecific
377      (key : thread_key_t; value : System.Address) return int;
378    pragma Import (C, thr_setspecific, "thr_setspecific");
379
380    function thr_getspecific
381      (key   : thread_key_t;
382       value : access System.Address) return int;
383    pragma Import (C, thr_getspecific, "thr_getspecific");
384
385    function thr_keycreate
386      (key : access thread_key_t; destructor : System.Address) return int;
387    pragma Import (C, thr_keycreate, "thr_keycreate");
388
389    function thr_setprio (thread : thread_t; priority : int) return int;
390    pragma Import (C, thr_setprio, "thr_setprio");
391
392    procedure thr_exit (status : System.Address);
393    pragma Import (C, thr_exit, "thr_exit");
394
395    function thr_setconcurrency (new_level : int) return int;
396    pragma Import (C, thr_setconcurrency, "thr_setconcurrency");
397
398    function sigwait (set : access sigset_t; sig : access Signal) return int;
399    pragma Import (C, sigwait, "__posix_sigwait");
400
401    function thr_kill (thread : thread_t; sig : Signal) return int;
402    pragma Import (C, thr_kill, "thr_kill");
403
404    function thr_sigsetmask
405      (how  : int;
406       set  : access sigset_t;
407       oset : access sigset_t) return int;
408    pragma Import (C, thr_sigsetmask, "thr_sigsetmask");
409
410    function pthread_sigmask
411      (how  : int;
412       set  : access sigset_t;
413       oset : access sigset_t) return int;
414    pragma Import (C, pthread_sigmask, "thr_sigsetmask");
415
416    function thr_suspend (target_thread : thread_t) return int;
417    pragma Import (C, thr_suspend, "thr_suspend");
418
419    function thr_continue (target_thread : thread_t) return int;
420    pragma Import (C, thr_continue, "thr_continue");
421
422    procedure thr_yield;
423    pragma Import (C, thr_yield, "thr_yield");
424
425    ---------
426    -- LWP --
427    ---------
428
429    P_PID   : constant := 0;
430    P_LWPID : constant := 8;
431
432    PC_GETCID    : constant := 0;
433    PC_GETCLINFO : constant := 1;
434    PC_SETPARMS  : constant := 2;
435    PC_GETPARMS  : constant := 3;
436    PC_ADMIN     : constant := 4;
437
438    PC_CLNULL : constant := -1;
439
440    RT_NOCHANGE : constant := -1;
441    RT_TQINF    : constant := -2;
442    RT_TQDEF    : constant := -3;
443
444    PC_CLNMSZ : constant := 16;
445
446    PC_VERSION : constant := 1;
447
448    type lwpid_t is new int;
449
450    type pri_t is new short;
451
452    type id_t is new long;
453
454    P_MYID : constant := -1;
455    --  The specified LWP or process is the current one
456
457    type struct_pcinfo is record
458       pc_cid    : id_t;
459       pc_clname : String (1 .. PC_CLNMSZ);
460       rt_maxpri : short;
461    end record;
462    pragma Convention (C, struct_pcinfo);
463
464    type struct_pcparms is record
465       pc_cid     : id_t;
466       rt_pri     : pri_t;
467       rt_tqsecs  : long;
468       rt_tqnsecs : long;
469    end record;
470    pragma Convention (C, struct_pcparms);
471
472    function priocntl
473      (ver     : int;
474       id_type : int;
475       id      : lwpid_t;
476       cmd     : int;
477       arg     : System.Address) return Interfaces.C.long;
478    pragma Import (C, priocntl, "__priocntl");
479
480    function lwp_self return lwpid_t;
481    pragma Import (C, lwp_self, "_lwp_self");
482
483    type processorid_t is new int;
484    type processorid_t_ptr is access all processorid_t;
485
486    --  Constants for function processor_bind
487
488    PBIND_QUERY : constant processorid_t := -2;
489    --  The processor bindings are not changed
490
491    PBIND_NONE  : constant processorid_t := -1;
492    --  The processor bindings of the specified LWPs are cleared
493
494    --  Flags for function p_online
495
496    PR_OFFLINE : constant int := 1;
497    --  Processor is offline, as quiet as possible
498
499    PR_ONLINE  : constant int := 2;
500    --  Processor online
501
502    PR_STATUS  : constant int := 3;
503    --  Value passed to p_online to request status
504
505    function p_online (processorid : processorid_t; flag : int) return int;
506    pragma Import (C, p_online, "p_online");
507
508    function processor_bind
509      (id_type : int;
510       id      : id_t;
511       proc_id : processorid_t;
512       obind   : processorid_t_ptr) return int;
513    pragma Import (C, processor_bind, "processor_bind");
514
515    procedure pthread_init;
516    --  Dummy procedure to share s-intman.adb with other Solaris targets
517
518 private
519
520    type array_type_1 is array (0 .. 3) of unsigned_long;
521    type sigset_t is record
522       X_X_sigbits : array_type_1;
523    end record;
524    pragma Convention (C, sigset_t);
525
526    type pid_t is new long;
527
528    type time_t is new long;
529
530    type timespec is record
531       tv_sec  : time_t;
532       tv_nsec : long;
533    end record;
534    pragma Convention (C, timespec);
535
536    type clockid_t is new int;
537    CLOCK_REALTIME : constant clockid_t := 0;
538
539    type struct_timeval is record
540       tv_sec  : long;
541       tv_usec : long;
542    end record;
543    pragma Convention (C, struct_timeval);
544
545    type array_type_9 is array (0 .. 3) of unsigned_char;
546    type record_type_3 is record
547       flag  : array_type_9;
548       Xtype : unsigned_long;
549    end record;
550    pragma Convention (C, record_type_3);
551
552    type mutex_t is record
553       flags : record_type_3;
554       lock  : String (1 .. 8);
555       data  : String (1 .. 8);
556    end record;
557    pragma Convention (C, mutex_t);
558
559    type cond_t is record
560       flag  : array_type_9;
561       Xtype : unsigned_long;
562       data  : String (1 .. 8);
563    end record;
564    pragma Convention (C, cond_t);
565
566    type thread_key_t is new unsigned;
567
568 end System.OS_Interface;