Merge from mainline
[official-gcc.git] / gcc / ada / s-intman-irix.adb
blob71efec9721b565cd93c2db54d5d309d481160236
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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-2006, AdaCore --
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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
35 -- This is a SGI Pthread version of this package.
37 -- Make a careful study of all signals available under the OS,
38 -- to see which need to be reserved, kept always unmasked,
39 -- or kept always unmasked.
40 -- Be on the lookout for special signals that
41 -- may be used by the thread library.
43 package body System.Interrupt_Management is
45 use System.OS_Interface;
47 type Interrupt_List is array (Interrupt_ID range <>) of Interrupt_ID;
48 Exception_Interrupts : constant Interrupt_List :=
49 (SIGTSTP, SIGILL, SIGTRAP, SIGEMT, SIGFPE, SIGBUS, SIGSTOP, SIGKILL,
50 SIGSEGV, SIGSYS, SIGXCPU, SIGXFSZ, SIGPROF, SIGPTINTR, SIGPTRESCHED,
51 SIGABRT, SIGPIPE);
53 Unreserve_All_Interrupts : Interfaces.C.int;
54 pragma Import
55 (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
57 function State (Int : Interrupt_ID) return Character;
58 pragma Import (C, State, "__gnat_get_interrupt_state");
60 -- Get interrupt state. Defined in a-init.c
61 -- The input argument is the interrupt number,
62 -- and the result is one of the following:
64 User : constant Character := 'u';
65 Runtime : constant Character := 'r';
66 Default : constant Character := 's';
67 -- 'n' this interrupt not set by any Interrupt_State pragma
68 -- 'u' Interrupt_State pragma set state to User
69 -- 'r' Interrupt_State pragma set state to Runtime
70 -- 's' Interrupt_State pragma set state to System (use "default"
71 -- system handler)
73 ----------------
74 -- Initialize --
75 ----------------
77 Initialized : Boolean := False;
79 procedure Initialize is
80 use type Interfaces.C.int;
81 begin
82 if Initialized then
83 return;
84 end if;
86 Initialized := True;
87 Abort_Task_Interrupt := SIGABRT;
89 -- Change this if you want to use another signal for task abort.
90 -- SIGTERM might be a good one.
92 pragma Assert (Keep_Unmasked = (Interrupt_ID'Range => False));
93 pragma Assert (Reserve = (Interrupt_ID'Range => False));
95 -- Process state of exception signals
97 for J in Exception_Interrupts'Range loop
98 if State (Exception_Interrupts (J)) /= User then
99 Keep_Unmasked (Exception_Interrupts (J)) := True;
100 Reserve (Exception_Interrupts (J)) := True;
101 end if;
102 end loop;
104 if State (Abort_Task_Interrupt) /= User then
105 Keep_Unmasked (Abort_Task_Interrupt) := True;
106 Reserve (Abort_Task_Interrupt) := True;
107 end if;
109 -- Set SIGINT to unmasked state as long as it's
110 -- not in "User" state. Check for Unreserve_All_Interrupts last
112 if State (SIGINT) /= User then
113 Keep_Unmasked (SIGINT) := True;
114 end if;
116 -- Check all signals for state that requires keeping them
117 -- unmasked and reserved
119 for J in Interrupt_ID'Range loop
120 if State (J) = Default or else State (J) = Runtime then
121 Keep_Unmasked (J) := True;
122 Reserve (J) := True;
123 end if;
124 end loop;
126 -- Process pragma Unreserve_All_Interrupts. This overrides any
127 -- settings due to pragma Interrupt_State:
129 if Unreserve_All_Interrupts /= 0 then
130 Keep_Unmasked (SIGINT) := False;
131 Reserve (SIGINT) := False;
132 end if;
134 -- We do not have Signal 0 in reality. We just use this value
135 -- to identify not existing signals (see s-intnam.ads). Therefore,
136 -- Signal 0 should not be used in all signal related operations hence
137 -- mark it as reserved.
139 Reserve (0) := True;
140 end Initialize;
142 end System.Interrupt_Management;