Replace direct usage of wrgsbase and rdgsbase with a more portable solution (#3464)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

This commit is contained in:
kalaposfos13 2025-08-27 12:12:39 +02:00 committed by GitHub
parent adcf4d9749
commit 10afc6b3c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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