.. | .. |
---|
7 | 7 | |
---|
8 | 8 | #include <stdint.h> |
---|
9 | 9 | |
---|
| 10 | +/* |
---|
| 11 | + * RSEQ_SIG is used with the following reserved undefined instructions, which |
---|
| 12 | + * trap in user-space: |
---|
| 13 | + * |
---|
| 14 | + * x86-32: 0f b9 3d 53 30 05 53 ud1 0x53053053,%edi |
---|
| 15 | + * x86-64: 0f b9 3d 53 30 05 53 ud1 0x53053053(%rip),%edi |
---|
| 16 | + */ |
---|
10 | 17 | #define RSEQ_SIG 0x53053053 |
---|
11 | 18 | |
---|
| 19 | +/* |
---|
| 20 | + * Due to a compiler optimization bug in gcc-8 with asm goto and TLS asm input |
---|
| 21 | + * operands, we cannot use "m" input operands, and rather pass the __rseq_abi |
---|
| 22 | + * address through a "r" input operand. |
---|
| 23 | + */ |
---|
| 24 | + |
---|
| 25 | +/* Offset of cpu_id and rseq_cs fields in struct rseq. */ |
---|
| 26 | +#define RSEQ_CPU_ID_OFFSET 4 |
---|
| 27 | +#define RSEQ_CS_OFFSET 8 |
---|
| 28 | + |
---|
12 | 29 | #ifdef __x86_64__ |
---|
| 30 | + |
---|
| 31 | +#define RSEQ_ASM_TP_SEGMENT %%fs |
---|
13 | 32 | |
---|
14 | 33 | #define rseq_smp_mb() \ |
---|
15 | 34 | __asm__ __volatile__ ("lock; addl $0,-128(%%rsp)" ::: "memory", "cc") |
---|
.. | .. |
---|
37 | 56 | |
---|
38 | 57 | #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ |
---|
39 | 58 | start_ip, post_commit_offset, abort_ip) \ |
---|
40 | | - ".pushsection __rseq_table, \"aw\"\n\t" \ |
---|
| 59 | + ".pushsection __rseq_cs, \"aw\"\n\t" \ |
---|
41 | 60 | ".balign 32\n\t" \ |
---|
42 | 61 | __rseq_str(label) ":\n\t" \ |
---|
43 | 62 | ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \ |
---|
44 | 63 | ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \ |
---|
| 64 | + ".popsection\n\t" \ |
---|
| 65 | + ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \ |
---|
| 66 | + ".quad " __rseq_str(label) "b\n\t" \ |
---|
45 | 67 | ".popsection\n\t" |
---|
| 68 | + |
---|
46 | 69 | |
---|
47 | 70 | #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \ |
---|
48 | 71 | __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \ |
---|
49 | 72 | (post_commit_ip - start_ip), abort_ip) |
---|
50 | 73 | |
---|
| 74 | +/* |
---|
| 75 | + * Exit points of a rseq critical section consist of all instructions outside |
---|
| 76 | + * of the critical section where a critical section can either branch to or |
---|
| 77 | + * reach through the normal course of its execution. The abort IP and the |
---|
| 78 | + * post-commit IP are already part of the __rseq_cs section and should not be |
---|
| 79 | + * explicitly defined as additional exit points. Knowing all exit points is |
---|
| 80 | + * useful to assist debuggers stepping over the critical section. |
---|
| 81 | + */ |
---|
| 82 | +#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \ |
---|
| 83 | + ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \ |
---|
| 84 | + ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \ |
---|
| 85 | + ".popsection\n\t" |
---|
| 86 | + |
---|
51 | 87 | #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \ |
---|
52 | 88 | RSEQ_INJECT_ASM(1) \ |
---|
53 | 89 | "leaq " __rseq_str(cs_label) "(%%rip), %%rax\n\t" \ |
---|
54 | | - "movq %%rax, %[" __rseq_str(rseq_cs) "]\n\t" \ |
---|
| 90 | + "movq %%rax, " __rseq_str(rseq_cs) "\n\t" \ |
---|
55 | 91 | __rseq_str(label) ":\n\t" |
---|
56 | 92 | |
---|
57 | 93 | #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \ |
---|
58 | 94 | RSEQ_INJECT_ASM(2) \ |
---|
59 | | - "cmpl %[" __rseq_str(cpu_id) "], %[" __rseq_str(current_cpu_id) "]\n\t" \ |
---|
| 95 | + "cmpl %[" __rseq_str(cpu_id) "], " __rseq_str(current_cpu_id) "\n\t" \ |
---|
60 | 96 | "jnz " __rseq_str(label) "\n\t" |
---|
61 | 97 | |
---|
62 | 98 | #define RSEQ_ASM_DEFINE_ABORT(label, teardown, abort_label) \ |
---|
63 | 99 | ".pushsection __rseq_failure, \"ax\"\n\t" \ |
---|
64 | | - /* Disassembler-friendly signature: nopl <sig>(%rip). */\ |
---|
65 | | - ".byte 0x0f, 0x1f, 0x05\n\t" \ |
---|
| 100 | + /* Disassembler-friendly signature: ud1 <sig>(%rip),%edi. */ \ |
---|
| 101 | + ".byte 0x0f, 0xb9, 0x3d\n\t" \ |
---|
66 | 102 | ".long " __rseq_str(RSEQ_SIG) "\n\t" \ |
---|
67 | 103 | __rseq_str(label) ":\n\t" \ |
---|
68 | 104 | teardown \ |
---|
.. | .. |
---|
83 | 119 | |
---|
84 | 120 | __asm__ __volatile__ goto ( |
---|
85 | 121 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 122 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 123 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 124 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 125 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 126 | +#endif |
---|
86 | 127 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
87 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
88 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 128 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 129 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
89 | 130 | RSEQ_INJECT_ASM(3) |
---|
90 | 131 | "cmpq %[v], %[expect]\n\t" |
---|
91 | 132 | "jnz %l[cmpfail]\n\t" |
---|
92 | 133 | RSEQ_INJECT_ASM(4) |
---|
93 | 134 | #ifdef RSEQ_COMPARE_TWICE |
---|
94 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 135 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
95 | 136 | "cmpq %[v], %[expect]\n\t" |
---|
96 | 137 | "jnz %l[error2]\n\t" |
---|
97 | 138 | #endif |
---|
.. | .. |
---|
102 | 143 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
103 | 144 | : /* gcc asm goto does not allow outputs */ |
---|
104 | 145 | : [cpu_id] "r" (cpu), |
---|
105 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
106 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 146 | + [rseq_offset] "r" (rseq_offset), |
---|
107 | 147 | [v] "m" (*v), |
---|
108 | 148 | [expect] "r" (expect), |
---|
109 | 149 | [newv] "r" (newv) |
---|
.. | .. |
---|
114 | 154 | , error1, error2 |
---|
115 | 155 | #endif |
---|
116 | 156 | ); |
---|
| 157 | + rseq_after_asm_goto(); |
---|
117 | 158 | return 0; |
---|
118 | 159 | abort: |
---|
| 160 | + rseq_after_asm_goto(); |
---|
119 | 161 | RSEQ_INJECT_FAILED |
---|
120 | 162 | return -1; |
---|
121 | 163 | cmpfail: |
---|
| 164 | + rseq_after_asm_goto(); |
---|
122 | 165 | return 1; |
---|
123 | 166 | #ifdef RSEQ_COMPARE_TWICE |
---|
124 | 167 | error1: |
---|
| 168 | + rseq_after_asm_goto(); |
---|
125 | 169 | rseq_bug("cpu_id comparison failed"); |
---|
126 | 170 | error2: |
---|
| 171 | + rseq_after_asm_goto(); |
---|
127 | 172 | rseq_bug("expected value comparison failed"); |
---|
128 | 173 | #endif |
---|
129 | 174 | } |
---|
.. | .. |
---|
134 | 179 | */ |
---|
135 | 180 | static inline __attribute__((always_inline)) |
---|
136 | 181 | int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot, |
---|
137 | | - off_t voffp, intptr_t *load, int cpu) |
---|
| 182 | + long voffp, intptr_t *load, int cpu) |
---|
138 | 183 | { |
---|
139 | 184 | RSEQ_INJECT_C(9) |
---|
140 | 185 | |
---|
141 | 186 | __asm__ __volatile__ goto ( |
---|
142 | 187 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 188 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 189 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 190 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 191 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 192 | +#endif |
---|
143 | 193 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
144 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
145 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 194 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 195 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
146 | 196 | RSEQ_INJECT_ASM(3) |
---|
147 | 197 | "movq %[v], %%rbx\n\t" |
---|
148 | 198 | "cmpq %%rbx, %[expectnot]\n\t" |
---|
149 | 199 | "je %l[cmpfail]\n\t" |
---|
150 | 200 | RSEQ_INJECT_ASM(4) |
---|
151 | 201 | #ifdef RSEQ_COMPARE_TWICE |
---|
152 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 202 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
153 | 203 | "movq %[v], %%rbx\n\t" |
---|
154 | 204 | "cmpq %%rbx, %[expectnot]\n\t" |
---|
155 | 205 | "je %l[error2]\n\t" |
---|
.. | .. |
---|
164 | 214 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
165 | 215 | : /* gcc asm goto does not allow outputs */ |
---|
166 | 216 | : [cpu_id] "r" (cpu), |
---|
167 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
168 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 217 | + [rseq_offset] "r" (rseq_offset), |
---|
169 | 218 | /* final store input */ |
---|
170 | 219 | [v] "m" (*v), |
---|
171 | 220 | [expectnot] "r" (expectnot), |
---|
.. | .. |
---|
178 | 227 | , error1, error2 |
---|
179 | 228 | #endif |
---|
180 | 229 | ); |
---|
| 230 | + rseq_after_asm_goto(); |
---|
181 | 231 | return 0; |
---|
182 | 232 | abort: |
---|
| 233 | + rseq_after_asm_goto(); |
---|
183 | 234 | RSEQ_INJECT_FAILED |
---|
184 | 235 | return -1; |
---|
185 | 236 | cmpfail: |
---|
| 237 | + rseq_after_asm_goto(); |
---|
186 | 238 | return 1; |
---|
187 | 239 | #ifdef RSEQ_COMPARE_TWICE |
---|
188 | 240 | error1: |
---|
| 241 | + rseq_after_asm_goto(); |
---|
189 | 242 | rseq_bug("cpu_id comparison failed"); |
---|
190 | 243 | error2: |
---|
| 244 | + rseq_after_asm_goto(); |
---|
191 | 245 | rseq_bug("expected value comparison failed"); |
---|
192 | 246 | #endif |
---|
193 | 247 | } |
---|
.. | .. |
---|
199 | 253 | |
---|
200 | 254 | __asm__ __volatile__ goto ( |
---|
201 | 255 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 256 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 257 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 258 | +#endif |
---|
202 | 259 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
203 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
204 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 260 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 261 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
205 | 262 | RSEQ_INJECT_ASM(3) |
---|
206 | 263 | #ifdef RSEQ_COMPARE_TWICE |
---|
207 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 264 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
208 | 265 | #endif |
---|
209 | 266 | /* final store */ |
---|
210 | 267 | "addq %[count], %[v]\n\t" |
---|
.. | .. |
---|
213 | 270 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
214 | 271 | : /* gcc asm goto does not allow outputs */ |
---|
215 | 272 | : [cpu_id] "r" (cpu), |
---|
216 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
217 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 273 | + [rseq_offset] "r" (rseq_offset), |
---|
218 | 274 | /* final store input */ |
---|
219 | 275 | [v] "m" (*v), |
---|
220 | 276 | [count] "er" (count) |
---|
221 | 277 | : "memory", "cc", "rax" |
---|
| 278 | + RSEQ_INJECT_CLOBBER |
---|
| 279 | + : abort |
---|
| 280 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 281 | + , error1 |
---|
| 282 | +#endif |
---|
| 283 | + ); |
---|
| 284 | + rseq_after_asm_goto(); |
---|
| 285 | + return 0; |
---|
| 286 | +abort: |
---|
| 287 | + rseq_after_asm_goto(); |
---|
| 288 | + RSEQ_INJECT_FAILED |
---|
| 289 | + return -1; |
---|
| 290 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 291 | +error1: |
---|
| 292 | + rseq_after_asm_goto(); |
---|
| 293 | + rseq_bug("cpu_id comparison failed"); |
---|
| 294 | +#endif |
---|
| 295 | +} |
---|
| 296 | + |
---|
| 297 | +#define RSEQ_ARCH_HAS_OFFSET_DEREF_ADDV |
---|
| 298 | + |
---|
| 299 | +/* |
---|
| 300 | + * pval = *(ptr+off) |
---|
| 301 | + * *pval += inc; |
---|
| 302 | + */ |
---|
| 303 | +static inline __attribute__((always_inline)) |
---|
| 304 | +int rseq_offset_deref_addv(intptr_t *ptr, long off, intptr_t inc, int cpu) |
---|
| 305 | +{ |
---|
| 306 | + RSEQ_INJECT_C(9) |
---|
| 307 | + |
---|
| 308 | + __asm__ __volatile__ goto ( |
---|
| 309 | + RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 310 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 311 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 312 | +#endif |
---|
| 313 | + /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
| 314 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 315 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
| 316 | + RSEQ_INJECT_ASM(3) |
---|
| 317 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 318 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
| 319 | +#endif |
---|
| 320 | + /* get p+v */ |
---|
| 321 | + "movq %[ptr], %%rbx\n\t" |
---|
| 322 | + "addq %[off], %%rbx\n\t" |
---|
| 323 | + /* get pv */ |
---|
| 324 | + "movq (%%rbx), %%rcx\n\t" |
---|
| 325 | + /* *pv += inc */ |
---|
| 326 | + "addq %[inc], (%%rcx)\n\t" |
---|
| 327 | + "2:\n\t" |
---|
| 328 | + RSEQ_INJECT_ASM(4) |
---|
| 329 | + RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
| 330 | + : /* gcc asm goto does not allow outputs */ |
---|
| 331 | + : [cpu_id] "r" (cpu), |
---|
| 332 | + [rseq_offset] "r" (rseq_offset), |
---|
| 333 | + /* final store input */ |
---|
| 334 | + [ptr] "m" (*ptr), |
---|
| 335 | + [off] "er" (off), |
---|
| 336 | + [inc] "er" (inc) |
---|
| 337 | + : "memory", "cc", "rax", "rbx", "rcx" |
---|
222 | 338 | RSEQ_INJECT_CLOBBER |
---|
223 | 339 | : abort |
---|
224 | 340 | #ifdef RSEQ_COMPARE_TWICE |
---|
.. | .. |
---|
244 | 360 | |
---|
245 | 361 | __asm__ __volatile__ goto ( |
---|
246 | 362 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 363 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 364 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 365 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 366 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 367 | +#endif |
---|
247 | 368 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
248 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
249 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 369 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 370 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
250 | 371 | RSEQ_INJECT_ASM(3) |
---|
251 | 372 | "cmpq %[v], %[expect]\n\t" |
---|
252 | 373 | "jnz %l[cmpfail]\n\t" |
---|
253 | 374 | RSEQ_INJECT_ASM(4) |
---|
254 | 375 | #ifdef RSEQ_COMPARE_TWICE |
---|
255 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 376 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
256 | 377 | "cmpq %[v], %[expect]\n\t" |
---|
257 | 378 | "jnz %l[error2]\n\t" |
---|
258 | 379 | #endif |
---|
.. | .. |
---|
266 | 387 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
267 | 388 | : /* gcc asm goto does not allow outputs */ |
---|
268 | 389 | : [cpu_id] "r" (cpu), |
---|
269 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
270 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 390 | + [rseq_offset] "r" (rseq_offset), |
---|
271 | 391 | /* try store input */ |
---|
272 | 392 | [v2] "m" (*v2), |
---|
273 | 393 | [newv2] "r" (newv2), |
---|
.. | .. |
---|
282 | 402 | , error1, error2 |
---|
283 | 403 | #endif |
---|
284 | 404 | ); |
---|
| 405 | + rseq_after_asm_goto(); |
---|
285 | 406 | return 0; |
---|
286 | 407 | abort: |
---|
| 408 | + rseq_after_asm_goto(); |
---|
287 | 409 | RSEQ_INJECT_FAILED |
---|
288 | 410 | return -1; |
---|
289 | 411 | cmpfail: |
---|
| 412 | + rseq_after_asm_goto(); |
---|
290 | 413 | return 1; |
---|
291 | 414 | #ifdef RSEQ_COMPARE_TWICE |
---|
292 | 415 | error1: |
---|
| 416 | + rseq_after_asm_goto(); |
---|
293 | 417 | rseq_bug("cpu_id comparison failed"); |
---|
294 | 418 | error2: |
---|
| 419 | + rseq_after_asm_goto(); |
---|
295 | 420 | rseq_bug("expected value comparison failed"); |
---|
296 | 421 | #endif |
---|
297 | 422 | } |
---|
.. | .. |
---|
314 | 439 | |
---|
315 | 440 | __asm__ __volatile__ goto ( |
---|
316 | 441 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 442 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 443 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 444 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 445 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 446 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) |
---|
| 447 | +#endif |
---|
317 | 448 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
318 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
319 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 449 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 450 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
320 | 451 | RSEQ_INJECT_ASM(3) |
---|
321 | 452 | "cmpq %[v], %[expect]\n\t" |
---|
322 | 453 | "jnz %l[cmpfail]\n\t" |
---|
.. | .. |
---|
325 | 456 | "jnz %l[cmpfail]\n\t" |
---|
326 | 457 | RSEQ_INJECT_ASM(5) |
---|
327 | 458 | #ifdef RSEQ_COMPARE_TWICE |
---|
328 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 459 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
329 | 460 | "cmpq %[v], %[expect]\n\t" |
---|
330 | 461 | "jnz %l[error2]\n\t" |
---|
331 | 462 | "cmpq %[v2], %[expect2]\n\t" |
---|
.. | .. |
---|
338 | 469 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
339 | 470 | : /* gcc asm goto does not allow outputs */ |
---|
340 | 471 | : [cpu_id] "r" (cpu), |
---|
341 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
342 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 472 | + [rseq_offset] "r" (rseq_offset), |
---|
343 | 473 | /* cmp2 input */ |
---|
344 | 474 | [v2] "m" (*v2), |
---|
345 | 475 | [expect2] "r" (expect2), |
---|
.. | .. |
---|
354 | 484 | , error1, error2, error3 |
---|
355 | 485 | #endif |
---|
356 | 486 | ); |
---|
| 487 | + rseq_after_asm_goto(); |
---|
357 | 488 | return 0; |
---|
358 | 489 | abort: |
---|
| 490 | + rseq_after_asm_goto(); |
---|
359 | 491 | RSEQ_INJECT_FAILED |
---|
360 | 492 | return -1; |
---|
361 | 493 | cmpfail: |
---|
| 494 | + rseq_after_asm_goto(); |
---|
362 | 495 | return 1; |
---|
363 | 496 | #ifdef RSEQ_COMPARE_TWICE |
---|
364 | 497 | error1: |
---|
| 498 | + rseq_after_asm_goto(); |
---|
365 | 499 | rseq_bug("cpu_id comparison failed"); |
---|
366 | 500 | error2: |
---|
| 501 | + rseq_after_asm_goto(); |
---|
367 | 502 | rseq_bug("1st expected value comparison failed"); |
---|
368 | 503 | error3: |
---|
| 504 | + rseq_after_asm_goto(); |
---|
369 | 505 | rseq_bug("2nd expected value comparison failed"); |
---|
370 | 506 | #endif |
---|
371 | 507 | } |
---|
.. | .. |
---|
381 | 517 | |
---|
382 | 518 | __asm__ __volatile__ goto ( |
---|
383 | 519 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 520 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 521 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 522 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 523 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 524 | +#endif |
---|
384 | 525 | "movq %[src], %[rseq_scratch0]\n\t" |
---|
385 | 526 | "movq %[dst], %[rseq_scratch1]\n\t" |
---|
386 | 527 | "movq %[len], %[rseq_scratch2]\n\t" |
---|
387 | 528 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
388 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
389 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 529 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 530 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
390 | 531 | RSEQ_INJECT_ASM(3) |
---|
391 | 532 | "cmpq %[v], %[expect]\n\t" |
---|
392 | 533 | "jnz 5f\n\t" |
---|
393 | 534 | RSEQ_INJECT_ASM(4) |
---|
394 | 535 | #ifdef RSEQ_COMPARE_TWICE |
---|
395 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) |
---|
| 536 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 6f) |
---|
396 | 537 | "cmpq %[v], %[expect]\n\t" |
---|
397 | 538 | "jnz 7f\n\t" |
---|
398 | 539 | #endif |
---|
.. | .. |
---|
440 | 581 | #endif |
---|
441 | 582 | : /* gcc asm goto does not allow outputs */ |
---|
442 | 583 | : [cpu_id] "r" (cpu), |
---|
443 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
444 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 584 | + [rseq_offset] "r" (rseq_offset), |
---|
445 | 585 | /* final store input */ |
---|
446 | 586 | [v] "m" (*v), |
---|
447 | 587 | [expect] "r" (expect), |
---|
.. | .. |
---|
460 | 600 | , error1, error2 |
---|
461 | 601 | #endif |
---|
462 | 602 | ); |
---|
| 603 | + rseq_after_asm_goto(); |
---|
463 | 604 | return 0; |
---|
464 | 605 | abort: |
---|
| 606 | + rseq_after_asm_goto(); |
---|
465 | 607 | RSEQ_INJECT_FAILED |
---|
466 | 608 | return -1; |
---|
467 | 609 | cmpfail: |
---|
| 610 | + rseq_after_asm_goto(); |
---|
468 | 611 | return 1; |
---|
469 | 612 | #ifdef RSEQ_COMPARE_TWICE |
---|
470 | 613 | error1: |
---|
| 614 | + rseq_after_asm_goto(); |
---|
471 | 615 | rseq_bug("cpu_id comparison failed"); |
---|
472 | 616 | error2: |
---|
| 617 | + rseq_after_asm_goto(); |
---|
473 | 618 | rseq_bug("expected value comparison failed"); |
---|
474 | 619 | #endif |
---|
475 | 620 | } |
---|
.. | .. |
---|
486 | 631 | |
---|
487 | 632 | #endif /* !RSEQ_SKIP_FASTPATH */ |
---|
488 | 633 | |
---|
489 | | -#elif __i386__ |
---|
| 634 | +#elif defined(__i386__) |
---|
| 635 | + |
---|
| 636 | +#define RSEQ_ASM_TP_SEGMENT %%gs |
---|
490 | 637 | |
---|
491 | 638 | #define rseq_smp_mb() \ |
---|
492 | 639 | __asm__ __volatile__ ("lock; addl $0,-128(%%esp)" ::: "memory", "cc") |
---|
.. | .. |
---|
520 | 667 | */ |
---|
521 | 668 | #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ |
---|
522 | 669 | start_ip, post_commit_offset, abort_ip) \ |
---|
523 | | - ".pushsection __rseq_table, \"aw\"\n\t" \ |
---|
| 670 | + ".pushsection __rseq_cs, \"aw\"\n\t" \ |
---|
524 | 671 | ".balign 32\n\t" \ |
---|
525 | 672 | __rseq_str(label) ":\n\t" \ |
---|
526 | 673 | ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \ |
---|
527 | 674 | ".long " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) ", 0x0\n\t" \ |
---|
| 675 | + ".popsection\n\t" \ |
---|
| 676 | + ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \ |
---|
| 677 | + ".long " __rseq_str(label) "b, 0x0\n\t" \ |
---|
528 | 678 | ".popsection\n\t" |
---|
529 | 679 | |
---|
530 | 680 | #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \ |
---|
531 | 681 | __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \ |
---|
532 | 682 | (post_commit_ip - start_ip), abort_ip) |
---|
533 | 683 | |
---|
| 684 | +/* |
---|
| 685 | + * Exit points of a rseq critical section consist of all instructions outside |
---|
| 686 | + * of the critical section where a critical section can either branch to or |
---|
| 687 | + * reach through the normal course of its execution. The abort IP and the |
---|
| 688 | + * post-commit IP are already part of the __rseq_cs section and should not be |
---|
| 689 | + * explicitly defined as additional exit points. Knowing all exit points is |
---|
| 690 | + * useful to assist debuggers stepping over the critical section. |
---|
| 691 | + */ |
---|
| 692 | +#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \ |
---|
| 693 | + ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \ |
---|
| 694 | + ".long " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) ", 0x0\n\t" \ |
---|
| 695 | + ".popsection\n\t" |
---|
| 696 | + |
---|
534 | 697 | #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \ |
---|
535 | 698 | RSEQ_INJECT_ASM(1) \ |
---|
536 | | - "movl $" __rseq_str(cs_label) ", %[rseq_cs]\n\t" \ |
---|
| 699 | + "movl $" __rseq_str(cs_label) ", " __rseq_str(rseq_cs) "\n\t" \ |
---|
537 | 700 | __rseq_str(label) ":\n\t" |
---|
538 | 701 | |
---|
539 | 702 | #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \ |
---|
540 | 703 | RSEQ_INJECT_ASM(2) \ |
---|
541 | | - "cmpl %[" __rseq_str(cpu_id) "], %[" __rseq_str(current_cpu_id) "]\n\t" \ |
---|
| 704 | + "cmpl %[" __rseq_str(cpu_id) "], " __rseq_str(current_cpu_id) "\n\t" \ |
---|
542 | 705 | "jnz " __rseq_str(label) "\n\t" |
---|
543 | 706 | |
---|
544 | 707 | #define RSEQ_ASM_DEFINE_ABORT(label, teardown, abort_label) \ |
---|
545 | 708 | ".pushsection __rseq_failure, \"ax\"\n\t" \ |
---|
546 | | - /* Disassembler-friendly signature: nopl <sig>. */ \ |
---|
547 | | - ".byte 0x0f, 0x1f, 0x05\n\t" \ |
---|
| 709 | + /* Disassembler-friendly signature: ud1 <sig>,%edi. */ \ |
---|
| 710 | + ".byte 0x0f, 0xb9, 0x3d\n\t" \ |
---|
548 | 711 | ".long " __rseq_str(RSEQ_SIG) "\n\t" \ |
---|
549 | 712 | __rseq_str(label) ":\n\t" \ |
---|
550 | 713 | teardown \ |
---|
.. | .. |
---|
565 | 728 | |
---|
566 | 729 | __asm__ __volatile__ goto ( |
---|
567 | 730 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 731 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 732 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 733 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 734 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 735 | +#endif |
---|
568 | 736 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
569 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
570 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 737 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 738 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
571 | 739 | RSEQ_INJECT_ASM(3) |
---|
572 | 740 | "cmpl %[v], %[expect]\n\t" |
---|
573 | 741 | "jnz %l[cmpfail]\n\t" |
---|
574 | 742 | RSEQ_INJECT_ASM(4) |
---|
575 | 743 | #ifdef RSEQ_COMPARE_TWICE |
---|
576 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 744 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
577 | 745 | "cmpl %[v], %[expect]\n\t" |
---|
578 | 746 | "jnz %l[error2]\n\t" |
---|
579 | 747 | #endif |
---|
.. | .. |
---|
584 | 752 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
585 | 753 | : /* gcc asm goto does not allow outputs */ |
---|
586 | 754 | : [cpu_id] "r" (cpu), |
---|
587 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
588 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 755 | + [rseq_offset] "r" (rseq_offset), |
---|
589 | 756 | [v] "m" (*v), |
---|
590 | 757 | [expect] "r" (expect), |
---|
591 | 758 | [newv] "r" (newv) |
---|
.. | .. |
---|
596 | 763 | , error1, error2 |
---|
597 | 764 | #endif |
---|
598 | 765 | ); |
---|
| 766 | + rseq_after_asm_goto(); |
---|
599 | 767 | return 0; |
---|
600 | 768 | abort: |
---|
| 769 | + rseq_after_asm_goto(); |
---|
601 | 770 | RSEQ_INJECT_FAILED |
---|
602 | 771 | return -1; |
---|
603 | 772 | cmpfail: |
---|
| 773 | + rseq_after_asm_goto(); |
---|
604 | 774 | return 1; |
---|
605 | 775 | #ifdef RSEQ_COMPARE_TWICE |
---|
606 | 776 | error1: |
---|
| 777 | + rseq_after_asm_goto(); |
---|
607 | 778 | rseq_bug("cpu_id comparison failed"); |
---|
608 | 779 | error2: |
---|
| 780 | + rseq_after_asm_goto(); |
---|
609 | 781 | rseq_bug("expected value comparison failed"); |
---|
610 | 782 | #endif |
---|
611 | 783 | } |
---|
.. | .. |
---|
616 | 788 | */ |
---|
617 | 789 | static inline __attribute__((always_inline)) |
---|
618 | 790 | int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot, |
---|
619 | | - off_t voffp, intptr_t *load, int cpu) |
---|
| 791 | + long voffp, intptr_t *load, int cpu) |
---|
620 | 792 | { |
---|
621 | 793 | RSEQ_INJECT_C(9) |
---|
622 | 794 | |
---|
623 | 795 | __asm__ __volatile__ goto ( |
---|
624 | 796 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 797 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 798 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 799 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 800 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 801 | +#endif |
---|
625 | 802 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
626 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
627 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 803 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 804 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
628 | 805 | RSEQ_INJECT_ASM(3) |
---|
629 | 806 | "movl %[v], %%ebx\n\t" |
---|
630 | 807 | "cmpl %%ebx, %[expectnot]\n\t" |
---|
631 | 808 | "je %l[cmpfail]\n\t" |
---|
632 | 809 | RSEQ_INJECT_ASM(4) |
---|
633 | 810 | #ifdef RSEQ_COMPARE_TWICE |
---|
634 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 811 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
635 | 812 | "movl %[v], %%ebx\n\t" |
---|
636 | 813 | "cmpl %%ebx, %[expectnot]\n\t" |
---|
637 | 814 | "je %l[error2]\n\t" |
---|
.. | .. |
---|
646 | 823 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
647 | 824 | : /* gcc asm goto does not allow outputs */ |
---|
648 | 825 | : [cpu_id] "r" (cpu), |
---|
649 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
650 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 826 | + [rseq_offset] "r" (rseq_offset), |
---|
651 | 827 | /* final store input */ |
---|
652 | 828 | [v] "m" (*v), |
---|
653 | 829 | [expectnot] "r" (expectnot), |
---|
.. | .. |
---|
660 | 836 | , error1, error2 |
---|
661 | 837 | #endif |
---|
662 | 838 | ); |
---|
| 839 | + rseq_after_asm_goto(); |
---|
663 | 840 | return 0; |
---|
664 | 841 | abort: |
---|
| 842 | + rseq_after_asm_goto(); |
---|
665 | 843 | RSEQ_INJECT_FAILED |
---|
666 | 844 | return -1; |
---|
667 | 845 | cmpfail: |
---|
| 846 | + rseq_after_asm_goto(); |
---|
668 | 847 | return 1; |
---|
669 | 848 | #ifdef RSEQ_COMPARE_TWICE |
---|
670 | 849 | error1: |
---|
| 850 | + rseq_after_asm_goto(); |
---|
671 | 851 | rseq_bug("cpu_id comparison failed"); |
---|
672 | 852 | error2: |
---|
| 853 | + rseq_after_asm_goto(); |
---|
673 | 854 | rseq_bug("expected value comparison failed"); |
---|
674 | 855 | #endif |
---|
675 | 856 | } |
---|
.. | .. |
---|
681 | 862 | |
---|
682 | 863 | __asm__ __volatile__ goto ( |
---|
683 | 864 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 865 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 866 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 867 | +#endif |
---|
684 | 868 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
685 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
686 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 869 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 870 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
687 | 871 | RSEQ_INJECT_ASM(3) |
---|
688 | 872 | #ifdef RSEQ_COMPARE_TWICE |
---|
689 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 873 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
690 | 874 | #endif |
---|
691 | 875 | /* final store */ |
---|
692 | 876 | "addl %[count], %[v]\n\t" |
---|
.. | .. |
---|
695 | 879 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
696 | 880 | : /* gcc asm goto does not allow outputs */ |
---|
697 | 881 | : [cpu_id] "r" (cpu), |
---|
698 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
699 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 882 | + [rseq_offset] "r" (rseq_offset), |
---|
700 | 883 | /* final store input */ |
---|
701 | 884 | [v] "m" (*v), |
---|
702 | 885 | [count] "ir" (count) |
---|
.. | .. |
---|
707 | 890 | , error1 |
---|
708 | 891 | #endif |
---|
709 | 892 | ); |
---|
| 893 | + rseq_after_asm_goto(); |
---|
710 | 894 | return 0; |
---|
711 | 895 | abort: |
---|
| 896 | + rseq_after_asm_goto(); |
---|
712 | 897 | RSEQ_INJECT_FAILED |
---|
713 | 898 | return -1; |
---|
714 | 899 | #ifdef RSEQ_COMPARE_TWICE |
---|
715 | 900 | error1: |
---|
| 901 | + rseq_after_asm_goto(); |
---|
716 | 902 | rseq_bug("cpu_id comparison failed"); |
---|
717 | 903 | #endif |
---|
718 | 904 | } |
---|
.. | .. |
---|
726 | 912 | |
---|
727 | 913 | __asm__ __volatile__ goto ( |
---|
728 | 914 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 915 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 916 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 917 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 918 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 919 | +#endif |
---|
729 | 920 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
730 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
731 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 921 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 922 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
732 | 923 | RSEQ_INJECT_ASM(3) |
---|
733 | 924 | "cmpl %[v], %[expect]\n\t" |
---|
734 | 925 | "jnz %l[cmpfail]\n\t" |
---|
735 | 926 | RSEQ_INJECT_ASM(4) |
---|
736 | 927 | #ifdef RSEQ_COMPARE_TWICE |
---|
737 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 928 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
738 | 929 | "cmpl %[v], %[expect]\n\t" |
---|
739 | 930 | "jnz %l[error2]\n\t" |
---|
740 | 931 | #endif |
---|
.. | .. |
---|
749 | 940 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
750 | 941 | : /* gcc asm goto does not allow outputs */ |
---|
751 | 942 | : [cpu_id] "r" (cpu), |
---|
752 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
753 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 943 | + [rseq_offset] "r" (rseq_offset), |
---|
754 | 944 | /* try store input */ |
---|
755 | 945 | [v2] "m" (*v2), |
---|
756 | 946 | [newv2] "m" (newv2), |
---|
.. | .. |
---|
765 | 955 | , error1, error2 |
---|
766 | 956 | #endif |
---|
767 | 957 | ); |
---|
| 958 | + rseq_after_asm_goto(); |
---|
768 | 959 | return 0; |
---|
769 | 960 | abort: |
---|
| 961 | + rseq_after_asm_goto(); |
---|
770 | 962 | RSEQ_INJECT_FAILED |
---|
771 | 963 | return -1; |
---|
772 | 964 | cmpfail: |
---|
| 965 | + rseq_after_asm_goto(); |
---|
773 | 966 | return 1; |
---|
774 | 967 | #ifdef RSEQ_COMPARE_TWICE |
---|
775 | 968 | error1: |
---|
| 969 | + rseq_after_asm_goto(); |
---|
776 | 970 | rseq_bug("cpu_id comparison failed"); |
---|
777 | 971 | error2: |
---|
| 972 | + rseq_after_asm_goto(); |
---|
778 | 973 | rseq_bug("expected value comparison failed"); |
---|
779 | 974 | #endif |
---|
780 | 975 | } |
---|
.. | .. |
---|
788 | 983 | |
---|
789 | 984 | __asm__ __volatile__ goto ( |
---|
790 | 985 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 986 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 987 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 988 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 989 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 990 | +#endif |
---|
791 | 991 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
792 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
793 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 992 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 993 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
794 | 994 | RSEQ_INJECT_ASM(3) |
---|
795 | 995 | "movl %[expect], %%eax\n\t" |
---|
796 | 996 | "cmpl %[v], %%eax\n\t" |
---|
797 | 997 | "jnz %l[cmpfail]\n\t" |
---|
798 | 998 | RSEQ_INJECT_ASM(4) |
---|
799 | 999 | #ifdef RSEQ_COMPARE_TWICE |
---|
800 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 1000 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
801 | 1001 | "movl %[expect], %%eax\n\t" |
---|
802 | 1002 | "cmpl %[v], %%eax\n\t" |
---|
803 | 1003 | "jnz %l[error2]\n\t" |
---|
.. | .. |
---|
813 | 1013 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
814 | 1014 | : /* gcc asm goto does not allow outputs */ |
---|
815 | 1015 | : [cpu_id] "r" (cpu), |
---|
816 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
817 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 1016 | + [rseq_offset] "r" (rseq_offset), |
---|
818 | 1017 | /* try store input */ |
---|
819 | 1018 | [v2] "m" (*v2), |
---|
820 | 1019 | [newv2] "r" (newv2), |
---|
.. | .. |
---|
829 | 1028 | , error1, error2 |
---|
830 | 1029 | #endif |
---|
831 | 1030 | ); |
---|
| 1031 | + rseq_after_asm_goto(); |
---|
832 | 1032 | return 0; |
---|
833 | 1033 | abort: |
---|
| 1034 | + rseq_after_asm_goto(); |
---|
834 | 1035 | RSEQ_INJECT_FAILED |
---|
835 | 1036 | return -1; |
---|
836 | 1037 | cmpfail: |
---|
| 1038 | + rseq_after_asm_goto(); |
---|
837 | 1039 | return 1; |
---|
838 | 1040 | #ifdef RSEQ_COMPARE_TWICE |
---|
839 | 1041 | error1: |
---|
| 1042 | + rseq_after_asm_goto(); |
---|
840 | 1043 | rseq_bug("cpu_id comparison failed"); |
---|
841 | 1044 | error2: |
---|
| 1045 | + rseq_after_asm_goto(); |
---|
842 | 1046 | rseq_bug("expected value comparison failed"); |
---|
843 | 1047 | #endif |
---|
844 | 1048 | |
---|
.. | .. |
---|
853 | 1057 | |
---|
854 | 1058 | __asm__ __volatile__ goto ( |
---|
855 | 1059 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 1060 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 1061 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 1062 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 1063 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 1064 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) |
---|
| 1065 | +#endif |
---|
856 | 1066 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
857 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
858 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 1067 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 1068 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
859 | 1069 | RSEQ_INJECT_ASM(3) |
---|
860 | 1070 | "cmpl %[v], %[expect]\n\t" |
---|
861 | 1071 | "jnz %l[cmpfail]\n\t" |
---|
.. | .. |
---|
864 | 1074 | "jnz %l[cmpfail]\n\t" |
---|
865 | 1075 | RSEQ_INJECT_ASM(5) |
---|
866 | 1076 | #ifdef RSEQ_COMPARE_TWICE |
---|
867 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, %l[error1]) |
---|
| 1077 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), %l[error1]) |
---|
868 | 1078 | "cmpl %[v], %[expect]\n\t" |
---|
869 | 1079 | "jnz %l[error2]\n\t" |
---|
870 | 1080 | "cmpl %[expect2], %[v2]\n\t" |
---|
.. | .. |
---|
878 | 1088 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
879 | 1089 | : /* gcc asm goto does not allow outputs */ |
---|
880 | 1090 | : [cpu_id] "r" (cpu), |
---|
881 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
882 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 1091 | + [rseq_offset] "r" (rseq_offset), |
---|
883 | 1092 | /* cmp2 input */ |
---|
884 | 1093 | [v2] "m" (*v2), |
---|
885 | 1094 | [expect2] "r" (expect2), |
---|
.. | .. |
---|
894 | 1103 | , error1, error2, error3 |
---|
895 | 1104 | #endif |
---|
896 | 1105 | ); |
---|
| 1106 | + rseq_after_asm_goto(); |
---|
897 | 1107 | return 0; |
---|
898 | 1108 | abort: |
---|
| 1109 | + rseq_after_asm_goto(); |
---|
899 | 1110 | RSEQ_INJECT_FAILED |
---|
900 | 1111 | return -1; |
---|
901 | 1112 | cmpfail: |
---|
| 1113 | + rseq_after_asm_goto(); |
---|
902 | 1114 | return 1; |
---|
903 | 1115 | #ifdef RSEQ_COMPARE_TWICE |
---|
904 | 1116 | error1: |
---|
| 1117 | + rseq_after_asm_goto(); |
---|
905 | 1118 | rseq_bug("cpu_id comparison failed"); |
---|
906 | 1119 | error2: |
---|
| 1120 | + rseq_after_asm_goto(); |
---|
907 | 1121 | rseq_bug("1st expected value comparison failed"); |
---|
908 | 1122 | error3: |
---|
| 1123 | + rseq_after_asm_goto(); |
---|
909 | 1124 | rseq_bug("2nd expected value comparison failed"); |
---|
910 | 1125 | #endif |
---|
911 | 1126 | } |
---|
.. | .. |
---|
922 | 1137 | |
---|
923 | 1138 | __asm__ __volatile__ goto ( |
---|
924 | 1139 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 1140 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 1141 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 1142 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 1143 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 1144 | +#endif |
---|
925 | 1145 | "movl %[src], %[rseq_scratch0]\n\t" |
---|
926 | 1146 | "movl %[dst], %[rseq_scratch1]\n\t" |
---|
927 | 1147 | "movl %[len], %[rseq_scratch2]\n\t" |
---|
928 | 1148 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
929 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
930 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 1149 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 1150 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
931 | 1151 | RSEQ_INJECT_ASM(3) |
---|
932 | 1152 | "movl %[expect], %%eax\n\t" |
---|
933 | 1153 | "cmpl %%eax, %[v]\n\t" |
---|
934 | 1154 | "jnz 5f\n\t" |
---|
935 | 1155 | RSEQ_INJECT_ASM(4) |
---|
936 | 1156 | #ifdef RSEQ_COMPARE_TWICE |
---|
937 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) |
---|
| 1157 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 6f) |
---|
938 | 1158 | "movl %[expect], %%eax\n\t" |
---|
939 | 1159 | "cmpl %%eax, %[v]\n\t" |
---|
940 | 1160 | "jnz 7f\n\t" |
---|
.. | .. |
---|
984 | 1204 | #endif |
---|
985 | 1205 | : /* gcc asm goto does not allow outputs */ |
---|
986 | 1206 | : [cpu_id] "r" (cpu), |
---|
987 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
988 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 1207 | + [rseq_offset] "r" (rseq_offset), |
---|
989 | 1208 | /* final store input */ |
---|
990 | 1209 | [v] "m" (*v), |
---|
991 | 1210 | [expect] "m" (expect), |
---|
.. | .. |
---|
1004 | 1223 | , error1, error2 |
---|
1005 | 1224 | #endif |
---|
1006 | 1225 | ); |
---|
| 1226 | + rseq_after_asm_goto(); |
---|
1007 | 1227 | return 0; |
---|
1008 | 1228 | abort: |
---|
| 1229 | + rseq_after_asm_goto(); |
---|
1009 | 1230 | RSEQ_INJECT_FAILED |
---|
1010 | 1231 | return -1; |
---|
1011 | 1232 | cmpfail: |
---|
| 1233 | + rseq_after_asm_goto(); |
---|
1012 | 1234 | return 1; |
---|
1013 | 1235 | #ifdef RSEQ_COMPARE_TWICE |
---|
1014 | 1236 | error1: |
---|
| 1237 | + rseq_after_asm_goto(); |
---|
1015 | 1238 | rseq_bug("cpu_id comparison failed"); |
---|
1016 | 1239 | error2: |
---|
| 1240 | + rseq_after_asm_goto(); |
---|
1017 | 1241 | rseq_bug("expected value comparison failed"); |
---|
1018 | 1242 | #endif |
---|
1019 | 1243 | } |
---|
.. | .. |
---|
1030 | 1254 | |
---|
1031 | 1255 | __asm__ __volatile__ goto ( |
---|
1032 | 1256 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 1257 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 1258 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 1259 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 1260 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 1261 | +#endif |
---|
1033 | 1262 | "movl %[src], %[rseq_scratch0]\n\t" |
---|
1034 | 1263 | "movl %[dst], %[rseq_scratch1]\n\t" |
---|
1035 | 1264 | "movl %[len], %[rseq_scratch2]\n\t" |
---|
1036 | 1265 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
1037 | | - RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
1038 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
| 1266 | + RSEQ_ASM_STORE_RSEQ_CS(1, 3b, RSEQ_ASM_TP_SEGMENT:RSEQ_CS_OFFSET(%[rseq_offset])) |
---|
| 1267 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 4f) |
---|
1039 | 1268 | RSEQ_INJECT_ASM(3) |
---|
1040 | 1269 | "movl %[expect], %%eax\n\t" |
---|
1041 | 1270 | "cmpl %%eax, %[v]\n\t" |
---|
1042 | 1271 | "jnz 5f\n\t" |
---|
1043 | 1272 | RSEQ_INJECT_ASM(4) |
---|
1044 | 1273 | #ifdef RSEQ_COMPARE_TWICE |
---|
1045 | | - RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 6f) |
---|
| 1274 | + RSEQ_ASM_CMP_CPU_ID(cpu_id, RSEQ_ASM_TP_SEGMENT:RSEQ_CPU_ID_OFFSET(%[rseq_offset]), 6f) |
---|
1046 | 1275 | "movl %[expect], %%eax\n\t" |
---|
1047 | 1276 | "cmpl %%eax, %[v]\n\t" |
---|
1048 | 1277 | "jnz 7f\n\t" |
---|
.. | .. |
---|
1093 | 1322 | #endif |
---|
1094 | 1323 | : /* gcc asm goto does not allow outputs */ |
---|
1095 | 1324 | : [cpu_id] "r" (cpu), |
---|
1096 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
1097 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 1325 | + [rseq_offset] "r" (rseq_offset), |
---|
1098 | 1326 | /* final store input */ |
---|
1099 | 1327 | [v] "m" (*v), |
---|
1100 | 1328 | [expect] "m" (expect), |
---|
.. | .. |
---|
1113 | 1341 | , error1, error2 |
---|
1114 | 1342 | #endif |
---|
1115 | 1343 | ); |
---|
| 1344 | + rseq_after_asm_goto(); |
---|
1116 | 1345 | return 0; |
---|
1117 | 1346 | abort: |
---|
| 1347 | + rseq_after_asm_goto(); |
---|
1118 | 1348 | RSEQ_INJECT_FAILED |
---|
1119 | 1349 | return -1; |
---|
1120 | 1350 | cmpfail: |
---|
| 1351 | + rseq_after_asm_goto(); |
---|
1121 | 1352 | return 1; |
---|
1122 | 1353 | #ifdef RSEQ_COMPARE_TWICE |
---|
1123 | 1354 | error1: |
---|
| 1355 | + rseq_after_asm_goto(); |
---|
1124 | 1356 | rseq_bug("cpu_id comparison failed"); |
---|
1125 | 1357 | error2: |
---|
| 1358 | + rseq_after_asm_goto(); |
---|
1126 | 1359 | rseq_bug("expected value comparison failed"); |
---|
1127 | 1360 | #endif |
---|
1128 | 1361 | } |
---|