loader(seh), hle(xasync): dispatch bad/guard-page RSP faults on a TEB emergency stack and give workers 8 MiB stacks #566

Open
github-bot wants to merge 1 commit from github-bot/gh-562 into main AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 05:00 UTC · original
Sheffy007:fix/seh-emergency-stack-xasync-stacks → main · +185 −23 · 5 files · 1 commits · open

Closes #565
Refs #395, #525

Summary

  • TEB emergency exception-dispatch stack (crates/victory-loader/src/native/teb.rs, seh/signal.rs, seh/context.rs):
    • Allocates a page-aligned 256 KiB emergency stack ([OFF_EMERGENCY_LIMIT, OFF_EMERGENCY_BASE)) per ThreadTeb and frees it on Drop.
    • Updates on_signal (choose_dispatch_stack) so when an interrupted title fault has < 32 KiB of headroom above OFF_STACK_LIMIT (e.g. hitting the stack guard page) or an out-of-bounds/corrupted RSP, Context, ExceptionRecord, and entry_rsp are placed at the top of the TEB's emergency stack while preserving the faulting RSP inside Context.
    • Classifies SIGSEGV / SIGBUS faults in the guard region immediately below OFF_STACK_LIMIT as EXCEPTION_STACK_OVERFLOW (0xC00000FD) instead of dying silently with a nested SIGSEGV (exit code 139) before dispatch or unhandled_exception can log.
  • 8 MiB worker stacks (crates/victory-hle/src/modules/xasync.rs, crates/victory-gpu/src/pipeline/make.rs):
    • Gives XTaskQueue (xtask-serial, xtask-pool, xtask-delay), XAsync (xasync-work), and victory-pipelines-* background threads 8 MiB stacks (8 << 20, matching host_posix::MIN_STACK) instead of Rust's 2 MiB default.

Verification

  • cargo test -p victory-loader --target x86_64-apple-darwin --locked -- --test-threads=1 (33 passed, including new Rosetta test guard_page_and_invalid_rsp_faults_dispatch_on_the_teb_emergency_stack)
  • cargo test -p victory-hle --lib --target x86_64-apple-darwin xasync --locked -- --test-threads=1 (13 passed)
  • cargo test -p victory-gpu --lib pipeline:: --locked -- --test-threads=1 (11 passed)
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-28 05:00 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/562) `Sheffy007:fix/seh-emergency-stack-xasync-stacks` → `main` · +185 −23 · 5 files · 1 commits · open Closes #565 Refs #395, #525 ### Summary - **TEB emergency exception-dispatch stack (`crates/victory-loader/src/native/teb.rs`, `seh/signal.rs`, `seh/context.rs`):** - Allocates a page-aligned 256 KiB emergency stack (`[OFF_EMERGENCY_LIMIT, OFF_EMERGENCY_BASE)`) per `ThreadTeb` and frees it on `Drop`. - Updates `on_signal` (`choose_dispatch_stack`) so when an interrupted title fault has `< 32 KiB` of headroom above `OFF_STACK_LIMIT` (e.g. hitting the stack guard page) or an out-of-bounds/corrupted `RSP`, `Context`, `ExceptionRecord`, and `entry_rsp` are placed at the top of the TEB's emergency stack while preserving the faulting `RSP` inside `Context`. - Classifies `SIGSEGV` / `SIGBUS` faults in the guard region immediately below `OFF_STACK_LIMIT` as `EXCEPTION_STACK_OVERFLOW` (`0xC00000FD`) instead of dying silently with a nested `SIGSEGV` (`exit code 139`) before `dispatch` or `unhandled_exception` can log. - **8 MiB worker stacks (`crates/victory-hle/src/modules/xasync.rs`, `crates/victory-gpu/src/pipeline/make.rs`):** - Gives `XTaskQueue` (`xtask-serial`, `xtask-pool`, `xtask-delay`), `XAsync` (`xasync-work`), and `victory-pipelines-*` background threads 8 MiB stacks (`8 << 20`, matching `host_posix::MIN_STACK`) instead of Rust's 2 MiB default. ### Verification - `cargo test -p victory-loader --target x86_64-apple-darwin --locked -- --test-threads=1` (33 passed, including new Rosetta test `guard_page_and_invalid_rsp_faults_dispatch_on_the_teb_emergency_stack`) - `cargo test -p victory-hle --lib --target x86_64-apple-darwin xasync --locked -- --test-threads=1` (13 passed) - `cargo test -p victory-gpu --lib pipeline:: --locked -- --test-threads=1` (11 passed) - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` cc @⁠Olima34
- Give every ThreadTeb a page-aligned 256 KiB emergency exception-dispatch
  stack ([OFF_EMERGENCY_LIMIT, OFF_EMERGENCY_BASE)) and route SIGSEGV/SIGBUS
  faults whose RSP lacks 32 KiB of headroom above OFF_STACK_LIMIT (or lies
  outside [OFF_STACK_LIMIT, OFF_STACK_BASE)) onto it while preserving the
  faulting RSP in Context.
