Introduce rseq-abi.h
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 23 Jan 2022 19:07:54 +0000 (14:07 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 24 Jan 2022 14:19:23 +0000 (09:19 -0500)
Introduce our own header for the rseq kernel ABI, so we do not depend on
Linux kernel headers.

Use this header's rseq_cs.arch.ptr field as accessor for the rseq_cs ptr
on 32-bit.

Remove the extra/ directory because the copy of the Linux kernel headers
is not needed anymore.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I0170f2bcaa7defd3a0d3f9a38115bc7d321ddde2

12 files changed:
extra/README [deleted file]
extra/linux/rseq.h [deleted file]
include/Makefile.am
include/rseq/rseq-abi.h [new file with mode: 0644]
include/rseq/rseq-arm.h
include/rseq/rseq-arm64.h
include/rseq/rseq-mips.h
include/rseq/rseq-ppc.h
include/rseq/rseq-s390.h
include/rseq/rseq-x86.h
include/rseq/rseq.h
src/rseq.c

diff --git a/extra/README b/extra/README
deleted file mode 100644 (file)
index f34f3b8..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-Kernel headers for test builds. Do not use for production builds.
-
-- linux/rseq.h
-
-  It is a copy from the upstream Linux v5.0 kernel uapi.
-
-  It also contains definitive system call number definitions for the rseq
-  system call, in case the kernel uapi headers are not recent enough
-  to define them.
diff --git a/extra/linux/rseq.h b/extra/linux/rseq.h
deleted file mode 100644 (file)
index 306a0ba..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
-#ifndef _UAPI_LINUX_RSEQ_H
-#define _UAPI_LINUX_RSEQ_H
-
-/*
- * linux/rseq.h
- *
- * Restartable sequences system call API
- *
- * Copyright (c) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#include <linux/types.h>
-#include <asm/byteorder.h>
-
-enum rseq_cpu_id_state {
-       RSEQ_CPU_ID_UNINITIALIZED               = -1,
-       RSEQ_CPU_ID_REGISTRATION_FAILED         = -2,
-};
-
-enum rseq_flags {
-       RSEQ_FLAG_UNREGISTER = (1 << 0),
-};
-
-enum rseq_cs_flags_bit {
-       RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT  = 0,
-       RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT   = 1,
-       RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT  = 2,
-};
-
-enum rseq_cs_flags {
-       RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT      =
-               (1U << RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
-       RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL       =
-               (1U << RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
-       RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE      =
-               (1U << RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
-};
-
-/*
- * struct rseq_cs is aligned on 4 * 8 bytes to ensure it is always
- * contained within a single cache-line. It is usually declared as
- * link-time constant data.
- */
-struct rseq_cs {
-       /* Version of this structure. */
-       __u32 version;
-       /* enum rseq_cs_flags */
-       __u32 flags;
-       __u64 start_ip;
-       /* Offset from start_ip. */
-       __u64 post_commit_offset;
-       __u64 abort_ip;
-} __attribute__((aligned(4 * sizeof(__u64))));
-
-/*
- * struct rseq is aligned on 4 * 8 bytes to ensure it is always
- * contained within a single cache-line.
- *
- * A single struct rseq per thread is allowed.
- */
-struct rseq {
-       /*
-        * Restartable sequences cpu_id_start field. Updated by the
-        * kernel. Read by user-space with single-copy atomicity
-        * semantics. This field should only be read by the thread which
-        * registered this data structure. Aligned on 32-bit. Always
-        * contains a value in the range of possible CPUs, although the
-        * value may not be the actual current CPU (e.g. if rseq is not
-        * initialized). This CPU number value should always be compared
-        * against the value of the cpu_id field before performing a rseq
-        * commit or returning a value read from a data structure indexed
-        * using the cpu_id_start value.
-        */
-       __u32 cpu_id_start;
-       /*
-        * Restartable sequences cpu_id field. Updated by the kernel.
-        * Read by user-space with single-copy atomicity semantics. This
-        * field should only be read by the thread which registered this
-        * data structure. Aligned on 32-bit. Values
-        * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED
-        * have a special semantic: the former means "rseq uninitialized",
-        * and latter means "rseq initialization failed". This value is
-        * meant to be read within rseq critical sections and compared
-        * with the cpu_id_start value previously read, before performing
-        * the commit instruction, or read and compared with the
-        * cpu_id_start value before returning a value loaded from a data
-        * structure indexed using the cpu_id_start value.
-        */
-       __u32 cpu_id;
-       /*
-        * Restartable sequences rseq_cs field.
-        *
-        * Contains NULL when no critical section is active for the current
-        * thread, or holds a pointer to the currently active struct rseq_cs.
-        *
-        * Updated by user-space, which sets the address of the currently
-        * active rseq_cs at the beginning of assembly instruction sequence
-        * block, and set to NULL by the kernel when it restarts an assembly
-        * instruction sequence block, as well as when the kernel detects that
-        * it is preempting or delivering a signal outside of the range
-        * targeted by the rseq_cs. Also needs to be set to NULL by user-space
-        * before reclaiming memory that contains the targeted struct rseq_cs.
-        *
-        * Read and set by the kernel. Set by user-space with single-copy
-        * atomicity semantics. This field should only be updated by the
-        * thread which registered this data structure. Aligned on 64-bit.
-        */
-       union {
-               __u64 ptr64;
-#ifdef __LP64__
-               __u64 ptr;
-#else
-               struct {
-#if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || defined(__BIG_ENDIAN)
-                       __u32 padding;          /* Initialized to zero. */
-                       __u32 ptr32;
-#else /* LITTLE */
-                       __u32 ptr32;
-                       __u32 padding;          /* Initialized to zero. */
-#endif /* ENDIAN */
-               } ptr;
-#endif
-       } rseq_cs;
-
-       /*
-        * Restartable sequences flags field.
-        *
-        * This field should only be updated by the thread which
-        * registered this data structure. Read by the kernel.
-        * Mainly used for single-stepping through rseq critical sections
-        * with debuggers.
-        *
-        * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT
-        *     Inhibit instruction sequence block restart on preemption
-        *     for this thread.
-        * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL
-        *     Inhibit instruction sequence block restart on signal
-        *     delivery for this thread.
-        * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE
-        *     Inhibit instruction sequence block restart on migration for
-        *     this thread.
-        */
-       __u32 flags;
-} __attribute__((aligned(4 * sizeof(__u64))));
-
-/*
- * Define the rseq system call number if not yet available in
- * the system headers.
- */
-#ifdef __x86_64__
-
-#ifndef __NR_rseq
-#define __NR_rseq              334
-#endif
-
-#elif defined(__i386__)
-
-#ifndef __NR_rseq
-#define __NR_rseq              386
-#endif
-
-#elif defined(__AARCH64EL__)
-
-#ifndef __NR_rseq
-#define __NR_rseq              293
-#endif
-
-#elif defined(__ARMEL__)
-
-#ifndef __NR_rseq
-#define __NR_rseq              398
-#endif
-
-#elif defined(__PPC__)
-
-#ifndef __NR_rseq
-#define __NR_rseq              387
-#endif
-
-#elif defined(__s390__)
-
-#ifndef __NR_rseq
-#define __NR_rseq              383
-#endif
-
-#endif
-
-#endif /* _UAPI_LINUX_RSEQ_H */
index ec68ae03f71fb986d344227e0a124be2fb813bc4..8e378132d20e7639b76e7e1e595166fc1c39317a 100644 (file)
@@ -6,6 +6,7 @@
 nobase_include_HEADERS = \
        rseq/compiler.h \
        rseq/rseq.h \
+       rseq/rseq-abi.h \
        rseq/rseq-arm.h \
        rseq/rseq-mips.h \
        rseq/rseq-ppc.h \
diff --git a/include/rseq/rseq-abi.h b/include/rseq/rseq-abi.h
new file mode 100644 (file)
index 0000000..4102d6e
--- /dev/null
@@ -0,0 +1,193 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef _RSEQ_ABI_H
+#define _RSEQ_ABI_H
+
+/*
+ * rseq/rseq-abi.h
+ *
+ * Restartable sequences system call API
+ *
+ * Copyright (c) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+enum rseq_abi_cpu_id_state {
+       RSEQ_ABI_CPU_ID_UNINITIALIZED                   = -1,
+       RSEQ_ABI_CPU_ID_REGISTRATION_FAILED             = -2,
+};
+
+enum rseq_abi_flags {
+       RSEQ_ABI_FLAG_UNREGISTER = (1 << 0),
+};
+
+enum rseq_abi_cs_flags_bit {
+       RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT      = 0,
+       RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT       = 1,
+       RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT      = 2,
+};
+
+enum rseq_abi_cs_flags {
+       RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT  =
+               (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
+       RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL   =
+               (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
+       RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE  =
+               (1U << RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
+};
+
+/*
+ * struct rseq_abi_cs is aligned on 4 * 8 bytes to ensure it is always
+ * contained within a single cache-line. It is usually declared as
+ * link-time constant data.
+ */
+struct rseq_abi_cs {
+       /* Version of this structure. */
+       __u32 version;
+       /* enum rseq_abi_cs_flags */
+       __u32 flags;
+       __u64 start_ip;
+       /* Offset from start_ip. */
+       __u64 post_commit_offset;
+       __u64 abort_ip;
+} __attribute__((aligned(4 * sizeof(__u64))));
+
+/*
+ * struct rseq_abi is aligned on 4 * 8 bytes to ensure it is always
+ * contained within a single cache-line.
+ *
+ * A single struct rseq_abi per thread is allowed.
+ */
+struct rseq_abi {
+       /*
+        * Restartable sequences cpu_id_start field. Updated by the
+        * kernel. Read by user-space with single-copy atomicity
+        * semantics. This field should only be read by the thread which
+        * registered this data structure. Aligned on 32-bit. Always
+        * contains a value in the range of possible CPUs, although the
+        * value may not be the actual current CPU (e.g. if rseq is not
+        * initialized). This CPU number value should always be compared
+        * against the value of the cpu_id field before performing a rseq
+        * commit or returning a value read from a data structure indexed
+        * using the cpu_id_start value.
+        */
+       __u32 cpu_id_start;
+       /*
+        * Restartable sequences cpu_id field. Updated by the kernel.
+        * Read by user-space with single-copy atomicity semantics. This
+        * field should only be read by the thread which registered this
+        * data structure. Aligned on 32-bit. Values
+        * RSEQ_CPU_ID_UNINITIALIZED and RSEQ_CPU_ID_REGISTRATION_FAILED
+        * have a special semantic: the former means "rseq uninitialized",
+        * and latter means "rseq initialization failed". This value is
+        * meant to be read within rseq critical sections and compared
+        * with the cpu_id_start value previously read, before performing
+        * the commit instruction, or read and compared with the
+        * cpu_id_start value before returning a value loaded from a data
+        * structure indexed using the cpu_id_start value.
+        */
+       __u32 cpu_id;
+       /*
+        * Restartable sequences rseq_cs field.
+        *
+        * Contains NULL when no critical section is active for the current
+        * thread, or holds a pointer to the currently active struct rseq_cs.
+        *
+        * Updated by user-space, which sets the address of the currently
+        * active rseq_cs at the beginning of assembly instruction sequence
+        * block, and set to NULL by the kernel when it restarts an assembly
+        * instruction sequence block, as well as when the kernel detects that
+        * it is preempting or delivering a signal outside of the range
+        * targeted by the rseq_cs. Also needs to be set to NULL by user-space
+        * before reclaiming memory that contains the targeted struct rseq_cs.
+        *
+        * Read and set by the kernel. Set by user-space with single-copy
+        * atomicity semantics. This field should only be updated by the
+        * thread which registered this data structure. Aligned on 64-bit.
+        */
+       union {
+               __u64 ptr64;
+
+               /*
+                * The "arch" field provides architecture accessor for
+                * the ptr field based on architecture pointer size and
+                * endianness.
+                */
+               struct {
+#ifdef __LP64__
+                       __u64 ptr;
+#elif defined(__BYTE_ORDER) ? (__BYTE_ORDER == __BIG_ENDIAN) : defined(__BIG_ENDIAN)
+                       __u32 padding;          /* Initialized to zero. */
+                       __u32 ptr;
+#else
+                       __u32 ptr;
+                       __u32 padding;          /* Initialized to zero. */
+#endif
+               } arch;
+       } rseq_cs;
+
+       /*
+        * Restartable sequences flags field.
+        *
+        * This field should only be updated by the thread which
+        * registered this data structure. Read by the kernel.
+        * Mainly used for single-stepping through rseq critical sections
+        * with debuggers.
+        *
+        * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_PREEMPT
+        *     Inhibit instruction sequence block restart on preemption
+        *     for this thread.
+        * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_SIGNAL
+        *     Inhibit instruction sequence block restart on signal
+        *     delivery for this thread.
+        * - RSEQ_ABI_CS_FLAG_NO_RESTART_ON_MIGRATE
+        *     Inhibit instruction sequence block restart on migration for
+        *     this thread.
+        */
+       __u32 flags;
+} __attribute__((aligned(4 * sizeof(__u64))));
+
+/*
+ * Define the rseq system call number if not yet available in
+ * the system headers.
+ */
+#ifdef __x86_64__
+
+#ifndef __NR_rseq
+#define __NR_rseq              334
+#endif
+
+#elif defined(__i386__)
+
+#ifndef __NR_rseq
+#define __NR_rseq              386
+#endif
+
+#elif defined(__AARCH64EL__)
+
+#ifndef __NR_rseq
+#define __NR_rseq              293
+#endif
+
+#elif defined(__ARMEL__)
+
+#ifndef __NR_rseq
+#define __NR_rseq              398
+#endif
+
+#elif defined(__PPC__)
+
+#ifndef __NR_rseq
+#define __NR_rseq              387
+#endif
+
+#elif defined(__s390__)
+
+#ifndef __NR_rseq
+#define __NR_rseq              383
+#endif
+
+#endif
+
+#endif /* _RSEQ_ABI_H */
index 975c2a4cf4620e0038a69316b52cba9f192cf66a..9645d8210f9095a4386639de42530d4d62ce0229 100644 (file)
@@ -60,8 +60,6 @@
 #define RSEQ_SIG    0xe7f5def3      /* udf    #24035    ; 0x5de3 */
 #endif
 
-#define RSEQ_CS_PTR    RSEQ_CS_PTR32
-
 #define rseq_smp_mb()  __asm__ __volatile__ ("dmb" ::: "memory", "cc")
 #define rseq_smp_rmb() __asm__ __volatile__ ("dmb" ::: "memory", "cc")
 #define rseq_smp_wmb() __asm__ __volatile__ ("dmb" ::: "memory", "cc")
@@ -185,7 +183,7 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
                  [newv]                "r" (newv)
@@ -256,7 +254,7 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expectnot]           "r" (expectnot),
@@ -318,7 +316,7 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [count]               "Ir" (count)
                  RSEQ_INJECT_INPUT
