1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . I N T E R R U P T _ M A N A G E M E N T --
9 -- $Revision: 1.15 $ --
11 -- Copyright (C) 1991-2001 Florida State University --
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 Sun OS (FSU THREADS) version of this package
39 -- PLEASE DO NOT add any dependences on other packages. ??? why not ???
40 -- This package is designed to work with or without tasking support.
42 -- Make a careful study of all signals available under the OS, to see which
43 -- need to be reserved, kept always unmasked, or kept always unmasked. Be on
44 -- the lookout for special signals that may be used by the thread library.
49 with System
.Error_Reporting
;
52 with System
.OS_Interface
;
53 -- used for various Constants, Signal and types
55 package body System
.Interrupt_Management
is
58 use System
.Error_Reporting
;
59 use System
.OS_Interface
;
61 type Interrupt_List
is array (Interrupt_ID
range <>) of Interrupt_ID
;
62 Exception_Interrupts
: constant Interrupt_List
:=
63 (SIGFPE
, SIGILL
, SIGSEGV
);
65 Unreserve_All_Interrupts
: Interfaces
.C
.int
;
67 (C
, Unreserve_All_Interrupts
, "__gl_unreserve_all_interrupts");
69 -----------------------
70 -- Local Subprograms --
71 -----------------------
73 procedure Notify_Exception
75 info
: access siginfo_t
;
76 context
: access struct_sigcontext
);
77 -- This function identifies the Ada exception to be raised using
78 -- the information when the system received a synchronous signal.
79 -- Since this function is machine and OS dependent, different code
80 -- has to be provided for different target.
82 ----------------------
83 -- Notify_Exception --
84 ----------------------
86 -- The following code is intended for SunOS on Sparcstation.
88 procedure Notify_Exception
90 info
: access siginfo_t
;
91 context
: access struct_sigcontext
)
94 -- As long as we are using a longjmp to return control to the
95 -- exception handler on the runtime stack, we are safe. The original
96 -- signal mask (the one we had before coming into this signal catching
97 -- function) will be restored by the longjmp. Therefore, raising
98 -- an exception in this handler should be a safe operation.
100 -- Check that treatment of exception propagation here
101 -- is consistent with treatment of the abort signal in
102 -- System.Task_Primitives.Operations.
107 when FPE_INTOVF_TRAP |
114 raise Constraint_Error
;
117 pragma Assert
(Shutdown
("Unexpected SIGFPE signal"));
125 ILL_PRIVINSTR_FAULT
=>
126 raise Constraint_Error
;
129 pragma Assert
(Shutdown
("Unexpected SIGILL signal"));
135 -- was caused by accessing a null pointer.
137 -- ???? Origin of this code is unclear, may be broken ???
139 if context
.sc_o0
in 0 .. 16#
2000#
then
140 raise Constraint_Error
;
146 pragma Assert
(Shutdown
("Unexpected signal"));
149 end Notify_Exception
;
151 ---------------------------
152 -- Initialize_Interrupts --
153 ---------------------------
155 -- Nothing needs to be done on this platform
157 procedure Initialize_Interrupts
is
160 end Initialize_Interrupts
;
162 -------------------------
163 -- Package Elaboration --
164 -------------------------
168 act
: aliased struct_sigaction
;
169 old_act
: aliased struct_sigaction
;
170 mask
: aliased sigset_t
;
171 Result
: Interfaces
.C
.int
;
174 -- Need to call pthread_init very early because it is doing signal
179 -- Change the following assignment to use another signal for task abort.
180 -- For example, SIGTERM might be a good one if SIGABRT is required for
183 Abort_Task_Interrupt
:= SIGABRT
;
185 act
.sa_handler
:= Notify_Exception
'Address;
187 -- Set sa_flags to SA_NODEFER so that during the handler execution
188 -- we do not change the Signal_Mask to be masked for the Signal.
189 -- This is a temporary fix to the problem that the Signal_Mask is
190 -- not restored after the exception (longjmp) from the handler.
191 -- The right fix should be made in sigsetjmp so that we save
192 -- the Signal_Set and restore it after a longjmp.
194 -- In that case, this field should be changed back to 0. ???
198 Result
:= sigemptyset
(mask
'Access);
199 pragma Assert
(Result
= 0);
201 for J
in Exception_Interrupts
'Range loop
202 Result
:= sigaddset
(mask
'Access, Signal
(Exception_Interrupts
(J
)));
203 pragma Assert
(Result
= 0);
208 for J
in Exception_Interrupts
'Range loop
209 Keep_Unmasked
(Exception_Interrupts
(J
)) := True;
211 if Unreserve_All_Interrupts
= 0 then
214 (Signal
(Exception_Interrupts
(J
)),
215 act
'Unchecked_Access,
216 old_act
'Unchecked_Access);
217 pragma Assert
(Result
= 0);
221 Keep_Unmasked
(Abort_Task_Interrupt
) := True;
222 Keep_Unmasked
(SIGBUS
) := True;
223 Keep_Unmasked
(SIGFPE
) := True;
226 (Signal
(SIGFPE
), act
'Unchecked_Access,
227 old_act
'Unchecked_Access);
229 Keep_Unmasked
(SIGALRM
) := True;
230 Keep_Unmasked
(SIGSTOP
) := True;
231 Keep_Unmasked
(SIGKILL
) := True;
232 Keep_Unmasked
(SIGXCPU
) := True;
234 -- By keeping SIGINT unmasked, allow the user to do a Ctrl-C, but at
235 -- the same time, disable the ability of handling this signal using
236 -- package Ada.Interrupts.
238 -- The pragma Unreserve_All_Interrupts allows the user the ability to
239 -- change this behavior.
241 if Unreserve_All_Interrupts
= 0 then
242 Keep_Unmasked
(SIGINT
) := True;
245 -- Reserve this not to interfere with thread scheduling
247 -- ??? consider adding this to interrupt exceptions
248 -- Keep_Unmasked (SIGALRM) := True;
250 -- An earlier version had a comment about SIGALRM needing to be unmasked
251 -- in at least one thread for cond_timedwait to work.
253 -- It is unclear whether this is True for Solaris threads, FSU threads,
254 -- both, or maybe just an old version of FSU threads. ????
256 -- Following signals should not be disturbed. Found by experiment
258 Keep_Unmasked
(SIGEMT
) := True;
259 Keep_Unmasked
(SIGCHLD
) := True;
261 -- We do not have Signal 0 in reality. We just use this value
262 -- to identify not existing signals (see s-intnam.ads). Therefore,
263 -- Signal 0 should not be used in all signal related operations hence
264 -- mark it as reserved.
266 Reserve
:= Reserve
or Keep_Unmasked
or Keep_Masked
;
269 end System
.Interrupt_Management
;