Fix rseq ext detection on x86 and RPI
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(buildmach CXX C)
|
||||||
|
|
||||||
option(COMPILE_CL_CHECKS "Compile CL checks" OFF)
|
option(COMPILE_CL_CHECKS "Compile CL checks" OFF)
|
||||||
option(COMPILE_PCL_TOOLS "Compile PCL-based validation tools" ON)
|
option(COMPILE_PCL_TOOLS "Compile PCL-based validation tools" ON)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <sys/prctl.h>
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@@ -14,6 +13,12 @@
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
#ifndef ARCH_GET_FS
|
||||||
|
#define ARCH_GET_FS 0x1003
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PR_RSEQ_SLICE_EXTENSION
|
#ifndef PR_RSEQ_SLICE_EXTENSION
|
||||||
#define PR_RSEQ_SLICE_EXTENSION 79
|
#define PR_RSEQ_SLICE_EXTENSION 79
|
||||||
#define PR_RSEQ_SLICE_EXTENSION_GET 1
|
#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;
|
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 {
|
struct rseq_slice_ctrl_compat {
|
||||||
union {
|
union {
|
||||||
uint32_t all;
|
uint32_t all;
|
||||||
struct {
|
rseq_slice_ctrl_fields parts;
|
||||||
uint8_t request;
|
|
||||||
uint8_t granted;
|
|
||||||
uint16_t reserved;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,7 +81,6 @@ struct rseq_compat {
|
|||||||
uint32_t mm_cid;
|
uint32_t mm_cid;
|
||||||
struct rseq_slice_ctrl_compat slice_ctrl;
|
struct rseq_slice_ctrl_compat slice_ctrl;
|
||||||
uint8_t reserved;
|
uint8_t reserved;
|
||||||
char end[];
|
|
||||||
} __attribute__((aligned(32)));
|
} __attribute__((aligned(32)));
|
||||||
|
|
||||||
alignas(32) static thread_local unsigned char local_rseq_storage[512];
|
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;
|
return -1;
|
||||||
*tp_out = fsbase;
|
*tp_out = fsbase;
|
||||||
return 0;
|
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
|
#else
|
||||||
(void) tp_out;
|
(void) tp_out;
|
||||||
errno = ENOTSUP;
|
errno = ENOTSUP;
|
||||||
@@ -268,8 +280,8 @@ static void probe_slice_extension(void)
|
|||||||
|
|
||||||
if (has_slice_ctrl) {
|
if (has_slice_ctrl) {
|
||||||
std::printf("slice_ctrl.request=%u granted=%u raw=0x%x\n",
|
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.parts.request,
|
||||||
g_registered_rseq_compat->slice_ctrl.granted,
|
g_registered_rseq_compat->slice_ctrl.parts.granted,
|
||||||
g_registered_rseq_compat->slice_ctrl.all);
|
g_registered_rseq_compat->slice_ctrl.all);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user