OSDN Git Service

2004-08-13 Olivier Hainque <hainque@act-europe.fr>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-unixware.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 UnixWare (Native 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 ("-lthread");
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 := 145;
74
75    -------------
76    -- Signals --
77    -------------
78
79    Max_Interrupt : constant := 34;
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    SIGIOT      : constant := 6; --  IOT instruction
89    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
90    SIGEMT      : constant := 7; --  EMT instruction
91    SIGFPE      : constant := 8; --  floating point exception
92    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
93    SIGBUS      : constant := 10; --  bus error
94    SIGSEGV     : constant := 11; --  segmentation violation
95    SIGSYS      : constant := 12; --  bad argument to system call
96    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
97    SIGALRM     : constant := 14; --  alarm clock
98    SIGTERM     : constant := 15; --  software termination signal from kill
99    SIGUSR1     : constant := 16; --  user defined signal 1
100    SIGUSR2     : constant := 17; --  user defined signal 2
101    SIGCLD      : constant := 18; --  alias for SIGCHLD
102    SIGCHLD     : constant := 18; --  child status change
103    SIGPWR      : constant := 19; --  power-fail restart
104    SIGWINCH    : constant := 20; --  window size change
105    SIGURG      : constant := 21; --  urgent condition on IO channel
106    SIGPOLL     : constant := 22; --  pollable event occurred
107    SIGIO       : constant := 22; --  I/O possible (Solaris SIGPOLL alias)
108    SIGSTOP     : constant := 23; --  stop (cannot be caught or ignored)
109    SIGTSTP     : constant := 24; --  user stop requested from tty
110    SIGCONT     : constant := 25; --  stopped process has been continued
111    SIGTTIN     : constant := 26; --  background tty read attempted
112    SIGTTOU     : constant := 27; --  background tty write attempted
113    SIGVTALRM   : constant := 28; --  virtual timer expired
114    SIGPROF     : constant := 29; --  profiling timer expired
115    SIGXCPU     : constant := 30; --  CPU time limit exceeded
116    SIGXFSZ     : constant := 31; --  filesize limit exceeded
117    SIGWAITING  : constant := 32; --  all LWPs blocked interruptibly notific.
118    SIGLWP      : constant := 33; --  signal reserved for thread lib impl.
119    SIGAIO      : constant := 34; --  Asynchronous I/O signal
120
121    SIGADAABORT : constant := SIGABRT;
122    --  Change this if you want to use another signal for task abort.
123    --  SIGTERM might be a good one.
124
125    type Signal_Set is array (Natural range <>) of Signal;
126
127    Unmasked    : constant Signal_Set :=
128      (SIGTRAP, SIGLWP, SIGWAITING, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
129    Reserved    : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP);
130
131    type sigset_t is private;
132
133    function sigaddset (set : access sigset_t; sig : Signal) return int;
134    pragma Import (C, sigaddset, "sigaddset");
135
136    function sigdelset (set : access sigset_t; sig : Signal) return int;
137    pragma Import (C, sigdelset, "sigdelset");
138
139    function sigfillset (set : access sigset_t) return int;
140    pragma Import (C, sigfillset, "sigfillset");
141
142    function sigismember (set : access sigset_t; sig : Signal) return int;
143    pragma Import (C, sigismember, "sigismember");
144
145    function sigemptyset (set : access sigset_t) return int;
146    pragma Import (C, sigemptyset, "sigemptyset");
147
148    type struct_sigaction is record
149       sa_flags   : int;
150       sa_handler : System.Address;
151       sa_mask    : sigset_t;
152       sa_resv1   : int;
153       sa_resv2   : int;
154    end record;
155    pragma Convention (C, struct_sigaction);
156    type struct_sigaction_ptr is access all struct_sigaction;
157
158    SIG_BLOCK   : constant := 1;
159    SIG_UNBLOCK : constant := 2;
160    SIG_SETMASK : constant := 3;
161
162    SIG_DFL : constant := 0;
163    SIG_IGN : constant := 1;
164    --  SIG_ERR : constant := -1;
165    --  not used
166
167    function sigaction
168      (sig  : Signal;
169       act  : struct_sigaction_ptr;
170       oact : struct_sigaction_ptr) return int;
171    pragma Import (C, sigaction, "sigaction");
172
173    ----------
174    -- Time --
175    ----------
176
177    Time_Slice_Supported : constant Boolean := False;
178    --  Indicates wether time slicing is supported
179
180    type timespec is private;
181
182    type clockid_t is private;
183
184    CLOCK_REALTIME : constant clockid_t;
185
186    function clock_gettime
187      (clock_id : clockid_t;
188       tp       : access timespec) return int;
189    --  UnixWare threads don't have clock_gettime
190    --  We instead use gettimeofday()
191
192    function To_Duration (TS : timespec) return Duration;
193    pragma Inline (To_Duration);
194
195    function To_Timespec (D : Duration) return timespec;
196    pragma Inline (To_Timespec);
197
198    type struct_timezone is record
199       tz_minuteswest : int;
200       tz_dsttime     : int;
201    end record;
202    pragma Convention (C, struct_timezone);
203    type struct_timezone_ptr is access all struct_timezone;
204
205    type struct_timeval is private;
206    --  This is needed on systems that do not have clock_gettime()
207    --  but do have gettimeofday().
208
209    function To_Duration (TV : struct_timeval) return Duration;
210    pragma Inline (To_Duration);
211
212    function To_Timeval (D : Duration) return struct_timeval;
213    pragma Inline (To_Timeval);
214
215    -------------------------
216    -- Priority Scheduling --
217    -------------------------
218
219    SCHED_FIFO  : constant := 2;
220    SCHED_RR    : constant := 3;
221    SCHED_OTHER : constant := 1;
222
223    -------------
224    -- Process --
225    -------------
226
227    type pid_t is private;
228
229    function kill (pid : pid_t; sig : Signal) return int;
230    pragma Import (C, kill, "kill");
231
232    function getpid return pid_t;
233    pragma Import (C, getpid, "getpid");
234
235    ---------
236    -- LWP --
237    ---------
238
239    function lwp_self return System.Address;
240    pragma Import (C, lwp_self, "_lwp_self");
241
242    -------------
243    -- Threads --
244    -------------
245
246    type Thread_Body is access
247      function (arg : System.Address) return System.Address;
248
249    function Thread_Body_Access is new
250      Unchecked_Conversion (System.Address, Thread_Body);
251
252    type pthread_t           is private;
253    subtype Thread_Id        is pthread_t;
254
255    type pthread_mutex_t     is limited private;
256    type pthread_cond_t      is limited private;
257    type pthread_attr_t      is limited private;
258    type pthread_mutexattr_t is limited private;
259    type pthread_condattr_t  is limited private;
260    type pthread_key_t       is private;
261
262    PTHREAD_CREATE_DETACHED : constant := 0;
263
264    -----------
265    -- Stack --
266    -----------
267
268    Stack_Base_Available : constant Boolean := False;
269    --  Indicates wether the stack base is available on this target.
270
271    function Get_Stack_Base (thread : pthread_t) return Address;
272    pragma Inline (Get_Stack_Base);
273    --  returns the stack base of the specified thread.
274    --  Only call this function when Stack_Base_Available is True.
275
276    function Get_Page_Size return size_t;
277    function Get_Page_Size return Address;
278    pragma Import (C, Get_Page_Size, "getpagesize");
279    --  returns the size of a page, or 0 if this is not relevant on this
280    --  target
281
282    PROT_NONE  : constant := 0;
283    PROT_READ  : constant := 1;
284    PROT_WRITE : constant := 2;
285    PROT_EXEC  : constant := 4;
286    PROT_USER  : constant := 8;
287    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC + PROT_USER;
288
289    PROT_ON    : constant := PROT_READ;
290    PROT_OFF   : constant := PROT_ALL;
291
292    function mprotect (addr : Address; len : size_t; prot : int) return int;
293    pragma Import (C, mprotect);
294
295    -------------------------
296    -- POSIX.1c  Section 3 --
297    -------------------------
298
299    function sigwait (set : access sigset_t; sig : access Signal) return int;
300    pragma Inline (sigwait);
301    --  UnixWare provides a non standard sigwait
302
303    function pthread_kill (thread : pthread_t; sig : Signal) return int;
304    pragma Inline (pthread_kill);
305    --  UnixWare provides a non standard pthread_kill
306
307    type sigset_t_ptr is access all sigset_t;
308
309    function pthread_sigmask
310      (how  : int;
311       set  : sigset_t_ptr;
312       oset : sigset_t_ptr) return int;
313    pragma Import (C, pthread_sigmask, "pthread_sigmask");
314
315    --------------------------
316    -- POSIX.1c  Section 11 --
317    --------------------------
318
319    function pthread_mutexattr_init
320      (attr : access pthread_mutexattr_t) return int;
321    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
322
323    function pthread_mutexattr_destroy
324      (attr : access pthread_mutexattr_t) return int;
325    pragma Import (C, pthread_mutexattr_destroy, "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 Import (C, pthread_mutex_init, "pthread_mutex_init");
331
332    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
333    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
334
335    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
336    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
337
338    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
339    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
340
341    function pthread_condattr_init
342      (attr : access pthread_condattr_t) return int;
343    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
344
345    function pthread_condattr_destroy
346      (attr : access pthread_condattr_t) return int;
347    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
348
349    function pthread_cond_init
350      (cond : access pthread_cond_t;
351       attr : access pthread_condattr_t) return int;
352    pragma Import (C, pthread_cond_init, "pthread_cond_init");
353
354    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
355    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
356
357    function pthread_cond_signal (cond : access pthread_cond_t) return int;
358    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
359
360    function pthread_cond_wait
361      (cond  : access pthread_cond_t;
362       mutex : access pthread_mutex_t) return int;
363    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
364
365    function pthread_cond_timedwait
366      (cond    : access pthread_cond_t;
367       mutex   : access pthread_mutex_t;
368       abstime : access timespec) return int;
369    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
370
371    Relative_Timed_Wait : constant Boolean := False;
372    --  pthread_cond_timedwait requires an absolute delay time
373
374    --------------------------
375    -- POSIX.1c  Section 13 --
376    --------------------------
377
378    PTHREAD_PRIO_NONE    : constant := 1;
379    PTHREAD_PRIO_INHERIT : constant := 2;
380    PTHREAD_PRIO_PROTECT : constant := 3;
381
382    function pthread_mutexattr_setprotocol
383      (attr     : access pthread_mutexattr_t;
384       protocol : int) return int;
385    pragma Import (C, pthread_mutexattr_setprotocol);
386
387    function pthread_mutexattr_setprioceiling
388      (attr     : access pthread_mutexattr_t;
389       prioceiling : int) return int;
390    pragma Import (C, pthread_mutexattr_setprioceiling);
391
392    type sched_union is record
393       sched_fifo    : int;
394       sched_fcfs    : int;
395       sched_other   : int;
396       sched_ts      : int;
397       policy_params : long;
398    end record;
399
400    type struct_sched_param is record
401       sched_priority    : int;
402       sched_other_stuff : sched_union;
403    end record;
404
405    function pthread_setschedparam
406      (thread : pthread_t;
407       policy : int;
408       param  : access struct_sched_param) return int;
409    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
410
411    function pthread_attr_setscope
412      (attr            : access pthread_attr_t;
413       contentionscope : int) return int;
414    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
415
416    function pthread_attr_setinheritsched
417      (attr            : access pthread_attr_t;
418       inheritsched : int) return int;
419    pragma Import (C, pthread_attr_setinheritsched);
420
421    function pthread_attr_setschedpolicy
422      (attr   : access pthread_attr_t;
423       policy : int) return int;
424    pragma Import (C, pthread_attr_setschedpolicy);
425
426    function sched_yield return int;
427    pragma Import (C, sched_yield, "sched_yield");
428
429    ---------------------------
430    -- P1003.1c - Section 16 --
431    ---------------------------
432
433    function pthread_attr_init (attributes : access pthread_attr_t) return int;
434    pragma Import (C, pthread_attr_init, "pthread_attr_init");
435
436    function pthread_attr_destroy
437      (attributes : access pthread_attr_t) return int;
438    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
439
440    function pthread_attr_setdetachstate
441      (attr        : access pthread_attr_t;
442       detachstate : int) return int;
443    pragma Import (C, pthread_attr_setdetachstate);
444
445    function pthread_attr_setstacksize
446      (attr      : access pthread_attr_t;
447       stacksize : size_t) return int;
448    pragma Import (C, pthread_attr_setstacksize);
449
450    function pthread_create
451      (thread        : access pthread_t;
452       attributes    : access pthread_attr_t;
453       start_routine : Thread_Body;
454       arg           : System.Address) return int;
455    pragma Import (C, pthread_create, "pthread_create");
456
457    procedure pthread_exit (status : System.Address);
458    pragma Import (C, pthread_exit, "pthread_exit");
459
460    function pthread_self return pthread_t;
461    pragma Import (C, pthread_self, "pthread_self");
462
463    --------------------------
464    -- POSIX.1c  Section 17 --
465    --------------------------
466
467    function pthread_setspecific
468      (key   : pthread_key_t;
469       value : System.Address) return int;
470    pragma Import (C, pthread_setspecific, "pthread_setspecific");
471
472    function pthread_getspecific (key : pthread_key_t) return System.Address;
473    pragma Import (C, pthread_getspecific, "pthread_getspecific");
474
475    type destructor_pointer is access procedure (arg : System.Address);
476
477    function pthread_key_create
478      (key        : access pthread_key_t;
479       destructor : destructor_pointer) return int;
480    pragma Import (C, pthread_key_create, "pthread_key_create");
481
482    procedure pthread_init;
483    --  This is a dummy procedure to share some GNULLI files
484
485 private
486
487    type sigbit_array is array (1 .. 4) of unsigned;
488    type sigset_t is record
489       sa_sigbits : sigbit_array;
490    end record;
491    pragma Convention (C_Pass_By_Copy, sigset_t);
492
493    type pid_t is new unsigned;
494
495    type time_t is new long;
496
497    type timespec is record
498       tv_sec       : time_t;
499       tv_nsec      : long;
500    end record;
501    pragma Convention (C, timespec);
502
503    type clockid_t is new int;
504    CLOCK_REALTIME : constant clockid_t := 0;
505
506    type struct_timeval is record
507       tv_sec       : long;
508       tv_usec      : long;
509    end record;
510    pragma Convention (C, struct_timeval);
511
512    type pthread_attr_t is record
513       pt_attr_status          : int;
514       pt_attr_stacksize       : size_t;
515       pt_attr_stackaddr       : System.Address;
516       pt_attr_detachstate     : int;
517       pt_attr_contentionscope : int;
518       pt_attr_inheritsched    : int;
519       pt_attr_schedpolicy     : int;
520       pt_attr_sched_param     : struct_sched_param;
521       pt_attr_tlflags         : int;
522    end record;
523    pragma Convention (C, pthread_attr_t);
524
525    type pthread_condattr_t is record
526       pt_condattr_status  : int;
527       pt_condattr_pshared : int;
528    end record;
529    pragma Convention (C, pthread_condattr_t);
530
531    type pthread_mutexattr_t is record
532       pt_mutexattr_status  : int;
533       pt_mutexattr_pshared : int;
534       pt_mutexattr_type    : int;
535    end record;
536    pragma Convention (C, pthread_mutexattr_t);
537
538    type thread_t is new long;
539    type pthread_t is new thread_t;
540
541    type thrq_elt_t;
542    type thrq_elt_t_ptr is access all thrq_elt_t;
543
544    type thrq_elt_t is record
545       thrq_next : thrq_elt_t_ptr;
546       thrq_prev : thrq_elt_t_ptr;
547    end record;
548    pragma Convention (C, thrq_elt_t);
549
550    type lwp_mutex_t is record
551       wanted : char;
552       lock   : unsigned_char;
553    end record;
554    pragma Convention (C, lwp_mutex_t);
555    pragma Volatile (lwp_mutex_t);
556
557    type mutex_t is record
558       m_lmutex    : lwp_mutex_t;
559       m_sync_lock : lwp_mutex_t;
560       m_type      : int;
561       m_sleepq    : thrq_elt_t;
562       filler1     : int;
563       filler2     : int;
564    end record;
565    pragma Convention (C, mutex_t);
566    pragma Volatile (mutex_t);
567
568    type pthread_mutex_t is record
569       pt_mutex_mutex : mutex_t;
570       pt_mutex_pid   : pid_t;
571       pt_mutex_owner : thread_t;
572       pt_mutex_depth : int;
573       pt_mutex_attr  : pthread_mutexattr_t;
574    end record;
575    pragma Convention (C, pthread_mutex_t);
576
577    type lwp_cond_t is record
578       wanted : char;
579    end record;
580    pragma Convention (C, lwp_cond_t);
581    pragma Volatile (lwp_cond_t);
582
583    type cond_t is record
584       c_lcond     : lwp_cond_t;
585       c_sync_lock : lwp_mutex_t;
586       c_type      : int;
587       c_syncq     : thrq_elt_t;
588    end record;
589    pragma Convention (C, cond_t);
590    pragma Volatile (cond_t);
591
592    type pthread_cond_t is record
593       pt_cond_cond : cond_t;
594       pt_cond_attr : pthread_condattr_t;
595    end record;
596    pragma Convention (C, pthread_cond_t);
597
598    type pthread_key_t is new unsigned;
599
600 end System.OS_Interface;