Skip to content

Commit b244ed1

Browse files
thisalihassanChenyu Yang
authored and
Chenyu Yang
committed
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: nodejs#52404 Refs: nodejs#35033 PR-URL: nodejs#52545 Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent cd8c281 commit b244ed1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/node.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ typedef void (*sigaction_cb)(int signo, siginfo_t* info, void* ucontext);
429429
#endif
430430
#if NODE_USE_V8_WASM_TRAP_HANDLER
431431
#if defined(_WIN32)
432-
static LONG TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
432+
static LONG WINAPI TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
433433
if (v8::TryHandleWebAssemblyTrapWindows(exception)) {
434434
return EXCEPTION_CONTINUE_EXECUTION;
435435
}
@@ -635,13 +635,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
635635
RegisterSignalHandler(SIGTERM, SignalExit, true);
636636

637637
#if NODE_USE_V8_WASM_TRAP_HANDLER
638-
#if defined(_WIN32)
639-
{
640-
constexpr ULONG first = TRUE;
641-
per_process::old_vectored_exception_handler =
642-
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
643-
}
644-
#else
645638
// Tell V8 to disable emitting WebAssembly
646639
// memory bounds checks. This means that we have
647640
// to catch the SIGSEGV/SIGBUS in TrapWebAssemblyOrContinue
@@ -657,7 +650,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
657650
CHECK_EQ(sigaction(SIGBUS, &sa, nullptr), 0);
658651
#endif
659652
}
660-
#endif // defined(_WIN32)
661653
V8::EnableWebAssemblyTrapHandler(false);
662654
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
663655
}
@@ -686,6 +678,14 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
686678
}
687679
#endif // __POSIX__
688680
#ifdef _WIN32
681+
#ifdef NODE_USE_V8_WASM_TRAP_HANDLER
682+
{
683+
constexpr ULONG first = TRUE;
684+
per_process::old_vectored_exception_handler =
685+
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
686+
}
687+
V8::EnableWebAssemblyTrapHandler(false);
688+
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
689689
if (!(flags & ProcessInitializationFlags::kNoStdioInitialization)) {
690690
for (int fd = 0; fd <= 2; ++fd) {
691691
auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));

0 commit comments

Comments
 (0)