@@ -362,10 +362,19 @@ static LONG TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) {
362362}
363363#else
364364static std::atomic<sigaction_cb> previous_sigsegv_action;
365+ // TODO(align behavior between macos and other in next major version)
366+ #if defined(__APPLE__)
367+ static std::atomic<sigaction_cb> previous_sigbus_action;
368+ #endif // __APPLE__
365369
366370void TrapWebAssemblyOrContinue (int signo, siginfo_t * info, void * ucontext) {
367371 if (!v8::TryHandleWebAssemblyTrapPosix (signo, info, ucontext)) {
372+ #if defined(__APPLE__)
373+ sigaction_cb prev = signo == SIGBUS ? previous_sigbus_action.load ()
374+ : previous_sigsegv_action.load ();
375+ #else
368376 sigaction_cb prev = previous_sigsegv_action.load ();
377+ #endif // __APPLE__
369378 if (prev != nullptr ) {
370379 prev (signo, info, ucontext);
371380 } else {
@@ -395,6 +404,15 @@ void RegisterSignalHandler(int signal,
395404 previous_sigsegv_action.store (handler);
396405 return ;
397406 }
407+ // TODO(align behavior between macos and other in next major version)
408+ #if defined(__APPLE__)
409+ if (signal == SIGBUS) {
410+ CHECK (previous_sigbus_action.is_lock_free ());
411+ CHECK (!reset_handler);
412+ previous_sigbus_action.store (handler);
413+ return ;
414+ }
415+ #endif // __APPLE__
398416#endif // NODE_USE_V8_WASM_TRAP_HANDLER
399417 struct sigaction sa;
400418 memset (&sa, 0 , sizeof (sa));
@@ -551,14 +569,18 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
551569#else
552570 // Tell V8 to disable emitting WebAssembly
553571 // memory bounds checks. This means that we have
554- // to catch the SIGSEGV in TrapWebAssemblyOrContinue
572+ // to catch the SIGSEGV/SIGBUS in TrapWebAssemblyOrContinue
555573 // and pass the signal context to V8.
556574 {
557575 struct sigaction sa;
558576 memset (&sa, 0 , sizeof (sa));
559577 sa.sa_sigaction = TrapWebAssemblyOrContinue;
560578 sa.sa_flags = SA_SIGINFO;
561579 CHECK_EQ (sigaction (SIGSEGV, &sa, nullptr ), 0 );
580+ // TODO(align behavior between macos and other in next major version)
581+ #if defined(__APPLE__)
582+ CHECK_EQ (sigaction (SIGBUS, &sa, nullptr ), 0 );
583+ #endif
562584 }
563585#endif // defined(_WIN32)
564586 V8::EnableWebAssemblyTrapHandler (false );
0 commit comments