From 9c276e762a25262cd635e97f5aad4b09fa41b427 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 5 Jul 2024 11:36:26 +0900 Subject: [PATCH] Don't use ath_self, but get thread ID directly. * src/debug.c [HAVE_W32_SYSTEM or __linux] (tid_log_callback): Use native thread ID call for Windows and Linux, ifdef-out-ed. (debug_init): Only call gpgrt_log_set_pid_suffix_cb for relevant systems. -- Signed-off-by: NIIBE Yutaka --- src/debug.c | 25 +++++++++++++++++++++---- src/w32-util.c | 3 +-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/debug.c b/src/debug.c index b6dc4457..2a87305b 100644 --- a/src/debug.c +++ b/src/debug.c @@ -43,8 +43,12 @@ #endif #include +#ifdef HAVE_W32_SYSTEM +#include +#include +#endif + #include "util.h" -#include "ath.h" #include "sema.h" #include "sys-util.h" #include "debug.h" @@ -138,20 +142,31 @@ safe_to_use_debug_file (void) } +#if defined(HAVE_W32_SYSTEM) || defined(__linux) static int tid_log_callback (unsigned long *rvalue) { int len = sizeof (*rvalue); uintptr_t thread; - thread = ath_self (); +#ifdef HAVE_W32_SYSTEM + thread = (uintptr_t)GetCurrentThreadId (); +#elif defined(__linux) + thread = (uintptr_t)gettid (); +#endif if (sizeof (thread) < len) - len = sizeof (thread); + { + int zerolen = len; + + len = sizeof (thread); + zerolen -= len; + memset (rvalue + len, 0, zerolen); + } memcpy (rvalue, &thread, len); return 2; /* Use use hex representation. */ } - +#endif static void @@ -217,7 +232,9 @@ debug_init (void) | GPGRT_LOG_WITH_PID); gpgrt_log_set_prefix (*gpgrt_log_get_prefix (NULL)?NULL:"gpgme", flags); +#if defined(HAVE_W32_SYSTEM) || defined(__linux) gpgrt_log_set_pid_suffix_cb (tid_log_callback); +#endif } } diff --git a/src/w32-util.c b/src/w32-util.c index c661fb4b..1b805bdc 100644 --- a/src/w32-util.c +++ b/src/w32-util.c @@ -60,7 +60,6 @@ #include #include "util.h" -#include "ath.h" #include "sema.h" #include "debug.h" #include "sys-util.h" @@ -858,7 +857,7 @@ my_mkstemp (char *tmpl) random_time_bits = (((uint64_t)ft.dwHighDateTime << 32) | (uint64_t)ft.dwLowDateTime); } - value += random_time_bits ^ ath_self (); + value += random_time_bits ^ ((uintptr_t)GetCurrentThreadId ()); for (count = 0; count < attempts; value += 7777, ++count) {