Refactor error/exception strings to reduce binary size (#359)
This commit is contained in:
@ -19,8 +19,26 @@
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
{
|
||||
if (error_buf != NULL)
|
||||
snprintf(error_buf, error_buf_size, "%s", string);
|
||||
if (error_buf != NULL) {
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: %s", string);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_error_buf_v(char *error_buf, uint32 error_buf_size,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[128];
|
||||
|
||||
if (error_buf != NULL) {
|
||||
va_start(args, format);
|
||||
vsnprintf(buf, sizeof(buf), format, args);
|
||||
va_end(args);
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: %s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
#define exchange_uint8(p_data) (void)0
|
||||
@ -64,8 +82,7 @@ check_buf(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,
|
||||
"AOT module load failed: unexpect end.");
|
||||
set_error_buf(error_buf, error_buf_size, "unexpect end");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -169,8 +186,7 @@ loader_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
|
||||
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.");
|
||||
"allocate memory failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -200,8 +216,7 @@ const_str_set_insert(const uint8 *str, int32 len, AOTModule *module,
|
||||
|
||||
if (!bh_hash_map_insert(set, c_str, c_str)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"insert string to hash map failed.");
|
||||
"insert string to hash map failed");
|
||||
wasm_runtime_free(c_str);
|
||||
return NULL;
|
||||
}
|
||||
@ -233,18 +248,15 @@ get_aot_file_target(AOTTargetInfo *target_info,
|
||||
machine_type = "xtensa";
|
||||
break;
|
||||
default:
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: unknown machine type %d.",
|
||||
target_info->e_machine);
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"unknown machine type %d",
|
||||
target_info->e_machine);
|
||||
return false;
|
||||
}
|
||||
if (strncmp(target_info->arch, machine_type, strlen(machine_type))) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"machine type (%s) isn't consistent with target type (%s).",
|
||||
machine_type, target_info->arch);
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"machine type (%s) isn't consistent with target type (%s)",
|
||||
machine_type, target_info->arch);
|
||||
return false;
|
||||
}
|
||||
snprintf(target_buf, target_buf_size, "%s", target_info->arch);
|
||||
@ -264,12 +276,9 @@ check_machine_info(AOTTargetInfo *target_info,
|
||||
return false;
|
||||
|
||||
if (strcmp(target_expected, target_got)) {
|
||||
if (error_buf) {
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid target type, "
|
||||
"expected %s but got %s.",
|
||||
target_expected, target_got);
|
||||
}
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"invalid target type, expected %s but got %s",
|
||||
target_expected, target_got);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -297,39 +306,35 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (p != buf_end) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid section size.");
|
||||
"invalid section size");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check target endian type */
|
||||
is_target_little_endian = target_info.bin_type & 1 ? false : true;
|
||||
if (is_little_endian() != is_target_little_endian) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid target endian type, expected %s but got %s.",
|
||||
is_little_endian() ? "little endian" : "big endian",
|
||||
is_target_little_endian ? "little endian" : "big endian");
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"invalid target endian type, expected %s but got %s",
|
||||
is_little_endian() ? "little endian" : "big endian",
|
||||
is_target_little_endian ? "little endian" : "big endian");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check target bit width */
|
||||
is_target_64_bit = target_info.bin_type & 2 ? true : false;
|
||||
if ((sizeof(void*) == 8 ? true : false) != is_target_64_bit) {
|
||||
if (error_buf)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid target bit width, expected %s but got %s.",
|
||||
sizeof(void*) == 8 ? "64-bit" : "32-bit",
|
||||
is_target_64_bit ? "64-bit" : "32-bit");
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"invalid target bit width, expected %s but got %s",
|
||||
sizeof(void*) == 8 ? "64-bit" : "32-bit",
|
||||
is_target_64_bit ? "64-bit" : "32-bit");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check target elf file type */
|
||||
if (target_info.e_type != E_TYPE_REL) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid object file type, "
|
||||
"expected relocatable file type but got others.");
|
||||
"invalid object file type, "
|
||||
"expected relocatable file type but got others");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -340,7 +345,7 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (target_info.e_version != E_VERSION_CURRENT) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid elf file version.");
|
||||
"invalid elf file version");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -639,7 +644,6 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end,
|
||||
|
||||
if (param_count > UINT16_MAX || result_count > UINT16_MAX) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"param count or result count too large");
|
||||
return false;
|
||||
}
|
||||
@ -660,7 +664,6 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end,
|
||||
result_count);
|
||||
if (param_cell_num > UINT16_MAX || ret_cell_num > UINT16_MAX) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"param count or result count too large");
|
||||
return false;
|
||||
}
|
||||
@ -866,8 +869,7 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end,
|
||||
for (i = 0; i < module->import_func_count; i++) {
|
||||
read_uint16(buf, buf_end, import_funcs[i].func_type_index);
|
||||
if (import_funcs[i].func_type_index >= module->func_type_count) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: unknown type.");
|
||||
set_error_buf(error_buf, error_buf_size, "unknown type");
|
||||
return false;
|
||||
}
|
||||
import_funcs[i].func_type = module->func_types[import_funcs[i].func_type_index];
|
||||
@ -967,8 +969,7 @@ load_object_data_sections(const uint8 **p_buf, const uint8 *buf_end,
|
||||
if (!(data_sections[i].data =
|
||||
os_mmap(NULL, data_sections[i].size, map_prot, map_flags))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"allocate memory failed.");
|
||||
"allocate memory failed");
|
||||
return false;
|
||||
}
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
||||
@ -1034,7 +1035,6 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,
|
||||
&& (module->start_func_index >= module->import_func_count
|
||||
+ module->func_count)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid start function index");
|
||||
return false;
|
||||
}
|
||||
@ -1053,7 +1053,6 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (p != p_end) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid init data section size");
|
||||
return false;
|
||||
}
|
||||
@ -1073,7 +1072,7 @@ load_text_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (module->func_count > 0 && buf_end == buf) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid code size.");
|
||||
"invalid code size");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1120,8 +1119,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||
}
|
||||
if (text_offset >= module->code_size) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid function code offset.");
|
||||
"invalid function code offset");
|
||||
return false;
|
||||
}
|
||||
module->func_ptrs[i] = (uint8*)module->code + text_offset;
|
||||
@ -1154,15 +1152,13 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||
for (i = 0; i < module->func_count; i++) {
|
||||
read_uint32(p, p_end, module->func_type_indexes[i]);
|
||||
if (module->func_type_indexes[i] >= module->func_type_count) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: unknown type.");
|
||||
set_error_buf(error_buf, error_buf_size, "unknown type");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (p != buf_end) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid function section size");
|
||||
return false;
|
||||
}
|
||||
@ -1204,8 +1200,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end,
|
||||
if (export_funcs[i].index >=
|
||||
module->func_count + module->import_func_count) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"function index is out of range.");
|
||||
"function index is out of range");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@ -1232,7 +1227,6 @@ load_export_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (p != p_end) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid export section size");
|
||||
return false;
|
||||
}
|
||||
@ -1299,7 +1293,7 @@ do_text_relocation(AOTModule *module,
|
||||
|
||||
if (group->relocation_count > 0 && !aot_text) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid text relocation count.");
|
||||
"invalid text relocation count");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1321,11 +1315,8 @@ do_text_relocation(AOTModule *module,
|
||||
p = symbol + strlen(AOT_FUNC_PREFIX);
|
||||
if (*p == '\0'
|
||||
|| (func_index = (uint32)atoi(p)) > module->func_count) {
|
||||
if (error_buf != NULL)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid import symbol %s.",
|
||||
symbol);
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"invalid import symbol %s", symbol);
|
||||
goto check_symbol_fail;
|
||||
}
|
||||
symbol_addr = module->func_ptrs[func_index];
|
||||
@ -1339,11 +1330,8 @@ do_text_relocation(AOTModule *module,
|
||||
|| !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst"))) {
|
||||
symbol_addr = get_data_section_addr(module, symbol, NULL);
|
||||
if (!symbol_addr) {
|
||||
if (error_buf != NULL)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid data section (%s).",
|
||||
symbol);
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"invalid data section (%s)", symbol);
|
||||
goto check_symbol_fail;
|
||||
}
|
||||
}
|
||||
@ -1351,11 +1339,8 @@ do_text_relocation(AOTModule *module,
|
||||
symbol_addr = module->literal;
|
||||
}
|
||||
else if (!(symbol_addr = resolve_target_sym(symbol, &symbol_index))) {
|
||||
if (error_buf != NULL)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"resolve symbol %s failed.",
|
||||
symbol);
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"resolve symbol %s failed", symbol);
|
||||
goto check_symbol_fail;
|
||||
}
|
||||
|
||||
@ -1400,8 +1385,7 @@ do_data_relocation(AOTModule *module,
|
||||
}
|
||||
else {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid data relocation section name.");
|
||||
"invalid data relocation section name");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1409,7 +1393,7 @@ do_data_relocation(AOTModule *module,
|
||||
&data_size);
|
||||
if (group->relocation_count > 0 && !data_addr) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid data relocation count.");
|
||||
"invalid data relocation count");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1419,11 +1403,8 @@ do_data_relocation(AOTModule *module,
|
||||
symbol_addr = module->code;
|
||||
}
|
||||
else {
|
||||
if (error_buf != NULL)
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"invalid relocation symbol %s.",
|
||||
symbol);
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"invalid relocation symbol %s", symbol);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1494,8 +1475,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||
symbol_offsets, symbol_count,
|
||||
error_buf, error_buf_size)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"validate symbol table failed.");
|
||||
"validate symbol table failed");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -1521,8 +1501,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (name_index >= symbol_count) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"symbol index out of range.");
|
||||
"symbol index out of range");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -1568,8 +1547,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||
|
||||
if (symbol_index >= symbol_count) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"symbol index out of range.");
|
||||
"symbol index out of range");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -1630,7 +1608,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
|
||||
|| (last_section_type != (uint32)-1
|
||||
&& section_type != last_section_type + 1)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid section order.");
|
||||
"invalid section order");
|
||||
return false;
|
||||
}
|
||||
last_section_type = section_type;
|
||||
@ -1672,7 +1650,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
|
||||
|
||||
if (last_section_type != AOT_SECTION_TYPE_RELOCATION) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: section missing.");
|
||||
"section missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1747,8 +1725,7 @@ create_module(char *error_buf, uint32 error_buf_size)
|
||||
NULL,
|
||||
aot_free))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"create const string set failed.");
|
||||
"create const string set failed");
|
||||
wasm_runtime_free(module);
|
||||
return NULL;
|
||||
}
|
||||
@ -1838,8 +1815,7 @@ create_sections(const uint8 *buf, uint32 size,
|
||||
map_prot, map_flags))) {
|
||||
wasm_runtime_free(section);
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"mmap memory failed.");
|
||||
"mmap memory failed");
|
||||
goto fail;
|
||||
}
|
||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
||||
@ -1874,14 +1850,14 @@ create_sections(const uint8 *buf, uint32 size,
|
||||
}
|
||||
else {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: invalid section id.");
|
||||
"invalid section id");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (!section_list) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: create section list failed.");
|
||||
"create section list failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2032,7 +2008,7 @@ aot_load_from_comp_data(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||
(void *)LLVMGetFunctionAddress(comp_ctx->exec_engine,
|
||||
func_name))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Get function address fail.");
|
||||
"get function address failed");
|
||||
goto fail3;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,8 +13,10 @@
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
{
|
||||
if (error_buf != NULL)
|
||||
snprintf(error_buf, error_buf_size, "%s", string);
|
||||
if (error_buf != NULL) {
|
||||
snprintf(error_buf, error_buf_size,
|
||||
"AOT module instantiate failed: %s", string);
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
@ -25,8 +27,7 @@ runtime_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
|
||||
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.");
|
||||
"allocate memory failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -60,8 +61,7 @@ global_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||
switch (init_expr->init_expr_type) {
|
||||
case INIT_EXPR_TYPE_GET_GLOBAL:
|
||||
if (init_expr->u.global_index >= module->import_global_count + i) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate global failed: unknown global.");
|
||||
set_error_buf(error_buf, error_buf_size, "unknown global");
|
||||
return false;
|
||||
}
|
||||
memcpy(p,
|
||||
@ -333,14 +333,12 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(p = mapped_mem = os_mmap(NULL, map_size,
|
||||
MMAP_PROT_NONE, MMAP_MAP_NONE))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module instantiate failed: mmap memory failed.");
|
||||
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (os_mprotect(p, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module instantiate failed: mprotec memory failed.");
|
||||
set_error_buf(error_buf, error_buf_size, "mprotec memory failed");
|
||||
os_munmap(mapped_mem, map_size);
|
||||
return NULL;
|
||||
}
|
||||
@ -364,8 +362,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||
if (!(heap_handle = mem_allocator_create(memory_inst->heap_data.ptr,
|
||||
heap_size))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module instantiate failed:"
|
||||
"init app heap failed.");
|
||||
"init app heap failed");
|
||||
goto fail1;
|
||||
}
|
||||
memory_inst->heap_handle.ptr = heap_handle;
|
||||
@ -392,8 +389,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||
if (!shared_memory_set_memory_inst((WASMModuleCommon *)module,
|
||||
(WASMMemoryInstanceCommon *)memory_inst)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"Instantiate memory failed:"
|
||||
"allocate memory failed.");
|
||||
"allocate memory failed");
|
||||
goto fail2;
|
||||
}
|
||||
}
|
||||
@ -659,7 +655,7 @@ execute_start_function(AOTModuleInstance *module_inst)
|
||||
|
||||
if (!(exec_env = wasm_exec_env_create((WASMModuleInstanceCommon*)module_inst,
|
||||
module_inst->default_wasm_stack_size))) {
|
||||
aot_set_exception(module_inst, "allocate memory failed.");
|
||||
aot_set_exception(module_inst, "allocate memory failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -988,7 +984,7 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
|
||||
|
||||
if (aot_exec_env
|
||||
&& (aot_exec_env != exec_env)) {
|
||||
aot_set_exception(module_inst, "Invalid exec env.");
|
||||
aot_set_exception(module_inst, "invalid exec env");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -999,7 +995,7 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
|
||||
/* First time to call aot function, protect one page */
|
||||
if (os_mprotect(stack_min_addr, page_size * guard_page_count,
|
||||
MMAP_PROT_NONE) != 0) {
|
||||
aot_set_exception(module_inst, "Set protected page failed.");
|
||||
aot_set_exception(module_inst, "set protected page failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1132,7 +1128,7 @@ aot_create_exec_env_and_call_function(AOTModuleInstance *module_inst,
|
||||
|
||||
if (!(exec_env = wasm_exec_env_create((WASMModuleInstanceCommon*)module_inst,
|
||||
module_inst->default_wasm_stack_size))) {
|
||||
aot_set_exception(module_inst, "allocate memory failed.");
|
||||
aot_set_exception(module_inst, "allocate memory failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1471,12 +1467,10 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
|
||||
|
||||
if (total_page_count < cur_page_count /* integer overflow */
|
||||
|| total_page_count > max_page_count) {
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (total_size >= UINT32_MAX) {
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1501,7 +1495,6 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
|
||||
/* Restore heap's lock if memory re-alloc failed */
|
||||
mem_allocator_reinit_lock(memory_inst->heap_handle.ptr);
|
||||
}
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
bh_memcpy_s(memory_data, (uint32)total_size,
|
||||
@ -1522,7 +1515,6 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
|
||||
+ (memory_data - memory_data_old);
|
||||
if (mem_allocator_migrate(memory_inst->heap_handle.ptr,
|
||||
heap_handle_old) != 0) {
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1562,14 +1554,12 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
|
||||
|
||||
if (total_page_count < cur_page_count /* integer overflow */
|
||||
|| total_page_count > max_page_count) {
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (os_mprotect(memory_inst->memory_data_end.ptr,
|
||||
num_bytes_per_page * inc_page_count,
|
||||
MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user