1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
3 * Select the instruction "csrw mhartid, x0" as the RSEQ_SIG. Unlike
4 * other architectures, the ebreak instruction has no immediate field for
5 * distinguishing purposes. Hence, ebreak is not suitable as RSEQ_SIG.
6 * "csrw mhartid, x0" can also satisfy the RSEQ requirement because it
7 * is an uncommon instruction and will raise an illegal instruction
8 * exception when executed in all modes.
12 #if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __LITTLE_ENDIAN) : defined(__LITTLE_ENDIAN)
13 #define RSEQ_SIG 0xf1401073 /* csrr mhartid, x0 */
15 #error "Currently, RSEQ only supports Little-Endian version"
18 #if __riscv_xlen == 64
19 #define __REG_SEL(a, b) a
20 #elif __riscv_xlen == 32
21 #define __REG_SEL(a, b) b
24 #define REG_L __REG_SEL("ld ", "lw ")
25 #define REG_S __REG_SEL("sd ", "sw ")
27 #define RISCV_FENCE(p, s) \
28 __asm__ __volatile__ ("fence " #p "," #s : : : "memory")
29 #define rseq_smp_mb() RISCV_FENCE(rw, rw)
30 #define rseq_smp_rmb() RISCV_FENCE(r, r)
31 #define rseq_smp_wmb() RISCV_FENCE(w, w)
32 #define RSEQ_ASM_TMP_REG_1 "t6"
33 #define RSEQ_ASM_TMP_REG_2 "t5"
34 #define RSEQ_ASM_TMP_REG_3 "t4"
35 #define RSEQ_ASM_TMP_REG_4 "t3"
37 #define rseq_smp_load_acquire(p) \
39 __typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p)); \
44 #define rseq_smp_acquire__after_ctrl_dep() rseq_smp_rmb()
46 #define rseq_smp_store_release(p, v) \
49 RSEQ_WRITE_ONCE(*(p), v); \
52 #ifdef RSEQ_SKIP_FASTPATH
53 #include "rseq-skip.h"
54 #else /* !RSEQ_SKIP_FASTPATH */
56 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
57 post_commit_offset, abort_ip) \
58 ".pushsection __rseq_cs, \"aw\"\n" \
60 __rseq_str(label) ":\n" \
61 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n" \
62 ".quad " __rseq_str(start_ip) ", " \
63 __rseq_str(post_commit_offset) ", " \
64 __rseq_str(abort_ip) "\n" \
66 ".pushsection __rseq_cs_ptr_array, \"aw\"\n" \
67 ".quad " __rseq_str(label) "b\n" \
70 #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
71 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
72 ((post_commit_ip) - (start_ip)), abort_ip)
75 * Exit points of a rseq critical section consist of all instructions outside
76 * of the critical section where a critical section can either branch to or
77 * reach through the normal course of its execution. The abort IP and the
78 * post-commit IP are already part of the __rseq_cs section and should not be
79 * explicitly defined as additional exit points. Knowing all exit points is
80 * useful to assist debuggers stepping over the critical section.
82 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
83 ".pushsection __rseq_exit_point_array, \"aw\"\n" \
84 ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n" \
87 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
89 "la " RSEQ_ASM_TMP_REG_1 ", " __rseq_str(cs_label) "\n" \
90 REG_S RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(rseq_cs) "]\n" \
91 __rseq_str(label) ":\n"
93 #define RSEQ_ASM_DEFINE_ABORT(label, abort_label) \
96 ".long " __rseq_str(RSEQ_SIG) "\n" \
97 __rseq_str(label) ":\n" \
98 "j %l[" __rseq_str(abort_label) "]\n" \
101 #define RSEQ_ASM_OP_STORE(value, var) \
102 REG_S "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n"
104 #define RSEQ_ASM_OP_CMPEQ(var, expect, label) \
105 REG_L RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(var) "]\n" \
106 "bne " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(expect) "] ," \
107 __rseq_str(label) "\n"
109 #define RSEQ_ASM_OP_CMPEQ32(var, expect, label) \
110 "lw " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(var) "]\n" \
111 "bne " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(expect) "] ," \
112 __rseq_str(label) "\n"
114 #define RSEQ_ASM_OP_CMPNE(var, expect, label) \
115 REG_L RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(var) "]\n" \
116 "beq " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(expect) "] ," \
117 __rseq_str(label) "\n"
119 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
121 RSEQ_ASM_OP_CMPEQ32(current_cpu_id, cpu_id, label)
123 #define RSEQ_ASM_OP_R_LOAD(var) \
124 REG_L RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(var) "]\n"
126 #define RSEQ_ASM_OP_R_STORE(var) \
127 REG_S RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(var) "]\n"
129 #define RSEQ_ASM_OP_R_LOAD_OFF(offset) \
130 "add " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(offset) "], " \
131 RSEQ_ASM_TMP_REG_1 "\n" \
132 REG_L RSEQ_ASM_TMP_REG_1 ", (" RSEQ_ASM_TMP_REG_1 ")\n"
134 #define RSEQ_ASM_OP_R_ADD(count) \
135 "add " RSEQ_ASM_TMP_REG_1 ", " RSEQ_ASM_TMP_REG_1 \
136 ", %[" __rseq_str(count) "]\n"
138 #define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \
139 RSEQ_ASM_OP_STORE(value, var) \
140 __rseq_str(post_commit_label) ":\n"
142 #define RSEQ_ASM_OP_FINAL_STORE_RELEASE(value, var, post_commit_label) \
144 RSEQ_ASM_OP_STORE(value, var) \
145 __rseq_str(post_commit_label) ":\n"
147 #define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \
148 REG_S RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(var) "]\n" \
149 __rseq_str(post_commit_label) ":\n"
151 #define RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len) \
152 "beqz %[" __rseq_str(len) "], 333f\n" \
153 "mv " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(len) "]\n" \
154 "mv " RSEQ_ASM_TMP_REG_2 ", %[" __rseq_str(src) "]\n" \
155 "mv " RSEQ_ASM_TMP_REG_3 ", %[" __rseq_str(dst) "]\n" \
157 "lb " RSEQ_ASM_TMP_REG_4 ", 0(" RSEQ_ASM_TMP_REG_2 ")\n" \
158 "sb " RSEQ_ASM_TMP_REG_4 ", 0(" RSEQ_ASM_TMP_REG_3 ")\n" \
159 "addi " RSEQ_ASM_TMP_REG_1 ", " RSEQ_ASM_TMP_REG_1 ", -1\n" \
160 "addi " RSEQ_ASM_TMP_REG_2 ", " RSEQ_ASM_TMP_REG_2 ", 1\n" \
161 "addi " RSEQ_ASM_TMP_REG_3 ", " RSEQ_ASM_TMP_REG_3 ", 1\n" \
162 "bnez " RSEQ_ASM_TMP_REG_1 ", 222b\n" \
165 #define RSEQ_ASM_OP_R_DEREF_ADDV(ptr, off, post_commit_label) \
166 "mv " RSEQ_ASM_TMP_REG_1 ", %[" __rseq_str(ptr) "]\n" \
167 RSEQ_ASM_OP_R_ADD(off) \
168 REG_L RSEQ_ASM_TMP_REG_1 ", 0(" RSEQ_ASM_TMP_REG_1 ")\n" \
169 RSEQ_ASM_OP_R_ADD(inc) \
170 __rseq_str(post_commit_label) ":\n"
172 static inline __always_inline
173 int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
177 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
178 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
179 #ifdef RSEQ_COMPARE_TWICE
180 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
181 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
183 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
184 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
186 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]")
188 #ifdef RSEQ_COMPARE_TWICE
189 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
190 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]")
192 RSEQ_ASM_OP_FINAL_STORE(newv, v, 3)
194 RSEQ_ASM_DEFINE_ABORT(4, abort)
195 : /* gcc asm goto does not allow outputs */
196 : [cpu_id] "r" (cpu),
197 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
198 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
200 [expect] "r" (expect),
203 : "memory", RSEQ_ASM_TMP_REG_1
206 #ifdef RSEQ_COMPARE_TWICE
217 #ifdef RSEQ_COMPARE_TWICE
219 rseq_bug("cpu_id comparison failed");
221 rseq_bug("expected value comparison failed");
225 static inline __always_inline
226 int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
227 off_t voffp, intptr_t *load, int cpu)
231 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
232 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
233 #ifdef RSEQ_COMPARE_TWICE
234 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
235 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
237 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
238 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
240 RSEQ_ASM_OP_CMPNE(v, expectnot, "%l[cmpfail]")
242 #ifdef RSEQ_COMPARE_TWICE
243 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
244 RSEQ_ASM_OP_CMPNE(v, expectnot, "%l[error2]")
246 RSEQ_ASM_OP_R_LOAD(v)
247 RSEQ_ASM_OP_R_STORE(load)
248 RSEQ_ASM_OP_R_LOAD_OFF(voffp)
249 RSEQ_ASM_OP_R_FINAL_STORE(v, 3)
251 RSEQ_ASM_DEFINE_ABORT(4, abort)
252 : /* gcc asm goto does not allow outputs */
253 : [cpu_id] "r" (cpu),
254 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
255 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
257 [expectnot] "r" (expectnot),
261 : "memory", RSEQ_ASM_TMP_REG_1
264 #ifdef RSEQ_COMPARE_TWICE
274 #ifdef RSEQ_COMPARE_TWICE
276 rseq_bug("cpu_id comparison failed");
278 rseq_bug("expected value comparison failed");
282 static inline __always_inline
283 int rseq_addv(intptr_t *v, intptr_t count, int cpu)
287 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
288 #ifdef RSEQ_COMPARE_TWICE
289 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
291 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
292 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
294 #ifdef RSEQ_COMPARE_TWICE
295 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
297 RSEQ_ASM_OP_R_LOAD(v)
298 RSEQ_ASM_OP_R_ADD(count)
299 RSEQ_ASM_OP_R_FINAL_STORE(v, 3)
301 RSEQ_ASM_DEFINE_ABORT(4, abort)
302 : /* gcc asm goto does not allow outputs */
303 : [cpu_id] "r" (cpu),
304 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
305 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
309 : "memory", RSEQ_ASM_TMP_REG_1
312 #ifdef RSEQ_COMPARE_TWICE
320 #ifdef RSEQ_COMPARE_TWICE
322 rseq_bug("cpu_id comparison failed");
326 static inline __always_inline
327 int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
328 intptr_t *v2, intptr_t newv2,
329 intptr_t newv, int cpu)
333 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
334 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
335 #ifdef RSEQ_COMPARE_TWICE
336 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
337 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
339 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
340 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
342 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]")
344 #ifdef RSEQ_COMPARE_TWICE
345 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
346 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]")
348 RSEQ_ASM_OP_STORE(newv2, v2)
350 RSEQ_ASM_OP_FINAL_STORE(newv, v, 3)
352 RSEQ_ASM_DEFINE_ABORT(4, abort)
353 : /* gcc asm goto does not allow outputs */
354 : [cpu_id] "r" (cpu),
355 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
356 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
357 [expect] "r" (expect),
363 : "memory", RSEQ_ASM_TMP_REG_1
366 #ifdef RSEQ_COMPARE_TWICE
377 #ifdef RSEQ_COMPARE_TWICE
379 rseq_bug("cpu_id comparison failed");
381 rseq_bug("expected value comparison failed");
385 static inline __always_inline
386 int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
387 intptr_t *v2, intptr_t newv2,
388 intptr_t newv, int cpu)
392 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
393 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
394 #ifdef RSEQ_COMPARE_TWICE
395 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
396 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
398 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
399 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
401 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]")
403 #ifdef RSEQ_COMPARE_TWICE
404 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
405 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]")
407 RSEQ_ASM_OP_STORE(newv2, v2)
409 RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3)
411 RSEQ_ASM_DEFINE_ABORT(4, abort)
412 : /* gcc asm goto does not allow outputs */
413 : [cpu_id] "r" (cpu),
414 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
415 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
416 [expect] "r" (expect),
422 : "memory", RSEQ_ASM_TMP_REG_1
425 #ifdef RSEQ_COMPARE_TWICE
436 #ifdef RSEQ_COMPARE_TWICE
438 rseq_bug("cpu_id comparison failed");
440 rseq_bug("expected value comparison failed");
444 static inline __always_inline
445 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
446 intptr_t *v2, intptr_t expect2,
447 intptr_t newv, int cpu)
451 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
452 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
453 #ifdef RSEQ_COMPARE_TWICE
454 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
455 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
456 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error3]")
458 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
459 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
461 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]")
463 RSEQ_ASM_OP_CMPEQ(v2, expect2, "%l[cmpfail]")
465 #ifdef RSEQ_COMPARE_TWICE
466 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
467 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]")
468 RSEQ_ASM_OP_CMPEQ(v2, expect2, "%l[error3]")
470 RSEQ_ASM_OP_FINAL_STORE(newv, v, 3)
472 RSEQ_ASM_DEFINE_ABORT(4, abort)
473 : /* gcc asm goto does not allow outputs */
474 : [cpu_id] "r" (cpu),
475 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
476 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
478 [expect] "r" (expect),
480 [expect2] "r" (expect2),
483 : "memory", RSEQ_ASM_TMP_REG_1
486 #ifdef RSEQ_COMPARE_TWICE
487 , error1, error2, error3
497 #ifdef RSEQ_COMPARE_TWICE
499 rseq_bug("cpu_id comparison failed");
501 rseq_bug("expected value comparison failed");
503 rseq_bug("2nd expected value comparison failed");
507 static inline __always_inline
508 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
509 void *dst, void *src, size_t len,
510 intptr_t newv, int cpu)
513 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
514 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
515 #ifdef RSEQ_COMPARE_TWICE
516 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
517 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
519 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
520 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
522 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]")
524 #ifdef RSEQ_COMPARE_TWICE
525 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
526 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]")
528 RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len)
530 RSEQ_ASM_OP_FINAL_STORE(newv, v, 3)
532 RSEQ_ASM_DEFINE_ABORT(4, abort)
533 : /* gcc asm goto does not allow outputs */
534 : [cpu_id] "r" (cpu),
535 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
536 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
537 [expect] "r" (expect),
544 : "memory", RSEQ_ASM_TMP_REG_1, RSEQ_ASM_TMP_REG_2,
545 RSEQ_ASM_TMP_REG_3, RSEQ_ASM_TMP_REG_4
548 #ifdef RSEQ_COMPARE_TWICE
559 #ifdef RSEQ_COMPARE_TWICE
561 rseq_bug("cpu_id comparison failed");
563 rseq_bug("expected value comparison failed");
567 static inline __always_inline
568 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
569 void *dst, void *src, size_t len,
570 intptr_t newv, int cpu)
574 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
575 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[cmpfail]")
576 #ifdef RSEQ_COMPARE_TWICE
577 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
578 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error2]")
580 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
581 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
583 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[cmpfail]")
585 #ifdef RSEQ_COMPARE_TWICE
586 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
587 RSEQ_ASM_OP_CMPEQ(v, expect, "%l[error2]")
589 RSEQ_ASM_OP_R_BAD_MEMCPY(dst, src, len)
591 RSEQ_ASM_OP_FINAL_STORE_RELEASE(newv, v, 3)
593 RSEQ_ASM_DEFINE_ABORT(4, abort)
594 : /* gcc asm goto does not allow outputs */
595 : [cpu_id] "r" (cpu),
596 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
597 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
598 [expect] "r" (expect),
605 : "memory", RSEQ_ASM_TMP_REG_1, RSEQ_ASM_TMP_REG_2,
606 RSEQ_ASM_TMP_REG_3, RSEQ_ASM_TMP_REG_4
609 #ifdef RSEQ_COMPARE_TWICE
620 #ifdef RSEQ_COMPARE_TWICE
622 rseq_bug("cpu_id comparison failed");
624 rseq_bug("expected value comparison failed");
628 #define RSEQ_ARCH_HAS_OFFSET_DEREF_ADDV
634 static inline __always_inline
635 int rseq_offset_deref_addv(intptr_t *ptr, off_t off, intptr_t inc, int cpu)
639 __asm__ __volatile__ goto(RSEQ_ASM_DEFINE_TABLE(1, 2f, 3f, 4f)
640 #ifdef RSEQ_COMPARE_TWICE
641 RSEQ_ASM_DEFINE_EXIT_POINT(2f, "%l[error1]")
643 RSEQ_ASM_STORE_RSEQ_CS(2, 1b, rseq_cs)
644 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f)
646 #ifdef RSEQ_COMPARE_TWICE
647 RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, "%l[error1]")
649 RSEQ_ASM_OP_R_DEREF_ADDV(ptr, off, 3)
651 RSEQ_ASM_DEFINE_ABORT(4, abort)
652 : /* gcc asm goto does not allow outputs */
653 : [cpu_id] "r" (cpu),
654 [current_cpu_id] "m" (rseq_get_abi()->cpu_id),
655 [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr),
660 : "memory", RSEQ_ASM_TMP_REG_1
663 #ifdef RSEQ_COMPARE_TWICE
671 #ifdef RSEQ_COMPARE_TWICE
673 rseq_bug("cpu_id comparison failed");
677 #endif /* !RSEQ_SKIP_FASTPATH */