annotate gcc/ada/libgnarl/s-intman__solaris.adb @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
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 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This is a Solaris version of this package
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- Make a careful study of all signals available under the OS, to see which
kono
parents:
diff changeset
35 -- need to be reserved, kept always unmasked, or kept always unmasked.
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 -- Be on the lookout for special signals that may be used by the thread
kono
parents:
diff changeset
38 -- library.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 package body System.Interrupt_Management is
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 use Interfaces.C;
kono
parents:
diff changeset
43 use System.OS_Interface;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 type Interrupt_List is array (Interrupt_ID range <>) of Interrupt_ID;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 Exception_Interrupts : constant Interrupt_List :=
kono
parents:
diff changeset
48 (SIGFPE, SIGILL, SIGSEGV, SIGBUS);
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 Unreserve_All_Interrupts : Interfaces.C.int;
kono
parents:
diff changeset
51 pragma Import
kono
parents:
diff changeset
52 (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 function State (Int : Interrupt_ID) return Character;
kono
parents:
diff changeset
55 pragma Import (C, State, "__gnat_get_interrupt_state");
kono
parents:
diff changeset
56 -- Get interrupt state. Defined in init.c
kono
parents:
diff changeset
57 -- The input argument is the interrupt number,
kono
parents:
diff changeset
58 -- and the result is one of the following:
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 User : constant Character := 'u';
kono
parents:
diff changeset
61 Runtime : constant Character := 'r';
kono
parents:
diff changeset
62 Default : constant Character := 's';
kono
parents:
diff changeset
63 -- 'n' this interrupt not set by any Interrupt_State pragma
kono
parents:
diff changeset
64 -- 'u' Interrupt_State pragma set state to User
kono
parents:
diff changeset
65 -- 'r' Interrupt_State pragma set state to Runtime
kono
parents:
diff changeset
66 -- 's' Interrupt_State pragma set state to System (use "default"
kono
parents:
diff changeset
67 -- system handler)
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 ----------------------
kono
parents:
diff changeset
70 -- Notify_Exception --
kono
parents:
diff changeset
71 ----------------------
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -- This function identifies the Ada exception to be raised using the
kono
parents:
diff changeset
74 -- information when the system received a synchronous signal. Since this
kono
parents:
diff changeset
75 -- function is machine and OS dependent, different code has to be provided
kono
parents:
diff changeset
76 -- for different target.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 procedure Notify_Exception
kono
parents:
diff changeset
79 (signo : Signal;
kono
parents:
diff changeset
80 info : access siginfo_t;
kono
parents:
diff changeset
81 context : access ucontext_t);
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 ----------------------
kono
parents:
diff changeset
84 -- Notify_Exception --
kono
parents:
diff changeset
85 ----------------------
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 procedure Notify_Exception
kono
parents:
diff changeset
88 (signo : Signal;
kono
parents:
diff changeset
89 info : access siginfo_t;
kono
parents:
diff changeset
90 context : access ucontext_t)
kono
parents:
diff changeset
91 is
kono
parents:
diff changeset
92 pragma Unreferenced (info);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 begin
kono
parents:
diff changeset
95 -- Perform the necessary context adjustments prior to a raise from a
kono
parents:
diff changeset
96 -- signal handler.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 Adjust_Context_For_Raise (signo, context.all'Address);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 -- Check that treatment of exception propagation here is consistent with
kono
parents:
diff changeset
101 -- treatment of the abort signal in System.Task_Primitives.Operations.
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 case signo is
kono
parents:
diff changeset
104 when SIGFPE => raise Constraint_Error;
kono
parents:
diff changeset
105 when SIGILL => raise Program_Error;
kono
parents:
diff changeset
106 when SIGSEGV => raise Storage_Error;
kono
parents:
diff changeset
107 when SIGBUS => raise Storage_Error;
kono
parents:
diff changeset
108 when others => null;
kono
parents:
diff changeset
109 end case;
kono
parents:
diff changeset
110 end Notify_Exception;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 ----------------
kono
parents:
diff changeset
113 -- Initialize --
kono
parents:
diff changeset
114 ----------------
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 Initialized : Boolean := False;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Initialize is
kono
parents:
diff changeset
119 act : aliased struct_sigaction;
kono
parents:
diff changeset
120 old_act : aliased struct_sigaction;
kono
parents:
diff changeset
121 mask : aliased sigset_t;
kono
parents:
diff changeset
122 Result : Interfaces.C.int;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 begin
kono
parents:
diff changeset
125 if Initialized then
kono
parents:
diff changeset
126 return;
kono
parents:
diff changeset
127 end if;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 Initialized := True;
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 -- Need to call pthread_init very early because it is doing signal
kono
parents:
diff changeset
132 -- initializations.
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 pthread_init;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- Change this if you want to use another signal for task abort.
kono
parents:
diff changeset
137 -- SIGTERM might be a good one.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 Abort_Task_Interrupt := SIGABRT;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 act.sa_handler := Notify_Exception'Address;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 -- Set sa_flags to SA_NODEFER so that during the handler execution
kono
parents:
diff changeset
144 -- we do not change the Signal_Mask to be masked for the Signal.
kono
parents:
diff changeset
145 -- This is a temporary fix to the problem that the Signal_Mask is
kono
parents:
diff changeset
146 -- not restored after the exception (longjmp) from the handler.
kono
parents:
diff changeset
147 -- The right fix should be made in sigsetjmp so that we save
kono
parents:
diff changeset
148 -- the Signal_Set and restore it after a longjmp.
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 -- In that case, this field should be changed back to 0. ??? (Dong-Ik)
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 act.sa_flags := 16;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 Result := sigemptyset (mask'Access);
kono
parents:
diff changeset
155 pragma Assert (Result = 0);
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 -- ??? For the same reason explained above, we can't mask these signals
kono
parents:
diff changeset
158 -- because otherwise we won't be able to catch more than one signal.
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 act.sa_mask := mask;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 pragma Assert (Keep_Unmasked = (Interrupt_ID'Range => False));
kono
parents:
diff changeset
163 pragma Assert (Reserve = (Interrupt_ID'Range => False));
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 for J in Exception_Interrupts'Range loop
kono
parents:
diff changeset
166 if State (Exception_Interrupts (J)) /= User then
kono
parents:
diff changeset
167 Keep_Unmasked (Exception_Interrupts (J)) := True;
kono
parents:
diff changeset
168 Reserve (Exception_Interrupts (J)) := True;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 if State (Exception_Interrupts (J)) /= Default then
kono
parents:
diff changeset
171 Result :=
kono
parents:
diff changeset
172 sigaction
kono
parents:
diff changeset
173 (Signal (Exception_Interrupts (J)), act'Unchecked_Access,
kono
parents:
diff changeset
174 old_act'Unchecked_Access);
kono
parents:
diff changeset
175 pragma Assert (Result = 0);
kono
parents:
diff changeset
176 end if;
kono
parents:
diff changeset
177 end if;
kono
parents:
diff changeset
178 end loop;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 if State (Abort_Task_Interrupt) /= User then
kono
parents:
diff changeset
181 Keep_Unmasked (Abort_Task_Interrupt) := True;
kono
parents:
diff changeset
182 Reserve (Abort_Task_Interrupt) := True;
kono
parents:
diff changeset
183 end if;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 -- Set SIGINT to unmasked state as long as it's
kono
parents:
diff changeset
186 -- not in "User" state. Check for Unreserve_All_Interrupts last
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 if State (SIGINT) /= User then
kono
parents:
diff changeset
189 Keep_Unmasked (SIGINT) := True;
kono
parents:
diff changeset
190 Reserve (SIGINT) := True;
kono
parents:
diff changeset
191 end if;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 -- Check all signals for state that requires keeping them
kono
parents:
diff changeset
194 -- unmasked and reserved
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 for J in Interrupt_ID'Range loop
kono
parents:
diff changeset
197 if State (J) = Default or else State (J) = Runtime then
kono
parents:
diff changeset
198 Keep_Unmasked (J) := True;
kono
parents:
diff changeset
199 Reserve (J) := True;
kono
parents:
diff changeset
200 end if;
kono
parents:
diff changeset
201 end loop;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 -- Add the set of signals that must always be unmasked for this target
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 for J in Unmasked'Range loop
kono
parents:
diff changeset
206 Keep_Unmasked (Interrupt_ID (Unmasked (J))) := True;
kono
parents:
diff changeset
207 Reserve (Interrupt_ID (Unmasked (J))) := True;
kono
parents:
diff changeset
208 end loop;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 -- Add target-specific reserved signals
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 for J in Reserved'Range loop
kono
parents:
diff changeset
213 Reserve (Interrupt_ID (Reserved (J))) := True;
kono
parents:
diff changeset
214 end loop;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 -- Process pragma Unreserve_All_Interrupts. This overrides any
kono
parents:
diff changeset
217 -- settings due to pragma Interrupt_State:
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 if Unreserve_All_Interrupts /= 0 then
kono
parents:
diff changeset
220 Keep_Unmasked (SIGINT) := False;
kono
parents:
diff changeset
221 Reserve (SIGINT) := False;
kono
parents:
diff changeset
222 end if;
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 -- We do not have Signal 0 in reality. We just use this value to
kono
parents:
diff changeset
225 -- identify not existing signals (see s-intnam.ads). Therefore, Signal 0
kono
parents:
diff changeset
226 -- should not be used in all signal related operations hence mark it as
kono
parents:
diff changeset
227 -- reserved.
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 Reserve (0) := True;
kono
parents:
diff changeset
230 end Initialize;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 end System.Interrupt_Management;