Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,9 @@ check_linked_symbol(AOTModule *module, char *error_buf, uint32 error_buf_size)

AOTModuleInstance *
aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
uint32 max_memory_pages, char *error_buf, uint32 error_buf_size)
WASMExecEnv *exec_env_main,
const struct InstantiationArgs2 *args, char *error_buf,
uint32 error_buf_size)
{
AOTModuleInstance *module_inst;
#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_REF_TYPES != 0
Expand All @@ -1908,6 +1909,9 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
#if WASM_ENABLE_MULTI_MODULE != 0
bool ret = false;
#endif
uint32 stack_size = args->v1.default_stack_size;
uint32 heap_size = args->v1.host_managed_heap_size;
uint32 max_memory_pages = args->v1.max_memory_pages;

/* Align and validate heap size */
heap_size = align_uint(heap_size, 8);
Expand Down Expand Up @@ -1989,7 +1993,7 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,

ret = wasm_runtime_sub_module_instantiate(
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
args, error_buf, error_buf_size);
if (!ret) {
LOG_DEBUG("build a sub module list failed");
goto fail;
Expand Down
9 changes: 3 additions & 6 deletions core/iwasm/aot/aot_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,19 +544,16 @@ aot_resolve_import_func(AOTModule *module, AOTImportFunc *import_func);
*
* @param module the AOT module to instantiate
* @param parent the parent module instance
* @param heap_size the default heap size of the module instance, a heap will
* be created besides the app memory space. Both wasm app and native
* function can allocate memory from the heap. If heap_size is 0, the
* default heap size will be used.
* @param args the instantiation parameters
* @param error_buf buffer to output the error info if failed
* @param error_buf_size the size of the error buffer
*
* @return return the instantiated AOT module instance, NULL if failed
*/
AOTModuleInstance *
aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
uint32 max_memory_pages, char *error_buf,
WASMExecEnv *exec_env_main,
const struct InstantiationArgs2 *args, char *error_buf,
uint32 error_buf_size);

/**
Expand Down
48 changes: 24 additions & 24 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1623,41 +1623,45 @@ wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
WASMModuleInstanceCommon *
wasm_runtime_instantiate_internal(WASMModuleCommon *module,
WASMModuleInstanceCommon *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, uint32 max_memory_pages,
WASMExecEnv *exec_env_main,
const struct InstantiationArgs2 *args,
char *error_buf, uint32 error_buf_size)
{
#if WASM_ENABLE_INTERP != 0
if (module->module_type == Wasm_Module_Bytecode)
return (WASMModuleInstanceCommon *)wasm_instantiate(
(WASMModule *)module, (WASMModuleInstance *)parent, exec_env_main,
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
args, error_buf, error_buf_size);
#endif
#if WASM_ENABLE_AOT != 0
if (module->module_type == Wasm_Module_AoT)
return (WASMModuleInstanceCommon *)aot_instantiate(
(AOTModule *)module, (AOTModuleInstance *)parent, exec_env_main,
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
args, error_buf, error_buf_size);
#endif
set_error_buf(error_buf, error_buf_size,
"Instantiate module failed, invalid module type");
return NULL;
}

void
wasm_runtime_instantiation_args_set_defaults(struct InstantiationArgs2 *args)
{
memset(args, 0, sizeof(*args));
}

WASMModuleInstanceCommon *
wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size,
uint32 heap_size, char *error_buf,
uint32 error_buf_size)
{
return wasm_runtime_instantiate_internal(module, NULL, NULL, stack_size,
heap_size, 0, error_buf,
error_buf_size);
}

static void
instantiation_args_set_defaults(struct InstantiationArgs2 *args)
{
memset(args, 0, sizeof(*args));
struct InstantiationArgs2 args;
wasm_runtime_instantiation_args_set_defaults(&args);
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
wasm_runtime_instantiation_args_set_host_managed_heap_size(&args,
heap_size);
return wasm_runtime_instantiate_internal(module, NULL, NULL, &args,
error_buf, error_buf_size);
}

WASMModuleInstanceCommon *
Expand All @@ -1666,7 +1670,7 @@ wasm_runtime_instantiate_ex(WASMModuleCommon *module,
uint32 error_buf_size)
{
struct InstantiationArgs2 v2;
instantiation_args_set_defaults(&v2);
wasm_runtime_instantiation_args_set_defaults(&v2);
v2.v1 = *args;
return wasm_runtime_instantiate_ex2(module, &v2, error_buf, error_buf_size);
}
Expand All @@ -1678,7 +1682,7 @@ wasm_runtime_instantiation_args_create(struct InstantiationArgs2 **p)
if (args == NULL) {
return false;
}
instantiation_args_set_defaults(args);
wasm_runtime_instantiation_args_set_defaults(args);
*p = args;
return true;
}
Expand Down Expand Up @@ -1715,10 +1719,8 @@ wasm_runtime_instantiate_ex2(WASMModuleCommon *module,
const struct InstantiationArgs2 *args,
char *error_buf, uint32 error_buf_size)
{
return wasm_runtime_instantiate_internal(
module, NULL, NULL, args->v1.default_stack_size,
args->v1.host_managed_heap_size, args->v1.max_memory_pages, error_buf,
error_buf_size);
return wasm_runtime_instantiate_internal(module, NULL, NULL, args,
error_buf, error_buf_size);
}

void
Expand Down Expand Up @@ -7651,9 +7653,8 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
bool
wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
WASMModuleInstanceCommon *module_inst,
uint32 stack_size, uint32 heap_size,
uint32 max_memory_pages, char *error_buf,
uint32 error_buf_size)
const struct InstantiationArgs2 *args,
char *error_buf, uint32 error_buf_size)
{
bh_list *sub_module_inst_list = NULL;
WASMRegisteredModule *sub_module_list_node = NULL;
Expand Down Expand Up @@ -7681,8 +7682,7 @@ wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
WASMModuleCommon *sub_module = sub_module_list_node->module;
WASMModuleInstanceCommon *sub_module_inst = NULL;
sub_module_inst = wasm_runtime_instantiate_internal(
sub_module, NULL, NULL, stack_size, heap_size, max_memory_pages,
error_buf, error_buf_size);
sub_module, NULL, NULL, args, error_buf, error_buf_size);
if (!sub_module_inst) {
LOG_DEBUG("instantiate %s failed",
sub_module_list_node->module_name);
Expand Down
12 changes: 7 additions & 5 deletions core/iwasm/common/wasm_runtime_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ struct InstantiationArgs2 {
InstantiationArgs v1;
};

void
wasm_runtime_instantiation_args_set_defaults(struct InstantiationArgs2 *args);

/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_init(void);
Expand Down Expand Up @@ -683,8 +686,8 @@ wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
WASMModuleInstanceCommon *
wasm_runtime_instantiate_internal(WASMModuleCommon *module,
WASMModuleInstanceCommon *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, uint32 max_memory_pages,
WASMExecEnv *exec_env_main,
const struct InstantiationArgs2 *args,
char *error_buf, uint32 error_buf_size);

/* Internal API */
Expand Down Expand Up @@ -1064,9 +1067,8 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
bool
wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
WASMModuleInstanceCommon *module_inst,
uint32 stack_size, uint32 heap_size,
uint32 max_memory_pages, char *error_buf,
uint32 error_buf_size);
const struct InstantiationArgs2 *args,
char *error_buf, uint32 error_buf_size);
void
wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
#endif
Expand Down
9 changes: 6 additions & 3 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2421,8 +2421,8 @@ wasm_set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode)
*/
WASMModuleInstance *
wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, uint32 max_memory_pages, char *error_buf,
WASMExecEnv *exec_env_main,
const struct InstantiationArgs2 *args, char *error_buf,
uint32 error_buf_size)
{
WASMModuleInstance *module_inst;
Expand All @@ -2440,6 +2440,9 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
bool ret = false;
#endif
const bool is_sub_inst = parent != NULL;
uint32 stack_size = args->v1.default_stack_size;
uint32 heap_size = args->v1.host_managed_heap_size;
uint32 max_memory_pages = args->v1.max_memory_pages;

if (!module)
return NULL;
Expand Down Expand Up @@ -2515,7 +2518,7 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
&module_inst->e->sub_module_inst_list_head;
ret = wasm_runtime_sub_module_instantiate(
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
args, error_buf, error_buf_size);
if (!ret) {
LOG_DEBUG("build a sub module list failed");
goto fail;
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/interpreter/wasm_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ wasm_resolve_import_func(const WASMModule *module,

WASMModuleInstance *
wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, uint32 max_memory_pages, char *error_buf,
WASMExecEnv *exec_env_main,
const struct InstantiationArgs2 *args, char *error_buf,
uint32 error_buf_size);

void
Expand Down
5 changes: 4 additions & 1 deletion core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
uint32 aux_stack_size;
uint64 aux_stack_start = 0;
int32 ret = -1;
struct InstantiationArgs2 args;

bh_assert(module);
bh_assert(module_inst);
Expand All @@ -579,8 +580,10 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
}
#endif

wasm_runtime_instantiation_args_set_defaults(&args);
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
if (!(new_module_inst = wasm_runtime_instantiate_internal(
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0)))
module, module_inst, exec_env, &args, NULL, 0)))
return -1;

/* Set custom_data to new module instance */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
int32 thread_id;
uint32 stack_size = 8192;
int32 ret = -1;
struct InstantiationArgs2 args;

bh_assert(module);
bh_assert(module_inst);

stack_size = ((WASMModuleInstance *)module_inst)->default_wasm_stack_size;

wasm_runtime_instantiation_args_set_defaults(&args);
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
if (!(new_module_inst = wasm_runtime_instantiate_internal(
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0)))
module, module_inst, exec_env, &args, NULL, 0)))
return -1;

wasm_runtime_set_custom_data_internal(
Expand Down
5 changes: 4 additions & 1 deletion core/iwasm/libraries/thread-mgr/thread_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,16 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
uint32 aux_stack_size;
uint64 aux_stack_start;
uint32 stack_size = 8192;
struct InstantiationArgs2 args;

if (!module_inst || !(module = wasm_exec_env_get_module(exec_env))) {
return NULL;
}

wasm_runtime_instantiation_args_set_defaults(&args);
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
if (!(new_module_inst = wasm_runtime_instantiate_internal(
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0))) {
module, module_inst, exec_env, &args, NULL, 0))) {
return NULL;
}

Expand Down
Loading