Mark ChangeLog
[official-gcc.git] / gcc / ada / s-soflin.ads
blob256039d924b36d48e0d391edc3b24fe2cf2cf164
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . S O F T _ L I N K S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This package contains a set of subprogram access variables that access
35 -- some low-level primitives that are called different depending wether
36 -- tasking is involved or not (e.g. the Get/Set_Jmpbuf_Address that needs
37 -- to provide a different value for each task). To avoid dragging in the
38 -- tasking all the time, we use a system of soft links where the links are
39 -- initialized to non-tasking versions, and then if the tasking is
40 -- initialized, they are reset to the real tasking versions.
42 with Ada.Exceptions;
43 with System.Stack_Checking;
45 package System.Soft_Links is
46 pragma Elaborate_Body;
48 subtype EOA is Ada.Exceptions.Exception_Occurrence_Access;
49 subtype EO is Ada.Exceptions.Exception_Occurrence;
51 function Current_Target_Exception return EO;
52 pragma Import
53 (Ada, Current_Target_Exception,
54 "__gnat_current_target_exception");
55 -- Import this subprogram from the private part of Ada.Exceptions.
57 -- First we have the access subprogram types used to establish the links.
58 -- The approach is to establish variables containing access subprogram
59 -- values which by default point to dummy no tasking versions of routines.
61 type No_Param_Proc is access procedure;
62 type Addr_Param_Proc is access procedure (Addr : Address);
64 type Get_Address_Call is access function return Address;
65 type Set_Address_Call is access procedure (Addr : Address);
66 type Set_Address_Call2 is access procedure
67 (Self_ID : Address; Addr : Address);
69 type Get_Integer_Call is access function return Integer;
70 type Set_Integer_Call is access procedure (Len : Integer);
72 type Get_EOA_Call is access function return EOA;
73 type Set_EOA_Call is access procedure (Excep : EOA);
74 type Set_EO_Call is access procedure (Excep : EO);
76 type Special_EO_Call is access
77 procedure (Excep : EO := Current_Target_Exception);
79 type Timed_Delay_Call is access
80 procedure (Time : Duration; Mode : Integer);
82 type Get_Stack_Access_Call is access
83 function return Stack_Checking.Stack_Access;
85 type Task_Name_Call is access
86 function return String;
88 -- Suppress checks on all these types, since we know corrresponding
89 -- values can never be null (the soft links are always initialized).
91 pragma Suppress (Access_Check, No_Param_Proc);
92 pragma Suppress (Access_Check, Addr_Param_Proc);
93 pragma Suppress (Access_Check, Get_Address_Call);
94 pragma Suppress (Access_Check, Set_Address_Call);
95 pragma Suppress (Access_Check, Set_Address_Call2);
96 pragma Suppress (Access_Check, Get_Integer_Call);
97 pragma Suppress (Access_Check, Set_Integer_Call);
98 pragma Suppress (Access_Check, Get_EOA_Call);
99 pragma Suppress (Access_Check, Set_EOA_Call);
100 pragma Suppress (Access_Check, Timed_Delay_Call);
101 pragma Suppress (Access_Check, Get_Stack_Access_Call);
102 pragma Suppress (Access_Check, Task_Name_Call);
104 -- The following one is not related to tasking/no-tasking but to the
105 -- traceback decorators for exceptions.
107 type Traceback_Decorator_Wrapper_Call is access
108 function (Traceback : System.Address;
109 Len : Natural)
110 return String;
112 -- Declarations for the no tasking versions of the required routines
114 procedure Abort_Defer_NT;
115 -- Defer task abortion (non-tasking case, does nothing)
117 procedure Abort_Undefer_NT;
118 -- Undefer task abortion (non-tasking case, does nothing)
120 procedure Abort_Handler_NT;
121 -- Handle task abortion (non-tasking case, does nothing). Currently,
122 -- only VMS uses this.
124 procedure Update_Exception_NT (X : EO := Current_Target_Exception);
125 -- Handle exception setting. This routine is provided for targets
126 -- which have built-in exception handling such as the Java Virtual
127 -- Machine. Currently, only JGNAT uses this. See 4jexcept.ads for
128 -- an explanation on how this routine is used.
130 function Check_Abort_Status_NT return Integer;
131 -- Returns Boolean'Pos (True) iff abort signal should raise
132 -- Standard.Abort_Signal.
134 procedure Task_Lock_NT;
135 -- Lock out other tasks (non-tasking case, does nothing)
137 procedure Task_Unlock_NT;
138 -- Release lock set by Task_Lock (non-tasking case, does nothing)
140 procedure Null_Adafinal;
141 -- Shuts down the runtime system (non-tasking no-finalization case,
142 -- does nothing)
144 Abort_Defer : No_Param_Proc := Abort_Defer_NT'Access;
145 pragma Suppress (Access_Check, Abort_Defer);
146 -- Defer task abortion (task/non-task case as appropriate)
148 Abort_Undefer : No_Param_Proc := Abort_Undefer_NT'Access;
149 pragma Suppress (Access_Check, Abort_Undefer);
150 -- Undefer task abortion (task/non-task case as appropriate)
152 Abort_Handler : No_Param_Proc := Abort_Handler_NT'Access;
153 -- Handle task abortion (task/non-task case as appropriate)
155 Update_Exception : Special_EO_Call := Update_Exception_NT'Access;
156 -- Handle exception setting and tasking polling when appropriate
158 Check_Abort_Status : Get_Integer_Call := Check_Abort_Status_NT'Access;
159 -- Called when Abort_Signal is delivered to the process. Checks to
160 -- see if signal should result in raising Standard.Abort_Signal.
162 Lock_Task : No_Param_Proc := Task_Lock_NT'Access;
163 -- Locks out other tasks. Preceding a section of code by Task_Lock and
164 -- following it by Task_Unlock creates a critical region. This is used
165 -- for ensuring that a region of non-tasking code (such as code used to
166 -- allocate memory) is tasking safe. Note that it is valid for calls to
167 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
168 -- only the corresponding outer level Task_Unlock will actually unlock.
169 -- This routine also prevents against asynchronous aborts (abort is
170 -- deferred).
172 Unlock_Task : No_Param_Proc := Task_Unlock_NT'Access;
173 -- Releases lock previously set by call to Lock_Task. In the nested case,
174 -- all nested locks must be released before other tasks competing for the
175 -- tasking lock are released.
177 -- In the non nested case, this routine terminates the protection against
178 -- asynchronous aborts introduced by Lock_Task (unless abort was already
179 -- deferred before the call to Lock_Task (e.g in a protected procedures).
181 -- Note: the recommended protocol for using Lock_Task and Unlock_Task
182 -- is as follows:
184 -- Locked_Processing : begin
185 -- System.Soft_Links.Lock_Task.all;
186 -- ...
187 -- System.Soft_Links..Unlock_Task.all;
189 -- exception
190 -- when others =>
191 -- System.Soft_Links..Unlock_Task.all;
192 -- raise;
193 -- end Locked_Processing;
195 -- This ensures that the lock is not left set if an exception is raised
196 -- explicitly or implicitly during the critical locked region.
198 Adafinal : No_Param_Proc := Null_Adafinal'Access;
199 -- Performs the finalization of the Ada Runtime.
201 function Get_Jmpbuf_Address_NT return Address;
202 procedure Set_Jmpbuf_Address_NT (Addr : Address);
204 Get_Jmpbuf_Address : Get_Address_Call := Get_Jmpbuf_Address_NT'Access;
205 Set_Jmpbuf_Address : Set_Address_Call := Set_Jmpbuf_Address_NT'Access;
207 function Get_Sec_Stack_Addr_NT return Address;
208 procedure Set_Sec_Stack_Addr_NT (Addr : Address);
210 Get_Sec_Stack_Addr : Get_Address_Call := Get_Sec_Stack_Addr_NT'Access;
211 Set_Sec_Stack_Addr : Set_Address_Call := Set_Sec_Stack_Addr_NT'Access;
213 function Get_Machine_State_Addr_NT return Address;
214 procedure Set_Machine_State_Addr_NT (Addr : Address);
216 Get_Machine_State_Addr : Get_Address_Call
217 := Get_Machine_State_Addr_NT'Access;
218 Set_Machine_State_Addr : Set_Address_Call
219 := Set_Machine_State_Addr_NT'Access;
221 function Get_Exc_Stack_Addr_NT return Address;
222 procedure Set_Exc_Stack_Addr_NT (Self_ID : Address; Addr : Address);
223 -- Self_ID is a Task_Id, but in the non-tasking case there is no
224 -- Task_Id type available, so make do with Address.
226 Get_Exc_Stack_Addr : Get_Address_Call := Get_Exc_Stack_Addr_NT'Access;
227 Set_Exc_Stack_Addr : Set_Address_Call2 := Set_Exc_Stack_Addr_NT'Access;
229 function Get_Current_Excep_NT return EOA;
231 Get_Current_Excep : Get_EOA_Call := Get_Current_Excep_NT'Access;
233 function Get_Stack_Info_NT return Stack_Checking.Stack_Access;
235 Get_Stack_Info : Get_Stack_Access_Call := Get_Stack_Info_NT'Access;
237 --------------------------
238 -- Master_Id Soft-Links --
239 --------------------------
241 -- Soft-Links are used for procedures that manipulate Master_Ids because
242 -- a Master_Id must be generated for access to limited class-wide types,
243 -- whose root may be extended with task components.
245 function Current_Master_NT return Integer;
246 procedure Enter_Master_NT;
247 procedure Complete_Master_NT;
249 Current_Master : Get_Integer_Call := Current_Master_NT'Access;
250 Enter_Master : No_Param_Proc := Enter_Master_NT'Access;
251 Complete_Master : No_Param_Proc := Complete_Master_NT'Access;
253 ----------------------
254 -- Delay Soft-Links --
255 ----------------------
257 -- Soft-Links are used for procedures that manipulate time to avoid
258 -- dragging the tasking run time when using delay statements.
260 Timed_Delay : Timed_Delay_Call;
262 --------------------------
263 -- Task Name Soft-Links --
264 --------------------------
266 function Task_Name_NT return String;
268 Task_Name : Task_Name_Call := Task_Name_NT'Access;
270 -------------------------------------
271 -- Exception Tracebacks Soft-Links --
272 -------------------------------------
274 Traceback_Decorator_Wrapper : Traceback_Decorator_Wrapper_Call;
275 -- Wrapper to the possible user specified traceback decorator to be
276 -- called during automatic output of exception data.
278 -- The nullity of this wrapper shall correspond to the nullity of the
279 -- current actual decorator. This is ensured first by the null initial
280 -- value of the corresponding variables, and then by Set_Trace_Decorator
281 -- in g-exctra.adb.
283 pragma Atomic (Traceback_Decorator_Wrapper);
284 -- Since concurrent read/write operations may occur on this variable.
285 -- See the body of Tailored_Exception_Traceback in Ada.Exceptions for
286 -- a more detailed description of the potential problems.
288 ------------------------
289 -- Task Specific Data --
290 ------------------------
292 -- Here we define a single type that encapsulates the various task
293 -- specific data. This type is used to store the necessary data into
294 -- the Task_Control_Block or into a global variable in the non tasking
295 -- case.
297 type TSD is record
298 Pri_Stack_Info : aliased Stack_Checking.Stack_Info;
299 -- Information on stack (Base/Limit/Size) that is used
300 -- by System.Stack_Checking. If this TSD does not belong to
301 -- the environment task, the Size field must be initialized
302 -- to the tasks requested stack size before the task can do
303 -- its first stack check.
305 Jmpbuf_Address : Address := Null_Address;
306 -- Address of jump buffer used to store the address of the
307 -- current longjmp/setjmp buffer for exception management.
308 -- These buffers are threaded into a stack, and the address
309 -- here is the top of the stack. A null address means that
310 -- no exception handler is currently active.
312 Sec_Stack_Addr : Address := Null_Address;
313 -- Address of currently allocated secondary stack
315 Exc_Stack_Addr : Address := Null_Address;
316 -- Address of a task-specific stack used for the propagation of
317 -- exceptions in response to synchronous faults. This alternate
318 -- stack is necessary when propagating Storage_Error resulting
319 -- from a stack overflow, as the task's primary stack is full.
320 -- This is currently only used on the SGI, and this value stays
321 -- null on other platforms.
323 Current_Excep : aliased EO;
324 -- Exception occurrence that contains the information for the
325 -- current exception. Note that any exception in the same task
326 -- destroys this information, so the data in this variable must
327 -- be copied out before another exception can occur.
329 -- Also act as a list of the active exceptions in the case of the GCC
330 -- exception mechanism, organized as a stack with the most recent first.
332 Machine_State_Addr : Address := Null_Address;
333 -- Machine state address. Used by front-end zero cost exception
334 end record;
336 procedure Create_TSD (New_TSD : in out TSD);
337 pragma Inline (Create_TSD);
338 -- Called from s-tassta when a new thread is created to perform
339 -- any required initialization of the TSD.
341 procedure Destroy_TSD (Old_TSD : in out TSD);
342 pragma Inline (Destroy_TSD);
343 -- Called from s-tassta just before a thread is destroyed to perform
344 -- any required finalization.
346 function Get_GNAT_Exception return Ada.Exceptions.Exception_Id;
347 pragma Inline (Get_GNAT_Exception);
348 -- This function obtains the Exception_Id from the Exception_Occurrence
349 -- referenced by the Current_Excep field of the task specific data, i.e.
350 -- the call is equivalent to
351 -- Exception_Identity (Get_Current_Exception.all)
353 -- Export the Get/Set routines for the various Task Specific Data (TSD)
354 -- elements as callable subprograms instead of objects of access to
355 -- subprogram types.
357 function Get_Jmpbuf_Address_Soft return Address;
358 procedure Set_Jmpbuf_Address_Soft (Addr : Address);
359 pragma Inline (Get_Jmpbuf_Address_Soft);
360 pragma Inline (Set_Jmpbuf_Address_Soft);
362 function Get_Sec_Stack_Addr_Soft return Address;
363 procedure Set_Sec_Stack_Addr_Soft (Addr : Address);
364 pragma Inline (Get_Sec_Stack_Addr_Soft);
365 pragma Inline (Set_Sec_Stack_Addr_Soft);
367 function Get_Exc_Stack_Addr_Soft return Address;
368 procedure Set_Exc_Stack_Addr_Soft (Self_ID : Address; Addr : Address);
369 pragma Inline (Get_Exc_Stack_Addr_Soft);
370 pragma Inline (Set_Exc_Stack_Addr_Soft);
372 function Get_Machine_State_Addr_Soft return Address;
373 procedure Set_Machine_State_Addr_Soft (Addr : Address);
374 pragma Inline (Get_Machine_State_Addr_Soft);
375 pragma Inline (Set_Machine_State_Addr_Soft);
377 end System.Soft_Links;