mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 21:21:33 +00:00
Use memory min and max values from module to generate environment memory
This commit is contained in:
@ -52,7 +52,8 @@ mod varargs;
|
|||||||
|
|
||||||
pub use self::storage::align_memory;
|
pub use self::storage::align_memory;
|
||||||
pub use self::utils::{
|
pub use self::utils::{
|
||||||
allocate_cstr_on_stack, allocate_on_stack, get_emscripten_table_size, is_emscripten_module,
|
allocate_cstr_on_stack, allocate_on_stack, get_emscripten_memory_size,
|
||||||
|
get_emscripten_table_size, is_emscripten_module,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Magic number - how is this calculated?
|
// TODO: Magic number - how is this calculated?
|
||||||
@ -365,14 +366,21 @@ pub struct EmscriptenGlobals {
|
|||||||
pub vm_table: LocalTable,
|
pub vm_table: LocalTable,
|
||||||
pub table_min: u32,
|
pub table_min: u32,
|
||||||
pub table_max: Option<u32>,
|
pub table_max: Option<u32>,
|
||||||
|
pub memory_min: u32,
|
||||||
|
pub memory_max: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmscriptenGlobals {
|
impl EmscriptenGlobals {
|
||||||
pub fn new(table_min: u32, table_max: Option<u32>) -> Self {
|
pub fn new(
|
||||||
|
table_min: u32,
|
||||||
|
table_max: Option<u32>,
|
||||||
|
memory_min: u32,
|
||||||
|
memory_max: Option<u32>,
|
||||||
|
) -> Self {
|
||||||
// Memory initialization
|
// Memory initialization
|
||||||
let memory_type = Memory {
|
let memory_type = Memory {
|
||||||
min: 256,
|
min: memory_min,
|
||||||
max: Some(256),
|
max: memory_max,
|
||||||
shared: false,
|
shared: false,
|
||||||
};
|
};
|
||||||
let mut memory = LinearMemory::new(&memory_type);
|
let mut memory = LinearMemory::new(&memory_type);
|
||||||
@ -412,6 +420,8 @@ impl EmscriptenGlobals {
|
|||||||
vm_table,
|
vm_table,
|
||||||
table_min,
|
table_min,
|
||||||
table_max,
|
table_max,
|
||||||
|
memory_min,
|
||||||
|
memory_max,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,8 +448,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
|||||||
local: local_memory,
|
local: local_memory,
|
||||||
ctx: null_ctx,
|
ctx: null_ctx,
|
||||||
memory: Memory {
|
memory: Memory {
|
||||||
min: 256,
|
min: globals.memory_min,
|
||||||
max: Some(256),
|
max: globals.memory_max,
|
||||||
shared: false,
|
shared: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -6,7 +6,10 @@ use std::mem::size_of;
|
|||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use wasmer_runtime_core::{
|
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
|
/// 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)
|
(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 {
|
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;
|
let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut c_char;
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ macro_rules! assert_emscripten_output {
|
|||||||
// let module = compile(&wasm_bytes[..])
|
// let module = compile(&wasm_bytes[..])
|
||||||
// .map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ??
|
// .map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ??
|
||||||
let (table_min, table_max) = wasmer_emscripten::get_emscripten_table_size(&module);
|
let (table_min, table_max) = wasmer_emscripten::get_emscripten_table_size(&module);
|
||||||
let mut emscripten_globals = EmscriptenGlobals::new(table_min, table_max);
|
let (memory_min, memory_max) = wasmer_emscripten::get_emscripten_memory_size(&module);
|
||||||
|
let mut emscripten_globals = EmscriptenGlobals::new(table_min, table_max, memory_min, memory_max);
|
||||||
let import_object = generate_emscripten_env(&mut emscripten_globals);
|
let import_object = generate_emscripten_env(&mut emscripten_globals);
|
||||||
|
|
||||||
let mut instance = module.instantiate(import_object)
|
let mut instance = module.instantiate(import_object)
|
||||||
|
@ -71,8 +71,9 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
|
|
||||||
let (_abi, import_object) = if wasmer_emscripten::is_emscripten_module(&module) {
|
let (_abi, import_object) = if wasmer_emscripten::is_emscripten_module(&module) {
|
||||||
let (table_min, table_max) = wasmer_emscripten::get_emscripten_table_size(&module);
|
let (table_min, table_max) = wasmer_emscripten::get_emscripten_table_size(&module);
|
||||||
|
let (memory_min, memory_max) = wasmer_emscripten::get_emscripten_memory_size(&module);
|
||||||
let mut emscripten_globals =
|
let mut emscripten_globals =
|
||||||
wasmer_emscripten::EmscriptenGlobals::new(table_min, table_max);
|
wasmer_emscripten::EmscriptenGlobals::new(table_min, table_max, memory_min, memory_max);
|
||||||
(
|
(
|
||||||
InstanceABI::Emscripten,
|
InstanceABI::Emscripten,
|
||||||
wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals),
|
wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals),
|
||||||
|
Reference in New Issue
Block a user