#ifndef _UNWIND_CXX_H
#define _UNWIND_CXX_H 1
#include <typeinfo>
#include <exception>
#include <cstddef>
#include "unwind.h"
#include <bits/atomic_word.h>
#pragma GCC visibility push(default)
namespace __cxxabiv1
{
struct __cxa_exception
{
std::type_info *exceptionType;
void (*exceptionDestructor)(void *);
std::unexpected_handler unexpectedHandler;
std::terminate_handler terminateHandler;
__cxa_exception *nextException;
int handlerCount;
#ifdef __ARM_EABI_UNWINDER__
__cxa_exception* nextPropagatingException;
int propagationCount;
#else
int handlerSwitchValue;
const unsigned char *actionRecord;
const unsigned char *languageSpecificData;
_Unwind_Ptr catchTemp;
void *adjustedPtr;
#endif
_Unwind_Exception unwindHeader;
};
struct __cxa_refcounted_exception
{
_Atomic_word referenceCount;
__cxa_exception exc;
};
struct __cxa_dependent_exception
{
void *primaryException;
std::unexpected_handler unexpectedHandler;
std::terminate_handler terminateHandler;
__cxa_exception *nextException;
int handlerCount;
#ifdef __ARM_EABI_UNWINDER__
__cxa_exception* nextPropagatingException;
int propagationCount;
#else
int handlerSwitchValue;
const unsigned char *actionRecord;
const unsigned char *languageSpecificData;
_Unwind_Ptr catchTemp;
void *adjustedPtr;
#endif
_Unwind_Exception unwindHeader;
};
struct __cxa_eh_globals
{
__cxa_exception *caughtExceptions;
unsigned int uncaughtExceptions;
#ifdef __ARM_EABI_UNWINDER__
__cxa_exception* propagatingExceptions;
#endif
};
extern "C" __cxa_eh_globals *__cxa_get_globals () throw()
__attribute__ ((__const__));
extern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw()
__attribute__ ((__const__));
extern "C" void *__cxa_allocate_exception(std::size_t thrown_size) throw();
extern "C" void __cxa_free_exception(void *thrown_exception) throw();
extern "C" __cxa_dependent_exception*
__cxa_allocate_dependent_exception() throw();
extern "C" void
__cxa_free_dependent_exception(__cxa_dependent_exception *ex) throw();
extern "C" void __cxa_throw (void *thrown_exception,
std::type_info *tinfo,
void (*dest) (void *))
__attribute__((__noreturn__));
extern "C" void *__cxa_get_exception_ptr (void *) throw()
__attribute__ ((__pure__));
extern "C" void *__cxa_begin_catch (void *) throw();
extern "C" void __cxa_end_catch ();
extern "C" void __cxa_rethrow () __attribute__((__noreturn__));
extern "C" void __cxa_bad_cast () __attribute__((__noreturn__));
extern "C" void __cxa_bad_typeid () __attribute__((__noreturn__));
extern "C" void __cxa_call_unexpected (void *) __attribute__((__noreturn__));
extern "C" void __cxa_call_terminate (_Unwind_Exception*) throw ()
__attribute__((__noreturn__));
#ifdef __ARM_EABI_UNWINDER__
typedef enum {
ctm_failed = 0,
ctm_succeeded = 1,
ctm_succeeded_with_ptr_to_base = 2
} __cxa_type_match_result;
extern "C" __cxa_type_match_result __cxa_type_match(_Unwind_Exception*,
const std::type_info*,
bool, void**);
extern "C" bool __cxa_begin_cleanup (_Unwind_Exception*);
extern "C" void __cxa_end_cleanup (void);
#endif
extern void __terminate(std::terminate_handler) throw ()
__attribute__((__noreturn__));
extern void __unexpected(std::unexpected_handler)
__attribute__((__noreturn__));
extern std::terminate_handler __terminate_handler;
extern std::unexpected_handler __unexpected_handler;
static inline __cxa_exception *
__get_exception_header_from_obj (void *ptr)
{
return reinterpret_cast<__cxa_exception *>(ptr) - 1;
}
static inline __cxa_exception *
__get_exception_header_from_ue (_Unwind_Exception *exc)
{
return reinterpret_cast<__cxa_exception *>(exc + 1) - 1;
}
static inline __cxa_refcounted_exception *
__get_refcounted_exception_header_from_obj (void *ptr)
{
return reinterpret_cast<__cxa_refcounted_exception *>(ptr) - 1;
}
static inline __cxa_refcounted_exception *
__get_refcounted_exception_header_from_ue (_Unwind_Exception *exc)
{
return reinterpret_cast<__cxa_refcounted_exception *>(exc + 1) - 1;
}
static inline __cxa_dependent_exception *
__get_dependent_exception_from_ue (_Unwind_Exception *exc)
{
return reinterpret_cast<__cxa_dependent_exception *>(exc + 1) - 1;
}
#ifdef __ARM_EABI_UNWINDER__
static inline bool
__is_gxx_exception_class(_Unwind_Exception_Class c)
{
return c[0] == 'G'
&& c[1] == 'N'
&& c[2] == 'U'
&& c[3] == 'C'
&& c[4] == 'C'
&& c[5] == '+'
&& c[6] == '+'
&& (c[7] == '\0' || c[7] == '\x01');
}
static inline bool
__is_dependent_exception(_Unwind_Exception_Class c)
{
return c[7] == '\x01';
}
static inline void
__GXX_INIT_PRIMARY_EXCEPTION_CLASS(_Unwind_Exception_Class c)
{
c[0] = 'G';
c[1] = 'N';
c[2] = 'U';
c[3] = 'C';
c[4] = 'C';
c[5] = '+';
c[6] = '+';
c[7] = '\0';
}
static inline void
__GXX_INIT_DEPENDENT_EXCEPTION_CLASS(_Unwind_Exception_Class c)
{
c[0] = 'G';
c[1] = 'N';
c[2] = 'U';
c[3] = 'C';
c[4] = 'C';
c[5] = '+';
c[6] = '+';
c[7] = '\x01';
}
static inline bool
__is_gxx_forced_unwind_class(_Unwind_Exception_Class c)
{
return c[0] == 'G'
&& c[1] == 'N'
&& c[2] == 'U'
&& c[3] == 'C'
&& c[4] == 'F'
&& c[5] == 'O'
&& c[6] == 'R'
&& c[7] == '\0';
}
static inline void
__GXX_INIT_FORCED_UNWIND_CLASS(_Unwind_Exception_Class c)
{
c[0] = 'G';
c[1] = 'N';
c[2] = 'U';
c[3] = 'C';
c[4] = 'F';
c[5] = 'O';
c[6] = 'R';
c[7] = '\0';
}
static inline void*
__gxx_caught_object(_Unwind_Exception* eo)
{
return (void*)eo->barrier_cache.bitpattern[0];
}
#else
const _Unwind_Exception_Class __gxx_primary_exception_class
= ((((((((_Unwind_Exception_Class) 'G'
<< 8 | (_Unwind_Exception_Class) 'N')
<< 8 | (_Unwind_Exception_Class) 'U')
<< 8 | (_Unwind_Exception_Class) 'C')
<< 8 | (_Unwind_Exception_Class) 'C')
<< 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '\0');
const _Unwind_Exception_Class __gxx_dependent_exception_class
= ((((((((_Unwind_Exception_Class) 'G'
<< 8 | (_Unwind_Exception_Class) 'N')
<< 8 | (_Unwind_Exception_Class) 'U')
<< 8 | (_Unwind_Exception_Class) 'C')
<< 8 | (_Unwind_Exception_Class) 'C')
<< 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '\x01');
static inline bool
__is_gxx_exception_class(_Unwind_Exception_Class c)
{
return c == __gxx_primary_exception_class
|| c == __gxx_dependent_exception_class;
}
static inline bool
__is_dependent_exception(_Unwind_Exception_Class c)
{
return (c & 1);
}
#define __GXX_INIT_PRIMARY_EXCEPTION_CLASS(c) c = __gxx_primary_exception_class
#define __GXX_INIT_DEPENDENT_EXCEPTION_CLASS(c) \
c = __gxx_dependent_exception_class
extern "C" _Unwind_Reason_Code __gxx_personality_v0
(int, _Unwind_Action, _Unwind_Exception_Class,
struct _Unwind_Exception *, struct _Unwind_Context *);
extern "C" _Unwind_Reason_Code __gxx_personality_sj0
(int, _Unwind_Action, _Unwind_Exception_Class,
struct _Unwind_Exception *, struct _Unwind_Context *);
static inline void*
__gxx_caught_object(_Unwind_Exception* eo)
{
__cxa_exception* header = __get_exception_header_from_ue (eo);
return header->adjustedPtr;
}
#endif
static inline void*
__get_object_from_ue(_Unwind_Exception* eo) throw()
{
return __is_dependent_exception (eo->exception_class) ?
__get_dependent_exception_from_ue (eo)->primaryException :
eo + 1;
}
static inline void *
__get_object_from_ambiguous_exception(__cxa_exception *p_or_d) throw()
{
return __get_object_from_ue (&p_or_d->unwindHeader);
}
}
#pragma GCC visibility pop
#endif