From dcddfddf5663294ece7a906bf52b086c3cde004d Mon Sep 17 00:00:00 2001 From: "yuri@FreeBSD" Date: Thu, 15 Aug 2024 20:38:07 -0700 Subject: [PATCH] Fix crash on FreeBSD due to incorrect thr_self system call invocation (#285) The correct signature is: int thr_self(long *id); It was called as thr_self() which caused memory corruption. --- src/libs/threading.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/threading.h b/src/libs/threading.h index e813df2b..fcd32e90 100644 --- a/src/libs/threading.h +++ b/src/libs/threading.h @@ -113,7 +113,9 @@ INLINE void us_thread_get_name(char *name) { // Always required for logging #if defined(__linux__) const pid_t tid = syscall(SYS_gettid); #elif defined(__FreeBSD__) - const pid_t tid = syscall(SYS_thr_self); + long id; + assert(!syscall(SYS_thr_self, &id)); + const pid_t tid = id; #elif defined(__OpenBSD__) const pid_t tid = syscall(SYS_getthrid); #elif defined(__NetBSD__)