OSDN Git Service

* 1aexcept.adb, 1aexcept.ads, 1ic.ads, 1ssecsta.adb,
[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 --          Copyright (C) 1997-2001 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNARL is free software; you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This is a OpenNT/Interix (FSU THREADS) version of this package.
35
36 --  This package encapsulates all direct interfaces to OS services
37 --  that are needed by children of System.
38
39 --  PLEASE DO NOT add any with-clauses to this package
40 --  or remove the pragma Elaborate_Body.
41 --  It is designed to be a bottom-level (leaf) package.
42
43 with Interfaces.C;
44 package System.OS_Interface is
45    pragma Preelaborate;
46
47    pragma Linker_Options ("-lgthreads");
48    pragma Linker_Options ("-lmalloc");
49
50    subtype int            is Interfaces.C.int;
51    subtype short          is Interfaces.C.short;
52    subtype long           is Interfaces.C.long;
53    subtype unsigned       is Interfaces.C.unsigned;
54    subtype unsigned_short is Interfaces.C.unsigned_short;
55    subtype unsigned_long  is Interfaces.C.unsigned_long;
56    subtype unsigned_char  is Interfaces.C.unsigned_char;
57    subtype plain_char     is Interfaces.C.plain_char;
58    subtype size_t         is Interfaces.C.size_t;
59
60    -----------
61    -- Errno --
62    -----------
63
64    function errno return int;
65    pragma Import (C, errno, "__get_errno");
66
67    EAGAIN    : constant := 11;
68    EINTR     : constant := 4;
69    EINVAL    : constant := 22;
70    ENOMEM    : constant := 12;
71    ETIMEDOUT : constant := 60;
72
73    -------------
74    -- Signals --
75    -------------
76
77    Max_Interrupt : constant := 31;
78    type Signal is new int range 0 .. Max_Interrupt;
79    for Signal'Size use int'Size;
80
81    SIGHUP      : constant := 1; --  hangup
82    SIGINT      : constant := 2; --  interrupt (rubout)
83    SIGQUIT     : constant := 3; --  quit (ASCD FS)
84    SIGILL      : constant := 4; --  illegal instruction (not reset)
85    SIGTRAP     : constant := 5; --  trace trap (not reset)
86    SIGIOT      : constant := 6; --  IOT instruction
87    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
88    SIGEMT      : constant := 0; --  EMT instruction
89    SIGFPE      : constant := 8; --  floating point exception
90    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
91    SIGBUS      : constant := 10; --  bus error
92    SIGSEGV     : constant := 11; --  segmentation violation
93    SIGSYS      : constant := 12;  --  bad argument to system call
94    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
95    SIGALRM     : constant := 14; --  alarm clock
96    SIGTERM     : constant := 15; --  software termination signal from kill
97    SIGUSR1     : constant := 16; --  user defined signal 1
98    SIGUSR2     : constant := 17; --  user defined signal 2
99    SIGCLD      : constant := 18; --  alias for SIGCHLD
100    SIGCHLD     : constant := 18; --  child status change
101    SIGPWR      : constant := 0; --  power-fail restart
102    SIGWINCH    : constant := 20; --  window size change
103    SIGURG      : constant := 21; --  urgent condition on IO channel
104    SIGPOLL     : constant := 22; --  pollable event occurred
105    SIGIO       : constant := 19; --  I/O possible (Solaris SIGPOLL alias)
106    SIGSTOP     : constant := 23; --  stop (cannot be caught or ignored)
107    SIGTSTP     : constant := 24; --  user stop requested from tty
108    SIGCONT     : constant := 25; --  stopped process has been continued
109    SIGTTIN     : constant := 26; --  background tty read attempted
110    SIGTTOU     : constant := 27; --  background tty write attempted
111    SIGVTALRM   : constant := 28; --  virtual timer expired
112    SIGPROF     : constant := 29; --  profiling timer expired
113    SIGXCPU     : constant := 30; --  CPU time limit exceeded
114    SIGXFSZ     : constant := 31; --  filesize limit exceeded
115
116    SIGADAABORT : constant := SIGABRT;
117
118    type Signal_Set is array (Natural range <>) of Signal;
119
120    Unmasked    : constant Signal_Set :=
121      (SIGTRAP, SIGALRM, SIGVTALRM, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
122
123    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
124
125    type sigset_t is private;
126
127    function sigaddset (set : access sigset_t; sig : Signal) return int;
128    pragma Import (C, sigaddset, "sigaddset");
129
130    function sigdelset (set : access sigset_t; sig : Signal) return int;
131    pragma Import (C, sigdelset, "sigdelset");
132
133    function sigfillset (set : access sigset_t) return int;
134    pragma Import (C, sigfillset, "sigfillset");
135
136    function sigismember (set : access sigset_t; sig : Signal) return int;
137    pragma Import (C, sigismember, "sigismember");
138
139    function sigemptyset (set : access sigset_t) return int;
140    pragma Import (C, sigemptyset, "sigemptyset");
141
142    type struct_sigaction is record
143       sa_handler  : System.Address;
144       sa_mask     : sigset_t;
145       sa_flags    : int;
146       sa_restorer : System.Address;
147    end record;
148    pragma Convention (C, struct_sigaction);
149    type struct_sigaction_ptr is access all struct_sigaction;
150
151    SIG_BLOCK   : constant := 1;
152    SIG_UNBLOCK : constant := 2;
153    SIG_SETMASK : constant := 3;
154
155    SIG_DFL : constant := 0;
156    SIG_IGN : constant := 1;
157
158    function sigaction
159      (sig  : Signal;
160       act  : struct_sigaction_ptr;
161       oact : struct_sigaction_ptr) return int;
162    --  FSU pthreads redefines sigaction and then uses a special syscall
163    --  API to call the system version. Doing syscalls on OpenNT is very
164    --  difficult, so we rename the pthread version instead.
165    pragma Import (C, sigaction, "pthread_wrapper_sigaction");
166
167    ----------
168    -- Time --
169    ----------
170
171    Time_Slice_Supported : constant Boolean := False;
172    --  Indicates wether time slicing is supported (i.e FSU threads have been
173    --  compiled with DEF_RR)
174
175    type timespec is private;
176
177    type clockid_t is private;
178
179    CLOCK_REALTIME : constant clockid_t;
180
181    function clock_gettime
182      (clock_id : clockid_t;
183       tp       : access timespec) return int;
184    pragma Import (C, clock_gettime, "clock_gettime");
185
186    function To_Duration (TS : timespec) return Duration;
187    pragma Inline (To_Duration);
188
189    function To_Timespec (D : Duration) return timespec;
190    pragma Inline (To_Timespec);
191
192    type struct_timeval is private;
193
194    function To_Duration (TV : struct_timeval) return Duration;
195    pragma Inline (To_Duration);
196
197    function To_Timeval (D : Duration) return struct_timeval;
198    pragma Inline (To_Timeval);
199
200    -------------------------
201    -- Priority Scheduling --
202    -------------------------
203
204    SCHED_FIFO  : constant := 0;
205    SCHED_RR    : constant := 1;
206    SCHED_OTHER : constant := 2;
207
208    -------------
209    -- Process --
210    -------------
211
212    type pid_t is private;
213
214    function kill (pid : pid_t; sig : Signal) return int;
215    pragma Import (C, kill, "kill");
216
217    function getpid return pid_t;
218    pragma Import (C, getpid, "getpid");
219
220    ---------
221    -- LWP --
222    ---------
223
224    function lwp_self return System.Address;
225    --  lwp_self does not exist on this thread library, revert to pthread_self
226    --  which is the closest approximation (with getpid). This function is
227    --  needed to share 7staprop.adb across POSIX-like targets.
228    pragma Import (C, lwp_self, "pthread_self");
229
230    -------------
231    -- Threads --
232    -------------
233
234    type Thread_Body is access
235      function (arg : System.Address) return System.Address;
236    type pthread_t           is private;
237    subtype Thread_Id        is pthread_t;
238
239    type pthread_mutex_t     is limited private;
240    type pthread_cond_t      is limited private;
241    type pthread_attr_t      is limited private;
242    type pthread_mutexattr_t is limited private;
243    type pthread_condattr_t  is limited private;
244    type pthread_key_t       is private;
245
246    PTHREAD_CREATE_DETACHED : constant := 1;
247    PTHREAD_CREATE_JOINABLE : constant := 0;
248
249    -----------
250    -- Stack --
251    -----------
252
253    Stack_Base_Available : constant Boolean := False;
254    --  Indicates wether the stack base is available on this target.
255    --  This allows us to share s-osinte.adb between all the FSU run time.
256    --  Note that this value can only be true if pthread_t has a complete
257    --  definition that corresponds exactly to the C header files.
258
259    function Get_Stack_Base (thread : pthread_t) return Address;
260    pragma Inline (Get_Stack_Base);
261    --  returns the stack base of the specified thread.
262    --  Only call this function when Stack_Base_Available is True.
263
264    function Get_Page_Size return size_t;
265    function Get_Page_Size return Address;
266    pragma Import (C, Get_Page_Size, "getpagesize");
267    --  returns the size of a page, or 0 if this is not relevant on this
268    --  target
269
270    PROT_NONE  : constant := 0;
271    PROT_READ  : constant := 1;
272    PROT_WRITE : constant := 2;
273    PROT_EXEC  : constant := 4;
274    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
275
276    PROT_ON    : constant := PROT_NONE;
277    PROT_OFF   : constant := PROT_ALL;
278
279    function mprotect (addr : Address; len : size_t; prot : int) return int;
280    pragma Import (C, mprotect);
281
282    ---------------------------------------
283    -- Nonstandard Thread Initialization --
284    ---------------------------------------
285
286    procedure pthread_init;
287    --  FSU_THREADS requires pthread_init, which is nonstandard
288    --  and this should be invoked during the elaboration of s-taprop.adb
289    pragma Import (C, pthread_init, "pthread_init");
290
291    -------------------------
292    -- POSIX.1c  Section 3 --
293    -------------------------
294
295    function sigwait
296      (set : access sigset_t;
297       sig : access Signal) return int;
298    --  FSU_THREADS has a nonstandard sigwait
299
300    function pthread_kill
301      (thread : pthread_t;
302       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, "pthread_wrapper_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 Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
320
321    function pthread_mutexattr_destroy
322      (attr : access pthread_mutexattr_t) return int;
323    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
324
325    function pthread_mutex_init
326      (mutex : access pthread_mutex_t;
327       attr  : access pthread_mutexattr_t) return int;
328    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
329
330    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
331    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
332
333    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
334    --  FSU_THREADS has nonstandard pthread_mutex_lock
335
336    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
337    --  FSU_THREADS has nonstandard pthread_mutex_lock
338
339    function pthread_condattr_init
340      (attr : access pthread_condattr_t) return int;
341    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
342
343    function pthread_condattr_destroy
344      (attr : access pthread_condattr_t) return int;
345    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
346
347    function pthread_cond_init
348      (cond : access pthread_cond_t;
349       attr : access pthread_condattr_t) return int;
350    pragma Import (C, pthread_cond_init, "pthread_cond_init");
351
352    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
353    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
354
355    function pthread_cond_signal (cond : access pthread_cond_t) return int;
356    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
357
358    function pthread_cond_wait
359      (cond  : access pthread_cond_t;
360       mutex : access pthread_mutex_t) return int;
361    --  FSU_THREADS has a nonstandard pthread_cond_wait
362
363    function pthread_cond_timedwait
364      (cond    : access pthread_cond_t;
365       mutex   : access pthread_mutex_t;
366       abstime : access timespec) return int;
367    --  FSU_THREADS has a nonstandard pthread_cond_timedwait
368
369    Relative_Timed_Wait : constant Boolean := False;
370    --  pthread_cond_timedwait requires an absolute delay time
371
372    --------------------------
373    -- POSIX.1c  Section 13 --
374    --------------------------
375
376    PTHREAD_PRIO_NONE    : constant := 0;
377    PTHREAD_PRIO_PROTECT : constant := 2;
378    PTHREAD_PRIO_INHERIT : constant := 1;
379
380    function pthread_mutexattr_setprotocol
381      (attr     : access pthread_mutexattr_t;
382       protocol : int) return int;
383    pragma Import (C, pthread_mutexattr_setprotocol);
384
385    function pthread_mutexattr_setprioceiling
386      (attr     : access pthread_mutexattr_t;
387       prioceiling : int) return int;
388    pragma Import
389      (C, pthread_mutexattr_setprioceiling,
390       "pthread_mutexattr_setprio_ceiling");
391
392    type struct_sched_param is record
393       sched_priority : int;  --  scheduling priority
394    end record;
395
396    function pthread_setschedparam
397      (thread : pthread_t;
398       policy : int;
399       param  : access struct_sched_param) return int;
400    --  FSU_THREADS does not have pthread_setschedparam
401
402    function pthread_attr_setscope
403      (attr            : access pthread_attr_t;
404       contentionscope : int) return int;
405    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
406
407    function pthread_attr_setinheritsched
408      (attr         : access pthread_attr_t;
409       inheritsched : int) return int;
410    pragma Import (C, pthread_attr_setinheritsched);
411
412    function pthread_attr_setschedpolicy
413      (attr   : access pthread_attr_t;
414       policy : int) return int;
415    pragma Import
416     (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
417
418    function sched_yield return int;
419    --  FSU_THREADS does not have sched_yield;
420
421    ---------------------------
422    -- P1003.1c - Section 16 --
423    ---------------------------
424
425    function pthread_attr_init (attributes : access pthread_attr_t) return int;
426    pragma Import (C, pthread_attr_init, "pthread_attr_init");
427
428    function pthread_attr_destroy
429      (attributes : access pthread_attr_t) return int;
430    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
431
432    function pthread_attr_setdetachstate
433      (attr        : access pthread_attr_t;
434       detachstate : int) return int;
435    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
436
437    function pthread_attr_setstacksize
438      (attr      : access pthread_attr_t;
439       stacksize : size_t) return int;
440    pragma Import (C, pthread_attr_setstacksize);
441
442    function pthread_create
443      (thread        : access pthread_t;
444       attributes    : access pthread_attr_t;
445       start_routine : Thread_Body;
446       arg           : System.Address) return int;
447    pragma Import (C, pthread_create, "pthread_create");
448
449    procedure pthread_exit (status : System.Address);
450    pragma Import (C, pthread_exit, "pthread_exit");
451
452    function pthread_self return pthread_t;
453    pragma Import (C, pthread_self, "pthread_self");
454
455    --------------------------
456    -- POSIX.1c  Section 17 --
457    --------------------------
458
459    function pthread_setspecific
460      (key   : pthread_key_t;
461       value : System.Address) return  int;
462    pragma Import (C, pthread_setspecific, "pthread_setspecific");
463
464    function pthread_getspecific (key : pthread_key_t) return System.Address;
465    --  FSU_THREADS has a nonstandard pthread_getspecific
466
467    type destructor_pointer is access procedure (arg : System.Address);
468
469    function pthread_key_create
470      (key        : access pthread_key_t;
471       destructor : destructor_pointer) return int;
472    pragma Import (C, pthread_key_create, "pthread_key_create");
473
474 private
475
476    type sigset_t is new unsigned_long;
477    pragma Convention (C, sigset_t);
478
479    type pid_t is new int;
480
481    subtype time_t is long;
482
483    type timespec is record
484       tv_sec  : time_t;
485       tv_nsec : long;
486    end record;
487    pragma Convention (C, timespec);
488
489    type clockid_t is new int;
490    CLOCK_REALTIME : constant clockid_t := 0;
491
492    type struct_timeval is record
493       tv_sec  : time_t;
494       tv_usec : long;
495    end record;
496    pragma Convention (C, struct_timeval);
497
498    type pthread_attr_t is record
499       flags           : int;
500       stacksize       : int;
501       contentionscope : int;
502       inheritsched    : int;
503       detachstate     : int;
504       sched           : int;
505       prio            : int;
506       starttime       : timespec;
507       deadline        : timespec;
508       period          : timespec;
509    end record;
510    pragma Convention (C_Pass_By_Copy, pthread_attr_t);
511
512    type pthread_condattr_t is record
513       flags : int;
514    end record;
515    pragma Convention (C, pthread_condattr_t);
516
517    type pthread_mutexattr_t is record
518       flags        : int;
519       prio_ceiling : int;
520       protocol     : int;
521    end record;
522    pragma Convention (C, pthread_mutexattr_t);
523
524    type sigjmp_buf is array (Integer range 0 .. 17) of int;
525
526    type pthread_t_struct is record
527       context    : sigjmp_buf;
528       pbody      : sigjmp_buf;
529       errno      : int;
530       ret        : int;
531       stack_base : System.Address;
532    end record;
533    pragma Convention (C, pthread_t_struct);
534
535    type pthread_t is access all pthread_t_struct;
536
537    type queue_t is record
538       head : System.Address;
539       tail : System.Address;
540    end record;
541    pragma Convention (C, queue_t);
542
543    type pthread_mutex_t is record
544       queue                 : queue_t;
545       lock                  : plain_char;
546       owner                 : System.Address;
547       flags                 : int;
548       prio_ceiling          : int;
549       protocol              : int;
550       prev_max_ceiling_prio : int;
551    end record;
552    pragma Convention (C, pthread_mutex_t);
553
554    type pthread_cond_t is record
555       queue   : queue_t;
556       flags   : int;
557       waiters : int;
558       mutex   : System.Address;
559    end record;
560    pragma Convention (C, pthread_cond_t);
561
562    type pthread_key_t is new int;
563
564 end System.OS_Interface;