Remove unused argument in wasm_runtime_lookup_function and refactor WASMModuleInstance (#3218)
Remove the unused parameter `signature` from `wasm_runtime_lookup_function`. Refactor the layout of WASMModuleInstance structure: - move common data members `c_api_func_imports` and `cur_exec_env` from `WASMModuleInstanceExtraCommon` to `WASMModuleInstance` - In `WASMModuleInstance`, enlarge `reserved[3]` to `reserved[5]` in case that we need to add more fields in the future ps. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2530 https://github.com/bytecodealliance/wasm-micro-runtime/issues/3202
This commit is contained in:
@ -1106,9 +1106,8 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
if (!func_import->call_conv_wasm_c_api) {
|
||||
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
||||
}
|
||||
else if (module_inst->e->common.c_api_func_imports) {
|
||||
c_api_func_import =
|
||||
module_inst->e->common.c_api_func_imports + cur_func_index;
|
||||
else if (module_inst->c_api_func_imports) {
|
||||
c_api_func_import = module_inst->c_api_func_imports + cur_func_index;
|
||||
native_func_pointer = c_api_func_import->func_ptr_linked;
|
||||
}
|
||||
|
||||
@ -5427,8 +5426,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
#ifndef OS_ENABLE_HW_BOUND_CHECK
|
||||
CHECK_BULK_MEMORY_OVERFLOW(addr, bytes, maddr);
|
||||
#else
|
||||
if ((uint64)(uint32)addr + bytes
|
||||
> (uint64)linear_mem_size)
|
||||
if ((uint64)(uint32)addr + bytes > linear_mem_size)
|
||||
goto out_of_bounds;
|
||||
maddr = memory->memory_data + (uint32)addr;
|
||||
#endif
|
||||
@ -5447,7 +5445,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
if (offset + bytes > seg_len)
|
||||
goto out_of_bounds;
|
||||
|
||||
bh_memcpy_s(maddr, linear_mem_size - addr,
|
||||
bh_memcpy_s(maddr, (uint32)(linear_mem_size - addr),
|
||||
data + offset, (uint32)bytes);
|
||||
break;
|
||||
}
|
||||
@ -5479,11 +5477,11 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
CHECK_BULK_MEMORY_OVERFLOW(src, len, msrc);
|
||||
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
|
||||
#else
|
||||
if ((uint64)(uint32)src + len > (uint64)linear_mem_size)
|
||||
if ((uint64)(uint32)src + len > linear_mem_size)
|
||||
goto out_of_bounds;
|
||||
msrc = memory->memory_data + (uint32)src;
|
||||
|
||||
if ((uint64)(uint32)dst + len > (uint64)linear_mem_size)
|
||||
if ((uint64)(uint32)dst + len > linear_mem_size)
|
||||
goto out_of_bounds;
|
||||
mdst = memory->memory_data + (uint32)dst;
|
||||
#endif
|
||||
|
||||
@ -1187,9 +1187,8 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
if (!func_import->call_conv_wasm_c_api) {
|
||||
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
||||
}
|
||||
else if (module_inst->e->common.c_api_func_imports) {
|
||||
c_api_func_import =
|
||||
module_inst->e->common.c_api_func_imports + cur_func_index;
|
||||
else if (module_inst->c_api_func_imports) {
|
||||
c_api_func_import = module_inst->c_api_func_imports + cur_func_index;
|
||||
native_func_pointer = c_api_func_import->func_ptr_linked;
|
||||
}
|
||||
|
||||
|
||||
@ -656,7 +656,7 @@ functions_instantiate(const WASMModule *module, WASMModuleInstance *module_inst,
|
||||
if (function->import_module_inst) {
|
||||
function->import_func_inst =
|
||||
wasm_lookup_function(function->import_module_inst,
|
||||
import->u.function.field_name, NULL);
|
||||
import->u.function.field_name);
|
||||
}
|
||||
}
|
||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||
@ -1220,7 +1220,7 @@ lookup_post_instantiate_func(WASMModuleInstance *module_inst,
|
||||
WASMFunctionInstance *func;
|
||||
WASMFuncType *func_type;
|
||||
|
||||
if (!(func = wasm_lookup_function(module_inst, func_name, NULL)))
|
||||
if (!(func = wasm_lookup_function(module_inst, func_name)))
|
||||
/* Not found */
|
||||
return NULL;
|
||||
|
||||
@ -2967,8 +2967,8 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (module_inst->e->common.c_api_func_imports)
|
||||
wasm_runtime_free(module_inst->e->common.c_api_func_imports);
|
||||
if (module_inst->c_api_func_imports)
|
||||
wasm_runtime_free(module_inst->c_api_func_imports);
|
||||
|
||||
if (!is_sub_inst) {
|
||||
#if WASM_ENABLE_WASI_NN != 0
|
||||
@ -2988,14 +2988,12 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||
}
|
||||
|
||||
WASMFunctionInstance *
|
||||
wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name,
|
||||
const char *signature)
|
||||
wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name)
|
||||
{
|
||||
uint32 i;
|
||||
for (i = 0; i < module_inst->export_func_count; i++)
|
||||
if (!strcmp(module_inst->export_functions[i].name, name))
|
||||
return module_inst->export_functions[i].function;
|
||||
(void)signature;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -3169,8 +3167,8 @@ wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
|
||||
hw bound check is enabled */
|
||||
#endif
|
||||
|
||||
/* Set exec env so it can be later retrieved from instance */
|
||||
module_inst->e->common.cur_exec_env = exec_env;
|
||||
/* Set exec env, so it can be later retrieved from instance */
|
||||
module_inst->cur_exec_env = exec_env;
|
||||
|
||||
interp_call_wasm(module_inst, exec_env, function, argc, argv);
|
||||
return !wasm_copy_exception(module_inst, NULL);
|
||||
@ -4050,9 +4048,8 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||
|
||||
import_func = &module->import_functions[func_idx].u.function;
|
||||
if (import_func->call_conv_wasm_c_api) {
|
||||
if (module_inst->e->common.c_api_func_imports) {
|
||||
c_api_func_import =
|
||||
module_inst->e->common.c_api_func_imports + func_idx;
|
||||
if (module_inst->c_api_func_imports) {
|
||||
c_api_func_import = module_inst->c_api_func_imports + func_idx;
|
||||
func_ptr = c_api_func_import->func_ptr_linked;
|
||||
}
|
||||
else {
|
||||
|
||||
@ -297,10 +297,9 @@ typedef struct CApiFuncImport {
|
||||
|
||||
/* The common part of WASMModuleInstanceExtra and AOTModuleInstanceExtra */
|
||||
typedef struct WASMModuleInstanceExtraCommon {
|
||||
CApiFuncImport *c_api_func_imports;
|
||||
#if WASM_ENABLE_MODULE_INST_CONTEXT != 0
|
||||
void *contexts[WASM_MAX_INSTANCE_CONTEXTS];
|
||||
/* pointer to the exec env currently used */
|
||||
WASMExecEnv *cur_exec_env;
|
||||
#endif
|
||||
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
|
||||
/* Disable bounds checks or not */
|
||||
bool disable_bounds_checks;
|
||||
@ -426,13 +425,16 @@ struct WASMModuleInstance {
|
||||
/* Function performance profiling info list, only available
|
||||
in AOTModuleInstance */
|
||||
DefPointer(struct AOTFuncPerfProfInfo *, func_perf_profilings);
|
||||
DefPointer(CApiFuncImport *, c_api_func_imports);
|
||||
/* Pointer to the exec env currently used */
|
||||
DefPointer(WASMExecEnv *, cur_exec_env);
|
||||
/* WASM/AOT module extra info, for AOTModuleInstance,
|
||||
it denotes `AOTModuleInstanceExtra *` */
|
||||
DefPointer(WASMModuleInstanceExtra *, e);
|
||||
|
||||
/* Default WASM operand stack size */
|
||||
uint32 default_wasm_stack_size;
|
||||
uint32 reserved[3];
|
||||
uint32 reserved[5];
|
||||
|
||||
/*
|
||||
* +------------------------------+ <-- memories
|
||||
@ -539,8 +541,7 @@ wasm_set_running_mode(WASMModuleInstance *module_inst,
|
||||
RunningMode running_mode);
|
||||
|
||||
WASMFunctionInstance *
|
||||
wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name,
|
||||
const char *signature);
|
||||
wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name);
|
||||
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
WASMGlobalInstance *
|
||||
|
||||
Reference in New Issue
Block a user