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 --
9 -- Copyright (C) 1991-2002, Florida State University --
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. --
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. --
29 -- GNARL was developed by the GNARL team at Florida State University. It is --
30 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
31 -- State University (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 -- This is the default version of this package
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 -- See the other warnings in the package specification before making
43 -- any modifications to this file.
45 -- Make a careful study of all signals available under the OS, to see which
46 -- need to be reserved, kept always unmasked, or kept always unmasked. Be on
47 -- the lookout for special signals that may be used by the thread library.
49 -- Since this is a multi target file, the signal <-> exception mapping
50 -- is simple minded. If you need a more precise and target specific
51 -- signal handling, create a new s-intman.adb that will fit your needs.
53 -- This file assumes that:
55 -- SIGFPE, SIGILL, SIGSEGV and SIGBUS exist. They are mapped as follows:
56 -- SIGPFE => Constraint_Error
57 -- SIGILL => Program_Error
58 -- SIGSEGV => Storage_Error
59 -- SIGBUS => Storage_Error
61 -- SIGINT exists and will be kept unmasked unless the pragma
62 -- Unreserve_All_Interrupts is specified anywhere in the application.
64 -- System.OS_Interface contains the following:
65 -- SIGADAABORT: the signal that will be used to abort tasks.
66 -- Unmasked: the OS specific set of signals that should be unmasked in
67 -- all the threads. SIGADAABORT is unmasked by
69 -- Reserved: the OS specific set of signals that are reserved.
72 -- used for int and other types
74 with System
.OS_Interface
;
75 -- used for various Constants, Signal and types
77 package body System
.Interrupt_Management
is
80 use System
.OS_Interface
;
82 type Interrupt_List
is array (Interrupt_ID
range <>) of Interrupt_ID
;
83 Exception_Interrupts
: constant Interrupt_List
:=
84 (SIGFPE
, SIGILL
, SIGSEGV
, SIGBUS
);
86 Unreserve_All_Interrupts
: Interfaces
.C
.int
;
88 (C
, Unreserve_All_Interrupts
, "__gl_unreserve_all_interrupts");
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Notify_Exception
(signo
: Signal
);
95 -- This function identifies the Ada exception to be raised using
96 -- the information when the system received a synchronous signal.
97 -- Since this function is machine and OS dependent, different code
98 -- has to be provided for different target.
100 ----------------------
101 -- Notify_Exception --
102 ----------------------
104 Signal_Mask
: aliased sigset_t
;
105 -- The set of signals handled by Notify_Exception
107 procedure Notify_Exception
(signo
: Signal
) is
108 Result
: Interfaces
.C
.int
;
111 -- With the __builtin_longjmp, the signal mask is not restored, so we
112 -- need to restore it explicitly.
114 Result
:= pthread_sigmask
(SIG_UNBLOCK
, Signal_Mask
'Access, null);
115 pragma Assert
(Result
= 0);
117 -- Check that treatment of exception propagation here
118 -- is consistent with treatment of the abort signal in
119 -- System.Task_Primitives.Operations.
123 raise Constraint_Error
;
133 end Notify_Exception
;
135 ---------------------------
136 -- Initialize_Interrupts --
137 ---------------------------
139 -- Nothing needs to be done on this platform.
141 procedure Initialize_Interrupts
is
144 end Initialize_Interrupts
;
146 -------------------------
147 -- Package Elaboration --
148 -------------------------
152 act
: aliased struct_sigaction
;
153 old_act
: aliased struct_sigaction
;
154 Result
: Interfaces
.C
.int
;
157 -- Need to call pthread_init very early because it is doing signal
162 Abort_Task_Interrupt
:= SIGADAABORT
;
164 act
.sa_handler
:= Notify_Exception
'Address;
168 -- On some targets, we set sa_flags to SA_NODEFER so that during the
169 -- handler execution we do not change the Signal_Mask to be masked for
172 -- This is a temporary fix to the problem that the Signal_Mask is
173 -- not restored after the exception (longjmp) from the handler.
174 -- The right fix should be made in sigsetjmp so that we save
175 -- the Signal_Set and restore it after a longjmp.
177 -- Since SA_NODEFER is obsolete, instead we reset explicitly
178 -- the mask in the exception handler.
180 Result
:= sigemptyset
(Signal_Mask
'Access);
181 pragma Assert
(Result
= 0);
183 -- ??? For the same reason explained above, we can't mask these
184 -- signals because otherwise we won't be able to catch more than
187 act
.sa_mask
:= Signal_Mask
;
189 Keep_Unmasked
(Abort_Task_Interrupt
) := True;
191 -- By keeping SIGINT unmasked, allow the user to do a Ctrl-C, but at
192 -- the same time, disable the ability of handling this signal via
193 -- package Ada.Interrupts.
195 -- The pragma Unreserve_All_Interrupts let the user the ability to
196 -- change this behavior.
198 if Unreserve_All_Interrupts
= 0 then
199 Keep_Unmasked
(SIGINT
) := True;
202 for J
in Exception_Interrupts
'Range loop
203 Keep_Unmasked
(Exception_Interrupts
(J
)) := True;
207 (Signal
(Exception_Interrupts
(J
)), act
'Unchecked_Access,
208 old_act
'Unchecked_Access);
209 pragma Assert
(Result
= 0);
212 for J
in Unmasked
'Range loop
213 Keep_Unmasked
(Interrupt_ID
(Unmasked
(J
))) := True;
216 Reserve
:= Keep_Unmasked
or Keep_Masked
;
218 for J
in Reserved
'Range loop
219 Reserve
(Interrupt_ID
(Reserved
(J
))) := True;
222 -- We do not have Signal 0 in reality. We just use this value
223 -- to identify non-existent signals (see s-intnam.ads). Therefore,
224 -- Signal 0 should not be used in all signal related operations hence
225 -- mark it as reserved.
229 end System
.Interrupt_Management
;