INCLUDES=$(wildcard include/rseq/*.h)
-librseq.so: src/rseq.c src/cpu-op.c ${INCLUDES}
+librseq.so: src/rseq.c src/cpu-op.c src/percpu-op.c ${INCLUDES}
$(CC) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) -shared -fpic \
- src/rseq.c src/cpu-op.c -o $@
+ src/rseq.c src/cpu-op.c src/percpu-op.c -o $@
.PHONY: clean install uninstall
int cpu_opv(struct cpu_op *cpuopv, int cpuopcnt, int cpu, int flags);
int cpu_op_get_current_cpu(void);
+int cpu_op_available(void);
int cpu_op_cmpxchg(void *v, void *expect, void *old, void *_new, size_t len,
int cpu);
#include <rseq/rseq.h>
#include <rseq/cpu-op.h>
+int percpu_op_available(void);
+
static inline __attribute__((always_inline))
int percpu_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv,
int cpu)
*/
int32_t rseq_fallback_current_cpu(void);
+int rseq_available(void);
+
/*
* Values returned can be either the current CPU number, -1 (rseq is
* uninitialized), or -2 (rseq initialization has failed).
return syscall(__NR_cpu_opv, cpu_opv, cpuopcnt, cpu, flags);
}
+int cpu_op_available(void)
+{
+ int rc;
+
+ rc = cpu_opv(NULL, 0, 0, CPU_OP_NR_FLAG);
+ if (rc >= 0)
+ return 1;
+ return 0;
+}
+
int cpu_op_get_current_cpu(void)
{
int cpu;
--- /dev/null
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * percpu-op.c
+ *
+ * Copyright (C) 2017 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#define _GNU_SOURCE
+#include <rseq/rseq.h>
+#include <rseq/cpu-op.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#define RSEQ_FLAG_UNDEFINED 0x80000000
+
/*
* 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,
extern __attribute__((weak, alias("__lib_rseq_abi"))) __thread
volatile struct rseq __rseq_abi;
+static int sys_rseq(volatile struct rseq *rseq_abi, uint32_t rseq_len,
+ int flags, uint32_t sig)
+{
+ return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
+}
+
+int rseq_available(void)
+{
+ int rc;
+
+ rc = sys_rseq(NULL, 0, RSEQ_FLAG_UNDEFINED, 0);
+ if (rc != -1)
+ abort();
+ switch (errno) {
+ case ENOSYS:
+ return 0;
+ case EINVAL:
+ return 1;
+ default:
+ abort();
+ }
+}
+
static void signal_off_save(sigset_t *oldset)
{
sigset_t set;
abort();
}
-static int sys_rseq(volatile struct rseq *rseq_abi, uint32_t rseq_len,
- int flags, uint32_t sig)
-{
- return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
-}
-
int rseq_register_current_thread(void)
{
int rc, ret = 0;