Commit e8ffd4d
authored
[wasm2c] Fix exception testing on macOS (#2716)
This commit addresses the assertion failures during exception testing
in `wasm2c` on macOS:
`Assertion failed: (!(ss.ss_flags & SS_ONSTACK) && "attempt to
deallocate altstack while in use")`
Exception handling in wasm2c uses `wasm_rt_try(target)` which mapped
to `sigsetjmp(buf, 1)`. However, on macOS (XNU), performing nested
`sigsetjmp(..., 1)` and `siglongjmp` across threads with an allocated
alternate signal stack can erroneously cause the kernel to preserve the
`SS_ONSTACK` flag in the thread state, even when the exception did not
originate from the signal handler.
Since WebAssembly exception handling relies strictly on
`setjmp`/`longjmp`
for control flow and does not need to restore signal masks (unlike stack
exhaustion traps, which do need the mask to unblock `SIGSEGV`), the fix
is to simply avoid saving the signal mask for exception boundaries.
We split `WASM_RT_SETJMP_SETBUF` into two variants:
- `WASM_RT_SETJMP_TRAP_SETBUF`: Uses `sigsetjmp(buf, 1)` for traps
(safely handles `SIGSEGV`).
- `WASM_RT_SETJMP_EXN_SETBUF`: Uses `sigsetjmp(buf, 0)` for Wasm
exceptions (bypasses `SS_ONSTACK` bug).
This also reverts commit 74cc83c
(which temporarily disabled `macos-latest` in CI), as the tests now
pass successfully.
Fixes #26541 parent 10dcc58 commit e8ffd4d
2 files changed
+20
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 33 | + | |
36 | 34 | | |
37 | 35 | | |
38 | 36 | | |
| |||
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
48 | | - | |
| 46 | + | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
575 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
576 | 587 | | |
577 | | - | |
| 588 | + | |
| 589 | + | |
578 | 590 | | |
579 | 591 | | |
580 | 592 | | |
581 | | - | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
582 | 596 | | |
583 | 597 | | |
584 | 598 | | |
| |||
604 | 618 | | |
605 | 619 | | |
606 | 620 | | |
607 | | - | |
| 621 | + | |
608 | 622 | | |
609 | 623 | | |
610 | 624 | | |
| |||
0 commit comments