OSDN Git Service

PR c++/9704
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5mosinte.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.       --
31 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a MACOS (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    pragma Linker_Options ("-lgthreads");
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 := 35;
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 := 7; --  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 := 30; --  user defined signal 1
98    SIGUSR2     : constant := 31; --  user defined signal 2
99    SIGCLD      : constant := 20; --  alias for SIGCHLD
100    SIGCHLD     : constant := 20; --  child status change
101    SIGWINCH    : constant := 28; --  window size change
102    SIGURG      : constant := 16; --  urgent condition on IO channel
103    SIGIO       : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
104    SIGSTOP     : constant := 17; --  stop (cannot be caught or ignored)
105    SIGTSTP     : constant := 18; --  user stop requested from tty
106    SIGCONT     : constant := 19; --  stopped process has been continued
107    SIGTTIN     : constant := 21; --  background tty read attempted
108    SIGTTOU     : constant := 22; --  background tty write attempted
109    SIGVTALRM   : constant := 26; --  virtual timer expired
110    SIGPROF     : constant := 27; --  profiling timer expired
111    SIGXCPU     : constant := 24; --  CPU time limit exceeded
112    SIGXFSZ     : constant := 25; --  filesize limit exceeded
113
114    SIGADAABORT : constant := SIGABRT;
115
116    type Signal_Set is array (Natural range <>) of Signal;
117
118    Unmasked    : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT, SIGCHLD);
119    Reserved    : constant Signal_Set := (SIGKILL, SIGSTOP);
120
121    type sigset_t is private;
122
123    function sigaddset (set : access sigset_t; sig : Signal) return int;
124    pragma Import (C, sigaddset, "sigaddset");
125
126    function sigdelset (set : access sigset_t; sig : Signal) return int;
127    pragma Import (C, sigdelset, "sigdelset");
128
129    function sigfillset (set : access sigset_t) return int;
130    pragma Import (C, sigfillset, "sigfillset");
131
132    function sigismember (set : access sigset_t; sig : Signal) return int;
133    pragma Import (C, sigismember, "sigismember");
134
135    function sigemptyset (set : access sigset_t) return int;
136    pragma Import (C, sigemptyset, "sigemptyset");
137
138    type struct_sigaction is record
139       sa_handler : System.Address;
140       sa_mask    : sigset_t;
141       sa_flags   : int;
142    end record;
143    pragma Convention (C, struct_sigaction);
144    type struct_sigaction_ptr is access all struct_sigaction;
145
146    SIG_BLOCK   : constant := 1;
147    SIG_UNBLOCK : constant := 2;
148    SIG_SETMASK : constant := 3;
149
150    SIG_DFL : constant := 0;
151    SIG_IGN : constant := 1;
152
153    function sigaction
154      (sig  : Signal;
155       act  : struct_sigaction_ptr;
156       oact : struct_sigaction_ptr) return int;
157    pragma Import (C, sigaction, "sigaction");
158
159    ----------
160    -- Time --
161    ----------
162
163    Time_Slice_Supported : constant Boolean := False;
164    --  Indicates wether time slicing is supported (i.e FSU threads have been
165    --  compiled with DEF_RR)
166
167    type timespec is private;
168
169    type clockid_t is private;
170
171    CLOCK_REALTIME : constant clockid_t;
172
173    function clock_gettime
174      (clock_id : clockid_t;
175       tp       : access timespec) return int;
176    pragma Import (C, clock_gettime, "clock_gettime");
177
178    function To_Duration (TS : timespec) return Duration;
179    pragma Inline (To_Duration);
180
181    function To_Timespec (D : Duration) return timespec;
182    pragma Inline (To_Timespec);
183
184    type struct_timeval is private;
185
186    function To_Duration (TV : struct_timeval) return Duration;
187    pragma Inline (To_Duration);
188
189    function To_Timeval (D : Duration) return struct_timeval;
190    pragma Inline (To_Timeval);
191
192    -------------------------
193    -- Priority Scheduling --
194    -------------------------
195
196    SCHED_FIFO  : constant := 0;
197    SCHED_RR    : constant := 1;
198    SCHED_OTHER : constant := 2;
199
200    -------------
201    -- Process --
202    -------------
203
204    type pid_t is private;
205
206    function kill (pid : pid_t; sig : Signal) return int;
207    pragma Import (C, kill, "kill");
208
209    function getpid return pid_t;
210    pragma Import (C, getpid, "getpid");
211
212    ---------
213    -- LWP --
214    ---------
215
216    function lwp_self return System.Address;
217    --  lwp_self does not exist on this thread library, revert to pthread_self
218    --  which is the closest approximation (with getpid). This function is
219    --  needed to share 7staprop.adb across POSIX-like targets.
220    pragma Import (C, lwp_self, "pthread_self");
221
222    -------------
223    -- Threads --
224    -------------
225
226    type Thread_Body is access
227      function (arg : System.Address) return System.Address;
228
229    type pthread_t           is private;
230    subtype Thread_Id        is pthread_t;
231
232    type pthread_mutex_t     is limited private;
233    type pthread_cond_t      is limited private;
234    type pthread_attr_t      is limited private;
235    type pthread_mutexattr_t is limited private;
236    type pthread_condattr_t  is limited private;
237    type pthread_key_t       is private;
238
239    PTHREAD_CREATE_DETACHED : constant := 1;
240
241    -----------
242    -- Stack --
243    -----------
244
245    Stack_Base_Available : constant Boolean := False;
246    --  Indicates wether the stack base is available on this target.
247    --  This allows us to share s-osinte.adb between all the FSU run time.
248    --  Note that this value can only be true if pthread_t has a complete
249    --  definition that corresponds exactly to the C header files.
250
251    function Get_Stack_Base (thread : pthread_t) return Address;
252    pragma Inline (Get_Stack_Base);
253    --  returns the stack base of the specified thread.
254    --  Only call this function when Stack_Base_Available is True.
255
256    function Get_Page_Size return size_t;
257    function Get_Page_Size return Address;
258    pragma Import (C, Get_Page_Size, "getpagesize");
259    --  returns the size of a page, or 0 if this is not relevant on this
260    --  target
261
262    PROT_NONE  : constant := 0;
263    PROT_READ  : constant := 1;
264    PROT_WRITE : constant := 2;
265    PROT_EXEC  : constant := 4;
266    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
267
268    PROT_ON    : constant := PROT_NONE;
269    PROT_OFF   : constant := PROT_ALL;
270
271    function mprotect (addr : Address; len : size_t; prot : int) return int;
272    pragma Import (C, mprotect);
273
274    ---------------------------------------
275    -- Nonstandard Thread Initialization --
276    ---------------------------------------
277
278    procedure pthread_init;
279    --  FSU_THREADS requires pthread_init, which is nonstandard
280    --  and this should be invoked during the elaboration of s-taprop.adb
281    pragma Import (C, pthread_init, "pthread_init");
282
283    -------------------------
284    -- POSIX.1c  Section 3 --
285    -------------------------
286
287    function sigwait
288      (set : access sigset_t;
289       sig : access Signal) return int;
290    --  FSU_THREADS has a nonstandard sigwait
291
292    function pthread_kill
293      (thread : pthread_t;
294       sig    : Signal) return int;
295    pragma Import (C, pthread_kill, "pthread_kill");
296
297    type sigset_t_ptr is access all sigset_t;
298
299    function pthread_sigmask
300      (how  : int;
301       set  : sigset_t_ptr;
302       oset : sigset_t_ptr)
303       return int;
304    pragma Import (C, pthread_sigmask, "sigprocmask");
305
306    --------------------------
307    -- POSIX.1c  Section 11 --
308    --------------------------
309
310    function pthread_mutexattr_init
311      (attr : access pthread_mutexattr_t) return int;
312    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
313
314    function pthread_mutexattr_destroy
315      (attr : access pthread_mutexattr_t) return int;
316    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
317
318    function pthread_mutex_init
319      (mutex : access pthread_mutex_t;
320       attr  : access pthread_mutexattr_t) return int;
321    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
322
323    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
324    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
325
326    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
327    --  FSU_THREADS has nonstandard pthread_mutex_lock
328
329    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
330    --  FSU_THREADS has nonstandard pthread_mutex_lock
331
332    function pthread_condattr_init
333      (attr : access pthread_condattr_t) return int;
334    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
335
336    function pthread_condattr_destroy
337      (attr : access pthread_condattr_t) return int;
338    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
339
340    function pthread_cond_init
341      (cond : access pthread_cond_t;
342       attr : access pthread_condattr_t) return int;
343    pragma Import (C, pthread_cond_init, "pthread_cond_init");
344
345    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
346    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
347
348    function pthread_cond_signal (cond : access pthread_cond_t) return int;
349    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
350
351    function pthread_cond_wait
352      (cond  : access pthread_cond_t;
353       mutex : access pthread_mutex_t) return int;
354    --  FSU_THREADS has a nonstandard pthread_cond_wait
355
356    function pthread_cond_timedwait
357      (cond    : access pthread_cond_t;
358       mutex   : access pthread_mutex_t;
359       abstime : access timespec) return int;
360    --  FSU_THREADS has a nonstandard pthread_cond_timedwait
361
362    Relative_Timed_Wait : constant Boolean := False;
363    --  pthread_cond_timedwait requires an absolute delay time
364
365    --------------------------
366    -- POSIX.1c  Section 13 --
367    --------------------------
368
369    PTHREAD_PRIO_NONE    : constant := 0;
370    PTHREAD_PRIO_PROTECT : constant := 2;
371    PTHREAD_PRIO_INHERIT : constant := 1;
372
373    function pthread_mutexattr_setprotocol
374      (attr     : access pthread_mutexattr_t;
375       protocol : int) return int;
376    pragma Import (C, pthread_mutexattr_setprotocol);
377
378    function pthread_mutexattr_setprioceiling
379      (attr     : access pthread_mutexattr_t;
380       prioceiling : int) return int;
381    pragma Import
382      (C, pthread_mutexattr_setprioceiling,
383       "pthread_mutexattr_setprio_ceiling");
384
385    type struct_sched_param is record
386       sched_priority : int;  --  scheduling priority
387    end record;
388
389    function pthread_setschedparam
390      (thread : pthread_t;
391       policy : int;
392       param  : access struct_sched_param) return int;
393    --  FSU_THREADS does not have pthread_setschedparam
394
395    function pthread_attr_setscope
396      (attr            : access pthread_attr_t;
397       contentionscope : int) return int;
398    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
399
400    function pthread_attr_setinheritsched
401      (attr            : access pthread_attr_t;
402       inheritsched : int) return int;
403    pragma Import (C, pthread_attr_setinheritsched);
404
405    function pthread_attr_setschedpolicy
406      (attr   : access pthread_attr_t;
407       policy : int) return int;
408    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
409
410    function pthread_attr_setschedparam
411      (attr        : access pthread_attr_t;
412       sched_param : int) return int;
413    pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam");
414
415    function sched_yield return int;
416    --  FSU_THREADS does not have sched_yield;
417
418    ---------------------------
419    -- P1003.1c - Section 16 --
420    ---------------------------
421
422    function pthread_attr_init (attributes : access pthread_attr_t) return int;
423    pragma Import (C, pthread_attr_init, "pthread_attr_init");
424
425    function pthread_attr_destroy
426      (attributes : access pthread_attr_t) return int;
427    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
428
429    function pthread_attr_setdetachstate
430      (attr        : access pthread_attr_t;
431       detachstate : int) return int;
432    --  FSU_THREADS has a nonstandard pthread_attr_setdetachstate
433
434    function pthread_attr_setstacksize
435      (attr      : access pthread_attr_t;
436       stacksize : size_t) return int;
437    pragma Import (C, pthread_attr_setstacksize);
438
439    function pthread_create
440      (thread        : access pthread_t;
441       attributes    : access pthread_attr_t;
442       start_routine : Thread_Body;
443       arg           : System.Address) return int;
444    pragma Import (C, pthread_create, "pthread_create");
445
446    procedure pthread_exit (status : System.Address);
447    pragma Import (C, pthread_exit, "pthread_exit");
448
449    function pthread_self return pthread_t;
450    pragma Import (C, pthread_self, "pthread_self");
451
452    --------------------------
453    -- POSIX.1c  Section 17 --
454    --------------------------
455
456    function pthread_setspecific
457      (key   : pthread_key_t;
458       value : System.Address) return int;
459    pragma Import (C, pthread_setspecific, "pthread_setspecific");
460
461    function pthread_getspecific (key : pthread_key_t) return System.Address;
462    --  FSU_THREADS has a nonstandard pthread_getspecific
463
464    type destructor_pointer is access procedure (arg : System.Address);
465
466    function pthread_key_create
467      (key        : access pthread_key_t;
468       destructor : destructor_pointer) return int;
469    pragma Import (C, pthread_key_create, "pthread_key_create");
470
471 private
472
473    type sigset_t is new int;
474
475    type pid_t is new int;
476
477    type time_t is new long;
478
479    type timespec is record
480       tv_sec  : time_t;
481       tv_nsec : long;
482    end record;
483    pragma Convention (C, timespec);
484
485    type clockid_t is new int;
486    CLOCK_REALTIME : constant clockid_t := 0;
487
488    type struct_timeval is record
489       tv_sec       : long;
490       tv_usec      : long;
491    end record;
492    pragma Convention (C, struct_timeval);
493
494    type pthread_attr_t is record
495       flags           : int;
496       stacksize       : int;
497       contentionscope : int;
498       inheritsched    : int;
499       detachstate     : int;
500       sched           : int;
501       prio            : int;
502       starttime       : timespec;
503       deadline        : timespec;
504       period          : timespec;
505    end record;
506    pragma Convention (C, pthread_attr_t);
507
508    type pthread_condattr_t is record
509       flags : int;
510    end record;
511    pragma Convention (C, pthread_condattr_t);
512
513    type pthread_mutexattr_t is record
514       flags        : int;
515       prio_ceiling : int;
516       protocol     : int;
517    end record;
518    pragma Convention (C, pthread_mutexattr_t);
519
520    type sigjmp_buf is array (Integer range 0 .. 9) of int;
521
522    type pthread_t_struct is record
523       context    : sigjmp_buf;
524       pbody      : sigjmp_buf;
525       errno      : int;
526       ret        : int;
527       stack_base : System.Address;
528    end record;
529    pragma Convention (C, pthread_t_struct);
530
531    type pthread_t is access all pthread_t_struct;
532
533    type queue_t is record
534       head : System.Address;
535       tail : System.Address;
536    end record;
537    pragma Convention (C, queue_t);
538
539    type pthread_mutex_t is record
540       queue        : queue_t;
541       lock         : plain_char;
542       owner        : System.Address;
543       flags        : int;
544       prio_ceiling : int;
545       protocol     : int;
546       prev_max_ceiling_prio  : int;
547    end record;
548    pragma Convention (C, pthread_mutex_t);
549
550    type pthread_cond_t is record
551       queue   : queue_t;
552       flags   : int;
553       waiters : int;
554       mutex   : System.Address;
555    end record;
556    pragma Convention (C, pthread_cond_t);
557
558    type pthread_key_t is new int;
559
560 end System.OS_Interface;