Allow overriding max memory on module instantiation (#3198)
This PR adds a max_memory_pages parameter to module instantiation APIs, to allow overriding the max memory defined in the WASM module. Sticking to the max memory defined in the module is quite limiting when using shared memory in production. If targeted devices have different memory constraints, many wasm files have to be generated with different max memory values. And device constraints may not be known in advance. Being able to set the max memory value during module instantiation allows to reuse the same wasm module, e.g. by retrying instantiation with different max memory value.
This commit is contained in:
@ -4872,6 +4872,19 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
|
||||
const wasm_extern_vec_t *imports,
|
||||
own wasm_trap_t **trap, const uint32 stack_size,
|
||||
const uint32 heap_size)
|
||||
{
|
||||
InstantiationArgs inst_args = { 0 };
|
||||
inst_args.default_stack_size = stack_size;
|
||||
inst_args.host_managed_heap_size = heap_size;
|
||||
return wasm_instance_new_with_args_ex(store, module, imports, trap,
|
||||
&inst_args);
|
||||
}
|
||||
|
||||
wasm_instance_t *
|
||||
wasm_instance_new_with_args_ex(wasm_store_t *store, const wasm_module_t *module,
|
||||
const wasm_extern_vec_t *imports,
|
||||
own wasm_trap_t **trap,
|
||||
const InstantiationArgs *inst_args)
|
||||
{
|
||||
char sub_error_buf[128] = { 0 };
|
||||
char error_buf[256] = { 0 };
|
||||
@ -4911,8 +4924,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
|
||||
* will do the linking result check at the end of wasm_runtime_instantiate
|
||||
*/
|
||||
|
||||
instance->inst_comm_rt = wasm_runtime_instantiate(
|
||||
*module, stack_size, heap_size, sub_error_buf, sizeof(sub_error_buf));
|
||||
instance->inst_comm_rt = wasm_runtime_instantiate_ex(
|
||||
*module, inst_args, sub_error_buf, sizeof(sub_error_buf));
|
||||
if (!instance->inst_comm_rt) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user