OSDN Git Service

Delete all lines containing "$Revision:".
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5posinte.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) 1997-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 OpenNT/Interix (FSU THREADS) 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 ("-lgthreads");
50    pragma Linker_Options ("-lmalloc");
51
52    subtype int            is Interfaces.C.int;
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 := 31;
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 := 0; --  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 := 0; --  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 := 19; --  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
118    SIGADAABORT : constant := SIGABRT;
119
120    type Signal_Set is array (Natural range <>) of Signal;
121
122    Unmasked    : constant Signal_Set :=
123      (SIGTRAP, SIGALRM, SIGVTALRM, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
124
125    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
126
127    type sigset_t is private;
128
129    function sigaddset (set : access sigset_t; sig : Signal) return int;
130    pragma Import (C, sigaddset, "sigaddset");
131
132    function sigdelset (set : access sigset_t; sig : Signal) return int;
133    pragma Import (C, sigdelset, "sigdelset");
134
135    function sigfillset (set : access sigset_t) return int;
136    pragma Import (C, sigfillset, "sigfillset");
137
138    function sigismember (set : access sigset_t; sig : Signal) return int;
139    pragma Import (C, sigismember, "sigismember");
140
141    function sigemptyset (set : access sigset_t) return int;
142    pragma Import (C, sigemptyset, "sigemptyset");
143
144    type struct_sigaction is record
145       sa_handler  : System.Address;
146       sa_mask     : sigset_t;
147       sa_flags    : int;
148       sa_restorer : System.Address;
149    end record;
150    pragma Convention (C, struct_sigaction);
151    type struct_sigaction_ptr is access all struct_sigaction;
152
153    SIG_BLOCK   : constant := 1;
154    SIG_UNBLOCK : constant := 2;
155    SIG_SETMASK : constant := 3;
156
157    SIG_DFL : constant := 0;
158    SIG_IGN : constant := 1;
159
160    function sigaction
161      (sig  : Signal;
162       act  : struct_sigaction_ptr;
163       oact : struct_sigaction_ptr) return int;
164    --  FSU pthreads redefines sigaction and then uses a special syscall
165    --  API to call the system version. Doing syscalls on OpenNT is very
166    --  difficult, so we rename the pthread version instead.
167    pragma Import (C, sigaction, "pthread_wrapper_sigaction");
168
169    ----------
170    -- Time --
171    ----------
172
173    Time_Slice_Supported : constant Boolean := False;
174    --  Indicates wether time slicing is supported (i.e FSU threads have been
175    --  compiled with DEF_RR)
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 Import (C, clock_gettime, "clock_gettime");
187
188    function To_Duration (TS : timespec) return Duration;
189    pragma Inline (To_Duration);
190
191    function To_Timespec (D : Duration) return timespec;
192    pragma Inline (To_Timespec);
193
194    type struct_timeval is private;
195
196    function To_Duration (TV : struct_timeval) return Duration;
197    pragma Inline (To_Duration);
198
199    function To_Timeval (D : Duration) return struct_timeval;
200    pragma Inline (To_Timeval);
201
202    -------------------------
203    -- Priority Scheduling --
204    -------------------------
205
206    SCHED_FIFO  : constant := 0;
207    SCHED_RR    : constant := 1;
208    SCHED_OTHER : constant := 2;
209
210    -------------
211    -- Process --
212    -------------
213
214    type pid_t is private;
215
216    function kill (pid : pid_t; sig : Signal) return int;
217    pragma Import (C, kill, "kill");
218
219    function getpid return pid_t;
220    pragma Import (C, getpid, "getpid");
221
222    ---------
223    -- LWP --
224    ---------
225
226    function lwp_self return System.Address;
227    --  lwp_self does not exist on this thread library, revert to pthread_self
228    --  which is the closest approximation (with getpid). This function is
229    --  needed to share 7staprop.adb across POSIX-like targets.
230    pragma Import (C, lwp_self, "pthread_self");
231
232    -------------
233    -- Threads --
234    -------------
235
236    type Thread_Body is access
237      function (arg : System.Address) return System.Address;
238    type pthread_t           is private;
239    subtype Thread_Id        is pthread_t;
240
241    type pthread_mutex_t     is limited private;
242    type pthread_cond_t      is limited private;
243    type pthread_attr_t      is limited private;
244    type pthread_mutexattr_t is limited private;
245    type pthread_condattr_t  is limited private;
246    type pthread_key_t       is private;
247
248    PTHREAD_CREATE_DETACHED : constant := 1;
249    PTHREAD_CREATE_JOINABLE : constant := 0;
250
251    -----------
252    -- Stack --
253    -----------
254
255    Stack_Base_Available : constant Boolean := False;
256    --  Indicates wether the stack base is available on this target.
257    --  This allows us to share s-osinte.adb between all the FSU run time.
258    --  Note that this value can only be true if pthread_t has a complete
259    --  definition that corresponds exactly to the C header files.
260
261    function Get_Stack_Base (thread : pthread_t) return Address;
262    pragma Inline (Get_Stack_Base);
263    --  returns the stack base of the specified thread.
264    --  Only call this function when Stack_Base_Available is True.
265
266    function Get_Page_Size return size_t;
267    function Get_Page_Size return Address;
268    pragma Import (C, Get_Page_Size, "getpagesize");
269    --  returns the size of a page, or 0 if this is not relevant on this
270    --  target
271
272    PROT_NONE  : constant := 0;
273    PROT_READ  : constant := 1;
274    PROT_WRITE : constant := 2;
275    PROT_EXEC  : constant := 4;
276    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
277
278    PROT_ON    : constant := PROT_NONE;
279    PROT_OFF   : constant := PROT_ALL;
280
281    function mprotect (addr : Address; len : size_t; prot : int) return int;
282    pragma Import (C, mprotect);
283
284    ---------------------------------------
285    -- Nonstandard Thread Initialization --
286    ---------------------------------------
287
288    procedure pthread_init;
289    --  FSU_THREADS requires pthread_init, which is nonstandard
290    --  and this should be invoked during the elaboration of s-taprop.adb
291    pragma Import (C, pthread_init, "pthread_init");
292
293    -------------------------
294    -- POSIX.1c  Section 3 --
295    -------------------------
296
297    function sigwait
298      (set : access sigset_t;
299       sig : access Signal) return int;
300    --  FSU_THREADS has a nonstandard sigwait
301
302    function pthread_kill
303      (thread : pthread_t;
304       sig    : Signal) return   int;
305    pragma Import (C, pthread_kill, "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_wrapper_sigprocmask");
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    --  FSU_THREADS has nonstandard pthread_mutex_lock
337
338    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
339    --  FSU_THREADS has nonstandard pthread_mutex_lock
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    --  FSU_THREADS has a nonstandard 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    --  FSU_THREADS has a nonstandard 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 := 0;
379    PTHREAD_PRIO_PROTECT : constant := 2;
380    PTHREAD_PRIO_INHERIT : constant := 1;
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
391      (C, pthread_mutexattr_setprioceiling,
392       "pthread_mutexattr_setprio_ceiling");
393
394    type struct_sched_param is record
395       sched_priority : int;  --  scheduling priority
396    end record;
397
398    function pthread_setschedparam
399      (thread : pthread_t;
400       policy : int;
401       param  : access struct_sched_param) return int;
402    --  FSU_THREADS does not have pthread_setschedparam
403
404    function pthread_attr_setscope
405      (attr            : access pthread_attr_t;
406       contentionscope : int) return int;
407    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
408
409    function pthread_attr_setinheritsched
410      (attr         : access pthread_attr_t;
411       inheritsched : int) return int;
412    pragma Import (C, pthread_attr_setinheritsched);
413
414    function pthread_attr_setschedpolicy
415      (attr   : access pthread_attr_t;
416       policy : int) return int;
417    pragma Import
418     (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
419
420    function sched_yield return int;
421    --  FSU_THREADS does not have sched_yield;
422
423    ---------------------------
424    -- P1003.1c - Section 16 --
425    ---------------------------
426
427    function pthread_attr_init (attributes : access pthread_attr_t) return int;
428    pragma Import (C, pthread_attr_init, "pthread_attr_init");
429
430    function pthread_attr_destroy
431      (attributes : access pthread_attr_t) return int;
432    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
433
434    function pthread_attr_setdetachstate
435      (attr        : access pthread_attr_t;
436       detachstate : int) return int;
437    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
438
439    function pthread_attr_setstacksize
440      (attr      : access pthread_attr_t;
441       stacksize : size_t) return int;
442    pragma Import (C, pthread_attr_setstacksize);
443
444    function pthread_create
445      (thread        : access pthread_t;
446       attributes    : access pthread_attr_t;
447       start_routine : Thread_Body;
448       arg           : System.Address) return int;
449    pragma Import (C, pthread_create, "pthread_create");
450
451    procedure pthread_exit (status : System.Address);
452    pragma Import (C, pthread_exit, "pthread_exit");
453
454    function pthread_self return pthread_t;
455    pragma Import (C, pthread_self, "pthread_self");
456
457    --------------------------
458    -- POSIX.1c  Section 17 --
459    --------------------------
460
461    function pthread_setspecific
462      (key   : pthread_key_t;
463       value : System.Address) return  int;
464    pragma Import (C, pthread_setspecific, "pthread_setspecific");
465
466    function pthread_getspecific (key : pthread_key_t) return System.Address;
467    --  FSU_THREADS has a nonstandard pthread_getspecific
468
469    type destructor_pointer is access procedure (arg : System.Address);
470
471    function pthread_key_create
472      (key        : access pthread_key_t;
473       destructor : destructor_pointer) return int;
474    pragma Import (C, pthread_key_create, "pthread_key_create");
475
476 private
477
478    type sigset_t is new unsigned_long;
479    pragma Convention (C, sigset_t);
480
481    type pid_t is new int;
482
483    subtype time_t is long;
484
485    type timespec is record
486       tv_sec  : time_t;
487       tv_nsec : long;
488    end record;
489    pragma Convention (C, timespec);
490
491    type clockid_t is new int;
492    CLOCK_REALTIME : constant clockid_t := 0;
493
494    type struct_timeval is record
495       tv_sec  : time_t;
496       tv_usec : long;
497    end record;
498    pragma Convention (C, struct_timeval);
499
500    type pthread_attr_t is record
501       flags           : int;
502       stacksize       : int;
503       contentionscope : int;
504       inheritsched    : int;
505       detachstate     : int;
506       sched           : int;
507       prio            : int;
508       starttime       : timespec;
509       deadline        : timespec;
510       period          : timespec;
511    end record;
512    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
513
514    type pthread_condattr_t is record
515       flags : int;
516    end record;
517    pragma Convention (C, pthread_condattr_t);
518
519    type pthread_mutexattr_t is record
520       flags        : int;
521       prio_ceiling : int;
522       protocol     : int;
523    end record;
524    pragma Convention (C, pthread_mutexattr_t);
525
526    type sigjmp_buf is array (Integer range 0 .. 17) of int;
527
528    type pthread_t_struct is record
529       context    : sigjmp_buf;
530       pbody      : sigjmp_buf;
531       errno      : int;
532       ret        : int;
533       stack_base : System.Address;
534    end record;
535    pragma Convention (C, pthread_t_struct);
536
537    type pthread_t is access all pthread_t_struct;
538
539    type queue_t is record
540       head : System.Address;
541       tail : System.Address;
542    end record;
543    pragma Convention (C, queue_t);
544
545    type pthread_mutex_t is record
546       queue                 : queue_t;
547       lock                  : plain_char;
548       owner                 : System.Address;
549       flags                 : int;
550       prio_ceiling          : int;
551       protocol              : int;
552       prev_max_ceiling_prio : int;
553    end record;
554    pragma Convention (C, pthread_mutex_t);
555
556    type pthread_cond_t is record
557       queue   : queue_t;
558       flags   : int;
559       waiters : int;
560       mutex   : System.Address;
561    end record;
562    pragma Convention (C, pthread_cond_t);
563
564    type pthread_key_t is new int;
565
566 end System.OS_Interface;