OSDN Git Service

* output.h (init_section, fini_section): Delete.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-intman-irix-athread.adb
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-2005, 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 ------------------------------------------------------------------------------
34
35 --  This is an Irix (old pthread library) version of this package.
36
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
41 --  Be on the lookout for special signals that
42 --  may be used by the thread library.
43
44 with System.OS_Interface;
45 --  used for various Constants, Signal and types
46
47 with Interfaces.C;
48 --  used for "int"
49
50 package body System.Interrupt_Management is
51
52    use System.OS_Interface;
53
54    type Interrupt_List is array (Interrupt_ID range <>) of Interrupt_ID;
55
56    Exception_Interrupts : constant Interrupt_List :=
57      (SIGILL,
58       SIGABRT,
59       SIGFPE,
60       SIGSEGV,
61       SIGBUS);
62
63    Reserved_Interrupts : constant Interrupt_List :=
64      (0,
65       SIGTRAP,
66       SIGKILL,
67       SIGSYS,
68       SIGALRM,
69       SIGSTOP,
70       SIGPTINTR,
71       SIGPTRESCHED);
72
73    Abort_Signal : constant := 48;
74    --
75    --  Serious MOJO:  The SGI pthreads library only supports the
76    --                 unnamed signal number 48 for pthread_kill!
77    --
78
79    Unreserve_All_Interrupts : Interfaces.C.int;
80    pragma Import
81      (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
82
83    function State (Int : Interrupt_ID) return Character;
84    pragma Import (C, State, "__gnat_get_interrupt_state");
85    --  Get interrupt state.  Defined in a-init.c
86    --  The input argument is the interrupt number,
87    --  and the result is one of the following:
88
89    User    : constant Character := 'u';
90    Runtime : constant Character := 'r';
91    Default : constant Character := 's';
92    --    'n'   this interrupt not set by any Interrupt_State pragma
93    --    'u'   Interrupt_State pragma set state to User
94    --    'r'   Interrupt_State pragma set state to Runtime
95    --    's'   Interrupt_State pragma set state to System (use "default"
96    --           system handler)
97
98    ----------------
99    -- Initialize --
100    ----------------
101
102    procedure Initialize is
103       use Interfaces.C;
104    begin
105       Abort_Task_Interrupt := Abort_Signal;
106
107       pragma Assert (Keep_Unmasked = (Interrupt_ID'Range => False));
108       pragma Assert (Reserve = (Interrupt_ID'Range => False));
109
110       --  Process state of exception signals
111
112       for J in Exception_Interrupts'Range loop
113          if State (Exception_Interrupts (J)) /= User then
114             Keep_Unmasked (Exception_Interrupts (J)) := True;
115             Reserve (Exception_Interrupts (J)) := True;
116          end if;
117       end loop;
118
119       if State (Abort_Task_Interrupt) /= User then
120          Keep_Unmasked (Abort_Task_Interrupt) := True;
121          Reserve (Abort_Task_Interrupt) := True;
122       end if;
123
124       --  Set SIGINT to unmasked state as long as it's
125       --  not in "User" state.  Check for Unreserve_All_Interrupts last
126
127       if State (SIGINT) /= User then
128          Keep_Unmasked (SIGINT) := True;
129       end if;
130
131       --  Check all signals for state that requires keeping them
132       --  unmasked and reserved
133
134       for J in Interrupt_ID'Range loop
135          if State (J) = Default or else State (J) = Runtime then
136             Keep_Unmasked (J) := True;
137             Reserve (J) := True;
138          end if;
139       end loop;
140
141       --  Add target-specific reserved signals
142
143       for J in Reserved_Interrupts'Range loop
144          Reserve (Interrupt_ID (Reserved_Interrupts (J))) := True;
145       end loop;
146
147       --  Process pragma Unreserve_All_Interrupts. This overrides any
148       --  settings due to pragma Interrupt_State:
149
150       if Unreserve_All_Interrupts /= 0 then
151          Keep_Unmasked (SIGINT) := False;
152          Reserve (SIGINT) := False;
153       end if;
154
155       --  We do not have Signal 0 in reality. We just use this value
156       --  to identify not existing signals (see s-intnam.ads). Therefore,
157       --  Signal 0 should not be used in all signal related operations hence
158       --  mark it as reserved.
159
160       Reserve (0) := True;
161    end Initialize;
162
163 end System.Interrupt_Management;