Skip to content

Conversation

@TianlongLiang
Copy link
Collaborator

No description provided.

@TianlongLiang
Copy link
Collaborator Author

Will add a test case too

@TianlongLiang TianlongLiang force-pushed the dev/fix_hw_multi_module branch from c53d251 to b846382 Compare November 24, 2025 13:37
@TianlongLiang TianlongLiang marked this pull request as ready for review November 28, 2025 02:39
Copy link
Collaborator

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another smaller solution by using wasm_exec_env_restore_module_inst() in call_wasm_with_hw_bound_check() when an exception occurs.

diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c
index 7ac6a66f..81d1223a 100644
--- a/core/iwasm/interpreter/wasm_runtime.c
+++ b/core/iwasm/interpreter/wasm_runtime.c
@@ -3665,6 +3665,11 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst,
         /* Restore operand frames */
         wasm_exec_env_set_cur_frame(exec_env, prev_frame);
         exec_env->wasm_stack.top = prev_top;
+        /* Restore instance*/
+        if ((uintptr_t)module_inst != (uintptr_t)exec_env->module_inst) {
+            wasm_exec_env_restore_module_inst(exec_env,
+                (WASMModuleInstanceCommon *)module_inst);
+        }
     }
 
     jmpbuf_node_pop = wasm_exec_env_pop_jmpbuf(exec_env);

(WASMModuleInstanceCommon *)jmpbuf_node->module_inst,
(WASMModuleInstanceCommon *)module_inst);
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure why we need WASM_ENABLE_MULTI_MODULE handling in this low level logic.

exception propagation should be done regardless of hw bound check, shouldn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific case #4703 occurs only when an exception happens in the child module instance, and the main module instance fails to copy that exception, causing the problem.

We both agree that there is another simple solution for this issue.

However, in the short term, I can't determine under which circumstances it is necessary to switch module instances before calling a WASM function. Please enlighten me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants