upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/loader_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/loader_test.cpp')
-rw-r--r--runtime/test/loader_test.cpp29
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");