* config/xtensa/linux.h (TARGET_OS_CPP_BUILTINS): Remove definition of
[official-gcc.git] / gcc / ada / s-soflin.ads
blob96d2155c21dcbf5f8b0a384f632429698c5f4c6f
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-2001, 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
125 (X : EO := Current_Target_Exception);
126 -- Handle exception setting. This routine is provided for targets
127 -- which have built-in exception handling such as the Java Virtual
128 -- Machine. Currently, only JGNAT uses this. See 4jexcept.ads for
129 -- an explanation on how this routine is used.
131 function Check_Abort_Status_NT return Integer;
132 -- Returns Boolean'Pos (True) iff abort signal should raise
133 -- Standard.Abort_Signal.
135 procedure Task_Lock_NT;
136 -- Lock out other tasks (non-tasking case, does nothing)
138 procedure Task_Unlock_NT;
139 -- Release lock set by Task_Lock (non-tasking case, does nothing)
141 procedure Null_Adafinal;
142 -- Shuts down the runtime system (non-tasking no-finalization case,
143 -- does nothing)
145 Abort_Defer : No_Param_Proc := Abort_Defer_NT'Access;
146 pragma Suppress (Access_Check, Abort_Defer);
147 -- Defer task abortion (task/non-task case as appropriate)
149 Abort_Undefer : No_Param_Proc := Abort_Undefer_NT'Access;
150 pragma Suppress (Access_Check, Abort_Undefer);
151 -- Undefer task abortion (task/non-task case as appropriate)
153 Abort_Handler : No_Param_Proc := Abort_Handler_NT'Access;
154 -- Handle task abortion (task/non-task case as appropriate)
156 Update_Exception : Special_EO_Call := Update_Exception_NT'Access;
157 -- Handle exception setting and tasking polling when appropriate
159 Check_Abort_Status : Get_Integer_Call := Check_Abort_Status_NT'Access;
160 -- Called when Abort_Signal is delivered to the process. Checks to
161 -- see if signal should result in raising Standard.Abort_Signal.
163 Lock_Task : No_Param_Proc := Task_Lock_NT'Access;
164 -- Locks out other tasks. Preceding a section of code by Task_Lock and
165 -- following it by Task_Unlock creates a critical region. This is used
166 -- for ensuring that a region of non-tasking code (such as code used to
167 -- allocate memory) is tasking safe. Note that it is valid for calls to
168 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
169 -- only the corresponding outer level Task_Unlock will actually unlock.
170 -- This routine also prevents against asynchronous aborts (abort is
171 -- deferred).
173 Unlock_Task : No_Param_Proc := Task_Unlock_NT'Access;
174 -- Releases lock previously set by call to Lock_Task. In the nested case,
175 -- all nested locks must be released before other tasks competing for the
176 -- tasking lock are released.
178 -- In the non nested case, this routine terminates the protection against
179 -- asynchronous aborts introduced by Lock_Task (unless abort was already
180 -- deferred before the call to Lock_Task (e.g in a protected procedures).
182 -- Note: the recommended protocol for using Lock_Task and Unlock_Task
183 -- is as follows:
185 -- Locked_Processing : begin
186 -- System.Soft_Links.Lock_Task.all;
187 -- ...
188 -- System.Soft_Links..Unlock_Task.all;
190 -- exception
191 -- when others =>
192 -- System.Soft_Links..Unlock_Task.all;
193 -- raise;
194 -- end Locked_Processing;
196 -- This ensures that the lock is not left set if an exception is raised
197 -- explicitly or implicitly during the critical locked region.
199 Adafinal : No_Param_Proc := Null_Adafinal'Access;
200 -- Performs the finalization of the Ada Runtime.
202 function Get_Jmpbuf_Address_NT return Address;
203 procedure Set_Jmpbuf_Address_NT (Addr : Address);
205 Get_Jmpbuf_Address : Get_Address_Call := Get_Jmpbuf_Address_NT'Access;
206 Set_Jmpbuf_Address : Set_Address_Call := Set_Jmpbuf_Address_NT'Access;
208 function Get_Sec_Stack_Addr_NT return Address;
209 procedure Set_Sec_Stack_Addr_NT (Addr : Address);
211 Get_Sec_Stack_Addr : Get_Address_Call := Get_Sec_Stack_Addr_NT'Access;
212 Set_Sec_Stack_Addr : Set_Address_Call := Set_Sec_Stack_Addr_NT'Access;
214 function Get_Machine_State_Addr_NT return Address;
215 procedure Set_Machine_State_Addr_NT (Addr : Address);
217 Get_Machine_State_Addr : Get_Address_Call
218 := Get_Machine_State_Addr_NT'Access;
219 Set_Machine_State_Addr : Set_Address_Call
220 := Set_Machine_State_Addr_NT'Access;
222 function Get_Exc_Stack_Addr_NT return Address;
223 procedure Set_Exc_Stack_Addr_NT (Self_ID : Address; Addr : Address);
224 -- Self_ID is a Task_ID, but in the non-tasking case there is no
225 -- Task_ID type available, so make do with Address.
227 Get_Exc_Stack_Addr : Get_Address_Call := Get_Exc_Stack_Addr_NT'Access;
228 Set_Exc_Stack_Addr : Set_Address_Call2 := Set_Exc_Stack_Addr_NT'Access;
230 function Get_Current_Excep_NT return EOA;
232 Get_Current_Excep : Get_EOA_Call := Get_Current_Excep_NT'Access;
234 function Get_Stack_Info_NT return Stack_Checking.Stack_Access;
236 Get_Stack_Info : Get_Stack_Access_Call := Get_Stack_Info_NT'Access;
238 --------------------------
239 -- Master_Id Soft-Links --
240 --------------------------
242 -- Soft-Links are used for procedures that manipulate Master_Ids because
243 -- a Master_Id must be generated for access to limited class-wide types,
244 -- whose root may be extended with task components.
246 function Current_Master_NT return Integer;
247 procedure Enter_Master_NT;
248 procedure Complete_Master_NT;
250 Current_Master : Get_Integer_Call := Current_Master_NT'Access;
251 Enter_Master : No_Param_Proc := Enter_Master_NT'Access;
252 Complete_Master : No_Param_Proc := Complete_Master_NT'Access;
254 ----------------------
255 -- Delay Soft-Links --
256 ----------------------
258 -- Soft-Links are used for procedures that manipulate time to avoid
259 -- dragging the tasking run time when using delay statements.
261 Timed_Delay : Timed_Delay_Call;
263 --------------------------
264 -- Task Name Soft-Links --
265 --------------------------
267 function Task_Name_NT return String;
269 Task_Name : Task_Name_Call := Task_Name_NT'Access;
271 -------------------------------------
272 -- Exception Tracebacks Soft-Links --
273 -------------------------------------
275 Traceback_Decorator_Wrapper : Traceback_Decorator_Wrapper_Call;
276 -- Wrapper to the possible user specified traceback decorator to be
277 -- called during automatic output of exception data.
279 -- The nullity of this wrapper shall correspond to the nullity of the
280 -- current actual decorator. This is ensured first by the null initial
281 -- value of the corresponding variables, and then by Set_Trace_Decorator
282 -- in g-exctra.adb.
284 pragma Atomic (Traceback_Decorator_Wrapper);
285 -- Since concurrent read/write operations may occur on this variable.
286 -- See the body of Tailored_Exception_Traceback in Ada.Exceptions for
287 -- a more detailed description of the potential problems.
289 ------------------------
290 -- Task Specific Data --
291 ------------------------
293 -- Here we define a single type that encapsulates the various task
294 -- specific data. This type is used to store the necessary data into
295 -- the Task_Control_Block or into a global variable in the non tasking
296 -- case.
298 type TSD is record
299 Pri_Stack_Info : aliased Stack_Checking.Stack_Info;
300 -- Information on stack (Base/Limit/Size) that is used
301 -- by System.Stack_Checking. If this TSD does not belong to
302 -- the environment task, the Size field must be initialized
303 -- to the tasks requested stack size before the task can do
304 -- its first stack check.
306 Jmpbuf_Address : Address := Null_Address;
307 -- Address of jump buffer used to store the address of the
308 -- current longjmp/setjmp buffer for exception management.
309 -- These buffers are threaded into a stack, and the address
310 -- here is the top of the stack. A null address means that
311 -- no exception handler is currently active.
313 Sec_Stack_Addr : Address := Null_Address;
314 -- Address of currently allocated secondary stack
316 Exc_Stack_Addr : Address := Null_Address;
317 -- Address of a task-specific stack used for the propagation of
318 -- exceptions in response to synchronous faults. This alternate
319 -- stack is necessary when propagating Storage_Error resulting
320 -- from a stack overflow, as the task's primary stack is full.
321 -- This is currently only used on the SGI, and this value stays
322 -- null on other platforms.
324 Current_Excep : aliased EO;
325 -- Exception occurrence that contains the information for the
326 -- current exception. Note that any exception in the same task
327 -- destroys this information, so the data in this variable must
328 -- be copied out before another exception can occur.
330 Machine_State_Addr : Address := Null_Address;
332 end record;
334 procedure Create_TSD (New_TSD : in out TSD);
335 pragma Inline (Create_TSD);
336 -- Called from s-tassta when a new thread is created to perform
337 -- any required initialization of the TSD.
339 procedure Destroy_TSD (Old_TSD : in out TSD);
340 pragma Inline (Destroy_TSD);
341 -- Called from s-tassta just before a thread is destroyed to perform
342 -- any required finalization.
344 function Get_GNAT_Exception return Ada.Exceptions.Exception_Id;
345 pragma Inline (Get_GNAT_Exception);
346 -- This function obtains the Exception_Id from the Exception_Occurrence
347 -- referenced by the Current_Excep field of the task specific data, i.e.
348 -- the call is equivalent to
349 -- Exception_Identity (Get_Current_Exception.all)
351 -- Export the Get/Set routines for the various Task Specific Data (TSD)
352 -- elements as callable subprograms instead of objects of access to
353 -- subprogram types.
355 function Get_Jmpbuf_Address_Soft return Address;
356 procedure Set_Jmpbuf_Address_Soft (Addr : Address);
357 pragma Inline (Get_Jmpbuf_Address_Soft);
358 pragma Inline (Set_Jmpbuf_Address_Soft);
360 function Get_Sec_Stack_Addr_Soft return Address;
361 procedure Set_Sec_Stack_Addr_Soft (Addr : Address);
362 pragma Inline (Get_Sec_Stack_Addr_Soft);
363 pragma Inline (Set_Sec_Stack_Addr_Soft);
365 function Get_Exc_Stack_Addr_Soft return Address;
366 procedure Set_Exc_Stack_Addr_Soft (Self_ID : Address; Addr : Address);
367 pragma Inline (Get_Exc_Stack_Addr_Soft);
368 pragma Inline (Set_Exc_Stack_Addr_Soft);
370 function Get_Machine_State_Addr_Soft return Address;
371 procedure Set_Machine_State_Addr_Soft (Addr : Address);
372 pragma Inline (Get_Machine_State_Addr_Soft);
373 pragma Inline (Set_Machine_State_Addr_Soft);
375 end System.Soft_Links;