mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-13 21:21:22 +00:00
Introduce WASMModuleInstanceExtraCommon (#2429)
Move the common parts of WASMModuleInstanceExtra and AOTModuleInstanceExtra into the new structure.
This commit is contained in:
parent
81fbfbfcc0
commit
51714c41c0
|
@ -1271,9 +1271,9 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
|
||||||
if (module_inst->func_type_indexes)
|
if (module_inst->func_type_indexes)
|
||||||
wasm_runtime_free(module_inst->func_type_indexes);
|
wasm_runtime_free(module_inst->func_type_indexes);
|
||||||
|
|
||||||
if (((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports)
|
if (((AOTModuleInstanceExtra *)module_inst->e)->common.c_api_func_imports)
|
||||||
wasm_runtime_free(
|
wasm_runtime_free(((AOTModuleInstanceExtra *)module_inst->e)
|
||||||
((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports);
|
->common.c_api_func_imports);
|
||||||
|
|
||||||
if (!is_sub_inst) {
|
if (!is_sub_inst) {
|
||||||
#if WASM_ENABLE_LIBC_WASI != 0
|
#if WASM_ENABLE_LIBC_WASI != 0
|
||||||
|
@ -1925,8 +1925,8 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||||
AOTModuleInstanceExtra *module_inst_extra =
|
AOTModuleInstanceExtra *module_inst_extra =
|
||||||
(AOTModuleInstanceExtra *)module_inst->e;
|
(AOTModuleInstanceExtra *)module_inst->e;
|
||||||
CApiFuncImport *c_api_func_import =
|
CApiFuncImport *c_api_func_import =
|
||||||
module_inst_extra->c_api_func_imports
|
module_inst_extra->common.c_api_func_imports
|
||||||
? module_inst_extra->c_api_func_imports + func_idx
|
? module_inst_extra->common.c_api_func_imports + func_idx
|
||||||
: NULL;
|
: NULL;
|
||||||
uint32 *func_type_indexes = module_inst->func_type_indexes;
|
uint32 *func_type_indexes = module_inst->func_type_indexes;
|
||||||
uint32 func_type_idx = func_type_indexes[func_idx];
|
uint32 func_type_idx = func_type_indexes[func_idx];
|
||||||
|
|
|
@ -89,11 +89,7 @@ typedef struct AOTFunctionInstance {
|
||||||
|
|
||||||
typedef struct AOTModuleInstanceExtra {
|
typedef struct AOTModuleInstanceExtra {
|
||||||
DefPointer(const uint32 *, stack_sizes);
|
DefPointer(const uint32 *, stack_sizes);
|
||||||
CApiFuncImport *c_api_func_imports;
|
WASMModuleInstanceExtraCommon common;
|
||||||
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
|
|
||||||
/* Disable bounds checks or not */
|
|
||||||
bool disable_bounds_checks;
|
|
||||||
#endif
|
|
||||||
} AOTModuleInstanceExtra;
|
} AOTModuleInstanceExtra;
|
||||||
|
|
||||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
||||||
|
|
|
@ -4858,7 +4858,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
|
||||||
if (instance->inst_comm_rt->module_type == Wasm_Module_Bytecode) {
|
if (instance->inst_comm_rt->module_type == Wasm_Module_Bytecode) {
|
||||||
WASMModuleInstanceExtra *e =
|
WASMModuleInstanceExtra *e =
|
||||||
((WASMModuleInstance *)instance->inst_comm_rt)->e;
|
((WASMModuleInstance *)instance->inst_comm_rt)->e;
|
||||||
p_func_imports = &(e->c_api_func_imports);
|
p_func_imports = &(e->common.c_api_func_imports);
|
||||||
import_func_count = MODULE_INTERP(module)->import_function_count;
|
import_func_count = MODULE_INTERP(module)->import_function_count;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -4868,7 +4868,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
|
||||||
(AOTModuleInstanceExtra *)((AOTModuleInstance *)
|
(AOTModuleInstanceExtra *)((AOTModuleInstance *)
|
||||||
instance->inst_comm_rt)
|
instance->inst_comm_rt)
|
||||||
->e;
|
->e;
|
||||||
p_func_imports = &(e->c_api_func_imports);
|
p_func_imports = &(e->common.c_api_func_imports);
|
||||||
import_func_count = MODULE_AOT(module)->import_func_count;
|
import_func_count = MODULE_AOT(module)->import_func_count;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2491,14 +2491,14 @@ wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
|
||||||
#if WASM_ENABLE_INTERP != 0
|
#if WASM_ENABLE_INTERP != 0
|
||||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||||
((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e)
|
((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e)
|
||||||
->disable_bounds_checks = enable ? false : true;
|
->common.disable_bounds_checks = enable ? false : true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WASM_ENABLE_AOT != 0
|
#if WASM_ENABLE_AOT != 0
|
||||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||||
((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
|
((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
|
||||||
->disable_bounds_checks = enable ? false : true;
|
->common.disable_bounds_checks = enable ? false : true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -2511,7 +2511,7 @@ wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst)
|
||||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||||
return !((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)
|
return !((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)
|
||||||
->e)
|
->e)
|
||||||
->disable_bounds_checks;
|
->common.disable_bounds_checks;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2519,7 +2519,7 @@ wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst)
|
||||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||||
return !((AOTModuleInstanceExtra *)((WASMModuleInstance *)module_inst)
|
return !((AOTModuleInstanceExtra *)((WASMModuleInstance *)module_inst)
|
||||||
->e)
|
->e)
|
||||||
->disable_bounds_checks;
|
->common.disable_bounds_checks;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -905,8 +905,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||||
if (!func_import->call_conv_wasm_c_api) {
|
if (!func_import->call_conv_wasm_c_api) {
|
||||||
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
||||||
}
|
}
|
||||||
else if (module_inst->e->c_api_func_imports) {
|
else if (module_inst->e->common.c_api_func_imports) {
|
||||||
c_api_func_import = module_inst->e->c_api_func_imports + cur_func_index;
|
c_api_func_import =
|
||||||
|
module_inst->e->common.c_api_func_imports + cur_func_index;
|
||||||
native_func_pointer = c_api_func_import->func_ptr_linked;
|
native_func_pointer = c_api_func_import->func_ptr_linked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -938,8 +938,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||||
if (!func_import->call_conv_wasm_c_api) {
|
if (!func_import->call_conv_wasm_c_api) {
|
||||||
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
||||||
}
|
}
|
||||||
else if (module_inst->e->c_api_func_imports) {
|
else if (module_inst->e->common.c_api_func_imports) {
|
||||||
c_api_func_import = module_inst->e->c_api_func_imports + cur_func_index;
|
c_api_func_import =
|
||||||
|
module_inst->e->common.c_api_func_imports + cur_func_index;
|
||||||
native_func_pointer = c_api_func_import->func_ptr_linked;
|
native_func_pointer = c_api_func_import->func_ptr_linked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2227,8 +2227,8 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (module_inst->e->c_api_func_imports)
|
if (module_inst->e->common.c_api_func_imports)
|
||||||
wasm_runtime_free(module_inst->e->c_api_func_imports);
|
wasm_runtime_free(module_inst->e->common.c_api_func_imports);
|
||||||
|
|
||||||
if (!is_sub_inst) {
|
if (!is_sub_inst) {
|
||||||
#if WASM_ENABLE_LIBC_WASI != 0
|
#if WASM_ENABLE_LIBC_WASI != 0
|
||||||
|
@ -3141,8 +3141,9 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||||
|
|
||||||
import_func = &module->import_functions[func_idx].u.function;
|
import_func = &module->import_functions[func_idx].u.function;
|
||||||
if (import_func->call_conv_wasm_c_api) {
|
if (import_func->call_conv_wasm_c_api) {
|
||||||
if (module_inst->e->c_api_func_imports) {
|
if (module_inst->e->common.c_api_func_imports) {
|
||||||
c_api_func_import = module_inst->e->c_api_func_imports + func_idx;
|
c_api_func_import =
|
||||||
|
module_inst->e->common.c_api_func_imports + func_idx;
|
||||||
func_ptr = c_api_func_import->func_ptr_linked;
|
func_ptr = c_api_func_import->func_ptr_linked;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -210,8 +210,19 @@ typedef struct CApiFuncImport {
|
||||||
void *env_arg;
|
void *env_arg;
|
||||||
} CApiFuncImport;
|
} CApiFuncImport;
|
||||||
|
|
||||||
|
/* The common part of WASMModuleInstanceExtra and AOTModuleInstanceExtra */
|
||||||
|
typedef struct WASMModuleInstanceExtraCommon {
|
||||||
|
CApiFuncImport *c_api_func_imports;
|
||||||
|
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
|
||||||
|
/* Disable bounds checks or not */
|
||||||
|
bool disable_bounds_checks;
|
||||||
|
#endif
|
||||||
|
} WASMModuleInstanceExtraCommon;
|
||||||
|
|
||||||
/* Extra info of WASM module instance for interpreter/jit mode */
|
/* Extra info of WASM module instance for interpreter/jit mode */
|
||||||
typedef struct WASMModuleInstanceExtra {
|
typedef struct WASMModuleInstanceExtra {
|
||||||
|
WASMModuleInstanceExtraCommon common;
|
||||||
|
|
||||||
WASMGlobalInstance *globals;
|
WASMGlobalInstance *globals;
|
||||||
WASMFunctionInstance *functions;
|
WASMFunctionInstance *functions;
|
||||||
|
|
||||||
|
@ -223,7 +234,6 @@ typedef struct WASMModuleInstanceExtra {
|
||||||
WASMFunctionInstance *free_function;
|
WASMFunctionInstance *free_function;
|
||||||
WASMFunctionInstance *retain_function;
|
WASMFunctionInstance *retain_function;
|
||||||
|
|
||||||
CApiFuncImport *c_api_func_imports;
|
|
||||||
RunningMode running_mode;
|
RunningMode running_mode;
|
||||||
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
|
@ -242,10 +252,6 @@ typedef struct WASMModuleInstanceExtra {
|
||||||
&& WASM_ENABLE_LAZY_JIT != 0)
|
&& WASM_ENABLE_LAZY_JIT != 0)
|
||||||
WASMModuleInstance *next;
|
WASMModuleInstance *next;
|
||||||
#endif
|
#endif
|
||||||
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
|
|
||||||
/* Disable bounds checks or not */
|
|
||||||
bool disable_bounds_checks;
|
|
||||||
#endif
|
|
||||||
} WASMModuleInstanceExtra;
|
} WASMModuleInstanceExtra;
|
||||||
|
|
||||||
struct AOTFuncPerfProfInfo;
|
struct AOTFuncPerfProfInfo;
|
||||||
|
|
|
@ -746,10 +746,10 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
|
||||||
|
|
||||||
#if WASM_ENABLE_INTERP != 0
|
#if WASM_ENABLE_INTERP != 0
|
||||||
if (module_inst_src->module_type == Wasm_Module_Bytecode) {
|
if (module_inst_src->module_type == Wasm_Module_Bytecode) {
|
||||||
new_c_api_func_imports =
|
new_c_api_func_imports = &(((WASMModuleInstance *)module_inst_dst)
|
||||||
&(((WASMModuleInstance *)module_inst_dst)->e->c_api_func_imports);
|
->e->common.c_api_func_imports);
|
||||||
c_api_func_imports = ((const WASMModuleInstance *)module_inst_src)
|
c_api_func_imports = ((const WASMModuleInstance *)module_inst_src)
|
||||||
->e->c_api_func_imports;
|
->e->common.c_api_func_imports;
|
||||||
import_func_count =
|
import_func_count =
|
||||||
((WASMModule *)(((const WASMModuleInstance *)module_inst_src)
|
((WASMModule *)(((const WASMModuleInstance *)module_inst_src)
|
||||||
->module))
|
->module))
|
||||||
|
@ -760,10 +760,10 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
|
||||||
if (module_inst_src->module_type == Wasm_Module_AoT) {
|
if (module_inst_src->module_type == Wasm_Module_AoT) {
|
||||||
AOTModuleInstanceExtra *e =
|
AOTModuleInstanceExtra *e =
|
||||||
(AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_dst)->e;
|
(AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_dst)->e;
|
||||||
new_c_api_func_imports = &(e->c_api_func_imports);
|
new_c_api_func_imports = &(e->common.c_api_func_imports);
|
||||||
|
|
||||||
e = (AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_src)->e;
|
e = (AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_src)->e;
|
||||||
c_api_func_imports = e->c_api_func_imports;
|
c_api_func_imports = e->common.c_api_func_imports;
|
||||||
|
|
||||||
import_func_count =
|
import_func_count =
|
||||||
((AOTModule *)(((AOTModuleInstance *)module_inst_src)->module))
|
((AOTModule *)(((AOTModuleInstance *)module_inst_src)->module))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user