-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathryzen_segv_test.s
498 lines (498 loc) · 7.82 KB
/
ryzen_segv_test.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
.file "ryzen_segv_test.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "lock inconsistency!!\n"
.text
.p2align 4,,15
.type lock_leave, @function
lock_leave:
.LFB80:
.cfi_startproc
xorl %eax, %eax
xchgl locked(%rip), %eax
testl %eax, %eax
je .L4
rep ret
.p2align 4,,10
.p2align 3
.L4:
movq stderr(%rip), %rcx
leaq .LC0(%rip), %rdi
movl $21, %edx
movl $1, %esi
jmp fwrite@PLT
.cfi_endproc
.LFE80:
.size lock_leave, .-lock_leave
.section .rodata.str1.1
.LC1:
.string "mismatch!!!!!!!!!!! %u %u\n"
.text
.p2align 4,,15
.globl thread1
.type thread1, @function
thread1:
.LFB83:
.cfi_startproc
pushq %r13
.cfi_def_cfa_offset 16
.cfi_offset 13, -16
pushq %r12
.cfi_def_cfa_offset 24
.cfi_offset 12, -24
movq %rdi, %r12
pushq %rbp
.cfi_def_cfa_offset 32
.cfi_offset 6, -32
pushq %rbx
.cfi_def_cfa_offset 40
.cfi_offset 3, -40
xorl %ebp, %ebp
subq $24, %rsp
.cfi_def_cfa_offset 64
movq %fs:40, %rax
movq %rax, 8(%rsp)
xorl %eax, %eax
cmpq $0, (%rdi)
je .L12
.p2align 4,,10
.p2align 3
.L16:
movl $1, %edx
.p2align 4,,10
.p2align 3
.L7:
movl %edx, %eax
xchgl locked(%rip), %eax
testl %eax, %eax
jne .L7
#APP
# 152 "ryzen_segv_test.c" 1
mfence
# 0 "" 2
# 163 "ryzen_segv_test.c" 1
cpuid
# 0 "" 2
#NO_APP
movq func_set(%rip), %rdi
movzbl 571(%rdi), %eax
movl 572(%rdi), %ebx
leaq 64(%rdi,%rax), %rax
call *%rax
movl %eax, %r13d
xorl %eax, %eax
call lock_leave
movl %ebx, %eax
sall $13, %eax
xorl %ebx, %eax
movl %eax, %edx
shrl $17, %edx
xorl %edx, %eax
movl %eax, %edx
sall $5, %edx
xorl %edx, %eax
cmpl $-958040967, %eax
leal 1697253807(%rax), %r8d
ja .L9
xorl $-958040966, %eax
movl %eax, %r8d
sall $13, %eax
xorl %eax, %r8d
movl %r8d, %eax
shrl $17, %eax
xorl %eax, %r8d
movl %r8d, %eax
sall $5, %eax
xorl %eax, %r8d
.L9:
cmpl %r13d, %r8d
je .L10
movq stderr(%rip), %rdi
leaq .LC1(%rip), %rdx
movl %r13d, %ecx
movl $1, %esi
xorl %eax, %eax
call __fprintf_chk@PLT
.L10:
movq (%r12), %rax
addq $1, %rbp
cmpq %rbp, %rax
jg .L16
shrq $63, %rax
testb %al, %al
jne .L16
.L12:
movl $0, flg(%rip)
mfence
movq 8(%rsp), %rax
xorq %fs:40, %rax
jne .L20
addq $24, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 40
popq %rbx
.cfi_def_cfa_offset 32
popq %rbp
.cfi_def_cfa_offset 24
popq %r12
.cfi_def_cfa_offset 16
popq %r13
.cfi_def_cfa_offset 8
ret
.L20:
.cfi_restore_state
call __stack_chk_fail@PLT
.cfi_endproc
.LFE83:
.size thread1, .-thread1
.section .rodata.str1.1
.LC2:
.string "mmap returns MAP_FAILED!\n"
.text
.p2align 4,,15
.globl threadx
.type threadx, @function
threadx:
.LFB84:
.cfi_startproc
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
xorl %r12d, %r12d
pushq %rbx
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
movl flg(%rip), %eax
testq %rdi, %rdi
setne %r12b
leaq func_base(%rip), %rbx
testl %eax, %eax
je .L32
.p2align 4,,10
.p2align 3
.L27:
call random@PLT
cqto
shrq $56, %rdx
leaq (%rax,%rdx), %rbp
movzbl %bpl, %ebp
subq %rdx, %rbp
call random@PLT
testl %r12d, %r12d
movq %rax, %rdx
jne .L23
movl $1, %ecx
.p2align 4,,10
.p2align 3
.L24:
movl %ecx, %eax
xchgl locked(%rip), %eax
testl %eax, %eax
jne .L24
movq func_set(%rip), %rax
.L26:
leaq 8(%rax), %rdi
movq $0, 568(%rax)
movq $0, (%rax)
andq $-8, %rdi
subq %rdi, %rax
leal 576(%rax), %ecx
xorl %eax, %eax
shrl $3, %ecx
rep stosq
movzbl %bpl, %edi
movq func_set(%rip), %rax
movq (%rbx), %rsi
addq %rax, %rdi
movq %rsi, 64(%rdi)
movq 243+func_base(%rip), %rsi
leaq 64(%rdi), %rcx
addq $72, %rdi
movq %rsi, 235(%rdi)
andq $-8, %rdi
movq %rbx, %rsi
subq %rdi, %rcx
subq %rcx, %rsi
addl $251, %ecx
shrl $3, %ecx
rep movsq
movb %bpl, 571(%rax)
movl %edx, 572(%rax)
#APP
# 152 "ryzen_segv_test.c" 1
mfence
# 0 "" 2
#NO_APP
xorl %eax, %eax
xorl %r12d, %r12d
call lock_leave
movl flg(%rip), %eax
testl %eax, %eax
jne .L27
.L32:
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L23:
.cfi_restore_state
movq func_set(%rip), %rax
cmpq $-1, %rax
jne .L26
popq %rbx
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
movq stderr(%rip), %rcx
leaq .LC2(%rip), %rdi
movl $25, %edx
movl $1, %esi
jmp fwrite@PLT
.cfi_endproc
.LFE84:
.size threadx, .-threadx
.section .rodata.str1.1
.LC3:
.string "PID:%d CPU:%d\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB85:
.cfi_startproc
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
movq %rsi, %r12
pushq %rbx
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
movl %edi, %ebx
subq $176, %rsp
.cfi_def_cfa_offset 208
movq %fs:40, %rax
movq %rax, 168(%rsp)
xorl %eax, %eax
call getpid@PLT
cmpl $1, %ebx
movl %eax, %ebp
jle .L34
movq 8(%r12), %rdi
movl $10, %edx
xorl %esi, %esi
call strtoll@PLT
movq %rax, (%rsp)
.L35:
movl $84, %edi
call sysconf@PLT
xorl %r9d, %r9d
movl $-1, %r8d
movl $34, %ecx
movl $7, %edx
movl $576, %esi
xorl %edi, %edi
movl %eax, n_cpus(%rip)
call mmap@PLT
movq %rax, func_set(%rip)
xorl %edi, %edi
movl $1, flg(%rip)
mfence
movl $1, locked(%rip)
mfence
call time@PLT
leal 0(%rbp,%rax), %edi
call srandom@PLT
#APP
# 152 "ryzen_segv_test.c" 1
mfence
# 0 "" 2
#NO_APP
leaq thread1(%rip), %rdx
leaq 8(%rsp), %rdi
xorl %esi, %esi
movq %rsp, %rcx
call pthread_create@PLT
leaq 16(%rsp), %rdi
leaq threadx(%rip), %rdx
xorl %esi, %esi
movl $1, %ecx
call pthread_create@PLT
leaq 24(%rsp), %rdi
leaq threadx(%rip), %rdx
xorl %ecx, %ecx
xorl %esi, %esi
call pthread_create@PLT
call random@PLT
movslq n_cpus(%rip), %rbx
cqto
movl $16, %ecx
idivq %rbx
xorl %eax, %eax
movq %rdx, %rbx
leaq 32(%rsp), %rdx
cmpq $1023, %rbx
movq %rdx, %rdi
rep stosq
ja .L36
movq %rbx, %rsi
movl $1, %eax
movl %ebx, %ecx
shrq $6, %rsi
salq %cl, %rax
orq %rax, (%rdx,%rsi,8)
.L36:
movl $128, %esi
movl %ebp, %edi
call sched_setaffinity@PLT
movq stderr(%rip), %rdi
leaq .LC3(%rip), %rdx
movl %ebx, %r8d
movl %ebp, %ecx
movl $1, %esi
xorl %eax, %eax
call __fprintf_chk@PLT
movq 8(%rsp), %rdi
xorl %esi, %esi
call pthread_join@PLT
movq 16(%rsp), %rdi
xorl %esi, %esi
call pthread_join@PLT
movq 24(%rsp), %rdi
xorl %esi, %esi
call pthread_join@PLT
xorl %eax, %eax
movq 168(%rsp), %rbx
xorq %fs:40, %rbx
jne .L39
addq $176, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 32
popq %rbx
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.L34:
.cfi_restore_state
movq $-1, (%rsp)
jmp .L35
.L39:
call __stack_chk_fail@PLT
.cfi_endproc
.LFE85:
.size main, .-main
.globl n_cpus
.data
.align 4
.type n_cpus, @object
.size n_cpus, 4
n_cpus:
.long 16
.globl func_base
.align 32
.type func_base, @object
.size func_base, 251
func_base:
.byte -117
.byte -105
.byte 60
.byte 2
.byte 0
.byte 0
.byte -119
.byte -48
.byte -63
.byte -32
.byte 13
.byte 49
.byte -62
.byte -119
.byte -48
.byte -63
.byte -24
.byte 17
.byte 49
.byte -62
.byte -119
.byte -48
.byte -63
.byte -32
.byte 5
.byte 49
.byte -62
.byte -127
.byte -6
.byte 121
.byte 116
.byte -27
.byte -58
.byte -115
.byte -126
.byte -81
.byte 9
.byte 42
.byte 101
.byte 118
.byte 7
.byte -13
.byte -61
.byte 15
.byte 31
.byte 68
.byte 0
.byte 0
.byte -119
.byte -48
.byte 53
.byte 122
.byte 116
.byte -27
.byte -58
.byte -119
.byte -62
.byte -63
.byte -30
.byte 13
.byte 49
.byte -48
.byte -119
.byte -62
.byte -63
.byte -22
.byte 17
.byte 49
.byte -48
.byte -119
.byte -62
.byte -63
.byte -30
.byte 5
.byte 49
.byte -48
.byte -61
.byte 15
.byte 31
.byte 0
.zero 171
.comm locked,4,4
.comm flg,4,4
.comm func_set,8,8
.ident "GCC: (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406"
.section .note.GNU-stack,"",@progbits