02-commit-fd92733-3.1.27.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From fd92733b4753ad0efdb916a5aca3742b555c9de0 Mon Sep 17 00:00:00 2001
  2. From: Sam Clegg <sbc@chromium.org>
  3. Date: Tue, 6 Dec 2022 17:01:34 -0800
  4. Subject: [PATCH] Patches from emscripten 3.1.27
  5. diff --git a/src/cxa_exception.cpp b/src/cxa_exception.cpp
  6. --- a/src/cxa_exception.cpp
  7. +++ b/src/cxa_exception.cpp
  8. @@ -263,6 +263,13 @@ handler, _Unwind_RaiseException may return. In that case, __cxa_throw
  9. will call terminate, assuming that there was no handler for the
  10. exception.
  11. */
  12. +
  13. +#if defined(__USING_WASM_EXCEPTIONS__) && !defined(NDEBUG)
  14. +extern "C" {
  15. +void __throw_exception_with_stack_trace(_Unwind_Exception*);
  16. +} // extern "C"
  17. +#endif
  18. +
  19. void
  20. #ifdef __USING_WASM_EXCEPTIONS__
  21. // In wasm, destructors return their argument
  22. @@ -289,11 +296,27 @@ __cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FU
  23. __asan_handle_no_return();
  24. #endif
  25. +#ifdef __EMSCRIPTEN__
  26. #ifdef __USING_SJLJ_EXCEPTIONS__
  27. _Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
  28. +#elif __USING_WASM_EXCEPTIONS__
  29. +#ifdef NDEBUG
  30. + _Unwind_RaiseException(&exception_header->unwindHeader);
  31. +#else
  32. + // In debug mode, call a JS library function to use WebAssembly.Exception JS
  33. + // API, which enables us to include stack traces
  34. + __throw_exception_with_stack_trace(&exception_header->unwindHeader);
  35. +#endif
  36. #else
  37. _Unwind_RaiseException(&exception_header->unwindHeader);
  38. #endif
  39. +#else // !__EMSCRIPTEN__
  40. +#ifdef __USING_SJLJ_EXCEPTIONS__
  41. + _Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
  42. +#else
  43. + _Unwind_RaiseException(&exception_header->unwindHeader);
  44. +#endif
  45. +#endif
  46. // This only happens when there is no handler, or some unexpected unwinding
  47. // error happens.
  48. failed_throw(exception_header);
  49. diff --git a/src/cxa_personality.cpp b/src/cxa_personality.cpp
  50. --- a/src/cxa_personality.cpp
  51. +++ b/src/cxa_personality.cpp
  52. @@ -977,6 +977,11 @@ __gxx_personality_v0
  53. exc->languageSpecificData = results.languageSpecificData;
  54. exc->catchTemp = reinterpret_cast<void*>(results.landingPad);
  55. exc->adjustedPtr = results.adjustedPtr;
  56. +#ifdef __USING_WASM_EXCEPTIONS__
  57. + // Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the
  58. + // results here.
  59. + set_registers(unwind_exception, context, results);
  60. +#endif
  61. }
  62. return _URC_HANDLER_FOUND;
  63. }
  64. @@ -994,16 +999,6 @@ __gxx_personality_v0
  65. exception_header->catchTemp = 0;
  66. #endif
  67. }
  68. -#ifdef __USING_WASM_EXCEPTIONS__
  69. - // Wasm uses only one phase in _UA_CLEANUP_PHASE, so we should set
  70. - // these here.
  71. - __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception+1) - 1;
  72. - exception_header->handlerSwitchValue = static_cast<int>(results.ttypeIndex);
  73. - exception_header->actionRecord = results.actionRecord;
  74. - exception_header->languageSpecificData = results.languageSpecificData;
  75. - exception_header->catchTemp = reinterpret_cast<void*>(results.landingPad);
  76. - exception_header->adjustedPtr = results.adjustedPtr;
  77. -#endif
  78. return _URC_INSTALL_CONTEXT;
  79. }