Files
mandy/runtime/test/fixtures/dll_thread_calls.cpp
Sc4ros a83d28fbdb Tests: the no-CRT fixtures link in Debug
dll_thread_calls and tiny_tls_cb_only link with /NODEFAULTLIB, but the Visual Studio generator's Debug config compiles with /RTC1,
whose checks reference _RTC_InitBase and _RTC_Shutdown: LNK1120 in Debug. Both fixtures define the two as no-ops when
__MSVC_RUNTIME_CHECKS is set. Release and RelWithDebInfo are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 22:19:14 +01:00

25 lines
1.2 KiB
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>
#ifdef __MSVC_RUNTIME_CHECKS
// Debug builds compile with /RTC1 (the Visual Studio generator's default), whose checks call into the CRT; /NODEFAULTLIB
// leaves these unresolved (LNK1120). The checks have nothing to check here, so they do nothing.
extern "C" {
void __cdecl _RTC_InitBase() {}
void __cdecl _RTC_Shutdown() {}
}
#endif
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)));
}