69
69
70
70
#include " large_pages/node_large_page.h"
71
71
72
- #if defined(__APPLE__) || defined(__linux__)
72
+ #if defined(__APPLE__) || defined(__linux__) || defined(_WIN32)
73
73
#define NODE_USE_V8_WASM_TRAP_HANDLER 1
74
74
#else
75
75
#define NODE_USE_V8_WASM_TRAP_HANDLER 0
76
76
#endif
77
77
78
78
#if NODE_USE_V8_WASM_TRAP_HANDLER
79
+ #if defined(_WIN32)
80
+ #include " v8-wasm-trap-handler-win.h"
81
+ #else
79
82
#include < atomic>
80
83
#include " v8-wasm-trap-handler-posix.h"
84
+ #endif
81
85
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
82
86
83
87
// ========== global C headers ==========
@@ -149,6 +153,10 @@ bool v8_initialized = false;
149
153
// process-relative uptime base in nanoseconds, initialized in node::Start()
150
154
uint64_t node_start_time;
151
155
156
+ #if NODE_USE_V8_WASM_TRAP_HANDLER && defined(_WIN32)
157
+ PVOID old_vectored_exception_handler;
158
+ #endif
159
+
152
160
// node_v8_platform-inl.h
153
161
struct V8Platform v8_platform;
154
162
} // namespace per_process
@@ -506,6 +514,14 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
506
514
typedef void (*sigaction_cb)(int signo, siginfo_t * info, void * ucontext);
507
515
#endif
508
516
#if NODE_USE_V8_WASM_TRAP_HANDLER
517
+ #if defined(_WIN32)
518
+ static LONG TrapWebAssemblyOrContinue (EXCEPTION_POINTERS* exception ) {
519
+ if (v8::TryHandleWebAssemblyTrapWindows (exception )) {
520
+ return EXCEPTION_CONTINUE_EXECUTION;
521
+ }
522
+ return EXCEPTION_CONTINUE_SEARCH;
523
+ }
524
+ #else
509
525
static std::atomic<sigaction_cb> previous_sigsegv_action;
510
526
511
527
void TrapWebAssemblyOrContinue (int signo, siginfo_t * info, void * ucontext) {
@@ -525,6 +541,7 @@ void TrapWebAssemblyOrContinue(int signo, siginfo_t* info, void* ucontext) {
525
541
}
526
542
}
527
543
}
544
+ #endif // defined(_WIN32)
528
545
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
529
546
530
547
#ifdef __POSIX__
@@ -547,7 +564,6 @@ void RegisterSignalHandler(int signal,
547
564
sigfillset (&sa.sa_mask );
548
565
CHECK_EQ (sigaction (signal , &sa, nullptr ), 0 );
549
566
}
550
-
551
567
#endif // __POSIX__
552
568
553
569
#ifdef __POSIX__
@@ -630,6 +646,13 @@ inline void PlatformInit() {
630
646
RegisterSignalHandler (SIGTERM, SignalExit, true );
631
647
632
648
#if NODE_USE_V8_WASM_TRAP_HANDLER
649
+ #if defined(_WIN32)
650
+ {
651
+ constexpr ULONG first = TRUE ;
652
+ per_process::old_vectored_exception_handler =
653
+ AddVectoredExceptionHandler (first, TrapWebAssemblyOrContinue);
654
+ }
655
+ #else
633
656
// Tell V8 to disable emitting WebAssembly
634
657
// memory bounds checks. This means that we have
635
658
// to catch the SIGSEGV in TrapWebAssemblyOrContinue
@@ -640,6 +663,7 @@ inline void PlatformInit() {
640
663
sa.sa_sigaction = TrapWebAssemblyOrContinue;
641
664
CHECK_EQ (sigaction (SIGSEGV, &sa, nullptr ), 0 );
642
665
}
666
+ #endif // defined(_WIN32)
643
667
V8::EnableWebAssemblyTrapHandler (false );
644
668
#endif // NODE_USE_V8_WASM_TRAP_HANDLER
645
669
@@ -1050,6 +1074,10 @@ void TearDownOncePerProcess() {
1050
1074
per_process::v8_initialized = false ;
1051
1075
V8::Dispose ();
1052
1076
1077
+ #if NODE_USE_V8_WASM_TRAP_HANDLER && defined(_WIN32)
1078
+ RemoveVectoredExceptionHandler (per_process::old_vectored_exception_handler);
1079
+ #endif
1080
+
1053
1081
// uv_run cannot be called from the time before the beforeExit callback
1054
1082
// runs until the program exits unless the event loop has any referenced
1055
1083
// handles after beforeExit terminates. This prevents unrefed timers
0 commit comments