// -*- C++ -*- The GNU C++ exception personality routine.
-// Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+// 2011
+// Free Software Foundation, Inc.
//
// This file is part of GCC.
//
// GCC is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2, or (at your option)
+// the Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// GCC is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
-// You should have received a copy of the GNU General Public License
-// along with GCC; see the file COPYING. If not, write to
-// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-// Boston, MA 02110-1301, USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
#include <bits/c++config.h>
#include <cstdlib>
-#include <exception_defines.h>
+#include <bits/exception_defines.h>
+#include <cxxabi.h>
#include "unwind-cxx.h"
using namespace __cxxabiv1;
parse_lsda_header (_Unwind_Context *context, const unsigned char *p,
lsda_header_info *info)
{
- _Unwind_Word tmp;
+ _uleb128_t tmp;
unsigned char lpstart_encoding;
info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
// Return an element from a type table.
static const std::type_info*
-get_ttype_entry(lsda_header_info* info, _Unwind_Word i)
+get_ttype_entry(lsda_header_info* info, _uleb128_t i)
{
_Unwind_Ptr ptr;
static bool
check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
- void* thrown_ptr, _Unwind_Sword filter_value)
+ void* thrown_ptr, _sleb128_t filter_value)
{
- const _Unwind_Word* e = ((const _Unwind_Word*) info->TType)
+ const _uleb128_t* e = ((const _uleb128_t*) info->TType)
- filter_value - 1;
while (1)
{
const std::type_info* catch_type;
- _Unwind_Word tmp;
+ _uleb128_t tmp;
tmp = *e;
} \
while (0)
+// Return true if the filter spec is empty, ie throw().
+
+static bool
+empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
+{
+ const _Unwind_Word* e = ((const _Unwind_Word*) info->TType)
+ - filter_value - 1;
+
+ return *e == 0;
+}
+
#else
typedef const std::type_info _throw_typet;
// Return an element from a type table.
static const std::type_info *
-get_ttype_entry (lsda_header_info *info, _Unwind_Word i)
+get_ttype_entry (lsda_header_info *info, _uleb128_t i)
{
_Unwind_Ptr ptr;
static bool
check_exception_spec(lsda_header_info* info, _throw_typet* throw_type,
- void* thrown_ptr, _Unwind_Sword filter_value)
+ void* thrown_ptr, _sleb128_t filter_value)
{
const unsigned char *e = info->TType - filter_value - 1;
while (1)
{
const std::type_info *catch_type;
- _Unwind_Word tmp;
+ _uleb128_t tmp;
e = read_uleb128 (e, &tmp);
#define CONTINUE_UNWINDING return _URC_CONTINUE_UNWIND
-#endif // !__ARM_EABI_UNWINDER__
-
// Return true if the filter spec is empty, ie throw().
static bool
empty_exception_spec (lsda_header_info *info, _Unwind_Sword filter_value)
{
const unsigned char *e = info->TType - filter_value - 1;
- _Unwind_Word tmp;
+ _uleb128_t tmp;
e = read_uleb128 (e, &tmp);
return tmp == 0;
}
+#endif // !__ARM_EABI_UNWINDER__
+
+namespace __cxxabiv1
+{
+
// Using a different personality function name causes link failures
// when trying to mix code using different exception handling models.
#ifdef _GLIBCXX_SJLJ_EXCEPTIONS
const unsigned char *p;
_Unwind_Ptr landing_pad, ip;
int handler_switch_value;
- void* thrown_ptr = ue_header + 1;
+ void* thrown_ptr = 0;
bool foreign_exception;
+ int ip_before_insn = 0;
#ifdef __ARM_EABI_UNWINDER__
_Unwind_Action actions;
// Parse the LSDA header.
p = parse_lsda_header (context, language_specific_data, &info);
info.ttype_base = base_of_encoded_value (info.ttype_encoding, context);
- ip = _Unwind_GetIP (context) - 1;
+#ifdef _GLIBCXX_HAVE_GETIPINFO
+ ip = _Unwind_GetIPInfo (context, &ip_before_insn);
+#else
+ ip = _Unwind_GetIP (context);
+#endif
+ if (! ip_before_insn)
+ --ip;
landing_pad = 0;
action_record = 0;
handler_switch_value = 0;
}
else
{
- _Unwind_Word cs_lp, cs_action;
+ _uleb128_t cs_lp, cs_action;
do
{
p = read_uleb128 (p, &cs_lp);
while (p < info.action_table)
{
_Unwind_Ptr cs_start, cs_len, cs_lp;
- _Unwind_Word cs_action;
+ _uleb128_t cs_action;
// Note that all call-site encodings are "absolute" displacements.
p = read_encoded_value (0, info.call_site_encoding, p, &cs_start);
{
// Otherwise we have a catch handler or exception specification.
- _Unwind_Sword ar_filter, ar_disp;
+ _sleb128_t ar_filter, ar_disp;
const std::type_info* catch_type;
_throw_typet* throw_type;
bool saw_cleanup = false;
bool saw_handler = false;
- // During forced unwinding, we only run cleanups. With a foreign
- // exception class, there's no exception type.
- // ??? What to do about GNU Java and GNU Ada exceptions.
-
- if ((actions & _UA_FORCE_UNWIND)
- || foreign_exception)
- throw_type = 0;
- else
#ifdef __ARM_EABI_UNWINDER__
- throw_type = ue_header;
+ // ??? How does this work - more importantly, how does it interact with
+ // dependent exceptions?
+ throw_type = ue_header;
+ if (actions & _UA_FORCE_UNWIND)
+ {
+ __GXX_INIT_FORCED_UNWIND_CLASS(ue_header->exception_class);
+ }
+ else if (!foreign_exception)
+ thrown_ptr = __get_object_from_ue (ue_header);
#else
- throw_type = xh->exceptionType;
+#ifdef __GXX_RTTI
+ // During forced unwinding, match a magic exception type.
+ if (actions & _UA_FORCE_UNWIND)
+ {
+ throw_type = &typeid(abi::__forced_unwind);
+ }
+ // With a foreign exception class, there's no exception type.
+ // ??? What to do about GNU Java and GNU Ada exceptions?
+ else if (foreign_exception)
+ {
+ throw_type = &typeid(abi::__foreign_exception);
+ }
+ else
+#endif
+ {
+ thrown_ptr = __get_object_from_ue (ue_header);
+ throw_type = __get_exception_header_from_obj
+ (thrown_ptr)->exceptionType;
+ }
#endif
while (1)
// object to stuff bits in for __cxa_call_unexpected to use.
// Allow them iff the exception spec is non-empty. I.e.
// a throw() specification results in __unexpected.
- if (throw_type
+ if ((throw_type
+ && !(actions & _UA_FORCE_UNWIND)
+ && !foreign_exception)
? ! check_exception_spec (&info, throw_type, thrown_ptr,
ar_filter)
: empty_exception_spec (&info, ar_filter))
std::terminate ();
else if (handler_switch_value < 0)
{
- try
+ __try
{ std::unexpected (); }
- catch(...)
+ __catch(...)
{ std::terminate (); }
}
}
return _URC_INSTALL_CONTEXT;
}
-/* The ARM EABI implementation of __cxa_call_unexpected is in a different
- file so that the personality routine san be used standalone. The generic
- routine sahred datastructures with the PR so it is most convenient to
- implement it here. */
+/* The ARM EABI implementation of __cxa_call_unexpected is in a
+ different file so that the personality routine (PR) can be used
+ standalone. The generic routine shared datastructures with the PR
+ so it is most convenient to implement it here. */
#ifndef __ARM_EABI_UNWINDER__
extern "C" void
__cxa_call_unexpected (void *exc_obj_in)
xh_terminate_handler = xh->terminateHandler;
info.ttype_base = (_Unwind_Ptr) xh->catchTemp;
- try
+ __try
{ __unexpected (xh->unexpectedHandler); }
- catch(...)
+ __catch(...)
{
// Get the exception thrown from unexpected.
__cxa_eh_globals *globals = __cxa_get_globals_fast ();
__cxa_exception *new_xh = globals->caughtExceptions;
- void *new_ptr = new_xh + 1;
+ void *new_ptr = __get_object_from_ambiguous_exception (new_xh);
// We don't quite have enough stuff cached; re-parse the LSDA.
parse_lsda_header (0, xh_lsda, &info);
// If this new exception meets the exception spec, allow it.
- if (check_exception_spec (&info, new_xh->exceptionType,
+ if (check_exception_spec (&info, __get_exception_header_from_obj
+ (new_ptr)->exceptionType,
new_ptr, xh_switch_value))
__throw_exception_again;
// If the exception spec allows std::bad_exception, throw that.
// We don't have a thrown object to compare against, but since
// bad_exception doesn't have virtual bases, that's OK; just pass 0.
-#ifdef __EXCEPTIONS
+#if defined(__EXCEPTIONS) && defined(__GXX_RTTI)
const std::type_info &bad_exc = typeid (std::bad_exception);
if (check_exception_spec (&info, &bad_exc, 0, xh_switch_value))
throw std::bad_exception();
}
}
#endif
+
+} // namespace __cxxabiv1