Skip to content

pe_loader: pass NULL lpvReserved to DllMain on wide dynamic loads - #7996

Open
CourtyardGames wants to merge 1 commit into
ItsNotRexed:mainfrom
CourtyardGames:fix/pe-loader-wide-dynamic-reserved
Open

CourtyardGames wants to merge 1 commit into
ItsNotRexed:mainfrom
CourtyardGames:fix/pe-loader-wide-dynamic-reserved

Conversation

@CourtyardGames

Copy link
Copy Markdown

Claimed in the coordination issue as: #7694 (comment)

What and why

Loader::load_runtime_module_w (runtime/src/pe_loader.cpp) did not hold a RuntimeLoadScope, unlike Loader::load_runtime_module and Loader::resolve_module_export. When a bundled DLL with a non-ASCII basename was dynamically loaded via load_runtime_module_w, Loader::load() left mapped->dynamic_load = false (since runtime_loads_ == 0), causing Loader::initialise() to pass a non-NULL lpvReserved (the static-load indicator) to DllMain(DLL_PROCESS_ATTACH) instead of nullptr.

This moves const RuntimeLoadScope dynamic(runtime_loads_); into Loader::load_runtime_candidate around load(candidate), so both narrow (load_runtime_module) and wide (load_runtime_module_w) dynamic loads mark the mapped module and its dependencies as dynamic loads.

Also adds a regression check in runtime/test/loader_test.cpp (test_attach_reserved) verifying that load_runtime_module_w on a non-ASCII bundled DLL (attach_reserved_漢.dll) passes lpvReserved == nullptr to DllMain(DLL_PROCESS_ATTACH).

Tested

  • Windows x64, MSVC 19.51.36260.0 (RelWithDebInfo, Ninja); CPU-only (no GPU or game files needed).
  • Verified the new check in loader_test fails on unpatched main (FAIL a wide run-time load's DllMain gets a NULL lpvReserved: lpvReserved was non-NULL, 89 checks, 1 failed).
  • After the fix: ctest --test-dir runtime/build -R "^(loader|module_names|pe_loader|loader_tls|dll_thread_calls)$" --output-on-failure — 5/5 passed.
  • python -I scripts/check_no_game_data.py runtime/src/pe_loader.cpp runtime/test/loader_test.cpp — passed (exit 0).

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — runtime loader fix, not a shader-translator rule.)

@al3xar al3xar 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.

Tested 7f9564c24 on Windows 11 x64, MSVC 19.44.35230.0 (VS 2022 Build Tools), CMake + Ninja RelWithDebInfo, Windows SDK 10.0.26100.0 (CPU-only, no game files): pass.

  • Merges cleanly onto upstream/main (dde82f27e).
  • Built loader_test, pe_loader_test, module_names_test, loader_tls_test, and dll_thread_calls_test with zero warnings.
  • ctest -R "^(loader|module_names|pe_loader|loader_tls|dll_thread_calls)$" --output-on-failure: 5/5 passed.
  • loader_test.exe on PR head (7f9564c24): 89 checks, 0 failed (ok a wide run-time load's DllMain gets a NULL lpvReserved).
  • Negative control (runtime/src/pe_loader.cpp reverted to upstream/main, PR test kept): loader_test.exe fails as expected (89 checks, 1 failed: FAIL a wide run-time load's DllMain gets a NULL lpvReserved: lpvReserved was non-NULL).
  • python -I scripts/check_no_game_data.py runtime/src/pe_loader.cpp runtime/test/loader_test.cpp: clean (exit 0).
  • Diff review: moving RuntimeLoadScope into load_runtime_candidate() covers both narrow and wide run-time dynamic loads cleanly.

AI-assisted.

@iTzAlvar

Copy link
Copy Markdown

Tested 7f9564c24 merged onto main dde82f27e (clean merge), Windows 11 Pro 25H2 (26200), MSVC 2022 Build Tools, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, NVIDIA RTX 5080 / 621.24: pass.

  • loader_test: 89 checks, 0 failed, including "a wide run-time load's DllMain gets a NULL lpvReserved".
  • Negative control, the same test with main's runtime/src/pe_loader.cpp: 89 checks, 1 failed. FAIL a wide run-time load's DllMain gets a NULL lpvReserved: lpvReserved was non-NULL, which is the bug this fixes.

Code read: RuntimeLoadScope is a counter, so moving it into load_runtime_candidate covers the narrow and the wide entry points. The call from resolve_module_export, which already holds one, just nests. No game files. AI-assisted (Claude Code).

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.

3 participants