#include <cxxabi.h>
#include "unwind-cxx.h"
#ifdef __ARM_EABI_UNWINDER__
using namespace __cxxabiv1;
extern "C" __cxa_type_match_result
__cxa_type_match(_Unwind_Exception* ue_header,
const std::type_info* catch_type,
bool is_reference __attribute__((__unused__)),
void** thrown_ptr_p)
{
if (!__is_gxx_exception_class(ue_header->exception_class))
return ctm_failed;
__cxa_exception* xh = __get_exception_header_from_ue(ue_header);
const std::type_info* throw_type = xh->exceptionType;
void* thrown_ptr = *thrown_ptr_p;
if (throw_type->__is_pointer_p())
thrown_ptr = *(void**) thrown_ptr;
if (catch_type->__do_catch(throw_type, &thrown_ptr, 1))
{
*thrown_ptr_p = thrown_ptr;
if (typeid(*catch_type) == typeid (typeid(void*)))
{
const __pointer_type_info *catch_pointer_type =
static_cast<const __pointer_type_info *> (catch_type);
const __pointer_type_info *throw_pointer_type =
static_cast<const __pointer_type_info *> (throw_type);
if (typeid (*catch_pointer_type->__pointee) != typeid (void)
&& (*catch_pointer_type->__pointee !=
*throw_pointer_type->__pointee))
return ctm_succeeded_with_ptr_to_base;
}
return ctm_succeeded;
}
return ctm_failed;
}
extern "C" bool
__cxa_begin_cleanup(_Unwind_Exception* ue_header)
{
__cxa_eh_globals *globals = __cxa_get_globals();
__cxa_exception *header = __get_exception_header_from_ue(ue_header);
bool native = __is_gxx_exception_class(header->unwindHeader.exception_class);
if (native)
{
header->propagationCount++;
if (header->propagationCount == 1)
{
header->nextPropagatingException = globals->propagatingExceptions;
globals->propagatingExceptions = header;
}
}
else
{
if (globals->propagatingExceptions)
std::terminate ();
globals->propagatingExceptions = header;
}
return true;
}
extern "C" _Unwind_Exception *
__gnu_end_cleanup(void)
{
__cxa_exception *header;
__cxa_eh_globals *globals = __cxa_get_globals();
header = globals->propagatingExceptions;
if (!header)
std::terminate();
if (__is_gxx_exception_class(header->unwindHeader.exception_class))
{
header->propagationCount--;
if (header->propagationCount == 0)
{
globals->propagatingExceptions = header->nextPropagatingException;
header->nextPropagatingException = NULL;
}
}
else
globals->propagatingExceptions = NULL;
return &header->unwindHeader;
}
#ifdef __thumb__
asm (".global __cxa_end_cleanup\n"
" .type __cxa_end_cleanup, \"function\"\n"
" .thumb_func\n"
"__cxa_end_cleanup:\n"
" push\t{r1, r2, r3, r4}\n"
" bl\t__gnu_end_cleanup\n"
" pop\t{r1, r2, r3, r4}\n"
" bl\t_Unwind_Resume @ Never returns\n");
#else
asm (".global __cxa_end_cleanup\n"
" .type __cxa_end_cleanup, \"function\"\n"
"__cxa_end_cleanup:\n"
" stmfd\tsp!, {r1, r2, r3, r4}\n"
" bl\t__gnu_end_cleanup\n"
" ldmfd\tsp!, {r1, r2, r3, r4}\n"
" bl\t_Unwind_Resume @ Never returns\n");
#endif
#endif