From 8d8ebee38415c28abcf29d23710be7c57b3e268b Mon Sep 17 00:00:00 2001 From: Dea7hsmiles <188018312+dea7hsmiless@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:02:45 -0800 Subject: 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. --- runtime/src/pe_loader.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'runtime/src/pe_loader.cpp') diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index a0198c033..c04594c27 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp @@ -281,6 +281,16 @@ void* Loader::resolve_forwarder(const std::string& spec, Binding& binding, int d auto dot = spec.rfind('.'); if (dot == std::string::npos || dot == 0 || dot + 1 >= spec.size()) return nullptr; const std::string module = spec.substr(0, dot), symbol = spec.substr(dot + 1); + + // A forwarder can name a module the loader shims. Shims take precedence over a bundled or host copy, exactly as + // they do for a direct import in resolve(); without this, a forwarded xmem or d3d12_xs call becomes a failure thunk. + std::string shim_key = lower(module); + if (shim_key.size() < 4 || shim_key.compare(shim_key.size() - 4, 4, ".dll") != 0) shim_key += ".dll"; + if (void* p = shims::find(shim_key, symbol)) { + binding = Binding::Shim; + return p; + } + const bool by_ordinal = symbol.size() > 1 && symbol[0] == '#'; uint32_t ordinal = 0; if (by_ordinal) { -- cgit v1.2.3