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:
authorNolan Cotter <186326284+NolanCotter@users.noreply.github.com>2026-11-22 20:39:59 -0700
committerNolan Cotter <186326284+NolanCotter@users.noreply.github.com>2026-11-22 20:39:59 -0700
commitfa5f26db8eafd2cc27f627b68c0a5a5949bcf2ff (patch)
treefc57e238be829295fc216dff89a6d93e64c16b50 /runtime/src/pe_loader.cpp
parent9b693ecd8a2f90799f6c47f8f06cf062feb9820c (diff)
parent7b7d73f890f9fbbf5967bbb694390bbc99e33ba6 (diff)
Merge origin/main: DXGI device fields coexist with the console-ABI device state
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index 278444c6f..3c7f9da08 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -529,15 +529,7 @@ void cleanup_tls_clones() { cleanup_tls_clones_internal(); }
529 529
530namespace { 530namespace {
531bool lookup_in_loader(void* ctx, uint64_t address, std::string& module, uint32_t& rva) { 531bool lookup_in_loader(void* ctx, uint64_t address, std::string& module, uint32_t& rva) {
532 for (const Module* m : static_cast<Loader*>(ctx)->modules()) { 532 return static_cast<Loader*>(ctx)->find_address(address, module, rva);
533 const auto base = reinterpret_cast<uint64_t>(m->base);
534 if (m->base && address >= base && address - base < m->size) {
535 module = m->name;
536 rva = static_cast<uint32_t>(address - base);
537 return true;
538 }
539 }
540 return false;
541} 533}
542 534
543void* bundled_find_loaded(void* ctx, const std::string& dll_lower) { 535void* bundled_find_loaded(void* ctx, const std::string& dll_lower) {
@@ -732,6 +724,18 @@ void* Loader::resolve_module_export(void* module_handle, const std::string& sym,
732 return nullptr; 724 return nullptr;
733} 725}
734 726
727bool Loader::find_address(uint64_t address, std::string& module, uint32_t& rva) const {
728 std::shared_lock lock(ranges_mutex_);
729 for (const MappedRange& r : ranges_) {
730 if (address >= r.base && address - r.base < r.size) {
731 module = r.name;
732 rva = static_cast<uint32_t>(address - r.base);
733 return true;
734 }
735 }
736 return false;
737}
738
735bool Loader::owns_module_handle(void* module_handle) const { 739bool Loader::owns_module_handle(void* module_handle) const {
736 if (!module_handle) return false; 740 if (!module_handle) return false;
737 std::lock_guard lock(mutex_); 741 std::lock_guard lock(mutex_);
@@ -873,6 +877,12 @@ Module& Loader::map_image(const std::filesystem::path& path) {
873 m->base = static_cast<uint8_t*>(VirtualAlloc(nullptr, oh.SizeOfImage, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); 877 m->base = static_cast<uint8_t*>(VirtualAlloc(nullptr, oh.SizeOfImage, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
874 if (!m->base) throw std::runtime_error(m->name + ": VirtualAlloc failed"); 878 if (!m->base) throw std::runtime_error(m->name + ": VirtualAlloc failed");
875 } 879 }
880 {
881 // From here an address inside the image names it. The memory stays until ~Loader, which unregisters the
882 // lookup first.
883 std::unique_lock lock(ranges_mutex_);
884 ranges_.push_back({reinterpret_cast<uint64_t>(m->base), m->size, m->name});
885 }
876 886
877 std::memcpy(m->base, file.data(), oh.SizeOfHeaders); 887 std::memcpy(m->base, file.data(), oh.SizeOfHeaders);
878 auto* sec = IMAGE_FIRST_SECTION(nt); 888 auto* sec = IMAGE_FIRST_SECTION(nt);