OSDN Git Service

2007-08-14 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-darwin.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNAT 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-2007, 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,  51  Franklin  Street,  Fifth  Floor, --
21 -- Boston, MA 02110-1301, 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 Darwin pthreads version of this package
36
37 --  This package includes all direct interfaces to OS services that are needed
38 --  by children of System.
39
40 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 --  Elaborate_Body. 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    subtype int            is Interfaces.C.int;
48    subtype short          is Interfaces.C.short;
49    subtype long           is Interfaces.C.long;
50    subtype unsigned       is Interfaces.C.unsigned;
51    subtype unsigned_short is Interfaces.C.unsigned_short;
52    subtype unsigned_long  is Interfaces.C.unsigned_long;
53    subtype unsigned_char  is Interfaces.C.unsigned_char;
54    subtype plain_char     is Interfaces.C.plain_char;
55    subtype size_t         is Interfaces.C.size_t;
56
57    -----------
58    -- Errno --
59    -----------
60
61    function errno return int;
62    pragma Import (C, errno, "__get_errno");
63
64    EINTR     : constant := 4;
65    ENOMEM    : constant := 12;
66    EINVAL    : constant := 22;
67    EAGAIN    : constant := 35;
68    ETIMEDOUT : constant := 60;
69
70    -------------
71    -- Signals --
72    -------------
73
74    Max_Interrupt : constant := 31;
75    type Signal is new int range 0 .. Max_Interrupt;
76    for Signal'Size use int'Size;
77
78    SIGHUP     : constant := 1; --  hangup
79    SIGINT     : constant := 2; --  interrupt (rubout)
80    SIGQUIT    : constant := 3; --  quit (ASCD FS)
81    SIGILL     : constant := 4; --  illegal instruction (not reset)
82    SIGTRAP    : constant := 5; --  trace trap (not reset)
83    SIGIOT     : constant := 6; --  IOT instruction
84    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
85    SIGEMT     : constant := 7; --  EMT instruction
86    SIGFPE     : constant := 8; --  floating point exception
87    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
88    SIGBUS     : constant := 10; --  bus error
89    SIGSEGV    : constant := 11; --  segmentation violation
90    SIGSYS     : constant := 12; --  bad argument to system call
91    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
92    SIGALRM    : constant := 14; --  alarm clock
93    SIGTERM    : constant := 15; --  software termination signal from kill
94    SIGURG     : constant := 16; --  urgent condition on IO channel
95    SIGSTOP    : constant := 17; --  stop (cannot be caught or ignored)
96    SIGTSTP    : constant := 18; --  user stop requested from tty
97    SIGCONT    : constant := 19; --  stopped process has been continued
98    SIGCHLD    : constant := 20; --  child status change
99    SIGTTIN    : constant := 21; --  background tty read attempted
100    SIGTTOU    : constant := 22; --  background tty write attempted
101    SIGIO      : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
102    SIGXCPU    : constant := 24; --  CPU time limit exceeded
103    SIGXFSZ    : constant := 25; --  filesize limit exceeded
104    SIGVTALRM  : constant := 26; --  virtual timer expired
105    SIGPROF    : constant := 27; --  profiling timer expired
106    SIGWINCH   : constant := 28; --  window size change
107    SIGINFO    : constant := 29; --  information request
108    SIGUSR1    : constant := 30; --  user defined signal 1
109    SIGUSR2    : constant := 31; --  user defined signal 2
110
111    SIGADAABORT : constant := SIGTERM;
112    --  Change this if you want to use another signal for task abort.
113    --  SIGTERM might be a good one.
114
115    type Signal_Set is array (Natural range <>) of Signal;
116
117    Unmasked : constant Signal_Set :=
118      (SIGTTIN, SIGTTOU, SIGSTOP, SIGTSTP);
119
120    Reserved : constant Signal_Set :=
121      (SIGKILL, SIGSTOP);
122
123    type sigset_t is private;
124
125    function sigaddset (set : access sigset_t; sig : Signal) return int;
126    pragma Import (C, sigaddset, "sigaddset");
127
128    function sigdelset (set : access sigset_t; sig : Signal) return int;
129    pragma Import (C, sigdelset, "sigdelset");
130
131    function sigfillset (set : access sigset_t) return int;
132    pragma Import (C, sigfillset, "sigfillset");
133
134    function sigismember (set : access sigset_t; sig : Signal) return int;
135    pragma Import (C, sigismember, "sigismember");
136
137    function sigemptyset (set : access sigset_t) return int;
138    pragma Import (C, sigemptyset, "sigemptyset");
139
140    type siginfo_t is private;
141    type ucontext_t is private;
142
143    type Signal_Handler is access procedure
144      (signo   : Signal;
145       info    : access siginfo_t;
146       context : access ucontext_t);
147
148    type struct_sigaction is record
149       sa_handler : System.Address;
150       sa_mask    : sigset_t;
151       sa_flags   : int;
152    end record;
153    pragma Convention (C, struct_sigaction);
154    type struct_sigaction_ptr is access all struct_sigaction;
155
156    SIG_BLOCK   : constant := 1;
157    SIG_UNBLOCK : constant := 2;
158    SIG_SETMASK : constant := 3;
159
160    SIG_DFL : constant := 0;
161    SIG_IGN : constant := 1;
162
163    SA_SIGINFO : constant := 16#0040#;
164
165    function sigaction
166      (sig  : Signal;
167       act  : struct_sigaction_ptr;
168       oact : struct_sigaction_ptr) return int;
169    pragma Import (C, sigaction, "sigaction");
170
171    ----------
172    -- Time --
173    ----------
174
175    Time_Slice_Supported : constant Boolean := True;
176    --  Indicates wether time slicing is supported
177
178    type timespec is private;
179
180    type clockid_t is private;
181
182    CLOCK_REALTIME : constant clockid_t;
183
184    function clock_gettime
185      (clock_id : clockid_t;
186       tp       : access timespec) return int;
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_OTHER : constant := 1;
207    SCHED_RR    : constant := 2;
208    SCHED_FIFO  : constant := 4;
209
210    function To_Target_Priority
211      (Prio : System.Any_Priority) return Interfaces.C.int;
212    --  Maps System.Any_Priority to a POSIX priority
213
214    -------------
215    -- Process --
216    -------------
217
218    type pid_t is private;
219
220    function kill (pid : pid_t; sig : Signal) return int;
221    pragma Import (C, kill, "kill");
222
223    function getpid return pid_t;
224    pragma Import (C, getpid, "getpid");
225
226    ---------
227    -- LWP --
228    ---------
229
230    function lwp_self return System.Address;
231    --  lwp_self does not exist on this thread library, revert to pthread_self
232    --  which is the closest approximation (with getpid). This function is
233    --  needed to share 7staprop.adb across POSIX-like targets.
234    pragma Import (C, lwp_self, "pthread_self");
235
236    -------------
237    -- Threads --
238    -------------
239
240    type Thread_Body is access
241      function (arg : System.Address) return System.Address;
242    type pthread_t           is private;
243    subtype Thread_Id        is pthread_t;
244
245    type pthread_mutex_t     is limited private;
246    type pthread_cond_t      is limited private;
247    type pthread_attr_t      is limited private;
248    type pthread_mutexattr_t is limited private;
249    type pthread_condattr_t  is limited private;
250    type pthread_key_t       is private;
251
252    type pthread_mutex_ptr is access all pthread_mutex_t;
253    type pthread_cond_ptr is access all pthread_cond_t;
254
255    PTHREAD_CREATE_DETACHED : constant := 2;
256
257    PTHREAD_SCOPE_PROCESS : constant := 2;
258    PTHREAD_SCOPE_SYSTEM  : constant := 1;
259
260    -----------
261    -- Stack --
262    -----------
263
264    Stack_Base_Available : constant Boolean := False;
265    --  Indicates wether the stack base is available on this target.
266    --  This allows us to share s-osinte.adb between all the FSU run time.
267    --  Note that this value can only be true if pthread_t has a complete
268    --  definition that corresponds exactly to the C header files.
269
270    function Get_Stack_Base (thread : pthread_t) return System.Address;
271    pragma Inline (Get_Stack_Base);
272    --  returns the stack base of the specified thread.
273    --  Only call this function when Stack_Base_Available is True.
274
275    function Get_Page_Size return size_t;
276    function Get_Page_Size return System.Address;
277    pragma Import (C, Get_Page_Size, "getpagesize");
278    --  returns the size of a page, or 0 if this is not relevant on this
279    --  target
280
281    PROT_NONE  : constant := 0;
282    PROT_READ  : constant := 1;
283    PROT_WRITE : constant := 2;
284    PROT_EXEC  : constant := 4;
285    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
286
287    PROT_ON    : constant := PROT_NONE;
288    PROT_OFF   : constant := PROT_ALL;
289
290    function mprotect (addr : System.Address;
291                       len : size_t;
292                       prot : int) return int;
293    pragma Import (C, mprotect);
294
295    ---------------------------------------
296    -- Nonstandard Thread Initialization --
297    ---------------------------------------
298
299    procedure pthread_init;
300
301    -------------------------
302    -- POSIX.1c  Section 3 --
303    -------------------------
304
305    function sigwait (set : access sigset_t; sig : access Signal) return int;
306    pragma Import (C, sigwait, "sigwait");
307
308    function pthread_kill (thread : pthread_t; sig : Signal) return int;
309    pragma Import (C, pthread_kill, "pthread_kill");
310
311    function pthread_sigmask
312      (how  : int;
313       set  : access sigset_t;
314       oset : access sigset_t) return int;
315    pragma Import (C, pthread_sigmask, "pthread_sigmask");
316
317    --------------------------
318    -- POSIX.1c  Section 11 --
319    --------------------------
320
321    function pthread_mutexattr_init
322      (attr : access pthread_mutexattr_t) return int;
323    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
324
325    function pthread_mutexattr_destroy
326      (attr : access pthread_mutexattr_t) return int;
327    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
328
329    function pthread_mutex_init
330      (mutex : access pthread_mutex_t;
331       attr  : access pthread_mutexattr_t) return int;
332    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
333
334    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
335    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
336
337    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
338    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
339
340    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
341    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
342
343    function pthread_condattr_init
344      (attr : access pthread_condattr_t) return int;
345    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
346
347    function pthread_condattr_destroy
348      (attr : access pthread_condattr_t) return int;
349    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
350
351    function pthread_cond_init
352      (cond : access pthread_cond_t;
353       attr : access pthread_condattr_t) return int;
354    pragma Import (C, pthread_cond_init, "pthread_cond_init");
355
356    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
357    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
358
359    function pthread_cond_signal (cond : access pthread_cond_t) return int;
360    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
361
362    function pthread_cond_wait
363      (cond  : access pthread_cond_t;
364       mutex : access pthread_mutex_t) return int;
365    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
366
367    function pthread_cond_timedwait
368      (cond    : access pthread_cond_t;
369       mutex   : access pthread_mutex_t;
370       abstime : access timespec) return int;
371    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
372
373    Relative_Timed_Wait : constant Boolean := False;
374    --  pthread_cond_timedwait requires an absolute delay time
375
376    --------------------------
377    -- POSIX.1c  Section 13 --
378    --------------------------
379
380    PTHREAD_PRIO_NONE    : constant := 0;
381    PTHREAD_PRIO_INHERIT : constant := 1;
382    PTHREAD_PRIO_PROTECT : constant := 2;
383
384    function pthread_mutexattr_setprotocol
385      (attr     : access pthread_mutexattr_t;
386       protocol : int) return int;
387    pragma Import
388      (C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol");
389
390    function pthread_mutexattr_setprioceiling
391      (attr     : access pthread_mutexattr_t;
392       prioceiling : int) return int;
393    pragma Import
394      (C, pthread_mutexattr_setprioceiling,
395       "pthread_mutexattr_setprioceiling");
396
397    type padding is array (int range <>) of Interfaces.C.char;
398
399    type struct_sched_param is record
400       sched_priority : int;  --  scheduling priority
401       opaque         : padding (1 .. 4);
402    end record;
403    pragma Convention (C, struct_sched_param);
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
420      (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
421
422    function pthread_attr_setschedpolicy
423      (attr   : access pthread_attr_t;
424       policy : int) return int;
425    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
426
427    function sched_yield return int;
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
444      (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
445
446    function pthread_attr_setstacksize
447      (attr      : access pthread_attr_t;
448       stacksize : size_t) return int;
449    pragma Import
450      (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
451
452    function pthread_create
453      (thread        : access pthread_t;
454       attributes    : access pthread_attr_t;
455       start_routine : Thread_Body;
456       arg           : System.Address) return int;
457    pragma Import (C, pthread_create, "pthread_create");
458
459    procedure pthread_exit (status : System.Address);
460    pragma Import (C, pthread_exit, "pthread_exit");
461
462    function pthread_self return pthread_t;
463    pragma Import (C, pthread_self, "pthread_self");
464
465    --------------------------
466    -- POSIX.1c  Section 17 --
467    --------------------------
468
469    function pthread_setspecific
470      (key   : pthread_key_t;
471       value : System.Address) return int;
472    pragma Import (C, pthread_setspecific, "pthread_setspecific");
473
474    function pthread_getspecific (key : pthread_key_t) return System.Address;
475    pragma Import (C, pthread_getspecific, "pthread_getspecific");
476
477    type destructor_pointer is access procedure (arg : System.Address);
478
479    function pthread_key_create
480      (key        : access pthread_key_t;
481       destructor : destructor_pointer) return int;
482    pragma Import (C, pthread_key_create, "pthread_key_create");
483
484 private
485
486    type sigset_t is new unsigned;
487
488    type int32_t is new int;
489
490    type pid_t is new int32_t;
491
492    type time_t is new long;
493
494    type timespec is record
495       tv_sec  : time_t;
496       tv_nsec : int32_t;
497    end record;
498    pragma Convention (C, timespec);
499
500    type clockid_t is new int;
501    CLOCK_REALTIME : constant clockid_t := 0;
502
503    type struct_timeval is record
504       tv_sec  : int32_t;
505       tv_usec : int32_t;
506    end record;
507    pragma Convention (C, struct_timeval);
508
509    --
510    --  Darwin specific signal implementation
511    --
512    type Pad_Type is array (1 .. 7) of unsigned;
513    type siginfo_t is record
514       si_signo  : int;               --  signal number
515       si_errno  : int;               --  errno association
516       si_code   : int;               --  signal code
517       si_pid    : int;               --  sending process
518       si_uid    : unsigned;          --  sender's ruid
519       si_status : int;               --  exit value
520       si_addr   : System.Address;    --  faulting instruction
521       si_value  : System.Address;    --  signal value
522       si_band   : long;              --  band event for SIGPOLL
523       pad       : Pad_Type;          --  RFU
524    end record;
525    pragma Convention (C, siginfo_t);
526
527    type stack_t is record
528       ss_sp    : System.Address;
529       ss_size  : int;
530       ss_flags : int;
531    end record;
532    pragma Convention (C, stack_t);
533
534    type mcontext_t is new System.Address;
535
536    type ucontext_t is record
537       uc_onstack  : int;
538       uc_sigmask  : sigset_t;         --  Signal Mask Used By This Context
539       uc_stack    : stack_t;          --  Stack Used By This Context
540       uc_link     : System.Address;   --  Pointer To Resuming Context
541       uc_mcsize   : size_t;           --  Size of The Machine Context
542       uc_mcontext : mcontext_t;       --  Machine Specific Context
543    end record;
544    pragma Convention (C, ucontext_t);
545
546    --
547    --  Darwin specific pthread implementation
548    --
549    type pthread_t is new System.Address;
550
551    type pthread_lock_t is new long;
552
553    type pthread_attr_t is record
554       sig    : long;
555       opaque : padding (1 .. 36);
556    end record;
557    pragma Convention (C, pthread_attr_t);
558
559    type pthread_mutexattr_t is record
560       sig    : long;
561       opaque : padding (1 .. 8);
562    end record;
563    pragma Convention (C, pthread_mutexattr_t);
564
565    type pthread_mutex_t is record
566       sig    : long;
567       opaque : padding (1 .. 40);
568    end record;
569    pragma Convention (C, pthread_mutex_t);
570
571    type pthread_condattr_t is record
572       sig    : long;
573       opaque : padding (1 .. 4);
574    end record;
575    pragma Convention (C, pthread_condattr_t);
576
577    type pthread_cond_t is record
578       sig    : long;
579       opaque : padding (1 .. 24);
580    end record;
581    pragma Convention (C, pthread_cond_t);
582
583    type pthread_once_t is record
584       sig    : long;
585       opaque : padding (1 .. 4);
586    end record;
587    pragma Convention (C, pthread_once_t);
588
589    type pthread_key_t is new unsigned_long;
590
591 end System.OS_Interface;