Implement wasm mini loader and refine footprint of loader and runtime (#276)

This commit is contained in:
wenyongh 2020-06-08 11:19:09 +08:00 committed by GitHub
parent 002f3b7ac4
commit 7a287fd1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 5285 additions and 431 deletions

View File

@ -133,10 +133,16 @@ endif ()
if (WAMR_BUILD_SPEC_TEST EQUAL 1) if (WAMR_BUILD_SPEC_TEST EQUAL 1)
add_definitions (-DWASM_ENABLE_SPEC_TEST=1) add_definitions (-DWASM_ENABLE_SPEC_TEST=1)
message (" spec test compatible mode is on") message (" spec test compatible mode is on")
endif() endif ()
if (WAMR_BUILD_BULK_MEMORY EQUAL 1) if (WAMR_BUILD_BULK_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_BULK_MEMORY=1) add_definitions (-DWASM_ENABLE_BULK_MEMORY=1)
message (" Bulk memory feature enabled") message (" Bulk memory feature enabled")
else () else ()
add_definitions (-DWASM_ENABLE_BULK_MEMORY=0) add_definitions (-DWASM_ENABLE_BULK_MEMORY=0)
endif() endif ()
if (WAMR_BUILD_MINI_LOADER EQUAL 1)
add_definitions (-DWASM_ENABLE_MINI_LOADER=1)
message (" WASM mini loader enabled")
else ()
add_definitions (-DWASM_ENABLE_MINI_LOADER=0)
endif ()

View File

@ -130,6 +130,11 @@ enum {
#define WASM_ENABLE_MULTI_MODULE 0 #define WASM_ENABLE_MULTI_MODULE 0
#endif #endif
/* Enable wasm mini loader or not */
#ifndef WASM_ENABLE_MINI_LOADER
#define WASM_ENABLE_MINI_LOADER 0
#endif
/* Heap and stack profiling */ /* Heap and stack profiling */
#define BH_ENABLE_MEMORY_PROFILING 0 #define BH_ENABLE_MEMORY_PROFILING 0

View File

@ -59,13 +59,24 @@ static union {
#define is_little_endian() (__ue.b == 1) #define is_little_endian() (__ue.b == 1)
#define CHECK_BUF(buf, buf_end, length) do { \ static bool
if (buf + length > buf_end) { \ check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
set_error_buf(error_buf, error_buf_size, \ char *error_buf, uint32 error_buf_size)
"Read data failed: unexpected end."); \ {
goto fail; \ if (buf + length > buf_end) {
} \ set_error_buf(error_buf, error_buf_size,
} while (0) "AOT module load failed: unexpect end.");
return false;
}
return true;
}
#define CHECK_BUF(buf, buf_end, length) do { \
if (!check_buf(buf, buf_end, length, \
error_buf, error_buf_size)) { \
goto fail; \
} \
} while (0)
static uint8* static uint8*
align_ptr(const uint8 *p, uint32 b) align_ptr(const uint8 *p, uint32 b)
@ -150,17 +161,32 @@ GET_U64_FROM_ADDR(uint32 *addr)
/* Legal values for e_version */ /* Legal values for e_version */
#define E_VERSION_CURRENT 1 /* Current version */ #define E_VERSION_CURRENT 1 /* Current version */
static void *
loader_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
{
void *mem;
if (size >= UINT32_MAX
|| !(mem = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return NULL;
}
memset(mem, 0, (uint32)size);
return mem;
}
static char* static char*
const_str_set_insert(const uint8 *str, int32 len, AOTModule *module, const_str_set_insert(const uint8 *str, int32 len, AOTModule *module,
char* error_buf, uint32 error_buf_size) char* error_buf, uint32 error_buf_size)
{ {
HashMap *set = module->const_str_set; HashMap *set = module->const_str_set;
char *c_str = wasm_runtime_malloc((uint32)len + 1), *value; char *c_str, *value;
if (!c_str) { if (!(c_str = loader_malloc((uint32)len + 1,
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"AOT module load failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
@ -348,17 +374,11 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTMemInitData *) * (uint64)module->mem_init_data_count; size = sizeof(AOTMemInitData *) * (uint64)module->mem_init_data_count;
if (size >= UINT32_MAX if (!(module->mem_init_data_list = data_list =
|| !(module->mem_init_data_list = loader_malloc(size, error_buf, error_buf_size))) {
data_list = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(data_list, 0, size);
/* Create each memory data segment */ /* Create each memory data segment */
for (i = 0; i < module->mem_init_data_count; i++) { for (i = 0; i < module->mem_init_data_count; i++) {
uint32 init_expr_type, byte_count; uint32 init_expr_type, byte_count;
@ -372,11 +392,8 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
read_uint64(buf, buf_end, init_expr_value); read_uint64(buf, buf_end, init_expr_value);
read_uint32(buf, buf_end, byte_count); read_uint32(buf, buf_end, byte_count);
size = offsetof(AOTMemInitData, bytes) + (uint64)byte_count; size = offsetof(AOTMemInitData, bytes) + (uint64)byte_count;
if (size >= UINT32_MAX if (!(data_list[i] = loader_malloc
|| !(data_list[i] = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
@ -447,17 +464,11 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTTableInitData *) * (uint64)module->table_init_data_count; size = sizeof(AOTTableInitData *) * (uint64)module->table_init_data_count;
if (size >= UINT32_MAX if (!(module->table_init_data_list = data_list =
|| !(module->table_init_data_list = loader_malloc(size, error_buf, error_buf_size))) {
data_list = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(data_list, 0, size);
/* Create each table data segment */ /* Create each table data segment */
for (i = 0; i < module->table_init_data_count; i++) { for (i = 0; i < module->table_init_data_count; i++) {
uint32 init_expr_type, func_index_count; uint32 init_expr_type, func_index_count;
@ -469,11 +480,8 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
size1 = sizeof(uint32) * (uint64)func_index_count; size1 = sizeof(uint32) * (uint64)func_index_count;
size = offsetof(AOTTableInitData, func_indexes) + size1; size = offsetof(AOTTableInitData, func_indexes) + size1;
if (size >= UINT32_MAX if (!(data_list[i] = loader_malloc
|| !(data_list[i] = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
@ -535,16 +543,11 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTFuncType *) * (uint64)module->func_type_count; size = sizeof(AOTFuncType *) * (uint64)module->func_type_count;
if (size >= UINT32_MAX if (!(module->func_types = func_types = loader_malloc
|| !(module->func_types = func_types = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(func_types, 0, size);
/* Create each function type */ /* Create each function type */
for (i = 0; i < module->func_type_count; i++) { for (i = 0; i < module->func_type_count; i++) {
uint32 param_count, result_count; uint32 param_count, result_count;
@ -555,11 +558,8 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end,
size1 = (uint64)param_count + (uint64)result_count; size1 = (uint64)param_count + (uint64)result_count;
size = offsetof(AOTFuncType, types) + size1; size = offsetof(AOTFuncType, types) + size1;
if (size >= UINT32_MAX if (!(func_types[i] = loader_malloc
|| !(func_types[i] = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
@ -613,17 +613,11 @@ load_import_globals(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTImportGlobal) * (uint64)module->import_global_count; size = sizeof(AOTImportGlobal) * (uint64)module->import_global_count;
if (size >= UINT32_MAX if (!(module->import_globals = import_globals =
|| !(module->import_globals = loader_malloc(size, error_buf, error_buf_size))) {
import_globals = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(import_globals, 0, size);
/* Create each import global */ /* Create each import global */
for (i = 0; i < module->import_global_count; i++) { for (i = 0; i < module->import_global_count; i++) {
buf = (uint8*)align_ptr(buf, 2); buf = (uint8*)align_ptr(buf, 2);
@ -685,16 +679,11 @@ load_globals(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTGlobal) * (uint64)module->global_count; size = sizeof(AOTGlobal) * (uint64)module->global_count;
if (size >= UINT32_MAX if (!(module->globals = globals = loader_malloc
|| !(module->globals = globals = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(globals, 0, size);
if (module->import_global_count > 0) { if (module->import_global_count > 0) {
last_import_global = last_import_global =
&module->import_globals[module->import_global_count - 1]; &module->import_globals[module->import_global_count - 1];
@ -767,17 +756,11 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTImportFunc) * (uint64)module->import_func_count; size = sizeof(AOTImportFunc) * (uint64)module->import_func_count;
if (size >= UINT32_MAX if (!(module->import_funcs = import_funcs =
|| !(module->import_funcs = loader_malloc(size, error_buf, error_buf_size))) {
import_funcs = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(import_funcs, 0, size);
/* Create each import func */ /* Create each import func */
for (i = 0; i < module->import_func_count; i++) { for (i = 0; i < module->import_func_count; i++) {
read_uint16(buf, buf_end, import_funcs[i].func_type_index); read_uint16(buf, buf_end, import_funcs[i].func_type_index);
@ -860,17 +843,11 @@ load_object_data_sections(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTObjectDataSection) * (uint64)module->data_section_count; size = sizeof(AOTObjectDataSection) * (uint64)module->data_section_count;
if (size >= UINT32_MAX if (!(module->data_sections = data_sections =
|| !(module->data_sections = loader_malloc(size, error_buf, error_buf_size))) {
data_sections = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(data_sections, 0, size);
/* Create each data section */ /* Create each data section */
for (i = 0; i < module->data_section_count; i++) { for (i = 0; i < module->data_section_count; i++) {
int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE; int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE;
@ -1021,10 +998,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
uint64 size, text_offset; uint64 size, text_offset;
size = sizeof(void*) * (uint64)module->func_count; size = sizeof(void*) * (uint64)module->func_count;
if (size >= UINT32_MAX if (!(module->func_ptrs = loader_malloc
|| !(module->func_ptrs = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: allocate memory failed.");
return false; return false;
} }
@ -1065,10 +1040,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
} }
size = sizeof(uint32) * (uint64)module->func_count; size = sizeof(uint32) * (uint64)module->func_count;
if (size >= UINT32_MAX if (!(module->func_type_indexes = loader_malloc
|| !(module->func_type_indexes = wasm_runtime_malloc((uint32)size))) { (size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: allocate memory failed.");
return false; return false;
} }
@ -1112,17 +1085,11 @@ load_export_funcs(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTExportFunc) * (uint64)module->export_func_count; size = sizeof(AOTExportFunc) * (uint64)module->export_func_count;
if (size >= UINT32_MAX if (!(module->export_funcs = export_funcs =
|| !(module->export_funcs = loader_malloc(size, error_buf, error_buf_size))) {
export_funcs = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(export_funcs, 0, size);
/* Create each export func */ /* Create each export func */
for (i = 0; i < module->export_func_count; i++) { for (i = 0; i < module->export_func_count; i++) {
read_uint32(buf, buf_end, export_funcs[i].func_index); read_uint32(buf, buf_end, export_funcs[i].func_index);
@ -1234,10 +1201,8 @@ do_text_relocation(AOTModule *module,
if (symbol_len + 1 <= sizeof(symbol_buf)) if (symbol_len + 1 <= sizeof(symbol_buf))
symbol = symbol_buf; symbol = symbol_buf;
else { else {
if (!(symbol = wasm_runtime_malloc(symbol_len + 1))) { if (!(symbol = loader_malloc(symbol_len + 1,
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"AOT module load failed: "
"allocate memory failed.");
return false; return false;
} }
} }
@ -1432,15 +1397,10 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
/* Allocate memory for relocation groups */ /* Allocate memory for relocation groups */
size = sizeof(AOTRelocationGroup) * (uint64)group_count; size = sizeof(AOTRelocationGroup) * (uint64)group_count;
if (size >= UINT32_MAX || !(groups = wasm_runtime_malloc((uint32)size))) { if (!(groups = loader_malloc(size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
goto fail; goto fail;
} }
memset(groups, 0, size);
/* Load each relocation group */ /* Load each relocation group */
for (i = 0, group = groups; i < group_count; i++, group++) { for (i = 0, group = groups; i < group_count; i++, group++) {
AOTRelocation *relocation; AOTRelocation *relocation;
@ -1473,18 +1433,12 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
/* Allocate memory for relocations */ /* Allocate memory for relocations */
size = sizeof(AOTRelocation) * (uint64)group->relocation_count; size = sizeof(AOTRelocation) * (uint64)group->relocation_count;
if (size >= UINT32_MAX if (!(group->relocations = relocation =
|| !(group->relocations = relocation = loader_malloc(size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"allocate memory failed.");
ret = false; ret = false;
goto fail; goto fail;
} }
memset(group->relocations, 0, size);
/* Load each relocation */ /* Load each relocation */
for (j = 0; j < group->relocation_count; j++, relocation++) { for (j = 0; j < group->relocation_count; j++, relocation++) {
uint32 symbol_index; uint32 symbol_index;

View File

@ -14,6 +14,23 @@ set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
snprintf(error_buf, error_buf_size, "%s", string); snprintf(error_buf, error_buf_size, "%s", string);
} }
static void *
runtime_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
{
void *mem;
if (size >= UINT32_MAX
|| !(mem = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module instantiate failed: "
"allocate memory failed.");
return NULL;
}
memset(mem, 0, (uint32)size);
return mem;
}
static bool static bool
global_instantiate(AOTModuleInstance *module_inst, AOTModule *module, global_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
char *error_buf, uint32 error_buf_size) char *error_buf, uint32 error_buf_size)
@ -142,15 +159,10 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
uint8 *p; uint8 *p;
/* Allocate memory */ /* Allocate memory */
if (total_size >= UINT32_MAX if (!(p = runtime_malloc(total_size, error_buf, error_buf_size))) {
|| !(p = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module instantiate failed: allocate memory failed.");
return false; return false;
} }
memset(p, 0, (uint32)total_size);
/* Initialize heap info */ /* Initialize heap info */
module_inst->heap_data.ptr = p; module_inst->heap_data.ptr = p;
p += heap_size; p += heap_size;
@ -270,15 +282,11 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module,
((uint64)module->import_func_count + module->func_count) * sizeof(void*); ((uint64)module->import_func_count + module->func_count) * sizeof(void*);
/* Allocate memory */ /* Allocate memory */
if (total_size >= UINT32_MAX if (!(module_inst->func_ptrs.ptr = runtime_malloc
|| !(module_inst->func_ptrs.ptr = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module instantiate failed: allocate memory failed.");
return false; return false;
} }
memset(module_inst->func_ptrs.ptr, 0, (uint32)total_size);
/* Set import function pointers */ /* Set import function pointers */
func_ptrs = (void**)module_inst->func_ptrs.ptr; func_ptrs = (void**)module_inst->func_ptrs.ptr;
for (i = 0; i < module->import_func_count; i++, func_ptrs++) for (i = 0; i < module->import_func_count; i++, func_ptrs++)
@ -299,16 +307,11 @@ init_func_type_indexes(AOTModuleInstance *module_inst, AOTModule *module,
((uint64)module->import_func_count + module->func_count) * sizeof(uint32); ((uint64)module->import_func_count + module->func_count) * sizeof(uint32);
/* Allocate memory */ /* Allocate memory */
if (total_size >= UINT32_MAX if (!(module_inst->func_type_indexes.ptr =
|| !(module_inst->func_type_indexes.ptr = runtime_malloc(total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module instantiate failed: allocate memory failed.");
return false; return false;
} }
memset(module_inst->func_type_indexes.ptr, 0, (uint32)total_size);
/* Set import function type indexes */ /* Set import function type indexes */
func_type_index = (uint32*)module_inst->func_type_indexes.ptr; func_type_index = (uint32*)module_inst->func_type_indexes.ptr;
for (i = 0; i < module->import_func_count; i++, func_type_index++) for (i = 0; i < module->import_func_count; i++, func_type_index++)
@ -381,14 +384,11 @@ aot_instantiate(AOTModule *module,
heap_size = APP_HEAP_SIZE_MAX; heap_size = APP_HEAP_SIZE_MAX;
/* Allocate module instance, global data, table data and heap data */ /* Allocate module instance, global data, table data and heap data */
if (total_size >= UINT32_MAX if (!(module_inst = runtime_malloc(total_size,
|| !(module_inst = wasm_runtime_malloc((uint32)total_size))) { error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"AOT module instantiate failed: allocate memory failed.");
return NULL; return NULL;
} }
memset(module_inst, 0, total_size);
module_inst->module_type = Wasm_Module_AoT; module_inst->module_type = Wasm_Module_AoT;
module_inst->aot_module.ptr = module; module_inst->aot_module.ptr = module;
@ -801,7 +801,7 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
/* Destroy heap's lock firstly, if its memory is re-allocated, /* Destroy heap's lock firstly, if its memory is re-allocated,
we cannot access its lock again. */ we cannot access its lock again. */
mem_allocator_destroy_lock(module_inst->heap_handle.ptr); mem_allocator_destroy_lock(module_inst->heap_handle.ptr);
if (!(heap_data = wasm_runtime_realloc(heap_handle_old, (uint32)total_size))) { if (!(heap_data = wasm_runtime_realloc(heap_data_old, (uint32)total_size))) {
if (!(heap_data = wasm_runtime_malloc((uint32)total_size))) { if (!(heap_data = wasm_runtime_malloc((uint32)total_size))) {
/* Restore heap's lock if memory re-alloc failed */ /* Restore heap's lock if memory re-alloc failed */
mem_allocator_reinit_lock(module_inst->heap_handle.ptr); mem_allocator_reinit_lock(module_inst->heap_handle.ptr);

View File

@ -60,6 +60,29 @@ set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
snprintf(error_buf, error_buf_size, "%s", string); snprintf(error_buf, error_buf_size, "%s", string);
} }
static void *
runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst,
char *error_buf, uint32 error_buf_size)
{
void *mem;
if (size >= UINT32_MAX
|| !(mem = wasm_runtime_malloc((uint32)size))) {
if (module_inst != NULL) {
wasm_runtime_set_exception(module_inst,
"allocate memory failed.");
}
else if (error_buf != NULL) {
set_error_buf(error_buf, error_buf_size,
"allocate memory failed.");
}
return NULL;
}
memset(mem, 0, (uint32)size);
return mem;
}
static bool static bool
wasm_runtime_env_init() wasm_runtime_env_init()
{ {
@ -91,12 +114,12 @@ wasm_runtime_env_init()
static bool static bool
wasm_runtime_exec_env_check(WASMExecEnv *exec_env) wasm_runtime_exec_env_check(WASMExecEnv *exec_env)
{ {
return !(!exec_env return exec_env
|| !exec_env->module_inst && exec_env->module_inst
|| exec_env->wasm_stack_size == 0 && exec_env->wasm_stack_size > 0
|| exec_env->wasm_stack.s.top_boundary != && exec_env->wasm_stack.s.top_boundary ==
exec_env->wasm_stack.s.bottom + exec_env->wasm_stack_size exec_env->wasm_stack.s.bottom + exec_env->wasm_stack_size
|| exec_env->wasm_stack.s.top > exec_env->wasm_stack.s.top_boundary); && exec_env->wasm_stack.s.top <= exec_env->wasm_stack.s.top_boundary;
} }
bool bool
@ -240,13 +263,10 @@ wasm_runtime_register_module_internal(const char *module_name,
} }
/* module hasn't been registered */ /* module hasn't been registered */
node = wasm_runtime_malloc(sizeof(WASMRegisteredModule)); node = runtime_malloc(sizeof(WASMRegisteredModule), NULL, NULL, 0);
if (!node) { if (!node) {
LOG_DEBUG("malloc WASMRegisteredModule failed. SZ=%d", LOG_DEBUG("malloc WASMRegisteredModule failed. SZ=%d",
sizeof(WASMRegisteredModule)); sizeof(WASMRegisteredModule));
set_error_buf_v(error_buf, error_buf_size,
"malloc WASMRegisteredModule failed. SZ=%d",
sizeof(WASMRegisteredModule));
return false; return false;
} }
@ -377,16 +397,15 @@ wasm_runtime_destroy_registered_module_list()
} }
bool bool
wasm_runtime_add_loading_module(const char *module_name, char *error_buf, wasm_runtime_add_loading_module(const char *module_name,
uint32 error_buf_size) char *error_buf, uint32 error_buf_size)
{ {
LOG_DEBUG("add %s into a loading list", module_name); LOG_DEBUG("add %s into a loading list", module_name);
LoadingModule *loadingModule = wasm_runtime_malloc(sizeof(LoadingModule)); LoadingModule *loadingModule =
runtime_malloc(sizeof(LoadingModule), NULL,
error_buf, error_buf_size);
if (!loadingModule) { if (!loadingModule) {
set_error_buf_v(error_buf, error_buf_size,
"malloc LoadingModule failed. SZ=%d",
sizeof(LoadingModule));
return false; return false;
} }
@ -1145,13 +1164,11 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
uint64 total_size; uint64 total_size;
uint32 i; uint32 i;
if (!(wasi_ctx = wasm_runtime_malloc(sizeof(WASIContext)))) { if (!(wasi_ctx = runtime_malloc(sizeof(WASIContext), NULL,
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"Init wasi environment failed: allocate memory failed.");
return false; return false;
} }
memset(wasi_ctx, 0, sizeof(WASIContext));
wasm_runtime_set_wasi_ctx(module_inst, wasi_ctx); wasm_runtime_set_wasi_ctx(module_inst, wasi_ctx);
#if WASM_ENABLE_INTERP != 0 #if WASM_ENABLE_INTERP != 0
@ -1645,12 +1662,11 @@ resolve_function(const WASMModuleInstanceCommon *module_inst,
char *function_name = NULL; char *function_name = NULL;
uint32 length = strlen(name) + 1; uint32 length = strlen(name) + 1;
orig_name = wasm_runtime_malloc(sizeof(char) * length); orig_name = runtime_malloc(sizeof(char) * length, NULL, NULL, 0);
if (!orig_name) { if (!orig_name) {
return NULL; return NULL;
} }
memset(orig_name, 0, sizeof(char) * length);
strncpy(orig_name, name, length); strncpy(orig_name, name, length);
if (!parse_function_name(orig_name, &sub_module_name, &function_name)) { if (!parse_function_name(orig_name, &sub_module_name, &function_name)) {
@ -1808,9 +1824,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
} }
total_size = sizeof(uint32) * (uint64)(argc1 > 2 ? argc1 : 2); total_size = sizeof(uint32) * (uint64)(argc1 > 2 ? argc1 : 2);
if (total_size >= UINT32_MAX if ((!(argv1 = runtime_malloc((uint32)total_size, module_inst,
|| (!(argv1 = wasm_runtime_malloc((uint32)total_size)))) { NULL, 0)))) {
wasm_runtime_set_exception(module_inst, "allocate memory failed.");
goto fail; goto fail;
} }
@ -2008,13 +2023,10 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
argc1 = func_type->param_count; argc1 = func_type->param_count;
if (argc1 > sizeof(argv_buf) / sizeof(uint64)) { if (argc1 > sizeof(argv_buf) / sizeof(uint64)) {
size = sizeof(uint64) * (uint64)argc1; size = sizeof(uint64) * (uint64)argc1;
if (size >= UINT32_MAX if (!(argv1 = runtime_malloc((uint32)size, exec_env->module_inst,
|| !(argv1 = wasm_runtime_malloc((uint32)size))) { NULL, 0))) {
wasm_runtime_set_exception(exec_env->module_inst,
"allocate memory failed.");
return false; return false;
} }
memset(argv1, 0, (uint32)size);
} }
argv_dst = argv1; argv_dst = argv1;
@ -2208,10 +2220,8 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
argc1 = MAX_REG_INTS + MAX_REG_FLOATS + n_stacks; argc1 = MAX_REG_INTS + MAX_REG_FLOATS + n_stacks;
if (argc1 > sizeof(argv_buf) / sizeof(uint32)) { if (argc1 > sizeof(argv_buf) / sizeof(uint32)) {
size = sizeof(uint32) * (uint32)argc1; size = sizeof(uint32) * (uint32)argc1;
if (size >= UINT32_MAX if (!(argv1 = runtime_malloc((uint32)size, exec_env->module_inst,
|| !(argv1 = wasm_runtime_malloc((uint32)size))) { NULL, 0))) {
wasm_runtime_set_exception(exec_env->module_inst,
"allocate memory failed.");
return false; return false;
} }
} }
@ -2386,10 +2396,8 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
if (argc1 > sizeof(argv_buf) / sizeof(uint32)) { if (argc1 > sizeof(argv_buf) / sizeof(uint32)) {
size = sizeof(uint32) * (uint64)argc1; size = sizeof(uint32) * (uint64)argc1;
if (size >= UINT_MAX if (!(argv1 = runtime_malloc((uint32)size, exec_env->module_inst,
|| !(argv1 = wasm_runtime_malloc((uint32)size))) { NULL, 0))) {
wasm_runtime_set_exception(exec_env->module_inst,
"allocate memory failed.");
return false; return false;
} }
} }
@ -2543,10 +2551,8 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
argc1 = 1 + MAX_REG_FLOATS + func_type->param_count + 2; argc1 = 1 + MAX_REG_FLOATS + func_type->param_count + 2;
if (argc1 > sizeof(argv_buf) / sizeof(uint64)) { if (argc1 > sizeof(argv_buf) / sizeof(uint64)) {
size = sizeof(uint64) * (uint64)argc1; size = sizeof(uint64) * (uint64)argc1;
if (size >= UINT32_MAX if (!(argv1 = runtime_malloc((uint32)size, exec_env->module_inst,
|| !(argv1 = wasm_runtime_malloc((uint32)size))) { NULL, 0))) {
wasm_runtime_set_exception(exec_env->module_inst,
"allocate memory failed.");
return false; return false;
} }
} }

View File

@ -13,8 +13,14 @@ else ()
set (INTERPRETER "wasm_interp_classic.c") set (INTERPRETER "wasm_interp_classic.c")
endif () endif ()
if (WAMR_BUILD_MINI_LOADER EQUAL 1)
set (LOADER "wasm_mini_loader.c")
else ()
set (LOADER "wasm_loader.c")
endif ()
file (GLOB_RECURSE source_all file (GLOB_RECURSE source_all
${IWASM_INTERP_DIR}/wasm_loader.c ${IWASM_INTERP_DIR}/${LOADER}
${IWASM_INTERP_DIR}/wasm_runtime.c ${IWASM_INTERP_DIR}/wasm_runtime.c
${IWASM_INTERP_DIR}/${INTERPRETER} ${IWASM_INTERP_DIR}/${INTERPRETER}
) )

View File

@ -24,21 +24,43 @@ set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
snprintf(error_buf, error_buf_size, "%s", string); snprintf(error_buf, error_buf_size, "%s", string);
} }
#define CHECK_BUF(buf, buf_end, length) do { \ static bool
if (buf + length > buf_end) { \ check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
set_error_buf(error_buf, error_buf_size, \ char *error_buf, uint32 error_buf_size)
"WASM module load failed: " \ {
"unexpected end of section or function"); \ if (buf + length > buf_end) {
return false; \ set_error_buf(error_buf, error_buf_size,
} \ "WASM module load failed: "
"unexpected end of section or function");
return false;
}
return true;
}
static bool
check_buf1(const uint8 *buf, const uint8 *buf_end, uint32 length,
char *error_buf, uint32 error_buf_size)
{
if (buf + length > buf_end) {
set_error_buf(error_buf, error_buf_size,
"WASM module load failed: unexpected end");
return false;
}
return true;
}
#define CHECK_BUF(buf, buf_end, length) do { \
if (!check_buf(buf, buf_end, length, \
error_buf, error_buf_size)) { \
return false; \
} \
} while (0) } while (0)
#define CHECK_BUF1(buf, buf_end, length) do { \ #define CHECK_BUF1(buf, buf_end, length) do { \
if (buf + length > buf_end) { \ if (!check_buf1(buf, buf_end, length, \
set_error_buf(error_buf, error_buf_size, \ error_buf, error_buf_size)) { \
"WASM module load failed: unexpected end");\ return false; \
return false; \ } \
} \
} while (0) } while (0)
static bool static bool
@ -193,6 +215,23 @@ fail_integer_too_large:
res = (int32)res64; \ res = (int32)res64; \
} while (0) } while (0)
static void *
loader_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
{
void *mem;
if (size >= UINT32_MAX
|| !(mem = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"WASM module load failed: "
"allocate memory failed.");
return NULL;
}
memset(mem, 0, (uint32)size);
return mem;
}
static bool static bool
check_utf8_str(const uint8* str, uint32 len) check_utf8_str(const uint8* str, uint32 len)
{ {
@ -256,10 +295,8 @@ const_str_list_insert(const uint8 *str, uint32 len, WASMModule *module,
return node->str; return node->str;
} }
if (!(node = wasm_runtime_malloc(sizeof(StringNode) + len + 1))) { if (!(node = loader_malloc(sizeof(StringNode) + len + 1,
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"WASM module load failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
@ -361,15 +398,11 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
if (type_count) { if (type_count) {
module->type_count = type_count; module->type_count = type_count;
total_size = sizeof(WASMType*) * (uint64)type_count; total_size = sizeof(WASMType*) * (uint64)type_count;
if (total_size >= UINT32_MAX if (!(module->types = loader_malloc
|| !(module->types = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load type section failed: allocate memory failed.");
return false; return false;
} }
memset(module->types, 0, (uint32)total_size);
for (i = 0; i < type_count; i++) { for (i = 0; i < type_count; i++) {
CHECK_BUF(p, p_end, 1); CHECK_BUF(p, p_end, 1);
flag = read_uint8(p); flag = read_uint8(p);
@ -396,11 +429,8 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
total_size = offsetof(WASMType, types) + total_size = offsetof(WASMType, types) +
sizeof(uint8) * (uint64)(param_count + result_count); sizeof(uint8) * (uint64)(param_count + result_count);
if (total_size >= UINT32_MAX if (!(type = module->types[i] =
|| !(type = module->types[i] = loader_malloc(total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Load type section failed: allocate memory failed.");
return false; return false;
} }
@ -808,12 +838,6 @@ load_table_import(WASMModule *sub_module, const char *sub_module_name,
} }
*p_buf = p; *p_buf = p;
if ((declare_max_size_flag & 1) && declare_init_size > declare_max_size) {
set_error_buf(error_buf, error_buf_size,
"size minimum must not be greater than maximum");
return false;
}
#if WASM_ENABLE_MULTI_MODULE != 0 #if WASM_ENABLE_MULTI_MODULE != 0
if (!wasm_runtime_is_built_in_module(sub_module_name)) { if (!wasm_runtime_is_built_in_module(sub_module_name)) {
linked_table = wasm_loader_resolve_table( linked_table = wasm_loader_resolve_table(
@ -1093,12 +1117,6 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMTable *table,
else else
table->max_size = 0x10000; table->max_size = 0x10000;
if ((table->flags & 1) && table->init_size > table->max_size) {
set_error_buf(error_buf, error_buf_size,
"size minimum must not be greater than maximum");
return false;
}
*p_buf = p; *p_buf = p;
return true; return true;
} }
@ -1327,15 +1345,11 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
if (import_count) { if (import_count) {
module->import_count = import_count; module->import_count = import_count;
total_size = sizeof(WASMImport) * (uint64)import_count; total_size = sizeof(WASMImport) * (uint64)import_count;
if (total_size >= UINT32_MAX if (!(module->imports = loader_malloc
|| !(module->imports = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load import section failed: allocate memory failed.");
return false; return false;
} }
memset(module->imports, 0, (uint32)total_size);
p_old = p; p_old = p;
/* Scan firstly to get import count of each type */ /* Scan firstly to get import count of each type */
@ -1576,10 +1590,8 @@ init_function_local_offsets(WASMFunction *func,
uint32 i, local_offset = 0; uint32 i, local_offset = 0;
uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count); uint64 total_size = sizeof(uint16) * ((uint64)param_count + local_count);
if (total_size >= UINT32_MAX if (!(func->local_offsets =
|| !(func->local_offsets = wasm_runtime_malloc((uint32)total_size))) { loader_malloc(total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load function section failed: allocate memory failed.");
return false; return false;
} }
@ -1627,15 +1639,11 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
if (func_count) { if (func_count) {
module->function_count = func_count; module->function_count = func_count;
total_size = sizeof(WASMFunction*) * (uint64)func_count; total_size = sizeof(WASMFunction*) * (uint64)func_count;
if (total_size >= UINT32_MAX if (!(module->functions =
|| !(module->functions = wasm_runtime_malloc((uint32)total_size))) { loader_malloc(total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load function section failed: allocate memory failed.");
return false; return false;
} }
memset(module->functions, 0, (uint32)total_size);
for (i = 0; i < func_count; i++) { for (i = 0; i < func_count; i++) {
/* Resolve function type */ /* Resolve function type */
read_leb_uint32(p, p_end, type_index); read_leb_uint32(p, p_end, type_index);
@ -1680,17 +1688,12 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
code_size = (uint32)(p_code_end - p_code); code_size = (uint32)(p_code_end - p_code);
total_size = sizeof(WASMFunction) + (uint64)local_count; total_size = sizeof(WASMFunction) + (uint64)local_count;
if (total_size >= UINT32_MAX if (!(func = module->functions[i] =
|| !(func = module->functions[i] = loader_malloc(total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Load function section failed: "
"allocate memory failed.");
return false; return false;
} }
/* Set function type, local count, code size and code body */ /* Set function type, local count, code size and code body */
memset(func, 0, (uint32)total_size);
func->func_type = module->types[type_index]; func->func_type = module->types[type_index];
func->local_count = local_count; func->local_count = local_count;
if (local_count > 0) if (local_count > 0)
@ -1775,15 +1778,11 @@ load_table_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
if (table_count) { if (table_count) {
module->table_count = table_count; module->table_count = table_count;
total_size = sizeof(WASMTable) * (uint64)table_count; total_size = sizeof(WASMTable) * (uint64)table_count;
if (total_size >= UINT32_MAX if (!(module->tables = loader_malloc
|| !(module->tables = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load table section failed: allocate memory failed.");
return false; return false;
} }
memset(module->tables, 0, (uint32)total_size);
/* load each table */ /* load each table */
table = module->tables; table = module->tables;
for (i = 0; i < table_count; i++, table++) for (i = 0; i < table_count; i++, table++)
@ -1820,15 +1819,11 @@ load_memory_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
if (memory_count) { if (memory_count) {
module->memory_count = memory_count; module->memory_count = memory_count;
total_size = sizeof(WASMMemory) * (uint64)memory_count; total_size = sizeof(WASMMemory) * (uint64)memory_count;
if (total_size >= UINT32_MAX if (!(module->memories = loader_malloc
|| !(module->memories = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load memory section failed: allocate memory failed.");
return false; return false;
} }
memset(module->memories, 0, (uint32)total_size);
/* load each memory */ /* load each memory */
memory = module->memories; memory = module->memories;
for (i = 0; i < memory_count; i++, memory++) for (i = 0; i < memory_count; i++, memory++)
@ -1861,16 +1856,11 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
if (global_count) { if (global_count) {
module->global_count = global_count; module->global_count = global_count;
total_size = sizeof(WASMGlobal) * (uint64)global_count; total_size = sizeof(WASMGlobal) * (uint64)global_count;
if (total_size >= UINT32_MAX if (!(module->globals = loader_malloc
|| !(module->globals = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load global section failed: "
"allocate memory failed.");
return false; return false;
} }
memset(module->globals, 0, (uint32)total_size);
global = module->globals; global = module->globals;
for(i = 0; i < global_count; i++, global++) { for(i = 0; i < global_count; i++, global++) {
@ -1932,16 +1922,11 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
if (export_count) { if (export_count) {
module->export_count = export_count; module->export_count = export_count;
total_size = sizeof(WASMExport) * (uint64)export_count; total_size = sizeof(WASMExport) * (uint64)export_count;
if (total_size >= UINT32_MAX if (!(module->exports = loader_malloc
|| !(module->exports = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load export section failed: "
"allocate memory failed.");
return false; return false;
} }
memset(module->exports, 0, (uint32)total_size);
export = module->exports; export = module->exports;
for (i = 0; i < export_count; i++, export++) { for (i = 0; i < export_count; i++, export++) {
read_leb_uint32(p, p_end, str_len); read_leb_uint32(p, p_end, str_len);
@ -2038,16 +2023,11 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *m
if (table_segment_count) { if (table_segment_count) {
module->table_seg_count = table_segment_count; module->table_seg_count = table_segment_count;
total_size = sizeof(WASMTableSeg) * (uint64)table_segment_count; total_size = sizeof(WASMTableSeg) * (uint64)table_segment_count;
if (total_size >= UINT32_MAX if (!(module->table_segments = loader_malloc
|| !(module->table_segments = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load table segment section failed: "
"allocate memory failed.");
return false; return false;
} }
memset(module->table_segments, 0, (uint32)total_size);
table_segment = module->table_segments; table_segment = module->table_segments;
for (i = 0; i < table_segment_count; i++, table_segment++) { for (i = 0; i < table_segment_count; i++, table_segment++) {
if (p >= p_end) { if (p >= p_end) {
@ -2074,12 +2054,8 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *m
read_leb_uint32(p, p_end, function_count); read_leb_uint32(p, p_end, function_count);
table_segment->function_count = function_count; table_segment->function_count = function_count;
total_size = sizeof(uint32) * (uint64)function_count; total_size = sizeof(uint32) * (uint64)function_count;
if (total_size >= UINT32_MAX if (!(table_segment->func_indexes = (uint32 *)
|| !(table_segment->func_indexes = (uint32 *) loader_malloc(total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Load table segment section failed: "
"allocate memory failed.");
return false; return false;
} }
for (j = 0; j < function_count; j++) { for (j = 0; j < function_count; j++) {
@ -2134,16 +2110,11 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
if (data_seg_count) { if (data_seg_count) {
module->data_seg_count = data_seg_count; module->data_seg_count = data_seg_count;
total_size = sizeof(WASMDataSeg*) * (uint64)data_seg_count; total_size = sizeof(WASMDataSeg*) * (uint64)data_seg_count;
if (total_size >= UINT32_MAX if (!(module->data_segments = loader_malloc
|| !(module->data_segments = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load data segment section failed: "
"allocate memory failed.");
return false; return false;
} }
memset(module->data_segments, 0, (uint32)total_size);
for (i = 0; i < data_seg_count; i++) { for (i = 0; i < data_seg_count; i++) {
read_leb_uint32(p, p_end, mem_index); read_leb_uint32(p, p_end, mem_index);
#if WASM_ENABLE_BULK_MEMORY != 0 #if WASM_ENABLE_BULK_MEMORY != 0
@ -2157,7 +2128,6 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
/* no memory index, treat index as 0 */ /* no memory index, treat index as 0 */
mem_index = 0; mem_index = 0;
goto check_mem_index; goto check_mem_index;
break;
case 0x02: case 0x02:
/* read following memory index */ /* read following memory index */
read_leb_uint32(p, p_end, mem_index); read_leb_uint32(p, p_end, mem_index);
@ -2193,11 +2163,8 @@ check_mem_index:
read_leb_uint32(p, p_end, data_seg_len); read_leb_uint32(p, p_end, data_seg_len);
if (!(dataseg = module->data_segments[i] = if (!(dataseg = module->data_segments[i] = loader_malloc
wasm_runtime_malloc((uint32)sizeof(WASMDataSeg)))) { (sizeof(WASMDataSeg), error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Load data segment section failed: "
"allocate memory failed.");
return false; return false;
} }
@ -2477,18 +2444,19 @@ load_from_sections(WASMModule *module, WASMSection *sections,
#endif #endif
total_size = sizeof(BlockAddr) * (uint64)BLOCK_ADDR_CACHE_SIZE * BLOCK_ADDR_CONFLICT_SIZE; total_size = sizeof(BlockAddr) * (uint64)BLOCK_ADDR_CACHE_SIZE * BLOCK_ADDR_CONFLICT_SIZE;
if (total_size >= UINT32_MAX if (!(block_addr_cache = loader_malloc
|| !(block_addr_cache = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"WASM module load failed: allocate memory failed");
return false; return false;
} }
for (i = 0; i < module->function_count; i++) { for (i = 0; i < module->function_count; i++) {
WASMFunction *func = module->functions[i]; WASMFunction *func = module->functions[i];
memset(block_addr_cache, 0, (uint32)total_size); memset(block_addr_cache, 0, (uint32)total_size);
if (!wasm_loader_prepare_bytecode(module, func, block_addr_cache, error_buf, error_buf_size)) if (!wasm_loader_prepare_bytecode(module, func, block_addr_cache,
error_buf, error_buf_size)) {
wasm_runtime_free(block_addr_cache);
return false; return false;
}
} }
wasm_runtime_free(block_addr_cache); wasm_runtime_free(block_addr_cache);
@ -2616,17 +2584,13 @@ static void wasm_loader_free(void *ptr)
static WASMModule* static WASMModule*
create_module(char *error_buf, uint32 error_buf_size) create_module(char *error_buf, uint32 error_buf_size)
{ {
WASMModule *module = wasm_runtime_malloc(sizeof(WASMModule)); WASMModule *module = loader_malloc(sizeof(WASMModule),
error_buf, error_buf_size);
if (!module) { if (!module) {
set_error_buf(error_buf, error_buf_size,
"WASM module load failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(module, 0, sizeof(WASMModule));
module->module_type = Wasm_Module_Bytecode; module->module_type = Wasm_Module_Bytecode;
/* Set start_function to -1, means no start function */ /* Set start_function to -1, means no start function */
@ -2732,14 +2696,11 @@ create_sections(const uint8 *buf, uint32 size,
read_leb_uint32(p, p_end, section_size); read_leb_uint32(p, p_end, section_size);
CHECK_BUF1(p, p_end, section_size); CHECK_BUF1(p, p_end, section_size);
if (!(section = wasm_runtime_malloc(sizeof(WASMSection)))) { if (!(section = loader_malloc(sizeof(WASMSection),
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"WASM module load failed: "
"allocate memory failed.");
return false; return false;
} }
memset(section, 0, sizeof(WASMSection));
section->section_type = section_type; section->section_type = section_type;
section->section_body = (uint8*)p; section->section_body = (uint8*)p;
section->section_body_size = section_size; section->section_body_size = section_size;
@ -3416,16 +3377,12 @@ memory_realloc(void *mem_old, uint32 size_old, uint32 size_new,
{ {
uint8 *mem_new; uint8 *mem_new;
bh_assert(size_new > size_old); bh_assert(size_new > size_old);
if ((mem_new = wasm_runtime_malloc(size_new))) { if ((mem_new = loader_malloc
(size_new, error_buf, error_buf_size))) {
bh_memcpy_s(mem_new, size_new, mem_old, size_old); bh_memcpy_s(mem_new, size_new, mem_old, size_old);
memset(mem_new + size_old, 0, size_new - size_old); memset(mem_new + size_old, 0, size_new - size_old);
wasm_runtime_free(mem_old); wasm_runtime_free(mem_old);
} }
else {
set_error_buf(error_buf, error_buf_size,
"WASM loader prepare bytecode failed: "
"allocate memory failed.");
}
return mem_new; return mem_new;
} }
@ -3485,7 +3442,8 @@ check_offset_pop(WASMLoaderContext *ctx, uint32 cells)
return true; return true;
} }
static void free_label_patch_list(BranchBlock *frame_csp) static void
free_label_patch_list(BranchBlock *frame_csp)
{ {
BranchBlockPatch *label_patch = frame_csp->patch_list; BranchBlockPatch *label_patch = frame_csp->patch_list;
BranchBlockPatch *next; BranchBlockPatch *next;
@ -3497,7 +3455,8 @@ static void free_label_patch_list(BranchBlock *frame_csp)
frame_csp->patch_list = NULL; frame_csp->patch_list = NULL;
} }
static void free_all_label_patch_lists(BranchBlock *frame_csp, uint32 csp_num) static void
free_all_label_patch_lists(BranchBlock *frame_csp, uint32 csp_num)
{ {
BranchBlock *tmp_csp = frame_csp; BranchBlock *tmp_csp = frame_csp;
@ -3525,7 +3484,6 @@ fail:
return false; return false;
} }
static bool static bool
check_stack_top_values(uint8 *frame_ref, int32 stack_cell_num, uint8 type, check_stack_top_values(uint8 *frame_ref, int32 stack_cell_num, uint8 type,
char *error_buf, uint32 error_buf_size) char *error_buf, uint32 error_buf_size)
@ -3580,7 +3538,8 @@ check_stack_pop(WASMLoaderContext *ctx, uint8 type,
return true; return true;
} }
static void wasm_loader_ctx_destroy(WASMLoaderContext *ctx) static void
wasm_loader_ctx_destroy(WASMLoaderContext *ctx)
{ {
if (ctx) { if (ctx) {
if (ctx->frame_ref_bottom) if (ctx->frame_ref_bottom)
@ -4055,11 +4014,9 @@ add_label_patch_to_list(BranchBlock *frame_csp,
uint8 patch_type, uint8 *p_code_compiled, uint8 patch_type, uint8 *p_code_compiled,
char *error_buf, uint32 error_buf_size) char *error_buf, uint32 error_buf_size)
{ {
BranchBlockPatch *patch = wasm_runtime_malloc(sizeof(BranchBlockPatch)); BranchBlockPatch *patch = loader_malloc
(sizeof(BranchBlockPatch), error_buf, error_buf_size);
if (!patch) { if (!patch) {
set_error_buf(error_buf, error_buf_size,
"WASM loader prepare bytecode failed: "
"allocate memory failed");
return false; return false;
} }
patch->patch_type = patch_type; patch->patch_type = patch_type;
@ -5505,7 +5462,7 @@ re_scan:
case WASM_OP_SET_GLOBAL: case WASM_OP_SET_GLOBAL:
{ {
bool is_multable = false; bool is_mutable = false;
read_leb_uint32(p, p_end, global_idx); read_leb_uint32(p, p_end, global_idx);
if (global_idx >= global_count) { if (global_idx >= global_count) {
set_error_buf(error_buf, error_buf_size, set_error_buf(error_buf, error_buf_size,
@ -5514,12 +5471,12 @@ re_scan:
goto fail; goto fail;
} }
is_multable = is_mutable =
global_idx < module->import_global_count global_idx < module->import_global_count
? module->import_globals[global_idx].u.global.is_mutable ? module->import_globals[global_idx].u.global.is_mutable
: module->globals[global_idx - module->import_global_count] : module->globals[global_idx - module->import_global_count]
.is_mutable; .is_mutable;
if (!is_multable) { if (!is_mutable) {
set_error_buf(error_buf, set_error_buf(error_buf,
error_buf_size, error_buf_size,
"global is immutable"); "global is immutable");
@ -5772,8 +5729,6 @@ re_scan:
POP2_AND_PUSH(VALUE_TYPE_F64, VALUE_TYPE_I32); POP2_AND_PUSH(VALUE_TYPE_F64, VALUE_TYPE_I32);
break; break;
break;
case WASM_OP_I32_CLZ: case WASM_OP_I32_CLZ:
case WASM_OP_I32_CTZ: case WASM_OP_I32_CTZ:
case WASM_OP_I32_POPCNT: case WASM_OP_I32_POPCNT:
@ -6092,13 +6047,10 @@ fail_data_cnt_sec_require:
func->const_cell_num = loader_ctx->const_cell_num; func->const_cell_num = loader_ctx->const_cell_num;
if (!(func->consts = func_const = if (!(func->consts = func_const =
wasm_runtime_malloc(func->const_cell_num * 4))) { loader_malloc(func->const_cell_num * 4,
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"WASM loader prepare bytecode failed: "
"allocate memory failed");
goto fail; goto fail;
} }
memset(func->consts, 0, func->const_cell_num * 4);
func_const_end = func->consts + func->const_cell_num * 4; func_const_end = func->consts + func->const_cell_num * 4;
// reverse the const buf // reverse the const buf
for (int i = loader_ctx->num_const - 1; i >= 0; i--) { for (int i = loader_ctx->num_const - 1; i >= 0; i--) {

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,23 @@ wasm_unload(WASMModule *module)
wasm_loader_unload(module); wasm_loader_unload(module);
} }
static void *
runtime_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
{
void *mem;
if (size >= UINT32_MAX
|| !(mem = wasm_runtime_malloc((uint32)size))) {
set_error_buf(error_buf, error_buf_size,
"WASM module instantiate failed: "
"allocate memory failed.");
return NULL;
}
memset(mem, 0, (uint32)size);
return mem;
}
#if WASM_ENABLE_MULTI_MODULE != 0 #if WASM_ENABLE_MULTI_MODULE != 0
static WASMModuleInstance * static WASMModuleInstance *
get_sub_module_inst(const WASMModuleInstance *parent_module_inst, get_sub_module_inst(const WASMModuleInstance *parent_module_inst,
@ -93,14 +110,11 @@ memory_instantiate(uint32 num_bytes_per_page,
num_bytes_per_page * (uint64)init_page_count; num_bytes_per_page * (uint64)init_page_count;
/* Allocate memory space, addr data and global data */ /* Allocate memory space, addr data and global data */
if (total_size >= UINT32_MAX if (!(memory = runtime_malloc(total_size,
|| !(memory = wasm_runtime_malloc((uint32)total_size))) { error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate memory failed: allocate memory failed.");
return NULL; return NULL;
} }
memset(memory, 0, (uint32)total_size);
memory->num_bytes_per_page = num_bytes_per_page; memory->num_bytes_per_page = num_bytes_per_page;
memory->cur_page_count = init_page_count; memory->cur_page_count = init_page_count;
memory->max_page_count = max_page_count; memory->max_page_count = max_page_count;
@ -144,16 +158,11 @@ memories_instantiate(const WASMModule *module,
total_size = sizeof(WASMMemoryInstance*) * (uint64)memory_count; total_size = sizeof(WASMMemoryInstance*) * (uint64)memory_count;
if (total_size >= UINT32_MAX if (!(memories = runtime_malloc(total_size,
|| !(memories = wasm_runtime_malloc((uint32)total_size))) { error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate memory failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(memories, 0, (uint32)total_size);
/* instantiate memories from import section */ /* instantiate memories from import section */
import = module->import_memories; import = module->import_memories;
for (i = 0; i < module->import_memory_count; i++, import++) { for (i = 0; i < module->import_memory_count; i++, import++) {
@ -271,16 +280,11 @@ tables_instantiate(const WASMModule *module,
uint64 total_size = sizeof(WASMTableInstance*) * (uint64)table_count; uint64 total_size = sizeof(WASMTableInstance*) * (uint64)table_count;
WASMTableInstance **tables, *table; WASMTableInstance **tables, *table;
if (total_size >= UINT32_MAX if (!(tables = runtime_malloc(total_size,
|| !(tables = wasm_runtime_malloc((uint32)total_size))) { error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate table failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(tables, 0, (uint32)total_size);
/* instantiate tables from import section */ /* instantiate tables from import section */
import = module->import_tables; import = module->import_tables;
for (i = 0; i < module->import_table_count; i++, import++) { for (i = 0; i < module->import_table_count; i++, import++) {
@ -310,12 +314,8 @@ tables_instantiate(const WASMModule *module,
+ sizeof(uint32) * (uint64)import->u.table.init_size; + sizeof(uint32) * (uint64)import->u.table.init_size;
} }
if (total_size >= UINT32_MAX if (!(table = tables[table_index++] = runtime_malloc
|| !(table = tables[table_index++] = (total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate table failed: "
"allocate memory failed.");
tables_deinstantiate(tables, table_count); tables_deinstantiate(tables, table_count);
return NULL; return NULL;
} }
@ -342,12 +342,8 @@ tables_instantiate(const WASMModule *module,
for (i = 0; i < module->table_count; i++) { for (i = 0; i < module->table_count; i++) {
total_size = offsetof(WASMTableInstance, base_addr) + total_size = offsetof(WASMTableInstance, base_addr) +
sizeof(uint32) * (uint64)module->tables[i].init_size; sizeof(uint32) * (uint64)module->tables[i].init_size;
if (total_size >= UINT32_MAX if (!(table = tables[table_index++] = runtime_malloc
|| !(table = tables[table_index++] = (total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate table failed: "
"allocate memory failed.");
tables_deinstantiate(tables, table_count); tables_deinstantiate(tables, table_count);
return NULL; return NULL;
} }
@ -392,16 +388,11 @@ functions_instantiate(const WASMModule *module,
uint64 total_size = sizeof(WASMFunctionInstance) * (uint64)function_count; uint64 total_size = sizeof(WASMFunctionInstance) * (uint64)function_count;
WASMFunctionInstance *functions, *function; WASMFunctionInstance *functions, *function;
if (total_size >= UINT32_MAX if (!(functions = runtime_malloc(total_size,
|| !(functions = wasm_runtime_malloc((uint32)total_size))) { error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate function failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(functions, 0, (uint32)total_size);
/* instantiate functions from import section */ /* instantiate functions from import section */
function = functions; function = functions;
import = module->import_functions; import = module->import_functions;
@ -555,16 +546,11 @@ globals_instantiate(const WASMModule *module,
uint64 total_size = sizeof(WASMGlobalInstance) * (uint64)global_count; uint64 total_size = sizeof(WASMGlobalInstance) * (uint64)global_count;
WASMGlobalInstance *globals, *global; WASMGlobalInstance *globals, *global;
if (total_size >= UINT32_MAX if (!(globals = runtime_malloc(total_size,
|| !(globals = wasm_runtime_malloc((uint32)total_size))) { error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate global failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(globals, 0, (uint32)total_size);
/* instantiate globals from import section */ /* instantiate globals from import section */
global = globals; global = globals;
import = module->import_globals; import = module->import_globals;
@ -727,16 +713,11 @@ export_functions_instantiate(const WASMModule *module,
uint32 i; uint32 i;
uint64 total_size = sizeof(WASMExportFuncInstance) * (uint64)export_func_count; uint64 total_size = sizeof(WASMExportFuncInstance) * (uint64)export_func_count;
if (total_size >= UINT32_MAX if (!(export_func = export_funcs = runtime_malloc
|| !(export_func = export_funcs = wasm_runtime_malloc((uint32)total_size))) { (total_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate export function failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(export_funcs, 0, (uint32)total_size);
for (i = 0; i < module->export_count; i++, export++) for (i = 0; i < module->export_count; i++, export++)
if (export->kind == EXPORT_KIND_FUNC) { if (export->kind == EXPORT_KIND_FUNC) {
export_func->name = export->name; export_func->name = export->name;
@ -767,17 +748,11 @@ export_globals_instantiate(const WASMModule *module,
uint32 i; uint32 i;
uint64 total_size = sizeof(WASMExportGlobInstance) * (uint64)export_glob_count; uint64 total_size = sizeof(WASMExportGlobInstance) * (uint64)export_glob_count;
if (total_size >= UINT32_MAX if (!(export_global = export_globals = runtime_malloc
|| !(export_global = export_globals = (total_size, error_buf, error_buf_size))) {
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate export global failed: "
"allocate memory failed.");
return NULL; return NULL;
} }
memset(export_globals, 0, (uint32)total_size);
for (i = 0; i < module->export_count; i++, export++) for (i = 0; i < module->export_count; i++, export++)
if (export->kind == EXPORT_KIND_GLOBAL) { if (export->kind == EXPORT_KIND_GLOBAL) {
export_global->name = export->name; export_global->name = export->name;
@ -853,12 +828,11 @@ sub_module_instantiate(WASMModule *module, WASMModuleInstance *module_inst,
return false; return false;
} }
WASMSubModInstNode *sub_module_inst_list_node = WASMSubModInstNode *sub_module_inst_list_node = runtime_malloc
wasm_runtime_malloc(sizeof(WASMSubModInstNode)); (sizeof(WASMSubModInstNode), error_buf, error_buf_size);
if (!sub_module_inst_list_node) { if (!sub_module_inst_list_node) {
LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d", LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d",
sizeof(WASMSubModInstNode)); sizeof(WASMSubModInstNode));
set_error_buf_v(error_buf, error_buf_size, "malloc failed");
wasm_deinstantiate(sub_module_inst); wasm_deinstantiate(sub_module_inst);
return false; return false;
} }
@ -921,9 +895,8 @@ wasm_instantiate(WASMModule *module,
heap_size = APP_HEAP_SIZE_MAX; heap_size = APP_HEAP_SIZE_MAX;
/* Allocate the memory */ /* Allocate the memory */
if (!(module_inst = wasm_runtime_malloc((uint32)sizeof(WASMModuleInstance)))) { if (!(module_inst = runtime_malloc(sizeof(WASMModuleInstance),
set_error_buf(error_buf, error_buf_size, error_buf, error_buf_size))) {
"Instantiate module failed: allocate memory failed.");
return NULL; return NULL;
} }
@ -971,12 +944,11 @@ wasm_instantiate(WASMModule *module,
#endif #endif
if (global_count > 0) { if (global_count > 0) {
if (!(module_inst->global_data = if (!(module_inst->global_data = runtime_malloc
wasm_runtime_malloc(global_data_size))) { (global_data_size, error_buf, error_buf_size))) {
wasm_deinstantiate(module_inst); wasm_deinstantiate(module_inst);
return NULL; return NULL;
} }
memset(module_inst->global_data, 0, global_data_size);
} }
/* Instantiate memories/tables/functions */ /* Instantiate memories/tables/functions */
@ -1546,13 +1518,17 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
return false; return false;
} }
/* Destroy heap's lock firstly, if its memory is re-allocated, if (heap_size > 0) {
we cannot access its lock again. */ /* Destroy heap's lock firstly, if its memory is re-allocated,
mem_allocator_destroy_lock(memory->heap_handle); we cannot access its lock again. */
mem_allocator_destroy_lock(memory->heap_handle);
}
if (!(new_memory = wasm_runtime_realloc(memory, (uint32)total_size))) { if (!(new_memory = wasm_runtime_realloc(memory, (uint32)total_size))) {
if (!(new_memory = wasm_runtime_malloc((uint32)total_size))) { if (!(new_memory = wasm_runtime_malloc((uint32)total_size))) {
/* Restore heap's lock if memory re-alloc failed */ if (heap_size > 0) {
mem_allocator_reinit_lock(memory->heap_handle); /* Restore heap's lock if memory re-alloc failed */
mem_allocator_reinit_lock(memory->heap_handle);
}
wasm_set_exception(module, "fail to enlarge memory."); wasm_set_exception(module, "fail to enlarge memory.");
return false; return false;
} }
@ -1564,12 +1540,14 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
memset((uint8*)new_memory + total_size_old, memset((uint8*)new_memory + total_size_old,
0, (uint32)total_size - total_size_old); 0, (uint32)total_size - total_size_old);
new_memory->heap_handle = (uint8*)heap_handle_old + if (heap_size > 0) {
((uint8*)new_memory - (uint8*)memory); new_memory->heap_handle = (uint8*)heap_handle_old +
if (mem_allocator_migrate(new_memory->heap_handle, ((uint8*)new_memory - (uint8*)memory);
heap_handle_old) != 0) { if (mem_allocator_migrate(new_memory->heap_handle,
wasm_set_exception(module, "fail to enlarge memory."); heap_handle_old) != 0) {
return false; wasm_set_exception(module, "fail to enlarge memory.");
return false;
}
} }
new_memory->cur_page_count = total_page_count; new_memory->cur_page_count = total_page_count;
@ -1582,7 +1560,6 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
return true; return true;
} }
bool bool
wasm_call_indirect(WASMExecEnv *exec_env, wasm_call_indirect(WASMExecEnv *exec_env,
uint32_t element_indices, uint32_t element_indices,
@ -1599,7 +1576,7 @@ wasm_call_indirect(WASMExecEnv *exec_env,
table_inst = module_inst->default_table; table_inst = module_inst->default_table;
if (!table_inst) { if (!table_inst) {
wasm_set_exception(module_inst, "there is no table"); wasm_set_exception(module_inst, "unknown table");
goto got_exception; goto got_exception;
} }

View File

@ -52,6 +52,11 @@ The script `runtime_lib.cmake` defined a number of variables for configuring the
- **WAMR_BUILD_MULTI_MODULE**=1/0, default to disable if not set - **WAMR_BUILD_MULTI_MODULE**=1/0, default to disable if not set
#### **Enable WASM mini loader**
- **WAMR_BUILD_MINI_LOADER**=1/0, default to disable if not set
Note: the mini loader doesn't check the integrity of the WASM binary file, user must ensure that the WASM file is not mal-formed.
**Combination of configurations:** **Combination of configurations:**
We can combine the configurations. For example, if we want to disable interpreter, enable AOT and WASI, we can run command: We can combine the configurations. For example, if we want to disable interpreter, enable AOT and WASI, we can run command:

View File

@ -65,17 +65,8 @@ set (APP_FRAMEWORK_DIR ${WAMR_ROOT_DIR}/core/app-framework)
# include the build config template file # include the build config template file
include (${WAMR_ROOT_DIR}/build-scripts/config_common.cmake) include (${WAMR_ROOT_DIR}/build-scripts/config_common.cmake)
if ("$ENV{SGX_SDK}" STREQUAL "")
set (SGX_SDK_DIR "/opt/intel/sgxsdk")
else()
set (SGX_SDK_DIR $ENV{SGX_SDK})
endif()
include_directories (${SHARED_DIR}/include include_directories (${SHARED_DIR}/include
${IWASM_DIR}/include ${IWASM_DIR}/include)
${SGX_SDK_DIR}/include
${SGX_SDK_DIR}/include/tlibc
${SGX_SDK_DIR}/include/libcxx)
enable_language (ASM) enable_language (ASM)

View File

@ -65,6 +65,11 @@ if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
set (WAMR_BUILD_MULTI_MODULE 0) set (WAMR_BUILD_MULTI_MODULE 0)
endif () endif ()
if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
# Disable wasm mini loader by default
set (WAMR_BUILD_MINI_LOADER 0)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)