1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . S O F T _ L I N K S . T A S K I N G --
9 -- Copyright (C) 2004-2023, Free Software Foundation, Inc. --
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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 pragma Style_Checks
(All_Checks
);
33 -- Turn off subprogram alpha ordering check, since we group soft link bodies
34 -- and dummy soft link bodies together separately in this unit.
37 with Ada
.Exceptions
.Is_Null_Occurrence
;
39 with System
.Task_Primitives
.Operations
;
41 with System
.Stack_Checking
;
42 with System
.Secondary_Stack
;
44 package body System
.Soft_Links
.Tasking
is
46 package STPO
renames System
.Task_Primitives
.Operations
;
47 package SSL
renames System
.Soft_Links
;
51 use type System
.Secondary_Stack
.SS_Stack_Ptr
;
53 use type System
.Tasking
.Task_Id
;
54 use type System
.Tasking
.Termination_Handler
;
60 Initialized
: Boolean := False;
61 -- Boolean flag that indicates whether the tasking soft links have
64 -----------------------------------------------------------------
65 -- Tasking Versions of Services Needed by Non-Tasking Programs --
66 -----------------------------------------------------------------
68 function Get_Jmpbuf_Address
return Address
;
69 procedure Set_Jmpbuf_Address
(Addr
: Address
);
70 -- Get/Set Jmpbuf_Address for current task
72 function Get_Sec_Stack
return SST
.SS_Stack_Ptr
;
73 procedure Set_Sec_Stack
(Stack
: SST
.SS_Stack_Ptr
);
74 -- Get/Set location of current task's secondary stack
76 procedure Timed_Delay_T
(Time
: Duration; Mode
: Integer);
77 -- Task-safe version of SSL.Timed_Delay
79 procedure Task_Termination_Handler_T
(Excep
: SSL
.EO
);
80 -- Task-safe version of the task termination procedure
82 function Get_Stack_Info
return Stack_Checking
.Stack_Access
;
83 -- Get access to the current task's Stack_Info
85 --------------------------
86 -- Soft-Link Get Bodies --
87 --------------------------
89 function Get_Jmpbuf_Address
return Address
is
91 return STPO
.Self
.Common
.Compiler_Data
.Jmpbuf_Address
;
92 end Get_Jmpbuf_Address
;
94 function Get_Sec_Stack
return SST
.SS_Stack_Ptr
is
96 return Result
: constant SST
.SS_Stack_Ptr
:=
97 STPO
.Self
.Common
.Compiler_Data
.Sec_Stack_Ptr
99 pragma Assert
(Result
/= null);
103 function Get_Stack_Info
return Stack_Checking
.Stack_Access
is
105 return STPO
.Self
.Common
.Compiler_Data
.Pri_Stack_Info
'Access;
108 --------------------------
109 -- Soft-Link Set Bodies --
110 --------------------------
112 procedure Set_Jmpbuf_Address
(Addr
: Address
) is
114 STPO
.Self
.Common
.Compiler_Data
.Jmpbuf_Address
:= Addr
;
115 end Set_Jmpbuf_Address
;
117 procedure Set_Sec_Stack
(Stack
: SST
.SS_Stack_Ptr
) is
119 STPO
.Self
.Common
.Compiler_Data
.Sec_Stack_Ptr
:= Stack
;
126 procedure Timed_Delay_T
(Time
: Duration; Mode
: Integer) is
127 Self_Id
: constant System
.Tasking
.Task_Id
:= STPO
.Self
;
130 -- In case pragma Detect_Blocking is active then Program_Error
131 -- must be raised if this potentially blocking operation
132 -- is called from a protected operation.
134 if System
.Tasking
.Detect_Blocking
135 and then Self_Id
.Common
.Protected_Action_Nesting
> 0
137 raise Program_Error
with "potentially blocking operation";
140 STPO
.Timed_Delay
(Self_Id
, Time
, Mode
);
145 --------------------------------
146 -- Task_Termination_Handler_T --
147 --------------------------------
149 procedure Task_Termination_Handler_T
(Excep
: SSL
.EO
) is
150 Self_Id
: constant System
.Tasking
.Task_Id
:= STPO
.Self
;
151 Cause
: System
.Tasking
.Cause_Of_Termination
;
152 EO
: Ada
.Exceptions
.Exception_Occurrence
;
155 -- We can only be here because we are terminating the environment task.
156 -- Task termination for all other tasks is handled in the Task_Wrapper.
158 -- We do not want to enable this check and e.g. call System.OS_Lib.Abort
159 -- here because some restricted run-times may not have System.OS_Lib
160 -- and calling abort may do more harm than good to the main application.
162 pragma Assert
(Self_Id
= STPO
.Environment_Task
);
164 -- Normal task termination
166 if Is_Null_Occurrence
(Excep
) then
167 Cause
:= System
.Tasking
.Normal
;
168 Ada
.Exceptions
.Save_Occurrence
(EO
, Ada
.Exceptions
.Null_Occurrence
);
170 -- Abnormal task termination
172 elsif Exception_Identity
(Excep
) = Standard
'Abort_Signal'Identity then
173 Cause := System.Tasking.Abnormal;
174 Ada.Exceptions.Save_Occurrence (EO, Ada.Exceptions.Null_Occurrence);
176 -- Termination because of an unhandled exception
179 Cause := System.Tasking.Unhandled_Exception;
180 Ada.Exceptions.Save_Occurrence (EO, Excep);
183 -- There is no need for explicit protection against race conditions for
184 -- this part because it can only be executed by the environment task
185 -- after all the other tasks have been finalized. Note that there is no
186 -- fall-back handler which could apply to this environment task because
187 -- it has no parents, and, as specified in ARM C.7.3 par. 9/2, "the
188 -- fall-back handler applies only to the dependent tasks of the task".
190 if Self_Id.Common.Specific_Handler /= null then
192 Self_Id.Common.Specific_Handler.all (Cause, Self_Id, EO);
194 -- RM-C.7.3(16) requires all exceptions raised here to be ignored
200 end Task_Termination_Handler_T;
202 -----------------------------
203 -- Init_Tasking_Soft_Links --
204 -----------------------------
206 procedure Init_Tasking_Soft_Links is
208 -- Set links only if not set already
210 if not Initialized then
212 -- Mark tasking soft links as initialized
216 -- The application being executed uses tasking so that the tasking
217 -- version of the following soft links need to be used.
219 SSL.Get_Jmpbuf_Address := Get_Jmpbuf_Address'Access;
220 SSL.Set_Jmpbuf_Address := Set_Jmpbuf_Address'Access;
221 SSL.Get_Sec_Stack := Get_Sec_Stack'Access;
222 SSL.Get_Stack_Info := Get_Stack_Info'Access;
223 SSL.Set_Sec_Stack := Set_Sec_Stack'Access;
224 SSL.Timed_Delay := Timed_Delay_T'Access;
225 SSL.Task_Termination_Handler := Task_Termination_Handler_T'Access;
227 -- No need to create a new secondary stack, since we will use the
228 -- default one created in s-secsta.adb.
230 SSL.Set_Sec_Stack (SSL.Get_Sec_Stack_NT);
231 SSL.Set_Jmpbuf_Address (SSL.Get_Jmpbuf_Address_NT);
234 pragma Assert (Get_Sec_Stack /= null);
235 end Init_Tasking_Soft_Links;
237 end System.Soft_Links.Tasking;