Compare commits

...

2 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
6b70f7166d
Merge 1a28133517 into b36fac9bcd 2025-09-02 09:51:20 +01:00
YAMAMOTO Takashi
1a28133517 Pass InstantiationArgs2 down to aot_instantiate/wasm_instantiate
This is a preparation for
https://github.com/bytecodealliance/wasm-micro-runtime/issues/4364

No functional changes are intended.
2025-09-02 13:56:10 +09:00
9 changed files with 61 additions and 46 deletions

View File

@ -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
@ -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);
@ -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;

View File

@ -544,10 +544,7 @@ 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
*
@ -555,8 +552,8 @@ aot_resolve_import_func(AOTModule *module, AOTImportFunc *import_func);
*/
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);
/**

View File

@ -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 *
@ -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);
}
@ -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;
}
@ -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
@ -7651,9 +7653,8 @@ delete_loading_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;
@ -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);

View File

@ -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);
@ -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 */
@ -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

View File

@ -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;
@ -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;
@ -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;

View File

@ -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

View File

@ -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);
@ -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 */

View File

@ -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(

View File

@ -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;
}