OSDN Git Service

PR 33870
[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
303    function Thread_Body_Access is new
304      Ada.Unchecked_Conversion (System.Address, Thread_Body);
305
306    THR_DETACHED  : constant := 64;
307    THR_BOUND     : constant := 1;
308    THR_NEW_LWP   : constant := 2;
309    USYNC_THREAD  : constant := 0;
310
311    type thread_t is new unsigned;
312    subtype Thread_Id is thread_t;
313    --  These types should be commented ???
314
315    function To_thread_t is new Ada.Unchecked_Conversion (Integer, thread_t);
316
317    type mutex_t is limited private;
318
319    type cond_t is limited private;
320
321    type thread_key_t is private;
322
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");
331
332    function thr_min_stack return size_t;
333    pragma Import (C, thr_min_stack, "thr_min_stack");
334
335    function thr_self return thread_t;
336    pragma Import (C, thr_self, "thr_self");
337
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");
343
344    function mutex_destroy (mutex : access mutex_t) return int;
345    pragma Import (C, mutex_destroy, "mutex_destroy");
346
347    function mutex_lock (mutex : access mutex_t) return int;
348    pragma Import (C, mutex_lock, "mutex_lock");
349
350    function mutex_unlock (mutex : access mutex_t) return int;
351    pragma Import (C, mutex_unlock, "mutex_unlock");
352
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");
358
359    function cond_wait
360      (cond : access cond_t; mutex : access mutex_t) return int;
361    pragma Import (C, cond_wait, "cond_wait");
362
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");
368
369    function cond_signal (cond : access cond_t) return int;
370    pragma Import (C, cond_signal, "cond_signal");
371
372    function cond_destroy (cond : access cond_t) return int;
373    pragma Import (C, cond_destroy, "cond_destroy");
374
375    function thr_setspecific
376      (key : thread_key_t; value : System.Address) return int;
377    pragma Import (C, thr_setspecific, "thr_setspecific");
378
379    function thr_getspecific
380      (key   : thread_key_t;
381       value : access System.Address) return int;
382    pragma Import (C, thr_getspecific, "thr_getspecific");
383
384    function thr_keycreate
385      (key : access thread_key_t; destructor : System.Address) return int;
386    pragma Import (C, thr_keycreate, "thr_keycreate");
387
388    function thr_setprio (thread : thread_t; priority : int) return int;
389    pragma Import (C, thr_setprio, "thr_setprio");
390
391    procedure thr_exit (status : System.Address);
392    pragma Import (C, thr_exit, "thr_exit");
393
394    function thr_setconcurrency (new_level : int) return int;
395    pragma Import (C, thr_setconcurrency, "thr_setconcurrency");
396
397    function sigwait (set : access sigset_t; sig : access Signal) return int;
398    pragma Import (C, sigwait, "__posix_sigwait");
399
400    function thr_kill (thread : thread_t; sig : Signal) return int;
401    pragma Import (C, thr_kill, "thr_kill");
402
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");
408
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");
414
415    function thr_suspend (target_thread : thread_t) return int;
416    pragma Import (C, thr_suspend, "thr_suspend");
417
418    function thr_continue (target_thread : thread_t) return int;
419    pragma Import (C, thr_continue, "thr_continue");
420
421    procedure thr_yield;
422    pragma Import (C, thr_yield, "thr_yield");
423
424    ---------
425    -- LWP --
426    ---------
427
428    P_PID   : constant := 0;
429    P_LWPID : constant := 8;
430
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;
436
437    PC_CLNULL : constant := -1;
438
439    RT_NOCHANGE : constant := -1;
440    RT_TQINF    : constant := -2;
441    RT_TQDEF    : constant := -3;
442
443    PC_CLNMSZ : constant := 16;
444
445    PC_VERSION : constant := 1;
446
447    type lwpid_t is new int;
448
449    type pri_t is new short;
450
451    type id_t is new long;
452
453    P_MYID : constant := -1;
454    --  The specified LWP or process is the current one
455
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);
462
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);
470
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");
478
479    function lwp_self return lwpid_t;
480    pragma Import (C, lwp_self, "_lwp_self");
481
482    type processorid_t is new int;
483    type processorid_t_ptr is access all processorid_t;
484
485    --  Constants for function processor_bind
486
487    PBIND_QUERY : constant processorid_t := -2;
488    --  The processor bindings are not changed
489
490    PBIND_NONE  : constant processorid_t := -1;
491    --  The processor bindings of the specified LWPs are cleared
492
493    --  Flags for function p_online
494
495    PR_OFFLINE : constant int := 1;
496    --  Processor is offline, as quiet as possible
497
498    PR_ONLINE  : constant int := 2;
499    --  Processor online
500
501    PR_STATUS  : constant int := 3;
502    --  Value passed to p_online to request status
503
504    function p_online (processorid : processorid_t; flag : int) return int;
505    pragma Import (C, p_online, "p_online");
506
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");
513
514    procedure pthread_init;
515    --  Dummy procedure to share s-intman.adb with other Solaris targets
516
517 private
518
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);
524
525    type pid_t is new long;
526
527    type time_t is new long;
528
529    type timespec is record
530       tv_sec  : time_t;
531       tv_nsec : long;
532    end record;
533    pragma Convention (C, timespec);
534
535    type clockid_t is new int;
536    CLOCK_REALTIME : constant clockid_t := 0;
537
538    type struct_timeval is record
539       tv_sec  : long;
540       tv_usec : long;
541    end record;
542    pragma Convention (C, struct_timeval);
543
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);
550
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);
557
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);
564
565    type thread_key_t is new unsigned;
566
567 end System.OS_Interface;