- Classify SIGSEGV/SIGBUS faults in the guard region below OFF_STACK_LIMIT
  as EXCEPTION_STACK_OVERFLOW (0xC00000FD) so vectored and unhandled
  exception filters log and diagnose stack exhaustion instead of dying
  silently with SIGSEGV (exit code 139).
- Give XTaskQueue/XAsync workers and victory-pipelines-* background threads
  explicit 8 MiB stacks matching host_posix::MIN_STACK.

Closes #561
Refs #392, #521
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:06:10 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 17:18 UTC · original

Verified on the head 3410c883 (M3 Pro, macOS 27.3, Rosetta): cargo test --target x86_64-apple-darwin -p victory-loader --lib -- --test-threads=1 → 30/30 pass, including the new guard_page_and_invalid_rsp_faults_dispatch_on_the_teb_emergency_stack; windows clippy -D warnings clean. The change itself reads well (emergency dispatch stack for guard-page/corrupt-RSP faults, stack-overflow classification, 8 MiB workers).

One local concern, same class as #552: in the default parallel run the test binary itself dies with SIGSEGV (twice in a row: rc=101 after 23 tests), while upstream/main passes the same command twice (rc=0). The new signal test likely races the other seh::signal tests' handlers under Rosetta. Could it be serialized (or take a lock) the way #583 does for the Metal GPU tests? Single-threaded it's fine.

**@⁠AnastasisKon** on GitHub · 2026-11-28 17:18 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/562#issuecomment-7242912952) Verified on the head 3410c883 (M3 Pro, macOS 27.3, Rosetta): `cargo test --target x86_64-apple-darwin -p victory-loader --lib -- --test-threads=1` → 30/30 pass, including the new `guard_page_and_invalid_rsp_faults_dispatch_on_the_teb_emergency_stack`; windows clippy `-D warnings` clean. The change itself reads well (emergency dispatch stack for guard-page/corrupt-RSP faults, stack-overflow classification, 8 MiB workers). One local concern, same class as #552: in the default parallel run the test binary itself dies with SIGSEGV (twice in a row: rc=101 after 23 tests), while `upstream/main` passes the same command twice (rc=0). The new signal test likely races the other `seh::signal` tests' handlers under Rosetta. Could it be serialized (or take a lock) the way #583 does for the Metal GPU tests? Single-threaded it's fine.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/566/head:github-bot/gh-562'
git switch 'github-bot/gh-562'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-562'
git switch 'github-bot/gh-562'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-562'
git switch 'github-bot/gh-562'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-562'
git switch 'main'
git merge --squash 'github-bot/gh-562'
git switch 'main'
git merge --ff-only 'github-bot/gh-562'
git switch 'main'
git merge 'github-bot/gh-562'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.