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
|
||||
}
|
||||
|
||||
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, f as usize); // function
|
||||
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,
|
||||
new_stack: &Stack) -> usize {
|
||||
// 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]
|
||||
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
|
||||
}
|
||||
|
||||
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, 0 as usize); // alignment
|
||||
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,
|
||||
new_stack: &Stack) -> usize {
|
||||
// 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]
|
||||
unsafe extern "C" fn trampoline() {
|
||||
|
|
|
@ -12,7 +12,7 @@ pub struct StackId(self::valgrind::Value);
|
|||
impl StackId {
|
||||
#[inline(always)]
|
||||
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 {
|
||||
#[inline(always)]
|
||||
fn top(&self) -> *mut u8 {
|
||||
fn base(&self) -> *mut u8 {
|
||||
unsafe {
|
||||
self.ptr.offset(self.len as isize)
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
/// A trait for objects that hold ownership of a stack.
|
||||
pub trait Stack {
|
||||
/// Returns the top of the stack.
|
||||
/// Returns the base of the stack.
|
||||
/// On all modern architectures, the stack grows downwards,
|
||||
/// so this is the highest address.
|
||||
fn top(&self) -> *mut u8;
|
||||
fn base(&self) -> *mut u8;
|
||||
/// Returns the bottom of the stack.
|
||||
/// On all modern architectures, the stack grows downwards,
|
||||
/// so this is the lowest address.
|
||||
|
|
|
@ -9,12 +9,12 @@ use fringe::{Stack, OsStack};
|
|||
fn default_stack() {
|
||||
let stack = OsStack::new(0).unwrap();
|
||||
// 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]
|
||||
fn one_page_stack() {
|
||||
let stack = OsStack::new(4096).unwrap();
|
||||
// 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