Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/libcxxrt/exception.cc
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
* stored in the C++ exception. | * stored in the C++ exception. | ||||
*/ | */ | ||||
static void saveLandingPad(struct _Unwind_Context *context, | static void saveLandingPad(struct _Unwind_Context *context, | ||||
struct _Unwind_Exception *ucb, | struct _Unwind_Exception *ucb, | ||||
struct __cxa_exception *ex, | struct __cxa_exception *ex, | ||||
int selector, | int selector, | ||||
dw_eh_ptr_t landingPad) | dw_eh_ptr_t landingPad) | ||||
{ | { | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
// On ARM, we store the saved exception in the generic part of the structure | // On ARM, we store the saved exception in the generic part of the structure | ||||
ucb->barrier_cache.sp = _Unwind_GetGR(context, 13); | ucb->barrier_cache.sp = _Unwind_GetGR(context, 13); | ||||
ucb->barrier_cache.bitpattern[1] = (uint32_t)selector; | ucb->barrier_cache.bitpattern[1] = static_cast<uint32_t>(selector); | ||||
ucb->barrier_cache.bitpattern[3] = (uint32_t)landingPad; | ucb->barrier_cache.bitpattern[3] = reinterpret_cast<uint32_t>(landingPad); | ||||
#endif | #endif | ||||
// Cache the results for the phase 2 unwind, if we found a handler | // Cache the results for the phase 2 unwind, if we found a handler | ||||
// and this is not a foreign exception. | // and this is not a foreign exception. | ||||
if (ex) | if (ex) | ||||
{ | { | ||||
ex->handlerSwitchValue = selector; | ex->handlerSwitchValue = selector; | ||||
ex->catchTemp = landingPad; | ex->catchTemp = landingPad; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Loads the saved landing pad. Returns 1 on success, 0 on failure. | * Loads the saved landing pad. Returns 1 on success, 0 on failure. | ||||
*/ | */ | ||||
static int loadLandingPad(struct _Unwind_Context *context, | static int loadLandingPad(struct _Unwind_Context *context, | ||||
struct _Unwind_Exception *ucb, | struct _Unwind_Exception *ucb, | ||||
struct __cxa_exception *ex, | struct __cxa_exception *ex, | ||||
unsigned long *selector, | unsigned long *selector, | ||||
dw_eh_ptr_t *landingPad) | dw_eh_ptr_t *landingPad) | ||||
{ | { | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
*selector = ucb->barrier_cache.bitpattern[1]; | *selector = ucb->barrier_cache.bitpattern[1]; | ||||
*landingPad = (dw_eh_ptr_t)ucb->barrier_cache.bitpattern[3]; | *landingPad = reinterpret_cast<dw_eh_ptr_t>(ucb->barrier_cache.bitpattern[3]); | ||||
return 1; | return 1; | ||||
#else | #else | ||||
if (ex) | if (ex) | ||||
{ | { | ||||
*selector = ex->handlerSwitchValue; | *selector = ex->handlerSwitchValue; | ||||
*landingPad = (dw_eh_ptr_t)ex->catchTemp; | *landingPad = reinterpret_cast<dw_eh_ptr_t>(ex->catchTemp); | ||||
return 0; | return 0; | ||||
} | } | ||||
return 0; | return 0; | ||||
#endif | #endif | ||||
} | } | ||||
static inline _Unwind_Reason_Code continueUnwinding(struct _Unwind_Exception *ex, | static inline _Unwind_Reason_Code continueUnwinding(struct _Unwind_Exception *ex, | ||||
struct _Unwind_Context *context) | struct _Unwind_Context *context) | ||||
{ | { | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
if (__gnu_unwind_frame(ex, context) != _URC_OK) { return _URC_FAILURE; } | if (__gnu_unwind_frame(ex, context) != _URC_OK) { return _URC_FAILURE; } | ||||
#endif | #endif | ||||
return _URC_CONTINUE_UNWIND; | return _URC_CONTINUE_UNWIND; | ||||
} | } | ||||
extern "C" void __cxa_free_exception(void *thrown_exception); | extern "C" void __cxa_free_exception(void *thrown_exception); | ||||
extern "C" void __cxa_free_dependent_exception(void *thrown_exception); | extern "C" void __cxa_free_dependent_exception(void *thrown_exception); | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | #if __LP64__ | ||||
void *primaryException; | void *primaryException; | ||||
#endif | #endif | ||||
std::type_info *exceptionType; | std::type_info *exceptionType; | ||||
void (*exceptionDestructor) (void *); | void (*exceptionDestructor) (void *); | ||||
unexpected_handler unexpectedHandler; | unexpected_handler unexpectedHandler; | ||||
terminate_handler terminateHandler; | terminate_handler terminateHandler; | ||||
__cxa_exception *nextException; | __cxa_exception *nextException; | ||||
int handlerCount; | int handlerCount; | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
_Unwind_Exception *nextCleanup; | _Unwind_Exception *nextCleanup; | ||||
int cleanupCount; | int cleanupCount; | ||||
#endif | #endif | ||||
int handlerSwitchValue; | int handlerSwitchValue; | ||||
const char *actionRecord; | const char *actionRecord; | ||||
const char *languageSpecificData; | const char *languageSpecificData; | ||||
void *catchTemp; | void *catchTemp; | ||||
void *adjustedPtr; | void *adjustedPtr; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
static bool isDependentException(uint64_t cls) | static bool isDependentException(uint64_t cls) | ||||
{ | { | ||||
return cls == dependent_exception_class; | return cls == dependent_exception_class; | ||||
} | } | ||||
static __cxa_exception *exceptionFromPointer(void *ex) | static __cxa_exception *exceptionFromPointer(void *ex) | ||||
{ | { | ||||
return (__cxa_exception*)((char*)ex - | return reinterpret_cast<__cxa_exception*>(static_cast<char*>(ex) - | ||||
offsetof(struct __cxa_exception, unwindHeader)); | offsetof(struct __cxa_exception, unwindHeader)); | ||||
} | } | ||||
static __cxa_exception *realExceptionFromException(__cxa_exception *ex) | static __cxa_exception *realExceptionFromException(__cxa_exception *ex) | ||||
{ | { | ||||
if (!isDependentException(ex->unwindHeader.exception_class)) { return ex; } | if (!isDependentException(ex->unwindHeader.exception_class)) { return ex; } | ||||
return ((__cxa_exception*)(((__cxa_dependent_exception*)ex)->primaryException))-1; | return reinterpret_cast<__cxa_exception*>((reinterpret_cast<__cxa_dependent_exception*>(ex))->primaryException)-1; | ||||
} | } | ||||
namespace std | namespace std | ||||
{ | { | ||||
// Forward declaration of standard library terminate() function used to | // Forward declaration of standard library terminate() function used to | ||||
// abort execution. | // abort execution. | ||||
void terminate(void); | void terminate(void); | ||||
Show All 14 Lines | |||||
/** | /** | ||||
* Cleanup function, allowing foreign exception handlers to correctly destroy | * Cleanup function, allowing foreign exception handlers to correctly destroy | ||||
* this exception if they catch it. | * this exception if they catch it. | ||||
*/ | */ | ||||
static void exception_cleanup(_Unwind_Reason_Code reason, | static void exception_cleanup(_Unwind_Reason_Code reason, | ||||
struct _Unwind_Exception *ex) | struct _Unwind_Exception *ex) | ||||
{ | { | ||||
__cxa_free_exception((void*)ex); | __cxa_free_exception(static_cast<void*>(ex)); | ||||
} | } | ||||
static void dependent_exception_cleanup(_Unwind_Reason_Code reason, | static void dependent_exception_cleanup(_Unwind_Reason_Code reason, | ||||
struct _Unwind_Exception *ex) | struct _Unwind_Exception *ex) | ||||
{ | { | ||||
__cxa_free_dependent_exception((void*)ex); | __cxa_free_dependent_exception(static_cast<void*>(ex)); | ||||
} | } | ||||
/** | /** | ||||
* Recursively walk a list of exceptions and delete them all in post-order. | * Recursively walk a list of exceptions and delete them all in post-order. | ||||
*/ | */ | ||||
static void free_exception_list(__cxa_exception *ex) | static void free_exception_list(__cxa_exception *ex) | ||||
{ | { | ||||
if (0 != ex->nextException) | if (0 != ex->nextException) | ||||
{ | { | ||||
free_exception_list(ex->nextException); | free_exception_list(ex->nextException); | ||||
} | } | ||||
// __cxa_free_exception() expects to be passed the thrown object, which | // __cxa_free_exception() expects to be passed the thrown object, which | ||||
// immediately follows the exception, not the exception itself | // immediately follows the exception, not the exception itself | ||||
__cxa_free_exception(ex+1); | __cxa_free_exception(ex+1); | ||||
} | } | ||||
/** | /** | ||||
* Cleanup function called when a thread exists to make certain that all of the | * Cleanup function called when a thread exists to make certain that all of the | ||||
* per-thread data is deleted. | * per-thread data is deleted. | ||||
*/ | */ | ||||
static void thread_cleanup(void* thread_info) | static void thread_cleanup(void* thread_info) | ||||
{ | { | ||||
__cxa_thread_info *info = (__cxa_thread_info*)thread_info; | __cxa_thread_info *info = static_cast<__cxa_thread_info*>(thread_info); | ||||
if (info->globals.caughtExceptions) | if (info->globals.caughtExceptions) | ||||
{ | { | ||||
// If this is a foreign exception, ask it to clean itself up. | // If this is a foreign exception, ask it to clean itself up. | ||||
if (info->foreign_exception_state != __cxa_thread_info::none) | if (info->foreign_exception_state != __cxa_thread_info::none) | ||||
{ | { | ||||
_Unwind_Exception *e = (_Unwind_Exception*)info->globals.caughtExceptions; | _Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(info->globals.caughtExceptions); | ||||
e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e); | e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
free_exception_list(info->globals.caughtExceptions); | free_exception_list(info->globals.caughtExceptions); | ||||
} | } | ||||
} | } | ||||
free(thread_info); | free(thread_info); | ||||
Show All 23 Lines | static void init_key(void) | ||||
if ((0 == pthread_key_create) || | if ((0 == pthread_key_create) || | ||||
(0 == pthread_setspecific) || | (0 == pthread_setspecific) || | ||||
(0 == pthread_getspecific)) | (0 == pthread_getspecific)) | ||||
{ | { | ||||
fakeTLS = true; | fakeTLS = true; | ||||
return; | return; | ||||
} | } | ||||
pthread_key_create(&eh_key, thread_cleanup); | pthread_key_create(&eh_key, thread_cleanup); | ||||
pthread_setspecific(eh_key, (void*)0x42); | pthread_setspecific(eh_key, reinterpret_cast<void *>(0x42)); | ||||
fakeTLS = (pthread_getspecific(eh_key) != (void*)0x42); | fakeTLS = (pthread_getspecific(eh_key) != reinterpret_cast<void *>(0x42)); | ||||
pthread_setspecific(eh_key, 0); | pthread_setspecific(eh_key, 0); | ||||
} | } | ||||
/** | /** | ||||
* Returns the thread info structure, creating it if it is not already created. | * Returns the thread info structure, creating it if it is not already created. | ||||
*/ | */ | ||||
static __cxa_thread_info *thread_info() | static __cxa_thread_info *thread_info() | ||||
{ | { | ||||
if ((0 == pthread_once) || pthread_once(&once_control, init_key)) | if ((0 == pthread_once) || pthread_once(&once_control, init_key)) | ||||
{ | { | ||||
fakeTLS = true; | fakeTLS = true; | ||||
} | } | ||||
if (fakeTLS) { return &singleThreadInfo; } | if (fakeTLS) { return &singleThreadInfo; } | ||||
__cxa_thread_info *info = (__cxa_thread_info*)pthread_getspecific(eh_key); | __cxa_thread_info *info = static_cast<__cxa_thread_info*>(pthread_getspecific(eh_key)); | ||||
if (0 == info) | if (0 == info) | ||||
{ | { | ||||
info = (__cxa_thread_info*)calloc(1, sizeof(__cxa_thread_info)); | info = static_cast<__cxa_thread_info*>(calloc(1, sizeof(__cxa_thread_info))); | ||||
pthread_setspecific(eh_key, info); | pthread_setspecific(eh_key, info); | ||||
} | } | ||||
return info; | return info; | ||||
} | } | ||||
/** | /** | ||||
* Fast version of thread_info(). May fail if thread_info() is not called on | * Fast version of thread_info(). May fail if thread_info() is not called on | ||||
* this thread at least once already. | * this thread at least once already. | ||||
*/ | */ | ||||
static __cxa_thread_info *thread_info_fast() | static __cxa_thread_info *thread_info_fast() | ||||
{ | { | ||||
if (fakeTLS) { return &singleThreadInfo; } | if (fakeTLS) { return &singleThreadInfo; } | ||||
return (__cxa_thread_info*)pthread_getspecific(eh_key); | return static_cast<__cxa_thread_info*>(pthread_getspecific(eh_key)); | ||||
} | } | ||||
/** | /** | ||||
* ABI function returning the __cxa_eh_globals structure. | * ABI function returning the __cxa_eh_globals structure. | ||||
*/ | */ | ||||
extern "C" __cxa_eh_globals *ABI_NAMESPACE::__cxa_get_globals(void) | extern "C" __cxa_eh_globals *ABI_NAMESPACE::__cxa_get_globals(void) | ||||
{ | { | ||||
return &(thread_info()->globals); | return &(thread_info()->globals); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | while (buffer < 0) | ||||
// While we were sleeping on the lock, another thread might have free'd | // While we were sleeping on the lock, another thread might have free'd | ||||
// enough memory for us to use, so try the allocation again - no point | // enough memory for us to use, so try the allocation again - no point | ||||
// using the emergency buffer if there is some real memory that we can | // using the emergency buffer if there is some real memory that we can | ||||
// use... | // use... | ||||
void *m = calloc(1, size); | void *m = calloc(1, size); | ||||
if (0 != m) | if (0 != m) | ||||
{ | { | ||||
pthread_mutex_unlock(&emergency_malloc_lock); | pthread_mutex_unlock(&emergency_malloc_lock); | ||||
return (char*)m; | return static_cast<char*>(m); | ||||
} | } | ||||
for (int i=0 ; i<16 ; i++) | for (int i=0 ; i<16 ; i++) | ||||
{ | { | ||||
if (!buffer_allocated[i]) | if (!buffer_allocated[i]) | ||||
{ | { | ||||
buffer = i; | buffer = i; | ||||
buffer_allocated[i] = true; | buffer_allocated[i] = true; | ||||
break; | break; | ||||
Show All 21 Lines | |||||
* often. | * often. | ||||
*/ | */ | ||||
static void emergency_malloc_free(char *ptr) | static void emergency_malloc_free(char *ptr) | ||||
{ | { | ||||
int buffer = -1; | int buffer = -1; | ||||
// Find the buffer corresponding to this pointer. | // Find the buffer corresponding to this pointer. | ||||
for (int i=0 ; i<16 ; i++) | for (int i=0 ; i<16 ; i++) | ||||
{ | { | ||||
if (ptr == (void*)(emergency_buffer + (1024 * i))) | if (ptr == static_cast<void*>(emergency_buffer + (1024 * i))) | ||||
{ | { | ||||
buffer = i; | buffer = i; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
assert(buffer > 0 && | assert(buffer > 0 && | ||||
"Trying to free something that is not an emergency buffer!"); | "Trying to free something that is not an emergency buffer!"); | ||||
// emergency_malloc() is expected to return 0-initialized data. We don't | // emergency_malloc() is expected to return 0-initialized data. We don't | ||||
// zero the buffer when allocating it, because the static buffers will | // zero the buffer when allocating it, because the static buffers will | ||||
// begin life containing 0 values. | // begin life containing 0 values. | ||||
memset((void*)ptr, 0, 1024); | memset(ptr, 0, 1024); | ||||
// Signal the condition variable to wake up any threads that are blocking | // Signal the condition variable to wake up any threads that are blocking | ||||
// waiting for some space in the emergency buffer | // waiting for some space in the emergency buffer | ||||
pthread_mutex_lock(&emergency_malloc_lock); | pthread_mutex_lock(&emergency_malloc_lock); | ||||
// In theory, we don't need to do this with the lock held. In practice, | // In theory, we don't need to do this with the lock held. In practice, | ||||
// our array of bools will probably be updated using 32-bit or 64-bit | // our array of bools will probably be updated using 32-bit or 64-bit | ||||
// memory operations, so this update may clobber adjacent values. | // memory operations, so this update may clobber adjacent values. | ||||
buffer_allocated[buffer] = false; | buffer_allocated[buffer] = false; | ||||
pthread_cond_signal(&emergency_malloc_wait); | pthread_cond_signal(&emergency_malloc_wait); | ||||
pthread_mutex_unlock(&emergency_malloc_lock); | pthread_mutex_unlock(&emergency_malloc_lock); | ||||
} | } | ||||
static char *alloc_or_die(size_t size) | static char *alloc_or_die(size_t size) | ||||
{ | { | ||||
char *buffer = (char*)calloc(1, size); | char *buffer = static_cast<char*>(calloc(1, size)); | ||||
// If calloc() doesn't want to give us any memory, try using an emergency | // If calloc() doesn't want to give us any memory, try using an emergency | ||||
// buffer. | // buffer. | ||||
if (0 == buffer) | if (0 == buffer) | ||||
{ | { | ||||
buffer = emergency_malloc(size); | buffer = emergency_malloc(size); | ||||
// This is only reached if the allocation is greater than 1KB, and | // This is only reached if the allocation is greater than 1KB, and | ||||
// anyone throwing objects that big really should know better. | // anyone throwing objects that big really should know better. | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
* calling __cxa_allocate_exception() and actually throwing the exception. | * calling __cxa_allocate_exception() and actually throwing the exception. | ||||
* This happens when the object's copy constructor throws an exception. | * This happens when the object's copy constructor throws an exception. | ||||
* | * | ||||
* In this implementation, it is also called by __cxa_end_catch() and during | * In this implementation, it is also called by __cxa_end_catch() and during | ||||
* thread cleanup. | * thread cleanup. | ||||
*/ | */ | ||||
extern "C" void __cxa_free_exception(void *thrown_exception) | extern "C" void __cxa_free_exception(void *thrown_exception) | ||||
{ | { | ||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1; | __cxa_exception *ex = reinterpret_cast<__cxa_exception*>(thrown_exception) - 1; | ||||
// Free the object that was thrown, calling its destructor | // Free the object that was thrown, calling its destructor | ||||
if (0 != ex->exceptionDestructor) | if (0 != ex->exceptionDestructor) | ||||
{ | { | ||||
try | try | ||||
{ | { | ||||
ex->exceptionDestructor(thrown_exception); | ex->exceptionDestructor(thrown_exception); | ||||
} | } | ||||
catch(...) | catch(...) | ||||
{ | { | ||||
// FIXME: Check that this is really what the spec says to do. | // FIXME: Check that this is really what the spec says to do. | ||||
std::terminate(); | std::terminate(); | ||||
} | } | ||||
} | } | ||||
free_exception((char*)ex); | free_exception(reinterpret_cast<char*>(ex)); | ||||
} | } | ||||
static void releaseException(__cxa_exception *exception) | static void releaseException(__cxa_exception *exception) | ||||
{ | { | ||||
if (isDependentException(exception->unwindHeader.exception_class)) | if (isDependentException(exception->unwindHeader.exception_class)) | ||||
{ | { | ||||
__cxa_free_dependent_exception(exception+1); | __cxa_free_dependent_exception(exception+1); | ||||
return; | return; | ||||
} | } | ||||
if (__sync_sub_and_fetch(&exception->referenceCount, 1) == 0) | if (__sync_sub_and_fetch(&exception->referenceCount, 1) == 0) | ||||
{ | { | ||||
// __cxa_free_exception() expects to be passed the thrown object, | // __cxa_free_exception() expects to be passed the thrown object, | ||||
// which immediately follows the exception, not the exception | // which immediately follows the exception, not the exception | ||||
// itself | // itself | ||||
__cxa_free_exception(exception+1); | __cxa_free_exception(exception+1); | ||||
} | } | ||||
} | } | ||||
void __cxa_free_dependent_exception(void *thrown_exception) | void __cxa_free_dependent_exception(void *thrown_exception) | ||||
{ | { | ||||
__cxa_dependent_exception *ex = ((__cxa_dependent_exception*)thrown_exception) - 1; | __cxa_dependent_exception *ex = reinterpret_cast<__cxa_dependent_exception*>(thrown_exception) - 1; | ||||
assert(isDependentException(ex->unwindHeader.exception_class)); | assert(isDependentException(ex->unwindHeader.exception_class)); | ||||
if (ex->primaryException) | if (ex->primaryException) | ||||
{ | { | ||||
releaseException(realExceptionFromException((__cxa_exception*)ex)); | releaseException(realExceptionFromException(reinterpret_cast<__cxa_exception*>(ex))); | ||||
} | } | ||||
free_exception((char*)ex); | free_exception(reinterpret_cast<char*>(ex)); | ||||
} | } | ||||
/** | /** | ||||
* Callback function used with _Unwind_Backtrace(). | * Callback function used with _Unwind_Backtrace(). | ||||
* | * | ||||
* Prints a stack trace. Used only for debugging help. | * Prints a stack trace. Used only for debugging help. | ||||
* | * | ||||
* Note: As of FreeBSD 8.1, dladd() still doesn't work properly, so this only | * Note: As of FreeBSD 8.1, dladd() still doesn't work properly, so this only | ||||
* correctly prints function names from public, relocatable, symbols. | * correctly prints function names from public, relocatable, symbols. | ||||
*/ | */ | ||||
static _Unwind_Reason_Code trace(struct _Unwind_Context *context, void *c) | static _Unwind_Reason_Code trace(struct _Unwind_Context *context, void *c) | ||||
{ | { | ||||
Dl_info myinfo; | Dl_info myinfo; | ||||
int mylookup = | int mylookup = | ||||
dladdr((void*)(uintptr_t)__cxa_current_exception_type, &myinfo); | dladdr(reinterpret_cast<void *>(__cxa_current_exception_type), &myinfo); | ||||
void *ip = (void*)_Unwind_GetIP(context); | void *ip = reinterpret_cast<void*>(_Unwind_GetIP(context)); | ||||
Dl_info info; | Dl_info info; | ||||
if (dladdr(ip, &info) != 0) | if (dladdr(ip, &info) != 0) | ||||
{ | { | ||||
if (mylookup == 0 || strcmp(info.dli_fname, myinfo.dli_fname) != 0) | if (mylookup == 0 || strcmp(info.dli_fname, myinfo.dli_fname) != 0) | ||||
{ | { | ||||
printf("%p:%s() in %s\n", ip, info.dli_sname, info.dli_fname); | printf("%p:%s() in %s\n", ip, info.dli_sname, info.dli_fname); | ||||
} | } | ||||
} | } | ||||
return _URC_CONTINUE_UNWIND; | return _URC_CONTINUE_UNWIND; | ||||
} | } | ||||
/** | /** | ||||
* Report a failure that occurred when attempting to throw an exception. | * Report a failure that occurred when attempting to throw an exception. | ||||
* | * | ||||
* If the failure happened by falling off the end of the stack without finding | * If the failure happened by falling off the end of the stack without finding | ||||
* a handler, prints a back trace before aborting. | * a handler, prints a back trace before aborting. | ||||
*/ | */ | ||||
#if __GNUC__ > 3 && __GNUC_MINOR__ > 2 | |||||
extern "C" void *__cxa_begin_catch(void *e) throw(); | |||||
#else | |||||
extern "C" void *__cxa_begin_catch(void *e); | |||||
#endif | |||||
static void report_failure(_Unwind_Reason_Code err, __cxa_exception *thrown_exception) | static void report_failure(_Unwind_Reason_Code err, __cxa_exception *thrown_exception) | ||||
{ | { | ||||
switch (err) | switch (err) | ||||
{ | { | ||||
default: break; | default: break; | ||||
case _URC_FATAL_PHASE1_ERROR: | case _URC_FATAL_PHASE1_ERROR: | ||||
fprintf(stderr, "Fatal error during phase 1 unwinding\n"); | fprintf(stderr, "Fatal error during phase 1 unwinding\n"); | ||||
break; | break; | ||||
#ifndef __arm__ | #if !defined(__arm__) || defined(__ARM_DWARF_EH__) | ||||
case _URC_FATAL_PHASE2_ERROR: | case _URC_FATAL_PHASE2_ERROR: | ||||
fprintf(stderr, "Fatal error during phase 2 unwinding\n"); | fprintf(stderr, "Fatal error during phase 2 unwinding\n"); | ||||
break; | break; | ||||
#endif | #endif | ||||
case _URC_END_OF_STACK: | case _URC_END_OF_STACK: | ||||
__cxa_begin_catch (&(thrown_exception->unwindHeader)); | |||||
std::terminate(); | |||||
fprintf(stderr, "Terminating due to uncaught exception %p", | fprintf(stderr, "Terminating due to uncaught exception %p", | ||||
(void*)thrown_exception); | static_cast<void*>(thrown_exception)); | ||||
thrown_exception = realExceptionFromException(thrown_exception); | thrown_exception = realExceptionFromException(thrown_exception); | ||||
static const __class_type_info *e_ti = | static const __class_type_info *e_ti = | ||||
static_cast<const __class_type_info*>(&typeid(std::exception)); | static_cast<const __class_type_info*>(&typeid(std::exception)); | ||||
const __class_type_info *throw_ti = | const __class_type_info *throw_ti = | ||||
dynamic_cast<const __class_type_info*>(thrown_exception->exceptionType); | dynamic_cast<const __class_type_info*>(thrown_exception->exceptionType); | ||||
if (throw_ti) | if (throw_ti) | ||||
{ | { | ||||
std::exception *e = | std::exception *e = | ||||
(std::exception*)e_ti->cast_to((void*)(thrown_exception+1), | static_cast<std::exception*>(e_ti->cast_to(static_cast<void*>(thrown_exception+1), | ||||
throw_ti); | throw_ti)); | ||||
if (e) | if (e) | ||||
{ | { | ||||
fprintf(stderr, " '%s'", e->what()); | fprintf(stderr, " '%s'", e->what()); | ||||
} | } | ||||
} | } | ||||
size_t bufferSize = 128; | size_t bufferSize = 128; | ||||
char *demangled = (char*)malloc(bufferSize); | char *demangled = static_cast<char*>(malloc(bufferSize)); | ||||
const char *mangled = thrown_exception->exceptionType->name(); | const char *mangled = thrown_exception->exceptionType->name(); | ||||
int status; | int status; | ||||
demangled = __cxa_demangle(mangled, demangled, &bufferSize, &status); | demangled = __cxa_demangle(mangled, demangled, &bufferSize, &status); | ||||
fprintf(stderr, " of type %s\n", | fprintf(stderr, " of type %s\n", | ||||
status == 0 ? (const char*)demangled : mangled); | status == 0 ? demangled : mangled); | ||||
if (status == 0) { free(demangled); } | if (status == 0) { free(demangled); } | ||||
// Print a back trace if no handler is found. | // Print a back trace if no handler is found. | ||||
// TODO: Make this optional | // TODO: Make this optional | ||||
#ifndef __arm__ | #ifndef __arm__ | ||||
_Unwind_Backtrace(trace, 0); | _Unwind_Backtrace(trace, 0); | ||||
#endif | #endif | ||||
// Just abort. No need to call std::terminate for the second time | |||||
abort(); | |||||
break; | break; | ||||
} | } | ||||
std::terminate(); | std::terminate(); | ||||
} | } | ||||
static void throw_exception(__cxa_exception *ex) | static void throw_exception(__cxa_exception *ex) | ||||
{ | { | ||||
__cxa_thread_info *info = thread_info(); | __cxa_thread_info *info = thread_info(); | ||||
Show All 21 Lines | |||||
* ABI function for throwing an exception. Takes the object to be thrown (the | * ABI function for throwing an exception. Takes the object to be thrown (the | ||||
* pointer returned by __cxa_allocate_exception()), the type info for the | * pointer returned by __cxa_allocate_exception()), the type info for the | ||||
* pointee, and the destructor (if there is one) as arguments. | * pointee, and the destructor (if there is one) as arguments. | ||||
*/ | */ | ||||
extern "C" void __cxa_throw(void *thrown_exception, | extern "C" void __cxa_throw(void *thrown_exception, | ||||
std::type_info *tinfo, | std::type_info *tinfo, | ||||
void(*dest)(void*)) | void(*dest)(void*)) | ||||
{ | { | ||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1; | __cxa_exception *ex = reinterpret_cast<__cxa_exception*>(thrown_exception) - 1; | ||||
ex->referenceCount = 1; | ex->referenceCount = 1; | ||||
ex->exceptionType = tinfo; | ex->exceptionType = tinfo; | ||||
ex->exceptionDestructor = dest; | ex->exceptionDestructor = dest; | ||||
ex->unwindHeader.exception_class = exception_class; | ex->unwindHeader.exception_class = exception_class; | ||||
ex->unwindHeader.exception_cleanup = exception_cleanup; | ex->unwindHeader.exception_cleanup = exception_cleanup; | ||||
throw_exception(ex); | throw_exception(ex); | ||||
} | } | ||||
extern "C" void __cxa_rethrow_primary_exception(void* thrown_exception) | extern "C" void __cxa_rethrow_primary_exception(void* thrown_exception) | ||||
{ | { | ||||
if (NULL == thrown_exception) { return; } | if (NULL == thrown_exception) { return; } | ||||
__cxa_exception *original = exceptionFromPointer(thrown_exception); | __cxa_exception *original = exceptionFromPointer(thrown_exception); | ||||
__cxa_dependent_exception *ex = ((__cxa_dependent_exception*)__cxa_allocate_dependent_exception())-1; | __cxa_dependent_exception *ex = reinterpret_cast<__cxa_dependent_exception*>(__cxa_allocate_dependent_exception())-1; | ||||
ex->primaryException = thrown_exception; | ex->primaryException = thrown_exception; | ||||
__cxa_increment_exception_refcount(thrown_exception); | __cxa_increment_exception_refcount(thrown_exception); | ||||
ex->exceptionType = original->exceptionType; | ex->exceptionType = original->exceptionType; | ||||
ex->unwindHeader.exception_class = dependent_exception_class; | ex->unwindHeader.exception_class = dependent_exception_class; | ||||
ex->unwindHeader.exception_cleanup = dependent_exception_cleanup; | ex->unwindHeader.exception_cleanup = dependent_exception_cleanup; | ||||
throw_exception((__cxa_exception*)ex); | throw_exception(reinterpret_cast<__cxa_exception*>(ex)); | ||||
} | } | ||||
extern "C" void *__cxa_current_primary_exception(void) | extern "C" void *__cxa_current_primary_exception(void) | ||||
{ | { | ||||
__cxa_eh_globals* globals = __cxa_get_globals(); | __cxa_eh_globals* globals = __cxa_get_globals(); | ||||
__cxa_exception *ex = globals->caughtExceptions; | __cxa_exception *ex = globals->caughtExceptions; | ||||
if (0 == ex) { return NULL; } | if (0 == ex) { return NULL; } | ||||
ex = realExceptionFromException(ex); | ex = realExceptionFromException(ex); | ||||
__sync_fetch_and_add(&ex->referenceCount, 1); | __sync_fetch_and_add(&ex->referenceCount, 1); | ||||
return ex + 1; | return ex + 1; | ||||
} | } | ||||
extern "C" void __cxa_increment_exception_refcount(void* thrown_exception) | extern "C" void __cxa_increment_exception_refcount(void* thrown_exception) | ||||
{ | { | ||||
if (NULL == thrown_exception) { return; } | if (NULL == thrown_exception) { return; } | ||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1; | __cxa_exception *ex = static_cast<__cxa_exception*>(thrown_exception) - 1; | ||||
if (isDependentException(ex->unwindHeader.exception_class)) { return; } | if (isDependentException(ex->unwindHeader.exception_class)) { return; } | ||||
__sync_fetch_and_add(&ex->referenceCount, 1); | __sync_fetch_and_add(&ex->referenceCount, 1); | ||||
} | } | ||||
extern "C" void __cxa_decrement_exception_refcount(void* thrown_exception) | extern "C" void __cxa_decrement_exception_refcount(void* thrown_exception) | ||||
{ | { | ||||
if (NULL == thrown_exception) { return; } | if (NULL == thrown_exception) { return; } | ||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1; | __cxa_exception *ex = static_cast<__cxa_exception*>(thrown_exception) - 1; | ||||
releaseException(ex); | releaseException(ex); | ||||
} | } | ||||
/** | /** | ||||
* ABI function. Rethrows the current exception. Does not remove the | * ABI function. Rethrows the current exception. Does not remove the | ||||
* exception from the stack or decrement its handler count - the compiler is | * exception from the stack or decrement its handler count - the compiler is | ||||
* expected to set the landing pad for this function to the end of the catch | * expected to set the landing pad for this function to the end of the catch | ||||
* block, and then call _Unwind_Resume() to continue unwinding once | * block, and then call _Unwind_Resume() to continue unwinding once | ||||
Show All 15 Lines | if (0 == ex) | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"Attempting to rethrow an exception that doesn't exist!\n"); | "Attempting to rethrow an exception that doesn't exist!\n"); | ||||
std::terminate(); | std::terminate(); | ||||
} | } | ||||
if (ti->foreign_exception_state != __cxa_thread_info::none) | if (ti->foreign_exception_state != __cxa_thread_info::none) | ||||
{ | { | ||||
ti->foreign_exception_state = __cxa_thread_info::rethrown; | ti->foreign_exception_state = __cxa_thread_info::rethrown; | ||||
_Unwind_Exception *e = (_Unwind_Exception*)ex; | _Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(ex); | ||||
_Unwind_Reason_Code err = _Unwind_Resume_or_Rethrow(e); | _Unwind_Reason_Code err = _Unwind_Resume_or_Rethrow(e); | ||||
report_failure(err, ex); | report_failure(err, ex); | ||||
return; | return; | ||||
} | } | ||||
assert(ex->handlerCount > 0 && "Rethrowing uncaught exception!"); | assert(ex->handlerCount > 0 && "Rethrowing uncaught exception!"); | ||||
// ex->handlerCount will be decremented in __cxa_end_catch in enclosing | // ex->handlerCount will be decremented in __cxa_end_catch in enclosing | ||||
Show All 26 Lines | static std::type_info *get_type_info_entry(_Unwind_Context *context, | ||||
dw_eh_ptr_t start = record; | dw_eh_ptr_t start = record; | ||||
// Read the value, but it's probably an indirect reference... | // Read the value, but it's probably an indirect reference... | ||||
int64_t offset = read_value(lsda->type_table_encoding, &record); | int64_t offset = read_value(lsda->type_table_encoding, &record); | ||||
// (If the entry is 0, don't try to dereference it. That would be bad.) | // (If the entry is 0, don't try to dereference it. That would be bad.) | ||||
if (offset == 0) { return 0; } | if (offset == 0) { return 0; } | ||||
// ...so we need to resolve it | // ...so we need to resolve it | ||||
return (std::type_info*)resolve_indirect_value(context, | return reinterpret_cast<std::type_info*>(resolve_indirect_value(context, | ||||
lsda->type_table_encoding, offset, start); | lsda->type_table_encoding, offset, start)); | ||||
} | } | ||||
/** | /** | ||||
* Checks the type signature found in a handler against the type of the thrown | * Checks the type signature found in a handler against the type of the thrown | ||||
* object. If ex is 0 then it is assumed to be a foreign exception and only | * object. If ex is 0 then it is assumed to be a foreign exception and only | ||||
* matches cleanups. | * matches cleanups. | ||||
*/ | */ | ||||
static bool check_type_signature(__cxa_exception *ex, | static bool check_type_signature(__cxa_exception *ex, | ||||
const std::type_info *type, | const std::type_info *type, | ||||
void *&adjustedPtr) | void *&adjustedPtr) | ||||
{ | { | ||||
void *exception_ptr = (void*)(ex+1); | void *exception_ptr = static_cast<void*>(ex+1); | ||||
const std::type_info *ex_type = ex ? ex->exceptionType : 0; | const std::type_info *ex_type = ex ? ex->exceptionType : 0; | ||||
bool is_ptr = ex ? ex_type->__is_pointer_p() : false; | bool is_ptr = ex ? ex_type->__is_pointer_p() : false; | ||||
if (is_ptr) | if (is_ptr) | ||||
{ | { | ||||
exception_ptr = *(void**)exception_ptr; | exception_ptr = *static_cast<void**>(exception_ptr); | ||||
} | } | ||||
// Always match a catchall, even with a foreign exception | // Always match a catchall, even with a foreign exception | ||||
// | // | ||||
// Note: A 0 here is a catchall, not a cleanup, so we return true to | // Note: A 0 here is a catchall, not a cleanup, so we return true to | ||||
// indicate that we found a catch. | // indicate that we found a catch. | ||||
if (0 == type) | if (0 == type) | ||||
{ | { | ||||
if (ex) | if (ex) | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | if (filter > 0) | ||||
*selector = filter; | *selector = filter; | ||||
return handler_catch; | return handler_catch; | ||||
} | } | ||||
} | } | ||||
else if (filter < 0 && 0 != ex) | else if (filter < 0 && 0 != ex) | ||||
{ | { | ||||
bool matched = false; | bool matched = false; | ||||
*selector = filter; | *selector = filter; | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
filter++; | filter++; | ||||
std::type_info *handler_type = get_type_info_entry(context, lsda, filter--); | std::type_info *handler_type = get_type_info_entry(context, lsda, filter--); | ||||
while (handler_type) | while (handler_type) | ||||
{ | { | ||||
if (check_type_signature(ex, handler_type, adjustedPtr)) | if (check_type_signature(ex, handler_type, adjustedPtr)) | ||||
{ | { | ||||
matched = true; | matched = true; | ||||
break; | break; | ||||
} | } | ||||
handler_type = get_type_info_entry(context, lsda, filter--); | handler_type = get_type_info_entry(context, lsda, filter--); | ||||
} | } | ||||
#else | #else | ||||
unsigned char *type_index = ((unsigned char*)lsda->type_table - filter - 1); | unsigned char *type_index = reinterpret_cast<unsigned char*>(lsda->type_table) - filter - 1; | ||||
while (*type_index) | while (*type_index) | ||||
{ | { | ||||
std::type_info *handler_type = get_type_info_entry(context, lsda, *(type_index++)); | std::type_info *handler_type = get_type_info_entry(context, lsda, *(type_index++)); | ||||
// If the exception spec matches a permitted throw type for | // If the exception spec matches a permitted throw type for | ||||
// this function, don't report a handler - we are allowed to | // this function, don't report a handler - we are allowed to | ||||
// propagate this exception out. | // propagate this exception out. | ||||
if (check_type_signature(ex, handler_type, adjustedPtr)) | if (check_type_signature(ex, handler_type, adjustedPtr)) | ||||
{ | { | ||||
Show All 15 Lines | #endif | ||||
} | } | ||||
} | } | ||||
return found; | return found; | ||||
} | } | ||||
static void pushCleanupException(_Unwind_Exception *exceptionObject, | static void pushCleanupException(_Unwind_Exception *exceptionObject, | ||||
__cxa_exception *ex) | __cxa_exception *ex) | ||||
{ | { | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
__cxa_thread_info *info = thread_info_fast(); | __cxa_thread_info *info = thread_info_fast(); | ||||
if (ex) | if (ex) | ||||
{ | { | ||||
ex->cleanupCount++; | ex->cleanupCount++; | ||||
if (ex->cleanupCount > 1) | if (ex->cleanupCount > 1) | ||||
{ | { | ||||
assert(exceptionObject == info->currentCleanup); | assert(exceptionObject == info->currentCleanup); | ||||
return; | return; | ||||
Show All 28 Lines | BEGIN_PERSONALITY_FUNCTION(__gxx_personality_v0) | ||||
// If this isn't a foreign exception, then we have a C++ exception structure | // If this isn't a foreign exception, then we have a C++ exception structure | ||||
if (!foreignException) | if (!foreignException) | ||||
{ | { | ||||
ex = exceptionFromPointer(exceptionObject); | ex = exceptionFromPointer(exceptionObject); | ||||
realEx = realExceptionFromException(ex); | realEx = realExceptionFromException(ex); | ||||
} | } | ||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__) | |||||
unsigned char *lsda_addr = | unsigned char *lsda_addr = | ||||
(unsigned char*)_Unwind_GetLanguageSpecificData(context); | static_cast<unsigned char*>(_Unwind_GetLanguageSpecificData(context)); | ||||
#else | |||||
unsigned char *lsda_addr = | |||||
reinterpret_cast<unsigned char*>(static_cast<uintptr_t>(_Unwind_GetLanguageSpecificData(context))); | |||||
#endif | |||||
// No LSDA implies no landing pads - try the next frame | // No LSDA implies no landing pads - try the next frame | ||||
if (0 == lsda_addr) { return continueUnwinding(exceptionObject, context); } | if (0 == lsda_addr) { return continueUnwinding(exceptionObject, context); } | ||||
// These two variables define how the exception will be handled. | // These two variables define how the exception will be handled. | ||||
dwarf_eh_action action = {0}; | dwarf_eh_action action = {0}; | ||||
unsigned long selector = 0; | unsigned long selector = 0; | ||||
Show All 32 Lines | if (actions & _UA_SEARCH_PHASE) | ||||
// searching for something real | // searching for something real | ||||
if (found_handler == handler_catch) | if (found_handler == handler_catch) | ||||
{ | { | ||||
// Cache the results for the phase 2 unwind, if we found a handler | // Cache the results for the phase 2 unwind, if we found a handler | ||||
// and this is not a foreign exception. | // and this is not a foreign exception. | ||||
if (ex) | if (ex) | ||||
{ | { | ||||
saveLandingPad(context, exceptionObject, ex, selector, action.landing_pad); | saveLandingPad(context, exceptionObject, ex, selector, action.landing_pad); | ||||
ex->languageSpecificData = (const char*)lsda_addr; | ex->languageSpecificData = reinterpret_cast<const char*>(lsda_addr); | ||||
ex->actionRecord = (const char*)action.action_record; | ex->actionRecord = reinterpret_cast<const char*>(action.action_record); | ||||
// ex->adjustedPtr is set when finding the action record. | // ex->adjustedPtr is set when finding the action record. | ||||
} | } | ||||
return _URC_HANDLER_FOUND; | return _URC_HANDLER_FOUND; | ||||
} | } | ||||
return continueUnwinding(exceptionObject, context); | return continueUnwinding(exceptionObject, context); | ||||
} | } | ||||
Show All 29 Lines | #endif | ||||
{ | { | ||||
// Restore the saved info if we saved some last time. | // Restore the saved info if we saved some last time. | ||||
loadLandingPad(context, exceptionObject, ex, &selector, &action.landing_pad); | loadLandingPad(context, exceptionObject, ex, &selector, &action.landing_pad); | ||||
ex->catchTemp = 0; | ex->catchTemp = 0; | ||||
ex->handlerSwitchValue = 0; | ex->handlerSwitchValue = 0; | ||||
} | } | ||||
_Unwind_SetIP(context, (unsigned long)action.landing_pad); | _Unwind_SetIP(context, reinterpret_cast<unsigned long>(action.landing_pad)); | ||||
_Unwind_SetGR(context, __builtin_eh_return_data_regno(0), | _Unwind_SetGR(context, __builtin_eh_return_data_regno(0), | ||||
(unsigned long)exceptionObject); | reinterpret_cast<unsigned long>(exceptionObject)); | ||||
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1), selector); | _Unwind_SetGR(context, __builtin_eh_return_data_regno(1), selector); | ||||
return _URC_INSTALL_CONTEXT; | return _URC_INSTALL_CONTEXT; | ||||
} | } | ||||
/** | /** | ||||
* ABI function called when entering a catch statement. The argument is the | * ABI function called when entering a catch statement. The argument is the | ||||
* pointer passed out of the personality function. This is always the start of | * pointer passed out of the personality function. This is always the start of | ||||
* the _Unwind_Exception object. The return value for this function is the | * the _Unwind_Exception object. The return value for this function is the | ||||
* pointer to the caught exception, which is either the adjusted pointer (for | * pointer to the caught exception, which is either the adjusted pointer (for | ||||
* C++ exceptions) of the unadjusted pointer (for foreign exceptions). | * C++ exceptions) of the unadjusted pointer (for foreign exceptions). | ||||
*/ | */ | ||||
#if __GNUC__ > 3 && __GNUC_MINOR__ > 2 | #if __GNUC__ > 3 && __GNUC_MINOR__ > 2 | ||||
extern "C" void *__cxa_begin_catch(void *e) throw() | extern "C" void *__cxa_begin_catch(void *e) throw() | ||||
#else | #else | ||||
extern "C" void *__cxa_begin_catch(void *e) | extern "C" void *__cxa_begin_catch(void *e) | ||||
#endif | #endif | ||||
{ | { | ||||
// We can't call the fast version here, because if the first exception that | // We can't call the fast version here, because if the first exception that | ||||
// we see is a foreign exception then we won't have called it yet. | // we see is a foreign exception then we won't have called it yet. | ||||
__cxa_thread_info *ti = thread_info(); | __cxa_thread_info *ti = thread_info(); | ||||
__cxa_eh_globals *globals = &ti->globals; | __cxa_eh_globals *globals = &ti->globals; | ||||
globals->uncaughtExceptions--; | globals->uncaughtExceptions--; | ||||
_Unwind_Exception *exceptionObject = (_Unwind_Exception*)e; | _Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(e); | ||||
if (isCXXException(exceptionObject->exception_class)) | if (isCXXException(exceptionObject->exception_class)) | ||||
{ | { | ||||
__cxa_exception *ex = exceptionFromPointer(exceptionObject); | __cxa_exception *ex = exceptionFromPointer(exceptionObject); | ||||
if (ex->handlerCount == 0) | if (ex->handlerCount == 0) | ||||
{ | { | ||||
// Add this to the front of the list of exceptions being handled | // Add this to the front of the list of exceptions being handled | ||||
Show All 37 Lines | #endif | ||||
{ | { | ||||
// If this is a foreign exception, then we need to be able to | // If this is a foreign exception, then we need to be able to | ||||
// store it. We can't chain foreign exceptions, so we give up | // store it. We can't chain foreign exceptions, so we give up | ||||
// if there are already some outstanding ones. | // if there are already some outstanding ones. | ||||
if (globals->caughtExceptions != 0) | if (globals->caughtExceptions != 0) | ||||
{ | { | ||||
std::terminate(); | std::terminate(); | ||||
} | } | ||||
globals->caughtExceptions = (__cxa_exception*)exceptionObject; | globals->caughtExceptions = reinterpret_cast<__cxa_exception*>(exceptionObject); | ||||
ti->foreign_exception_state = __cxa_thread_info::caught; | ti->foreign_exception_state = __cxa_thread_info::caught; | ||||
} | } | ||||
// exceptionObject is the pointer to the _Unwind_Exception within the | // exceptionObject is the pointer to the _Unwind_Exception within the | ||||
// __cxa_exception. The throw object is after this | // __cxa_exception. The throw object is after this | ||||
return ((char*)exceptionObject + sizeof(_Unwind_Exception)); | return (reinterpret_cast<char*>(exceptionObject) + sizeof(_Unwind_Exception)); | ||||
} | } | ||||
/** | /** | ||||
* ABI function called when exiting a catch block. This will free the current | * ABI function called when exiting a catch block. This will free the current | ||||
* exception if it is no longer referenced in other catch blocks. | * exception if it is no longer referenced in other catch blocks. | ||||
*/ | */ | ||||
extern "C" void __cxa_end_catch() | extern "C" void __cxa_end_catch() | ||||
{ | { | ||||
// We can call the fast version here because the slow version is called in | // We can call the fast version here because the slow version is called in | ||||
// __cxa_throw(), which must have been called before we end a catch block | // __cxa_throw(), which must have been called before we end a catch block | ||||
__cxa_thread_info *ti = thread_info_fast(); | __cxa_thread_info *ti = thread_info_fast(); | ||||
__cxa_eh_globals *globals = &ti->globals; | __cxa_eh_globals *globals = &ti->globals; | ||||
__cxa_exception *ex = globals->caughtExceptions; | __cxa_exception *ex = globals->caughtExceptions; | ||||
assert(0 != ex && "Ending catch when no exception is on the stack!"); | assert(0 != ex && "Ending catch when no exception is on the stack!"); | ||||
if (ti->foreign_exception_state != __cxa_thread_info::none) | if (ti->foreign_exception_state != __cxa_thread_info::none) | ||||
{ | { | ||||
globals->caughtExceptions = 0; | globals->caughtExceptions = 0; | ||||
if (ti->foreign_exception_state != __cxa_thread_info::rethrown) | if (ti->foreign_exception_state != __cxa_thread_info::rethrown) | ||||
{ | { | ||||
_Unwind_Exception *e = (_Unwind_Exception*)ti->globals.caughtExceptions; | _Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(ti->globals.caughtExceptions); | ||||
e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e); | e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e); | ||||
} | } | ||||
ti->foreign_exception_state = __cxa_thread_info::none; | ti->foreign_exception_state = __cxa_thread_info::none; | ||||
return; | return; | ||||
} | } | ||||
bool deleteException = true; | bool deleteException = true; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* ABI function, called when an exception specification is violated. | * ABI function, called when an exception specification is violated. | ||||
* | * | ||||
* This function does not return. | * This function does not return. | ||||
*/ | */ | ||||
extern "C" void __cxa_call_unexpected(void*exception) | extern "C" void __cxa_call_unexpected(void*exception) | ||||
{ | { | ||||
_Unwind_Exception *exceptionObject = (_Unwind_Exception*)exception; | _Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(exception); | ||||
if (exceptionObject->exception_class == exception_class) | if (exceptionObject->exception_class == exception_class) | ||||
{ | { | ||||
__cxa_exception *ex = exceptionFromPointer(exceptionObject); | __cxa_exception *ex = exceptionFromPointer(exceptionObject); | ||||
if (ex->unexpectedHandler) | if (ex->unexpectedHandler) | ||||
{ | { | ||||
ex->unexpectedHandler(); | ex->unexpectedHandler(); | ||||
// Should not be reached. | // Should not be reached. | ||||
abort(); | abort(); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | terminate_handler get_terminate() throw() | ||||
__cxa_thread_info *info = thread_info(); | __cxa_thread_info *info = thread_info(); | ||||
if (info->terminateHandler) | if (info->terminateHandler) | ||||
{ | { | ||||
return info->terminateHandler; | return info->terminateHandler; | ||||
} | } | ||||
return ATOMIC_LOAD(&terminateHandler); | return ATOMIC_LOAD(&terminateHandler); | ||||
} | } | ||||
} | } | ||||
#ifdef __arm__ | #if defined(__arm__) && !defined(__ARM_DWARF_EH__) | ||||
extern "C" _Unwind_Exception *__cxa_get_cleanup(void) | extern "C" _Unwind_Exception *__cxa_get_cleanup(void) | ||||
{ | { | ||||
__cxa_thread_info *info = thread_info_fast(); | __cxa_thread_info *info = thread_info_fast(); | ||||
_Unwind_Exception *exceptionObject = info->currentCleanup; | _Unwind_Exception *exceptionObject = info->currentCleanup; | ||||
if (isCXXException(exceptionObject->exception_class)) | if (isCXXException(exceptionObject->exception_class)) | ||||
{ | { | ||||
__cxa_exception *ex = exceptionFromPointer(exceptionObject); | __cxa_exception *ex = exceptionFromPointer(exceptionObject); | ||||
ex->cleanupCount--; | ex->cleanupCount--; | ||||
Show All 26 Lines |