Run, HLE: keep late-loaded title DLLs private until DllMain succeeds and unload on bind failure #3308
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3308
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3308"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@fuzeofficlal on GitHub · 2026-11-26 16:55 UTC · original
fuzeofficlal:fix/late-dll-publish-and-bind-rollback→main· +654 −30 · 2 files · 1 commits · openSummary
Fixes two lifecycle and concurrency bugs in late title DLL loading (
LateDlls::loadinapps/victory/src/run.rsandIMAGE_PATHSincrates/victory-hle/src/runtime.rs):Prevent cross-thread observation and use-after-free of uninitialized/rolling-back DLLs:
Previously,
LateDlls::loadregistered every newly mapped DLL globally inIMAGE_PATHSviaset_image_pathbefore runningDllMain(DLL_PROCESS_ATTACH). BecauseGetModuleHandleA/WandGetModuleFileNameA/WqueryIMAGE_PATHSwithout acquiringLoaderLock, another thread running the standard fast-path (GetModuleHandlebeforeLoadLibrary) could observe anHMODULEwhileDllMainwas still executing on the loading thread—either invoking exports before initialization finished, or holding a dangling module handle whenDllMainreturnedFALSEandLateDlls::loaddetached and unmapped the batch viadll.unload().victory_hle::runtimenow supports thread-staged image paths (stage_image_path/publish_images). Staged images remain visible to the loading thread (soDllMain,GetModuleFileName,GetModuleHandle,FreeLibrary, and re-entrantLoadLibrarycontinue to work during both attach and rollback detach), stay hidden from all other threads until every DLL in the batch finishesattach(), and are published atomically as a batch beforeLoaderLockis released.Roll back mapped DLLs on import-binding failure:
Previously, if
bind_importsfailed on a later DLL in a newly mapped batch, early?exit leaked every mappedLoadedImagein host virtual memory andvictory_loader::threads::IMAGESwhile leaving earlier bound DLLs permanently registered inIMAGE_PATHSwithout ever running theirDllMainor adding them toLateDlls::mapped.LateDlls::loadnow completes import binding for the entire batch before staging paths or updatingmapped, and unloads every newly mapped image in reverse order if binding fails.Verification
All tests are clean-room synthetic tests using copies of the host's
System32\version.dllwith unique trailing overlay tags (no game data) and deterministicstd::sync::Barriersynchronization (no sleeps):63bcca43:cargo test -p victory --locked late_dll_failed 4/4 deterministically in 0.04s (cross-thread visibility during attach and leakedIMAGE_PATHSentry after bind failure).rustfmt --check --edition 2024: 0 diffs inapps/victory/src/run.rsand 0 diffs on touched hunks incrates/victory-hle/src/runtime.rs.victory(late_dll_, 4/4) andvictory-hle(runtime::tests::staged_images, 1/1) passed 20/20 consecutive runs.cargo test -p victory --locked(22/22),cargo test -p victory --all-features --locked(22/22),cargo test -p victory-hle --locked(155/155),cargo test -p victory-hle --all-features --locked(155/155).cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features: clean.cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.@Dukestar69 on GitHub · 2026-11-26 17:08 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
stage_image_path) untilDllMainsucceeds (publish_images) and unloading/forgetting all mapped DLLs onbind_importsorattachfailure cleanly prevents cross-thread observation of uninitialized DLLs and mapped-image leaks.cargo test -p victory-hle --lib runtime:: -- --test-threads=1: 5 passed, 0 failed (includingstaged_images_are_thread_private_until_published_or_forgotten).cargo test -p victory -- --test-threads=1: 18 unit + 4 integration tests passed, 0 failed (includinglate_dll_bind_failure_unloads_all_mapped_dlls_and_leaves_no_stale_paths,late_dll_publishes_to_other_threads_only_after_attach_succeeds,late_dll_reentrant_load_keeps_outer_hidden_and_inner_published_independently, andlate_dll_stays_hidden_from_other_threads_during_attach_and_rolls_back_on_failure).cargo clippy -p victory -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 17:32 UTC · original · edited 2026-11-26 17:34 UTC
Independent local verification of PR #3308 on exact head
56b85362bb384b452be5912f4adf154504783416. Control:origin/main63bcca43c6a00a758510398fa43096ce7e4f7df0.Environment: Windows 11 x64, Rust 1.98.1 MSVC, CPU-only (no GPU used), no game files, dumps or shaders; the tests use copies of the host's
System32\version.dll.Head results (
--locked,-j 4):cargo test -p victory late_dll_: 4/4 passed. Stress loop of 20 consecutive runs: 20/20 passed (4/4 each time).cargo test -p victory-hle --lib staged_images: 1/1 passed, 20/20 consecutive runs.cargo test -p victory(--no-fail-fast): all passed (18 + 2 + 1 + 1 tests across its targets, 0 failed).cargo test -p victory-hle --lib: 152 passed, 1 failed in 3 of 4 full runs, 153/153 in 1 of 4 runs. The failure ismodules::dstorage::tests::a_page_list_filled_after_its_request_starts(assertionleft == right). It does not involve the code this PR changes.Control on
origin/main: the same dstorage test fails in 2 of 3 fullvictory-hle --libruns (151 passed, 1 failed; one run 152/152), so that flake predates this PR. The PR's new tests cannot be built on main becauseload_withdoes not exist there.Negative control on head: I replaced
stage_image_path(...)with an immediately-globalset_image_path(...)inLateDlls::load_withand kept the PR's tests. 3 of 4late_dll_tests then failed:..._publishes_to_other_threads_only_after_attach_succeeds,..._reentrant_load_keeps_outer_hidden_...and..._stays_hidden_from_other_threads_.... Only..._bind_failure_unloads_...still passed, since that one covers the rollback path, which this mutation does not touch. The mutation was discarded and the tree restored.AI use: Claude Code (Claude Sonnet 5.5).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.