diff options
| author | Sc4ros <353102343+Sc4ros@users.noreply.github.com> | 2026-11-22 17:52:04 +0100 |
|---|---|---|
| committer | Sc4ros <353102343+Sc4ros@users.noreply.github.com> | 2026-11-22 17:52:04 +0100 |
| commit | 4c9d995b2632d83480d8bb37965426958b4e47b9 (patch) | |
| tree | 12d497fc41c6d668c8a0f6e95fc267495f36f2d2 /runtime/shims/library_loader.cpp | |
| parent | 49475796c226c8511b9470bf97a4daf57b8af323 (diff) | |
Runtime: DisableThreadLibraryCalls from a mapped DllMain succeeds
The real DisableThreadLibraryCalls only accepts a module the Windows loader
mapped, so for a manually mapped image it returned FALSE. A DllMain that
returns its result (the MSVC runtime's msvcp140_1, msvcp140_2,
msvcp140_atomic_wait and msvcp140_codecvt_ids DLLs do) then made
Loader::initialise() throw "DllMain returned FALSE".
shims/library_loader.cpp serves the call next to FreeLibrary: TRUE for a
module the shims own or the loader mapped, the real function for any other
handle. New dll_thread_calls_test (CRT-free fixture DLL) fails on main and
passes with this change; docs/runtime_imports.md counts follow.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/library_loader.cpp')
| -rw-r--r-- | runtime/shims/library_loader.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/runtime/shims/library_loader.cpp b/runtime/shims/library_loader.cpp index b67a38660..2740089c9 100644 --- a/runtime/shims/library_loader.cpp +++ b/runtime/shims/library_loader.cpp | |||
| @@ -213,6 +213,16 @@ BOOL WINAPI free_library(HMODULE module) { | |||
| 213 | return FreeLibrary(module); | 213 | return FreeLibrary(module); |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | // DisableThreadLibraryCalls(hinstance) from a mapped image's DllMain. The real function only accepts a module the | ||
| 217 | // Windows loader mapped, so for ours it fails, and a DllMain that returns its result (the MSVC runtime's satellite DLLs | ||
| 218 | // do) fails Loader::initialise() with "DllMain returned FALSE". Owned and mapped modules answer TRUE. The loader sends | ||
| 219 | // no thread events to a DllMain, so there is nothing further to switch off; every other handle goes to the real function. | ||
| 220 | BOOL WINAPI disable_thread_calls(HMODULE module) { | ||
| 221 | if (pseudo(module)) return TRUE; | ||
| 222 | if (owns_bundled_module_handle(module)) return TRUE; | ||
| 223 | return DisableThreadLibraryCalls(module); | ||
| 224 | } | ||
| 225 | |||
| 216 | #define LOADER(dll) \ | 226 | #define LOADER(dll) \ |
| 217 | {dll, "LoadLibraryA", reinterpret_cast<void*>(&rt::shims::library_loader::load_library_a)}, \ | 227 | {dll, "LoadLibraryA", reinterpret_cast<void*>(&rt::shims::library_loader::load_library_a)}, \ |
| 218 | {dll, "LoadLibraryW", reinterpret_cast<void*>(&rt::shims::library_loader::load_library_w)}, \ | 228 | {dll, "LoadLibraryW", reinterpret_cast<void*>(&rt::shims::library_loader::load_library_w)}, \ |
| @@ -221,7 +231,7 @@ BOOL WINAPI free_library(HMODULE module) { | |||
| 221 | {dll, "GetModuleHandleA", reinterpret_cast<void*>(&rt::shims::library_loader::get_module_handle_a)}, \ | 231 | {dll, "GetModuleHandleA", reinterpret_cast<void*>(&rt::shims::library_loader::get_module_handle_a)}, \ |
| 222 | {dll, "GetModuleHandleW", reinterpret_cast<void*>(&rt::shims::library_loader::get_module_handle_w)}, \ | 232 | {dll, "GetModuleHandleW", reinterpret_cast<void*>(&rt::shims::library_loader::get_module_handle_w)}, \ |
| 223 | {dll, "GetProcAddress", reinterpret_cast<void*>(&rt::shims::library_loader::get_proc_address)}, \ | 233 | {dll, "GetProcAddress", reinterpret_cast<void*>(&rt::shims::library_loader::get_proc_address)}, \ |
| 224 | {dll, "FreeLibrary", reinterpret_cast<void*>(&rt::shims::library_loader::free_library)} | 234 | {dll, "FreeLibrary", reinterpret_cast<void*>(&rt::shims::library_loader::free_library)}, {dll, "DisableThreadLibraryCalls", reinterpret_cast<void*>(&rt::shims::library_loader::disable_thread_calls)} |
| 225 | 235 | ||
| 226 | } // namespace | 236 | } // namespace |
| 227 | } // namespace rt::shims::library_loader | 237 | } // namespace rt::shims::library_loader |