* testsuite/18_support/initializer_list/range_access.cc: Fix copying
[official-gcc.git] / libstdc++-v3 / libsupc++ / eh_personality.cc
blob72f596e0692c9758998d0094a4831e56e03ef52f
1 // -*- C++ -*- The GNU C++ exception personality routine.
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of GCC.
7 //
8 // GCC is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // GCC is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 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 #include <bits/c++config.h>
28 #include <cstdlib>
29 #include <bits/exception_defines.h>
30 #include <cxxabi.h>
31 #include "unwind-cxx.h"
34 using namespace __cxxabiv1;
36 #include "unwind-pe.h"
39 struct lsda_header_info
41 _Unwind_Ptr Start;
42 _Unwind_Ptr LPStart;
43 _Unwind_Ptr ttype_base;
44 const unsigned char *TType;
45 const unsigned char *action_table;
46 unsigned char ttype_encoding;
47 unsigned char call_site_encoding;
50 static const unsigned char *
51 parse_lsda_header (_Unwind_Context *context, const unsigned char *p,
52 lsda_header_info *info)
54 _uleb128_t tmp;
55 unsigned char lpstart_encoding;
57 info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
59 // Find @LPStart, the base to which landing pad offsets are relative.
60 lpstart_encoding = *p++;
61 if (lpstart_encoding != DW_EH_PE_omit)
62 p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
63 else
64 info->LPStart = info->Start;
66 // Find @TType, the base of the handler and exception spec type data.
67 info->ttype_encoding = *p++;
68 if (info->ttype_encoding != DW_EH_PE_omit)
70 #if _GLIBCXX_OVERRIDE_TTYPE_ENCODING
71 /* Older ARM EABI toolchains set this value incorrectly, so use a
72 hardcoded OS-specific format. */
73 info->ttype_encoding = _GLIBCXX_OVERRIDE_TTYPE_ENCODING;
74 #endif
75 p = read_uleb128 (p, &tmp);
76 info->TType = p + tmp;
78 else
79 info->TType = 0;
81 // The encoding and length of the call-site table; the action table
82 // immediately follows.
83 info->call_site_encoding = *p++;
84 p = read_uleb128 (p, &tmp);
85 info->action_table = p + tmp;
87 return p;
90 // Return an element from a type table.
92 static const std::type_info *
93 get_ttype_entry (lsda_header_info *info, _uleb128_t i)
95 _Unwind_Ptr ptr;
97 i *= size_of_encoded_value (info->ttype_encoding);
98 read_encoded_value_with_base (info->ttype_encoding, info->ttype_base,
99 info->TType - i, &ptr);
101 return reinterpret_cast<const std::type_info *>(ptr);
104 #ifdef __ARM_EABI_UNWINDER__
106 // The ABI provides a routine for matching exception object types.
107 typedef _Unwind_Control_Block _throw_typet;
108 #define get_adjusted_ptr(catch_type, throw_type, thrown_ptr_p) \
109 (__cxa_type_match (throw_type, catch_type, false, thrown_ptr_p) \
110 != ctm_failed)
112 // Return true if THROW_TYPE matches one if the filter types.
114 static bool
115 check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
116 void* thrown_ptr, _sleb128_t filter_value)
118 const _uleb128_t* e = ((const _uleb128_t*) info->TType)
119 - filter_value - 1;
121 while (1)
123 const std::type_info* catch_type;
124 _uleb128_t tmp;
126 tmp = *e;
128 // Zero signals the end of the list. If we've not found
129 // a match by now, then we've failed the specification.
130 if (tmp == 0)
131 return false;
133 tmp = _Unwind_decode_typeinfo_ptr(info->ttype_base, (_Unwind_Word) e);
135 // Match a ttype entry.
136 catch_type = reinterpret_cast<const std::type_info*>(tmp);
138 // ??? There is currently no way to ask the RTTI code about the
139 // relationship between two types without reference to a specific
140 // object. There should be; then we wouldn't need to mess with
141 // thrown_ptr here.
142 if (get_adjusted_ptr(catch_type, throw_type, &thrown_ptr))
143 return true;
145 // Advance to the next entry.
146 e++;
151 // Save stage1 handler information in the exception object
153 static inline void
154 save_caught_exception(struct _Unwind_Exception* ue_header,
155 struct _Unwind_Context* context,
156 void* thrown_ptr,
157 int handler_switch_value,
158 const unsigned char* language_specific_data,
159 _Unwind_Ptr landing_pad,
160 const unsigned char* action_record
161 __attribute__((__unused__)))
163 ue_header->barrier_cache.sp = _Unwind_GetGR(context, UNWIND_STACK_REG);
164 ue_header->barrier_cache.bitpattern[0] = (_uw) thrown_ptr;
165 ue_header->barrier_cache.bitpattern[1]
166 = (_uw) handler_switch_value;
167 ue_header->barrier_cache.bitpattern[2]
168 = (_uw) language_specific_data;
169 ue_header->barrier_cache.bitpattern[3] = (_uw) landing_pad;
173 // Restore the catch handler data saved during phase1.
175 static inline void
176 restore_caught_exception(struct _Unwind_Exception* ue_header,
177 int& handler_switch_value,
178 const unsigned char*& language_specific_data,
179 _Unwind_Ptr& landing_pad)
181 handler_switch_value = (int) ue_header->barrier_cache.bitpattern[1];
182 language_specific_data =
183 (const unsigned char*) ue_header->barrier_cache.bitpattern[2];
184 landing_pad = (_Unwind_Ptr) ue_header->barrier_cache.bitpattern[3];
187 #define CONTINUE_UNWINDING \
188 do \
190 if (__gnu_unwind_frame(ue_header, context) != _URC_OK) \
191 return _URC_FAILURE; \
192 return _URC_CONTINUE_UNWIND; \
194 while (0)
196 // Return true if the filter spec is empty, ie throw().
198 static bool
199 empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
201 const _Unwind_Word* e = ((const _Unwind_Word*) info->TType)
202 - filter_value - 1;
204 return *e == 0;
207 #else
208 typedef const std::type_info _throw_typet;
211 // Given the thrown type THROW_TYPE, pointer to a variable containing a
212 // pointer to the exception object THROWN_PTR_P and a type CATCH_TYPE to
213 // compare against, return whether or not there is a match and if so,
214 // update *THROWN_PTR_P.
216 static bool
217 get_adjusted_ptr (const std::type_info *catch_type,
218 const std::type_info *throw_type,
219 void **thrown_ptr_p)
221 void *thrown_ptr = *thrown_ptr_p;
223 // Pointer types need to adjust the actual pointer, not
224 // the pointer to pointer that is the exception object.
225 // This also has the effect of passing pointer types
226 // "by value" through the __cxa_begin_catch return value.
227 if (throw_type->__is_pointer_p ())
228 thrown_ptr = *(void **) thrown_ptr;
230 if (catch_type->__do_catch (throw_type, &thrown_ptr, 1))
232 *thrown_ptr_p = thrown_ptr;
233 return true;
236 return false;
239 // Return true if THROW_TYPE matches one if the filter types.
241 static bool
242 check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
243 void* thrown_ptr, _sleb128_t filter_value)
245 const unsigned char *e = info->TType - filter_value - 1;
247 while (1)
249 const std::type_info *catch_type;
250 _uleb128_t tmp;
252 e = read_uleb128 (e, &tmp);
254 // Zero signals the end of the list. If we've not found
255 // a match by now, then we've failed the specification.
256 if (tmp == 0)
257 return false;
259 // Match a ttype entry.
260 catch_type = get_ttype_entry (info, tmp);
262 // ??? There is currently no way to ask the RTTI code about the
263 // relationship between two types without reference to a specific
264 // object. There should be; then we wouldn't need to mess with
265 // thrown_ptr here.
266 if (get_adjusted_ptr (catch_type, throw_type, &thrown_ptr))
267 return true;
272 // Save stage1 handler information in the exception object
274 static inline void
275 save_caught_exception(struct _Unwind_Exception* ue_header,
276 struct _Unwind_Context* context
277 __attribute__((__unused__)),
278 void* thrown_ptr,
279 int handler_switch_value,
280 const unsigned char* language_specific_data,
281 _Unwind_Ptr landing_pad __attribute__((__unused__)),
282 const unsigned char* action_record)
284 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
286 xh->handlerSwitchValue = handler_switch_value;
287 xh->actionRecord = action_record;
288 xh->languageSpecificData = language_specific_data;
289 xh->adjustedPtr = thrown_ptr;
291 // ??? Completely unknown what this field is supposed to be for.
292 // ??? Need to cache TType encoding base for call_unexpected.
293 xh->catchTemp = landing_pad;
297 // Restore the catch handler information saved during phase1.
299 static inline void
300 restore_caught_exception(struct _Unwind_Exception* ue_header,
301 int& handler_switch_value,
302 const unsigned char*& language_specific_data,
303 _Unwind_Ptr& landing_pad)
305 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
306 handler_switch_value = xh->handlerSwitchValue;
307 language_specific_data = xh->languageSpecificData;
308 landing_pad = (_Unwind_Ptr) xh->catchTemp;
311 #define CONTINUE_UNWINDING return _URC_CONTINUE_UNWIND
313 // Return true if the filter spec is empty, ie throw().
315 static bool
316 empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
318 const unsigned char *e = info->TType - filter_value - 1;
319 _uleb128_t tmp;
321 e = read_uleb128 (e, &tmp);
322 return tmp == 0;
325 #endif // !__ARM_EABI_UNWINDER__
327 namespace __cxxabiv1
330 // Using a different personality function name causes link failures
331 // when trying to mix code using different exception handling models.
332 #ifdef _GLIBCXX_SJLJ_EXCEPTIONS
333 #define PERSONALITY_FUNCTION __gxx_personality_sj0
334 #define __builtin_eh_return_data_regno(x) x
335 #elif defined(__SEH__)
336 #define PERSONALITY_FUNCTION __gxx_personality_imp
337 #else
338 #define PERSONALITY_FUNCTION __gxx_personality_v0
339 #endif
341 #ifdef __SEH__
342 static
343 #else
344 extern "C"
345 #endif
346 _Unwind_Reason_Code
347 #ifdef __ARM_EABI_UNWINDER__
348 PERSONALITY_FUNCTION (_Unwind_State state,
349 struct _Unwind_Exception* ue_header,
350 struct _Unwind_Context* context)
351 #else
352 PERSONALITY_FUNCTION (int version,
353 _Unwind_Action actions,
354 _Unwind_Exception_Class exception_class,
355 struct _Unwind_Exception *ue_header,
356 struct _Unwind_Context *context)
357 #endif
359 enum found_handler_type
361 found_nothing,
362 found_terminate,
363 found_cleanup,
364 found_handler
365 } found_type;
367 lsda_header_info info;
368 const unsigned char *language_specific_data;
369 const unsigned char *action_record;
370 const unsigned char *p;
371 _Unwind_Ptr landing_pad, ip;
372 int handler_switch_value;
373 void* thrown_ptr = 0;
374 bool foreign_exception;
375 int ip_before_insn = 0;
377 #ifdef __ARM_EABI_UNWINDER__
378 _Unwind_Action actions;
380 switch (state & _US_ACTION_MASK)
382 case _US_VIRTUAL_UNWIND_FRAME:
383 actions = _UA_SEARCH_PHASE;
384 break;
386 case _US_UNWIND_FRAME_STARTING:
387 actions = _UA_CLEANUP_PHASE;
388 if (!(state & _US_FORCE_UNWIND)
389 && ue_header->barrier_cache.sp == _Unwind_GetGR(context,
390 UNWIND_STACK_REG))
391 actions |= _UA_HANDLER_FRAME;
392 break;
394 case _US_UNWIND_FRAME_RESUME:
395 CONTINUE_UNWINDING;
396 break;
398 default:
399 std::abort();
401 actions |= state & _US_FORCE_UNWIND;
403 // We don't know which runtime we're working with, so can't check this.
404 // However the ABI routines hide this from us, and we don't actually need
405 // to know.
406 foreign_exception = false;
408 // The dwarf unwinder assumes the context structure holds things like the
409 // function and LSDA pointers. The ARM implementation caches these in
410 // the exception header (UCB). To avoid rewriting everything we make a
411 // virtual scratch register point at the UCB.
412 ip = (_Unwind_Ptr) ue_header;
413 _Unwind_SetGR(context, UNWIND_POINTER_REG, ip);
414 #else
415 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
417 // Interface version check.
418 if (version != 1)
419 return _URC_FATAL_PHASE1_ERROR;
420 foreign_exception = !__is_gxx_exception_class(exception_class);
421 #endif
423 // Shortcut for phase 2 found handler for domestic exception.
424 if (actions == (_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME)
425 && !foreign_exception)
427 restore_caught_exception(ue_header, handler_switch_value,
428 language_specific_data, landing_pad);
429 found_type = (landing_pad == 0 ? found_terminate : found_handler);
430 goto install_context;
433 language_specific_data = (const unsigned char *)
434 _Unwind_GetLanguageSpecificData (context);
436 // If no LSDA, then there are no handlers or cleanups.
437 if (! language_specific_data)
438 CONTINUE_UNWINDING;
440 // Parse the LSDA header.
441 p = parse_lsda_header (context, language_specific_data, &info);
442 info.ttype_base = base_of_encoded_value (info.ttype_encoding, context);
443 #ifdef _GLIBCXX_HAVE_GETIPINFO
444 ip = _Unwind_GetIPInfo (context, &ip_before_insn);
445 #else
446 ip = _Unwind_GetIP (context);
447 #endif
448 if (! ip_before_insn)
449 --ip;
450 landing_pad = 0;
451 action_record = 0;
452 handler_switch_value = 0;
454 #ifdef _GLIBCXX_SJLJ_EXCEPTIONS
455 // The given "IP" is an index into the call-site table, with two
456 // exceptions -- -1 means no-action, and 0 means terminate. But
457 // since we're using uleb128 values, we've not got random access
458 // to the array.
459 if ((int) ip < 0)
460 return _URC_CONTINUE_UNWIND;
461 else if (ip == 0)
463 // Fall through to set found_terminate.
465 else
467 _uleb128_t cs_lp, cs_action;
470 p = read_uleb128 (p, &cs_lp);
471 p = read_uleb128 (p, &cs_action);
473 while (--ip);
475 // Can never have null landing pad for sjlj -- that would have
476 // been indicated by a -1 call site index.
477 landing_pad = cs_lp + 1;
478 if (cs_action)
479 action_record = info.action_table + cs_action - 1;
480 goto found_something;
482 #else
483 // Search the call-site table for the action associated with this IP.
484 while (p < info.action_table)
486 _Unwind_Ptr cs_start, cs_len, cs_lp;
487 _uleb128_t cs_action;
489 // Note that all call-site encodings are "absolute" displacements.
490 p = read_encoded_value (0, info.call_site_encoding, p, &cs_start);
491 p = read_encoded_value (0, info.call_site_encoding, p, &cs_len);
492 p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp);
493 p = read_uleb128 (p, &cs_action);
495 // The table is sorted, so if we've passed the ip, stop.
496 if (ip < info.Start + cs_start)
497 p = info.action_table;
498 else if (ip < info.Start + cs_start + cs_len)
500 if (cs_lp)
501 landing_pad = info.LPStart + cs_lp;
502 if (cs_action)
503 action_record = info.action_table + cs_action - 1;
504 goto found_something;
507 #endif // _GLIBCXX_SJLJ_EXCEPTIONS
509 // If ip is not present in the table, call terminate. This is for
510 // a destructor inside a cleanup, or a library routine the compiler
511 // was not expecting to throw.
512 found_type = found_terminate;
513 goto do_something;
515 found_something:
516 if (landing_pad == 0)
518 // If ip is present, and has a null landing pad, there are
519 // no cleanups or handlers to be run.
520 found_type = found_nothing;
522 else if (action_record == 0)
524 // If ip is present, has a non-null landing pad, and a null
525 // action table offset, then there are only cleanups present.
526 // Cleanups use a zero switch value, as set above.
527 found_type = found_cleanup;
529 else
531 // Otherwise we have a catch handler or exception specification.
533 _sleb128_t ar_filter, ar_disp;
534 const std::type_info* catch_type;
535 _throw_typet* throw_type;
536 bool saw_cleanup = false;
537 bool saw_handler = false;
539 #ifdef __ARM_EABI_UNWINDER__
540 // ??? How does this work - more importantly, how does it interact with
541 // dependent exceptions?
542 throw_type = ue_header;
543 if (actions & _UA_FORCE_UNWIND)
545 __GXX_INIT_FORCED_UNWIND_CLASS(ue_header->exception_class);
547 else if (!foreign_exception)
548 thrown_ptr = __get_object_from_ue (ue_header);
549 #else
550 #ifdef __GXX_RTTI
551 // During forced unwinding, match a magic exception type.
552 if (actions & _UA_FORCE_UNWIND)
554 throw_type = &typeid(abi::__forced_unwind);
556 // With a foreign exception class, there's no exception type.
557 // ??? What to do about GNU Java and GNU Ada exceptions?
558 else if (foreign_exception)
560 throw_type = &typeid(abi::__foreign_exception);
562 else
563 #endif
565 thrown_ptr = __get_object_from_ue (ue_header);
566 throw_type = __get_exception_header_from_obj
567 (thrown_ptr)->exceptionType;
569 #endif
571 while (1)
573 p = action_record;
574 p = read_sleb128 (p, &ar_filter);
575 read_sleb128 (p, &ar_disp);
577 if (ar_filter == 0)
579 // Zero filter values are cleanups.
580 saw_cleanup = true;
582 else if (ar_filter > 0)
584 // Positive filter values are handlers.
585 catch_type = get_ttype_entry (&info, ar_filter);
587 // Null catch type is a catch-all handler; we can catch foreign
588 // exceptions with this. Otherwise we must match types.
589 if (! catch_type
590 || (throw_type
591 && get_adjusted_ptr (catch_type, throw_type,
592 &thrown_ptr)))
594 saw_handler = true;
595 break;
598 else
600 // Negative filter values are exception specifications.
601 // ??? How do foreign exceptions fit in? As far as I can
602 // see we can't match because there's no __cxa_exception
603 // object to stuff bits in for __cxa_call_unexpected to use.
604 // Allow them iff the exception spec is non-empty. I.e.
605 // a throw() specification results in __unexpected.
606 if ((throw_type
607 && !(actions & _UA_FORCE_UNWIND)
608 && !foreign_exception)
609 ? ! check_exception_spec (&info, throw_type, thrown_ptr,
610 ar_filter)
611 : empty_exception_spec (&info, ar_filter))
613 saw_handler = true;
614 break;
618 if (ar_disp == 0)
619 break;
620 action_record = p + ar_disp;
623 if (saw_handler)
625 handler_switch_value = ar_filter;
626 found_type = found_handler;
628 else
629 found_type = (saw_cleanup ? found_cleanup : found_nothing);
632 do_something:
633 if (found_type == found_nothing)
634 CONTINUE_UNWINDING;
636 if (actions & _UA_SEARCH_PHASE)
638 if (found_type == found_cleanup)
639 CONTINUE_UNWINDING;
641 // For domestic exceptions, we cache data from phase 1 for phase 2.
642 if (!foreign_exception)
644 save_caught_exception(ue_header, context, thrown_ptr,
645 handler_switch_value, language_specific_data,
646 landing_pad, action_record);
648 return _URC_HANDLER_FOUND;
651 install_context:
653 // We can't use any of the cxa routines with foreign exceptions,
654 // because they all expect ue_header to be a struct __cxa_exception.
655 // So in that case, call terminate or unexpected directly.
656 if ((actions & _UA_FORCE_UNWIND)
657 || foreign_exception)
659 if (found_type == found_terminate)
660 std::terminate ();
661 else if (handler_switch_value < 0)
663 __try
664 { std::unexpected (); }
665 __catch(...)
666 { std::terminate (); }
669 else
671 if (found_type == found_terminate)
672 __cxa_call_terminate(ue_header);
674 // Cache the TType base value for __cxa_call_unexpected, as we won't
675 // have an _Unwind_Context then.
676 if (handler_switch_value < 0)
678 parse_lsda_header (context, language_specific_data, &info);
679 info.ttype_base = base_of_encoded_value (info.ttype_encoding,
680 context);
682 #ifdef __ARM_EABI_UNWINDER__
683 const _Unwind_Word* e;
684 _Unwind_Word n;
686 e = ((const _Unwind_Word*) info.TType) - handler_switch_value - 1;
687 // Count the number of rtti objects.
688 n = 0;
689 while (e[n] != 0)
690 n++;
692 // Count.
693 ue_header->barrier_cache.bitpattern[1] = n;
694 // Base
695 ue_header->barrier_cache.bitpattern[2] = info.ttype_base;
696 // Stride.
697 ue_header->barrier_cache.bitpattern[3] = 4;
698 // List head.
699 ue_header->barrier_cache.bitpattern[4] = (_Unwind_Word) e;
700 #else
701 xh->catchTemp = base_of_encoded_value (info.ttype_encoding, context);
702 #endif
706 /* For targets with pointers smaller than the word size, we must extend the
707 pointer, and this extension is target dependent. */
708 _Unwind_SetGR (context, __builtin_eh_return_data_regno (0),
709 __builtin_extend_pointer (ue_header));
710 _Unwind_SetGR (context, __builtin_eh_return_data_regno (1),
711 handler_switch_value);
712 _Unwind_SetIP (context, landing_pad);
713 #ifdef __ARM_EABI_UNWINDER__
714 if (found_type == found_cleanup)
715 __cxa_begin_cleanup(ue_header);
716 #endif
717 return _URC_INSTALL_CONTEXT;
720 /* The ARM EABI implementation of __cxa_call_unexpected is in a
721 different file so that the personality routine (PR) can be used
722 standalone. The generic routine shared datastructures with the PR
723 so it is most convenient to implement it here. */
724 #ifndef __ARM_EABI_UNWINDER__
725 extern "C" void
726 __cxa_call_unexpected (void *exc_obj_in)
728 _Unwind_Exception *exc_obj
729 = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
731 __cxa_begin_catch (exc_obj);
733 // This function is a handler for our exception argument. If we exit
734 // by throwing a different exception, we'll need the original cleaned up.
735 struct end_catch_protect
737 end_catch_protect() { }
738 ~end_catch_protect() { __cxa_end_catch(); }
739 } end_catch_protect_obj;
741 lsda_header_info info;
742 __cxa_exception *xh = __get_exception_header_from_ue (exc_obj);
743 const unsigned char *xh_lsda;
744 _Unwind_Sword xh_switch_value;
745 std::terminate_handler xh_terminate_handler;
747 // If the unexpectedHandler rethrows the exception (e.g. to categorize it),
748 // it will clobber data about the current handler. So copy the data out now.
749 xh_lsda = xh->languageSpecificData;
750 xh_switch_value = xh->handlerSwitchValue;
751 xh_terminate_handler = xh->terminateHandler;
752 info.ttype_base = (_Unwind_Ptr) xh->catchTemp;
754 __try
755 { __unexpected (xh->unexpectedHandler); }
756 __catch(...)
758 // Get the exception thrown from unexpected.
760 __cxa_eh_globals *globals = __cxa_get_globals_fast ();
761 __cxa_exception *new_xh = globals->caughtExceptions;
762 void *new_ptr = __get_object_from_ambiguous_exception (new_xh);
764 // We don't quite have enough stuff cached; re-parse the LSDA.
765 parse_lsda_header (0, xh_lsda, &info);
767 // If this new exception meets the exception spec, allow it.
768 if (check_exception_spec (&info, __get_exception_header_from_obj
769 (new_ptr)->exceptionType,
770 new_ptr, xh_switch_value))
771 __throw_exception_again;
773 // If the exception spec allows std::bad_exception, throw that.
774 // We don't have a thrown object to compare against, but since
775 // bad_exception doesn't have virtual bases, that's OK; just pass 0.
776 #if defined(__EXCEPTIONS) && defined(__GXX_RTTI)
777 const std::type_info &bad_exc = typeid (std::bad_exception);
778 if (check_exception_spec (&info, &bad_exc, 0, xh_switch_value))
779 throw std::bad_exception();
780 #endif
782 // Otherwise, die.
783 __terminate (xh_terminate_handler);
786 #endif
788 #ifdef __SEH__
789 extern "C"
790 EXCEPTION_DISPOSITION
791 __gxx_personality_seh0 (PEXCEPTION_RECORD ms_exc, void *this_frame,
792 PCONTEXT ms_orig_context, PDISPATCHER_CONTEXT ms_disp)
794 return _GCC_specific_handler (ms_exc, this_frame, ms_orig_context,
795 ms_disp, __gxx_personality_imp);
797 #endif /* SEH */
799 } // namespace __cxxabiv1