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-2019, 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 a GNU/Linux version of this package 34 35-- This package encapsulates all direct interfaces to OS services 36-- that are needed by the tasking run-time (libgnarl). 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 41with Ada.Unchecked_Conversion; 42with Interfaces.C; 43with System.Linux; 44with System.OS_Constants; 45 46package System.OS_Interface is 47 pragma Preelaborate; 48 49 pragma Linker_Options ("-lpthread"); 50 pragma Linker_Options ("-lrt"); 51 -- Needed for clock_getres with glibc versions prior to 2.17 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 := System.Linux.EAGAIN; 72 EINTR : constant := System.Linux.EINTR; 73 EINVAL : constant := System.Linux.EINVAL; 74 ENOMEM : constant := System.Linux.ENOMEM; 75 EPERM : constant := System.Linux.EPERM; 76 ETIMEDOUT : constant := System.Linux.ETIMEDOUT; 77 78 ------------- 79 -- Signals -- 80 ------------- 81 82 Max_Interrupt : constant := 63; 83 type Signal is new int range 0 .. Max_Interrupt; 84 for Signal'Size use int'Size; 85 86 SIGHUP : constant := System.Linux.SIGHUP; 87 SIGINT : constant := System.Linux.SIGINT; 88 SIGQUIT : constant := System.Linux.SIGQUIT; 89 SIGILL : constant := System.Linux.SIGILL; 90 SIGTRAP : constant := System.Linux.SIGTRAP; 91 SIGIOT : constant := System.Linux.SIGIOT; 92 SIGABRT : constant := System.Linux.SIGABRT; 93 SIGBUS : constant := System.Linux.SIGBUS; 94 SIGFPE : constant := System.Linux.SIGFPE; 95 SIGKILL : constant := System.Linux.SIGKILL; 96 SIGUSR1 : constant := System.Linux.SIGUSR1; 97 SIGSEGV : constant := System.Linux.SIGSEGV; 98 SIGUSR2 : constant := System.Linux.SIGUSR2; 99 SIGPIPE : constant := System.Linux.SIGPIPE; 100 SIGALRM : constant := System.Linux.SIGALRM; 101 SIGTERM : constant := System.Linux.SIGTERM; 102 SIGSTKFLT : constant := System.Linux.SIGSTKFLT; 103 SIGCLD : constant := System.Linux.SIGCLD; 104 SIGCHLD : constant := System.Linux.SIGCHLD; 105 SIGCONT : constant := System.Linux.SIGCONT; 106 SIGSTOP : constant := System.Linux.SIGSTOP; 107 SIGTSTP : constant := System.Linux.SIGTSTP; 108 SIGTTIN : constant := System.Linux.SIGTTIN; 109 SIGTTOU : constant := System.Linux.SIGTTOU; 110 SIGURG : constant := System.Linux.SIGURG; 111 SIGXCPU : constant := System.Linux.SIGXCPU; 112 SIGXFSZ : constant := System.Linux.SIGXFSZ; 113 SIGVTALRM : constant := System.Linux.SIGVTALRM; 114 SIGPROF : constant := System.Linux.SIGPROF; 115 SIGWINCH : constant := System.Linux.SIGWINCH; 116 SIGPOLL : constant := System.Linux.SIGPOLL; 117 SIGIO : constant := System.Linux.SIGIO; 118 SIGLOST : constant := System.Linux.SIGLOST; 119 SIGPWR : constant := System.Linux.SIGPWR; 120 SIGSYS : constant := System.Linux.SIGSYS; 121 SIGUNUSED : constant := System.Linux.SIGUNUSED; 122 SIG32 : constant := System.Linux.SIG32; 123 SIG33 : constant := System.Linux.SIG33; 124 SIG34 : constant := System.Linux.SIG34; 125 126 SIGADAABORT : constant := SIGABRT; 127 -- Change this to use another signal for task abort. SIGTERM might be a 128 -- good one. 129 130 type Signal_Set is array (Natural range <>) of Signal; 131 132 Unmasked : constant Signal_Set := ( 133 SIGTRAP, 134 -- To enable debugging on multithreaded applications, mark SIGTRAP to 135 -- be kept unmasked. 136 137 SIGBUS, 138 139 SIGTTIN, SIGTTOU, SIGTSTP, 140 -- Keep these three signals unmasked so that background processes and IO 141 -- behaves as normal "C" applications 142 143 SIGPROF, 144 -- To avoid confusing the profiler 145 146 SIGKILL, SIGSTOP 147 -- These two signals actually can't be masked (POSIX won't allow it) 148 ); 149 150 Reserved : constant Signal_Set := ( 151 SIG32, SIG33, SIG34 152 -- glibc POSIX threads implementation uses two (NPTL) or three 153 -- (LinuxThreads) real-time signals for its own use (see SIGNAL(7)). 154 -- These signals are considered reserved and not unmasked as glibc does 155 -- not permit these signals to be used by the public signal.h API. 156 -- While LinuxThreads is mostly likely unused now, SIG34 is still 157 -- reserved as this behavior is consistent with past GNAT releases. 158 ); 159 160 type sigset_t is private; 161 162 function sigaddset (set : access sigset_t; sig : Signal) return int; 163 pragma Import (C, sigaddset, "sigaddset"); 164 165 function sigdelset (set : access sigset_t; sig : Signal) return int; 166 pragma Import (C, sigdelset, "sigdelset"); 167 168 function sigfillset (set : access sigset_t) return int; 169 pragma Import (C, sigfillset, "sigfillset"); 170 171 function sigismember (set : access sigset_t; sig : Signal) return int; 172 pragma Import (C, sigismember, "sigismember"); 173 174 function sigemptyset (set : access sigset_t) return int; 175 pragma Import (C, sigemptyset, "sigemptyset"); 176 177 type union_type_3 is new String (1 .. 116); 178 type siginfo_t is record 179 si_signo : int; 180 si_code : int; 181 si_errno : int; 182 X_data : union_type_3; 183 end record; 184 pragma Convention (C, siginfo_t); 185 186 type struct_sigaction is record 187 sa_handler : System.Address; 188 sa_mask : sigset_t; 189 sa_flags : int; 190 sa_restorer : System.Address; 191 end record; 192 pragma Convention (C, struct_sigaction); 193 194 type struct_sigaction_ptr is access all struct_sigaction; 195 196 type Machine_State is record 197 eip : unsigned_long; 198 ebx : unsigned_long; 199 esp : unsigned_long; 200 ebp : unsigned_long; 201 esi : unsigned_long; 202 edi : unsigned_long; 203 end record; 204 type Machine_State_Ptr is access all Machine_State; 205 206 SA_SIGINFO : constant := System.Linux.SA_SIGINFO; 207 SA_ONSTACK : constant := System.Linux.SA_ONSTACK; 208 209 SIG_BLOCK : constant := 0; 210 SIG_UNBLOCK : constant := 1; 211 SIG_SETMASK : constant := 2; 212 213 SIG_DFL : constant := 0; 214 SIG_IGN : constant := 1; 215 216 function sigaction 217 (sig : Signal; 218 act : struct_sigaction_ptr; 219 oact : struct_sigaction_ptr) return int; 220 pragma Import (C, sigaction, "sigaction"); 221 222 ---------- 223 -- Time -- 224 ---------- 225 226 subtype time_t is System.Linux.time_t; 227 subtype timespec is System.Linux.timespec; 228 subtype timeval is System.Linux.timeval; 229 subtype clockid_t is System.Linux.clockid_t; 230 231 function clock_gettime 232 (clock_id : clockid_t; tp : access timespec) return int; 233 pragma Import (C, clock_gettime, "clock_gettime"); 234 235 function clock_getres 236 (clock_id : clockid_t; 237 res : access timespec) return int; 238 pragma Import (C, clock_getres, "clock_getres"); 239 240 function To_Duration (TS : timespec) return Duration; 241 pragma Inline (To_Duration); 242 243 function To_Timespec (D : Duration) return timespec; 244 pragma Inline (To_Timespec); 245 246 function sysconf (name : int) return long; 247 pragma Import (C, sysconf); 248 249 SC_CLK_TCK : constant := 2; 250 SC_NPROCESSORS_ONLN : constant := 84; 251 252 ------------------------- 253 -- Priority Scheduling -- 254 ------------------------- 255 256 SCHED_OTHER : constant := 0; 257 SCHED_FIFO : constant := 1; 258 SCHED_RR : constant := 2; 259 260 function To_Target_Priority 261 (Prio : System.Any_Priority) return Interfaces.C.int; 262 -- Maps System.Any_Priority to a POSIX priority 263 264 ------------- 265 -- Process -- 266 ------------- 267 268 type pid_t is private; 269 270 function kill (pid : pid_t; sig : Signal) return int; 271 pragma Import (C, kill, "kill"); 272 273 function getpid return pid_t; 274 pragma Import (C, getpid, "getpid"); 275 276 PR_SET_NAME : constant := 15; 277 PR_GET_NAME : constant := 16; 278 279 function prctl 280 (option : int; 281 arg2, arg3, arg4, arg5 : unsigned_long := 0) return int; 282 pragma Import (C, prctl); 283 284 ------------- 285 -- Threads -- 286 ------------- 287 288 type Thread_Body is access 289 function (arg : System.Address) return System.Address; 290 pragma Convention (C, Thread_Body); 291 292 function Thread_Body_Access is new 293 Ada.Unchecked_Conversion (System.Address, Thread_Body); 294 295 type pthread_t is new unsigned_long; 296 subtype Thread_Id is pthread_t; 297 298 function To_pthread_t is 299 new Ada.Unchecked_Conversion (unsigned_long, pthread_t); 300 301 type pthread_mutex_t is limited private; 302 type pthread_rwlock_t is limited private; 303 type pthread_cond_t is limited private; 304 type pthread_attr_t is limited private; 305 type pthread_mutexattr_t is limited private; 306 type pthread_rwlockattr_t is limited private; 307 type pthread_condattr_t is limited private; 308 type pthread_key_t is private; 309 310 PTHREAD_CREATE_DETACHED : constant := 1; 311 312 ----------- 313 -- Stack -- 314 ----------- 315 316 type stack_t is record 317 ss_sp : System.Address; 318 ss_flags : int; 319 ss_size : size_t; 320 end record; 321 pragma Convention (C, stack_t); 322 323 function sigaltstack 324 (ss : not null access stack_t; 325 oss : access stack_t) return int; 326 pragma Import (C, sigaltstack, "sigaltstack"); 327 328 Alternate_Stack : aliased System.Address; 329 pragma Import (C, Alternate_Stack, "__gnat_alternate_stack"); 330 -- The alternate signal stack for stack overflows 331 332 Alternate_Stack_Size : constant := 16 * 1024; 333 -- This must be in keeping with init.c:__gnat_alternate_stack 334 335 function Get_Stack_Base (thread : pthread_t) return Address; 336 pragma Inline (Get_Stack_Base); 337 -- This is a dummy procedure to share some GNULLI files 338 339 --------------------------------------- 340 -- Nonstandard Thread Initialization -- 341 --------------------------------------- 342 343 procedure pthread_init; 344 pragma Inline (pthread_init); 345 -- This is a dummy procedure to share some GNULLI files 346 347 ------------------------- 348 -- POSIX.1c Section 3 -- 349 ------------------------- 350 351 function sigwait (set : access sigset_t; sig : access Signal) return int; 352 pragma Import (C, sigwait, "sigwait"); 353 354 function pthread_kill (thread : pthread_t; sig : Signal) return int; 355 pragma Import (C, pthread_kill, "pthread_kill"); 356 357 function pthread_sigmask 358 (how : int; 359 set : access sigset_t; 360 oset : access sigset_t) return int; 361 pragma Import (C, pthread_sigmask, "pthread_sigmask"); 362 363 -------------------------- 364 -- POSIX.1c Section 11 -- 365 -------------------------- 366 367 function pthread_mutexattr_init 368 (attr : access pthread_mutexattr_t) return int; 369 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); 370 371 function pthread_mutexattr_destroy 372 (attr : access pthread_mutexattr_t) return int; 373 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); 374 375 function pthread_mutex_init 376 (mutex : access pthread_mutex_t; 377 attr : access pthread_mutexattr_t) return int; 378 pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); 379 380 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; 381 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); 382 383 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; 384 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); 385 386 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; 387 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); 388 389 function pthread_rwlockattr_init 390 (attr : access pthread_rwlockattr_t) return int; 391 pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init"); 392 393 function pthread_rwlockattr_destroy 394 (attr : access pthread_rwlockattr_t) return int; 395 pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy"); 396 397 PTHREAD_RWLOCK_PREFER_READER_NP : constant := 0; 398 PTHREAD_RWLOCK_PREFER_WRITER_NP : constant := 1; 399 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2; 400 401 function pthread_rwlockattr_setkind_np 402 (attr : access pthread_rwlockattr_t; 403 pref : int) return int; 404 pragma Import 405 (C, pthread_rwlockattr_setkind_np, "pthread_rwlockattr_setkind_np"); 406 407 function pthread_rwlock_init 408 (mutex : access pthread_rwlock_t; 409 attr : access pthread_rwlockattr_t) return int; 410 pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init"); 411 412 function pthread_rwlock_destroy 413 (mutex : access pthread_rwlock_t) return int; 414 pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy"); 415 416 function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int; 417 pragma Import (C, pthread_rwlock_rdlock, "pthread_rwlock_rdlock"); 418 419 function pthread_rwlock_wrlock (mutex : access pthread_rwlock_t) return int; 420 pragma Import (C, pthread_rwlock_wrlock, "pthread_rwlock_wrlock"); 421 422 function pthread_rwlock_unlock (mutex : access pthread_rwlock_t) return int; 423 pragma Import (C, pthread_rwlock_unlock, "pthread_rwlock_unlock"); 424 425 function pthread_condattr_init 426 (attr : access pthread_condattr_t) return int; 427 pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); 428 429 function pthread_condattr_destroy 430 (attr : access pthread_condattr_t) return int; 431 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); 432 433 function pthread_cond_init 434 (cond : access pthread_cond_t; 435 attr : access pthread_condattr_t) return int; 436 pragma Import (C, pthread_cond_init, "pthread_cond_init"); 437 438 function pthread_cond_destroy (cond : access pthread_cond_t) return int; 439 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); 440 441 function pthread_cond_signal (cond : access pthread_cond_t) return int; 442 pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); 443 444 function pthread_cond_wait 445 (cond : access pthread_cond_t; 446 mutex : access pthread_mutex_t) return int; 447 pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); 448 449 function pthread_cond_timedwait 450 (cond : access pthread_cond_t; 451 mutex : access pthread_mutex_t; 452 abstime : access timespec) return int; 453 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); 454 455 -------------------------- 456 -- POSIX.1c Section 13 -- 457 -------------------------- 458 459 PTHREAD_PRIO_NONE : constant := 0; 460 PTHREAD_PRIO_INHERIT : constant := 1; 461 PTHREAD_PRIO_PROTECT : constant := 2; 462 463 function pthread_mutexattr_setprotocol 464 (attr : access pthread_mutexattr_t; 465 protocol : int) return int; 466 pragma Import (C, pthread_mutexattr_setprotocol); 467 468 function pthread_mutexattr_setprioceiling 469 (attr : access pthread_mutexattr_t; 470 prioceiling : int) return int; 471 pragma Import (C, pthread_mutexattr_setprioceiling); 472 473 type struct_sched_param is record 474 sched_priority : int; -- scheduling priority 475 end record; 476 pragma Convention (C, struct_sched_param); 477 478 function pthread_setschedparam 479 (thread : pthread_t; 480 policy : int; 481 param : access struct_sched_param) return int; 482 pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); 483 484 function pthread_attr_setschedpolicy 485 (attr : access pthread_attr_t; 486 policy : int) return int; 487 pragma Import 488 (C, pthread_attr_setschedpolicy, "pthread_attr_setschedpolicy"); 489 490 function sched_yield return int; 491 pragma Import (C, sched_yield, "sched_yield"); 492 493 --------------------------- 494 -- P1003.1c - Section 16 -- 495 --------------------------- 496 497 function pthread_attr_init 498 (attributes : access pthread_attr_t) return int; 499 pragma Import (C, pthread_attr_init, "pthread_attr_init"); 500 501 function pthread_attr_destroy 502 (attributes : access pthread_attr_t) return int; 503 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); 504 505 function pthread_attr_setdetachstate 506 (attr : access pthread_attr_t; 507 detachstate : int) return int; 508 pragma Import 509 (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate"); 510 511 function pthread_attr_setstacksize 512 (attr : access pthread_attr_t; 513 stacksize : size_t) return int; 514 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); 515 516 function pthread_create 517 (thread : access pthread_t; 518 attributes : access pthread_attr_t; 519 start_routine : Thread_Body; 520 arg : System.Address) return int; 521 pragma Import (C, pthread_create, "pthread_create"); 522 523 procedure pthread_exit (status : System.Address); 524 pragma Import (C, pthread_exit, "pthread_exit"); 525 526 function pthread_self return pthread_t; 527 pragma Import (C, pthread_self, "pthread_self"); 528 529 function lwp_self return System.Address; 530 pragma Import (C, lwp_self, "__gnat_lwp_self"); 531 532 -------------------------- 533 -- POSIX.1c Section 17 -- 534 -------------------------- 535 536 function pthread_setspecific 537 (key : pthread_key_t; 538 value : System.Address) return int; 539 pragma Import (C, pthread_setspecific, "pthread_setspecific"); 540 541 function pthread_getspecific (key : pthread_key_t) return System.Address; 542 pragma Import (C, pthread_getspecific, "pthread_getspecific"); 543 544 type destructor_pointer is access procedure (arg : System.Address); 545 pragma Convention (C, destructor_pointer); 546 547 function pthread_key_create 548 (key : access pthread_key_t; 549 destructor : destructor_pointer) return int; 550 pragma Import (C, pthread_key_create, "pthread_key_create"); 551 552 ---------------- 553 -- Extensions -- 554 ---------------- 555 556 CPU_SETSIZE : constant := 1_024; 557 -- Size of the cpu_set_t mask on most linux systems (SUSE 11 uses 4_096). 558 -- This is kept for backward compatibility (System.Task_Info uses it), but 559 -- the run-time library does no longer rely on static masks, using 560 -- dynamically allocated masks instead. 561 562 type bit_field is array (1 .. CPU_SETSIZE) of Boolean; 563 for bit_field'Size use CPU_SETSIZE; 564 pragma Pack (bit_field); 565 pragma Convention (C, bit_field); 566 567 type cpu_set_t is record 568 bits : bit_field; 569 end record; 570 pragma Convention (C, cpu_set_t); 571 572 type cpu_set_t_ptr is access all cpu_set_t; 573 -- In the run-time library we use this pointer because the size of type 574 -- cpu_set_t varies depending on the glibc version. Hence, objects of type 575 -- cpu_set_t are allocated dynamically using the number of processors 576 -- available in the target machine (value obtained at execution time). 577 578 function CPU_ALLOC (count : size_t) return cpu_set_t_ptr; 579 pragma Import (C, CPU_ALLOC, "__gnat_cpu_alloc"); 580 -- Wrapper around the CPU_ALLOC C macro 581 582 function CPU_ALLOC_SIZE (count : size_t) return size_t; 583 pragma Import (C, CPU_ALLOC_SIZE, "__gnat_cpu_alloc_size"); 584 -- Wrapper around the CPU_ALLOC_SIZE C macro 585 586 procedure CPU_FREE (cpuset : cpu_set_t_ptr); 587 pragma Import (C, CPU_FREE, "__gnat_cpu_free"); 588 -- Wrapper around the CPU_FREE C macro 589 590 procedure CPU_ZERO (count : size_t; cpuset : cpu_set_t_ptr); 591 pragma Import (C, CPU_ZERO, "__gnat_cpu_zero"); 592 -- Wrapper around the CPU_ZERO_S C macro 593 594 procedure CPU_SET (cpu : int; count : size_t; cpuset : cpu_set_t_ptr); 595 pragma Import (C, CPU_SET, "__gnat_cpu_set"); 596 -- Wrapper around the CPU_SET_S C macro 597 598 function pthread_setaffinity_np 599 (thread : pthread_t; 600 cpusetsize : size_t; 601 cpuset : cpu_set_t_ptr) return int; 602 pragma Import (C, pthread_setaffinity_np, "pthread_setaffinity_np"); 603 pragma Weak_External (pthread_setaffinity_np); 604 -- Use a weak symbol because this function may be available or not, 605 -- depending on the version of the system. 606 607 function pthread_attr_setaffinity_np 608 (attr : access pthread_attr_t; 609 cpusetsize : size_t; 610 cpuset : cpu_set_t_ptr) return int; 611 pragma Import (C, pthread_attr_setaffinity_np, 612 "pthread_attr_setaffinity_np"); 613 pragma Weak_External (pthread_attr_setaffinity_np); 614 -- Use a weak symbol because this function may be available or not, 615 -- depending on the version of the system. 616 617private 618 619 type sigset_t is 620 array (0 .. OS_Constants.SIZEOF_sigset - 1) of unsigned_char; 621 pragma Convention (C, sigset_t); 622 for sigset_t'Alignment use Interfaces.C.unsigned_long'Alignment; 623 624 pragma Warnings (Off); 625 for struct_sigaction use record 626 sa_handler at Linux.sa_handler_pos range 0 .. Standard'Address_Size - 1; 627 sa_mask at Linux.sa_mask_pos range 0 .. 1023; 628 sa_flags at Linux.sa_flags_pos range 0 .. int'Size - 1; 629 end record; 630 -- We intentionally leave sa_restorer unspecified and let the compiler 631 -- append it after the last field, so disable corresponding warning. 632 pragma Warnings (On); 633 634 type pid_t is new int; 635 636 subtype char_array is Interfaces.C.char_array; 637 638 type pthread_attr_t is record 639 Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE); 640 end record; 641 pragma Convention (C, pthread_attr_t); 642 for pthread_attr_t'Alignment use Interfaces.C.unsigned_long'Alignment; 643 644 type pthread_condattr_t is record 645 Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE); 646 end record; 647 pragma Convention (C, pthread_condattr_t); 648 for pthread_condattr_t'Alignment use Interfaces.C.int'Alignment; 649 650 type pthread_mutexattr_t is record 651 Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE); 652 end record; 653 pragma Convention (C, pthread_mutexattr_t); 654 for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment; 655 656 type pthread_mutex_t is record 657 Data : char_array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE); 658 end record; 659 pragma Convention (C, pthread_mutex_t); 660 for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment; 661 662 type pthread_rwlockattr_t is record 663 Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE); 664 end record; 665 pragma Convention (C, pthread_rwlockattr_t); 666 for pthread_rwlockattr_t'Alignment use Interfaces.C.unsigned_long'Alignment; 667 668 type pthread_rwlock_t is record 669 Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCK_SIZE); 670 end record; 671 pragma Convention (C, pthread_rwlock_t); 672 for pthread_rwlock_t'Alignment use Interfaces.C.unsigned_long'Alignment; 673 674 type pthread_cond_t is record 675 Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE); 676 end record; 677 pragma Convention (C, pthread_cond_t); 678 for pthread_cond_t'Alignment use Interfaces.Unsigned_64'Alignment; 679 680 type pthread_key_t is new unsigned; 681 682end System.OS_Interface; 683