From b217dbb910966b402fe217e518718a8936e5ee3b Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Wed, 29 Oct 2025 11:45:03 -0400 Subject: [PATCH] Fix lock contention checker for MACOS MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The lock contention checker uses the gettid() syscall to get a unique thread id for each thread contending on a lock. While MACOS has this syscall, it does something completely different: https://elliotth.blogspot.com/2012/04/gettid-on-mac-os.html Resulting in -1 being returned for all threads. Use a macos specific call to get the thread id instead Fixes openssl/project#1699 Reviewed-by: Saša Nedvědický Reviewed-by: Tom Cosgrove (Merged from https://github.com/openssl/openssl/pull/29031) --- crypto/threads_pthread.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index 9d9958e68fe..d3d92cf120c 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -654,7 +654,19 @@ struct stack_traces { /* The glibc gettid() definition presents only since 2.30. */ static ossl_inline pid_t get_tid(void) { +# ifdef OPENSSL_SYS_MACOSX + /* + * MACOS has the gettid call, but it does something completely different + * here than on other unixes. Specifically it returns the uid of the calling thread + * (if set), or -1. We need to use a MACOS specific call to get the thread id here + */ + uint64_t tid; + + pthread_threadid_np(NULL, &tid); + return (pid_t)tid; +# else return syscall(SYS_gettid); +# endif } # ifdef FIPS_MODULE -- 2.47.3