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:
authorDea7hsmiles <188018312+dea7hsmiless@users.noreply.github.com>2026-11-21 13:02:45 -0800
committerDea7hsmiles <188018312+dea7hsmiless@users.noreply.github.com>2026-11-21 13:20:30 -0800
commit8d8ebee38415c28abcf29d23710be7c57b3e268b (patch)
tree3324e411301ab638215785f07b3574ab75d64a6d /runtime/test/loader_test.cpp
parent4e390e0871d7265e629b51aca8ff99a15a6a6845 (diff)
Loader: resolve forwarders to shimmed modules through the shim registry
A forwarder target is resolved through game_dir and System32, but not through shims::find, so a forwarder to xmem or d3d12_xs became an unimplemented thunk. Check the normalized module name against the shim registry first, as a direct import already does. A synthetic shim table and a forwarder-to-shim test cover it.
Diffstat (limited to 'runtime/test/loader_test.cpp')
-rw-r--r--runtime/test/loader_test.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp
index 6fd1dced4..96672d406 100644
--- a/runtime/test/loader_test.cpp
+++ b/runtime/test/loader_test.cpp
@@ -14,6 +14,7 @@
14#include <string> 14#include <string>
15#include <vector> 15#include <vector>
16 16
17#include "../shims/shims.h"
17#include "../src/pe_loader.h" 18#include "../src/pe_loader.h"
18 19
19namespace { 20namespace {
@@ -137,6 +138,12 @@ void* host_symbol(const char* dll, const char* name) {
137 return h ? reinterpret_cast<void*>(GetProcAddress(h, name)) : nullptr; 138 return h ? reinterpret_cast<void*>(GetProcAddress(h, name)) : nullptr;
138} 139}
139 140
141// A shim table for the forwarder test, so the test does not depend on the real xmem shim. Registering it at startup
142// exercises the same registry a packaged module reaches.
143int g_test_shim_target = 0;
144void* test_shim_function() { return &g_test_shim_target; }
145SHIM_TABLE(test_forwarder_shim, {"testshim.dll", "F", reinterpret_cast<void*>(&test_shim_function)});
146
140// 0 when the image loaded, 1 when it was rejected. A crash here is a test failure, which is the point. 147// 0 when the image loaded, 1 when it was rejected. A crash here is a test failure, which is the point.
141int load(const std::filesystem::path& p, std::string& error) { 148int load(const std::filesystem::path& p, std::string& error) {
142 try { 149 try {
@@ -583,6 +590,22 @@ void test_forwarded_exports() {
583 failed(what, e.what()); 590 failed(what, e.what());
584 } 591 }
585 } 592 }
593 {
594 const char* what = "a forwarder to a shimmed module binds to the shim";
595 write_image_as(make_forwarder_image("testshim.F", 0x180000000), "prov_shim.dll");
596 auto importer = write_image_as(make_import_image("prov_shim.dll", "fwd"), "importer_shim.exe");
597 try {
598 rt::Loader loader(g_dir);
599 rt::Module& m = loader.load(importer);
600 if (m.imports.size() != 1 || m.imports[0].binding != rt::Binding::Shim)
601 return failed(what, "the import did not bind as a shim");
602 if (*reinterpret_cast<void**>(m.base + 0x1180) != reinterpret_cast<void*>(&test_shim_function))
603 return failed(what, "the address table does not hold the shim function");
604 pass(what);
605 } catch (const std::exception& e) {
606 failed(what, e.what());
607 }
608 }
586} 609}
587 610
588void test_delay_descriptor_fields() { 611void test_delay_descriptor_fields() {