summaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <[email protected]>2025-01-22 00:22:18 +0000
committerAlexander Smirnov <[email protected]>2025-01-22 00:22:18 +0000
commit47763d31b221c4f827cfb2d3dec8c0a23489fccc (patch)
treeead46596168eae5e9d38b6e8b770456acaf69ec9 /contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp
parentf64d8ea3633ca6e8062dd5cd795e72f107353854 (diff)
parentfbaf25eeb4ece3eafbc5f111ff230d1124b86cab (diff)
Merge branch 'rightlib' into merge-libs-250122-0020
Diffstat (limited to 'contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp')
-rw-r--r--contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp71
1 files changed, 39 insertions, 32 deletions
diff --git a/contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp b/contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp
index 19c333d9c0d..4a792e08510 100644
--- a/contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp
+++ b/contrib/libs/cxxsupp/libcxxabi/src/cxa_exception.cpp
@@ -206,6 +206,24 @@ void __cxa_free_exception(void *thrown_object) throw() {
__aligned_free_with_fallback((void *)raw_buffer);
}
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo,
+#ifdef __USING_WASM_EXCEPTIONS__
+// In Wasm, a destructor returns its argument
+ void *(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
+#else
+ void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
+#endif
+ __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
+ exception_header->referenceCount = 0;
+ exception_header->unexpectedHandler = std::get_unexpected();
+ exception_header->terminateHandler = std::get_terminate();
+ exception_header->exceptionType = tinfo;
+ exception_header->exceptionDestructor = dest;
+ setOurExceptionClass(&exception_header->unwindHeader);
+ exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
+
+ return exception_header;
+}
// This function shall allocate a __cxa_dependent_exception and
// return a pointer to it. (Really to the object, not past its' end).
@@ -254,7 +272,7 @@ will call terminate, assuming that there was no handler for the
exception.
*/
-#if defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
+#if defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
extern "C" {
void __throw_exception_with_stack_trace(_Unwind_Exception*);
} // extern "C"
@@ -262,51 +280,31 @@ void __throw_exception_with_stack_trace(_Unwind_Exception*);
void
#ifdef __USING_WASM_EXCEPTIONS__
-// In wasm, destructors return their argument
-__cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *))
+// In Wasm, a destructor returns its argument
+__cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
#else
-__cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FUNC *dest)(void *))
+__cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
#endif
-{
- __cxa_eh_globals *globals = __cxa_get_globals();
- __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
-
- exception_header->unexpectedHandler = std::get_unexpected();
- exception_header->terminateHandler = std::get_terminate();
- exception_header->exceptionType = tinfo;
- exception_header->exceptionDestructor = dest;
- setOurExceptionClass(&exception_header->unwindHeader);
- exception_header->referenceCount = 1; // This is a newly allocated exception, no need for thread safety.
- globals->uncaughtExceptions += 1; // Not atomically, since globals are thread-local
+ __cxa_eh_globals* globals = __cxa_get_globals();
+ globals->uncaughtExceptions += 1; // Not atomically, since globals are thread-local
- exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
+ __cxa_exception* exception_header = __cxa_init_primary_exception(thrown_object, tinfo, dest);
+ exception_header->referenceCount = 1; // This is a newly allocated exception, no need for thread safety.
#if __has_feature(address_sanitizer)
- // Inform the ASan runtime that now might be a good time to clean stuff up.
- __asan_handle_no_return();
+ // Inform the ASan runtime that now might be a good time to clean stuff up.
+ __asan_handle_no_return();
#endif
-#ifdef __EMSCRIPTEN__
#ifdef __USING_SJLJ_EXCEPTIONS__
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
-#elif __USING_WASM_EXCEPTIONS__
-#ifdef NDEBUG
- _Unwind_RaiseException(&exception_header->unwindHeader);
-#else
+#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
// In debug mode, call a JS library function to use WebAssembly.Exception JS
// API, which enables us to include stack traces
__throw_exception_with_stack_trace(&exception_header->unwindHeader);
-#endif
#else
_Unwind_RaiseException(&exception_header->unwindHeader);
#endif
-#else // !__EMSCRIPTEN__
-#ifdef __USING_SJLJ_EXCEPTIONS__
- _Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
-#else
- _Unwind_RaiseException(&exception_header->unwindHeader);
-#endif
-#endif
// This only happens when there is no handler, or some unexpected unwinding
// error happens.
failed_throw(exception_header);
@@ -653,6 +651,10 @@ void __cxa_rethrow() {
}
#ifdef __USING_SJLJ_EXCEPTIONS__
_Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
+#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
+ // In debug mode, call a JS library function to use WebAssembly.Exception JS
+ // API, which enables us to include stack traces
+ __throw_exception_with_stack_trace(&exception_header->unwindHeader);
#else
_Unwind_RaiseException(&exception_header->unwindHeader);
#endif
@@ -778,6 +780,11 @@ __cxa_rethrow_primary_exception(void* thrown_object)
dep_exception_header->unwindHeader.exception_cleanup = dependent_exception_cleanup;
#ifdef __USING_SJLJ_EXCEPTIONS__
_Unwind_SjLj_RaiseException(&dep_exception_header->unwindHeader);
+#elif defined(__EMSCRIPTEN__) && defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
+ // In debug mode, call a JS library function to use
+ // WebAssembly.Exception JS API, which enables us to include stack
+ // traces
+ __throw_exception_with_stack_trace(&exception_header->unwindHeader);
#else
_Unwind_RaiseException(&dep_exception_header->unwindHeader);
#endif
@@ -800,6 +807,6 @@ __cxa_uncaught_exceptions() throw()
return globals->uncaughtExceptions;
}
-} // extern "C"
+} // extern "C"
} // abi