OSDN Git Service

2011-08-05 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-irix.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-2010, 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 the SGI Pthreads version of this package
34
35 --  This package encapsulates all direct interfaces to OS services that are
36 --  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 Ada.Unchecked_Conversion;
42
43 with Interfaces.C;
44
45 package System.OS_Interface is
46
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-lpthread");
50
51    subtype int            is Interfaces.C.int;
52    subtype short          is Interfaces.C.short;
53    subtype long           is Interfaces.C.long;
54    subtype unsigned       is Interfaces.C.unsigned;
55    subtype unsigned_short is Interfaces.C.unsigned_short;
56    subtype unsigned_long  is Interfaces.C.unsigned_long;
57    subtype unsigned_char  is Interfaces.C.unsigned_char;
58    subtype plain_char     is Interfaces.C.plain_char;
59    subtype size_t         is Interfaces.C.size_t;
60
61    -----------
62    -- Errno --
63    -----------
64
65    function errno return int;
66    pragma Import (C, errno, "__get_errno");
67
68    EINTR     : constant := 4;   --  interrupted system call
69    EAGAIN    : constant := 11;  --  No more processes
70    ENOMEM    : constant := 12;  --  Not enough core
71    EINVAL    : constant := 22;  --  Invalid argument
72    ETIMEDOUT : constant := 145; --  Connection timed out
73
74    -------------
75    -- Signals --
76    -------------
77
78    Max_Interrupt : constant := 64;
79    type Signal is new int range 0 .. Max_Interrupt;
80    for Signal'Size use int'Size;
81
82    SIGHUP     : constant := 1; --  hangup
83    SIGINT     : constant := 2; --  interrupt (rubout)
84    SIGQUIT    : constant := 3; --  quit (ASCD FS)
85    SIGILL     : constant := 4; --  illegal instruction (not reset)
86    SIGTRAP    : constant := 5; --  trace trap (not reset)
87    SIGIOT     : constant := 6; --  IOT instruction
88    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the future
89    SIGEMT     : constant := 7; --  EMT instruction
90    SIGFPE     : constant := 8; --  floating point exception
91    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
92    SIGBUS     : constant := 10; --  bus error
93    SIGSEGV    : constant := 11; --  segmentation violation
94    SIGSYS     : constant := 12; --  bad argument to system call
95    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
96    SIGALRM    : constant := 14; --  alarm clock
97    SIGTERM    : constant := 15; --  software termination signal from kill
98    SIGUSR1    : constant := 16; --  user defined signal 1
99    SIGUSR2    : constant := 17; --  user defined signal 2
100    SIGCLD     : constant := 18; --  alias for SIGCHLD
101    SIGCHLD    : constant := 18; --  child status change
102    SIGPWR     : constant := 19; --  power-fail restart
103    SIGWINCH   : constant := 20; --  window size change
104    SIGURG     : constant := 21; --  urgent condition on IO channel
105    SIGPOLL    : constant := 22; --  pollable event occurred
106    SIGIO      : constant := 22; --  I/O possible (Solaris SIGPOLL alias)
107    SIGSTOP    : constant := 23; --  stop (cannot be caught or ignored)
108    SIGTSTP    : constant := 24; --  user stop requested from tty
109    SIGCONT    : constant := 25; --  stopped process has been continued
110    SIGTTIN    : constant := 26; --  background tty read attempted
111    SIGTTOU    : constant := 27; --  background tty write attempted
112    SIGVTALRM  : constant := 28; --  virtual timer expired
113    SIGPROF    : constant := 29; --  profiling timer expired
114    SIGXCPU    : constant := 30; --  CPU time limit exceeded
115    SIGXFSZ    : constant := 31; --  filesize limit exceeded
116    SIGK32     : constant := 32; --  reserved for kernel (IRIX)
117    SIGCKPT    : constant := 33; --  Checkpoint warning
118    SIGRESTART : constant := 34; --  Restart warning
119    SIGUME     : constant := 35; --  Uncorrectable memory error
120    --  Signals defined for Posix 1003.1c
121    SIGPTINTR    : constant := 47;
122    SIGPTRESCHED : constant := 48;
123    --  Posix 1003.1b signals
124    SIGRTMIN   : constant := 49; --  Posix 1003.1b signals
125    SIGRTMAX   : constant := 64; --  Posix 1003.1b signals
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 array_type_2 is array (Integer range 0 .. 1) of int;
145    type struct_sigaction is record
146       sa_flags     : int;
147       sa_handler   : System.Address;
148       sa_mask      : sigset_t;
149       sa_resv      : array_type_2;
150    end record;
151    pragma Convention (C, struct_sigaction);
152
153    type struct_sigaction_ptr is access all struct_sigaction;
154
155    SIG_BLOCK   : constant := 1;
156    SIG_UNBLOCK : constant := 2;
157    SIG_SETMASK : constant := 3;
158
159    SIG_DFL : constant := 0;
160    SIG_IGN : constant := 1;
161
162    function sigaction
163      (sig  : Signal;
164       act  : struct_sigaction_ptr;
165       oact : struct_sigaction_ptr := null) return int;
166    pragma Import (C, sigaction, "sigaction");
167
168    ----------
169    -- Time --
170    ----------
171
172    type timespec is private;
173    type timespec_ptr is access all timespec;
174
175    type clockid_t is private;
176
177    CLOCK_REALTIME  : constant clockid_t;
178    CLOCK_SGI_FAST  : constant clockid_t;
179    CLOCK_SGI_CYCLE : constant clockid_t;
180
181    SGI_CYCLECNTR_SIZE : constant := 165;
182
183    function syssgi (request : Interfaces.C.int) return Interfaces.C.ptrdiff_t;
184    pragma Import (C, syssgi, "syssgi");
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       tp       : 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_TS    : constant := 3;
209    SCHED_OTHER : constant := 3;
210    SCHED_NP    : constant := 4;
211
212    function sched_get_priority_min (Policy : int) return int;
213    pragma Import (C, sched_get_priority_min, "sched_get_priority_min");
214
215    function sched_get_priority_max (Policy : int) return int;
216    pragma Import (C, sched_get_priority_max, "sched_get_priority_max");
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    -- Threads --
232    -------------
233
234    type Thread_Body is access
235      function (arg : System.Address) return System.Address;
236    pragma Convention (C, Thread_Body);
237
238    function Thread_Body_Access is new
239      Ada.Unchecked_Conversion (System.Address, Thread_Body);
240
241    type pthread_t           is private;
242    subtype Thread_Id        is pthread_t;
243
244    type pthread_mutex_t     is limited private;
245    type pthread_cond_t      is limited private;
246    type pthread_attr_t      is limited private;
247    type pthread_mutexattr_t is limited private;
248    type pthread_condattr_t  is limited private;
249    type pthread_key_t       is private;
250
251    PTHREAD_CREATE_DETACHED : constant := 1;
252
253    -----------
254    -- Stack --
255    -----------
256
257    Alternate_Stack_Size : constant := 0;
258    --  No alternate signal stack is used on this platform
259
260    ---------------------------------------
261    -- Nonstandard Thread Initialization --
262    ---------------------------------------
263
264    procedure pthread_init;
265    pragma Inline (pthread_init);
266    --  This is a dummy procedure to share some GNULLI files
267
268    -------------------------
269    -- POSIX.1c  Section 3 --
270    -------------------------
271
272    function sigwait
273      (set : access sigset_t;
274       sig : access Signal) return int;
275    pragma Import (C, sigwait, "sigwait");
276
277    function pthread_kill
278      (thread : pthread_t;
279       sig    : Signal) return int;
280    pragma Import (C, pthread_kill, "pthread_kill");
281
282    function pthread_sigmask
283      (how  : int;
284       set  : access sigset_t;
285       oset : access sigset_t) return int;
286    pragma Import (C, pthread_sigmask, "pthread_sigmask");
287
288    --------------------------
289    -- POSIX.1c  Section 11 --
290    --------------------------
291
292    function pthread_mutexattr_init
293      (attr : access pthread_mutexattr_t) return int;
294    pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
295
296    function pthread_mutexattr_destroy
297      (attr : access pthread_mutexattr_t) return int;
298    pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
299
300    function pthread_mutex_init
301      (mutex : access pthread_mutex_t;
302       attr  : access pthread_mutexattr_t) return int;
303    pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
304
305    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
306    pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
307
308    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
309    pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
310
311    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
312    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
313
314    function pthread_condattr_init
315      (attr : access pthread_condattr_t) return int;
316    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
317
318    function pthread_condattr_destroy
319      (attr : access pthread_condattr_t) return int;
320    pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
321
322    function pthread_cond_init
323      (cond : access pthread_cond_t;
324       attr : access pthread_condattr_t) return int;
325    pragma Import (C, pthread_cond_init, "pthread_cond_init");
326
327    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
328    pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
329
330    function pthread_cond_signal (cond : access pthread_cond_t) return int;
331    pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
332
333    function pthread_cond_wait
334      (cond  : access pthread_cond_t;
335       mutex : access pthread_mutex_t) return int;
336    pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
337
338    function pthread_cond_timedwait
339      (cond    : access pthread_cond_t;
340       mutex   : access pthread_mutex_t;
341       abstime : access timespec) return int;
342    pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
343
344    --------------------------
345    -- POSIX.1c  Section 13 --
346    --------------------------
347
348    PTHREAD_PRIO_NONE    : constant := 0;
349    PTHREAD_PRIO_PROTECT : constant := 2;
350    PTHREAD_PRIO_INHERIT : constant := 1;
351
352    function pthread_mutexattr_setprotocol
353      (attr     : access pthread_mutexattr_t;
354       protocol : int) return int;
355    pragma Import (C, pthread_mutexattr_setprotocol);
356
357    function pthread_mutexattr_setprioceiling
358      (attr     : access pthread_mutexattr_t;
359       prioceiling : int) return int;
360    pragma Import (C, pthread_mutexattr_setprioceiling);
361
362    type struct_sched_param is record
363       sched_priority : int;
364    end record;
365    pragma Convention (C, struct_sched_param);
366
367    function pthread_setschedparam
368      (thread : pthread_t;
369       policy : int;
370       param  : access struct_sched_param)
371      return int;
372    pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
373
374    function pthread_attr_setscope
375      (attr            : access pthread_attr_t;
376       contentionscope : int) return int;
377    pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
378
379    function pthread_attr_setinheritsched
380      (attr         : access pthread_attr_t;
381       inheritsched : int) return int;
382    pragma Import
383      (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
384
385    function pthread_attr_setschedpolicy
386      (attr   : access pthread_attr_t;
387       policy : int) return int;
388    pragma Import (C, pthread_attr_setschedpolicy);
389
390    function pthread_attr_setschedparam
391      (attr        : access pthread_attr_t;
392       sched_param : access struct_sched_param)
393      return int;
394    pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam");
395
396    function sched_yield return int;
397    pragma Import (C, sched_yield, "sched_yield");
398
399    ---------------------------
400    -- P1003.1c - Section 16 --
401    ---------------------------
402
403    function pthread_attr_init (attributes : access pthread_attr_t) return int;
404    pragma Import (C, pthread_attr_init, "pthread_attr_init");
405
406    function pthread_attr_destroy
407      (attributes : access pthread_attr_t) return int;
408    pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
409
410    function pthread_attr_setdetachstate
411      (attr        : access pthread_attr_t;
412       detachstate : int) return int;
413    pragma Import (C, pthread_attr_setdetachstate);
414
415    function pthread_attr_setstacksize
416      (attr      : access pthread_attr_t;
417       stacksize : size_t) return int;
418    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
419
420    function pthread_create
421      (thread        : access pthread_t;
422       attributes    : access pthread_attr_t;
423       start_routine : Thread_Body;
424       arg           : System.Address) return int;
425    pragma Import (C, pthread_create, "pthread_create");
426
427    procedure pthread_exit (status : System.Address);
428    pragma Import (C, pthread_exit, "pthread_exit");
429
430    function pthread_self return pthread_t;
431    pragma Import (C, pthread_self, "pthread_self");
432
433    --------------------------
434    -- POSIX.1c  Section 17 --
435    --------------------------
436
437    function pthread_setspecific
438      (key   : pthread_key_t;
439       value : System.Address) return int;
440    pragma Import (C, pthread_setspecific, "pthread_setspecific");
441
442    function pthread_getspecific (key : pthread_key_t) return System.Address;
443    pragma Import (C, pthread_getspecific, "pthread_getspecific");
444
445    type destructor_pointer is access procedure (arg : System.Address);
446    pragma Convention (C, destructor_pointer);
447
448    function pthread_key_create
449      (key        : access pthread_key_t;
450       destructor : destructor_pointer) return int;
451    pragma Import (C, pthread_key_create, "pthread_key_create");
452
453    -------------------
454    -- SGI Additions --
455    -------------------
456
457    --  Non portable SGI 6.5 additions to the pthread interface must be
458    --  executed from within the context of a system scope task.
459
460    function pthread_setrunon_np (cpu : int) return int;
461    pragma Import (C, pthread_setrunon_np, "pthread_setrunon_np");
462
463 private
464
465    type array_type_1 is array (Integer range 0 .. 3) of unsigned;
466    type sigset_t is record
467       X_X_sigbits : array_type_1;
468    end record;
469    pragma Convention (C, sigset_t);
470
471    type pid_t is new long;
472
473    type time_t is new long;
474
475    type timespec is record
476       tv_sec  : time_t;
477       tv_nsec : long;
478    end record;
479    pragma Convention (C, timespec);
480
481    type clockid_t is new int;
482    CLOCK_REALTIME  : constant clockid_t := 1;
483    CLOCK_SGI_CYCLE : constant clockid_t := 2;
484    CLOCK_SGI_FAST  : constant clockid_t := 3;
485
486    type array_type_9 is array (Integer range 0 .. 4) of long;
487    type pthread_attr_t is record
488       X_X_D : array_type_9;
489    end record;
490    pragma Convention (C, pthread_attr_t);
491
492    type array_type_8 is array (Integer range 0 .. 1) of long;
493    type pthread_condattr_t is record
494       X_X_D : array_type_8;
495    end record;
496    pragma Convention (C, pthread_condattr_t);
497
498    type array_type_7 is array (Integer range 0 .. 1) of long;
499    type pthread_mutexattr_t is record
500       X_X_D : array_type_7;
501    end record;
502    pragma Convention (C, pthread_mutexattr_t);
503
504    type pthread_t is new unsigned;
505
506    type array_type_10 is array (Integer range 0 .. 7) of long;
507    type pthread_mutex_t is record
508       X_X_D : array_type_10;
509    end record;
510    pragma Convention (C, pthread_mutex_t);
511
512    type array_type_11 is array (Integer range 0 .. 7) of long;
513    type pthread_cond_t is record
514       X_X_D : array_type_11;
515    end record;
516    pragma Convention (C, pthread_cond_t);
517
518    type pthread_key_t is new int;
519
520 end System.OS_Interface;