From ad5ff2d783ea796825d92a6ab84445f0f15900e9 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Thu, 7 Dec 2023 19:00:14 +0000 Subject: [PATCH] [*] Simplified Win32 TLS callback overhead to prevent unwanted LoadLibraryW calls (ive seen windows components do stupid things to result in crashes. time to harden.) --- Source/AuProcAddresses.NT.cpp | 46 +++++++++++++++++++++++++++++++++++ Source/AuProcAddresses.NT.hpp | 1 + Source/Time/AuClock.cpp | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Source/AuProcAddresses.NT.cpp b/Source/AuProcAddresses.NT.cpp index d0af3ae7..02e5ab09 100644 --- a/Source/AuProcAddresses.NT.cpp +++ b/Source/AuProcAddresses.NT.cpp @@ -73,6 +73,52 @@ namespace Aurora return false; } + void InitNTAddressesForClock() + { + #if defined(AURORA_PLATFORM_WIN32) + // We just need a partial AuSwInfo pass to work in order to setup the clocks at TLS callback-time + // Why? rng isnt ready either. We need the fallback clock to work. + pLoadLibraryW = LoadLibraryW; + pGetProcAddress = GetProcAddress; + + #define ADD_LOAD_LIB(name) \ + HMODULE h ## name {}; \ + h ## name = GetModuleHandleW(k## name ## DllName); \ + if (!h ## name) \ + { \ + h ## name = pLoadLibraryW(k## name ## DllName); \ + } \ + + #define ADD_GET_PROC(name, proc) \ + if (h ## name) \ + { \ + p ## proc = AuReinterpretCast(pGetProcAddress(h ## name, #proc)); \ + } \ + + ADD_LOAD_LIB(Kernel32); + #if 0 + ADD_LOAD_LIB(AdvancedApi); + #endif + + ADD_GET_PROC(Kernel32, VerifyVersionInfoW) + ADD_GET_PROC(Kernel32, VerSetConditionMask) + ADD_GET_PROC(Kernel32, QueryPerformanceCounter) + ADD_GET_PROC(Kernel32, QueryPerformanceFrequency) + + #if 0 + ADD_GET_PROC(AdvancedApi, RegSetValueExW) + ADD_GET_PROC(AdvancedApi, RegCloseKey) + ADD_GET_PROC(AdvancedApi, RegOpenKeyExW) + ADD_GET_PROC(AdvancedApi, RegQueryValueExW) + #endif + + #undef ADD_GET_PROC + #undef ADD_LOAD_LIB + #else + InitNTAddresses(); + #endif + } + void InitNTAddresses() { #if defined(AURORA_PLATFORM_WIN32) diff --git a/Source/AuProcAddresses.NT.hpp b/Source/AuProcAddresses.NT.hpp index f540042b..1e09e9e2 100644 --- a/Source/AuProcAddresses.NT.hpp +++ b/Source/AuProcAddresses.NT.hpp @@ -44,6 +44,7 @@ enum _MINIDUMP_TYPE; namespace Aurora { void InitNTAddresses(); + void InitNTAddressesForClock(); static const wchar_t *kSyncDllName { L"API-MS-Win-Core-Synch-l1-2-0.dll" }; static const wchar_t *kNtDllName { L"NTDLL.dll" }; diff --git a/Source/Time/AuClock.cpp b/Source/Time/AuClock.cpp index 996ea536..8fca0103 100644 --- a/Source/Time/AuClock.cpp +++ b/Source/Time/AuClock.cpp @@ -156,7 +156,7 @@ static AuInitOnce gInitOnce; gInitOnce.Call([] { - Aurora::InitNTAddresses(); + Aurora::InitNTAddressesForClock(); AuSwInfo::InitSwInfoEarly(); {