| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <stdbool.h> |
|
|
| #include "config.h" |
|
|
| #ifdef __WASM_EXCEPTIONS__ |
|
|
| #include "unwind.h" |
| #include <threads.h> |
|
|
| _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action actions, |
| uint64_t exceptionClass, |
| _Unwind_Exception *unwind_exception, |
| _Unwind_Context *context); |
|
|
| struct _Unwind_LandingPadContext { |
| |
| uintptr_t lpad_index; |
| uintptr_t lsda; |
|
|
| |
| uintptr_t selector; |
| }; |
|
|
| |
| |
| thread_local struct _Unwind_LandingPadContext __wasm_lpad_context; |
|
|
| |
| |
| |
| |
| |
| |
| |
| _Unwind_Reason_Code _Unwind_CallPersonality(void *exception_ptr) { |
| struct _Unwind_Exception *exception_object = |
| (struct _Unwind_Exception *)exception_ptr; |
| _LIBUNWIND_TRACE_API("_Unwind_CallPersonality(exception_object=%p)", |
| (void *)exception_object); |
|
|
| |
| __wasm_lpad_context.selector = 0; |
|
|
| |
| |
| return __gxx_personality_wasm0( |
| 1, _UA_SEARCH_PHASE, exception_object->exception_class, exception_object, |
| (struct _Unwind_Context *)&__wasm_lpad_context); |
| } |
|
|
| |
| _LIBUNWIND_EXPORT _Unwind_Reason_Code |
| _Unwind_RaiseException(_Unwind_Exception *exception_object) { |
| _LIBUNWIND_TRACE_API("_Unwind_RaiseException(exception_object=%p)", |
| (void *)exception_object); |
| |
| __builtin_wasm_throw(0, exception_object); |
| } |
|
|
| |
| _LIBUNWIND_EXPORT void |
| _Unwind_DeleteException(_Unwind_Exception *exception_object) { |
| _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)", |
| (void *)(exception_object)); |
| if (exception_object->exception_cleanup != NULL) |
| (*exception_object->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT, |
| exception_object); |
| } |
|
|
| |
| _LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index, |
| uintptr_t value) { |
| _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, index=%d, value=%lu)", |
| (void *)context, index, value); |
| |
| |
| if (index == 1) |
| ((struct _Unwind_LandingPadContext *)context)->selector = value; |
| } |
|
|
| |
| _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) { |
| |
| |
| uintptr_t result = |
| ((struct _Unwind_LandingPadContext *)context)->lpad_index + 2; |
| _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => %lu", (void *)context, |
| result); |
| return result; |
| } |
|
|
| |
| _LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {} |
|
|
| |
| _LIBUNWIND_EXPORT uintptr_t |
| _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) { |
| uintptr_t result = ((struct _Unwind_LandingPadContext *)context)->lsda; |
| _LIBUNWIND_TRACE_API("_Unwind_GetLanguageSpecificData(context=%p) => 0x%lx", |
| (void *)context, result); |
| return result; |
| } |
|
|
| |
| _LIBUNWIND_EXPORT uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *) { |
| return 0; |
| } |
|
|
| #endif |
|
|