OSDN Git Service

2007-01-26 Andrew Haley <aph@redhat.com>
[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-2006, 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 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      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    -----------
267    -- Stack --
268    -----------
269
270    Stack_Base_Available : constant Boolean := False;
271    --  Indicates whether the stack base is available on this target.
272
273    function Get_Stack_Base (thread : pthread_t) return Address;
274    pragma Inline (Get_Stack_Base);
275    --  returns the stack base of the specified thread.
276    --  Only call this function when Stack_Base_Available is True.
277
278    function Get_Page_Size return size_t;
279    function Get_Page_Size return Address;
280    pragma Import (C, Get_Page_Size, "getpagesize");
281    --  returns the size of a page, or 0 if this is not relevant on this
282    --  target
283
284    PROT_NONE  : constant := 0;
285    PROT_READ  : constant := 1;
286    PROT_WRITE : constant := 2;
287    PROT_EXEC  : constant := 4;
288    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
289
290    PROT_ON    : constant := PROT_READ;
291    PROT_OFF   : constant := PROT_ALL;
292
293    function mprotect (addr : Address; len : size_t; prot : int) return int;
294    pragma Import (C, mprotect);
295
296    ---------------------------------------
297    -- Nonstandard Thread Initialization --
298    ---------------------------------------
299
300    procedure pthread_init;
301    --  This is a dummy procedure to share some GNULLI files
302
303    -------------------------
304    -- POSIX.1c  Section 3 --
305    -------------------------
306
307    function sigwait
308      (set : access sigset_t;
309       sig : access Signal) return int;
310    pragma Import (C, sigwait, "__posix_sigwait");
311
312    function pthread_kill
313      (thread : pthread_t;
314       sig    : Signal) return int;
315    pragma Import (C, pthread_kill, "pthread_kill");
316
317    function pthread_sigmask
318      (how  : int;
319       set  : access sigset_t;
320       oset : access sigset_t) return int;
321    pragma Import (C, pthread_sigmask, "pthread_sigmask");
322
323    --------------------------
324    -- POSIX.1c  Section 11 --
325    --------------------------
326
327    function pthread_mutexattr_init
328      (attr : access pthread_mutexattr_t) return int;
329    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
330
331    function pthread_mutexattr_destroy
332      (attr : access pthread_mutexattr_t) return int;
333    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
334
335    function pthread_mutex_init
336      (mutex : access pthread_mutex_t;
337       attr  : access pthread_mutexattr_t) return int;
338    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
339
340    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
341    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
342
343    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
344    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
345
346    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
347    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
348
349    function pthread_condattr_init
350      (attr : access pthread_condattr_t) return int;
351    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
352
353    function pthread_condattr_destroy
354      (attr : access pthread_condattr_t) return int;
355    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
356
357    function pthread_cond_init
358      (cond : access pthread_cond_t;
359       attr : access pthread_condattr_t) return int;
360    pragma Import (C, pthread_cond_init, "pthread_cond_init");
361
362    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
363    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
364
365    function pthread_cond_signal (cond : access pthread_cond_t) return int;
366    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
367
368    function pthread_cond_wait
369      (cond  : access pthread_cond_t;
370       mutex : access pthread_mutex_t) return int;
371    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
372
373    function pthread_cond_timedwait
374      (cond    : access pthread_cond_t;
375       mutex   : access pthread_mutex_t;
376       abstime : access timespec) return int;
377    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
378
379    Relative_Timed_Wait : constant Boolean := False;
380    --  pthread_cond_timedwait requires an absolute delay time
381
382    --------------------------
383    -- POSIX.1c  Section 13 --
384    --------------------------
385
386    PTHREAD_PRIO_NONE    : constant := 0;
387    PTHREAD_PRIO_INHERIT : constant := 16#10#;
388    PTHREAD_PRIO_PROTECT : constant := 16#20#;
389
390    function pthread_mutexattr_setprotocol
391      (attr     : access pthread_mutexattr_t;
392       protocol : int) return int;
393    pragma Import (C, pthread_mutexattr_setprotocol);
394
395    function pthread_mutexattr_setprioceiling
396      (attr        : access pthread_mutexattr_t;
397       prioceiling : int) return int;
398    pragma Import (C, pthread_mutexattr_setprioceiling);
399
400    type Array_8_Int is array (0 .. 7) of int;
401    type struct_sched_param is record
402       sched_priority : int;
403       sched_pad      : Array_8_Int;
404    end record;
405
406    function pthread_setschedparam
407      (thread : pthread_t;
408       policy : int;
409       param  : access struct_sched_param) return int;
410    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
411
412    function pthread_attr_setscope
413      (attr            : access pthread_attr_t;
414       contentionscope : int) return int;
415    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
416
417    function pthread_attr_setinheritsched
418      (attr         : access pthread_attr_t;
419       inheritsched : int) return int;
420    pragma Import (C, pthread_attr_setinheritsched);
421
422    function pthread_attr_setschedpolicy
423      (attr   : access pthread_attr_t;
424       policy : int) return int;
425    pragma Import (C, pthread_attr_setschedpolicy);
426
427    function sched_yield return int;
428    pragma Import (C, sched_yield, "sched_yield");
429
430    ---------------------------
431    -- P1003.1c - Section 16 --
432    ---------------------------
433
434    function pthread_attr_init (attributes : access pthread_attr_t) return int;
435    pragma Import (C, pthread_attr_init, "pthread_attr_init");
436
437    function pthread_attr_destroy
438      (attributes : access pthread_attr_t) return int;
439    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
440
441    function pthread_attr_setdetachstate
442      (attr        : access pthread_attr_t;
443       detachstate : int) return int;
444    pragma Import (C, pthread_attr_setdetachstate);
445
446    function pthread_attr_setstacksize
447      (attr      : access pthread_attr_t;
448       stacksize : size_t) return int;
449    pragma Import (C, pthread_attr_setstacksize);
450
451    function pthread_create
452      (thread        : access pthread_t;
453       attributes    : access pthread_attr_t;
454       start_routine : Thread_Body;
455       arg           : System.Address) return int;
456    pragma Import (C, pthread_create, "pthread_create");
457
458    procedure pthread_exit (status : System.Address);
459    pragma Import (C, pthread_exit, "pthread_exit");
460
461    function pthread_self return pthread_t;
462    pragma Import (C, pthread_self, "pthread_self");
463
464    --------------------------
465    -- POSIX.1c  Section 17 --
466    --------------------------
467
468    function pthread_setspecific
469      (key   : pthread_key_t;
470       value : System.Address) return int;
471    pragma Import (C, pthread_setspecific, "pthread_setspecific");
472
473    function pthread_getspecific (key : pthread_key_t) return System.Address;
474    pragma Import (C, pthread_getspecific, "pthread_getspecific");
475
476    type destructor_pointer is access procedure (arg : System.Address);
477
478    function pthread_key_create
479      (key        : access pthread_key_t;
480       destructor : destructor_pointer) return int;
481    pragma Import (C, pthread_key_create, "pthread_key_create");
482
483 private
484
485    type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
486    type sigset_t is record
487       X_X_sigbits  : array_type_1;
488    end record;
489    pragma Convention (C, sigset_t);
490
491    type pid_t is new long;
492
493    type time_t is new long;
494
495    type timespec is record
496       tv_sec  : time_t;
497       tv_nsec : long;
498    end record;
499    pragma Convention (C, timespec);
500
501    type clockid_t is new int;
502    CLOCK_REALTIME : constant clockid_t := 0;
503
504    type struct_timeval is record
505       tv_sec  : time_t;
506       tv_usec : time_t;
507    end record;
508    pragma Convention (C, struct_timeval);
509
510    type pthread_attr_t is record
511       pthread_attrp : System.Address;
512    end record;
513    pragma Convention (C, pthread_attr_t);
514
515    type pthread_condattr_t is record
516       pthread_condattrp : System.Address;
517    end record;
518    pragma Convention (C, pthread_condattr_t);
519
520    type pthread_mutexattr_t is record
521       pthread_mutexattrp : System.Address;
522    end record;
523    pragma Convention (C, pthread_mutexattr_t);
524
525    type pthread_t is new unsigned;
526
527    type uint64_t is mod 2 ** 64;
528
529    type pthread_mutex_t is record
530       pthread_mutex_flags   : uint64_t;
531       pthread_mutex_owner64 : uint64_t;
532       pthread_mutex_data    : uint64_t;
533    end record;
534    pragma Convention (C, pthread_mutex_t);
535    type pthread_mutex_t_ptr is access pthread_mutex_t;
536
537    type pthread_cond_t is record
538       pthread_cond_flags : uint64_t;
539       pthread_cond_data  : uint64_t;
540    end record;
541    pragma Convention (C, pthread_cond_t);
542
543    type pthread_key_t is new unsigned;
544
545 end System.OS_Interface;