2019-01-29 10:31:44 -08:00
|
|
|
#![allow(clippy::cast_ptr_alignment)]
|
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
use crate::{
|
2019-01-25 15:28:54 -08:00
|
|
|
memory::{DynamicMemory, StaticMemory},
|
2019-01-17 13:09:05 -08:00
|
|
|
structures::TypedIndex,
|
|
|
|
types::{ImportedMemoryIndex, LocalMemoryIndex, LocalTableIndex},
|
|
|
|
vm,
|
|
|
|
};
|
2019-01-08 12:09:47 -05:00
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
// +*****************************+
|
|
|
|
// | LOCAL MEMORIES |
|
|
|
|
// +****************************+
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn local_static_memory_grow(
|
2019-01-16 10:26:10 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-25 15:28:54 -08:00
|
|
|
delta: u32,
|
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-08 12:09:47 -05:00
|
|
|
) -> i32 {
|
2019-01-25 15:28:54 -08:00
|
|
|
let local_memory = *ctx.memories.add(memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
|
|
|
if let Some(old) = (*memory).grow(delta, &mut *local_memory) {
|
|
|
|
old as i32
|
2019-01-08 12:09:47 -05:00
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
pub unsafe extern "C" fn local_static_memory_size(
|
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-25 15:28:54 -08:00
|
|
|
ctx: &vm::Ctx,
|
2019-01-17 13:09:05 -08:00
|
|
|
) -> u32 {
|
2019-01-25 15:28:54 -08:00
|
|
|
let local_memory = *ctx.memories.add(memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
|
|
|
(*memory).current()
|
2019-01-08 12:09:47 -05:00
|
|
|
}
|
2019-01-09 18:31:11 -05:00
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
pub unsafe extern "C" fn local_dynamic_memory_grow(
|
2019-01-16 10:26:10 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-25 15:28:54 -08:00
|
|
|
delta: u32,
|
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-09 18:31:11 -05:00
|
|
|
) -> i32 {
|
2019-01-25 15:28:54 -08:00
|
|
|
let local_memory = *ctx.memories.add(memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
|
|
|
if let Some(old) = (*memory).grow(delta, &mut *local_memory) {
|
|
|
|
old as i32
|
2019-01-09 18:31:11 -05:00
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
2019-01-10 22:59:57 -05:00
|
|
|
}
|
2019-01-17 13:09:05 -08:00
|
|
|
|
2019-01-25 15:28:54 -08:00
|
|
|
pub unsafe extern "C" fn local_dynamic_memory_size(
|
|
|
|
memory_index: LocalMemoryIndex,
|
|
|
|
ctx: &vm::Ctx,
|
|
|
|
) -> u32 {
|
|
|
|
let local_memory = *ctx.memories.add(memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
|
|
|
(*memory).current()
|
|
|
|
}
|
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
// +*****************************+
|
|
|
|
// | IMPORTED MEMORIES |
|
|
|
|
// +****************************+
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_static_memory_grow(
|
2019-01-25 15:28:54 -08:00
|
|
|
import_memory_index: ImportedMemoryIndex,
|
|
|
|
delta: u32,
|
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-17 13:09:05 -08:00
|
|
|
) -> i32 {
|
2019-01-25 15:28:54 -08:00
|
|
|
let local_memory = *ctx.imported_memories.add(import_memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
|
|
|
if let Some(old) = (*memory).grow(delta, &mut *local_memory) {
|
|
|
|
old as i32
|
2019-01-17 13:09:05 -08:00
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_static_memory_size(
|
2019-01-25 15:28:54 -08:00
|
|
|
import_memory_index: ImportedMemoryIndex,
|
|
|
|
ctx: &vm::Ctx,
|
2019-01-17 13:09:05 -08:00
|
|
|
) -> u32 {
|
2019-01-25 15:28:54 -08:00
|
|
|
let local_memory = *ctx.imported_memories.add(import_memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
|
|
|
(*memory).current()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_dynamic_memory_grow(
|
|
|
|
memory_index: ImportedMemoryIndex,
|
|
|
|
delta: u32,
|
|
|
|
ctx: &mut vm::Ctx,
|
|
|
|
) -> i32 {
|
|
|
|
let local_memory = *ctx.imported_memories.add(memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
|
|
|
if let Some(old) = (*memory).grow(delta, &mut *local_memory) {
|
|
|
|
old as i32
|
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_dynamic_memory_size(
|
|
|
|
memory_index: ImportedMemoryIndex,
|
|
|
|
ctx: &vm::Ctx,
|
|
|
|
) -> u32 {
|
|
|
|
let local_memory = *ctx.imported_memories.add(memory_index.index());
|
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
|
|
|
(*memory).current()
|
2019-01-17 13:09:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// +*****************************+
|
|
|
|
// | LOCAL TABLES |
|
|
|
|
// +****************************+
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn local_table_grow(
|
|
|
|
table_index: LocalTableIndex,
|
2019-01-25 15:28:54 -08:00
|
|
|
delta: u32,
|
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-17 13:09:05 -08:00
|
|
|
) -> i32 {
|
|
|
|
let _ = table_index;
|
2019-01-25 15:28:54 -08:00
|
|
|
let _ = delta;
|
2019-01-17 13:09:05 -08:00
|
|
|
let _ = ctx;
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:28:54 -08:00
|
|
|
pub unsafe extern "C" fn local_table_size(table_index: LocalTableIndex, ctx: &vm::Ctx) -> u32 {
|
2019-01-17 13:09:05 -08:00
|
|
|
let _ = table_index;
|
|
|
|
let _ = ctx;
|
|
|
|
unimplemented!()
|
|
|
|
}
|