forked from M-Labs/libfringe
parent
7d5075edc2
commit
b79e7c0a9b
|
@ -84,7 +84,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
|
||||||
*sp.0 = val
|
*sp.0 = val
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sp = StackPointer(stack.top() as *mut usize);
|
let mut sp = StackPointer(stack.base() as *mut usize);
|
||||||
push(&mut sp, 0xdead0cfa); // CFA slot
|
push(&mut sp, 0xdead0cfa); // CFA slot
|
||||||
push(&mut sp, f as usize); // function
|
push(&mut sp, f as usize); // function
|
||||||
push(&mut sp, trampoline_1 as usize);
|
push(&mut sp, trampoline_1 as usize);
|
||||||
|
@ -96,7 +96,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
|
||||||
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
|
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
|
||||||
new_stack: &Stack) -> usize {
|
new_stack: &Stack) -> usize {
|
||||||
// Address of the topmost CFA stack slot.
|
// Address of the topmost CFA stack slot.
|
||||||
let new_cfa = (new_stack.top() as *mut usize).offset(-1);
|
let new_cfa = (new_stack.base() as *mut usize).offset(-1);
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
unsafe extern "C" fn trampoline() {
|
unsafe extern "C" fn trampoline() {
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
|
||||||
*sp.0 = val
|
*sp.0 = val
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sp = StackPointer(stack.top() as *mut usize);
|
let mut sp = StackPointer(stack.base() as *mut usize);
|
||||||
push(&mut sp, 0xdeaddeaddead0cfa); // CFA slot
|
push(&mut sp, 0xdeaddeaddead0cfa); // CFA slot
|
||||||
push(&mut sp, 0 as usize); // alignment
|
push(&mut sp, 0 as usize); // alignment
|
||||||
push(&mut sp, f as usize); // function
|
push(&mut sp, f as usize); // function
|
||||||
|
@ -98,7 +98,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
|
||||||
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
|
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
|
||||||
new_stack: &Stack) -> usize {
|
new_stack: &Stack) -> usize {
|
||||||
// Address of the topmost CFA stack slot.
|
// Address of the topmost CFA stack slot.
|
||||||
let new_cfa = (new_stack.top() as *mut usize).offset(-1);
|
let new_cfa = (new_stack.base() as *mut usize).offset(-1);
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
unsafe extern "C" fn trampoline() {
|
unsafe extern "C" fn trampoline() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub struct StackId(self::valgrind::Value);
|
||||||
impl StackId {
|
impl StackId {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn register<Stack: stack::Stack>(stack: &Stack) -> StackId {
|
pub fn register<Stack: stack::Stack>(stack: &Stack) -> StackId {
|
||||||
StackId(stack_register(stack.limit(), stack.top()))
|
StackId(stack_register(stack.limit(), stack.base()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl Stack {
|
||||||
|
|
||||||
impl stack::Stack for Stack {
|
impl stack::Stack for Stack {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn top(&self) -> *mut u8 {
|
fn base(&self) -> *mut u8 {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.ptr.offset(self.len as isize)
|
self.ptr.offset(self.len as isize)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
|
|
||||||
/// A trait for objects that hold ownership of a stack.
|
/// A trait for objects that hold ownership of a stack.
|
||||||
pub trait Stack {
|
pub trait Stack {
|
||||||
/// Returns the top of the stack.
|
/// Returns the base of the stack.
|
||||||
/// On all modern architectures, the stack grows downwards,
|
/// On all modern architectures, the stack grows downwards,
|
||||||
/// so this is the highest address.
|
/// so this is the highest address.
|
||||||
fn top(&self) -> *mut u8;
|
fn base(&self) -> *mut u8;
|
||||||
/// Returns the bottom of the stack.
|
/// Returns the bottom of the stack.
|
||||||
/// On all modern architectures, the stack grows downwards,
|
/// On all modern architectures, the stack grows downwards,
|
||||||
/// so this is the lowest address.
|
/// so this is the lowest address.
|
||||||
|
|
|
@ -9,12 +9,12 @@ use fringe::{Stack, OsStack};
|
||||||
fn default_stack() {
|
fn default_stack() {
|
||||||
let stack = OsStack::new(0).unwrap();
|
let stack = OsStack::new(0).unwrap();
|
||||||
// Make sure the topmost page of the stack, at least, is accessible.
|
// Make sure the topmost page of the stack, at least, is accessible.
|
||||||
unsafe { *(stack.top().offset(-1)) = 0; }
|
unsafe { *(stack.base().offset(-1)) = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one_page_stack() {
|
fn one_page_stack() {
|
||||||
let stack = OsStack::new(4096).unwrap();
|
let stack = OsStack::new(4096).unwrap();
|
||||||
// Make sure the topmost page of the stack, at least, is accessible.
|
// Make sure the topmost page of the stack, at least, is accessible.
|
||||||
unsafe { *(stack.top().offset(-1)) = 0; }
|
unsafe { *(stack.base().offset(-1)) = 0; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue