rearrange the os::{Stack, StackSource} code a little
This commit is contained in:
parent
8dd3044da5
commit
2c3a203f57
38
src/os.rs
38
src/os.rs
|
@ -6,6 +6,8 @@ use stack;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[path = "os/unix.rs"] mod sys;
|
#[path = "os/unix.rs"] mod sys;
|
||||||
|
|
||||||
|
pub struct StackSource;
|
||||||
|
|
||||||
#[allow(raw_pointer_derive)]
|
#[allow(raw_pointer_derive)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Stack {
|
pub struct Stack {
|
||||||
|
@ -13,33 +15,11 @@ pub struct Stack {
|
||||||
len: usize
|
len: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StackSource;
|
|
||||||
|
|
||||||
impl stack::StackSource for StackSource {
|
impl stack::StackSource for StackSource {
|
||||||
type Output = Stack;
|
type Output = Stack;
|
||||||
type Error = IoError;
|
type Error = IoError;
|
||||||
|
|
||||||
fn get_stack(size: usize) -> Result<Stack, 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();
|
let page_size = sys::page_size();
|
||||||
|
|
||||||
// round the page size up,
|
// 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 {
|
impl Drop for Stack {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in New Issue