Files
mandy/runtime/test/fixtures/dll_thread_calls.cpp
Sc4ros 4c9d995b26 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>
2026-11-22 17:52:04 +01:00

16 lines
846 B
C++

// A DLL whose DllMain returns the result of DisableThreadLibraryCalls(hinstance), the way the MSVC runtime's satellite
// DLLs do (msvcp140_1.dll, msvcp140_2.dll, msvcp140_atomic_wait.dll, msvcp140_codecvt_ids.dll). Built without the
// CRT, so nothing but this one call runs at DLL_PROCESS_ATTACH. dll_thread_calls_test maps it with the loader. No game
// data.
#include <windows.h>
extern "C" BOOL WINAPI dll_thread_calls_main(HINSTANCE instance, DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) return DisableThreadLibraryCalls(instance);
return TRUE;
}
// The same call on a handle that names no module: the answer must stay the Windows one (FALSE).
extern "C" __declspec(dllexport) BOOL dll_thread_calls_bogus_handle() {
return DisableThreadLibraryCalls(reinterpret_cast<HMODULE>(static_cast<uintptr_t>(0x10000)));
}