engine: platform: directly call __NR_gettid syscall for compatibility with older systems

This commit is contained in:
Alibek Omarov 2024-11-18 10:07:10 +03:00
parent a29b6772b9
commit ac6dc2c2d3
2 changed files with 16 additions and 19 deletions

View file

@ -26,32 +26,24 @@ GNU General Public License for more details.
#include <time.h>
#include <unistd.h>
#include <math.h>
#include <sys/syscall.h>
#include "platform/platform.h"
#include <sys/types.h>
#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 <sys/syscall.h>
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 );

View file

@ -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 <sys/syscall.h>
#include <sys/types.h>
#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 <sys/syscall.h>
#include <sys/types.h>
#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