use core::alloc::Layout;
use mnemosyne_core::MemoryBackend;
pub struct WasmBackend;
impl MemoryBackend for WasmBackend {
const SUPPORTS_PAGE_RESET: bool = false;
const SUPPORTS_MAKE_GUARD: bool = false;
const SUPPORTS_DECOMMIT: bool = false;
unsafe fn allocate(size: usize) -> *mut u8 {
let Ok(layout) = Layout::from_size_align(size, mnemosyne_core::PAGE_ALIGN) else {
return core::ptr::null_mut();
};
unsafe { alloc::alloc::alloc(layout) }
}
unsafe fn deallocate(ptr: *mut u8, size: usize) -> bool {
if ptr.is_null() {
return false;
}
let Ok(layout) = Layout::from_size_align(size, mnemosyne_core::PAGE_ALIGN) else {
return false;
};
unsafe { alloc::alloc::dealloc(ptr, layout) };
true
}
}