2019-01-16 10:26:10 -08:00
|
|
|
use crate::{memory::LinearMemory, structures::TypedIndex, types::LocalMemoryIndex, vm};
|
2019-01-08 12:09:47 -05:00
|
|
|
|
|
|
|
pub unsafe extern "C" fn memory_grow_static(
|
2019-01-16 10:26:10 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-08 12:09:47 -05:00
|
|
|
by_pages: u32,
|
|
|
|
ctx: *mut vm::Ctx,
|
|
|
|
) -> i32 {
|
2019-01-12 22:02:19 -05:00
|
|
|
if let Some(old) = (*(*ctx).local_backing)
|
|
|
|
.memory(memory_index)
|
|
|
|
.grow_static(by_pages)
|
2019-01-08 12:09:47 -05:00
|
|
|
{
|
|
|
|
// Store the new size back into the vmctx.
|
2019-01-16 10:26:10 -08:00
|
|
|
(*(*ctx).memories.add(memory_index.index())).size =
|
2019-01-08 12:09:47 -05:00
|
|
|
(old as usize + by_pages as usize) * LinearMemory::PAGE_SIZE as usize;
|
|
|
|
old
|
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 10:26:10 -08:00
|
|
|
pub unsafe extern "C" fn memory_size(memory_index: LocalMemoryIndex, ctx: *mut vm::Ctx) -> u32 {
|
2019-01-12 22:02:19 -05:00
|
|
|
(*(*ctx).local_backing).memory(memory_index).pages()
|
2019-01-08 12:09:47 -05:00
|
|
|
}
|
2019-01-09 18:31:11 -05:00
|
|
|
|
|
|
|
pub unsafe extern "C" fn memory_grow_dynamic(
|
2019-01-16 10:26:10 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-09 18:31:11 -05:00
|
|
|
by_pages: u32,
|
|
|
|
ctx: *mut vm::Ctx,
|
|
|
|
) -> i32 {
|
2019-01-12 22:02:19 -05:00
|
|
|
if let Some(old) = (*(*ctx).local_backing)
|
|
|
|
.memory(memory_index)
|
|
|
|
.grow_dynamic(by_pages)
|
2019-01-09 18:31:11 -05:00
|
|
|
{
|
|
|
|
// Store the new size back into the vmctx.
|
2019-01-16 10:26:10 -08:00
|
|
|
(*(*ctx).memories.add(memory_index.index())).size =
|
2019-01-09 18:31:11 -05:00
|
|
|
(old as usize + by_pages as usize) * LinearMemory::PAGE_SIZE as usize;
|
|
|
|
old
|
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
2019-01-10 22:59:57 -05:00
|
|
|
}
|