1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
11 -- Copyright (C) 1997-2001 Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This is the VxWorks version of this package.
39 -- VxWorks does not directly support the needed POSIX routines, but it
40 -- does have other routines that make it possible to code equivalent
41 -- POSIX compliant routines. The approach taken is to provide an
42 -- FSU threads compliant interface.
44 -- This package encapsulates all direct interfaces to OS services
45 -- that are needed by children of System.
47 -- PLEASE DO NOT add any with-clauses to this package
48 -- or remove the pragma Elaborate_Body.
49 -- It is designed to be a bottom-level (leaf) package.
53 package System
.OS_Interface
is
56 subtype int
is Interfaces
.C
.int
;
57 subtype short
is Interfaces
.C
.short
;
58 subtype long
is Interfaces
.C
.long
;
59 subtype unsigned
is Interfaces
.C
.unsigned
;
60 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
61 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
62 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
63 subtype plain_char
is Interfaces
.C
.plain_char
;
64 subtype size_t
is Interfaces
.C
.size_t
;
65 subtype char
is Interfaces
.C
.char
;
71 function errno
return int
;
72 pragma Import
(C
, errno
, "errnoGet");
74 EINTR
: constant := 4;
75 EAGAIN
: constant := 35;
76 ENOMEM
: constant := 12;
77 EINVAL
: constant := 22;
78 ETIMEDOUT
: constant := 60;
80 FUNC_ERR
: constant := -1;
82 ----------------------------
83 -- Signals and Interrupts --
84 ----------------------------
86 -- In order to support both signal and hardware interrupt handling,
87 -- the ranges of "interrupt IDs" for the vectored hardware interrupts
88 -- and the signals are catenated. In other words, the external IDs
89 -- used to designate signals are relocated beyond the range of the
90 -- vectored interrupts. The IDs given in Ada.Interrupts.Names should
91 -- be used to designate signals; vectored interrupts are designated
92 -- by their interrupt number.
94 NSIG
: constant := 32;
95 -- Number of signals on the target OS
96 type Signal
is new int
range 0 .. Interfaces
.C
."-" (NSIG
, 1);
98 Max_HW_Interrupt
: constant := System
.VxWorks
.Num_HW_Interrupts
- 1;
99 type HW_Interrupt
is new int
range 0 .. Max_HW_Interrupt
;
101 Max_Interrupt
: constant := Max_HW_Interrupt
+ NSIG
;
103 SIGILL
: constant := 4; -- illegal instruction (not reset)
104 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
105 SIGFPE
: constant := 8; -- floating point exception
106 SIGBUS
: constant := 10; -- bus error
107 SIGSEGV
: constant := 11; -- segmentation violation
109 -----------------------------------
110 -- Signal processing definitions --
111 -----------------------------------
113 -- The how in sigprocmask().
114 SIG_BLOCK
: constant := 1;
115 SIG_UNBLOCK
: constant := 2;
116 SIG_SETMASK
: constant := 3;
118 -- The sa_flags in struct sigaction.
119 SA_SIGINFO
: constant := 16#
0002#
;
120 SA_ONSTACK
: constant := 16#
0004#
;
122 -- ANSI args and returns from signal().
123 SIG_DFL
: constant := 0;
124 SIG_IGN
: constant := 1;
126 type sigset_t
is private;
128 type struct_sigaction
is record
129 sa_handler
: System
.Address
;
133 pragma Convention
(C
, struct_sigaction
);
134 type struct_sigaction_ptr
is access all struct_sigaction
;
136 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
137 pragma Import
(C
, sigaddset
, "sigaddset");
139 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
140 pragma Import
(C
, sigdelset
, "sigdelset");
142 function sigfillset
(set
: access sigset_t
) return int
;
143 pragma Import
(C
, sigfillset
, "sigfillset");
145 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
146 pragma Import
(C
, sigismember
, "sigismember");
148 function sigemptyset
(set
: access sigset_t
) return int
;
149 pragma Import
(C
, sigemptyset
, "sigemptyset");
153 act
: struct_sigaction_ptr
;
154 oact
: struct_sigaction_ptr
) return int
;
155 pragma Import
(C
, sigaction
, "sigaction");
157 type isr_address
is access procedure (sig
: int
);
159 function c_signal
(sig
: Signal
; handler
: isr_address
) return isr_address
;
160 pragma Import
(C
, c_signal
, "signal");
162 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
163 pragma Inline
(sigwait
);
165 type sigset_t_ptr
is access all sigset_t
;
167 function pthread_sigmask
170 oset
: sigset_t_ptr
) return int
;
171 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
177 type time_t
is new unsigned_long
;
179 type timespec
is record
183 pragma Convention
(C
, timespec
);
185 type clockid_t
is private;
187 CLOCK_REALTIME
: constant clockid_t
; -- System wide realtime clock
189 function To_Duration
(TS
: timespec
) return Duration;
190 pragma Inline
(To_Duration
);
192 function To_Timespec
(D
: Duration) return timespec
;
193 pragma Inline
(To_Timespec
);
195 function To_Clock_Ticks
(D
: Duration) return int
;
196 -- Convert a duration value (in seconds) into clock ticks.
198 function clock_gettime
199 (clock_id
: clockid_t
; tp
: access timespec
) return int
;
200 pragma Import
(C
, clock_gettime
, "clock_gettime");
202 -------------------------
203 -- Priority Scheduling --
204 -------------------------
206 -- Scheduling policies.
207 SCHED_FIFO
: constant := 1;
208 SCHED_RR
: constant := 2;
209 SCHED_OTHER
: constant := 4;
215 type Thread_Body
is access
216 function (arg
: System
.Address
) return System
.Address
;
218 type pthread_t
is private;
219 subtype Thread_Id
is pthread_t
;
221 null_pthread
: constant pthread_t
;
223 type pthread_mutex_t
is limited private;
224 type pthread_cond_t
is limited private;
225 type pthread_attr_t
is limited private;
226 type pthread_mutexattr_t
is limited private;
227 type pthread_condattr_t
is limited private;
228 type pthread_key_t
is private;
230 PTHREAD_CREATE_DETACHED
: constant := 0;
231 PTHREAD_CREATE_JOINABLE
: constant := 1;
233 function kill
(pid
: pthread_t
; sig
: Signal
) return int
;
234 pragma Import
(C
, kill
, "kill");
236 -- VxWorks doesn't have getpid; taskIdSelf is the equivalent
238 function getpid
return pthread_t
;
239 pragma Import
(C
, getpid
, "taskIdSelf");
241 ---------------------------------
242 -- Nonstandard Thread Routines --
243 ---------------------------------
245 procedure pthread_init
;
246 pragma Inline
(pthread_init
);
247 -- Vxworks requires this for the moment.
249 function taskIdSelf
return pthread_t
;
250 pragma Import
(C
, taskIdSelf
, "taskIdSelf");
252 function taskSuspend
(tid
: pthread_t
) return int
;
253 pragma Import
(C
, taskSuspend
, "taskSuspend");
255 function taskResume
(tid
: pthread_t
) return int
;
256 pragma Import
(C
, taskResume
, "taskResume");
258 function taskIsSuspended
(tid
: pthread_t
) return int
;
259 pragma Import
(C
, taskIsSuspended
, "taskIsSuspended");
263 pVar
: access System
.Address
) return int
;
264 pragma Import
(C
, taskVarAdd
, "taskVarAdd");
266 function taskVarDelete
268 pVar
: access System
.Address
) return int
;
269 pragma Import
(C
, taskVarDelete
, "taskVarDelete");
273 pVar
: access System
.Address
;
274 value
: System
.Address
) return int
;
275 pragma Import
(C
, taskVarSet
, "taskVarSet");
279 pVar
: access System
.Address
) return int
;
280 pragma Import
(C
, taskVarGet
, "taskVarGet");
284 pTaskDesc
: access System
.VxWorks
.TASK_DESC
) return int
;
285 pragma Import
(C
, taskInfoGet
, "taskInfoGet");
287 function taskDelay
(ticks
: int
) return int
;
288 pragma Import
(C
, taskDelay
, "taskDelay");
290 function sysClkRateGet
return int
;
291 pragma Import
(C
, sysClkRateGet
, "sysClkRateGet");
293 --------------------------
294 -- POSIX.1c Section 11 --
295 --------------------------
297 function pthread_mutexattr_init
298 (attr
: access pthread_mutexattr_t
) return int
;
299 pragma Inline
(pthread_mutexattr_init
);
301 function pthread_mutexattr_destroy
302 (attr
: access pthread_mutexattr_t
) return int
;
303 pragma Inline
(pthread_mutexattr_destroy
);
305 function pthread_mutex_init
306 (mutex
: access pthread_mutex_t
;
307 attr
: access pthread_mutexattr_t
) return int
;
308 pragma Inline
(pthread_mutex_init
);
310 function pthread_mutex_destroy
(mutex
: access pthread_mutex_t
) return int
;
311 pragma Inline
(pthread_mutex_destroy
);
313 function pthread_mutex_lock
(mutex
: access pthread_mutex_t
) return int
;
314 pragma Inline
(pthread_mutex_lock
);
316 function pthread_mutex_unlock
(mutex
: access pthread_mutex_t
) return int
;
317 pragma Inline
(pthread_mutex_unlock
);
319 function pthread_condattr_init
320 (attr
: access pthread_condattr_t
) return int
;
321 pragma Inline
(pthread_condattr_init
);
323 function pthread_condattr_destroy
324 (attr
: access pthread_condattr_t
) return int
;
325 pragma Inline
(pthread_condattr_destroy
);
327 function pthread_cond_init
328 (cond
: access pthread_cond_t
;
329 attr
: access pthread_condattr_t
) return int
;
330 pragma Inline
(pthread_cond_init
);
332 function pthread_cond_destroy
(cond
: access pthread_cond_t
) return int
;
333 pragma Inline
(pthread_cond_destroy
);
335 function pthread_cond_signal
(cond
: access pthread_cond_t
) return int
;
336 pragma Inline
(pthread_cond_signal
);
338 function pthread_cond_wait
339 (cond
: access pthread_cond_t
;
340 mutex
: access pthread_mutex_t
) return int
;
341 pragma Inline
(pthread_cond_wait
);
343 function pthread_cond_timedwait
344 (cond
: access pthread_cond_t
;
345 mutex
: access pthread_mutex_t
;
346 abstime
: access timespec
) return int
;
347 pragma Inline
(pthread_cond_timedwait
);
349 --------------------------
350 -- POSIX.1c Section 13 --
351 --------------------------
353 PTHREAD_PRIO_NONE
: constant := 0;
354 PTHREAD_PRIO_PROTECT
: constant := 2;
355 PTHREAD_PRIO_INHERIT
: constant := 1;
357 function pthread_mutexattr_setprotocol
358 (attr
: access pthread_mutexattr_t
;
359 protocol
: int
) return int
;
360 pragma Inline
(pthread_mutexattr_setprotocol
);
362 function pthread_mutexattr_setprioceiling
363 (attr
: access pthread_mutexattr_t
;
364 prioceiling
: int
) return int
;
365 pragma Inline
(pthread_mutexattr_setprioceiling
);
367 type struct_sched_param
is record
368 sched_priority
: int
;
371 function pthread_setschedparam
374 param
: access struct_sched_param
) return int
;
375 pragma Inline
(pthread_setschedparam
);
377 function sched_yield
return int
;
378 pragma Inline
(sched_yield
);
380 function pthread_sched_rr_set_interval
(usecs
: int
) return int
;
381 pragma Inline
(pthread_sched_rr_set_interval
);
383 ---------------------------
384 -- P1003.1c - Section 16 --
385 ---------------------------
387 function pthread_attr_init
(attr
: access pthread_attr_t
) return int
;
388 pragma Inline
(pthread_attr_init
);
390 function pthread_attr_destroy
(attr
: access pthread_attr_t
) return int
;
391 pragma Inline
(pthread_attr_destroy
);
393 function pthread_attr_setdetachstate
394 (attr
: access pthread_attr_t
;
395 detachstate
: int
) return int
;
396 pragma Inline
(pthread_attr_setdetachstate
);
398 function pthread_attr_setstacksize
399 (attr
: access pthread_attr_t
;
400 stacksize
: size_t
) return int
;
401 pragma Inline
(pthread_attr_setstacksize
);
403 function pthread_attr_setname_np
404 (attr
: access pthread_attr_t
;
405 name
: System
.Address
) return int
;
406 -- In VxWorks tasks, we have a non-portable routine to set the
407 -- task name. This makes it really convenient for debugging.
408 pragma Inline
(pthread_attr_setname_np
);
410 function pthread_create
411 (thread
: access pthread_t
;
412 attr
: access pthread_attr_t
;
413 start_routine
: Thread_Body
;
414 arg
: System
.Address
) return int
;
415 pragma Inline
(pthread_create
);
417 function pthread_detach
(thread
: pthread_t
) return int
;
418 pragma Inline
(pthread_detach
);
420 procedure pthread_exit
(status
: System
.Address
);
421 pragma Inline
(pthread_exit
);
423 function pthread_self
return pthread_t
;
424 pragma Inline
(pthread_self
);
426 function pthread_equal
(t1
: pthread_t
; t2
: pthread_t
) return int
;
427 pragma Inline
(pthread_equal
);
428 -- be careful not to use "=" on thread_t!
430 --------------------------
431 -- POSIX.1c Section 17 --
432 --------------------------
434 function pthread_setspecific
435 (key
: pthread_key_t
;
436 value
: System
.Address
) return int
;
437 pragma Inline
(pthread_setspecific
);
439 function pthread_getspecific
(key
: pthread_key_t
) return System
.Address
;
440 pragma Inline
(pthread_getspecific
);
442 type destructor_pointer
is access procedure (arg
: System
.Address
);
444 function pthread_key_create
445 (key
: access pthread_key_t
;
446 destructor
: destructor_pointer
) return int
;
447 pragma Inline
(pthread_key_create
);
449 -- VxWorks binary semaphores. These are exported for use by the
450 -- implementation of hardware interrupt handling.
452 subtype STATUS
is int
;
453 -- Equivalent of the C type STATUS
455 OK
: constant STATUS
:= 0;
456 ERROR
: constant STATUS
:= Interfaces
.C
."-" (1);
458 -- Semaphore creation flags.
460 SEM_Q_FIFO
: constant := 0;
461 SEM_Q_PRIORITY
: constant := 1;
462 SEM_DELETE_SAFE
: constant := 4; -- only valid for binary semaphore
463 SEM_INVERSION_SAFE
: constant := 8; -- only valid for binary semaphore
465 -- Semaphore initial state flags;
467 SEM_EMPTY
: constant := 0;
468 SEM_FULL
: constant := 1;
470 -- Semaphore take (semTake) time constants.
472 WAIT_FOREVER
: constant := -1;
473 NO_WAIT
: constant := 0;
475 type SEM_ID
is new long
;
476 -- The VxWorks semaphore ID is an integer which is really just
477 -- a pointer to a semaphore structure.
479 function semBCreate
(Options
: int
; Initial_State
: int
) return SEM_ID
;
480 -- Create a binary semaphore. Returns ID, or 0 if memory could not
482 pragma Import
(C
, semBCreate
, "semBCreate");
484 function semTake
(SemID
: SEM_ID
; Timeout
: int
) return STATUS
;
485 -- Attempt to take binary semaphore. Error is returned if operation
487 pragma Import
(C
, semTake
, "semTake");
489 function semGive
(SemID
: SEM_ID
) return STATUS
;
490 -- Release one thread blocked on the semaphore
491 pragma Import
(C
, semGive
, "semGive");
493 function semFlush
(SemID
: SEM_ID
) return STATUS
;
494 -- Release all threads blocked on the semaphore
495 pragma Import
(C
, semFlush
, "semFlush");
497 function semDelete
(SemID
: SEM_ID
) return STATUS
;
498 -- Delete a semaphore
499 pragma Import
(C
, semDelete
, "semDelete");
503 -- This interface assumes that "unsigned" and "int" are 32-bit entities.
505 type sigset_t
is new long
;
507 type pid_t
is new int
;
509 ERROR_PID
: constant pid_t
:= -1;
511 type clockid_t
is new int
;
512 CLOCK_REALTIME
: constant clockid_t
:= 0;
514 -- Priority ceilings are now implemented in the body of
517 type pthread_mutexattr_t
is record
518 Flags
: int
; -- mutex semaphore creation flags
519 Prio_Ceiling
: int
; -- priority ceiling
523 type pthread_mutex_t
is record
526 Prio_Ceiling
: int
; -- priority ceiling of lock
529 type pthread_condattr_t
is record
533 type pthread_cond_t
is record
534 Sem
: SEM_ID
; -- VxWorks semaphore ID
535 Waiting
: Integer; -- Number of queued tasks waiting
538 type pthread_attr_t
is record
542 Taskname
: System
.Address
;
545 type pthread_t
is new long
;
547 null_pthread
: constant pthread_t
:= 0;
549 type pthread_key_t
is new int
;
551 -- These are to store the pthread_keys that are created with
552 -- pthread_key_create. Currently, we only need one key.
554 Key_Storage
: array (1 .. 10) of aliased System
.Address
;
555 Keys_Created
: Integer;
559 end System
.OS_Interface
;