Skip to content

Commit d02907e

Browse files
thisalihassanmarco-ippolito
authored andcommittedJun 17, 2024
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: #52404 Refs: #35033 PR-URL: #52545 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent cd1415c commit d02907e

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
@@ -421,7 +421,7 @@ typedef void (*sigaction_cb)(int signo, siginfo_t* info, void* ucontext);
421421
#endif
422422
#if NODE_USE_V8_WASM_TRAP_HANDLER
423423
#if defined(_WIN32)
424-
static LONG TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
424+
static LONG WINAPI TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
425425
if (v8::TryHandleWebAssemblyTrapWindows(exception)) {
426426
return EXCEPTION_CONTINUE_EXECUTION;
427427
}
@@ -627,13 +627,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
627627
RegisterSignalHandler(SIGTERM, SignalExit, true);
628628

629629
#if NODE_USE_V8_WASM_TRAP_HANDLER
630-
#if defined(_WIN32)
631-
{
632-
constexpr ULONG first = TRUE;
633-
per_process::old_vectored_exception_handler =
634-
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
635-
}
636-
#else
637630
// Tell V8 to disable emitting WebAssembly
638631
// memory bounds checks. This means that we have
639632
// to catch the SIGSEGV/SIGBUS in TrapWebAssemblyOrContinue
@@ -649,7 +642,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
649642
CHECK_EQ(sigaction(SIGBUS, &sa, nullptr), 0);
650643
#endif
651644
}
652-
#endif // defined(_WIN32)
653645
V8::EnableWebAssemblyTrapHandler(false);
654646
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
655647
}
@@ -678,6 +670,14 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
678670
}
679671
#endif // __POSIX__
680672
#ifdef _WIN32
673+
#ifdef NODE_USE_V8_WASM_TRAP_HANDLER
674+
{
675+
constexpr ULONG first = TRUE;
676+
per_process::old_vectored_exception_handler =
677+
AddVectoredExceptionHandler(first, TrapWebAssemblyOrContinue);
678+
}
679+
V8::EnableWebAssemblyTrapHandler(false);
680+
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
681681
if (!(flags & ProcessInitializationFlags::kNoStdioInitialization)) {
682682
for (int fd = 0; fd <= 2; ++fd) {
683683
auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));

0 commit comments

Comments
 (0)
Please sign in to comment.