OSDN Git Service

* Makefile.in (reload1.o-warn): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-solaris-posix.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 (POSIX Threads) version of this package
36
37 --  This package encapsulates 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 ("-lpthread");
51
52    --  The following is needed to allow --enable-threads=solaris
53
54    pragma Linker_Options ("-lthread");
55
56    subtype int            is Interfaces.C.int;
57    subtype short          is Interfaces.C.short;
58    subtype long           is Interfaces.C.long;
59    subtype unsigned       is Interfaces.C.unsigned;
60    subtype unsigned_short is Interfaces.C.unsigned_short;
61    subtype unsigned_long  is Interfaces.C.unsigned_long;
62    subtype unsigned_char  is Interfaces.C.unsigned_char;
63    subtype plain_char     is Interfaces.C.plain_char;
64    subtype size_t         is Interfaces.C.size_t;
65
66    -----------
67    -- Errno --
68    -----------
69
70    function errno return int;
71    pragma Import (C, errno, "__get_errno");
72
73    EAGAIN    : constant := 11;
74    EINTR     : constant := 4;
75    EINVAL    : constant := 22;
76    ENOMEM    : constant := 12;
77    ETIMEDOUT : constant := 145;
78
79    -------------
80    -- Signals --
81    -------------
82
83    Max_Interrupt : constant := 45;
84    type Signal is new int range 0 .. Max_Interrupt;
85    for Signal'Size use int'Size;
86
87    SIGHUP      : constant := 1; --  hangup
88    SIGINT      : constant := 2; --  interrupt (rubout)
89    SIGQUIT     : constant := 3; --  quit (ASCD FS)
90    SIGILL      : constant := 4; --  illegal instruction (not reset)
91    SIGTRAP     : constant := 5; --  trace trap (not reset)
92    SIGIOT      : constant := 6; --  IOT instruction
93    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
94    SIGEMT      : constant := 7; --  EMT instruction
95    SIGFPE      : constant := 8; --  floating point exception
96    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
97    SIGBUS      : constant := 10; --  bus error
98    SIGSEGV     : constant := 11; --  segmentation violation
99    SIGSYS      : constant := 12; --  bad argument to system call
100    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
101    SIGALRM     : constant := 14; --  alarm clock
102    SIGTERM     : constant := 15; --  software termination signal from kill
103    SIGUSR1     : constant := 16; --  user defined signal 1
104    SIGUSR2     : constant := 17; --  user defined signal 2
105    SIGCLD      : constant := 18; --  alias for SIGCHLD
106    SIGCHLD     : constant := 18; --  child status change
107    SIGPWR      : constant := 19; --  power-fail restart
108    SIGWINCH    : constant := 20; --  window size change
109    SIGURG      : constant := 21; --  urgent condition on IO channel
110    SIGPOLL     : constant := 22; --  pollable event occurred
111    SIGIO       : constant := 22; --  I/O possible (Solaris SIGPOLL alias)
112    SIGSTOP     : constant := 23; --  stop (cannot be caught or ignored)
113    SIGTSTP     : constant := 24; --  user stop requested from tty
114    SIGCONT     : constant := 25; --  stopped process has been continued
115    SIGTTIN     : constant := 26; --  background tty read attempted
116    SIGTTOU     : constant := 27; --  background tty write attempted
117    SIGVTALRM   : constant := 28; --  virtual timer expired
118    SIGPROF     : constant := 29; --  profiling timer expired
119    SIGXCPU     : constant := 30; --  CPU time limit exceeded
120    SIGXFSZ     : constant := 31; --  filesize limit exceeded
121    SIGWAITING  : constant := 32; --  process's lwps blocked (Solaris)
122    SIGLWP      : constant := 33; --  used by thread library (Solaris)
123    SIGFREEZE   : constant := 34; --  used by CPR (Solaris)
124    SIGTHAW     : constant := 35; --  used by CPR (Solaris)
125    SIGCANCEL   : constant := 36; --  thread cancellation signal (libthread)
126
127    SIGADAABORT : constant := SIGABRT;
128
129    type Signal_Set is array (Natural range <>) of Signal;
130
131    Unmasked    : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
132
133    --  Following signals should not be disturbed.
134    --  See c-posix-signals.c in FLORIST
135
136    Reserved    : constant Signal_Set :=
137      (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL);
138
139    type sigset_t is private;
140
141    function sigaddset (set : access sigset_t; sig : Signal) return int;
142    pragma Import (C, sigaddset, "sigaddset");
143
144    function sigdelset (set : access sigset_t; sig : Signal) return int;
145    pragma Import (C, sigdelset, "sigdelset");
146
147    function sigfillset (set : access sigset_t) return int;
148    pragma Import (C, sigfillset, "sigfillset");
149
150    function sigismember (set : access sigset_t; sig : Signal) return int;
151    pragma Import (C, sigismember, "sigismember");
152
153    function sigemptyset (set : access sigset_t) return int;
154    pragma Import (C, sigemptyset, "sigemptyset");
155
156    type struct_sigaction is record
157       sa_flags   : int;
158       sa_handler : System.Address;
159       sa_mask    : sigset_t;
160       sa_resv1   : int;
161       sa_resv2   : int;
162    end record;
163    pragma Convention (C, struct_sigaction);
164    type struct_sigaction_ptr is access all struct_sigaction;
165
166    SA_SIGINFO : constant := 16#0008#;
167
168    SIG_BLOCK   : constant := 1;
169    SIG_UNBLOCK : constant := 2;
170    SIG_SETMASK : constant := 3;
171
172    SIG_DFL : constant := 0;
173    SIG_IGN : constant := 1;
174
175    function sigaction
176      (sig  : Signal;
177       act  : struct_sigaction_ptr;
178       oact : struct_sigaction_ptr) return int;
179    pragma Import (C, sigaction, "sigaction");
180
181    ----------
182    -- Time --
183    ----------
184
185    Time_Slice_Supported : constant Boolean := True;
186    --  Indicates wether time slicing is supported
187
188    type timespec is private;
189
190    type clockid_t is private;
191
192    CLOCK_REALTIME : constant clockid_t;
193
194    function clock_gettime
195      (clock_id : clockid_t;
196       tp       : access timespec) return int;
197    pragma Import (C, clock_gettime, "clock_gettime");
198
199    function To_Duration (TS : timespec) return Duration;
200    pragma Inline (To_Duration);
201
202    function To_Timespec (D : Duration) return timespec;
203    pragma Inline (To_Timespec);
204
205    type struct_timeval is private;
206
207    function To_Duration (TV : struct_timeval) return Duration;
208    pragma Inline (To_Duration);
209
210    function To_Timeval (D : Duration) return struct_timeval;
211    pragma Inline (To_Timeval);
212
213    -------------------------
214    -- Priority Scheduling --
215    -------------------------
216
217    SCHED_FIFO  : constant := 1;
218    SCHED_RR    : constant := 2;
219    SCHED_OTHER : constant := 0;
220
221    function To_Target_Priority
222      (Prio : System.Any_Priority) return Interfaces.C.int;
223    --  Maps System.Any_Priority to a POSIX priority.
224
225    -------------
226    -- Process --
227    -------------
228
229    type pid_t is private;
230
231    function kill (pid : pid_t; sig : Signal) return int;
232    pragma Import (C, kill, "kill");
233
234    function getpid return pid_t;
235    pragma Import (C, getpid, "getpid");
236
237    ---------
238    -- LWP --
239    ---------
240
241    function lwp_self return System.Address;
242    pragma Import (C, lwp_self, "_lwp_self");
243
244    -------------
245    -- Threads --
246    -------------
247
248    type Thread_Body is access
249      function (arg : System.Address) return System.Address;
250
251    function Thread_Body_Access is new
252      Ada.Unchecked_Conversion (System.Address, Thread_Body);
253
254    type pthread_t           is private;
255    subtype Thread_Id        is pthread_t;
256
257    type pthread_mutex_t     is limited private;
258    type pthread_cond_t      is limited private;
259    type pthread_attr_t      is limited private;
260    type pthread_mutexattr_t is limited private;
261    type pthread_condattr_t  is limited private;
262    type pthread_key_t       is private;
263
264    PTHREAD_CREATE_DETACHED : constant := 16#40#;
265
266    PTHREAD_SCOPE_PROCESS : constant := 0;
267    PTHREAD_SCOPE_SYSTEM  : constant := 1;
268
269    -----------
270    -- Stack --
271    -----------
272
273    Stack_Base_Available : constant Boolean := False;
274    --  Indicates whether the stack base is available on this target.
275
276    function Get_Stack_Base (thread : pthread_t) return Address;
277    pragma Inline (Get_Stack_Base);
278    --  returns the stack base of the specified thread.
279    --  Only call this function when Stack_Base_Available is True.
280
281    function Get_Page_Size return size_t;
282    function Get_Page_Size return Address;
283    pragma Import (C, Get_Page_Size, "getpagesize");
284    --  returns the size of a page, or 0 if this is not relevant on this
285    --  target
286
287    PROT_NONE  : constant := 0;
288    PROT_READ  : constant := 1;
289    PROT_WRITE : constant := 2;
290    PROT_EXEC  : constant := 4;
291    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
292
293    PROT_ON    : constant := PROT_READ;
294    PROT_OFF   : constant := PROT_ALL;
295
296    function mprotect (addr : Address; len : size_t; prot : int) return int;
297    pragma Import (C, mprotect);
298
299    ---------------------------------------
300    -- Nonstandard Thread Initialization --
301    ---------------------------------------
302
303    procedure pthread_init;
304    --  This is a dummy procedure to share some GNULLI files
305
306    -------------------------
307    -- POSIX.1c  Section 3 --
308    -------------------------
309
310    function sigwait
311      (set : access sigset_t;
312       sig : access Signal) return int;
313    pragma Import (C, sigwait, "__posix_sigwait");
314
315    function pthread_kill
316      (thread : pthread_t;
317       sig    : Signal) return int;
318    pragma Import (C, pthread_kill, "pthread_kill");
319
320    function pthread_sigmask
321      (how  : int;
322       set  : access sigset_t;
323       oset : access sigset_t) return int;
324    pragma Import (C, pthread_sigmask, "pthread_sigmask");
325
326    --------------------------
327    -- POSIX.1c  Section 11 --
328    --------------------------
329
330    function pthread_mutexattr_init
331      (attr : access pthread_mutexattr_t) return int;
332    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
333
334    function pthread_mutexattr_destroy
335      (attr : access pthread_mutexattr_t) return int;
336    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
337
338    function pthread_mutex_init
339      (mutex : access pthread_mutex_t;
340       attr  : access pthread_mutexattr_t) return int;
341    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
342
343    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
344    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
345
346    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
347    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
348
349    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
350    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
351
352    function pthread_condattr_init
353      (attr : access pthread_condattr_t) return int;
354    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
355
356    function pthread_condattr_destroy
357      (attr : access pthread_condattr_t) return int;
358    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
359
360    function pthread_cond_init
361      (cond : access pthread_cond_t;
362       attr : access pthread_condattr_t) return int;
363    pragma Import (C, pthread_cond_init, "pthread_cond_init");
364
365    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
366    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
367
368    function pthread_cond_signal (cond : access pthread_cond_t) return int;
369    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
370
371    function pthread_cond_wait
372      (cond  : access pthread_cond_t;
373       mutex : access pthread_mutex_t) return int;
374    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
375
376    function pthread_cond_timedwait
377      (cond    : access pthread_cond_t;
378       mutex   : access pthread_mutex_t;
379       abstime : access timespec) return int;
380    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
381
382    Relative_Timed_Wait : constant Boolean := False;
383    --  pthread_cond_timedwait requires an absolute delay time
384
385    --------------------------
386    -- POSIX.1c  Section 13 --
387    --------------------------
388
389    PTHREAD_PRIO_NONE    : constant := 0;
390    PTHREAD_PRIO_INHERIT : constant := 16#10#;
391    PTHREAD_PRIO_PROTECT : constant := 16#20#;
392
393    function pthread_mutexattr_setprotocol
394      (attr     : access pthread_mutexattr_t;
395       protocol : int) return int;
396    pragma Import (C, pthread_mutexattr_setprotocol);
397
398    function pthread_mutexattr_setprioceiling
399      (attr        : access pthread_mutexattr_t;
400       prioceiling : int) return int;
401    pragma Import (C, pthread_mutexattr_setprioceiling);
402
403    type Array_8_Int is array (0 .. 7) of int;
404    type struct_sched_param is record
405       sched_priority : int;
406       sched_pad      : Array_8_Int;
407    end record;
408
409    function pthread_setschedparam
410      (thread : pthread_t;
411       policy : int;
412       param  : access struct_sched_param) return int;
413    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
414
415    function pthread_attr_setscope
416      (attr            : access pthread_attr_t;
417       contentionscope : int) return int;
418    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
419
420    function pthread_attr_setinheritsched
421      (attr         : access pthread_attr_t;
422       inheritsched : int) return int;
423    pragma Import (C, pthread_attr_setinheritsched);
424
425    function pthread_attr_setschedpolicy
426      (attr   : access pthread_attr_t;
427       policy : int) return int;
428    pragma Import (C, pthread_attr_setschedpolicy);
429
430    function sched_yield return int;
431    pragma Import (C, sched_yield, "sched_yield");
432
433    ---------------------------
434    -- P1003.1c - Section 16 --
435    ---------------------------
436
437    function pthread_attr_init (attributes : access pthread_attr_t) return int;
438    pragma Import (C, pthread_attr_init, "pthread_attr_init");
439
440    function pthread_attr_destroy
441      (attributes : access pthread_attr_t) return int;
442    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
443
444    function pthread_attr_setdetachstate
445      (attr        : access pthread_attr_t;
446       detachstate : int) return int;
447    pragma Import (C, pthread_attr_setdetachstate);
448
449    function pthread_attr_setstacksize
450      (attr      : access pthread_attr_t;
451       stacksize : size_t) return int;
452    pragma Import (C, pthread_attr_setstacksize);
453
454    function pthread_create
455      (thread        : access pthread_t;
456       attributes    : access pthread_attr_t;
457       start_routine : Thread_Body;
458       arg           : System.Address) return int;
459    pragma Import (C, pthread_create, "pthread_create");
460
461    procedure pthread_exit (status : System.Address);
462    pragma Import (C, pthread_exit, "pthread_exit");
463
464    function pthread_self return pthread_t;
465    pragma Import (C, pthread_self, "pthread_self");
466
467    --------------------------
468    -- POSIX.1c  Section 17 --
469    --------------------------
470
471    function pthread_setspecific
472      (key   : pthread_key_t;
473       value : System.Address) return int;
474    pragma Import (C, pthread_setspecific, "pthread_setspecific");
475
476    function pthread_getspecific (key : pthread_key_t) return System.Address;
477    pragma Import (C, pthread_getspecific, "pthread_getspecific");
478
479    type destructor_pointer is access procedure (arg : System.Address);
480
481    function pthread_key_create
482      (key        : access pthread_key_t;
483       destructor : destructor_pointer) return int;
484    pragma Import (C, pthread_key_create, "pthread_key_create");
485
486 private
487
488    type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
489    type sigset_t is record
490       X_X_sigbits  : array_type_1;
491    end record;
492    pragma Convention (C, sigset_t);
493
494    type pid_t is new long;
495
496    type time_t is new long;
497
498    type timespec is record
499       tv_sec  : time_t;
500       tv_nsec : long;
501    end record;
502    pragma Convention (C, timespec);
503
504    type clockid_t is new int;
505    CLOCK_REALTIME : constant clockid_t := 0;
506
507    type struct_timeval is record
508       tv_sec  : time_t;
509       tv_usec : time_t;
510    end record;
511    pragma Convention (C, struct_timeval);
512
513    type pthread_attr_t is record
514       pthread_attrp : System.Address;
515    end record;
516    pragma Convention (C, pthread_attr_t);
517
518    type pthread_condattr_t is record
519       pthread_condattrp : System.Address;
520    end record;
521    pragma Convention (C, pthread_condattr_t);
522
523    type pthread_mutexattr_t is record
524       pthread_mutexattrp : System.Address;
525    end record;
526    pragma Convention (C, pthread_mutexattr_t);
527
528    type pthread_t is new unsigned;
529
530    type uint64_t is mod 2 ** 64;
531
532    type pthread_mutex_t is record
533       pthread_mutex_flags   : uint64_t;
534       pthread_mutex_owner64 : uint64_t;
535       pthread_mutex_data    : uint64_t;
536    end record;
537    pragma Convention (C, pthread_mutex_t);
538    type pthread_mutex_t_ptr is access pthread_mutex_t;
539
540    type pthread_cond_t is record
541       pthread_cond_flags : uint64_t;
542       pthread_cond_data  : uint64_t;
543    end record;
544    pragma Convention (C, pthread_cond_t);
545
546    type pthread_key_t is new unsigned;
547
548 end System.OS_Interface;