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:
@ -186,6 +186,16 @@ struct wasm_config_t {
|
||||
/*TODO: wasi args*/
|
||||
};
|
||||
|
||||
#ifndef INSTANTIATION_ARGS_OPTION_DEFINED
|
||||
#define INSTANTIATION_ARGS_OPTION_DEFINED
|
||||
/* WASM module instantiation arguments */
|
||||
typedef struct InstantiationArgs {
|
||||
uint32_t default_stack_size;
|
||||
uint32_t host_managed_heap_size;
|
||||
uint32_t max_memory_pages;
|
||||
} InstantiationArgs;
|
||||
#endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
|
||||
|
||||
/*
|
||||
* by default:
|
||||
* - mem_alloc_type is Alloc_With_System_Allocator
|
||||
@ -644,6 +654,12 @@ WASM_API_EXTERN own wasm_instance_t* wasm_instance_new_with_args(
|
||||
own wasm_trap_t** trap, const uint32_t stack_size, const uint32_t heap_size
|
||||
);
|
||||
|
||||
// please refer to wasm_runtime_instantiate_ex(...) in core/iwasm/include/wasm_export.h
|
||||
WASM_API_EXTERN own wasm_instance_t* wasm_instance_new_with_args_ex(
|
||||
wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t *imports,
|
||||
own wasm_trap_t** trap, const InstantiationArgs *inst_args
|
||||
);
|
||||
|
||||
WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);
|
||||
|
||||
|
||||
|
||||
@ -183,6 +183,16 @@ typedef struct RuntimeInitArgs {
|
||||
bool enable_linux_perf;
|
||||
} RuntimeInitArgs;
|
||||
|
||||
#ifndef INSTANTIATION_ARGS_OPTION_DEFINED
|
||||
#define INSTANTIATION_ARGS_OPTION_DEFINED
|
||||
/* WASM module instantiation arguments */
|
||||
typedef struct InstantiationArgs {
|
||||
uint32_t default_stack_size;
|
||||
uint32_t host_managed_heap_size;
|
||||
uint32_t max_memory_pages;
|
||||
} InstantiationArgs;
|
||||
#endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
|
||||
|
||||
#ifndef WASM_VALKIND_T_DEFINED
|
||||
#define WASM_VALKIND_T_DEFINED
|
||||
typedef uint8_t wasm_valkind_t;
|
||||
@ -527,6 +537,16 @@ wasm_runtime_instantiate(const wasm_module_t module,
|
||||
uint32_t default_stack_size, uint32_t host_managed_heap_size,
|
||||
char *error_buf, uint32_t error_buf_size);
|
||||
|
||||
/**
|
||||
* Instantiate a WASM module, with specified instantiation arguments
|
||||
*
|
||||
* Same as wasm_runtime_instantiate, but it also allows overwriting maximum memory
|
||||
*/
|
||||
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
|
||||
wasm_runtime_instantiate_ex(const wasm_module_t module,
|
||||
const InstantiationArgs *args,
|
||||
char *error_buf, uint32_t error_buf_size);
|
||||
|
||||
/**
|
||||
* Set the running mode of a WASM module instance, override the
|
||||
* default running mode of the runtime. Note that it only makes sense when
|
||||
|
||||
Reference in New Issue
Block a user