aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxxabi/patches/02-commit-fd92733-3.1.27.patch
blob: 7610425424ab4de8d63ea33a200b92bed593634b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From fd92733b4753ad0efdb916a5aca3742b555c9de0 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc@chromium.org>
Date: Tue, 6 Dec 2022 17:01:34 -0800
Subject: [PATCH] Patches from emscripten 3.1.27

diff --git a/src/cxa_exception.cpp b/src/cxa_exception.cpp
--- a/src/cxa_exception.cpp
+++ b/src/cxa_exception.cpp
@@ -263,6 +263,13 @@ handler, _Unwind_RaiseException may return. In that case, __cxa_throw
 will call terminate, assuming that there was no handler for the
 exception.
 */
+
+#if defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
+extern "C" {
+void __throw_exception_with_stack_trace(_Unwind_Exception*);
+} // extern "C"
+#endif
+
 void
 #ifdef __USING_WASM_EXCEPTIONS__
 // In wasm, destructors return their argument
@@ -289,11 +296,27 @@ __cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FU
     __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
+    // 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);
diff --git a/src/cxa_personality.cpp b/src/cxa_personality.cpp
--- a/src/cxa_personality.cpp
+++ b/src/cxa_personality.cpp
@@ -977,6 +977,11 @@ __gxx_personality_v0
             exc->languageSpecificData = results.languageSpecificData;
             exc->catchTemp = reinterpret_cast<void*>(results.landingPad);
             exc->adjustedPtr = results.adjustedPtr;
+#ifdef __USING_WASM_EXCEPTIONS__
+            // Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the
+            // results here.
+            set_registers(unwind_exception, context, results);
+#endif
         }
         return _URC_HANDLER_FOUND;
     }
@@ -994,16 +999,6 @@ __gxx_personality_v0
       exception_header->catchTemp = 0;
 #endif
     }
-#ifdef __USING_WASM_EXCEPTIONS__
-    // Wasm uses only one phase in _UA_CLEANUP_PHASE, so we should set
-    // these here.
-    __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception+1) - 1;
-    exception_header->handlerSwitchValue = static_cast<int>(results.ttypeIndex);
-    exception_header->actionRecord = results.actionRecord;
-    exception_header->languageSpecificData = results.languageSpecificData;
-    exception_header->catchTemp = reinterpret_cast<void*>(results.landingPad);
-    exception_header->adjustedPtr = results.adjustedPtr;
-#endif
     return _URC_INSTALL_CONTEXT;
 }