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-2014, 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 -- Turn polling off for this package. We don't need polling during any of the
38 -- routines in this package, and more to the point, if we try to poll it can
39 -- cause infinite loops.
42 with Ada
.Exceptions
.Is_Null_Occurrence
;
44 with System
.Task_Primitives
.Operations
;
46 with System
.Stack_Checking
;
48 package body System
.Soft_Links
.Tasking
is
50 package STPO
renames System
.Task_Primitives
.Operations
;
51 package SSL
renames System
.Soft_Links
;
55 use type System
.Tasking
.Task_Id
;
56 use type System
.Tasking
.Termination_Handler
;
62 Initialized
: Boolean := False;
63 -- Boolean flag that indicates whether the tasking soft links have
66 -----------------------------------------------------------------
67 -- Tasking Versions of Services Needed by Non-Tasking Programs --
68 -----------------------------------------------------------------
70 function Get_Jmpbuf_Address
return Address
;
71 procedure Set_Jmpbuf_Address
(Addr
: Address
);
72 -- Get/Set Jmpbuf_Address for current task
74 function Get_Sec_Stack_Addr
return Address
;
75 procedure Set_Sec_Stack_Addr
(Addr
: Address
);
76 -- Get/Set location of current task's secondary stack
78 procedure Timed_Delay_T
(Time
: Duration; Mode
: Integer);
79 -- Task-safe version of SSL.Timed_Delay
81 procedure Task_Termination_Handler_T
(Excep
: SSL
.EO
);
82 -- Task-safe version of the task termination procedure
84 function Get_Stack_Info
return Stack_Checking
.Stack_Access
;
85 -- Get access to the current task's Stack_Info
87 --------------------------
88 -- Soft-Link Get Bodies --
89 --------------------------
91 function Get_Jmpbuf_Address
return Address
is
93 return STPO
.Self
.Common
.Compiler_Data
.Jmpbuf_Address
;
94 end Get_Jmpbuf_Address
;
96 function Get_Sec_Stack_Addr
return Address
is
98 return Result
: constant Address
:=
99 STPO
.Self
.Common
.Compiler_Data
.Sec_Stack_Addr
101 pragma Assert
(Result
/= Null_Address
);
103 end Get_Sec_Stack_Addr
;
105 function Get_Stack_Info
return Stack_Checking
.Stack_Access
is
107 return STPO
.Self
.Common
.Compiler_Data
.Pri_Stack_Info
'Access;
110 --------------------------
111 -- Soft-Link Set Bodies --
112 --------------------------
114 procedure Set_Jmpbuf_Address
(Addr
: Address
) is
116 STPO
.Self
.Common
.Compiler_Data
.Jmpbuf_Address
:= Addr
;
117 end Set_Jmpbuf_Address
;
119 procedure Set_Sec_Stack_Addr
(Addr
: Address
) is
121 STPO
.Self
.Common
.Compiler_Data
.Sec_Stack_Addr
:= Addr
;
122 end Set_Sec_Stack_Addr
;
128 procedure Timed_Delay_T
(Time
: Duration; Mode
: Integer) is
129 Self_Id
: constant System
.Tasking
.Task_Id
:= STPO
.Self
;
132 -- In case pragma Detect_Blocking is active then Program_Error
133 -- must be raised if this potentially blocking operation
134 -- is called from a protected operation.
136 if System
.Tasking
.Detect_Blocking
137 and then Self_Id
.Common
.Protected_Action_Nesting
> 0
139 raise Program_Error
with "potentially blocking operation";
142 STPO
.Timed_Delay
(Self_Id
, Time
, Mode
);
147 --------------------------------
148 -- Task_Termination_Handler_T --
149 --------------------------------
151 procedure Task_Termination_Handler_T
(Excep
: SSL
.EO
) is
152 Self_Id
: constant System
.Tasking
.Task_Id
:= STPO
.Self
;
153 Cause
: System
.Tasking
.Cause_Of_Termination
;
154 EO
: Ada
.Exceptions
.Exception_Occurrence
;
157 -- We can only be here because we are terminating the environment task.
158 -- Task termination for all other tasks is handled in the Task_Wrapper.
160 -- We do not want to enable this check and e.g. call System.OS_Lib.Abort
161 -- here because some restricted run-times may not have System.OS_Lib
162 -- (e.g. JVM), and calling abort may do more harm than good to the
165 pragma Assert
(Self_Id
= STPO
.Environment_Task
);
167 -- Normal task termination
169 if Is_Null_Occurrence
(Excep
) then
170 Cause
:= System
.Tasking
.Normal
;
171 Ada
.Exceptions
.Save_Occurrence
(EO
, Ada
.Exceptions
.Null_Occurrence
);
173 -- Abnormal task termination
175 elsif Exception_Identity
(Excep
) = Standard
'Abort_Signal'Identity then
176 Cause := System.Tasking.Abnormal;
177 Ada.Exceptions.Save_Occurrence (EO, Ada.Exceptions.Null_Occurrence);
179 -- Termination because of an unhandled exception
182 Cause := System.Tasking.Unhandled_Exception;
183 Ada.Exceptions.Save_Occurrence (EO, Excep);
186 -- There is no need for explicit protection against race conditions for
187 -- this part because it can only be executed by the environment task
188 -- after all the other tasks have been finalized. Note that there is no
189 -- fall-back handler which could apply to this environment task because
190 -- it has no parents, and, as specified in ARM C.7.3 par. 9/2, "the
191 -- fall-back handler applies only to the dependent tasks of the task".
193 if Self_Id.Common.Specific_Handler /= null then
194 Self_Id.Common.Specific_Handler.all (Cause, Self_Id, EO);
196 end Task_Termination_Handler_T;
198 -----------------------------
199 -- Init_Tasking_Soft_Links --
200 -----------------------------
202 procedure Init_Tasking_Soft_Links is
204 -- Set links only if not set already
206 if not Initialized then
208 -- Mark tasking soft links as initialized
212 -- The application being executed uses tasking so that the tasking
213 -- version of the following soft links need to be used.
215 SSL.Get_Jmpbuf_Address := Get_Jmpbuf_Address'Access;
216 SSL.Set_Jmpbuf_Address := Set_Jmpbuf_Address'Access;
217 SSL.Get_Sec_Stack_Addr := Get_Sec_Stack_Addr'Access;
218 SSL.Get_Stack_Info := Get_Stack_Info'Access;
219 SSL.Set_Sec_Stack_Addr := Set_Sec_Stack_Addr'Access;
220 SSL.Timed_Delay := Timed_Delay_T'Access;
221 SSL.Task_Termination_Handler := Task_Termination_Handler_T'Access;
223 -- No need to create a new secondary stack, since we will use the
224 -- default one created in s-secsta.adb.
226 SSL.Set_Sec_Stack_Addr (SSL.Get_Sec_Stack_Addr_NT);
227 SSL.Set_Jmpbuf_Address (SSL.Get_Jmpbuf_Address_NT);
230 pragma Assert (Get_Sec_Stack_Addr /= Null_Address);
231 end Init_Tasking_Soft_Links;
233 end System.Soft_Links.Tasking;