@@ -383,7 +381,7 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -460,7 +458,7 @@ int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -541,7 +539,7 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* cmp2 input */
                  [v2]                  "m" (*v2),
                  [expect2]             "r" (expect2),
@@ -663,7 +661,7 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
@@ -787,7 +785,7 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
index b0e60200fa938f3aba99eb40d98d8cc56792c34e..4511bec4c3bc6b928854a726b2f1cb77d5481465 100644 (file)
@@ -21,8 +21,6 @@
 
 #define RSEQ_SIG       RSEQ_SIG_DATA
 
-#define RSEQ_CS_PTR    rseq_cs.ptr
-
 #define rseq_smp_mb()  __asm__ __volatile__ ("dmb ish" ::: "memory")
 #define rseq_smp_rmb() __asm__ __volatile__ ("dmb ishld" ::: "memory")
 #define rseq_smp_wmb() __asm__ __volatile__ ("dmb ishst" ::: "memory")
@@ -233,7 +231,7 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "Qo" (*v),
                  [expect]              "r" (expect),
                  [newv]                "r" (newv)
@@ -294,7 +292,7 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "Qo" (*v),
                  [expectnot]           "r" (expectnot),
                  [load]                "Qo" (*load),
@@ -349,7 +347,7 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "Qo" (*v),
                  [count]               "r" (count)
                  RSEQ_INJECT_INPUT
