From f82d0e2c21261f321b6643774b6acf1b20852035 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 3 Sep 2016 12:38:24 +0000 Subject: [PATCH] Bring back workarounds for Mach-O assembly syntax. --- src/arch/x86.rs | 22 ++++++++++++++++++++++ src/arch/x86_64.rs | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 6370234..fbe47b2 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -23,6 +23,7 @@ pub const STACK_ALIGNMENT: usize = 16; pub struct StackPointer(*mut usize); pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { + #[cfg(not(target_vendor = "apple"))] #[naked] unsafe extern "C" fn trampoline() { asm!( @@ -56,6 +57,27 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP : : : : "volatile") } + #[cfg(target_vendor = "apple")] + #[naked] + unsafe extern "C" fn trampoline() { + asm!( + r#" + # Identical to the above, except avoids .local/.size that aren't available on Mach-O. + __morestack: + .private_extern __morestack + + subl $$8, %esp + .cfi_def_cfa_offset 8 + .cfi_offset %ebp, -8 + movl %esp, %ebp + .cfi_def_cfa_register %ebp + # Call f. + pushl %eax + calll *12(%esp) + "# + : : : : "volatile") + } + unsafe fn push(sp: &mut StackPointer, val: usize) { sp.0 = sp.0.offset(-1); *sp.0 = val diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 284d6e7..ad1015a 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -27,6 +27,7 @@ pub const STACK_ALIGNMENT: usize = 16; pub struct StackPointer(*mut usize); pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { + #[cfg(not(target_vendor = "apple"))] #[naked] unsafe extern "C" fn trampoline() { asm!( @@ -59,6 +60,24 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP : : : : "volatile") } + #[cfg(target_vendor = "apple")] + #[naked] + unsafe extern "C" fn trampoline() { + asm!( + r#" + # Identical to the above, except avoids .local/.size that aren't available on Mach-O. + __morestack: + .private_extern __morestack + + subq $$16, %rsp + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + movq %rsp, %rbp + .cfi_def_cfa_register %rbp + callq *16(%rsp) + "# + : : : : "volatile") + } unsafe fn push(sp: &mut StackPointer, val: usize) { sp.0 = sp.0.offset(-1); *sp.0 = val