* lto.c (do_stream_out): Add PART parameter; open dump file.
[official-gcc.git] / gcc / ada / libgnarl / s-osinte__kfreebsd-gnu.ads
blob408187314995038d37fc8bd3be26d7bf8e73a45d
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 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2018, 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 the GNU/kFreeBSD (POSIX Threads) version of this package
35 -- This package encapsulates all direct interfaces to OS services
36 -- that are needed by children of System.
38 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 -- Preelaborate. This package is designed to be a bottom-level (leaf) package
41 with Interfaces.C;
42 with Unchecked_Conversion;
44 package System.OS_Interface is
45 pragma Preelaborate;
47 pragma Linker_Options ("-lpthread");
49 subtype int is Interfaces.C.int;
50 subtype char is Interfaces.C.char;
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;
60 -----------
61 -- Errno --
62 -----------
64 function errno return int;
65 pragma Import (C, errno, "__get_errno");
67 EAGAIN : constant := 35;
68 EINTR : constant := 4;
69 EINVAL : constant := 22;
70 ENOMEM : constant := 12;
71 EPERM : constant := 1;
72 ETIMEDOUT : constant := 60;
74 -------------
75 -- Signals --
76 -------------
78 Max_Interrupt : constant := 128;
79 type Signal is new int range 0 .. Max_Interrupt;
80 for Signal'Size use int'Size;
82 SIGHUP : constant := 1; -- hangup
83 SIGINT : constant := 2; -- interrupt (rubout)
84 SIGQUIT : constant := 3; -- quit (ASCD FS)
85 SIGILL : constant := 4; -- illegal instruction (not reset)
86 SIGTRAP : constant := 5; -- trace trap (not reset)
87 SIGIOT : constant := 6; -- IOT instruction
88 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
89 SIGEMT : constant := 7; -- EMT instruction
90 SIGFPE : constant := 8; -- floating point exception
91 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
92 SIGBUS : constant := 10; -- bus error
93 SIGSEGV : constant := 11; -- segmentation violation
94 SIGSYS : constant := 12; -- bad argument to system call
95 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
96 SIGALRM : constant := 14; -- alarm clock
97 SIGTERM : constant := 15; -- software termination signal from kill
98 SIGURG : constant := 16; -- urgent condition on IO channel
99 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
100 SIGTSTP : constant := 18; -- user stop requested from tty
101 SIGCONT : constant := 19; -- stopped process has been continued
102 SIGCLD : constant := 20; -- alias for SIGCHLD
103 SIGCHLD : constant := 20; -- child status change
104 SIGTTIN : constant := 21; -- background tty read attempted
105 SIGTTOU : constant := 22; -- background tty write attempted
106 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
107 SIGXCPU : constant := 24; -- CPU time limit exceeded
108 SIGXFSZ : constant := 25; -- filesize limit exceeded
109 SIGVTALRM : constant := 26; -- virtual timer expired
110 SIGPROF : constant := 27; -- profiling timer expired
111 SIGWINCH : constant := 28; -- window size change
112 SIGINFO : constant := 29; -- information request (NetBSD/FreeBSD)
113 SIGUSR1 : constant := 30; -- user defined signal 1
114 SIGUSR2 : constant := 31; -- user defined signal 2
115 SIGLTHRRES : constant := 32; -- GNU/LinuxThreads restart signal
116 SIGLTHRCAN : constant := 33; -- GNU/LinuxThreads cancel signal
117 SIGLTHRDBG : constant := 34; -- GNU/LinuxThreads debugger signal
119 SIGADAABORT : constant := SIGABRT;
120 -- Change this if you want to use another signal for task abort.
121 -- SIGTERM might be a good one.
123 type Signal_Set is array (Natural range <>) of Signal;
125 Unmasked : constant Signal_Set := (
126 SIGTRAP,
127 -- To enable debugging on multithreaded applications, mark SIGTRAP to
128 -- be kept unmasked.
130 SIGBUS,
132 SIGTTIN, SIGTTOU, SIGTSTP,
133 -- Keep these three signals unmasked so that background processes
134 -- and IO behaves as normal "C" applications
136 SIGPROF,
137 -- To avoid confusing the profiler
139 SIGKILL, SIGSTOP,
140 -- These two signals actually cannot be masked;
141 -- POSIX simply won't allow it.
143 SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG);
144 -- These three signals are used by GNU/LinuxThreads starting from
145 -- glibc 2.1 (future 2.2).
147 Reserved : constant Signal_Set :=
148 -- I am not sure why the following signal is reserved.
149 -- I guess they are not supported by this version of GNU/kFreeBSD.
150 (0 .. 0 => SIGVTALRM);
152 type sigset_t is private;
154 function sigaddset (set : access sigset_t; sig : Signal) return int;
155 pragma Import (C, sigaddset, "sigaddset");
157 function sigdelset (set : access sigset_t; sig : Signal) return int;
158 pragma Import (C, sigdelset, "sigdelset");
160 function sigfillset (set : access sigset_t) return int;
161 pragma Import (C, sigfillset, "sigfillset");
163 function sigismember (set : access sigset_t; sig : Signal) return int;
164 pragma Import (C, sigismember, "sigismember");
166 function sigemptyset (set : access sigset_t) return int;
167 pragma Import (C, sigemptyset, "sigemptyset");
169 -- sigcontext is architecture dependent, so define it private
170 type struct_sigcontext is private;
172 type struct_sigaction is record
173 sa_handler : System.Address;
174 sa_flags : int;
175 sa_mask : sigset_t;
176 end record;
177 pragma Convention (C, struct_sigaction);
179 type struct_sigaction_ptr is access all struct_sigaction;
181 SIG_BLOCK : constant := 1;
182 SIG_UNBLOCK : constant := 2;
183 SIG_SETMASK : constant := 3;
185 SIG_DFL : constant := 0;
186 SIG_IGN : constant := 1;
188 SA_SIGINFO : constant := 16#0040#;
189 SA_ONSTACK : constant := 16#0001#;
191 function sigaction
192 (sig : Signal;
193 act : struct_sigaction_ptr;
194 oact : struct_sigaction_ptr) return int;
195 pragma Import (C, sigaction, "sigaction");
197 ----------
198 -- Time --
199 ----------
201 Time_Slice_Supported : constant Boolean := True;
202 -- Indicates whether time slicing is supported (i.e SCHED_RR is supported)
204 type timespec is private;
206 function nanosleep (rqtp, rmtp : access timespec) return int;
207 pragma Import (C, nanosleep, "nanosleep");
209 type clockid_t is private;
211 CLOCK_REALTIME : constant clockid_t;
213 function clock_gettime
214 (clock_id : clockid_t;
215 tp : access timespec)
216 return int;
217 pragma Import (C, clock_gettime, "clock_gettime");
219 function clock_getres
220 (clock_id : clockid_t;
221 res : access timespec) return int;
222 pragma Import (C, clock_getres, "clock_getres");
224 function To_Duration (TS : timespec) return Duration;
225 pragma Inline (To_Duration);
227 function To_Timespec (D : Duration) return timespec;
228 pragma Inline (To_Timespec);
230 function sysconf (name : int) return long;
231 pragma Import (C, sysconf);
233 SC_CLK_TCK : constant := 2;
234 SC_NPROCESSORS_ONLN : constant := 84;
236 -------------------------
237 -- Priority Scheduling --
238 -------------------------
240 SCHED_FIFO : constant := 1;
241 SCHED_OTHER : constant := 2;
242 SCHED_RR : constant := 3;
244 function To_Target_Priority
245 (Prio : System.Any_Priority) return Interfaces.C.int;
246 -- Maps System.Any_Priority to a POSIX priority.
248 -------------
249 -- Process --
250 -------------
252 type pid_t is private;
254 function kill (pid : pid_t; sig : Signal) return int;
255 pragma Import (C, kill, "kill");
257 function getpid return pid_t;
258 pragma Import (C, getpid, "getpid");
260 ---------
261 -- LWP --
262 ---------
264 function lwp_self return System.Address;
265 -- lwp_self does not exist on this thread library, revert to pthread_self
266 -- which is the closest approximation (with getpid). This function is
267 -- needed to share 7staprop.adb across POSIX-like targets.
268 pragma Import (C, lwp_self, "pthread_self");
270 -------------
271 -- Threads --
272 -------------
274 type Thread_Body is access
275 function (arg : System.Address) return System.Address;
276 pragma Convention (C, Thread_Body);
278 function Thread_Body_Access is new
279 Unchecked_Conversion (System.Address, Thread_Body);
281 type pthread_t is new unsigned_long;
282 subtype Thread_Id is pthread_t;
284 function To_pthread_t is new Unchecked_Conversion
285 (unsigned_long, pthread_t);
287 type pthread_mutex_t is limited private;
288 type pthread_cond_t is limited private;
289 type pthread_attr_t is limited private;
290 type pthread_mutexattr_t is limited private;
291 type pthread_condattr_t is limited private;
292 type pthread_key_t is private;
294 PTHREAD_CREATE_DETACHED : constant := 1;
295 PTHREAD_CREATE_JOINABLE : constant := 0;
297 PTHREAD_SCOPE_PROCESS : constant := 0;
298 PTHREAD_SCOPE_SYSTEM : constant := 2;
300 -- Read/Write lock not supported on kfreebsd. To add support both types
301 -- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
302 -- with the associated routines pthread_rwlock_[init/destroy] and
303 -- pthread_rwlock_[rdlock/wrlock/unlock].
305 subtype pthread_rwlock_t is pthread_mutex_t;
306 subtype pthread_rwlockattr_t is pthread_mutexattr_t;
308 -----------
309 -- Stack --
310 -----------
312 type stack_t is record
313 ss_sp : System.Address;
314 ss_size : size_t;
315 ss_flags : int;
316 end record;
317 pragma Convention (C, stack_t);
319 function sigaltstack
320 (ss : not null access stack_t;
321 oss : access stack_t) return int;
322 pragma Import (C, sigaltstack, "sigaltstack");
324 Alternate_Stack : aliased System.Address;
325 -- This is a dummy definition, never used (Alternate_Stack_Size is null)
327 Alternate_Stack_Size : constant := 0;
328 -- No alternate signal stack is used on this platform
330 Stack_Base_Available : constant Boolean := False;
331 -- Indicates whether the stack base is available on this target
333 function Get_Stack_Base (thread : pthread_t) return Address;
334 pragma Inline (Get_Stack_Base);
335 -- returns the stack base of the specified thread. Only call this function
336 -- when Stack_Base_Available is True.
338 function Get_Page_Size return int;
339 pragma Import (C, Get_Page_Size, "getpagesize");
340 -- Returns the size of a page
342 PROT_NONE : constant := 0;
343 PROT_READ : constant := 1;
344 PROT_WRITE : constant := 2;
345 PROT_EXEC : constant := 4;
346 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
347 PROT_ON : constant := PROT_NONE;
348 PROT_OFF : constant := PROT_ALL;
350 function mprotect (addr : Address; len : size_t; prot : int) return int;
351 pragma Import (C, mprotect);
353 ---------------------------------------
354 -- Nonstandard Thread Initialization --
355 ---------------------------------------
357 procedure pthread_init;
358 pragma Inline (pthread_init);
359 -- This is a dummy procedure to share some GNULLI files
361 -------------------------
362 -- POSIX.1c Section 3 --
363 -------------------------
365 function sigwait (set : access sigset_t; sig : access Signal) return int;
366 pragma Import (C, sigwait, "sigwait");
368 function pthread_kill (thread : pthread_t; sig : Signal) return int;
369 pragma Import (C, pthread_kill, "pthread_kill");
371 function pthread_sigmask
372 (how : int;
373 set : access sigset_t;
374 oset : access sigset_t) return int;
375 pragma Import (C, pthread_sigmask, "pthread_sigmask");
377 --------------------------
378 -- POSIX.1c Section 11 --
379 --------------------------
381 function pthread_mutexattr_init
382 (attr : access pthread_mutexattr_t) return int;
383 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
385 function pthread_mutexattr_destroy
386 (attr : access pthread_mutexattr_t) return int;
387 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
389 function pthread_mutex_init
390 (mutex : access pthread_mutex_t;
391 attr : access pthread_mutexattr_t) return int;
392 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
394 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
395 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
397 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
398 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
400 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
401 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
403 function pthread_condattr_init
404 (attr : access pthread_condattr_t) return int;
405 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
407 function pthread_condattr_destroy
408 (attr : access pthread_condattr_t) return int;
409 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
411 function pthread_cond_init
412 (cond : access pthread_cond_t;
413 attr : access pthread_condattr_t) return int;
414 pragma Import (C, pthread_cond_init, "pthread_cond_init");
416 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
417 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
419 function pthread_cond_signal (cond : access pthread_cond_t) return int;
420 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
422 function pthread_cond_wait
423 (cond : access pthread_cond_t;
424 mutex : access pthread_mutex_t) return int;
425 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
427 function pthread_cond_timedwait
428 (cond : access pthread_cond_t;
429 mutex : access pthread_mutex_t;
430 abstime : access timespec) return int;
431 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
433 --------------------------
434 -- POSIX.1c Section 13 --
435 --------------------------
437 PTHREAD_PRIO_NONE : constant := 0;
438 PTHREAD_PRIO_PROTECT : constant := 2;
439 PTHREAD_PRIO_INHERIT : constant := 1;
441 function pthread_mutexattr_setprotocol
442 (attr : access pthread_mutexattr_t;
443 protocol : int) return int;
444 pragma Import
445 (C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol");
447 function pthread_mutexattr_getprotocol
448 (attr : access pthread_mutexattr_t;
449 protocol : access int) return int;
450 pragma Import
451 (C, pthread_mutexattr_getprotocol, "pthread_mutexattr_getprotocol");
453 function pthread_mutexattr_setprioceiling
454 (attr : access pthread_mutexattr_t;
455 prioceiling : int) return int;
456 pragma Import
457 (C, pthread_mutexattr_setprioceiling,
458 "pthread_mutexattr_setprioceiling");
460 function pthread_mutexattr_getprioceiling
461 (attr : access pthread_mutexattr_t;
462 prioceiling : access int) return int;
463 pragma Import
464 (C, pthread_mutexattr_getprioceiling,
465 "pthread_mutexattr_getprioceiling");
467 type struct_sched_param is record
468 sched_priority : int; -- scheduling priority
469 end record;
470 pragma Convention (C, struct_sched_param);
472 function pthread_setschedparam
473 (thread : pthread_t;
474 policy : int;
475 param : access struct_sched_param) return int;
476 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
478 function pthread_attr_setscope
479 (attr : access pthread_attr_t;
480 contentionscope : int) return int;
481 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
483 function pthread_attr_getscope
484 (attr : access pthread_attr_t;
485 contentionscope : access int) return int;
486 pragma Import (C, pthread_attr_getscope, "pthread_attr_getscope");
488 function pthread_attr_setinheritsched
489 (attr : access pthread_attr_t;
490 inheritsched : int) return int;
491 pragma Import
492 (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
494 function pthread_attr_getinheritsched
495 (attr : access pthread_attr_t;
496 inheritsched : access int) return int;
497 pragma Import
498 (C, pthread_attr_getinheritsched, "pthread_attr_getinheritsched");
500 function pthread_attr_setschedpolicy
501 (attr : access pthread_attr_t;
502 policy : int) return int;
503 pragma Import
504 (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy");
506 function sched_yield return int;
507 pragma Import (C, sched_yield, "sched_yield");
509 ---------------------------
510 -- P1003.1c - Section 16 --
511 ---------------------------
513 function pthread_attr_init
514 (attributes : access pthread_attr_t) return int;
515 pragma Import (C, pthread_attr_init, "pthread_attr_init");
517 function pthread_attr_destroy
518 (attributes : access pthread_attr_t) return int;
519 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
521 function pthread_attr_setdetachstate
522 (attr : access pthread_attr_t;
523 detachstate : int) return int;
524 pragma Import
525 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
527 function pthread_attr_setstacksize
528 (attr : access pthread_attr_t;
529 stacksize : size_t) return int;
530 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
532 function pthread_create
533 (thread : access pthread_t;
534 attributes : access pthread_attr_t;
535 start_routine : Thread_Body;
536 arg : System.Address) return int;
537 pragma Import (C, pthread_create, "pthread_create");
539 procedure pthread_exit (status : System.Address);
540 pragma Import (C, pthread_exit, "pthread_exit");
542 function pthread_self return pthread_t;
543 pragma Import (C, pthread_self, "pthread_self");
545 --------------------------
546 -- POSIX.1c Section 17 --
547 --------------------------
549 function pthread_setspecific
550 (key : pthread_key_t;
551 value : System.Address) return int;
552 pragma Import (C, pthread_setspecific, "pthread_setspecific");
554 function pthread_getspecific (key : pthread_key_t) return System.Address;
555 pragma Import (C, pthread_getspecific, "pthread_getspecific");
557 type destructor_pointer is access procedure (arg : System.Address);
558 pragma Convention (C, destructor_pointer);
560 function pthread_key_create
561 (key : access pthread_key_t;
562 destructor : destructor_pointer) return int;
563 pragma Import (C, pthread_key_create, "pthread_key_create");
565 CPU_SETSIZE : constant := 1_024;
567 type bit_field is array (1 .. CPU_SETSIZE) of Boolean;
568 for bit_field'Size use CPU_SETSIZE;
569 pragma Pack (bit_field);
570 pragma Convention (C, bit_field);
572 type cpu_set_t is record
573 bits : bit_field;
574 end record;
575 pragma Convention (C, cpu_set_t);
577 function pthread_setaffinity_np
578 (thread : pthread_t;
579 cpusetsize : size_t;
580 cpuset : access cpu_set_t) return int;
581 pragma Import (C, pthread_setaffinity_np, "__gnat_pthread_setaffinity_np");
583 private
585 type sigset_t is array (1 .. 4) of unsigned;
587 -- In FreeBSD the component sa_handler turns out to
588 -- be one a union type, and the selector is a macro:
589 -- #define sa_handler __sigaction_u._handler
590 -- #define sa_sigaction __sigaction_u._sigaction
592 -- Should we add a signal_context type here ?
593 -- How could it be done independent of the CPU architecture ?
594 -- sigcontext type is opaque, so it is architecturally neutral.
595 -- It is always passed as an access type, so define it as an empty record
596 -- since the contents are not used anywhere.
597 type struct_sigcontext is null record;
598 pragma Convention (C, struct_sigcontext);
600 type pid_t is new int;
602 type time_t is new long;
604 type timespec is record
605 tv_sec : time_t;
606 tv_nsec : long;
607 end record;
608 pragma Convention (C, timespec);
610 type clockid_t is new int;
611 CLOCK_REALTIME : constant clockid_t := 0;
613 type pthread_attr_t is record
614 detachstate : int;
615 schedpolicy : int;
616 schedparam : struct_sched_param;
617 inheritsched : int;
618 scope : int;
619 guardsize : size_t;
620 stackaddr_set : int;
621 stackaddr : System.Address;
622 stacksize : size_t;
623 end record;
624 pragma Convention (C, pthread_attr_t);
626 type pthread_condattr_t is record
627 dummy : int;
628 end record;
629 pragma Convention (C, pthread_condattr_t);
631 type pthread_mutexattr_t is record
632 mutexkind : int;
633 end record;
634 pragma Convention (C, pthread_mutexattr_t);
636 type struct_pthread_fast_lock is record
637 status : long;
638 spinlock : int;
639 end record;
640 pragma Convention (C, struct_pthread_fast_lock);
642 type pthread_mutex_t is record
643 m_reserved : int;
644 m_count : int;
645 m_owner : System.Address;
646 m_kind : int;
647 m_lock : struct_pthread_fast_lock;
648 end record;
649 pragma Convention (C, pthread_mutex_t);
651 type pthread_cond_t is array (0 .. 47) of unsigned_char;
652 pragma Convention (C, pthread_cond_t);
654 type pthread_key_t is new unsigned;
656 end System.OS_Interface;