rearrange the os::{Stack, StackSource} code a little

This commit is contained in:
edef 2015-04-16 05:24:18 -04:00
parent 8dd3044da5
commit 2c3a203f57
1 changed files with 16 additions and 22 deletions

View File

@ -6,6 +6,8 @@ use stack;
#[cfg(unix)]
#[path = "os/unix.rs"] mod sys;
pub struct StackSource;
#[allow(raw_pointer_derive)]
#[derive(Debug)]
pub struct Stack {
@ -13,33 +15,11 @@ pub struct Stack {
len: usize
}
pub struct StackSource;
impl stack::StackSource for StackSource {
type Output = Stack;
type Error = IoError;
fn get_stack(size: usize) -> Result<Stack, IoError> {
Stack::new(size)
}
}
impl stack::Stack for Stack {
fn top(&mut self) -> *mut u8 {
unsafe {
self.ptr.offset(self.len as isize)
}
}
fn limit(&self) -> *const u8 {
unsafe {
self.ptr.offset(sys::page_size() as isize)
}
}
}
impl Stack {
fn new(size: usize) -> Result<Stack, IoError> {
let page_size = sys::page_size();
// round the page size up,
@ -64,6 +44,20 @@ impl Stack {
}
}
impl stack::Stack for Stack {
fn top(&mut self) -> *mut u8 {
unsafe {
self.ptr.offset(self.len as isize)
}
}
fn limit(&self) -> *const u8 {
unsafe {
self.ptr.offset(sys::page_size() as isize)
}
}
}
impl Drop for Stack {
fn drop(&mut self) {
unsafe {