1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ I N T E R F A C E --
11 -- Copyright (C) 1997-2001 Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This is a Solaris (native) version of this package
39 -- This package includes all direct interfaces to OS services
40 -- that are needed by children of System.
42 -- PLEASE DO NOT add any with-clauses to this package
43 -- or remove the pragma Elaborate_Body.
44 -- It is designed to be a bottom-level (leaf) package.
47 package System
.OS_Interface
is
50 pragma Linker_Options
("-lposix4");
51 pragma Linker_Options
("-lthread");
53 subtype int
is Interfaces
.C
.int
;
54 subtype short
is Interfaces
.C
.short
;
55 subtype long
is Interfaces
.C
.long
;
56 subtype unsigned
is Interfaces
.C
.unsigned
;
57 subtype unsigned_short
is Interfaces
.C
.unsigned_short
;
58 subtype unsigned_long
is Interfaces
.C
.unsigned_long
;
59 subtype unsigned_char
is Interfaces
.C
.unsigned_char
;
60 subtype plain_char
is Interfaces
.C
.plain_char
;
61 subtype size_t
is Interfaces
.C
.size_t
;
67 function errno
return int
;
68 pragma Import
(C
, errno
, "__get_errno");
70 EAGAIN
: constant := 11;
71 EINTR
: constant := 4;
72 EINVAL
: constant := 22;
73 ENOMEM
: constant := 12;
74 ETIME
: constant := 62;
75 ETIMEDOUT
: constant := 145;
81 Max_Interrupt
: constant := 45;
82 type Signal
is new int
range 0 .. Max_Interrupt
;
83 for Signal
'Size use int
'Size;
85 SIGHUP
: constant := 1; -- hangup
86 SIGINT
: constant := 2; -- interrupt (rubout)
87 SIGQUIT
: constant := 3; -- quit (ASCD FS)
88 SIGILL
: constant := 4; -- illegal instruction (not reset)
89 SIGTRAP
: constant := 5; -- trace trap (not reset)
90 SIGIOT
: constant := 6; -- IOT instruction
91 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
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 SIGUSR1
: constant := 16; -- user defined signal 1
102 SIGUSR2
: constant := 17; -- user defined signal 2
103 SIGCLD
: constant := 18; -- alias for SIGCHLD
104 SIGCHLD
: constant := 18; -- child status change
105 SIGPWR
: constant := 19; -- power-fail restart
106 SIGWINCH
: constant := 20; -- window size change
107 SIGURG
: constant := 21; -- urgent condition on IO channel
108 SIGPOLL
: constant := 22; -- pollable event occurred
109 SIGIO
: constant := 22; -- I/O possible (Solaris SIGPOLL alias)
110 SIGSTOP
: constant := 23; -- stop (cannot be caught or ignored)
111 SIGTSTP
: constant := 24; -- user stop requested from tty
112 SIGCONT
: constant := 25; -- stopped process has been continued
113 SIGTTIN
: constant := 26; -- background tty read attempted
114 SIGTTOU
: constant := 27; -- background tty write attempted
115 SIGVTALRM
: constant := 28; -- virtual timer expired
116 SIGPROF
: constant := 29; -- profiling timer expired
117 SIGXCPU
: constant := 30; -- CPU time limit exceeded
118 SIGXFSZ
: constant := 31; -- filesize limit exceeded
119 SIGWAITING
: constant := 32; -- process's lwps blocked (Solaris)
120 SIGLWP
: constant := 33; -- used by thread library (Solaris)
121 SIGFREEZE
: constant := 34; -- used by CPR (Solaris)
122 SIGTHAW
: constant := 35; -- used by CPR (Solaris)
123 SIGCANCEL
: constant := 36; -- thread cancellation signal (libthread)
125 type Signal_Set
is array (Natural range <>) of Signal
;
127 Unmasked
: constant Signal_Set
:= (SIGTRAP
, SIGLWP
, SIGPROF
);
129 -- Following signals should not be disturbed.
130 -- See c-posix-signals.c in FLORIST
132 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
, SIGWAITING
, SIGCANCEL
);
134 type sigset_t
is private;
136 function sigaddset
(set
: access sigset_t
; sig
: Signal
) return int
;
137 pragma Import
(C
, sigaddset
, "sigaddset");
139 function sigdelset
(set
: access sigset_t
; sig
: Signal
) return int
;
140 pragma Import
(C
, sigdelset
, "sigdelset");
142 function sigfillset
(set
: access sigset_t
) return int
;
143 pragma Import
(C
, sigfillset
, "sigfillset");
145 function sigismember
(set
: access sigset_t
; sig
: Signal
) return int
;
146 pragma Import
(C
, sigismember
, "sigismember");
148 function sigemptyset
(set
: access sigset_t
) return int
;
149 pragma Import
(C
, sigemptyset
, "sigemptyset");
151 type union_type_3
is new String (1 .. 116);
152 type siginfo_t
is record
156 X_data
: union_type_3
;
158 pragma Convention
(C
, siginfo_t
);
160 -- The types mcontext_t and gregset_t are part of the ucontext_t
161 -- information, which is specific to Solaris2.4 for SPARC
162 -- The ucontext_t info seems to be used by the handler
163 -- for SIGSEGV to decide whether it is a Storage_Error (stack overflow) or
164 -- a Constraint_Error (bad pointer). The original code that did this
165 -- is suspect, so it is not clear whether we really need this part of
166 -- the signal context information, or perhaps something else.
167 -- More analysis is needed, after which these declarations may need to
170 FPE_INTDIV
: constant := 1; -- integer divide by zero
171 FPE_INTOVF
: constant := 2; -- integer overflow
172 FPE_FLTDIV
: constant := 3; -- floating point divide by zero
173 FPE_FLTOVF
: constant := 4; -- floating point overflow
174 FPE_FLTUND
: constant := 5; -- floating point underflow
175 FPE_FLTRES
: constant := 6; -- floating point inexact result
176 FPE_FLTINV
: constant := 7; -- invalid floating point operation
177 FPE_FLTSUB
: constant := 8; -- subscript out of range
179 type greg_t
is new int
;
181 type gregset_t
is array (0 .. 18) of greg_t
;
183 type union_type_2
is new String (1 .. 128);
184 type record_type_1
is record
185 fpu_fr
: union_type_2
;
186 fpu_q
: System
.Address
;
188 fpu_qcnt
: unsigned_char
;
189 fpu_q_entrysize
: unsigned_char
;
190 fpu_en
: unsigned_char
;
192 pragma Convention
(C
, record_type_1
);
194 type array_type_7
is array (Integer range 0 .. 20) of long
;
195 type mcontext_t
is record
197 gwins
: System
.Address
;
198 fpregs
: record_type_1
;
199 filler
: array_type_7
;
201 pragma Convention
(C
, mcontext_t
);
203 type record_type_2
is record
204 ss_sp
: System
.Address
;
208 pragma Convention
(C
, record_type_2
);
210 type array_type_8
is array (Integer range 0 .. 22) of long
;
211 type ucontext_t
is record
212 uc_flags
: unsigned_long
;
213 uc_link
: System
.Address
;
214 uc_sigmask
: sigset_t
;
215 uc_stack
: record_type_2
;
216 uc_mcontext
: mcontext_t
;
217 uc_filler
: array_type_8
;
219 pragma Convention
(C
, ucontext_t
);
221 type Signal_Handler
is access procedure
223 info
: access siginfo_t
;
224 context
: access ucontext_t
);
226 type union_type_1
is new plain_char
;
227 type array_type_2
is array (Integer range 0 .. 1) of int
;
228 type struct_sigaction
is record
230 sa_handler
: System
.Address
;
232 sa_resv
: array_type_2
;
234 pragma Convention
(C
, struct_sigaction
);
235 type struct_sigaction_ptr
is access all struct_sigaction
;
237 SIG_BLOCK
: constant := 1;
238 SIG_UNBLOCK
: constant := 2;
239 SIG_SETMASK
: constant := 3;
241 SIG_DFL
: constant := 0;
242 SIG_IGN
: constant := 1;
246 act
: struct_sigaction_ptr
;
247 oact
: struct_sigaction_ptr
) return int
;
248 pragma Import
(C
, sigaction
, "sigaction");
254 type timespec
is private;
256 type clockid_t
is private;
258 CLOCK_REALTIME
: constant clockid_t
;
260 function clock_gettime
261 (clock_id
: clockid_t
; tp
: access timespec
) return int
;
262 pragma Import
(C
, clock_gettime
, "clock_gettime");
264 function To_Duration
(TS
: timespec
) return Duration;
265 pragma Inline
(To_Duration
);
267 function To_Timespec
(D
: Duration) return timespec
;
268 pragma Inline
(To_Timespec
);
270 type struct_timeval
is private;
271 -- This is needed on systems that do not have clock_gettime()
272 -- but do have gettimeofday().
274 function To_Duration
(TV
: struct_timeval
) return Duration;
275 pragma Inline
(To_Duration
);
277 function To_Timeval
(D
: Duration) return struct_timeval
;
278 pragma Inline
(To_Timeval
);
284 type pid_t
is private;
286 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
287 pragma Import
(C
, kill
, "kill");
289 function getpid
return pid_t
;
290 pragma Import
(C
, getpid
, "getpid");
296 type Thread_Body
is access
297 function (arg
: System
.Address
) return System
.Address
;
299 THR_DETACHED
: constant := 64;
300 THR_BOUND
: constant := 1;
301 THR_NEW_LWP
: constant := 2;
302 USYNC_THREAD
: constant := 0;
304 type thread_t
is private;
305 subtype Thread_Id
is thread_t
;
307 type mutex_t
is limited private;
309 type cond_t
is limited private;
311 type thread_key_t
is private;
314 (stack_base
: System
.Address
;
316 start_routine
: Thread_Body
;
317 arg
: System
.Address
;
319 new_thread
: access thread_t
) return int
;
320 pragma Import
(C
, thr_create
, "thr_create");
322 function thr_min_stack
return size_t
;
323 pragma Import
(C
, thr_min_stack
, "thr_min_stack");
325 function thr_self
return thread_t
;
326 pragma Import
(C
, thr_self
, "thr_self");
329 (mutex
: access mutex_t
;
331 arg
: System
.Address
) return int
;
332 pragma Import
(C
, mutex_init
, "mutex_init");
334 function mutex_destroy
(mutex
: access mutex_t
) return int
;
335 pragma Import
(C
, mutex_destroy
, "mutex_destroy");
337 function mutex_lock
(mutex
: access mutex_t
) return int
;
338 pragma Import
(C
, mutex_lock
, "mutex_lock");
340 function mutex_unlock
(mutex
: access mutex_t
) return int
;
341 pragma Import
(C
, mutex_unlock
, "mutex_unlock");
344 (cond
: access cond_t
;
346 arg
: int
) return int
;
347 pragma Import
(C
, cond_init
, "cond_init");
350 (cond
: access cond_t
; mutex
: access mutex_t
) return int
;
351 pragma Import
(C
, cond_wait
, "cond_wait");
353 function cond_timedwait
354 (cond
: access cond_t
;
355 mutex
: access mutex_t
;
356 abstime
: access timespec
) return int
;
357 pragma Import
(C
, cond_timedwait
, "cond_timedwait");
359 function cond_signal
(cond
: access cond_t
) return int
;
360 pragma Import
(C
, cond_signal
, "cond_signal");
362 function cond_destroy
(cond
: access cond_t
) return int
;
363 pragma Import
(C
, cond_destroy
, "cond_destroy");
365 function thr_setspecific
366 (key
: thread_key_t
; value
: System
.Address
) return int
;
367 pragma Import
(C
, thr_setspecific
, "thr_setspecific");
369 function thr_getspecific
371 value
: access System
.Address
) return int
;
372 pragma Import
(C
, thr_getspecific
, "thr_getspecific");
374 function thr_keycreate
375 (key
: access thread_key_t
; destructor
: System
.Address
) return int
;
376 pragma Import
(C
, thr_keycreate
, "thr_keycreate");
378 function thr_setprio
(thread
: thread_t
; priority
: int
) return int
;
379 pragma Import
(C
, thr_setprio
, "thr_setprio");
381 procedure thr_exit
(status
: System
.Address
);
382 pragma Import
(C
, thr_exit
, "thr_exit");
384 function thr_setconcurrency
(new_level
: int
) return int
;
385 pragma Import
(C
, thr_setconcurrency
, "thr_setconcurrency");
387 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
388 pragma Import
(C
, sigwait
, "__posix_sigwait");
390 function thr_kill
(thread
: thread_t
; sig
: Signal
) return int
;
391 pragma Import
(C
, thr_kill
, "thr_kill");
393 type sigset_t_ptr
is access all sigset_t
;
395 function thr_sigsetmask
398 oset
: sigset_t_ptr
) return int
;
399 pragma Import
(C
, thr_sigsetmask
, "thr_sigsetmask");
401 function pthread_sigmask
404 oset
: sigset_t_ptr
) return int
;
405 pragma Import
(C
, pthread_sigmask
, "thr_sigsetmask");
407 function thr_suspend
(target_thread
: thread_t
) return int
;
408 pragma Import
(C
, thr_suspend
, "thr_suspend");
410 function thr_continue
(target_thread
: thread_t
) return int
;
411 pragma Import
(C
, thr_continue
, "thr_continue");
414 pragma Import
(C
, thr_yield
, "thr_yield");
420 P_PID
: constant := 0;
421 P_LWPID
: constant := 8;
423 PC_GETCID
: constant := 0;
424 PC_GETCLINFO
: constant := 1;
425 PC_SETPARMS
: constant := 2;
426 PC_GETPARMS
: constant := 3;
427 PC_ADMIN
: constant := 4;
429 PC_CLNULL
: constant := -1;
431 RT_NOCHANGE
: constant := -1;
432 RT_TQINF
: constant := -2;
433 RT_TQDEF
: constant := -3;
435 PC_CLNMSZ
: constant := 16;
437 PC_VERSION
: constant := 1;
439 type lwpid_t
is new int
;
441 type pri_t
is new short
;
443 type id_t
is new long
;
445 P_MYID
: constant := -1;
446 -- the specified LWP or process is the current one.
448 type struct_pcinfo
is record
450 pc_clname
: String (1 .. PC_CLNMSZ
);
453 pragma Convention
(C
, struct_pcinfo
);
455 type struct_pcparms
is record
461 pragma Convention
(C
, struct_pcparms
);
468 arg
: System
.Address
) return Interfaces
.C
.long
;
469 pragma Import
(C
, priocntl
, "__priocntl");
471 function lwp_self
return lwpid_t
;
472 pragma Import
(C
, lwp_self
, "_lwp_self");
474 type processorid_t
is new int
;
475 type processorid_t_ptr
is access all processorid_t
;
477 -- Constants for function processor_bind
479 PBIND_QUERY
: constant processorid_t
:= -2;
480 -- the processor bindings are not changed.
482 PBIND_NONE
: constant processorid_t
:= -1;
483 -- the processor bindings of the specified LWPs are cleared.
485 -- Flags for function p_online
487 PR_OFFLINE
: constant int
:= 1;
488 -- processor is offline, as quiet as possible
490 PR_ONLINE
: constant int
:= 2;
493 PR_STATUS
: constant int
:= 3;
494 -- value passed to p_online to request status
496 function p_online
(processorid
: processorid_t
; flag
: int
) return int
;
497 pragma Import
(C
, p_online
, "p_online");
499 function processor_bind
502 proc_id
: processorid_t
;
503 obind
: processorid_t_ptr
) return int
;
504 pragma Import
(C
, processor_bind
, "processor_bind");
506 procedure pthread_init
;
507 -- dummy procedure to share s-intman.adb with other Solaris targets.
511 type array_type_1
is array (0 .. 3) of unsigned_long
;
512 type sigset_t
is record
513 X_X_sigbits
: array_type_1
;
515 pragma Convention
(C
, sigset_t
);
517 type pid_t
is new long
;
519 type time_t
is new long
;
521 type timespec
is record
525 pragma Convention
(C
, timespec
);
527 type clockid_t
is new int
;
528 CLOCK_REALTIME
: constant clockid_t
:= 0;
530 type struct_timeval
is record
534 pragma Convention
(C
, struct_timeval
);
536 type thread_t
is new unsigned
;
538 type array_type_9
is array (0 .. 3) of unsigned_char
;
539 type record_type_3
is record
541 Xtype
: unsigned_long
;
543 pragma Convention
(C
, record_type_3
);
545 type mutex_t
is record
546 flags
: record_type_3
;
547 lock
: String (1 .. 8);
548 data
: String (1 .. 8);
550 pragma Convention
(C
, mutex_t
);
552 type cond_t
is record
554 Xtype
: unsigned_long
;
555 data
: String (1 .. 8);
557 pragma Convention
(C
, cond_t
);
559 type thread_key_t
is new unsigned
;
561 end System
.OS_Interface
;