gthread-win32: Register fallback handler for thread name as last

Many ASAN implementations install Vectored Exception Handlers that
must be the first in the sequence. As we don't really care about
ordering, let's place our handler as last.

References:
 - https://developercommunity.visualstudio.com/t/asan-problems-when-manual-exception-handling/1242524
 - https://source.chromium.org/chromium/chromium/src/+/main:components/browser_watcher/extended_crash_reporting.cc;l=150;drc=4ced8912
This commit is contained in:
Luca Bacci 2023-09-04 13:57:48 +02:00
parent 69e2007f68
commit d60ca9aa38

View File

@ -681,7 +681,12 @@ g_thread_win32_init (void)
InitializeCriticalSection (&g_private_lock);
#ifndef _MSC_VER
SetThreadName_VEH_handle = AddVectoredExceptionHandler (1, &SetThreadName_VEH);
/* Set the handler as last to not interfere with ASAN runtimes.
* Many ASAN implementations (currently all three of GCC, CLANG
* and MSVC) install a Vectored Exception Handler that must be
* first in the sequence to work well
*/
SetThreadName_VEH_handle = AddVectoredExceptionHandler (0, &SetThreadName_VEH);
if (SetThreadName_VEH_handle == NULL)
{
/* This is bad, but what can we do? */