mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-12 23:43:25 +00:00
Compare commits
No commits in common. "65bf04e98643f9cbccd6cdc5b8e6d82029c52c38" and "867dbd8912f8fd489ea9b24497abb9d3c81f1b40" have entirely different histories.
65bf04e986
...
867dbd8912
|
@ -591,17 +591,15 @@ str2uint64(const char *buf, uint64 *p_res);
|
||||||
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
static void *
|
static void *
|
||||||
aot_loader_resolve_function(const AOTModule *module, const char *function_name,
|
aot_loader_resolve_function(const char *module_name, const char *function_name,
|
||||||
const AOTFuncType *expected_function_type,
|
const AOTFuncType *expected_function_type,
|
||||||
char *error_buf, uint32 error_buf_size);
|
char *error_buf, uint32 error_buf_size)
|
||||||
|
|
||||||
static void *
|
|
||||||
aot_loader_resolve_function_ex(const char *module_name,
|
|
||||||
const char *function_name,
|
|
||||||
const AOTFuncType *expected_function_type,
|
|
||||||
char *error_buf, uint32 error_buf_size)
|
|
||||||
{
|
{
|
||||||
WASMModuleCommon *module_reg;
|
WASMModuleCommon *module_reg;
|
||||||
|
void *function = NULL;
|
||||||
|
AOTExport *export = NULL;
|
||||||
|
AOTModule *module = NULL;
|
||||||
|
AOTFuncType *target_function_type = NULL;
|
||||||
|
|
||||||
module_reg = wasm_runtime_find_module_registered(module_name);
|
module_reg = wasm_runtime_find_module_registered(module_name);
|
||||||
if (!module_reg || module_reg->module_type != Wasm_Module_AoT) {
|
if (!module_reg || module_reg->module_type != Wasm_Module_AoT) {
|
||||||
|
@ -610,23 +608,10 @@ aot_loader_resolve_function_ex(const char *module_name,
|
||||||
set_error_buf(error_buf, error_buf_size, "unknown import");
|
set_error_buf(error_buf, error_buf_size, "unknown import");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return aot_loader_resolve_function((AOTModule *)module_reg, function_name,
|
|
||||||
expected_function_type, error_buf,
|
|
||||||
error_buf_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
module = (AOTModule *)module_reg;
|
||||||
aot_loader_resolve_function(const AOTModule *module, const char *function_name,
|
export = loader_find_export(module_reg, module_name, function_name,
|
||||||
const AOTFuncType *expected_function_type,
|
EXPORT_KIND_FUNC, error_buf, error_buf_size);
|
||||||
char *error_buf, uint32 error_buf_size)
|
|
||||||
{
|
|
||||||
void *function = NULL;
|
|
||||||
AOTExport *export = NULL;
|
|
||||||
AOTFuncType *target_function_type = NULL;
|
|
||||||
|
|
||||||
export = loader_find_export((WASMModuleCommon *)module, module->name,
|
|
||||||
function_name, EXPORT_KIND_FUNC, error_buf,
|
|
||||||
error_buf_size);
|
|
||||||
if (!export) {
|
if (!export) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -648,7 +633,7 @@ aot_loader_resolve_function(const AOTModule *module, const char *function_name,
|
||||||
if (!wasm_type_equal((WASMType *)expected_function_type,
|
if (!wasm_type_equal((WASMType *)expected_function_type,
|
||||||
(WASMType *)target_function_type, module->types,
|
(WASMType *)target_function_type, module->types,
|
||||||
module->type_count)) {
|
module->type_count)) {
|
||||||
LOG_DEBUG("%s.%s failed the type check", module->name, function_name);
|
LOG_DEBUG("%s.%s failed the type check", module_name, function_name);
|
||||||
set_error_buf(error_buf, error_buf_size, "incompatible import type");
|
set_error_buf(error_buf, error_buf_size, "incompatible import type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2097,10 +2082,6 @@ load_import_globals(const uint8 **p_buf, const uint8 *buf_end,
|
||||||
read_string(buf, buf_end, import_globals[i].module_name);
|
read_string(buf, buf_end, import_globals[i].module_name);
|
||||||
read_string(buf, buf_end, import_globals[i].global_name);
|
read_string(buf, buf_end, import_globals[i].global_name);
|
||||||
|
|
||||||
if (!is_valid_value_type(import_globals[i].type.val_type)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
||||||
if (wasm_native_lookup_libc_builtin_global(
|
if (wasm_native_lookup_libc_builtin_global(
|
||||||
import_globals[i].module_name, import_globals[i].global_name,
|
import_globals[i].module_name, import_globals[i].global_name,
|
||||||
|
@ -2279,24 +2260,17 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
|
||||||
&import_funcs[i].signature, &import_funcs[i].attachment,
|
&import_funcs[i].signature, &import_funcs[i].attachment,
|
||||||
&import_funcs[i].call_conv_raw);
|
&import_funcs[i].call_conv_raw);
|
||||||
if (!linked_func) {
|
if (!linked_func) {
|
||||||
sub_module = NULL;
|
|
||||||
if (!wasm_runtime_is_built_in_module(module_name)) {
|
if (!wasm_runtime_is_built_in_module(module_name)) {
|
||||||
sub_module = (AOTModule *)wasm_runtime_load_depended_module(
|
sub_module = (AOTModule *)wasm_runtime_load_depended_module(
|
||||||
(WASMModuleCommon *)module, module_name, error_buf,
|
(WASMModuleCommon *)module, module_name, error_buf,
|
||||||
error_buf_size);
|
error_buf_size);
|
||||||
if (!sub_module) {
|
if (!sub_module) {
|
||||||
LOG_ERROR("failed to load sub module: %s", error_buf);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sub_module)
|
linked_func = aot_loader_resolve_function(
|
||||||
linked_func = aot_loader_resolve_function_ex(
|
module_name, field_name, declare_func_type, error_buf,
|
||||||
module_name, field_name, declare_func_type, error_buf,
|
error_buf_size);
|
||||||
error_buf_size);
|
|
||||||
else
|
|
||||||
linked_func = aot_loader_resolve_function(
|
|
||||||
sub_module, field_name, declare_func_type, error_buf,
|
|
||||||
error_buf_size);
|
|
||||||
}
|
}
|
||||||
import_funcs[i].func_ptr_linked = linked_func;
|
import_funcs[i].func_ptr_linked = linked_func;
|
||||||
import_funcs[i].func_type = declare_func_type;
|
import_funcs[i].func_type = declare_func_type;
|
||||||
|
|
|
@ -1640,16 +1640,6 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
|
||||||
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
extra->sub_module_inst_list = &extra->sub_module_inst_list_head;
|
extra->sub_module_inst_list = &extra->sub_module_inst_list_head;
|
||||||
|
|
||||||
/* Allocate memory for import_func_module_insts*/
|
|
||||||
if (module->import_func_count > 0
|
|
||||||
&& !(extra->import_func_module_insts =
|
|
||||||
runtime_malloc((uint64)module->import_func_count
|
|
||||||
* sizeof(WASMModuleInstanceCommon *),
|
|
||||||
error_buf, error_buf_size))) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = wasm_runtime_sub_module_instantiate(
|
ret = wasm_runtime_sub_module_instantiate(
|
||||||
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
|
(WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
|
||||||
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
|
stack_size, heap_size, max_memory_pages, error_buf, error_buf_size);
|
||||||
|
@ -1990,8 +1980,6 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
wasm_runtime_sub_module_deinstantiate(
|
wasm_runtime_sub_module_deinstantiate(
|
||||||
(WASMModuleInstanceCommon *)module_inst);
|
(WASMModuleInstanceCommon *)module_inst);
|
||||||
if (extra->import_func_module_insts)
|
|
||||||
wasm_runtime_free(extra->import_func_module_insts);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (module_inst->tables)
|
if (module_inst->tables)
|
||||||
|
@ -2847,6 +2835,10 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||||
void *attachment;
|
void *attachment;
|
||||||
char buf[96];
|
char buf[96];
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
|
bh_list *sub_module_list_node = NULL;
|
||||||
|
const char *sub_inst_name = NULL;
|
||||||
|
#endif
|
||||||
bh_assert(func_idx < aot_module->import_func_count);
|
bh_assert(func_idx < aot_module->import_func_count);
|
||||||
|
|
||||||
import_func = aot_module->import_funcs + func_idx;
|
import_func = aot_module->import_funcs + func_idx;
|
||||||
|
@ -2871,10 +2863,20 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
|
||||||
else if (!import_func->call_conv_raw) {
|
else if (!import_func->call_conv_raw) {
|
||||||
signature = import_func->signature;
|
signature = import_func->signature;
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
WASMModuleInstanceCommon *sub_inst = NULL;
|
sub_module_list_node =
|
||||||
if ((sub_inst = ((AOTModuleInstanceExtra *)module_inst->e)
|
((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list;
|
||||||
->import_func_module_insts[func_idx])) {
|
sub_module_list_node = bh_list_first_elem(sub_module_list_node);
|
||||||
exec_env = wasm_runtime_get_exec_env_singleton(sub_inst);
|
while (sub_module_list_node) {
|
||||||
|
sub_inst_name =
|
||||||
|
((AOTSubModInstNode *)sub_module_list_node)->module_name;
|
||||||
|
if (strcmp(sub_inst_name, import_func->module_name) == 0) {
|
||||||
|
exec_env = wasm_runtime_get_exec_env_singleton(
|
||||||
|
(WASMModuleInstanceCommon *)((AOTSubModInstNode *)
|
||||||
|
sub_module_list_node)
|
||||||
|
->module_inst);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sub_module_list_node = bh_list_elem_next(sub_module_list_node);
|
||||||
}
|
}
|
||||||
if (exec_env == NULL) {
|
if (exec_env == NULL) {
|
||||||
wasm_runtime_set_exception((WASMModuleInstanceCommon *)module_inst,
|
wasm_runtime_set_exception((WASMModuleInstanceCommon *)module_inst,
|
||||||
|
|
|
@ -109,7 +109,6 @@ typedef struct AOTModuleInstanceExtra {
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
bh_list sub_module_inst_list_head;
|
bh_list sub_module_inst_list_head;
|
||||||
bh_list *sub_module_inst_list;
|
bh_list *sub_module_inst_list;
|
||||||
WASMModuleInstanceCommon **import_func_module_insts;
|
|
||||||
#endif
|
#endif
|
||||||
} AOTModuleInstanceExtra;
|
} AOTModuleInstanceExtra;
|
||||||
|
|
||||||
|
|
|
@ -919,26 +919,6 @@ return_func:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst,
|
|
||||||
uint32_t inc_page_count)
|
|
||||||
{
|
|
||||||
#if WASM_ENABLE_AOT != 0
|
|
||||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
|
||||||
return aot_enlarge_memory((AOTModuleInstance *)module_inst,
|
|
||||||
inc_page_count);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if WASM_ENABLE_INTERP != 0
|
|
||||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
|
||||||
return wasm_enlarge_memory((WASMModuleInstance *)module_inst,
|
|
||||||
inc_page_count);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wasm_runtime_set_enlarge_mem_error_callback(
|
wasm_runtime_set_enlarge_mem_error_callback(
|
||||||
const enlarge_memory_error_callback_t callback, void *user_data)
|
const enlarge_memory_error_callback_t callback, void *user_data)
|
||||||
|
|
|
@ -7325,32 +7325,6 @@ wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
|
||||||
(WASMModuleInstance *)sub_module_inst;
|
(WASMModuleInstance *)sub_module_inst;
|
||||||
sub_module_inst_list_node->module_name =
|
sub_module_inst_list_node->module_name =
|
||||||
sub_module_list_node->module_name;
|
sub_module_list_node->module_name;
|
||||||
|
|
||||||
#if WASM_ENABLE_AOT != 0
|
|
||||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
|
||||||
AOTModuleInstance *aot_module_inst =
|
|
||||||
(AOTModuleInstance *)module_inst;
|
|
||||||
AOTModule *aot_module = (AOTModule *)module;
|
|
||||||
AOTModuleInstanceExtra *aot_extra =
|
|
||||||
(AOTModuleInstanceExtra *)aot_module_inst->e;
|
|
||||||
uint32 i;
|
|
||||||
AOTImportFunc *import_func;
|
|
||||||
for (i = 0; i < aot_module->import_func_count; i++) {
|
|
||||||
if (aot_extra->import_func_module_insts[i])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
import_func = &aot_module->import_funcs[i];
|
|
||||||
if (strcmp(sub_module_inst_list_node->module_name,
|
|
||||||
import_func->module_name)
|
|
||||||
== 0) {
|
|
||||||
aot_extra->import_func_module_insts[i] =
|
|
||||||
(WASMModuleInstanceCommon *)
|
|
||||||
sub_module_inst_list_node->module_inst;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bh_list_status ret =
|
bh_list_status ret =
|
||||||
bh_list_insert(sub_module_inst_list, sub_module_inst_list_node);
|
bh_list_insert(sub_module_inst_list, sub_module_inst_list_node);
|
||||||
bh_assert(BH_LIST_SUCCESS == ret);
|
bh_assert(BH_LIST_SUCCESS == ret);
|
||||||
|
|
|
@ -1842,10 +1842,6 @@ WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_is_import_global_linked(const char *module_name,
|
wasm_runtime_is_import_global_linked(const char *module_name,
|
||||||
const char *global_name);
|
const char *global_name);
|
||||||
|
|
||||||
WASM_RUNTIME_API_EXTERN bool
|
|
||||||
wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst,
|
|
||||||
uint32_t inc_page_count);
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
INTERNAL_ERROR,
|
INTERNAL_ERROR,
|
||||||
MAX_SIZE_REACHED,
|
MAX_SIZE_REACHED,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user