diff options
| author | omardev29 <154835571+omardev29@users.noreply.github.com> | 2026-11-22 05:27:51 +0100 |
|---|---|---|
| committer | omardev29 <154835571+omardev29@users.noreply.github.com> | 2026-11-22 12:29:52 +0100 |
| commit | 5b9782f68d574b7774ea3dca794d1367bb52ba2a (patch) | |
| tree | 9f20803e1facef8ae9f5f07948cbe0b4ee0ec937 /runtime | |
| parent | 21b920bfb0579f242c2f1069971b238beaedeae6 (diff) | |
shims: mapped_image_base, the base of the mapped module holding an address
Answers from the same per-Loader lookups the unimplemented-import report uses,
under the same lock. Used by the next commit.
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/registry.cpp | 12 | ||||
| -rw-r--r-- | runtime/shims/shims.h | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/runtime/shims/registry.cpp b/runtime/shims/registry.cpp index d6f989fae..4c6a0d60b 100644 --- a/runtime/shims/registry.cpp +++ b/runtime/shims/registry.cpp | |||
| @@ -302,6 +302,18 @@ void add_module_lookup(void* ctx, ModuleLookup fn) { | |||
| 302 | g_lookups.push_back({ctx, fn}); | 302 | g_lookups.push_back({ctx, fn}); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | bool mapped_image_base(uint64_t address, uint64_t& base) { | ||
| 306 | std::string module; | ||
| 307 | uint32_t rva = 0; | ||
| 308 | std::lock_guard lock(g_lookup_mutex); | ||
| 309 | for (auto& l : g_lookups) | ||
| 310 | if (l.fn(l.ctx, address, module, rva)) { | ||
| 311 | base = address - rva; | ||
| 312 | return true; | ||
| 313 | } | ||
| 314 | return false; | ||
| 315 | } | ||
| 316 | |||
| 305 | void remove_module_lookup(void* ctx) { | 317 | void remove_module_lookup(void* ctx) { |
| 306 | std::lock_guard lock(g_lookup_mutex); | 318 | std::lock_guard lock(g_lookup_mutex); |
| 307 | for (auto it = g_lookups.begin(); it != g_lookups.end(); ++it) | 319 | for (auto it = g_lookups.begin(); it != g_lookups.end(); ++it) |
diff --git a/runtime/shims/shims.h b/runtime/shims/shims.h index 582a08686..6b9cf39d3 100644 --- a/runtime/shims/shims.h +++ b/runtime/shims/shims.h | |||
| @@ -52,6 +52,9 @@ using ModuleLookup = bool (*)(void* ctx, uint64_t address, std::string& module, | |||
| 52 | void add_module_lookup(void* ctx, ModuleLookup fn); | 52 | void add_module_lookup(void* ctx, ModuleLookup fn); |
| 53 | void remove_module_lookup(void* ctx); | 53 | void remove_module_lookup(void* ctx); |
| 54 | 54 | ||
| 55 | // The base of the mapped module holding `address`, through the same lookups. False if no live Loader maps it. | ||
| 56 | bool mapped_image_base(uint64_t address, uint64_t& base); | ||
| 57 | |||
| 55 | // Test seam: called at the top of every unimplemented-import call with the address of rt_unimplemented's return | 58 | // Test seam: called at the top of every unimplemented-import call with the address of rt_unimplemented's return |
| 56 | // address slot (so a test can check stack alignment) and from inside the call (so it can walk the stack). | 59 | // address slot (so a test can check stack alignment) and from inside the call (so it can walk the stack). |
| 57 | using TestHook = void (*)(const void* return_address_slot); | 60 | using TestHook = void (*)(const void* return_address_slot); |