1
0
Fork 0

add StackSource and implement it for platform::Stack

This commit is contained in:
edef 2015-04-15 15:56:57 -04:00
parent f7511dc2c1
commit 7aa58f43f7
3 changed files with 17 additions and 3 deletions

View File

@ -1,5 +1,5 @@
use core::prelude::*; use core::prelude::*;
use platform::Stack; use stack::StackSource;
use arch::Registers; use arch::Registers;
use platform; use platform;
@ -11,7 +11,7 @@ pub struct Context {
impl Context { impl Context {
#[inline] #[inline]
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static { pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
let mut stack = Stack::new(4 << 20); let mut stack = platform::StackSource::get_stack(4 << 20);
let regs = Registers::new(&mut stack, f); let regs = Registers::new(&mut stack, f);
Context { Context {
regs: regs, regs: regs,

View File

@ -22,6 +22,15 @@ pub struct Stack {
valgrind_id: libc::c_uint valgrind_id: libc::c_uint
} }
pub struct StackSource;
impl stack::StackSource for StackSource {
type Output = Stack;
fn get_stack(size: usize) -> Stack {
Stack::new(size)
}
}
impl stack::Stack for Stack { impl stack::Stack for Stack {
fn top(&mut self) -> *mut u8 { fn top(&mut self) -> *mut u8 {
unsafe { unsafe {
@ -37,7 +46,7 @@ impl stack::Stack for Stack {
} }
impl Stack { impl Stack {
pub fn new(size: usize) -> Stack { fn new(size: usize) -> Stack {
let page_size = env::page_size(); let page_size = env::page_size();
// round the page size up, // round the page size up,

View File

@ -2,3 +2,8 @@ pub trait Stack {
fn top(&mut self) -> *mut u8; fn top(&mut self) -> *mut u8;
fn limit(&self) -> *const u8; fn limit(&self) -> *const u8;
} }
pub trait StackSource {
type Output: Stack;
fn get_stack(size: usize) -> Self::Output;
}