From bcb9f6d5f24363a2ea9fc1e18c7538d39ea4d622 Mon Sep 17 00:00:00 2001 From: AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:46:33 +0100 Subject: runtime: LEONIDA_UNIMPLEMENTED=log|fail|stop policy for imports with no binding An unimplemented import used to return 0 silently, which is S_OK for an HRESULT function with its out parameters never written. The thunk now passes the caller's return address and rcx/rdx/r8/r9 to a shared stub, and LEONIDA_UNIMPLEMENTED picks the behaviour: - log (default): exactly as before. - fail: E_NOTIMPL for imports known to return HRESULT (D3D12Create*/Serialize*, CreateDXGIFactory*, XGameRuntimeInitialize, and the GDK XAsync/XTaskQueue/ XUser/XStore/XGameSave/XPackage/XGameUi families minus their documented void/bool/int functions), 0 otherwise. - stop: print the import, the caller as module+RVA and the four argument registers, then break under a debugger or exit with code 3. --dry-run now counts unimplemented imports by return class. The stub zeroes xmm0 and has unwind info, so float callers and debuggers are unaffected. unimplemented_policy_test builds a synthetic image and checks all three modes. Co-Authored-By: Claude Sonnet 5.5 --- runtime/src/pe_loader.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'runtime/src/pe_loader.cpp') diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index 9ac97239f..2d691862d 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp @@ -131,7 +131,26 @@ bool prefer_host_copy(const std::string& dll) { } // namespace +namespace { +bool lookup_in_loader(void* ctx, uint64_t address, std::string& module, uint32_t& rva) { + for (const Module* m : static_cast(ctx)->modules()) { + const auto base = reinterpret_cast(m->base); + if (m->base && address >= base && address - base < m->size) { + module = m->name; + rva = static_cast(address - base); + return true; + } + } + return false; +} +} // namespace + +Loader::Loader(std::filesystem::path game_dir) : game_dir_(std::move(game_dir)) { + shims::add_module_lookup(this, &lookup_in_loader); +} + Loader::~Loader() { + shims::remove_module_lookup(this); for (auto* m : order_) { // TLS state must go away before the image and its TLS block are unmapped. if (m->tls_index != kNoTlsIndex) { -- cgit v1.2.3