@@ -362,10 +362,19 @@ static LONG TrapWebAssemblyOrContinue(EXCEPTION_POINTERS* exception) { |
362 | 362 | } |
363 | 363 | #else |
364 | 364 | static 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__ |
365 | 369 |
|
366 | 370 | void TrapWebAssemblyOrContinue(int signo, siginfo_t* info, void* ucontext) { |
367 | 371 | 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 |
368 | 376 | sigaction_cb prev = previous_sigsegv_action.load(); |
| 377 | +#endif // __APPLE__ |
369 | 378 | if (prev != nullptr) { |
370 | 379 | prev(signo, info, ucontext); |
371 | 380 | } else { |
@@ -395,6 +404,15 @@ void RegisterSignalHandler(int signal, |
395 | 404 | previous_sigsegv_action.store(handler); |
396 | 405 | return; |
397 | 406 | } |
| 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__ |
398 | 416 | #endif // NODE_USE_V8_WASM_TRAP_HANDLER |
399 | 417 | struct sigaction sa; |
400 | 418 | memset(&sa, 0, sizeof(sa)); |
@@ -551,14 +569,18 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) { |
551 | 569 | #else |
552 | 570 | // Tell V8 to disable emitting WebAssembly |
553 | 571 | // memory bounds checks. This means that we have |
554 | | - // to catch the SIGSEGV in TrapWebAssemblyOrContinue |
| 572 | + // to catch the SIGSEGV/SIGBUS in TrapWebAssemblyOrContinue |
555 | 573 | // and pass the signal context to V8. |
556 | 574 | { |
557 | 575 | struct sigaction sa; |
558 | 576 | memset(&sa, 0, sizeof(sa)); |
559 | 577 | sa.sa_sigaction = TrapWebAssemblyOrContinue; |
560 | 578 | sa.sa_flags = SA_SIGINFO; |
561 | 579 | 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 |
562 | 584 | } |
563 | 585 | #endif // defined(_WIN32) |
564 | 586 | V8::EnableWebAssemblyTrapHandler(false); |
|