Skip to content

loader/shims: host-binding fix, ordinal classes, module identity for mapped images - #5731

Closed
NolanCotter wants to merge 7 commits into
ProjectLeonida:mainfrom
NolanCotter:2490-loader
Closed

NolanCotter wants to merge 7 commits into
ProjectLeonida:mainfrom
NolanCotter:2490-loader

Conversation

@NolanCotter

Copy link
Copy Markdown
Contributor

Split from #2490 (first of three), rebased onto current main after the revert.

Summary

  • Shim-owned modules (xgameruntime.dll, gameinput.dll, d3d12_xs.dll, xmem.dll) no longer bind to their real System32 namesakes — an unregistered console import ends unimplemented instead of reaching a host Gaming Services call, in Loader::resolve and resolve_forwarder alike.
  • dll_key applies LoadLibrary's file-name rule to imports, so TestShim, testshim.dll. and testshim.dll all key to testshim.dll's shim.
  • gameinput.dll!#1 and xaudio2_9.dll ordinals (Add pytest regression tests for the RDNA2 -> SPIR-V translator, plus a Linux CI job #1, host-only CI: Dependabot for GitHub Actions and the rpf9-explorer submodule #8–Add a pull request template from CONTRIBUTING.md #10) classify as HResult.
  • GetModuleHandle(nullptr) answers with the mapped main image; GetModuleFileNameA/W answer for bundled modules' stored paths (Win32 spelling, Z: under Wine) through two new BundledModuleOps.
  • New docs: docs/import_routing.md (the bind order) and docs/console_libraries.md (the console-DLL surface); docs/boot.md records the packaging-probe run this work enabled.

This carries the pre-revert tree's version of these files, so it keeps the upstream refinements that landed on the merged code (e.g. the ExistingThreads TLS work stays untouched).

Test plan

  • loader_test 88/0 and unimplemented_policy_test 96/0 under Wine/clang-cl on the build host
  • No game files, no GPU needed

AI-assisted.

Generated with Devin

@searyecheesepeaceful

Copy link
Copy Markdown

Tested 3362ef8 on Intel UHD Graphics 770, driver 32.0.101.7088: loader_test exits 0 with "88 checks, 0 failed", including "ok a forwarder to a shimmed module binds to the shim" and "ok a forwarder to a CRT module without ".dll" binds the host copy, not the bundled one". unimplemented_policy_test exits 0 with "105 checks, 0 failed". No check line in either output names module identity, GetModuleHandle(nullptr) or GetModuleFileName, so the identity part of the description is not shown by this run.

AI-assisted.

NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
gertify's check on ItsNotRexed#5731 showed no check line names module identity:
the ops behind GetModuleHandle(nullptr) and GetModuleFileName were
only covered indirectly. A load() now verifies the main-module op
answers the first mapped image and module_path answers the main
image's and the module's own stored path.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@NolanCotter

Copy link
Copy Markdown
Contributor Author

