From baa9b7b4997e0f0445f059a54c31ea0874d4f31a Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sun, 24 May 2026 16:43:24 -0400 Subject: [PATCH] Fix rseq ext detection on x86 and RPI --- buildmach/CMakeLists.txt | 3 +++ buildmach/rseqsliceprobe.cpp | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/buildmach/CMakeLists.txt b/buildmach/CMakeLists.txt index 4ef829c..c16eae0 100644 --- a/buildmach/CMakeLists.txt +++ b/buildmach/CMakeLists.txt @@ -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) diff --git a/buildmach/rseqsliceprobe.cpp b/buildmach/rseqsliceprobe.cpp index dda6ae7..d41c655 100644 --- a/buildmach/rseqsliceprobe.cpp +++ b/buildmach/rseqsliceprobe.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -14,6 +13,12 @@ #include #include +#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(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); }