]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix lock contention checker for MACOS
authorNeil Horman <nhorman@openssl.org>
Wed, 29 Oct 2025 15:45:03 +0000 (11:45 -0400)
committerNeil Horman <nhorman@openssl.org>
Tue, 4 Nov 2025 21:13:29 +0000 (16:13 -0500)
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ý <sashan@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/29031)

crypto/threads_pthread.c

index 9d9958e68fe0c6abe77d894a6b5db4db2dad3040..d3d92cf120c6090327fd76fdcfbf0c6bb9f12324 100644 (file)
@@ -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