annotate libstdc++-v3/libsupc++/eh_personality.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*- The GNU C++ exception personality routine.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 // Copyright (C) 2001-2020 Free Software Foundation, Inc.
111
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
kono
parents:
diff changeset
7 // it 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,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public 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 <bits/c++config.h>
kono
parents:
diff changeset
26 #include <cstdlib>
kono
parents:
diff changeset
27 #include <bits/exception_defines.h>
kono
parents:
diff changeset
28 #include <cxxabi.h>
kono
parents:
diff changeset
29 #include "unwind-cxx.h"
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 using namespace __cxxabiv1;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 #include "unwind-pe.h"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 struct lsda_header_info
kono
parents:
diff changeset
38 {
kono
parents:
diff changeset
39 _Unwind_Ptr Start;
kono
parents:
diff changeset
40 _Unwind_Ptr LPStart;
kono
parents:
diff changeset
41 _Unwind_Ptr ttype_base;
kono
parents:
diff changeset
42 const unsigned char *TType;
kono
parents:
diff changeset
43 const unsigned char *action_table;
kono
parents:
diff changeset
44 unsigned char ttype_encoding;
kono
parents:
diff changeset
45 unsigned char call_site_encoding;
kono
parents:
diff changeset
46 };
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 static const unsigned char *
kono
parents:
diff changeset
49 parse_lsda_header (_Unwind_Context *context, const unsigned char *p,
kono
parents:
diff changeset
50 lsda_header_info *info)
kono
parents:
diff changeset
51 {
kono
parents:
diff changeset
52 _uleb128_t tmp;
kono
parents:
diff changeset
53 unsigned char lpstart_encoding;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 // Find @LPStart, the base to which landing pad offsets are relative.
kono
parents:
diff changeset
58 lpstart_encoding = *p++;
kono
parents:
diff changeset
59 if (lpstart_encoding != DW_EH_PE_omit)
kono
parents:
diff changeset
60 p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
kono
parents:
diff changeset
61 else
kono
parents:
diff changeset
62 info->LPStart = info->Start;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 // Find @TType, the base of the handler and exception spec type data.
kono
parents:
diff changeset
65 info->ttype_encoding = *p++;
kono
parents:
diff changeset
66 if (info->ttype_encoding != DW_EH_PE_omit)
kono
parents:
diff changeset
67 {
kono
parents:
diff changeset
68 #if _GLIBCXX_OVERRIDE_TTYPE_ENCODING
kono
parents:
diff changeset
69 /* Older ARM EABI toolchains set this value incorrectly, so use a
kono
parents:
diff changeset
70 hardcoded OS-specific format. */
kono
parents:
diff changeset
71 info->ttype_encoding = _GLIBCXX_OVERRIDE_TTYPE_ENCODING;
kono
parents:
diff changeset
72 #endif
kono
parents:
diff changeset
73 p = read_uleb128 (p, &tmp);
kono
parents:
diff changeset
74 info->TType = p + tmp;
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76 else
kono
parents:
diff changeset
77 info->TType = 0;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 // The encoding and length of the call-site table; the action table
kono
parents:
diff changeset
80 // immediately follows.
kono
parents:
diff changeset
81 info->call_site_encoding = *p++;
kono
parents:
diff changeset
82 p = read_uleb128 (p, &tmp);
kono
parents:
diff changeset
83 info->action_table = p + tmp;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 return p;
kono
parents:
diff changeset
86 }
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 // Return an element from a type table.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 static const std::type_info *
kono
parents:
diff changeset
91 get_ttype_entry (lsda_header_info *info, _uleb128_t i)
kono
parents:
diff changeset
92 {
kono
parents:
diff changeset
93 _Unwind_Ptr ptr;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 i *= size_of_encoded_value (info->ttype_encoding);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
96 read_encoded_value_with_base (
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
97 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
98 /* Force these flags to nake sure to
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
99 take the GOT into account. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
100 (DW_EH_PE_pcrel | DW_EH_PE_indirect),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
101 #else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
102 info->ttype_encoding,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
103 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
104 info->ttype_base,
111
kono
parents:
diff changeset
105 info->TType - i, &ptr);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 return reinterpret_cast<const std::type_info *>(ptr);
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 // The ABI provides a routine for matching exception object types.
kono
parents:
diff changeset
113 typedef _Unwind_Control_Block _throw_typet;
kono
parents:
diff changeset
114 #define get_adjusted_ptr(catch_type, throw_type, thrown_ptr_p) \
kono
parents:
diff changeset
115 (__cxa_type_match (throw_type, catch_type, false, thrown_ptr_p) \
kono
parents:
diff changeset
116 != ctm_failed)
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 // Return true if THROW_TYPE matches one if the filter types.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 static bool
kono
parents:
diff changeset
121 check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
kono
parents:
diff changeset
122 void* thrown_ptr, _sleb128_t filter_value)
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 const _uleb128_t* e = ((const _uleb128_t*) info->TType)
kono
parents:
diff changeset
125 - filter_value - 1;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 while (1)
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 const std::type_info* catch_type;
kono
parents:
diff changeset
130 _uleb128_t tmp;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 tmp = *e;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 // Zero signals the end of the list. If we've not found
kono
parents:
diff changeset
135 // a match by now, then we've failed the specification.
kono
parents:
diff changeset
136 if (tmp == 0)
kono
parents:
diff changeset
137 return false;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 tmp = _Unwind_decode_typeinfo_ptr(info->ttype_base, (_Unwind_Word) e);
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 // Match a ttype entry.
kono
parents:
diff changeset
142 catch_type = reinterpret_cast<const std::type_info*>(tmp);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 // ??? There is currently no way to ask the RTTI code about the
kono
parents:
diff changeset
145 // relationship between two types without reference to a specific
kono
parents:
diff changeset
146 // object. There should be; then we wouldn't need to mess with
kono
parents:
diff changeset
147 // thrown_ptr here.
kono
parents:
diff changeset
148 if (get_adjusted_ptr(catch_type, throw_type, &thrown_ptr))
kono
parents:
diff changeset
149 return true;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 // Advance to the next entry.
kono
parents:
diff changeset
152 e++;
kono
parents:
diff changeset
153 }
kono
parents:
diff changeset
154 }
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 // Save stage1 handler information in the exception object
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 static inline void
kono
parents:
diff changeset
160 save_caught_exception(struct _Unwind_Exception* ue_header,
kono
parents:
diff changeset
161 struct _Unwind_Context* context,
kono
parents:
diff changeset
162 void* thrown_ptr,
kono
parents:
diff changeset
163 int handler_switch_value,
kono
parents:
diff changeset
164 const unsigned char* language_specific_data,
kono
parents:
diff changeset
165 _Unwind_Ptr landing_pad,
kono
parents:
diff changeset
166 const unsigned char* action_record
kono
parents:
diff changeset
167 __attribute__((__unused__)))
kono
parents:
diff changeset
168 {
kono
parents:
diff changeset
169 ue_header->barrier_cache.sp = _Unwind_GetGR(context, UNWIND_STACK_REG);
kono
parents:
diff changeset
170 ue_header->barrier_cache.bitpattern[0] = (_uw) thrown_ptr;
kono
parents:
diff changeset
171 ue_header->barrier_cache.bitpattern[1]
kono
parents:
diff changeset
172 = (_uw) handler_switch_value;
kono
parents:
diff changeset
173 ue_header->barrier_cache.bitpattern[2]
kono
parents:
diff changeset
174 = (_uw) language_specific_data;
kono
parents:
diff changeset
175 ue_header->barrier_cache.bitpattern[3] = (_uw) landing_pad;
kono
parents:
diff changeset
176 }
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 // Restore the catch handler data saved during phase1.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 static inline void
kono
parents:
diff changeset
182 restore_caught_exception(struct _Unwind_Exception* ue_header,
kono
parents:
diff changeset
183 int& handler_switch_value,
kono
parents:
diff changeset
184 const unsigned char*& language_specific_data,
kono
parents:
diff changeset
185 _Unwind_Ptr& landing_pad)
kono
parents:
diff changeset
186 {
kono
parents:
diff changeset
187 handler_switch_value = (int) ue_header->barrier_cache.bitpattern[1];
kono
parents:
diff changeset
188 language_specific_data =
kono
parents:
diff changeset
189 (const unsigned char*) ue_header->barrier_cache.bitpattern[2];
kono
parents:
diff changeset
190 landing_pad = (_Unwind_Ptr) ue_header->barrier_cache.bitpattern[3];
kono
parents:
diff changeset
191 }
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 #define CONTINUE_UNWINDING \
kono
parents:
diff changeset
194 do \
kono
parents:
diff changeset
195 { \
kono
parents:
diff changeset
196 if (__gnu_unwind_frame(ue_header, context) != _URC_OK) \
kono
parents:
diff changeset
197 return _URC_FAILURE; \
kono
parents:
diff changeset
198 return _URC_CONTINUE_UNWIND; \
kono
parents:
diff changeset
199 } \
kono
parents:
diff changeset
200 while (0)
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 // Return true if the filter spec is empty, ie throw().
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 static bool
kono
parents:
diff changeset
205 empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
kono
parents:
diff changeset
206 {
kono
parents:
diff changeset
207 const _Unwind_Word* e = ((const _Unwind_Word*) info->TType)
kono
parents:
diff changeset
208 - filter_value - 1;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 return *e == 0;
kono
parents:
diff changeset
211 }
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 #else
kono
parents:
diff changeset
214 typedef const std::type_info _throw_typet;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 // Given the thrown type THROW_TYPE, pointer to a variable containing a
kono
parents:
diff changeset
218 // pointer to the exception object THROWN_PTR_P and a type CATCH_TYPE to
kono
parents:
diff changeset
219 // compare against, return whether or not there is a match and if so,
kono
parents:
diff changeset
220 // update *THROWN_PTR_P.
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 static bool
kono
parents:
diff changeset
223 get_adjusted_ptr (const std::type_info *catch_type,
kono
parents:
diff changeset
224 const std::type_info *throw_type,
kono
parents:
diff changeset
225 void **thrown_ptr_p)
kono
parents:
diff changeset
226 {
kono
parents:
diff changeset
227 void *thrown_ptr = *thrown_ptr_p;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 // Pointer types need to adjust the actual pointer, not
kono
parents:
diff changeset
230 // the pointer to pointer that is the exception object.
kono
parents:
diff changeset
231 // This also has the effect of passing pointer types
kono
parents:
diff changeset
232 // "by value" through the __cxa_begin_catch return value.
kono
parents:
diff changeset
233 if (throw_type->__is_pointer_p ())
kono
parents:
diff changeset
234 thrown_ptr = *(void **) thrown_ptr;
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 if (catch_type->__do_catch (throw_type, &thrown_ptr, 1))
kono
parents:
diff changeset
237 {
kono
parents:
diff changeset
238 *thrown_ptr_p = thrown_ptr;
kono
parents:
diff changeset
239 return true;
kono
parents:
diff changeset
240 }
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 return false;
kono
parents:
diff changeset
243 }
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 // Return true if THROW_TYPE matches one if the filter types.
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 static bool
kono
parents:
diff changeset
248 check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
kono
parents:
diff changeset
249 void* thrown_ptr, _sleb128_t filter_value)
kono
parents:
diff changeset
250 {
kono
parents:
diff changeset
251 const unsigned char *e = info->TType - filter_value - 1;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 while (1)
kono
parents:
diff changeset
254 {
kono
parents:
diff changeset
255 const std::type_info *catch_type;
kono
parents:
diff changeset
256 _uleb128_t tmp;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 e = read_uleb128 (e, &tmp);
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 // Zero signals the end of the list. If we've not found
kono
parents:
diff changeset
261 // a match by now, then we've failed the specification.
kono
parents:
diff changeset
262 if (tmp == 0)
kono
parents:
diff changeset
263 return false;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 // Match a ttype entry.
kono
parents:
diff changeset
266 catch_type = get_ttype_entry (info, tmp);
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 // ??? There is currently no way to ask the RTTI code about the
kono
parents:
diff changeset
269 // relationship between two types without reference to a specific
kono
parents:
diff changeset
270 // object. There should be; then we wouldn't need to mess with
kono
parents:
diff changeset
271 // thrown_ptr here.
kono
parents:
diff changeset
272 if (get_adjusted_ptr (catch_type, throw_type, &thrown_ptr))
kono
parents:
diff changeset
273 return true;
kono
parents:
diff changeset
274 }
kono
parents:
diff changeset
275 }
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 // Save stage1 handler information in the exception object
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 static inline void
kono
parents:
diff changeset
281 save_caught_exception(struct _Unwind_Exception* ue_header,
kono
parents:
diff changeset
282 struct _Unwind_Context* context
kono
parents:
diff changeset
283 __attribute__((__unused__)),
kono
parents:
diff changeset
284 void* thrown_ptr,
kono
parents:
diff changeset
285 int handler_switch_value,
kono
parents:
diff changeset
286 const unsigned char* language_specific_data,
kono
parents:
diff changeset
287 _Unwind_Ptr landing_pad __attribute__((__unused__)),
kono
parents:
diff changeset
288 const unsigned char* action_record)
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 xh->handlerSwitchValue = handler_switch_value;
kono
parents:
diff changeset
293 xh->actionRecord = action_record;
kono
parents:
diff changeset
294 xh->languageSpecificData = language_specific_data;
kono
parents:
diff changeset
295 xh->adjustedPtr = thrown_ptr;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 // ??? Completely unknown what this field is supposed to be for.
kono
parents:
diff changeset
298 // ??? Need to cache TType encoding base for call_unexpected.
kono
parents:
diff changeset
299 xh->catchTemp = landing_pad;
kono
parents:
diff changeset
300 }
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 // Restore the catch handler information saved during phase1.
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 static inline void
kono
parents:
diff changeset
306 restore_caught_exception(struct _Unwind_Exception* ue_header,
kono
parents:
diff changeset
307 int& handler_switch_value,
kono
parents:
diff changeset
308 const unsigned char*& language_specific_data,
kono
parents:
diff changeset
309 _Unwind_Ptr& landing_pad)
kono
parents:
diff changeset
310 {
kono
parents:
diff changeset
311 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
kono
parents:
diff changeset
312 handler_switch_value = xh->handlerSwitchValue;
kono
parents:
diff changeset
313 language_specific_data = xh->languageSpecificData;
kono
parents:
diff changeset
314 landing_pad = (_Unwind_Ptr) xh->catchTemp;
kono
parents:
diff changeset
315 }
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 #define CONTINUE_UNWINDING return _URC_CONTINUE_UNWIND
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 // Return true if the filter spec is empty, ie throw().
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 static bool
kono
parents:
diff changeset
322 empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
kono
parents:
diff changeset
323 {
kono
parents:
diff changeset
324 const unsigned char *e = info->TType - filter_value - 1;
kono
parents:
diff changeset
325 _uleb128_t tmp;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 e = read_uleb128 (e, &tmp);
kono
parents:
diff changeset
328 return tmp == 0;
kono
parents:
diff changeset
329 }
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 #endif // !__ARM_EABI_UNWINDER__
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 namespace __cxxabiv1
kono
parents:
diff changeset
334 {
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 // Using a different personality function name causes link failures
kono
parents:
diff changeset
337 // when trying to mix code using different exception handling models.
kono
parents:
diff changeset
338 #ifdef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
339 #define PERSONALITY_FUNCTION __gxx_personality_sj0
kono
parents:
diff changeset
340 #define __builtin_eh_return_data_regno(x) x
kono
parents:
diff changeset
341 #elif defined(__SEH__)
kono
parents:
diff changeset
342 #define PERSONALITY_FUNCTION __gxx_personality_imp
kono
parents:
diff changeset
343 #else
kono
parents:
diff changeset
344 #define PERSONALITY_FUNCTION __gxx_personality_v0
kono
parents:
diff changeset
345 #endif
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 #if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
kono
parents:
diff changeset
348 static
kono
parents:
diff changeset
349 #else
kono
parents:
diff changeset
350 extern "C"
kono
parents:
diff changeset
351 #endif
kono
parents:
diff changeset
352 _Unwind_Reason_Code
kono
parents:
diff changeset
353 #ifdef __ARM_EABI_UNWINDER__
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
354 __attribute__((target ("general-regs-only")))
111
kono
parents:
diff changeset
355 PERSONALITY_FUNCTION (_Unwind_State state,
kono
parents:
diff changeset
356 struct _Unwind_Exception* ue_header,
kono
parents:
diff changeset
357 struct _Unwind_Context* context)
kono
parents:
diff changeset
358 #else
kono
parents:
diff changeset
359 PERSONALITY_FUNCTION (int version,
kono
parents:
diff changeset
360 _Unwind_Action actions,
kono
parents:
diff changeset
361 _Unwind_Exception_Class exception_class,
kono
parents:
diff changeset
362 struct _Unwind_Exception *ue_header,
kono
parents:
diff changeset
363 struct _Unwind_Context *context)
kono
parents:
diff changeset
364 #endif
kono
parents:
diff changeset
365 {
kono
parents:
diff changeset
366 enum found_handler_type
kono
parents:
diff changeset
367 {
kono
parents:
diff changeset
368 found_nothing,
kono
parents:
diff changeset
369 found_terminate,
kono
parents:
diff changeset
370 found_cleanup,
kono
parents:
diff changeset
371 found_handler
kono
parents:
diff changeset
372 } found_type;
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 lsda_header_info info;
kono
parents:
diff changeset
375 const unsigned char *language_specific_data;
kono
parents:
diff changeset
376 const unsigned char *action_record;
kono
parents:
diff changeset
377 const unsigned char *p;
kono
parents:
diff changeset
378 _Unwind_Ptr landing_pad, ip;
kono
parents:
diff changeset
379 int handler_switch_value;
kono
parents:
diff changeset
380 void* thrown_ptr = 0;
kono
parents:
diff changeset
381 bool foreign_exception;
kono
parents:
diff changeset
382 int ip_before_insn = 0;
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
385 _Unwind_Action actions;
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 switch (state & _US_ACTION_MASK)
kono
parents:
diff changeset
388 {
kono
parents:
diff changeset
389 case _US_VIRTUAL_UNWIND_FRAME:
kono
parents:
diff changeset
390 // If the unwind state pattern is
kono
parents:
diff changeset
391 // _US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND
kono
parents:
diff changeset
392 // then we don't need to search for any handler as it is not a real
kono
parents:
diff changeset
393 // exception. Just unwind the stack.
kono
parents:
diff changeset
394 if (state & _US_FORCE_UNWIND)
kono
parents:
diff changeset
395 CONTINUE_UNWINDING;
kono
parents:
diff changeset
396 actions = _UA_SEARCH_PHASE;
kono
parents:
diff changeset
397 break;
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 case _US_UNWIND_FRAME_STARTING:
kono
parents:
diff changeset
400 actions = _UA_CLEANUP_PHASE;
kono
parents:
diff changeset
401 if (!(state & _US_FORCE_UNWIND)
kono
parents:
diff changeset
402 && ue_header->barrier_cache.sp == _Unwind_GetGR(context,
kono
parents:
diff changeset
403 UNWIND_STACK_REG))
kono
parents:
diff changeset
404 actions |= _UA_HANDLER_FRAME;
kono
parents:
diff changeset
405 break;
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 case _US_UNWIND_FRAME_RESUME:
kono
parents:
diff changeset
408 CONTINUE_UNWINDING;
kono
parents:
diff changeset
409 break;
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 default:
kono
parents:
diff changeset
412 std::abort();
kono
parents:
diff changeset
413 }
kono
parents:
diff changeset
414 actions |= state & _US_FORCE_UNWIND;
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 // We don't know which runtime we're working with, so can't check this.
kono
parents:
diff changeset
417 // However the ABI routines hide this from us, and we don't actually need
kono
parents:
diff changeset
418 // to know.
kono
parents:
diff changeset
419 foreign_exception = false;
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 // The dwarf unwinder assumes the context structure holds things like the
kono
parents:
diff changeset
422 // function and LSDA pointers. The ARM implementation caches these in
kono
parents:
diff changeset
423 // the exception header (UCB). To avoid rewriting everything we make a
kono
parents:
diff changeset
424 // virtual scratch register point at the UCB.
kono
parents:
diff changeset
425 ip = (_Unwind_Ptr) ue_header;
kono
parents:
diff changeset
426 _Unwind_SetGR(context, UNWIND_POINTER_REG, ip);
kono
parents:
diff changeset
427 #else
kono
parents:
diff changeset
428 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 // Interface version check.
kono
parents:
diff changeset
431 if (version != 1)
kono
parents:
diff changeset
432 return _URC_FATAL_PHASE1_ERROR;
kono
parents:
diff changeset
433 foreign_exception = !__is_gxx_exception_class(exception_class);
kono
parents:
diff changeset
434 #endif
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 // Shortcut for phase 2 found handler for domestic exception.
kono
parents:
diff changeset
437 if (actions == (_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME)
kono
parents:
diff changeset
438 && !foreign_exception)
kono
parents:
diff changeset
439 {
kono
parents:
diff changeset
440 restore_caught_exception(ue_header, handler_switch_value,
kono
parents:
diff changeset
441 language_specific_data, landing_pad);
kono
parents:
diff changeset
442 found_type = (landing_pad == 0 ? found_terminate : found_handler);
kono
parents:
diff changeset
443 goto install_context;
kono
parents:
diff changeset
444 }
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 language_specific_data = (const unsigned char *)
kono
parents:
diff changeset
447 _Unwind_GetLanguageSpecificData (context);
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 // If no LSDA, then there are no handlers or cleanups.
kono
parents:
diff changeset
450 if (! language_specific_data)
kono
parents:
diff changeset
451 CONTINUE_UNWINDING;
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 // Parse the LSDA header.
kono
parents:
diff changeset
454 p = parse_lsda_header (context, language_specific_data, &info);
kono
parents:
diff changeset
455 info.ttype_base = base_of_encoded_value (info.ttype_encoding, context);
kono
parents:
diff changeset
456 #ifdef _GLIBCXX_HAVE_GETIPINFO
kono
parents:
diff changeset
457 ip = _Unwind_GetIPInfo (context, &ip_before_insn);
kono
parents:
diff changeset
458 #else
kono
parents:
diff changeset
459 ip = _Unwind_GetIP (context);
kono
parents:
diff changeset
460 #endif
kono
parents:
diff changeset
461 if (! ip_before_insn)
kono
parents:
diff changeset
462 --ip;
kono
parents:
diff changeset
463 landing_pad = 0;
kono
parents:
diff changeset
464 action_record = 0;
kono
parents:
diff changeset
465 handler_switch_value = 0;
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 #ifdef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
468 // The given "IP" is an index into the call-site table, with two
kono
parents:
diff changeset
469 // exceptions -- -1 means no-action, and 0 means terminate. But
kono
parents:
diff changeset
470 // since we're using uleb128 values, we've not got random access
kono
parents:
diff changeset
471 // to the array.
kono
parents:
diff changeset
472 if ((int) ip < 0)
kono
parents:
diff changeset
473 return _URC_CONTINUE_UNWIND;
kono
parents:
diff changeset
474 else if (ip == 0)
kono
parents:
diff changeset
475 {
kono
parents:
diff changeset
476 // Fall through to set found_terminate.
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478 else
kono
parents:
diff changeset
479 {
kono
parents:
diff changeset
480 _uleb128_t cs_lp, cs_action;
kono
parents:
diff changeset
481 do
kono
parents:
diff changeset
482 {
kono
parents:
diff changeset
483 p = read_uleb128 (p, &cs_lp);
kono
parents:
diff changeset
484 p = read_uleb128 (p, &cs_action);
kono
parents:
diff changeset
485 }
kono
parents:
diff changeset
486 while (--ip);
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 // Can never have null landing pad for sjlj -- that would have
kono
parents:
diff changeset
489 // been indicated by a -1 call site index.
kono
parents:
diff changeset
490 landing_pad = cs_lp + 1;
kono
parents:
diff changeset
491 if (cs_action)
kono
parents:
diff changeset
492 action_record = info.action_table + cs_action - 1;
kono
parents:
diff changeset
493 goto found_something;
kono
parents:
diff changeset
494 }
kono
parents:
diff changeset
495 #else
kono
parents:
diff changeset
496 // Search the call-site table for the action associated with this IP.
kono
parents:
diff changeset
497 while (p < info.action_table)
kono
parents:
diff changeset
498 {
kono
parents:
diff changeset
499 _Unwind_Ptr cs_start, cs_len, cs_lp;
kono
parents:
diff changeset
500 _uleb128_t cs_action;
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 // Note that all call-site encodings are "absolute" displacements.
kono
parents:
diff changeset
503 p = read_encoded_value (0, info.call_site_encoding, p, &cs_start);
kono
parents:
diff changeset
504 p = read_encoded_value (0, info.call_site_encoding, p, &cs_len);
kono
parents:
diff changeset
505 p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp);
kono
parents:
diff changeset
506 p = read_uleb128 (p, &cs_action);
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 // The table is sorted, so if we've passed the ip, stop.
kono
parents:
diff changeset
509 if (ip < info.Start + cs_start)
kono
parents:
diff changeset
510 p = info.action_table;
kono
parents:
diff changeset
511 else if (ip < info.Start + cs_start + cs_len)
kono
parents:
diff changeset
512 {
kono
parents:
diff changeset
513 if (cs_lp)
kono
parents:
diff changeset
514 landing_pad = info.LPStart + cs_lp;
kono
parents:
diff changeset
515 if (cs_action)
kono
parents:
diff changeset
516 action_record = info.action_table + cs_action - 1;
kono
parents:
diff changeset
517 goto found_something;
kono
parents:
diff changeset
518 }
kono
parents:
diff changeset
519 }
kono
parents:
diff changeset
520 #endif // __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 // If ip is not present in the table, call terminate. This is for
kono
parents:
diff changeset
523 // a destructor inside a cleanup, or a library routine the compiler
kono
parents:
diff changeset
524 // was not expecting to throw.
kono
parents:
diff changeset
525 found_type = found_terminate;
kono
parents:
diff changeset
526 goto do_something;
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 found_something:
kono
parents:
diff changeset
529 if (landing_pad == 0)
kono
parents:
diff changeset
530 {
kono
parents:
diff changeset
531 // If ip is present, and has a null landing pad, there are
kono
parents:
diff changeset
532 // no cleanups or handlers to be run.
kono
parents:
diff changeset
533 found_type = found_nothing;
kono
parents:
diff changeset
534 }
kono
parents:
diff changeset
535 else if (action_record == 0)
kono
parents:
diff changeset
536 {
kono
parents:
diff changeset
537 // If ip is present, has a non-null landing pad, and a null
kono
parents:
diff changeset
538 // action table offset, then there are only cleanups present.
kono
parents:
diff changeset
539 // Cleanups use a zero switch value, as set above.
kono
parents:
diff changeset
540 found_type = found_cleanup;
kono
parents:
diff changeset
541 }
kono
parents:
diff changeset
542 else
kono
parents:
diff changeset
543 {
kono
parents:
diff changeset
544 // Otherwise we have a catch handler or exception specification.
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 _sleb128_t ar_filter, ar_disp;
kono
parents:
diff changeset
547 const std::type_info* catch_type;
kono
parents:
diff changeset
548 _throw_typet* throw_type;
kono
parents:
diff changeset
549 bool saw_cleanup = false;
kono
parents:
diff changeset
550 bool saw_handler = false;
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
553 // ??? How does this work - more importantly, how does it interact with
kono
parents:
diff changeset
554 // dependent exceptions?
kono
parents:
diff changeset
555 throw_type = ue_header;
kono
parents:
diff changeset
556 if (actions & _UA_FORCE_UNWIND)
kono
parents:
diff changeset
557 {
kono
parents:
diff changeset
558 __GXX_INIT_FORCED_UNWIND_CLASS(ue_header->exception_class);
kono
parents:
diff changeset
559 }
kono
parents:
diff changeset
560 else if (!foreign_exception)
kono
parents:
diff changeset
561 thrown_ptr = __get_object_from_ue (ue_header);
kono
parents:
diff changeset
562 #else
kono
parents:
diff changeset
563 #if __cpp_rtti
kono
parents:
diff changeset
564 // During forced unwinding, match a magic exception type.
kono
parents:
diff changeset
565 if (actions & _UA_FORCE_UNWIND)
kono
parents:
diff changeset
566 {
kono
parents:
diff changeset
567 throw_type = &typeid(abi::__forced_unwind);
kono
parents:
diff changeset
568 }
kono
parents:
diff changeset
569 // With a foreign exception class, there's no exception type.
kono
parents:
diff changeset
570 // ??? What to do about GNU Java and GNU Ada exceptions?
kono
parents:
diff changeset
571 else if (foreign_exception)
kono
parents:
diff changeset
572 {
kono
parents:
diff changeset
573 throw_type = &typeid(abi::__foreign_exception);
kono
parents:
diff changeset
574 }
kono
parents:
diff changeset
575 else
kono
parents:
diff changeset
576 #endif
kono
parents:
diff changeset
577 {
kono
parents:
diff changeset
578 thrown_ptr = __get_object_from_ue (ue_header);
kono
parents:
diff changeset
579 throw_type = __get_exception_header_from_obj
kono
parents:
diff changeset
580 (thrown_ptr)->exceptionType;
kono
parents:
diff changeset
581 }
kono
parents:
diff changeset
582 #endif
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 while (1)
kono
parents:
diff changeset
585 {
kono
parents:
diff changeset
586 p = action_record;
kono
parents:
diff changeset
587 p = read_sleb128 (p, &ar_filter);
kono
parents:
diff changeset
588 read_sleb128 (p, &ar_disp);
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 if (ar_filter == 0)
kono
parents:
diff changeset
591 {
kono
parents:
diff changeset
592 // Zero filter values are cleanups.
kono
parents:
diff changeset
593 saw_cleanup = true;
kono
parents:
diff changeset
594 }
kono
parents:
diff changeset
595 else if (ar_filter > 0)
kono
parents:
diff changeset
596 {
kono
parents:
diff changeset
597 // Positive filter values are handlers.
kono
parents:
diff changeset
598 catch_type = get_ttype_entry (&info, ar_filter);
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 // Null catch type is a catch-all handler; we can catch foreign
kono
parents:
diff changeset
601 // exceptions with this. Otherwise we must match types.
kono
parents:
diff changeset
602 if (! catch_type
kono
parents:
diff changeset
603 || (throw_type
kono
parents:
diff changeset
604 && get_adjusted_ptr (catch_type, throw_type,
kono
parents:
diff changeset
605 &thrown_ptr)))
kono
parents:
diff changeset
606 {
kono
parents:
diff changeset
607 saw_handler = true;
kono
parents:
diff changeset
608 break;
kono
parents:
diff changeset
609 }
kono
parents:
diff changeset
610 }
kono
parents:
diff changeset
611 else
kono
parents:
diff changeset
612 {
kono
parents:
diff changeset
613 // Negative filter values are exception specifications.
kono
parents:
diff changeset
614 // ??? How do foreign exceptions fit in? As far as I can
kono
parents:
diff changeset
615 // see we can't match because there's no __cxa_exception
kono
parents:
diff changeset
616 // object to stuff bits in for __cxa_call_unexpected to use.
kono
parents:
diff changeset
617 // Allow them iff the exception spec is non-empty. I.e.
kono
parents:
diff changeset
618 // a throw() specification results in __unexpected.
kono
parents:
diff changeset
619 if ((throw_type
kono
parents:
diff changeset
620 && !(actions & _UA_FORCE_UNWIND)
kono
parents:
diff changeset
621 && !foreign_exception)
kono
parents:
diff changeset
622 ? ! check_exception_spec (&info, throw_type, thrown_ptr,
kono
parents:
diff changeset
623 ar_filter)
kono
parents:
diff changeset
624 : empty_exception_spec (&info, ar_filter))
kono
parents:
diff changeset
625 {
kono
parents:
diff changeset
626 saw_handler = true;
kono
parents:
diff changeset
627 break;
kono
parents:
diff changeset
628 }
kono
parents:
diff changeset
629 }
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 if (ar_disp == 0)
kono
parents:
diff changeset
632 break;
kono
parents:
diff changeset
633 action_record = p + ar_disp;
kono
parents:
diff changeset
634 }
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 if (saw_handler)
kono
parents:
diff changeset
637 {
kono
parents:
diff changeset
638 handler_switch_value = ar_filter;
kono
parents:
diff changeset
639 found_type = found_handler;
kono
parents:
diff changeset
640 }
kono
parents:
diff changeset
641 else
kono
parents:
diff changeset
642 found_type = (saw_cleanup ? found_cleanup : found_nothing);
kono
parents:
diff changeset
643 }
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 do_something:
kono
parents:
diff changeset
646 if (found_type == found_nothing)
kono
parents:
diff changeset
647 CONTINUE_UNWINDING;
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 if (actions & _UA_SEARCH_PHASE)
kono
parents:
diff changeset
650 {
kono
parents:
diff changeset
651 if (found_type == found_cleanup)
kono
parents:
diff changeset
652 CONTINUE_UNWINDING;
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 // For domestic exceptions, we cache data from phase 1 for phase 2.
kono
parents:
diff changeset
655 if (!foreign_exception)
kono
parents:
diff changeset
656 {
kono
parents:
diff changeset
657 save_caught_exception(ue_header, context, thrown_ptr,
kono
parents:
diff changeset
658 handler_switch_value, language_specific_data,
kono
parents:
diff changeset
659 landing_pad, action_record);
kono
parents:
diff changeset
660 }
kono
parents:
diff changeset
661 return _URC_HANDLER_FOUND;
kono
parents:
diff changeset
662 }
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 install_context:
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 // We can't use any of the cxa routines with foreign exceptions,
kono
parents:
diff changeset
667 // because they all expect ue_header to be a struct __cxa_exception.
kono
parents:
diff changeset
668 // So in that case, call terminate or unexpected directly.
kono
parents:
diff changeset
669 if ((actions & _UA_FORCE_UNWIND)
kono
parents:
diff changeset
670 || foreign_exception)
kono
parents:
diff changeset
671 {
kono
parents:
diff changeset
672 if (found_type == found_terminate)
kono
parents:
diff changeset
673 std::terminate ();
kono
parents:
diff changeset
674 else if (handler_switch_value < 0)
kono
parents:
diff changeset
675 {
kono
parents:
diff changeset
676 __try
kono
parents:
diff changeset
677 { std::unexpected (); }
kono
parents:
diff changeset
678 __catch(...)
kono
parents:
diff changeset
679 { std::terminate (); }
kono
parents:
diff changeset
680 }
kono
parents:
diff changeset
681 }
kono
parents:
diff changeset
682 else
kono
parents:
diff changeset
683 {
kono
parents:
diff changeset
684 if (found_type == found_terminate)
kono
parents:
diff changeset
685 __cxa_call_terminate(ue_header);
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 // Cache the TType base value for __cxa_call_unexpected, as we won't
kono
parents:
diff changeset
688 // have an _Unwind_Context then.
kono
parents:
diff changeset
689 if (handler_switch_value < 0)
kono
parents:
diff changeset
690 {
kono
parents:
diff changeset
691 parse_lsda_header (context, language_specific_data, &info);
kono
parents:
diff changeset
692 info.ttype_base = base_of_encoded_value (info.ttype_encoding,
kono
parents:
diff changeset
693 context);
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
696 const _Unwind_Word* e;
kono
parents:
diff changeset
697 _Unwind_Word n;
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 e = ((const _Unwind_Word*) info.TType) - handler_switch_value - 1;
kono
parents:
diff changeset
700 // Count the number of rtti objects.
kono
parents:
diff changeset
701 n = 0;
kono
parents:
diff changeset
702 while (e[n] != 0)
kono
parents:
diff changeset
703 n++;
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 // Count.
kono
parents:
diff changeset
706 ue_header->barrier_cache.bitpattern[1] = n;
kono
parents:
diff changeset
707 // Base
kono
parents:
diff changeset
708 ue_header->barrier_cache.bitpattern[2] = info.ttype_base;
kono
parents:
diff changeset
709 // Stride.
kono
parents:
diff changeset
710 ue_header->barrier_cache.bitpattern[3] = 4;
kono
parents:
diff changeset
711 // List head.
kono
parents:
diff changeset
712 ue_header->barrier_cache.bitpattern[4] = (_Unwind_Word) e;
kono
parents:
diff changeset
713 #else
kono
parents:
diff changeset
714 xh->catchTemp = base_of_encoded_value (info.ttype_encoding, context);
kono
parents:
diff changeset
715 #endif
kono
parents:
diff changeset
716 }
kono
parents:
diff changeset
717 }
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 /* For targets with pointers smaller than the word size, we must extend the
kono
parents:
diff changeset
720 pointer, and this extension is target dependent. */
kono
parents:
diff changeset
721 _Unwind_SetGR (context, __builtin_eh_return_data_regno (0),
kono
parents:
diff changeset
722 __builtin_extend_pointer (ue_header));
kono
parents:
diff changeset
723 _Unwind_SetGR (context, __builtin_eh_return_data_regno (1),
kono
parents:
diff changeset
724 handler_switch_value);
kono
parents:
diff changeset
725 _Unwind_SetIP (context, landing_pad);
kono
parents:
diff changeset
726 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
727 if (found_type == found_cleanup)
kono
parents:
diff changeset
728 __cxa_begin_cleanup(ue_header);
kono
parents:
diff changeset
729 #endif
kono
parents:
diff changeset
730 return _URC_INSTALL_CONTEXT;
kono
parents:
diff changeset
731 }
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 /* The ARM EABI implementation of __cxa_call_unexpected is in a
kono
parents:
diff changeset
734 different file so that the personality routine (PR) can be used
kono
parents:
diff changeset
735 standalone. The generic routine shared datastructures with the PR
kono
parents:
diff changeset
736 so it is most convenient to implement it here. */
kono
parents:
diff changeset
737 #ifndef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
738 extern "C" void
kono
parents:
diff changeset
739 __cxa_call_unexpected (void *exc_obj_in)
kono
parents:
diff changeset
740 {
kono
parents:
diff changeset
741 _Unwind_Exception *exc_obj
kono
parents:
diff changeset
742 = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 __cxa_begin_catch (exc_obj);
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 // This function is a handler for our exception argument. If we exit
kono
parents:
diff changeset
747 // by throwing a different exception, we'll need the original cleaned up.
kono
parents:
diff changeset
748 struct end_catch_protect
kono
parents:
diff changeset
749 {
kono
parents:
diff changeset
750 end_catch_protect() { }
kono
parents:
diff changeset
751 ~end_catch_protect() { __cxa_end_catch(); }
kono
parents:
diff changeset
752 } end_catch_protect_obj;
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 lsda_header_info info;
kono
parents:
diff changeset
755 __cxa_exception *xh = __get_exception_header_from_ue (exc_obj);
kono
parents:
diff changeset
756 const unsigned char *xh_lsda;
kono
parents:
diff changeset
757 _Unwind_Sword xh_switch_value;
kono
parents:
diff changeset
758 std::terminate_handler xh_terminate_handler;
kono
parents:
diff changeset
759
kono
parents:
diff changeset
760 // If the unexpectedHandler rethrows the exception (e.g. to categorize it),
kono
parents:
diff changeset
761 // it will clobber data about the current handler. So copy the data out now.
kono
parents:
diff changeset
762 xh_lsda = xh->languageSpecificData;
kono
parents:
diff changeset
763 xh_switch_value = xh->handlerSwitchValue;
kono
parents:
diff changeset
764 xh_terminate_handler = xh->terminateHandler;
kono
parents:
diff changeset
765 info.ttype_base = (_Unwind_Ptr) xh->catchTemp;
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 __try
kono
parents:
diff changeset
768 { __unexpected (xh->unexpectedHandler); }
kono
parents:
diff changeset
769 __catch(...)
kono
parents:
diff changeset
770 {
kono
parents:
diff changeset
771 // Get the exception thrown from unexpected.
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 __cxa_eh_globals *globals = __cxa_get_globals_fast ();
kono
parents:
diff changeset
774 __cxa_exception *new_xh = globals->caughtExceptions;
kono
parents:
diff changeset
775 void *new_ptr = __get_object_from_ambiguous_exception (new_xh);
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 // We don't quite have enough stuff cached; re-parse the LSDA.
kono
parents:
diff changeset
778 parse_lsda_header (0, xh_lsda, &info);
kono
parents:
diff changeset
779
kono
parents:
diff changeset
780 // If this new exception meets the exception spec, allow it.
kono
parents:
diff changeset
781 if (check_exception_spec (&info, __get_exception_header_from_obj
kono
parents:
diff changeset
782 (new_ptr)->exceptionType,
kono
parents:
diff changeset
783 new_ptr, xh_switch_value))
kono
parents:
diff changeset
784 { __throw_exception_again; }
kono
parents:
diff changeset
785
kono
parents:
diff changeset
786 // If the exception spec allows std::bad_exception, throw that.
kono
parents:
diff changeset
787 // We don't have a thrown object to compare against, but since
kono
parents:
diff changeset
788 // bad_exception doesn't have virtual bases, that's OK; just pass 0.
kono
parents:
diff changeset
789 #if __cpp_exceptions && __cpp_rtti
kono
parents:
diff changeset
790 const std::type_info &bad_exc = typeid (std::bad_exception);
kono
parents:
diff changeset
791 if (check_exception_spec (&info, &bad_exc, 0, xh_switch_value))
kono
parents:
diff changeset
792 throw std::bad_exception();
kono
parents:
diff changeset
793 #endif
kono
parents:
diff changeset
794
kono
parents:
diff changeset
795 // Otherwise, die.
kono
parents:
diff changeset
796 __terminate (xh_terminate_handler);
kono
parents:
diff changeset
797 }
kono
parents:
diff changeset
798 }
kono
parents:
diff changeset
799 #endif
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 #if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
kono
parents:
diff changeset
802 extern "C"
kono
parents:
diff changeset
803 EXCEPTION_DISPOSITION
kono
parents:
diff changeset
804 __gxx_personality_seh0 (PEXCEPTION_RECORD ms_exc, void *this_frame,
kono
parents:
diff changeset
805 PCONTEXT ms_orig_context, PDISPATCHER_CONTEXT ms_disp)
kono
parents:
diff changeset
806 {
kono
parents:
diff changeset
807 return _GCC_specific_handler (ms_exc, this_frame, ms_orig_context,
kono
parents:
diff changeset
808 ms_disp, __gxx_personality_imp);
kono
parents:
diff changeset
809 }
kono
parents:
diff changeset
810 #endif /* SEH */
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 } // namespace __cxxabiv1