App: release LoaderLock on unwind via Drop guard #2999

Closed
Dukestar69 wants to merge 1 commit from upstream-pr/3001 into main
Dukestar69 commented 2026-11-26 03:01:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:01:28Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6618553809 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3001). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:01:28Z. --- ## 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).
kotekompotek commented 2026-11-26 03:05:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T03:03:12Z.

Review: APPROVED


LGTM — moving the release into a Drop guard covers panic unwinds; the nested-hold test discriminates (inner guard 2→1, outer 1→0 + notify), and the second thread acquiring within the timeout proves the lock isn't leaked.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067986383 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3001#pullrequestreview-6067986383). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T03:03:12Z. **Review:** APPROVED --- LGTM — moving the release into a Drop guard covers panic unwinds; the nested-hold test discriminates (inner guard 2→1, outer 1→0 + notify), and the second thread acquiring within the timeout proves the lock isn't leaked.
fuzeofficlal commented 2026-11-26 04:05:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:22:47Z.

Review: APPROVED


Code review on 86031027 (static source inspection):

  • apps/victory/src/run.rs:436-474 wraps LoaderLock release in an RAII Guard whose Drop impl decrements the recursion depth and clears the owner + notifies free when depth reaches zero.
  • Preserves same-thread re-entry across LateDlls::load while preventing permanent deadlock if a closure panics/unwinds, and loader_lock_releases_on_panic_and_reentrant_unwind directly tests nested re-entrant unwind recovery.
<!-- greyfinch-sync:Marvisak/VIctory:review:6068130928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3001#pullrequestreview-6068130928). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:22:47Z. **Review:** APPROVED --- Code review on `86031027` (static source inspection): - `apps/victory/src/run.rs:436-474` wraps `LoaderLock` release in an RAII `Guard` whose `Drop` impl decrements the recursion depth and clears the owner + notifies `free` when depth reaches zero. - Preserves same-thread re-entry across `LateDlls::load` while preventing permanent deadlock if a closure panics/unwinds, and `loader_lock_releases_on_panic_and_reentrant_unwind` directly tests nested re-entrant unwind recovery.
futurepro62 commented 2026-11-26 05:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T04:40:03Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7182796374 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3001#issuecomment-7182796374). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T04:40:03Z. --- 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.
Marvisak commented 2026-11-26 06:03:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:34:27Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183609730 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3001#issuecomment-7183609730). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:34:27Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-26 07:01:02 +00:00
Dukestar69 commented 2026-11-26 07:01:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:45:49Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184757492 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3001#issuecomment-7184757492). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:45:49Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2999
No description provided.