Skip to content

Commit 1a28133

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 1a28133

File tree

9 files changed

+61
-46
lines changed

9 files changed

+61
-46
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: 24 additions & 24 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+
void
1648+
wasm_runtime_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+
wasm_runtime_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 *
@@ -1666,7 +1670,7 @@ wasm_runtime_instantiate_ex(WASMModuleCommon *module,
16661670
uint32 error_buf_size)
16671671
{
16681672
struct InstantiationArgs2 v2;
1669-
instantiation_args_set_defaults(&v2);
1673+
wasm_runtime_instantiation_args_set_defaults(&v2);
16701674
v2.v1 = *args;
16711675
return wasm_runtime_instantiate_ex2(module, &v2, error_buf, error_buf_size);
16721676
}
@@ -1678,7 +1682,7 @@ wasm_runtime_instantiation_args_create(struct InstantiationArgs2 **p)
16781682
if (args == NULL) {
16791683
return false;
16801684
}
1681-
instantiation_args_set_defaults(args);
1685+
wasm_runtime_instantiation_args_set_defaults(args);
16821686
*p = args;
16831687
return true;
16841688
}
@@ -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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ struct InstantiationArgs2 {
616616
InstantiationArgs v1;
617617
};
618618

619+
void
620+
wasm_runtime_instantiation_args_set_defaults(struct InstantiationArgs2 *args);
621+
619622
/* See wasm_export.h for description */
620623
WASM_RUNTIME_API_EXTERN bool
621624
wasm_runtime_init(void);
@@ -683,8 +686,8 @@ wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
683686
WASMModuleInstanceCommon *
684687
wasm_runtime_instantiate_internal(WASMModuleCommon *module,
685688
WASMModuleInstanceCommon *parent,
686-
WASMExecEnv *exec_env_main, uint32 stack_size,
687-
uint32 heap_size, uint32 max_memory_pages,
689+
WASMExecEnv *exec_env_main,
690+
const struct InstantiationArgs2 *args,
688691
char *error_buf, uint32 error_buf_size);
689692

690693
/* Internal API */
@@ -1064,9 +1067,8 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
10641067
bool
10651068
wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
10661069
WASMModuleInstanceCommon *module_inst,
1067-
uint32 stack_size, uint32 heap_size,
1068-
uint32 max_memory_pages, char *error_buf,
1069-
uint32 error_buf_size);
1070+
const struct InstantiationArgs2 *args,
1071+
char *error_buf, uint32 error_buf_size);
10701072
void
10711073
wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
10721074
#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

core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
561561
uint32 aux_stack_size;
562562
uint64 aux_stack_start = 0;
563563
int32 ret = -1;
564+
struct InstantiationArgs2 args;
564565

565566
bh_assert(module);
566567
bh_assert(module_inst);
@@ -579,8 +580,10 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
579580
}
580581
#endif
581582

583+
wasm_runtime_instantiation_args_set_defaults(&args);
584+
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
582585
if (!(new_module_inst = wasm_runtime_instantiate_internal(
583-
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0)))
586+
module, module_inst, exec_env, &args, NULL, 0)))
584587
return -1;
585588

586589
/* Set custom_data to new module instance */

core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,17 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
8080
int32 thread_id;
8181
uint32 stack_size = 8192;
8282
int32 ret = -1;
83+
struct InstantiationArgs2 args;
8384

8485
bh_assert(module);
8586
bh_assert(module_inst);
8687

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

90+
wasm_runtime_instantiation_args_set_defaults(&args);
91+
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
8992
if (!(new_module_inst = wasm_runtime_instantiate_internal(
90-
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0)))
93+
module, module_inst, exec_env, &args, NULL, 0)))
9194
return -1;
9295

9396
wasm_runtime_set_custom_data_internal(

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,16 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
501501
uint32 aux_stack_size;
502502
uint64 aux_stack_start;
503503
uint32 stack_size = 8192;
504+
struct InstantiationArgs2 args;
504505

505506
if (!module_inst || !(module = wasm_exec_env_get_module(exec_env))) {
506507
return NULL;
507508
}
508509

510+
wasm_runtime_instantiation_args_set_defaults(&args);
511+
wasm_runtime_instantiation_args_set_default_stack_size(&args, stack_size);
509512
if (!(new_module_inst = wasm_runtime_instantiate_internal(
510-
module, module_inst, exec_env, stack_size, 0, 0, NULL, 0))) {
513+
module, module_inst, exec_env, &args, NULL, 0))) {
511514
return NULL;
512515
}
513516

0 commit comments

Comments
 (0)