1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
9 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2006, Free Software Foundation, Inc. --
12 -- GNARL 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 2, or (at your option) any later ver- --
15 -- sion. GNARL 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. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
33 ------------------------------------------------------------------------------
35 -- This is the VxWorks version of this package
37 -- This package encapsulates all direct interfaces to OS services
38 -- that are needed by children of System.
40 -- PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 -- Preelaborate. This package is designed to be a bottom-level (leaf) package.
46 package System
.OS_Interface
is
49 subtype int
is Interfaces
.C
.int
;
50 subtype short
is Short_Integer;
51 type unsigned_int
is mod 2 ** int
'Size;
52 type long
is new Long_Integer;
53 type unsigned_long
is mod 2 ** long
'Size;
54 type size_t
is mod 2 ** Standard
'Address_Size;
60 function errno
return int
;
61 pragma Import
(C
, errno
, "errnoGet");
63 EINTR
: constant := 4;
64 EAGAIN
: constant := 35;
65 ENOMEM
: constant := 12;
66 EINVAL
: constant := 22;
67 ETIMEDOUT
: constant := 60;
69 FUNC_ERR
: constant := -1;
71 ----------------------------
72 -- Signals and Interrupts --
73 ----------------------------
75 NSIG
: constant := 32;
76 -- Number of signals on the target OS
77 type Signal
is new int
range 0 .. Interfaces
.C
."-" (NSIG
, 1);
79 Max_HW_Interrupt
: constant := System
.VxWorks
.Num_HW_Interrupts
- 1;
80 type HW_Interrupt
is new int
range 0 .. Max_HW_Interrupt
;
82 Max_Interrupt
: constant := Max_HW_Interrupt
;
84 SIGILL
: constant := 4; -- illegal instruction (not reset)
85 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
86 SIGFPE
: constant := 8; -- floating point exception
87 SIGBUS
: constant := 10; -- bus error
88 SIGSEGV
: constant := 11; -- segmentation violation
90 -----------------------------------
91 -- Signal processing definitions --
92 -----------------------------------
94 -- The how in sigprocmask().
95 SIG_BLOCK
: constant := 1;
96 SIG_UNBLOCK
: constant := 2;
97 SIG_SETMASK
: constant := 3;
99 -- The sa_flags in struct sigaction.
100 SA_SIGINFO
: constant := 16#
0002#
;
101 SA_ONSTACK
: constant := 16#
0004#
;
103 SIG_DFL
: constant := 0;
104 SIG_IGN
: constant := 1;
106 type sigset_t
is private;
108 type struct_sigaction
is record
109 sa_handler
: System
.Address
;
113 pragma Convention
(C
, struct_sigaction
);
114 type struct_sigaction_ptr
is access all struct_sigaction
;
116 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
117 pragma Import
(C
, sigaddset
, "sigaddset");
119 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
120 pragma Import
(C
, sigdelset
, "sigdelset");
122 function sigfillset
(set
: access sigset_t
) return int
;
123 pragma Import
(C
, sigfillset
, "sigfillset");
125 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
126 pragma Import
(C
, sigismember
, "sigismember");
128 function sigemptyset
(set
: access sigset_t
) return int
;
129 pragma Import
(C
, sigemptyset
, "sigemptyset");
133 act
: struct_sigaction_ptr
;
134 oact
: struct_sigaction_ptr
) return int
;
135 pragma Import
(C
, sigaction
, "sigaction");
137 type isr_address
is access procedure (sig
: int
);
139 function c_signal
(sig
: Signal
; handler
: isr_address
) return isr_address
;
140 pragma Import
(C
, c_signal
, "signal");
142 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
143 pragma Inline
(sigwait
);
145 function pthread_sigmask
147 set
: access sigset_t
;
148 oset
: access sigset_t
) return int
;
149 pragma Import
(C
, pthread_sigmask
, "sigprocmask");
151 type t_id
is new long
;
152 subtype Thread_Id
is t_id
;
154 function kill
(pid
: t_id
; sig
: Signal
) return int
;
155 pragma Inline
(kill
);
157 function getpid
return t_id
;
158 pragma Inline
(getpid
);
164 type time_t
is new unsigned_long
;
166 type timespec
is record
170 pragma Convention
(C
, timespec
);
172 type clockid_t
is private;
174 CLOCK_REALTIME
: constant clockid_t
; -- System wide realtime clock
176 function To_Duration
(TS
: timespec
) return Duration;
177 pragma Inline
(To_Duration
);
179 function To_Timespec
(D
: Duration) return timespec
;
180 pragma Inline
(To_Timespec
);
182 function To_Clock_Ticks
(D
: Duration) return int
;
183 -- Convert a duration value (in seconds) into clock ticks
185 function clock_gettime
186 (clock_id
: clockid_t
; tp
: access timespec
) return int
;
187 pragma Import
(C
, clock_gettime
, "clock_gettime");
189 type ULONG
is new unsigned_long
;
191 procedure tickSet
(ticks
: ULONG
);
192 pragma Import
(C
, tickSet
, "tickSet");
194 function tickGet
return ULONG
;
195 pragma Import
(C
, tickGet
, "tickGet");
197 ----------------------
198 -- Utility Routines --
199 ----------------------
201 function To_VxWorks_Priority
(Priority
: in int
) return int
;
202 pragma Inline
(To_VxWorks_Priority
);
203 -- Convenience routine to convert between VxWorks priority and Ada priority
205 --------------------------
206 -- VxWorks specific API --
207 --------------------------
209 subtype STATUS
is int
;
210 -- Equivalent of the C type STATUS
212 OK
: constant STATUS
:= 0;
213 ERROR
: constant STATUS
:= Interfaces
.C
.int
(-1);
215 function taskIdVerify
(tid
: t_id
) return STATUS
;
216 pragma Import
(C
, taskIdVerify
, "taskIdVerify");
218 function taskIdSelf
return t_id
;
219 pragma Import
(C
, taskIdSelf
, "taskIdSelf");
221 function taskOptionsGet
(tid
: t_id
; pOptions
: access int
) return int
;
222 pragma Import
(C
, taskOptionsGet
, "taskOptionsGet");
224 function taskSuspend
(tid
: t_id
) return int
;
225 pragma Import
(C
, taskSuspend
, "taskSuspend");
227 function taskResume
(tid
: t_id
) return int
;
228 pragma Import
(C
, taskResume
, "taskResume");
230 function taskIsSuspended
(tid
: t_id
) return int
;
231 pragma Import
(C
, taskIsSuspended
, "taskIsSuspended");
233 function taskDelay
(ticks
: int
) return int
;
234 procedure taskDelay
(ticks
: int
);
235 pragma Import
(C
, taskDelay
, "taskDelay");
237 function sysClkRateGet
return int
;
238 pragma Import
(C
, sysClkRateGet
, "sysClkRateGet");
240 -- VxWorks 5.x specific functions
243 (tid
: t_id
; pVar
: access System
.Address
) return int
;
244 pragma Import
(C
, taskVarAdd
, "taskVarAdd");
246 function taskVarDelete
247 (tid
: t_id
; pVar
: access System
.Address
) return int
;
248 pragma Import
(C
, taskVarDelete
, "taskVarDelete");
252 pVar
: access System
.Address
;
253 value
: System
.Address
) return int
;
254 pragma Import
(C
, taskVarSet
, "taskVarSet");
258 pVar
: access System
.Address
) return int
;
259 pragma Import
(C
, taskVarGet
, "taskVarGet");
261 -- VxWorks 6.x specific functions
263 function tlsKeyCreate
return int
;
264 pragma Import
(C
, tlsKeyCreate
, "tlsKeyCreate");
266 function tlsValueGet
(key
: int
) return System
.Address
;
267 pragma Import
(C
, tlsValueGet
, "tlsValueGet");
269 function tlsValueSet
(key
: int
; value
: System
.Address
) return STATUS
;
270 pragma Import
(C
, tlsValueSet
, "tlsValueSet");
272 -- Option flags for taskSpawn
274 VX_UNBREAKABLE
: constant := 16#
0002#
;
275 VX_FP_PRIVATE_ENV
: constant := 16#
0080#
;
276 VX_NO_STACK_FILL
: constant := 16#
0100#
;
278 function VX_FP_TASK
return int
;
279 pragma Inline
(VX_FP_TASK
);
282 (name
: System
.Address
; -- Pointer to task name
286 start_routine
: System
.Address
;
287 arg1
: System
.Address
;
296 arg10
: int
:= 0) return t_id
;
297 pragma Import
(C
, taskSpawn
, "taskSpawn");
299 procedure taskDelete
(tid
: t_id
);
300 pragma Import
(C
, taskDelete
, "taskDelete");
302 function Set_Time_Slice
(ticks
: int
) return int
;
303 pragma Inline
(Set_Time_Slice
);
304 -- Calls kernelTimeSlice under VxWorks 5.x
305 -- Do nothing under VxWorks 6.x
307 function taskPriorityGet
(tid
: t_id
; pPriority
: access int
) return int
;
308 pragma Import
(C
, taskPriorityGet
, "taskPriorityGet");
310 function taskPrioritySet
(tid
: t_id
; newPriority
: int
) return int
;
311 pragma Import
(C
, taskPrioritySet
, "taskPrioritySet");
313 -- Semaphore creation flags
315 SEM_Q_FIFO
: constant := 0;
316 SEM_Q_PRIORITY
: constant := 1;
317 SEM_DELETE_SAFE
: constant := 4; -- only valid for binary semaphore
318 SEM_INVERSION_SAFE
: constant := 8; -- only valid for binary semaphore
320 -- Semaphore initial state flags
322 SEM_EMPTY
: constant := 0;
323 SEM_FULL
: constant := 1;
325 -- Semaphore take (semTake) time constants
327 WAIT_FOREVER
: constant := -1;
328 NO_WAIT
: constant := 0;
330 -- Error codes (errno). The lower level 16 bits are the error code, with
331 -- the upper 16 bits representing the module number in which the error
332 -- occurred. By convention, the module number is 0 for UNIX errors. VxWorks
333 -- reserves module numbers 1-500, with the remaining module numbers being
334 -- available for user applications.
336 M_objLib
: constant := 61 * 2**16;
337 -- semTake() failure with ticks = NO_WAIT
338 S_objLib_OBJ_UNAVAILABLE
: constant := M_objLib
+ 2;
339 -- semTake() timeout with ticks > NO_WAIT
340 S_objLib_OBJ_TIMEOUT
: constant := M_objLib
+ 4;
342 type SEM_ID
is new System
.Address
;
343 -- typedef struct semaphore *SEM_ID;
345 -- We use two different kinds of VxWorks semaphores: mutex and binary
346 -- semaphores. A null ID is returned when a semaphore cannot be created.
348 function semBCreate
(options
: int
; initial_state
: int
) return SEM_ID
;
349 pragma Import
(C
, semBCreate
, "semBCreate");
350 -- Create a binary semaphore. Return ID, or 0 if memory could not
353 function semMCreate
(options
: int
) return SEM_ID
;
354 pragma Import
(C
, semMCreate
, "semMCreate");
356 function semDelete
(Sem
: SEM_ID
) return int
;
357 pragma Import
(C
, semDelete
, "semDelete");
358 -- Delete a semaphore
360 function semGive
(Sem
: SEM_ID
) return int
;
361 pragma Import
(C
, semGive
, "semGive");
363 function semTake
(Sem
: SEM_ID
; timeout
: int
) return int
;
364 pragma Import
(C
, semTake
, "semTake");
365 -- Attempt to take binary semaphore. Error is returned if operation
368 function semFlush
(SemID
: SEM_ID
) return STATUS
;
369 pragma Import
(C
, semFlush
, "semFlush");
370 -- Release all threads blocked on the semaphore
373 type sigset_t
is new long
;
375 type pid_t
is new int
;
377 ERROR_PID
: constant pid_t
:= -1;
379 type clockid_t
is new int
;
380 CLOCK_REALTIME
: constant clockid_t
:= 0;
382 end System
.OS_Interface
;