App: roll back re-entrant dependent DLLs on LateDlls attach failure #3017

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/3019 into main
fuzeofficlal commented 2026-11-26 03:30:57 +00:00 (Migrated from github.com)

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


Summary

  • Roll back re-entrantly loaded dependent title DLLs when an outer LateDlls::load fails during DllMain(DLL_PROCESS_ATTACH) in apps/victory/src/run.rs.
  • Previously, if A.dll's DllMain re-entrantly called LoadLibrary("B.dll") where B.dll statically or delay-imported A.dll, and A.dll's DllMain then returned FALSE, rollback detached and unloaded only the outer new batch (A.dll), leaving B.dll registered in LateDlls::mapped and runtime::IMAGES with IAT pointers into unmapped memory.
  • Add pure helper reentrant_dependents to compute the transitive closure of re-entrantly appended modules importing (static or delay-import, ASCII case-insensitive) any module in the failing batch, remove them under self.mapped, detach them in reverse load order before detaching new[..=i], and forget/unload them before unmapping new (while preserving independent re-entrant modules).
  • Add 4 unit tests in run::reentrant_rollback_tests covering direct dependents, transitive reverse-order rollback, preservation of independent re-entrant modules, and ASCII case-insensitive import matching.

Verification

  • rustfmt --edition 2024 --check apps/victory/src/run.rs: ok.
  • cargo test --locked -p victory: 18 unit tests + 4 integration tests passed.
  • cargo clippy --locked -p victory --all-targets -- -D warnings (default and --all-features): 0 warnings.
  • cargo xtask policy: 191 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6618887378 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3019). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:30:57Z. --- ## Summary - Roll back re-entrantly loaded dependent title DLLs when an outer `LateDlls::load` fails during `DllMain(DLL_PROCESS_ATTACH)` in `apps/victory/src/run.rs`. - Previously, if `A.dll`'s `DllMain` re-entrantly called `LoadLibrary("B.dll")` where `B.dll` statically or delay-imported `A.dll`, and `A.dll`'s `DllMain` then returned `FALSE`, rollback detached and unloaded only the outer `new` batch (`A.dll`), leaving `B.dll` registered in `LateDlls::mapped` and `runtime::IMAGES` with IAT pointers into unmapped memory. - Add pure helper `reentrant_dependents` to compute the transitive closure of re-entrantly appended modules importing (static or delay-import, ASCII case-insensitive) any module in the failing batch, remove them under `self.mapped`, detach them in reverse load order before detaching `new[..=i]`, and forget/unload them before unmapping `new` (while preserving independent re-entrant modules). - Add 4 unit tests in `run::reentrant_rollback_tests` covering direct dependents, transitive reverse-order rollback, preservation of independent re-entrant modules, and ASCII case-insensitive import matching. ## Verification - `rustfmt --edition 2024 --check apps/victory/src/run.rs`: ok. - `cargo test --locked -p victory`: 18 unit tests + 4 integration tests passed. - `cargo clippy --locked -p victory --all-targets -- -D warnings` (default and `--all-features`): 0 warnings. - `cargo xtask policy`: 191 files ok.
kotekompotek commented 2026-11-26 05:03:52 +00:00 (Migrated from github.com)

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

Review: APPROVED


