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 --
10 -- Copyright (C) 1991-2002 Florida State University --
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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This is a Sun OS (FSU THREADS) version of this package
38 -- PLEASE DO NOT add any dependences on other packages. ??? why not ???
39 -- This package is designed to work with or without tasking support.
41 -- Make a careful study of all signals available under the OS, to see which
42 -- need to be reserved, kept always unmasked, or kept always unmasked. Be on
43 -- the lookout for special signals that may be used by the thread library.
48 with System
.Error_Reporting
;
51 with System
.OS_Interface
;
52 -- used for various Constants, Signal and types
54 package body System
.Interrupt_Management
is
57 use System
.Error_Reporting
;
58 use System
.OS_Interface
;
60 type Interrupt_List
is array (Interrupt_ID
range <>) of Interrupt_ID
;
61 Exception_Interrupts
: constant Interrupt_List
:=
62 (SIGFPE
, SIGILL
, SIGSEGV
);
64 Unreserve_All_Interrupts
: Interfaces
.C
.int
;
66 (C
, Unreserve_All_Interrupts
, "__gl_unreserve_all_interrupts");
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Notify_Exception
74 info
: access siginfo_t
;
75 context
: access struct_sigcontext
);
76 -- This function identifies the Ada exception to be raised using
77 -- the information when the system received a synchronous signal.
78 -- Since this function is machine and OS dependent, different code
79 -- has to be provided for different target.
81 ----------------------
82 -- Notify_Exception --
83 ----------------------
85 -- The following code is intended for SunOS on Sparcstation.
87 procedure Notify_Exception
89 info
: access siginfo_t
;
90 context
: access struct_sigcontext
)
93 -- As long as we are using a longjmp to return control to the
94 -- exception handler on the runtime stack, we are safe. The original
95 -- signal mask (the one we had before coming into this signal catching
96 -- function) will be restored by the longjmp. Therefore, raising
97 -- an exception in this handler should be a safe operation.
99 -- Check that treatment of exception propagation here
100 -- is consistent with treatment of the abort signal in
101 -- System.Task_Primitives.Operations.
106 when FPE_INTOVF_TRAP |
113 raise Constraint_Error
;
116 pragma Assert
(Shutdown
("Unexpected SIGFPE signal"));
124 ILL_PRIVINSTR_FAULT
=>
125 raise Constraint_Error
;
128 pragma Assert
(Shutdown
("Unexpected SIGILL signal"));
134 -- was caused by accessing a null pointer.
136 -- ???? Origin of this code is unclear, may be broken ???
138 if context
.sc_o0
in 0 .. 16#
2000#
then
139 raise Constraint_Error
;
145 pragma Assert
(Shutdown
("Unexpected signal"));
148 end Notify_Exception
;
150 ---------------------------
151 -- Initialize_Interrupts --
152 ---------------------------
154 -- Nothing needs to be done on this platform
156 procedure Initialize_Interrupts
is
159 end Initialize_Interrupts
;
161 -------------------------
162 -- Package Elaboration --
163 -------------------------
167 act
: aliased struct_sigaction
;
168 old_act
: aliased struct_sigaction
;
169 mask
: aliased sigset_t
;
170 Result
: Interfaces
.C
.int
;
173 -- Need to call pthread_init very early because it is doing signal
178 -- Change the following assignment to use another signal for task abort.
179 -- For example, SIGTERM might be a good one if SIGABRT is required for
182 Abort_Task_Interrupt
:= SIGABRT
;
184 act
.sa_handler
:= Notify_Exception
'Address;
186 -- Set sa_flags to SA_NODEFER so that during the handler execution
187 -- we do not change the Signal_Mask to be masked for the Signal.
188 -- This is a temporary fix to the problem that the Signal_Mask is
189 -- not restored after the exception (longjmp) from the handler.
190 -- The right fix should be made in sigsetjmp so that we save
191 -- the Signal_Set and restore it after a longjmp.
193 -- In that case, this field should be changed back to 0. ???
197 Result
:= sigemptyset
(mask
'Access);
198 pragma Assert
(Result
= 0);
200 for J
in Exception_Interrupts
'Range loop
201 Result
:= sigaddset
(mask
'Access, Signal
(Exception_Interrupts
(J
)));
202 pragma Assert
(Result
= 0);
207 for J
in Exception_Interrupts
'Range loop
208 Keep_Unmasked
(Exception_Interrupts
(J
)) := True;
212 (Signal
(Exception_Interrupts
(J
)),
213 act
'Unchecked_Access,
214 old_act
'Unchecked_Access);
215 pragma Assert
(Result
= 0);
218 Keep_Unmasked
(Abort_Task_Interrupt
) := True;
219 Keep_Unmasked
(SIGALRM
) := True;
220 Keep_Unmasked
(SIGSTOP
) := True;
221 Keep_Unmasked
(SIGKILL
) := True;
223 -- By keeping SIGINT unmasked, allow the user to do a Ctrl-C, but at
224 -- the same time, disable the ability of handling this signal using
225 -- package Ada.Interrupts.
227 -- The pragma Unreserve_All_Interrupts allows the user the ability to
228 -- change this behavior.
230 if Unreserve_All_Interrupts
= 0 then
231 Keep_Unmasked
(SIGINT
) := True;
234 -- Reserve this not to interfere with thread scheduling
236 -- ??? consider adding this to interrupt exceptions
237 -- Keep_Unmasked (SIGALRM) := True;
239 -- An earlier version had a comment about SIGALRM needing to be unmasked
240 -- in at least one thread for cond_timedwait to work.
242 -- It is unclear whether this is True for Solaris threads, FSU threads,
243 -- both, or maybe just an old version of FSU threads. ????
245 -- Following signals should not be disturbed. Found by experiment
247 Keep_Unmasked
(SIGEMT
) := True;
248 Keep_Unmasked
(SIGCHLD
) := True;
250 -- We do not have Signal 0 in reality. We just use this value
251 -- to identify not existing signals (see s-intnam.ads). Therefore,
252 -- Signal 0 should not be used in all signal related operations hence
253 -- mark it as reserved.
255 Reserve
:= Reserve
or Keep_Unmasked
or Keep_Masked
;
258 end System
.Interrupt_Management
;