OSDN Git Service

More improvements to sparc VIS vec_init code generation.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-solaris-posix.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-2011, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT 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 3,  or (at your option) any later ver- --
15 -- sion.  GNAT 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.                                     --
18 --                                                                          --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception,   --
21 -- version 3.1, as published by the Free Software Foundation.               --
22 --                                                                          --
23 -- You should have received a copy of the GNU General Public License and    --
24 -- a copy of the GCC Runtime Library Exception along with this program;     --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
26 -- <http://www.gnu.org/licenses/>.                                          --
27 --                                                                          --
28 -- GNARL was developed by the GNARL team at Florida State University.       --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
30 --                                                                          --
31 ------------------------------------------------------------------------------
32
33 --  This is a Solaris (POSIX Threads) version of this package
34
35 --  This package encapsulates all direct interfaces to OS services
36 --  that are needed by the tasking run-time (libgnarl).
37
38 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
40
41 with Interfaces.C;
42
43 with Ada.Unchecked_Conversion;
44
45 package System.OS_Interface is
46    pragma Preelaborate;
47
48    pragma Linker_Options ("-lposix4");
49    pragma Linker_Options ("-lpthread");
50
51    --  The following is needed to allow --enable-threads=solaris
52
53    pragma Linker_Options ("-lthread");
54
55    subtype int            is Interfaces.C.int;
56    subtype short          is Interfaces.C.short;
57    subtype long           is Interfaces.C.long;
58    subtype unsigned       is Interfaces.C.unsigned;
59    subtype unsigned_short is Interfaces.C.unsigned_short;
60    subtype unsigned_long  is Interfaces.C.unsigned_long;
61    subtype unsigned_char  is Interfaces.C.unsigned_char;
62    subtype plain_char     is Interfaces.C.plain_char;
63    subtype size_t         is Interfaces.C.size_t;
64
65    -----------
66    -- Errno --
67    -----------
68
69    function errno return int;
70    pragma Import (C, errno, "__get_errno");
71
72    EAGAIN    : constant := 11;
73    EINTR     : constant := 4;
74    EINVAL    : constant := 22;
75    ENOMEM    : constant := 12;
76    ETIMEDOUT : constant := 145;
77
78    -------------
79    -- Signals --
80    -------------
81
82    Max_Interrupt : constant := 45;
83    type Signal is new int range 0 .. Max_Interrupt;
84    for Signal'Size use int'Size;
85
86    SIGHUP      : constant := 1; --  hangup
87    SIGINT      : constant := 2; --  interrupt (rubout)
88    SIGQUIT     : constant := 3; --  quit (ASCD FS)
89    SIGILL      : constant := 4; --  illegal instruction (not reset)
90    SIGTRAP     : constant := 5; --  trace trap (not reset)
91    SIGIOT      : constant := 6; --  IOT instruction
92    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
93    SIGEMT      : constant := 7; --  EMT instruction
94    SIGFPE      : constant := 8; --  floating point exception
95    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
96    SIGBUS      : constant := 10; --  bus error
97    SIGSEGV     : constant := 11; --  segmentation violation
98    SIGSYS      : constant := 12; --  bad argument to system call
99    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
100    SIGALRM     : constant := 14; --  alarm clock
101    SIGTERM     : constant := 15; --  software termination signal from kill
102    SIGUSR1     : constant := 16; --  user defined signal 1
103    SIGUSR2     : constant := 17; --  user defined signal 2
104    SIGCLD      : constant := 18; --  alias for SIGCHLD
105    SIGCHLD     : constant := 18; --  child status change
106    SIGPWR      : constant := 19; --  power-fail restart
107    SIGWINCH    : constant := 20; --  window size change
108    SIGURG      : constant := 21; --  urgent condition on IO channel
109    SIGPOLL     : constant := 22; --  pollable event occurred
110    SIGIO       : constant := 22; --  I/O possible (Solaris SIGPOLL alias)
111    SIGSTOP     : constant := 23; --  stop (cannot be caught or ignored)
112    SIGTSTP     : constant := 24; --  user stop requested from tty
113    SIGCONT     : constant := 25; --  stopped process has been continued
114    SIGTTIN     : constant := 26; --  background tty read attempted
115    SIGTTOU     : constant := 27; --  background tty write attempted
116    SIGVTALRM   : constant := 28; --  virtual timer expired
117    SIGPROF     : constant := 29; --  profiling timer expired
118    SIGXCPU     : constant := 30; --  CPU time limit exceeded
119    SIGXFSZ     : constant := 31; --  filesize limit exceeded
120    SIGWAITING  : constant := 32; --  process's lwps blocked (Solaris)
121    SIGLWP      : constant := 33; --  used by thread library (Solaris)
122    SIGFREEZE   : constant := 34; --  used by CPR (Solaris)
123    SIGTHAW     : constant := 35; --  used by CPR (Solaris)
124    SIGCANCEL   : constant := 36; --  thread cancellation signal (libthread)
125
126    SIGADAABORT : constant := SIGABRT;
127
128    type Signal_Set is array (Natural range <>) of Signal;
129
130    Unmasked    : constant Signal_Set := (SIGTRAP, SIGLWP, SIGPROF);
131
132    --  Following signals should not be disturbed.
133    --  See c-posix-signals.c in FLORIST
134
135    Reserved    : constant Signal_Set :=
136      (SIGKILL, SIGSTOP, SIGWAITING, SIGCANCEL);
137
138    type sigset_t is private;
139
140    function sigaddset (set : access sigset_t; sig : Signal) return int;
141    pragma Import (C, sigaddset, "sigaddset");
142
143    function sigdelset (set : access sigset_t; sig : Signal) return int;
144    pragma Import (C, sigdelset, "sigdelset");
145
146    function sigfillset (set : access sigset_t) return int;
147    pragma Import (C, sigfillset, "sigfillset");
148
149    function sigismember (set : access sigset_t; sig : Signal) return int;
150    pragma Import (C, sigismember, "sigismember");
151
152    function sigemptyset (set : access sigset_t) return int;
153    pragma Import (C, sigemptyset, "sigemptyset");
154
155    type struct_sigaction is record
156       sa_flags   : int;
157       sa_handler : System.Address;
158       sa_mask    : sigset_t;
159       sa_resv1   : int;
160       sa_resv2   : int;
161    end record;
162    pragma Convention (C, struct_sigaction);
163    type struct_sigaction_ptr is access all struct_sigaction;
164
165    SA_SIGINFO : constant := 16#0008#;
166    SA_ONSTACK : constant := 16#0001#;
167
168    SIG_BLOCK   : constant := 1;
169    SIG_UNBLOCK : constant := 2;
170    SIG_SETMASK : constant := 3;
171
172    SIG_DFL : constant := 0;
173    SIG_IGN : constant := 1;
174
175    function sigaction
176      (sig  : Signal;
177       act  : struct_sigaction_ptr;
178       oact : struct_sigaction_ptr) return int;
179    pragma Import (C, sigaction, "sigaction");
180
181    ----------
182    -- Time --
183    ----------
184
185    Time_Slice_Supported : constant Boolean := True;
186    --  Indicates whether time slicing is supported
187
188    type timespec is private;
189
190    type clockid_t is private;
191
192    CLOCK_REALTIME  : constant clockid_t;
193    CLOCK_MONOTONIC : constant clockid_t;
194
195    function clock_gettime
196      (clock_id : clockid_t;
197       tp       : access timespec) return int;
198    pragma Import (C, clock_gettime, "clock_gettime");
199
200    function To_Duration (TS : timespec) return Duration;
201    pragma Inline (To_Duration);
202
203    function To_Timespec (D : Duration) return timespec;
204    pragma Inline (To_Timespec);
205
206    -------------------------
207    -- Priority Scheduling --
208    -------------------------
209
210    SCHED_FIFO  : constant := 1;
211    SCHED_RR    : constant := 2;
212    SCHED_OTHER : constant := 0;
213
214    function To_Target_Priority
215      (Prio : System.Any_Priority) return Interfaces.C.int;
216    --  Maps System.Any_Priority to a POSIX priority
217
218    -------------
219    -- Process --
220    -------------
221
222    type pid_t is private;
223
224    function kill (pid : pid_t; sig : Signal) return int;
225    pragma Import (C, kill, "kill");
226
227    function getpid return pid_t;
228    pragma Import (C, getpid, "getpid");
229
230    ---------
231    -- LWP --
232    ---------
233
234    function lwp_self return System.Address;
235    pragma Import (C, lwp_self, "_lwp_self");
236
237    -------------
238    -- Threads --
239    -------------
240
241    type Thread_Body is access
242      function (arg : System.Address) return System.Address;
243    pragma Convention (C, Thread_Body);
244
245    function Thread_Body_Access is new
246      Ada.Unchecked_Conversion (System.Address, Thread_Body);
247
248    type pthread_t           is private;
249    subtype Thread_Id        is pthread_t;
250
251    type pthread_mutex_t     is limited private;
252    type pthread_cond_t      is limited private;
253    type pthread_attr_t      is limited private;
254    type pthread_mutexattr_t is limited private;
255    type pthread_condattr_t  is limited private;
256    type pthread_key_t       is private;
257
258    --  Read/Write lock not supported on Solaris. To add support both types
259    --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
260    --  with the associated routines pthread_rwlock_[init/destroy] and
261    --  pthread_rwlock_[rdlock/wrlock/unlock].
262
263    subtype pthread_rwlock_t     is pthread_mutex_t;
264    subtype pthread_rwlockattr_t is pthread_mutexattr_t;
265
266    PTHREAD_CREATE_DETACHED : constant := 16#40#;
267
268    PTHREAD_SCOPE_PROCESS : constant := 0;
269    PTHREAD_SCOPE_SYSTEM  : constant := 1;
270
271    -----------
272    -- Stack --
273    -----------
274
275    type stack_t is record
276       ss_sp    : System.Address;
277       ss_size  : size_t;
278       ss_flags : int;
279    end record;
280    pragma Convention (C, stack_t);
281
282    function sigaltstack
283      (ss  : not null access stack_t;
284       oss : access stack_t) return int;
285    pragma Import (C, sigaltstack, "sigaltstack");
286
287    Alternate_Stack : aliased System.Address;
288    --  This is a dummy definition, never used (Alternate_Stack_Size is null)
289
290    Alternate_Stack_Size : constant := 0;
291    --  No alternate signal stack is used on this platform
292
293    Stack_Base_Available : constant Boolean := False;
294    --  Indicates whether the stack base is available on this target
295
296    function Get_Stack_Base (thread : pthread_t) return Address;
297    pragma Inline (Get_Stack_Base);
298    --  Returns the stack base of the specified thread. Only call this function
299    --  when Stack_Base_Available is True.
300
301    function Get_Page_Size return size_t;
302    function Get_Page_Size return Address;
303    pragma Import (C, Get_Page_Size, "getpagesize");
304    --  Returns the size of a page
305
306    PROT_NONE  : constant := 0;
307    PROT_READ  : constant := 1;
308    PROT_WRITE : constant := 2;
309    PROT_EXEC  : constant := 4;
310    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
311    PROT_ON    : constant := PROT_READ;
312    PROT_OFF   : constant := PROT_ALL;
313
314    function mprotect (addr : Address; len : size_t; prot : int) return int;
315    pragma Import (C, mprotect);
316
317    ---------------------------------------
318    -- Nonstandard Thread Initialization --
319    ---------------------------------------
320
321    procedure pthread_init;
322    --  This is a dummy procedure to share some GNULLI files
323
324    -------------------------
325    -- POSIX.1c  Section 3 --
326    -------------------------
327
328    function sigwait
329      (set : access sigset_t;
330       sig : access Signal) return int;
331    pragma Import (C, sigwait, "__posix_sigwait");
332
333    function pthread_kill
334      (thread : pthread_t;
335       sig    : Signal) return int;
336    pragma Import (C, pthread_kill, "pthread_kill");
337
338    function pthread_sigmask
339      (how  : int;
340       set  : access sigset_t;
341       oset : access sigset_t) return int;
342    pragma Import (C, pthread_sigmask, "pthread_sigmask");
343
344    --------------------------
345    -- POSIX.1c  Section 11 --
346    --------------------------
347
348    function pthread_mutexattr_init
349      (attr : access pthread_mutexattr_t) return int;
350    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
351
352    function pthread_mutexattr_destroy
353      (attr : access pthread_mutexattr_t) return int;
354    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
355
356    function pthread_mutex_init
357      (mutex : access pthread_mutex_t;
358       attr  : access pthread_mutexattr_t) return int;
359    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
360
361    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
362    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
363
364    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
365    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
366
367    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
368    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
369
370    function pthread_condattr_init
371      (attr : access pthread_condattr_t) return int;
372    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
373
374    function pthread_condattr_destroy
375      (attr : access pthread_condattr_t) return int;
376    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
377
378    function pthread_cond_init
379      (cond : access pthread_cond_t;
380       attr : access pthread_condattr_t) return int;
381    pragma Import (C, pthread_cond_init, "pthread_cond_init");
382
383    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
384    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
385
386    function pthread_cond_signal (cond : access pthread_cond_t) return int;
387    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
388
389    function pthread_cond_wait
390      (cond  : access pthread_cond_t;
391       mutex : access pthread_mutex_t) return int;
392    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
393
394    function pthread_cond_timedwait
395      (cond    : access pthread_cond_t;
396       mutex   : access pthread_mutex_t;
397       abstime : access timespec) return int;
398    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
399
400    Relative_Timed_Wait : constant Boolean := False;
401    --  pthread_cond_timedwait requires an absolute delay time
402
403    --------------------------
404    -- POSIX.1c  Section 13 --
405    --------------------------
406
407    PTHREAD_PRIO_NONE    : constant := 0;
408    PTHREAD_PRIO_INHERIT : constant := 16#10#;
409    PTHREAD_PRIO_PROTECT : constant := 16#20#;
410
411    function pthread_mutexattr_setprotocol
412      (attr     : access pthread_mutexattr_t;
413       protocol : int) return int;
414    pragma Import (C, pthread_mutexattr_setprotocol);
415
416    function pthread_mutexattr_setprioceiling
417      (attr        : access pthread_mutexattr_t;
418       prioceiling : int) return int;
419    pragma Import (C, pthread_mutexattr_setprioceiling);
420
421    type Array_8_Int is array (0 .. 7) of int;
422    type struct_sched_param is record
423       sched_priority : int;
424       sched_pad      : Array_8_Int;
425    end record;
426
427    function pthread_setschedparam
428      (thread : pthread_t;
429       policy : int;
430       param  : access struct_sched_param) return int;
431    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
432
433    function pthread_attr_setscope
434      (attr            : access pthread_attr_t;
435       contentionscope : int) return int;
436    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
437
438    function pthread_attr_setinheritsched
439      (attr         : access pthread_attr_t;
440       inheritsched : int) return int;
441    pragma Import (C, pthread_attr_setinheritsched);
442
443    function pthread_attr_setschedpolicy
444      (attr   : access pthread_attr_t;
445       policy : int) return int;
446    pragma Import (C, pthread_attr_setschedpolicy);
447
448    function sched_yield return int;
449    pragma Import (C, sched_yield, "sched_yield");
450
451    ---------------------------
452    -- P1003.1c - Section 16 --
453    ---------------------------
454
455    function pthread_attr_init (attributes : access pthread_attr_t) return int;
456    pragma Import (C, pthread_attr_init, "pthread_attr_init");
457
458    function pthread_attr_destroy
459      (attributes : access pthread_attr_t) return int;
460    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
461
462    function pthread_attr_setdetachstate
463      (attr        : access pthread_attr_t;
464       detachstate : int) return int;
465    pragma Import (C, pthread_attr_setdetachstate);
466
467    function pthread_attr_setstacksize
468      (attr      : access pthread_attr_t;
469       stacksize : size_t) return int;
470    pragma Import (C, pthread_attr_setstacksize);
471
472    function pthread_create
473      (thread        : access pthread_t;
474       attributes    : access pthread_attr_t;
475       start_routine : Thread_Body;
476       arg           : System.Address) return int;
477    pragma Import (C, pthread_create, "pthread_create");
478
479    procedure pthread_exit (status : System.Address);
480    pragma Import (C, pthread_exit, "pthread_exit");
481
482    function pthread_self return pthread_t;
483    pragma Import (C, pthread_self, "pthread_self");
484
485    --------------------------
486    -- POSIX.1c  Section 17 --
487    --------------------------
488
489    function pthread_setspecific
490      (key   : pthread_key_t;
491       value : System.Address) return int;
492    pragma Import (C, pthread_setspecific, "pthread_setspecific");
493
494    function pthread_getspecific (key : pthread_key_t) return System.Address;
495    pragma Import (C, pthread_getspecific, "pthread_getspecific");
496
497    type destructor_pointer is access procedure (arg : System.Address);
498    pragma Convention (C, destructor_pointer);
499
500    function pthread_key_create
501      (key        : access pthread_key_t;
502       destructor : destructor_pointer) return int;
503    pragma Import (C, pthread_key_create, "pthread_key_create");
504
505 private
506
507    type array_type_1 is array (Integer range 0 .. 3) of unsigned_long;
508    type sigset_t is record
509       X_X_sigbits  : array_type_1;
510    end record;
511    pragma Convention (C, sigset_t);
512
513    type pid_t is new long;
514
515    type time_t is new long;
516
517    type timespec is record
518       tv_sec  : time_t;
519       tv_nsec : long;
520    end record;
521    pragma Convention (C, timespec);
522
523    type clockid_t is new int;
524    CLOCK_REALTIME  : constant clockid_t := 3;
525    CLOCK_MONOTONIC : constant clockid_t := CLOCK_REALTIME;
526
527    type pthread_attr_t is record
528       pthread_attrp : System.Address;
529    end record;
530    pragma Convention (C, pthread_attr_t);
531
532    type pthread_condattr_t is record
533       pthread_condattrp : System.Address;
534    end record;
535    pragma Convention (C, pthread_condattr_t);
536
537    type pthread_mutexattr_t is record
538       pthread_mutexattrp : System.Address;
539    end record;
540    pragma Convention (C, pthread_mutexattr_t);
541
542    type pthread_t is new unsigned;
543
544    type uint64_t is mod 2 ** 64;
545
546    type pthread_mutex_t is record
547       pthread_mutex_flags   : uint64_t;
548       pthread_mutex_owner64 : uint64_t;
549       pthread_mutex_data    : uint64_t;
550    end record;
551    pragma Convention (C, pthread_mutex_t);
552    type pthread_mutex_t_ptr is access pthread_mutex_t;
553
554    type pthread_cond_t is record
555       pthread_cond_flags : uint64_t;
556       pthread_cond_data  : uint64_t;
557    end record;
558    pragma Convention (C, pthread_cond_t);
559
560    type pthread_key_t is new unsigned;
561
562 end System.OS_Interface;