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 check.
This fix will ensure that the intended exception handling is active
on Windows builds.

Fixes: #52404
Refs: #35033
PR-URL: #52545
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
thisalihassan authored and marco-ippolito committed May 23, 2024
1 parent e6d9fbe commit 07c45ba
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ typedef void (*sigaction_cb)(int signo, siginfo_t* info, void* ucontext);
#endif
#if NODE_USE_V8_WASM_TRAP_HANDLER
#if defined(_WIN32)
static LONG TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
static LONG WINAPI TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
if (v8::TryHandleWebAssemblyTrapWindows(exception)) {
return EXCEPTION_CONTINUE_EXECUTION;
}
Expand Down Expand Up @@ -627,13 +627,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
Expand All @@ -649,7 +642,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 Expand Up @@ -678,6 +670,14 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
}
#endif // __POSIX__
#ifdef _WIN32
#ifdef NODE_USE_V8_WASM_TRAP_HANDLER
{
constexpr ULONG first = TRUE;
per_process::old_vectored_exception_handler =
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
}
V8::EnableWebAssemblyTrapHandler(false);
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
if (!(flags & ProcessInitializationFlags::kNoStdioInitialization)) {
for (int fd = 0; fd <= 2; ++fd) {
auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
Expand Down

0 comments on commit 07c45ba

Please sign in to comment.