2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / s-osinte-darwin.ads
blobd53e2c43dcabb9ec575f356288c3d7dd7959c4bf
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-2008, 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 ------------------------------------------------------------------------------
35 -- This is Darwin pthreads version of this package
37 -- This package includes all direct interfaces to OS services that are needed
38 -- by the tasking run-time (libgnarl).
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.
43 with Interfaces.C;
45 package System.OS_Interface is
46 pragma Preelaborate;
48 subtype int is Interfaces.C.int;
49 subtype short is Interfaces.C.short;
50 subtype long is Interfaces.C.long;
51 subtype unsigned is Interfaces.C.unsigned;
52 subtype unsigned_short is Interfaces.C.unsigned_short;
53 subtype unsigned_long is Interfaces.C.unsigned_long;
54 subtype unsigned_char is Interfaces.C.unsigned_char;
55 subtype plain_char is Interfaces.C.plain_char;
56 subtype size_t is Interfaces.C.size_t;
58 -----------
59 -- Errno --
60 -----------
62 function errno return int;
63 pragma Import (C, errno, "__get_errno");
65 EINTR : constant := 4;
66 ENOMEM : constant := 12;
67 EINVAL : constant := 22;
68 EAGAIN : constant := 35;
69 ETIMEDOUT : constant := 60;
71 -------------
72 -- Signals --
73 -------------
75 Max_Interrupt : constant := 31;
76 type Signal is new int range 0 .. Max_Interrupt;
77 for Signal'Size use int'Size;
79 SIGHUP : constant := 1; -- hangup
80 SIGINT : constant := 2; -- interrupt (rubout)
81 SIGQUIT : constant := 3; -- quit (ASCD FS)
82 SIGILL : constant := 4; -- illegal instruction (not reset)
83 SIGTRAP : constant := 5; -- trace trap (not reset)
84 SIGIOT : constant := 6; -- IOT instruction
85 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
86 SIGEMT : constant := 7; -- EMT instruction
87 SIGFPE : constant := 8; -- floating point exception
88 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
89 SIGBUS : constant := 10; -- bus error
90 SIGSEGV : constant := 11; -- segmentation violation
91 SIGSYS : constant := 12; -- bad argument to system call
92 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
93 SIGALRM : constant := 14; -- alarm clock
94 SIGTERM : constant := 15; -- software termination signal from kill
95 SIGURG : constant := 16; -- urgent condition on IO channel
96 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
97 SIGTSTP : constant := 18; -- user stop requested from tty
98 SIGCONT : constant := 19; -- stopped process has been continued
99 SIGCHLD : constant := 20; -- child status change
100 SIGTTIN : constant := 21; -- background tty read attempted
101 SIGTTOU : constant := 22; -- background tty write attempted
102 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
103 SIGXCPU : constant := 24; -- CPU time limit exceeded
104 SIGXFSZ : constant := 25; -- filesize limit exceeded
105 SIGVTALRM : constant := 26; -- virtual timer expired
106 SIGPROF : constant := 27; -- profiling timer expired
107 SIGWINCH : constant := 28; -- window size change
108 SIGINFO : constant := 29; -- information request
109 SIGUSR1 : constant := 30; -- user defined signal 1
110 SIGUSR2 : constant := 31; -- user defined signal 2
112 SIGADAABORT : constant := SIGTERM;
113 -- Change this if you want to use another signal for task abort.
114 -- SIGTERM might be a good one.
116 type Signal_Set is array (Natural range <>) of Signal;
118 Unmasked : constant Signal_Set :=
119 (SIGTTIN, SIGTTOU, SIGSTOP, SIGTSTP);
121 Reserved : constant Signal_Set :=
122 (SIGKILL, SIGSTOP);
124 type sigset_t is private;
126 function sigaddset (set : access sigset_t; sig : Signal) return int;
127 pragma Import (C, sigaddset, "sigaddset");
129 function sigdelset (set : access sigset_t; sig : Signal) return int;
130 pragma Import (C, sigdelset, "sigdelset");
132 function sigfillset (set : access sigset_t) return int;
133 pragma Import (C, sigfillset, "sigfillset");
135 function sigismember (set : access sigset_t; sig : Signal) return int;
136 pragma Import (C, sigismember, "sigismember");
138 function sigemptyset (set : access sigset_t) return int;
139 pragma Import (C, sigemptyset, "sigemptyset");
141 type siginfo_t is private;
142 type ucontext_t is private;
144 type Signal_Handler is access procedure
145 (signo : Signal;
146 info : access siginfo_t;
147 context : access ucontext_t);
149 type struct_sigaction is record
150 sa_handler : System.Address;
151 sa_mask : sigset_t;
152 sa_flags : int;
153 end record;
154 pragma Convention (C, struct_sigaction);
155 type struct_sigaction_ptr is access all struct_sigaction;
157 SIG_BLOCK : constant := 1;
158 SIG_UNBLOCK : constant := 2;
159 SIG_SETMASK : constant := 3;
161 SIG_DFL : constant := 0;
162 SIG_IGN : constant := 1;
164 SA_SIGINFO : constant := 16#0040#;
165 SA_ONSTACK : constant := 16#0001#;
167 function sigaction
168 (sig : Signal;
169 act : struct_sigaction_ptr;
170 oact : struct_sigaction_ptr) return int;
171 pragma Import (C, sigaction, "sigaction");
173 ----------
174 -- Time --
175 ----------
177 Time_Slice_Supported : constant Boolean := True;
178 -- Indicates whether time slicing is supported
180 type timespec is private;
182 type clockid_t is private;
184 CLOCK_REALTIME : constant clockid_t;
186 function clock_gettime
187 (clock_id : clockid_t;
188 tp : access timespec) return int;
190 function To_Duration (TS : timespec) return Duration;
191 pragma Inline (To_Duration);
193 function To_Timespec (D : Duration) return timespec;
194 pragma Inline (To_Timespec);
196 type struct_timeval is private;
198 function To_Duration (TV : struct_timeval) return Duration;
199 pragma Inline (To_Duration);
201 function To_Timeval (D : Duration) return struct_timeval;
202 pragma Inline (To_Timeval);
204 -------------------------
205 -- Priority Scheduling --
206 -------------------------
208 SCHED_OTHER : constant := 1;
209 SCHED_RR : constant := 2;
210 SCHED_FIFO : constant := 4;
212 function To_Target_Priority
213 (Prio : System.Any_Priority) return Interfaces.C.int;
214 -- Maps System.Any_Priority to a POSIX priority
216 -------------
217 -- Process --
218 -------------
220 type pid_t is private;
222 function kill (pid : pid_t; sig : Signal) return int;
223 pragma Import (C, kill, "kill");
225 function getpid return pid_t;
226 pragma Import (C, getpid, "getpid");
228 ---------
229 -- LWP --
230 ---------
232 function lwp_self return System.Address;
233 pragma Import (C, lwp_self, "pthread_self");
234 -- lwp_self does not exist on this thread library, revert to pthread_self
235 -- which is the closest approximation (with getpid). This function is
236 -- needed to share 7staprop.adb across POSIX-like targets.
238 -------------
239 -- Threads --
240 -------------
242 type Thread_Body is access
243 function (arg : System.Address) return System.Address;
244 pragma Convention (C, Thread_Body);
246 type pthread_t is private;
247 subtype Thread_Id is pthread_t;
249 type pthread_mutex_t is limited private;
250 type pthread_cond_t is limited private;
251 type pthread_attr_t is limited private;
252 type pthread_mutexattr_t is limited private;
253 type pthread_condattr_t is limited private;
254 type pthread_key_t is private;
256 type pthread_mutex_ptr is access all pthread_mutex_t;
257 type pthread_cond_ptr is access all pthread_cond_t;
259 PTHREAD_CREATE_DETACHED : constant := 2;
261 PTHREAD_SCOPE_PROCESS : constant := 2;
262 PTHREAD_SCOPE_SYSTEM : constant := 1;
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 -- This is a dummy definition, never used (Alternate_Stack_Size is null)
283 Alternate_Stack_Size : constant := 0;
284 -- No alternate signal stack is used on this platform
286 Stack_Base_Available : constant Boolean := False;
287 -- Indicates whether the stack base is available on this target. This
288 -- allows us to share s-osinte.adb between all the FSU run time. Note that
289 -- this value can only be true if pthread_t has a complete definition that
290 -- corresponds exactly to the C header files.
292 function Get_Stack_Base (thread : pthread_t) return System.Address;
293 pragma Inline (Get_Stack_Base);
294 -- returns the stack base of the specified thread. Only call this function
295 -- when Stack_Base_Available is True.
297 function Get_Page_Size return size_t;
298 function Get_Page_Size return System.Address;
299 pragma Import (C, Get_Page_Size, "getpagesize");
300 -- Returns the size of a page, or 0 if this is not relevant on this target
302 PROT_NONE : constant := 0;
303 PROT_READ : constant := 1;
304 PROT_WRITE : constant := 2;
305 PROT_EXEC : constant := 4;
306 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
308 PROT_ON : constant := PROT_NONE;
309 PROT_OFF : constant := PROT_ALL;
311 function mprotect
312 (addr : System.Address;
313 len : size_t;
314 prot : int) return int;
315 pragma Import (C, mprotect);
317 ---------------------------------------
318 -- Nonstandard Thread Initialization --
319 ---------------------------------------
321 procedure pthread_init;
323 -------------------------
324 -- POSIX.1c Section 3 --
325 -------------------------
327 function sigwait (set : access sigset_t; sig : access Signal) return int;
328 pragma Import (C, sigwait, "sigwait");
330 function pthread_kill (thread : pthread_t; sig : Signal) return int;
331 pragma Import (C, pthread_kill, "pthread_kill");
333 function pthread_sigmask
334 (how : int;
335 set : access sigset_t;
336 oset : access sigset_t) return int;
337 pragma Import (C, pthread_sigmask, "pthread_sigmask");
339 --------------------------
340 -- POSIX.1c Section 11 --
341 --------------------------
343 function pthread_mutexattr_init
344 (attr : access pthread_mutexattr_t) return int;
345 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
347 function pthread_mutexattr_destroy
348 (attr : access pthread_mutexattr_t) return int;
349 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
351 function pthread_mutex_init
352 (mutex : access pthread_mutex_t;
353 attr : access pthread_mutexattr_t) return int;
354 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
356 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
357 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
359 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
360 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
362 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
363 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
365 function pthread_condattr_init
366 (attr : access pthread_condattr_t) return int;
367 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
369 function pthread_condattr_destroy
370 (attr : access pthread_condattr_t) return int;
371 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
373 function pthread_cond_init
374 (cond : access pthread_cond_t;
375 attr : access pthread_condattr_t) return int;
376 pragma Import (C, pthread_cond_init, "pthread_cond_init");
378 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
379 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
381 function pthread_cond_signal (cond : access pthread_cond_t) return int;
382 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
384 function pthread_cond_wait
385 (cond : access pthread_cond_t;
386 mutex : access pthread_mutex_t) return int;
387 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
389 function pthread_cond_timedwait
390 (cond : access pthread_cond_t;
391 mutex : access pthread_mutex_t;
392 abstime : access timespec) return int;
393 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
395 Relative_Timed_Wait : constant Boolean := False;
396 -- pthread_cond_timedwait requires an absolute delay time
398 --------------------------
399 -- POSIX.1c Section 13 --
400 --------------------------
402 PTHREAD_PRIO_NONE : constant := 0;
403 PTHREAD_PRIO_INHERIT : constant := 1;
404 PTHREAD_PRIO_PROTECT : constant := 2;
406 function pthread_mutexattr_setprotocol
407 (attr : access pthread_mutexattr_t;
408 protocol : int) return int;
409 pragma Import
410 (C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol");
412 function pthread_mutexattr_setprioceiling
413 (attr : access pthread_mutexattr_t;
414 prioceiling : int) return int;
415 pragma Import
416 (C, pthread_mutexattr_setprioceiling,
417 "pthread_mutexattr_setprioceiling");
419 type padding is array (int range <>) of Interfaces.C.char;
421 type struct_sched_param is record
422 sched_priority : int; -- scheduling priority
423 opaque : padding (1 .. 4);
424 end record;
425 pragma Convention (C, struct_sched_param);
427 function pthread_setschedparam
428 (thread : pthread_t;
429 policy : int;
430 param : access struct_sched_param) return int;
431 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
433 function pthread_attr_setscope
434 (attr : access pthread_attr_t;
435 contentionscope : int) return int;
436 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
438 function pthread_attr_setinheritsched
439 (attr : access pthread_attr_t;
440 inheritsched : int) return int;
441 pragma Import
442 (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
444 function pthread_attr_setschedpolicy
445 (attr : access pthread_attr_t;
446 policy : int) return int;
447 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
449 function sched_yield return int;
451 ---------------------------
452 -- P1003.1c - Section 16 --
453 ---------------------------
455 function pthread_attr_init (attributes : access pthread_attr_t) return int;
456 pragma Import (C, pthread_attr_init, "pthread_attr_init");
458 function pthread_attr_destroy
459 (attributes : access pthread_attr_t) return int;
460 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
462 function pthread_attr_setdetachstate
463 (attr : access pthread_attr_t;
464 detachstate : int) return int;
465 pragma Import
466 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
468 function pthread_attr_setstacksize
469 (attr : access pthread_attr_t;
470 stacksize : size_t) return int;
471 pragma Import
472 (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
474 function pthread_create
475 (thread : access pthread_t;
476 attributes : access pthread_attr_t;
477 start_routine : Thread_Body;
478 arg : System.Address) return int;
479 pragma Import (C, pthread_create, "pthread_create");
481 procedure pthread_exit (status : System.Address);
482 pragma Import (C, pthread_exit, "pthread_exit");
484 function pthread_self return pthread_t;
485 pragma Import (C, pthread_self, "pthread_self");
487 --------------------------
488 -- POSIX.1c Section 17 --
489 --------------------------
491 function pthread_setspecific
492 (key : pthread_key_t;
493 value : System.Address) return int;
494 pragma Import (C, pthread_setspecific, "pthread_setspecific");
496 function pthread_getspecific (key : pthread_key_t) return System.Address;
497 pragma Import (C, pthread_getspecific, "pthread_getspecific");
499 type destructor_pointer is access procedure (arg : System.Address);
500 pragma Convention (C, destructor_pointer);
502 function pthread_key_create
503 (key : access pthread_key_t;
504 destructor : destructor_pointer) return int;
505 pragma Import (C, pthread_key_create, "pthread_key_create");
507 private
509 type sigset_t is new unsigned;
511 type int32_t is new int;
513 type pid_t is new int32_t;
515 type time_t is new long;
517 type timespec is record
518 tv_sec : time_t;
519 tv_nsec : int32_t;
520 end record;
521 pragma Convention (C, timespec);
523 type clockid_t is new int;
524 CLOCK_REALTIME : constant clockid_t := 0;
526 type struct_timeval is record
527 tv_sec : int32_t;
528 tv_usec : int32_t;
529 end record;
530 pragma Convention (C, struct_timeval);
533 -- Darwin specific signal implementation
535 type Pad_Type is array (1 .. 7) of unsigned;
536 type siginfo_t is record
537 si_signo : int; -- signal number
538 si_errno : int; -- errno association
539 si_code : int; -- signal code
540 si_pid : int; -- sending process
541 si_uid : unsigned; -- sender's ruid
542 si_status : int; -- exit value
543 si_addr : System.Address; -- faulting instruction
544 si_value : System.Address; -- signal value
545 si_band : long; -- band event for SIGPOLL
546 pad : Pad_Type; -- RFU
547 end record;
548 pragma Convention (C, siginfo_t);
550 type mcontext_t is new System.Address;
552 type ucontext_t is record
553 uc_onstack : int;
554 uc_sigmask : sigset_t; -- Signal Mask Used By This Context
555 uc_stack : stack_t; -- Stack Used By This Context
556 uc_link : System.Address; -- Pointer To Resuming Context
557 uc_mcsize : size_t; -- Size of The Machine Context
558 uc_mcontext : mcontext_t; -- Machine Specific Context
559 end record;
560 pragma Convention (C, ucontext_t);
563 -- Darwin specific pthread implementation
565 type pthread_t is new System.Address;
567 type pthread_lock_t is new long;
569 type pthread_attr_t is record
570 sig : long;
571 opaque : padding (1 .. 36);
572 end record;
573 pragma Convention (C, pthread_attr_t);
575 type pthread_mutexattr_t is record
576 sig : long;
577 opaque : padding (1 .. 8);
578 end record;
579 pragma Convention (C, pthread_mutexattr_t);
581 type pthread_mutex_t is record
582 sig : long;
583 opaque : padding (1 .. 40);
584 end record;
585 pragma Convention (C, pthread_mutex_t);
587 type pthread_condattr_t is record
588 sig : long;
589 opaque : padding (1 .. 4);
590 end record;
591 pragma Convention (C, pthread_condattr_t);
593 type pthread_cond_t is record
594 sig : long;
595 opaque : padding (1 .. 24);
596 end record;
597 pragma Convention (C, pthread_cond_t);
599 type pthread_once_t is record
600 sig : long;
601 opaque : padding (1 .. 4);
602 end record;
603 pragma Convention (C, pthread_once_t);
605 type pthread_key_t is new unsigned_long;
607 end System.OS_Interface;