Skip to content

PE loader: load system DLLs by path as given and do not cache failures - #1151

Merged
throny merged 1 commit into
xcl-dev:mainfrom
emirduran707:resolver-system-cache
Nov 29, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
emirduran707:resolver-system-cache

Conversation

@emirduran707

@emirduran707 emirduran707 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

system_module cached host module handles in SYS_CACHE by dll_key, which drops the directory, and it cached failures (0) too. So:

  • after LoadLibrary("C:\Missing\foo.dll") failed, a later LoadLibrary("foo.dll") returned NULL without trying;
  • once version.dll was cached, LoadLibrary("C:\Mods\version.dll") returned the System32 copy.

Windows loads the path it is given.

A name with a directory component is now loaded as given with LoadLibraryW and is not cached. Bare names (import resolution, the HLE modules' system_module("x.dll") calls) still use the name-keyed cache, which now holds only successful loads.

What is in it

  • crates/xcl/src/resolver.rs: the change, and tests failed_system_load_by_path_is_not_cached and system_load_by_path_loads_that_path.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on 5157a51: 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests
  • both new tests fail without the change and pass with it
  • under Wine a copy of version.dll is a Wine builtin, which Wine maps to the module already loaded under that name whatever the path; system_load_by_path_loads_that_path checks the load by path only on Windows (found in a test run under Wine, see the comments)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19650 MB

this PR:

xcl-smoke v1
commit: 5157a51c57a137f9500101d36b09a38e37a9329b
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1565 (PresentX 1565)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19669 MB

Not tested

  • A title that loads a DLL by full path: the smoke title's run is a regression check only.
  • NVIDIA and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.

  • cargo test -p xcl --lib resolver: 7 passed, 0 failed — includes the new system_load_by_path_loads_that_path and failed_system_load_by_path_is_not_cached.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@fromthemoonx

fromthemoonx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Rerun on the new head 5157a51 (system DLLs by path, failures not cached): still passes on the RTX 3060.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, 5157a51 merged onto main b49be18 (clean; resolver.rs auto-merged) 1437 passed, 0 failed, 47 ignored; 25 SKIPPED lines
system_load_by_path_loads_that_path and failed_system_load_by_path_is_not_cached, alone, 30 runs each; resolver:: (8 tests) at --test-threads=8, 30 runs 30 of 30 each; 30 of 30
scratch: the path branch of system_module disabled (if false && dll.contains(…)) system_load_by_path_loads_that_path fails (left != right, the cached System32 handle came back); the other 7 pass

Same machine, debug. The report below is for eecffed.


NVIDIA run with the whole suite, since Not tested lists NVIDIA.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug
  • Exact head eecffede46e7c3bab32a5af70cce6422d2f3d5f2, which is on current main 47efa2e (so also the merged result): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 743 passed, 0 failed, 41 ignored, the same as yours
  • Both new tests fail without the change, as you say: with resolver.rs as on main plus only the two tests and their module_path helper:
    • failed_system_load_by_path_is_not_cached panics at line 624
    • system_load_by_path_loads_that_path fails its assert_ne! at line 637
    • with the change, both pass
  • resolver:: + loader:: tests, 10 runs: 10 of 10 passed (9 each)
  • e2e, 3 runs: 3 of 3 passed. The test title resolves its imports and loads testgame_mw.dll through this code.
  • D3D12 debug layer: the test title's XCL_D3D12_DEBUG=1 run logs the same set of debug-layer errors and warnings as on main.
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

  • A title that LoadLibrarys a mod DLL by path (none here); release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests on the machine above, including the check without the change, and wrote this report from the output.

@JoaoPauluu

JoaoPauluu commented Nov 24, 2026 •

Copy link
Copy Markdown

Rerun at 5157a51 under Wine on Linux: all resolver:: tests pass now.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 5157a51 as it is (based on 47efa2e) and main 47efa2e, no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact).
  • resolver:: tests on 5157a51: 7 passed, 0 failed, failed_system_load_by_path_is_not_cached and system_load_by_path_loads_that_path included.
  • Earlier, on eecffed: system_load_by_path_loads_that_path failed here at assert_ne!(h, sys) (both 123145285140480). The prefix's version.dll is a Wine builtin (the file has the Wine builtin DLL marker), and Wine gave the System32 handle for the copy's path. With 5157a51 that check is skipped under Wine, so on Wine the by-path load itself is still not checked.
  • Retail title 1.0.2.1, scripts/linux/smoke.sh (Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257) for 60 s, no input.

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1384 (PresentX 1384)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR (5157a51):

