xcl run: restore orig trampoline slot when RawDetour::enable fails #1568

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

@⁠b3IKK on GitHub · 2026-11-24 17:45 UTC · original
b3IKK:hooks/rollback-orig-on-enable-fail → main · +42 −3 · 1 files · 1 commits · open

In hooks::hook, orig.store(d.trampoline() as *const () as usize, Ordering::Release) ran before d.enable()?. If d.enable() failed, RawDetour dropped and freed the trampoline memory while orig retained the dangling trampoline address. CString::new(func).unwrap() also panicked on interior NUL bytes.

This extracts enable_detour() to restore the previous orig value on error, and returns Err instead of panicking on invalid function names.

What is in it

  • crates/xcl/src/hooks.rs: add enable_detour() rollback on failure, replace CString::new(func).unwrap() with map_err, and add unit tests enable_detour_restores_orig_on_failure_and_keeps_it_on_success and hook_rejects_interior_nul_without_panicking.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 778 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware; 1 no heap windows — heap_window_out_of_memory_falls_back_to_the_switch_form)
  • cargo test -p xcl --lib hooks::tests: 12 passed, 0 failed (includes the 2 new hooks::tests tests)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: e33c72134bc24edfb8f615594fa4a3191f347088
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1641 (PresentX 1641)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited hooks.rs, wrote the fix and unit tests, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 17:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/1568) `b3IKK:hooks/rollback-orig-on-enable-fail` → `main` · +42 −3 · 1 files · 1 commits · open In `hooks::hook`, `orig.store(d.trampoline() as *const () as usize, Ordering::Release)` ran before `d.enable()?`. If `d.enable()` failed, `RawDetour` dropped and freed the trampoline memory while `orig` retained the dangling trampoline address. `CString::new(func).unwrap()` also panicked on interior NUL bytes. This extracts `enable_detour()` to restore the previous `orig` value on error, and returns `Err` instead of panicking on invalid function names. **What is in it** - `crates/xcl/src/hooks.rs`: add `enable_detour()` rollback on failure, replace `CString::new(func).unwrap()` with `map_err`, and add unit tests `enable_detour_restores_orig_on_failure_and_keeps_it_on_success` and `hook_rejects_interior_nul_without_panicking`. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 778 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`; 1 `no heap windows` — `heap_window_out_of_memory_falls_back_to_the_switch_form`) - `cargo test -p xcl --lib hooks::tests`: 12 passed, 0 failed (includes the 2 new `hooks::tests` tests) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: e33c72134bc24edfb8f615594fa4a3191f347088 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1641 (PresentX 1641) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14592 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `hooks.rs`, wrote the fix and unit tests, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
In hooks::hook, `orig.store(d.trampoline(), ...)` ran before
`d.enable()?`. If `d.enable()` returned Err, `RawDetour` dropped and
freed the trampoline while `orig` retained the dangling trampoline
address. `CString::new(func).unwrap()` also panicked on interior NULs.

Extract enable_detour() to restore the previous `orig` value on error,
and return Err instead of panicking on invalid function names.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:44 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 18:53 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head e33c721 (on its base 9e3831e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 777 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: enable_detour_restores_orig_on_failure_and_keeps_it_on_success, hook_rejects_interior_nul_without_panicking.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 778 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as #1651.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 18:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1568#issuecomment-7141301179) Full-suite run, since this PR has no test report yet. Tested exact head `e33c721` (on its base `9e3831e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form`: **777 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `enable_detour_restores_orig_on_failure_and_keeps_it_on_success`, `hook_rejects_interior_nul_without_panicking`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **778 passed, 0 failed, 41 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `heap_window_out_of_memory_falls_back_to_the_switch_form` was skipped with `--skip`. It fails on main `9e3831e` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (`XCL_HEAP_WINDOWS` unset). Reported as #1651. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 19:41 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 19:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/1568#issuecomment-7142452590) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. Thanks!
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 16:08 UTC · original

NVIDIA test report for e33c721: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its base 9e3831e.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4: 720 passed, 0 failed, 21 ignored; 2 SKIPPED (no wave64: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), neither in a file this PR changes.
  • hooks::tests::enable_detour_restores_orig_on_failure_and_keeps_it_on_success and hook_rejects_interior_nul_without_panicking, each with --exact --test-threads=1 --nocapture, 3 runs: 3/3 passed each, 0 SKIPPED.
    Lib tests only; no title run.
    AI-assisted (Claude Code, Claude Opus 5.5).
**@⁠upipibi** on GitHub · 2026-11-26 16:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1568#issuecomment-7197231451) NVIDIA test report for `e33c721`: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its base `9e3831e`. - `cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4`: 720 passed, 0 failed, 21 ignored; 2 SKIPPED (`no wave64`: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), neither in a file this PR changes. - `hooks::tests::enable_detour_restores_orig_on_failure_and_keeps_it_on_success` and `hook_rejects_interior_nul_without_panicking`, each with `--exact --test-threads=1 --nocapture`, 3 runs: 3/3 passed each, 0 SKIPPED. Lib tests only; no title run. AI-assisted (Claude Code, Claude Opus 5.5).
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/1568/head:github-bot/gh-1568'
git switch 'github-bot/gh-1568'

Merge

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