annotate gcc/ada/libgnat/s-thread__ae653.adb @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . T H R E A D S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This is the VxWorks 653 version of this package
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 pragma Restrictions (No_Tasking);
kono
parents:
diff changeset
35 -- The VxWorks 653 version of this package is intended only for programs
kono
parents:
diff changeset
36 -- which do not use Ada tasking. This restriction ensures that this
kono
parents:
diff changeset
37 -- will be checked by the binder.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 with System.OS_Versions; use System.OS_Versions;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package body System.Threads is
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 use Interfaces.C;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 package SSL renames System.Soft_Links;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 Current_ATSD : aliased System.Address := System.Null_Address;
kono
parents:
diff changeset
48 pragma Export (C, Current_ATSD, "__gnat_current_atsd");
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 Main_ATSD : aliased ATSD;
kono
parents:
diff changeset
51 -- TSD for environment task
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 Stack_Limit : Address;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 pragma Import (C, Stack_Limit, "__gnat_stack_limit");
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 type Set_Stack_Limit_Proc_Acc is access procedure;
kono
parents:
diff changeset
58 pragma Convention (C, Set_Stack_Limit_Proc_Acc);
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc;
kono
parents:
diff changeset
61 pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook");
kono
parents:
diff changeset
62 -- Procedure to be called when a task is created to set stack limit if
kono
parents:
diff changeset
63 -- limit checking is used.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 --------------------------
kono
parents:
diff changeset
66 -- VxWorks specific API --
kono
parents:
diff changeset
67 --------------------------
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 ERROR : constant STATUS := Interfaces.C.int (-1);
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 function taskIdVerify (tid : t_id) return STATUS;
kono
parents:
diff changeset
72 pragma Import (C, taskIdVerify, "taskIdVerify");
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 function taskIdSelf return t_id;
kono
parents:
diff changeset
75 pragma Import (C, taskIdSelf, "taskIdSelf");
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function taskVarAdd
kono
parents:
diff changeset
78 (tid : t_id; pVar : System.Address) return int;
kono
parents:
diff changeset
79 pragma Import (C, taskVarAdd, "taskVarAdd");
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -----------------------
kono
parents:
diff changeset
82 -- Local Subprograms --
kono
parents:
diff changeset
83 -----------------------
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Init_RTS;
kono
parents:
diff changeset
86 -- This procedure performs the initialization of the run-time lib.
kono
parents:
diff changeset
87 -- It installs System.Threads versions of certain operations of the
kono
parents:
diff changeset
88 -- run-time lib.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 procedure Install_Handler;
kono
parents:
diff changeset
91 pragma Import (C, Install_Handler, "__gnat_install_handler");
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 function Get_Sec_Stack return SST.SS_Stack_Ptr;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 procedure Set_Sec_Stack (Stack : SST.SS_Stack_Ptr);
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -----------------------
kono
parents:
diff changeset
98 -- Thread_Body_Enter --
kono
parents:
diff changeset
99 -----------------------
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 procedure Thread_Body_Enter
kono
parents:
diff changeset
102 (Sec_Stack_Ptr : SST.SS_Stack_Ptr;
kono
parents:
diff changeset
103 Process_ATSD_Address : System.Address)
kono
parents:
diff changeset
104 is
kono
parents:
diff changeset
105 -- Current_ATSD must already be a taskVar of taskIdSelf.
kono
parents:
diff changeset
106 -- No assertion because taskVarGet is not available on VxWorks/CERT,
kono
parents:
diff changeset
107 -- which is used on VxWorks 653 3.x as a guest OS.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 TSD : constant ATSD_Access := From_Address (Process_ATSD_Address);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 begin
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 TSD.Sec_Stack_Ptr := Sec_Stack_Ptr;
kono
parents:
diff changeset
114 SST.SS_Init (TSD.Sec_Stack_Ptr);
kono
parents:
diff changeset
115 Current_ATSD := Process_ATSD_Address;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 Install_Handler;
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 -- Initialize stack limit if needed
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 if Current_ATSD /= Main_ATSD'Address
kono
parents:
diff changeset
122 and then Set_Stack_Limit_Hook /= null
kono
parents:
diff changeset
123 then
kono
parents:
diff changeset
124 Set_Stack_Limit_Hook.all;
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126 end Thread_Body_Enter;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 ----------------------------------
kono
parents:
diff changeset
129 -- Thread_Body_Exceptional_Exit --
kono
parents:
diff changeset
130 ----------------------------------
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 procedure Thread_Body_Exceptional_Exit
kono
parents:
diff changeset
133 (EO : Ada.Exceptions.Exception_Occurrence)
kono
parents:
diff changeset
134 is
kono
parents:
diff changeset
135 pragma Unreferenced (EO);
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 begin
kono
parents:
diff changeset
138 -- No action for this target
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 null;
kono
parents:
diff changeset
141 end Thread_Body_Exceptional_Exit;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 -----------------------
kono
parents:
diff changeset
144 -- Thread_Body_Leave --
kono
parents:
diff changeset
145 -----------------------
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 procedure Thread_Body_Leave is
kono
parents:
diff changeset
148 begin
kono
parents:
diff changeset
149 -- No action for this target
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 null;
kono
parents:
diff changeset
152 end Thread_Body_Leave;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 --------------
kono
parents:
diff changeset
155 -- Init_RTS --
kono
parents:
diff changeset
156 --------------
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 procedure Init_RTS is
kono
parents:
diff changeset
159 -- Register environment task
kono
parents:
diff changeset
160 Result : constant Interfaces.C.int := Register (taskIdSelf);
kono
parents:
diff changeset
161 pragma Assert (Result /= ERROR);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 begin
kono
parents:
diff changeset
164 Main_ATSD.Sec_Stack_Ptr := SSL.Get_Sec_Stack_NT;
kono
parents:
diff changeset
165 Current_ATSD := Main_ATSD'Address;
kono
parents:
diff changeset
166 Install_Handler;
kono
parents:
diff changeset
167 SSL.Get_Sec_Stack := Get_Sec_Stack'Access;
kono
parents:
diff changeset
168 SSL.Set_Sec_Stack := Set_Sec_Stack'Access;
kono
parents:
diff changeset
169 end Init_RTS;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 -------------------
kono
parents:
diff changeset
172 -- Get_Sec_Stack --
kono
parents:
diff changeset
173 -------------------
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 function Get_Sec_Stack return SST.SS_Stack_Ptr is
kono
parents:
diff changeset
176 CTSD : constant ATSD_Access := From_Address (Current_ATSD);
kono
parents:
diff changeset
177 begin
kono
parents:
diff changeset
178 pragma Assert (CTSD /= null);
kono
parents:
diff changeset
179 return CTSD.Sec_Stack_Ptr;
kono
parents:
diff changeset
180 end Get_Sec_Stack;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 --------------
kono
parents:
diff changeset
183 -- Register --
kono
parents:
diff changeset
184 --------------
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 function Register (T : Thread_Id) return STATUS is
kono
parents:
diff changeset
187 Result : STATUS;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 begin
kono
parents:
diff changeset
190 -- It cannot be assumed that the caller of this routine has a ATSD;
kono
parents:
diff changeset
191 -- so neither this procedure nor the procedures that it calls should
kono
parents:
diff changeset
192 -- raise or handle exceptions, or make use of a secondary stack.
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 -- This routine is only necessary because taskVarAdd cannot be
kono
parents:
diff changeset
195 -- executed once an VxWorks 653 partition has entered normal mode
kono
parents:
diff changeset
196 -- (depending on configRecord.c, allocation could be disabled).
kono
parents:
diff changeset
197 -- Otherwise, everything could have been done in Thread_Body_Enter.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 if taskIdVerify (T) = ERROR then
kono
parents:
diff changeset
200 return ERROR;
kono
parents:
diff changeset
201 end if;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 Result := taskVarAdd (T, Current_ATSD'Address);
kono
parents:
diff changeset
204 pragma Assert (Result /= ERROR);
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 -- The same issue applies to the task variable that contains the stack
kono
parents:
diff changeset
207 -- limit when that overflow checking mechanism is used instead of
kono
parents:
diff changeset
208 -- probing. If stack checking is enabled and limit checking is used,
kono
parents:
diff changeset
209 -- allocate the limit for this task. The environment task has this
kono
parents:
diff changeset
210 -- initialized by the binder-generated main when
kono
parents:
diff changeset
211 -- System.Stack_Check_Limits = True.
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 pragma Warnings (Off);
kono
parents:
diff changeset
214 -- OS is a constant
kono
parents:
diff changeset
215 if Result /= ERROR
kono
parents:
diff changeset
216 and then OS /= VxWorks_653
kono
parents:
diff changeset
217 and then Set_Stack_Limit_Hook /= null
kono
parents:
diff changeset
218 then
kono
parents:
diff changeset
219 Result := taskVarAdd (T, Stack_Limit'Address);
kono
parents:
diff changeset
220 pragma Assert (Result /= ERROR);
kono
parents:
diff changeset
221 end if;
kono
parents:
diff changeset
222 pragma Warnings (On);
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 return Result;
kono
parents:
diff changeset
225 end Register;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 -------------------
kono
parents:
diff changeset
228 -- Set_Sec_Stack --
kono
parents:
diff changeset
229 -------------------
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 procedure Set_Sec_Stack (Stack : SST.SS_Stack_Ptr) is
kono
parents:
diff changeset
232 CTSD : constant ATSD_Access := From_Address (Current_ATSD);
kono
parents:
diff changeset
233 begin
kono
parents:
diff changeset
234 pragma Assert (CTSD /= null);
kono
parents:
diff changeset
235 CTSD.Sec_Stack_Ptr := Stack;
kono
parents:
diff changeset
236 end Set_Sec_Stack;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 begin
kono
parents:
diff changeset
239 -- Initialize run-time library
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 Init_RTS;
kono
parents:
diff changeset
242 end System.Threads;