1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
8 -- (GNU/Linux-HPPA Version) --
10 -- Copyright (C) 1991-1994, Florida State University --
11 -- Copyright (C) 1995-2008, Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
22 -- Boston, MA 02110-1301, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. --
32 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
34 ------------------------------------------------------------------------------
36 -- This is a GNU/Linux (GNU/LinuxThreads) version of this package
38 -- This package encapsulates all direct interfaces to OS services that are
39 -- needed by the tasking run-time (libgnarl).
41 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
42 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
44 with Ada
.Unchecked_Conversion
;
48 package System
.OS_Interface
is
51 pragma Linker_Options
("-lpthread");
53 subtype int
is Interfaces
.C
.int
;
54 subtype char
is Interfaces
.C
.char
;
55 subtype short
is Interfaces
.C
.short
;
56 subtype long
is Interfaces
.C
.long
;
57 subtype unsigned
is Interfaces
.C
.unsigned
;
58 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
59 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
60 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
61 subtype plain_char
is Interfaces
.C
.plain_char
;
62 subtype size_t
is Interfaces
.C
.size_t
;
68 function errno
return int
;
69 pragma Import
(C
, errno
, "__get_errno");
71 EAGAIN
: constant := 11;
72 EINTR
: constant := 4;
73 EINVAL
: constant := 22;
74 ENOMEM
: constant := 12;
75 EPERM
: constant := 1;
76 ETIMEDOUT
: constant := 238;
82 Max_Interrupt
: constant := 63;
83 type Signal
is new int
range 0 .. Max_Interrupt
;
84 for Signal
'Size use int
'Size;
86 SIGHUP
: constant := 1; -- hangup
87 SIGINT
: constant := 2; -- interrupt (rubout)
88 SIGQUIT
: constant := 3; -- quit (ASCD FS)
89 SIGILL
: constant := 4; -- illegal instruction (not reset)
90 SIGTRAP
: constant := 5; -- trace trap (not reset)
91 SIGIOT
: constant := 6; -- IOT instruction
92 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
93 SIGEMT
: constant := 7; -- EMT
94 SIGFPE
: constant := 8; -- floating point exception
95 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
96 SIGBUS
: constant := 10; -- bus error
97 SIGSEGV
: constant := 11; -- segmentation violation
98 SIGSYS
: constant := 12; -- bad system call
99 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
100 SIGALRM
: constant := 14; -- alarm clock
101 SIGTERM
: constant := 15; -- software termination signal from kill
102 SIGUSR1
: constant := 16; -- user defined signal 1
103 SIGUSR2
: constant := 17; -- user defined signal 2
104 SIGCLD
: constant := 18; -- alias for SIGCHLD
105 SIGCHLD
: constant := 18; -- child status change
106 SIGPWR
: constant := 19; -- power-fail restart
107 SIGVTALRM
: constant := 20; -- virtual timer expired
108 SIGPROF
: constant := 21; -- profiling timer expired
109 SIGPOLL
: constant := 22; -- pollable event occurred
110 SIGIO
: constant := 22; -- I/O now possible (4.2 BSD)
111 SIGWINCH
: constant := 23; -- window size change
112 SIGSTOP
: constant := 24; -- stop (cannot be caught or ignored)
113 SIGTSTP
: constant := 25; -- user stop requested from tty
114 SIGCONT
: constant := 26; -- stopped process has been continued
115 SIGTTIN
: constant := 27; -- background tty read attempted
116 SIGTTOU
: constant := 28; -- background tty write attempted
117 SIGURG
: constant := 29; -- urgent condition on IO channel
118 SIGLOST
: constant := 30; -- File lock lost
119 SIGUNUSED
: constant := 31; -- unused signal (GNU/Linux)
120 SIGXCPU
: constant := 33; -- CPU time limit exceeded
121 SIGXFSZ
: constant := 34; -- filesize limit exceeded
122 SIGSTKFLT
: constant := 36; -- coprocessor stack fault (Linux)
123 SIGLTHRRES
: constant := 37; -- GNU/LinuxThreads restart signal
124 SIGLTHRCAN
: constant := 38; -- GNU/LinuxThreads cancel signal
125 SIGLTHRDBG
: constant := 39; -- GNU/LinuxThreads debugger signal
127 SIGADAABORT
: constant := SIGABRT
;
128 -- Change this if you want to use another signal for task abort.
129 -- SIGTERM might be a good one.
131 type Signal_Set
is array (Natural range <>) of Signal
;
133 Unmasked
: constant Signal_Set
:= (
135 -- To enable debugging on multithreaded applications, mark SIGTRAP to
140 SIGTTIN
, SIGTTOU
, SIGTSTP
,
141 -- Keep these three signals unmasked so that background processes
142 -- and IO behaves as normal "C" applications
145 -- To avoid confusing the profiler
148 -- These two signals actually cannot be masked;
149 -- POSIX simply won't allow it.
151 SIGLTHRRES
, SIGLTHRCAN
, SIGLTHRDBG
);
152 -- These three signals are used by GNU/LinuxThreads starting from
153 -- glibc 2.1 (future 2.2).
155 Reserved
: constant Signal_Set
:=
156 -- I am not sure why the following two signals are reserved.
157 -- I guess they are not supported by this version of GNU/Linux.
158 (SIGVTALRM
, SIGUNUSED
);
160 type sigset_t
is private;
162 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
163 pragma Import
(C
, sigaddset
, "sigaddset");
165 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
166 pragma Import
(C
, sigdelset
, "sigdelset");
168 function sigfillset
(set
: access sigset_t
) return int
;
169 pragma Import
(C
, sigfillset
, "sigfillset");
171 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
172 pragma Import
(C
, sigismember
, "sigismember");
174 function sigemptyset
(set
: access sigset_t
) return int
;
175 pragma Import
(C
, sigemptyset
, "sigemptyset");
177 type union_type_3
is new String (1 .. 116);
178 type siginfo_t
is record
182 X_data
: union_type_3
;
184 pragma Convention
(C
, siginfo_t
);
186 type struct_sigaction
is record
187 sa_handler
: System
.Address
;
188 sa_flags
: unsigned_long
;
191 pragma Convention
(C
, struct_sigaction
);
192 type struct_sigaction_ptr
is access all struct_sigaction
;
194 type Machine_State
is record
202 type Machine_State_Ptr
is access all Machine_State
;
204 SA_SIGINFO
: constant := 16;
206 SIG_BLOCK
: constant := 0;
207 SIG_UNBLOCK
: constant := 1;
208 SIG_SETMASK
: constant := 2;
210 SIG_DFL
: constant := 0;
211 SIG_IGN
: constant := 1;
215 act
: struct_sigaction_ptr
;
216 oact
: struct_sigaction_ptr
) return int
;
217 pragma Import
(C
, sigaction
, "sigaction");
223 type timespec
is private;
225 function To_Duration
(TS
: timespec
) return Duration;
226 pragma Inline
(To_Duration
);
228 function To_Timespec
(D
: Duration) return timespec
;
229 pragma Inline
(To_Timespec
);
231 type struct_timeval
is private;
233 function To_Duration
(TV
: struct_timeval
) return Duration;
234 pragma Inline
(To_Duration
);
236 function To_Timeval
(D
: Duration) return struct_timeval
;
237 pragma Inline
(To_Timeval
);
239 function gettimeofday
240 (tv
: access struct_timeval
;
241 tz
: System
.Address
:= System
.Null_Address
) return int
;
242 pragma Import
(C
, gettimeofday
, "gettimeofday");
244 function sysconf
(name
: int
) return long
;
245 pragma Import
(C
, sysconf
);
247 SC_CLK_TCK
: constant := 2;
248 SC_NPROCESSORS_ONLN
: constant := 84;
250 -------------------------
251 -- Priority Scheduling --
252 -------------------------
254 SCHED_OTHER
: constant := 0;
255 SCHED_FIFO
: constant := 1;
256 SCHED_RR
: constant := 2;
258 function To_Target_Priority
259 (Prio
: System
.Any_Priority
) return Interfaces
.C
.int
;
260 -- Maps System.Any_Priority to a POSIX priority
266 type pid_t
is private;
268 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
269 pragma Import
(C
, kill
, "kill");
271 function getpid
return pid_t
;
272 pragma Import
(C
, getpid
, "getpid");
278 type Thread_Body
is access
279 function (arg
: System
.Address
) return System
.Address
;
280 pragma Convention
(C
, Thread_Body
);
282 function Thread_Body_Access
is new
283 Ada
.Unchecked_Conversion
(System
.Address
, Thread_Body
);
285 type pthread_t
is new unsigned_long
;
286 subtype Thread_Id
is pthread_t
;
288 function To_pthread_t
is new Ada
.Unchecked_Conversion
289 (unsigned_long
, pthread_t
);
291 type pthread_mutex_t
is limited private;
292 type pthread_cond_t
is limited private;
293 type pthread_attr_t
is limited private;
294 type pthread_mutexattr_t
is limited private;
295 type pthread_condattr_t
is limited private;
296 type pthread_key_t
is private;
298 PTHREAD_CREATE_DETACHED
: constant := 1;
304 function Get_Stack_Base
(thread
: pthread_t
) return Address
;
305 pragma Inline
(Get_Stack_Base
);
306 -- This is a dummy procedure to share some GNULLI files
308 ---------------------------------------
309 -- Nonstandard Thread Initialization --
310 ---------------------------------------
312 procedure pthread_init
;
313 pragma Inline
(pthread_init
);
314 -- This is a dummy procedure to share some GNULLI files
316 -------------------------
317 -- POSIX.1c Section 3 --
318 -------------------------
320 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
321 pragma Import
(C
, sigwait
, "sigwait");
323 function pthread_kill
(thread
: pthread_t
; sig
: Signal
) return int
;
324 pragma Import
(C
, pthread_kill
, "pthread_kill");
326 function pthread_sigmask
328 set
: access sigset_t
;
329 oset
: access sigset_t
) return int
;
330 pragma Import
(C
, pthread_sigmask
, "pthread_sigmask");
332 --------------------------
333 -- POSIX.1c Section 11 --
334 --------------------------
336 function pthread_mutexattr_init
337 (attr
: access pthread_mutexattr_t
) return int
;
338 pragma Import
(C
, pthread_mutexattr_init
, "pthread_mutexattr_init");
340 function pthread_mutexattr_destroy
341 (attr
: access pthread_mutexattr_t
) return int
;
342 pragma Import
(C
, pthread_mutexattr_destroy
, "pthread_mutexattr_destroy");
344 function pthread_mutex_init
345 (mutex
: access pthread_mutex_t
;
346 attr
: access pthread_mutexattr_t
) return int
;
347 pragma Import
(C
, pthread_mutex_init
, "pthread_mutex_init");
349 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
350 pragma Import
(C
, pthread_mutex_destroy
, "pthread_mutex_destroy");
352 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
353 pragma Import
(C
, pthread_mutex_lock
, "pthread_mutex_lock");
355 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
356 pragma Import
(C
, pthread_mutex_unlock
, "pthread_mutex_unlock");
358 function pthread_condattr_init
359 (attr
: access pthread_condattr_t
) return int
;
360 pragma Import
(C
, pthread_condattr_init
, "pthread_condattr_init");
362 function pthread_condattr_destroy
363 (attr
: access pthread_condattr_t
) return int
;
364 pragma Import
(C
, pthread_condattr_destroy
, "pthread_condattr_destroy");
366 function pthread_cond_init
367 (cond
: access pthread_cond_t
;
368 attr
: access pthread_condattr_t
) return int
;
369 pragma Import
(C
, pthread_cond_init
, "pthread_cond_init");
371 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
372 pragma Import
(C
, pthread_cond_destroy
, "pthread_cond_destroy");
374 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
375 pragma Import
(C
, pthread_cond_signal
, "pthread_cond_signal");
377 function pthread_cond_wait
378 (cond
: access pthread_cond_t
;
379 mutex
: access pthread_mutex_t
) return int
;
380 pragma Import
(C
, pthread_cond_wait
, "pthread_cond_wait");
382 function pthread_cond_timedwait
383 (cond
: access pthread_cond_t
;
384 mutex
: access pthread_mutex_t
;
385 abstime
: access timespec
) return int
;
386 pragma Import
(C
, pthread_cond_timedwait
, "pthread_cond_timedwait");
388 --------------------------
389 -- POSIX.1c Section 13 --
390 --------------------------
392 type struct_sched_param
is record
393 sched_priority
: int
; -- scheduling priority
395 pragma Convention
(C
, struct_sched_param
);
397 function pthread_setschedparam
400 param
: access struct_sched_param
) return int
;
401 pragma Import
(C
, pthread_setschedparam
, "pthread_setschedparam");
403 function pthread_attr_setschedpolicy
404 (attr
: access pthread_attr_t
;
405 policy
: int
) return int
;
407 (C
, pthread_attr_setschedpolicy
, "pthread_attr_setschedpolicy");
409 function sched_yield
return int
;
410 pragma Import
(C
, sched_yield
, "sched_yield");
412 ---------------------------
413 -- P1003.1c - Section 16 --
414 ---------------------------
416 function pthread_attr_init
417 (attributes
: access pthread_attr_t
) return int
;
418 pragma Import
(C
, pthread_attr_init
, "pthread_attr_init");
420 function pthread_attr_destroy
421 (attributes
: access pthread_attr_t
) return int
;
422 pragma Import
(C
, pthread_attr_destroy
, "pthread_attr_destroy");
424 function pthread_attr_setdetachstate
425 (attr
: access pthread_attr_t
;
426 detachstate
: int
) return int
;
428 (C
, pthread_attr_setdetachstate
, "pthread_attr_setdetachstate");
430 function pthread_attr_setstacksize
431 (attr
: access pthread_attr_t
;
432 stacksize
: size_t
) return int
;
433 pragma Import
(C
, pthread_attr_setstacksize
, "pthread_attr_setstacksize");
435 function pthread_create
436 (thread
: access pthread_t
;
437 attributes
: access pthread_attr_t
;
438 start_routine
: Thread_Body
;
439 arg
: System
.Address
) return int
;
440 pragma Import
(C
, pthread_create
, "pthread_create");
442 procedure pthread_exit
(status
: System
.Address
);
443 pragma Import
(C
, pthread_exit
, "pthread_exit");
445 function pthread_self
return pthread_t
;
446 pragma Import
(C
, pthread_self
, "pthread_self");
448 --------------------------
449 -- POSIX.1c Section 17 --
450 --------------------------
452 function pthread_setspecific
453 (key
: pthread_key_t
;
454 value
: System
.Address
) return int
;
455 pragma Import
(C
, pthread_setspecific
, "pthread_setspecific");
457 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
458 pragma Import
(C
, pthread_getspecific
, "pthread_getspecific");
460 type destructor_pointer
is access procedure (arg
: System
.Address
);
461 pragma Convention
(C
, destructor_pointer
);
463 function pthread_key_create
464 (key
: access pthread_key_t
;
465 destructor
: destructor_pointer
) return int
;
466 pragma Import
(C
, pthread_key_create
, "pthread_key_create");
468 CPU_SETSIZE
: constant := 1_024
;
470 type bit_field
is array (1 .. CPU_SETSIZE
) of Boolean;
471 for bit_field
'Size use CPU_SETSIZE
;
472 pragma Pack
(bit_field
);
473 pragma Convention
(C
, bit_field
);
475 type cpu_set_t
is record
478 pragma Convention
(C
, cpu_set_t
);
480 function pthread_setaffinity_np
483 cpuset
: access cpu_set_t
) return int
;
484 pragma Import
(C
, pthread_setaffinity_np
, "__gnat_pthread_setaffinity_np");
488 type sigset_t
is array (0 .. 31) of unsigned_long
;
489 pragma Convention
(C
, sigset_t
);
491 type pid_t
is new int
;
493 type time_t
is new long
;
495 type timespec
is record
499 pragma Convention
(C
, timespec
);
501 type struct_timeval
is record
505 pragma Convention
(C
, struct_timeval
);
507 type pthread_attr_t
is record
510 schedparam
: struct_sched_param
;
515 stackaddr
: System
.Address
;
518 pragma Convention
(C
, pthread_attr_t
);
520 type pthread_condattr_t
is record
523 pragma Convention
(C
, pthread_condattr_t
);
525 type pthread_mutexattr_t
is record
528 pragma Convention
(C
, pthread_mutexattr_t
);
530 type lock_array
is array (1 .. 4) of int
;
531 type atomic_lock_t
is record
534 pragma Convention
(C
, atomic_lock_t
);
535 -- ??? Alignment should be 16 but this is larger than BIGGEST_ALIGNMENT.
536 -- This causes an erroneous pointer value to sometimes be passed to free
537 -- during deallocation. See PR ada/24533 for more details.
538 for atomic_lock_t
'Alignment use 8;
540 type struct_pthread_fast_lock
is record
541 spinlock
: atomic_lock_t
;
544 pragma Convention
(C
, struct_pthread_fast_lock
);
546 type pthread_mutex_t
is record
549 m_owner
: System
.Address
;
551 m_lock
: struct_pthread_fast_lock
;
553 pragma Convention
(C
, pthread_mutex_t
);
555 type pthread_cond_t
is array (0 .. 47) of unsigned_char
;
556 pragma Convention
(C
, pthread_cond_t
);
558 type pthread_key_t
is new unsigned
;
560 end System
.OS_Interface
;