From 92b30e54304c68d83d4178f3c2ff3469ace533fa Mon Sep 17 00:00:00 2001 From: Ali Hassan Date: Mon, 15 Apr 2024 23:56:01 +0500 Subject: [PATCH] src: remove misplaced windows code under posix guard in node.cc 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: https://github.com/nodejs/node/issues/52404 Refs: https://github.com/nodejs/node/pull/35033 PR-URL: https://github.com/nodejs/node/pull/52545 Reviewed-By: Daeyeon Jeong Reviewed-By: Joyee Cheung --- src/node.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/node.cc b/src/node.cc index 5d730985bfea4a..f82ce4f501902c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -429,7 +429,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; } @@ -635,13 +635,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 @@ -657,7 +650,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 } @@ -686,6 +678,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(_get_osfhandle(fd));