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:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 17:38:46 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 17:38:46 -0500
commite28fe7281b5094bba2fb279f3b37e8e49b82184d (patch)
tree4ebd5723afb5cd809f43c6fcf5360eabb7cb4fad /runtime/test/loader_test.cpp
parentfafcc4197b48ae13fa6ca59d38c16ef7432ae0de (diff)
parent8d8ebee38415c28abcf29d23710be7c57b3e268b (diff)
Merge pull request #191 from Dea7hsmiles
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() {