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-2009, 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 the SuSV3 threads 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. Be on
36 -- the lookout for special signals that may be used by the thread library.
38 -- Since this is a multi target file, the signal <-> exception mapping
39 -- is simple minded. If you need a more precise and target specific
40 -- signal handling, create a new s-intman.adb that will fit your needs.
42 -- This file assumes that:
44 -- SIGINT exists and will be kept unmasked unless the pragma
45 -- Unreserve_All_Interrupts is specified anywhere in the application.
47 -- System.OS_Interface contains the following:
48 -- SIGADAABORT: the signal that will be used to abort tasks.
49 -- Unmasked: the OS specific set of signals that should be unmasked in
50 -- all the threads. SIGADAABORT is unmasked by
52 -- Reserved: the OS specific set of signals that are reserved.
54 package body System
.Interrupt_Management
is
57 use System
.OS_Interface
;
59 Unreserve_All_Interrupts
: Interfaces
.C
.int
;
61 (C
, Unreserve_All_Interrupts
, "__gl_unreserve_all_interrupts");
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function State
(Int
: Interrupt_ID
) return Character;
68 pragma Import
(C
, State
, "__gnat_get_interrupt_state");
69 -- Get interrupt state. Defined in init.c The input argument is the
70 -- interrupt number, and the result is one of the following:
72 User
: constant Character := 'u';
73 Runtime
: constant Character := 'r';
74 Default
: constant Character := 's';
75 -- 'n' this interrupt not set by any Interrupt_State pragma
76 -- 'u' Interrupt_State pragma set state to User
77 -- 'r' Interrupt_State pragma set state to Runtime
78 -- 's' Interrupt_State pragma set state to System (use "default"
85 Initialized
: Boolean := False;
87 procedure Initialize
is
95 -- Need to call pthread_init very early because it is doing signal
100 Abort_Task_Interrupt
:= SIGADAABORT
;
102 pragma Assert
(Keep_Unmasked
= (Interrupt_ID
'Range => False));
103 pragma Assert
(Reserve
= (Interrupt_ID
'Range => False));
105 -- Process state of exception signals
107 for J
in Exception_Signals
'Range loop
109 Sig
: constant Signal
:= Exception_Signals
(J
);
110 Id
: constant Interrupt_ID
:= Interrupt_ID
(Sig
);
112 if State
(Id
) /= User
then
113 Keep_Unmasked
(Id
) := True;
114 Reserve
(Id
) := True;
119 if State
(Abort_Task_Interrupt
) /= User
then
120 Keep_Unmasked
(Abort_Task_Interrupt
) := True;
121 Reserve
(Abort_Task_Interrupt
) := True;
124 -- Set SIGINT to unmasked state as long as it is not in "User" state.
125 -- Check for Unreserve_All_Interrupts last.
127 if State
(SIGINT
) /= User
then
128 Keep_Unmasked
(SIGINT
) := True;
129 Reserve
(SIGINT
) := True;
132 -- Check all signals for state that requires keeping them unmasked and
135 for J
in Interrupt_ID
'Range loop
136 if State
(J
) = Default
or else State
(J
) = Runtime
then
137 Keep_Unmasked
(J
) := True;
142 -- Add the set of signals that must always be unmasked for this target
144 for J
in Unmasked
'Range loop
145 Keep_Unmasked
(Interrupt_ID
(Unmasked
(J
))) := True;
146 Reserve
(Interrupt_ID
(Unmasked
(J
))) := True;
149 -- Add target-specific reserved signals
151 for J
in Reserved
'Range loop
152 Reserve
(Interrupt_ID
(Reserved
(J
))) := True;
155 -- Process pragma Unreserve_All_Interrupts. This overrides any settings
156 -- due to pragma Interrupt_State:
158 if Unreserve_All_Interrupts
/= 0 then
159 Keep_Unmasked
(SIGINT
) := False;
160 Reserve
(SIGINT
) := False;
163 -- We do not really have Signal 0. We just use this value to identify
164 -- non-existent signals (see s-intnam.ads). Therefore, Signal should not
165 -- be used in all signal related operations hence mark it as reserved.
170 end System
.Interrupt_Management
;