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

This commit is contained in:
Brandon Fish
2019-01-25 19:55:33 -06:00
parent 5209b5a558
commit 1a1958a0ce
4 changed files with 25 additions and 10 deletions

View File

@ -5,7 +5,9 @@ use std::ffi::CStr;
use std::mem::size_of;
use std::os::raw::c_char;
use std::slice;
use wasmer_runtime_core::{module::Module, vm::Ctx};
use wasmer_runtime_core::{
module::Module, structures::TypedIndex, types::ImportedTableIndex, vm::Ctx,
};
/// We check if a provided module is an Emscripten generated one
pub fn is_emscripten_module(module: &Module) -> bool {
@ -17,6 +19,11 @@ pub fn is_emscripten_module(module: &Module) -> bool {
false
}
pub fn get_emscripten_table_size(module: &Module) -> (u32, Option<u32>) {
let (_, table) = &module.0.imported_tables[ImportedTableIndex::new(0)];
(table.min, table.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;