OSDN Git Service

* targhooks.c (default_stack_protect_guard): Avoid sharing RTL
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-aix.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNAT 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) 1991-1994, Florida State University            --
10 --          Copyright (C) 1995-2009, Free Software Foundation, Inc.         --
11 --                                                                          --
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.                                              --
22 --                                                                          --
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.                                      --
29 --                                                                          --
30 -- GNARL was developed by the GNARL team at Florida State University.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a AIX (Native THREADS) version of this package
36
37 --  This package encapsulates all direct interfaces to OS services that are
38 --  needed by the tasking run-time (libgnarl).
39
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.
42
43 with Ada.Unchecked_Conversion;
44
45 with Interfaces.C;
46
47 package System.OS_Interface is
48    pragma Preelaborate;
49
50    pragma Linker_Options ("-pthread");
51    --  This implies -lpthreads + other things depending on the GCC
52    --  configuration, such as the selection of a proper libgcc variant
53    --  for table-based exception handling when it is available.
54
55    pragma Linker_Options ("-lc_r");
56
57    subtype int            is Interfaces.C.int;
58    subtype short          is Interfaces.C.short;
59    subtype long           is Interfaces.C.long;
60    subtype unsigned       is Interfaces.C.unsigned;
61    subtype unsigned_short is Interfaces.C.unsigned_short;
62    subtype unsigned_long  is Interfaces.C.unsigned_long;
63    subtype unsigned_char  is Interfaces.C.unsigned_char;
64    subtype plain_char     is Interfaces.C.plain_char;
65    subtype size_t         is Interfaces.C.size_t;
66
67    -----------
68    -- Errno --
69    -----------
70
71    function errno return int;
72    pragma Import (C, errno, "__get_errno");
73
74    EAGAIN    : constant := 11;
75    EINTR     : constant := 4;
76    EINVAL    : constant := 22;
77    ENOMEM    : constant := 12;
78    ETIMEDOUT : constant := 78;
79
80    -------------
81    -- Signals --
82    -------------
83
84    Max_Interrupt : constant := 63;
85    type Signal is new int range 0 .. Max_Interrupt;
86    for Signal'Size use int'Size;
87
88    SIGHUP      : constant := 1; --  hangup
89    SIGINT      : constant := 2; --  interrupt (rubout)
90    SIGQUIT     : constant := 3; --  quit (ASCD FS)
91    SIGILL      : constant := 4; --  illegal instruction (not reset)
92    SIGTRAP     : constant := 5; --  trace trap (not reset)
93    SIGIOT      : constant := 6; --  IOT instruction
94    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
95    SIGEMT      : constant := 7; --  EMT instruction
96    SIGFPE      : constant := 8; --  floating point exception
97    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
98    SIGBUS      : constant := 10; --  bus error
99    SIGSEGV     : constant := 11; --  segmentation violation
100    SIGSYS      : constant := 12; --  bad argument to system call
101    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
102    SIGALRM     : constant := 14; --  alarm clock
103    SIGTERM     : constant := 15; --  software termination signal from kill
104    SIGUSR1     : constant := 30; --  user defined signal 1
105    SIGUSR2     : constant := 31; --  user defined signal 2
106    SIGCLD      : constant := 20; --  alias for SIGCHLD
107    SIGCHLD     : constant := 20; --  child status change
108    SIGPWR      : constant := 29; --  power-fail restart
109    SIGWINCH    : constant := 28; --  window size change
110    SIGURG      : constant := 16; --  urgent condition on IO channel
111    SIGPOLL     : constant := 23; --  pollable event occurred
112    SIGIO       : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
113    SIGSTOP     : constant := 17; --  stop (cannot be caught or ignored)
114    SIGTSTP     : constant := 18; --  user stop requested from tty
115    SIGCONT     : constant := 19; --  stopped process has been continued
116    SIGTTIN     : constant := 21; --  background tty read attempted
117    SIGTTOU     : constant := 22; --  background tty write attempted
118    SIGVTALRM   : constant := 34; --  virtual timer expired
119    SIGPROF     : constant := 32; --  profiling timer expired
120    SIGXCPU     : constant := 24; --  CPU time limit exceeded
121    SIGXFSZ     : constant := 25; --  filesize limit exceeded
122    SIGWAITING  : constant := 39; --  m:n scheduling
123
124    --  The following signals are AIX specific
125
126    SIGMSG      : constant := 27; -- input data is in the ring buffer
127    SIGDANGER   : constant := 33; -- system crash imminent
128    SIGMIGRATE  : constant := 35; -- migrate process
129    SIGPRE      : constant := 36; -- programming exception
130    SIGVIRT     : constant := 37; -- AIX virtual time alarm
131    SIGALRM1    : constant := 38; -- m:n condition variables
132    SIGCPUFAIL  : constant := 59; -- Predictive De-configuration of Processors
133    SIGKAP      : constant := 60; -- keep alive poll from native keyboard
134    SIGGRANT    : constant := SIGKAP; -- monitor mode granted
135    SIGRETRACT  : constant := 61; -- monitor mode should be relinquished
136    SIGSOUND    : constant := 62; -- sound control has completed
137    SIGSAK      : constant := 63; -- secure attention key
138
139    SIGADAABORT : constant := SIGEMT;
140    --  Note: on other targets, we usually use SIGABRT, but on AIX, it appears
141    --  that SIGABRT can't be used in sigwait(), so we use SIGEMT.
142    --  SIGEMT is "Emulator Trap Instruction" from the PDP-11, and does not
143    --  have a standardized usage.
144
145    type Signal_Set is array (Natural range <>) of Signal;
146
147    Unmasked : constant Signal_Set :=
148                 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
149    Reserved : constant Signal_Set :=
150                 (SIGABRT, SIGKILL, SIGSTOP, SIGALRM1, SIGWAITING, SIGCPUFAIL);
151
152    type sigset_t is private;
153
154    function sigaddset (set : access sigset_t; sig : Signal) return int;
155    pragma Import (C, sigaddset, "sigaddset");
156
157    function sigdelset (set : access sigset_t; sig : Signal) return int;
158    pragma Import (C, sigdelset, "sigdelset");
159
160    function sigfillset (set : access sigset_t) return int;
161    pragma Import (C, sigfillset, "sigfillset");
162
163    function sigismember (set : access sigset_t; sig : Signal) return int;
164    pragma Import (C, sigismember, "sigismember");
165
166    function sigemptyset (set : access sigset_t) return int;
167    pragma Import (C, sigemptyset, "sigemptyset");
168
169    type struct_sigaction is record
170       sa_handler : System.Address;
171       sa_mask    : sigset_t;
172       sa_flags   : int;
173    end record;
174    pragma Convention (C, struct_sigaction);
175    type struct_sigaction_ptr is access all struct_sigaction;
176
177    SA_SIGINFO : constant := 16#0100#;
178    SA_ONSTACK : constant := 16#0001#;
179
180    SIG_BLOCK   : constant := 0;
181    SIG_UNBLOCK : constant := 1;
182    SIG_SETMASK : constant := 2;
183
184    SIG_DFL : constant := 0;
185    SIG_IGN : constant := 1;
186
187    function sigaction
188      (sig  : Signal;
189       act  : struct_sigaction_ptr;
190       oact : struct_sigaction_ptr) return int;
191    pragma Import (C, sigaction, "sigaction");
192
193    ----------
194    -- Time --
195    ----------
196
197    Time_Slice_Supported : constant Boolean := True;
198    --  Indicates whether time slicing is supported
199
200    type timespec is private;
201
202    type clockid_t is private;
203
204    CLOCK_REALTIME : constant clockid_t;
205
206    function clock_gettime
207      (clock_id : clockid_t;
208       tp       : access timespec) return int;
209
210    function To_Duration (TS : timespec) return Duration;
211    pragma Inline (To_Duration);
212
213    function To_Timespec (D : Duration) return timespec;
214    pragma Inline (To_Timespec);
215
216    type struct_timezone is record
217       tz_minuteswest : int;
218       tz_dsttime     : int;
219    end record;
220    pragma Convention (C, struct_timezone);
221    type struct_timezone_ptr is access all struct_timezone;
222
223    -------------------------
224    -- Priority Scheduling --
225    -------------------------
226
227    SCHED_FIFO  : constant := 1;
228    SCHED_RR    : constant := 2;
229    SCHED_OTHER : constant := 0;
230
231    function To_Target_Priority
232      (Prio : System.Any_Priority) return Interfaces.C.int;
233    --  Maps System.Any_Priority to a POSIX priority
234
235    -------------
236    -- Process --
237    -------------
238
239    type pid_t is private;
240
241    function kill (pid : pid_t; sig : Signal) return int;
242    pragma Import (C, kill, "kill");
243
244    function getpid return pid_t;
245    pragma Import (C, getpid, "getpid");
246
247    ---------
248    -- LWP --
249    ---------
250
251    function lwp_self return System.Address;
252    pragma Import (C, lwp_self, "thread_self");
253
254    -------------
255    -- Threads --
256    -------------
257
258    type Thread_Body is access
259      function (arg : System.Address) return System.Address;
260    pragma Convention (C, Thread_Body);
261
262    function Thread_Body_Access is new
263      Ada.Unchecked_Conversion (System.Address, Thread_Body);
264
265    type pthread_t           is private;
266    subtype Thread_Id        is pthread_t;
267
268    type pthread_mutex_t     is limited private;
269    type pthread_cond_t      is limited private;
270    type pthread_attr_t      is limited private;
271    type pthread_mutexattr_t is limited private;
272    type pthread_condattr_t  is limited private;
273    type pthread_key_t       is private;
274
275    PTHREAD_CREATE_DETACHED : constant := 1;
276
277    PTHREAD_SCOPE_PROCESS : constant := 1;
278    PTHREAD_SCOPE_SYSTEM  : constant := 0;
279
280    -----------
281    -- Stack --
282    -----------
283
284    type stack_t is record
285       ss_sp    : System.Address;
286       ss_size  : size_t;
287       ss_flags : int;
288    end record;
289    pragma Convention (C, stack_t);
290
291    function sigaltstack
292      (ss  : not null access stack_t;
293       oss : access stack_t) return int;
294    pragma Import (C, sigaltstack, "sigaltstack");
295
296    Alternate_Stack : aliased System.Address;
297    --  This is a dummy definition, never used (Alternate_Stack_Size is null)
298
299    Alternate_Stack_Size : constant := 0;
300    --  No alternate signal stack is used on this platform
301
302    Stack_Base_Available : constant Boolean := False;
303    --  Indicates whether the stack base is available on this target
304
305    function Get_Stack_Base (thread : pthread_t) return Address;
306    pragma Inline (Get_Stack_Base);
307    --  Returns the stack base of the specified thread. Only call this function
308    --  when Stack_Base_Available is True.
309
310    function Get_Page_Size return size_t;
311    function Get_Page_Size return Address;
312    pragma Import (C, Get_Page_Size, "getpagesize");
313    --  Returns the size of a page
314
315    PROT_NONE  : constant := 0;
316    PROT_READ  : constant := 1;
317    PROT_WRITE : constant := 2;
318    PROT_EXEC  : constant := 4;
319    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
320    PROT_ON    : constant := PROT_READ;
321    PROT_OFF   : constant := PROT_ALL;
322
323    function mprotect (addr : Address; len : size_t; prot : int) return int;
324    pragma Import (C, mprotect);
325
326    ---------------------------------------
327    -- Nonstandard Thread Initialization --
328    ---------------------------------------
329
330    --  Though not documented, pthread_init *must* be called before any other
331    --  pthread call.
332
333    procedure pthread_init;
334    pragma Import (C, pthread_init, "pthread_init");
335
336    -------------------------
337    -- POSIX.1c  Section 3 --
338    -------------------------
339
340    function sigwait
341      (set : access sigset_t;
342       sig : access Signal) return int;
343    pragma Import (C, sigwait, "sigwait");
344
345    function pthread_kill
346      (thread : pthread_t;
347       sig    : Signal) return int;
348    pragma Import (C, pthread_kill, "pthread_kill");
349
350    function pthread_sigmask
351      (how  : int;
352       set  : access sigset_t;
353       oset : access sigset_t) return int;
354    pragma Import (C, pthread_sigmask, "sigthreadmask");
355
356    --------------------------
357    -- POSIX.1c  Section 11 --
358    --------------------------
359
360    function pthread_mutexattr_init
361      (attr : access pthread_mutexattr_t) return int;
362    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
363
364    function pthread_mutexattr_destroy
365      (attr : access pthread_mutexattr_t) return int;
366    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
367
368    function pthread_mutex_init
369      (mutex : access pthread_mutex_t;
370       attr  : access pthread_mutexattr_t) return int;
371    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
372
373    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
374    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
375
376    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
377    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
378
379    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
380    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
381
382    function pthread_condattr_init
383      (attr : access pthread_condattr_t) return int;
384    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
385
386    function pthread_condattr_destroy
387      (attr : access pthread_condattr_t) return int;
388    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
389
390    function pthread_cond_init
391      (cond : access pthread_cond_t;
392       attr : access pthread_condattr_t) return int;
393    pragma Import (C, pthread_cond_init, "pthread_cond_init");
394
395    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
396    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
397
398    function pthread_cond_signal (cond : access pthread_cond_t) return int;
399    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
400
401    function pthread_cond_wait
402      (cond  : access pthread_cond_t;
403       mutex : access pthread_mutex_t) return int;
404    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
405
406    function pthread_cond_timedwait
407      (cond    : access pthread_cond_t;
408       mutex   : access pthread_mutex_t;
409       abstime : access timespec) return int;
410    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
411
412    Relative_Timed_Wait : constant Boolean := False;
413    --  pthread_cond_timedwait requires an absolute delay time
414
415    --------------------------
416    -- POSIX.1c  Section 13 --
417    --------------------------
418
419    PTHREAD_PRIO_PROTECT : constant := 2;
420
421    function PTHREAD_PRIO_INHERIT return int;
422    --  Return value of C macro PTHREAD_PRIO_INHERIT. This function is needed
423    --  since the value is different between AIX versions.
424
425    function pthread_mutexattr_setprotocol
426      (attr     : access pthread_mutexattr_t;
427       protocol : int) return int;
428    pragma Import (C, pthread_mutexattr_setprotocol);
429
430    function pthread_mutexattr_setprioceiling
431      (attr        : access pthread_mutexattr_t;
432       prioceiling : int) return int;
433    pragma Import (C, pthread_mutexattr_setprioceiling);
434
435    type Array_5_Int is array (0 .. 5) of int;
436    type struct_sched_param is record
437       sched_priority : int;
438       sched_policy   : int;
439       sched_reserved : Array_5_Int;
440    end record;
441
442    function pthread_setschedparam
443      (thread : pthread_t;
444       policy : int;
445       param  : access struct_sched_param) return int;
446    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
447
448    function pthread_attr_setscope
449      (attr            : access pthread_attr_t;
450       contentionscope : int) return int;
451    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
452
453    function pthread_attr_setinheritsched
454      (attr            : access pthread_attr_t;
455       inheritsched : int) return int;
456    pragma Import (C, pthread_attr_setinheritsched);
457
458    function pthread_attr_setschedpolicy
459      (attr   : access pthread_attr_t;
460       policy : int) return int;
461    pragma Import (C, pthread_attr_setschedpolicy);
462
463    function pthread_attr_setschedparam
464      (attr        : access pthread_attr_t;
465       sched_param : int) return int;
466    pragma Import (C, pthread_attr_setschedparam);
467
468    function sched_yield return int;
469    --  AIX have a nonstandard sched_yield
470
471    --------------------------
472    -- P1003.1c  Section 16 --
473    --------------------------
474
475    function pthread_attr_init (attributes : access pthread_attr_t) return int;
476    pragma Import (C, pthread_attr_init, "pthread_attr_init");
477
478    function pthread_attr_destroy
479      (attributes : access pthread_attr_t) return int;
480    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
481
482    function pthread_attr_setdetachstate
483      (attr        : access pthread_attr_t;
484       detachstate : int) return int;
485    pragma Import (C, pthread_attr_setdetachstate);
486
487    function pthread_attr_setstacksize
488      (attr      : access pthread_attr_t;
489       stacksize : size_t) return int;
490    pragma Import (C, pthread_attr_setstacksize);
491
492    function pthread_create
493      (thread        : access pthread_t;
494       attributes    : access pthread_attr_t;
495       start_routine : Thread_Body;
496       arg           : System.Address)
497      return int;
498    pragma Import (C, pthread_create, "pthread_create");
499
500    procedure pthread_exit (status : System.Address);
501    pragma Import (C, pthread_exit, "pthread_exit");
502
503    function pthread_self return pthread_t;
504    pragma Import (C, pthread_self, "pthread_self");
505
506    --------------------------
507    -- POSIX.1c  Section 17 --
508    --------------------------
509
510    function pthread_setspecific
511      (key   : pthread_key_t;
512       value : System.Address) return int;
513    pragma Import (C, pthread_setspecific, "pthread_setspecific");
514
515    function pthread_getspecific (key : pthread_key_t) return System.Address;
516    pragma Import (C, pthread_getspecific, "pthread_getspecific");
517
518    type destructor_pointer is access procedure (arg : System.Address);
519    pragma Convention (C, destructor_pointer);
520
521    function pthread_key_create
522      (key        : access pthread_key_t;
523       destructor : destructor_pointer) return int;
524    pragma Import (C, pthread_key_create, "pthread_key_create");
525
526 private
527    type sigset_t is record
528       losigs : unsigned_long;
529       hisigs : unsigned_long;
530    end record;
531    pragma Convention (C_Pass_By_Copy, sigset_t);
532
533    type pid_t is new int;
534
535    type time_t is new long;
536
537    type timespec is record
538       tv_sec  : time_t;
539       tv_nsec : long;
540    end record;
541    pragma Convention (C, timespec);
542
543    type clockid_t is new int;
544    CLOCK_REALTIME : constant clockid_t := 0;
545
546    type pthread_attr_t is new System.Address;
547    pragma Convention (C, pthread_attr_t);
548    --  typedef struct __pt_attr        *pthread_attr_t;
549
550    type pthread_condattr_t is new System.Address;
551    pragma Convention (C, pthread_condattr_t);
552    --  typedef struct __pt_attr        *pthread_condattr_t;
553
554    type pthread_mutexattr_t is new System.Address;
555    pragma Convention (C, pthread_mutexattr_t);
556    --  typedef struct __pt_attr        *pthread_mutexattr_t;
557
558    type pthread_t is new System.Address;
559    pragma Convention (C, pthread_t);
560    --  typedef void    *pthread_t;
561
562    type ptq_queue;
563    type ptq_queue_ptr is access all ptq_queue;
564
565    type ptq_queue is record
566       ptq_next : ptq_queue_ptr;
567       ptq_prev : ptq_queue_ptr;
568    end record;
569
570    type Array_3_Int is array (0 .. 3) of int;
571    type pthread_mutex_t is record
572         link        : ptq_queue;
573         ptmtx_lock  : int;
574         ptmtx_flags : long;
575         protocol    : int;
576         prioceiling : int;
577         ptmtx_owner : pthread_t;
578         mtx_id      : int;
579         attr        : pthread_attr_t;
580         mtx_kind    : int;
581         lock_cpt    : int;
582         reserved    : Array_3_Int;
583    end record;
584    pragma Convention (C, pthread_mutex_t);
585    type pthread_mutex_t_ptr is access pthread_mutex_t;
586
587    type pthread_cond_t is record
588       link         : ptq_queue;
589       ptcv_lock    : int;
590       ptcv_flags   : long;
591       ptcv_waiters : ptq_queue;
592       cv_id        : int;
593       attr         : pthread_attr_t;
594       mutex        : pthread_mutex_t_ptr;
595       cptwait      : int;
596       reserved     : int;
597    end record;
598    pragma Convention (C, pthread_cond_t);
599
600    type pthread_key_t is new unsigned;
601
602 end System.OS_Interface;