annotate libgcc/unwind-sjlj.c @ 118:fd00160c1b76

ifdef TARGET_64BIT
author mir3636
date Tue, 27 Feb 2018 15:01:35 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* SJLJ exception handling and frame unwind runtime interface routines.
kono
parents:
diff changeset
2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
kono
parents:
diff changeset
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
kono
parents:
diff changeset
14 License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "tconfig.h"
kono
parents:
diff changeset
26 #include "tsystem.h"
kono
parents:
diff changeset
27 #include "coretypes.h"
kono
parents:
diff changeset
28 #include "tm.h"
kono
parents:
diff changeset
29 #include "libgcc_tm.h"
kono
parents:
diff changeset
30 #include "unwind.h"
kono
parents:
diff changeset
31 #include "gthr.h"
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #ifdef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 #ifdef __LIBGCC_DONT_USE_BUILTIN_SETJMP__
kono
parents:
diff changeset
36 #ifndef inhibit_libc
kono
parents:
diff changeset
37 #include <setjmp.h>
kono
parents:
diff changeset
38 #else
kono
parents:
diff changeset
39 typedef void *jmp_buf[__LIBGCC_JMP_BUF_SIZE__];
kono
parents:
diff changeset
40 extern void longjmp(jmp_buf, int) __attribute__((noreturn));
kono
parents:
diff changeset
41 #endif
kono
parents:
diff changeset
42 #else
kono
parents:
diff changeset
43 #define longjmp __builtin_longjmp
kono
parents:
diff changeset
44 #endif
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 /* The setjmp side is dealt with in the except.c file. */
kono
parents:
diff changeset
47 #undef setjmp
kono
parents:
diff changeset
48 #define setjmp setjmp_should_not_be_used_in_this_file
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* This structure is allocated on the stack of the target function.
kono
parents:
diff changeset
52 This must match the definition created in except.c:init_eh. */
kono
parents:
diff changeset
53 struct SjLj_Function_Context
kono
parents:
diff changeset
54 {
kono
parents:
diff changeset
55 /* This is the chain through all registered contexts. It is
kono
parents:
diff changeset
56 filled in by _Unwind_SjLj_Register. */
kono
parents:
diff changeset
57 struct SjLj_Function_Context *prev;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* This is assigned in by the target function before every call
kono
parents:
diff changeset
60 to the index of the call site in the lsda. It is assigned by
kono
parents:
diff changeset
61 the personality routine to the landing pad index. */
kono
parents:
diff changeset
62 int call_site;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 /* This is how data is returned from the personality routine to
kono
parents:
diff changeset
65 the target function's handler. */
kono
parents:
diff changeset
66 _Unwind_Word data[4];
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* These are filled in once by the target function before any
kono
parents:
diff changeset
69 exceptions are expected to be handled. */
kono
parents:
diff changeset
70 _Unwind_Personality_Fn personality;
kono
parents:
diff changeset
71 void *lsda;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 #ifdef __LIBGCC_DONT_USE_BUILTIN_SETJMP__
kono
parents:
diff changeset
74 /* We don't know what sort of alignment requirements the system
kono
parents:
diff changeset
75 jmp_buf has. We over estimated in except.c, and now we have
kono
parents:
diff changeset
76 to match that here just in case the system *didn't* have more
kono
parents:
diff changeset
77 restrictive requirements. */
kono
parents:
diff changeset
78 jmp_buf jbuf __attribute__((aligned));
kono
parents:
diff changeset
79 #else
kono
parents:
diff changeset
80 void *jbuf[];
kono
parents:
diff changeset
81 #endif
kono
parents:
diff changeset
82 };
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 struct _Unwind_Context
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 struct SjLj_Function_Context *fc;
kono
parents:
diff changeset
87 };
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 typedef struct
kono
parents:
diff changeset
90 {
kono
parents:
diff changeset
91 _Unwind_Personality_Fn personality;
kono
parents:
diff changeset
92 } _Unwind_FrameState;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 /* Manage the chain of registered function contexts. */
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 /* Single threaded fallback chain. */
kono
parents:
diff changeset
98 static struct SjLj_Function_Context *fc_static;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 #if __GTHREADS
kono
parents:
diff changeset
101 static __gthread_key_t fc_key;
kono
parents:
diff changeset
102 static int use_fc_key = -1;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 static void
kono
parents:
diff changeset
105 fc_key_init (void)
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 use_fc_key = __gthread_key_create (&fc_key, 0) == 0;
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 static void
kono
parents:
diff changeset
111 fc_key_init_once (void)
kono
parents:
diff changeset
112 {
kono
parents:
diff changeset
113 static __gthread_once_t once = __GTHREAD_ONCE_INIT;
kono
parents:
diff changeset
114 if (__gthread_once (&once, fc_key_init) != 0 || use_fc_key < 0)
kono
parents:
diff changeset
115 use_fc_key = 0;
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117 #endif
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 void
kono
parents:
diff changeset
120 _Unwind_SjLj_Register (struct SjLj_Function_Context *fc)
kono
parents:
diff changeset
121 {
kono
parents:
diff changeset
122 #if __GTHREADS
kono
parents:
diff changeset
123 if (use_fc_key < 0)
kono
parents:
diff changeset
124 fc_key_init_once ();
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 if (use_fc_key)
kono
parents:
diff changeset
127 {
kono
parents:
diff changeset
128 fc->prev = __gthread_getspecific (fc_key);
kono
parents:
diff changeset
129 __gthread_setspecific (fc_key, fc);
kono
parents:
diff changeset
130 }
kono
parents:
diff changeset
131 else
kono
parents:
diff changeset
132 #endif
kono
parents:
diff changeset
133 {
kono
parents:
diff changeset
134 fc->prev = fc_static;
kono
parents:
diff changeset
135 fc_static = fc;
kono
parents:
diff changeset
136 }
kono
parents:
diff changeset
137 }
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 static inline struct SjLj_Function_Context *
kono
parents:
diff changeset
140 _Unwind_SjLj_GetContext (void)
kono
parents:
diff changeset
141 {
kono
parents:
diff changeset
142 #if __GTHREADS
kono
parents:
diff changeset
143 if (use_fc_key < 0)
kono
parents:
diff changeset
144 fc_key_init_once ();
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 if (use_fc_key)
kono
parents:
diff changeset
147 return __gthread_getspecific (fc_key);
kono
parents:
diff changeset
148 #endif
kono
parents:
diff changeset
149 return fc_static;
kono
parents:
diff changeset
150 }
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 static inline void
kono
parents:
diff changeset
153 _Unwind_SjLj_SetContext (struct SjLj_Function_Context *fc)
kono
parents:
diff changeset
154 {
kono
parents:
diff changeset
155 #if __GTHREADS
kono
parents:
diff changeset
156 if (use_fc_key < 0)
kono
parents:
diff changeset
157 fc_key_init_once ();
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 if (use_fc_key)
kono
parents:
diff changeset
160 __gthread_setspecific (fc_key, fc);
kono
parents:
diff changeset
161 else
kono
parents:
diff changeset
162 #endif
kono
parents:
diff changeset
163 fc_static = fc;
kono
parents:
diff changeset
164 }
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 void
kono
parents:
diff changeset
167 _Unwind_SjLj_Unregister (struct SjLj_Function_Context *fc)
kono
parents:
diff changeset
168 {
kono
parents:
diff changeset
169 _Unwind_SjLj_SetContext (fc->prev);
kono
parents:
diff changeset
170 }
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 /* Get/set the return data value at INDEX in CONTEXT. */
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 _Unwind_Word
kono
parents:
diff changeset
176 _Unwind_GetGR (struct _Unwind_Context *context, int index)
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 return context->fc->data[index];
kono
parents:
diff changeset
179 }
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 /* Get the value of the CFA as saved in CONTEXT. */
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 _Unwind_Word
kono
parents:
diff changeset
184 _Unwind_GetCFA (struct _Unwind_Context *context __attribute__((unused)))
kono
parents:
diff changeset
185 {
kono
parents:
diff changeset
186 /* ??? Ideally __builtin_setjmp places the CFA in the jmpbuf. */
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 #ifndef __LIBGCC_DONT_USE_BUILTIN_SETJMP__
kono
parents:
diff changeset
189 /* This is a crude imitation of the CFA: the saved stack pointer.
kono
parents:
diff changeset
190 This is roughly the CFA of the frame before CONTEXT. When using the
kono
parents:
diff changeset
191 DWARF-2 unwinder _Unwind_GetCFA returns the CFA of the frame described
kono
parents:
diff changeset
192 by CONTEXT instead; but for DWARF-2 the cleanups associated with
kono
parents:
diff changeset
193 CONTEXT have already been run, and for SJLJ they have not yet been. */
kono
parents:
diff changeset
194 if (context->fc != NULL)
kono
parents:
diff changeset
195 return (_Unwind_Word) context->fc->jbuf[2];
kono
parents:
diff changeset
196 #endif
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 /* Otherwise we're out of luck for now. */
kono
parents:
diff changeset
199 return (_Unwind_Word) 0;
kono
parents:
diff changeset
200 }
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 void
kono
parents:
diff changeset
203 _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
kono
parents:
diff changeset
204 {
kono
parents:
diff changeset
205 context->fc->data[index] = val;
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 /* Get the call-site index as saved in CONTEXT. */
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 _Unwind_Ptr
kono
parents:
diff changeset
211 _Unwind_GetIP (struct _Unwind_Context *context)
kono
parents:
diff changeset
212 {
kono
parents:
diff changeset
213 return context->fc->call_site + 1;
kono
parents:
diff changeset
214 }
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 _Unwind_Ptr
kono
parents:
diff changeset
217 _Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
kono
parents:
diff changeset
218 {
kono
parents:
diff changeset
219 *ip_before_insn = 0;
kono
parents:
diff changeset
220 if (context->fc != NULL)
kono
parents:
diff changeset
221 return context->fc->call_site + 1;
kono
parents:
diff changeset
222 else
kono
parents:
diff changeset
223 return 0;
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 /* Set the return landing pad index in CONTEXT. */
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 void
kono
parents:
diff changeset
229 _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
kono
parents:
diff changeset
230 {
kono
parents:
diff changeset
231 context->fc->call_site = val - 1;
kono
parents:
diff changeset
232 }
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 void *
kono
parents:
diff changeset
235 _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
kono
parents:
diff changeset
236 {
kono
parents:
diff changeset
237 return context->fc->lsda;
kono
parents:
diff changeset
238 }
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 _Unwind_Ptr
kono
parents:
diff changeset
241 _Unwind_GetRegionStart (struct _Unwind_Context *context __attribute__((unused)) )
kono
parents:
diff changeset
242 {
kono
parents:
diff changeset
243 return 0;
kono
parents:
diff changeset
244 }
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 void *
kono
parents:
diff changeset
247 _Unwind_FindEnclosingFunction (void *pc __attribute__((unused)))
kono
parents:
diff changeset
248 {
kono
parents:
diff changeset
249 return NULL;
kono
parents:
diff changeset
250 }
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 #ifndef __ia64__
kono
parents:
diff changeset
253 _Unwind_Ptr
kono
parents:
diff changeset
254 _Unwind_GetDataRelBase (struct _Unwind_Context *context __attribute__((unused)) )
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 return 0;
kono
parents:
diff changeset
257 }
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 _Unwind_Ptr
kono
parents:
diff changeset
260 _Unwind_GetTextRelBase (struct _Unwind_Context *context __attribute__((unused)) )
kono
parents:
diff changeset
261 {
kono
parents:
diff changeset
262 return 0;
kono
parents:
diff changeset
263 }
kono
parents:
diff changeset
264 #endif
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 static inline _Unwind_Reason_Code
kono
parents:
diff changeset
267 uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
kono
parents:
diff changeset
268 {
kono
parents:
diff changeset
269 if (context->fc == NULL)
kono
parents:
diff changeset
270 {
kono
parents:
diff changeset
271 fs->personality = NULL;
kono
parents:
diff changeset
272 return _URC_END_OF_STACK;
kono
parents:
diff changeset
273 }
kono
parents:
diff changeset
274 else
kono
parents:
diff changeset
275 {
kono
parents:
diff changeset
276 fs->personality = context->fc->personality;
kono
parents:
diff changeset
277 return _URC_NO_REASON;
kono
parents:
diff changeset
278 }
kono
parents:
diff changeset
279 }
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 static inline void
kono
parents:
diff changeset
282 uw_update_context (struct _Unwind_Context *context,
kono
parents:
diff changeset
283 _Unwind_FrameState *fs __attribute__((unused)) )
kono
parents:
diff changeset
284 {
kono
parents:
diff changeset
285 context->fc = context->fc->prev;
kono
parents:
diff changeset
286 }
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 static void
kono
parents:
diff changeset
289 uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
kono
parents:
diff changeset
290 {
kono
parents:
diff changeset
291 _Unwind_SjLj_Unregister (context->fc);
kono
parents:
diff changeset
292 uw_update_context (context, fs);
kono
parents:
diff changeset
293 }
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 static inline void
kono
parents:
diff changeset
296 uw_init_context (struct _Unwind_Context *context)
kono
parents:
diff changeset
297 {
kono
parents:
diff changeset
298 context->fc = _Unwind_SjLj_GetContext ();
kono
parents:
diff changeset
299 }
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 static void __attribute__((noreturn))
kono
parents:
diff changeset
302 uw_install_context (struct _Unwind_Context *current __attribute__((unused)),
kono
parents:
diff changeset
303 struct _Unwind_Context *target)
kono
parents:
diff changeset
304 {
kono
parents:
diff changeset
305 _Unwind_SjLj_SetContext (target->fc);
kono
parents:
diff changeset
306 longjmp (target->fc->jbuf, 1);
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 static inline _Unwind_Ptr
kono
parents:
diff changeset
310 uw_identify_context (struct _Unwind_Context *context)
kono
parents:
diff changeset
311 {
kono
parents:
diff changeset
312 return (_Unwind_Ptr) context->fc;
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 /* Play games with unwind symbols so that we can have call frame
kono
parents:
diff changeset
317 and sjlj symbols in the same shared library. Not that you can
kono
parents:
diff changeset
318 use them simultaneously... */
kono
parents:
diff changeset
319 #define _Unwind_RaiseException _Unwind_SjLj_RaiseException
kono
parents:
diff changeset
320 #define _Unwind_ForcedUnwind _Unwind_SjLj_ForcedUnwind
kono
parents:
diff changeset
321 #define _Unwind_Resume _Unwind_SjLj_Resume
kono
parents:
diff changeset
322 #define _Unwind_Resume_or_Rethrow _Unwind_SjLj_Resume_or_Rethrow
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 #include "unwind.inc"
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 #endif /* USING_SJLJ_EXCEPTIONS */