OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5dosinte.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) 1992-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.       --
31 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a DOS/DJGPPv2 (FSU THREAD) 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
41 --  or remove the pragma Elaborate_Body.
42 --  It is designed to be a bottom-level (leaf) package.
43
44 with Interfaces.C;
45 package System.OS_Interface is
46    pragma Preelaborate;
47
48    --
49    --  A short name for libgthreads.a to keep Mike Feldman happy.
50    --
51    pragma Linker_Options ("-lgthre");
52
53    subtype int            is Interfaces.C.int;
54    subtype short          is Interfaces.C.short;
55    subtype long           is Interfaces.C.long;
56    subtype unsigned       is Interfaces.C.unsigned;
57    subtype unsigned_short is Interfaces.C.unsigned_short;
58    subtype unsigned_long  is Interfaces.C.unsigned_long;
59    subtype unsigned_char  is Interfaces.C.unsigned_char;
60    subtype plain_char     is Interfaces.C.plain_char;
61    subtype size_t         is Interfaces.C.size_t;
62
63    -----------
64    -- Errno --
65    -----------
66
67    function errno return int;
68    pragma Import (C, errno, "__get_errno");
69
70    EAGAIN : constant := 5;
71    EINTR  : constant := 13;
72    EINVAL : constant := 14;
73    ENOMEM : constant := 25;
74
75    -------------
76    -- Signals --
77    -------------
78
79    Max_Interrupt : constant := 319;
80    type Signal is new int range 0 .. Max_Interrupt;
81
82    SIGHUP  : constant := 294; --  hangup
83    SIGINT  : constant := 295; --  interrupt (rubout)
84    SIGQUIT : constant := 298; --  quit (ASCD FS)
85    SIGILL  : constant := 290; --  illegal instruction (not reset)
86    SIGABRT : constant := 288; --  used by abort
87    SIGFPE  : constant := 289; --  floating point exception
88    SIGKILL : constant := 296; --  kill (cannot be caught or ignored)
89    SIGSEGV : constant := 291; --  segmentation violation
90    SIGPIPE : constant := 297; --  write on a pipe with no one to read it
91    SIGALRM : constant := 293; --  alarm clock
92    SIGTERM : constant := 292; --  software termination signal from kill
93    SIGUSR1 : constant := 299; --  user defined signal 1
94    SIGUSR2 : constant := 300; --  user defined signal 2
95    SIGBUS  : constant := 0;
96
97    SIGADAABORT : constant := SIGABRT;
98
99    type Signal_Set is array (Natural range <>) of Signal;
100
101    Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM);
102    Reserved : constant Signal_Set := (0 .. 0 => SIGSTOP);
103
104    type sigset_t is private;
105
106    function sigaddset (set : access sigset_t; sig : Signal) return int;
107    pragma Import (C, sigaddset, "sigaddset");
108
109    function sigdelset (set : access sigset_t; sig : Signal) return int;
110    pragma Import (C, sigdelset, "sigdelset");
111
112    function sigfillset (set : access sigset_t) return int;
113    pragma Import (C, sigfillset, "sigfillset");
114
115    function sigismember (set : access sigset_t; sig : Signal) return int;
116    pragma Import (C, sigismember, "sigismember");
117
118    function sigemptyset (set : access sigset_t) return int;
119    pragma Import (C, sigemptyset, "sigemptyset");
120
121    type struct_sigaction is record
122       sa_flags   : int;
123       sa_handler : System.Address;
124       sa_mask    : sigset_t;
125    end record;
126    pragma Convention (C, struct_sigaction);
127    type struct_sigaction_ptr is access all struct_sigaction;
128
129    SIG_BLOCK   : constant := 1;
130    SIG_UNBLOCK : constant := 3;
131    SIG_SETMASK : constant := 2;
132
133    SIG_DFL : constant := 0;
134    SIG_IGN : constant := -1;
135
136    function sigaction
137      (sig  : Signal;
138       act  : struct_sigaction_ptr;
139       oact : struct_sigaction_ptr) return int;
140    pragma Import (C, sigaction, "sigaction");
141
142    ----------
143    -- Time --
144    ----------
145
146    Time_Slice_Supported : constant Boolean := False;
147    --  Indicates wether time slicing is supported (i.e FSU threads have been
148    --  compiled with DEF_RR)
149
150    type timespec is private;
151
152    function nanosleep (rqtp, rmtp : access timespec) return int;
153    --  FSU_THREADS has nonstandard nanosleep
154    type clockid_t is private;
155
156    CLOCK_REALTIME : constant clockid_t;
157
158    function clock_gettime
159      (clock_id : clockid_t;
160       tp       : access timespec) return int;
161    pragma Import (C, clock_gettime, "clock_gettime");
162
163    function To_Duration (TS : timespec) return Duration;
164    pragma Inline (To_Duration);
165
166    function To_Timespec (D : Duration) return timespec;
167    pragma Inline (To_Timespec);
168
169    type struct_timeval is private;
170
171    function To_Duration (TV : struct_timeval) return Duration;
172    pragma Inline (To_Duration);
173
174    function To_Timeval (D : Duration) return struct_timeval;
175    pragma Inline (To_Timeval);
176
177    -------------------------
178    -- Priority Scheduling --
179    -------------------------
180
181    SCHED_FIFO  : constant := 0;
182    SCHED_RR    : constant := 1;
183    SCHED_OTHER : constant := 2;
184
185    -------------
186    -- Process --
187    -------------
188
189    type pid_t is private;
190
191    function kill (pid : pid_t; sig : Signal) return int;
192    pragma Import (C, kill, "kill");
193
194    function getpid return pid_t;
195    pragma Import (C, getpid, "getpid");
196
197    ---------
198    -- LWP --
199    ---------
200
201    function lwp_self return System.Address;
202    --  lwp_self does not exist on this thread library, revert to pthread_self
203    --  which is the closest approximation (with getpid). This function is
204    --  needed to share 7staprop.adb across POSIX-like targets.
205    pragma Import (C, lwp_self, "pthread_self");
206
207    -------------
208    -- Threads --
209    -------------
210
211    type Thread_Body is access
212      function (arg : System.Address) return System.Address;
213
214    type pthread_t           is private;
215    subtype Thread_Id        is pthread_t;
216
217    type pthread_mutex_t     is limited private;
218    type pthread_cond_t      is limited private;
219    type pthread_attr_t      is limited private;
220    type pthread_mutexattr_t is limited private;
221    type pthread_condattr_t  is limited private;
222    type pthread_key_t       is private;
223
224    PTHREAD_CREATE_DETACHED : constant := 1;
225
226    -----------
227    -- Stack --
228    -----------
229
230    Stack_Base_Available : constant Boolean := False;
231    --  Indicates wether the stack base is available on this target.
232    --  This allows us to share s-osinte.adb between all the FSU run time.
233    --  Note that this value can only be true if pthread_t has a complete
234    --  definition that corresponds exactly to the C header files.
235
236    function Get_Stack_Base (thread : pthread_t) return Address;
237    pragma Inline (Get_Stack_Base);
238    --  returns the stack base of the specified thread.
239    --  Only call this function when Stack_Base_Available is True.
240
241    function Get_Page_Size return size_t;
242    function Get_Page_Size return Address;
243    pragma Import (C, Get_Page_Size, "getpagesize");
244    --  returns the size of a page, or 0 if this is not relevant on this
245    --  target
246
247    PROT_NONE  : constant := 0;
248    PROT_READ  : constant := 1;
249    PROT_WRITE : constant := 2;
250    PROT_EXEC  : constant := 4;
251    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
252
253    PROT_ON    : constant := PROT_NONE;
254    PROT_OFF   : constant := PROT_ALL;
255
256    function mprotect
257      (addr : Address; len : size_t; prot : int) return int;
258    pragma Import (C, mprotect);
259
260    ---------------------------------------
261    -- Nonstandard Thread Initialization --
262    ---------------------------------------
263
264    procedure pthread_init;
265    --  FSU_THREADS requires pthread_init, which is nonstandard
266    --  and this should be invoked during the elaboration of s-taprop.adb
267    pragma Import (C, pthread_init, "pthread_init");
268
269    -------------------------
270    -- POSIX.1c  Section 3 --
271    -------------------------
272
273    function sigwait (set : access sigset_t; sig : access Signal) return int;
274    --  FSU_THREADS has a nonstandard sigwait
275
276    function pthread_kill (thread : pthread_t; sig : Signal) return int;
277    pragma Import (C, pthread_kill, "pthread_kill");
278
279    type sigset_t_ptr is access all sigset_t;
280
281    function pthread_sigmask
282      (how  : int;
283       set  : sigset_t_ptr;
284       oset : sigset_t_ptr) return int;
285    pragma Import (C, pthread_sigmask, "sigprocmask");
286
287    --------------------------
288    -- POSIX.1c  Section 11 --
289    --------------------------
290
291    function pthread_mutexattr_init
292      (attr : access pthread_mutexattr_t) return int;
293    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
294
295    function pthread_mutexattr_destroy
296      (attr : access pthread_mutexattr_t) return int;
297    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
298
299    function pthread_mutex_init
300      (mutex : access pthread_mutex_t;
301       attr  : access pthread_mutexattr_t) return int;
302    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
303
304    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
305    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
306
307    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
308    --  FSU_THREADS has nonstandard pthread_mutex_lock
309
310    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
311    --  FSU_THREADS has nonstandard pthread_mutex_lock
312
313    function pthread_condattr_init
314      (attr : access pthread_condattr_t) return int;
315    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
316
317    function pthread_condattr_destroy
318      (attr : access pthread_condattr_t) return int;
319    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
320
321    function pthread_cond_init
322      (cond : access pthread_cond_t;
323       attr : access pthread_condattr_t) return int;
324    pragma Import (C, pthread_cond_init, "pthread_cond_init");
325
326    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
327    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
328
329    function pthread_cond_signal (cond : access pthread_cond_t) return int;
330    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
331
332    function pthread_cond_wait
333      (cond  : access pthread_cond_t;
334       mutex : access pthread_mutex_t) return int;
335    --  FSU_THREADS has a nonstandard pthread_cond_wait
336
337    function pthread_cond_timedwait
338      (cond    : access pthread_cond_t;
339       mutex   : access pthread_mutex_t;
340       abstime : access timespec) return int;
341    --  FSU_THREADS has a nonstandard pthread_cond_timedwait
342
343    Relative_Timed_Wait : constant Boolean := False;
344    --  pthread_cond_timedwait requires an absolute delay time
345
346    --------------------------
347    -- POSIX.1c  Section 13 --
348    --------------------------
349
350    PTHREAD_PRIO_NONE    : constant := 0;
351    PTHREAD_PRIO_PROTECT : constant := 2;
352    PTHREAD_PRIO_INHERIT : constant := 1;
353
354    function pthread_mutexattr_setprotocol
355      (attr     : access pthread_mutexattr_t;
356       protocol : int) return int;
357    pragma Import (C, pthread_mutexattr_setprotocol);
358
359    function pthread_mutexattr_setprioceiling
360      (attr     : access pthread_mutexattr_t;
361       prioceiling : int) return int;
362    pragma Import (C, pthread_mutexattr_setprioceiling);
363
364    type struct_sched_param is record
365       sched_priority : int;  --  scheduling priority
366    end record;
367
368    function pthread_setschedparam
369      (thread : pthread_t;
370       policy : int;
371       param  : access struct_sched_param) return int;
372    --  FSU_THREADS does not have pthread_setschedparam
373
374    function pthread_attr_setscope
375      (attr            : access pthread_attr_t;
376       contentionscope : int) return int;
377    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
378
379    function pthread_attr_setinheritsched
380      (attr            : access pthread_attr_t;
381       inheritsched : int) return int;
382    pragma Import (C, pthread_attr_setinheritsched);
383
384    function pthread_attr_setschedpolicy
385      (attr   : access pthread_attr_t;
386       policy : int) return int;
387    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
388
389    function sched_yield return int;
390    --  FSU_THREADS does not have sched_yield;
391
392    ---------------------------
393    -- P1003.1c - Section 16 --
394    ---------------------------
395
396    function pthread_attr_init (attributes : access pthread_attr_t) return int;
397    pragma Import (C, pthread_attr_init);
398
399    function pthread_attr_destroy
400      (attributes : access pthread_attr_t) return int;
401    pragma Import (C, pthread_attr_destroy);
402
403    function pthread_attr_setdetachstate
404      (attr        : access pthread_attr_t;
405       detachstate : int) return int;
406    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
407
408    function pthread_attr_setstacksize
409      (attr      : access pthread_attr_t;
410       stacksize : size_t) return int;
411    pragma Import (C, pthread_attr_setstacksize);
412
413    function pthread_create
414      (thread        : access pthread_t;
415       attributes    : access pthread_attr_t;
416       start_routine : Thread_Body;
417       arg           : System.Address) return int;
418    pragma Import (C, pthread_create);
419
420    procedure pthread_exit (status : System.Address);
421    pragma Import (C, pthread_exit, "pthread_exit");
422
423    function pthread_self return pthread_t;
424    pragma Import (C, pthread_self, "pthread_self");
425
426    --------------------------
427    -- POSIX.1c  Section 17 --
428    --------------------------
429
430    function pthread_setspecific
431      (key   : pthread_key_t;
432       value : System.Address) return  int;
433    pragma Import (C, pthread_setspecific, "pthread_setspecific");
434
435    function pthread_getspecific (key : pthread_key_t) return System.Address;
436    --  FSU_THREADS has a nonstandard pthread_getspecific
437
438    type destructor_pointer is access procedure (arg : System.Address);
439
440    function pthread_key_create
441      (key        : access pthread_key_t;
442       destructor : destructor_pointer) return int;
443    pragma Import (C, pthread_key_create, "pthread_key_create");
444
445 private
446
447    type bits_arr_t is array (Integer range 1 .. 10) of long;
448    type sigset_t is record
449       bits : bits_arr_t;
450    end record;
451
452    type pid_t is new int;
453
454    type time_t is new long;
455
456    type timespec is record
457       tv_sec  : time_t;
458       tv_nsec : long;
459    end record;
460    pragma Convention (C, timespec);
461
462    type clockid_t is new int;
463    CLOCK_REALTIME : constant clockid_t := 0;
464
465    type struct_timeval is record
466       tv_sec  : long;
467       tv_usec : long;
468    end record;
469    pragma Convention (C, struct_timeval);
470
471    type pthread_attr_t is record
472       flags           : int;
473       stacksize       : int;
474       contentionscope : int;
475       inheritsched    : int;
476       detachstate     : int;
477       sched           : int;
478       prio            : int;
479       starttime       : timespec;
480       deadline        : timespec;
481       period          : timespec;
482    end record;
483    pragma Convention (C, pthread_attr_t);
484
485    type pthread_condattr_t is record
486       flags : int;
487    end record;
488    pragma Convention (C, pthread_condattr_t);
489
490    type pthread_mutexattr_t is record
491       flags        : int;
492       prio_ceiling : int;
493       protocol     : int;
494    end record;
495    pragma Convention (C, pthread_mutexattr_t);
496
497    type sigjmp_buf is array (Integer range 0 .. 43) of int;
498
499    type pthread_t_struct is record
500       context    : sigjmp_buf;
501       pbody      : sigjmp_buf;
502       errno      : int;
503       ret        : int;
504       stack_base : System.Address;
505    end record;
506    pragma Convention (C, pthread_t_struct);
507
508    type pthread_t is access all pthread_t_struct;
509
510    type queue_t is record
511       head : System.Address;
512       tail : System.Address;
513    end record;
514    pragma Convention (C, queue_t);
515
516    type pthread_mutex_t is record
517       queue        : queue_t;
518       lock         : plain_char;
519       owner        : System.Address;
520       flags        : int;
521       prio_ceiling : int;
522       protocol     : int;
523       prev_max_ceiling_prio  : int;
524    end record;
525    pragma Convention (C, pthread_mutex_t);
526
527    type pthread_cond_t is record
528       queue   : queue_t;
529       flags   : int;
530       waiters : int;
531       mutex   : System.Address;
532    end record;
533    pragma Convention (C, pthread_cond_t);
534
535    type pthread_key_t is new int;
536
537 end System.OS_Interface;