Thank you (AI-assisted reply) — fair catch. eec5b68f adds a check that exercises the ops layer directly: a load() now verifies bundled_main_module() answers the first mapped image and bundled_module_path() names the main image's and the module's own stored path (the GetModuleHandle/GetModuleFileName shim bodies in library_loader.cpp sit on top of these ops; that file isn't in this target). loader_test now reports the check line "GetModuleHandle(nullptr)/GetModuleFileName answer for mapped images through the bundled ops" — 89 checks, 0 failed under Wine/clang-cl on the build host.

@Kam471 Kam471 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Superseded by the second (current) review on this PR.

@Kam471 Kam471 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed head 2e0f1a2 (base 561b65a). Build: pwsh scripts/build_runtime.ps1 -jobs 8 -> exit 0.

With LEONIDA_VK_DEVICE='RTX 5070 Ti', ctest -R '^(loader|pe_loader|pe_loader_bounds|loader_tls|unimplemented_policy|run_tiny_gdk_load|run_tiny_atexit|run_tiny_frame)$' -> 8/8 passed, 11.66 s:

  • loader 90 checks / 0 failed, including "an unregistered import of a shim-owned module ends unimplemented, not host"
  • unimplemented_policy 105 checks / 0 failed; pe_loader_bounds 54 checks / 0 failed; pe_loader passed with "SKIP (no package): LEONIDA_GAME_DIR is not set"; loader_tls passed
  • run_tiny_frame OK ("tiny_frame under gta6rt --run on the Vulkan D3D12 device: OK"); run_tiny_gdk_load and run_tiny_atexit passed

Manual probes on a guest mapped by this gta6rt:

  • GetModuleFileNameW(NULL)/...A return the guest's own path (ret 63); GetModuleHandleW(NULL) is the mapped base, not gta6rt.exe.
  • System32 xgameruntime.dll exports XErrorReport (LoadLibraryEx + GetProcAddress is non-NULL), yet a static xgameruntime.dll!XErrorReport import is UNIMPLEMENTED and the run calls the thunk.

The no-SDL3 gameinput.dll case is now qualified correctly in docs/import_routing.md, and the console-ABI link is fixed: tests/test_docs_links.py passes (15 passed, 6 subtests). git diff --check clean.

Verdict: no blockers. Runtime fix verified, run_tiny_frame unaffected, and the owned->host skip has a regression test.

@NolanCotter

Copy link
Copy Markdown
Contributor Author

Both addressed in 178fdb84 (AI-assisted reply).

  • Broken link: console_libraries.md now points at d3d12_vulkan.md and d3d12_command_objects.md (which already covers the PresentX surface) — test_docs_links passes 6/6. The ABI doc itself arrives with the d3d12_xs: console-ABI command lists, upload arena, PC-list fixture path #2490 slice.
  • The skip: pinned with a deterministic check — version.dll is claimed in the test table, so an import of the real GetFileVersionInfoSizeA export must end Unimplemented rather than bind the host copy — your xgameruntime.dll!XErrorReport probe made a check. loader_test 90 checks, 0 failed under Wine/clang-cl.

@NolanCotter

Copy link
Copy Markdown
Contributor Author

@Kam471 both fixed in 178fdb84, pushed on top of eec5b68f:

  • Link: console_libraries.md now links d3d12_vulkan.md + d3d12_command_objects.md instead — d3d12_xs_console_abi.md belongs to d3d12_xs: console-ABI command lists, upload arena, PC-list fixture path #2490's slice, so it can't exist here. unittest discover -s tests -p 'test_docs_*.py' is 6/6 OK now.
  • Nit: added ok an unregistered import of a shim-owned module ends unimplemented, not host to loader_test — registers version.dll (host-real, non-whitelisted, imported nowhere else in the suite) as shim-owned in a local rt::shims::Table, feeds an image importing real version.dll!GetFileVersionInfoSizeA unregistered, asserts the binding is Unimplemented. loader_test is now 90 checks, 0 failed under Wine/clang-cl.

@ItsNotRexed FYI on the GetModuleHandleW(nullptr) question Kam471 raised: the shim answers through bundled_main_module()/bundled_module_path() — the loader keeps the first-mapped-image handle as the "main" answer, and loader_test verifies the ops layer returns the guest image (not gta6rt.exe) at eec5b68f. The real GetModuleFileNameA/W shim bodies are in library_loader.cpp (not in the loader_test target) and were exercised natively by gertify's run.

NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
gameinput.cpp only compiles when SDL3 is available, so without the
shim gameinput.dll has no registry entries, is not owns_dll, and its
imports bind the host DLL or end unimplemented like any unserved
name (Kam471's review on ProjectLeonida#5731). xgameruntime.dll's GameInputCreate
entry is conditional the same way.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@NolanCotter

Copy link
Copy Markdown
Contributor Author

@Kam471 thanks for the re-verification — glad the owned→host-skip test and the link fix hold on your setup.

Good catch on the SDL3 caveat; that's a real doc imprecision. Fixed in 2e0f1a29: import_routing.md now qualifies gameinput.dll ownership as conditional on the SDL3 GameInput shim being built — a build without SDL3 has no gameinput.dll entries, so the name isn't owns_dll and imports bind host/unimplemented like any unserved name. Also qualified xgameruntime.dll's GameInputCreate entry the same way, since it registers inside gameinput.cpp (SDL3-gated compile) too. test_docs_links.py 6/6 OK.

@thatirishguyyy

Copy link
Copy Markdown

Tested 178fdb84 on Windows 11 with MSVC 19.51 (RelWithDebInfo). loader, pe_loader, pe_loader_bounds, loader_tls, and unimplemented_policy all passed, including the updated loader test. run_tiny_frame passed on both the RX 9070 XT (32.0.32029.2010) and integrated Radeon (32.0.21045.29003). This covers the synthetic frame regression that triggered the #2490 revert on two AMD adapters.

AI-assisted.

@NolanCotter

Copy link
Copy Markdown
Contributor Author

@Kam471 thanks for tracking the head through 2e0f1a297 — three clean reviews in a row now.

@thatirishguyyy the two-adapter run_tiny_frame pass is exactly the coverage this PR needed — that's the synthetic-frame regression that triggered the original revert, now verified on both an RX 9070 XT and an integrated Radeon on top of the loader changes. Thanks.

@searyecheesepeaceful

Copy link
Copy Markdown

Tested 2e0f1a2 on NVIDIA GeForce RTX 4080, driver 617.42: unimplemented_policy_test exits 0 with "105 checks, 0 failed". loader_test exits 1 with "50 checks, 2 failed": the two failures are "initialise runs a TLS callback and DllMain" and "writing the test images", both with "gta6rt_tls_host.dll is missing or has no module TLS index", so the TLS cases did not run in this build. The new cases pass here, including "an import naming TestShim resolves to testshim.dll's shim", "GetModuleHandle(nullptr)/GetModuleFileName answer for mapped images through the bundled ops" and "an unregistered import of a shim-owned module ends unimplemented, not host".

AI-assisted.

@NolanCotter

Copy link
Copy Markdown
Contributor Author

@gertify thanks for the run — good news is all the PR's own checks passed for you (forwarder→shim, bundled-ops module identity, owned→host skip). The two failures aren't from this slice though: the diff touches zero TLS code (git diff origin/main...HEAD -- runtime/test/loader_test.cpp runtime/src/pe_loader.cpp adds import-routing/module-identity lines only).

What's happening: pe_loader.cpp:1320 throws when a module with a TLS directory loads and gta6rt_tls_host.dll isn't next to the test exe — that's upstream's TLS-anchor fixture (src/tls_host.cpp), built by the gta6rt_tls_host target and wired via add_dependencies(loader_test gta6rt_tls_host). Your "50 checks" (vs the usual ~90) is the top-level write_image catch aborting the suite early after the same missing-DLL error escapes an inner test.

Likely cause: a build dir configured before gta6rt_tls_host existed in CMakeLists, so a target-scoped/incremental build never made the DLL. Could you check whether gta6rt_tls_host.dll sits beside loader_test.exe in your build output, and if not, re-run configure + cmake --build and retest? Kam471 (2e0f1a297) and thatirishguyyy (178fdb84) both got the full 90/0 on this head, so a complete build should clear it. If it still fails with the DLL present, that's a real signal and I'll dig in.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 2e0f1a29 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: no regression.

  • ctest: 235 passed, 11 skipped, 2 failed, the same two as main. On this card main 561b65a8 itself fails d3d12_indirect_dispatch_count (ExecuteCommandLists failed: invalid copy or resolve) and d3d12_indirect_rt (RayQueryKHR ARRAY expected hit=1 miss=0, got hit=0 miss=0), 3/3 runs each, and the GPU test ms_wave_info_s3; those are not from this PR.
  • run_gpu_tests.py: 183/232 passed, the same as main.

AI-assisted (Claude Code).

@NolanCotter

Copy link
Copy Markdown
Contributor Author

@itsonlysimbo thanks — the same-two-failures-on-main baseline is exactly the right check, and the 3/3 repro on 561b65a8 pins them as driver-level (indirect_dispatch_count/indirect_rt/ms_wave_info_s3 have nothing in this slice's diff). No regression confirmed.

@l-CatDemon-l

Copy link
Copy Markdown

Independent Windows check of module identity for a mapped image (synthetic guest, ASCII path, started from Explorer, no implicit layers, own builds of each tree, each result stable ×3). "image" = the guest's &__ImageBase, "gta6rt" = the host exe.

call native main 4beffda #2075 a92e46a #5731 2e0f1a2
GetModuleHandleW/A(NULL) image gta6rt image image
GetModuleHandleExW/A(0, NULL) image gta6rt image gta6rt
GetModuleHandleExW(FROM_ADDRESS, own function) image FALSE, 126 image FALSE, 126
GetModuleFileNameW/A(NULL) guest path gta6rt path guest path guest path
GetModuleFileNameW(&__ImageBase) guest path fails, 126 guest path guest path
GetProcAddress(NULL, export) own export NULL, 127 own export NULL, 127
GetProcAddress(&__ImageBase, export) own export own export own export own export

This covers only these calls; the other parts of #5731 (host binding, ordinal classes, docs) and non-ASCII or Wine paths were not measured. AI-assisted.

NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
gertify's check on ProjectLeonida#5731 showed no check line names module identity:
the ops behind GetModuleHandle(nullptr) and GetModuleFileName were
only covered indirectly. A load() now verifies the main-module op
answers the first mapped image and module_path answers the main
image's and the module's own stored path.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
gameinput.cpp only compiles when SDL3 is available, so without the
shim gameinput.dll has no registry entries, is not owns_dll, and its
imports bind the host DLL or end unimplemented like any unserved
name (Kam471's review on ProjectLeonida#5731). xgameruntime.dll's GameInputCreate
entry is conditional the same way.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
…mages

l-CatDemon-l's module-identity matrix on ProjectLeonida#5731 showed three gaps
against native answers: GetModuleHandleEx(0, NULL) returned the host
exe, GetModuleHandleEx(FROM_ADDRESS, fn) failed 126, and
GetProcAddress(NULL, export) found nothing — the Ex variants were
never shimmed and a null module never reached the mapped main image.

GetModuleHandleExA/W now share GetModuleHandle's order (owned
pseudo-handle, bundled by name, bundled main image, host), with
FROM_ADDRESS answered by a new module_for_address on the bundled ops
and PIN/UNCHANGED_REFCOUNT no-ops for mapped modules. A null module
in the GetProcAddress shim asks for the main image's exports first.

loader_test's module-identity check now covers
bundled_module_for_address inside and just past the image: 90 checks,
0 failed under Wine/clang-cl.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@NolanCotter

Copy link
Copy Markdown
Contributor Author

@l-CatDemon-l excellent matrix — three real gaps against native. All fixed in c4fcea0a, pushed on a rebase to f6c6d11e (upstream moved; the prior commits replayed clean):

  • GetModuleHandleEx(0, NULL) and GetModuleHandleEx(FROM_ADDRESS, fn): the Ex variants were never shimmed — they fell through to host kernel32, which doesn't know mapped images. GetModuleHandleExA/W are now registered with the same answer order as GetModuleHandle (owned → bundled-by-name → bundled main image → host), with FROM_ADDRESS answered by a new module_for_address op that finds the mapped module covering an address. PIN/UNCHANGED_REFCOUNT are no-ops — mapped images live until the loader unwinds.
  • GetProcAddress(NULL, export): a null module now asks for the mapped main image's exports, matching native (the process image is ours).

loader_test (Wine/clang-cl): 90/0 — the bundled-ops identity check now also covers module_for_address inside and just past the image; unimplemented_policy_test 96/0. Note the head SHA moved: the branch was rebased onto f6c6d11e, so the previous commits are ff87b7aa/2eeef10c/38ced104/6e102d36 equivalents of the 2e0f1a29 chain.

NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
gameinput.cpp only compiles when SDL3 is available, so without the
shim gameinput.dll has no registry entries, is not owns_dll, and its
imports bind the host DLL or end unimplemented like any unserved
name (Kam471's review on ItsNotRexed#5731). xgameruntime.dll's GameInputCreate
entry is conditional the same way.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
NolanCotter added a commit to NolanCotter/Leonida that referenced this pull request Nov 23, 2026
…mages

l-CatDemon-l's module-identity matrix on ItsNotRexed#5731 showed three gaps
against native answers: GetModuleHandleEx(0, NULL) returned the host
exe, GetModuleHandleEx(FROM_ADDRESS, fn) failed 126, and
GetProcAddress(NULL, export) found nothing — the Ex variants were
never shimmed and a null module never reached the mapped main image.

GetModuleHandleExA/W now share GetModuleHandle's order (owned
pseudo-handle, bundled by name, bundled main image, host), with
FROM_ADDRESS answered by a new module_for_address on the bundled ops
and PIN/UNCHANGED_REFCOUNT no-ops for mapped modules. A null module
in the GetProcAddress shim asks for the main image's exports first.

loader_test's module-identity check now covers
bundled_module_for_address inside and just past the image: 90 checks,
0 failed under Wine/clang-cl.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
NolanCotter and others added 7 commits November 23, 2026 09:59
Shim-owned modules (xgameruntime, gameinput, d3d12_xs, xmem) no longer
bind to their real System32 namesakes in resolve() or forwarded
exports — an unregistered console import now ends unimplemented
instead of reaching a host Gaming Services call. LoadLibrary's
file-name rule keys imports so "TestShim", "testshim.dll." and
"testshim.dll" hit the same shim.

registry gains the ordinal classes: gameinput #1 and xaudio2_9
(#1, and host-only ItsNotRexed#8-ItsNotRexed#10) classify as HResult.

GetModuleHandle(nullptr) answers with the mapped main image and
GetModuleFileNameA/W answer for bundled modules' stored paths
(Win32 spelling, Z: under Wine) through two new BundledModuleOps.
loader_test pins the name-rule binding; unimplemented_policy_test
pins the ordinal classes.

Split from ItsNotRexed#2490 (first of three). AI-assisted. Tested on the build
host under Wine/clang-cl: loader_test 88/0, unimplemented_policy_test
96/0.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
gertify's check on ProjectLeonida#5731 showed no check line names module identity:
the ops behind GetModuleHandle(nullptr) and GetModuleFileName were
only covered indirectly. A load() now verifies the main-module op
answers the first mapped image and module_path answers the main
image's and the module's own stored path.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
console_libraries.md linked d3d12_xs_console_abi.md, which lands with
the console-ABI slice — d3d12_command_objects.md already covers the
PresentX surface, so test_docs_links is green again (Kam471's blocker).

The unregistered-import-of-an-owned-module path now has a check:
version.dll is claimed in the test table, so an import of the real
GetFileVersionInfoSizeA export must end unimplemented rather than
bind the host copy — the same skip Kam471 probed by hand, made a
check. loader_test: 90 checks, 0 failed under Wine/clang-cl.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
gameinput.cpp only compiles when SDL3 is available, so without the
shim gameinput.dll has no registry entries, is not owns_dll, and its
imports bind the host DLL or end unimplemented like any unserved
name (Kam471's review on ItsNotRexed#5731). xgameruntime.dll's GameInputCreate
entry is conditional the same way.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…mages

l-CatDemon-l's module-identity matrix on ItsNotRexed#5731 showed three gaps
against native answers: GetModuleHandleEx(0, NULL) returned the host
exe, GetModuleHandleEx(FROM_ADDRESS, fn) failed 126, and
GetProcAddress(NULL, export) found nothing — the Ex variants were
never shimmed and a null module never reached the mapped main image.

GetModuleHandleExA/W now share GetModuleHandle's order (owned
pseudo-handle, bundled by name, bundled main image, host), with
FROM_ADDRESS answered by a new module_for_address on the bundled ops
and PIN/UNCHANGED_REFCOUNT no-ops for mapped modules. A null module
in the GetProcAddress shim asks for the main image's exports first.

loader_test's module-identity check now covers
bundled_module_for_address inside and just past the image: 90 checks,
0 failed under Wine/clang-cl.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
run_tiny_gdk_load and run_tiny_bundled_load asked host
GetModuleHandleExW whether the returned handle was host-registered;
the new shim answers for owned and mapped modules, so the probe
misfired. Read the mapping instead: host-loaded images are MEM_IMAGE,
rt::Loader images are VirtualAlloc'd MEM_PRIVATE, and a pseudo-handle
is never an image. The fixtures also assert the shim's new answer
directly.
Upstream's get_module_handle_w splits ASCII names (narrow + owned +
find_loaded) from non-ASCII (module_name_w + find_loaded_bundled_module_w);
the new Ex variant only had the narrow path, so a non-ASCII module name
would turn to '?' and miss a mapped module. Same split now.
@NolanCotter

Copy link
Copy Markdown
Contributor Author

Rebased onto cc4dabef — head abac4874. Upstream's wide-basename loader work collided in three files, all resolved keep-both:

  • shims.h/pe_loader.cpp: BundledModuleOps carries upstream's find_loaded_w/load_bundled_w and this slice's main_module/module_path/module_for_address; upstream's RuntimeLoadScope kept
  • library_loader.cpp: get_module_handle_w is upstream's ASCII/wide split plus our !name → mapped-main-image check
  • Plus one follow-on fix (abac4874): GetModuleHandleExW needed the same wide-basename split upstream just added — a non-ASCII module name would narrow() to '?' and miss a mapped module

Verified (clang-cl 20 + xwin, Wine): loader_test 92/0, unimplemented_policy_test 96/0, run_tiny_gdk_load + run_tiny_bundled_load pass.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested abac48743 merged into main dde82f27e on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass (no regression against main).

  • ctest -j4 --output-on-failure (full): "99% tests passed, 3 tests failed out of 272". The 3 failures are d3d12_indirect_dispatch_count, d3d12_depth_resolve and d3d12_vulkan_device, which also fail on plain main dde82f27e here. The PR touches loader_test, unimplemented_policy and the tiny_*_load fixtures; no failure in those.

AI-assisted (Claude Code).

@NolanCotter

Copy link
Copy Markdown
Contributor Author

Thanks — the baseline comparison is the useful part here: all three failures reproduce on plain main dde82f27e, so they're pre-existing and unrelated to this slice. The PR's own surface (loader_test, unimplemented_policy, both tiny_*_load fixtures) is green on your RTX 4090 + MSVC 18 build.

@2-CD

2-CD commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check. Hardware: NVIDIA GeForce RTX 5080 + RTX 3070 Ti (driver 621.01) and AMD Radeon 610M iGPU (Ryzen 9 9950X3D, driver 32.0.13018.6). OS: Windows 11. Toolchain: MSVC (VS BuildTools 18) + Ninja, single-config RelWithDebInfo; llvm-mc 21.1.8; SPIRV-Tools (spirv-as/spirv-val). Configured with -DLEONIDA_LLVM_MC and -DLEONIDA_SPIRV_AS/VAL so the shader-fixture GPU tests register.

Tested head abac487 (base 2c7095d).

Build: 657/657 targets, 0 errors/warnings.

Targeted tests (this PR's loader/shim scope), --repeat until-fail:3 on the RTX 5080: loader, unimplemented_policy, startup_trace, run_tiny_gdk_load, run_tiny_bundled_load, dll_thread_calls, loader_tls, pe_loader - 9 tests x3 = 27 runs, all pass. The host-binding fix, ordinal-class classification and module-identity changes are exercised by these and are green.

Full runtime suite, ctest -C RelWithDebInfo -j 6, excluding the 4 windowed present tests:

  • RTX 5080: 2 failures - d3d12_vulkan_device, d3d12_indirect_dispatch_count.
  • Radeon 610M iGPU (LEONIDA_VK_DEVICE=Radeon): 4 failures - vk_queue_query_sync, d3d12_vulkan_device, d3d12_indirect_dispatch_count, d3d12_mesh.

Isolation: every one of those reproduces IDENTICALLY on current main dde82f2 on the same hardware (e.g. d3d12_indirect_dispatch_count reports host 6/10, layer 0/0, expected 6/10 on both this head and main; the iGPU-only vk_queue_query_sync and d3d12_mesh also fail on main on the Radeon 610M). They are GPU tests outside this PR's loader/shim scope and are red on main on my GPUs (RTX 5080 + Radeon 610M driver 32.0.13018.6), so they are not attributable to this PR.

Windowed present tests, run serially --repeat until-fail:3 on each GPU: d3d12_present and xbox_present pass x3 on both the RTX 5080 and the Radeon 610M.

Net: this PR's loader/shim changes build clean and their targeted tests are green x3 on NVIDIA; the only full-suite failures are pre-existing main-red GPU tests on my hardware, unchanged by this PR.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@isfcrctfs isfcrctfs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Audit: clean. The 14 files are docs, loader/shims C++ and two test fixtures - no CI, workflow, hook, credential, submodule or binary/game-data changes, and no prompt-injection text in the diff.

I could not build the Windows tests here (no MSVC/xwin/wine in this sandbox), so the C++ side is a static read; the thread's Windows runs cover the runtime. The changes look sound: dll_key matches module_name's rule (basename, lower, drop a trailing dot, add .dll only when there is no dot), the new bundled_* ops are null-guarded, windows_form/GetModuleFileName* set ERROR_INSUFFICIENT_BUFFER and return size on truncation as the API does, and the test checks the base + size boundary. What I did find are statements in the new docs that do not match this tree's code:

  1. docs/console_libraries.md:57 "4 names registered", :78 "registers four names", :84/:207 "the other 19"/"4 of the 23": runtime/shims/d3d12_xs.cpp:233 also registers D3D12ConfigureVirtualMemoryX (added by #6792, which is in this PR's base), and docs/d3d12_xs_surface.md:67 lists it as one of the 23 exports. So it is 5 registered / 18 not, and the name is missing from the list and from docs/import_routing.md:56.

  2. docs/console_libraries.md:58,104 "39 names"/"38 names plus GameInputCreate": the xgameruntime table has 41 XGR names under xgameruntime.dll (plus the two gameplatformservices.dll entries; 42 with the SDL3 GameInputCreate).

  3. docs/console_libraries.md:127 "no such names are registered" and :213 "the shim covers only the four allocator/query names": runtime/shims/xmem.cpp:724-727 registers and implements XMemAllocatePhysicalPages, XMemFreePhysicalPages, XMemMapPhysicalPages and XMemMapPhysicalPagesScatter (with measured call sites in docs/xmem_exe_calls.md). The table has 15 entries, while docs/import_routing.md:58 lists 4.

  4. docs/console_libraries.md:153-154 "the ordinal lookup classifies as Other": root/runtime/shims/registry.cpp:112-119 in this PR classifies #1 (and #8-#10 for xaudio2_9.dll) as HResult, and unimplemented_policy_test asserts it.

  5. The owned list - docs/console_libraries.md:44-46 "the modules with a SHIM_TABLE entry", docs/import_routing.md:42-44 - omits winhttp.dll and gameplatformservices.dll. Both have SHIM_TABLE(xmem)-style entries (runtime/shims/winhttp_offline.cpp:440, runtime/shims/xgameruntime.cpp:1328) and neither is in the eight-name host list, so owns_dll is true for them. This matters because this PR is the first to gate host binding on owns_dll: an unregistered winhttp.dll import that used to bind System32's DLL now ends unimplemented. All 16 measured WinHttp* imports are in the table, so the package is unaffected, but please confirm that is intended and add both names to the lists (and the per-DLL table).

Also docs/design.md:3-6 points at docs/boot.md for the "packaging verification probe" statement, but boot.md does not contain it (the phrase appears only in design.md); either add the paragraph to boot.md or drop the pointer.

I found no functional defect in the C++ changes themselves; the doc mismatches above are the actionable items.

AI-assisted

@LaugeM LaugeM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR does two jobs, and I'd split them.

The import-routing part is useful and has nothing competing with it:

  • shim-owned modules skip their host namesakes in Loader::resolve and resolve_forwarder;
  • dll_key;
  • the #1 and #8-#10 return classes.

The module identity part (GetModuleHandle(NULL), GetModuleHandleEx*, GetModuleFileName*, GetProcAddress(NULL, ...)) duplicates #2075, which covers the same calls closer to what Windows does (details below). I'd keep the routing part here and leave identity to #2075.

Checked against upstream/main 5d74c27 (head abac487 merges cleanly). Measured natively on Windows 11 26200 with a small program, not under gta6rt:

  1. GetModuleHandleExA/W don't check their arguments (runtime/shims/library_loader.cpp:242-306).
    • With out == NULL, the shim returns TRUE for a mapped or owned module (if (out) *out = ...; return TRUE). Windows returns FALSE with ERROR_INVALID_PARAMETER (87).
    • An unknown flag, or PIN together with UNCHANGED_REFCOUNT, is accepted. Windows fails with 87 and clears *out (measured: GetModuleHandleExW(0x80, L"a.dll", &out) gives FALSE, 87, out NULL).
  2. GetModuleFileNameW/A with size == 0 returns 0 with ERROR_INVALID_PARAMETER (:331-334, :349-352). Windows returns 0 with ERROR_INSUFFICIENT_BUFFER (122).
  3. GetModuleHandleEx(0, name) keeps main's basename-only rule: module_name() drops the folder, so C:\other\x.dll finds a mapped x.dll. Windows returns NULL with 126 for a full path that isn't the module's own.
  4. The main module is order_.front() in every mode (runtime/src/pe_loader.cpp:1200-1203, :1207). Under gta6rt --init some.dll, or in a test that maps only a DLL, GetModuleHandle(NULL), GetModuleFileName(NULL) and GetProcAddress(NULL, ...) name that DLL. #2075 sets the main module only for --run (main.cpp:162 there).
  5. The three new lookups take Loader::mutex_ (pe_loader.cpp:1201, :1206, :1214). Main holds that mutex across a run-time load's DllMain (load_runtime_module, upstream pe_loader.cpp:1125). pe_loader.h:160-161 keeps a separate leaf-locked range table for exactly this reason.
    • So a GetModuleHandle(NULL) or GetModuleHandleEx(FROM_ADDRESS) on one thread now waits for any LoadLibrary of a bundled DLL on another, and deadlocks if that DllMain waits for the first thread.
    • Windows answers GetModuleHandle(NULL) from the PEB without the loader lock.
    • module_for_address could read ranges_ under ranges_mutex_, as find_address does.
  6. GetModuleFileNameA converts with narrow() (:354), which turns every character outside ASCII into ?. Windows converts with the ANSI code page.
  7. windows_form makes a relative stored path absolute when it is asked for (:319), against whatever the current folder is at that moment. map_image stores the path as given (pe_loader.cpp:1328), so a relative --game-dir plus a title that changes its folder gives a wrong path. #2075 makes Module::path absolute at map time.

Docs:

  • docs/design.md:3-6 says the game_scarlett_master.exe obtained so far "is a packaging verification probe, not the engine". Main now says otherwise: b7a3fed patches the retail executable's /GA TLS reads, and docs/boot.md:3-6 calls it the retail executable and records its --dry-run and --init runs. The sentence came from the reverted #2490 and should go.
  • isfcrctfs's count mismatches are still at this head: docs/console_libraries.md:57,58,78,84,104,127,154,213, and the owned list in import_routing.md is missing winhttp.dll and gameplatformservices.dll. The :154 "classifies as Other" line contradicts this PR's own registry.cpp change.

AI-assisted review (Opus 5.5). Read the diff against main; not built (merge-tree against upstream/main, and a native Windows probe of the Win32 behaviour quoted above).

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.