OSDN Git Service

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