| 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-2017, 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. It is -- |
| 29 |
-- now maintained by Ada Core Technologies Inc. in cooperation with Florida -- |
| 30 |
-- State University (http://www.gnat.com). -- |
| 31 |
-- -- |
| 32 |
------------------------------------------------------------------------------ |
| 33 |
|
| 34 |
-- This is the CheriBSD (POSIX Threads) version of this package |
| 35 |
|
| 36 |
-- This package encapsulates all direct interfaces to OS services |
| 37 |
-- that are needed by the tasking run-time (libgnarl). |
| 38 |
|
| 39 |
-- PLEASE DO NOT add any with-clauses to this package or remove the pragma |
| 40 |
-- Preelaborate. This package is designed to be a bottom-level (leaf) package. |
| 41 |
|
| 42 |
with Ada.Unchecked_Conversion; |
| 43 |
|
| 44 |
with Interfaces; |
| 45 |
with Interfaces.C; |
| 46 |
|
| 47 |
with System.OS_Locks; |
| 48 |
with System.Parameters; |
| 49 |
|
| 50 |
package System.OS_Interface is |
| 51 |
pragma Preelaborate; |
| 52 |
|
| 53 |
pragma Linker_Options ("-pthread"); |
| 54 |
|
| 55 |
subtype int is Interfaces.C.int; |
| 56 |
subtype short is Interfaces.C.short; |
| 57 |
subtype long is Interfaces.C.long; |
| 58 |
subtype unsigned is Interfaces.C.unsigned; |
| 59 |
subtype unsigned_short is Interfaces.C.unsigned_short; |
| 60 |
subtype unsigned_long is Interfaces.C.unsigned_long; |
| 61 |
subtype unsigned_char is Interfaces.C.unsigned_char; |
| 62 |
subtype plain_char is Interfaces.C.plain_char; |
| 63 |
subtype size_t is Interfaces.C.size_t; |
| 64 |
|
| 65 |
type int32_t is new int; |
| 66 |
type uint32_t is new unsigned; |
| 67 |
type uint64_t is new unsigned_long; |
| 68 |
type pid_t is new int32_t; |
| 69 |
type uid_t is new uint32_t; |
| 70 |
|
| 71 |
----------- |
| 72 |
-- Errno -- |
| 73 |
----------- |
| 74 |
|
| 75 |
function Errno return int; |
| 76 |
pragma Inline (Errno); |
| 77 |
|
| 78 |
EAGAIN : constant := 35; |
| 79 |
EINTR : constant := 4; |
| 80 |
EINVAL : constant := 22; |
| 81 |
ENOMEM : constant := 12; |
| 82 |
ETIMEDOUT : constant := 60; |
| 83 |
|
| 84 |
------------- |
| 85 |
-- Signals -- |
| 86 |
------------- |
| 87 |
|
| 88 |
Max_Interrupt : constant := 34; |
| 89 |
type Signal is new int range 0 .. Max_Interrupt; |
| 90 |
for Signal'Size use int'Size; |
| 91 |
|
| 92 |
SIGHUP : constant := 1; -- hangup |
| 93 |
SIGINT : constant := 2; -- interrupt (rubout) |
| 94 |
SIGQUIT : constant := 3; -- quit (ASCD FS) |
| 95 |
SIGILL : constant := 4; -- illegal instruction (not reset) |
| 96 |
SIGTRAP : constant := 5; -- trace trap (not reset) |
| 97 |
SIGIOT : constant := 6; -- IOT instruction |
| 98 |
SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future |
| 99 |
SIGEMT : constant := 7; -- EMT instruction |
| 100 |
SIGFPE : constant := 8; -- floating point exception |
| 101 |
SIGKILL : constant := 9; -- kill (cannot be caught or ignored) |
| 102 |
SIGBUS : constant := 10; -- bus error |
| 103 |
SIGSEGV : constant := 11; -- segmentation violation |
| 104 |
SIGSYS : constant := 12; -- bad argument to system call |
| 105 |
SIGPIPE : constant := 13; -- write on a pipe with no one to read it |
| 106 |
SIGALRM : constant := 14; -- alarm clock |
| 107 |
SIGTERM : constant := 15; -- software termination signal from kill |
| 108 |
SIGURG : constant := 16; -- urgent condition on IO channel |
| 109 |
SIGSTOP : constant := 17; -- stop (cannot be caught or ignored) |
| 110 |
SIGTSTP : constant := 18; -- user stop requested from tty |
| 111 |
SIGCONT : constant := 19; -- stopped process has been continued |
| 112 |
SIGCLD : constant := 20; -- alias for SIGCHLD |
| 113 |
SIGCHLD : constant := 20; -- child status change |
| 114 |
SIGTTIN : constant := 21; -- background tty read attempted |
| 115 |
SIGTTOU : constant := 22; -- background tty write attempted |
| 116 |
SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias) |
| 117 |
SIGXCPU : constant := 24; -- CPU time limit exceeded |
| 118 |
SIGXFSZ : constant := 25; -- filesize limit exceeded |
| 119 |
SIGVTALRM : constant := 26; -- virtual timer expired |
| 120 |
SIGPROF : constant := 27; -- profiling timer expired |
| 121 |
SIGWINCH : constant := 28; -- window size change |
| 122 |
SIGINFO : constant := 29; -- information request (NetBSD/FreeBSD) |
| 123 |
SIGUSR1 : constant := 30; -- user defined signal 1 |
| 124 |
SIGUSR2 : constant := 31; -- user defined signal 2 |
| 125 |
SIGPROT : constant := 34; -- in-address space security (CHERI) exception |
| 126 |
|
| 127 |
SIGADAABORT : constant := SIGABRT; |
| 128 |
-- Change this if you want to use another signal for task abort. |
| 129 |
-- SIGTERM might be a good one. |
| 130 |
|
| 131 |
type Signal_Set is array (Natural range <>) of Signal; |
| 132 |
|
| 133 |
-- Interrupts that must be unmasked at all times. FreeBSD |
| 134 |
-- pthreads will not allow an application to mask out any |
| 135 |
-- interrupt needed by the threads library. |
| 136 |
Unmasked : constant Signal_Set := |
| 137 |
(SIGTRAP, SIGBUS, SIGTTIN, SIGTTOU, SIGTSTP); |
| 138 |
|
| 139 |
-- FreeBSD will uses SIGPROF for timing. Do not allow a |
| 140 |
-- handler to attach to this signal. |
| 141 |
Reserved : constant Signal_Set := (0 .. 0 => SIGPROF); |
| 142 |
|
| 143 |
type sigset_t is private; |
| 144 |
|
| 145 |
function sigaddset |
| 146 |
(set : access sigset_t; |
| 147 |
sig : Signal) return int; |
| 148 |
pragma Import (C, sigaddset, "sigaddset"); |
| 149 |
|
| 150 |
function sigdelset |
| 151 |
(set : access sigset_t; |
| 152 |
sig : Signal) return int; |
| 153 |
pragma Import (C, sigdelset, "sigdelset"); |
| 154 |
|
| 155 |
function sigfillset (set : access sigset_t) return int; |
| 156 |
pragma Import (C, sigfillset, "sigfillset"); |
| 157 |
|
| 158 |
function sigismember |
| 159 |
(set : access sigset_t; |
| 160 |
sig : Signal) return int; |
| 161 |
pragma Import (C, sigismember, "sigismember"); |
| 162 |
|
| 163 |
function sigemptyset (set : access sigset_t) return int; |
| 164 |
pragma Import (C, sigemptyset, "sigemptyset"); |
| 165 |
|
| 166 |
type siginfo_reason is array (Integer range 1 .. 8) of int; |
| 167 |
type siginfo_t is record |
| 168 |
si_signo : int; |
| 169 |
si_errno : int; |
| 170 |
si_code : int; |
| 171 |
si_pid : pid_t; |
| 172 |
si_uid : uid_t; |
| 173 |
si_status : int; |
| 174 |
si_addr : Address; |
| 175 |
sival_int : int; |
| 176 |
reason : siginfo_reason; |
| 177 |
end record; |
| 178 |
pragma Convention (C, siginfo_t); |
| 179 |
|
| 180 |
-- Codes for SIGPROT |
| 181 |
PROT_CHERI_BOUNDS : constant int := 1; |
| 182 |
PROT_CHERI_TAG : constant int := 2; |
| 183 |
PROT_CHERI_SEALED : constant int := 3; |
| 184 |
PROT_CHERI_TYPE : constant int := 4; |
| 185 |
PROT_CHERI_PERM : constant int := 5; |
| 186 |
PROT_CHERI_IMPRECISE : constant int := 7; |
| 187 |
PROT_CHERI_STORELOCAL : constant int := 8; |
| 188 |
PROT_CHERI_CINVOKE : constant int := 9; |
| 189 |
PROT_CHERI_SYSREG : constant int := 11; |
| 190 |
PROT_CHERI_UNALIGNED_BASE : constant int := 12; |
| 191 |
|
| 192 |
-- sigcontext is architecture dependent, so define it private |
| 193 |
type struct_sigcontext is private; |
| 194 |
|
| 195 |
type old_struct_sigaction is record |
| 196 |
sa_handler : System.Address; |
| 197 |
sa_mask : sigset_t; |
| 198 |
sa_flags : int; |
| 199 |
end record; |
| 200 |
pragma Convention (C, old_struct_sigaction); |
| 201 |
|
| 202 |
type new_struct_sigaction is record |
| 203 |
sa_handler : System.Address; |
| 204 |
sa_flags : int; |
| 205 |
sa_mask : sigset_t; |
| 206 |
end record; |
| 207 |
pragma Convention (C, new_struct_sigaction); |
| 208 |
|
| 209 |
subtype struct_sigaction is new_struct_sigaction; |
| 210 |
type struct_sigaction_ptr is access all struct_sigaction; |
| 211 |
|
| 212 |
SIG_BLOCK : constant := 1; |
| 213 |
SIG_UNBLOCK : constant := 2; |
| 214 |
SIG_SETMASK : constant := 3; |
| 215 |
|
| 216 |
SIG_DFL : constant := 0; |
| 217 |
SIG_IGN : constant := 1; |
| 218 |
|
| 219 |
SA_SIGINFO : constant := 16#0040#; |
| 220 |
SA_ONSTACK : constant := 16#0001#; |
| 221 |
|
| 222 |
function sigaction |
| 223 |
(sig : Signal; |
| 224 |
act : struct_sigaction_ptr; |
| 225 |
oact : struct_sigaction_ptr) return int; |
| 226 |
pragma Import (C, sigaction, "sigaction"); |
| 227 |
|
| 228 |
---------- |
| 229 |
-- Time -- |
| 230 |
---------- |
| 231 |
|
| 232 |
Time_Slice_Supported : constant Boolean := True; |
| 233 |
-- Indicates whether time slicing is supported (i.e SCHED_RR is supported) |
| 234 |
|
| 235 |
type timespec is private; |
| 236 |
|
| 237 |
function nanosleep (rqtp, rmtp : access timespec) return int; |
| 238 |
pragma Import (C, nanosleep, "nanosleep"); |
| 239 |
|
| 240 |
type clockid_t is new int; |
| 241 |
|
| 242 |
function clock_getres |
| 243 |
(clock_id : clockid_t; |
| 244 |
res : access timespec) return int; |
| 245 |
pragma Import (C, clock_getres, "clock_getres"); |
| 246 |
|
| 247 |
function clock_gettime |
| 248 |
(clock_id : clockid_t; |
| 249 |
tp : access timespec) |
| 250 |
return int; |
| 251 |
pragma Import (C, clock_gettime, "clock_gettime"); |
| 252 |
|
| 253 |
function To_Duration (TS : timespec) return Duration; |
| 254 |
pragma Inline (To_Duration); |
| 255 |
|
| 256 |
function To_Timespec (D : Duration) return timespec; |
| 257 |
pragma Inline (To_Timespec); |
| 258 |
|
| 259 |
type struct_timezone is record |
| 260 |
tz_minuteswest : int; |
| 261 |
tz_dsttime : int; |
| 262 |
end record; |
| 263 |
pragma Convention (C, struct_timezone); |
| 264 |
|
| 265 |
procedure usleep (useconds : unsigned_long); |
| 266 |
pragma Import (C, usleep, "usleep"); |
| 267 |
|
| 268 |
------------------------- |
| 269 |
-- Priority Scheduling -- |
| 270 |
------------------------- |
| 271 |
|
| 272 |
SCHED_FIFO : constant := 1; |
| 273 |
SCHED_OTHER : constant := 2; |
| 274 |
SCHED_RR : constant := 3; |
| 275 |
|
| 276 |
function To_Target_Priority |
| 277 |
(Prio : System.Any_Priority) return Interfaces.C.int; |
| 278 |
-- Maps System.Any_Priority to a POSIX priority |
| 279 |
|
| 280 |
------------- |
| 281 |
-- Process -- |
| 282 |
------------- |
| 283 |
|
| 284 |
Self_PID : constant pid_t; |
| 285 |
|
| 286 |
function kill (pid : pid_t; sig : Signal) return int; |
| 287 |
pragma Import (C, kill, "kill"); |
| 288 |
|
| 289 |
function getpid return pid_t; |
| 290 |
pragma Import (C, getpid, "getpid"); |
| 291 |
|
| 292 |
--------- |
| 293 |
-- LWP -- |
| 294 |
--------- |
| 295 |
|
| 296 |
function lwp_self return System.Address; |
| 297 |
-- lwp_self does not exist on this thread library, revert to pthread_self |
| 298 |
-- which is the closest approximation (with getpid). This function is |
| 299 |
-- needed to share 7staprop.adb across POSIX-like targets. |
| 300 |
pragma Import (C, lwp_self, "pthread_self"); |
| 301 |
|
| 302 |
------------- |
| 303 |
-- Threads -- |
| 304 |
------------- |
| 305 |
|
| 306 |
type Thread_Body is access |
| 307 |
function (arg : System.Address) return System.Address; |
| 308 |
pragma Convention (C, Thread_Body); |
| 309 |
|
| 310 |
function Thread_Body_Access is new |
| 311 |
Ada.Unchecked_Conversion (System.Address, Thread_Body); |
| 312 |
|
| 313 |
type pthread_t is private; |
| 314 |
subtype Thread_Id is pthread_t; |
| 315 |
|
| 316 |
subtype pthread_mutex_t is System.OS_Locks.pthread_mutex_t; |
| 317 |
type pthread_cond_t is limited private; |
| 318 |
type pthread_attr_t is limited private; |
| 319 |
type pthread_mutexattr_t is limited private; |
| 320 |
type pthread_condattr_t is limited private; |
| 321 |
type pthread_key_t is private; |
| 322 |
|
| 323 |
PTHREAD_CREATE_DETACHED : constant := 1; |
| 324 |
PTHREAD_CREATE_JOINABLE : constant := 0; |
| 325 |
|
| 326 |
PTHREAD_SCOPE_PROCESS : constant := 0; |
| 327 |
PTHREAD_SCOPE_SYSTEM : constant := 2; |
| 328 |
|
| 329 |
-- Read/Write lock not supported on freebsd. To add support both types |
| 330 |
-- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined |
| 331 |
-- with the associated routines pthread_rwlock_[init/destroy] and |
| 332 |
-- pthread_rwlock_[rdlock/wrlock/unlock]. |
| 333 |
|
| 334 |
subtype pthread_rwlock_t is pthread_mutex_t; |
| 335 |
subtype pthread_rwlockattr_t is pthread_mutexattr_t; |
| 336 |
|
| 337 |
----------- |
| 338 |
-- Stack -- |
| 339 |
----------- |
| 340 |
|
| 341 |
type stack_t is record |
| 342 |
ss_sp : System.Address; |
| 343 |
ss_size : size_t; |
| 344 |
ss_flags : int; |
| 345 |
end record; |
| 346 |
pragma Convention (C, stack_t); |
| 347 |
|
| 348 |
function sigaltstack |
| 349 |
(ss : not null access stack_t; |
| 350 |
oss : access stack_t) return int; |
| 351 |
pragma Import (C, sigaltstack, "sigaltstack"); |
| 352 |
|
| 353 |
Alternate_Stack : aliased System.Address; |
| 354 |
-- This is a dummy definition, never used (Alternate_Stack_Size is null) |
| 355 |
|
| 356 |
Alternate_Stack_Size : constant := 0; |
| 357 |
-- No alternate signal stack is used on this platform |
| 358 |
|
| 359 |
Stack_Base_Available : constant Boolean := False; |
| 360 |
-- Indicates whether the stack base is available on this target |
| 361 |
|
| 362 |
function Get_Stack_Base (thread : pthread_t) return Address; |
| 363 |
pragma Inline (Get_Stack_Base); |
| 364 |
-- returns the stack base of the specified thread. Only call this function |
| 365 |
-- when Stack_Base_Available is True. |
| 366 |
|
| 367 |
function Get_Page_Size return int; |
| 368 |
pragma Import (C, Get_Page_Size, "getpagesize"); |
| 369 |
-- Returns the size of a page |
| 370 |
|
| 371 |
PROT_NONE : constant := 0; |
| 372 |
PROT_READ : constant := 1; |
| 373 |
PROT_WRITE : constant := 2; |
| 374 |
PROT_EXEC : constant := 4; |
| 375 |
PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC; |
| 376 |
PROT_ON : constant := PROT_NONE; |
| 377 |
PROT_OFF : constant := PROT_ALL; |
| 378 |
|
| 379 |
function mprotect (addr : Address; len : size_t; prot : int) return int; |
| 380 |
pragma Import (C, mprotect); |
| 381 |
|
| 382 |
--------------------------------------- |
| 383 |
-- Nonstandard Thread Initialization -- |
| 384 |
--------------------------------------- |
| 385 |
|
| 386 |
-- FSU_THREADS requires pthread_init, which is nonstandard and this should |
| 387 |
-- be invoked during the elaboration of s-taprop.adb. |
| 388 |
|
| 389 |
-- FreeBSD does not require this so we provide an empty Ada body |
| 390 |
|
| 391 |
procedure pthread_init; |
| 392 |
|
| 393 |
------------------------- |
| 394 |
-- POSIX.1c Section 3 -- |
| 395 |
------------------------- |
| 396 |
|
| 397 |
function sigwait |
| 398 |
(set : access sigset_t; |
| 399 |
sig : access Signal) return int; |
| 400 |
pragma Import (C, sigwait, "sigwait"); |
| 401 |
|
| 402 |
function pthread_kill |
| 403 |
(thread : pthread_t; |
| 404 |
sig : Signal) return int; |
| 405 |
pragma Import (C, pthread_kill, "pthread_kill"); |
| 406 |
|
| 407 |
function pthread_sigmask |
| 408 |
(how : int; |
| 409 |
set : access sigset_t; |
| 410 |
oset : access sigset_t) return int; |
| 411 |
pragma Import (C, pthread_sigmask, "pthread_sigmask"); |
| 412 |
|
| 413 |
-------------------------- |
| 414 |
-- POSIX.1c Section 11 -- |
| 415 |
-------------------------- |
| 416 |
|
| 417 |
function pthread_mutexattr_init |
| 418 |
(attr : access pthread_mutexattr_t) return int; |
| 419 |
pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); |
| 420 |
|
| 421 |
function pthread_mutexattr_destroy |
| 422 |
(attr : access pthread_mutexattr_t) return int; |
| 423 |
pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); |
| 424 |
|
| 425 |
function pthread_mutex_init |
| 426 |
(mutex : access pthread_mutex_t; |
| 427 |
attr : access pthread_mutexattr_t) return int; |
| 428 |
pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); |
| 429 |
|
| 430 |
function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; |
| 431 |
pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); |
| 432 |
|
| 433 |
function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; |
| 434 |
pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); |
| 435 |
|
| 436 |
function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; |
| 437 |
pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); |
| 438 |
|
| 439 |
function pthread_condattr_init |
| 440 |
(attr : access pthread_condattr_t) return int; |
| 441 |
pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); |
| 442 |
|
| 443 |
function pthread_condattr_destroy |
| 444 |
(attr : access pthread_condattr_t) return int; |
| 445 |
pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); |
| 446 |
|
| 447 |
function pthread_cond_init |
| 448 |
(cond : access pthread_cond_t; |
| 449 |
attr : access pthread_condattr_t) return int; |
| 450 |
pragma Import (C, pthread_cond_init, "pthread_cond_init"); |
| 451 |
|
| 452 |
function pthread_cond_destroy (cond : access pthread_cond_t) return int; |
| 453 |
pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); |
| 454 |
|
| 455 |
function pthread_cond_signal (cond : access pthread_cond_t) return int; |
| 456 |
pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); |
| 457 |
|
| 458 |
function pthread_cond_wait |
| 459 |
(cond : access pthread_cond_t; |
| 460 |
mutex : access pthread_mutex_t) return int; |
| 461 |
pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); |
| 462 |
|
| 463 |
function pthread_cond_timedwait |
| 464 |
(cond : access pthread_cond_t; |
| 465 |
mutex : access pthread_mutex_t; |
| 466 |
abstime : access timespec) return int; |
| 467 |
pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); |
| 468 |
|
| 469 |
-------------------------- |
| 470 |
-- POSIX.1c Section 13 -- |
| 471 |
-------------------------- |
| 472 |
|
| 473 |
PTHREAD_PRIO_NONE : constant := 0; |
| 474 |
PTHREAD_PRIO_PROTECT : constant := 2; |
| 475 |
PTHREAD_PRIO_INHERIT : constant := 1; |
| 476 |
|
| 477 |
function pthread_mutexattr_setprotocol |
| 478 |
(attr : access pthread_mutexattr_t; |
| 479 |
protocol : int) return int; |
| 480 |
pragma Import |
| 481 |
(C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol"); |
| 482 |
|
| 483 |
function pthread_mutexattr_getprotocol |
| 484 |
(attr : access pthread_mutexattr_t; |
| 485 |
protocol : access int) return int; |
| 486 |
pragma Import |
| 487 |
(C, pthread_mutexattr_getprotocol, "pthread_mutexattr_getprotocol"); |
| 488 |
|
| 489 |
function pthread_mutexattr_setprioceiling |
| 490 |
(attr : access pthread_mutexattr_t; |
| 491 |
prioceiling : int) return int; |
| 492 |
pragma Import |
| 493 |
(C, pthread_mutexattr_setprioceiling, |
| 494 |
"pthread_mutexattr_setprioceiling"); |
| 495 |
|
| 496 |
function pthread_mutexattr_getprioceiling |
| 497 |
(attr : access pthread_mutexattr_t; |
| 498 |
prioceiling : access int) return int; |
| 499 |
pragma Import |
| 500 |
(C, pthread_mutexattr_getprioceiling, |
| 501 |
"pthread_mutexattr_getprioceiling"); |
| 502 |
|
| 503 |
type struct_sched_param is record |
| 504 |
sched_priority : int; |
| 505 |
end record; |
| 506 |
pragma Convention (C, struct_sched_param); |
| 507 |
|
| 508 |
function pthread_getschedparam |
| 509 |
(thread : pthread_t; |
| 510 |
policy : access int; |
| 511 |
param : access struct_sched_param) return int; |
| 512 |
pragma Import (C, pthread_getschedparam, "pthread_getschedparam"); |
| 513 |
|
| 514 |
function pthread_setschedparam |
| 515 |
(thread : pthread_t; |
| 516 |
policy : int; |
| 517 |
param : access struct_sched_param) return int; |
| 518 |
pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); |
| 519 |
|
| 520 |
function pthread_attr_setscope |
| 521 |
(attr : access pthread_attr_t; |
| 522 |
contentionscope : int) return int; |
| 523 |
pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); |
| 524 |
|
| 525 |
function pthread_attr_getscope |
| 526 |
(attr : access pthread_attr_t; |
| 527 |
contentionscope : access int) return int; |
| 528 |
pragma Import (C, pthread_attr_getscope, "pthread_attr_getscope"); |
| 529 |
|
| 530 |
function pthread_attr_setinheritsched |
| 531 |
(attr : access pthread_attr_t; |
| 532 |
inheritsched : int) return int; |
| 533 |
pragma Import |
| 534 |
(C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched"); |
| 535 |
|
| 536 |
function pthread_attr_getinheritsched |
| 537 |
(attr : access pthread_attr_t; |
| 538 |
inheritsched : access int) return int; |
| 539 |
pragma Import |
| 540 |
(C, pthread_attr_getinheritsched, "pthread_attr_getinheritsched"); |
| 541 |
|
| 542 |
function pthread_attr_setschedpolicy |
| 543 |
(attr : access pthread_attr_t; |
| 544 |
policy : int) return int; |
| 545 |
pragma Import (C, pthread_attr_setschedpolicy, |
| 546 |
"pthread_attr_setschedpolicy"); |
| 547 |
|
| 548 |
function pthread_attr_getschedpolicy |
| 549 |
(attr : access pthread_attr_t; |
| 550 |
policy : access int) return int; |
| 551 |
pragma Import (C, pthread_attr_getschedpolicy, |
| 552 |
"pthread_attr_getschedpolicy"); |
| 553 |
|
| 554 |
function pthread_attr_setschedparam |
| 555 |
(attr : access pthread_attr_t; |
| 556 |
sched_param : int) return int; |
| 557 |
pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam"); |
| 558 |
|
| 559 |
function pthread_attr_getschedparam |
| 560 |
(attr : access pthread_attr_t; |
| 561 |
sched_param : access int) return int; |
| 562 |
pragma Import (C, pthread_attr_getschedparam, "pthread_attr_getschedparam"); |
| 563 |
|
| 564 |
function sched_yield return int; |
| 565 |
pragma Import (C, sched_yield, "pthread_yield"); |
| 566 |
|
| 567 |
-------------------------- |
| 568 |
-- P1003.1c Section 16 -- |
| 569 |
-------------------------- |
| 570 |
|
| 571 |
function pthread_attr_init (attributes : access pthread_attr_t) return int; |
| 572 |
pragma Import (C, pthread_attr_init, "pthread_attr_init"); |
| 573 |
|
| 574 |
function pthread_attr_destroy |
| 575 |
(attributes : access pthread_attr_t) return int; |
| 576 |
pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); |
| 577 |
|
| 578 |
function pthread_attr_setdetachstate |
| 579 |
(attr : access pthread_attr_t; |
| 580 |
detachstate : int) return int; |
| 581 |
pragma Import |
| 582 |
(C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate"); |
| 583 |
|
| 584 |
function pthread_attr_getdetachstate |
| 585 |
(attr : access pthread_attr_t; |
| 586 |
detachstate : access int) return int; |
| 587 |
pragma Import |
| 588 |
(C, pthread_attr_getdetachstate, "pthread_attr_getdetachstate"); |
| 589 |
|
| 590 |
function pthread_attr_getstacksize |
| 591 |
(attr : access pthread_attr_t; |
| 592 |
stacksize : access size_t) return int; |
| 593 |
pragma Import |
| 594 |
(C, pthread_attr_getstacksize, "pthread_attr_getstacksize"); |
| 595 |
|
| 596 |
function pthread_attr_setstacksize |
| 597 |
(attr : access pthread_attr_t; |
| 598 |
stacksize : size_t) return int; |
| 599 |
pragma Import |
| 600 |
(C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); |
| 601 |
|
| 602 |
function pthread_create |
| 603 |
(thread : access pthread_t; |
| 604 |
attributes : access pthread_attr_t; |
| 605 |
start_routine : Thread_Body; |
| 606 |
arg : System.Address) return int; |
| 607 |
pragma Import (C, pthread_create, "pthread_create"); |
| 608 |
|
| 609 |
function pthread_detach (thread : pthread_t) return int; |
| 610 |
pragma Import (C, pthread_detach, "pthread_detach"); |
| 611 |
|
| 612 |
procedure pthread_exit (status : System.Address); |
| 613 |
pragma Import (C, pthread_exit, "pthread_exit"); |
| 614 |
|
| 615 |
function pthread_self return pthread_t; |
| 616 |
pragma Import (C, pthread_self, "pthread_self"); |
| 617 |
|
| 618 |
-------------------------- |
| 619 |
-- POSIX.1c Section 17 -- |
| 620 |
-------------------------- |
| 621 |
|
| 622 |
function pthread_setspecific |
| 623 |
(key : pthread_key_t; |
| 624 |
value : System.Address) return int; |
| 625 |
pragma Import (C, pthread_setspecific, "pthread_setspecific"); |
| 626 |
|
| 627 |
function pthread_getspecific (key : pthread_key_t) return System.Address; |
| 628 |
pragma Import (C, pthread_getspecific, "pthread_getspecific"); |
| 629 |
|
| 630 |
type destructor_pointer is access procedure (arg : System.Address); |
| 631 |
pragma Convention (C, destructor_pointer); |
| 632 |
|
| 633 |
function pthread_key_create |
| 634 |
(key : access pthread_key_t; |
| 635 |
destructor : destructor_pointer) return int; |
| 636 |
pragma Import (C, pthread_key_create, "pthread_key_create"); |
| 637 |
|
| 638 |
------------------------------------ |
| 639 |
-- Non-portable Pthread Functions -- |
| 640 |
------------------------------------ |
| 641 |
|
| 642 |
function pthread_set_name_np |
| 643 |
(thread : pthread_t; |
| 644 |
name : System.Address) return int; |
| 645 |
pragma Import (C, pthread_set_name_np, "pthread_set_name_np"); |
| 646 |
|
| 647 |
private |
| 648 |
|
| 649 |
type sigset_t is array (1 .. 4) of unsigned; |
| 650 |
|
| 651 |
-- In FreeBSD the component sa_handler turns out to |
| 652 |
-- be one a union type, and the selector is a macro: |
| 653 |
-- #define sa_handler __sigaction_u._handler |
| 654 |
-- #define sa_sigaction __sigaction_u._sigaction |
| 655 |
|
| 656 |
-- Should we add a signal_context type here ??? |
| 657 |
-- How could it be done independent of the CPU architecture ??? |
| 658 |
-- sigcontext type is opaque, so it is architecturally neutral. |
| 659 |
-- It is always passed as an access type, so define it as an empty record |
| 660 |
-- since the contents are not used anywhere. |
| 661 |
|
| 662 |
type struct_sigcontext is null record; |
| 663 |
pragma Convention (C, struct_sigcontext); |
| 664 |
|
| 665 |
Self_PID : constant pid_t := 0; |
| 666 |
|
| 667 |
type time_t is range -2 ** (System.Parameters.time_t_bits - 1) |
| 668 |
.. 2 ** (System.Parameters.time_t_bits - 1) - 1; |
| 669 |
|
| 670 |
type timespec is record |
| 671 |
ts_sec : time_t; |
| 672 |
ts_nsec : long; |
| 673 |
end record; |
| 674 |
pragma Convention (C, timespec); |
| 675 |
|
| 676 |
type pthread_t is new System.Address; |
| 677 |
type pthread_attr_t is new System.Address; |
| 678 |
type pthread_mutexattr_t is new System.Address; |
| 679 |
type pthread_cond_t is new System.Address; |
| 680 |
type pthread_condattr_t is new System.Address; |
| 681 |
type pthread_key_t is new int; |
| 682 |
|
| 683 |
end System.OS_Interface; |