diff options
| author | Dominik <55330408+Dom-in@users.noreply.github.com> | 2026-11-22 14:59:38 +0000 |
|---|---|---|
| committer | Dominik <55330408+Dom-in@users.noreply.github.com> | 2026-11-22 15:26:25 +0000 |
| commit | 56fd84b2740f92a04154da8b1d8b90f10920b3ff (patch) | |
| tree | dca180c119a37a95805e30be896271f8ab872c30 /runtime/test/loader_test.cpp | |
| parent | 4eb6155d3ac4f9d3fadb0d095c4ce13e76783615 (diff) | |
pe_loader: a forwarded CRT export binds the host copy, as a direct import does
resolve_forwarder checked prefer_host_copy() on the bare forwarder module
name, but forwarder strings normally leave out ".dll" ("MSVCP140.?foo")
and the host-copy list is named with it. So a bundled module forwarding to
one of the CRT DLLs the package ships (vcruntime140, msvcp140, concrt140,
...) mapped the Xbox build of that DLL from the game folder instead of the
host's, unlike a direct import of the same symbol. It now uses shim_key,
the name with ".dll" the function already builds for the shim lookup.
loader_test: a fake bundled vcruntime140.dll plus a provider forwarding
"vcruntime140.memset" binds to the host memset and never maps the fake
(fails before the change: the import ends unimplemented).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index fd38434c6..f16ba5589 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -844,6 +844,35 @@ void test_forwarded_exports() { | |||
| 844 | } | 844 | } |
| 845 | } | 845 | } |
| 846 | { | 846 | { |
| 847 | // Forwarder strings name the module without ".dll". The package ships Xbox builds of the CRT | ||
| 848 | // (vcruntime140.dll, msvcp140.dll, ...) that the loader replaces with the host's for a direct import; a | ||
| 849 | // forwarded one must get the host copy too, not map the bundled file. | ||
| 850 | const char* what = "a forwarder to a CRT module without \".dll\" binds the host copy, not the bundled one"; | ||
| 851 | write_image_as(make_forwarder_image("KERNEL32.GetCurrentProcessId", 0x1a0000000), "vcruntime140.dll"); | ||
| 852 | write_image_as(make_forwarder_image("vcruntime140.memset", 0x180000000), "prov_crt.dll"); | ||
| 853 | auto importer = write_image_as(make_import_image("prov_crt.dll", "fwd"), "importer_crt.exe"); | ||
| 854 | HMODULE host_crt = LoadLibraryExA("vcruntime140.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
| 855 | void* expected = host_crt ? reinterpret_cast<void*>(GetProcAddress(host_crt, "memset")) : nullptr; | ||
| 856 | if (!expected) { | ||
| 857 | std::printf("SKIP %s: no vcruntime140.dll in System32\n", what); | ||
| 858 | } else { | ||
| 859 | try { | ||
| 860 | rt::Loader loader(g_dir); | ||
| 861 | rt::Module& m = loader.load(importer); | ||
| 862 | if (m.imports.size() != 1 || m.imports[0].binding != rt::Binding::Host) | ||
| 863 | return failed(what, "the forwarded CRT import did not bind to the host"); | ||
| 864 | if (*reinterpret_cast<void**>(m.base + 0x1180) != expected) | ||
| 865 | return failed(what, "the address table does not hold the host's memset"); | ||
| 866 | for (auto* mod : loader.modules()) | ||
| 867 | if (rt::lower(mod->name) == "vcruntime140.dll") | ||
| 868 | return failed(what, "the bundled vcruntime140.dll was mapped"); | ||
| 869 | pass(what); | ||
| 870 | } catch (const std::exception& e) { | ||
| 871 | failed(what, e.what()); | ||
| 872 | } | ||
| 873 | } | ||
| 874 | } | ||
| 875 | { | ||
| 847 | const char* what = "a forwarder to a shimmed module binds to the shim"; | 876 | const char* what = "a forwarder to a shimmed module binds to the shim"; |
| 848 | write_image_as(make_forwarder_image("testshim.F", 0x180000000), "prov_shim.dll"); | 877 | write_image_as(make_forwarder_image("testshim.F", 0x180000000), "prov_shim.dll"); |
| 849 | auto importer = write_image_as(make_import_image("prov_shim.dll", "fwd"), "importer_shim.exe"); | 878 | auto importer = write_image_as(make_import_image("prov_shim.dll", "fwd"), "importer_shim.exe"); |