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 --
10 -- Copyright (C) 1997-2001 Free Software Foundation, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
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. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 -- This is a Solaris (native) version of this package
37 -- This package includes 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
41 -- or remove the pragma Elaborate_Body.
42 -- It is designed to be a bottom-level (leaf) package.
45 package System
.OS_Interface
is
48 pragma Linker_Options
("-lposix4");
49 pragma Linker_Options
("-lthread");
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
;
65 function errno
return int
;
66 pragma Import
(C
, errno
, "__get_errno");
68 EAGAIN
: constant := 11;
69 EINTR
: constant := 4;
70 EINVAL
: constant := 22;
71 ENOMEM
: constant := 12;
72 ETIME
: constant := 62;
73 ETIMEDOUT
: constant := 145;
79 Max_Interrupt
: constant := 45;
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 SIGIOT
: constant := 6; -- IOT instruction
89 SIGABRT
: constant := 6; -- used by abort, replace SIGIOT in the future
90 SIGEMT
: constant := 7; -- EMT instruction
91 SIGFPE
: constant := 8; -- floating point exception
92 SIGKILL
: constant := 9; -- kill (cannot be caught or ignored)
93 SIGBUS
: constant := 10; -- bus error
94 SIGSEGV
: constant := 11; -- segmentation violation
95 SIGSYS
: constant := 12; -- bad argument to system call
96 SIGPIPE
: constant := 13; -- write on a pipe with no one to read it
97 SIGALRM
: constant := 14; -- alarm clock
98 SIGTERM
: constant := 15; -- software termination signal from kill
99 SIGUSR1
: constant := 16; -- user defined signal 1
100 SIGUSR2
: constant := 17; -- user defined signal 2
101 SIGCLD
: constant := 18; -- alias for SIGCHLD
102 SIGCHLD
: constant := 18; -- child status change
103 SIGPWR
: constant := 19; -- power-fail restart
104 SIGWINCH
: constant := 20; -- window size change
105 SIGURG
: constant := 21; -- urgent condition on IO channel
106 SIGPOLL
: constant := 22; -- pollable event occurred
107 SIGIO
: constant := 22; -- I/O possible (Solaris SIGPOLL alias)
108 SIGSTOP
: constant := 23; -- stop (cannot be caught or ignored)
109 SIGTSTP
: constant := 24; -- user stop requested from tty
110 SIGCONT
: constant := 25; -- stopped process has been continued
111 SIGTTIN
: constant := 26; -- background tty read attempted
112 SIGTTOU
: constant := 27; -- background tty write attempted
113 SIGVTALRM
: constant := 28; -- virtual timer expired
114 SIGPROF
: constant := 29; -- profiling timer expired
115 SIGXCPU
: constant := 30; -- CPU time limit exceeded
116 SIGXFSZ
: constant := 31; -- filesize limit exceeded
117 SIGWAITING
: constant := 32; -- process's lwps blocked (Solaris)
118 SIGLWP
: constant := 33; -- used by thread library (Solaris)
119 SIGFREEZE
: constant := 34; -- used by CPR (Solaris)
120 SIGTHAW
: constant := 35; -- used by CPR (Solaris)
121 SIGCANCEL
: constant := 36; -- thread cancellation signal (libthread)
123 type Signal_Set
is array (Natural range <>) of Signal
;
125 Unmasked
: constant Signal_Set
:= (SIGTRAP
, SIGLWP
, SIGPROF
);
127 -- Following signals should not be disturbed.
128 -- See c-posix-signals.c in FLORIST
130 Reserved
: constant Signal_Set
:= (SIGKILL
, SIGSTOP
, SIGWAITING
, SIGCANCEL
);
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 union_type_3
is new String (1 .. 116);
150 type siginfo_t
is record
154 X_data
: union_type_3
;
156 pragma Convention
(C
, siginfo_t
);
158 -- The types mcontext_t and gregset_t are part of the ucontext_t
159 -- information, which is specific to Solaris2.4 for SPARC
160 -- The ucontext_t info seems to be used by the handler
161 -- for SIGSEGV to decide whether it is a Storage_Error (stack overflow) or
162 -- a Constraint_Error (bad pointer). The original code that did this
163 -- is suspect, so it is not clear whether we really need this part of
164 -- the signal context information, or perhaps something else.
165 -- More analysis is needed, after which these declarations may need to
168 FPE_INTDIV
: constant := 1; -- integer divide by zero
169 FPE_INTOVF
: constant := 2; -- integer overflow
170 FPE_FLTDIV
: constant := 3; -- floating point divide by zero
171 FPE_FLTOVF
: constant := 4; -- floating point overflow
172 FPE_FLTUND
: constant := 5; -- floating point underflow
173 FPE_FLTRES
: constant := 6; -- floating point inexact result
174 FPE_FLTINV
: constant := 7; -- invalid floating point operation
175 FPE_FLTSUB
: constant := 8; -- subscript out of range
177 type greg_t
is new int
;
179 type gregset_t
is array (0 .. 18) of greg_t
;
181 type union_type_2
is new String (1 .. 128);
182 type record_type_1
is record
183 fpu_fr
: union_type_2
;
184 fpu_q
: System
.Address
;
186 fpu_qcnt
: unsigned_char
;
187 fpu_q_entrysize
: unsigned_char
;
188 fpu_en
: unsigned_char
;
190 pragma Convention
(C
, record_type_1
);
192 type array_type_7
is array (Integer range 0 .. 20) of long
;
193 type mcontext_t
is record
195 gwins
: System
.Address
;
196 fpregs
: record_type_1
;
197 filler
: array_type_7
;
199 pragma Convention
(C
, mcontext_t
);
201 type record_type_2
is record
202 ss_sp
: System
.Address
;
206 pragma Convention
(C
, record_type_2
);
208 type array_type_8
is array (Integer range 0 .. 22) of long
;
209 type ucontext_t
is record
210 uc_flags
: unsigned_long
;
211 uc_link
: System
.Address
;
212 uc_sigmask
: sigset_t
;
213 uc_stack
: record_type_2
;
214 uc_mcontext
: mcontext_t
;
215 uc_filler
: array_type_8
;
217 pragma Convention
(C
, ucontext_t
);
219 type Signal_Handler
is access procedure
221 info
: access siginfo_t
;
222 context
: access ucontext_t
);
224 type union_type_1
is new plain_char
;
225 type array_type_2
is array (Integer range 0 .. 1) of int
;
226 type struct_sigaction
is record
228 sa_handler
: System
.Address
;
230 sa_resv
: array_type_2
;
232 pragma Convention
(C
, struct_sigaction
);
233 type struct_sigaction_ptr
is access all struct_sigaction
;
235 SIG_BLOCK
: constant := 1;
236 SIG_UNBLOCK
: constant := 2;
237 SIG_SETMASK
: constant := 3;
239 SIG_DFL
: constant := 0;
240 SIG_IGN
: constant := 1;
244 act
: struct_sigaction_ptr
;
245 oact
: struct_sigaction_ptr
) return int
;
246 pragma Import
(C
, sigaction
, "sigaction");
252 type timespec
is private;
254 type clockid_t
is private;
256 CLOCK_REALTIME
: constant clockid_t
;
258 function clock_gettime
259 (clock_id
: clockid_t
; tp
: access timespec
) return int
;
260 pragma Import
(C
, clock_gettime
, "clock_gettime");
262 function To_Duration
(TS
: timespec
) return Duration;
263 pragma Inline
(To_Duration
);
265 function To_Timespec
(D
: Duration) return timespec
;
266 pragma Inline
(To_Timespec
);
268 type struct_timeval
is private;
269 -- This is needed on systems that do not have clock_gettime()
270 -- but do have gettimeofday().
272 function To_Duration
(TV
: struct_timeval
) return Duration;
273 pragma Inline
(To_Duration
);
275 function To_Timeval
(D
: Duration) return struct_timeval
;
276 pragma Inline
(To_Timeval
);
282 type pid_t
is private;
284 function kill
(pid
: pid_t
; sig
: Signal
) return int
;
285 pragma Import
(C
, kill
, "kill");
287 function getpid
return pid_t
;
288 pragma Import
(C
, getpid
, "getpid");
294 type Thread_Body
is access
295 function (arg
: System
.Address
) return System
.Address
;
297 THR_DETACHED
: constant := 64;
298 THR_BOUND
: constant := 1;
299 THR_NEW_LWP
: constant := 2;
300 USYNC_THREAD
: constant := 0;
302 type thread_t
is private;
303 subtype Thread_Id
is thread_t
;
305 type mutex_t
is limited private;
307 type cond_t
is limited private;
309 type thread_key_t
is private;
312 (stack_base
: System
.Address
;
314 start_routine
: Thread_Body
;
315 arg
: System
.Address
;
317 new_thread
: access thread_t
) return int
;
318 pragma Import
(C
, thr_create
, "thr_create");
320 function thr_min_stack
return size_t
;
321 pragma Import
(C
, thr_min_stack
, "thr_min_stack");
323 function thr_self
return thread_t
;
324 pragma Import
(C
, thr_self
, "thr_self");
327 (mutex
: access mutex_t
;
329 arg
: System
.Address
) return int
;
330 pragma Import
(C
, mutex_init
, "mutex_init");
332 function mutex_destroy
(mutex
: access mutex_t
) return int
;
333 pragma Import
(C
, mutex_destroy
, "mutex_destroy");
335 function mutex_lock
(mutex
: access mutex_t
) return int
;
336 pragma Import
(C
, mutex_lock
, "mutex_lock");
338 function mutex_unlock
(mutex
: access mutex_t
) return int
;
339 pragma Import
(C
, mutex_unlock
, "mutex_unlock");
342 (cond
: access cond_t
;
344 arg
: int
) return int
;
345 pragma Import
(C
, cond_init
, "cond_init");
348 (cond
: access cond_t
; mutex
: access mutex_t
) return int
;
349 pragma Import
(C
, cond_wait
, "cond_wait");
351 function cond_timedwait
352 (cond
: access cond_t
;
353 mutex
: access mutex_t
;
354 abstime
: access timespec
) return int
;
355 pragma Import
(C
, cond_timedwait
, "cond_timedwait");
357 function cond_signal
(cond
: access cond_t
) return int
;
358 pragma Import
(C
, cond_signal
, "cond_signal");
360 function cond_destroy
(cond
: access cond_t
) return int
;
361 pragma Import
(C
, cond_destroy
, "cond_destroy");
363 function thr_setspecific
364 (key
: thread_key_t
; value
: System
.Address
) return int
;
365 pragma Import
(C
, thr_setspecific
, "thr_setspecific");
367 function thr_getspecific
369 value
: access System
.Address
) return int
;
370 pragma Import
(C
, thr_getspecific
, "thr_getspecific");
372 function thr_keycreate
373 (key
: access thread_key_t
; destructor
: System
.Address
) return int
;
374 pragma Import
(C
, thr_keycreate
, "thr_keycreate");
376 function thr_setprio
(thread
: thread_t
; priority
: int
) return int
;
377 pragma Import
(C
, thr_setprio
, "thr_setprio");
379 procedure thr_exit
(status
: System
.Address
);
380 pragma Import
(C
, thr_exit
, "thr_exit");
382 function thr_setconcurrency
(new_level
: int
) return int
;
383 pragma Import
(C
, thr_setconcurrency
, "thr_setconcurrency");
385 function sigwait
(set
: access sigset_t
; sig
: access Signal
) return int
;
386 pragma Import
(C
, sigwait
, "__posix_sigwait");
388 function thr_kill
(thread
: thread_t
; sig
: Signal
) return int
;
389 pragma Import
(C
, thr_kill
, "thr_kill");
391 type sigset_t_ptr
is access all sigset_t
;
393 function thr_sigsetmask
396 oset
: sigset_t_ptr
) return int
;
397 pragma Import
(C
, thr_sigsetmask
, "thr_sigsetmask");
399 function pthread_sigmask
402 oset
: sigset_t_ptr
) return int
;
403 pragma Import
(C
, pthread_sigmask
, "thr_sigsetmask");
405 function thr_suspend
(target_thread
: thread_t
) return int
;
406 pragma Import
(C
, thr_suspend
, "thr_suspend");
408 function thr_continue
(target_thread
: thread_t
) return int
;
409 pragma Import
(C
, thr_continue
, "thr_continue");
412 pragma Import
(C
, thr_yield
, "thr_yield");
418 P_PID
: constant := 0;
419 P_LWPID
: constant := 8;
421 PC_GETCID
: constant := 0;
422 PC_GETCLINFO
: constant := 1;
423 PC_SETPARMS
: constant := 2;
424 PC_GETPARMS
: constant := 3;
425 PC_ADMIN
: constant := 4;
427 PC_CLNULL
: constant := -1;
429 RT_NOCHANGE
: constant := -1;
430 RT_TQINF
: constant := -2;
431 RT_TQDEF
: constant := -3;
433 PC_CLNMSZ
: constant := 16;
435 PC_VERSION
: constant := 1;
437 type lwpid_t
is new int
;
439 type pri_t
is new short
;
441 type id_t
is new long
;
443 P_MYID
: constant := -1;
444 -- the specified LWP or process is the current one.
446 type struct_pcinfo
is record
448 pc_clname
: String (1 .. PC_CLNMSZ
);
451 pragma Convention
(C
, struct_pcinfo
);
453 type struct_pcparms
is record
459 pragma Convention
(C
, struct_pcparms
);
466 arg
: System
.Address
) return Interfaces
.C
.long
;
467 pragma Import
(C
, priocntl
, "__priocntl");
469 function lwp_self
return lwpid_t
;
470 pragma Import
(C
, lwp_self
, "_lwp_self");
472 type processorid_t
is new int
;
473 type processorid_t_ptr
is access all processorid_t
;
475 -- Constants for function processor_bind
477 PBIND_QUERY
: constant processorid_t
:= -2;
478 -- the processor bindings are not changed.
480 PBIND_NONE
: constant processorid_t
:= -1;
481 -- the processor bindings of the specified LWPs are cleared.
483 -- Flags for function p_online
485 PR_OFFLINE
: constant int
:= 1;
486 -- processor is offline, as quiet as possible
488 PR_ONLINE
: constant int
:= 2;
491 PR_STATUS
: constant int
:= 3;
492 -- value passed to p_online to request status
494 function p_online
(processorid
: processorid_t
; flag
: int
) return int
;
495 pragma Import
(C
, p_online
, "p_online");
497 function processor_bind
500 proc_id
: processorid_t
;
501 obind
: processorid_t_ptr
) return int
;
502 pragma Import
(C
, processor_bind
, "processor_bind");
504 procedure pthread_init
;
505 -- dummy procedure to share s-intman.adb with other Solaris targets.
509 type array_type_1
is array (0 .. 3) of unsigned_long
;
510 type sigset_t
is record
511 X_X_sigbits
: array_type_1
;
513 pragma Convention
(C
, sigset_t
);
515 type pid_t
is new long
;
517 type time_t
is new long
;
519 type timespec
is record
523 pragma Convention
(C
, timespec
);
525 type clockid_t
is new int
;
526 CLOCK_REALTIME
: constant clockid_t
:= 0;
528 type struct_timeval
is record
532 pragma Convention
(C
, struct_timeval
);
534 type thread_t
is new unsigned
;
536 type array_type_9
is array (0 .. 3) of unsigned_char
;
537 type record_type_3
is record
539 Xtype
: unsigned_long
;
541 pragma Convention
(C
, record_type_3
);
543 type mutex_t
is record
544 flags
: record_type_3
;
545 lock
: String (1 .. 8);
546 data
: String (1 .. 8);
548 pragma Convention
(C
, mutex_t
);
550 type cond_t
is record
552 Xtype
: unsigned_long
;
553 data
: String (1 .. 8);
555 pragma Convention
(C
, cond_t
);
557 type thread_key_t
is new unsigned
;
559 end System
.OS_Interface
;