12e155fb7SMathieu Desnoyers /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
22e155fb7SMathieu Desnoyers /*
32e155fb7SMathieu Desnoyers * rseq.h
42e155fb7SMathieu Desnoyers *
52e155fb7SMathieu Desnoyers * (C) Copyright 2016-2018 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
62e155fb7SMathieu Desnoyers */
72e155fb7SMathieu Desnoyers
82e155fb7SMathieu Desnoyers #ifndef RSEQ_H
92e155fb7SMathieu Desnoyers #define RSEQ_H
102e155fb7SMathieu Desnoyers
112e155fb7SMathieu Desnoyers #include <stdint.h>
122e155fb7SMathieu Desnoyers #include <stdbool.h>
132e155fb7SMathieu Desnoyers #include <pthread.h>
142e155fb7SMathieu Desnoyers #include <signal.h>
152e155fb7SMathieu Desnoyers #include <sched.h>
162e155fb7SMathieu Desnoyers #include <errno.h>
172e155fb7SMathieu Desnoyers #include <stdio.h>
182e155fb7SMathieu Desnoyers #include <stdlib.h>
19889c5d60SMathieu Desnoyers #include <stddef.h>
205c105d55SMathieu Desnoyers #include "rseq-abi.h"
21b53823fbSMathieu Desnoyers #include "compiler.h"
222e155fb7SMathieu Desnoyers
2399babd04SMathieu Desnoyers #ifndef rseq_sizeof_field
2499babd04SMathieu Desnoyers #define rseq_sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
2599babd04SMathieu Desnoyers #endif
2699babd04SMathieu Desnoyers
2799babd04SMathieu Desnoyers #ifndef rseq_offsetofend
2899babd04SMathieu Desnoyers #define rseq_offsetofend(TYPE, MEMBER) \
2999babd04SMathieu Desnoyers (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER))
3099babd04SMathieu Desnoyers #endif
3199babd04SMathieu Desnoyers
322e155fb7SMathieu Desnoyers /*
332e155fb7SMathieu Desnoyers * Empty code injection macros, override when testing.
342e155fb7SMathieu Desnoyers * It is important to consider that the ASM injection macros need to be
352e155fb7SMathieu Desnoyers * fully reentrant (e.g. do not modify the stack).
362e155fb7SMathieu Desnoyers */
372e155fb7SMathieu Desnoyers #ifndef RSEQ_INJECT_ASM
382e155fb7SMathieu Desnoyers #define RSEQ_INJECT_ASM(n)
392e155fb7SMathieu Desnoyers #endif
402e155fb7SMathieu Desnoyers
412e155fb7SMathieu Desnoyers #ifndef RSEQ_INJECT_C
422e155fb7SMathieu Desnoyers #define RSEQ_INJECT_C(n)
432e155fb7SMathieu Desnoyers #endif
442e155fb7SMathieu Desnoyers
452e155fb7SMathieu Desnoyers #ifndef RSEQ_INJECT_INPUT
462e155fb7SMathieu Desnoyers #define RSEQ_INJECT_INPUT
472e155fb7SMathieu Desnoyers #endif
482e155fb7SMathieu Desnoyers
492e155fb7SMathieu Desnoyers #ifndef RSEQ_INJECT_CLOBBER
502e155fb7SMathieu Desnoyers #define RSEQ_INJECT_CLOBBER
512e155fb7SMathieu Desnoyers #endif
522e155fb7SMathieu Desnoyers
532e155fb7SMathieu Desnoyers #ifndef RSEQ_INJECT_FAILED
542e155fb7SMathieu Desnoyers #define RSEQ_INJECT_FAILED
552e155fb7SMathieu Desnoyers #endif
562e155fb7SMathieu Desnoyers
57233e667eSMathieu Desnoyers #include "rseq-thread-pointer.h"
58233e667eSMathieu Desnoyers
59233e667eSMathieu Desnoyers /* Offset from the thread pointer to the rseq area. */
60889c5d60SMathieu Desnoyers extern ptrdiff_t rseq_offset;
6103f5c027SMathieu Desnoyers
6203f5c027SMathieu Desnoyers /*
6303f5c027SMathieu Desnoyers * Size of the registered rseq area. 0 if the registration was
6403f5c027SMathieu Desnoyers * unsuccessful.
6503f5c027SMathieu Desnoyers */
66233e667eSMathieu Desnoyers extern unsigned int rseq_size;
6703f5c027SMathieu Desnoyers
68233e667eSMathieu Desnoyers /* Flags used during rseq registration. */
69233e667eSMathieu Desnoyers extern unsigned int rseq_flags;
702e155fb7SMathieu Desnoyers
71ae315738SMathieu Desnoyers enum rseq_mo {
72ae315738SMathieu Desnoyers RSEQ_MO_RELAXED = 0,
73ae315738SMathieu Desnoyers RSEQ_MO_CONSUME = 1, /* Unused */
74ae315738SMathieu Desnoyers RSEQ_MO_ACQUIRE = 2, /* Unused */
75ae315738SMathieu Desnoyers RSEQ_MO_RELEASE = 3,
76ae315738SMathieu Desnoyers RSEQ_MO_ACQ_REL = 4, /* Unused */
77ae315738SMathieu Desnoyers RSEQ_MO_SEQ_CST = 5, /* Unused */
78ae315738SMathieu Desnoyers };
79ae315738SMathieu Desnoyers
80ae315738SMathieu Desnoyers enum rseq_percpu_mode {
81ae315738SMathieu Desnoyers RSEQ_PERCPU_CPU_ID = 0,
82ae315738SMathieu Desnoyers RSEQ_PERCPU_MM_CID = 1,
83ae315738SMathieu Desnoyers };
84ae315738SMathieu Desnoyers
rseq_get_abi(void)85e546cd48SMathieu Desnoyers static inline struct rseq_abi *rseq_get_abi(void)
86e546cd48SMathieu Desnoyers {
87233e667eSMathieu Desnoyers return (struct rseq_abi *) ((uintptr_t) rseq_thread_pointer() + rseq_offset);
88e546cd48SMathieu Desnoyers }
89e546cd48SMathieu Desnoyers
902e155fb7SMathieu Desnoyers #define rseq_likely(x) __builtin_expect(!!(x), 1)
912e155fb7SMathieu Desnoyers #define rseq_unlikely(x) __builtin_expect(!!(x), 0)
922e155fb7SMathieu Desnoyers #define rseq_barrier() __asm__ __volatile__("" : : : "memory")
932e155fb7SMathieu Desnoyers
942e155fb7SMathieu Desnoyers #define RSEQ_ACCESS_ONCE(x) (*(__volatile__ __typeof__(x) *)&(x))
952e155fb7SMathieu Desnoyers #define RSEQ_WRITE_ONCE(x, v) __extension__ ({ RSEQ_ACCESS_ONCE(x) = (v); })
962e155fb7SMathieu Desnoyers #define RSEQ_READ_ONCE(x) RSEQ_ACCESS_ONCE(x)
972e155fb7SMathieu Desnoyers
982e155fb7SMathieu Desnoyers #define __rseq_str_1(x) #x
992e155fb7SMathieu Desnoyers #define __rseq_str(x) __rseq_str_1(x)
1002e155fb7SMathieu Desnoyers
1012e155fb7SMathieu Desnoyers #define rseq_log(fmt, args...) \
1022e155fb7SMathieu Desnoyers fprintf(stderr, fmt "(in %s() at " __FILE__ ":" __rseq_str(__LINE__)"\n", \
1032e155fb7SMathieu Desnoyers ## args, __func__)
1042e155fb7SMathieu Desnoyers
1052e155fb7SMathieu Desnoyers #define rseq_bug(fmt, args...) \
1062e155fb7SMathieu Desnoyers do { \
1072e155fb7SMathieu Desnoyers rseq_log(fmt, ##args); \
1082e155fb7SMathieu Desnoyers abort(); \
1092e155fb7SMathieu Desnoyers } while (0)
1102e155fb7SMathieu Desnoyers
1112e155fb7SMathieu Desnoyers #if defined(__x86_64__) || defined(__i386__)
1122e155fb7SMathieu Desnoyers #include <rseq-x86.h>
1132e155fb7SMathieu Desnoyers #elif defined(__ARMEL__)
1142e155fb7SMathieu Desnoyers #include <rseq-arm.h>
115b9657463SWill Deacon #elif defined (__AARCH64EL__)
116b9657463SWill Deacon #include <rseq-arm64.h>
1172e155fb7SMathieu Desnoyers #elif defined(__PPC__)
1182e155fb7SMathieu Desnoyers #include <rseq-ppc.h>
119744f4be5SPaul Burton #elif defined(__mips__)
120744f4be5SPaul Burton #include <rseq-mips.h>
1214c14d1ceSVasily Gorbik #elif defined(__s390__)
1224c14d1ceSVasily Gorbik #include <rseq-s390.h>
1236d1a6f46SVincent Chen #elif defined(__riscv)
1246d1a6f46SVincent Chen #include <rseq-riscv.h>
1252e155fb7SMathieu Desnoyers #else
1262e155fb7SMathieu Desnoyers #error unsupported target
1272e155fb7SMathieu Desnoyers #endif
1282e155fb7SMathieu Desnoyers
1292e155fb7SMathieu Desnoyers /*
1302e155fb7SMathieu Desnoyers * Register rseq for the current thread. This needs to be called once
1312e155fb7SMathieu Desnoyers * by any thread which uses restartable sequences, before they start
1322e155fb7SMathieu Desnoyers * using restartable sequences, to ensure restartable sequences
1332e155fb7SMathieu Desnoyers * succeed. A restartable sequence executed from a non-registered
1342e155fb7SMathieu Desnoyers * thread will always fail.
1352e155fb7SMathieu Desnoyers */
1362e155fb7SMathieu Desnoyers int rseq_register_current_thread(void);
1372e155fb7SMathieu Desnoyers
1382e155fb7SMathieu Desnoyers /*
1392e155fb7SMathieu Desnoyers * Unregister rseq for current thread.
1402e155fb7SMathieu Desnoyers */
1412e155fb7SMathieu Desnoyers int rseq_unregister_current_thread(void);
1422e155fb7SMathieu Desnoyers
1432e155fb7SMathieu Desnoyers /*
1442e155fb7SMathieu Desnoyers * Restartable sequence fallback for reading the current CPU number.
1452e155fb7SMathieu Desnoyers */
1462e155fb7SMathieu Desnoyers int32_t rseq_fallback_current_cpu(void);
1472e155fb7SMathieu Desnoyers
1482e155fb7SMathieu Desnoyers /*
14999babd04SMathieu Desnoyers * Restartable sequence fallback for reading the current node number.
15099babd04SMathieu Desnoyers */
15199babd04SMathieu Desnoyers int32_t rseq_fallback_current_node(void);
15299babd04SMathieu Desnoyers
15399babd04SMathieu Desnoyers /*
1542e155fb7SMathieu Desnoyers * Values returned can be either the current CPU number, -1 (rseq is
1552e155fb7SMathieu Desnoyers * uninitialized), or -2 (rseq initialization has failed).
1562e155fb7SMathieu Desnoyers */
rseq_current_cpu_raw(void)1572e155fb7SMathieu Desnoyers static inline int32_t rseq_current_cpu_raw(void)
1582e155fb7SMathieu Desnoyers {
159e546cd48SMathieu Desnoyers return RSEQ_ACCESS_ONCE(rseq_get_abi()->cpu_id);
1602e155fb7SMathieu Desnoyers }
1612e155fb7SMathieu Desnoyers
1622e155fb7SMathieu Desnoyers /*
1632e155fb7SMathieu Desnoyers * Returns a possible CPU number, which is typically the current CPU.
1642e155fb7SMathieu Desnoyers * The returned CPU number can be used to prepare for an rseq critical
1652e155fb7SMathieu Desnoyers * section, which will confirm whether the cpu number is indeed the
1662e155fb7SMathieu Desnoyers * current one, and whether rseq is initialized.
1672e155fb7SMathieu Desnoyers *
1682e155fb7SMathieu Desnoyers * The CPU number returned by rseq_cpu_start should always be validated
1692e155fb7SMathieu Desnoyers * by passing it to a rseq asm sequence, or by comparing it to the
1702e155fb7SMathieu Desnoyers * return value of rseq_current_cpu_raw() if the rseq asm sequence
1712e155fb7SMathieu Desnoyers * does not need to be invoked.
1722e155fb7SMathieu Desnoyers */
rseq_cpu_start(void)1732e155fb7SMathieu Desnoyers static inline uint32_t rseq_cpu_start(void)
1742e155fb7SMathieu Desnoyers {
175e546cd48SMathieu Desnoyers return RSEQ_ACCESS_ONCE(rseq_get_abi()->cpu_id_start);
1762e155fb7SMathieu Desnoyers }
1772e155fb7SMathieu Desnoyers
rseq_current_cpu(void)1782e155fb7SMathieu Desnoyers static inline uint32_t rseq_current_cpu(void)
1792e155fb7SMathieu Desnoyers {
1802e155fb7SMathieu Desnoyers int32_t cpu;
1812e155fb7SMathieu Desnoyers
1822e155fb7SMathieu Desnoyers cpu = rseq_current_cpu_raw();
1832e155fb7SMathieu Desnoyers if (rseq_unlikely(cpu < 0))
1842e155fb7SMathieu Desnoyers cpu = rseq_fallback_current_cpu();
1852e155fb7SMathieu Desnoyers return cpu;
1862e155fb7SMathieu Desnoyers }
1872e155fb7SMathieu Desnoyers
rseq_node_id_available(void)18899babd04SMathieu Desnoyers static inline bool rseq_node_id_available(void)
18999babd04SMathieu Desnoyers {
190*a0cc6493SMathieu Desnoyers return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, node_id);
19199babd04SMathieu Desnoyers }
19299babd04SMathieu Desnoyers
19399babd04SMathieu Desnoyers /*
19499babd04SMathieu Desnoyers * Current NUMA node number.
19599babd04SMathieu Desnoyers */
rseq_current_node_id(void)19699babd04SMathieu Desnoyers static inline uint32_t rseq_current_node_id(void)
19799babd04SMathieu Desnoyers {
19899babd04SMathieu Desnoyers assert(rseq_node_id_available());
19999babd04SMathieu Desnoyers return RSEQ_ACCESS_ONCE(rseq_get_abi()->node_id);
20099babd04SMathieu Desnoyers }
20199babd04SMathieu Desnoyers
rseq_mm_cid_available(void)20218c23558SMathieu Desnoyers static inline bool rseq_mm_cid_available(void)
20318c23558SMathieu Desnoyers {
204*a0cc6493SMathieu Desnoyers return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, mm_cid);
20518c23558SMathieu Desnoyers }
20618c23558SMathieu Desnoyers
rseq_current_mm_cid(void)20718c23558SMathieu Desnoyers static inline uint32_t rseq_current_mm_cid(void)
20818c23558SMathieu Desnoyers {
20918c23558SMathieu Desnoyers return RSEQ_ACCESS_ONCE(rseq_get_abi()->mm_cid);
21018c23558SMathieu Desnoyers }
21118c23558SMathieu Desnoyers
rseq_clear_rseq_cs(void)212ec9c82e0SMathieu Desnoyers static inline void rseq_clear_rseq_cs(void)
213ec9c82e0SMathieu Desnoyers {
214e546cd48SMathieu Desnoyers RSEQ_WRITE_ONCE(rseq_get_abi()->rseq_cs.arch.ptr, 0);
215ec9c82e0SMathieu Desnoyers }
216ec9c82e0SMathieu Desnoyers
2172e155fb7SMathieu Desnoyers /*
2188a465801SMathieu Desnoyers * rseq_prepare_unload() should be invoked by each thread executing a rseq
2198a465801SMathieu Desnoyers * critical section at least once between their last critical section and
2202a1f40adSMathieu Desnoyers * library unload of the library defining the rseq critical section (struct
2212a1f40adSMathieu Desnoyers * rseq_cs) or the code referred to by the struct rseq_cs start_ip and
2222a1f40adSMathieu Desnoyers * post_commit_offset fields. This also applies to use of rseq in code
2232a1f40adSMathieu Desnoyers * generated by JIT: rseq_prepare_unload() should be invoked at least once by
2242a1f40adSMathieu Desnoyers * each thread executing a rseq critical section before reclaim of the memory
2252a1f40adSMathieu Desnoyers * holding the struct rseq_cs or reclaim of the code pointed to by struct
2262a1f40adSMathieu Desnoyers * rseq_cs start_ip and post_commit_offset fields.
2272e155fb7SMathieu Desnoyers */
rseq_prepare_unload(void)2282e155fb7SMathieu Desnoyers static inline void rseq_prepare_unload(void)
2292e155fb7SMathieu Desnoyers {
230ec9c82e0SMathieu Desnoyers rseq_clear_rseq_cs();
2312e155fb7SMathieu Desnoyers }
2322e155fb7SMathieu Desnoyers
233ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_cmpeqv_storev(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * v,intptr_t expect,intptr_t newv,int cpu)234ae315738SMathieu Desnoyers int rseq_cmpeqv_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
235ae315738SMathieu Desnoyers intptr_t *v, intptr_t expect,
236ae315738SMathieu Desnoyers intptr_t newv, int cpu)
237ae315738SMathieu Desnoyers {
238ae315738SMathieu Desnoyers if (rseq_mo != RSEQ_MO_RELAXED)
239ae315738SMathieu Desnoyers return -1;
240ae315738SMathieu Desnoyers switch (percpu_mode) {
241ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
242ae315738SMathieu Desnoyers return rseq_cmpeqv_storev_relaxed_cpu_id(v, expect, newv, cpu);
243ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
244ae315738SMathieu Desnoyers return rseq_cmpeqv_storev_relaxed_mm_cid(v, expect, newv, cpu);
245ae315738SMathieu Desnoyers }
246ae315738SMathieu Desnoyers return -1;
247ae315738SMathieu Desnoyers }
248ae315738SMathieu Desnoyers
249ae315738SMathieu Desnoyers /*
250ae315738SMathieu Desnoyers * Compare @v against @expectnot. When it does _not_ match, load @v
251ae315738SMathieu Desnoyers * into @load, and store the content of *@v + voffp into @v.
252ae315738SMathieu Desnoyers */
253ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_cmpnev_storeoffp_load(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * v,intptr_t expectnot,long voffp,intptr_t * load,int cpu)254ae315738SMathieu Desnoyers int rseq_cmpnev_storeoffp_load(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
255ae315738SMathieu Desnoyers intptr_t *v, intptr_t expectnot, long voffp, intptr_t *load,
256ae315738SMathieu Desnoyers int cpu)
257ae315738SMathieu Desnoyers {
258ae315738SMathieu Desnoyers if (rseq_mo != RSEQ_MO_RELAXED)
259ae315738SMathieu Desnoyers return -1;
260ae315738SMathieu Desnoyers switch (percpu_mode) {
261ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
262ae315738SMathieu Desnoyers return rseq_cmpnev_storeoffp_load_relaxed_cpu_id(v, expectnot, voffp, load, cpu);
263ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
264ae315738SMathieu Desnoyers return rseq_cmpnev_storeoffp_load_relaxed_mm_cid(v, expectnot, voffp, load, cpu);
265ae315738SMathieu Desnoyers }
266ae315738SMathieu Desnoyers return -1;
267ae315738SMathieu Desnoyers }
268ae315738SMathieu Desnoyers
269ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_addv(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * v,intptr_t count,int cpu)270ae315738SMathieu Desnoyers int rseq_addv(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
271ae315738SMathieu Desnoyers intptr_t *v, intptr_t count, int cpu)
272ae315738SMathieu Desnoyers {
273ae315738SMathieu Desnoyers if (rseq_mo != RSEQ_MO_RELAXED)
274ae315738SMathieu Desnoyers return -1;
275ae315738SMathieu Desnoyers switch (percpu_mode) {
276ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
277ae315738SMathieu Desnoyers return rseq_addv_relaxed_cpu_id(v, count, cpu);
278ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
279ae315738SMathieu Desnoyers return rseq_addv_relaxed_mm_cid(v, count, cpu);
280ae315738SMathieu Desnoyers }
281ae315738SMathieu Desnoyers return -1;
282ae315738SMathieu Desnoyers }
283ae315738SMathieu Desnoyers
284ae315738SMathieu Desnoyers #ifdef RSEQ_ARCH_HAS_OFFSET_DEREF_ADDV
285ae315738SMathieu Desnoyers /*
286ae315738SMathieu Desnoyers * pval = *(ptr+off)
287ae315738SMathieu Desnoyers * *pval += inc;
288ae315738SMathieu Desnoyers */
289ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_offset_deref_addv(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * ptr,long off,intptr_t inc,int cpu)290ae315738SMathieu Desnoyers int rseq_offset_deref_addv(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
291ae315738SMathieu Desnoyers intptr_t *ptr, long off, intptr_t inc, int cpu)
292ae315738SMathieu Desnoyers {
293ae315738SMathieu Desnoyers if (rseq_mo != RSEQ_MO_RELAXED)
294ae315738SMathieu Desnoyers return -1;
295ae315738SMathieu Desnoyers switch (percpu_mode) {
296ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
297ae315738SMathieu Desnoyers return rseq_offset_deref_addv_relaxed_cpu_id(ptr, off, inc, cpu);
298ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
299ae315738SMathieu Desnoyers return rseq_offset_deref_addv_relaxed_mm_cid(ptr, off, inc, cpu);
300ae315738SMathieu Desnoyers }
301ae315738SMathieu Desnoyers return -1;
302ae315738SMathieu Desnoyers }
303ae315738SMathieu Desnoyers #endif
304ae315738SMathieu Desnoyers
305ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_cmpeqv_trystorev_storev(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * v,intptr_t expect,intptr_t * v2,intptr_t newv2,intptr_t newv,int cpu)306ae315738SMathieu Desnoyers int rseq_cmpeqv_trystorev_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
307ae315738SMathieu Desnoyers intptr_t *v, intptr_t expect,
308ae315738SMathieu Desnoyers intptr_t *v2, intptr_t newv2,
309ae315738SMathieu Desnoyers intptr_t newv, int cpu)
310ae315738SMathieu Desnoyers {
311ae315738SMathieu Desnoyers switch (rseq_mo) {
312ae315738SMathieu Desnoyers case RSEQ_MO_RELAXED:
313ae315738SMathieu Desnoyers switch (percpu_mode) {
314ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
315ae315738SMathieu Desnoyers return rseq_cmpeqv_trystorev_storev_relaxed_cpu_id(v, expect, v2, newv2, newv, cpu);
316ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
317ae315738SMathieu Desnoyers return rseq_cmpeqv_trystorev_storev_relaxed_mm_cid(v, expect, v2, newv2, newv, cpu);
318ae315738SMathieu Desnoyers }
319ae315738SMathieu Desnoyers return -1;
320ae315738SMathieu Desnoyers case RSEQ_MO_RELEASE:
321ae315738SMathieu Desnoyers switch (percpu_mode) {
322ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
323ae315738SMathieu Desnoyers return rseq_cmpeqv_trystorev_storev_release_cpu_id(v, expect, v2, newv2, newv, cpu);
324ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
325ae315738SMathieu Desnoyers return rseq_cmpeqv_trystorev_storev_release_mm_cid(v, expect, v2, newv2, newv, cpu);
326ae315738SMathieu Desnoyers }
327ae315738SMathieu Desnoyers return -1;
328ae315738SMathieu Desnoyers default:
329ae315738SMathieu Desnoyers return -1;
330ae315738SMathieu Desnoyers }
331ae315738SMathieu Desnoyers }
332ae315738SMathieu Desnoyers
333ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_cmpeqv_cmpeqv_storev(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * v,intptr_t expect,intptr_t * v2,intptr_t expect2,intptr_t newv,int cpu)334ae315738SMathieu Desnoyers int rseq_cmpeqv_cmpeqv_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
335ae315738SMathieu Desnoyers intptr_t *v, intptr_t expect,
336ae315738SMathieu Desnoyers intptr_t *v2, intptr_t expect2,
337ae315738SMathieu Desnoyers intptr_t newv, int cpu)
338ae315738SMathieu Desnoyers {
339ae315738SMathieu Desnoyers if (rseq_mo != RSEQ_MO_RELAXED)
340ae315738SMathieu Desnoyers return -1;
341ae315738SMathieu Desnoyers switch (percpu_mode) {
342ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
343ae315738SMathieu Desnoyers return rseq_cmpeqv_cmpeqv_storev_relaxed_cpu_id(v, expect, v2, expect2, newv, cpu);
344ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
345ae315738SMathieu Desnoyers return rseq_cmpeqv_cmpeqv_storev_relaxed_mm_cid(v, expect, v2, expect2, newv, cpu);
346ae315738SMathieu Desnoyers }
347ae315738SMathieu Desnoyers return -1;
348ae315738SMathieu Desnoyers }
349ae315738SMathieu Desnoyers
350ae315738SMathieu Desnoyers static inline __attribute__((always_inline))
rseq_cmpeqv_trymemcpy_storev(enum rseq_mo rseq_mo,enum rseq_percpu_mode percpu_mode,intptr_t * v,intptr_t expect,void * dst,void * src,size_t len,intptr_t newv,int cpu)351ae315738SMathieu Desnoyers int rseq_cmpeqv_trymemcpy_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
352ae315738SMathieu Desnoyers intptr_t *v, intptr_t expect,
353ae315738SMathieu Desnoyers void *dst, void *src, size_t len,
354ae315738SMathieu Desnoyers intptr_t newv, int cpu)
355ae315738SMathieu Desnoyers {
356ae315738SMathieu Desnoyers switch (rseq_mo) {
357ae315738SMathieu Desnoyers case RSEQ_MO_RELAXED:
358ae315738SMathieu Desnoyers switch (percpu_mode) {
359ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
360ae315738SMathieu Desnoyers return rseq_cmpeqv_trymemcpy_storev_relaxed_cpu_id(v, expect, dst, src, len, newv, cpu);
361ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
362ae315738SMathieu Desnoyers return rseq_cmpeqv_trymemcpy_storev_relaxed_mm_cid(v, expect, dst, src, len, newv, cpu);
363ae315738SMathieu Desnoyers }
364ae315738SMathieu Desnoyers return -1;
365ae315738SMathieu Desnoyers case RSEQ_MO_RELEASE:
366ae315738SMathieu Desnoyers switch (percpu_mode) {
367ae315738SMathieu Desnoyers case RSEQ_PERCPU_CPU_ID:
368ae315738SMathieu Desnoyers return rseq_cmpeqv_trymemcpy_storev_release_cpu_id(v, expect, dst, src, len, newv, cpu);
369ae315738SMathieu Desnoyers case RSEQ_PERCPU_MM_CID:
370ae315738SMathieu Desnoyers return rseq_cmpeqv_trymemcpy_storev_release_mm_cid(v, expect, dst, src, len, newv, cpu);
371ae315738SMathieu Desnoyers }
372ae315738SMathieu Desnoyers return -1;
373ae315738SMathieu Desnoyers default:
374ae315738SMathieu Desnoyers return -1;
375ae315738SMathieu Desnoyers }
376ae315738SMathieu Desnoyers }
377ae315738SMathieu Desnoyers
3782e155fb7SMathieu Desnoyers #endif /* RSEQ_H_ */
379