OSDN Git Service

6d28ec5ef30407ad23229cc00232257439cf1507
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-rtems.ads
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-2008 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 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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, 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 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
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 --  RTEMS target names are of the form CPU-rtems.
41 --  This implementation is designed to work on ALL RTEMS targets.
42 --  The RTEMS implementation is primarily based upon the POSIX threads
43 --  API but there are also bindings to GNAT/RTEMS support routines
44 --  to insulate this code from C API specific details and, in some
45 --  cases, obtain target architecture and BSP specific information
46 --  that is unavailable at the time this package is built.
47
48 --  This package encapsulates all direct interfaces to OS services
49 --  that are needed by children of System.
50
51 --  PLEASE DO NOT add any with-clauses to this package
52 --  or remove the pragma Preelaborate.
53 --  It is designed to be a bottom-level (leaf) package.
54
55 with Interfaces.C;
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 short          is Interfaces.C.short;
66    subtype long           is Interfaces.C.long;
67    subtype unsigned       is Interfaces.C.unsigned;
68    subtype unsigned_short is Interfaces.C.unsigned_short;
69    subtype unsigned_long  is Interfaces.C.unsigned_long;
70    subtype unsigned_char  is Interfaces.C.unsigned_char;
71    subtype plain_char     is Interfaces.C.plain_char;
72    subtype size_t         is Interfaces.C.size_t;
73
74    -----------
75    -- Errno --
76    -----------
77
78    function errno return int;
79    pragma Import (C, errno, "__get_errno");
80
81    EAGAIN    : constant := 11;
82    EINTR     : constant := 4;
83    EINVAL    : constant := 22;
84    ENOMEM    : constant := 12;
85    ETIMEDOUT : constant := 116;
86
87    -------------
88    -- Signals --
89    -------------
90
91    Max_Interrupt : constant := 31;
92    type Signal is new int range 0 .. Max_Interrupt;
93
94    SIGXCPU     : constant := 0; --  XCPU
95    SIGHUP      : constant := 1; --  hangup
96    SIGINT      : constant := 2; --  interrupt (rubout)
97    SIGQUIT     : constant := 3; --  quit (ASCD FS)
98    SIGILL      : constant := 4; --  illegal instruction (not reset)
99    SIGTRAP     : constant := 5; --  trace trap (not reset)
100    SIGIOT      : constant := 6; --  IOT instruction
101    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
102    SIGEMT      : constant := 7; --  EMT instruction
103    SIGFPE      : constant := 8; --  floating point exception
104    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
105    SIGBUS      : constant := 10; --  bus error
106    SIGSEGV     : constant := 11; --  segmentation violation
107    SIGSYS      : constant := 12; --  bad argument to system call
108    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
109    SIGALRM     : constant := 14; --  alarm clock
110    SIGTERM     : constant := 15; --  software termination signal from kill
111    SIGUSR1     : constant := 16; --  user defined signal 1
112    SIGUSR2     : constant := 17; --  user defined signal 2
113
114    SIGADAABORT : constant := SIGABRT;
115
116    type Signal_Set is array (Natural range <>) of Signal;
117
118    Unmasked    : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT);
119    Reserved    : constant Signal_Set := (1 .. 1 => SIGKILL);
120
121    type sigset_t is private;
122
123    function sigaddset (set : access sigset_t; sig : Signal) return int;
124    pragma Import (C, sigaddset, "sigaddset");
125
126    function sigdelset (set : access sigset_t; sig : Signal) return int;
127    pragma Import (C, sigdelset, "sigdelset");
128
129    function sigfillset (set : access sigset_t) return int;
130    pragma Import (C, sigfillset, "sigfillset");
131
132    function sigismember (set : access sigset_t; sig : Signal) return int;
133    pragma Import (C, sigismember, "sigismember");
134
135    function sigemptyset (set : access sigset_t) return int;
136    pragma Import (C, sigemptyset, "sigemptyset");
137
138    type struct_sigaction is record
139       sa_flags   : int;
140       sa_mask    : sigset_t;
141       sa_handler : System.Address;
142    end record;
143    pragma Convention (C, struct_sigaction);
144    type struct_sigaction_ptr is access all struct_sigaction;
145
146    SA_SIGINFO  : constant := 16#02#;
147
148    SA_ONSTACK : constant := 16#00#;
149    --  SA_ONSTACK is not defined on RTEMS, but it is referred to in the POSIX
150    --  implementation of System.Interrupt_Management. Therefore we define a
151    --  dummy value of zero here so that setting this flag is a nop.
152
153    SIG_BLOCK   : constant := 1;
154    SIG_UNBLOCK : constant := 2;
155    SIG_SETMASK : constant := 3;
156
157    SIG_DFL : constant := 0;
158    SIG_IGN : constant := 1;
159
160    function sigaction
161      (sig  : Signal;
162       act  : struct_sigaction_ptr;
163       oact : struct_sigaction_ptr) return int;
164    pragma Import (C, sigaction, "sigaction");
165
166    ----------
167    -- Time --
168    ----------
169
170    Time_Slice_Supported : constant Boolean := True;
171    --  Indicates whether time slicing is supported (i.e SCHED_RR is supported)
172
173    type timespec is private;
174
175    type clockid_t is private;
176
177    CLOCK_REALTIME : constant clockid_t;
178
179    function clock_gettime
180      (clock_id : clockid_t;
181       tp       : access timespec) return int;
182    pragma Import (C, clock_gettime, "clock_gettime");
183
184    function To_Duration (TS : timespec) return Duration;
185    pragma Inline (To_Duration);
186
187    function To_Timespec (D : Duration) return timespec;
188    pragma Inline (To_Timespec);
189
190    type struct_timeval is private;
191
192    function To_Duration (TV : struct_timeval) return Duration;
193    pragma Inline (To_Duration);
194
195    function To_Timeval (D : Duration) return struct_timeval;
196    pragma Inline (To_Timeval);
197
198    -------------------------
199    -- Priority Scheduling --
200    -------------------------
201
202    SCHED_FIFO  : constant := 1;
203    SCHED_RR    : constant := 2;
204    SCHED_OTHER : constant := 0;
205
206    function To_Target_Priority
207      (Prio : System.Any_Priority) return Interfaces.C.int;
208    --  Maps System.Any_Priority to a POSIX priority
209
210    -------------
211    -- Process --
212    -------------
213
214    type pid_t is private;
215
216    function kill (pid : pid_t; sig : Signal) return int;
217    pragma Import (C, kill, "kill");
218
219    function getpid return pid_t;
220    pragma Import (C, getpid, "getpid");
221
222    ---------
223    -- LWP --
224    ---------
225
226    function lwp_self return System.Address;
227    --  lwp_self does not exist on this thread library, revert to pthread_self
228    --  which is the closest approximation (with getpid). This function is
229    --  needed to share 7staprop.adb across POSIX-like targets.
230    pragma Import (C, lwp_self, "pthread_self");
231
232    -------------
233    -- Threads --
234    -------------
235
236    type Thread_Body is access
237      function (arg : System.Address) return System.Address;
238    pragma Convention (C, Thread_Body);
239
240    type pthread_t           is private;
241    subtype Thread_Id        is pthread_t;
242
243    type pthread_mutex_t     is limited private;
244    type pthread_cond_t      is limited private;
245    type pthread_attr_t      is limited private;
246    type pthread_mutexattr_t is limited private;
247    type pthread_condattr_t  is limited private;
248    type pthread_key_t       is private;
249
250    No_Key : constant pthread_key_t;
251
252    PTHREAD_CREATE_DETACHED : constant := 0;
253
254    PTHREAD_SCOPE_PROCESS : constant := 0;
255    PTHREAD_SCOPE_SYSTEM  : constant := 1;
256
257    -----------
258    -- Stack --
259    -----------
260
261    type stack_t is record
262       ss_sp    : System.Address;
263       ss_flags : int;
264       ss_size  : size_t;
265    end record;
266    pragma Convention (C, stack_t);
267
268    function sigaltstack
269      (ss  : not null access stack_t;
270       oss : access stack_t) return int;
271
272    Alternate_Stack : aliased System.Address;
273    --  This is a dummy definition, never used (Alternate_Stack_Size is null)
274
275    Alternate_Stack_Size : constant := 0;
276    --  No alternate signal stack is used on this platform
277
278    Stack_Base_Available : constant Boolean := False;
279    --  Indicates whether the stack base is available on this target.
280    --  This allows us to share s-osinte.adb between all the FSU/RTEMS
281    --  run time.
282    --  Note that this value can only be true if pthread_t has a complete
283    --  definition that corresponds exactly to the C header files.
284
285    function Get_Stack_Base (thread : pthread_t) return Address;
286    pragma Inline (Get_Stack_Base);
287    --  returns the stack base of the specified thread.
288    --  Only call this function when Stack_Base_Available is True.
289
290    --  These two functions are only needed to share s-taprop.adb with
291    --  FSU threads.
292
293    function Get_Page_Size return size_t;
294    function Get_Page_Size return Address;
295    --  returns the size of a page, or 0 if this is not relevant on this
296    --  target (which is the case for RTEMS)
297
298    PROT_ON  : constant := 0;
299    PROT_OFF : constant := 0;
300
301    function mprotect (addr : Address; len : size_t; prot : int) return int;
302    pragma Import (C, mprotect);
303
304    -----------------------------------------
305    --  Nonstandard Thread Initialization  --
306    -----------------------------------------
307
308    procedure pthread_init;
309    --  FSU_THREADS requires pthread_init, which is nonstandard
310    --  and this should be invoked during the elaboration of s-taprop.adb
311    --
312    --  RTEMS does not require this so we provide an empty Ada body.
313
314    -------------------------
315    -- POSIX.1c  Section 3 --
316    -------------------------
317
318    function sigwait
319      (set : access sigset_t;
320       sig : access Signal) return int;
321    pragma Import (C, sigwait, "sigwait");
322
323    function pthread_kill
324      (thread : pthread_t;
325       sig    : Signal) return int;
326    pragma Import (C, pthread_kill, "pthread_kill");
327
328    function pthread_sigmask
329      (how  : int;
330       set  : access sigset_t;
331       oset : access sigset_t) return int;
332    pragma Import (C, pthread_sigmask, "pthread_sigmask");
333
334    ----------------------------
335    --  POSIX.1c  Section 11  --
336    ----------------------------
337
338    function pthread_mutexattr_init
339      (attr : access pthread_mutexattr_t) return int;
340    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
341
342    function pthread_mutexattr_destroy
343      (attr : access pthread_mutexattr_t) return int;
344    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
345
346    function pthread_mutex_init
347      (mutex : access pthread_mutex_t;
348       attr  : access pthread_mutexattr_t) return int;
349    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
350
351    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
352    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
353
354    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
355    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
356
357    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
358    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
359
360    function pthread_condattr_init
361      (attr : access pthread_condattr_t) return int;
362    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
363
364    function pthread_condattr_destroy
365      (attr : access pthread_condattr_t) return int;
366    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
367
368    function pthread_cond_init
369      (cond : access pthread_cond_t;
370       attr : access pthread_condattr_t) return int;
371    pragma Import (C, pthread_cond_init, "pthread_cond_init");
372
373    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
374    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
375
376    function pthread_cond_signal (cond : access pthread_cond_t) return int;
377    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
378
379    function pthread_cond_wait
380      (cond  : access pthread_cond_t;
381       mutex : access pthread_mutex_t) return int;
382    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
383
384    function pthread_cond_timedwait
385      (cond    : access pthread_cond_t;
386       mutex   : access pthread_mutex_t;
387       abstime : access timespec) return int;
388    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
389
390    Relative_Timed_Wait : constant Boolean := False;
391    --  pthread_cond_timedwait requires an absolute delay time
392
393    --------------------------
394    -- POSIX.1c  Section 13 --
395    --------------------------
396
397    PTHREAD_PRIO_NONE    : constant := 0;
398    PTHREAD_PRIO_PROTECT : constant := 2;
399    PTHREAD_PRIO_INHERIT : constant := 1;
400
401    function pthread_mutexattr_setprotocol
402      (attr     : access pthread_mutexattr_t;
403       protocol : int) return int;
404    pragma Import (C, pthread_mutexattr_setprotocol);
405
406    function pthread_mutexattr_setprioceiling
407      (attr     : access pthread_mutexattr_t;
408       prioceiling : int) return int;
409    pragma Import
410      (C, pthread_mutexattr_setprioceiling,
411       "pthread_mutexattr_setprioceiling");
412
413    type struct_sched_param is record
414       sched_priority      : int;
415       ss_low_priority     : int;
416       ss_replenish_period : timespec;
417       ss_initial_budget   : timespec;
418    end record;
419    pragma Convention (C, struct_sched_param);
420
421    function pthread_setschedparam
422      (thread : pthread_t;
423       policy : int;
424       param  : access struct_sched_param) return int;
425    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
426
427    function pthread_attr_setscope
428      (attr            : access pthread_attr_t;
429       contentionscope : int) return int;
430    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
431
432    function pthread_attr_setinheritsched
433      (attr         : access pthread_attr_t;
434       inheritsched : int) return int;
435    pragma Import (C, pthread_attr_setinheritsched);
436
437    function pthread_attr_setschedpolicy
438      (attr   : access pthread_attr_t;
439       policy : int) return int;
440    pragma Import (C, pthread_attr_setschedpolicy);
441
442    function pthread_attr_setschedparam
443      (attr        : access pthread_attr_t;
444       sched_param : int) return int;
445    pragma Import (C, pthread_attr_setschedparam);
446
447    function sched_yield return int;
448    pragma Import (C, sched_yield, "sched_yield");
449
450    ---------------------------
451    -- P1003.1c - Section 16 --
452    ---------------------------
453
454    function pthread_attr_init (attributes : access pthread_attr_t) return int;
455    pragma Import (C, pthread_attr_init, "pthread_attr_init");
456
457    function pthread_attr_destroy
458      (attributes : access pthread_attr_t) return int;
459    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
460
461    function pthread_attr_setdetachstate
462      (attr        : access pthread_attr_t;
463       detachstate : int) return int;
464    pragma Import (C, pthread_attr_setdetachstate);
465
466    function pthread_attr_setstacksize
467      (attr      : access pthread_attr_t;
468       stacksize : size_t) return int;
469    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
470
471    function pthread_create
472      (thread        : access pthread_t;
473       attributes    : access pthread_attr_t;
474       start_routine : Thread_Body;
475       arg           : System.Address) return int;
476    pragma Import (C, pthread_create, "pthread_create");
477
478    procedure pthread_exit (status : System.Address);
479    pragma Import (C, pthread_exit, "pthread_exit");
480
481    function pthread_self return pthread_t;
482    pragma Import (C, pthread_self, "pthread_self");
483
484    --------------------------
485    -- POSIX.1c  Section 17 --
486    --------------------------
487
488    function pthread_setspecific
489      (key   : pthread_key_t;
490       value : System.Address) return int;
491    pragma Import (C, pthread_setspecific, "pthread_setspecific");
492
493    function pthread_getspecific (key : pthread_key_t) return System.Address;
494    pragma Import (C, pthread_getspecific, "pthread_getspecific");
495
496    type destructor_pointer is access procedure (arg : System.Address);
497    pragma Convention (C, destructor_pointer);
498
499    function pthread_key_create
500      (key        : access pthread_key_t;
501       destructor : destructor_pointer) return int;
502    pragma Import (C, pthread_key_create, "pthread_key_create");
503
504 private
505
506    type sigset_t is new int;
507
508    type pid_t is new int;
509
510    type time_t is new long;
511
512    type timespec is record
513       tv_sec  : time_t;
514       tv_nsec : long;
515    end record;
516    pragma Convention (C, timespec);
517
518    type clockid_t is new rtems_id;
519    CLOCK_REALTIME : constant clockid_t := 1;
520
521    type struct_timeval is record
522       tv_sec  : int;
523       tv_usec : int;
524    end record;
525    pragma Convention (C, struct_timeval);
526
527    type pthread_attr_t is record
528       is_initialized  : int;
529       stackaddr       : System.Address;
530       stacksize       : int;
531       contentionscope : int;
532       inheritsched    : int;
533       schedpolicy     : int;
534       schedparam      : struct_sched_param;
535       cputime_clocked_allowed : int;
536       deatchstate     : int;
537    end record;
538    pragma Convention (C, pthread_attr_t);
539
540    type pthread_condattr_t is record
541       flags           : int;
542       process_shared  : int;
543    end record;
544    pragma Convention (C, pthread_condattr_t);
545
546    type pthread_mutexattr_t is record
547       is_initialized  : int;
548       process_shared  : int;
549       prio_ceiling    : int;
550       protocol        : int;
551       recursive       : int;
552    end record;
553    pragma Convention (C, pthread_mutexattr_t);
554
555    type pthread_t is new rtems_id;
556
557    type pthread_mutex_t is new rtems_id;
558
559    type pthread_cond_t is new rtems_id;
560
561    type pthread_key_t is new rtems_id;
562
563    No_Key : constant pthread_key_t := 0;
564
565 end System.OS_Interface;