Bring back workarounds for Mach-O assembly syntax.

This commit is contained in:
whitequark 2016-09-03 12:38:24 +00:00 committed by edef
parent 491af39fc9
commit f82d0e2c21
2 changed files with 41 additions and 0 deletions

View File

@ -23,6 +23,7 @@ pub const STACK_ALIGNMENT: usize = 16;
pub struct StackPointer(*mut usize); pub struct StackPointer(*mut usize);
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
#[cfg(not(target_vendor = "apple"))]
#[naked] #[naked]
unsafe extern "C" fn trampoline() { unsafe extern "C" fn trampoline() {
asm!( asm!(
@ -56,6 +57,27 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
: : : : "volatile") : : : : "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) { unsafe fn push(sp: &mut StackPointer, val: usize) {
sp.0 = sp.0.offset(-1); sp.0 = sp.0.offset(-1);
*sp.0 = val *sp.0 = val

View File

@ -27,6 +27,7 @@ pub const STACK_ALIGNMENT: usize = 16;
pub struct StackPointer(*mut usize); pub struct StackPointer(*mut usize);
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
#[cfg(not(target_vendor = "apple"))]
#[naked] #[naked]
unsafe extern "C" fn trampoline() { unsafe extern "C" fn trampoline() {
asm!( asm!(
@ -59,6 +60,24 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
: : : : "volatile") : : : : "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) { unsafe fn push(sp: &mut StackPointer, val: usize) {
sp.0 = sp.0.offset(-1); sp.0 = sp.0.offset(-1);
*sp.0 = val *sp.0 = val