diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-21 20:09:27 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-21 20:09:27 -0500 |
| commit | dcc4c1dceb40c275d5b3bdf6a859f11657c07516 (patch) | |
| tree | 32a850f0c3cb17f3ea6d37df1181e55bbba0aeb8 /runtime/src/pe_loader.cpp | |
| parent | 60e196519bd07315290cc7a2f2243247af435d74 (diff) | |
| parent | 7cfa4354fe8dc505afa95c575eb9224c37c90978 (diff) | |
Merge pull request #590 from AlxcBTW
Diffstat (limited to 'runtime/src/pe_loader.cpp')
| -rw-r--r-- | runtime/src/pe_loader.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
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) { | |||
| 131 | 131 | ||
| 132 | } // namespace | 132 | } // namespace |
| 133 | 133 | ||
| 134 | namespace { | ||
| 135 | bool lookup_in_loader(void* ctx, uint64_t address, std::string& module, uint32_t& rva) { | ||
| 136 | for (const Module* m : static_cast<Loader*>(ctx)->modules()) { | ||
| 137 | const auto base = reinterpret_cast<uint64_t>(m->base); | ||
| 138 | if (m->base && address >= base && address - base < m->size) { | ||
| 139 | module = m->name; | ||
| 140 | rva = static_cast<uint32_t>(address - base); | ||
| 141 | return true; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | return false; | ||
| 145 | } | ||
| 146 | } // namespace | ||
| 147 | |||
| 148 | Loader::Loader(std::filesystem::path game_dir) : game_dir_(std::move(game_dir)) { | ||
| 149 | shims::add_module_lookup(this, &lookup_in_loader); | ||
| 150 | } | ||
| 151 | |||
| 134 | Loader::~Loader() { | 152 | Loader::~Loader() { |
| 153 | shims::remove_module_lookup(this); | ||
| 135 | for (auto* m : order_) { | 154 | for (auto* m : order_) { |
| 136 | // TLS state must go away before the image and its TLS block are unmapped. | 155 | // TLS state must go away before the image and its TLS block are unmapped. |
| 137 | if (m->tls_index != kNoTlsIndex) { | 156 | if (m->tls_index != kNoTlsIndex) { |