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},
|
2019-01-29 15:44:15 -08:00
|
|
|
units::Pages,
|
2019-01-17 13:09:05 -08:00
|
|
|
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-02-09 14:19:04 -08:00
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-16 10:26:10 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
delta: Pages,
|
2019-01-08 12:09:47 -05:00
|
|
|
) -> i32 {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx.internal.memories.add(memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
2019-05-13 05:11:08 -07:00
|
|
|
let ret = match (*memory).grow(delta, &mut *local_memory) {
|
2019-02-22 22:18:59 -08:00
|
|
|
Ok(old) => old.0 as i32,
|
|
|
|
Err(_) => -1,
|
2019-05-13 05:11:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ctx.internal.memory_base = (*local_memory).base;
|
|
|
|
ctx.internal.memory_bound = (*local_memory).bound;
|
|
|
|
|
|
|
|
ret
|
2019-01-08 12:09:47 -05:00
|
|
|
}
|
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
pub unsafe extern "C" fn local_static_memory_size(
|
2019-01-25 15:28:54 -08:00
|
|
|
ctx: &vm::Ctx,
|
2019-02-09 14:19:04 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
) -> Pages {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx.internal.memories.add(memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
2019-01-29 15:44:15 -08:00
|
|
|
(*memory).size()
|
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-02-09 14:19:04 -08:00
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-16 10:26:10 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
delta: Pages,
|
2019-01-09 18:31:11 -05:00
|
|
|
) -> i32 {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx.internal.memories.add(memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
2019-05-13 05:11:08 -07:00
|
|
|
let ret = match (*memory).grow(delta, &mut *local_memory) {
|
2019-02-22 22:18:59 -08:00
|
|
|
Ok(old) => old.0 as i32,
|
|
|
|
Err(_) => -1,
|
2019-05-13 05:11:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ctx.internal.memory_base = (*local_memory).base;
|
|
|
|
ctx.internal.memory_bound = (*local_memory).bound;
|
|
|
|
|
|
|
|
ret
|
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(
|
|
|
|
ctx: &vm::Ctx,
|
2019-02-09 14:19:04 -08:00
|
|
|
memory_index: LocalMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
) -> Pages {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx.internal.memories.add(memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
2019-01-29 15:44:15 -08:00
|
|
|
(*memory).size()
|
2019-01-25 15:28:54 -08:00
|
|
|
}
|
|
|
|
|
2019-01-17 13:09:05 -08:00
|
|
|
// +*****************************+
|
|
|
|
// | IMPORTED MEMORIES |
|
|
|
|
// +****************************+
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_static_memory_grow(
|
2019-02-09 14:19:04 -08:00
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-25 15:28:54 -08:00
|
|
|
import_memory_index: ImportedMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
delta: Pages,
|
2019-01-17 13:09:05 -08:00
|
|
|
) -> i32 {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx
|
|
|
|
.internal
|
|
|
|
.imported_memories
|
|
|
|
.add(import_memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
2019-05-13 05:11:08 -07:00
|
|
|
let ret = match (*memory).grow(delta, &mut *local_memory) {
|
2019-02-22 22:18:59 -08:00
|
|
|
Ok(old) => old.0 as i32,
|
|
|
|
Err(_) => -1,
|
2019-05-13 05:11:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ctx.internal.memory_base = (*local_memory).base;
|
|
|
|
ctx.internal.memory_bound = (*local_memory).bound;
|
|
|
|
|
|
|
|
ret
|
2019-01-17 13:09:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_static_memory_size(
|
2019-01-25 15:28:54 -08:00
|
|
|
ctx: &vm::Ctx,
|
2019-02-09 14:19:04 -08:00
|
|
|
import_memory_index: ImportedMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
) -> Pages {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx
|
|
|
|
.internal
|
|
|
|
.imported_memories
|
|
|
|
.add(import_memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut StaticMemory;
|
|
|
|
|
2019-01-29 15:44:15 -08:00
|
|
|
(*memory).size()
|
2019-01-25 15:28:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_dynamic_memory_grow(
|
2019-02-09 14:19:04 -08:00
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-25 15:28:54 -08:00
|
|
|
memory_index: ImportedMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
delta: Pages,
|
2019-01-25 15:28:54 -08:00
|
|
|
) -> i32 {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx.internal.imported_memories.add(memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
2019-05-13 05:11:08 -07:00
|
|
|
let ret = match (*memory).grow(delta, &mut *local_memory) {
|
2019-02-22 22:18:59 -08:00
|
|
|
Ok(old) => old.0 as i32,
|
|
|
|
Err(_) => -1,
|
2019-05-13 05:11:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ctx.internal.memory_base = (*local_memory).base;
|
|
|
|
ctx.internal.memory_bound = (*local_memory).bound;
|
|
|
|
|
|
|
|
ret
|
2019-01-25 15:28:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn imported_dynamic_memory_size(
|
|
|
|
ctx: &vm::Ctx,
|
2019-02-09 14:19:04 -08:00
|
|
|
memory_index: ImportedMemoryIndex,
|
2019-01-29 15:44:15 -08:00
|
|
|
) -> Pages {
|
2019-03-21 08:39:06 +08:00
|
|
|
let local_memory = *ctx.internal.imported_memories.add(memory_index.index());
|
2019-01-25 15:28:54 -08:00
|
|
|
let memory = (*local_memory).memory as *mut DynamicMemory;
|
|
|
|
|
2019-01-29 15:44:15 -08:00
|
|
|
(*memory).size()
|
2019-01-17 13:09:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// +*****************************+
|
|
|
|
// | LOCAL TABLES |
|
|
|
|
// +****************************+
|
|
|
|
|
|
|
|
pub unsafe extern "C" fn local_table_grow(
|
2019-02-09 14:19:04 -08:00
|
|
|
ctx: &mut vm::Ctx,
|
2019-01-17 13:09:05 -08:00
|
|
|
table_index: LocalTableIndex,
|
2019-01-25 15:28:54 -08:00
|
|
|
delta: u32,
|
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-02-09 14:19:04 -08:00
|
|
|
pub unsafe extern "C" fn local_table_size(ctx: &vm::Ctx, table_index: LocalTableIndex) -> u32 {
|
2019-01-17 13:09:05 -08:00
|
|
|
let _ = table_index;
|
|
|
|
let _ = ctx;
|
|
|
|
unimplemented!()
|
|
|
|
}
|