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 S --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
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. --
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. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
36 -- Any changes to this interface may require corresponding compiler changes.
38 -- This package encapsulates the implementation of interrupt or signal
39 -- handlers. It is logically an extension of the body of Ada.Interrupts.
40 -- It is made a child of System to allow visibility of various
41 -- runtime system internal data and operations.
43 -- See System.Interrupt_Management for core interrupt/signal interfaces.
45 -- These two packages are separated in order to allow
46 -- System.Interrupt_Management to be used without requiring the whole
47 -- tasking implementation to be linked and elaborated.
52 with System.Tasking.Protected_Objects.Entries;
53 -- used for Protection_Entries
55 with System.OS_Interface;
56 -- used for Max_Interrupt
58 package System.Interrupts is
60 pragma Elaborate_Body;
61 -- Comment needed on why this is here ???
63 -------------------------
64 -- Constants and types --
65 -------------------------
67 Default_Interrupt_Priority : constant System.Interrupt_Priority :=
68 System.Interrupt_Priority'Last;
69 -- Default value used when a pragma Interrupt_Handler or Attach_Handler is
70 -- specified without an Interrupt_Priority pragma, see D.3(10).
72 type Ada_Interrupt_ID is range 0 .. System.OS_Interface.Max_Interrupt;
73 -- Avoid inheritance by Ada.Interrupts.Interrupt_ID of unwanted operations
75 type Interrupt_ID is range 0 .. System.OS_Interface.Max_Interrupt;
77 type Parameterless_Handler is access protected procedure;
79 ----------------------
80 -- General services --
81 ----------------------
83 -- Attempt to attach a Handler to an Interrupt to which an Entry is
84 -- already bound will raise a Program_Error.
86 function Is_Reserved (Interrupt : Interrupt_ID) return Boolean;
88 function Is_Entry_Attached (Interrupt : Interrupt_ID) return Boolean;
90 function Is_Handler_Attached (Interrupt : Interrupt_ID) return Boolean;
92 function Current_Handler
93 (Interrupt : Interrupt_ID)
94 return Parameterless_Handler;
96 -- Calling the following procedures with New_Handler = null
97 -- and Static = true means that we want to modify the current handler
98 -- regardless of the previous handler's binding status.
99 -- (i.e. we do not care whether it is a dynamic or static handler)
101 procedure Attach_Handler
102 (New_Handler : Parameterless_Handler;
103 Interrupt : Interrupt_ID;
104 Static : Boolean := False);
106 procedure Exchange_Handler
107 (Old_Handler : out Parameterless_Handler;
108 New_Handler : Parameterless_Handler;
109 Interrupt : Interrupt_ID;
110 Static : Boolean := False);
112 procedure Detach_Handler
113 (Interrupt : Interrupt_ID;
114 Static : Boolean := False);
117 (Interrupt : Interrupt_ID)
118 return System.Address;
120 ---------------------------------
121 -- Interrupt entries services --
122 ---------------------------------
124 -- Routines needed for Interrupt Entries
125 -- Attempt to bind an Entry to an Interrupt to which a Handler is
126 -- already attached will raise a Program_Error.
128 procedure Bind_Interrupt_To_Entry
129 (T : System.Tasking.Task_ID;
130 E : System.Tasking.Task_Entry_Index;
131 Int_Ref : System.Address);
133 procedure Detach_Interrupt_Entries (T : System.Tasking.Task_ID);
134 -- This procedure detaches all the Interrupt Entries bound to a task.
136 -------------------------------
137 -- POSIX.5 signals services --
138 -------------------------------
140 -- Routines needed for POSIX dot5 POSIX_Signals
142 procedure Block_Interrupt (Interrupt : Interrupt_ID);
143 -- Block the Interrupt on the process level
145 procedure Unblock_Interrupt (Interrupt : Interrupt_ID);
147 function Unblocked_By
148 (Interrupt : Interrupt_ID)
149 return System.Tasking.Task_ID;
150 -- It returns the ID of the last Task which Unblocked this Interrupt.
151 -- It returns Null_Task if no tasks have ever requested the
152 -- Unblocking operation or the Interrupt is currently Blocked.
154 function Is_Blocked (Interrupt : Interrupt_ID) return Boolean;
155 -- Comment needed ???
157 procedure Ignore_Interrupt (Interrupt : Interrupt_ID);
158 -- Set the sigacion for the interrupt to SIG_IGN.
160 procedure Unignore_Interrupt (Interrupt : Interrupt_ID);
161 -- Comment needed ???
163 function Is_Ignored (Interrupt : Interrupt_ID) return Boolean;
164 -- Comment needed ???
166 -- Note : Direct calls to sigaction, sigprocmask, thr_sigsetmask or any
167 -- other low-level interface that changes the signal action or signal mask
168 -- needs a careful thought.
170 -- One may acheive the effect of system calls first making RTS blocked
171 -- (by calling Block_Interrupt) for the signal under consideration.
172 -- This will make all the tasks in RTS blocked for the Interrupt.
174 ----------------------
175 -- Protection types --
176 ----------------------
178 -- Routines and types needed to implement Interrupt_Handler and
181 -- There are two kinds of protected objects that deal with interrupts:
183 -- (1) Only Interrupt_Handler pragmas are used. We need to be able to
184 -- tell if an Interrupt_Handler applies to a given procedure, so
185 -- Register_Interrupt_Handler has to be called for all the potential
186 -- handlers, it should be done by calling Register_Interrupt_Handler
187 -- with the handler code address. On finalization, which can happen only
188 -- has part of library level finalization since PO with
189 -- Interrupt_Handler pragmas can only be declared at library level,
190 -- nothing special needs to be done since the default handlers have been
191 -- restored as part of task completion which is done just before global
192 -- finalization. Dynamic_Interrupt_Protection should be used in this
195 -- (2) Attach_Handler pragmas are used, and possibly Interrupt_Handler
196 -- pragma. We need to attach the handlers to the given interrupts when
197 -- the objet is elaborated. This should be done by constructing an array
198 -- of pairs (interrupt, handler) from the pragmas and calling
199 -- Install_Handlers with it (types to be used are New_Handler_Item and
200 -- New_Handler_Array). On finalization, we need to restore the handlers
201 -- that were installed before the elaboration of the PO, so we need to
202 -- store these previous handlers. This is also done by Install_Handlers,
203 -- the room for these informations is provided by adding a discriminant
204 -- which is the number of Attach_Handler pragmas and an array of this
205 -- size in the protection type, Static_Interrupt_Protection.
207 procedure Register_Interrupt_Handler
208 (Handler_Addr : System.Address);
209 -- This routine should be called by the compiler to allow the
210 -- handler be used as an Interrupt Handler. That means call this
211 -- procedure for each pragma Interrup_Handler providing the
212 -- address of the handler (not including the pointer to the
213 -- actual PO, this way this routine is called only once for
214 -- each type definition of PO).
216 type Static_Handler_Index is range 0 .. Integer'Last;
217 subtype Positive_Static_Handler_Index is
218 Static_Handler_Index range 1 .. Static_Handler_Index'Last;
219 -- Comment needed ???
221 type Previous_Handler_Item is record
222 Interrupt : Interrupt_ID;
223 Handler : Parameterless_Handler;
226 -- Contains all the information needed to restore a previous handler.
228 type Previous_Handler_Array is array
229 (Positive_Static_Handler_Index range <>) of Previous_Handler_Item;
231 type New_Handler_Item is record
232 Interrupt : Interrupt_ID;
233 Handler : Parameterless_Handler;
235 -- Contains all the information from an Attach_Handler pragma.
237 type New_Handler_Array is
238 array (Positive_Static_Handler_Index range <>) of New_Handler_Item;
239 -- Comment needed ???
243 type Dynamic_Interrupt_Protection is new
244 Tasking.Protected_Objects.Entries.Protection_Entries with null record;
246 -- ??? Finalize is not overloaded since we currently have no
247 -- way to detach the handlers during library level finalization.
249 function Has_Interrupt_Or_Attach_Handler
250 (Object : access Dynamic_Interrupt_Protection) return Boolean;
255 type Static_Interrupt_Protection
256 (Num_Entries : Tasking.Protected_Objects.Protected_Entry_Index;
257 Num_Attach_Handler : Static_Handler_Index)
259 Tasking.Protected_Objects.Entries.Protection_Entries (Num_Entries) with
261 Previous_Handlers : Previous_Handler_Array (1 .. Num_Attach_Handler);
264 function Has_Interrupt_Or_Attach_Handler
265 (Object : access Static_Interrupt_Protection)
269 procedure Finalize (Object : in out Static_Interrupt_Protection);
270 -- Restore previous handlers as required by C.3.1(12) then call
271 -- Finalize (Protection).
273 procedure Install_Handlers
274 (Object : access Static_Interrupt_Protection;
275 New_Handlers : in New_Handler_Array);
276 -- Store the old handlers in Object.Previous_Handlers and install
277 -- the new static handlers.
279 end System.Interrupts;