OSDN Git Service

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