Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: fix race condition with exception-based thread naming. #11257

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/thread/windows/SDL_systhread.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
#endif

#define SDL_DEBUGGER_NAME_EXCEPTION_CODE 0x406D1388

typedef void (__cdecl * SDL_EndThreadExCallback) (unsigned retval);
typedef uintptr_t (__cdecl * SDL_BeginThreadExCallback)
(void *security, unsigned stacksize, unsigned (__stdcall *startaddr)(void *),
Expand Down Expand Up @@ -97,10 +99,13 @@ typedef struct tagTHREADNAME_INFO
} THREADNAME_INFO;
#pragma pack(pop)

static LONG NTAPI EmptyVectoredExceptionHandler(EXCEPTION_POINTERS *ExceptionInfo)
static LONG NTAPI EmptyVectoredExceptionHandler(EXCEPTION_POINTERS *info)
{
(void)ExceptionInfo;
return EXCEPTION_CONTINUE_EXECUTION;
if (info != NULL && info->ExceptionRecord != NULL && info->ExceptionRecord->ExceptionCode == SDL_DEBUGGER_NAME_EXCEPTION_CODE) {
return EXCEPTION_CONTINUE_EXECUTION;
} else {
return EXCEPTION_CONTINUE_SEARCH;
}
}

typedef HRESULT(WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
Expand Down Expand Up @@ -148,7 +153,7 @@ void SDL_SYS_SetupThread(const char *name)
inf.dwFlags = 0;

// The debugger catches this, renames the thread, continues on.
RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR *)&inf);
RaiseException(SDL_DEBUGGER_NAME_EXCEPTION_CODE, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR *)&inf);
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
}
}
Expand Down
Loading