@@ -403,7 +401,7 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [expect]              "r" (expect),
                  [v]                   "Qo" (*v),
                  [newv]                "r" (newv),
@@ -466,7 +464,7 @@ int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [expect]              "r" (expect),
                  [v]                   "Qo" (*v),
                  [newv]                "r" (newv),
@@ -531,7 +529,7 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "Qo" (*v),
                  [expect]              "r" (expect),
                  [v2]                  "Qo" (*v2),
@@ -597,7 +595,7 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [expect]              "r" (expect),
                  [v]                   "Qo" (*v),
                  [newv]                "r" (newv),
@@ -661,7 +659,7 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "Qo" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [expect]              "r" (expect),
                  [v]                   "Qo" (*v),
                  [newv]                "r" (newv),
index cb63c55defb8066e028389093fcc14f308e9b460..67cf908005e4676dc73866efbcc010e858f347c5 100644 (file)
@@ -71,7 +71,6 @@ do {                                                                  \
 # define LONG_S                        "sd"
 # define LONG_ADDI             "daddiu"
 # define U32_U64_PAD(x)                x
-# define RSEQ_CS_PTR           rseq_cs.ptr
 #elif _MIPS_SZLONG == 32
 # define LONG                  ".word"
 # define LONG_LA               "la"
@@ -83,7 +82,6 @@ do {                                                                  \
 # else
 #  define U32_U64_PAD(x)       x ", 0x0"
 # endif
-# define RSEQ_CS_PTR           RSEQ_CS_PTR32
 #else
 # error unsupported _MIPS_SZLONG
 #endif
@@ -190,7 +188,7 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
                  [newv]                "r" (newv)
@@ -254,7 +252,7 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expectnot]           "r" (expectnot),
@@ -311,7 +309,7 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [count]               "Ir" (count)
                  RSEQ_INJECT_INPUT
@@ -371,7 +369,7 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -441,7 +439,7 @@ int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -513,7 +511,7 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* cmp2 input */
                  [v2]                  "m" (*v2),
                  [expect2]             "r" (expect2),
@@ -626,7 +624,7 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
@@ -742,7 +740,7 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
index 22ca2e24328800f43531c54ae2a3170b4f77c980..10c92a3b628eb7886c502d110e6e8c7b5e08581a 100644 (file)
@@ -55,8 +55,6 @@ do {                                                                  \
 #define RSEQ_CMP_LONG          "cmpd "
 #define RSEQ_CMP_LONG_INT      "cmpdi "
 
-#define RSEQ_CS_PTR            rseq_cs.ptr
-
 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags,                         \
                        start_ip, post_commit_offset, abort_ip)                 \
                ".pushsection __rseq_cs, \"aw\"\n\t"                            \
@@ -102,8 +100,6 @@ do {                                                                        \
 #define RSEQ_CMP_LONG          "cmpw "
 #define RSEQ_CMP_LONG_INT      "cmpwi "
 
-#define RSEQ_CS_PTR            RSEQ_CS_PTR32
-
 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags,                         \
                        start_ip, post_commit_offset, abort_ip)                 \
                ".pushsection __rseq_cs, \"aw\"\n\t"                            \
@@ -246,7 +242,7 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
                  [newv]                "r" (newv)
@@ -317,7 +313,7 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expectnot]           "r" (expectnot),
@@ -380,7 +376,7 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [count]               "r" (count)
@@ -443,7 +439,7 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -518,7 +514,7 @@ int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -594,7 +590,7 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* cmp2 input */
                  [v2]                  "m" (*v2),
                  [expect2]             "r" (expect2),
