Skip to content

Commit 1202c65

Browse files
committed
Pass InstantiationArgs2 down to aot_instantiate/wasm_instantiate
This is a preparation for #4364 No functional changes are intended.
1 parent 6c3f6fd commit 1202c65

File tree

6 files changed

+44
-41
lines changed

6 files changed

+44
-41
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,9 @@ check_linked_symbol(AOTModule *module, char *error_buf, uint32 error_buf_size)
18891889

18901890
AOTModuleInstance *
18911891
aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
1892-
WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
1893-
uint32 max_memory_pages, char *error_buf, uint32 error_buf_size)
1892+
WASMExecEnv *exec_env_main,
1893+
const struct InstantiationArgs2 *args, char *error_buf,
1894+
uint32 error_buf_size)
18941895
{
18951896
AOTModuleInstance *module_inst;
18961897
#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_REF_TYPES != 0
@@ -1908,6 +1909,9 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
19081909
#if WASM_ENABLE_MULTI_MODULE != 0
19091910
bool ret = false;
19101911
#endif
1912+
uint32 stack_size = args->v1.default_stack_size;
1913+
uint32 heap_size = args->v1.host_managed_heap_size;
1914+
uint32 max_memory_pages = args->v1.max_memory_pages;
19111915

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

19901994
ret = wasm_runtime_sub_module_instantiate(
19911995
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
1992-
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
1996+
args, error_buf, error_buf_size);
19931997
if (!ret) {
19941998
LOG_DEBUG("build a sub module list failed");
19951999
goto fail;

core/iwasm/aot/aot_runtime.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,16 @@ aot_resolve_import_func(AOTModule *module, AOTImportFunc *import_func);
544544
*
545545
* @param module the AOT module to instantiate
546546
* @param parent the parent module instance
547-
* @param heap_size the default heap size of the module instance, a heap will
548-
* be created besides the app memory space. Both wasm app and native
549-
* function can allocate memory from the heap. If heap_size is 0, the
550-
* default heap size will be used.
547+
* @param args the instantiation parameters
551548
* @param error_buf buffer to output the error info if failed
552549
* @param error_buf_size the size of the error buffer
553550
*
554551
* @return return the instantiated AOT module instance, NULL if failed
555552
*/
556553
AOTModuleInstance *
557554
aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
558-
WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
559-
uint32 max_memory_pages, char *error_buf,
555+
WASMExecEnv *exec_env_main,
556+
const struct InstantiationArgs2 *args, char *error_buf,
560557
uint32 error_buf_size);
561558

562559
/**

core/iwasm/common/wasm_runtime_common.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,41 +1623,45 @@ wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
16231623
WASMModuleInstanceCommon *
16241624
wasm_runtime_instantiate_internal(WASMModuleCommon *module,
16251625
WASMModuleInstanceCommon *parent,
1626-
WASMExecEnv *exec_env_main, uint32 stack_size,
1627-
uint32 heap_size, uint32 max_memory_pages,
1626+
WASMExecEnv *exec_env_main,
1627+
const struct InstantiationArgs2 *args,
16281628
char *error_buf, uint32 error_buf_size)
16291629
{
16301630
#if WASM_ENABLE_INTERP != 0
16311631
if (module->module_type == Wasm_Module_Bytecode)
16321632
return (WASMModuleInstanceCommon *)wasm_instantiate(
16331633
(WASMModule *)module, (WASMModuleInstance *)parent, exec_env_main,
1634-
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
1634+
args, error_buf, error_buf_size);
16351635
#endif
16361636
#if WASM_ENABLE_AOT != 0
16371637
if (module->module_type == Wasm_Module_AoT)
16381638
return (WASMModuleInstanceCommon *)aot_instantiate(
16391639
(AOTModule *)module, (AOTModuleInstance *)parent, exec_env_main,
1640-
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
1640+
args, error_buf, error_buf_size);
16411641
#endif
16421642
set_error_buf(error_buf, error_buf_size,
16431643
"Instantiate module failed, invalid module type");
16441644
return NULL;
16451645
}
16461646

1647+
static void
1648+
instantiation_args_set_defaults(struct InstantiationArgs2 *args)
1649+
{
1650+
memset(args, 0, sizeof(*args));
1651+
}
1652+
16471653
WASMModuleInstanceCommon *
16481654
wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size,
16491655
uint32 heap_size, char *error_buf,
16501656
uint32 error_buf_size)
16511657
{
1652-
return wasm_runtime_instantiate_internal(module, NULL, NULL, stack_size,
1653-
heap_size, 0, error_buf,
1654-
error_buf_size);
1655-
}
1656-
1657-
static void
1658-
instantiation_args_set_defaults(struct InstantiationArgs2 *args)
1659-
{
1660-
memset(args, 0, sizeof(*args));
1658+
struct InstantiationArgs2 args;
1659+
instantiation_args_set_defaults(&args);
1660+
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
1661+
wasm_runtime_instantiation_args_set_host_managed_heap_size(&args,
1662+
heap_size);
1663+
return wasm_runtime_instantiate_internal(module, NULL, NULL, &args,
1664+
error_buf, error_buf_size);
16611665
}
16621666

16631667
WASMModuleInstanceCommon *
@@ -1715,10 +1719,8 @@ wasm_runtime_instantiate_ex2(WASMModuleCommon *module,
17151719
const struct InstantiationArgs2 *args,
17161720
char *error_buf, uint32 error_buf_size)
17171721
{
1718-
return wasm_runtime_instantiate_internal(
1719-
module, NULL, NULL, args->v1.default_stack_size,
1720-
args->v1.host_managed_heap_size, args->v1.max_memory_pages, error_buf,
1721-
error_buf_size);
1722+
return wasm_runtime_instantiate_internal(module, NULL, NULL, args,
1723+
error_buf, error_buf_size);
17221724
}
17231725

17241726
void
@@ -7651,9 +7653,8 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
76517653
bool
76527654
wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
76537655
WASMModuleInstanceCommon *module_inst,
7654-
uint32 stack_size, uint32 heap_size,
7655-
uint32 max_memory_pages, char *error_buf,
7656-
uint32 error_buf_size)
7656+
const struct InstantiationArgs2 *args,
7657+
char *error_buf, uint32 error_buf_size)
76577658
{
76587659
bh_list *sub_module_inst_list = NULL;
76597660
WASMRegisteredModule *sub_module_list_node = NULL;
@@ -7681,8 +7682,7 @@ wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
76817682
WASMModuleCommon *sub_module = sub_module_list_node->module;
76827683
WASMModuleInstanceCommon *sub_module_inst = NULL;
76837684
sub_module_inst = wasm_runtime_instantiate_internal(
7684-
sub_module, NULL, NULL, stack_size, heap_size, max_memory_pages,
7685-
error_buf, error_buf_size);
7685+
sub_module, NULL, NULL, args, error_buf, error_buf_size);
76867686
if (!sub_module_inst) {
76877687
LOG_DEBUG("instantiate %s failed",
76887688
sub_module_list_node->module_name);

core/iwasm/common/wasm_runtime_common.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
683683
WASMModuleInstanceCommon *
684684
wasm_runtime_instantiate_internal(WASMModuleCommon *module,
685685
WASMModuleInstanceCommon *parent,
686-
WASMExecEnv *exec_env_main, uint32 stack_size,
687-
uint32 heap_size, uint32 max_memory_pages,
686+
WASMExecEnv *exec_env_main,
687+
const struct InstantiationArgs2 *args,
688688
char *error_buf, uint32 error_buf_size);
689689

690690
/* Internal API */
@@ -1064,9 +1064,8 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
10641064
bool
10651065
wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
10661066
WASMModuleInstanceCommon *module_inst,
1067-
uint32 stack_size, uint32 heap_size,
1068-
uint32 max_memory_pages, char *error_buf,
1069-
uint32 error_buf_size);
1067+
const struct InstantiationArgs2 *args,
1068+
char *error_buf, uint32 error_buf_size);
10701069
void
10711070
wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
10721071
#endif

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,8 +2421,8 @@ wasm_set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode)
24212421
*/
24222422
WASMModuleInstance *
24232423
wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
2424-
WASMExecEnv *exec_env_main, uint32 stack_size,
2425-
uint32 heap_size, uint32 max_memory_pages, char *error_buf,
2424+
WASMExecEnv *exec_env_main,
2425+
const struct InstantiationArgs2 *args, char *error_buf,
24262426
uint32 error_buf_size)
24272427
{
24282428
WASMModuleInstance *module_inst;
@@ -2440,6 +2440,9 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
24402440
bool ret = false;
24412441
#endif
24422442
const bool is_sub_inst = parent != NULL;
2443+
uint32 stack_size = args->v1.default_stack_size;
2444+
uint32 heap_size = args->v1.host_managed_heap_size;
2445+
uint32 max_memory_pages = args->v1.max_memory_pages;
24432446

24442447
if (!module)
24452448
return NULL;
@@ -2515,7 +2518,7 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
25152518
&module_inst->e->sub_module_inst_list_head;
25162519
ret = wasm_runtime_sub_module_instantiate(
25172520
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
2518-
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
2521+
args, error_buf, error_buf_size);
25192522
if (!ret) {
25202523
LOG_DEBUG("build a sub module list failed");
25212524
goto fail;

core/iwasm/interpreter/wasm_runtime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ wasm_resolve_import_func(const WASMModule *module,
553553

554554
WASMModuleInstance *
555555
wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
556-
WASMExecEnv *exec_env_main, uint32 stack_size,
557-
uint32 heap_size, uint32 max_memory_pages, char *error_buf,
556+
WASMExecEnv *exec_env_main,
557+
const struct InstantiationArgs2 *args, char *error_buf,
558558
uint32 error_buf_size);
559559

560560
void

0 commit comments

Comments
 (0)