c97784bbced7bb172e2e8b01fbd60af81da9dbee
1 /* SPDX-License-Identifier: MIT */
2 /* SPDX-FileCopyrightText: 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 static inline __attribute__((always_inline
))
151 int rseq_cmpeqv_storev(intptr_t *v
, intptr_t expect
, intptr_t newv
, int cpu
)
155 __asm__ __volatile__
goto (
156 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
157 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
158 #ifdef RSEQ_COMPARE_TWICE
159 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
160 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
162 /* Start rseq by storing table entry pointer into rseq_cs. */
163 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
164 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
167 "cmp %[expect], r0\n\t"
168 "bne %l[cmpfail]\n\t"
170 #ifdef RSEQ_COMPARE_TWICE
171 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
173 "cmp %[expect], r0\n\t"
177 "str %[newv], %[v]\n\t"
181 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
183 : /* gcc asm goto does not allow outputs */
184 : [cpu_id
] "r" (cpu
),
185 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
186 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
188 [expect
] "r" (expect
),
191 : "r0", "memory", "cc"
194 #ifdef RSEQ_COMPARE_TWICE
198 rseq_after_asm_goto();
201 rseq_after_asm_goto();
205 rseq_after_asm_goto();
207 #ifdef RSEQ_COMPARE_TWICE
209 rseq_after_asm_goto();
210 rseq_bug("cpu_id comparison failed");
212 rseq_after_asm_goto();
213 rseq_bug("expected value comparison failed");
217 static inline __attribute__((always_inline
))
218 int rseq_cmpnev_storeoffp_load(intptr_t *v
, intptr_t expectnot
,
219 long voffp
, intptr_t *load
, int cpu
)
223 __asm__ __volatile__
goto (
224 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
225 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
226 #ifdef RSEQ_COMPARE_TWICE
227 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
228 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
230 /* Start rseq by storing table entry pointer into rseq_cs. */
231 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
232 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
235 "cmp %[expectnot], r0\n\t"
236 "beq %l[cmpfail]\n\t"
238 #ifdef RSEQ_COMPARE_TWICE
239 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
241 "cmp %[expectnot], r0\n\t"
244 "str r0, %[load]\n\t"
245 "add r0, %[voffp]\n\t"
252 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
254 : /* gcc asm goto does not allow outputs */
255 : [cpu_id
] "r" (cpu
),
256 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
257 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
258 /* final store input */
260 [expectnot
] "r" (expectnot
),
261 [voffp
] "Ir" (voffp
),
264 : "r0", "memory", "cc"
267 #ifdef RSEQ_COMPARE_TWICE
271 rseq_after_asm_goto();
274 rseq_after_asm_goto();
278 rseq_after_asm_goto();
280 #ifdef RSEQ_COMPARE_TWICE
282 rseq_after_asm_goto();
283 rseq_bug("cpu_id comparison failed");
285 rseq_after_asm_goto();
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 __asm__ __volatile__
goto (
296 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
297 #ifdef RSEQ_COMPARE_TWICE
298 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
300 /* Start rseq by storing table entry pointer into rseq_cs. */
301 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
302 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
304 #ifdef RSEQ_COMPARE_TWICE
305 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
308 "add r0, %[count]\n\t"
314 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
316 : /* gcc asm goto does not allow outputs */
317 : [cpu_id
] "r" (cpu
),
318 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
319 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
323 : "r0", "memory", "cc"
326 #ifdef RSEQ_COMPARE_TWICE
330 rseq_after_asm_goto();
333 rseq_after_asm_goto();
336 #ifdef RSEQ_COMPARE_TWICE
338 rseq_after_asm_goto();
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 __asm__ __volatile__
goto (
351 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
352 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
353 #ifdef RSEQ_COMPARE_TWICE
354 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
355 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
357 /* Start rseq by storing table entry pointer into rseq_cs. */
358 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
359 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
362 "cmp %[expect], r0\n\t"
363 "bne %l[cmpfail]\n\t"
365 #ifdef RSEQ_COMPARE_TWICE
366 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
368 "cmp %[expect], r0\n\t"
372 "str %[newv2], %[v2]\n\t"
375 "str %[newv], %[v]\n\t"
379 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
381 : /* gcc asm goto does not allow outputs */
382 : [cpu_id
] "r" (cpu
),
383 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
384 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
385 /* try store input */
388 /* final store input */
390 [expect
] "r" (expect
),
393 : "r0", "memory", "cc"
396 #ifdef RSEQ_COMPARE_TWICE
400 rseq_after_asm_goto();
403 rseq_after_asm_goto();
407 rseq_after_asm_goto();
409 #ifdef RSEQ_COMPARE_TWICE
411 rseq_after_asm_goto();
412 rseq_bug("cpu_id comparison failed");
414 rseq_after_asm_goto();
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 __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_get_abi()->cpu_id
),
461 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
462 /* try store input */
465 /* final store input */
467 [expect
] "r" (expect
),
470 : "r0", "memory", "cc"
473 #ifdef RSEQ_COMPARE_TWICE
477 rseq_after_asm_goto();
480 rseq_after_asm_goto();
484 rseq_after_asm_goto();
486 #ifdef RSEQ_COMPARE_TWICE
488 rseq_after_asm_goto();
489 rseq_bug("cpu_id comparison failed");
491 rseq_after_asm_goto();
492 rseq_bug("expected value comparison failed");
496 static inline __attribute__((always_inline
))
497 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v
, intptr_t expect
,
498 intptr_t *v2
, intptr_t expect2
,
499 intptr_t newv
, int cpu
)
503 __asm__ __volatile__
goto (
504 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
505 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
506 #ifdef RSEQ_COMPARE_TWICE
507 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
508 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
509 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error3
])
511 /* Start rseq by storing table entry pointer into rseq_cs. */
512 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
513 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
516 "cmp %[expect], r0\n\t"
517 "bne %l[cmpfail]\n\t"
520 "cmp %[expect2], r0\n\t"
521 "bne %l[cmpfail]\n\t"
523 #ifdef RSEQ_COMPARE_TWICE
524 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
526 "cmp %[expect], r0\n\t"
529 "cmp %[expect2], r0\n\t"
533 "str %[newv], %[v]\n\t"
537 RSEQ_ASM_DEFINE_ABORT(3, 4, "", abort
, 1b
, 2b
, 4f
)
539 : /* gcc asm goto does not allow outputs */
540 : [cpu_id
] "r" (cpu
),
541 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
542 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
545 [expect2
] "r" (expect2
),
546 /* final store input */
548 [expect
] "r" (expect
),
551 : "r0", "memory", "cc"
554 #ifdef RSEQ_COMPARE_TWICE
555 , error1
, error2
, error3
558 rseq_after_asm_goto();
561 rseq_after_asm_goto();
565 rseq_after_asm_goto();
567 #ifdef RSEQ_COMPARE_TWICE
569 rseq_after_asm_goto();
570 rseq_bug("cpu_id comparison failed");
572 rseq_after_asm_goto();
573 rseq_bug("1st expected value comparison failed");
575 rseq_after_asm_goto();
576 rseq_bug("2nd expected value comparison failed");
580 static inline __attribute__((always_inline
))
581 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v
, intptr_t expect
,
582 void *dst
, void *src
, size_t len
,
583 intptr_t newv
, int cpu
)
585 uint32_t rseq_scratch
[3];
589 __asm__ __volatile__
goto (
590 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
591 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
592 #ifdef RSEQ_COMPARE_TWICE
593 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
594 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
596 "str %[src], %[rseq_scratch0]\n\t"
597 "str %[dst], %[rseq_scratch1]\n\t"
598 "str %[len], %[rseq_scratch2]\n\t"
599 /* Start rseq by storing table entry pointer into rseq_cs. */
600 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
601 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
604 "cmp %[expect], r0\n\t"
607 #ifdef RSEQ_COMPARE_TWICE
608 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 6f
)
610 "cmp %[expect], r0\n\t"
614 "cmp %[len], #0\n\t" \
617 "ldrb %%r0, [%[src]]\n\t" \
618 "strb %%r0, [%[dst]]\n\t" \
619 "adds %[src], #1\n\t" \
620 "adds %[dst], #1\n\t" \
621 "subs %[len], #1\n\t" \
626 "str %[newv], %[v]\n\t"
630 "ldr %[len], %[rseq_scratch2]\n\t"
631 "ldr %[dst], %[rseq_scratch1]\n\t"
632 "ldr %[src], %[rseq_scratch0]\n\t"
634 RSEQ_ASM_DEFINE_ABORT(3, 4,
636 "ldr %[len], %[rseq_scratch2]\n\t"
637 "ldr %[dst], %[rseq_scratch1]\n\t"
638 "ldr %[src], %[rseq_scratch0]\n\t",
640 RSEQ_ASM_DEFINE_CMPFAIL(5,
642 "ldr %[len], %[rseq_scratch2]\n\t"
643 "ldr %[dst], %[rseq_scratch1]\n\t"
644 "ldr %[src], %[rseq_scratch0]\n\t",
646 #ifdef RSEQ_COMPARE_TWICE
647 RSEQ_ASM_DEFINE_CMPFAIL(6,
649 "ldr %[len], %[rseq_scratch2]\n\t"
650 "ldr %[dst], %[rseq_scratch1]\n\t"
651 "ldr %[src], %[rseq_scratch0]\n\t",
653 RSEQ_ASM_DEFINE_CMPFAIL(7,
655 "ldr %[len], %[rseq_scratch2]\n\t"
656 "ldr %[dst], %[rseq_scratch1]\n\t"
657 "ldr %[src], %[rseq_scratch0]\n\t",
661 : /* gcc asm goto does not allow outputs */
662 : [cpu_id
] "r" (cpu
),
663 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
664 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
665 /* final store input */
667 [expect
] "r" (expect
),
669 /* try memcpy input */
673 [rseq_scratch0
] "m" (rseq_scratch
[0]),
674 [rseq_scratch1
] "m" (rseq_scratch
[1]),
675 [rseq_scratch2
] "m" (rseq_scratch
[2])
677 : "r0", "memory", "cc"
680 #ifdef RSEQ_COMPARE_TWICE
684 rseq_after_asm_goto();
687 rseq_after_asm_goto();
691 rseq_after_asm_goto();
693 #ifdef RSEQ_COMPARE_TWICE
695 rseq_after_asm_goto();
696 rseq_bug("cpu_id comparison failed");
698 rseq_after_asm_goto();
699 rseq_bug("expected value comparison failed");
703 static inline __attribute__((always_inline
))
704 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v
, intptr_t expect
,
705 void *dst
, void *src
, size_t len
,
706 intptr_t newv
, int cpu
)
708 uint32_t rseq_scratch
[3];
712 __asm__ __volatile__
goto (
713 RSEQ_ASM_DEFINE_TABLE(9, 1f
, 2f
, 4f
) /* start, commit, abort */
714 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
715 #ifdef RSEQ_COMPARE_TWICE
716 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
717 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
719 "str %[src], %[rseq_scratch0]\n\t"
720 "str %[dst], %[rseq_scratch1]\n\t"
721 "str %[len], %[rseq_scratch2]\n\t"
722 /* Start rseq by storing table entry pointer into rseq_cs. */
723 RSEQ_ASM_STORE_RSEQ_CS(1, 3f
, rseq_cs
)
724 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
727 "cmp %[expect], r0\n\t"
730 #ifdef RSEQ_COMPARE_TWICE
731 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 6f
)
733 "cmp %[expect], r0\n\t"
737 "cmp %[len], #0\n\t" \
740 "ldrb %%r0, [%[src]]\n\t" \
741 "strb %%r0, [%[dst]]\n\t" \
742 "adds %[src], #1\n\t" \
743 "adds %[dst], #1\n\t" \
744 "subs %[len], #1\n\t" \
748 "dmb\n\t" /* full mb provides store-release */
750 "str %[newv], %[v]\n\t"
754 "ldr %[len], %[rseq_scratch2]\n\t"
755 "ldr %[dst], %[rseq_scratch1]\n\t"
756 "ldr %[src], %[rseq_scratch0]\n\t"
758 RSEQ_ASM_DEFINE_ABORT(3, 4,
760 "ldr %[len], %[rseq_scratch2]\n\t"
761 "ldr %[dst], %[rseq_scratch1]\n\t"
762 "ldr %[src], %[rseq_scratch0]\n\t",
764 RSEQ_ASM_DEFINE_CMPFAIL(5,
766 "ldr %[len], %[rseq_scratch2]\n\t"
767 "ldr %[dst], %[rseq_scratch1]\n\t"
768 "ldr %[src], %[rseq_scratch0]\n\t",
770 #ifdef RSEQ_COMPARE_TWICE
771 RSEQ_ASM_DEFINE_CMPFAIL(6,
773 "ldr %[len], %[rseq_scratch2]\n\t"
774 "ldr %[dst], %[rseq_scratch1]\n\t"
775 "ldr %[src], %[rseq_scratch0]\n\t",
777 RSEQ_ASM_DEFINE_CMPFAIL(7,
779 "ldr %[len], %[rseq_scratch2]\n\t"
780 "ldr %[dst], %[rseq_scratch1]\n\t"
781 "ldr %[src], %[rseq_scratch0]\n\t",
785 : /* gcc asm goto does not allow outputs */
786 : [cpu_id
] "r" (cpu
),
787 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
788 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
789 /* final store input */
791 [expect
] "r" (expect
),
793 /* try memcpy input */
797 [rseq_scratch0
] "m" (rseq_scratch
[0]),
798 [rseq_scratch1
] "m" (rseq_scratch
[1]),
799 [rseq_scratch2
] "m" (rseq_scratch
[2])
801 : "r0", "memory", "cc"
804 #ifdef RSEQ_COMPARE_TWICE
808 rseq_after_asm_goto();
811 rseq_after_asm_goto();
815 rseq_after_asm_goto();
817 #ifdef RSEQ_COMPARE_TWICE
819 rseq_after_asm_goto();
820 rseq_bug("cpu_id comparison failed");
822 rseq_after_asm_goto();
823 rseq_bug("expected value comparison failed");
827 #endif /* !RSEQ_SKIP_FASTPATH */
This page took 0.047637 seconds and 3 git commands to generate.