1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
5 * (C) Copyright 2016-2018 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * RSEQ_SIG uses the udf A32 instruction with an uncommon immediate operand
12 * value 0x5de3. This traps if user-space reaches this instruction by mistake,
13 * and the uncommon operand ensures the kernel does not move the instruction
14 * pointer to attacker-controlled code on rseq abort.
16 * The instruction pattern in the A32 instruction set is:
18 * e7f5def3 udf #24035 ; 0x5de3
20 * This translates to the following instruction pattern in the T16 instruction
24 * def3 udf #243 ; 0xf3
27 * - ARMv6+ big endian (BE8):
29 * ARMv6+ -mbig-endian generates mixed endianness code vs data: little-endian
30 * code and big-endian data. The data value of the signature needs to have its
31 * byte order reversed to generate the trap instruction:
35 * Translates to this A32 instruction pattern:
37 * e7f5def3 udf #24035 ; 0x5de3
39 * Translates to this T16 instruction pattern:
41 * def3 udf #243 ; 0xf3
44 * - Prior to ARMv6 big endian (BE32):
46 * Prior to ARMv6, -mbig-endian generates big-endian code and data
47 * (which match), so the endianness of the data representation of the
48 * signature should not be reversed. However, the choice between BE32
49 * and BE8 is done by the linker, so we cannot know whether code and
50 * data endianness will be mixed before the linker is invoked. So rather
51 * than try to play tricks with the linker, the rseq signature is simply
52 * data (not a trap instruction) prior to ARMv6 on big endian. This is
53 * why the signature is expressed as data (.word) rather than as
54 * instruction (.inst) in assembler.
58 #define RSEQ_SIG 0xf3def5e7 /* udf #24035 ; 0x5de3 (ARMv6+) */
60 #define RSEQ_SIG 0xe7f5def3 /* udf #24035 ; 0x5de3 */
63 #define rseq_smp_mb() __asm__ __volatile__ ("dmb" ::: "memory", "cc")
64 #define rseq_smp_rmb() __asm__ __volatile__ ("dmb" ::: "memory", "cc")
65 #define rseq_smp_wmb() __asm__ __volatile__ ("dmb" ::: "memory", "cc")
67 #define rseq_smp_load_acquire(p) \
69 __typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \
74 #define rseq_smp_acquire__after_ctrl_dep() rseq_smp_rmb()
76 #define rseq_smp_store_release(p, v) \
79 RSEQ_WRITE_ONCE(*p, v); \
82 #ifdef RSEQ_SKIP_FASTPATH
83 #include "rseq-skip.h"
84 #else /* !RSEQ_SKIP_FASTPATH */
86 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
87 post_commit_offset, abort_ip) \
88 ".pushsection __rseq_cs, \"aw\"\n\t" \
90 __rseq_str(label) ":\n\t" \
91 ".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
92 ".word " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) ", 0x0\n\t" \
94 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
95 ".word " __rseq_str(label) "b, 0x0\n\t" \
98 #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
99 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
100 (post_commit_ip - start_ip), abort_ip)
103 * Exit points of a rseq critical section consist of all instructions outside
104 * of the critical section where a critical section can either branch to or
105 * reach through the normal course of its execution. The abort IP and the
106 * post-commit IP are already part of the __rseq_cs section and should not be
107 * explicitly defined as additional exit points. Knowing all exit points is
108 * useful to assist debuggers stepping over the critical section.
110 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
111 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
112 ".word " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) ", 0x0\n\t" \
115 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
117 "adr r0, " __rseq_str(cs_label) "\n\t" \
118 "str r0, %[" __rseq_str(rseq_cs) "]\n\t" \
119 __rseq_str(label) ":\n\t"
121 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
123 "ldr r0, %[" __rseq_str(current_cpu_id) "]\n\t" \
124 "cmp %[" __rseq_str(cpu_id) "], r0\n\t" \
125 "bne " __rseq_str(label) "\n\t"
127 #define __RSEQ_ASM_DEFINE_ABORT(table_label, label, teardown, \
128 abort_label, version, flags, \
129 start_ip, post_commit_offset, abort_ip) \
131 __rseq_str(table_label) ":\n\t" \
132 ".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
133 ".word " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) ", 0x0\n\t" \
134 ".word " __rseq_str(RSEQ_SIG) "\n\t" \
135 __rseq_str(label) ":\n\t" \
137 "b %l[" __rseq_str(abort_label) "]\n\t"
139 #define RSEQ_ASM_DEFINE_ABORT(table_label, label, teardown, abort_label, \
140 start_ip, post_commit_ip, abort_ip) \
141 __RSEQ_ASM_DEFINE_ABORT(table_label, label, teardown, \
142 abort_label, 0x0, 0x0, start_ip, \
143 (post_commit_ip - start_ip), abort_ip)
145 #define RSEQ_ASM_DEFINE_CMPFAIL(label, teardown, cmpfail_label) \
146 __rseq_str(label) ":\n\t" \
148 "b %l[" __rseq_str(cmpfail_label) "]\n\t"
150 #define rseq_workaround_gcc_asm_size_guess() __asm__ __volatile__("")
152 static inline __attribute__((always_inline
))
153 int rseq_cmpeqv_storev(intptr_t *v
, intptr_t expect
, intptr_t newv
, int cpu
)
157 rseq_workaround_gcc_asm_size_guess();
158 __asm__ __volatile__
goto (
159 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
160 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
161 #ifdef RSEQ_COMPARE_TWICE
162 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
163 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
165 /* Start rseq by storing table entry pointer into rseq_cs. */
166 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
167 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
170 "cmp %[expect], r0\n\t"
171 "bne %l[cmpfail]\n\t"
173 #ifdef RSEQ_COMPARE_TWICE
174 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
176 "cmp %[expect], r0\n\t"
180 "str %[newv], %[v]\n\t"
184 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
186 : /* gcc asm goto does not allow outputs */
187 : [cpu_id
] "r" (cpu
),
188 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
189 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
191 [expect
] "r" (expect
),
194 : "r0", "memory", "cc"
197 #ifdef RSEQ_COMPARE_TWICE
201 rseq_workaround_gcc_asm_size_guess();
204 rseq_workaround_gcc_asm_size_guess();
208 rseq_workaround_gcc_asm_size_guess();
210 #ifdef RSEQ_COMPARE_TWICE
212 rseq_bug("cpu_id comparison failed");
214 rseq_bug("expected value comparison failed");
218 static inline __attribute__((always_inline
))
219 int rseq_cmpnev_storeoffp_load(intptr_t *v
, intptr_t expectnot
,
220 off_t voffp
, intptr_t *load
, int cpu
)
224 rseq_workaround_gcc_asm_size_guess();
225 __asm__ __volatile__
goto (
226 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
227 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
228 #ifdef RSEQ_COMPARE_TWICE
229 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
230 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
232 /* Start rseq by storing table entry pointer into rseq_cs. */
233 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
234 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
237 "cmp %[expectnot], r0\n\t"
238 "beq %l[cmpfail]\n\t"
240 #ifdef RSEQ_COMPARE_TWICE
241 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
243 "cmp %[expectnot], r0\n\t"
246 "str r0, %[load]\n\t"
247 "add r0, %[voffp]\n\t"
254 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
256 : /* gcc asm goto does not allow outputs */
257 : [cpu_id
] "r" (cpu
),
258 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
259 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
260 /* final store input */
262 [expectnot
] "r" (expectnot
),
263 [voffp
] "Ir" (voffp
),
266 : "r0", "memory", "cc"
269 #ifdef RSEQ_COMPARE_TWICE
273 rseq_workaround_gcc_asm_size_guess();
276 rseq_workaround_gcc_asm_size_guess();
280 rseq_workaround_gcc_asm_size_guess();
282 #ifdef RSEQ_COMPARE_TWICE
284 rseq_bug("cpu_id comparison failed");
286 rseq_bug("expected value comparison failed");
290 static inline __attribute__((always_inline
))
291 int rseq_addv(intptr_t *v
, intptr_t count
, int cpu
)
295 rseq_workaround_gcc_asm_size_guess();
296 __asm__ __volatile__
goto (
297 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
298 #ifdef RSEQ_COMPARE_TWICE
299 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
301 /* Start rseq by storing table entry pointer into rseq_cs. */
302 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
303 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
305 #ifdef RSEQ_COMPARE_TWICE
306 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
309 "add r0, %[count]\n\t"
315 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
317 : /* gcc asm goto does not allow outputs */
318 : [cpu_id
] "r" (cpu
),
319 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
320 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
324 : "r0", "memory", "cc"
327 #ifdef RSEQ_COMPARE_TWICE
331 rseq_workaround_gcc_asm_size_guess();
334 rseq_workaround_gcc_asm_size_guess();
337 #ifdef RSEQ_COMPARE_TWICE
339 rseq_bug("cpu_id comparison failed");
343 static inline __attribute__((always_inline
))
344 int rseq_cmpeqv_trystorev_storev(intptr_t *v
, intptr_t expect
,
345 intptr_t *v2
, intptr_t newv2
,
346 intptr_t newv
, int cpu
)
350 rseq_workaround_gcc_asm_size_guess();
351 __asm__ __volatile__
goto (
352 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
353 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
354 #ifdef RSEQ_COMPARE_TWICE
355 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
356 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
358 /* Start rseq by storing table entry pointer into rseq_cs. */
359 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
360 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
363 "cmp %[expect], r0\n\t"
364 "bne %l[cmpfail]\n\t"
366 #ifdef RSEQ_COMPARE_TWICE
367 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
369 "cmp %[expect], r0\n\t"
373 "str %[newv2], %[v2]\n\t"
376 "str %[newv], %[v]\n\t"
380 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
382 : /* gcc asm goto does not allow outputs */
383 : [cpu_id
] "r" (cpu
),
384 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
385 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
386 /* try store input */
389 /* final store input */
391 [expect
] "r" (expect
),
394 : "r0", "memory", "cc"
397 #ifdef RSEQ_COMPARE_TWICE
401 rseq_workaround_gcc_asm_size_guess();
404 rseq_workaround_gcc_asm_size_guess();
408 rseq_workaround_gcc_asm_size_guess();
410 #ifdef RSEQ_COMPARE_TWICE
412 rseq_bug("cpu_id comparison failed");
414 rseq_bug("expected value comparison failed");
418 static inline __attribute__((always_inline
))
419 int rseq_cmpeqv_trystorev_storev_release(intptr_t *v
, intptr_t expect
,
420 intptr_t *v2
, intptr_t newv2
,
421 intptr_t newv
, int cpu
)
425 rseq_workaround_gcc_asm_size_guess();
426 __asm__ __volatile__
goto (
427 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
428 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
429 #ifdef RSEQ_COMPARE_TWICE
430 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
431 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
433 /* Start rseq by storing table entry pointer into rseq_cs. */
434 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
435 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
438 "cmp %[expect], r0\n\t"
439 "bne %l[cmpfail]\n\t"
441 #ifdef RSEQ_COMPARE_TWICE
442 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
444 "cmp %[expect], r0\n\t"
448 "str %[newv2], %[v2]\n\t"
450 "dmb\n\t" /* full mb provides store-release */
452 "str %[newv], %[v]\n\t"
456 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
458 : /* gcc asm goto does not allow outputs */
459 : [cpu_id
] "r" (cpu
),
460 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
461 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
462 /* try store input */
465 /* final store input */
467 [expect
] "r" (expect
),
470 : "r0", "memory", "cc"
473 #ifdef RSEQ_COMPARE_TWICE
477 rseq_workaround_gcc_asm_size_guess();
480 rseq_workaround_gcc_asm_size_guess();
484 rseq_workaround_gcc_asm_size_guess();
486 #ifdef RSEQ_COMPARE_TWICE
488 rseq_bug("cpu_id comparison failed");
490 rseq_bug("expected value comparison failed");
494 static inline __attribute__((always_inline
))
495 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v
, intptr_t expect
,
496 intptr_t *v2
, intptr_t expect2
,
497 intptr_t newv
, int cpu
)
501 rseq_workaround_gcc_asm_size_guess();
502 __asm__ __volatile__
goto (
503 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
504 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
505 #ifdef RSEQ_COMPARE_TWICE
506 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
507 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
508 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error3
])
510 /* Start rseq by storing table entry pointer into rseq_cs. */
511 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
512 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
515 "cmp %[expect], r0\n\t"
516 "bne %l[cmpfail]\n\t"
519 "cmp %[expect2], r0\n\t"
520 "bne %l[cmpfail]\n\t"
522 #ifdef RSEQ_COMPARE_TWICE
523 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
525 "cmp %[expect], r0\n\t"
528 "cmp %[expect2], r0\n\t"
532 "str %[newv], %[v]\n\t"
536 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
538 : /* gcc asm goto does not allow outputs */
539 : [cpu_id
] "r" (cpu
),
540 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
541 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
544 [expect2
] "r" (expect2
),
545 /* final store input */
547 [expect
] "r" (expect
),
550 : "r0", "memory", "cc"
553 #ifdef RSEQ_COMPARE_TWICE
554 , error1
, error2
, error3
557 rseq_workaround_gcc_asm_size_guess();
560 rseq_workaround_gcc_asm_size_guess();
564 rseq_workaround_gcc_asm_size_guess();
566 #ifdef RSEQ_COMPARE_TWICE
568 rseq_bug("cpu_id comparison failed");
570 rseq_bug("1st expected value comparison failed");
572 rseq_bug("2nd expected value comparison failed");
576 static inline __attribute__((always_inline
))
577 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v
, intptr_t expect
,
578 void *dst
, void *src
, size_t len
,
579 intptr_t newv
, int cpu
)
581 uint32_t rseq_scratch
[3];
585 rseq_workaround_gcc_asm_size_guess();
586 __asm__ __volatile__
goto (
587 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
588 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
589 #ifdef RSEQ_COMPARE_TWICE
590 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
591 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
593 "str %[src], %[rseq_scratch0]\n\t"
594 "str %[dst], %[rseq_scratch1]\n\t"
595 "str %[len], %[rseq_scratch2]\n\t"
596 /* Start rseq by storing table entry pointer into rseq_cs. */
597 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
598 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
601 "cmp %[expect], r0\n\t"
604 #ifdef RSEQ_COMPARE_TWICE
605 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 6f
)
607 "cmp %[expect], r0\n\t"
611 "cmp %[len], #0\n\t" \
614 "ldrb %%r0, [%[src]]\n\t" \
615 "strb %%r0, [%[dst]]\n\t" \
616 "adds %[src], #1\n\t" \
617 "adds %[dst], #1\n\t" \
618 "subs %[len], #1\n\t" \
623 "str %[newv], %[v]\n\t"
627 "ldr %[len], %[rseq_scratch2]\n\t"
628 "ldr %[dst], %[rseq_scratch1]\n\t"
629 "ldr %[src], %[rseq_scratch0]\n\t"
631 RSEQ_ASM_DEFINE_ABORT(3, 4,
633 "ldr %[len], %[rseq_scratch2]\n\t"
634 "ldr %[dst], %[rseq_scratch1]\n\t"
635 "ldr %[src], %[rseq_scratch0]\n\t",
637 RSEQ_ASM_DEFINE_CMPFAIL(5,
639 "ldr %[len], %[rseq_scratch2]\n\t"
640 "ldr %[dst], %[rseq_scratch1]\n\t"
641 "ldr %[src], %[rseq_scratch0]\n\t",
643 #ifdef RSEQ_COMPARE_TWICE
644 RSEQ_ASM_DEFINE_CMPFAIL(6,
646 "ldr %[len], %[rseq_scratch2]\n\t"
647 "ldr %[dst], %[rseq_scratch1]\n\t"
648 "ldr %[src], %[rseq_scratch0]\n\t",
650 RSEQ_ASM_DEFINE_CMPFAIL(7,
652 "ldr %[len], %[rseq_scratch2]\n\t"
653 "ldr %[dst], %[rseq_scratch1]\n\t"
654 "ldr %[src], %[rseq_scratch0]\n\t",
658 : /* gcc asm goto does not allow outputs */
659 : [cpu_id
] "r" (cpu
),
660 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
661 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
662 /* final store input */
664 [expect
] "r" (expect
),
666 /* try memcpy input */
670 [rseq_scratch0
] "m" (rseq_scratch
[0]),
671 [rseq_scratch1
] "m" (rseq_scratch
[1]),
672 [rseq_scratch2
] "m" (rseq_scratch
[2])
674 : "r0", "memory", "cc"
677 #ifdef RSEQ_COMPARE_TWICE
681 rseq_workaround_gcc_asm_size_guess();
684 rseq_workaround_gcc_asm_size_guess();
688 rseq_workaround_gcc_asm_size_guess();
690 #ifdef RSEQ_COMPARE_TWICE
692 rseq_workaround_gcc_asm_size_guess();
693 rseq_bug("cpu_id comparison failed");
695 rseq_workaround_gcc_asm_size_guess();
696 rseq_bug("expected value comparison failed");
700 static inline __attribute__((always_inline
))
701 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v
, intptr_t expect
,
702 void *dst
, void *src
, size_t len
,
703 intptr_t newv
, int cpu
)
705 uint32_t rseq_scratch
[3];
709 rseq_workaround_gcc_asm_size_guess();
710 __asm__ __volatile__
goto (
711 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
712 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
713 #ifdef RSEQ_COMPARE_TWICE
714 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
715 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
717 "str %[src], %[rseq_scratch0]\n\t"
718 "str %[dst], %[rseq_scratch1]\n\t"
719 "str %[len], %[rseq_scratch2]\n\t"
720 /* Start rseq by storing table entry pointer into rseq_cs. */
721 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
722 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
725 "cmp %[expect], r0\n\t"
728 #ifdef RSEQ_COMPARE_TWICE
729 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 6f
)
731 "cmp %[expect], r0\n\t"
735 "cmp %[len], #0\n\t" \
738 "ldrb %%r0, [%[src]]\n\t" \
739 "strb %%r0, [%[dst]]\n\t" \
740 "adds %[src], #1\n\t" \
741 "adds %[dst], #1\n\t" \
742 "subs %[len], #1\n\t" \
746 "dmb\n\t" /* full mb provides store-release */
748 "str %[newv], %[v]\n\t"
752 "ldr %[len], %[rseq_scratch2]\n\t"
753 "ldr %[dst], %[rseq_scratch1]\n\t"
754 "ldr %[src], %[rseq_scratch0]\n\t"
756 RSEQ_ASM_DEFINE_ABORT(3, 4,
758 "ldr %[len], %[rseq_scratch2]\n\t"
759 "ldr %[dst], %[rseq_scratch1]\n\t"
760 "ldr %[src], %[rseq_scratch0]\n\t",
762 RSEQ_ASM_DEFINE_CMPFAIL(5,
764 "ldr %[len], %[rseq_scratch2]\n\t"
765 "ldr %[dst], %[rseq_scratch1]\n\t"
766 "ldr %[src], %[rseq_scratch0]\n\t",
768 #ifdef RSEQ_COMPARE_TWICE
769 RSEQ_ASM_DEFINE_CMPFAIL(6,
771 "ldr %[len], %[rseq_scratch2]\n\t"
772 "ldr %[dst], %[rseq_scratch1]\n\t"
773 "ldr %[src], %[rseq_scratch0]\n\t",
775 RSEQ_ASM_DEFINE_CMPFAIL(7,
777 "ldr %[len], %[rseq_scratch2]\n\t"
778 "ldr %[dst], %[rseq_scratch1]\n\t"
779 "ldr %[src], %[rseq_scratch0]\n\t",
783 : /* gcc asm goto does not allow outputs */
784 : [cpu_id
] "r" (cpu
),
785 [current_cpu_id
] "m" (__rseq_abi
.cpu_id
),
786 [rseq_cs
] "m" (__rseq_abi
.rseq_cs
),
787 /* final store input */
789 [expect
] "r" (expect
),
791 /* try memcpy input */
795 [rseq_scratch0
] "m" (rseq_scratch
[0]),
796 [rseq_scratch1
] "m" (rseq_scratch
[1]),
797 [rseq_scratch2
] "m" (rseq_scratch
[2])
799 : "r0", "memory", "cc"
802 #ifdef RSEQ_COMPARE_TWICE
806 rseq_workaround_gcc_asm_size_guess();
809 rseq_workaround_gcc_asm_size_guess();
813 rseq_workaround_gcc_asm_size_guess();
815 #ifdef RSEQ_COMPARE_TWICE
817 rseq_workaround_gcc_asm_size_guess();
818 rseq_bug("cpu_id comparison failed");
820 rseq_workaround_gcc_asm_size_guess();
821 rseq_bug("expected value comparison failed");
825 #endif /* !RSEQ_SKIP_FASTPATH */