Fix rseq ext detection on x86 and RPI

This commit is contained in:
2026-05-24 16:43:24 -04:00
parent 9feadd0820
commit baa9b7b499
2 changed files with 24 additions and 9 deletions
+3
View File
@@ -1,3 +1,6 @@
cmake_minimum_required(VERSION 3.16)
project(buildmach CXX C)
option(COMPILE_CL_CHECKS "Compile CL checks" OFF)
option(COMPILE_PCL_TOOLS "Compile PCL-based validation tools" ON)
+21 -9
View File
@@ -1,4 +1,3 @@
#include <sys/prctl.h>
#include <cerrno>
#include <cinttypes>
#include <cstddef>
@@ -14,6 +13,12 @@
#include <sys/syscall.h>
#include <unistd.h>
#if defined(__x86_64__)
#ifndef ARCH_GET_FS
#define ARCH_GET_FS 0x1003
#endif
#endif
#ifndef PR_RSEQ_SLICE_EXTENSION
#define PR_RSEQ_SLICE_EXTENSION 79
#define PR_RSEQ_SLICE_EXTENSION_GET 1
@@ -54,14 +59,16 @@ extern __attribute__((weak)) unsigned int __rseq_size;
extern __attribute__((weak)) unsigned int __rseq_flags;
}
struct rseq_slice_ctrl_fields {
uint8_t request;
uint8_t granted;
uint16_t reserved;
};
struct rseq_slice_ctrl_compat {
union {
uint32_t all;
struct {
uint8_t request;
uint8_t granted;
uint16_t reserved;
};
rseq_slice_ctrl_fields parts;
};
};
@@ -74,7 +81,6 @@ struct rseq_compat {
uint32_t mm_cid;
struct rseq_slice_ctrl_compat slice_ctrl;
uint8_t reserved;
char end[];
} __attribute__((aligned(32)));
alignas(32) static thread_local unsigned char local_rseq_storage[512];
@@ -95,6 +101,12 @@ static int get_thread_pointer(uintptr_t *tp_out)
return -1;
*tp_out = fsbase;
return 0;
#elif defined(__aarch64__)
void *tp = nullptr;
__asm__ volatile("mrs %0, tpidr_el0" : "=r"(tp));
*tp_out = reinterpret_cast<uintptr_t>(tp);
return 0;
#else
(void) tp_out;
errno = ENOTSUP;
@@ -268,8 +280,8 @@ static void probe_slice_extension(void)
if (has_slice_ctrl) {
std::printf("slice_ctrl.request=%u granted=%u raw=0x%x\n",
g_registered_rseq_compat->slice_ctrl.request,
g_registered_rseq_compat->slice_ctrl.granted,
g_registered_rseq_compat->slice_ctrl.parts.request,
g_registered_rseq_compat->slice_ctrl.parts.granted,
g_registered_rseq_compat->slice_ctrl.all);
}