Skip to content

Commit

Permalink
Merge pull request #207 from sunfishcode/master
Browse files Browse the repository at this point in the history
Add "volatile" and "memory" clobber to asm! that doesn't fall through.
  • Loading branch information
alexcrichton authored Nov 15, 2017
2 parents 93e3091 + a6ecd1a commit f5532b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
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();
}

0 comments on commit f5532b2

Please sign in to comment.