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

Add "volatile" and "memory" clobber to asm! that doesn't fall through. #207

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub unsafe fn __aeabi_uidivmod() {
bl __udivmodsi4
ldr r1, [sp]
add sp, sp, #4
pop {pc}");
pop {pc}" ::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand All @@ -26,7 +26,7 @@ pub unsafe fn __aeabi_uldivmod() {
ldr r2, [sp, #8]
ldr r3, [sp, #12]
add sp, sp, #16
pop {r4, pc}");
pop {r4, pc}" ::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand All @@ -38,7 +38,7 @@ pub unsafe fn __aeabi_idivmod() {
pop {r1, r2}
muls r2, r2, r0
subs r1, r1, r2
pop {r4, pc}");
pop {r4, pc}" ::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand All @@ -53,7 +53,7 @@ pub unsafe fn __aeabi_ldivmod() {
ldr r2, [sp, #8]
ldr r3, [sp, #12]
add sp, sp, #16
pop {r4, pc}");
pop {r4, pc}" ::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand Down
4 changes: 2 additions & 2 deletions src/probestack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub unsafe extern fn __rust_probestack() {
add %rax,%rsp

ret
");
" ::: "memory" : "volatile");
::core::intrinsics::unreachable();
}

Expand Down Expand Up @@ -111,6 +111,6 @@ pub unsafe extern fn __rust_probestack() {
add %eax,%esp
pop %ecx
ret
");
" ::: "memory" : "volatile");
::core::intrinsics::unreachable();
}
7 changes: 4 additions & 3 deletions src/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub unsafe fn ___chkstk_ms() {
test %ecx,(%ecx)
pop %eax
pop %ecx
ret");
ret" ::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand All @@ -38,7 +38,8 @@ pub unsafe fn ___chkstk_ms() {
#[naked]
#[no_mangle]
pub unsafe fn __alloca() {
asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable");
asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand Down Expand Up @@ -66,6 +67,6 @@ pub unsafe fn ___chkstk() {
mov -4(%eax),%ecx // restore ecx
push (%eax) // push return address onto the stack
sub %esp,%eax // restore the original value in eax
ret");
ret" ::: "memory" : "volatile");
intrinsics::unreachable();
}
12 changes: 8 additions & 4 deletions src/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub unsafe fn ___chkstk_ms() {
test %rcx,(%rcx)
pop %rax
pop %rcx
ret");
ret" ::: "memory" : "volatile");
intrinsics::unreachable();
}

Expand All @@ -38,15 +38,17 @@ pub unsafe fn ___chkstk_ms() {
#[no_mangle]
pub unsafe fn __alloca() {
asm!("mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable");
jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
::: "memory" : "volatile");
intrinsics::unreachable();
}

#[cfg(all(windows, target_env = "gnu", not(feature = "mangled-names")))]
#[naked]
#[no_mangle]
pub unsafe fn ___chkstk() {
asm!("
asm!(
"
push %rcx
cmp $$0x1000,%rax
lea 16(%rsp),%rcx // rsp before calling this routine -> rcx
Expand All @@ -66,6 +68,8 @@ pub unsafe fn ___chkstk() {
mov -8(%rax),%rcx // restore rcx
push (%rax) // push return address onto the stack
sub %rsp,%rax // restore the original value in rax
ret");
ret"
::: "memory" : "volatile"
);
intrinsics::unreachable();
}