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