Last active
December 12, 2015 06:38
-
-
Save bionicbeagle/4730489 to your computer and use it in GitHub Desktop.
Cause of weird thread-naming crashes was... shitty x64 port!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct tagTHREADNAME_INFO | |
{ | |
DWORD dwType; // Must be 0x1000 | |
LPCSTR szName; // Pointer to name (in user address space) | |
DWORD dwThreadID; // Thread ID (-1 for caller thread) | |
DWORD dwFlags; // Reserved for future use; must be zero | |
} THREADNAME_INFO; | |
static void setThreadName(DWORD dwThreadID, LPCSTR szThreadName ) | |
{ | |
THREADNAME_INFO info; | |
info.dwType = 0x1000; | |
info.szName = szThreadName; | |
info.dwThreadID = dwThreadID; | |
info.dwFlags = 0; | |
__try | |
{ | |
#ifdef FB_X64 | |
RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); | |
// ------------------------------------------------^^^^^^^^^ this was DWORD! but | |
// the API counts pointer-sized arguments | |
// | |
#else | |
RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD *)&info ); | |
#endif | |
} | |
__except( EXCEPTION_CONTINUE_EXECUTION ) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment