PR middle-end/20297
[official-gcc.git] / gcc / ada / s-soflin.ads
blob2abe631a41823ae827dc49cc013c6a01f366d5d4
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 whether
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 Warnings (Off);
47 pragma Preelaborate_05;
48 pragma Warnings (On);
50 subtype EOA is Ada.Exceptions.Exception_Occurrence_Access;
51 subtype EO is Ada.Exceptions.Exception_Occurrence;
53 function Current_Target_Exception return EO;
54 pragma Import
55 (Ada, Current_Target_Exception,
56 "__gnat_current_target_exception");
57 -- Import this subprogram from the private part of Ada.Exceptions
59 -- First we have the access subprogram types used to establish the links.
60 -- The approach is to establish variables containing access subprogram
61 -- values which by default point to dummy no tasking versions of routines.
63 type No_Param_Proc is access procedure;
64 type Addr_Param_Proc is access procedure (Addr : Address);
65 type EO_Param_Proc is access procedure (Excep : EO);
67 type Get_Address_Call is access function return Address;
68 type Set_Address_Call is access procedure (Addr : Address);
69 type Set_Address_Call2 is access procedure
70 (Self_ID : Address; Addr : Address);
72 type Get_Integer_Call is access function return Integer;
73 type Set_Integer_Call is access procedure (Len : Integer);
75 type Get_EOA_Call is access function return EOA;
76 type Set_EOA_Call is access procedure (Excep : EOA);
77 type Set_EO_Call is access procedure (Excep : EO);
79 type Special_EO_Call is access
80 procedure (Excep : EO := Current_Target_Exception);
82 type Timed_Delay_Call is access
83 procedure (Time : Duration; Mode : Integer);
85 type Get_Stack_Access_Call is access
86 function return Stack_Checking.Stack_Access;
88 type Task_Name_Call is access
89 function return String;
91 -- Suppress checks on all these types, since we know corrresponding
92 -- values can never be null (the soft links are always initialized).
94 pragma Suppress (Access_Check, No_Param_Proc);
95 pragma Suppress (Access_Check, Addr_Param_Proc);
96 pragma Suppress (Access_Check, EO_Param_Proc);
97 pragma Suppress (Access_Check, Get_Address_Call);
98 pragma Suppress (Access_Check, Set_Address_Call);
99 pragma Suppress (Access_Check, Set_Address_Call2);
100 pragma Suppress (Access_Check, Get_Integer_Call);
101 pragma Suppress (Access_Check, Set_Integer_Call);
102 pragma Suppress (Access_Check, Get_EOA_Call);
103 pragma Suppress (Access_Check, Set_EOA_Call);
104 pragma Suppress (Access_Check, Timed_Delay_Call);
105 pragma Suppress (Access_Check, Get_Stack_Access_Call);
106 pragma Suppress (Access_Check, Task_Name_Call);
108 -- The following one is not related to tasking/no-tasking but to the
109 -- traceback decorators for exceptions.
111 type Traceback_Decorator_Wrapper_Call is access
112 function (Traceback : System.Address;
113 Len : Natural)
114 return String;
116 -- Declarations for the no tasking versions of the required routines
118 procedure Abort_Defer_NT;
119 -- Defer task abort (non-tasking case, does nothing)
121 procedure Abort_Undefer_NT;
122 -- Undefer task abort (non-tasking case, does nothing)
124 procedure Abort_Handler_NT;
125 -- Handle task abort (non-tasking case, does nothing). Currently, only VMS
126 -- uses this.
128 procedure Update_Exception_NT (X : EO := Current_Target_Exception);
129 -- Handle exception setting. This routine is provided for targets which
130 -- have built-in exception handling such as the Java Virtual Machine.
131 -- Currently, only JGNAT uses this. See 4jexcept.ads for an explanation on
132 -- how this routine is used.
134 function Check_Abort_Status_NT return Integer;
135 -- Returns Boolean'Pos (True) iff abort signal should raise
136 -- Standard.Abort_Signal.
138 procedure Task_Lock_NT;
139 -- Lock out other tasks (non-tasking case, does nothing)
141 procedure Task_Unlock_NT;
142 -- Release lock set by Task_Lock (non-tasking case, does nothing)
144 procedure Task_Termination_NT (Excep : EO);
145 -- Handle task termination routines for the environment task (non-tasking
146 -- case, does nothing).
148 procedure Null_Finalize_Global_List;
149 -- Finalize global list for controlled objects (does nothing)
151 procedure Adafinal_NT;
152 -- Shuts down the runtime system (non-tasking case)
154 Abort_Defer : No_Param_Proc := Abort_Defer_NT'Access;
155 pragma Suppress (Access_Check, Abort_Defer);
156 -- Defer task abort (task/non-task case as appropriate)
158 Abort_Undefer : No_Param_Proc := Abort_Undefer_NT'Access;
159 pragma Suppress (Access_Check, Abort_Undefer);
160 -- Undefer task abort (task/non-task case as appropriate)
162 Abort_Handler : No_Param_Proc := Abort_Handler_NT'Access;
163 -- Handle task abort (task/non-task case as appropriate)
165 Update_Exception : Special_EO_Call := Update_Exception_NT'Access;
166 -- Handle exception setting and tasking polling when appropriate
168 Check_Abort_Status : Get_Integer_Call := Check_Abort_Status_NT'Access;
169 -- Called when Abort_Signal is delivered to the process. Checks to
170 -- see if signal should result in raising Standard.Abort_Signal.
172 Lock_Task : No_Param_Proc := Task_Lock_NT'Access;
173 -- Locks out other tasks. Preceding a section of code by Task_Lock and
174 -- following it by Task_Unlock creates a critical region. This is used
175 -- for ensuring that a region of non-tasking code (such as code used to
176 -- allocate memory) is tasking safe. Note that it is valid for calls to
177 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
178 -- only the corresponding outer level Task_Unlock will actually unlock.
179 -- This routine also prevents against asynchronous aborts (abort is
180 -- deferred).
182 Unlock_Task : No_Param_Proc := Task_Unlock_NT'Access;
183 -- Releases lock previously set by call to Lock_Task. In the nested case,
184 -- all nested locks must be released before other tasks competing for the
185 -- tasking lock are released.
187 -- In the non nested case, this routine terminates the protection against
188 -- asynchronous aborts introduced by Lock_Task (unless abort was already
189 -- deferred before the call to Lock_Task (e.g in a protected procedures).
191 -- Note: the recommended protocol for using Lock_Task and Unlock_Task
192 -- is as follows:
194 -- Locked_Processing : begin
195 -- System.Soft_Links.Lock_Task.all;
196 -- ...
197 -- System.Soft_Links..Unlock_Task.all;
199 -- exception
200 -- when others =>
201 -- System.Soft_Links..Unlock_Task.all;
202 -- raise;
203 -- end Locked_Processing;
205 -- This ensures that the lock is not left set if an exception is raised
206 -- explicitly or implicitly during the critical locked region.
208 Task_Termination_Handler : EO_Param_Proc := Task_Termination_NT'Access;
209 -- Handle task termination routines (task/non-task case as appropriate)
211 Finalize_Global_List : No_Param_Proc := Null_Finalize_Global_List'Access;
212 -- Performs finalization of global list for controlled objects
214 Adafinal : No_Param_Proc := Adafinal_NT'Access;
215 -- Performs the finalization of the Ada Runtime
217 function Get_Jmpbuf_Address_NT return Address;
218 procedure Set_Jmpbuf_Address_NT (Addr : Address);
220 Get_Jmpbuf_Address : Get_Address_Call := Get_Jmpbuf_Address_NT'Access;
221 Set_Jmpbuf_Address : Set_Address_Call := Set_Jmpbuf_Address_NT'Access;
223 function Get_Sec_Stack_Addr_NT return Address;
224 procedure Set_Sec_Stack_Addr_NT (Addr : Address);
226 Get_Sec_Stack_Addr : Get_Address_Call := Get_Sec_Stack_Addr_NT'Access;
227 Set_Sec_Stack_Addr : Set_Address_Call := Set_Sec_Stack_Addr_NT'Access;
229 function Get_Exc_Stack_Addr_NT return Address;
230 Get_Exc_Stack_Addr : Get_Address_Call := Get_Exc_Stack_Addr_NT'Access;
232 function Get_Current_Excep_NT return EOA;
234 Get_Current_Excep : Get_EOA_Call := Get_Current_Excep_NT'Access;
236 function Get_Stack_Info_NT return Stack_Checking.Stack_Access;
238 Get_Stack_Info : Get_Stack_Access_Call := Get_Stack_Info_NT'Access;
240 --------------------------
241 -- Master_Id Soft-Links --
242 --------------------------
244 -- Soft-Links are used for procedures that manipulate Master_Ids because
245 -- a Master_Id must be generated for access to limited class-wide types,
246 -- whose root may be extended with task components.
248 function Current_Master_NT return Integer;
249 procedure Enter_Master_NT;
250 procedure Complete_Master_NT;
252 Current_Master : Get_Integer_Call := Current_Master_NT'Access;
253 Enter_Master : No_Param_Proc := Enter_Master_NT'Access;
254 Complete_Master : No_Param_Proc := Complete_Master_NT'Access;
256 ----------------------
257 -- Delay Soft-Links --
258 ----------------------
260 -- Soft-Links are used for procedures that manipulate time to avoid
261 -- dragging the tasking run time when using delay statements.
263 Timed_Delay : Timed_Delay_Call;
265 --------------------------
266 -- Task Name Soft-Links --
267 --------------------------
269 function Task_Name_NT return String;
271 Task_Name : Task_Name_Call := Task_Name_NT'Access;
273 -------------------------------------
274 -- Exception Tracebacks Soft-Links --
275 -------------------------------------
277 Traceback_Decorator_Wrapper : Traceback_Decorator_Wrapper_Call;
278 -- Wrapper to the possible user specified traceback decorator to be
279 -- called during automatic output of exception data.
281 -- The nullity of this wrapper shall correspond to the nullity of the
282 -- current actual decorator. This is ensured first by the null initial
283 -- value of the corresponding variables, and then by Set_Trace_Decorator
284 -- in g-exctra.adb.
286 pragma Atomic (Traceback_Decorator_Wrapper);
287 -- Since concurrent read/write operations may occur on this variable.
288 -- See the body of Tailored_Exception_Traceback in Ada.Exceptions for
289 -- a more detailed description of the potential problems.
291 ------------------------
292 -- Task Specific Data --
293 ------------------------
295 -- Here we define a single type that encapsulates the various task
296 -- specific data. This type is used to store the necessary data into
297 -- the Task_Control_Block or into a global variable in the non tasking
298 -- case.
300 type TSD is record
301 Pri_Stack_Info : aliased Stack_Checking.Stack_Info;
302 -- Information on stack (Base/Limit/Size) that is used
303 -- by System.Stack_Checking. If this TSD does not belong to
304 -- the environment task, the Size field must be initialized
305 -- to the tasks requested stack size before the task can do
306 -- its first stack check.
308 pragma Warnings (Off);
309 Jmpbuf_Address : System.Address := System.Null_Address;
310 -- Address of jump buffer used to store the address of the
311 -- current longjmp/setjmp buffer for exception management.
312 -- These buffers are threaded into a stack, and the address
313 -- here is the top of the stack. A null address means that
314 -- no exception handler is currently active.
316 Sec_Stack_Addr : System.Address := System.Null_Address;
317 pragma Warnings (On);
318 -- Address of currently allocated secondary stack
320 Current_Excep : aliased EO;
321 -- Exception occurrence that contains the information for the
322 -- current exception. Note that any exception in the same task
323 -- destroys this information, so the data in this variable must
324 -- be copied out before another exception can occur.
326 -- Also act as a list of the active exceptions in the case of the GCC
327 -- exception mechanism, organized as a stack with the most recent first.
328 end record;
330 procedure Create_TSD (New_TSD : in out TSD);
331 pragma Inline (Create_TSD);
332 -- Called from s-tassta when a new thread is created to perform
333 -- any required initialization of the TSD.
335 procedure Destroy_TSD (Old_TSD : in out TSD);
336 pragma Inline (Destroy_TSD);
337 -- Called from s-tassta just before a thread is destroyed to perform
338 -- any required finalization.
340 function Get_GNAT_Exception return Ada.Exceptions.Exception_Id;
341 pragma Inline (Get_GNAT_Exception);
342 -- This function obtains the Exception_Id from the Exception_Occurrence
343 -- referenced by the Current_Excep field of the task specific data, i.e.
344 -- the call is equivalent to
345 -- Exception_Identity (Get_Current_Exception.all)
347 -- Export the Get/Set routines for the various Task Specific Data (TSD)
348 -- elements as callable subprograms instead of objects of access to
349 -- subprogram types.
351 function Get_Jmpbuf_Address_Soft return Address;
352 procedure Set_Jmpbuf_Address_Soft (Addr : Address);
353 pragma Inline (Get_Jmpbuf_Address_Soft);
354 pragma Inline (Set_Jmpbuf_Address_Soft);
356 function Get_Sec_Stack_Addr_Soft return Address;
357 procedure Set_Sec_Stack_Addr_Soft (Addr : Address);
358 pragma Inline (Get_Sec_Stack_Addr_Soft);
359 pragma Inline (Set_Sec_Stack_Addr_Soft);
361 function Get_Exc_Stack_Addr_Soft return Address;
363 end System.Soft_Links;