1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
3 * Author: Paul Burton <paul.burton@mips.com>
4 * (C) Copyright 2018 MIPS Tech LLC
7 * (C) Copyright 2016-2018 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * RSEQ_SIG uses the break instruction. The instruction pattern is:
14 * 0350000d break 0x350
17 * 00100350 break 0x350
20 * 0000d407 break 0x350
22 * For nanoMIPS32 and microMIPS, the instruction stream is encoded as 16-bit
23 * halfwords, so the signature halfwords need to be swapped accordingly for
26 #if defined(__nanomips__)
28 # define RSEQ_SIG 0x03500010
30 # define RSEQ_SIG 0x00100350
32 #elif defined(__mips_micromips)
34 # define RSEQ_SIG 0xd4070000
36 # define RSEQ_SIG 0x0000d407
38 #elif defined(__mips__)
39 # define RSEQ_SIG 0x0350000d
41 /* Unknown MIPS architecture. */
44 #define rseq_smp_mb() __asm__ __volatile__ ("sync" ::: "memory")
45 #define rseq_smp_rmb() rseq_smp_mb()
46 #define rseq_smp_wmb() rseq_smp_mb()
48 #define rseq_smp_load_acquire(p) \
50 __typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \
55 #define rseq_smp_acquire__after_ctrl_dep() rseq_smp_rmb()
57 #define rseq_smp_store_release(p, v) \
60 RSEQ_WRITE_ONCE(*p, v); \
63 #ifdef RSEQ_SKIP_FASTPATH
64 #include "rseq-skip.h"
65 #else /* !RSEQ_SKIP_FASTPATH */
67 #if _MIPS_SZLONG == 64
68 # define LONG ".dword"
69 # define LONG_LA "dla"
72 # define LONG_ADDI "daddiu"
73 # define U32_U64_PAD(x) x
74 #elif _MIPS_SZLONG == 32
79 # define LONG_ADDI "addiu"
81 # define U32_U64_PAD(x) "0x0, " x
83 # define U32_U64_PAD(x) x ", 0x0"
86 # error unsupported _MIPS_SZLONG
89 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
90 post_commit_offset, abort_ip) \
91 ".pushsection __rseq_cs, \"aw\"\n\t" \
93 __rseq_str(label) ":\n\t" \
94 ".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
95 LONG " " U32_U64_PAD(__rseq_str(start_ip)) "\n\t" \
96 LONG " " U32_U64_PAD(__rseq_str(post_commit_offset)) "\n\t" \
97 LONG " " U32_U64_PAD(__rseq_str(abort_ip)) "\n\t" \
99 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
100 LONG " " U32_U64_PAD(__rseq_str(label) "b") "\n\t" \
103 #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
104 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
105 (post_commit_ip - start_ip), abort_ip)
108 * Exit points of a rseq critical section consist of all instructions outside
109 * of the critical section where a critical section can either branch to or
110 * reach through the normal course of its execution. The abort IP and the
111 * post-commit IP are already part of the __rseq_cs section and should not be
112 * explicitly defined as additional exit points. Knowing all exit points is
113 * useful to assist debuggers stepping over the critical section.
115 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
116 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
117 LONG " " U32_U64_PAD(__rseq_str(start_ip)) "\n\t" \
118 LONG " " U32_U64_PAD(__rseq_str(exit_ip)) "\n\t" \
121 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
123 LONG_LA " $4, " __rseq_str(cs_label) "\n\t" \
124 LONG_S " $4, %[" __rseq_str(rseq_cs) "]\n\t" \
125 __rseq_str(label) ":\n\t"
127 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
129 "lw $4, %[" __rseq_str(current_cpu_id) "]\n\t" \
130 "bne $4, %[" __rseq_str(cpu_id) "], " __rseq_str(label) "\n\t"
132 #define __RSEQ_ASM_DEFINE_ABORT(table_label, label, teardown, \
133 abort_label, version, flags, \
134 start_ip, post_commit_offset, abort_ip) \
136 __rseq_str(table_label) ":\n\t" \
137 ".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
138 LONG " " U32_U64_PAD(__rseq_str(start_ip)) "\n\t" \
139 LONG " " U32_U64_PAD(__rseq_str(post_commit_offset)) "\n\t" \
140 LONG " " U32_U64_PAD(__rseq_str(abort_ip)) "\n\t" \
141 ".word " __rseq_str(RSEQ_SIG) "\n\t" \
142 __rseq_str(label) ":\n\t" \
144 "b %l[" __rseq_str(abort_label) "]\n\t"
146 #define RSEQ_ASM_DEFINE_ABORT(table_label, label, teardown, abort_label, \
147 start_ip, post_commit_ip, abort_ip) \
148 __RSEQ_ASM_DEFINE_ABORT(table_label, label, teardown, \
149 abort_label, 0x0, 0x0, start_ip, \
150 (post_commit_ip - start_ip), abort_ip)
152 #define RSEQ_ASM_DEFINE_CMPFAIL(label, teardown, cmpfail_label) \
153 __rseq_str(label) ":\n\t" \
155 "b %l[" __rseq_str(cmpfail_label) "]\n\t"
157 #define rseq_workaround_gcc_asm_size_guess() __asm__ __volatile__("")
159 static inline __attribute__((always_inline
))
160 int rseq_cmpeqv_storev(intptr_t *v
, intptr_t expect
, intptr_t newv
, int cpu
)
164 rseq_workaround_gcc_asm_size_guess();
165 __asm__ __volatile__
goto (
166 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
167 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
168 #ifdef RSEQ_COMPARE_TWICE
169 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
170 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
172 /* Start rseq by storing table entry pointer into rseq_cs. */
173 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
174 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
176 LONG_L
" $4, %[v]\n\t"
177 "bne $4, %[expect], %l[cmpfail]\n\t"
179 #ifdef RSEQ_COMPARE_TWICE
180 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
181 LONG_L
" $4, %[v]\n\t"
182 "bne $4, %[expect], %l[error2]\n\t"
185 LONG_S
" %[newv], %[v]\n\t"
189 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
191 : /* gcc asm goto does not allow outputs */
192 : [cpu_id
] "r" (cpu
),
193 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
194 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
196 [expect
] "r" (expect
),
202 #ifdef RSEQ_COMPARE_TWICE
206 rseq_workaround_gcc_asm_size_guess();
209 rseq_workaround_gcc_asm_size_guess();
213 rseq_workaround_gcc_asm_size_guess();
215 #ifdef RSEQ_COMPARE_TWICE
217 rseq_bug("cpu_id comparison failed");
219 rseq_bug("expected value comparison failed");
223 static inline __attribute__((always_inline
))
224 int rseq_cmpnev_storeoffp_load(intptr_t *v
, intptr_t expectnot
,
225 off_t voffp
, intptr_t *load
, int cpu
)
229 rseq_workaround_gcc_asm_size_guess();
230 __asm__ __volatile__
goto (
231 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
232 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
233 #ifdef RSEQ_COMPARE_TWICE
234 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
235 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
237 /* Start rseq by storing table entry pointer into rseq_cs. */
238 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
239 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
241 LONG_L
" $4, %[v]\n\t"
242 "beq $4, %[expectnot], %l[cmpfail]\n\t"
244 #ifdef RSEQ_COMPARE_TWICE
245 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
246 LONG_L
" $4, %[v]\n\t"
247 "beq $4, %[expectnot], %l[error2]\n\t"
249 LONG_S
" $4, %[load]\n\t"
250 LONG_ADDI
" $4, %[voffp]\n\t"
251 LONG_L
" $4, 0($4)\n\t"
253 LONG_S
" $4, %[v]\n\t"
257 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
259 : /* gcc asm goto does not allow outputs */
260 : [cpu_id
] "r" (cpu
),
261 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
262 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
263 /* final store input */
265 [expectnot
] "r" (expectnot
),
266 [voffp
] "Ir" (voffp
),
272 #ifdef RSEQ_COMPARE_TWICE
276 rseq_workaround_gcc_asm_size_guess();
279 rseq_workaround_gcc_asm_size_guess();
283 rseq_workaround_gcc_asm_size_guess();
285 #ifdef RSEQ_COMPARE_TWICE
287 rseq_bug("cpu_id comparison failed");
289 rseq_bug("expected value comparison failed");
293 static inline __attribute__((always_inline
))
294 int rseq_addv(intptr_t *v
, intptr_t count
, int cpu
)
298 rseq_workaround_gcc_asm_size_guess();
299 __asm__ __volatile__
goto (
300 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
301 #ifdef RSEQ_COMPARE_TWICE
302 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
304 /* Start rseq by storing table entry pointer into rseq_cs. */
305 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
306 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
308 #ifdef RSEQ_COMPARE_TWICE
309 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
311 LONG_L
" $4, %[v]\n\t"
312 LONG_ADDI
" $4, %[count]\n\t"
314 LONG_S
" $4, %[v]\n\t"
318 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
320 : /* gcc asm goto does not allow outputs */
321 : [cpu_id
] "r" (cpu
),
322 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
323 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
330 #ifdef RSEQ_COMPARE_TWICE
334 rseq_workaround_gcc_asm_size_guess();
337 rseq_workaround_gcc_asm_size_guess();
340 #ifdef RSEQ_COMPARE_TWICE
342 rseq_bug("cpu_id comparison failed");
346 static inline __attribute__((always_inline
))
347 int rseq_cmpeqv_trystorev_storev(intptr_t *v
, intptr_t expect
,
348 intptr_t *v2
, intptr_t newv2
,
349 intptr_t newv
, int cpu
)
353 rseq_workaround_gcc_asm_size_guess();
354 __asm__ __volatile__
goto (
355 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
356 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
357 #ifdef RSEQ_COMPARE_TWICE
358 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
359 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
361 /* Start rseq by storing table entry pointer into rseq_cs. */
362 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
363 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
365 LONG_L
" $4, %[v]\n\t"
366 "bne $4, %[expect], %l[cmpfail]\n\t"
368 #ifdef RSEQ_COMPARE_TWICE
369 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
370 LONG_L
" $4, %[v]\n\t"
371 "bne $4, %[expect], %l[error2]\n\t"
374 LONG_S
" %[newv2], %[v2]\n\t"
377 LONG_S
" %[newv], %[v]\n\t"
381 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
383 : /* gcc asm goto does not allow outputs */
384 : [cpu_id
] "r" (cpu
),
385 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
386 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
387 /* try store input */
390 /* final store input */
392 [expect
] "r" (expect
),
398 #ifdef RSEQ_COMPARE_TWICE
402 rseq_workaround_gcc_asm_size_guess();
405 rseq_workaround_gcc_asm_size_guess();
409 rseq_workaround_gcc_asm_size_guess();
411 #ifdef RSEQ_COMPARE_TWICE
413 rseq_bug("cpu_id comparison failed");
415 rseq_bug("expected value comparison failed");
419 static inline __attribute__((always_inline
))
420 int rseq_cmpeqv_trystorev_storev_release(intptr_t *v
, intptr_t expect
,
421 intptr_t *v2
, intptr_t newv2
,
422 intptr_t newv
, int cpu
)
426 rseq_workaround_gcc_asm_size_guess();
427 __asm__ __volatile__
goto (
428 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
429 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
430 #ifdef RSEQ_COMPARE_TWICE
431 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
432 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
434 /* Start rseq by storing table entry pointer into rseq_cs. */
435 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
436 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
438 LONG_L
" $4, %[v]\n\t"
439 "bne $4, %[expect], %l[cmpfail]\n\t"
441 #ifdef RSEQ_COMPARE_TWICE
442 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
443 LONG_L
" $4, %[v]\n\t"
444 "bne $4, %[expect], %l[error2]\n\t"
447 LONG_S
" %[newv2], %[v2]\n\t"
449 "sync\n\t" /* full sync provides store-release */
451 LONG_S
" %[newv], %[v]\n\t"
455 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
457 : /* gcc asm goto does not allow outputs */
458 : [cpu_id
] "r" (cpu
),
459 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
460 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
461 /* try store input */
464 /* final store input */
466 [expect
] "r" (expect
),
472 #ifdef RSEQ_COMPARE_TWICE
476 rseq_workaround_gcc_asm_size_guess();
479 rseq_workaround_gcc_asm_size_guess();
483 rseq_workaround_gcc_asm_size_guess();
485 #ifdef RSEQ_COMPARE_TWICE
487 rseq_bug("cpu_id comparison failed");
489 rseq_bug("expected value comparison failed");
493 static inline __attribute__((always_inline
))
494 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v
, intptr_t expect
,
495 intptr_t *v2
, intptr_t expect2
,
496 intptr_t newv
, int cpu
)
500 rseq_workaround_gcc_asm_size_guess();
501 __asm__ __volatile__
goto (
502 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
503 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
504 #ifdef RSEQ_COMPARE_TWICE
505 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
506 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
507 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error3
])
509 /* Start rseq by storing table entry pointer into rseq_cs. */
510 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
511 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
513 LONG_L
" $4, %[v]\n\t"
514 "bne $4, %[expect], %l[cmpfail]\n\t"
516 LONG_L
" $4, %[v2]\n\t"
517 "bne $4, %[expect2], %l[cmpfail]\n\t"
519 #ifdef RSEQ_COMPARE_TWICE
520 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
521 LONG_L
" $4, %[v]\n\t"
522 "bne $4, %[expect], %l[error2]\n\t"
523 LONG_L
" $4, %[v2]\n\t"
524 "bne $4, %[expect2], %l[error3]\n\t"
527 LONG_S
" %[newv], %[v]\n\t"
531 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
533 : /* gcc asm goto does not allow outputs */
534 : [cpu_id
] "r" (cpu
),
535 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
536 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
539 [expect2
] "r" (expect2
),
540 /* final store input */
542 [expect
] "r" (expect
),
548 #ifdef RSEQ_COMPARE_TWICE
549 , error1
, error2
, error3
552 rseq_workaround_gcc_asm_size_guess();
555 rseq_workaround_gcc_asm_size_guess();
559 rseq_workaround_gcc_asm_size_guess();
561 #ifdef RSEQ_COMPARE_TWICE
563 rseq_bug("cpu_id comparison failed");
565 rseq_bug("1st expected value comparison failed");
567 rseq_bug("2nd expected value comparison failed");
571 static inline __attribute__((always_inline
))
572 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v
, intptr_t expect
,
573 void *dst
, void *src
, size_t len
,
574 intptr_t newv
, int cpu
)
576 uintptr_t rseq_scratch
[3];
580 rseq_workaround_gcc_asm_size_guess();
581 __asm__ __volatile__
goto (
582 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
583 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
584 #ifdef RSEQ_COMPARE_TWICE
585 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
586 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
588 LONG_S
" %[src], %[rseq_scratch0]\n\t"
589 LONG_S
" %[dst], %[rseq_scratch1]\n\t"
590 LONG_S
" %[len], %[rseq_scratch2]\n\t"
591 /* Start rseq by storing table entry pointer into rseq_cs. */
592 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
593 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
595 LONG_L
" $4, %[v]\n\t"
596 "bne $4, %[expect], 5f\n\t"
598 #ifdef RSEQ_COMPARE_TWICE
599 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 6f
)
600 LONG_L
" $4, %[v]\n\t"
601 "bne $4, %[expect], 7f\n\t"
604 "beqz %[len], 333f\n\t" \
606 "lb $4, 0(%[src])\n\t" \
607 "sb $4, 0(%[dst])\n\t" \
608 LONG_ADDI
" %[src], 1\n\t" \
609 LONG_ADDI
" %[dst], 1\n\t" \
610 LONG_ADDI
" %[len], -1\n\t" \
611 "bnez %[len], 222b\n\t" \
615 LONG_S
" %[newv], %[v]\n\t"
619 LONG_L
" %[len], %[rseq_scratch2]\n\t"
620 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
621 LONG_L
" %[src], %[rseq_scratch0]\n\t"
623 RSEQ_ASM_DEFINE_ABORT(3, 4,
625 LONG_L
" %[len], %[rseq_scratch2]\n\t"
626 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
627 LONG_L
" %[src], %[rseq_scratch0]\n\t",
629 RSEQ_ASM_DEFINE_CMPFAIL(5,
631 LONG_L
" %[len], %[rseq_scratch2]\n\t"
632 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
633 LONG_L
" %[src], %[rseq_scratch0]\n\t",
635 #ifdef RSEQ_COMPARE_TWICE
636 RSEQ_ASM_DEFINE_CMPFAIL(6,
638 LONG_L
" %[len], %[rseq_scratch2]\n\t"
639 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
640 LONG_L
" %[src], %[rseq_scratch0]\n\t",
642 RSEQ_ASM_DEFINE_CMPFAIL(7,
644 LONG_L
" %[len], %[rseq_scratch2]\n\t"
645 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
646 LONG_L
" %[src], %[rseq_scratch0]\n\t",
650 : /* gcc asm goto does not allow outputs */
651 : [cpu_id
] "r" (cpu
),
652 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
653 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
654 /* final store input */
656 [expect
] "r" (expect
),
658 /* try memcpy input */
662 [rseq_scratch0
] "m" (rseq_scratch
[0]),
663 [rseq_scratch1
] "m" (rseq_scratch
[1]),
664 [rseq_scratch2
] "m" (rseq_scratch
[2])
669 #ifdef RSEQ_COMPARE_TWICE
673 rseq_workaround_gcc_asm_size_guess();
676 rseq_workaround_gcc_asm_size_guess();
680 rseq_workaround_gcc_asm_size_guess();
682 #ifdef RSEQ_COMPARE_TWICE
684 rseq_workaround_gcc_asm_size_guess();
685 rseq_bug("cpu_id comparison failed");
687 rseq_workaround_gcc_asm_size_guess();
688 rseq_bug("expected value comparison failed");
692 static inline __attribute__((always_inline
))
693 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v
, intptr_t expect
,
694 void *dst
, void *src
, size_t len
,
695 intptr_t newv
, int cpu
)
697 uintptr_t rseq_scratch
[3];
701 rseq_workaround_gcc_asm_size_guess();
702 __asm__ __volatile__
goto (
703 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
704 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
705 #ifdef RSEQ_COMPARE_TWICE
706 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
707 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
709 LONG_S
" %[src], %[rseq_scratch0]\n\t"
710 LONG_S
" %[dst], %[rseq_scratch1]\n\t"
711 LONG_S
" %[len], %[rseq_scratch2]\n\t"
712 /* Start rseq by storing table entry pointer into rseq_cs. */
713 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
714 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
716 LONG_L
" $4, %[v]\n\t"
717 "bne $4, %[expect], 5f\n\t"
719 #ifdef RSEQ_COMPARE_TWICE
720 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 6f
)
721 LONG_L
" $4, %[v]\n\t"
722 "bne $4, %[expect], 7f\n\t"
725 "beqz %[len], 333f\n\t" \
727 "lb $4, 0(%[src])\n\t" \
728 "sb $4, 0(%[dst])\n\t" \
729 LONG_ADDI
" %[src], 1\n\t" \
730 LONG_ADDI
" %[dst], 1\n\t" \
731 LONG_ADDI
" %[len], -1\n\t" \
732 "bnez %[len], 222b\n\t" \
735 "sync\n\t" /* full sync provides store-release */
737 LONG_S
" %[newv], %[v]\n\t"
741 LONG_L
" %[len], %[rseq_scratch2]\n\t"
742 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
743 LONG_L
" %[src], %[rseq_scratch0]\n\t"
745 RSEQ_ASM_DEFINE_ABORT(3, 4,
747 LONG_L
" %[len], %[rseq_scratch2]\n\t"
748 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
749 LONG_L
" %[src], %[rseq_scratch0]\n\t",
751 RSEQ_ASM_DEFINE_CMPFAIL(5,
753 LONG_L
" %[len], %[rseq_scratch2]\n\t"
754 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
755 LONG_L
" %[src], %[rseq_scratch0]\n\t",
757 #ifdef RSEQ_COMPARE_TWICE
758 RSEQ_ASM_DEFINE_CMPFAIL(6,
760 LONG_L
" %[len], %[rseq_scratch2]\n\t"
761 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
762 LONG_L
" %[src], %[rseq_scratch0]\n\t",
764 RSEQ_ASM_DEFINE_CMPFAIL(7,
766 LONG_L
" %[len], %[rseq_scratch2]\n\t"
767 LONG_L
" %[dst], %[rseq_scratch1]\n\t"
768 LONG_L
" %[src], %[rseq_scratch0]\n\t",
772 : /* gcc asm goto does not allow outputs */
773 : [cpu_id
] "r" (cpu
),
774 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
775 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
776 /* final store input */
778 [expect
] "r" (expect
),
780 /* try memcpy input */
784 [rseq_scratch0
] "m" (rseq_scratch
[0]),
785 [rseq_scratch1
] "m" (rseq_scratch
[1]),
786 [rseq_scratch2
] "m" (rseq_scratch
[2])
791 #ifdef RSEQ_COMPARE_TWICE
795 rseq_workaround_gcc_asm_size_guess();
798 rseq_workaround_gcc_asm_size_guess();
802 rseq_workaround_gcc_asm_size_guess();
804 #ifdef RSEQ_COMPARE_TWICE
806 rseq_workaround_gcc_asm_size_guess();
807 rseq_bug("cpu_id comparison failed");
809 rseq_workaround_gcc_asm_size_guess();
810 rseq_bug("expected value comparison failed");
814 #endif /* !RSEQ_SKIP_FASTPATH */