Remove some compile time warnings about duplicate definitions.
[official-gcc.git] / gcc / ada / 5uintman.adb
blob9b11d3baa8e9371d1be7b294cac332d0bcc371d1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
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 --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.15 $ --
10 -- --
11 -- Copyright (C) 1991-2001 Florida State University --
12 -- --
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. --
23 -- --
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. --
30 -- --
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). --
34 -- --
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.
46 with Interfaces.C;
47 -- used for int
49 with System.Error_Reporting;
50 -- used for Shutdown
52 with System.OS_Interface;
53 -- used for various Constants, Signal and types
55 package body System.Interrupt_Management is
57 use Interfaces.C;
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;
66 pragma Import
67 (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
69 -----------------------
70 -- Local Subprograms --
71 -----------------------
73 procedure Notify_Exception
74 (signo : Signal;
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
89 (signo : Signal;
90 info : access siginfo_t;
91 context : access struct_sigcontext)
93 begin
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.
104 case signo is
105 when SIGFPE =>
106 case info.si_code is
107 when FPE_INTOVF_TRAP |
108 FPE_STARTSIG_TRAP |
109 FPE_INTDIV_TRAP |
110 FPE_FLTDIV_TRAP |
111 FPE_FLTUND_TRAP |
112 FPE_FLTOPERR_TRAP |
113 FPE_FLTOVF_TRAP =>
114 raise Constraint_Error;
116 when others =>
117 pragma Assert (Shutdown ("Unexpected SIGFPE signal"));
118 null;
119 end case;
121 when SIGILL =>
122 case info.si_code is
123 when ILL_STACK |
124 ILL_ILLINSTR_FAULT |
125 ILL_PRIVINSTR_FAULT =>
126 raise Constraint_Error;
128 when others =>
129 pragma Assert (Shutdown ("Unexpected SIGILL signal"));
130 null;
131 end case;
133 when SIGSEGV =>
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;
141 else
142 raise Storage_Error;
143 end if;
145 when others =>
146 pragma Assert (Shutdown ("Unexpected signal"));
147 null;
148 end case;
149 end Notify_Exception;
151 ---------------------------
152 -- Initialize_Interrupts --
153 ---------------------------
155 -- Nothing needs to be done on this platform
157 procedure Initialize_Interrupts is
158 begin
159 null;
160 end Initialize_Interrupts;
162 -------------------------
163 -- Package Elaboration --
164 -------------------------
166 begin
167 declare
168 act : aliased struct_sigaction;
169 old_act : aliased struct_sigaction;
170 mask : aliased sigset_t;
171 Result : Interfaces.C.int;
173 begin
174 -- Need to call pthread_init very early because it is doing signal
175 -- initializations.
177 pthread_init;
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
181 -- use elsewhere.
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. ???
196 act.sa_flags := 16;
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);
204 end loop;
206 act.sa_mask := mask;
208 for J in Exception_Interrupts'Range loop
209 Keep_Unmasked (Exception_Interrupts (J)) := True;
211 if Unreserve_All_Interrupts = 0 then
212 Result :=
213 sigaction
214 (Signal (Exception_Interrupts (J)),
215 act'Unchecked_Access,
216 old_act'Unchecked_Access);
217 pragma Assert (Result = 0);
218 end if;
219 end loop;
221 Keep_Unmasked (Abort_Task_Interrupt) := True;
222 Keep_Unmasked (SIGBUS) := True;
223 Keep_Unmasked (SIGFPE) := True;
224 Result :=
225 sigaction
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;
243 end if;
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;
267 Reserve (0) := True;
268 end;
269 end System.Interrupt_Management;