Run, HLE: keep late-loaded title DLLs private until DllMain succeeds and unload on bind failure #2447
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2447"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by fuzeofficlal on 2026-11-29T13:07:48Z.
Summary
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/W,GetModuleFileNameA/W, andimage_containingqueryIMAGE_PATHSwithout acquiringLoaderLock, another thread could observe anHMODULEwhileDllMainwas still executing on the loading thread—either invoking exports before initialization finished, or holding a dangling module handle / reading unmapped headers 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,image_containing, 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
System32\version.dllwith unique trailing overlay tags andBarriersynchronization inapps/victory/src/run.rs(late_dll_*) andcrates/victory-hle/src/runtime.rs(staged_images_are_thread_private_until_published_or_forgotten).VIctory-NVIDIA:cargo test --locked -p victory late_dll_cargo test --locked -p victorycargo test --locked -p victory-hle -- --test-threads=1cargo clippy --locked -p victory -p victory-hle --all-targets(no new warnings)cargo run --quiet --locked -p xtask -- policy --staged