xcl-smoke v1
commit: 5157a51c57a137f9500101d36b09a38e37a9329b
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1379 (PresentX 1379)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

Under Wine, peak commit reads 0 MB, so these blocks do not check memory. The two runs are from the same morning, not back to back.

Not tested

  • the by-path load with a DLL that is not a Wine builtin; native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the tests and runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

system_module cached host module handles in SYS_CACHE keyed by dll_key,
which drops the directory, and it cached failures (0) too. So after
LoadLibrary("C:\Missing\foo.dll") failed, a later LoadLibrary("foo.dll")
returned NULL without trying, and once version.dll was cached,
LoadLibrary("C:\Mods\version.dll") returned the System32 copy. Windows
loads the path it is given.

A name with a directory component is now loaded as given with
LoadLibraryW and not cached; bare names (import resolution, the HLE
modules' system_module("x.dll") calls) still use the name-keyed cache,
which now only holds successful loads.

Under Wine, a copy of version.dll is a Wine builtin and is mapped to the
module already loaded under that name whatever path is given, so the test
checks the load by path only on Windows (found in a test run under Wine).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirduran707

Copy link
Copy Markdown
Contributor Author

Thanks @JoaoPauluu. Pushed 5157a51: system_load_by_path_loads_that_path now checks the load by path only when util::under_wine() is false, since Wine maps the builtin version.dll to the loaded module whatever the path. On Wine it still checks that the load succeeds and that the bare name gives the System32 module. Reran the suite and the smoke run on 5157a51 (Windows) and updated the description. #1218 is rebased onto it (8200da8), also rerun.

AI-assisted (Claude Code, Claude Opus 5.5).

@pvfreis pvfreis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 5157a51 (merge base 47efa2e), by reading the code; nothing was built or run here. I checked system_module (resolver.rs:64-80) against its callers and that both new tests fail on the old code. No defect found.

Question for the author: a bare name that fails is no longer cached, so for a DLL that is not on the PC each import of it (resolver.rs:258) and each resolve_hle fallback lookup (resolver.rs:139, also reached from the title's GetProcAddress) runs a full failing LoadLibraryW search. Did you compare startup on a title that imports from such a DLL?

Review by Claude Code (written by Claude Opus 5.5, second read by Claude Fable 5.2); each point checked by a person before posting.

@emirduran707

Copy link
Copy Markdown
Contributor Author

@pvfreis No, I had not measured it. Measured now, on Windows 11 Pro 26300 with a Ryzen 5 5600:

  • A bare-name LoadLibraryW that fails costs about 0.50 ms per call here (2,000 calls of a name that exists nowhere; a name already loaded costs 1.7 µs).
  • On the retail title, the run's report.json lists one import from a DLL that is not on the PC (xmem.dll, stubbed) out of 1,186 imports. So the import pass pays about 0.5 ms more at startup.
  • The resolve_hle fallback lookups at resolver.rs:139 go to the modules' fallback lists: kernelbase.dll, kernel32.dll, advapi32.dll, sechost.dll, xaudio2_9.dll, mfplat.dll, user32.dll, or the imported DLL's own name (SELF, skipped for the module's own name). Those load and are cached as before.
  • What does pay every time is a title that calls GetProcAddress on a missing DLL in a loop: 0.5 ms per call. I have not seen one do that. If one does, a negative cache keyed by name, cleared whenever a load by path succeeds, would bring the old speed back without keeping a stale failure.

Written with Claude Code (Claude Opus 5.5); the measurement is mine.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Native Windows resolver test report for PR #1151 at 5157a51c57a137f9500101d36b09a38e37a9329b

Setup: Windows 11 build 26200, Ryzen 9 5980HX, Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99.0 MSVC. Clean checkout of the PR's exact head.

Tested

  • cargo test --locked -p xcl --lib -j 2 resolver::tests -- --test-threads=1 --show-output: 7 passed, 0 failed, 0 ignored. Both new regressions passed: a failed load by path did not poison the later bare-name load, and an explicit path loaded the copied version.dll rather than the cached System32 module.
  • cargo build --locked --workspace -j 2: passed.

Not tested: Full workspace suite, a retail title that loads a DLL by full path, paired title smoke, or Wine. No game data was used.

AI assistance: OpenAI Codex (GPT-6) ran the commands, extracted the counts from the log, and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…pstream xcl-dev#1218 + xcl-dev#1151, resolver verbatim reference-only)

Windows resolver.rs hunk verbatim reference-only (cfg(windows)-only):
system_module by-path early-load + name-keyed cache + failures-never-cached
rewrite + module_path helper + 2 tests. The xcl-dev#1218 resolver hunk is
byte-identical to xcl-dev#1151 (git diff pr1151head pr1218head -- resolver.rs
empty) — landed once, xcl-dev#1151 triage-closes as CONTAINED.

Windows hle/kernelx.rs hunks verbatim reference-only (cfg(windows)-only):
load_library_impl title-owned GetModuleHandleExW(FROM_ADDRESS)
self-reference block + free_library_of_a_system_dll test.

NO Linux twin change: resolver_linux::system_module (resolver_linux.rs)
is a stub returning None always — no LoadLibrary twin on Linux, same
category as xcl-dev#1667 no-hook-point. Both live heads re-verified pre-commit
(pr1218head=8200da86 +72/-7 2 files, pr1151head=5157a51c +47/-7 1 file,
both still OPEN, merge-base false, same hashes as plan pin, no force-push).
@thehollowedone

thehollowedone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 6089122
head: 5157a51
merge: clean
build: cargo build --workspace -> ok
tests: XCL_ADAPTER=nvidia cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1466 passed, 1 failed, 47 ignored; 25 SKIPPED notices. Both new resolver::tests passed. The sole failure was gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled), also reproduced on untouched main at this base here.
review: No introduced runtime blocker found in the full diff. Explicit paths now reach LoadLibraryW as supplied, and each such call gets its own module reference that the title's FreeLibrary can release. Successful bare-name loads retain the existing cache; failures are no longer stored. The two new tests establish path bypass, but neither would fail if bare-name failures were cached again. A separate isolated-process regression could fail a unique bare-name lookup, make that DLL loadable, then retry and resolve an export. The copied version.dll in the path test is also left in its temporary directory after the test process exits. These are test-hygiene and coverage follow-ups, not an observed runtime failure in this change.
performance: No added work on successful cached bare-name lookups. Explicit path loads and failed bare-name probes now call the Windows loader on each attempt; their frequency and timing in a title were not measured.
verdict: safe to merge
hardware / tool and model: NVIDIA RTX 3080 Ti 12 GiB, driver 621.35; Ryzen 7 9800X3D; Windows 11 build 26300; rustc 1.99.1 MSVC; DXC 1.8.2502.11. Codex (GPT-6.2 Sol) ran the build and tests, reviewed the diff and drafted this check; Codex (GPT-6.2 Astra) independently reviewed loader ownership and test coverage.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 5157a51

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 6089122
head: 5157a51
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1467 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1465 passed, 0 failed, 47 ignored
review: no blocker. The name comes from the title through the LoadLibrary shims; main already passed a full path to LoadLibraryW on the first load of each base name, so no new kind of load: what changes is that a title's own copy of a DLL no longer replaces the cached system handle XCL itself uses, and a path can be loaded again after a failure. The title runs native code in this process anyway, so no boundary is crossed.
performance: failed loads are no longer cached: each failing bare name costs a full search (about 0.5 ms by the author's measurement); import resolution at start and the GetProcAddress fallback, not per frame unless a title polls (not measured).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@throny
throny merged commit e5614bc into xcl-dev:main Nov 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants