| 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. -- |
| 29 |
-- Extensive contributions were provided by Ada Core Technologies, Inc. -- |
| 30 |
-- -- |
| 31 |
------------------------------------------------------------------------------ |
| 32 |
|
| 33 |
-- This is Darwin pthreads version of this package |
| 34 |
|
| 35 |
-- This package includes all direct interfaces to OS services that are needed |
| 36 |
-- by the tasking run-time (libgnarl). |
| 37 |
|
| 38 |
-- PLEASE DO NOT add any with-clauses to this package or remove the pragma |
| 39 |
-- Elaborate_Body. It is designed to be a bottom-level (leaf) package. |
| 40 |
|
| 41 |
with Interfaces.C; |
| 42 |
|
| 43 |
with System.OS_Constants; |
| 44 |
with System.OS_Locks; |
| 45 |
with System.Parameters; |
| 46 |
|
| 47 |
package System.OS_Interface is |
| 48 |
pragma Preelaborate; |
| 49 |
|
| 50 |
subtype int is Interfaces.C.int; |
| 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; |
| 59 |
|
| 60 |
----------- |
| 61 |
-- Errno -- |
| 62 |
----------- |
| 63 |
|
| 64 |
function errno return int; |
| 65 |
pragma Import (C, errno, "__get_errno"); |
| 66 |
|
| 67 |
EINTR : constant := 4; |
| 68 |
ENOMEM : constant := 12; |
| 69 |
EINVAL : constant := 22; |
| 70 |
EAGAIN : constant := 35; |
| 71 |
ETIMEDOUT : constant := 60; |
| 72 |
|
| 73 |
------------- |
| 74 |
-- Signals -- |
| 75 |
------------- |
| 76 |
|
| 77 |
Max_Interrupt : constant := 31; |
| 78 |
type Signal is new int range 0 .. Max_Interrupt; |
| 79 |
for Signal'Size use int'Size; |
| 80 |
|
| 81 |
SIGHUP : constant := 1; -- hangup |
| 82 |
SIGINT : constant := 2; -- interrupt (rubout) |
| 83 |
SIGQUIT : constant := 3; -- quit (ASCD FS) |
| 84 |
SIGILL : constant := 4; -- illegal instruction (not reset) |
| 85 |
SIGTRAP : constant := 5; -- trace trap (not reset) |
| 86 |
SIGIOT : constant := 6; -- IOT instruction |
| 87 |
SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future |
| 88 |
SIGEMT : constant := 7; -- EMT instruction |
| 89 |
SIGFPE : constant := 8; -- floating point exception |
| 90 |
SIGKILL : constant := 9; -- kill (cannot be caught or ignored) |
| 91 |
SIGBUS : constant := 10; -- bus error |
| 92 |
SIGSEGV : constant := 11; -- segmentation violation |
| 93 |
SIGSYS : constant := 12; -- bad argument to system call |
| 94 |
SIGPIPE : constant := 13; -- write on a pipe with no one to read it |
| 95 |
SIGALRM : constant := 14; -- alarm clock |
| 96 |
SIGTERM : constant := 15; -- software termination signal from kill |
| 97 |
SIGURG : constant := 16; -- urgent condition on IO channel |
| 98 |
SIGSTOP : constant := 17; -- stop (cannot be caught or ignored) |
| 99 |
SIGTSTP : constant := 18; -- user stop requested from tty |
| 100 |
SIGCONT : constant := 19; -- stopped process has been continued |
| 101 |
SIGCHLD : constant := 20; -- child status change |
| 102 |
SIGTTIN : constant := 21; -- background tty read attempted |
| 103 |
SIGTTOU : constant := 22; -- background tty write attempted |
| 104 |
SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias) |
| 105 |
SIGXCPU : constant := 24; -- CPU time limit exceeded |
| 106 |
SIGXFSZ : constant := 25; -- filesize limit exceeded |
| 107 |
SIGVTALRM : constant := 26; -- virtual timer expired |
| 108 |
SIGPROF : constant := 27; -- profiling timer expired |
| 109 |
SIGWINCH : constant := 28; -- window size change |
| 110 |
SIGINFO : constant := 29; -- information request |
| 111 |
SIGUSR1 : constant := 30; -- user defined signal 1 |
| 112 |
SIGUSR2 : constant := 31; -- user defined signal 2 |
| 113 |
|
| 114 |
SIGADAABORT : constant := SIGABRT; |
| 115 |
-- Change this if you want to use another signal for task abort. |
| 116 |
-- SIGTERM might be a good one. |
| 117 |
|
| 118 |
type Signal_Set is array (Natural range <>) of Signal; |
| 119 |
|
| 120 |
Unmasked : constant Signal_Set := |
| 121 |
(SIGTTIN, SIGTTOU, SIGSTOP, SIGTSTP); |
| 122 |
|
| 123 |
Reserved : constant Signal_Set := |
| 124 |
(SIGKILL, SIGSTOP); |
| 125 |
|
| 126 |
Exception_Signals : constant Signal_Set := |
| 127 |
(SIGFPE, SIGILL, SIGSEGV, SIGBUS); |
| 128 |
-- These signals (when runtime or system) will be caught and converted |
| 129 |
-- into an Ada exception. |
| 130 |
|
| 131 |
type sigset_t is private; |
| 132 |
|
| 133 |
function sigaddset (set : access sigset_t; sig : Signal) return int; |
| 134 |
pragma Import (C, sigaddset, "sigaddset"); |
| 135 |
|
| 136 |
function sigdelset (set : access sigset_t; sig : Signal) return int; |
| 137 |
pragma Import (C, sigdelset, "sigdelset"); |
| 138 |
|
| 139 |
function sigfillset (set : access sigset_t) return int; |
| 140 |
pragma Import (C, sigfillset, "sigfillset"); |
| 141 |
|
| 142 |
function sigismember (set : access sigset_t; sig : Signal) return int; |
| 143 |
pragma Import (C, sigismember, "sigismember"); |
| 144 |
|
| 145 |
function sigemptyset (set : access sigset_t) return int; |
| 146 |
pragma Import (C, sigemptyset, "sigemptyset"); |
| 147 |
|
| 148 |
type siginfo_t is private; |
| 149 |
type ucontext_t is private; |
| 150 |
|
| 151 |
type Signal_Handler is access procedure |
| 152 |
(signo : Signal; |
| 153 |
info : access siginfo_t; |
| 154 |
context : access ucontext_t); |
| 155 |
|
| 156 |
type struct_sigaction is record |
| 157 |
sa_handler : System.Address; |
| 158 |
sa_mask : sigset_t; |
| 159 |
sa_flags : int; |
| 160 |
end record; |
| 161 |
pragma Convention (C, struct_sigaction); |
| 162 |
type struct_sigaction_ptr is access all struct_sigaction; |
| 163 |
|
| 164 |
SIG_BLOCK : constant := 1; |
| 165 |
SIG_UNBLOCK : constant := 2; |
| 166 |
SIG_SETMASK : constant := 3; |
| 167 |
|
| 168 |
SIG_DFL : constant := 0; |
| 169 |
SIG_IGN : constant := 1; |
| 170 |
|
| 171 |
SA_SIGINFO : constant := 16#0040#; |
| 172 |
SA_ONSTACK : constant := 16#0001#; |
| 173 |
|
| 174 |
function sigaction |
| 175 |
(sig : Signal; |
| 176 |
act : struct_sigaction_ptr; |
| 177 |
oact : struct_sigaction_ptr) return int; |
| 178 |
pragma Import (C, sigaction, "sigaction"); |
| 179 |
|
| 180 |
---------- |
| 181 |
-- Time -- |
| 182 |
---------- |
| 183 |
|
| 184 |
Time_Slice_Supported : constant Boolean := True; |
| 185 |
-- Indicates whether time slicing is supported |
| 186 |
|
| 187 |
type timespec is private; |
| 188 |
|
| 189 |
type clockid_t is new int; |
| 190 |
|
| 191 |
function clock_gettime |
| 192 |
(clock_id : clockid_t; |
| 193 |
tp : access timespec) return int; |
| 194 |
|
| 195 |
function clock_getres |
| 196 |
(clock_id : clockid_t; |
| 197 |
res : access timespec) return int; |
| 198 |
|
| 199 |
function To_Duration (TS : timespec) return Duration; |
| 200 |
pragma Inline (To_Duration); |
| 201 |
|
| 202 |
function To_Timespec (D : Duration) return timespec; |
| 203 |
pragma Inline (To_Timespec); |
| 204 |
|
| 205 |
------------------------- |
| 206 |
-- Priority Scheduling -- |
| 207 |
------------------------- |
| 208 |
|
| 209 |
SCHED_OTHER : constant := 1; |
| 210 |
SCHED_RR : constant := 2; |
| 211 |
SCHED_FIFO : constant := 4; |
| 212 |
|
| 213 |
function To_Target_Priority |
| 214 |
(Prio : System.Any_Priority) return Interfaces.C.int; |
| 215 |
-- Maps System.Any_Priority to a POSIX priority |
| 216 |
|
| 217 |
------------- |
| 218 |
-- Process -- |
| 219 |
------------- |
| 220 |
|
| 221 |
type pid_t is private; |
| 222 |
|
| 223 |
function kill (pid : pid_t; sig : Signal) return int; |
| 224 |
pragma Import (C, kill, "kill"); |
| 225 |
|
| 226 |
function getpid return pid_t; |
| 227 |
pragma Import (C, getpid, "getpid"); |
| 228 |
|
| 229 |
--------- |
| 230 |
-- LWP -- |
| 231 |
--------- |
| 232 |
|
| 233 |
function lwp_self return System.Address; |
| 234 |
pragma Import (C, lwp_self, "__gnat_lwp_self"); |
| 235 |
-- Return the mach thread bound to the current thread. The value is not |
| 236 |
-- used by the run-time library but made available to debuggers. |
| 237 |
|
| 238 |
------------- |
| 239 |
-- Threads -- |
| 240 |
------------- |
| 241 |
|
| 242 |
type Thread_Body is access |
| 243 |
function (arg : System.Address) return System.Address; |
| 244 |
pragma Convention (C, Thread_Body); |
| 245 |
|
| 246 |
type pthread_t is private; |
| 247 |
subtype Thread_Id is pthread_t; |
| 248 |
|
| 249 |
subtype pthread_mutex_t is System.OS_Locks.pthread_mutex_t; |
| 250 |
type pthread_cond_t is limited private; |
| 251 |
type pthread_attr_t is limited private; |
| 252 |
type pthread_mutexattr_t is limited private; |
| 253 |
type pthread_condattr_t is limited private; |
| 254 |
type pthread_key_t is private; |
| 255 |
|
| 256 |
type pthread_mutex_ptr is access all pthread_mutex_t; |
| 257 |
type pthread_cond_ptr is access all pthread_cond_t; |
| 258 |
|
| 259 |
PTHREAD_CREATE_DETACHED : constant := 2; |
| 260 |
|
| 261 |
PTHREAD_SCOPE_PROCESS : constant := 2; |
| 262 |
PTHREAD_SCOPE_SYSTEM : constant := 1; |
| 263 |
|
| 264 |
-- Read/Write lock not supported on Darwin. To add support both types |
| 265 |
-- pthread_rwlock_t and pthread_rwlockattr_t must properly be defined |
| 266 |
-- with the associated routines pthread_rwlock_[init/destroy] and |
| 267 |
-- pthread_rwlock_[rdlock/wrlock/unlock]. |
| 268 |
|
| 269 |
subtype pthread_rwlock_t is pthread_mutex_t; |
| 270 |
subtype pthread_rwlockattr_t is pthread_mutexattr_t; |
| 271 |
|
| 272 |
----------- |
| 273 |
-- Stack -- |
| 274 |
----------- |
| 275 |
|
| 276 |
type stack_t is record |
| 277 |
ss_sp : System.Address; |
| 278 |
ss_size : size_t; |
| 279 |
ss_flags : int; |
| 280 |
end record; |
| 281 |
pragma Convention (C, stack_t); |
| 282 |
|
| 283 |
function sigaltstack |
| 284 |
(ss : not null access stack_t; |
| 285 |
oss : access stack_t) return int; |
| 286 |
pragma Import (C, sigaltstack, "sigaltstack"); |
| 287 |
|
| 288 |
Alternate_Stack : aliased System.Address; |
| 289 |
pragma Import (C, Alternate_Stack, "__gnat_alternate_stack"); |
| 290 |
-- The alternate signal stack for stack overflows |
| 291 |
|
| 292 |
Alternate_Stack_Size : constant := 32 * 1024; |
| 293 |
-- This must be in keeping with init.c:__gnat_alternate_stack |
| 294 |
|
| 295 |
Stack_Base_Available : constant Boolean := False; |
| 296 |
-- Indicates whether the stack base is available on this target. This |
| 297 |
-- allows us to share s-osinte.adb between all the FSU run time. Note that |
| 298 |
-- this value can only be true if pthread_t has a complete definition that |
| 299 |
-- corresponds exactly to the C header files. |
| 300 |
|
| 301 |
function Get_Stack_Base (thread : pthread_t) return System.Address; |
| 302 |
pragma Inline (Get_Stack_Base); |
| 303 |
-- returns the stack base of the specified thread. Only call this function |
| 304 |
-- when Stack_Base_Available is True. |
| 305 |
|
| 306 |
function Get_Page_Size return int; |
| 307 |
pragma Import (C, Get_Page_Size, "getpagesize"); |
| 308 |
-- Returns the size of a page |
| 309 |
|
| 310 |
PROT_NONE : constant := 0; |
| 311 |
PROT_READ : constant := 1; |
| 312 |
PROT_WRITE : constant := 2; |
| 313 |
PROT_EXEC : constant := 4; |
| 314 |
PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC; |
| 315 |
|
| 316 |
PROT_ON : constant := PROT_NONE; |
| 317 |
PROT_OFF : constant := PROT_ALL; |
| 318 |
|
| 319 |
function mprotect |
| 320 |
(addr : System.Address; |
| 321 |
len : size_t; |
| 322 |
prot : int) return int; |
| 323 |
pragma Import (C, mprotect); |
| 324 |
|
| 325 |
--------------------------------------- |
| 326 |
-- Nonstandard Thread Initialization -- |
| 327 |
--------------------------------------- |
| 328 |
|
| 329 |
procedure pthread_init; |
| 330 |
|
| 331 |
------------------------- |
| 332 |
-- POSIX.1c Section 3 -- |
| 333 |
------------------------- |
| 334 |
|
| 335 |
function sigwait (set : access sigset_t; sig : access Signal) return int; |
| 336 |
pragma Import (C, sigwait, "sigwait"); |
| 337 |
|
| 338 |
function pthread_kill (thread : pthread_t; sig : Signal) return int; |
| 339 |
pragma Import (C, pthread_kill, "pthread_kill"); |
| 340 |
|
| 341 |
function pthread_sigmask |
| 342 |
(how : int; |
| 343 |
set : access sigset_t; |
| 344 |
oset : access sigset_t) return int; |
| 345 |
pragma Import (C, pthread_sigmask, "pthread_sigmask"); |
| 346 |
|
| 347 |
-------------------------- |
| 348 |
-- POSIX.1c Section 11 -- |
| 349 |
-------------------------- |
| 350 |
|
| 351 |
function pthread_mutexattr_init |
| 352 |
(attr : access pthread_mutexattr_t) return int; |
| 353 |
pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); |
| 354 |
|
| 355 |
function pthread_mutexattr_destroy |
| 356 |
(attr : access pthread_mutexattr_t) return int; |
| 357 |
pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); |
| 358 |
|
| 359 |
function pthread_mutex_init |
| 360 |
(mutex : access pthread_mutex_t; |
| 361 |
attr : access pthread_mutexattr_t) return int; |
| 362 |
pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); |
| 363 |
|
| 364 |
function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; |
| 365 |
pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); |
| 366 |
|
| 367 |
function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; |
| 368 |
pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); |
| 369 |
|
| 370 |
function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; |
| 371 |
pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); |
| 372 |
|
| 373 |
function pthread_condattr_init |
| 374 |
(attr : access pthread_condattr_t) return int; |
| 375 |
pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); |
| 376 |
|
| 377 |
function pthread_condattr_destroy |
| 378 |
(attr : access pthread_condattr_t) return int; |
| 379 |
pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); |
| 380 |
|
| 381 |
function pthread_cond_init |
| 382 |
(cond : access pthread_cond_t; |
| 383 |
attr : access pthread_condattr_t) return int; |
| 384 |
pragma Import (C, pthread_cond_init, "pthread_cond_init"); |
| 385 |
|
| 386 |
function pthread_cond_destroy (cond : access pthread_cond_t) return int; |
| 387 |
pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); |
| 388 |
|
| 389 |
function pthread_cond_signal (cond : access pthread_cond_t) return int; |
| 390 |
pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); |
| 391 |
|
| 392 |
function pthread_cond_wait |
| 393 |
(cond : access pthread_cond_t; |
| 394 |
mutex : access pthread_mutex_t) return int; |
| 395 |
pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); |
| 396 |
|
| 397 |
function pthread_cond_timedwait |
| 398 |
(cond : access pthread_cond_t; |
| 399 |
mutex : access pthread_mutex_t; |
| 400 |
abstime : access timespec) return int; |
| 401 |
pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); |
| 402 |
|
| 403 |
-------------------------- |
| 404 |
-- POSIX.1c Section 13 -- |
| 405 |
-------------------------- |
| 406 |
|
| 407 |
PTHREAD_PRIO_NONE : constant := 0; |
| 408 |
PTHREAD_PRIO_INHERIT : constant := 1; |
| 409 |
PTHREAD_PRIO_PROTECT : constant := 2; |
| 410 |
|
| 411 |
function pthread_mutexattr_setprotocol |
| 412 |
(attr : access pthread_mutexattr_t; |
| 413 |
protocol : int) return int; |
| 414 |
pragma Import |
| 415 |
(C, pthread_mutexattr_setprotocol, "pthread_mutexattr_setprotocol"); |
| 416 |
|
| 417 |
function pthread_mutexattr_setprioceiling |
| 418 |
(attr : access pthread_mutexattr_t; |
| 419 |
prioceiling : int) return int; |
| 420 |
pragma Import |
| 421 |
(C, pthread_mutexattr_setprioceiling, |
| 422 |
"pthread_mutexattr_setprioceiling"); |
| 423 |
|
| 424 |
type padding is array (int range <>) of Interfaces.C.char; |
| 425 |
|
| 426 |
type struct_sched_param is record |
| 427 |
sched_priority : int; -- scheduling priority |
| 428 |
opaque : padding (1 .. 4); |
| 429 |
end record; |
| 430 |
pragma Convention (C, struct_sched_param); |
| 431 |
|
| 432 |
function pthread_setschedparam |
| 433 |
(thread : pthread_t; |
| 434 |
policy : int; |
| 435 |
param : access struct_sched_param) return int; |
| 436 |
pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); |
| 437 |
|
| 438 |
function pthread_attr_setscope |
| 439 |
(attr : access pthread_attr_t; |
| 440 |
contentionscope : int) return int; |
| 441 |
pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); |
| 442 |
|
| 443 |
function pthread_attr_setinheritsched |
| 444 |
(attr : access pthread_attr_t; |
| 445 |
inheritsched : int) return int; |
| 446 |
pragma Import |
| 447 |
(C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched"); |
| 448 |
|
| 449 |
function pthread_attr_setschedpolicy |
| 450 |
(attr : access pthread_attr_t; |
| 451 |
policy : int) return int; |
| 452 |
pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched"); |
| 453 |
|
| 454 |
function sched_yield return int; |
| 455 |
|
| 456 |
--------------------------- |
| 457 |
-- P1003.1c - Section 16 -- |
| 458 |
--------------------------- |
| 459 |
|
| 460 |
function pthread_attr_init (attributes : access pthread_attr_t) return int; |
| 461 |
pragma Import (C, pthread_attr_init, "pthread_attr_init"); |
| 462 |
|
| 463 |
function pthread_attr_destroy |
| 464 |
(attributes : access pthread_attr_t) return int; |
| 465 |
pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); |
| 466 |
|
| 467 |
function pthread_attr_setdetachstate |
| 468 |
(attr : access pthread_attr_t; |
| 469 |
detachstate : int) return int; |
| 470 |
pragma Import |
| 471 |
(C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate"); |
| 472 |
|
| 473 |
function pthread_attr_setstacksize |
| 474 |
(attr : access pthread_attr_t; |
| 475 |
stacksize : size_t) return int; |
| 476 |
pragma Import |
| 477 |
(C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); |
| 478 |
|
| 479 |
function pthread_create |
| 480 |
(thread : access pthread_t; |
| 481 |
attributes : access pthread_attr_t; |
| 482 |
start_routine : Thread_Body; |
| 483 |
arg : System.Address) return int; |
| 484 |
pragma Import (C, pthread_create, "pthread_create"); |
| 485 |
|
| 486 |
procedure pthread_exit (status : System.Address); |
| 487 |
pragma Import (C, pthread_exit, "pthread_exit"); |
| 488 |
|
| 489 |
function pthread_self return pthread_t; |
| 490 |
pragma Import (C, pthread_self, "pthread_self"); |
| 491 |
|
| 492 |
-------------------------- |
| 493 |
-- POSIX.1c Section 17 -- |
| 494 |
-------------------------- |
| 495 |
|
| 496 |
function pthread_setspecific |
| 497 |
(key : pthread_key_t; |
| 498 |
value : System.Address) return int; |
| 499 |
pragma Import (C, pthread_setspecific, "pthread_setspecific"); |
| 500 |
|
| 501 |
function pthread_getspecific (key : pthread_key_t) return System.Address; |
| 502 |
pragma Import (C, pthread_getspecific, "pthread_getspecific"); |
| 503 |
|
| 504 |
type destructor_pointer is access procedure (arg : System.Address); |
| 505 |
pragma Convention (C, destructor_pointer); |
| 506 |
|
| 507 |
function pthread_key_create |
| 508 |
(key : access pthread_key_t; |
| 509 |
destructor : destructor_pointer) return int; |
| 510 |
pragma Import (C, pthread_key_create, "pthread_key_create"); |
| 511 |
|
| 512 |
private |
| 513 |
|
| 514 |
type sigset_t is new unsigned; |
| 515 |
|
| 516 |
type int32_t is new int; |
| 517 |
|
| 518 |
type pid_t is new int32_t; |
| 519 |
|
| 520 |
type time_t is range -2 ** (System.Parameters.time_t_bits - 1) |
| 521 |
.. 2 ** (System.Parameters.time_t_bits - 1) - 1; |
| 522 |
|
| 523 |
type timespec is record |
| 524 |
tv_sec : time_t; |
| 525 |
tv_nsec : long; |
| 526 |
end record; |
| 527 |
pragma Convention (C, timespec); |
| 528 |
|
| 529 |
-- |
| 530 |
-- Darwin specific signal implementation |
| 531 |
-- |
| 532 |
type Pad_Type is array (1 .. 7) of unsigned_long; |
| 533 |
type siginfo_t is record |
| 534 |
si_signo : int; -- signal number |
| 535 |
si_errno : int; -- errno association |
| 536 |
si_code : int; -- signal code |
| 537 |
si_pid : int; -- sending process |
| 538 |
si_uid : unsigned; -- sender's ruid |
| 539 |
si_status : int; -- exit value |
| 540 |
si_addr : System.Address; -- faulting instruction |
| 541 |
si_value : System.Address; -- signal value |
| 542 |
si_band : long; -- band event for SIGPOLL |
| 543 |
pad : Pad_Type; -- RFU |
| 544 |
end record; |
| 545 |
pragma Convention (C, siginfo_t); |
| 546 |
|
| 547 |
type mcontext_t is new System.Address; |
| 548 |
|
| 549 |
type ucontext_t is record |
| 550 |
uc_onstack : int; |
| 551 |
uc_sigmask : sigset_t; -- Signal Mask Used By This Context |
| 552 |
uc_stack : stack_t; -- Stack Used By This Context |
| 553 |
uc_link : System.Address; -- Pointer To Resuming Context |
| 554 |
uc_mcsize : size_t; -- Size of The Machine Context |
| 555 |
uc_mcontext : mcontext_t; -- Machine Specific Context |
| 556 |
end record; |
| 557 |
pragma Convention (C, ucontext_t); |
| 558 |
|
| 559 |
-- |
| 560 |
-- Darwin specific pthread implementation |
| 561 |
-- |
| 562 |
type pthread_t is new System.Address; |
| 563 |
|
| 564 |
type pthread_attr_t is record |
| 565 |
sig : long; |
| 566 |
opaque : padding (1 .. System.OS_Constants.PTHREAD_ATTR_SIZE); |
| 567 |
end record; |
| 568 |
pragma Convention (C, pthread_attr_t); |
| 569 |
|
| 570 |
type pthread_mutexattr_t is record |
| 571 |
sig : long; |
| 572 |
opaque : padding (1 .. System.OS_Constants.PTHREAD_MUTEXATTR_SIZE); |
| 573 |
end record; |
| 574 |
pragma Convention (C, pthread_mutexattr_t); |
| 575 |
|
| 576 |
type pthread_condattr_t is record |
| 577 |
sig : long; |
| 578 |
opaque : padding (1 .. System.OS_Constants.PTHREAD_CONDATTR_SIZE); |
| 579 |
end record; |
| 580 |
pragma Convention (C, pthread_condattr_t); |
| 581 |
|
| 582 |
type pthread_cond_t is record |
| 583 |
sig : long; |
| 584 |
opaque : padding (1 .. System.OS_Constants.PTHREAD_COND_SIZE); |
| 585 |
end record; |
| 586 |
pragma Convention (C, pthread_cond_t); |
| 587 |
|
| 588 |
type pthread_once_t is record |
| 589 |
sig : long; |
| 590 |
opaque : padding (1 .. System.OS_Constants.PTHREAD_ONCE_SIZE); |
| 591 |
end record; |
| 592 |
pragma Convention (C, pthread_once_t); |
| 593 |
|
| 594 |
type pthread_key_t is new unsigned_long; |
| 595 |
|
| 596 |
end System.OS_Interface; |