LGTM — mirrors LoadLibrary's rollback: re-entrant modules that transitively import the failed batch detach in reverse load order before the batch itself. Descending-index removal keeps earlier indices valid; the generic accessor shape makes it testable.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068636404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3019#pullrequestreview-6068636404). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:40:48Z. **Review:** APPROVED --- LGTM — mirrors LoadLibrary's rollback: re-entrant modules that transitively import the failed batch detach in reverse load order before the batch itself. Descending-index removal keeps earlier indices valid; the generic accessor shape makes it testable.
futurepro62 commented 2026-11-26 05:04:05 +00:00 (Migrated from github.com)

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


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 92ce3d5 (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: 870 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: direct_reentrant_dependent_is_rolled_back, transitive_reentrant_dependents_rollback_in_reverse_load_order, independent_reentrant_modules_are_preserved, import_matching_ignores_ascii_case.
  • --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:7182467149 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3019#issuecomment-7182467149). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T04:17:37Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `92ce3d5` (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`: **870 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `direct_reentrant_dependent_is_rolled_back`, `transitive_reentrant_dependents_rollback_in_reverse_load_order`, `independent_reentrant_modules_are_preserved`, `import_matching_ignores_ascii_case`. - `--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.
upstream-sync closed this pull request 2026-11-26 07:01:11 +00:00
Marvisak commented 2026-11-26 07:01:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:16:42Z.


Automated triage for the maintainers.

This changes what LateDlls::load in apps/victory/src/run.rs does when a DllMain fails. A DLL that a DllMain in the failing batch loaded itself, and that imports a module of that batch (statically, through a delay import or transitively), is now detached and unloaded along with the batch. The new reentrant_dependents helper is tidy and its four tests cover its index logic. What is missing is evidence that this is the behaviour to emulate:

  • Loader semantics. The PR says this is what LoadLibrary does, but gives no reference. On Windows, a DLL loaded by its own LoadLibrary call inside DllMain holds its own reference, and its static import of the failing module adds a reference to that one too. Whether the Windows loader then tears it down, leaves it loaded or keeps the outer module mapped needs a citation or a small Windows test that shows the outcome. As written, the change could replace one wrong state with another.
  • Need. No title or test title is named that does this (a DllMain that fails after loading a DLL that imports it back). A concrete case, or a run log showing the dangling module, would show the change is worth its complexity.
  • Test coverage. The tests run only the pure index helper. Nothing checks the detach and unload order in load itself: dependents first, then new[..=i] in reverse, with forget_image before unload.

With a reference for the Windows behaviour, and ideally a case that hits it, this could be re-triaged.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184270268 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3019#issuecomment-7184270268). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:16:42Z. --- <!-- victory-triage v1 head=92ce3d59b4fb405ed55fb3787b036e771e8ad26b verdict=needs-work at=2026-11-26T06:16:32Z --> Automated triage for the maintainers. This changes what `LateDlls::load` in `apps/victory/src/run.rs` does when a `DllMain` fails. A DLL that a `DllMain` in the failing batch loaded itself, and that imports a module of that batch (statically, through a delay import or transitively), is now detached and unloaded along with the batch. The new `reentrant_dependents` helper is tidy and its four tests cover its index logic. What is missing is evidence that this is the behaviour to emulate: - **Loader semantics.** The PR says this is what `LoadLibrary` does, but gives no reference. On Windows, a DLL loaded by its own `LoadLibrary` call inside `DllMain` holds its own reference, and its static import of the failing module adds a reference to that one too. Whether the Windows loader then tears it down, leaves it loaded or keeps the outer module mapped needs a citation or a small Windows test that shows the outcome. As written, the change could replace one wrong state with another. - **Need.** No title or test title is named that does this (a `DllMain` that fails after loading a DLL that imports it back). A concrete case, or a run log showing the dangling module, would show the change is worth its complexity. - **Test coverage.** The tests run only the pure index helper. Nothing checks the detach and unload order in `load` itself: dependents first, then `new[..=i]` in reverse, with `forget_image` before `unload`. With a reference for the Windows behaviour, and ideally a case that hits it, this could be re-triaged. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 07:01:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T06:27:05Z.


Agreed — without a concrete title hitting re-entrant dependent DLL failure during DllMain or a verified test of native Windows LoadLibrary refcount semantics for this case, the added rollback complexity is not justified. Closing.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184441486 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3019#issuecomment-7184441486). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T06:27:05Z. --- Agreed — without a concrete title hitting re-entrant dependent DLL failure during `DllMain` or a verified test of native Windows `LoadLibrary` refcount semantics for this case, the added rollback complexity is not justified. Closing.

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!3017
No description provided.