All arch: use rseq_unqual_scalar_typeof in load-acquire
[librseq.git] / include / rseq / rseq-ppc.h
index 6780683f6950960f9789b25297b6eabbc908e1e2..81c8586b6af4d27ba57c7b15986f9dceb641fa3c 100644 (file)
@@ -1,9 +1,9 @@
-/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
+/* SPDX-License-Identifier: MIT */
+/* SPDX-FileCopyrightText: 2016-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
+/* SPDX-FileCopyrightText: 2016-2018 Boqun Feng <boqun.feng@gmail.com> */
+
 /*
  * rseq-ppc.h
- *
- * (C) Copyright 2016-2018 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * (C) Copyright 2016-2018 - Boqun Feng <boqun.feng@gmail.com>
  */
 
 /*
@@ -23,7 +23,7 @@
 
 #define rseq_smp_load_acquire(p)                                       \
 __extension__ ({                                                       \
-       __typeof(*p) ____p1 = RSEQ_READ_ONCE(*p);                       \
+       rseq_unqual_scalar_typeof(*(p)) ____p1 = RSEQ_READ_ONCE(*(p));  \
        rseq_smp_lwsync();                                              \
        ____p1;                                                         \
 })
@@ -33,7 +33,7 @@ __extension__ ({                                                      \
 #define rseq_smp_store_release(p, v)                                   \
 do {                                                                   \
        rseq_smp_lwsync();                                              \
-       RSEQ_WRITE_ONCE(*p, v);                                         \
+       RSEQ_WRITE_ONCE(*(p), v);                                       \
 } while (0)
 
 #ifdef RSEQ_SKIP_FASTPATH
@@ -53,6 +53,7 @@ do {                                                                  \
 #define RSEQ_LOAD_INT(arg)     "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] "    /* From memory ("m" constraint) */
 #define RSEQ_LOADX_LONG                "ldx "                                                  /* From base register ("b" constraint) */
 #define RSEQ_CMP_LONG          "cmpd "
+#define RSEQ_CMP_LONG_INT      "cmpdi "
 
 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags,                         \
                        start_ip, post_commit_offset, abort_ip)                 \
@@ -97,6 +98,7 @@ do {                                                                  \
 #define RSEQ_LOAD_INT(arg)     RSEQ_LOAD_LONG(arg)                                     /* From memory ("m" constraint) */
 #define RSEQ_LOADX_LONG                "lwzx "                                                 /* From base register ("b" constraint) */
 #define RSEQ_CMP_LONG          "cmpw "
+#define RSEQ_CMP_LONG_INT      "cmpwi "
 
 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags,                         \
                        start_ip, post_commit_offset, abort_ip)                 \
@@ -187,7 +189,7 @@ do {                                                                        \
 
 /* TODO: implement a faster memcpy. */
 #define RSEQ_ASM_OP_R_MEMCPY() \
-               "cmpdi %%r19, 0\n\t" \
+               RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
                "beq 333f\n\t" \
                "addi %%r20, %%r20, -1\n\t" \
                "addi %%r21, %%r21, -1\n\t" \
@@ -195,7 +197,7 @@ do {                                                                        \
                "lbzu %%r18, 1(%%r20)\n\t" \
                "stbu %%r18, 1(%%r21)\n\t" \
                "addi %%r19, %%r19, -1\n\t" \
-               "cmpdi %%r19, 0\n\t" \
+               RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
                "bne 222b\n\t" \
                "333:\n\t" \
 
@@ -239,8 +241,8 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
                  [newv]                "r" (newv)
@@ -252,23 +254,28 @@ int rseq_cmpeqv_storev(intptr_t *v, intptr_t expect, intptr_t newv, int cpu)
                  , error1, error2
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("expected value comparison failed");
 #endif
 }
 
 static inline __attribute__((always_inline))
 int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
-                              off_t voffp, intptr_t *load, int cpu)
+                              long voffp, intptr_t *load, int cpu)
 {
        RSEQ_INJECT_C(9)
 
@@ -305,8 +312,8 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expectnot]           "r" (expectnot),
@@ -320,16 +327,21 @@ int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot,
                  , error1, error2
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("expected value comparison failed");
 #endif
 }
@@ -363,8 +375,8 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [count]               "r" (count)
@@ -376,12 +388,15 @@ int rseq_addv(intptr_t *v, intptr_t count, int cpu)
                  , error1
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 #endif
 }
@@ -423,8 +438,8 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -440,16 +455,21 @@ int rseq_cmpeqv_trystorev_storev(intptr_t *v, intptr_t expect,
                  , error1, error2
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("expected value comparison failed");
 #endif
 }
@@ -493,8 +513,8 @@ int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* try store input */
                  [v2]                  "m" (*v2),
                  [newv2]               "r" (newv2),
@@ -510,16 +530,21 @@ int rseq_cmpeqv_trystorev_storev_release(intptr_t *v, intptr_t expect,
                  , error1, error2
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("expected value comparison failed");
 #endif
 }
@@ -564,8 +589,8 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* cmp2 input */
                  [v2]                  "m" (*v2),
                  [expect2]             "r" (expect2),
@@ -581,18 +606,24 @@ int rseq_cmpeqv_cmpeqv_storev(intptr_t *v, intptr_t expect,
                  , error1, error2, error3
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("1st expected value comparison failed");
 error3:
+       rseq_after_asm_goto();
        rseq_bug("2nd expected value comparison failed");
 #endif
 }
@@ -639,8 +670,8 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
@@ -657,16 +688,21 @@ int rseq_cmpeqv_trymemcpy_storev(intptr_t *v, intptr_t expect,
                  , error1, error2
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("expected value comparison failed");
 #endif
 }
@@ -715,8 +751,8 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
                RSEQ_ASM_DEFINE_ABORT(4, abort)
                : /* gcc asm goto does not allow outputs */
                : [cpu_id]              "r" (cpu),
-                 [current_cpu_id]      "m" (__rseq_abi.cpu_id),
-                 [rseq_cs]             "m" (__rseq_abi.rseq_cs),
+                 [current_cpu_id]      "m" (rseq_get_abi()->cpu_id),
+                 [rseq_cs]             "m" (rseq_get_abi()->rseq_cs.arch.ptr),
                  /* final store input */
                  [v]                   "m" (*v),
                  [expect]              "r" (expect),
@@ -733,23 +769,23 @@ int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v, intptr_t expect,
                  , error1, error2
 #endif
        );
+       rseq_after_asm_goto();
        return 0;
 abort:
+       rseq_after_asm_goto();
        RSEQ_INJECT_FAILED
        return -1;
 cmpfail:
+       rseq_after_asm_goto();
        return 1;
 #ifdef RSEQ_COMPARE_TWICE
 error1:
+       rseq_after_asm_goto();
        rseq_bug("cpu_id comparison failed");
 error2:
+       rseq_after_asm_goto();
        rseq_bug("expected value comparison failed");
 #endif
 }
 
-#undef RSEQ_STORE_LONG
-#undef RSEQ_LOAD_LONG
-#undef RSEQ_LOADX_LONG
-#undef RSEQ_CMP_LONG
-
 #endif /* !RSEQ_SKIP_FASTPATH */
This page took 0.030253 seconds and 4 git commands to generate.