]>
Commit | Line | Data |
---|---|---|
84481f76 RK |
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 | -- -- | |
c4039eb0 | 9 | -- Copyright (C) 1997-2003 Free Software Foundation, Inc. -- |
84481f76 RK |
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 2, or (at your option) any later ver- -- | |
14 | -- sion. GNARL 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. See the GNU General Public License -- | |
17 | -- for more details. You should have received a copy of the GNU General -- | |
18 | -- Public License distributed with GNARL; see file COPYING. If not, write -- | |
19 | -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- | |
20 | -- MA 02111-1307, USA. -- | |
21 | -- -- | |
22 | -- As a special exception, if other files instantiate generics from this -- | |
23 | -- unit, or you link this unit with other files to produce an executable, -- | |
24 | -- this unit does not by itself cause the resulting executable to be -- | |
25 | -- covered by the GNU General Public License. This exception does not -- | |
26 | -- however invalidate any other reasons why the executable file might be -- | |
27 | -- covered by the GNU Public License. -- | |
28 | -- -- | |
71ff80dc NN |
29 | -- GNARL was developed by the GNARL team at Florida State University. -- |
30 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- | |
84481f76 RK |
31 | -- -- |
32 | -- The GNARL files that were developed for RTEMS are maintained by On-Line -- | |
33 | -- Applications Research Corporation (http://www.oarcorp.com) in coopera- -- | |
34 | -- tion with Ada Core Technologies Inc. and Florida State University. -- | |
35 | -- -- | |
36 | ------------------------------------------------------------------------------ | |
37 | ||
38 | -- This is the RTEMS version of this package | |
39 | ||
40 | -- These are guesses based on what I think the GNARL team will want to | |
41 | -- call the rtems configurations. We use CPU-rtems for the rtems | |
42 | -- configurations. | |
43 | ||
44 | -- This package encapsulates all direct interfaces to OS services | |
45 | -- that are needed by children of System. | |
46 | ||
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. | |
50 | ||
51 | with Interfaces.C; | |
52 | package System.OS_Interface is | |
53 | pragma Preelaborate; | |
54 | ||
55 | -- This interface assumes that "unsigned" is a 32-bit entity. This | |
56 | -- will correspond to RTEMS object ids. | |
57 | ||
58 | subtype rtems_id is Interfaces.C.unsigned; | |
59 | ||
60 | subtype int is Interfaces.C.int; | |
61 | subtype short is Interfaces.C.short; | |
62 | subtype long is Interfaces.C.long; | |
63 | subtype unsigned is Interfaces.C.unsigned; | |
64 | subtype unsigned_short is Interfaces.C.unsigned_short; | |
65 | subtype unsigned_long is Interfaces.C.unsigned_long; | |
66 | subtype unsigned_char is Interfaces.C.unsigned_char; | |
67 | subtype plain_char is Interfaces.C.plain_char; | |
68 | subtype size_t is Interfaces.C.size_t; | |
69 | ||
70 | ----------- | |
71 | -- Errno -- | |
72 | ----------- | |
73 | ||
74 | function errno return int; | |
75 | pragma Import (C, errno, "__get_errno"); | |
76 | ||
77 | EAGAIN : constant := 11; | |
78 | EINTR : constant := 4; | |
79 | EINVAL : constant := 22; | |
80 | ENOMEM : constant := 12; | |
81 | ETIMEDOUT : constant := 116; | |
82 | ||
83 | ------------- | |
84 | -- Signals -- | |
85 | ------------- | |
86 | ||
87 | Max_Interrupt : constant := 31; | |
88 | type Signal is new int range 0 .. Max_Interrupt; | |
89 | ||
bcea76b6 | 90 | SIGXCPU : constant := 0; -- XCPU |
84481f76 RK |
91 | SIGHUP : constant := 1; -- hangup |
92 | SIGINT : constant := 2; -- interrupt (rubout) | |
93 | SIGQUIT : constant := 3; -- quit (ASCD FS) | |
94 | SIGILL : constant := 4; -- illegal instruction (not reset) | |
95 | SIGTRAP : constant := 5; -- trace trap (not reset) | |
96 | SIGIOT : constant := 6; -- IOT instruction | |
97 | SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future | |
98 | SIGEMT : constant := 7; -- EMT instruction | |
99 | SIGFPE : constant := 8; -- floating point exception | |
100 | SIGKILL : constant := 9; -- kill (cannot be caught or ignored) | |
101 | SIGBUS : constant := 10; -- bus error | |
102 | SIGSEGV : constant := 11; -- segmentation violation | |
103 | SIGSYS : constant := 12; -- bad argument to system call | |
104 | SIGPIPE : constant := 13; -- write on a pipe with no one to read it | |
105 | SIGALRM : constant := 14; -- alarm clock | |
106 | SIGTERM : constant := 15; -- software termination signal from kill | |
107 | SIGUSR1 : constant := 16; -- user defined signal 1 | |
108 | SIGUSR2 : constant := 17; -- user defined signal 2 | |
109 | ||
110 | SIGADAABORT : constant := SIGABRT; | |
111 | ||
112 | type Signal_Set is array (Natural range <>) of Signal; | |
113 | ||
114 | Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT); | |
115 | Reserved : constant Signal_Set := (1 .. 1 => SIGKILL); | |
116 | ||
117 | type sigset_t is private; | |
118 | ||
119 | function sigaddset (set : access sigset_t; sig : Signal) return int; | |
120 | pragma Import (C, sigaddset, "sigaddset"); | |
121 | ||
122 | function sigdelset (set : access sigset_t; sig : Signal) return int; | |
123 | pragma Import (C, sigdelset, "sigdelset"); | |
124 | ||
125 | function sigfillset (set : access sigset_t) return int; | |
126 | pragma Import (C, sigfillset, "sigfillset"); | |
127 | ||
128 | function sigismember (set : access sigset_t; sig : Signal) return int; | |
129 | pragma Import (C, sigismember, "sigismember"); | |
130 | ||
131 | function sigemptyset (set : access sigset_t) return int; | |
132 | pragma Import (C, sigemptyset, "sigemptyset"); | |
133 | ||
134 | type struct_sigaction is record | |
135 | sa_flags : int; | |
136 | sa_mask : sigset_t; | |
137 | sa_handler : System.Address; | |
138 | end record; | |
139 | pragma Convention (C, struct_sigaction); | |
140 | type struct_sigaction_ptr is access all struct_sigaction; | |
141 | ||
c00e272e JS |
142 | SA_SIGINFO : constant := 16#02#; |
143 | ||
84481f76 RK |
144 | SIG_BLOCK : constant := 1; |
145 | SIG_UNBLOCK : constant := 2; | |
146 | SIG_SETMASK : constant := 3; | |
147 | ||
148 | SIG_DFL : constant := 0; | |
149 | SIG_IGN : constant := 1; | |
150 | ||
151 | function sigaction | |
152 | (sig : Signal; | |
153 | act : struct_sigaction_ptr; | |
154 | oact : struct_sigaction_ptr) return int; | |
155 | pragma Import (C, sigaction, "sigaction"); | |
156 | ||
157 | ---------- | |
158 | -- Time -- | |
159 | ---------- | |
160 | ||
161 | Time_Slice_Supported : constant Boolean := True; | |
162 | -- Indicates wether time slicing is supported (i.e SCHED_RR is supported) | |
163 | ||
164 | type timespec is private; | |
165 | ||
166 | type clockid_t is private; | |
167 | ||
168 | CLOCK_REALTIME : constant clockid_t; | |
169 | ||
170 | function clock_gettime | |
171 | (clock_id : clockid_t; | |
172 | tp : access timespec) return int; | |
173 | pragma Import (C, clock_gettime, "clock_gettime"); | |
174 | ||
175 | function To_Duration (TS : timespec) return Duration; | |
176 | pragma Inline (To_Duration); | |
177 | ||
178 | function To_Timespec (D : Duration) return timespec; | |
179 | pragma Inline (To_Timespec); | |
180 | ||
181 | type struct_timeval is private; | |
182 | ||
183 | function To_Duration (TV : struct_timeval) return Duration; | |
184 | pragma Inline (To_Duration); | |
185 | ||
186 | function To_Timeval (D : Duration) return struct_timeval; | |
187 | pragma Inline (To_Timeval); | |
188 | ||
189 | ------------------------- | |
190 | -- Priority Scheduling -- | |
191 | ------------------------- | |
192 | ||
193 | SCHED_FIFO : constant := 1; | |
194 | SCHED_RR : constant := 2; | |
195 | SCHED_OTHER : constant := 0; | |
196 | ||
197 | ------------- | |
198 | -- Process -- | |
199 | ------------- | |
200 | ||
201 | type pid_t is private; | |
202 | ||
203 | function kill (pid : pid_t; sig : Signal) return int; | |
204 | pragma Import (C, kill, "kill"); | |
205 | ||
206 | function getpid return pid_t; | |
207 | pragma Import (C, getpid, "getpid"); | |
208 | ||
209 | --------- | |
210 | -- LWP -- | |
211 | --------- | |
212 | ||
213 | function lwp_self return System.Address; | |
214 | -- lwp_self does not exist on this thread library, revert to pthread_self | |
215 | -- which is the closest approximation (with getpid). This function is | |
216 | -- needed to share 7staprop.adb across POSIX-like targets. | |
217 | pragma Import (C, lwp_self, "pthread_self"); | |
218 | ||
219 | ------------- | |
220 | -- Threads -- | |
221 | ------------- | |
222 | ||
223 | type Thread_Body is access | |
224 | function (arg : System.Address) return System.Address; | |
225 | ||
226 | type pthread_t is private; | |
227 | subtype Thread_Id is pthread_t; | |
228 | ||
229 | type pthread_mutex_t is limited private; | |
230 | type pthread_cond_t is limited private; | |
231 | type pthread_attr_t is limited private; | |
232 | type pthread_mutexattr_t is limited private; | |
233 | type pthread_condattr_t is limited private; | |
234 | type pthread_key_t is private; | |
235 | ||
9011d4bb JS |
236 | No_Key : constant pthread_key_t; |
237 | ||
84481f76 RK |
238 | PTHREAD_CREATE_DETACHED : constant := 0; |
239 | ||
240 | ----------- | |
241 | -- Stack -- | |
242 | ----------- | |
243 | ||
244 | Stack_Base_Available : constant Boolean := False; | |
245 | -- Indicates wether the stack base is available on this target. | |
246 | -- This allows us to share s-osinte.adb between all the FSU/RTEMS | |
247 | -- run time. | |
248 | -- Note that this value can only be true if pthread_t has a complete | |
249 | -- definition that corresponds exactly to the C header files. | |
250 | ||
251 | function Get_Stack_Base (thread : pthread_t) return Address; | |
252 | pragma Inline (Get_Stack_Base); | |
253 | -- returns the stack base of the specified thread. | |
254 | -- Only call this function when Stack_Base_Available is True. | |
255 | ||
256 | -- These two functions are only needed to share s-taprop.adb with | |
257 | -- FSU threads. | |
258 | ||
259 | function Get_Page_Size return size_t; | |
260 | function Get_Page_Size return Address; | |
261 | -- returns the size of a page, or 0 if this is not relevant on this | |
262 | -- target (which is the case for RTEMS) | |
263 | ||
264 | PROT_ON : constant := 0; | |
265 | PROT_OFF : constant := 0; | |
266 | ||
267 | function mprotect (addr : Address; len : size_t; prot : int) return int; | |
c00e272e | 268 | pragma Import (C, mprotect); |
84481f76 RK |
269 | |
270 | ----------------------------------------- | |
271 | -- Nonstandard Thread Initialization -- | |
272 | ----------------------------------------- | |
273 | ||
274 | procedure pthread_init; | |
275 | -- FSU_THREADS requires pthread_init, which is nonstandard | |
276 | -- and this should be invoked during the elaboration of s-taprop.adb | |
277 | -- | |
278 | -- RTEMS does not require this so we provide an empty Ada body. | |
279 | ||
280 | ------------------------- | |
281 | -- POSIX.1c Section 3 -- | |
282 | ------------------------- | |
283 | ||
284 | function sigwait | |
285 | (set : access sigset_t; | |
286 | sig : access Signal) return int; | |
287 | pragma Import (C, sigwait, "sigwait"); | |
288 | ||
289 | function pthread_kill | |
290 | (thread : pthread_t; | |
291 | sig : Signal) return int; | |
292 | pragma Import (C, pthread_kill, "pthread_kill"); | |
293 | ||
294 | type sigset_t_ptr is access all sigset_t; | |
295 | ||
296 | function pthread_sigmask | |
297 | (how : int; | |
298 | set : sigset_t_ptr; | |
299 | oset : sigset_t_ptr) return int; | |
300 | pragma Import (C, pthread_sigmask, "pthread_sigmask"); | |
301 | ||
302 | ---------------------------- | |
303 | -- POSIX.1c Section 11 -- | |
304 | ---------------------------- | |
305 | ||
306 | function pthread_mutexattr_init | |
307 | (attr : access pthread_mutexattr_t) return int; | |
308 | pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init"); | |
309 | ||
310 | function pthread_mutexattr_destroy | |
311 | (attr : access pthread_mutexattr_t) return int; | |
312 | pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy"); | |
313 | ||
314 | function pthread_mutex_init | |
315 | (mutex : access pthread_mutex_t; | |
316 | attr : access pthread_mutexattr_t) return int; | |
317 | pragma Import (C, pthread_mutex_init, "pthread_mutex_init"); | |
318 | ||
319 | function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int; | |
320 | pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy"); | |
321 | ||
322 | function pthread_mutex_lock (mutex : access pthread_mutex_t) return int; | |
323 | pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock"); | |
324 | ||
325 | function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int; | |
326 | pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock"); | |
327 | ||
328 | function pthread_condattr_init | |
329 | (attr : access pthread_condattr_t) return int; | |
330 | pragma Import (C, pthread_condattr_init, "pthread_condattr_init"); | |
331 | ||
332 | function pthread_condattr_destroy | |
333 | (attr : access pthread_condattr_t) return int; | |
334 | pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy"); | |
335 | ||
336 | function pthread_cond_init | |
337 | (cond : access pthread_cond_t; | |
338 | attr : access pthread_condattr_t) return int; | |
339 | pragma Import (C, pthread_cond_init, "pthread_cond_init"); | |
340 | ||
341 | function pthread_cond_destroy (cond : access pthread_cond_t) return int; | |
342 | pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy"); | |
343 | ||
344 | function pthread_cond_signal (cond : access pthread_cond_t) return int; | |
345 | pragma Import (C, pthread_cond_signal, "pthread_cond_signal"); | |
346 | ||
347 | function pthread_cond_wait | |
348 | (cond : access pthread_cond_t; | |
349 | mutex : access pthread_mutex_t) return int; | |
350 | pragma Import (C, pthread_cond_wait, "pthread_cond_wait"); | |
351 | ||
352 | function pthread_cond_timedwait | |
353 | (cond : access pthread_cond_t; | |
354 | mutex : access pthread_mutex_t; | |
355 | abstime : access timespec) return int; | |
356 | pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait"); | |
357 | ||
358 | Relative_Timed_Wait : constant Boolean := False; | |
359 | -- pthread_cond_timedwait requires an absolute delay time | |
360 | ||
361 | -------------------------- | |
362 | -- POSIX.1c Section 13 -- | |
363 | -------------------------- | |
364 | ||
365 | PTHREAD_PRIO_NONE : constant := 0; | |
366 | PTHREAD_PRIO_PROTECT : constant := 2; | |
367 | PTHREAD_PRIO_INHERIT : constant := 1; | |
368 | ||
369 | function pthread_mutexattr_setprotocol | |
370 | (attr : access pthread_mutexattr_t; | |
371 | protocol : int) return int; | |
372 | pragma Import (C, pthread_mutexattr_setprotocol); | |
373 | ||
374 | function pthread_mutexattr_setprioceiling | |
375 | (attr : access pthread_mutexattr_t; | |
376 | prioceiling : int) return int; | |
377 | pragma Import | |
378 | (C, pthread_mutexattr_setprioceiling, | |
379 | "pthread_mutexattr_setprioceiling"); | |
380 | ||
381 | type struct_sched_param is record | |
382 | sched_priority : int; | |
383 | ss_low_priority : timespec; | |
384 | ss_replenish_period : timespec; | |
385 | ss_initial_budget : timespec; | |
386 | end record; | |
387 | pragma Convention (C, struct_sched_param); | |
388 | ||
389 | function pthread_setschedparam | |
390 | (thread : pthread_t; | |
391 | policy : int; | |
392 | param : access struct_sched_param) return int; | |
393 | pragma Import (C, pthread_setschedparam, "pthread_setschedparam"); | |
394 | ||
395 | function pthread_attr_setscope | |
396 | (attr : access pthread_attr_t; | |
397 | contentionscope : int) return int; | |
398 | pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope"); | |
399 | ||
400 | function pthread_attr_setinheritsched | |
401 | (attr : access pthread_attr_t; | |
402 | inheritsched : int) return int; | |
403 | pragma Import (C, pthread_attr_setinheritsched); | |
404 | ||
405 | function pthread_attr_setschedpolicy | |
406 | (attr : access pthread_attr_t; | |
407 | policy : int) return int; | |
408 | pragma Import (C, pthread_attr_setschedpolicy); | |
409 | ||
410 | function pthread_attr_setschedparam | |
411 | (attr : access pthread_attr_t; | |
412 | sched_param : int) return int; | |
413 | pragma Import (C, pthread_attr_setschedparam); | |
414 | ||
415 | function sched_yield return int; | |
416 | pragma Import (C, sched_yield, "sched_yield"); | |
417 | ||
418 | --------------------------- | |
419 | -- P1003.1c - Section 16 -- | |
420 | --------------------------- | |
421 | ||
422 | function pthread_attr_init (attributes : access pthread_attr_t) return int; | |
423 | pragma Import (C, pthread_attr_init, "pthread_attr_init"); | |
424 | ||
425 | function pthread_attr_destroy | |
426 | (attributes : access pthread_attr_t) return int; | |
427 | pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy"); | |
428 | ||
429 | function pthread_attr_setdetachstate | |
430 | (attr : access pthread_attr_t; | |
431 | detachstate : int) return int; | |
432 | pragma Import (C, pthread_attr_setdetachstate); | |
433 | ||
434 | function pthread_attr_setstacksize | |
435 | (attr : access pthread_attr_t; | |
436 | stacksize : size_t) return int; | |
437 | pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize"); | |
438 | ||
439 | function pthread_create | |
440 | (thread : access pthread_t; | |
441 | attributes : access pthread_attr_t; | |
442 | start_routine : Thread_Body; | |
443 | arg : System.Address) return int; | |
444 | pragma Import (C, pthread_create, "pthread_create"); | |
445 | ||
446 | procedure pthread_exit (status : System.Address); | |
447 | pragma Import (C, pthread_exit, "pthread_exit"); | |
448 | ||
449 | function pthread_self return pthread_t; | |
450 | pragma Import (C, pthread_self, "pthread_self"); | |
451 | ||
452 | -------------------------- | |
453 | -- POSIX.1c Section 17 -- | |
454 | -------------------------- | |
455 | ||
456 | function pthread_setspecific | |
457 | (key : pthread_key_t; | |
458 | value : System.Address) return int; | |
459 | pragma Import (C, pthread_setspecific, "pthread_setspecific"); | |
460 | ||
461 | function pthread_getspecific (key : pthread_key_t) return System.Address; | |
462 | pragma Import (C, pthread_getspecific, "pthread_getspecific"); | |
463 | ||
464 | type destructor_pointer is access procedure (arg : System.Address); | |
465 | ||
466 | function pthread_key_create | |
467 | (key : access pthread_key_t; | |
468 | destructor : destructor_pointer) return int; | |
469 | pragma Import (C, pthread_key_create, "pthread_key_create"); | |
470 | ||
471 | private | |
472 | ||
473 | type sigset_t is new int; | |
474 | ||
475 | type pid_t is new int; | |
476 | ||
477 | type time_t is new long; | |
478 | ||
479 | type timespec is record | |
480 | tv_sec : time_t; | |
481 | tv_nsec : long; | |
482 | end record; | |
483 | pragma Convention (C, timespec); | |
484 | ||
485 | type clockid_t is new rtems_id; | |
486 | CLOCK_REALTIME : constant clockid_t := 1; | |
487 | ||
488 | type struct_timeval is record | |
489 | tv_sec : int; | |
490 | tv_usec : int; | |
491 | end record; | |
492 | pragma Convention (C, struct_timeval); | |
493 | ||
494 | type pthread_attr_t is record | |
495 | is_initialized : int; | |
496 | stackaddr : System.Address; | |
497 | stacksize : int; | |
498 | contentionscope : int; | |
499 | inheritsched : int; | |
500 | schedpolicy : int; | |
501 | schedparam : struct_sched_param; | |
502 | cputime_clocked_allowed : int; | |
503 | deatchstate : int; | |
504 | end record; | |
505 | pragma Convention (C, pthread_attr_t); | |
506 | ||
507 | type pthread_condattr_t is record | |
508 | flags : int; | |
509 | end record; | |
510 | pragma Convention (C, pthread_condattr_t); | |
511 | ||
512 | type pthread_mutexattr_t is record | |
513 | is_initialized : int; | |
514 | process_shared : int; | |
515 | prio_ceiling : int; | |
516 | protocol : int; | |
517 | recursive : int; | |
518 | end record; | |
519 | pragma Convention (C, pthread_mutexattr_t); | |
520 | ||
521 | type pthread_t is new rtems_id; | |
522 | ||
523 | type pthread_mutex_t is new rtems_id; | |
524 | ||
525 | type pthread_cond_t is new rtems_id; | |
526 | ||
527 | type pthread_key_t is new rtems_id; | |
528 | ||
9011d4bb JS |
529 | No_Key : constant pthread_key_t := 0; |
530 | ||
84481f76 | 531 | end System.OS_Interface; |