OSDN Git Service

* doc/install.texi (xtensa-*-elf): New target.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 54osinte.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                GNU ADA 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 --                             $Revision: 1.6 $
10 --                                                                          --
11 --            Copyright (C) 2000-2001 Ada Core Technologies, Inc.           --
12 --                                                                          --
13 -- GNARL is free software; you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com).                                  --
34 --                                                                          --
35 ------------------------------------------------------------------------------
36
37 --  This is a Solaris (POSIX Threads) version of this package.
38
39 --  This package encapsulates all direct interfaces to OS services
40 --  that are needed by children of System.
41
42 --  PLEASE DO NOT add any with-clauses to this package
43 --  or remove the pragma Elaborate_Body.
44 --  It is designed to be a bottom-level (leaf) package.
45
46 with Interfaces.C;
47 package System.OS_Interface is
48    pragma Preelaborate;
49
50    pragma Linker_Options ("-lposix4");
51    pragma Linker_Options ("-lpthread");
52
53    subtype int            is Interfaces.C.int;
54    subtype short          is Interfaces.C.short;
55    subtype long           is Interfaces.C.long;
56    subtype unsigned       is Interfaces.C.unsigned;
57    subtype unsigned_short is Interfaces.C.unsigned_short;
58    subtype unsigned_long  is Interfaces.C.unsigned_long;
59    subtype unsigned_char  is Interfaces.C.unsigned_char;
60    subtype plain_char     is Interfaces.C.plain_char;
61    subtype size_t         is Interfaces.C.size_t;
62
63    -----------
64    -- Errno --
65    -----------
66
67    function errno return int;
68    pragma Import (C, errno, "__get_errno");
69
70    EAGAIN    : constant := 11;
71    EINTR     : constant := 4;
72    EINVAL    : constant := 22;
73    ENOMEM    : constant := 12;
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    SIGADAABORT : constant := SIGABRT;
125
126    type Signal_Set is array (Natural range <>) of Signal;
127
128    Unmasked    : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
129
130    --  Following signals should not be disturbed.
131    --  See c-posix-signals.c in FLORIST
132
133    Reserved    : constant Signal_Set :=
134      (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL);
135
136    type sigset_t is private;
137
138    function sigaddset (set : access sigset_t; sig : Signal) return int;
139    pragma Import (C, sigaddset, "sigaddset");
140
141    function sigdelset (set : access sigset_t; sig : Signal) return int;
142    pragma Import (C, sigdelset, "sigdelset");
143
144    function sigfillset (set : access sigset_t) return int;
145    pragma Import (C, sigfillset, "sigfillset");
146
147    function sigismember (set : access sigset_t; sig : Signal) return int;
148    pragma Import (C, sigismember, "sigismember");
149
150    function sigemptyset (set : access sigset_t) return int;
151    pragma Import (C, sigemptyset, "sigemptyset");
152
153    type struct_sigaction is record
154       sa_flags   : int;
155       sa_handler : System.Address;
156       sa_mask    : sigset_t;
157       sa_resv1   : int;
158       sa_resv2   : int;
159    end record;
160    pragma Convention (C, struct_sigaction);
161    type struct_sigaction_ptr is access all struct_sigaction;
162
163    SIG_BLOCK   : constant := 1;
164    SIG_UNBLOCK : constant := 2;
165    SIG_SETMASK : constant := 3;
166
167    SIG_DFL : constant := 0;
168    SIG_IGN : constant := 1;
169
170    function sigaction
171      (sig  : Signal;
172       act  : struct_sigaction_ptr;
173       oact : struct_sigaction_ptr) return int;
174    pragma Import (C, sigaction, "sigaction");
175
176    ----------
177    -- Time --
178    ----------
179
180    Time_Slice_Supported : constant Boolean := True;
181    --  Indicates wether time slicing is supported
182
183    type timespec is private;
184
185    type clockid_t is private;
186
187    CLOCK_REALTIME : constant clockid_t;
188
189    function clock_gettime
190      (clock_id : clockid_t;
191       tp       : access timespec) return int;
192    pragma Import (C, clock_gettime, "clock_gettime");
193
194    function To_Duration (TS : timespec) return Duration;
195    pragma Inline (To_Duration);
196
197    function To_Timespec (D : Duration) return timespec;
198    pragma Inline (To_Timespec);
199
200    type struct_timeval is private;
201
202    function To_Duration (TV : struct_timeval) return Duration;
203    pragma Inline (To_Duration);
204
205    function To_Timeval (D : Duration) return struct_timeval;
206    pragma Inline (To_Timeval);
207
208    -------------------------
209    -- Priority Scheduling --
210    -------------------------
211
212    SCHED_FIFO  : constant := 1;
213    SCHED_RR    : constant := 2;
214    SCHED_OTHER : constant := 0;
215
216    -------------
217    -- Process --
218    -------------
219
220    type pid_t is private;
221
222    function kill (pid : pid_t; sig : Signal) return int;
223    pragma Import (C, kill, "kill");
224
225    function getpid return pid_t;
226    pragma Import (C, getpid, "getpid");
227
228    ---------
229    -- LWP --
230    ---------
231
232    function lwp_self return System.Address;
233    pragma Import (C, lwp_self, "_lwp_self");
234
235    -------------
236    -- Threads --
237    -------------
238
239    type Thread_Body is access
240      function (arg : System.Address) return System.Address;
241    type pthread_t           is private;
242    subtype Thread_Id        is pthread_t;
243
244    type pthread_mutex_t     is limited private;
245    type pthread_cond_t      is limited private;
246    type pthread_attr_t      is limited private;
247    type pthread_mutexattr_t is limited private;
248    type pthread_condattr_t  is limited private;
249    type pthread_key_t       is private;
250
251    PTHREAD_CREATE_DETACHED : constant := 16#40#;
252
253    -----------
254    -- Stack --
255    -----------
256
257    Stack_Base_Available : constant Boolean := False;
258    --  Indicates wether the stack base is available on this target.
259
260    function Get_Stack_Base (thread : pthread_t) return Address;
261    pragma Inline (Get_Stack_Base);
262    --  returns the stack base of the specified thread.
263    --  Only call this function when Stack_Base_Available is True.
264
265    function Get_Page_Size return size_t;
266    function Get_Page_Size return Address;
267    pragma Import (C, Get_Page_Size, "getpagesize");
268    --  returns the size of a page, or 0 if this is not relevant on this
269    --  target
270
271    PROT_NONE  : constant := 0;
272    PROT_READ  : constant := 1;
273    PROT_WRITE : constant := 2;
274    PROT_EXEC  : constant := 4;
275    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
276
277    PROT_ON    : constant := PROT_READ;
278    PROT_OFF   : constant := PROT_ALL;
279
280    function mprotect (addr : Address; len : size_t; prot : int) return int;
281    pragma Import (C, mprotect);
282
283    ---------------------------------------
284    -- Nonstandard Thread Initialization --
285    ---------------------------------------
286
287    procedure pthread_init;
288    --  This is a dummy procedure to share some GNULLI files
289
290    -------------------------
291    -- POSIX.1c  Section 3 --
292    -------------------------
293
294    function sigwait
295      (set : access sigset_t;
296       sig : access Signal) return int;
297    pragma Import (C, sigwait, "sigwait");
298
299    function pthread_kill
300      (thread : pthread_t;
301       sig    : Signal) return int;
302    pragma Import (C, pthread_kill, "pthread_kill");
303
304    type sigset_t_ptr is access all sigset_t;
305
306    function pthread_sigmask
307      (how  : int;
308       set  : sigset_t_ptr;
309       oset : sigset_t_ptr) return int;
310    pragma Import (C, pthread_sigmask, "pthread_sigmask");
311
312    --------------------------
313    -- POSIX.1c  Section 11 --
314    --------------------------
315
316    function pthread_mutexattr_init
317      (attr : access pthread_mutexattr_t) return int;
318    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
319
320    function pthread_mutexattr_destroy
321      (attr : access pthread_mutexattr_t) return int;
322    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
323
324    function pthread_mutex_init
325      (mutex : access pthread_mutex_t;
326       attr  : access pthread_mutexattr_t) return int;
327    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
328
329    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
330    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
331
332    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
333    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
334
335    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
336    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
337
338    function pthread_condattr_init
339      (attr : access pthread_condattr_t) return int;
340    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
341
342    function pthread_condattr_destroy
343      (attr : access pthread_condattr_t) return int;
344    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
345
346    function pthread_cond_init
347      (cond : access pthread_cond_t;
348       attr : access pthread_condattr_t) return int;
349    pragma Import (C, pthread_cond_init, "pthread_cond_init");
350
351    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
352    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
353
354    function pthread_cond_signal (cond : access pthread_cond_t) return int;
355    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
356
357    function pthread_cond_wait
358      (cond  : access pthread_cond_t;
359       mutex : access pthread_mutex_t) return int;
360    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
361
362    function pthread_cond_timedwait
363      (cond    : access pthread_cond_t;
364       mutex   : access pthread_mutex_t;
365       abstime : access timespec) return int;
366    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
367
368    Relative_Timed_Wait : constant Boolean := False;
369    --  pthread_cond_timedwait requires an absolute delay time
370
371    --------------------------
372    -- POSIX.1c  Section 13 --
373    --------------------------
374
375    PTHREAD_PRIO_NONE    : constant := 0;
376    PTHREAD_PRIO_INHERIT : constant := 16#10#;
377    PTHREAD_PRIO_PROTECT : constant := 16#20#;
378
379    function pthread_mutexattr_setprotocol
380      (attr     : access pthread_mutexattr_t;
381       protocol : int) return int;
382    pragma Import (C, pthread_mutexattr_setprotocol);
383
384    function pthread_mutexattr_setprioceiling
385      (attr        : access pthread_mutexattr_t;
386       prioceiling : int) return int;
387    pragma Import (C, pthread_mutexattr_setprioceiling);
388
389    type Array_8_Int is array (0 .. 7) of int;
390    type struct_sched_param is record
391       sched_priority : int;
392       sched_pad      : Array_8_Int;
393    end record;
394
395    function pthread_setschedparam
396      (thread : pthread_t;
397       policy : int;
398       param  : access struct_sched_param) return int;
399    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
400
401    function pthread_attr_setscope
402      (attr            : access pthread_attr_t;
403       contentionscope : int) return int;
404    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
405
406    function pthread_attr_setinheritsched
407      (attr         : access pthread_attr_t;
408       inheritsched : int) return int;
409    pragma Import (C, pthread_attr_setinheritsched);
410
411    function pthread_attr_setschedpolicy
412      (attr   : access pthread_attr_t;
413       policy : int) return int;
414    pragma Import (C, pthread_attr_setschedpolicy);
415
416    function sched_yield return int;
417    pragma Import (C, sched_yield, "sched_yield");
418
419    ---------------------------
420    -- P1003.1c - Section 16 --
421    ---------------------------
422
423    function pthread_attr_init (attributes : access pthread_attr_t) return int;
424    pragma Import (C, pthread_attr_init, "pthread_attr_init");
425
426    function pthread_attr_destroy
427      (attributes : access pthread_attr_t) return int;
428    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
429
430    function pthread_attr_setdetachstate
431      (attr        : access pthread_attr_t;
432       detachstate : int) return int;
433    pragma Import (C, pthread_attr_setdetachstate);
434
435    function pthread_attr_setstacksize
436      (attr      : access pthread_attr_t;
437       stacksize : size_t) return int;
438    pragma Import (C, pthread_attr_setstacksize);
439
440    function pthread_create
441      (thread        : access pthread_t;
442       attributes    : access pthread_attr_t;
443       start_routine : Thread_Body;
444       arg           : System.Address) return int;
445    pragma Import (C, pthread_create, "pthread_create");
446
447    procedure pthread_exit (status : System.Address);
448    pragma Import (C, pthread_exit, "pthread_exit");
449
450    function pthread_self return pthread_t;
451    pragma Import (C, pthread_self, "pthread_self");
452
453    --------------------------
454    -- POSIX.1c  Section 17 --
455    --------------------------
456
457    function pthread_setspecific
458      (key   : pthread_key_t;
459       value : System.Address) return int;
460    pragma Import (C, pthread_setspecific, "pthread_setspecific");
461
462    function pthread_getspecific (key : pthread_key_t) return System.Address;
463    pragma Import (C, pthread_getspecific, "pthread_getspecific");
464
465    type destructor_pointer is access procedure (arg : System.Address);
466
467    function pthread_key_create
468      (key        : access pthread_key_t;
469       destructor : destructor_pointer) return int;
470    pragma Import (C, pthread_key_create, "pthread_key_create");
471
472 private
473
474    type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
475    type sigset_t is record
476       X_X_sigbits  : array_type_1;
477    end record;
478    pragma Convention (C, sigset_t);
479
480    type pid_t is new long;
481
482    type time_t is new long;
483
484    type timespec is record
485       tv_sec  : time_t;
486       tv_nsec : long;
487    end record;
488    pragma Convention (C, timespec);
489
490    type clockid_t is new int;
491    CLOCK_REALTIME : constant clockid_t := 0;
492
493    type struct_timeval is record
494       tv_sec  : time_t;
495       tv_usec : time_t;
496    end record;
497    pragma Convention (C, struct_timeval);
498
499    type pthread_attr_t is record
500       pthread_attrp : System.Address;
501    end record;
502    pragma Convention (C, pthread_attr_t);
503
504    type pthread_condattr_t is record
505       pthread_condattrp : System.Address;
506    end record;
507    pragma Convention (C, pthread_condattr_t);
508
509    type pthread_mutexattr_t is record
510       pthread_mutexattrp : System.Address;
511    end record;
512    pragma Convention (C, pthread_mutexattr_t);
513
514    type pthread_t is new unsigned;
515
516    type uint64_t is mod 2 ** 64;
517
518    type pthread_mutex_t is record
519       pthread_mutex_flags   : uint64_t;
520       pthread_mutex_owner64 : uint64_t;
521       pthread_mutex_data    : uint64_t;
522    end record;
523    pragma Convention (C, pthread_mutex_t);
524    type pthread_mutex_t_ptr is access pthread_mutex_t;
525
526    type pthread_cond_t is record
527       pthread_cond_flags : uint64_t;
528       pthread_cond_data  : uint64_t;
529    end record;
530    pragma Convention (C, pthread_cond_t);
531
532    type pthread_key_t is new unsigned;
533
534 end System.OS_Interface;