upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index 8865e6ddc..533a0264f 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -320,6 +320,16 @@ void redirect_pc_to_file_header(HMODULE host) {
320 } 320 }
321} 321}
322 322
323// The module a host import actually resolved into. GetProcAddress follows forwarders, so this can be another DLL
324// than the one imported (on Windows vcruntime140.dll implements _CxxThrowException itself); that module's
325// RtlPcToFileHeader import is the one the throw calls.
326void redirect_pc_to_file_header_at(const void* resolved) {
327 HMODULE owner = nullptr;
328 if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
329 static_cast<LPCWSTR>(resolved), &owner) && owner)
330 redirect_pc_to_file_header(owner);
331}
332
323} // namespace 333} // namespace
324 334
325namespace { 335namespace {
@@ -710,6 +720,7 @@ void* Loader::resolve_forwarder(const std::string& spec, Binding& binding, int d
710 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header(h); 720 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header(h);
711 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(static_cast<WORD>(ordinal)) : symbol.c_str()); 721 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(static_cast<WORD>(ordinal)) : symbol.c_str());
712 if (!p) return nullptr; 722 if (!p) return nullptr;
723 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header_at(reinterpret_cast<const void*>(p));
713 binding = Binding::Host; 724 binding = Binding::Host;
714 return reinterpret_cast<void*>(p); 725 return reinterpret_cast<void*>(p);
715} 726}
@@ -743,6 +754,7 @@ void* Loader::resolve(Module& m, const std::string& dll, const std::string& name
743 if (prefer_host_copy(key)) redirect_pc_to_file_header(h); // before any mapped code can throw through it 754 if (prefer_host_copy(key)) redirect_pc_to_file_header(h); // before any mapped code can throw through it
744 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(ordinal) : name.c_str()); 755 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(ordinal) : name.c_str());
745 if (p) { 756 if (p) {
757 if (prefer_host_copy(key)) redirect_pc_to_file_header_at(reinterpret_cast<const void*>(p));
746 m.imports.push_back({dll, sym, Binding::Host}); 758 m.imports.push_back({dll, sym, Binding::Host});
747 return reinterpret_cast<void*>(p); 759 return reinterpret_cast<void*>(p);
748 } 760 }