[*] Simplified Win32 TLS callback overhead to prevent unwanted LoadLibraryW calls

(ive seen windows components do stupid things to result in crashes. time to harden.)
This commit is contained in:
Reece Wilson 2023-12-07 19:00:14 +00:00
parent ae70feb29b
commit ad5ff2d783
3 changed files with 48 additions and 1 deletions

View File

@ -73,6 +73,52 @@ namespace Aurora
return false; 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<decltype(p ## proc)>(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() void InitNTAddresses()
{ {
#if defined(AURORA_PLATFORM_WIN32) #if defined(AURORA_PLATFORM_WIN32)

View File

@ -44,6 +44,7 @@ enum _MINIDUMP_TYPE;
namespace Aurora namespace Aurora
{ {
void InitNTAddresses(); void InitNTAddresses();
void InitNTAddressesForClock();
static const wchar_t *kSyncDllName { L"API-MS-Win-Core-Synch-l1-2-0.dll" }; static const wchar_t *kSyncDllName { L"API-MS-Win-Core-Synch-l1-2-0.dll" };
static const wchar_t *kNtDllName { L"NTDLL.dll" }; static const wchar_t *kNtDllName { L"NTDLL.dll" };

View File

@ -156,7 +156,7 @@
static AuInitOnce gInitOnce; static AuInitOnce gInitOnce;
gInitOnce.Call([] gInitOnce.Call([]
{ {
Aurora::InitNTAddresses(); Aurora::InitNTAddressesForClock();
AuSwInfo::InitSwInfoEarly(); AuSwInfo::InitSwInfoEarly();
{ {