Skip to content

Commit

Permalink
Fix calling multi-module import func issue (bytecodealliance#748)
Browse files Browse the repository at this point in the history
Before calling import function of sub module inst in multi-module mode,
we should copy the arguments to output area by using the func inst of
sub module inst but not func inst of current module inst.
  • Loading branch information
wenyongh authored Sep 14, 2021
1 parent b1173d1 commit ed32693
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
WASMFunctionInstance *cur_func,
WASMInterpFrame *prev_frame)
{
WASMModuleInstance *sub_module_inst = cur_func->import_module_inst;
WASMModuleInstance *sub_module_inst = cur_func->import_module_inst;
WASMFunctionInstance *sub_func_inst = cur_func->import_func_inst;
WASMFunctionImport *func_import = cur_func->u.func_import;
uint8 *ip = prev_frame->ip;
Expand Down Expand Up @@ -3286,8 +3286,21 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
/* Only do the copy when it's called from interpreter. */
{
WASMInterpFrame *outs_area = wasm_exec_env_wasm_stack_top(exec_env);
outs_area->lp = outs_area->operand + cur_func->const_cell_num;
for (int i = 0; i < cur_func->param_count; i++) {
int i;

#if WASM_ENABLE_MULTI_MODULE != 0
if (cur_func->is_import_func) {
outs_area->lp = outs_area->operand
+ (cur_func->import_func_inst
? cur_func->import_func_inst->const_cell_num
: 0);
}
else
#endif
{
outs_area->lp = outs_area->operand + cur_func->const_cell_num;
}
for (i = 0; i < cur_func->param_count; i++) {
if (cur_func->param_types[i] == VALUE_TYPE_I64
|| cur_func->param_types[i] == VALUE_TYPE_F64) {
PUT_I64_TO_ADDR(outs_area->lp,
Expand Down

0 comments on commit ed32693

Please sign in to comment.