1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate alloc;
use core::slice;
use self::alloc::heap;
use self::alloc::boxed::Box;
#[derive(Debug)]
pub struct OwnedStack(Box<[u8]>);
impl OwnedStack {
pub fn new(size: usize) -> OwnedStack {
unsafe {
let ptr = heap::allocate(size, ::STACK_ALIGNMENT);
OwnedStack(Box::from_raw(slice::from_raw_parts_mut(ptr, size)))
}
}
}
impl ::stack::Stack for OwnedStack {
#[inline(always)]
fn base(&self) -> *mut u8 {
let len: isize = self.0.len() as isize;
unsafe { self.limit().offset(len) }
}
#[inline(always)]
fn limit(&self) -> *mut u8 {
self.0.as_ptr() as *mut u8
}
}