include/ChangeLog:
[official-gcc.git] / gcc / ada / 5sintman.adb
blob77315a7a15bc6cfe6daa2b4931bbed8146126a24
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 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
10 -- --
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 2, or (at your option) any later ver- --
14 -- sion. GNARL 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This is a Solaris version of this package.
36 -- PLEASE DO NOT add any dependences on other packages.
37 -- This package is designed to work with or without tasking support.
39 -- Make a careful study of all signals available under the OS,
40 -- to see which need to be reserved, kept always unmasked,
41 -- or kept always unmasked.
43 -- Be on the lookout for special signals that
44 -- may be used by the thread library.
46 with Interfaces.C;
47 -- used for int
49 with System.OS_Interface;
50 -- used for various Constants, Signal and types
52 package body System.Interrupt_Management is
54 use Interfaces.C;
55 use System.OS_Interface;
57 type Interrupt_List is array (Interrupt_ID range <>) of Interrupt_ID;
59 Exception_Interrupts : constant Interrupt_List :=
60 (SIGFPE, SIGILL, SIGSEGV, SIGBUS);
62 Unreserve_All_Interrupts : Interfaces.C.int;
63 pragma Import
64 (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
66 ----------------------
67 -- Notify_Exception --
68 ----------------------
70 -- This function identifies the Ada exception to be raised using
71 -- the information when the system received a synchronous signal.
72 -- Since this function is machine and OS dependent, different code
73 -- has to be provided for different target.
75 procedure Notify_Exception
76 (signo : Signal;
77 info : access siginfo_t;
78 context : access ucontext_t);
80 procedure Notify_Exception
81 (signo : Signal;
82 info : access siginfo_t;
83 context : access ucontext_t) is
84 begin
85 -- Check that treatment of exception propagation here
86 -- is consistent with treatment of the abort signal in
87 -- System.Task_Primitives.Operations.
89 case signo is
90 when SIGFPE =>
91 case info.si_code is
92 when FPE_INTDIV |
93 FPE_INTOVF |
94 FPE_FLTDIV |
95 FPE_FLTOVF |
96 FPE_FLTUND |
97 FPE_FLTRES |
98 FPE_FLTINV |
99 FPE_FLTSUB =>
101 raise Constraint_Error;
103 when others =>
104 pragma Assert (False);
105 null;
106 end case;
108 when SIGILL | SIGSEGV | SIGBUS =>
109 raise Storage_Error;
111 when others =>
112 pragma Assert (False);
113 null;
114 end case;
115 end Notify_Exception;
117 ---------------------------
118 -- Initialize_Interrupts --
119 ---------------------------
121 -- Nothing needs to be done on this platform.
123 procedure Initialize_Interrupts is
124 begin
125 null;
126 end Initialize_Interrupts;
128 ----------------------------
129 -- Package Initialization --
130 ----------------------------
132 begin
133 declare
134 act : aliased struct_sigaction;
135 old_act : aliased struct_sigaction;
136 mask : aliased sigset_t;
137 Result : Interfaces.C.int;
139 begin
140 -- Need to call pthread_init very early because it is doing signal
141 -- initializations.
143 pthread_init;
145 -- Change this if you want to use another signal for task abort.
146 -- SIGTERM might be a good one.
148 Abort_Task_Interrupt := SIGABRT;
150 act.sa_handler := Notify_Exception'Address;
152 -- Set sa_flags to SA_NODEFER so that during the handler execution
153 -- we do not change the Signal_Mask to be masked for the Signal.
154 -- This is a temporary fix to the problem that the Signal_Mask is
155 -- not restored after the exception (longjmp) from the handler.
156 -- The right fix should be made in sigsetjmp so that we save
157 -- the Signal_Set and restore it after a longjmp.
159 -- In that case, this field should be changed back to 0. ??? (Dong-Ik)
161 act.sa_flags := 16;
163 Result := sigemptyset (mask'Access);
164 pragma Assert (Result = 0);
166 -- ??? For the same reason explained above, we can't mask these
167 -- signals because otherwise we won't be able to catch more than
168 -- one signal.
170 act.sa_mask := mask;
172 Keep_Unmasked (Abort_Task_Interrupt) := True;
174 -- By keeping SIGINT unmasked, allow the user to do a Ctrl-C, but in the
175 -- same time, disable the ability of handling this signal
176 -- via Ada.Interrupts.
177 -- The pragma Unreserve_All_Interrupts let the user the ability to
178 -- change this behavior.
180 if Unreserve_All_Interrupts = 0 then
181 Keep_Unmasked (SIGINT) := True;
182 end if;
184 for J in Exception_Interrupts'Range loop
185 Keep_Unmasked (Exception_Interrupts (J)) := True;
186 Result :=
187 sigaction
188 (Signal (Exception_Interrupts (J)), act'Unchecked_Access,
189 old_act'Unchecked_Access);
190 pragma Assert (Result = 0);
191 end loop;
193 for J in Unmasked'Range loop
194 Keep_Unmasked (Interrupt_ID (Unmasked (J))) := True;
195 end loop;
197 Reserve := Keep_Unmasked or Keep_Masked;
199 for J in Reserved'Range loop
200 Reserve (Interrupt_ID (Reserved (J))) := True;
201 end loop;
203 -- We do not have Signal 0 in reality. We just use this value
204 -- to identify not existing signals (see s-intnam.ads). Therefore,
205 -- Signal 0 should not be used in all signal related operations hence
206 -- mark it as reserved.
208 Reserve (0) := True;
209 end;
210 end System.Interrupt_Management;