From ac6dc2c2d3eb32443db798003274cbfbd0e4224f Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 18 Nov 2024 10:07:10 +0300 Subject: [PATCH] engine: platform: directly call __NR_gettid syscall for compatibility with older systems --- engine/platform/linux/sys_linux.c | 22 +++++++--------------- engine/platform/platform.h | 13 +++++++++---- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/engine/platform/linux/sys_linux.c b/engine/platform/linux/sys_linux.c index 6ec8f863..1788623e 100644 --- a/engine/platform/linux/sys_linux.c +++ b/engine/platform/linux/sys_linux.c @@ -26,32 +26,24 @@ GNU General Public License for more details. #include #include #include +#include #include "platform/platform.h" #include -#if defined( __GLIBC__ ) -#if ( __GLIBC__ <= 2 ) && ( __GLIBC_MINOR__ <= 30 ) -// Library support was added in glibc 2.30. -// Earlier glibc versions did not provide a wrapper for this system call, -// necessitating the use of syscall(2). -#include - -static pid_t gettid( void ) -{ - return syscall( SYS_gettid ); -} -#endif // ( __GLIBC__ <= 2 ) && ( __GLIBC_MINOR__ <= 30 ) - // Glibc misses this macro in POSIX headers (bits/types/sigevent_t.h) // but it does present in Linux headers (asm-generic/siginfo.h) and musl #if !defined( sigev_notify_thread_id ) #define sigev_notify_thread_id _sigev_un._tid #endif // !defined( sigev_notify_thread_id ) -#endif // defined(__GLIBC__) static void *g_hsystemd; static int (*g_pfn_sd_notify)( int unset_environment, const char *state ); +int Linux_GetProcessID( void ) +{ + return syscall( __NR_gettid ); +} + qboolean Platform_DebuggerPresent( void ) { char buf[4096]; @@ -163,7 +155,7 @@ void Linux_SetTimer( float tm ) // this path availiable in POSIX, but may signal wrong thread... // sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_notify = SIGEV_THREAD_ID; - sev.sigev_notify_thread_id = gettid(); + sev.sigev_notify_thread_id = Linux_GetProcessID(); sev.sigev_signo = DEBUG_TIMER_SIGNAL; sev.sigev_value.sival_ptr = &timerid; timer_create( CLOCK_REALTIME, &sev, &timerid ); diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 1605012d..fdbe9ea3 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -101,6 +101,7 @@ void DOS_Shutdown( void ); void Linux_Init( void ); void Linux_Shutdown( void ); void Linux_SetTimer( float time ); +int Linux_GetProcessID( void ); #endif static inline void Platform_Init( qboolean con_showalways ) @@ -287,10 +288,12 @@ qboolean VoiceCapture_Lock( qboolean lock ); #define INLINE_RAISE(x) asm volatile( "int $3;" ); #define INLINE_NANOSLEEP1() // nothing! #elif XASH_LINUX && XASH_ARM && !XASH_64BIT + #include + #include #define INLINE_RAISE(x) do \ { \ int raise_pid = getpid(); \ - int raise_tid = gettid(); \ + pid_t raise_tid = Linux_GetProcessID(); \ int raise_sig = (x); \ __asm__ volatile ( \ "mov r7,#268\n\t" \ @@ -318,10 +321,12 @@ qboolean VoiceCapture_Lock( qboolean lock ); ); \ } while( 0 ) #elif XASH_LINUX && XASH_ARM && XASH_64BIT + #include + #include #define INLINE_RAISE(x) do \ { \ int raise_pid = getpid(); \ - int raise_tid = gettid(); \ + pid_t raise_tid = Linux_GetProcessID(); \ int raise_sig = (x); \ __asm__ volatile ( \ "mov x8,#131\n\t" \ @@ -349,8 +354,8 @@ qboolean VoiceCapture_Lock( qboolean lock ); ); \ } while( 0 ) #elif XASH_LINUX - #ifdef __NR_tgkill - #define INLINE_RAISE(x) syscall( __NR_tgkill, getpid(), gettid(), x ) + #if defined( __NR_tgkill ) + #define INLINE_RAISE(x) syscall( __NR_tgkill, getpid(), Linux_GetProcessID(), x ) #else // __NR_tgkill #define INLINE_RAISE(x) raise(x) #endif // __NR_tgkill