add StackSource and implement it for platform::Stack
This commit is contained in:
parent
f7511dc2c1
commit
7aa58f43f7
@ -1,5 +1,5 @@
|
||||
use core::prelude::*;
|
||||
use platform::Stack;
|
||||
use stack::StackSource;
|
||||
use arch::Registers;
|
||||
use platform;
|
||||
|
||||
@ -11,7 +11,7 @@ pub struct Context {
|
||||
impl Context {
|
||||
#[inline]
|
||||
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);
|
||||
Context {
|
||||
regs: regs,
|
||||
|
@ -22,6 +22,15 @@ pub struct Stack {
|
||||
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 {
|
||||
fn top(&mut self) -> *mut u8 {
|
||||
unsafe {
|
||||
@ -37,7 +46,7 @@ impl stack::Stack for Stack {
|
||||
}
|
||||
|
||||
impl Stack {
|
||||
pub fn new(size: usize) -> Stack {
|
||||
fn new(size: usize) -> Stack {
|
||||
let page_size = env::page_size();
|
||||
|
||||
// round the page size up,
|
||||
|
@ -2,3 +2,8 @@ pub trait Stack {
|
||||
fn top(&mut self) -> *mut u8;
|
||||
fn limit(&self) -> *const u8;
|
||||
}
|
||||
|
||||
pub trait StackSource {
|
||||
type Output: Stack;
|
||||
fn get_stack(size: usize) -> Self::Output;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user