| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifdef __EMSCRIPTEN__ |
|
|
| #include "cxxabi.h" |
| #include "cxa_exception.h" |
| #include "include/atomic_support.h" |
| #include "fallback_malloc.h" |
| #include "private_typeinfo.h" |
| #include "stdio.h" |
| #include "assert.h" |
|
|
| #ifdef __WASM_EXCEPTIONS__ |
| #error "This file should only be included when building with emscripten exceptions" |
| #endif |
|
|
| |
| #if EXCEPTIONS_DEBUG |
| #include "emscripten/console.h" |
| #define DEBUG emscripten_errf |
| #else |
| #define DEBUG(...) |
| #endif |
|
|
| |
| |
| |
| |
| |
| |
| extern "C" _LIBCXXABI_FUNC_VIS _Unwind_Reason_Code |
| __gxx_personality_v0(int version, |
| _Unwind_Action actions, |
| uint64_t exceptionClass, |
| _Unwind_Exception* unwind_exception, |
| _Unwind_Context* context) { |
| abort(); |
| } |
|
|
| namespace __cxxabiv1 { |
|
|
| |
| static |
| inline |
| __cxa_exception* |
| cxa_exception_from_thrown_object(void* thrown_object) |
| { |
| DEBUG("cxa_exception_from_thrown_object %p -> %p", |
| thrown_object, static_cast<__cxa_exception*>(thrown_object) - 1); |
| return static_cast<__cxa_exception*>(thrown_object) - 1; |
| } |
|
|
| |
| |
| static |
| inline |
| void* |
| thrown_object_from_cxa_exception(__cxa_exception* exception_header) |
| { |
| DEBUG("thrown_object_from_cxa_exception %p -> %p", |
| exception_header, static_cast<void*>(exception_header + 1)); |
| return static_cast<void*>(exception_header + 1); |
| } |
|
|
| |
| static inline |
| size_t aligned_allocation_size(size_t s, size_t a) { |
| return (s + a - 1) & ~(a - 1); |
| } |
|
|
| static inline |
| size_t cxa_exception_size_from_exception_thrown_size(size_t size) { |
| return aligned_allocation_size(size + sizeof (__cxa_exception), |
| alignof(__cxa_exception)); |
| } |
|
|
| extern "C" { |
|
|
| |
| |
| |
| |
| |
| void *__cxa_allocate_exception(size_t thrown_size) throw() { |
| size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size); |
|
|
| char *raw_buffer = |
| (char *)__aligned_malloc_with_fallback(actual_size); |
| if (NULL == raw_buffer) |
| std::terminate(); |
| __cxa_exception *exception_header = |
| static_cast<__cxa_exception *>((void *)(raw_buffer)); |
| ::memset(exception_header, 0, actual_size); |
| return thrown_object_from_cxa_exception(exception_header); |
| } |
|
|
|
|
| |
| void __cxa_free_exception(void *thrown_object) throw() { |
| |
| char *raw_buffer = |
| ((char *)cxa_exception_from_thrown_object(thrown_object)); |
| __aligned_free_with_fallback((void *)raw_buffer); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| void |
| __cxa_increment_exception_refcount(void *thrown_object) throw() { |
| if (thrown_object != NULL ) |
| { |
| __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object); |
| DEBUG("INC: %p refcnt=%zu", thrown_object, exception_header->referenceCount); |
| std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(1)); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| _LIBCXXABI_NO_CFI |
| void __cxa_decrement_exception_refcount(void *thrown_object) throw() { |
| if (thrown_object != NULL ) |
| { |
| __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object); |
| DEBUG("DEC: %p refcnt=%zu rethrown=%d", thrown_object, |
| exception_header->referenceCount, exception_header->rethrown); |
| assert(exception_header->referenceCount > 0); |
| if (std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(-1)) == 0 && !exception_header->rethrown) |
| { |
| DEBUG("DEL: %p (dtor=%p)", thrown_object, exception_header->exceptionDestructor); |
| if (NULL != exception_header->exceptionDestructor) |
| exception_header->exceptionDestructor(thrown_object); |
| __cxa_free_exception(thrown_object); |
| } |
| } |
| } |
|
|
| __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo, |
| void *(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() { |
| __cxa_exception* exception_header = cxa_exception_from_thrown_object(object); |
| exception_header->referenceCount = 0; |
| exception_header->exceptionType = tinfo; |
| exception_header->exceptionDestructor = dest; |
| return exception_header; |
| } |
|
|
| } |
|
|
| } |
|
|
| #endif |
|
|