From: Mathieu Desnoyers Date: Wed, 24 Oct 2018 11:54:25 +0000 (-0400) Subject: Use __rseq_refcount symbol X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=1f7e39d3e152683e8a4afd3174263b4ad3f7a0c6;p=librseq.git Use __rseq_refcount symbol Signed-off-by: Mathieu Desnoyers --- diff --git a/include/rseq/rseq.h b/include/rseq/rseq.h index dd1199a..c45cd38 100644 --- a/include/rseq/rseq.h +++ b/include/rseq/rseq.h @@ -45,6 +45,7 @@ #endif extern __thread volatile struct rseq __rseq_abi; +extern __thread volatile uint32_t __rseq_refcount; #define rseq_likely(x) __builtin_expect(!!(x), 1) #define rseq_unlikely(x) __builtin_expect(!!(x), 0) diff --git a/src/rseq.c b/src/rseq.c index 172f4d9..a48f0e0 100644 --- a/src/rseq.c +++ b/src/rseq.c @@ -31,29 +31,13 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -/* - * linux/rseq.h defines struct rseq as aligned on 32 bytes. The kernel ABI - * size is 20 bytes. For support of multiple rseq users within a process, - * user-space defines an extra 4 bytes field as a reference count, for a - * total of 24 bytes. - */ -struct libc_rseq { - /* kernel-userspace ABI. */ - __u32 cpu_id_start; - __u32 cpu_id; - __u64 rseq_cs; - __u32 flags; - /* user-space ABI. */ - __u32 refcount; -} __attribute__((aligned(4 * sizeof(__u64)))); - -__attribute__((visibility("hidden"))) __thread -volatile struct libc_rseq __lib_rseq_abi = { +__attribute__((weak)) __thread +volatile struct rseq __rseq_abi = { .cpu_id = RSEQ_CPU_ID_UNINITIALIZED, }; -extern __attribute__((weak, alias("__lib_rseq_abi"))) __thread -volatile struct rseq __rseq_abi; +__attribute__((weak)) __thread +volatile uint32_t __rseq_refcount; static int sys_rseq(volatile struct rseq *rseq_abi, uint32_t rseq_len, int flags, uint32_t sig) @@ -104,11 +88,11 @@ int rseq_register_current_thread(void) sigset_t oldset; signal_off_save(&oldset); - if (__lib_rseq_abi.refcount == INT_MAX) { + if (__rseq_refcount == UINT_MAX) { ret = -1; goto end; } - if (__lib_rseq_abi.refcount++) + if (__rseq_refcount++) goto end; rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), 0, RSEQ_SIG); if (!rc) { @@ -118,7 +102,7 @@ int rseq_register_current_thread(void) if (errno != EBUSY) __rseq_abi.cpu_id = RSEQ_CPU_ID_REGISTRATION_FAILED; ret = -1; - __lib_rseq_abi.refcount--; + __rseq_refcount--; end: signal_restore(oldset); return ret; @@ -130,11 +114,11 @@ int rseq_unregister_current_thread(void) sigset_t oldset; signal_off_save(&oldset); - if (!__lib_rseq_abi.refcount) { + if (!__rseq_refcount) { ret = -1; goto end; } - if (--__lib_rseq_abi.refcount) + if (--__rseq_refcount) goto end; rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), RSEQ_FLAG_UNREGISTER, RSEQ_SIG);