Replace direct usage of wrgsbase and rdgsbase with a more portable solution (#3464)

This commit is contained in:
kalaposfos13
2025-08-27 12:12:39 +02:00
committed by GitHub
parent adcf4d9749
commit 10afc6b3c6

View File

@@ -18,6 +18,10 @@
#elif !defined(ARCH_X86_64) #elif !defined(ARCH_X86_64)
#include <pthread.h> #include <pthread.h>
#endif #endif
#if defined(__linux__) && defined(ARCH_X86_64)
#include <asm/prctl.h>
#include <sys/prctl.h>
#endif
namespace Core { namespace Core {
@@ -156,13 +160,15 @@ Tcb* GetTcbBase() {
// Other POSIX x86_64 // Other POSIX x86_64
void SetTcbBase(void* image_address) { void SetTcbBase(void* image_address) {
asm volatile("wrgsbase %0" ::"r"(image_address) : "memory"); const int ret = syscall(SYS_arch_prctl, ARCH_SET_GS, (unsigned long)image_address);
ASSERT_MSG(ret == 0, "Failed to set GS base: errno {}", errno);
} }
Tcb* GetTcbBase() { Tcb* GetTcbBase() {
Tcb* tcb; void* tcb = nullptr;
asm volatile("rdgsbase %0" : "=r"(tcb)::"memory"); const int ret = syscall(SYS_arch_prctl, ARCH_GET_GS, &tcb);
return tcb; ASSERT_MSG(ret == 0, "Failed to get GS base: errno {}", errno);
return static_cast<Tcb*>(tcb);
} }
#else #else