diff options
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 23 |
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 | ||
| 19 | namespace { | 20 | namespace { |
| @@ -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. | ||
| 143 | int g_test_shim_target = 0; | ||
| 144 | void* test_shim_function() { return &g_test_shim_target; } | ||
| 145 | SHIM_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. |
| 141 | int load(const std::filesystem::path& p, std::string& error) { | 148 | int 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 | ||
| 588 | void test_delay_descriptor_fields() { | 611 | void test_delay_descriptor_fields() { |