OSDN Git Service

2005-03-08 Pascal Obry <obry@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-lynxos.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 --             Copyright (C) 1991-1994, Florida State University            --
10 --             Copyright (C) 1995-2004, 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.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a LynxOS (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 ("-mthreads");
50    --  Selects the POSIX 1.c runtime, rather than the non-threading runtime
51    --  or the deprecated legacy threads library. The -mthreads flag is
52    --  defined in patch.LynxOS and matches the definition for Lynx's gcc.
53
54    subtype int            is Interfaces.C.int;
55    subtype short          is Interfaces.C.short;
56    subtype long           is Interfaces.C.long;
57    subtype unsigned       is Interfaces.C.unsigned;
58    subtype unsigned_short is Interfaces.C.unsigned_short;
59    subtype unsigned_long  is Interfaces.C.unsigned_long;
60    subtype unsigned_char  is Interfaces.C.unsigned_char;
61    subtype plain_char     is Interfaces.C.plain_char;
62    subtype size_t         is Interfaces.C.size_t;
63
64    -----------
65    -- Errno --
66    -----------
67
68    function errno return int;
69    pragma Import (C, errno, "__get_errno");
70
71    EAGAIN    : constant := 11;
72    EINTR     : constant := 4;
73    EINVAL    : constant := 22;
74    ENOMEM    : constant := 12;
75    ETIMEDOUT : constant := 60;
76
77    -------------
78    -- Signals --
79    -------------
80
81    Max_Interrupt : constant := 63;
82
83    --  Max_Interrupt is the number of OS signals, as defined in:
84    --
85    --   /usr/include/sys/signal.h
86    --
87    --
88    --  The lowest numbered signal is 1, but 0 is a valid argument to some
89    --  library functions, eg. kill(2). However, 0 is not just another
90    --  signal: For instance 'I in Signal' and similar should be used with
91    --  caution.
92
93    type Signal is new int range 0 .. Max_Interrupt;
94    for  Signal'Size use int'Size;
95
96    SIGHUP        : constant := 1;  --  hangup
97    SIGINT        : constant := 2;  --  interrupt (rubout)
98    SIGQUIT       : constant := 3;  --  quit (ASCD FS)
99    SIGILL        : constant := 4;  --  illegal instruction (not reset)
100    SIGTRAP       : constant := 5;  --  trace trap (not reset)
101    SIGBRK        : constant := 6;  --  break
102    SIGIOT        : constant := 6;  --  IOT instruction
103    SIGABRT       : constant := 6;  --  used by abort, replace SIGIOT in future
104    SIGCORE       : constant := 7;  --  kill with core dump
105    SIGEMT        : constant := 7;  --  EMT instruction
106    SIGFPE        : constant := 8;  --  floating point exception
107    SIGKILL       : constant := 9;  --  kill (cannot be caught or ignored)
108    SIGBUS        : constant := 10; --  bus error
109    SIGSEGV       : constant := 11; --  segmentation violation
110    SIGSYS        : constant := 12; --  bad argument to system call
111    SIGPIPE       : constant := 13; --  write on a pipe with no one to read it
112    SIGALRM       : constant := 14; --  alarm clock
113    SIGTERM       : constant := 15; --  software termination signal from kill
114    SIGURG        : constant := 16; --  urgent condition on IO channel
115    SIGSTOP       : constant := 17; --  stop (cannot be caught or ignored)
116    SIGTSTP       : constant := 18; --  user stop requested from tty
117    SIGCONT       : constant := 19; --  stopped process has been continued
118    SIGCLD        : constant := 20; --  alias for SIGCHLD
119    SIGCHLD       : constant := 20; --  child status change
120    SIGTTIN       : constant := 21; --  background tty read attempted
121    SIGTTOU       : constant := 22; --  background tty write attempted
122    SIGIO         : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
123    SIGPOLL       : constant := 23; --  pollable event occurred
124    SIGTHREADKILL : constant := 24; --  Reserved by LynxOS runtime
125    SIGXCPU       : constant := 24; --  CPU time limit exceeded
126    SIGXFSZ       : constant := 25; --  filesize limit exceeded
127    SIGVTALRM     : constant := 26; --  virtual timer expired
128    SIGPROF       : constant := 27; --  profiling timer expired
129    SIGWINCH      : constant := 28; --  window size change
130    SIGLOST       : constant := 29; --  SUN 4.1 compatibility
131    SIGUSR1       : constant := 30; --  user defined signal 1
132    SIGUSR2       : constant := 31; --  user defined signal 2
133
134    SIGPRIO       : constant := 32;
135    --  sent to a process with its priority or group is changed
136
137    SIGADAABORT : constant := SIGABRT;
138    --  Change this if you want to use another signal for task abort.
139    --  SIGTERM might be a good one.
140
141    type Signal_Set is array (Natural range <>) of Signal;
142
143    Unmasked    : constant Signal_Set :=
144      (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF, SIGTHREADKILL);
145    Reserved    : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP, SIGPRIO);
146
147    type sigset_t is private;
148
149    function sigaddset (set : access sigset_t; sig : Signal) return int;
150    pragma Import (C, sigaddset, "sigaddset");
151
152    function sigdelset (set : access sigset_t; sig : Signal) return int;
153    pragma Import (C, sigdelset, "sigdelset");
154
155    function sigfillset (set : access sigset_t) return int;
156    pragma Import (C, sigfillset, "sigfillset");
157
158    function sigismember (set : access sigset_t; sig : Signal) return int;
159    pragma Import (C, sigismember, "sigismember");
160
161    function sigemptyset (set : access sigset_t) return int;
162    pragma Import (C, sigemptyset, "sigemptyset");
163
164    type struct_sigaction is record
165       sa_handler   : System.Address;
166       sa_mask      : sigset_t;
167       sa_flags     : int;
168    end record;
169    pragma Convention (C, struct_sigaction);
170    type struct_sigaction_ptr is access all struct_sigaction;
171
172    SA_SIGINFO  : constant := 16#80#;
173
174    SIG_BLOCK   : constant := 0;
175    SIG_UNBLOCK : constant := 1;
176    SIG_SETMASK : constant := 2;
177
178    SIG_DFL : constant := 0;
179    SIG_IGN : constant := 1;
180
181    function sigaction
182      (sig  : Signal;
183       act  : struct_sigaction_ptr;
184       oact : struct_sigaction_ptr) return int;
185    pragma Import (C, sigaction, "sigaction");
186
187    ----------
188    -- Time --
189    ----------
190
191    Time_Slice_Supported : constant Boolean := True;
192    --  Indicates whether time slicing is supported
193
194    type timespec is private;
195
196    type clockid_t is private;
197
198    CLOCK_REALTIME : constant clockid_t;
199
200    function clock_gettime
201      (clock_id : clockid_t;
202       tp       : access timespec) return int;
203    pragma Import (C, clock_gettime, "clock_gettime");
204
205    function clock_getres
206      (clock_id : clockid_t;
207       res      : access timespec) return int;
208    pragma Import (C, clock_getres, "clock_getres");
209
210    function To_Duration (TS : timespec) return Duration;
211    pragma Inline (To_Duration);
212
213    function To_Timespec (D : Duration) return timespec;
214    pragma Inline (To_Timespec);
215
216    type struct_timezone is record
217       tz_minuteswest : int;
218       tz_dsttime     : int;
219    end record;
220    pragma Convention (C, struct_timezone);
221    type struct_timezone_ptr is access all struct_timezone;
222
223    type struct_timeval is private;
224    --  This is needed on systems that do not have clock_gettime()
225    --  but do have gettimeofday().
226
227    function To_Duration (TV : struct_timeval) return Duration;
228    pragma Inline (To_Duration);
229
230    function To_Timeval (D : Duration) return struct_timeval;
231    pragma Inline (To_Timeval);
232
233    -------------------------
234    -- Priority Scheduling --
235    -------------------------
236
237    SCHED_FIFO  : constant := 16#200000#;
238    SCHED_RR    : constant := 16#100000#;
239    SCHED_OTHER : constant := 16#400000#;
240
241    -------------
242    -- Process --
243    -------------
244
245    type pid_t is private;
246
247    function kill (pid : pid_t; sig : Signal) return int;
248    pragma Import (C, kill, "kill");
249
250    function getpid return pid_t;
251    pragma Import (C, getpid, "getpid");
252
253    ---------
254    -- LWP --
255    ---------
256
257    function lwp_self return System.Address;
258    pragma Import (C, lwp_self, "pthread_self");
259
260    -------------
261    -- Threads --
262    -------------
263
264    type Thread_Body is access
265      function (arg : System.Address) return System.Address;
266
267    function Thread_Body_Access is new
268      Unchecked_Conversion (System.Address, Thread_Body);
269
270    type pthread_t           is private;
271    subtype Thread_Id        is pthread_t;
272
273    type pthread_mutex_t     is limited private;
274    type pthread_cond_t      is limited private;
275    type pthread_attr_t      is limited private;
276    type pthread_mutexattr_t is limited private;
277    type pthread_condattr_t  is limited private;
278    type pthread_key_t       is private;
279
280    PTHREAD_CREATE_DETACHED : constant := 1;
281    PTHREAD_CREATE_JOINABLE : constant := 0;
282
283    -----------
284    -- Stack --
285    -----------
286
287    Stack_Base_Available : constant Boolean := False;
288    --  Indicates whether the stack base is available on this target.
289
290    function Get_Stack_Base (thread : pthread_t) return Address;
291    pragma Inline (Get_Stack_Base);
292    --  Returns the stack base of the specified thread.
293    --  Only call this function when Stack_Base_Available is True.
294
295    function Get_Page_Size return size_t;
296    function Get_Page_Size return Address;
297    pragma Import (C, Get_Page_Size, "getpagesize");
298    --  Returns the size of a page, or 0 if this is not relevant on this
299    --  target
300
301    PROT_NONE  : constant := 1;
302    PROT_READ  : constant := 2;
303    PROT_WRITE : constant := 4;
304    PROT_EXEC  : constant := 8;
305    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
306
307    PROT_ON    : constant := PROT_READ;
308    PROT_OFF   : constant := PROT_ALL;
309
310    function mprotect (addr : Address; len : size_t; prot : int) return int;
311    pragma Import (C, mprotect);
312
313    ---------------------------------------
314    -- Nonstandard Thread Initialization --
315    ---------------------------------------
316
317    procedure pthread_init;
318    --  This is a dummy procedure to share some GNULLI files
319
320    -------------------------
321    -- POSIX.1c  Section 3 --
322    -------------------------
323
324    function sigwait
325      (set : access sigset_t;
326       sig : access Signal) return int;
327    pragma Inline (sigwait);
328    --  LynxOS has non standard sigwait
329
330    function pthread_kill
331      (thread : pthread_t;
332       sig    : Signal) return int;
333    pragma Import (C, pthread_kill, "pthread_kill");
334
335    type sigset_t_ptr is access all sigset_t;
336
337    function pthread_sigmask
338      (how  : int;
339       set  : sigset_t_ptr;
340       oset : sigset_t_ptr) return int;
341    pragma Import (C, pthread_sigmask, "pthread_sigmask");
342    --  The behavior of pthread_sigmask on LynxOS requires
343    --  further investigation.
344
345    ----------------------------
346    --  POSIX.1c  Section 11  --
347    ----------------------------
348
349    function pthread_mutexattr_init
350      (attr : access pthread_mutexattr_t) return int;
351    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
352
353    function pthread_mutexattr_destroy
354      (attr : access pthread_mutexattr_t) return int;
355    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
356
357    function pthread_mutex_init
358      (mutex : access pthread_mutex_t;
359       attr  : access pthread_mutexattr_t) return int;
360    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
361
362    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
363    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
364
365    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
366    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
367
368    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
369    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
370
371    function pthread_condattr_init
372      (attr : access pthread_condattr_t) return int;
373    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
374
375    function pthread_condattr_destroy
376      (attr : access pthread_condattr_t) return int;
377    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
378
379    function pthread_cond_init
380      (cond : access pthread_cond_t;
381       attr : access pthread_condattr_t) return int;
382    pragma Import (C, pthread_cond_init, "pthread_cond_init");
383
384    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
385    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
386
387    function pthread_cond_signal (cond : access pthread_cond_t) return int;
388    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
389
390    function pthread_cond_wait
391      (cond  : access pthread_cond_t;
392       mutex : access pthread_mutex_t) return int;
393    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
394
395    function pthread_cond_timedwait
396      (cond    : access pthread_cond_t;
397       mutex   : access pthread_mutex_t;
398       abstime : access timespec) return int;
399    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
400
401    Relative_Timed_Wait : constant Boolean := False;
402    --  pthread_cond_timedwait requires an absolute delay time
403
404    --------------------------
405    -- POSIX.1c  Section 13 --
406    --------------------------
407
408    PTHREAD_PRIO_NONE    : constant := 0;
409    PTHREAD_PRIO_INHERIT : constant := 1;
410    PTHREAD_PRIO_PROTECT : constant := 2;
411
412    function pthread_mutexattr_setprotocol
413      (attr     : access pthread_mutexattr_t;
414       protocol : int) return int;
415    pragma Import (C, pthread_mutexattr_setprotocol);
416
417    function pthread_mutexattr_setprioceiling
418      (attr        : access pthread_mutexattr_t;
419       prioceiling : int) return int;
420    pragma Import (C, pthread_mutexattr_setprioceiling);
421
422    type struct_sched_param is record
423       sched_priority : int;
424    end record;
425
426    function pthread_setschedparam
427      (thread : pthread_t;
428       policy : int;
429       param  : access struct_sched_param) return int;
430    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
431
432    function pthread_attr_setscope
433      (attr            : access pthread_attr_t;
434       contentionscope : int) return int;
435    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
436
437    function pthread_attr_setinheritsched
438      (attr         : access pthread_attr_t;
439       inheritsched : int) return int;
440    pragma Import (C, pthread_attr_setinheritsched);
441
442    function pthread_attr_setschedpolicy
443      (attr   : access pthread_attr_t;
444       policy : int) return int;
445    pragma Import (C, pthread_attr_setschedpolicy);
446
447    function sched_yield return int;
448    pragma Import (C, sched_yield, "sched_yield");
449
450    --------------------------
451    -- P1003.1c  Section 16 --
452    --------------------------
453
454    function pthread_attr_init (attributes : access pthread_attr_t) return int;
455    pragma Import (C, pthread_attr_init, "pthread_attr_init");
456
457    function pthread_attr_destroy
458      (attributes : access pthread_attr_t) return int;
459    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
460
461    function pthread_attr_setdetachstate
462      (attr        : access pthread_attr_t;
463       detachstate : int) return int;
464    pragma Import (C, pthread_attr_setdetachstate);
465
466    function pthread_attr_setstacksize
467      (attr      : access pthread_attr_t;
468       stacksize : size_t) return int;
469    pragma Import (C, pthread_attr_setstacksize);
470
471    function pthread_create
472      (thread        : access pthread_t;
473       attributes    : access pthread_attr_t;
474       start_routine : Thread_Body;
475       arg           : System.Address) return int;
476    pragma Import (C, pthread_create, "pthread_create");
477
478    procedure pthread_exit (status : System.Address);
479    pragma Import (C, pthread_exit, "pthread_exit");
480
481    function pthread_self return pthread_t;
482    pragma Import (C, pthread_self, "pthread_self");
483
484    --------------------------
485    -- POSIX.1c  Section 17 --
486    --------------------------
487
488    function st_setspecific
489      (key   : pthread_key_t;
490       value : System.Address) return int;
491    pragma Import (C, st_setspecific, "st_setspecific");
492
493    function st_getspecific
494      (key    : pthread_key_t;
495       retval : System.Address) return int;
496    pragma Import (C, st_getspecific, "st_getspecific");
497
498    type destructor_pointer is access procedure (arg : System.Address);
499
500    function st_keycreate
501      (destructor : destructor_pointer;
502       key        : access pthread_key_t) return int;
503    pragma Import (C, st_keycreate, "st_keycreate");
504
505 private
506
507    type sigset_t is record
508       X1, X2 : long;
509    end record;
510    pragma Convention (C, sigset_t);
511
512    type pid_t is new long;
513
514    type time_t is new long;
515
516    type timespec is record
517       tv_sec  : time_t;
518       tv_nsec : long;
519    end record;
520    pragma Convention (C, timespec);
521
522    type clockid_t is new unsigned_char;
523    CLOCK_REALTIME : constant clockid_t := 0;
524
525    type struct_timeval is record
526       tv_sec  : time_t;
527       tv_usec : time_t;
528    end record;
529    pragma Convention (C, struct_timeval);
530
531    type st_attr_t is record
532       stksize      : int;
533       prio         : int;
534       inheritsched : int;
535       state        : int;
536       sched        : int;
537       detachstate  : int;
538       guardsize    : int;
539    end record;
540    pragma Convention (C, st_attr_t);
541
542    type pthread_attr_t is record
543       pthread_attr_magic : unsigned;
544       st                 : st_attr_t;
545       pthread_attr_scope : int;
546    end record;
547    pragma Convention (C, pthread_attr_t);
548
549    type pthread_condattr_t is record
550       cv_magic   : unsigned;
551       cv_pshared : unsigned;
552    end record;
553    pragma Convention (C, pthread_condattr_t);
554
555    type pthread_mutexattr_t is record
556       m_flags   : unsigned;
557       m_prio_c  : int;
558       m_pshared : int;
559    end record;
560    pragma Convention (C, pthread_mutexattr_t);
561
562    type tid_t is new short;
563    type pthread_t is new tid_t;
564
565    type block_obj_t is new System.Address;
566    --  typedef struct _block_obj_s {
567    --     struct st_entry *b_head;
568    --  } block_obj_t;
569
570    type pthread_mutex_t is record
571       m_flags      : unsigned;
572       m_owner      : tid_t;
573       m_wait       : block_obj_t;
574       m_prio_c     : int;
575       m_oldprio    : int;
576       m_count      : int;
577       m_referenced : int;
578    end record;
579    pragma Convention (C, pthread_mutex_t);
580    type pthread_mutex_t_ptr is access all pthread_mutex_t;
581
582    type pthread_cond_t is record
583       cv_magic  : unsigned;
584       cv_wait   : block_obj_t;
585       cv_mutex  : pthread_mutex_t_ptr;
586       cv_refcnt : int;
587    end record;
588    pragma Convention (C, pthread_cond_t);
589
590    type pthread_key_t is new int;
591
592 end System.OS_Interface;