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)
/* 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