OSDN Git Service

./:
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-tru64.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-2007, 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 the DEC Unix 4.0/5.1 version of this package
36
37 --  This package encapsulates all direct interfaces to OS services
38 --  that are needed by children of System.
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 Interfaces.C;
44 with Ada.Unchecked_Conversion;
45
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    pragma Linker_Options ("-lpthread");
50    pragma Linker_Options ("-lmach");
51    pragma Linker_Options ("-lexc");
52    pragma Linker_Options ("-lrt");
53
54    subtype int            is Interfaces.C.int;
55    subtype short          is Interfaces.C.short;
56    subtype long           is Interfaces.C.long;
57    subtype unsigned       is Interfaces.C.unsigned;
58    subtype unsigned_short is Interfaces.C.unsigned_short;
59    subtype unsigned_long  is Interfaces.C.unsigned_long;
60    subtype unsigned_char  is Interfaces.C.unsigned_char;
61    subtype plain_char     is Interfaces.C.plain_char;
62    subtype size_t         is Interfaces.C.size_t;
63    subtype char_array     is Interfaces.C.char_array;
64
65    -----------
66    -- Errno --
67    -----------
68
69    function errno return int;
70    pragma Import (C, errno, "_Geterrno");
71
72    EAGAIN    : constant := 35;
73    EINTR     : constant := 4;
74    EINVAL    : constant := 22;
75    ENOMEM    : constant := 12;
76    ETIMEDOUT : constant := 60;
77
78    -------------
79    -- Signals --
80    -------------
81
82    Max_Interrupt : constant := 48;
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    SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
92    SIGIOT     : constant := 6; --  abort (terminate) process
93    SIGLOST    : constant := 6; --  old BSD signal ??
94    SIGEMT     : constant := 7; --  EMT instruction
95    SIGFPE     : constant := 8; --  floating point exception
96    SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
97    SIGBUS     : constant := 10; --  bus error
98    SIGSEGV    : constant := 11; --  segmentation violation
99    SIGSYS     : constant := 12; --  bad argument to system call
100    SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
101    SIGALRM    : constant := 14; --  alarm clock
102    SIGTERM    : constant := 15; --  software termination signal from kill
103    SIGURG     : constant := 16; --  urgent condition on IO channel
104    SIGIOINT   : constant := 16; --  printer to backend error signal
105    SIGSTOP    : constant := 17; --  stop (cannot be caught or ignored)
106    SIGTSTP    : constant := 18; --  user stop requested from tty
107    SIGCONT    : constant := 19; --  stopped process has been continued
108    SIGCHLD    : constant := 20; --  child status change
109    SIGTTIN    : constant := 21; --  background tty read attempted
110    SIGTTOU    : constant := 22; --  background tty write attempted
111    SIGPOLL    : constant := 23; --  I/O possible, or completed
112    SIGIO      : constant := 23; --  STREAMS version of SIGPOLL
113    SIGAIO     : constant := 23; --  base lan i/o
114    SIGPTY     : constant := 23; --  pty i/o
115    SIGXCPU    : constant := 24; --  CPU time limit exceeded
116    SIGXFSZ    : constant := 25; --  filesize limit exceeded
117    SIGVTALRM  : constant := 26; --  virtual timer expired
118    SIGPROF    : constant := 27; --  profiling timer expired
119    SIGWINCH   : constant := 28; --  window size change
120    SIGINFO    : constant := 29; --  information request
121    SIGPWR     : constant := 29; --  Power Fail/Restart -- SVID3/SVR4
122    SIGUSR1    : constant := 30; --  user defined signal 1
123    SIGUSR2    : constant := 31; --  user defined signal 2
124    SIGRESV    : constant := 32; --  reserved by Digital for future use
125
126    SIGADAABORT : constant := SIGABRT;
127
128    type Signal_Set is array (Natural range <>) of Signal;
129
130    Unmasked    : constant Signal_Set := (0 .. 0 => SIGTRAP);
131    Reserved    : constant Signal_Set := (SIGALRM, SIGABRT, SIGKILL, SIGSTOP);
132
133    type sigset_t is private;
134
135    function sigaddset (set : access sigset_t; sig : Signal) return int;
136    pragma Import (C, sigaddset);
137
138    function sigdelset (set : access sigset_t; sig : Signal) return int;
139    pragma Import (C, sigdelset);
140
141    function sigfillset (set : access sigset_t) return int;
142    pragma Import (C, sigfillset);
143
144    function sigismember (set : access sigset_t; sig : Signal) return int;
145    pragma Import (C, sigismember);
146
147    function sigemptyset (set : access sigset_t) return int;
148    pragma Import (C, sigemptyset);
149
150    type union_type_3 is new String (1 .. 116);
151    type siginfo_t is record
152       si_signo     : int;
153       si_errno     : int;
154       si_code      : int;
155       X_data       : union_type_3;
156    end record;
157    for siginfo_t'Size use 8 * 128;
158    pragma Convention (C, siginfo_t);
159
160    type struct_sigaction is record
161       sa_handler : System.Address;
162       sa_mask    : sigset_t;
163       sa_flags   : int;
164       sa_signo   : int;
165    end record;
166    pragma Convention (C, struct_sigaction);
167    type struct_sigaction_ptr is access all struct_sigaction;
168
169    SIG_BLOCK   : constant := 1;
170    SIG_UNBLOCK : constant := 2;
171    SIG_SETMASK : constant := 3;
172
173    SIG_DFL : constant := 0;
174    SIG_IGN : constant := 1;
175
176    SA_NODEFER : constant := 8;
177    SA_SIGINFO : constant := 16#40#;
178
179    function sigaction
180      (sig  : Signal;
181       act  : struct_sigaction_ptr;
182       oact : struct_sigaction_ptr) return int;
183    pragma Import (C, sigaction);
184
185    ----------
186    -- Time --
187    ----------
188
189    type timespec is private;
190
191    function nanosleep (rqtp, rmtp : access timespec)  return int;
192    pragma Import (C, nanosleep);
193
194    type clockid_t is private;
195
196    CLOCK_REALTIME : constant clockid_t;
197
198    function clock_gettime
199      (clock_id : clockid_t;
200       tp       : access timespec) return int;
201    pragma Import (C, clock_gettime);
202
203    function To_Duration (TS : timespec) return Duration;
204    pragma Inline (To_Duration);
205
206    function To_Timespec (D : Duration) return timespec;
207    pragma Inline (To_Timespec);
208
209    type struct_timezone is record
210       tz_minuteswest : int;
211       tz_dsttime     : int;
212    end record;
213    pragma Convention (C, struct_timezone);
214
215    -------------------------
216    -- Priority Scheduling --
217    -------------------------
218
219    SCHED_FIFO  : constant := 1;
220    SCHED_RR    : constant := 2;
221    SCHED_OTHER : constant := 3;
222    SCHED_LFI   : constant := 5;
223
224    -------------
225    -- Process --
226    -------------
227
228    type pid_t is private;
229
230    function kill (pid : pid_t; sig : Signal) return int;
231    pragma Import (C, kill);
232
233    function getpid return pid_t;
234    pragma Import (C, getpid);
235
236    BIND_NO_INHERIT  : constant := 1;
237
238    function bind_to_cpu
239      (pid       : pid_t;
240       cpu_mask  : unsigned_long;
241       flag      : unsigned_long := BIND_NO_INHERIT) return int;
242    pragma Import (C, bind_to_cpu);
243
244    -------------
245    -- Threads --
246    -------------
247
248    type Thread_Body is access
249      function (arg : System.Address) return System.Address;
250
251    function Thread_Body_Access is new
252      Ada.Unchecked_Conversion (System.Address, Thread_Body);
253
254    type pthread_t           is private;
255    subtype Thread_Id        is pthread_t;
256
257    type pthread_mutex_t     is limited private;
258    type pthread_cond_t      is limited private;
259    type pthread_attr_t      is limited private;
260    type pthread_mutexattr_t is limited private;
261    type pthread_condattr_t  is limited private;
262    type pthread_key_t       is private;
263
264    PTHREAD_CREATE_DETACHED : constant := 1;
265
266    PTHREAD_SCOPE_PROCESS : constant := 0;
267    PTHREAD_SCOPE_SYSTEM  : constant := 1;
268
269    PTHREAD_EXPLICIT_SCHED : constant := 1;
270
271    -----------
272    -- Stack --
273    -----------
274
275    Stack_Base_Available : constant Boolean := False;
276    --  Indicates wether the stack base is available on this target.
277
278    function Get_Stack_Base (thread : pthread_t) return Address;
279    pragma Inline (Get_Stack_Base);
280    --  returns the stack base of the specified thread.
281    --  Only call this function when Stack_Base_Available is True.
282
283    function Get_Page_Size return size_t;
284    function Get_Page_Size return Address;
285    pragma Import (C, Get_Page_Size, "getpagesize");
286    --  returns the size of a page, or 0 if this is not relevant on this
287    --  target
288
289    PROT_NONE  : constant := 0;
290    PROT_READ  : constant := 1;
291    PROT_WRITE : constant := 2;
292    PROT_EXEC  : constant := 4;
293    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
294
295    PROT_ON    : constant := PROT_READ;
296    PROT_OFF   : constant := PROT_ALL;
297
298    function mprotect (addr : Address; len : size_t; prot : int) return int;
299    pragma Import (C, mprotect);
300
301    procedure Hide_Yellow_Zone;
302    --  Every thread except the initial one features an overflow warning area
303    --  just above the overflow guard area on the stack. They are called
304    --  the Yellow Zone and the Red Zone respectively. This procedure hides
305    --  the former so that the latter could be exposed to stack probing.
306
307    ---------------------------------------
308    -- Nonstandard Thread Initialization --
309    ---------------------------------------
310
311    procedure pthread_init;
312    pragma Inline (pthread_init);
313    --  This is a dummy procedure to share some GNULLI files
314
315    -------------------------
316    -- POSIX.1c  Section 3 --
317    -------------------------
318
319    function sigwait
320      (set : access sigset_t;
321       sig : access Signal) return int;
322    pragma Import (C, sigwait, "__sigwaitd10");
323
324    function pthread_kill
325      (thread : pthread_t;
326       sig    : Signal) return int;
327    pragma Import (C, pthread_kill);
328
329    function pthread_sigmask
330      (how  : int;
331       set  : access sigset_t;
332       oset : access sigset_t) return int;
333    pragma Import (C, pthread_sigmask);
334
335    --------------------------
336    -- POSIX.1c  Section 11 --
337    --------------------------
338
339    function pthread_mutexattr_init (attr : access pthread_mutexattr_t)
340      return int;
341    pragma Import (C, pthread_mutexattr_init);
342
343    function pthread_mutexattr_destroy
344      (attr : access pthread_mutexattr_t) return int;
345    pragma Import (C, pthread_mutexattr_destroy);
346
347    function pthread_mutex_init
348      (mutex : access pthread_mutex_t;
349       attr  : access pthread_mutexattr_t) return int;
350    pragma Import (C, pthread_mutex_init, "__pthread_mutex_init");
351
352    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
353    pragma Import (C, pthread_mutex_destroy, "__pthread_mutex_destroy");
354
355    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
356    pragma Import (C, pthread_mutex_lock, "__pthread_mutex_lock");
357
358    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
359    pragma Import (C, pthread_mutex_unlock, "__pthread_mutex_unlock");
360
361    function pthread_condattr_init
362      (attr : access pthread_condattr_t) return int;
363    pragma Import (C, pthread_condattr_init);
364
365    function pthread_condattr_destroy
366      (attr : access pthread_condattr_t) return int;
367    pragma Import (C, pthread_condattr_destroy);
368
369    function pthread_cond_init
370      (cond : access pthread_cond_t;
371       attr : access pthread_condattr_t) return int;
372    pragma Import (C, pthread_cond_init, "__pthread_cond_init");
373
374    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
375    pragma Import (C, pthread_cond_destroy, "__pthread_cond_destroy");
376
377    function pthread_cond_signal (cond : access pthread_cond_t) return int;
378    pragma Import (C, pthread_cond_signal, "__pthread_cond_signal");
379
380    function pthread_cond_wait
381      (cond  : access pthread_cond_t;
382       mutex : access pthread_mutex_t) return  int;
383    pragma Import (C, pthread_cond_wait, "__pthread_cond_wait");
384
385    function pthread_cond_timedwait
386      (cond    : access pthread_cond_t;
387       mutex   : access pthread_mutex_t;
388       abstime : access timespec) return int;
389    pragma Import (C, pthread_cond_timedwait, "__pthread_cond_timedwait");
390
391    --------------------------
392    -- POSIX.1c  Section 13 --
393    --------------------------
394
395    function pthread_mutexattr_setprotocol
396      (attr     : access pthread_mutexattr_t;
397       protocol : int) return int;
398    pragma Import (C, pthread_mutexattr_setprotocol);
399
400    function pthread_mutexattr_setprioceiling
401      (attr     : access pthread_mutexattr_t;
402       prioceiling : int) return int;
403    pragma Import (C, pthread_mutexattr_setprioceiling);
404
405    type struct_sched_param is record
406       sched_priority : int;  --  scheduling priority
407    end record;
408
409    function pthread_setschedparam
410      (thread : pthread_t;
411       policy : int;
412       param  : access struct_sched_param) return int;
413    pragma Import (C, pthread_setschedparam);
414
415    function pthread_attr_setscope
416      (attr            : access pthread_attr_t;
417       contentionscope : int) return int;
418    pragma Import (C, pthread_attr_setscope);
419
420    function pthread_attr_setinheritsched
421      (attr            : access pthread_attr_t;
422       inheritsched    : int) return int;
423    pragma Import (C, pthread_attr_setinheritsched,
424      "__pthread_attr_setinheritsched");
425
426    function pthread_attr_setschedpolicy
427      (attr : access pthread_attr_t; policy : int) return int;
428    pragma Import (C, pthread_attr_setschedpolicy);
429
430    function pthread_attr_setschedparam
431      (attr        : access pthread_attr_t;
432       sched_param : access struct_sched_param) return int;
433    pragma Import (C, pthread_attr_setschedparam);
434
435    function sched_yield return int;
436    pragma Import (C, sched_yield);
437
438    --------------------------
439    -- P1003.1c  Section 16 --
440    --------------------------
441
442    function pthread_attr_init (attributes : access pthread_attr_t)
443      return int;
444    pragma Import (C, pthread_attr_init);
445
446    function pthread_attr_destroy (attributes : access pthread_attr_t)
447      return int;
448    pragma Import (C, pthread_attr_destroy);
449
450    function pthread_attr_setdetachstate
451      (attr        : access pthread_attr_t;
452       detachstate : int) return int;
453    pragma Import (C, pthread_attr_setdetachstate);
454
455    function pthread_attr_setstacksize
456      (attr      : access pthread_attr_t;
457       stacksize : size_t) return int;
458    pragma Import (C, pthread_attr_setstacksize, "__pthread_attr_setstacksize");
459
460    function pthread_create
461      (thread        : access pthread_t;
462       attributes    : access pthread_attr_t;
463       start_routine : Thread_Body;
464       arg           : System.Address) return int;
465    pragma Import (C, pthread_create, "__pthread_create");
466
467    procedure pthread_exit (status : System.Address);
468    pragma Import (C, pthread_exit, "__pthread_exit");
469
470    function pthread_self return pthread_t;
471    pragma Inline (pthread_self);
472
473    --------------------------
474    -- POSIX.1c  Section 17 --
475    --------------------------
476
477    function pthread_setspecific
478      (key : pthread_key_t; value : System.Address) return int;
479    pragma Import (C, pthread_setspecific, "__pthread_setspecific");
480
481    function pthread_getspecific (key : pthread_key_t) return System.Address;
482    pragma Import (C, pthread_getspecific, "__pthread_getspecific");
483
484    type destructor_pointer is access procedure (arg : System.Address);
485
486    function pthread_key_create
487      (key        : access pthread_key_t;
488       destructor : destructor_pointer) return int;
489    pragma Import (C, pthread_key_create);
490
491 private
492
493    type sigset_t is new unsigned_long;
494
495    type pid_t is new int;
496
497    type time_t is new int;
498
499    type timespec is record
500       tv_sec  : time_t;
501       tv_nsec : long;
502    end record;
503    pragma Convention (C, timespec);
504
505    type clockid_t is new int;
506    CLOCK_REALTIME : constant clockid_t := 1;
507
508    type unsigned_long_array is array (Natural range <>) of unsigned_long;
509
510    type pthread_t is new System.Address;
511
512    type pthread_teb_t is record
513       reserved1     : System.Address;
514       reserved2     : System.Address;
515       size          : unsigned_short;
516       version       : unsigned_char;
517       reserved3     : unsigned_char;
518       external      : unsigned_char;
519       reserved4     : char_array (0 .. 1);
520       creator       : unsigned_char;
521       sequence      : unsigned_long;
522       reserved5     : unsigned_long_array (0 .. 1);
523       per_kt_area   : System.Address;
524       stack_base    : System.Address;
525       stack_reserve : System.Address;
526       stack_yellow  : System.Address;
527       stack_guard   : System.Address;
528       stack_size    : unsigned_long;
529       tsd_values    : System.Address;
530       tsd_count     : unsigned_long;
531       reserved6     : unsigned;
532       reserved7     : unsigned;
533       thread_flags  : unsigned;
534       thd_errno     : int;
535       stack_hiwater : System.Address;
536       home_rad      : unsigned_long;
537    end record;
538    pragma Convention (C, pthread_teb_t);
539
540    type pthread_cond_t is record
541       state     : unsigned;
542       valid     : unsigned;
543       name      : System.Address;
544       arg       : unsigned;
545       reserved1 : unsigned;
546       sequence  : unsigned_long;
547       block     : System.Address;
548    end record;
549    pragma Convention (C, pthread_cond_t);
550
551    type pthread_attr_t is record
552       valid    : long;
553       name     : System.Address;
554       arg      : unsigned_long;
555       reserved : unsigned_long_array (0 .. 18);
556    end record;
557    pragma Convention (C, pthread_attr_t);
558
559    type pthread_mutex_t is record
560       lock     : unsigned;
561       valid    : unsigned;
562       name     : System.Address;
563       arg      : unsigned;
564       depth    : unsigned;
565       sequence : unsigned_long;
566       owner    : unsigned_long;
567       block    : System.Address;
568    end record;
569    for pthread_mutex_t'Size use 8 * 48;
570    pragma Convention (C, pthread_mutex_t);
571
572    type pthread_mutexattr_t is record
573       valid    : long;
574       reserved : unsigned_long_array (0 .. 14);
575    end record;
576    pragma Convention (C, pthread_mutexattr_t);
577
578    type pthread_condattr_t is record
579       valid    : long;
580       reserved : unsigned_long_array (0 .. 12);
581    end record;
582    pragma Convention (C, pthread_condattr_t);
583
584    type pthread_key_t is new unsigned;
585
586 end System.OS_Interface;