Skip to content

Commit

Permalink
src: remove misplaced windows code under posix guard in node.cc
Browse files Browse the repository at this point in the history
The V8 WebAssembly trap handler setup for Windows was incorrectly
nested within a POSIX conditional compilation block in src/node.cc.
This caused the related functions to be effectively non-operational
on Windows. The changes involve removing the Windows-specific code from
the POSIX section and correctly placing it under the WIN32 checks.
This fix will ensure that the intended exception handling is active on
Windows builds, potentially improving WebAssembly performance.

Fixes: nodejs#52404
Refs: nodejs#35033
  • Loading branch information
thisalihassan committed Apr 15, 2024
1 parent 68f9e1f commit 83a1b8b
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/node.cc
Expand Up @@ -435,6 +435,11 @@ static LONG TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
}
return EXCEPTION_CONTINUE_SEARCH;
}
{
constexpr ULONG first = TRUE;
per_process::old_vectored_exception_handler =
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
}
#else
static std::atomic<sigaction_cb> previous_sigsegv_action;
// TODO(align behavior between macos and other in next major version)
Expand Down Expand Up @@ -635,17 +640,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
RegisterSignalHandler(SIGTERM, SignalExit, true);

#if NODE_USE_V8_WASM_TRAP_HANDLER
#if defined(_WIN32)
{
constexpr ULONG first = TRUE;
per_process::old_vectored_exception_handler =
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
}
#else
// Tell V8 to disable emitting WebAssembly
// memory bounds checks. This means that we have
// to catch the SIGSEGV/SIGBUS in TrapWebAssemblyOrContinue
// and pass the signal context to V8.
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
Expand All @@ -657,7 +651,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
CHECK_EQ(sigaction(SIGBUS, &sa, nullptr), 0);
#endif
}
#endif // defined(_WIN32)
V8::EnableWebAssemblyTrapHandler(false);
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
}
Expand Down

0 comments on commit 83a1b8b

Please sign in to comment.