mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-20 20:26:32 +00:00
Fix emscripten table assertion panic
This commit is contained in:
@ -436,7 +436,7 @@ pub struct EmscriptenGlobals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EmscriptenGlobals {
|
impl EmscriptenGlobals {
|
||||||
pub fn new(module: &Module /*, static_bump: u32 */) -> Self {
|
pub fn new(module: &Module /*, static_bump: u32 */) -> Result<Self, String> {
|
||||||
let mut use_old_abort_on_cannot_grow_memory = false;
|
let mut use_old_abort_on_cannot_grow_memory = false;
|
||||||
for (
|
for (
|
||||||
index,
|
index,
|
||||||
@ -458,7 +458,7 @@ impl EmscriptenGlobals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (table_min, table_max) = get_emscripten_table_size(&module);
|
let (table_min, table_max) = get_emscripten_table_size(&module)?;
|
||||||
let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module);
|
let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module);
|
||||||
|
|
||||||
// Memory initialization
|
// Memory initialization
|
||||||
@ -530,14 +530,14 @@ impl EmscriptenGlobals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
data,
|
data,
|
||||||
memory,
|
memory,
|
||||||
table,
|
table,
|
||||||
memory_min,
|
memory_min,
|
||||||
memory_max,
|
memory_max,
|
||||||
null_func_names,
|
null_func_names,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,13 +33,12 @@ pub fn is_emscripten_module(module: &Module) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_emscripten_table_size(module: &Module) -> (u32, Option<u32>) {
|
pub fn get_emscripten_table_size(module: &Module) -> Result<(u32, Option<u32>), String> {
|
||||||
assert!(
|
if module.info().imported_tables.len() == 0 {
|
||||||
module.info().imported_tables.len() > 0,
|
return Err("Emscripten requires at least one imported table".to_string());
|
||||||
"Emscripten requires at least one imported table"
|
}
|
||||||
);
|
|
||||||
let (_, table) = &module.info().imported_tables[ImportedTableIndex::new(0)];
|
let (_, table) = &module.info().imported_tables[ImportedTableIndex::new(0)];
|
||||||
(table.minimum, table.maximum)
|
Ok((table.minimum, table.maximum))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_emscripten_memory_size(module: &Module) -> (Pages, Option<Pages>, bool) {
|
pub fn get_emscripten_memory_size(module: &Module) -> (Pages, Option<Pages>, bool) {
|
||||||
|
@ -544,7 +544,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
|
|
||||||
// TODO: refactor this
|
// TODO: refactor this
|
||||||
if wasmer_emscripten::is_emscripten_module(&module) {
|
if wasmer_emscripten::is_emscripten_module(&module) {
|
||||||
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module);
|
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module)?;
|
||||||
let import_object = wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals);
|
let import_object = wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals);
|
||||||
let mut instance = module
|
let mut instance = module
|
||||||
.instantiate(&import_object)
|
.instantiate(&import_object)
|
||||||
|
Reference in New Issue
Block a user