Skip to content

Commit

Permalink
Move x86 trampoline to naked function
Browse files Browse the repository at this point in the history
Close #19
  • Loading branch information
Ericson2314 authored and edef1c committed Jul 16, 2016
1 parent 1ea4b01 commit 75ca6f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,26 @@ impl StackPointer {
}

pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
let g: usize;
asm!(
r#"
# Push address of the trampoline.
call 1f
# Pop function.
popl %ebx
# Push argument.
pushl %eax
# Call it.
call *%ebx
1:
# Pop address of the trampoline.
popl %eax
"#
: "={eax}" (g)
:
: "memory"
: "volatile"
);
#[naked]
unsafe extern "C" fn trampoline() -> ! {
asm!(
r#"
# Pop function.
popl %ebx
# Push argument.
pushl %eax
# Call it.
call *%ebx
"# ::: "memory" : "volatile");
::core::intrinsics::unreachable()
}

let mut sp = StackPointer::new(stack);
sp.push(0); // alignment
sp.push(0); // alignment
sp.push(0); // alignment
sp.push(f as usize); // function
sp.push(g as usize); // trampoline
sp.push(trampoline as usize);
sp
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) edef <edef@edef.eu>
// See the LICENSE file included in this distribution.
#![feature(asm)]
#![cfg_attr(target_arch = "x86", feature(naked_functions, core_intrinsics))]
#![no_std]

//! libfringe is a low-level green threading library.
Expand Down

0 comments on commit 75ca6f6

Please sign in to comment.