| 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) 1997-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNARL is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 17 |
-- -- |
| 18 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 19 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 20 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 21 |
-- -- |
| 22 |
-- You should have received a copy of the GNU General Public License and -- |
| 23 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 24 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 25 |
-- <http://www.gnu.org/licenses/>. -- |
| 26 |
-- -- |
| 27 |
-- GNARL was developed by the GNARL team at Florida State University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
-- The GNARL files that were developed for RTEMS are maintained by On-Line -- |
| 31 |
-- Applications Research Corporation (http://www.oarcorp.com) in coopera- -- |
| 32 |
-- tion with Ada Core Technologies Inc. and Florida State University. -- |
| 33 |
-- -- |
| 34 |
------------------------------------------------------------------------------ |
| 35 |
|
| 36 |
-- This is the RTEMS version of this package. |
| 37 |
-- |
| 38 |
-- RTEMS target names are of the form CPU-rtems. |
| 39 |
-- This implementation is designed to work on ALL RTEMS targets. |
| 40 |
-- The RTEMS implementation is primarily based upon the POSIX threads |
| 41 |
-- API but there are also bindings to GNAT/RTEMS support routines |
| 42 |
-- to insulate this code from C API specific details and, in some |
| 43 |
-- cases, obtain target architecture and BSP specific information |
| 44 |
-- that is unavailable at the time this package is built. |
| 45 |
|
| 46 |
-- This package encapsulates all direct interfaces to OS services |
| 47 |
-- that are needed by children of System. |
| 48 |
|
| 49 |
-- PLEASE DO NOT add any with-clauses to this package |
| 50 |
-- or remove the pragma Preelaborate. |
| 51 |
-- It is designed to be a bottom-level (leaf) package. |
| 52 |
|
| 53 |
with Interfaces.C; |
| 54 |
|
| 55 |
with System.OS_Constants; |
| 56 |
with System.OS_Locks; |
| 57 |
with System.Parameters; |
| 58 |
|
| 59 |
package System.OS_Interface is |
| 60 |
pragma Preelaborate; |
| 61 |
|
| 62 |
-- This interface assumes that "unsigned" is a 32-bit entity. This |
| 63 |
-- will correspond to RTEMS object ids. |
| 64 |
|
| 65 |
subtype rtems_id is Interfaces.C.unsigned; |
| 66 |
|
| 67 |
subtype int is Interfaces.C.int; |
| 68 |
subtype char is Interfaces.C.char; |
| 69 |
subtype short is Interfaces.C.short; |
| 70 |
subtype long is Interfaces.C.long; |
| 71 |
subtype unsigned is Interfaces.C.unsigned; |
| 72 |
subtype unsigned_short is Interfaces.C.unsigned_short; |
| 73 |
subtype unsigned_long is Interfaces.C.unsigned_long; |
| 74 |
subtype unsigned_char is Interfaces.C.unsigned_char; |
| 75 |
subtype plain_char is Interfaces.C.plain_char; |
| 76 |
subtype size_t is Interfaces.C.size_t; |
| 77 |
----------- |
| 78 |
-- Errno -- |
| 79 |
----------- |
| 80 |
|
| 81 |
function errno return int; |
| 82 |
pragma Import (C, errno, "__get_errno"); |
| 83 |
|
| 84 |
EAGAIN : constant := System.OS_Constants.EAGAIN; |
| 85 |
EINTR : constant := System.OS_Constants.EINTR; |
| 86 |
EINVAL : constant := System.OS_Constants.EINVAL; |
| 87 |
ENOMEM : constant := System.OS_Constants.ENOMEM; |
| 88 |
ETIMEDOUT : constant := System.OS_Constants.ETIMEDOUT; |
| 89 |
|
| 90 |
---------------------------- |
| 91 |
-- Signals and Interrupts -- |
| 92 |
---------------------------- |
| 93 |
|
| 94 |
NSIG : constant := 64; |
| 95 |
-- Number of signals on the target OS |
| 96 |
type Signal is new int range 0 .. Interfaces.C."-" (NSIG, 1); |
| 97 |
|
| 98 |
Max_HW_Interrupt : constant := 255; |
| 99 |
type HW_Interrupt is new int range 0 .. Max_HW_Interrupt; |
| 100 |
|
| 101 |
Max_Interrupt : constant := Max_HW_Interrupt; |
| 102 |
subtype Interrupt_Range is Natural range 0 .. Max_HW_Interrupt; |
| 103 |
-- For s-interr |
| 104 |
|
| 105 |
SIGXCPU : constant := 0; -- XCPU |
| 106 |
SIGHUP : constant := 1; -- hangup |
| 107 |
SIGINT : constant := 2; -- interrupt (rubout) |
| 108 |
SIGQUIT : constant := 3; -- quit (ASCD FS) |
| 109 |
SIGILL : constant := 4; -- illegal instruction (not reset) |
| 110 |
SIGTRAP : constant := 5; -- trace trap (not reset) |
| 111 |
SIGIOT : constant := 6; -- IOT instruction |
| 112 |
SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future |
| 113 |
SIGEMT : constant := 7; -- EMT instruction |
| 114 |
SIGFPE : constant := 8; -- floating point exception |
| 115 |
SIGKILL : constant := 9; -- kill (cannot be caught or ignored) |
| 116 |
SIGBUS : constant := 10; -- bus error |
| 117 |
SIGSEGV : constant := 11; -- segmentation violation |
| 118 |
SIGSYS : constant := 12; -- bad argument to system call |
| 119 |
SIGPIPE : constant := 13; -- write on a pipe with no one to read it |
| 120 |
SIGALRM : constant := 14; -- alarm clock |
| 121 |
SIGTERM : constant := 15; -- software termination signal from kill |
| 122 |
SIGUSR1 : constant := 16; -- user defined signal 1 |
| 123 |
SIGUSR2 : constant := 17; -- user defined signal 2 |
| 124 |
|
| 125 |
SIGADAABORT : constant := SIGABRT; |
| 126 |
|
| 127 |
type Signal_Set is array (Natural range <>) of Signal; |
| 128 |
|
| 129 |
Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT); |
| 130 |
Reserved : constant Signal_Set := (1 .. 1 => SIGKILL); |
| 131 |
|
| 132 |
type sigset_t is private; |
| 133 |
|
| 134 |
function sigaddset (set : access sigset_t; sig : Signal) return int; |
| 135 |
pragma Import (C, sigaddset, "sigaddset"); |
| 136 |
|
| 137 |
function sigdelset (set : access sigset_t; sig : Signal) return int; |
| 138 |
pragma Import (C, sigdelset, "sigdelset"); |
| 139 |
|
| 140 |
function sigfillset (set : access sigset_t) return int; |
| 141 |
pragma Import (C, sigfillset, "sigfillset"); |
| 142 |
|
| 143 |
function sigismember (set : access sigset_t; sig : Signal) return int; |
| 144 |
pragma Import (C, sigismember, "sigismember"); |
| 145 |
|
| 146 |
function sigemptyset (set : access sigset_t) return int; |
| 147 |
pragma Import (C, sigemptyset, "sigemptyset"); |
| 148 |
|
| 149 |
type struct_sigaction is record |
| 150 |
sa_flags : int; |
| 151 |
sa_mask : sigset_t; |
| 152 |
sa_handler : System.Address; |
| 153 |
end record; |
| 154 |
pragma Convention (C, struct_sigaction); |
| 155 |
type struct_sigaction_ptr is access all struct_sigaction; |
| 156 |
|
| 157 |
SA_SIGINFO : constant := 16#02#; |
| 158 |
|
| 159 |
SA_ONSTACK : constant := 16#00#; |
| 160 |
-- SA_ONSTACK is not defined on RTEMS, but it is referred to in the POSIX |
| 161 |
-- implementation of System.Interrupt_Management. Therefore we define a |
| 162 |
-- dummy value of zero here so that setting this flag is a nop. |
| 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 |
function sigaction |
| 172 |
(sig : Signal; |
| 173 |
act : struct_sigaction_ptr; |
| 174 |
oact : struct_sigaction_ptr) return int; |
| 175 |
pragma Import (C, sigaction, "sigaction"); |
| 176 |
|
| 177 |
---------- |
| 178 |
-- Time -- |
| 179 |
---------- |
| 180 |
|
| 181 |
Time_Slice_Supported : constant Boolean := True; |
| 182 |
-- Indicates whether time slicing is supported (i.e SCHED_RR is supported) |
| 183 |
|
| 184 |
type timespec is private; |
| 185 |
|
| 186 |
type clockid_t is new int; |
| 187 |
|
| 188 |
CLOCK_REALTIME : constant clockid_t; |
| 189 |
CLOCK_MONOTONIC : constant clockid_t; |
| 190 |
|
| 191 |
function clock_gettime |
| 192 |
(clock_id : clockid_t; |
| 193 |
tp : access timespec) return int; |
| 194 |
pragma Import (C, clock_gettime, "clock_gettime"); |
| 195 |
|
| 196 |
function clock_getres |
| 197 |
(clock_id : clockid_t; |
| 198 |
res : access timespec) return int; |
| 199 |
pragma Import (C, clock_getres, "clock_getres"); |
| 200 |
|
| 201 |
function To_Duration (TS : timespec) return Duration; |
| 202 |
pragma Inline (To_Duration); |
| 203 |
|
| 204 |
function To_Timespec (D : Duration) return timespec; |
| 205 |
pragma Inline (To_Timespec); |
| 206 |
|
| 207 |
------------------------- |
| 208 |
-- Priority Scheduling -- |
| 209 |
------------------------- |
| 210 |
|
| 211 |
SCHED_FIFO : constant := 1; |
| 212 |
SCHED_RR : constant := 2; |
| 213 |
SCHED_OTHER : constant := 0; |
| 214 |
|
| 215 |
function To_Target_Priority |
| 216 |
(Prio : System.Any_Priority) return Interfaces.C.int; |
| 217 |
-- Maps System.Any_Priority to a POSIX priority |
| 218 |
|
| 219 |
------------- |
| 220 |
-- Process -- |
| 221 |
------------- |
| 222 |
|
| 223 |
type pid_t is private; |
| 224 |
|
| 225 |
function kill (pid : pid_t; sig : Signal) return int; |
| 226 |
pragma Import (C, kill, "kill"); |
| 227 |
|
| 228 |
function getpid return pid_t; |
| 229 |
pragma Import (C, getpid, "getpid"); |
| 230 |
|
| 231 |
--------- |
| 232 |
-- LWP -- |
| 233 |
--------- |
| 234 |
|
| 235 |
function lwp_self return System.Address; |
| 236 |
-- lwp_self does not exist on this thread library, revert to pthread_self |
| 237 |
-- which is the closest approximation (with getpid). This function is |
| 238 |
-- needed to share 7staprop.adb across POSIX-like targets. |
| 239 |
pragma Import (C, lwp_self, "pthread_self"); |
| 240 |
|
| 241 |
------------- |
| 242 |
-- Threads -- |
| 243 |
------------- |
| 244 |
|
| 245 |
type Thread_Body is access |
| 246 |
function (arg : System.Address) return System.Address; |
| 247 |
pragma Convention (C, Thread_Body); |
| 248 |
|
| 249 |
type pthread_t is private; |
| 250 |
subtype Thread_Id is pthread_t; |
| 251 |
|
| 252 |
subtype pthread_mutex_t is System.OS_Locks.pthread_mutex_t; |
| 253 |
type pthread_rwlock_t is limited private; |
| 254 |
type pthread_cond_t is limited private; |
| 255 |
type pthread_attr_t is limited private; |
| 256 |
type pthread_mutexattr_t is limited private; |
| 257 |
type pthread_rwlockattr_t is limited private; |
| 258 |
type pthread_condattr_t is limited private; |
| 259 |
type pthread_key_t is private; |
| 260 |
|
| 261 |
No_Key : constant pthread_key_t; |
| 262 |
|
| 263 |
PTHREAD_CREATE_DETACHED : constant := 0; |
| 264 |
|
| 265 |
PTHREAD_SCOPE_PROCESS : constant := 0; |
| 266 |
PTHREAD_SCOPE_SYSTEM : constant := 1; |
| 267 |
|
| 268 |
----------- |
| 269 |
-- Stack -- |
| 270 |
----------- |
| 271 |
|
| 272 |
type stack_t is record |
| 273 |
ss_sp : System.Address; |
| 274 |
ss_flags : int; |
| 275 |
ss_size : size_t; |
| 276 |
end record; |
| 277 |
pragma Convention (C, stack_t); |
| 278 |
|
| 279 |
function sigaltstack |
| 280 |
(ss : not null access stack_t; |
| 281 |
oss : access stack_t) return int; |
| 282 |
|
| 283 |
Alternate_Stack : aliased System.Address; |
| 284 |
-- This is a dummy definition, never used (Alternate_Stack_Size is null) |
| 285 |
|
| 286 |
Alternate_Stack_Size : constant := 0; |
| 287 |
-- No alternate signal stack is used on this platform |
| 288 |
|
| 289 |
Stack_Base_Available : constant Boolean := False; |
| 290 |
-- Indicates whether the stack base is available on this target. |
| 291 |
-- This allows us to share s-osinte.adb between all the FSU/RTEMS |
| 292 |
-- run time. |
| 293 |
-- Note that this value can only be true if pthread_t has a complete |
| 294 |
-- definition that corresponds exactly to the C header files. |
| 295 |
|
| 296 |
function Get_Stack_Base (thread : pthread_t) return Address; |
| 297 |
pragma Inline (Get_Stack_Base); |
| 298 |
-- returns the stack base of the specified thread. |
| 299 |
-- Only call this function when Stack_Base_Available is True. |
| 300 |
|
| 301 |
-- These two functions are only needed to share s-taprop.adb with |
| 302 |
-- FSU threads. |
| 303 |
|
| 304 |
function Get_Page_Size return int; |
| 305 |
pragma Import (C, Get_Page_Size, "getpagesize"); |
| 306 |
-- Returns the size of a page |
| 307 |
|
| 308 |
PROT_ON : constant := 0; |
| 309 |
PROT_OFF : constant := 0; |
| 310 |
|
| 311 |
function mprotect (addr : Address; len : size_t; prot : int) return int; |
| 312 |
pragma Import (C, mprotect); |
| 313 |
|
| 314 |
----------------------------------------- |
| 315 |
-- Nonstandard Thread Initialization -- |
| 316 |
----------------------------------------- |
| 317 |
|
| 318 |
procedure pthread_init; |
| 319 |
-- FSU_THREADS requires pthread_init, which is nonstandard |
| 320 |
-- and this should be invoked during the elaboration of s-taprop.adb |
| 321 |
-- |
| 322 |
-- RTEMS does not require this so we provide an empty Ada body. |
| 323 |
|
| 324 |
------------------------- |
| 325 |
-- POSIX.1c Section 3 -- |
| 326 |
------------------------- |
| 327 |
|
| 328 |
function sigwait |
| 329 |
(set : access sigset_t; |
| 330 |
sig : access Signal) return int; |
| 331 |
pragma Import (C, sigwait, "sigwait"); |
| 332 |
|
| 333 |
function pthread_kill |
| 334 |
(thread : pthread_t; |
| 335 |
sig : Signal) return int; |
| 336 |
pragma Import (C, pthread_kill, "pthread_kill"); |
| 337 |
|
| 338 |
function pthread_sigmask |
| 339 |
(how : int; |
| 340 |
set : access sigset_t; |
| 341 |
oset : access sigset_t) return int; |
| 342 |
pragma Import (C, pthread_sigmask, "pthread_sigmask"); |
| 343 |
|
| 344 |
---------------------------- |
| 345 |
-- POSIX.1c Section 11 -- |
| 346 |
---------------------------- |
| 347 |
|
| 348 |
function pthread_mutexattr_init |
| 349 |
(attr : access pthread_mutexattr_t) return int; |
| 350 |
pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); |
| 351 |
|
| 352 |
function pthread_mutexattr_destroy |
| 353 |
(attr : access pthread_mutexattr_t) return int; |
| 354 |
pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); |
| 355 |
|
| 356 |
function pthread_mutex_init |
| 357 |
(mutex : access pthread_mutex_t; |
| 358 |
attr : access pthread_mutexattr_t) return int; |
| 359 |
pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); |
| 360 |
|
| 361 |
function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; |
| 362 |
pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); |
| 363 |
|
| 364 |
function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; |
| 365 |
pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); |
| 366 |
|
| 367 |
function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; |
| 368 |
pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); |
| 369 |
|
| 370 |
function pthread_rwlockattr_init |
| 371 |
(attr : access pthread_rwlockattr_t) return int; |
| 372 |
pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init"); |
| 373 |
|
| 374 |
function pthread_rwlockattr_destroy |
| 375 |
(attr : access pthread_rwlockattr_t) return int; |
| 376 |
pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy"); |
| 377 |
|
| 378 |
PTHREAD_RWLOCK_PREFER_READER_NP : constant := 0; |
| 379 |
PTHREAD_RWLOCK_PREFER_WRITER_NP : constant := 1; |
| 380 |
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2; |
| 381 |
|
| 382 |
function pthread_rwlockattr_setkind_np |
| 383 |
(attr : access pthread_rwlockattr_t; |
| 384 |
pref : int) return int; |
| 385 |
|
| 386 |
function pthread_rwlock_init |
| 387 |
(mutex : access pthread_rwlock_t; |
| 388 |
attr : access pthread_rwlockattr_t) return int; |
| 389 |
pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init"); |
| 390 |
|
| 391 |
function pthread_rwlock_destroy |
| 392 |
(mutex : access pthread_rwlock_t) return int; |
| 393 |
pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy"); |
| 394 |
|
| 395 |
function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int; |
| 396 |
pragma Import (C, pthread_rwlock_rdlock, "pthread_rwlock_rdlock"); |
| 397 |
|
| 398 |
function pthread_rwlock_wrlock (mutex : access pthread_rwlock_t) return int; |
| 399 |
pragma Import (C, pthread_rwlock_wrlock, "pthread_rwlock_wrlock"); |
| 400 |
|
| 401 |
function pthread_rwlock_unlock (mutex : access pthread_rwlock_t) return int; |
| 402 |
pragma Import (C, pthread_rwlock_unlock, "pthread_rwlock_unlock"); |
| 403 |
|
| 404 |
function pthread_condattr_init |
| 405 |
(attr : access pthread_condattr_t) return int; |
| 406 |
pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); |
| 407 |
|
| 408 |
function pthread_condattr_destroy |
| 409 |
(attr : access pthread_condattr_t) return int; |
| 410 |
pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); |
| 411 |
|
| 412 |
function pthread_cond_init |
| 413 |
(cond : access pthread_cond_t; |
| 414 |
attr : access pthread_condattr_t) return int; |
| 415 |
pragma Import (C, pthread_cond_init, "pthread_cond_init"); |
| 416 |
|
| 417 |
function pthread_cond_destroy (cond : access pthread_cond_t) return int; |
| 418 |
pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); |
| 419 |
|
| 420 |
function pthread_cond_signal (cond : access pthread_cond_t) return int; |
| 421 |
pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); |
| 422 |
|
| 423 |
function pthread_cond_wait |
| 424 |
(cond : access pthread_cond_t; |
| 425 |
mutex : access pthread_mutex_t) return int; |
| 426 |
pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); |
| 427 |
|
| 428 |
function pthread_cond_timedwait |
| 429 |
(cond : access pthread_cond_t; |
| 430 |
mutex : access pthread_mutex_t; |
| 431 |
abstime : access timespec) return int; |
| 432 |
pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); |
| 433 |
|
| 434 |
-------------------------- |
| 435 |
-- POSIX.1c Section 13 -- |
| 436 |
-------------------------- |
| 437 |
|
| 438 |
PTHREAD_PRIO_NONE : constant := 0; |
| 439 |
PTHREAD_PRIO_PROTECT : constant := 2; |
| 440 |
PTHREAD_PRIO_INHERIT : constant := 1; |
| 441 |
|
| 442 |
function pthread_mutexattr_setprotocol |
| 443 |
(attr : access pthread_mutexattr_t; |
| 444 |
protocol : int) return int; |
| 445 |
pragma Import (C, pthread_mutexattr_setprotocol); |
| 446 |
|
| 447 |
function pthread_mutexattr_setprioceiling |
| 448 |
(attr : access pthread_mutexattr_t; |
| 449 |
prioceiling : int) return int; |
| 450 |
pragma Import |
| 451 |
(C, pthread_mutexattr_setprioceiling, |
| 452 |
"pthread_mutexattr_setprioceiling"); |
| 453 |
|
| 454 |
type struct_sched_param is record |
| 455 |
sched_priority : int; |
| 456 |
ss_low_priority : int; |
| 457 |
ss_replenish_period : timespec; |
| 458 |
ss_initial_budget : timespec; |
| 459 |
sched_ss_max_repl : int; |
| 460 |
end record; |
| 461 |
pragma Convention (C, struct_sched_param); |
| 462 |
|
| 463 |
function pthread_setschedparam |
| 464 |
(thread : pthread_t; |
| 465 |
policy : int; |
| 466 |
param : access struct_sched_param) return int; |
| 467 |
pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); |
| 468 |
|
| 469 |
function pthread_attr_setscope |
| 470 |
(attr : access pthread_attr_t; |
| 471 |
contentionscope : int) return int; |
| 472 |
pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); |
| 473 |
|
| 474 |
function pthread_attr_setinheritsched |
| 475 |
(attr : access pthread_attr_t; |
| 476 |
inheritsched : int) return int; |
| 477 |
pragma Import (C, pthread_attr_setinheritsched); |
| 478 |
|
| 479 |
function pthread_attr_setschedpolicy |
| 480 |
(attr : access pthread_attr_t; |
| 481 |
policy : int) return int; |
| 482 |
pragma Import (C, pthread_attr_setschedpolicy); |
| 483 |
|
| 484 |
function pthread_attr_setschedparam |
| 485 |
(attr : access pthread_attr_t; |
| 486 |
sched_param : int) return int; |
| 487 |
pragma Import (C, pthread_attr_setschedparam); |
| 488 |
|
| 489 |
function sched_yield return int; |
| 490 |
pragma Import (C, sched_yield, "sched_yield"); |
| 491 |
|
| 492 |
--------------------------- |
| 493 |
-- P1003.1c - Section 16 -- |
| 494 |
--------------------------- |
| 495 |
|
| 496 |
function pthread_attr_init (attributes : access pthread_attr_t) return int; |
| 497 |
pragma Import (C, pthread_attr_init, "pthread_attr_init"); |
| 498 |
|
| 499 |
function pthread_attr_destroy |
| 500 |
(attributes : access pthread_attr_t) return int; |
| 501 |
pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); |
| 502 |
|
| 503 |
function pthread_attr_setdetachstate |
| 504 |
(attr : access pthread_attr_t; |
| 505 |
detachstate : int) return int; |
| 506 |
pragma Import (C, pthread_attr_setdetachstate); |
| 507 |
|
| 508 |
function pthread_attr_setstacksize |
| 509 |
(attr : access pthread_attr_t; |
| 510 |
stacksize : size_t) return int; |
| 511 |
pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); |
| 512 |
|
| 513 |
function pthread_create |
| 514 |
(thread : access pthread_t; |
| 515 |
attributes : access pthread_attr_t; |
| 516 |
start_routine : Thread_Body; |
| 517 |
arg : System.Address) return int; |
| 518 |
pragma Import (C, pthread_create, "pthread_create"); |
| 519 |
|
| 520 |
procedure pthread_exit (status : System.Address); |
| 521 |
pragma Import (C, pthread_exit, "pthread_exit"); |
| 522 |
|
| 523 |
function pthread_self return pthread_t; |
| 524 |
pragma Import (C, pthread_self, "pthread_self"); |
| 525 |
|
| 526 |
-------------------------- |
| 527 |
-- POSIX.1c Section 17 -- |
| 528 |
-------------------------- |
| 529 |
|
| 530 |
function pthread_setspecific |
| 531 |
(key : pthread_key_t; |
| 532 |
value : System.Address) return int; |
| 533 |
pragma Import (C, pthread_setspecific, "pthread_setspecific"); |
| 534 |
|
| 535 |
function pthread_getspecific (key : pthread_key_t) return System.Address; |
| 536 |
pragma Import (C, pthread_getspecific, "pthread_getspecific"); |
| 537 |
|
| 538 |
type destructor_pointer is access procedure (arg : System.Address); |
| 539 |
pragma Convention (C, destructor_pointer); |
| 540 |
|
| 541 |
function pthread_key_create |
| 542 |
(key : access pthread_key_t; |
| 543 |
destructor : destructor_pointer) return int; |
| 544 |
pragma Import (C, pthread_key_create, "pthread_key_create"); |
| 545 |
|
| 546 |
------------------------------------------------------------ |
| 547 |
-- Binary Semaphore Wrapper to Support Interrupt Tasks -- |
| 548 |
------------------------------------------------------------ |
| 549 |
|
| 550 |
type Binary_Semaphore_Id is new rtems_id; |
| 551 |
|
| 552 |
function Binary_Semaphore_Create return Binary_Semaphore_Id; |
| 553 |
pragma Inline (Binary_Semaphore_Create); |
| 554 |
|
| 555 |
function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id) return int; |
| 556 |
pragma Inline (Binary_Semaphore_Delete); |
| 557 |
|
| 558 |
function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id) return int; |
| 559 |
pragma Inline (Binary_Semaphore_Obtain); |
| 560 |
|
| 561 |
function Binary_Semaphore_Release (ID : Binary_Semaphore_Id) return int; |
| 562 |
pragma Inline (Binary_Semaphore_Release); |
| 563 |
|
| 564 |
function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int; |
| 565 |
pragma Inline (Binary_Semaphore_Flush); |
| 566 |
|
| 567 |
------------------------------------------------------------ |
| 568 |
-- Hardware Interrupt Wrappers to Support Interrupt Tasks -- |
| 569 |
------------------------------------------------------------ |
| 570 |
|
| 571 |
type Interrupt_Handler is access procedure (parameter : System.Address); |
| 572 |
pragma Convention (C, Interrupt_Handler); |
| 573 |
|
| 574 |
type Interrupt_Vector is new System.Address; |
| 575 |
|
| 576 |
function Interrupt_Connect |
| 577 |
(Vector : Interrupt_Vector; |
| 578 |
Handler : Interrupt_Handler; |
| 579 |
Parameter : System.Address := System.Null_Address) return int; |
| 580 |
-- Use this to set up an user handler. The routine installs a |
| 581 |
-- a user handler which is invoked after RTEMS has saved enough |
| 582 |
-- context for a high-level language routine to be safely invoked. |
| 583 |
|
| 584 |
function Interrupt_Number_To_Vector (intNum : int) return Interrupt_Vector; |
| 585 |
-- Convert a logical interrupt number to the hardware interrupt vector |
| 586 |
-- number used to connect the interrupt. |
| 587 |
|
| 588 |
private |
| 589 |
|
| 590 |
type sigset_t is new unsigned_long; |
| 591 |
|
| 592 |
type pid_t is new int; |
| 593 |
|
| 594 |
type time_t is range -2 ** (System.Parameters.time_t_bits - 1) |
| 595 |
.. 2 ** (System.Parameters.time_t_bits - 1) - 1; |
| 596 |
|
| 597 |
type timespec is record |
| 598 |
tv_sec : time_t; |
| 599 |
tv_nsec : long; |
| 600 |
end record; |
| 601 |
pragma Convention (C, timespec); |
| 602 |
|
| 603 |
CLOCK_REALTIME : constant clockid_t := System.OS_Constants.CLOCK_REALTIME; |
| 604 |
CLOCK_MONOTONIC : constant clockid_t := System.OS_Constants.CLOCK_MONOTONIC; |
| 605 |
|
| 606 |
subtype char_array is Interfaces.C.char_array; |
| 607 |
|
| 608 |
type pthread_attr_t is record |
| 609 |
Data : char_array (1 .. OS_Constants.PTHREAD_ATTR_SIZE); |
| 610 |
end record; |
| 611 |
pragma Convention (C, pthread_attr_t); |
| 612 |
for pthread_attr_t'Alignment use Interfaces.C.double'Alignment; |
| 613 |
|
| 614 |
type pthread_condattr_t is record |
| 615 |
Data : char_array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE); |
| 616 |
end record; |
| 617 |
pragma Convention (C, pthread_condattr_t); |
| 618 |
for pthread_condattr_t'Alignment use Interfaces.C.double'Alignment; |
| 619 |
|
| 620 |
type pthread_mutexattr_t is record |
| 621 |
Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE); |
| 622 |
end record; |
| 623 |
pragma Convention (C, pthread_mutexattr_t); |
| 624 |
for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment; |
| 625 |
|
| 626 |
type pthread_rwlockattr_t is record |
| 627 |
Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE); |
| 628 |
end record; |
| 629 |
pragma Convention (C, pthread_rwlockattr_t); |
| 630 |
for pthread_rwlockattr_t'Alignment use Interfaces.C.int'Alignment; |
| 631 |
|
| 632 |
type pthread_t is new rtems_id; |
| 633 |
|
| 634 |
type pthread_rwlock_t is record |
| 635 |
Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCK_SIZE); |
| 636 |
end record; |
| 637 |
pragma Convention (C, pthread_rwlock_t); |
| 638 |
for pthread_rwlock_t'Alignment use Interfaces.C.size_t'Alignment; |
| 639 |
|
| 640 |
type pthread_cond_t is record |
| 641 |
Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE); |
| 642 |
end record; |
| 643 |
pragma Convention (C, pthread_cond_t); |
| 644 |
for pthread_cond_t'Alignment use Interfaces.C.size_t'Alignment; |
| 645 |
|
| 646 |
type pthread_key_t is new rtems_id; |
| 647 |
|
| 648 |
No_Key : constant pthread_key_t := 0; |
| 649 |
|
| 650 |
end System.OS_Interface; |