Fix Windows x64 ABI
This commit is contained in:
parent
42f37c967e
commit
8c761d944f
|
@ -42,8 +42,8 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
|
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
|
||||||
let ret: usize;
|
macro_rules! swap_body {
|
||||||
asm!(
|
() => {
|
||||||
r#"
|
r#"
|
||||||
# Save frame pointer explicitly; LLVM doesn't spill it even if it is
|
# Save frame pointer explicitly; LLVM doesn't spill it even if it is
|
||||||
# marked as clobbered.
|
# marked as clobbered.
|
||||||
|
@ -71,6 +71,14 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer)
|
||||||
jmpq *%rbx
|
jmpq *%rbx
|
||||||
2:
|
2:
|
||||||
"#
|
"#
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
#[inline(always)]
|
||||||
|
unsafe fn swap_impl(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
|
||||||
|
let ret: usize;
|
||||||
|
asm!(swap_body!()
|
||||||
: "={rdi}" (ret)
|
: "={rdi}" (ret)
|
||||||
: "{rdi}" (arg)
|
: "{rdi}" (arg)
|
||||||
"{rsi}" (old_sp)
|
"{rsi}" (old_sp)
|
||||||
|
@ -89,4 +97,33 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer)
|
||||||
// thing on x86_64.
|
// thing on x86_64.
|
||||||
: "volatile", "alignstack");
|
: "volatile", "alignstack");
|
||||||
ret
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[inline(always)]
|
||||||
|
unsafe fn swap_impl(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
|
||||||
|
let ret: usize;
|
||||||
|
asm!(swap_body!()
|
||||||
|
: "={rcx}" (ret)
|
||||||
|
: "{rcx}" (arg)
|
||||||
|
"{rsi}" (old_sp)
|
||||||
|
"{rdx}" (new_sp)
|
||||||
|
: "rax", "rbx", "rcx", "rdx", "rsi", "rdi", //"rbp", "rsp",
|
||||||
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
||||||
|
"xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
|
||||||
|
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
|
||||||
|
"xmm16", "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23",
|
||||||
|
"xmm24", "xmm25", "xmm26", "xmm27", "xmm28", "xmm29", "xmm30", "xmm31"
|
||||||
|
"cc", "fpsr", "flags", "memory"
|
||||||
|
// Ideally, we would set the LLVM "noredzone" attribute on this function
|
||||||
|
// (and it would be propagated to the call site). Unfortunately, rustc
|
||||||
|
// provides no such functionality. Fortunately, by a lucky coincidence,
|
||||||
|
// the "alignstack" LLVM inline assembly option does exactly the same
|
||||||
|
// thing on x86_64.
|
||||||
|
: "volatile", "alignstack");
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
swap_impl(arg, old_sp, new_sp)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue