OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 52osinte.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 --                                                                          --
10 --          Copyright (C) 1999-2001 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,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, 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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com).                                  --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 --  This is a LynxOS (Native) version of this package.
37
38 --  This package encapsulates all direct interfaces to OS services
39 --  that are needed by children of System.
40
41 --  PLEASE DO NOT add any with-clauses to this package
42 --  or remove the pragma Elaborate_Body.
43 --  It is designed to be a bottom-level (leaf) package.
44
45 with Interfaces.C;
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-mthreads");
50
51    subtype int            is Interfaces.C.int;
52    subtype char           is Interfaces.C.char;
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    ETIMEDOUT : constant := 60;
74
75    -------------
76    -- Signals --
77    -------------
78
79    Max_Interrupt : constant := 63;
80    type Signal is new int range 0 .. Max_Interrupt;
81    for Signal'Size use int'Size;
82
83    SIGHUP      : constant := 1; --  hangup
84    SIGINT      : constant := 2; --  interrupt (rubout)
85    SIGQUIT     : constant := 3; --  quit (ASCD FS)
86    SIGILL      : constant := 4; --  illegal instruction (not reset)
87    SIGTRAP     : constant := 5; --  trace trap (not reset)
88    SIGBRK      : constant := 6; --  break
89    SIGIOT      : constant := 6; --  IOT instruction
90    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
91    SIGCORE     : constant := 7; --  kill with core dump
92    SIGEMT      : constant := 7; --  EMT instruction
93    SIGFPE      : constant := 8; --  floating point exception
94    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
95    SIGBUS      : constant := 10; --  bus error
96    SIGSEGV     : constant := 11; --  segmentation violation
97    SIGSYS      : constant := 12; --  bad argument to system call
98    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
99    SIGALRM     : constant := 14; --  alarm clock
100    SIGTERM     : constant := 15; --  software termination signal from kill
101    SIGURG      : constant := 16; --  urgent condition on IO channel
102    SIGSTOP     : constant := 17; --  stop (cannot be caught or ignored)
103    SIGTSTP     : constant := 18; --  user stop requested from tty
104    SIGCONT     : constant := 19; --  stopped process has been continued
105    SIGCLD      : constant := 20; --  alias for SIGCHLD
106    SIGCHLD     : constant := 20; --  child status change
107    SIGTTIN     : constant := 21; --  background tty read attempted
108    SIGTTOU     : constant := 22; --  background tty write attempted
109    SIGIO       : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
110    SIGPOLL     : constant := 23; --  pollable event occurred
111    SIGXCPU     : constant := 24; --  CPU time limit exceeded
112    SIGXFSZ     : constant := 25; --  filesize limit exceeded
113    SIGVTALRM   : constant := 26; --  virtual timer expired
114    SIGPROF     : constant := 27; --  profiling timer expired
115    SIGWINCH    : constant := 28; --  window size change
116    SIGLOST     : constant := 29; --  SUN 4.1 compatibility
117    SIGUSR1     : constant := 30; --  user defined signal 1
118    SIGUSR2     : constant := 31; --  user defined signal 2
119    SIGPRIO     : constant := 32; --  sent to a process with its priority or
120                                  --  group is changed
121
122    SIGADAABORT : constant := SIGABRT;
123    --  Change this if you want to use another signal for task abort.
124    --  SIGTERM might be a good one.
125
126    type Signal_Set is array (Natural range <>) of Signal;
127
128    Unmasked    : constant Signal_Set :=
129      (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
130    Reserved    : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP, SIGPRIO);
131
132    type sigset_t is private;
133
134    function sigaddset (set : access sigset_t; sig : Signal) return int;
135    pragma Import (C, sigaddset, "sigaddset");
136
137    function sigdelset (set : access sigset_t; sig : Signal) return int;
138    pragma Import (C, sigdelset, "sigdelset");
139
140    function sigfillset (set : access sigset_t) return int;
141    pragma Import (C, sigfillset, "sigfillset");
142
143    function sigismember (set : access sigset_t; sig : Signal) return int;
144    pragma Import (C, sigismember, "sigismember");
145
146    function sigemptyset (set : access sigset_t) return int;
147    pragma Import (C, sigemptyset, "sigemptyset");
148
149    type struct_sigaction is record
150       sa_handler : System.Address;
151       sa_mask    : sigset_t;
152       sa_flags   : int;
153    end record;
154    pragma Convention (C, struct_sigaction);
155    type struct_sigaction_ptr is access all struct_sigaction;
156
157    SIG_BLOCK   : constant := 0;
158    SIG_UNBLOCK : constant := 1;
159    SIG_SETMASK : constant := 2;
160
161    SIG_DFL : constant := 0;
162    SIG_IGN : constant := 1;
163
164    function sigaction
165      (sig  : Signal;
166       act  : struct_sigaction_ptr;
167       oact : struct_sigaction_ptr) return int;
168    pragma Import (C, sigaction, "sigaction");
169
170    ----------
171    -- Time --
172    ----------
173
174    Time_Slice_Supported : constant Boolean := True;
175    --  Indicates wether time slicing is supported
176
177    type timespec is private;
178
179    type clockid_t is private;
180
181    CLOCK_REALTIME : constant clockid_t;
182
183    function clock_gettime
184      (clock_id : clockid_t;
185       tp       : access timespec) return int;
186    pragma Inline (clock_gettime);
187    --  LynxOS has non standard clock_gettime
188
189    function To_Duration (TS : timespec) return Duration;
190    pragma Inline (To_Duration);
191
192    function To_Timespec (D : Duration) return timespec;
193    pragma Inline (To_Timespec);
194
195    type struct_timezone is record
196       tz_minuteswest : int;
197       tz_dsttime     : int;
198    end record;
199    pragma Convention (C, struct_timezone);
200    type struct_timezone_ptr is access all struct_timezone;
201
202    type struct_timeval is private;
203    --  This is needed on systems that do not have clock_gettime()
204    --  but do have gettimeofday().
205
206    function To_Duration (TV : struct_timeval) return Duration;
207    pragma Inline (To_Duration);
208
209    function To_Timeval (D : Duration) return struct_timeval;
210    pragma Inline (To_Timeval);
211
212    -------------------------
213    -- Priority Scheduling --
214    -------------------------
215
216    SCHED_FIFO  : constant := 16#00200000#;
217    SCHED_RR    : constant := 16#00100000#;
218    SCHED_OTHER : constant := 16#00400000#;
219
220    -------------
221    -- Process --
222    -------------
223
224    type pid_t is private;
225
226    function kill (pid : pid_t; sig : Signal) return int;
227    pragma Import (C, kill, "kill");
228
229    function getpid return pid_t;
230    pragma Import (C, getpid, "getpid");
231
232    ---------
233    -- LWP --
234    ---------
235
236    function lwp_self return System.Address;
237    --  lwp_self does not exist on this thread library, revert to pthread_self
238    --  which is the closest approximation (with getpid). This function is
239    --  needed to share 7staprop.adb across POSIX-like targets.
240    pragma Import (C, lwp_self, "pthread_self");
241
242    -------------
243    -- Threads --
244    -------------
245
246    type Thread_Body is access
247      function (arg : System.Address) return System.Address;
248    type pthread_t           is private;
249    subtype Thread_Id        is pthread_t;
250
251    type pthread_mutex_t     is limited private;
252    type pthread_cond_t      is limited private;
253    type st_t                is limited private;
254    type pthread_attr_t      is limited private;
255    type pthread_mutexattr_t is limited private;
256    type pthread_condattr_t  is limited private;
257    type pthread_key_t       is private;
258
259    PTHREAD_CREATE_DETACHED : constant := 0;
260
261    -----------
262    -- Stack --
263    -----------
264
265    Stack_Base_Available : constant Boolean := False;
266    --  Indicates wether the stack base is available on this target.
267
268    function Get_Stack_Base (thread : pthread_t) return Address;
269    pragma Inline (Get_Stack_Base);
270    --  returns the stack base of the specified thread.
271    --  Only call this function when Stack_Base_Available is True.
272
273    function Get_Page_Size return size_t;
274    function Get_Page_Size return Address;
275    pragma Import (C, Get_Page_Size, "getpagesize");
276    --  returns the size of a page, or 0 if this is not relevant on this
277    --  target
278
279    PROT_NONE  : constant := 0;
280    PROT_READ  : constant := 1;
281    PROT_WRITE : constant := 2;
282    PROT_EXEC  : constant := 4;
283    PROT_USER  : constant := 8;
284    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC + PROT_USER;
285
286    PROT_ON    : constant := PROT_READ;
287    PROT_OFF   : constant := PROT_ALL;
288
289    function mprotect (addr : Address; len : size_t; prot : int) return int;
290    pragma Import (C, mprotect);
291
292    -------------------------
293    -- POSIX.1c  Section 3 --
294    -------------------------
295
296    function sigwait
297      (set : access sigset_t;
298       sig : access Signal) return int;
299    pragma Inline (sigwait);
300    --  LynxOS has non standard sigwait
301
302    function pthread_kill (thread : pthread_t; sig : Signal) return int;
303    pragma Import (C, pthread_kill, "pthread_kill");
304
305    type sigset_t_ptr is access all sigset_t;
306
307    function pthread_sigmask
308      (how  : int;
309       set  : sigset_t_ptr;
310       oset : sigset_t_ptr) return int;
311    pragma Import (C, pthread_sigmask, "sigprocmask");
312
313    --------------------------
314    -- POSIX.1c  Section 11 --
315    --------------------------
316
317    function pthread_mutexattr_init
318      (attr : access pthread_mutexattr_t) return int;
319    pragma Inline (pthread_mutexattr_init);
320    --  LynxOS has a nonstandard pthread_mutexattr_init
321
322    function pthread_mutexattr_destroy
323      (attr : access pthread_mutexattr_t) return int;
324    pragma Inline (pthread_mutexattr_destroy);
325    --  Lynxos has a nonstandard pthread_mutexattr_destroy
326
327    function pthread_mutex_init
328      (mutex : access pthread_mutex_t;
329       attr  : access pthread_mutexattr_t) return int;
330    pragma Inline (pthread_mutex_init);
331    --  LynxOS has a nonstandard pthread_mutex_init
332
333    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
334    pragma Inline (pthread_mutex_destroy);
335    --  LynxOS has a nonstandard pthread_mutex_destroy
336
337    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
338    pragma Inline (pthread_mutex_lock);
339    --  LynxOS has a nonstandard pthread_mutex_lock
340
341    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
342    pragma Inline (pthread_mutex_unlock);
343    --  LynxOS has a nonstandard pthread_mutex_unlock
344
345    function pthread_condattr_init
346      (attr : access pthread_condattr_t) return int;
347    pragma Inline (pthread_condattr_init);
348    --  LynxOS has a nonstandard pthread_condattr_init
349
350    function pthread_condattr_destroy
351      (attr : access pthread_condattr_t) return int;
352    pragma Inline (pthread_condattr_destroy);
353    --  LynxOS has a nonstandard pthread_condattr_destroy
354
355    function pthread_cond_init
356      (cond : access pthread_cond_t;
357       attr : access pthread_condattr_t) return int;
358    pragma Inline (pthread_cond_init);
359    --  LynxOS has a non standard pthread_cond_init
360
361    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
362    pragma Inline (pthread_cond_destroy);
363    --  LynxOS has a nonstandard pthread_cond_destroy
364
365    function pthread_cond_signal (cond : access pthread_cond_t) return int;
366    pragma Inline (pthread_cond_signal);
367    --  LynxOS has a nonstandard pthread_cond_signal
368
369    function pthread_cond_wait
370      (cond  : access pthread_cond_t;
371       mutex : access pthread_mutex_t) return int;
372    pragma Inline (pthread_cond_wait);
373    --  LynxOS has a nonstandard pthread_cond_wait
374
375    function pthread_cond_timedwait
376      (cond    : access pthread_cond_t;
377       mutex   : access pthread_mutex_t;
378       reltime : access timespec) return int;
379    pragma Inline (pthread_cond_timedwait);
380    --  LynxOS has a nonstandard pthrad_cond_timedwait
381
382    Relative_Timed_Wait : constant Boolean := True;
383    --  pthread_cond_timedwait requires a relative delay time
384
385    --------------------------
386    -- POSIX.1c  Section 13 --
387    --------------------------
388
389    PTHREAD_PRIO_NONE    : constant := 0;
390    PTHREAD_PRIO_INHERIT : constant := 0;
391    PTHREAD_PRIO_PROTECT : constant := 0;
392
393    type struct_sched_param is record
394       sched_priority : int;  --  scheduling priority
395    end record;
396
397    function pthread_setschedparam
398      (thread : pthread_t;
399       policy : int;
400       param  : access struct_sched_param) return int;
401    pragma Inline (pthread_setschedparam);
402    --  LynxOS doesn't have pthread_setschedparam.
403    --  Instead, use pthread_setscheduler
404
405    function pthread_mutexattr_setprotocol
406      (attr     : access pthread_mutexattr_t;
407       protocol : int) return int;
408    pragma Inline (pthread_mutexattr_setprotocol);
409    --  LynxOS doesn't have pthread_mutexattr_setprotocol
410
411    function pthread_mutexattr_setprioceiling
412      (attr     : access pthread_mutexattr_t;
413       prioceiling : int) return int;
414    pragma Inline (pthread_mutexattr_setprioceiling);
415    --  LynxOS doesn't have pthread_mutexattr_setprioceiling
416
417    function pthread_attr_setscope
418      (attr            : access pthread_attr_t;
419       contentionscope : int) return int;
420    --  LynxOS doesn't have pthread_attr_setscope: all threads have system scope
421    pragma Inline (pthread_attr_setscope);
422
423    function pthread_attr_setschedpolicy
424      (attr   : access pthread_attr_t;
425       policy : int) return int;
426    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
427
428    function sched_yield return int;
429    --   pragma Import (C, sched_yield, "sched_yield");
430    pragma Inline (sched_yield);
431
432    ---------------------------
433    -- P1003.1c - Section 16 --
434    ---------------------------
435
436    function pthread_attr_init (attributes : access pthread_attr_t) return int;
437    pragma Import (C, pthread_attr_init, "pthread_attr_create");
438
439    function pthread_attr_destroy
440      (attributes : access pthread_attr_t) return int;
441    pragma Import (C, pthread_attr_destroy, "pthread_attr_delete");
442
443    function pthread_attr_setdetachstate
444      (attr        : access pthread_attr_t;
445       detachstate : int) return int;
446    pragma Inline (pthread_attr_setdetachstate);
447    --  LynxOS doesn't have 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, "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 Inline (pthread_create);
460    --  LynxOS has a non standard pthread_create
461
462    procedure pthread_exit (status : System.Address);
463    pragma Import (C, pthread_exit, "pthread_exit");
464
465    function pthread_self return pthread_t;
466    pragma Import (C, pthread_self, "pthread_self");
467
468    --------------------------
469    -- POSIX.1c  Section 17 --
470    --------------------------
471
472    function pthread_setspecific
473      (key   : pthread_key_t;
474       value : System.Address) return int;
475    pragma Inline (pthread_setspecific);
476    --  LynxOS has a non standard pthread_setspecific
477
478    function pthread_getspecific (key : pthread_key_t) return System.Address;
479    pragma Inline (pthread_getspecific);
480    --  LynxOS has a non standard pthread_getspecific
481
482    type destructor_pointer is access procedure (arg : System.Address);
483
484    function pthread_key_create
485      (key        : access pthread_key_t;
486       destructor : destructor_pointer) return int;
487    pragma Inline (pthread_key_create);
488    --  LynxOS has a non standard pthread_keycreate
489
490    procedure pthread_init;
491    --  This is a dummy procedure to share some GNULLI files
492
493 private
494
495    type sigbit_array is array (1 .. 2) of long;
496    type sigset_t is record
497       sa_sigbits : sigbit_array;
498    end record;
499    pragma Convention (C_Pass_By_Copy, sigset_t);
500
501    type pid_t is new long;
502
503    type time_t is new long;
504
505    type timespec is record
506       tv_sec  : time_t;
507       tv_nsec : long;
508    end record;
509    pragma Convention (C, timespec);
510
511    type clockid_t is new unsigned_char;
512    CLOCK_REALTIME : constant clockid_t := 0;
513
514    type struct_timeval is record
515       tv_sec  : time_t;
516       tv_usec : time_t;
517    end record;
518    pragma Convention (C, struct_timeval);
519
520    type st_t is record
521       stksize      : int;
522       prio         : int;
523       inheritsched : int;
524       state        : int;
525       sched        : int;
526    end record;
527    pragma Convention (C, st_t);
528
529    type pthread_attr_t is record
530       st                 : st_t;
531       pthread_attr_scope : int;  --  ignored
532    end record;
533    pragma Convention (C, pthread_attr_t);
534
535    type pthread_condattr_t is new int;
536
537    type pthread_mutexattr_t is new int;
538
539    type tid_t is new short;
540    type pthread_t is new tid_t;
541
542    type synch_ptr is access all pthread_mutex_t;
543    type pthread_mutex_t is record
544       w_count   : int;
545       mut_owner : int;
546       id        : unsigned;
547       next      : synch_ptr;
548    end record;
549    pragma Convention (C, pthread_mutex_t);
550
551    type pthread_cond_t is new pthread_mutex_t;
552
553    type pthread_key_t is new int;
554
555 end System.OS_Interface;