OSDN Git Service

PR bootstrap/11932
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5fintman.adb
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) 1991-1994, Florida State University            --
10 --             Copyright (C) 1995-2003, Ada Core Technologies               --
11 --                                                                          --
12 -- GNARL is free software; you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNARL was developed by the GNARL team at Florida State University.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is a SGI Pthread version of this package.
36
37 --  PLEASE DO NOT add any dependences on other packages.
38 --  This package is designed to work with or without tasking support.
39
40 --  Make a careful study of all signals available under the OS,
41 --  to see which need to be reserved, kept always unmasked,
42 --  or kept always unmasked.
43 --  Be on the lookout for special signals that
44 --  may be used by the thread library.
45
46 with Interfaces.C;
47 --  used for int
48
49 with System.OS_Interface;
50 --  used for various Constants, Signal and types
51
52 package body System.Interrupt_Management is
53
54    use System.OS_Interface;
55
56    type Interrupt_List is array (Interrupt_ID range <>) of Interrupt_ID;
57    Exception_Interrupts : constant Interrupt_List :=
58      (SIGTSTP, SIGILL, SIGTRAP, SIGEMT, SIGFPE, SIGBUS, SIGSTOP, SIGKILL,
59       SIGSEGV, SIGSYS, SIGXCPU, SIGXFSZ, SIGPROF, SIGPTINTR, SIGPTRESCHED,
60       SIGABRT, SIGPIPE);
61
62    ---------------------------
63    -- Initialize_Interrupts --
64    ---------------------------
65
66    --  Nothing needs to be done on this platform
67
68    procedure Initialize_Interrupts is
69    begin
70       null;
71    end Initialize_Interrupts;
72
73    Unreserve_All_Interrupts : Interfaces.C.int;
74    pragma Import
75      (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
76
77    use type Interfaces.C.int;
78
79 begin
80    declare
81       function State (Int : Interrupt_ID) return Character;
82       pragma Import (C, State, "__gnat_get_interrupt_state");
83
84       --  Get interrupt state.  Defined in a-init.c
85       --  The input argument is the interrupt number,
86       --  and the result is one of the following:
87
88       User    : constant Character := 'u';
89       Runtime : constant Character := 'r';
90       Default : constant Character := 's';
91       --    'n'   this interrupt not set by any Interrupt_State pragma
92       --    'u'   Interrupt_State pragma set state to User
93       --    'r'   Interrupt_State pragma set state to Runtime
94       --    's'   Interrupt_State pragma set state to System (use "default"
95       --           system handler)
96
97    begin
98       Abort_Task_Interrupt := SIGABRT;
99
100       --  Change this if you want to use another signal for task abort.
101       --  SIGTERM might be a good one.
102
103       pragma Assert (Keep_Unmasked = (Interrupt_ID'Range => False));
104       pragma Assert (Reserve = (Interrupt_ID'Range => False));
105
106       --  Process state of exception signals
107
108       for J in Exception_Interrupts'Range loop
109          if State (Exception_Interrupts (J)) /= User then
110             Keep_Unmasked (Exception_Interrupts (J)) := True;
111             Reserve (Exception_Interrupts (J)) := True;
112          end if;
113       end loop;
114
115       if State (Abort_Task_Interrupt) /= User then
116          Keep_Unmasked (Abort_Task_Interrupt) := True;
117          Reserve (Abort_Task_Interrupt) := True;
118       end if;
119
120       --  Set SIGINT to unmasked state as long as it's
121       --  not in "User" state.  Check for Unreserve_All_Interrupts last
122
123       if State (SIGINT) /= User then
124          Keep_Unmasked (SIGINT) := True;
125       end if;
126
127       --  Check all signals for state that requires keeping them
128       --  unmasked and reserved
129
130       for J in Interrupt_ID'Range loop
131          if State (J) = Default or else State (J) = Runtime then
132             Keep_Unmasked (J) := True;
133             Reserve (J) := True;
134          end if;
135       end loop;
136
137       --  Process pragma Unreserve_All_Interrupts. This overrides any
138       --  settings due to pragma Interrupt_State:
139
140       if Unreserve_All_Interrupts /= 0 then
141          Keep_Unmasked (SIGINT) := False;
142          Reserve (SIGINT) := False;
143       end if;
144
145       --  We do not have Signal 0 in reality. We just use this value
146       --  to identify not existing signals (see s-intnam.ads). Therefore,
147       --  Signal 0 should not be used in all signal related operations hence
148       --  mark it as reserved.
149
150       Reserve (0) := True;
151    end;
152 end System.Interrupt_Management;