Windows: Call SetThreadStackGuarantee for all threads, not just main thread

This commit is contained in:
Jonathan G Rennison
2021-03-12 17:30:40 +00:00
parent 909e343f40
commit f53697ce76
6 changed files with 35 additions and 6 deletions

View File

@@ -219,6 +219,8 @@ void SetCurrentThreadName(const char *)
int GetCurrentThreadName(char *str, const char *last) { return 0; }
void SetSelfAsMainThread() { }
void PerThreadSetup() { }
void PerThreadSetupInit() { }
bool IsMainThread() { return false; }
bool IsNonMainThread() { return false; }

View File

@@ -256,6 +256,7 @@ int CDECL main(int argc, char *argv[])
argc = 1;
}
#endif
PerThreadSetupInit();
CrashLog::InitialiseCrashLog();
SetRandomSeed(time(nullptr));
@@ -348,6 +349,10 @@ void SetSelfAsMainThread()
#endif
}
void PerThreadSetup() { }
void PerThreadSetupInit() { }
bool IsMainThread()
{
#if !defined(NO_THREADS)

View File

@@ -725,12 +725,6 @@ static void CDECL CustomAbort(int signal)
if (LoadLibraryList((Function*)&AddVectoredExceptionHandler, "kernel32.dll\0AddVectoredExceptionHandler\0\0")) {
AddVectoredExceptionHandler(1, VectoredExceptionHandler);
}
BOOL (WINAPI *SetThreadStackGuarantee)(PULONG);
if (LoadLibraryList((Function*)&SetThreadStackGuarantee, "kernel32.dll\0SetThreadStackGuarantee\0\0")) {
ULONG stacksize = 65536;
SetThreadStackGuarantee(&stacksize);
}
}
/* static */ void CrashLog::DesyncCrashLog(const std::string *log_in, std::string *log_out, const DesyncExtraInfo &info)

View File

@@ -436,6 +436,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
/* Set system timer resolution to 1ms. */
timeBeginPeriod(1);
PerThreadSetupInit();
CrashLog::InitialiseCrashLog();
/* Convert the command line to UTF-8. We need a dedicated buffer
@@ -739,6 +740,21 @@ void SetSelfAsMainThread()
main_thread_id = GetCurrentThreadId();
}
static BOOL (WINAPI *_SetThreadStackGuarantee)(PULONG) = nullptr;
void PerThreadSetup()
{
if (_SetThreadStackGuarantee != nullptr) {
ULONG stacksize = 65536;
_SetThreadStackGuarantee(&stacksize);
}
}
void PerThreadSetupInit()
{
LoadLibraryList((Function*)&_SetThreadStackGuarantee, "kernel32.dll\0SetThreadStackGuarantee\0\0");
}
bool IsMainThread()
{
return main_thread_id == GetCurrentThreadId();