@@ -675,7 +671,7 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
@@ -756,7 +752,7 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
index 94eb55f82f40aac3046ebcb49a6f31e9ecbf67d4..7b1e351d8c6f400ed14d3b179b8752766c5c896c 100644 (file)
@@ -34,8 +34,6 @@ do {                                                                  \
 
 #ifdef __s390x__
 
-#define RSEQ_CS_PTR            rseq_cs.ptr
-
 #define LONG_L                 "lg"
 #define LONG_S                 "stg"
 #define LONG_LT_R              "ltgr"
@@ -71,8 +69,6 @@ do {                                                                  \
 
 #elif __s390__
 
-#define RSEQ_CS_PTR            RSEQ_CS_PTR32
-
 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags,                 \
                                start_ip, post_commit_offset, abort_ip) \
                ".pushsection __rseq_cs, \"aw\"\n\t"                    \
@@ -170,7 +166,7 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
                  [newv]                "r" (newv)
@@ -243,7 +239,7 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expectnot]           "r" (expectnot),
@@ -303,7 +299,7 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [count]               "r" (count)
@@ -365,7 +361,7 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -449,7 +445,7 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* cmp2 input */
                  [v2]                  "m" (*v2),
                  [expect2]             "r" (expect2),
@@ -563,7 +559,7 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
                  [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
-                 [rseq_cs]             "m" (rseq_get_abi()->RSEQ_CS_PTR),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
index 7e0417fa773805904bc46988b647b984615786c7..0bd472d5edee6d3c6fdade486901fd127715479d 100644 (file)
@@ -23,7 +23,7 @@
  * (TODO: revisit after migration to glibc's ABI)
  */
 
-/* Offset of cpu_id and rseq_cs fields in struct rseq. */
+/* Offset of cpu_id and rseq_cs fields in struct rseq_abi. */
 #define RSEQ_CPU_ID_OFFSET     4
 #define RSEQ_CS_OFFSET         8
 
index 061e82a7390d7f4ec9a874f07f651a5ee8a969d5..8e58139919b4e04aa6b97ee0f3ea7d8dde452cb9 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <sched.h>
-#include <linux/rseq.h>
+#include <rseq/rseq-abi.h>
 #include <rseq/compiler.h>
 
-/* Work-around rseq.h uapi bug wrt endianness on little endian. */
-#if !(defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN))
-# if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || defined(__BIG_ENDIAN)
-/* Kernel uapi mistakenly orders padding vs ptr32. */
-#  define RSEQ_CS_PTR32        rseq_cs.ptr.padding
-# endif
-#endif
-
-#ifndef RSEQ_CS_PTR32
-# define RSEQ_CS_PTR32 rseq_cs.ptr.ptr32
-#endif
-
 /*
  * Empty code injection macros, override when testing.
  * It is important to consider that the ASM injection macros need to be
@@ -79,9 +67,9 @@ extern unsigned int rseq_size;
 /* Flags used during rseq registration.  */
 extern unsigned int rseq_flags;
 
-static inline struct rseq *rseq_get_abi(void)
+static inline struct rseq_abi *rseq_get_abi(void)
 {
-       return (struct rseq *) ((uintptr_t) rseq_thread_pointer() + rseq_offset);
+       return (struct rseq_abi *) ((uintptr_t) rseq_thread_pointer() + rseq_offset);
 }
 
 # ifdef __cplusplus
@@ -189,21 +177,17 @@ static inline uint32_t rseq_current_cpu(void)
 
 static inline void rseq_clear_rseq_cs(void)
 {
-#ifdef __LP64__
-       RSEQ_WRITE_ONCE(rseq_get_abi()->rseq_cs.ptr, 0);
-#else
-       RSEQ_WRITE_ONCE(rseq_get_abi()->RSEQ_CS_PTR32, 0);
-#endif
+       RSEQ_WRITE_ONCE(rseq_get_abi()->rseq_cs.arch.ptr, 0);
 }
 
 /*
  * rseq_prepare_unload() should be invoked by each thread executing a rseq
  * critical section at least once between their last critical section and
  * library unload of the library defining the rseq critical section
- * (struct rseq_cs). This also applies to use of rseq in code generated by
+ * (struct rseq_ab_cs). This also applies to use of rseq in code generated by
  * JIT: rseq_prepare_unload() should be invoked at least once by each
  * thread executing a rseq critical section before reclaim of the memory
- * holding the struct rseq_cs.
+ * holding the struct rseq_abi_cs.
  */
 static inline void rseq_prepare_unload(void)
 {
index 54e080f44f1c64610569b86a96a6fd48ed8150b2..a122da25a1371ede32059e4184ddb521f6ac3a00 100644 (file)
@@ -50,11 +50,11 @@ unsigned int rseq_flags;
 static int rseq_ownership;
 
 static
-__thread struct rseq __rseq_abi __attribute__((tls_model("initial-exec"))) = {
-       .cpu_id = RSEQ_CPU_ID_UNINITIALIZED,
+__thread struct rseq_abi __rseq_abi __attribute__((tls_model("initial-exec"))) = {
+       .cpu_id = RSEQ_ABI_CPU_ID_UNINITIALIZED,
 };
 
-static int sys_rseq(struct rseq *rseq_abi, uint32_t rseq_len,
+static int sys_rseq(struct rseq_abi *rseq_abi, uint32_t rseq_len,
                    int flags, uint32_t sig)
 {
        return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
@@ -85,7 +85,7 @@ int rseq_register_current_thread(void)
                /* Treat libc's ownership as a successful registration. */
                return 0;
        }
-       rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), 0, RSEQ_SIG);
+       rc = sys_rseq(&__rseq_abi, sizeof(struct rseq_abi), 0, RSEQ_SIG);
        if (rc)
                return -1;
        assert(rseq_current_cpu_raw() >= 0);
@@ -100,7 +100,7 @@ int rseq_unregister_current_thread(void)
                /* Treat libc's ownership as a successful unregistration. */
                return 0;
        }
-       rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
+       rc = sys_rseq(&__rseq_abi, sizeof(struct rseq_abi), RSEQ_ABI_FLAG_UNREGISTER, RSEQ_SIG);
        if (rc)
                return -1;
        return 0;
@@ -123,7 +123,7 @@ void rseq_init(void)
                return;
        rseq_ownership = 1;
        rseq_offset = (void *)&__rseq_abi - rseq_thread_pointer();
-       rseq_size = sizeof(struct rseq);
+       rseq_size = sizeof(struct rseq_abi);
        rseq_flags = 0;
 }
 
This page took 0.065908 seconds and 4 git commands to generate.