re PR rtl-optimization/34522 (inefficient code for long long multiply when only low...
[official-gcc.git] / gcc / ada / s-osinte-lynxos-3.ads
blobeb775d2fcbd3c8484effa0aa26dfad29e2e8dbb6
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 ------------------------------------------------------------------------------
35 -- This is a LynxOS (Native) version of this package
37 -- This package encapsulates all direct interfaces to OS services
38 -- that are needed by children of System.
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.
43 with Interfaces.C;
44 with Ada.Unchecked_Conversion;
46 package System.OS_Interface is
47 pragma Preelaborate;
49 pragma Linker_Options ("-mthreads");
51 subtype int is Interfaces.C.int;
52 subtype char is Interfaces.C.char;
53 subtype short is Interfaces.C.short;
54 subtype long is Interfaces.C.long;
55 subtype unsigned is Interfaces.C.unsigned;
56 subtype unsigned_short is Interfaces.C.unsigned_short;
57 subtype unsigned_long is Interfaces.C.unsigned_long;
58 subtype unsigned_char is Interfaces.C.unsigned_char;
59 subtype plain_char is Interfaces.C.plain_char;
60 subtype size_t is Interfaces.C.size_t;
62 -----------
63 -- Errno --
64 -----------
66 function errno return int;
67 pragma Import (C, errno, "__get_errno");
69 EAGAIN : constant := 11;
70 EINTR : constant := 4;
71 EINVAL : constant := 22;
72 ENOMEM : constant := 12;
73 ETIMEDOUT : constant := 60;
75 -------------
76 -- Signals --
77 -------------
79 Max_Interrupt : constant := 63;
80 type Signal is new int range 0 .. Max_Interrupt;
81 for Signal'Size use int'Size;
83 SIGHUP : constant := 1; -- hangup
84 SIGINT : constant := 2; -- interrupt (rubout)
85 SIGQUIT : constant := 3; -- quit (ASCD FS)
86 SIGILL : constant := 4; -- illegal instruction (not reset)
87 SIGTRAP : constant := 5; -- trace trap (not reset)
88 SIGBRK : constant := 6; -- break
89 SIGIOT : constant := 6; -- IOT instruction
90 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
91 SIGCORE : constant := 7; -- kill with core dump
92 SIGEMT : constant := 7; -- EMT instruction
93 SIGFPE : constant := 8; -- floating point exception
94 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
95 SIGBUS : constant := 10; -- bus error
96 SIGSEGV : constant := 11; -- segmentation violation
97 SIGSYS : constant := 12; -- bad argument to system call
98 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
99 SIGALRM : constant := 14; -- alarm clock
100 SIGTERM : constant := 15; -- software termination signal from kill
101 SIGURG : constant := 16; -- urgent condition on IO channel
102 SIGSTOP : constant := 17; -- stop (cannot be caught or ignored)
103 SIGTSTP : constant := 18; -- user stop requested from tty
104 SIGCONT : constant := 19; -- stopped process has been continued
105 SIGCLD : constant := 20; -- alias for SIGCHLD
106 SIGCHLD : constant := 20; -- child status change
107 SIGTTIN : constant := 21; -- background tty read attempted
108 SIGTTOU : constant := 22; -- background tty write attempted
109 SIGIO : constant := 23; -- I/O possible (Solaris SIGPOLL alias)
110 SIGPOLL : constant := 23; -- pollable event occurred
111 SIGXCPU : constant := 24; -- CPU time limit exceeded
112 SIGXFSZ : constant := 25; -- filesize limit exceeded
113 SIGVTALRM : constant := 26; -- virtual timer expired
114 SIGPROF : constant := 27; -- profiling timer expired
115 SIGWINCH : constant := 28; -- window size change
116 SIGLOST : constant := 29; -- SUN 4.1 compatibility
117 SIGUSR1 : constant := 30; -- user defined signal 1
118 SIGUSR2 : constant := 31; -- user defined signal 2
119 SIGPRIO : constant := 32; -- sent to a process with its priority or
120 -- group is changed
122 SIGADAABORT : constant := SIGABRT;
123 -- Change this if you want to use another signal for task abort.
124 -- SIGTERM might be a good one.
126 type Signal_Set is array (Natural range <>) of Signal;
128 Unmasked : constant Signal_Set :=
129 (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
130 Reserved : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP, SIGPRIO);
132 type sigset_t is private;
134 function sigaddset (set : access sigset_t; sig : Signal) return int;
135 pragma Import (C, sigaddset, "sigaddset");
137 function sigdelset (set : access sigset_t; sig : Signal) return int;
138 pragma Import (C, sigdelset, "sigdelset");
140 function sigfillset (set : access sigset_t) return int;
141 pragma Import (C, sigfillset, "sigfillset");
143 function sigismember (set : access sigset_t; sig : Signal) return int;
144 pragma Import (C, sigismember, "sigismember");
146 function sigemptyset (set : access sigset_t) return int;
147 pragma Import (C, sigemptyset, "sigemptyset");
149 type struct_sigaction is record
150 sa_handler : System.Address;
151 sa_mask : sigset_t;
152 sa_flags : int;
153 end record;
154 pragma Convention (C, struct_sigaction);
155 type struct_sigaction_ptr is access all struct_sigaction;
157 SA_SIGINFO : constant := 16#80#;
159 SIG_BLOCK : constant := 0;
160 SIG_UNBLOCK : constant := 1;
161 SIG_SETMASK : constant := 2;
163 SIG_DFL : constant := 0;
164 SIG_IGN : constant := 1;
166 function sigaction
167 (sig : Signal;
168 act : struct_sigaction_ptr;
169 oact : struct_sigaction_ptr) return int;
170 pragma Import (C, sigaction, "sigaction");
172 ----------
173 -- Time --
174 ----------
176 Time_Slice_Supported : constant Boolean := True;
177 -- Indicates wether time slicing is supported
179 type timespec is private;
181 type clockid_t is private;
183 CLOCK_REALTIME : constant clockid_t;
185 function clock_gettime
186 (clock_id : clockid_t;
187 tp : access timespec) return int;
188 pragma Inline (clock_gettime);
189 -- LynxOS has non standard clock_gettime
191 function To_Duration (TS : timespec) return Duration;
192 pragma Inline (To_Duration);
194 function To_Timespec (D : Duration) return timespec;
195 pragma Inline (To_Timespec);
197 type struct_timezone is record
198 tz_minuteswest : int;
199 tz_dsttime : int;
200 end record;
201 pragma Convention (C, struct_timezone);
202 type struct_timezone_ptr is access all struct_timezone;
204 -------------------------
205 -- Priority Scheduling --
206 -------------------------
208 SCHED_FIFO : constant := 16#00200000#;
209 SCHED_RR : constant := 16#00100000#;
210 SCHED_OTHER : constant := 16#00400000#;
212 function To_Target_Priority
213 (Prio : System.Any_Priority) return Interfaces.C.int;
214 -- Maps System.Any_Priority to a POSIX priority
216 -------------
217 -- Process --
218 -------------
220 type pid_t is private;
222 function kill (pid : pid_t; sig : Signal) return int;
223 pragma Import (C, kill, "kill");
225 function getpid return pid_t;
226 pragma Import (C, getpid, "getpid");
228 ---------
229 -- LWP --
230 ---------
232 function lwp_self return System.Address;
233 -- lwp_self does not exist on this thread library, revert to pthread_self
234 -- which is the closest approximation (with getpid). This function is
235 -- needed to share 7staprop.adb across POSIX-like targets.
236 pragma Import (C, lwp_self, "pthread_self");
238 -------------
239 -- Threads --
240 -------------
242 type Thread_Body is access
243 function (arg : System.Address) return System.Address;
244 pragma Convention (C, Thread_Body);
246 function Thread_Body_Access is new
247 Ada.Unchecked_Conversion (System.Address, Thread_Body);
249 type pthread_t is private;
250 subtype Thread_Id is pthread_t;
252 type pthread_mutex_t is limited private;
253 type pthread_cond_t is limited private;
254 type st_t is limited private;
255 type pthread_attr_t is limited private;
256 type pthread_mutexattr_t is limited private;
257 type pthread_condattr_t is limited private;
258 type pthread_key_t is private;
260 PTHREAD_CREATE_DETACHED : constant := 0;
262 PTHREAD_SCOPE_PROCESS : constant := 0;
263 PTHREAD_SCOPE_SYSTEM : constant := 1;
265 -----------
266 -- Stack --
267 -----------
269 Stack_Base_Available : constant Boolean := False;
270 -- Indicates wether the stack base is available on this target
272 function Get_Stack_Base (thread : pthread_t) return Address;
273 pragma Inline (Get_Stack_Base);
274 -- returns the stack base of the specified thread.
275 -- Only call this function when Stack_Base_Available is True.
277 function Get_Page_Size return size_t;
278 function Get_Page_Size return Address;
279 pragma Import (C, Get_Page_Size, "getpagesize");
280 -- returns the size of a page, or 0 if this is not relevant on this
281 -- target
283 PROT_NONE : constant := 0;
284 PROT_READ : constant := 1;
285 PROT_WRITE : constant := 2;
286 PROT_EXEC : constant := 4;
287 PROT_USER : constant := 8;
288 PROT_ALL : constant := PROT_READ + PROT_WRITE + PROT_EXEC + PROT_USER;
290 PROT_ON : constant := PROT_READ;
291 PROT_OFF : constant := PROT_ALL;
293 function mprotect (addr : Address; len : size_t; prot : int) return int;
294 pragma Import (C, mprotect);
296 -------------------------
297 -- POSIX.1c Section 3 --
298 -------------------------
300 function sigwait
301 (set : access sigset_t;
302 sig : access Signal) return int;
303 pragma Inline (sigwait);
304 -- LynxOS has non standard sigwait
306 function pthread_kill (thread : pthread_t; sig : Signal) return int;
307 pragma Import (C, pthread_kill, "pthread_kill");
309 function pthread_sigmask
310 (how : int;
311 set : access sigset_t;
312 oset : access sigset_t) return int;
313 pragma Import (C, pthread_sigmask, "sigprocmask");
315 --------------------------
316 -- POSIX.1c Section 11 --
317 --------------------------
319 function pthread_mutexattr_init
320 (attr : access pthread_mutexattr_t) return int;
321 pragma Inline (pthread_mutexattr_init);
322 -- LynxOS has a nonstandard pthread_mutexattr_init
324 function pthread_mutexattr_destroy
325 (attr : access pthread_mutexattr_t) return int;
326 pragma Inline (pthread_mutexattr_destroy);
327 -- Lynxos has a nonstandard pthread_mutexattr_destroy
329 function pthread_mutex_init
330 (mutex : access pthread_mutex_t;
331 attr : access pthread_mutexattr_t) return int;
332 pragma Inline (pthread_mutex_init);
333 -- LynxOS has a nonstandard pthread_mutex_init
335 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
336 pragma Inline (pthread_mutex_destroy);
337 -- LynxOS has a nonstandard pthread_mutex_destroy
339 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
340 pragma Inline (pthread_mutex_lock);
341 -- LynxOS has a nonstandard pthread_mutex_lock
343 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
344 pragma Inline (pthread_mutex_unlock);
345 -- LynxOS has a nonstandard pthread_mutex_unlock
347 function pthread_condattr_init
348 (attr : access pthread_condattr_t) return int;
349 pragma Inline (pthread_condattr_init);
350 -- LynxOS has a nonstandard pthread_condattr_init
352 function pthread_condattr_destroy
353 (attr : access pthread_condattr_t) return int;
354 pragma Inline (pthread_condattr_destroy);
355 -- LynxOS has a nonstandard pthread_condattr_destroy
357 function pthread_cond_init
358 (cond : access pthread_cond_t;
359 attr : access pthread_condattr_t) return int;
360 pragma Inline (pthread_cond_init);
361 -- LynxOS has a non standard pthread_cond_init
363 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
364 pragma Inline (pthread_cond_destroy);
365 -- LynxOS has a nonstandard pthread_cond_destroy
367 function pthread_cond_signal (cond : access pthread_cond_t) return int;
368 pragma Inline (pthread_cond_signal);
369 -- LynxOS has a nonstandard pthread_cond_signal
371 function pthread_cond_wait
372 (cond : access pthread_cond_t;
373 mutex : access pthread_mutex_t) return int;
374 pragma Inline (pthread_cond_wait);
375 -- LynxOS has a nonstandard pthread_cond_wait
377 function pthread_cond_timedwait
378 (cond : access pthread_cond_t;
379 mutex : access pthread_mutex_t;
380 reltime : access timespec) return int;
381 pragma Inline (pthread_cond_timedwait);
382 -- LynxOS has a nonstandard pthrad_cond_timedwait
384 Relative_Timed_Wait : constant Boolean := True;
385 -- pthread_cond_timedwait requires a relative delay time
387 --------------------------
388 -- POSIX.1c Section 13 --
389 --------------------------
391 PTHREAD_PRIO_NONE : constant := 0;
392 PTHREAD_PRIO_INHERIT : constant := 0;
393 PTHREAD_PRIO_PROTECT : constant := 0;
395 type struct_sched_param is record
396 sched_priority : int; -- scheduling priority
397 end record;
399 function pthread_setschedparam
400 (thread : pthread_t;
401 policy : int;
402 param : access struct_sched_param) return int;
403 pragma Inline (pthread_setschedparam);
404 -- LynxOS doesn't have pthread_setschedparam.
405 -- Instead, use pthread_setscheduler
407 function pthread_mutexattr_setprotocol
408 (attr : access pthread_mutexattr_t;
409 protocol : int) return int;
410 pragma Inline (pthread_mutexattr_setprotocol);
411 -- LynxOS doesn't have pthread_mutexattr_setprotocol
413 function pthread_mutexattr_setprioceiling
414 (attr : access pthread_mutexattr_t;
415 prioceiling : int) return int;
416 pragma Inline (pthread_mutexattr_setprioceiling);
417 -- LynxOS doesn't have pthread_mutexattr_setprioceiling
419 function pthread_attr_setscope
420 (attr : access pthread_attr_t;
421 contentionscope : int) return int;
422 -- LynxOS doesn't have pthread_attr_setscope: all threads have system scope
423 pragma Inline (pthread_attr_setscope);
425 function pthread_attr_setschedpolicy
426 (attr : access pthread_attr_t;
427 policy : int) return int;
428 pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
430 function sched_yield return int;
431 -- pragma Import (C, sched_yield, "sched_yield");
432 pragma Inline (sched_yield);
434 ---------------------------
435 -- P1003.1c - Section 16 --
436 ---------------------------
438 function pthread_attr_init (attributes : access pthread_attr_t) return int;
439 pragma Import (C, pthread_attr_init, "pthread_attr_create");
441 function pthread_attr_destroy
442 (attributes : access pthread_attr_t) return int;
443 pragma Import (C, pthread_attr_destroy, "pthread_attr_delete");
445 function pthread_attr_setdetachstate
446 (attr : access pthread_attr_t;
447 detachstate : int) return int;
448 pragma Inline (pthread_attr_setdetachstate);
449 -- LynxOS doesn't have pthread_attr_setdetachstate
451 function pthread_attr_setstacksize
452 (attr : access pthread_attr_t;
453 stacksize : size_t) return int;
454 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
456 function pthread_create
457 (thread : access pthread_t;
458 attributes : access pthread_attr_t;
459 start_routine : Thread_Body;
460 arg : System.Address) return int;
461 pragma Inline (pthread_create);
462 -- LynxOS has a non standard pthread_create
464 function pthread_detach (thread : pthread_t) return int;
465 pragma Inline (pthread_detach);
467 procedure pthread_exit (status : System.Address);
468 pragma Import (C, pthread_exit, "pthread_exit");
470 function pthread_self return pthread_t;
471 pragma Import (C, pthread_self, "pthread_self");
473 --------------------------
474 -- POSIX.1c Section 17 --
475 --------------------------
477 function pthread_setspecific
478 (key : pthread_key_t;
479 value : System.Address) return int;
480 pragma Inline (pthread_setspecific);
481 -- LynxOS has a non standard pthread_setspecific
483 function pthread_getspecific (key : pthread_key_t) return System.Address;
484 pragma Inline (pthread_getspecific);
485 -- LynxOS has a non standard pthread_getspecific
487 type destructor_pointer is access procedure (arg : System.Address);
488 pragma Convention (C, destructor_pointer);
490 function pthread_key_create
491 (key : access pthread_key_t;
492 destructor : destructor_pointer) return int;
493 pragma Inline (pthread_key_create);
494 -- LynxOS has a non standard pthread_keycreate
496 procedure pthread_init;
497 -- This is a dummy procedure to share some GNULLI files
499 private
501 type sigbit_array is array (1 .. 2) of long;
502 type sigset_t is record
503 sa_sigbits : sigbit_array;
504 end record;
505 pragma Convention (C_Pass_By_Copy, sigset_t);
507 type pid_t is new long;
509 type time_t is new long;
511 type timespec is record
512 tv_sec : time_t;
513 tv_nsec : long;
514 end record;
515 pragma Convention (C, timespec);
517 type clockid_t is new unsigned_char;
518 CLOCK_REALTIME : constant clockid_t := 0;
520 type st_t is record
521 stksize : int;
522 prio : int;
523 inheritsched : int;
524 state : int;
525 sched : int;
526 end record;
527 pragma Convention (C, st_t);
529 type pthread_attr_t is record
530 st : st_t;
531 pthread_attr_scope : int; -- ignored
532 end record;
533 pragma Convention (C, pthread_attr_t);
535 type pthread_condattr_t is new int;
537 type pthread_mutexattr_t is new int;
539 type tid_t is new short;
540 type pthread_t is new tid_t;
542 type synch_ptr is access all pthread_mutex_t;
543 type pthread_mutex_t is record
544 w_count : int;
545 mut_owner : int;
546 id : unsigned;
547 next : synch_ptr;
548 end record;
549 pragma Convention (C, pthread_mutex_t);
551 type pthread_cond_t is new pthread_mutex_t;
553 type pthread_key_t is new int;
555 end System.OS_Interface;