mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-13 07:48:17 +00:00
Compare commits
3 Commits
c0a7d40510
...
ba0eb0b388
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ba0eb0b388 | ||
![]() |
b519dd976a | ||
![]() |
01f49f45d0 |
|
@ -1152,63 +1152,29 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module,
|
||||||
char *error_buf, uint32 error_buf_size)
|
char *error_buf, uint32 error_buf_size)
|
||||||
{
|
{
|
||||||
uint32 i;
|
uint32 i;
|
||||||
AOTImportFunc *import_func;
|
|
||||||
void **func_ptrs;
|
void **func_ptrs;
|
||||||
uint64 total_size = ((uint64)module->import_func_count + module->func_count)
|
uint64 total_size = ((uint64)module->import_func_count + module->func_count)
|
||||||
* sizeof(void *);
|
* sizeof(void *);
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
||||||
char *ptr;
|
|
||||||
AOTModuleInstanceExtra *extra;
|
|
||||||
bh_list *sub_module_list_node = NULL;
|
|
||||||
const char *sub_inst_name = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (module->import_func_count + module->func_count == 0)
|
if (module->import_func_count + module->func_count == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
||||||
if (!(ptr = runtime_malloc(total_size * 2, error_buf, error_buf_size))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
module_inst->func_ptrs = (void **)ptr;
|
|
||||||
extra = (AOTModuleInstanceExtra *)module_inst->e;
|
|
||||||
extra->func_module_insts = (WASMModuleInstanceCommon **)(ptr + total_size);
|
|
||||||
#else
|
|
||||||
if (!(module_inst->func_ptrs =
|
if (!(module_inst->func_ptrs =
|
||||||
runtime_malloc(total_size, error_buf, error_buf_size))) {
|
runtime_malloc(total_size, error_buf, error_buf_size))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set import function pointers */
|
/* Set import function pointers */
|
||||||
func_ptrs = (void **)module_inst->func_ptrs;
|
func_ptrs = (void **)module_inst->func_ptrs;
|
||||||
for (i = 0; i < module->import_func_count; i++, func_ptrs++) {
|
for (i = 0; i < module->import_func_count; i++, func_ptrs++) {
|
||||||
import_func = &module->import_funcs[i];
|
*func_ptrs = (void *)module->import_funcs[i].func_ptr_linked;
|
||||||
*func_ptrs = (void *)import_func->func_ptr_linked;
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE == 0
|
|
||||||
if (!*func_ptrs) {
|
if (!*func_ptrs) {
|
||||||
const char *module_name = import_func->module_name;
|
const char *module_name = module->import_funcs[i].module_name;
|
||||||
const char *field_name = import_func->func_name;
|
const char *field_name = module->import_funcs[i].func_name;
|
||||||
LOG_WARNING("warning: failed to link import function (%s, %s)",
|
LOG_WARNING("warning: failed to link import function (%s, %s)",
|
||||||
module_name, field_name);
|
module_name, field_name);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
sub_module_list_node = extra->sub_module_inst_list;
|
|
||||||
sub_module_list_node = bh_list_first_elem(sub_module_list_node);
|
|
||||||
while (sub_module_list_node) {
|
|
||||||
sub_inst_name =
|
|
||||||
((AOTSubModInstNode *)sub_module_list_node)->module_name;
|
|
||||||
if (strcmp(sub_inst_name, import_func->module_name) == 0) {
|
|
||||||
extra->func_module_insts[i] =
|
|
||||||
(WASMModuleInstanceCommon *)((AOTSubModInstNode *)
|
|
||||||
sub_module_list_node)
|
|
||||||
->module_inst;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sub_module_list_node = bh_list_elem_next(sub_module_list_node);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set defined function pointers */
|
/* Set defined function pointers */
|
||||||
|
@ -1674,6 +1640,17 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
|
||||||
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
extra->sub_module_inst_list = &extra->sub_module_inst_list_head;
|
extra->sub_module_inst_list = &extra->sub_module_inst_list_head;
|
||||||
|
|
||||||
|
/* Allocate memory for import_func_module_insts*/
|
||||||
|
if (module->import_func_count > 0
|
||||||
|
&& !(extra->import_func_module_insts =
|
||||||
|
runtime_malloc((uint64)module->import_func_count
|
||||||
|
* sizeof(WASMModuleInstanceCommon *),
|
||||||
|
error_buf, error_buf_size))) {
|
||||||
|
wasm_runtime_free(extra->import_func_module_insts);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
ret = wasm_runtime_sub_module_instantiate(
|
ret = wasm_runtime_sub_module_instantiate(
|
||||||
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
|
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
|
||||||
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
|
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
|
||||||
|
@ -2014,6 +1991,8 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
wasm_runtime_sub_module_deinstantiate(
|
wasm_runtime_sub_module_deinstantiate(
|
||||||
(WASMModuleInstanceCommon *)module_inst);
|
(WASMModuleInstanceCommon *)module_inst);
|
||||||
|
if (extra->import_func_module_insts)
|
||||||
|
wasm_runtime_free(extra->import_func_module_insts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (module_inst->tables)
|
if (module_inst->tables)
|
||||||
|
@ -2895,7 +2874,7 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
WASMModuleInstanceCommon *sub_inst = NULL;
|
WASMModuleInstanceCommon *sub_inst = NULL;
|
||||||
if ((sub_inst = ((AOTModuleInstanceExtra *)module_inst->e)
|
if ((sub_inst = ((AOTModuleInstanceExtra *)module_inst->e)
|
||||||
->func_module_insts[func_idx])) {
|
->import_func_module_insts[func_idx])) {
|
||||||
exec_env = wasm_runtime_get_exec_env_singleton(sub_inst);
|
exec_env = wasm_runtime_get_exec_env_singleton(sub_inst);
|
||||||
}
|
}
|
||||||
if (exec_env == NULL) {
|
if (exec_env == NULL) {
|
||||||
|
|
|
@ -109,7 +109,7 @@ typedef struct AOTModuleInstanceExtra {
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
bh_list sub_module_inst_list_head;
|
bh_list sub_module_inst_list_head;
|
||||||
bh_list *sub_module_inst_list;
|
bh_list *sub_module_inst_list;
|
||||||
WASMModuleInstanceCommon **func_module_insts;
|
WASMModuleInstanceCommon **import_func_module_insts;
|
||||||
#endif
|
#endif
|
||||||
} AOTModuleInstanceExtra;
|
} AOTModuleInstanceExtra;
|
||||||
|
|
||||||
|
|
|
@ -7322,6 +7322,29 @@ wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
|
||||||
(WASMModuleInstance *)sub_module_inst;
|
(WASMModuleInstance *)sub_module_inst;
|
||||||
sub_module_inst_list_node->module_name =
|
sub_module_inst_list_node->module_name =
|
||||||
sub_module_list_node->module_name;
|
sub_module_list_node->module_name;
|
||||||
|
|
||||||
|
#if WASM_ENABLE_AOT != 0
|
||||||
|
AOTModuleInstance *aot_module_inst = (AOTModuleInstance *)module_inst;
|
||||||
|
AOTModule *aot_module = (AOTModule *)module;
|
||||||
|
AOTModuleInstanceExtra *aot_extra =
|
||||||
|
(AOTModuleInstanceExtra *)aot_module_inst->e;
|
||||||
|
uint32 i;
|
||||||
|
AOTImportFunc *import_func;
|
||||||
|
for (i = 0; i < aot_module->import_func_count; i++) {
|
||||||
|
if (aot_extra->import_func_module_insts[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
import_func = &aot_module->import_funcs[i];
|
||||||
|
if (strcmp(sub_module_inst_list_node->module_name,
|
||||||
|
import_func->module_name)
|
||||||
|
== 0) {
|
||||||
|
aot_extra->import_func_module_insts[i] =
|
||||||
|
(WASMModuleInstanceCommon *)
|
||||||
|
sub_module_inst_list_node->module_inst;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bh_list_status ret =
|
bh_list_status ret =
|
||||||
bh_list_insert(sub_module_inst_list, sub_module_inst_list_node);
|
bh_list_insert(sub_module_inst_list, sub_module_inst_list_node);
|
||||||
bh_assert(BH_LIST_SUCCESS == ret);
|
bh_assert(BH_LIST_SUCCESS == ret);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user