From 0ec27af9df392a3cc81bf728647ff5146eeb608d Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Thu, 14 Jul 2022 11:36:11 +0800 Subject: [PATCH] Add API wasm_runtime_set_module_inst (#1286) Add API wasm_runtime_set_module_inst, per request from #1275 --- core/iwasm/common/wasm_exec_env.c | 7 +++++++ core/iwasm/common/wasm_exec_env.h | 4 ++++ core/iwasm/common/wasm_runtime_common.c | 7 +++++++ core/iwasm/common/wasm_runtime_common.h | 5 +++++ core/iwasm/include/wasm_export.h | 15 +++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/core/iwasm/common/wasm_exec_env.c b/core/iwasm/common/wasm_exec_env.c index e98fdaa6..ba21a997 100644 --- a/core/iwasm/common/wasm_exec_env.c +++ b/core/iwasm/common/wasm_exec_env.c @@ -178,6 +178,13 @@ wasm_exec_env_get_module_inst(WASMExecEnv *exec_env) return exec_env->module_inst; } +void +wasm_exec_env_set_module_inst(WASMExecEnv *exec_env, + WASMModuleInstanceCommon *const module_inst) +{ + exec_env->module_inst = module_inst; +} + void wasm_exec_env_set_thread_info(WASMExecEnv *exec_env) { diff --git a/core/iwasm/common/wasm_exec_env.h b/core/iwasm/common/wasm_exec_env.h index f7e348d8..c99222a5 100644 --- a/core/iwasm/common/wasm_exec_env.h +++ b/core/iwasm/common/wasm_exec_env.h @@ -255,6 +255,10 @@ wasm_exec_env_get_cur_frame(WASMExecEnv *exec_env) struct WASMModuleInstanceCommon * wasm_exec_env_get_module_inst(WASMExecEnv *exec_env); +void +wasm_exec_env_set_module_inst( + WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst); + void wasm_exec_env_set_thread_info(WASMExecEnv *exec_env); diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index fea9987a..d357391e 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -1180,6 +1180,13 @@ wasm_runtime_get_module_inst(WASMExecEnv *exec_env) return wasm_exec_env_get_module_inst(exec_env); } +void +wasm_runtime_set_module_inst(WASMExecEnv *exec_env, + WASMModuleInstanceCommon *const module_inst) +{ + wasm_exec_env_set_module_inst(exec_env, module_inst); +} + void * wasm_runtime_get_function_attachment(WASMExecEnv *exec_env) { diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index 87a2e4aa..a4bec59c 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -507,6 +507,11 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env); WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon * wasm_runtime_get_module_inst(WASMExecEnv *exec_env); +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_module_inst(WASMExecEnv *exec_env, + WASMModuleInstanceCommon *const module_inst); + /* See wasm_export.h for description */ WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_function_attachment(WASMExecEnv *exec_env); diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 2fc31319..71317a40 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -539,6 +539,21 @@ wasm_runtime_thread_env_inited(void); WASM_RUNTIME_API_EXTERN wasm_module_inst_t wasm_runtime_get_module_inst(wasm_exec_env_t exec_env); +/** + * Set WASM module instance of execution environment + * Caution: + * normally the module instance is bound with the execution + * environment one by one, if multiple module instances want + * to share to the same execution environment, developer should + * be responsible for the backup and restore of module instance + * + * @param exec_env the execution environment + * @param module_inst the WASM module instance to set + */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_module_inst(wasm_exec_env_t exec_env, + const wasm_module_inst_t module_inst); + /** * Call the given WASM function of a WASM module instance with * arguments (bytecode and AoT).