diff --git a/src/os.rs b/src/os.rs index 88e96ec..b21572a 100644 --- a/src/os.rs +++ b/src/os.rs @@ -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::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 { 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 {