1 ------------------------------------------------------------------------------
3 -- GNAT 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 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 -- This is a Solaris version of this package
34 -- Make a careful study of all signals available under the OS, to see which
35 -- need to be reserved, kept always unmasked, or kept always unmasked.
37 -- Be on the lookout for special signals that may be used by the thread
40 package body System
.Interrupt_Management
is
43 use System
.OS_Interface
;
45 type Interrupt_List
is array (Interrupt_ID
range <>) of Interrupt_ID
;
47 Exception_Interrupts
: constant Interrupt_List
:=
48 (SIGFPE
, SIGILL
, SIGSEGV
, SIGBUS
);
50 Unreserve_All_Interrupts
: Interfaces
.C
.int
;
52 (C
, Unreserve_All_Interrupts
, "__gl_unreserve_all_interrupts");
54 function State
(Int
: Interrupt_ID
) return Character;
55 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
56 -- Get interrupt state. Defined in init.c
57 -- The input argument is the interrupt number,
58 -- and the result is one of the following:
60 User
: constant Character := 'u';
61 Runtime
: constant Character := 'r';
62 Default
: constant Character := 's';
63 -- 'n' this interrupt not set by any Interrupt_State pragma
64 -- 'u' Interrupt_State pragma set state to User
65 -- 'r' Interrupt_State pragma set state to Runtime
66 -- 's' Interrupt_State pragma set state to System (use "default"
69 ----------------------
70 -- Notify_Exception --
71 ----------------------
73 -- This function identifies the Ada exception to be raised using the
74 -- information when the system received a synchronous signal. Since this
75 -- function is machine and OS dependent, different code has to be provided
76 -- for different target.
78 procedure Notify_Exception
80 info
: access siginfo_t
;
81 context
: access ucontext_t
);
83 ----------------------
84 -- Notify_Exception --
85 ----------------------
87 procedure Notify_Exception
89 info
: access siginfo_t
;
90 context
: access ucontext_t
)
92 pragma Unreferenced
(info
);
95 -- Perform the necessary context adjustments prior to a raise from a
98 Adjust_Context_For_Raise
(signo
, context
.all'Address);
100 -- Check that treatment of exception propagation here is consistent with
101 -- treatment of the abort signal in System.Task_Primitives.Operations.
104 when SIGFPE
=> raise Constraint_Error
;
105 when SIGILL
=> raise Program_Error
;
106 when SIGSEGV
=> raise Storage_Error
;
107 when SIGBUS
=> raise Storage_Error
;
110 end Notify_Exception
;
116 Initialized
: Boolean := False;
118 procedure Initialize
is
119 act
: aliased struct_sigaction
;
120 old_act
: aliased struct_sigaction
;
121 mask
: aliased sigset_t
;
122 Result
: Interfaces
.C
.int
;
131 -- Need to call pthread_init very early because it is doing signal
136 -- Change this if you want to use another signal for task abort.
137 -- SIGTERM might be a good one.
139 Abort_Task_Interrupt
:= SIGABRT
;
141 act
.sa_handler
:= Notify_Exception
'Address;
143 -- Set sa_flags to SA_NODEFER so that during the handler execution
144 -- we do not change the Signal_Mask to be masked for the Signal.
145 -- This is a temporary fix to the problem that the Signal_Mask is
146 -- not restored after the exception (longjmp) from the handler.
147 -- The right fix should be made in sigsetjmp so that we save
148 -- the Signal_Set and restore it after a longjmp.
150 -- In that case, this field should be changed back to 0. ??? (Dong-Ik)
154 Result
:= sigemptyset
(mask
'Access);
155 pragma Assert
(Result
= 0);
157 -- ??? For the same reason explained above, we can't mask these signals
158 -- because otherwise we won't be able to catch more than one signal.
162 pragma Assert
(Keep_Unmasked
= (Interrupt_ID
'Range => False));
163 pragma Assert
(Reserve
= (Interrupt_ID
'Range => False));
165 for J
in Exception_Interrupts
'Range loop
166 if State
(Exception_Interrupts
(J
)) /= User
then
167 Keep_Unmasked
(Exception_Interrupts
(J
)) := True;
168 Reserve
(Exception_Interrupts
(J
)) := True;
170 if State
(Exception_Interrupts
(J
)) /= Default
then
173 (Signal
(Exception_Interrupts
(J
)), act
'Unchecked_Access,
174 old_act
'Unchecked_Access);
175 pragma Assert
(Result
= 0);
180 if State
(Abort_Task_Interrupt
) /= User
then
181 Keep_Unmasked
(Abort_Task_Interrupt
) := True;
182 Reserve
(Abort_Task_Interrupt
) := True;
185 -- Set SIGINT to unmasked state as long as it's
186 -- not in "User" state. Check for Unreserve_All_Interrupts last
188 if State
(SIGINT
) /= User
then
189 Keep_Unmasked
(SIGINT
) := True;
190 Reserve
(SIGINT
) := True;
193 -- Check all signals for state that requires keeping them
194 -- unmasked and reserved
196 for J
in Interrupt_ID
'Range loop
197 if State
(J
) = Default
or else State
(J
) = Runtime
then
198 Keep_Unmasked
(J
) := True;
203 -- Add the set of signals that must always be unmasked for this target
205 for J
in Unmasked
'Range loop
206 Keep_Unmasked
(Interrupt_ID
(Unmasked
(J
))) := True;
207 Reserve
(Interrupt_ID
(Unmasked
(J
))) := True;
210 -- Add target-specific reserved signals
212 for J
in Reserved
'Range loop
213 Reserve
(Interrupt_ID
(Reserved
(J
))) := True;
216 -- Process pragma Unreserve_All_Interrupts. This overrides any
217 -- settings due to pragma Interrupt_State:
219 if Unreserve_All_Interrupts
/= 0 then
220 Keep_Unmasked
(SIGINT
) := False;
221 Reserve
(SIGINT
) := False;
224 -- We do not have Signal 0 in reality. We just use this value to
225 -- identify not existing signals (see s-intnam.ads). Therefore, Signal 0
226 -- should not be used in all signal related operations hence mark it as
232 end System
.Interrupt_Management
;