diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 01:46:33 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 01:46:33 +0100 |
| commit | bcb9f6d5f24363a2ea9fc1e18c7538d39ea4d622 (patch) | |
| tree | 229f22fcf89d9540426e230bab25dd2659017065 /runtime/src/main.cpp | |
| parent | 91b36cf86cb92a95836eed8af73abc0671a61e31 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 8fbc8dc4b..8e2ac0b03 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -73,7 +73,7 @@ int wmain(int argc, wchar_t** argv) { | |||
| 73 | loader.initialise(); // TLS callbacks, then DllMain(DLL_PROCESS_ATTACH) for DLLs | 73 | loader.initialise(); // TLS callbacks, then DllMain(DLL_PROCESS_ATTACH) for DLLs |
| 74 | std::printf("%zu module(s) initialised\n", loader.modules().size()); | 74 | std::printf("%zu module(s) initialised\n", loader.modules().size()); |
| 75 | } | 75 | } |
| 76 | int unimplemented = 0; | 76 | int unimplemented = 0, unimplemented_hresult = 0; |
| 77 | for (auto* m : loader.modules()) { | 77 | for (auto* m : loader.modules()) { |
| 78 | std::map<rt::Binding, int> counts; | 78 | std::map<rt::Binding, int> counts; |
| 79 | for (auto& r : m->imports) counts[r.binding]++; | 79 | for (auto& r : m->imports) counts[r.binding]++; |
| @@ -83,11 +83,18 @@ int wmain(int argc, wchar_t** argv) { | |||
| 83 | counts[rt::Binding::Unimplemented]); | 83 | counts[rt::Binding::Unimplemented]); |
| 84 | for (auto& r : m->imports) | 84 | for (auto& r : m->imports) |
| 85 | if (r.binding == rt::Binding::Unimplemented || r.binding == rt::Binding::Shim) { | 85 | if (r.binding == rt::Binding::Unimplemented || r.binding == rt::Binding::Shim) { |
| 86 | std::printf(" %-13s %s!%s\n", binding_name(r.binding), r.dll.c_str(), r.name.c_str()); | 86 | const bool missing = r.binding == rt::Binding::Unimplemented; |
| 87 | unimplemented += r.binding == rt::Binding::Unimplemented; | 87 | const bool hresult = |
| 88 | missing && rt::shims::classify_import(r.dll, r.name) == rt::shims::ReturnClass::HResult; | ||
| 89 | std::printf(" %-13s %s!%s%s\n", binding_name(r.binding), r.dll.c_str(), r.name.c_str(), | ||
| 90 | hresult ? " [returns HRESULT]" : ""); | ||
| 91 | unimplemented += missing; | ||
| 92 | unimplemented_hresult += hresult; | ||
| 88 | } | 93 | } |
| 89 | } | 94 | } |
| 90 | std::printf("%zu module(s) mapped, %d unimplemented import(s)\n", loader.modules().size(), unimplemented); | 95 | std::printf("%zu module(s) mapped, %d unimplemented import(s)\n", loader.modules().size(), unimplemented); |
| 96 | std::printf("unimplemented by return policy: hresult=%d other=%d\n", unimplemented_hresult, | ||
| 97 | unimplemented - unimplemented_hresult); | ||
| 91 | if (!run) return 0; | 98 | if (!run) return 0; |
| 92 | if (!main_module.entry_rva) { | 99 | if (!main_module.entry_rva) { |
| 93 | std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); | 100 | std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); |