.. | .. |
---|
6 | 6 | * (C) Copyright 2016-2018 - Boqun Feng <boqun.feng@gmail.com> |
---|
7 | 7 | */ |
---|
8 | 8 | |
---|
9 | | -#define RSEQ_SIG 0x53053053 |
---|
| 9 | +/* |
---|
| 10 | + * RSEQ_SIG is used with the following trap instruction: |
---|
| 11 | + * |
---|
| 12 | + * powerpc-be: 0f e5 00 0b twui r5,11 |
---|
| 13 | + * powerpc64-le: 0b 00 e5 0f twui r5,11 |
---|
| 14 | + * powerpc64-be: 0f e5 00 0b twui r5,11 |
---|
| 15 | + */ |
---|
| 16 | + |
---|
| 17 | +#define RSEQ_SIG 0x0fe5000b |
---|
10 | 18 | |
---|
11 | 19 | #define rseq_smp_mb() __asm__ __volatile__ ("sync" ::: "memory", "cc") |
---|
12 | 20 | #define rseq_smp_lwsync() __asm__ __volatile__ ("lwsync" ::: "memory", "cc") |
---|
.. | .. |
---|
33 | 41 | #else /* !RSEQ_SKIP_FASTPATH */ |
---|
34 | 42 | |
---|
35 | 43 | /* |
---|
36 | | - * The __rseq_table section can be used by debuggers to better handle |
---|
37 | | - * single-stepping through the restartable critical sections. |
---|
| 44 | + * The __rseq_cs_ptr_array and __rseq_cs sections can be used by debuggers to |
---|
| 45 | + * better handle single-stepping through the restartable critical sections. |
---|
38 | 46 | */ |
---|
39 | 47 | |
---|
40 | 48 | #ifdef __PPC64__ |
---|
41 | 49 | |
---|
42 | | -#define STORE_WORD "std " |
---|
43 | | -#define LOAD_WORD "ld " |
---|
44 | | -#define LOADX_WORD "ldx " |
---|
45 | | -#define CMP_WORD "cmpd " |
---|
| 50 | +#define RSEQ_STORE_LONG(arg) "std%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */ |
---|
| 51 | +#define RSEQ_STORE_INT(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */ |
---|
| 52 | +#define RSEQ_LOAD_LONG(arg) "ld%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */ |
---|
| 53 | +#define RSEQ_LOAD_INT(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */ |
---|
| 54 | +#define RSEQ_LOADX_LONG "ldx " /* From base register ("b" constraint) */ |
---|
| 55 | +#define RSEQ_CMP_LONG "cmpd " |
---|
| 56 | +#define RSEQ_CMP_LONG_INT "cmpdi " |
---|
46 | 57 | |
---|
47 | 58 | #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ |
---|
48 | 59 | start_ip, post_commit_offset, abort_ip) \ |
---|
49 | | - ".pushsection __rseq_table, \"aw\"\n\t" \ |
---|
| 60 | + ".pushsection __rseq_cs, \"aw\"\n\t" \ |
---|
50 | 61 | ".balign 32\n\t" \ |
---|
51 | 62 | __rseq_str(label) ":\n\t" \ |
---|
52 | 63 | ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \ |
---|
53 | 64 | ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \ |
---|
| 65 | + ".popsection\n\t" \ |
---|
| 66 | + ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \ |
---|
| 67 | + ".quad " __rseq_str(label) "b\n\t" \ |
---|
54 | 68 | ".popsection\n\t" |
---|
55 | 69 | |
---|
56 | 70 | #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \ |
---|
.. | .. |
---|
63 | 77 | "std %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \ |
---|
64 | 78 | __rseq_str(label) ":\n\t" |
---|
65 | 79 | |
---|
| 80 | +/* |
---|
| 81 | + * Exit points of a rseq critical section consist of all instructions outside |
---|
| 82 | + * of the critical section where a critical section can either branch to or |
---|
| 83 | + * reach through the normal course of its execution. The abort IP and the |
---|
| 84 | + * post-commit IP are already part of the __rseq_cs section and should not be |
---|
| 85 | + * explicitly defined as additional exit points. Knowing all exit points is |
---|
| 86 | + * useful to assist debuggers stepping over the critical section. |
---|
| 87 | + */ |
---|
| 88 | +#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \ |
---|
| 89 | + ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \ |
---|
| 90 | + ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \ |
---|
| 91 | + ".popsection\n\t" |
---|
| 92 | + |
---|
66 | 93 | #else /* #ifdef __PPC64__ */ |
---|
67 | 94 | |
---|
68 | | -#define STORE_WORD "stw " |
---|
69 | | -#define LOAD_WORD "lwz " |
---|
70 | | -#define LOADX_WORD "lwzx " |
---|
71 | | -#define CMP_WORD "cmpw " |
---|
| 95 | +#define RSEQ_STORE_LONG(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */ |
---|
| 96 | +#define RSEQ_STORE_INT(arg) RSEQ_STORE_LONG(arg) /* To memory ("m" constraint) */ |
---|
| 97 | +#define RSEQ_LOAD_LONG(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */ |
---|
| 98 | +#define RSEQ_LOAD_INT(arg) RSEQ_LOAD_LONG(arg) /* From memory ("m" constraint) */ |
---|
| 99 | +#define RSEQ_LOADX_LONG "lwzx " /* From base register ("b" constraint) */ |
---|
| 100 | +#define RSEQ_CMP_LONG "cmpw " |
---|
| 101 | +#define RSEQ_CMP_LONG_INT "cmpwi " |
---|
72 | 102 | |
---|
73 | 103 | #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ |
---|
74 | 104 | start_ip, post_commit_offset, abort_ip) \ |
---|
75 | | - ".pushsection __rseq_table, \"aw\"\n\t" \ |
---|
| 105 | + ".pushsection __rseq_cs, \"aw\"\n\t" \ |
---|
76 | 106 | ".balign 32\n\t" \ |
---|
77 | 107 | __rseq_str(label) ":\n\t" \ |
---|
78 | 108 | ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \ |
---|
79 | 109 | /* 32-bit only supported on BE */ \ |
---|
80 | 110 | ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) "\n\t" \ |
---|
| 111 | + ".popsection\n\t" \ |
---|
| 112 | + ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \ |
---|
| 113 | + ".long 0x0, " __rseq_str(label) "b\n\t" \ |
---|
| 114 | + ".popsection\n\t" |
---|
| 115 | + |
---|
| 116 | +/* |
---|
| 117 | + * Exit points of a rseq critical section consist of all instructions outside |
---|
| 118 | + * of the critical section where a critical section can either branch to or |
---|
| 119 | + * reach through the normal course of its execution. The abort IP and the |
---|
| 120 | + * post-commit IP are already part of the __rseq_cs section and should not be |
---|
| 121 | + * explicitly defined as additional exit points. Knowing all exit points is |
---|
| 122 | + * useful to assist debuggers stepping over the critical section. |
---|
| 123 | + */ |
---|
| 124 | +#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \ |
---|
| 125 | + ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \ |
---|
| 126 | + /* 32-bit only supported on BE */ \ |
---|
| 127 | + ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) "\n\t" \ |
---|
81 | 128 | ".popsection\n\t" |
---|
82 | 129 | |
---|
83 | 130 | #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \ |
---|
84 | 131 | RSEQ_INJECT_ASM(1) \ |
---|
85 | 132 | "lis %%r17, (" __rseq_str(cs_label) ")@ha\n\t" \ |
---|
86 | 133 | "addi %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \ |
---|
87 | | - "stw %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \ |
---|
| 134 | + RSEQ_STORE_INT(rseq_cs) "%%r17, %[" __rseq_str(rseq_cs) "]\n\t" \ |
---|
88 | 135 | __rseq_str(label) ":\n\t" |
---|
89 | 136 | |
---|
90 | 137 | #endif /* #ifdef __PPC64__ */ |
---|
.. | .. |
---|
95 | 142 | |
---|
96 | 143 | #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \ |
---|
97 | 144 | RSEQ_INJECT_ASM(2) \ |
---|
98 | | - "lwz %%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \ |
---|
| 145 | + RSEQ_LOAD_INT(current_cpu_id) "%%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \ |
---|
99 | 146 | "cmpw cr7, %[" __rseq_str(cpu_id) "], %%r17\n\t" \ |
---|
100 | 147 | "bne- cr7, " __rseq_str(label) "\n\t" |
---|
101 | 148 | |
---|
.. | .. |
---|
112 | 159 | * RSEQ_ASM_OP_* (else): doesn't have hard-code registers(unless cr7) |
---|
113 | 160 | */ |
---|
114 | 161 | #define RSEQ_ASM_OP_CMPEQ(var, expect, label) \ |
---|
115 | | - LOAD_WORD "%%r17, %[" __rseq_str(var) "]\n\t" \ |
---|
116 | | - CMP_WORD "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \ |
---|
| 162 | + RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \ |
---|
| 163 | + RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \ |
---|
117 | 164 | "bne- cr7, " __rseq_str(label) "\n\t" |
---|
118 | 165 | |
---|
119 | 166 | #define RSEQ_ASM_OP_CMPNE(var, expectnot, label) \ |
---|
120 | | - LOAD_WORD "%%r17, %[" __rseq_str(var) "]\n\t" \ |
---|
121 | | - CMP_WORD "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \ |
---|
| 167 | + RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \ |
---|
| 168 | + RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \ |
---|
122 | 169 | "beq- cr7, " __rseq_str(label) "\n\t" |
---|
123 | 170 | |
---|
124 | 171 | #define RSEQ_ASM_OP_STORE(value, var) \ |
---|
125 | | - STORE_WORD "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" |
---|
| 172 | + RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" |
---|
126 | 173 | |
---|
127 | 174 | /* Load @var to r17 */ |
---|
128 | 175 | #define RSEQ_ASM_OP_R_LOAD(var) \ |
---|
129 | | - LOAD_WORD "%%r17, %[" __rseq_str(var) "]\n\t" |
---|
| 176 | + RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" |
---|
130 | 177 | |
---|
131 | 178 | /* Store r17 to @var */ |
---|
132 | 179 | #define RSEQ_ASM_OP_R_STORE(var) \ |
---|
133 | | - STORE_WORD "%%r17, %[" __rseq_str(var) "]\n\t" |
---|
| 180 | + RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" |
---|
134 | 181 | |
---|
135 | 182 | /* Add @count to r17 */ |
---|
136 | 183 | #define RSEQ_ASM_OP_R_ADD(count) \ |
---|
.. | .. |
---|
138 | 185 | |
---|
139 | 186 | /* Load (r17 + voffp) to r17 */ |
---|
140 | 187 | #define RSEQ_ASM_OP_R_LOADX(voffp) \ |
---|
141 | | - LOADX_WORD "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t" |
---|
| 188 | + RSEQ_LOADX_LONG "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t" |
---|
142 | 189 | |
---|
143 | 190 | /* TODO: implement a faster memcpy. */ |
---|
144 | 191 | #define RSEQ_ASM_OP_R_MEMCPY() \ |
---|
145 | | - "cmpdi %%r19, 0\n\t" \ |
---|
| 192 | + RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \ |
---|
146 | 193 | "beq 333f\n\t" \ |
---|
147 | 194 | "addi %%r20, %%r20, -1\n\t" \ |
---|
148 | 195 | "addi %%r21, %%r21, -1\n\t" \ |
---|
.. | .. |
---|
150 | 197 | "lbzu %%r18, 1(%%r20)\n\t" \ |
---|
151 | 198 | "stbu %%r18, 1(%%r21)\n\t" \ |
---|
152 | 199 | "addi %%r19, %%r19, -1\n\t" \ |
---|
153 | | - "cmpdi %%r19, 0\n\t" \ |
---|
| 200 | + RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \ |
---|
154 | 201 | "bne 222b\n\t" \ |
---|
155 | 202 | "333:\n\t" \ |
---|
156 | 203 | |
---|
157 | 204 | #define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \ |
---|
158 | | - STORE_WORD "%%r17, %[" __rseq_str(var) "]\n\t" \ |
---|
| 205 | + RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \ |
---|
159 | 206 | __rseq_str(post_commit_label) ":\n\t" |
---|
160 | 207 | |
---|
161 | 208 | #define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \ |
---|
162 | | - STORE_WORD "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \ |
---|
| 209 | + RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \ |
---|
163 | 210 | __rseq_str(post_commit_label) ":\n\t" |
---|
164 | 211 | |
---|
165 | 212 | static inline __attribute__((always_inline)) |
---|
.. | .. |
---|
169 | 216 | |
---|
170 | 217 | __asm__ __volatile__ goto ( |
---|
171 | 218 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 219 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 220 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 221 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 222 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 223 | +#endif |
---|
172 | 224 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
173 | 225 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
174 | 226 | /* cmp cpuid */ |
---|
.. | .. |
---|
189 | 241 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
190 | 242 | : /* gcc asm goto does not allow outputs */ |
---|
191 | 243 | : [cpu_id] "r" (cpu), |
---|
192 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
193 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 244 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 245 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
194 | 246 | [v] "m" (*v), |
---|
195 | 247 | [expect] "r" (expect), |
---|
196 | 248 | [newv] "r" (newv) |
---|
.. | .. |
---|
202 | 254 | , error1, error2 |
---|
203 | 255 | #endif |
---|
204 | 256 | ); |
---|
| 257 | + rseq_after_asm_goto(); |
---|
205 | 258 | return 0; |
---|
206 | 259 | abort: |
---|
| 260 | + rseq_after_asm_goto(); |
---|
207 | 261 | RSEQ_INJECT_FAILED |
---|
208 | 262 | return -1; |
---|
209 | 263 | cmpfail: |
---|
| 264 | + rseq_after_asm_goto(); |
---|
210 | 265 | return 1; |
---|
211 | 266 | #ifdef RSEQ_COMPARE_TWICE |
---|
212 | 267 | error1: |
---|
| 268 | + rseq_after_asm_goto(); |
---|
213 | 269 | rseq_bug("cpu_id comparison failed"); |
---|
214 | 270 | error2: |
---|
| 271 | + rseq_after_asm_goto(); |
---|
215 | 272 | rseq_bug("expected value comparison failed"); |
---|
216 | 273 | #endif |
---|
217 | 274 | } |
---|
218 | 275 | |
---|
219 | 276 | static inline __attribute__((always_inline)) |
---|
220 | 277 | int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot, |
---|
221 | | - off_t voffp, intptr_t *load, int cpu) |
---|
| 278 | + long voffp, intptr_t *load, int cpu) |
---|
222 | 279 | { |
---|
223 | 280 | RSEQ_INJECT_C(9) |
---|
224 | 281 | |
---|
225 | 282 | __asm__ __volatile__ goto ( |
---|
226 | 283 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 284 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 285 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 286 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 287 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 288 | +#endif |
---|
227 | 289 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
228 | 290 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
229 | 291 | /* cmp cpuid */ |
---|
.. | .. |
---|
250 | 312 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
251 | 313 | : /* gcc asm goto does not allow outputs */ |
---|
252 | 314 | : [cpu_id] "r" (cpu), |
---|
253 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
254 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 315 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 316 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
255 | 317 | /* final store input */ |
---|
256 | 318 | [v] "m" (*v), |
---|
257 | 319 | [expectnot] "r" (expectnot), |
---|
.. | .. |
---|
265 | 327 | , error1, error2 |
---|
266 | 328 | #endif |
---|
267 | 329 | ); |
---|
| 330 | + rseq_after_asm_goto(); |
---|
268 | 331 | return 0; |
---|
269 | 332 | abort: |
---|
| 333 | + rseq_after_asm_goto(); |
---|
270 | 334 | RSEQ_INJECT_FAILED |
---|
271 | 335 | return -1; |
---|
272 | 336 | cmpfail: |
---|
| 337 | + rseq_after_asm_goto(); |
---|
273 | 338 | return 1; |
---|
274 | 339 | #ifdef RSEQ_COMPARE_TWICE |
---|
275 | 340 | error1: |
---|
| 341 | + rseq_after_asm_goto(); |
---|
276 | 342 | rseq_bug("cpu_id comparison failed"); |
---|
277 | 343 | error2: |
---|
| 344 | + rseq_after_asm_goto(); |
---|
278 | 345 | rseq_bug("expected value comparison failed"); |
---|
279 | 346 | #endif |
---|
280 | 347 | } |
---|
.. | .. |
---|
286 | 353 | |
---|
287 | 354 | __asm__ __volatile__ goto ( |
---|
288 | 355 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 356 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 357 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 358 | +#endif |
---|
289 | 359 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
290 | 360 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
291 | 361 | /* cmp cpuid */ |
---|
.. | .. |
---|
305 | 375 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
306 | 376 | : /* gcc asm goto does not allow outputs */ |
---|
307 | 377 | : [cpu_id] "r" (cpu), |
---|
308 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
309 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 378 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 379 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
310 | 380 | /* final store input */ |
---|
311 | 381 | [v] "m" (*v), |
---|
312 | 382 | [count] "r" (count) |
---|
.. | .. |
---|
318 | 388 | , error1 |
---|
319 | 389 | #endif |
---|
320 | 390 | ); |
---|
| 391 | + rseq_after_asm_goto(); |
---|
321 | 392 | return 0; |
---|
322 | 393 | abort: |
---|
| 394 | + rseq_after_asm_goto(); |
---|
323 | 395 | RSEQ_INJECT_FAILED |
---|
324 | 396 | return -1; |
---|
325 | 397 | #ifdef RSEQ_COMPARE_TWICE |
---|
326 | 398 | error1: |
---|
| 399 | + rseq_after_asm_goto(); |
---|
327 | 400 | rseq_bug("cpu_id comparison failed"); |
---|
328 | 401 | #endif |
---|
329 | 402 | } |
---|
.. | .. |
---|
337 | 410 | |
---|
338 | 411 | __asm__ __volatile__ goto ( |
---|
339 | 412 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 413 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 414 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 415 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 416 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 417 | +#endif |
---|
340 | 418 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
341 | 419 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
342 | 420 | /* cmp cpuid */ |
---|
.. | .. |
---|
360 | 438 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
361 | 439 | : /* gcc asm goto does not allow outputs */ |
---|
362 | 440 | : [cpu_id] "r" (cpu), |
---|
363 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
364 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 441 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 442 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
365 | 443 | /* try store input */ |
---|
366 | 444 | [v2] "m" (*v2), |
---|
367 | 445 | [newv2] "r" (newv2), |
---|
.. | .. |
---|
377 | 455 | , error1, error2 |
---|
378 | 456 | #endif |
---|
379 | 457 | ); |
---|
| 458 | + rseq_after_asm_goto(); |
---|
380 | 459 | return 0; |
---|
381 | 460 | abort: |
---|
| 461 | + rseq_after_asm_goto(); |
---|
382 | 462 | RSEQ_INJECT_FAILED |
---|
383 | 463 | return -1; |
---|
384 | 464 | cmpfail: |
---|
| 465 | + rseq_after_asm_goto(); |
---|
385 | 466 | return 1; |
---|
386 | 467 | #ifdef RSEQ_COMPARE_TWICE |
---|
387 | 468 | error1: |
---|
| 469 | + rseq_after_asm_goto(); |
---|
388 | 470 | rseq_bug("cpu_id comparison failed"); |
---|
389 | 471 | error2: |
---|
| 472 | + rseq_after_asm_goto(); |
---|
390 | 473 | rseq_bug("expected value comparison failed"); |
---|
391 | 474 | #endif |
---|
392 | 475 | } |
---|
.. | .. |
---|
400 | 483 | |
---|
401 | 484 | __asm__ __volatile__ goto ( |
---|
402 | 485 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 486 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 487 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 488 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 489 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 490 | +#endif |
---|
403 | 491 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
404 | 492 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
405 | 493 | /* cmp cpuid */ |
---|
.. | .. |
---|
425 | 513 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
426 | 514 | : /* gcc asm goto does not allow outputs */ |
---|
427 | 515 | : [cpu_id] "r" (cpu), |
---|
428 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
429 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 516 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 517 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
430 | 518 | /* try store input */ |
---|
431 | 519 | [v2] "m" (*v2), |
---|
432 | 520 | [newv2] "r" (newv2), |
---|
.. | .. |
---|
442 | 530 | , error1, error2 |
---|
443 | 531 | #endif |
---|
444 | 532 | ); |
---|
| 533 | + rseq_after_asm_goto(); |
---|
445 | 534 | return 0; |
---|
446 | 535 | abort: |
---|
| 536 | + rseq_after_asm_goto(); |
---|
447 | 537 | RSEQ_INJECT_FAILED |
---|
448 | 538 | return -1; |
---|
449 | 539 | cmpfail: |
---|
| 540 | + rseq_after_asm_goto(); |
---|
450 | 541 | return 1; |
---|
451 | 542 | #ifdef RSEQ_COMPARE_TWICE |
---|
452 | 543 | error1: |
---|
| 544 | + rseq_after_asm_goto(); |
---|
453 | 545 | rseq_bug("cpu_id comparison failed"); |
---|
454 | 546 | error2: |
---|
| 547 | + rseq_after_asm_goto(); |
---|
455 | 548 | rseq_bug("expected value comparison failed"); |
---|
456 | 549 | #endif |
---|
457 | 550 | } |
---|
.. | .. |
---|
465 | 558 | |
---|
466 | 559 | __asm__ __volatile__ goto ( |
---|
467 | 560 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 561 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 562 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 563 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 564 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 565 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) |
---|
| 566 | +#endif |
---|
468 | 567 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
469 | 568 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
470 | 569 | /* cmp cpuid */ |
---|
.. | .. |
---|
490 | 589 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
491 | 590 | : /* gcc asm goto does not allow outputs */ |
---|
492 | 591 | : [cpu_id] "r" (cpu), |
---|
493 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
494 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 592 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 593 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
495 | 594 | /* cmp2 input */ |
---|
496 | 595 | [v2] "m" (*v2), |
---|
497 | 596 | [expect2] "r" (expect2), |
---|
.. | .. |
---|
507 | 606 | , error1, error2, error3 |
---|
508 | 607 | #endif |
---|
509 | 608 | ); |
---|
| 609 | + rseq_after_asm_goto(); |
---|
510 | 610 | return 0; |
---|
511 | 611 | abort: |
---|
| 612 | + rseq_after_asm_goto(); |
---|
512 | 613 | RSEQ_INJECT_FAILED |
---|
513 | 614 | return -1; |
---|
514 | 615 | cmpfail: |
---|
| 616 | + rseq_after_asm_goto(); |
---|
515 | 617 | return 1; |
---|
516 | 618 | #ifdef RSEQ_COMPARE_TWICE |
---|
517 | 619 | error1: |
---|
| 620 | + rseq_after_asm_goto(); |
---|
518 | 621 | rseq_bug("cpu_id comparison failed"); |
---|
519 | 622 | error2: |
---|
| 623 | + rseq_after_asm_goto(); |
---|
520 | 624 | rseq_bug("1st expected value comparison failed"); |
---|
521 | 625 | error3: |
---|
| 626 | + rseq_after_asm_goto(); |
---|
522 | 627 | rseq_bug("2nd expected value comparison failed"); |
---|
523 | 628 | #endif |
---|
524 | 629 | } |
---|
.. | .. |
---|
532 | 637 | |
---|
533 | 638 | __asm__ __volatile__ goto ( |
---|
534 | 639 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 640 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 641 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 642 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 643 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 644 | +#endif |
---|
535 | 645 | /* setup for mempcy */ |
---|
536 | 646 | "mr %%r19, %[len]\n\t" |
---|
537 | 647 | "mr %%r20, %[src]\n\t" |
---|
.. | .. |
---|
560 | 670 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
561 | 671 | : /* gcc asm goto does not allow outputs */ |
---|
562 | 672 | : [cpu_id] "r" (cpu), |
---|
563 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
564 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 673 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 674 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
565 | 675 | /* final store input */ |
---|
566 | 676 | [v] "m" (*v), |
---|
567 | 677 | [expect] "r" (expect), |
---|
.. | .. |
---|
578 | 688 | , error1, error2 |
---|
579 | 689 | #endif |
---|
580 | 690 | ); |
---|
| 691 | + rseq_after_asm_goto(); |
---|
581 | 692 | return 0; |
---|
582 | 693 | abort: |
---|
| 694 | + rseq_after_asm_goto(); |
---|
583 | 695 | RSEQ_INJECT_FAILED |
---|
584 | 696 | return -1; |
---|
585 | 697 | cmpfail: |
---|
| 698 | + rseq_after_asm_goto(); |
---|
586 | 699 | return 1; |
---|
587 | 700 | #ifdef RSEQ_COMPARE_TWICE |
---|
588 | 701 | error1: |
---|
| 702 | + rseq_after_asm_goto(); |
---|
589 | 703 | rseq_bug("cpu_id comparison failed"); |
---|
590 | 704 | error2: |
---|
| 705 | + rseq_after_asm_goto(); |
---|
591 | 706 | rseq_bug("expected value comparison failed"); |
---|
592 | 707 | #endif |
---|
593 | 708 | } |
---|
.. | .. |
---|
601 | 716 | |
---|
602 | 717 | __asm__ __volatile__ goto ( |
---|
603 | 718 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 719 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 720 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 721 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 722 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 723 | +#endif |
---|
604 | 724 | /* setup for mempcy */ |
---|
605 | 725 | "mr %%r19, %[len]\n\t" |
---|
606 | 726 | "mr %%r20, %[src]\n\t" |
---|
.. | .. |
---|
631 | 751 | RSEQ_ASM_DEFINE_ABORT(4, abort) |
---|
632 | 752 | : /* gcc asm goto does not allow outputs */ |
---|
633 | 753 | : [cpu_id] "r" (cpu), |
---|
634 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
635 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 754 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 755 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
636 | 756 | /* final store input */ |
---|
637 | 757 | [v] "m" (*v), |
---|
638 | 758 | [expect] "r" (expect), |
---|
.. | .. |
---|
649 | 769 | , error1, error2 |
---|
650 | 770 | #endif |
---|
651 | 771 | ); |
---|
| 772 | + rseq_after_asm_goto(); |
---|
652 | 773 | return 0; |
---|
653 | 774 | abort: |
---|
| 775 | + rseq_after_asm_goto(); |
---|
654 | 776 | RSEQ_INJECT_FAILED |
---|
655 | 777 | return -1; |
---|
656 | 778 | cmpfail: |
---|
| 779 | + rseq_after_asm_goto(); |
---|
657 | 780 | return 1; |
---|
658 | 781 | #ifdef RSEQ_COMPARE_TWICE |
---|
659 | 782 | error1: |
---|
| 783 | + rseq_after_asm_goto(); |
---|
660 | 784 | rseq_bug("cpu_id comparison failed"); |
---|
661 | 785 | error2: |
---|
| 786 | + rseq_after_asm_goto(); |
---|
662 | 787 | rseq_bug("expected value comparison failed"); |
---|
663 | 788 | #endif |
---|
664 | 789 | } |
---|
665 | | - |
---|
666 | | -#undef STORE_WORD |
---|
667 | | -#undef LOAD_WORD |
---|
668 | | -#undef LOADX_WORD |
---|
669 | | -#undef CMP_WORD |
---|
670 | 790 | |
---|
671 | 791 | #endif /* !RSEQ_SKIP_FASTPATH */ |
---|