PR c++/54038
[official-gcc.git] / gcc / ada / s-osinte-darwin.ads
blobff0480379bc3ba834b4bc58da4b8d188927de4e1
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-2011, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT 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 3, or (at your option) any later ver- --
15 -- sion. GNAT 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. --
18 -- --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception, --
21 -- version 3.1, as published by the Free Software Foundation. --
22 -- --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
27 -- --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 -- --
31 ------------------------------------------------------------------------------
33 -- This is Darwin pthreads version of this package
35 -- This package includes all direct interfaces to OS services that are needed
36 -- by the tasking run-time (libgnarl).
38 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 -- Elaborate_Body. It is designed to be a bottom-level (leaf) package.
41 with Interfaces.C;
42 with System.OS_Constants;
44 package System.OS_Interface is
45 pragma Preelaborate;
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;
57 -----------
58 -- Errno --
59 -----------
61 function errno return int;
62 pragma Import (C, errno, "__get_errno");
64 EINTR : constant := 4;
65 ENOMEM : constant := 12;
66 EINVAL : constant := 22;
67 EAGAIN : constant := 35;
68 ETIMEDOUT : constant := 60;
70 -------------
71 -- Signals --
72 -------------
74 Max_Interrupt : constant := 31;
75 type Signal is new int range 0 .. Max_Interrupt;
76 for Signal'Size use int'Size;
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
111 SIGADAABORT : constant := SIGABRT;
112 -- Change this if you want to use another signal for task abort.
113 -- SIGTERM might be a good one.
115 type Signal_Set is array (Natural range <>) of Signal;
117 Unmasked : constant Signal_Set :=
118 (SIGTTIN, SIGTTOU, SIGSTOP, SIGTSTP);
120 Reserved : constant Signal_Set :=
121 (SIGKILL, SIGSTOP);
123 Exception_Signals : constant Signal_Set :=
124 (SIGFPE, SIGILL, SIGSEGV, SIGBUS);
125 -- These signals (when runtime or system) will be caught and converted
126 -- into an Ada exception.
128 type sigset_t is private;
130 function sigaddset (set : access sigset_t; sig : Signal) return int;
131 pragma Import (C, sigaddset, "sigaddset");
133 function sigdelset (set : access sigset_t; sig : Signal) return int;
134 pragma Import (C, sigdelset, "sigdelset");
136 function sigfillset (set : access sigset_t) return int;
137 pragma Import (C, sigfillset, "sigfillset");
139 function sigismember (set : access sigset_t; sig : Signal) return int;
140 pragma Import (C, sigismember, "sigismember");
142 function sigemptyset (set : access sigset_t) return int;
143 pragma Import (C, sigemptyset, "sigemptyset");
145 type siginfo_t is private;
146 type ucontext_t is private;
148 type Signal_Handler is access procedure
149 (signo : Signal;
150 info : access siginfo_t;
151 context : access ucontext_t);
153 type struct_sigaction is record
154 sa_handler : System.Address;
155 sa_mask : sigset_t;
156 sa_flags : int;
157 end record;
158 pragma Convention (C, struct_sigaction);
159 type struct_sigaction_ptr is access all struct_sigaction;
161 SIG_BLOCK : constant := 1;
162 SIG_UNBLOCK : constant := 2;
163 SIG_SETMASK : constant := 3;
165 SIG_DFL : constant := 0;
166 SIG_IGN : constant := 1;
168 SA_SIGINFO : constant := 16#0040#;
169 SA_ONSTACK : constant := 16#0001#;
171 function sigaction
172 (sig : Signal;
173 act : struct_sigaction_ptr;
174 oact : struct_sigaction_ptr) return int;
175 pragma Import (C, sigaction, "sigaction");
177 ----------
178 -- Time --
179 ----------
181 Time_Slice_Supported : constant Boolean := True;
182 -- Indicates whether time slicing is supported
184 type timespec is private;
186 type clockid_t is new int;
188 function clock_gettime
189 (clock_id : clockid_t;
190 tp : access timespec) return int;
192 function To_Duration (TS : timespec) return Duration;
193 pragma Inline (To_Duration);
195 function To_Timespec (D : Duration) return timespec;
196 pragma Inline (To_Timespec);
198 -------------------------
199 -- Priority Scheduling --
200 -------------------------
202 SCHED_OTHER : constant := 1;
203 SCHED_RR : constant := 2;
204 SCHED_FIFO : constant := 4;
206 function To_Target_Priority
207 (Prio : System.Any_Priority) return Interfaces.C.int;
208 -- Maps System.Any_Priority to a POSIX priority
210 -------------
211 -- Process --
212 -------------
214 type pid_t is private;
216 function kill (pid : pid_t; sig : Signal) return int;
217 pragma Import (C, kill, "kill");
219 function getpid return pid_t;
220 pragma Import (C, getpid, "getpid");
222 ---------
223 -- LWP --
224 ---------
226 function lwp_self return System.Address;
227 -- Return the mach thread bound to the current thread. The value is not
228 -- used by the run-time library but made available to debuggers.
230 -------------
231 -- Threads --
232 -------------
234 type Thread_Body is access
235 function (arg : System.Address) return System.Address;
236 pragma Convention (C, Thread_Body);
238 type pthread_t is private;
239 subtype Thread_Id is pthread_t;
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;
248 type pthread_mutex_ptr is access all pthread_mutex_t;
249 type pthread_cond_ptr is access all pthread_cond_t;
251 PTHREAD_CREATE_DETACHED : constant := 2;
253 PTHREAD_SCOPE_PROCESS : constant := 2;
254 PTHREAD_SCOPE_SYSTEM : constant := 1;
256 -- Read/Write lock not supported on Darwin. To add support both types
257 -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
258 -- with the associated routines pthread_rwlock_[init/destroy] and
259 -- pthread_rwlock_[rdlock/wrlock/unlock].
261 subtype pthread_rwlock_t is pthread_mutex_t;
262 subtype pthread_rwlockattr_t is pthread_mutexattr_t;
264 -----------
265 -- Stack --
266 -----------
268 type stack_t is record
269 ss_sp : System.Address;
270 ss_size : size_t;
271 ss_flags : int;
272 end record;
273 pragma Convention (C, stack_t);
275 function sigaltstack
276 (ss : not null access stack_t;
277 oss : access stack_t) return int;
278 pragma Import (C, sigaltstack, "sigaltstack");
280 Alternate_Stack : aliased System.Address;
281 pragma Import (C, Alternate_Stack, "__gnat_alternate_stack");
282 -- The alternate signal stack for stack overflows
284 Alternate_Stack_Size : constant := 32 * 1024;
285 -- This must be in keeping with init.c:__gnat_alternate_stack
287 Stack_Base_Available : constant Boolean := False;
288 -- Indicates whether the stack base is available on this target. This
289 -- allows us to share s-osinte.adb between all the FSU run time. Note that
290 -- this value can only be true if pthread_t has a complete definition that
291 -- corresponds exactly to the C header files.
293 function Get_Stack_Base (thread : pthread_t) return System.Address;
294 pragma Inline (Get_Stack_Base);
295 -- returns the stack base of the specified thread. Only call this function
296 -- when Stack_Base_Available is True.
298 function Get_Page_Size return size_t;
299 function Get_Page_Size return System.Address;
300 pragma Import (C, Get_Page_Size, "getpagesize");
301 -- Returns the size of a page
303 PROT_NONE : constant := 0;
304 PROT_READ : constant := 1;
305 PROT_WRITE : constant := 2;
306 PROT_EXEC : constant := 4;
307 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
309 PROT_ON : constant := PROT_NONE;
310 PROT_OFF : constant := PROT_ALL;
312 function mprotect
313 (addr : System.Address;
314 len : size_t;
315 prot : int) return int;
316 pragma Import (C, mprotect);
318 ---------------------------------------
319 -- Nonstandard Thread Initialization --
320 ---------------------------------------
322 procedure pthread_init;
324 -------------------------
325 -- POSIX.1c Section 3 --
326 -------------------------
328 function sigwait (set : access sigset_t; sig : access Signal) return int;
329 pragma Import (C, sigwait, "sigwait");
331 function pthread_kill (thread : pthread_t; sig : Signal) return int;
332 pragma Import (C, pthread_kill, "pthread_kill");
334 function pthread_sigmask
335 (how : int;
336 set : access sigset_t;
337 oset : access sigset_t) return int;
338 pragma Import (C, pthread_sigmask, "pthread_sigmask");
340 --------------------------
341 -- POSIX.1c Section 11 --
342 --------------------------
344 function pthread_mutexattr_init
345 (attr : access pthread_mutexattr_t) return int;
346 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
348 function pthread_mutexattr_destroy
349 (attr : access pthread_mutexattr_t) return int;
350 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
352 function pthread_mutex_init
353 (mutex : access pthread_mutex_t;
354 attr : access pthread_mutexattr_t) return int;
355 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
357 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
358 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
360 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
361 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
363 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
364 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
366 function pthread_condattr_init
367 (attr : access pthread_condattr_t) return int;
368 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
370 function pthread_condattr_destroy
371 (attr : access pthread_condattr_t) return int;
372 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
374 function pthread_cond_init
375 (cond : access pthread_cond_t;
376 attr : access pthread_condattr_t) return int;
377 pragma Import (C, pthread_cond_init, "pthread_cond_init");
379 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
380 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
382 function pthread_cond_signal (cond : access pthread_cond_t) return int;
383 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
385 function pthread_cond_wait
386 (cond : access pthread_cond_t;
387 mutex : access pthread_mutex_t) return int;
388 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
390 function pthread_cond_timedwait
391 (cond : access pthread_cond_t;
392 mutex : access pthread_mutex_t;
393 abstime : access timespec) return int;
394 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
396 Relative_Timed_Wait : constant Boolean := False;
397 -- pthread_cond_timedwait requires an absolute delay time
399 --------------------------
400 -- POSIX.1c Section 13 --
401 --------------------------
403 PTHREAD_PRIO_NONE : constant := 0;
404 PTHREAD_PRIO_INHERIT : constant := 1;
405 PTHREAD_PRIO_PROTECT : constant := 2;
407 function pthread_mutexattr_setprotocol
408 (attr : access pthread_mutexattr_t;
409 protocol : int) return int;
410 pragma Import
411 (C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol");
413 function pthread_mutexattr_setprioceiling
414 (attr : access pthread_mutexattr_t;
415 prioceiling : int) return int;
416 pragma Import
417 (C, pthread_mutexattr_setprioceiling,
418 "pthread_mutexattr_setprioceiling");
420 type padding is array (int range <>) of Interfaces.C.char;
422 type struct_sched_param is record
423 sched_priority : int; -- scheduling priority
424 opaque : padding (1 .. 4);
425 end record;
426 pragma Convention (C, struct_sched_param);
428 function pthread_setschedparam
429 (thread : pthread_t;
430 policy : int;
431 param : access struct_sched_param) return int;
432 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
434 function pthread_attr_setscope
435 (attr : access pthread_attr_t;
436 contentionscope : int) return int;
437 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
439 function pthread_attr_setinheritsched
440 (attr : access pthread_attr_t;
441 inheritsched : int) return int;
442 pragma Import
443 (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
445 function pthread_attr_setschedpolicy
446 (attr : access pthread_attr_t;
447 policy : int) return int;
448 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
450 function sched_yield return int;
452 ---------------------------
453 -- P1003.1c - Section 16 --
454 ---------------------------
456 function pthread_attr_init (attributes : access pthread_attr_t) return int;
457 pragma Import (C, pthread_attr_init, "pthread_attr_init");
459 function pthread_attr_destroy
460 (attributes : access pthread_attr_t) return int;
461 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
463 function pthread_attr_setdetachstate
464 (attr : access pthread_attr_t;
465 detachstate : int) return int;
466 pragma Import
467 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
469 function pthread_attr_setstacksize
470 (attr : access pthread_attr_t;
471 stacksize : size_t) return int;
472 pragma Import
473 (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
475 function pthread_create
476 (thread : access pthread_t;
477 attributes : access pthread_attr_t;
478 start_routine : Thread_Body;
479 arg : System.Address) return int;
480 pragma Import (C, pthread_create, "pthread_create");
482 procedure pthread_exit (status : System.Address);
483 pragma Import (C, pthread_exit, "pthread_exit");
485 function pthread_self return pthread_t;
486 pragma Import (C, pthread_self, "pthread_self");
488 --------------------------
489 -- POSIX.1c Section 17 --
490 --------------------------
492 function pthread_setspecific
493 (key : pthread_key_t;
494 value : System.Address) return int;
495 pragma Import (C, pthread_setspecific, "pthread_setspecific");
497 function pthread_getspecific (key : pthread_key_t) return System.Address;
498 pragma Import (C, pthread_getspecific, "pthread_getspecific");
500 type destructor_pointer is access procedure (arg : System.Address);
501 pragma Convention (C, destructor_pointer);
503 function pthread_key_create
504 (key : access pthread_key_t;
505 destructor : destructor_pointer) return int;
506 pragma Import (C, pthread_key_create, "pthread_key_create");
508 private
510 type sigset_t is new unsigned;
512 type int32_t is new int;
514 type pid_t is new int32_t;
516 type time_t is new long;
518 type timespec is record
519 tv_sec : time_t;
520 tv_nsec : long;
521 end record;
522 pragma Convention (C, timespec);
525 -- Darwin specific signal implementation
527 type Pad_Type is array (1 .. 7) of unsigned_long;
528 type siginfo_t is record
529 si_signo : int; -- signal number
530 si_errno : int; -- errno association
531 si_code : int; -- signal code
532 si_pid : int; -- sending process
533 si_uid : unsigned; -- sender's ruid
534 si_status : int; -- exit value
535 si_addr : System.Address; -- faulting instruction
536 si_value : System.Address; -- signal value
537 si_band : long; -- band event for SIGPOLL
538 pad : Pad_Type; -- RFU
539 end record;
540 pragma Convention (C, siginfo_t);
542 type mcontext_t is new System.Address;
544 type ucontext_t is record
545 uc_onstack : int;
546 uc_sigmask : sigset_t; -- Signal Mask Used By This Context
547 uc_stack : stack_t; -- Stack Used By This Context
548 uc_link : System.Address; -- Pointer To Resuming Context
549 uc_mcsize : size_t; -- Size of The Machine Context
550 uc_mcontext : mcontext_t; -- Machine Specific Context
551 end record;
552 pragma Convention (C, ucontext_t);
555 -- Darwin specific pthread implementation
557 type pthread_t is new System.Address;
559 type pthread_attr_t is record
560 sig : long;
561 opaque : padding (1 .. System.OS_Constants.PTHREAD_ATTR_SIZE);
562 end record;
563 pragma Convention (C, pthread_attr_t);
565 type pthread_mutexattr_t is record
566 sig : long;
567 opaque : padding (1 .. System.OS_Constants.PTHREAD_MUTEXATTR_SIZE);
568 end record;
569 pragma Convention (C, pthread_mutexattr_t);
571 type pthread_mutex_t is record
572 sig : long;
573 opaque : padding (1 .. System.OS_Constants.PTHREAD_MUTEX_SIZE);
574 end record;
575 pragma Convention (C, pthread_mutex_t);
577 type pthread_condattr_t is record
578 sig : long;
579 opaque : padding (1 .. System.OS_Constants.PTHREAD_CONDATTR_SIZE);
580 end record;
581 pragma Convention (C, pthread_condattr_t);
583 type pthread_cond_t is record
584 sig : long;
585 opaque : padding (1 .. System.OS_Constants.PTHREAD_COND_SIZE);
586 end record;
587 pragma Convention (C, pthread_cond_t);
589 type pthread_once_t is record
590 sig : long;
591 opaque : padding (1 .. System.OS_Constants.PTHREAD_ONCE_SIZE);
592 end record;
593 pragma Convention (C, pthread_once_t);
595 type pthread_key_t is new unsigned_long;
597 end System.OS_Interface;