| 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-2025, 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 |
------------------------------------------------------------------------------ |
| 32 |
|
| 33 |
-- This is the GNU/kFreeBSD (POSIX Threads) version of this package |
| 34 |
|
| 35 |
-- This package encapsulates all direct interfaces to OS services |
| 36 |
-- that are needed by children of System. |
| 37 |
|
| 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 |
| 40 |
|
| 41 |
with Ada.Unchecked_Conversion; |
| 42 |
|
| 43 |
with Interfaces.C; |
| 44 |
|
| 45 |
with System.OS_Locks; |
| 46 |
with System.Parameters; |
| 47 |
|
| 48 |
package System.OS_Interface is |
| 49 |
pragma Preelaborate; |
| 50 |
|
| 51 |
pragma Linker_Options ("-lpthread"); |
| 52 |
|
| 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; |
| 63 |
|
| 64 |
----------- |
| 65 |
-- Errno -- |
| 66 |
----------- |
| 67 |
|
| 68 |
function errno return int; |
| 69 |
pragma Import (C, errno, "__get_errno"); |
| 70 |
|
| 71 |
EAGAIN : constant := 35; |
| 72 |
EINTR : constant := 4; |
| 73 |
EINVAL : constant := 22; |
| 74 |
ENOMEM : constant := 12; |
| 75 |
EPERM : constant := 1; |
| 76 |
ETIMEDOUT : constant := 60; |
| 77 |
|
| 78 |
------------- |
| 79 |
-- Signals -- |
| 80 |
------------- |
| 81 |
|
| 82 |
Max_Interrupt : constant := 128; |
| 83 |
type Signal is new int range 0 .. Max_Interrupt; |
| 84 |
for Signal'Size use int'Size; |
| 85 |
|
| 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 instruction |
| 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 argument to 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 |
SIGURG : constant := 16; -- urgent condition on IO channel |
| 103 |
SIGSTOP : constant := 17; -- stop (cannot be caught or ignored) |
| 104 |
SIGTSTP : constant := 18; -- user stop requested from tty |
| 105 |
SIGCONT : constant := 19; -- stopped process has been continued |
| 106 |
SIGCLD : constant := 20; -- alias for SIGCHLD |
| 107 |
SIGCHLD : constant := 20; -- child status change |
| 108 |
SIGTTIN : constant := 21; -- background tty read attempted |
| 109 |
SIGTTOU : constant := 22; -- background tty write attempted |
| 110 |
SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias) |
| 111 |
SIGXCPU : constant := 24; -- CPU time limit exceeded |
| 112 |
SIGXFSZ : constant := 25; -- filesize limit exceeded |
| 113 |
SIGVTALRM : constant := 26; -- virtual timer expired |
| 114 |
SIGPROF : constant := 27; -- profiling timer expired |
| 115 |
SIGWINCH : constant := 28; -- window size change |
| 116 |
SIGINFO : constant := 29; -- information request (NetBSD/FreeBSD) |
| 117 |
SIGUSR1 : constant := 30; -- user defined signal 1 |
| 118 |
SIGUSR2 : constant := 31; -- user defined signal 2 |
| 119 |
SIGLTHRRES : constant := 32; -- GNU/LinuxThreads restart signal |
| 120 |
SIGLTHRCAN : constant := 33; -- GNU/LinuxThreads cancel signal |
| 121 |
SIGLTHRDBG : constant := 34; -- GNU/LinuxThreads debugger signal |
| 122 |
|
| 123 |
SIGADAABORT : constant := SIGABRT; |
| 124 |
-- Change this if you want to use another signal for task abort. |
| 125 |
-- SIGTERM might be a good one. |
| 126 |
|
| 127 |
type Signal_Set is array (Natural range <>) of Signal; |
| 128 |
|
| 129 |
Unmasked : constant Signal_Set := ( |
| 130 |
SIGTRAP, |
| 131 |
-- To enable debugging on multithreaded applications, mark SIGTRAP to |
| 132 |
-- be kept unmasked. |
| 133 |
|
| 134 |
SIGBUS, |
| 135 |
|
| 136 |
SIGTTIN, SIGTTOU, SIGTSTP, |
| 137 |
-- Keep these three signals unmasked so that background processes |
| 138 |
-- and IO behaves as normal "C" applications |
| 139 |
|
| 140 |
SIGPROF, |
| 141 |
-- To avoid confusing the profiler |
| 142 |
|
| 143 |
SIGKILL, SIGSTOP, |
| 144 |
-- These two signals actually cannot be masked; |
| 145 |
-- POSIX simply won't allow it. |
| 146 |
|
| 147 |
SIGLTHRRES, SIGLTHRCAN, SIGLTHRDBG); |
| 148 |
-- These three signals are used by GNU/LinuxThreads starting from |
| 149 |
-- glibc 2.1 (future 2.2). |
| 150 |
|
| 151 |
Reserved : constant Signal_Set := |
| 152 |
-- I am not sure why the following signal is reserved. |
| 153 |
-- I guess they are not supported by this version of GNU/kFreeBSD. |
| 154 |
(0 .. 0 => SIGVTALRM); |
| 155 |
|
| 156 |
type sigset_t is private; |
| 157 |
|
| 158 |
function sigaddset (set : access sigset_t; sig : Signal) return int; |
| 159 |
pragma Import (C, sigaddset, "sigaddset"); |
| 160 |
|
| 161 |
function sigdelset (set : access sigset_t; sig : Signal) return int; |
| 162 |
pragma Import (C, sigdelset, "sigdelset"); |
| 163 |
|
| 164 |
function sigfillset (set : access sigset_t) return int; |
| 165 |
pragma Import (C, sigfillset, "sigfillset"); |
| 166 |
|
| 167 |
function sigismember (set : access sigset_t; sig : Signal) return int; |
| 168 |
pragma Import (C, sigismember, "sigismember"); |
| 169 |
|
| 170 |
function sigemptyset (set : access sigset_t) return int; |
| 171 |
pragma Import (C, sigemptyset, "sigemptyset"); |
| 172 |
|
| 173 |
-- sigcontext is architecture dependent, so define it private |
| 174 |
type struct_sigcontext is private; |
| 175 |
|
| 176 |
type struct_sigaction is record |
| 177 |
sa_handler : System.Address; |
| 178 |
sa_flags : int; |
| 179 |
sa_mask : sigset_t; |
| 180 |
end record; |
| 181 |
pragma Convention (C, struct_sigaction); |
| 182 |
|
| 183 |
type struct_sigaction_ptr is access all struct_sigaction; |
| 184 |
|
| 185 |
SIG_BLOCK : constant := 1; |
| 186 |
SIG_UNBLOCK : constant := 2; |
| 187 |
SIG_SETMASK : constant := 3; |
| 188 |
|
| 189 |
SIG_DFL : constant := 0; |
| 190 |
SIG_IGN : constant := 1; |
| 191 |
|
| 192 |
SA_SIGINFO : constant := 16#0040#; |
| 193 |
SA_ONSTACK : constant := 16#0001#; |
| 194 |
|
| 195 |
function sigaction |
| 196 |
(sig : Signal; |
| 197 |
act : struct_sigaction_ptr; |
| 198 |
oact : struct_sigaction_ptr) return int; |
| 199 |
pragma Import (C, sigaction, "sigaction"); |
| 200 |
|
| 201 |
---------- |
| 202 |
-- Time -- |
| 203 |
---------- |
| 204 |
|
| 205 |
Time_Slice_Supported : constant Boolean := True; |
| 206 |
-- Indicates whether time slicing is supported (i.e SCHED_RR is supported) |
| 207 |
|
| 208 |
type timespec is private; |
| 209 |
|
| 210 |
function nanosleep (rqtp, rmtp : access timespec) return int; |
| 211 |
pragma Import (C, nanosleep, "nanosleep"); |
| 212 |
|
| 213 |
type clockid_t is new int; |
| 214 |
CLOCK_REALTIME : constant clockid_t := 0; |
| 215 |
|
| 216 |
function clock_gettime |
| 217 |
(clock_id : clockid_t; |
| 218 |
tp : access timespec) |
| 219 |
return int; |
| 220 |
pragma Import (C, clock_gettime, "clock_gettime"); |
| 221 |
|
| 222 |
function clock_getres |
| 223 |
(clock_id : clockid_t; |
| 224 |
res : access timespec) return int; |
| 225 |
pragma Import (C, clock_getres, "clock_getres"); |
| 226 |
|
| 227 |
function To_Duration (TS : timespec) return Duration; |
| 228 |
pragma Inline (To_Duration); |
| 229 |
|
| 230 |
function To_Timespec (D : Duration) return timespec; |
| 231 |
pragma Inline (To_Timespec); |
| 232 |
|
| 233 |
function sysconf (name : int) return long; |
| 234 |
pragma Import (C, sysconf); |
| 235 |
|
| 236 |
SC_CLK_TCK : constant := 2; |
| 237 |
SC_NPROCESSORS_ONLN : constant := 84; |
| 238 |
|
| 239 |
------------------------- |
| 240 |
-- Priority Scheduling -- |
| 241 |
------------------------- |
| 242 |
|
| 243 |
SCHED_FIFO : constant := 1; |
| 244 |
SCHED_OTHER : constant := 2; |
| 245 |
SCHED_RR : constant := 3; |
| 246 |
|
| 247 |
function To_Target_Priority |
| 248 |
(Prio : System.Any_Priority) return Interfaces.C.int; |
| 249 |
-- Maps System.Any_Priority to a POSIX priority. |
| 250 |
|
| 251 |
------------- |
| 252 |
-- Process -- |
| 253 |
------------- |
| 254 |
|
| 255 |
type pid_t is private; |
| 256 |
|
| 257 |
function kill (pid : pid_t; sig : Signal) return int; |
| 258 |
pragma Import (C, kill, "kill"); |
| 259 |
|
| 260 |
function getpid return pid_t; |
| 261 |
pragma Import (C, getpid, "getpid"); |
| 262 |
|
| 263 |
--------- |
| 264 |
-- LWP -- |
| 265 |
--------- |
| 266 |
|
| 267 |
function lwp_self return System.Address; |
| 268 |
-- lwp_self does not exist on this thread library, revert to pthread_self |
| 269 |
-- which is the closest approximation (with getpid). This function is |
| 270 |
-- needed to share 7staprop.adb across POSIX-like targets. |
| 271 |
pragma Import (C, lwp_self, "pthread_self"); |
| 272 |
|
| 273 |
------------- |
| 274 |
-- Threads -- |
| 275 |
------------- |
| 276 |
|
| 277 |
type Thread_Body is access |
| 278 |
function (arg : System.Address) return System.Address; |
| 279 |
pragma Convention (C, Thread_Body); |
| 280 |
|
| 281 |
function Thread_Body_Access is new |
| 282 |
Ada.Unchecked_Conversion (System.Address, Thread_Body); |
| 283 |
|
| 284 |
type pthread_t is new unsigned_long; |
| 285 |
subtype Thread_Id is pthread_t; |
| 286 |
|
| 287 |
function To_pthread_t is new Ada.Unchecked_Conversion |
| 288 |
(unsigned_long, pthread_t); |
| 289 |
|
| 290 |
subtype pthread_mutex_t is System.OS_Locks.pthread_mutex_t; |
| 291 |
type pthread_cond_t is limited private; |
| 292 |
type pthread_attr_t is limited private; |
| 293 |
type pthread_mutexattr_t is limited private; |
| 294 |
type pthread_condattr_t is limited private; |
| 295 |
type pthread_key_t is private; |
| 296 |
|
| 297 |
PTHREAD_CREATE_DETACHED : constant := 1; |
| 298 |
PTHREAD_CREATE_JOINABLE : constant := 0; |
| 299 |
|
| 300 |
PTHREAD_SCOPE_PROCESS : constant := 0; |
| 301 |
PTHREAD_SCOPE_SYSTEM : constant := 2; |
| 302 |
|
| 303 |
-- Read/Write lock not supported on kfreebsd. To add support both types |
| 304 |
-- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined |
| 305 |
-- with the associated routines pthread_rwlock_[init/destroy] and |
| 306 |
-- pthread_rwlock_[rdlock/wrlock/unlock]. |
| 307 |
|
| 308 |
subtype pthread_rwlock_t is pthread_mutex_t; |
| 309 |
subtype pthread_rwlockattr_t is pthread_mutexattr_t; |
| 310 |
|
| 311 |
----------- |
| 312 |
-- Stack -- |
| 313 |
----------- |
| 314 |
|
| 315 |
type stack_t is record |
| 316 |
ss_sp : System.Address; |
| 317 |
ss_size : size_t; |
| 318 |
ss_flags : int; |
| 319 |
end record; |
| 320 |
pragma Convention (C, stack_t); |
| 321 |
|
| 322 |
function sigaltstack |
| 323 |
(ss : not null access stack_t; |
| 324 |
oss : access stack_t) return int; |
| 325 |
pragma Import (C, sigaltstack, "sigaltstack"); |
| 326 |
|
| 327 |
Alternate_Stack : aliased System.Address; |
| 328 |
-- This is a dummy definition, never used (Alternate_Stack_Size is null) |
| 329 |
|
| 330 |
Alternate_Stack_Size : constant := 0; |
| 331 |
-- No alternate signal stack is used on this platform |
| 332 |
|
| 333 |
Stack_Base_Available : constant Boolean := False; |
| 334 |
-- Indicates whether the stack base is available on this target |
| 335 |
|
| 336 |
function Get_Stack_Base (thread : pthread_t) return Address; |
| 337 |
pragma Inline (Get_Stack_Base); |
| 338 |
-- returns the stack base of the specified thread. Only call this function |
| 339 |
-- when Stack_Base_Available is True. |
| 340 |
|
| 341 |
function Get_Page_Size return int; |
| 342 |
pragma Import (C, Get_Page_Size, "getpagesize"); |
| 343 |
-- Returns the size of a page |
| 344 |
|
| 345 |
PROT_NONE : constant := 0; |
| 346 |
PROT_READ : constant := 1; |
| 347 |
PROT_WRITE : constant := 2; |
| 348 |
PROT_EXEC : constant := 4; |
| 349 |
PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC; |
| 350 |
PROT_ON : constant := PROT_NONE; |
| 351 |
PROT_OFF : constant := PROT_ALL; |
| 352 |
|
| 353 |
function mprotect (addr : Address; len : size_t; prot : int) return int; |
| 354 |
pragma Import (C, mprotect); |
| 355 |
|
| 356 |
--------------------------------------- |
| 357 |
-- Nonstandard Thread Initialization -- |
| 358 |
--------------------------------------- |
| 359 |
|
| 360 |
procedure pthread_init; |
| 361 |
pragma Inline (pthread_init); |
| 362 |
-- This is a dummy procedure to share some GNULLI files |
| 363 |
|
| 364 |
------------------------- |
| 365 |
-- POSIX.1c Section 3 -- |
| 366 |
------------------------- |
| 367 |
|
| 368 |
function sigwait (set : access sigset_t; sig : access Signal) return int; |
| 369 |
pragma Import (C, sigwait, "sigwait"); |
| 370 |
|
| 371 |
function pthread_kill (thread : pthread_t; sig : Signal) return int; |
| 372 |
pragma Import (C, pthread_kill, "pthread_kill"); |
| 373 |
|
| 374 |
function pthread_sigmask |
| 375 |
(how : int; |
| 376 |
set : access sigset_t; |
| 377 |
oset : access sigset_t) return int; |
| 378 |
pragma Import (C, pthread_sigmask, "pthread_sigmask"); |
| 379 |
|
| 380 |
-------------------------- |
| 381 |
-- POSIX.1c Section 11 -- |
| 382 |
-------------------------- |
| 383 |
|
| 384 |
function pthread_mutexattr_init |
| 385 |
(attr : access pthread_mutexattr_t) return int; |
| 386 |
pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); |
| 387 |
|
| 388 |
function pthread_mutexattr_destroy |
| 389 |
(attr : access pthread_mutexattr_t) return int; |
| 390 |
pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); |
| 391 |
|
| 392 |
function pthread_mutex_init |
| 393 |
(mutex : access pthread_mutex_t; |
| 394 |
attr : access pthread_mutexattr_t) return int; |
| 395 |
pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); |
| 396 |
|
| 397 |
function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; |
| 398 |
pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); |
| 399 |
|
| 400 |
function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; |
| 401 |
pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); |
| 402 |
|
| 403 |
function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; |
| 404 |
pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); |
| 405 |
|
| 406 |
function pthread_condattr_init |
| 407 |
(attr : access pthread_condattr_t) return int; |
| 408 |
pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); |
| 409 |
|
| 410 |
function pthread_condattr_destroy |
| 411 |
(attr : access pthread_condattr_t) return int; |
| 412 |
pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); |
| 413 |
|
| 414 |
function pthread_cond_init |
| 415 |
(cond : access pthread_cond_t; |
| 416 |
attr : access pthread_condattr_t) return int; |
| 417 |
pragma Import (C, pthread_cond_init, "pthread_cond_init"); |
| 418 |
|
| 419 |
function pthread_cond_destroy (cond : access pthread_cond_t) return int; |
| 420 |
pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); |
| 421 |
|
| 422 |
function pthread_cond_signal (cond : access pthread_cond_t) return int; |
| 423 |
pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); |
| 424 |
|
| 425 |
function pthread_cond_wait |
| 426 |
(cond : access pthread_cond_t; |
| 427 |
mutex : access pthread_mutex_t) return int; |
| 428 |
pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); |
| 429 |
|
| 430 |
function pthread_cond_timedwait |
| 431 |
(cond : access pthread_cond_t; |
| 432 |
mutex : access pthread_mutex_t; |
| 433 |
abstime : access timespec) return int; |
| 434 |
pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); |
| 435 |
|
| 436 |
-------------------------- |
| 437 |
-- POSIX.1c Section 13 -- |
| 438 |
-------------------------- |
| 439 |
|
| 440 |
PTHREAD_PRIO_NONE : constant := 0; |
| 441 |
PTHREAD_PRIO_PROTECT : constant := 2; |
| 442 |
PTHREAD_PRIO_INHERIT : constant := 1; |
| 443 |
|
| 444 |
function pthread_mutexattr_setprotocol |
| 445 |
(attr : access pthread_mutexattr_t; |
| 446 |
protocol : int) return int; |
| 447 |
pragma Import |
| 448 |
(C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol"); |
| 449 |
|
| 450 |
function pthread_mutexattr_getprotocol |
| 451 |
(attr : access pthread_mutexattr_t; |
| 452 |
protocol : access int) return int; |
| 453 |
pragma Import |
| 454 |
(C, pthread_mutexattr_getprotocol, "pthread_mutexattr_getprotocol"); |
| 455 |
|
| 456 |
function pthread_mutexattr_setprioceiling |
| 457 |
(attr : access pthread_mutexattr_t; |
| 458 |
prioceiling : int) return int; |
| 459 |
pragma Import |
| 460 |
(C, pthread_mutexattr_setprioceiling, |
| 461 |
"pthread_mutexattr_setprioceiling"); |
| 462 |
|
| 463 |
function pthread_mutexattr_getprioceiling |
| 464 |
(attr : access pthread_mutexattr_t; |
| 465 |
prioceiling : access int) return int; |
| 466 |
pragma Import |
| 467 |
(C, pthread_mutexattr_getprioceiling, |
| 468 |
"pthread_mutexattr_getprioceiling"); |
| 469 |
|
| 470 |
type struct_sched_param is record |
| 471 |
sched_priority : int; -- scheduling priority |
| 472 |
end record; |
| 473 |
pragma Convention (C, struct_sched_param); |
| 474 |
|
| 475 |
function pthread_setschedparam |
| 476 |
(thread : pthread_t; |
| 477 |
policy : int; |
| 478 |
param : access struct_sched_param) return int; |
| 479 |
pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); |
| 480 |
|
| 481 |
function pthread_attr_setscope |
| 482 |
(attr : access pthread_attr_t; |
| 483 |
contentionscope : int) return int; |
| 484 |
pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); |
| 485 |
|
| 486 |
function pthread_attr_getscope |
| 487 |
(attr : access pthread_attr_t; |
| 488 |
contentionscope : access int) return int; |
| 489 |
pragma Import (C, pthread_attr_getscope, "pthread_attr_getscope"); |
| 490 |
|
| 491 |
function pthread_attr_setinheritsched |
| 492 |
(attr : access pthread_attr_t; |
| 493 |
inheritsched : int) return int; |
| 494 |
pragma Import |
| 495 |
(C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched"); |
| 496 |
|
| 497 |
function pthread_attr_getinheritsched |
| 498 |
(attr : access pthread_attr_t; |
| 499 |
inheritsched : access int) return int; |
| 500 |
pragma Import |
| 501 |
(C, pthread_attr_getinheritsched, "pthread_attr_getinheritsched"); |
| 502 |
|
| 503 |
function pthread_attr_setschedpolicy |
| 504 |
(attr : access pthread_attr_t; |
| 505 |
policy : int) return int; |
| 506 |
pragma Import |
| 507 |
(C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy"); |
| 508 |
|
| 509 |
function sched_yield return int; |
| 510 |
pragma Import (C, sched_yield, "sched_yield"); |
| 511 |
|
| 512 |
--------------------------- |
| 513 |
-- P1003.1c - Section 16 -- |
| 514 |
--------------------------- |
| 515 |
|
| 516 |
function pthread_attr_init |
| 517 |
(attributes : access pthread_attr_t) return int; |
| 518 |
pragma Import (C, pthread_attr_init, "pthread_attr_init"); |
| 519 |
|
| 520 |
function pthread_attr_destroy |
| 521 |
(attributes : access pthread_attr_t) return int; |
| 522 |
pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); |
| 523 |
|
| 524 |
function pthread_attr_setdetachstate |
| 525 |
(attr : access pthread_attr_t; |
| 526 |
detachstate : int) return int; |
| 527 |
pragma Import |
| 528 |
(C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate"); |
| 529 |
|
| 530 |
function pthread_attr_setstacksize |
| 531 |
(attr : access pthread_attr_t; |
| 532 |
stacksize : size_t) return int; |
| 533 |
pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); |
| 534 |
|
| 535 |
function pthread_create |
| 536 |
(thread : access pthread_t; |
| 537 |
attributes : access pthread_attr_t; |
| 538 |
start_routine : Thread_Body; |
| 539 |
arg : System.Address) return int; |
| 540 |
pragma Import (C, pthread_create, "pthread_create"); |
| 541 |
|
| 542 |
procedure pthread_exit (status : System.Address); |
| 543 |
pragma Import (C, pthread_exit, "pthread_exit"); |
| 544 |
|
| 545 |
function pthread_self return pthread_t; |
| 546 |
pragma Import (C, pthread_self, "pthread_self"); |
| 547 |
|
| 548 |
-------------------------- |
| 549 |
-- POSIX.1c Section 17 -- |
| 550 |
-------------------------- |
| 551 |
|
| 552 |
function pthread_setspecific |
| 553 |
(key : pthread_key_t; |
| 554 |
value : System.Address) return int; |
| 555 |
pragma Import (C, pthread_setspecific, "pthread_setspecific"); |
| 556 |
|
| 557 |
function pthread_getspecific (key : pthread_key_t) return System.Address; |
| 558 |
pragma Import (C, pthread_getspecific, "pthread_getspecific"); |
| 559 |
|
| 560 |
type destructor_pointer is access procedure (arg : System.Address); |
| 561 |
pragma Convention (C, destructor_pointer); |
| 562 |
|
| 563 |
function pthread_key_create |
| 564 |
(key : access pthread_key_t; |
| 565 |
destructor : destructor_pointer) return int; |
| 566 |
pragma Import (C, pthread_key_create, "pthread_key_create"); |
| 567 |
|
| 568 |
CPU_SETSIZE : constant := 1_024; |
| 569 |
|
| 570 |
type bit_field is array (1 .. CPU_SETSIZE) of Boolean; |
| 571 |
for bit_field'Size use CPU_SETSIZE; |
| 572 |
pragma Pack (bit_field); |
| 573 |
pragma Convention (C, bit_field); |
| 574 |
|
| 575 |
type cpu_set_t is record |
| 576 |
bits : bit_field; |
| 577 |
end record; |
| 578 |
pragma Convention (C, cpu_set_t); |
| 579 |
|
| 580 |
function pthread_setaffinity_np |
| 581 |
(thread : pthread_t; |
| 582 |
cpusetsize : size_t; |
| 583 |
cpuset : access cpu_set_t) return int; |
| 584 |
pragma Import (C, pthread_setaffinity_np, "__gnat_pthread_setaffinity_np"); |
| 585 |
|
| 586 |
private |
| 587 |
|
| 588 |
type sigset_t is array (1 .. 4) of unsigned; |
| 589 |
|
| 590 |
-- In FreeBSD the component sa_handler turns out to |
| 591 |
-- be one a union type, and the selector is a macro: |
| 592 |
-- #define sa_handler __sigaction_u._handler |
| 593 |
-- #define sa_sigaction __sigaction_u._sigaction |
| 594 |
|
| 595 |
-- Should we add a signal_context type here ? |
| 596 |
-- How could it be done independent of the CPU architecture ? |
| 597 |
-- sigcontext type is opaque, so it is architecturally neutral. |
| 598 |
-- It is always passed as an access type, so define it as an empty record |
| 599 |
-- since the contents are not used anywhere. |
| 600 |
type struct_sigcontext is null record; |
| 601 |
pragma Convention (C, struct_sigcontext); |
| 602 |
|
| 603 |
type pid_t is new int; |
| 604 |
|
| 605 |
type time_t is range -2 ** (System.Parameters.time_t_bits - 1) |
| 606 |
.. 2 ** (System.Parameters.time_t_bits - 1) - 1; |
| 607 |
|
| 608 |
type timespec is record |
| 609 |
tv_sec : time_t; |
| 610 |
tv_nsec : long; |
| 611 |
end record; |
| 612 |
pragma Convention (C, timespec); |
| 613 |
|
| 614 |
type pthread_attr_t is record |
| 615 |
detachstate : int; |
| 616 |
schedpolicy : int; |
| 617 |
schedparam : struct_sched_param; |
| 618 |
inheritsched : int; |
| 619 |
scope : int; |
| 620 |
guardsize : size_t; |
| 621 |
stackaddr_set : int; |
| 622 |
stackaddr : System.Address; |
| 623 |
stacksize : size_t; |
| 624 |
end record; |
| 625 |
pragma Convention (C, pthread_attr_t); |
| 626 |
|
| 627 |
type pthread_condattr_t is record |
| 628 |
dummy : int; |
| 629 |
end record; |
| 630 |
pragma Convention (C, pthread_condattr_t); |
| 631 |
|
| 632 |
type pthread_mutexattr_t is record |
| 633 |
mutexkind : int; |
| 634 |
end record; |
| 635 |
pragma Convention (C, pthread_mutexattr_t); |
| 636 |
|
| 637 |
type struct_pthread_fast_lock is record |
| 638 |
status : long; |
| 639 |
spinlock : int; |
| 640 |
end record; |
| 641 |
pragma Convention (C, struct_pthread_fast_lock); |
| 642 |
|
| 643 |
type pthread_cond_t is array (0 .. 47) of unsigned_char; |
| 644 |
pragma Convention (C, pthread_cond_t); |
| 645 |
|
| 646 |
type pthread_key_t is new unsigned; |
| 647 |
|
| 648 |
end System.OS_Interface; |