App: release LoaderLock on unwind via Drop guard #3001

Closed
github-bot wants to merge 1 commit from github-bot/gh-3001 into main AGit
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 03:01 UTC · original
Dukestar69:fix/loader-lock-unwind → main · +38 −10 · 1 files · 1 commits · closed without merging

Problem

In apps/victory/src/run.rs, LoaderLock::hold decrements the re-entrancy counter, clears owner, and calls self.free.notify_one() only on the normal return path after f(). If f() panics/unwinds, the lock remains owned by the panicked thread indefinitely, causing any other thread calling LoaderLock::hold to deadlock in self.free.wait(...).

Fix

Move the release logic into a local RAII Guard (impl Drop) created immediately after acquiring self.owner, so both normal returns and unwinds (including re-entrant holds) decrement the count and notify waiters when it reaches zero.

Verification (Windows 11 x64)

  • cargo test -p victory --bin victory run::: 8 passed, 0 failed (including new loader_lock_releases_on_panic_and_reentrant_unwind, which times out/deadlocks on origin/main 63bcca4).
  • cargo clippy -p victory --all-targets -- -D warnings: clean.
  • rustfmt --edition 2024 --check apps/victory/src/run.rs: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 03:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/3001) `Dukestar69:fix/loader-lock-unwind` → `main` · +38 −10 · 1 files · 1 commits · closed without merging ## Problem In `apps/victory/src/run.rs`, `LoaderLock::hold` decrements the re-entrancy counter, clears `owner`, and calls `self.free.notify_one()` only on the normal return path after `f()`. If `f()` panics/unwinds, the lock remains owned by the panicked thread indefinitely, causing any other thread calling `LoaderLock::hold` to deadlock in `self.free.wait(...)`. ## Fix Move the release logic into a local RAII `Guard` (`impl Drop`) created immediately after acquiring `self.owner`, so both normal returns and unwinds (including re-entrant holds) decrement the count and notify waiters when it reaches zero. ## Verification (Windows 11 x64) - `cargo test -p victory --bin victory run::`: **8 passed, 0 failed** (including new `loader_lock_releases_on_panic_and_reentrant_unwind`, which times out/deadlocks on `origin/main` `63bcca4`). - `cargo clippy -p victory --all-targets -- -D warnings`: clean. - `rustfmt --edition 2024 --check apps/victory/src/run.rs`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:49 +00:00
github-bot closed this pull request 2026-11-26 06:55:42 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 04:40 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 8603102 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: loader_lock_releases_on_panic_and_reentrant_unwind.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (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-26 04:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3001#issuecomment-7182796374) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `8603102` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `loader_lock_releases_on_panic_and_reentrant_unwind`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (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

@⁠Marvisak on GitHub · 2026-11-26 05:34 UTC · original

Automated triage for the maintainers.

Proposed close. The change makes LoaderLock::hold in apps/victory/src/run.rs release the lock while unwinding. The deadlock it prevents cannot happen in this program. The only caller is LateDlls::load, which is reached only through the title-DLL loader closure. That closure runs from victory_hle::runtime::load_title_dll, called by find_module in victory-hle/src/modules/kernel.rs under the extern "system" exports LoadLibraryExA/ExW/A/W. A Rust panic cannot unwind out of an extern "system" function: the process aborts. So no other thread is left waiting on the lock. The new test only shows the unwinding case because it calls hold directly on a test thread.

It would be worth reopening if there is a caller that catches the unwind (for example a catch_unwind around the loader closure). This PR has no CI run.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3001#issuecomment-7183609730) <!-- victory-triage v1 head=860310276a79082a7c8ef887e082e9dd54d52796 verdict=proposed-close at=2026-11-26T05:34:16Z --> Automated triage for the maintainers. **Proposed close.** The change makes `LoaderLock::hold` in `apps/victory/src/run.rs` release the lock while unwinding. The deadlock it prevents cannot happen in this program. The only caller is `LateDlls::load`, which is reached only through the title-DLL loader closure. That closure runs from `victory_hle::runtime::load_title_dll`, called by `find_module` in `victory-hle/src/modules/kernel.rs` under the `extern "system"` exports `LoadLibraryExA/ExW/A/W`. A Rust panic cannot unwind out of an `extern "system"` function: the process aborts. So no other thread is left waiting on the lock. The new test only shows the unwinding case because it calls `hold` directly on a test thread. It would be worth reopening if there is a caller that catches the unwind (for example a `catch_unwind` around the loader closure). This PR has no CI run. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 06:45 UTC · original

Fair point from triage — since LateDlls::load is only reached through extern system LoadLibrary* exports, a Rust panic aborts the process rather than unwinding. Closing to keep the queue clean. AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 06:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/3001#issuecomment-7184757492) Fair point from triage — since LateDlls::load is only reached through extern system LoadLibrary* exports, a Rust panic aborts the process rather than unwinding. Closing to keep the queue clean. AI-assisted (Gemini 4 Neon).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3001
No description provided.