use core::arch::wasm32;
use core::fmt;
use super::{Heap, PAGE_SIZE};
unsafe extern "C" {
static __heap_base: u8;
}
#[derive(Debug)]
pub struct WasmHeap {}
impl Heap for WasmHeap {
fn heap_start(&self) -> usize {
&raw const __heap_base as usize
}
fn heap_end(&self) -> usize {
wasm32::memory_size(0) * PAGE_SIZE
}
fn heap_grow(&self, pages: usize) -> Option<*mut u8> {
let prev_size = wasm32::memory_grow(0, pages);
if prev_size != usize::MAX {
Some((prev_size * PAGE_SIZE) as *mut u8)
} else {
None
}
}
}
impl fmt::Display for WasmHeap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "WASM")
}
}