Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on x86_64 #15

Open
gcsbt opened this issue Apr 9, 2024 · 0 comments
Open

Segfault on x86_64 #15

gcsbt opened this issue Apr 9, 2024 · 0 comments

Comments

@gcsbt
Copy link

gcsbt commented Apr 9, 2024

Hello,

I encounter a crash on a x86_64 machine. It looks like the rdx register is dereferenced while being invalid:

Program received signal SIGSEGV, Segmentation fault
0x000055555558aa2c in _ ()
(gdb) x/6i $pc-20
   0x55555558aa18 <_+56>:    rdtsc
   0x55555558aa1a <_+58>:    shl    rdx,0x20
   0x55555558aa1e <_+62>:    or     rax,rdx
   0x55555558aa21 <_+65>:    mov    QWORD PTR [rcx],0x1
   0x55555558aa28 <_+72>:    mov    QWORD PTR [rcx+0x8],rax
=> 0x55555558aa2c <_+76>:    movzx  eax,BYTE PTR [rdx+0x14]
(gdb) i r $rdx
rdx            0x227bd00000000     606642655723520

I guess the reason is rdx is not marked as an out register in start() and stop() functions, and the compiler assumes it isn't modified.

Suggested fix (untested): add out("rdx") _ to the asm! macros if you don't want to rely on core::arch::x86_64::_rdtsc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant