From 58d6f3b817562adb98e8450b35cdfd77fed9edce Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Wed, 4 Aug 2021 15:57:42 +0200 Subject: [PATCH] fix: search all loaded modules for symbols on Windows --- src/library/compiler/ir_interpreter.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/library/compiler/ir_interpreter.cpp b/src/library/compiler/ir_interpreter.cpp index f61fe4ca00..91dd9e7e4a 100644 --- a/src/library/compiler/ir_interpreter.cpp +++ b/src/library/compiler/ir_interpreter.cpp @@ -31,6 +31,7 @@ functions, which have a (relatively) homogeneous ABI that we can use without run #ifdef LEAN_WINDOWS #include #undef ERROR // thanks, wingdi.h +#include #else #include #endif @@ -286,7 +287,16 @@ void print_value(std::ostream & ios, value const & v, type t) { void * lookup_symbol_in_cur_exe(char const * sym) { #ifdef LEAN_WINDOWS - return reinterpret_cast(GetProcAddress(GetModuleHandle(nullptr), sym)); + HMODULE hmods[128]; // 128 modules should be enough for everyone + DWORD bytes_needed; + lean_always_assert(EnumProcessModules(GetCurrentProcess(), hmods, sizeof(hmods), &bytes_needed)); + for (int i = 0; i < bytes_needed / sizeof(HMODULE); i++) { + void * addr = reinterpret_cast(GetProcAddress(hmods[i], sym)); + if (addr) { + return addr; + } + } + return nullptr; #else return dlsym(RTLD_DEFAULT, sym); #endif