Use memory min and max values from module to generate environment memory

This commit is contained in:
Brandon Fish
2019-01-25 20:12:36 -06:00
parent 1a1958a0ce
commit ee911092ea
4 changed files with 29 additions and 9 deletions

View File

@ -6,7 +6,10 @@ use std::mem::size_of;
use std::os::raw::c_char;
use std::slice;
use wasmer_runtime_core::{
module::Module, structures::TypedIndex, types::ImportedTableIndex, vm::Ctx,
module::Module,
structures::TypedIndex,
types::{ImportedMemoryIndex, ImportedTableIndex},
vm::Ctx,
};
/// We check if a provided module is an Emscripten generated one
@ -24,6 +27,11 @@ pub fn get_emscripten_table_size(module: &Module) -> (u32, Option<u32>) {
(table.min, table.max)
}
pub fn get_emscripten_memory_size(module: &Module) -> (u32, Option<u32>) {
let (_, memory) = &module.0.imported_memories[ImportedMemoryIndex::new(0)];
(memory.min, memory.max)
}
pub unsafe fn write_to_buf(string: *const c_char, buf: u32, max: u32, ctx: &mut Ctx) -> u32 {
let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut c_char;