From d60ca9aa383a604660d7a8e0bd19d27181cb5afc Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Mon, 4 Sep 2023 13:57:48 +0200 Subject: [PATCH] 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 --- glib/gthread-win32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c index 58e244ebe..afb3e5215 100644 --- a/glib/gthread-win32.c +++ b/glib/gthread-win32.c @@ -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? */