mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
Refactor error/exception strings to reduce binary size (#359)
This commit is contained in:
parent
89d2937cde
commit
0103f6429c
|
@ -19,8 +19,26 @@
|
||||||
static void
|
static void
|
||||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||||
{
|
{
|
||||||
if (error_buf != NULL)
|
if (error_buf != NULL) {
|
||||||
snprintf(error_buf, error_buf_size, "%s", string);
|
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
|
#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)
|
char *error_buf, uint32 error_buf_size)
|
||||||
{
|
{
|
||||||
if (buf + length > buf_end) {
|
if (buf + length > buf_end) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unexpect end");
|
||||||
"AOT module load failed: unexpect end.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -169,8 +186,7 @@ loader_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
|
||||||
if (size >= UINT32_MAX
|
if (size >= UINT32_MAX
|
||||||
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
return NULL;
|
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)) {
|
if (!bh_hash_map_insert(set, c_str, c_str)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
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);
|
wasm_runtime_free(c_str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -233,18 +248,15 @@ get_aot_file_target(AOTTargetInfo *target_info,
|
||||||
machine_type = "xtensa";
|
machine_type = "xtensa";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (error_buf)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"unknown machine type %d",
|
||||||
"AOT module load failed: unknown machine type %d.",
|
target_info->e_machine);
|
||||||
target_info->e_machine);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strncmp(target_info->arch, machine_type, strlen(machine_type))) {
|
if (strncmp(target_info->arch, machine_type, strlen(machine_type))) {
|
||||||
if (error_buf)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"machine type (%s) isn't consistent with target type (%s)",
|
||||||
"AOT module load failed: "
|
machine_type, target_info->arch);
|
||||||
"machine type (%s) isn't consistent with target type (%s).",
|
|
||||||
machine_type, target_info->arch);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
snprintf(target_buf, target_buf_size, "%s", target_info->arch);
|
snprintf(target_buf, target_buf_size, "%s", target_info->arch);
|
||||||
|
@ -264,12 +276,9 @@ check_machine_info(AOTTargetInfo *target_info,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (strcmp(target_expected, target_got)) {
|
if (strcmp(target_expected, target_got)) {
|
||||||
if (error_buf) {
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"invalid target type, expected %s but got %s",
|
||||||
"AOT module load failed: invalid target type, "
|
target_expected, target_got);
|
||||||
"expected %s but got %s.",
|
|
||||||
target_expected, target_got);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,39 +306,35 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
|
|
||||||
if (p != buf_end) {
|
if (p != buf_end) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid section size.");
|
"invalid section size");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check target endian type */
|
/* Check target endian type */
|
||||||
is_target_little_endian = target_info.bin_type & 1 ? false : true;
|
is_target_little_endian = target_info.bin_type & 1 ? false : true;
|
||||||
if (is_little_endian() != is_target_little_endian) {
|
if (is_little_endian() != is_target_little_endian) {
|
||||||
if (error_buf)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"invalid target endian type, expected %s but got %s",
|
||||||
"AOT module load failed: "
|
is_little_endian() ? "little endian" : "big endian",
|
||||||
"invalid target endian type, expected %s but got %s.",
|
is_target_little_endian ? "little endian" : "big endian");
|
||||||
is_little_endian() ? "little endian" : "big endian",
|
|
||||||
is_target_little_endian ? "little endian" : "big endian");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check target bit width */
|
/* Check target bit width */
|
||||||
is_target_64_bit = target_info.bin_type & 2 ? true : false;
|
is_target_64_bit = target_info.bin_type & 2 ? true : false;
|
||||||
if ((sizeof(void*) == 8 ? true : false) != is_target_64_bit) {
|
if ((sizeof(void*) == 8 ? true : false) != is_target_64_bit) {
|
||||||
if (error_buf)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"invalid target bit width, expected %s but got %s",
|
||||||
"AOT module load failed: "
|
sizeof(void*) == 8 ? "64-bit" : "32-bit",
|
||||||
"invalid target bit width, expected %s but got %s.",
|
is_target_64_bit ? "64-bit" : "32-bit");
|
||||||
sizeof(void*) == 8 ? "64-bit" : "32-bit",
|
|
||||||
is_target_64_bit ? "64-bit" : "32-bit");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check target elf file type */
|
/* Check target elf file type */
|
||||||
if (target_info.e_type != E_TYPE_REL) {
|
if (target_info.e_type != E_TYPE_REL) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid object file type, "
|
"invalid object file type, "
|
||||||
"expected relocatable file type but got others.");
|
"expected relocatable file type but got others");
|
||||||
return false;
|
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) {
|
if (target_info.e_version != E_VERSION_CURRENT) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid elf file version.");
|
"invalid elf file version");
|
||||||
return false;
|
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) {
|
if (param_count > UINT16_MAX || result_count > UINT16_MAX) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
|
||||||
"param count or result count too large");
|
"param count or result count too large");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -660,7 +664,6 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end,
|
||||||
result_count);
|
result_count);
|
||||||
if (param_cell_num > UINT16_MAX || ret_cell_num > UINT16_MAX) {
|
if (param_cell_num > UINT16_MAX || ret_cell_num > UINT16_MAX) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
|
||||||
"param count or result count too large");
|
"param count or result count too large");
|
||||||
return false;
|
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++) {
|
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);
|
||||||
if (import_funcs[i].func_type_index >= module->func_type_count) {
|
if (import_funcs[i].func_type_index >= module->func_type_count) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown type");
|
||||||
"AOT module load failed: unknown type.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
import_funcs[i].func_type = module->func_types[import_funcs[i].func_type_index];
|
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 =
|
if (!(data_sections[i].data =
|
||||||
os_mmap(NULL, data_sections[i].size, map_prot, map_flags))) {
|
os_mmap(NULL, data_sections[i].size, map_prot, map_flags))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
#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->start_func_index >= module->import_func_count
|
||||||
+ module->func_count)) {
|
+ module->func_count)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid start function index");
|
"invalid start function index");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1053,7 +1053,6 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
|
|
||||||
if (p != p_end) {
|
if (p != p_end) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid init data section size");
|
"invalid init data section size");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1073,7 +1072,7 @@ load_text_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
|
|
||||||
if (module->func_count > 0 && buf_end == buf) {
|
if (module->func_count > 0 && buf_end == buf) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid code size.");
|
"invalid code size");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1120,8 +1119,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
}
|
}
|
||||||
if (text_offset >= module->code_size) {
|
if (text_offset >= module->code_size) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"invalid function code offset");
|
||||||
"invalid function code offset.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
module->func_ptrs[i] = (uint8*)module->code + text_offset;
|
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++) {
|
for (i = 0; i < module->func_count; i++) {
|
||||||
read_uint32(p, p_end, module->func_type_indexes[i]);
|
read_uint32(p, p_end, module->func_type_indexes[i]);
|
||||||
if (module->func_type_indexes[i] >= module->func_type_count) {
|
if (module->func_type_indexes[i] >= module->func_type_count) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown type");
|
||||||
"AOT module load failed: unknown type.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p != buf_end) {
|
if (p != buf_end) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid function section size");
|
"invalid function section size");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1204,8 +1200,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end,
|
||||||
if (export_funcs[i].index >=
|
if (export_funcs[i].index >=
|
||||||
module->func_count + module->import_func_count) {
|
module->func_count + module->import_func_count) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1232,7 +1227,6 @@ load_export_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
|
|
||||||
if (p != p_end) {
|
if (p != p_end) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid export section size");
|
"invalid export section size");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1299,7 +1293,7 @@ do_text_relocation(AOTModule *module,
|
||||||
|
|
||||||
if (group->relocation_count > 0 && !aot_text) {
|
if (group->relocation_count > 0 && !aot_text) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid text relocation count.");
|
"invalid text relocation count");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,11 +1315,8 @@ do_text_relocation(AOTModule *module,
|
||||||
p = symbol + strlen(AOT_FUNC_PREFIX);
|
p = symbol + strlen(AOT_FUNC_PREFIX);
|
||||||
if (*p == '\0'
|
if (*p == '\0'
|
||||||
|| (func_index = (uint32)atoi(p)) > module->func_count) {
|
|| (func_index = (uint32)atoi(p)) > module->func_count) {
|
||||||
if (error_buf != NULL)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"invalid import symbol %s", symbol);
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid import symbol %s.",
|
|
||||||
symbol);
|
|
||||||
goto check_symbol_fail;
|
goto check_symbol_fail;
|
||||||
}
|
}
|
||||||
symbol_addr = module->func_ptrs[func_index];
|
symbol_addr = module->func_ptrs[func_index];
|
||||||
|
@ -1339,11 +1330,8 @@ do_text_relocation(AOTModule *module,
|
||||||
|| !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst"))) {
|
|| !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst"))) {
|
||||||
symbol_addr = get_data_section_addr(module, symbol, NULL);
|
symbol_addr = get_data_section_addr(module, symbol, NULL);
|
||||||
if (!symbol_addr) {
|
if (!symbol_addr) {
|
||||||
if (error_buf != NULL)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"invalid data section (%s)", symbol);
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid data section (%s).",
|
|
||||||
symbol);
|
|
||||||
goto check_symbol_fail;
|
goto check_symbol_fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1351,11 +1339,8 @@ do_text_relocation(AOTModule *module,
|
||||||
symbol_addr = module->literal;
|
symbol_addr = module->literal;
|
||||||
}
|
}
|
||||||
else if (!(symbol_addr = resolve_target_sym(symbol, &symbol_index))) {
|
else if (!(symbol_addr = resolve_target_sym(symbol, &symbol_index))) {
|
||||||
if (error_buf != NULL)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"resolve symbol %s failed", symbol);
|
||||||
"AOT module load failed: "
|
|
||||||
"resolve symbol %s failed.",
|
|
||||||
symbol);
|
|
||||||
goto check_symbol_fail;
|
goto check_symbol_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1400,8 +1385,7 @@ do_data_relocation(AOTModule *module,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"invalid data relocation section name");
|
||||||
"invalid data relocation section name.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1409,7 +1393,7 @@ do_data_relocation(AOTModule *module,
|
||||||
&data_size);
|
&data_size);
|
||||||
if (group->relocation_count > 0 && !data_addr) {
|
if (group->relocation_count > 0 && !data_addr) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid data relocation count.");
|
"invalid data relocation count");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1419,11 +1403,8 @@ do_data_relocation(AOTModule *module,
|
||||||
symbol_addr = module->code;
|
symbol_addr = module->code;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (error_buf != NULL)
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
snprintf(error_buf, error_buf_size,
|
"invalid relocation symbol %s", symbol);
|
||||||
"AOT module load failed: "
|
|
||||||
"invalid relocation symbol %s.",
|
|
||||||
symbol);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1494,8 +1475,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
symbol_offsets, symbol_count,
|
symbol_offsets, symbol_count,
|
||||||
error_buf, error_buf_size)) {
|
error_buf, error_buf_size)) {
|
||||||
set_error_buf(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;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1521,8 +1501,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
|
|
||||||
if (name_index >= symbol_count) {
|
if (name_index >= symbol_count) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"symbol index out of range");
|
||||||
"symbol index out of range.");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1568,8 +1547,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
|
|
||||||
if (symbol_index >= symbol_count) {
|
if (symbol_index >= symbol_count) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"symbol index out of range");
|
||||||
"symbol index out of range.");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1630,7 +1608,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
|
||||||
|| (last_section_type != (uint32)-1
|
|| (last_section_type != (uint32)-1
|
||||||
&& section_type != last_section_type + 1)) {
|
&& section_type != last_section_type + 1)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid section order.");
|
"invalid section order");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
last_section_type = section_type;
|
last_section_type = section_type;
|
||||||
|
@ -1672,7 +1650,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
|
||||||
|
|
||||||
if (last_section_type != AOT_SECTION_TYPE_RELOCATION) {
|
if (last_section_type != AOT_SECTION_TYPE_RELOCATION) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: section missing.");
|
"section missing");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1747,8 +1725,7 @@ create_module(char *error_buf, uint32 error_buf_size)
|
||||||
NULL,
|
NULL,
|
||||||
aot_free))) {
|
aot_free))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
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);
|
wasm_runtime_free(module);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1838,8 +1815,7 @@ create_sections(const uint8 *buf, uint32 size,
|
||||||
map_prot, map_flags))) {
|
map_prot, map_flags))) {
|
||||||
wasm_runtime_free(section);
|
wasm_runtime_free(section);
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: "
|
"mmap memory failed");
|
||||||
"mmap memory failed.");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
||||||
|
@ -1874,14 +1850,14 @@ create_sections(const uint8 *buf, uint32 size,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: invalid section id.");
|
"invalid section id");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!section_list) {
|
if (!section_list) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module load failed: create section list failed.");
|
"create section list failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2032,7 +2008,7 @@ aot_load_from_comp_data(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||||
(void *)LLVMGetFunctionAddress(comp_ctx->exec_engine,
|
(void *)LLVMGetFunctionAddress(comp_ctx->exec_engine,
|
||||||
func_name))) {
|
func_name))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Get function address fail.");
|
"get function address failed");
|
||||||
goto fail3;
|
goto fail3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
static void
|
static void
|
||||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||||
{
|
{
|
||||||
if (error_buf != NULL)
|
if (error_buf != NULL) {
|
||||||
snprintf(error_buf, error_buf_size, "%s", string);
|
snprintf(error_buf, error_buf_size,
|
||||||
|
"AOT module instantiate failed: %s", string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
@ -25,8 +27,7 @@ runtime_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
|
||||||
if (size >= UINT32_MAX
|
if (size >= UINT32_MAX
|
||||||
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module instantiate failed: "
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +61,7 @@ global_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||||
switch (init_expr->init_expr_type) {
|
switch (init_expr->init_expr_type) {
|
||||||
case INIT_EXPR_TYPE_GET_GLOBAL:
|
case INIT_EXPR_TYPE_GET_GLOBAL:
|
||||||
if (init_expr->u.global_index >= module->import_global_count + i) {
|
if (init_expr->u.global_index >= module->import_global_count + i) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown global");
|
||||||
"Instantiate global failed: unknown global.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memcpy(p,
|
memcpy(p,
|
||||||
|
@ -333,14 +333,12 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||||
if (total_size >= UINT32_MAX
|
if (total_size >= UINT32_MAX
|
||||||
|| !(p = mapped_mem = os_mmap(NULL, map_size,
|
|| !(p = mapped_mem = os_mmap(NULL, map_size,
|
||||||
MMAP_PROT_NONE, MMAP_MAP_NONE))) {
|
MMAP_PROT_NONE, MMAP_MAP_NONE))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
|
||||||
"AOT module instantiate failed: mmap memory failed.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_mprotect(p, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
|
if (os_mprotect(p, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "mprotec memory failed");
|
||||||
"AOT module instantiate failed: mprotec memory failed.");
|
|
||||||
os_munmap(mapped_mem, map_size);
|
os_munmap(mapped_mem, map_size);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -364,8 +362,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
||||||
if (!(heap_handle = mem_allocator_create(memory_inst->heap_data.ptr,
|
if (!(heap_handle = mem_allocator_create(memory_inst->heap_data.ptr,
|
||||||
heap_size))) {
|
heap_size))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"AOT module instantiate failed:"
|
"init app heap failed");
|
||||||
"init app heap failed.");
|
|
||||||
goto fail1;
|
goto fail1;
|
||||||
}
|
}
|
||||||
memory_inst->heap_handle.ptr = heap_handle;
|
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,
|
if (!shared_memory_set_memory_inst((WASMModuleCommon *)module,
|
||||||
(WASMMemoryInstanceCommon *)memory_inst)) {
|
(WASMMemoryInstanceCommon *)memory_inst)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Instantiate memory failed:"
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
goto fail2;
|
goto fail2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -659,7 +655,7 @@ execute_start_function(AOTModuleInstance *module_inst)
|
||||||
|
|
||||||
if (!(exec_env = wasm_exec_env_create((WASMModuleInstanceCommon*)module_inst,
|
if (!(exec_env = wasm_exec_env_create((WASMModuleInstanceCommon*)module_inst,
|
||||||
module_inst->default_wasm_stack_size))) {
|
module_inst->default_wasm_stack_size))) {
|
||||||
aot_set_exception(module_inst, "allocate memory failed.");
|
aot_set_exception(module_inst, "allocate memory failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -988,7 +984,7 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
|
||||||
|
|
||||||
if (aot_exec_env
|
if (aot_exec_env
|
||||||
&& (aot_exec_env != 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;
|
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 */
|
/* First time to call aot function, protect one page */
|
||||||
if (os_mprotect(stack_min_addr, page_size * guard_page_count,
|
if (os_mprotect(stack_min_addr, page_size * guard_page_count,
|
||||||
MMAP_PROT_NONE) != 0) {
|
MMAP_PROT_NONE) != 0) {
|
||||||
aot_set_exception(module_inst, "Set protected page failed.");
|
aot_set_exception(module_inst, "set protected page failed");
|
||||||
return false;
|
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,
|
if (!(exec_env = wasm_exec_env_create((WASMModuleInstanceCommon*)module_inst,
|
||||||
module_inst->default_wasm_stack_size))) {
|
module_inst->default_wasm_stack_size))) {
|
||||||
aot_set_exception(module_inst, "allocate memory failed.");
|
aot_set_exception(module_inst, "allocate memory failed");
|
||||||
return false;
|
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 */
|
if (total_page_count < cur_page_count /* integer overflow */
|
||||||
|| total_page_count > max_page_count) {
|
|| total_page_count > max_page_count) {
|
||||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total_size >= UINT32_MAX) {
|
if (total_size >= UINT32_MAX) {
|
||||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
|
||||||
return false;
|
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 */
|
/* Restore heap's lock if memory re-alloc failed */
|
||||||
mem_allocator_reinit_lock(memory_inst->heap_handle.ptr);
|
mem_allocator_reinit_lock(memory_inst->heap_handle.ptr);
|
||||||
}
|
}
|
||||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bh_memcpy_s(memory_data, (uint32)total_size,
|
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);
|
+ (memory_data - memory_data_old);
|
||||||
if (mem_allocator_migrate(memory_inst->heap_handle.ptr,
|
if (mem_allocator_migrate(memory_inst->heap_handle.ptr,
|
||||||
heap_handle_old) != 0) {
|
heap_handle_old) != 0) {
|
||||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
|
||||||
return false;
|
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 */
|
if (total_page_count < cur_page_count /* integer overflow */
|
||||||
|| total_page_count > max_page_count) {
|
|| total_page_count > max_page_count) {
|
||||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_mprotect(memory_inst->memory_data_end.ptr,
|
if (os_mprotect(memory_inst->memory_data_end.ptr,
|
||||||
num_bytes_per_page * inc_page_count,
|
num_bytes_per_page * inc_page_count,
|
||||||
MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
|
MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
|
||||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,16 +49,6 @@ static void
|
||||||
wasm_runtime_destroy_registered_module_list();
|
wasm_runtime_destroy_registered_module_list();
|
||||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||||
|
|
||||||
void
|
|
||||||
set_error_buf_v(char *error_buf, uint32 error_buf_size, const char *format,
|
|
||||||
...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
vsnprintf(error_buf, error_buf_size, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||||
{
|
{
|
||||||
|
@ -76,11 +66,11 @@ runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst,
|
||||||
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||||
if (module_inst != NULL) {
|
if (module_inst != NULL) {
|
||||||
wasm_runtime_set_exception(module_inst,
|
wasm_runtime_set_exception(module_inst,
|
||||||
"allocate memory failed.");
|
"allocate memory failed");
|
||||||
}
|
}
|
||||||
else if (error_buf != NULL) {
|
else if (error_buf != NULL) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"allocate memory failed.");
|
"allocate memory failed");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -308,8 +298,9 @@ wasm_runtime_register_module_internal(const char *module_name,
|
||||||
/* module has different name */
|
/* module has different name */
|
||||||
LOG_DEBUG("module(%p) has been registered with name %s",
|
LOG_DEBUG("module(%p) has been registered with name %s",
|
||||||
module, node->module_name);
|
module, node->module_name);
|
||||||
set_error_buf_v(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"can not rename the module");
|
"Register module failed: "
|
||||||
|
"failed to rename the module");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -359,14 +350,16 @@ wasm_runtime_register_module(const char *module_name, WASMModuleCommon *module,
|
||||||
|
|
||||||
if (!module_name || !module) {
|
if (!module_name || !module) {
|
||||||
LOG_DEBUG("module_name and module are required");
|
LOG_DEBUG("module_name and module are required");
|
||||||
set_error_buf_v(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"module_name and module are required");
|
"Register module failed: "
|
||||||
|
"module_name and module are required");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasm_runtime_is_built_in_module(module_name)) {
|
if (wasm_runtime_is_built_in_module(module_name)) {
|
||||||
LOG_DEBUG("%s is a built-in module name", module_name);
|
LOG_DEBUG("%s is a built-in module name", module_name);
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
|
"Register module failed: "
|
||||||
"can not register as a built-in module");
|
"can not register as a built-in module");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1325,7 +1318,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
(module_inst, (uint32)argv_buf_len,
|
(module_inst, (uint32)argv_buf_len,
|
||||||
(void**)&argv_buf))) {
|
(void**)&argv_buf))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: allocate memory failed.");
|
"Init wasi environment failed: allocate memory failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1349,7 +1342,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
(module_inst, (uint32)env_buf_len,
|
(module_inst, (uint32)env_buf_len,
|
||||||
(void**)&env_buf))) {
|
(void**)&env_buf))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: allocate memory failed.");
|
"Init wasi environment failed: allocate memory failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1368,7 +1361,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
(module_inst, sizeof(struct argv_environ_values),
|
(module_inst, sizeof(struct argv_environ_values),
|
||||||
(void**)&argv_environ))) {
|
(void**)&argv_environ))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: allocate memory failed.");
|
"Init wasi environment failed: allocate memory failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1383,7 +1376,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
if (!fd_table_init(curfds)) {
|
if (!fd_table_init(curfds)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: "
|
"Init wasi environment failed: "
|
||||||
"init fd table failed.");
|
"init fd table failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
fd_table_inited = true;
|
fd_table_inited = true;
|
||||||
|
@ -1391,7 +1384,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
if (!fd_prestats_init(prestats)) {
|
if (!fd_prestats_init(prestats)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: "
|
"Init wasi environment failed: "
|
||||||
"init fd prestats failed.");
|
"init fd prestats failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
fd_prestats_inited = true;
|
fd_prestats_inited = true;
|
||||||
|
@ -1403,7 +1396,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
env_buf, env_buf_len)) {
|
env_buf, env_buf_len)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: "
|
"Init wasi environment failed: "
|
||||||
"init argument environment failed.");
|
"init argument environment failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
argv_environ_inited = true;
|
argv_environ_inited = true;
|
||||||
|
@ -1413,7 +1406,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
|| !fd_table_insert_existing(curfds, 1, 1)
|
|| !fd_table_insert_existing(curfds, 1, 1)
|
||||||
|| !fd_table_insert_existing(curfds, 2, 2)) {
|
|| !fd_table_insert_existing(curfds, 2, 2)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: init fd table failed.");
|
"Init wasi environment failed: init fd table failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1689,7 +1682,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
||||||
|
|
||||||
if (!func) {
|
if (!func) {
|
||||||
wasm_runtime_set_exception(module_inst,
|
wasm_runtime_set_exception(module_inst,
|
||||||
"lookup main function failed.");
|
"lookup main function failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1697,7 +1690,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
||||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||||
if (((WASMFunctionInstance*)func)->is_import_func) {
|
if (((WASMFunctionInstance*)func)->is_import_func) {
|
||||||
wasm_runtime_set_exception(module_inst,
|
wasm_runtime_set_exception(module_inst,
|
||||||
"lookup main function failed.");
|
"lookup main function failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
func_type = ((WASMFunctionInstance*)func)->u.func->func_type;
|
func_type = ((WASMFunctionInstance*)func)->u.func->func_type;
|
||||||
|
@ -1710,7 +1703,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
||||||
|
|
||||||
if (!check_main_func_type(func_type)) {
|
if (!check_main_func_type(func_type)) {
|
||||||
wasm_runtime_set_exception(module_inst,
|
wasm_runtime_set_exception(module_inst,
|
||||||
"invalid function type of main function.");
|
"invalid function type of main function");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1726,7 +1719,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
|
||||||
wasm_runtime_module_malloc(module_inst, (uint32)total_size,
|
wasm_runtime_module_malloc(module_inst, (uint32)total_size,
|
||||||
(void**)&argv_buf))) {
|
(void**)&argv_buf))) {
|
||||||
wasm_runtime_set_exception(module_inst,
|
wasm_runtime_set_exception(module_inst,
|
||||||
"allocate memory failed.");
|
"allocate memory failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1942,7 +1935,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||||
func = resolve_function(module_inst, name);
|
func = resolve_function(module_inst, name);
|
||||||
|
|
||||||
if (!func) {
|
if (!func) {
|
||||||
snprintf(buf, sizeof(buf), "lookup function %s failed.", name);
|
snprintf(buf, sizeof(buf), "lookup function %s failed", name);
|
||||||
wasm_runtime_set_exception(module_inst, buf);
|
wasm_runtime_set_exception(module_inst, buf);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1955,7 +1948,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||||
&& !wasm_func->import_func_inst
|
&& !wasm_func->import_func_inst
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
snprintf(buf, sizeof(buf), "lookup function %s failed.", name);
|
snprintf(buf, sizeof(buf), "lookup function %s failed", name);
|
||||||
wasm_runtime_set_exception(module_inst, buf);
|
wasm_runtime_set_exception(module_inst, buf);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1976,7 +1969,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||||
|
|
||||||
if (type->param_count != (uint32)argc) {
|
if (type->param_count != (uint32)argc) {
|
||||||
wasm_runtime_set_exception(module_inst,
|
wasm_runtime_set_exception(module_inst,
|
||||||
"invalid input argument count.");
|
"invalid input argument count");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1994,7 +1987,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
bh_assert(argv[i] != NULL);
|
bh_assert(argv[i] != NULL);
|
||||||
if (argv[i][0] == '\0') {
|
if (argv[i][0] == '\0') {
|
||||||
snprintf(buf, sizeof(buf), "invalid input argument %d.", i);
|
snprintf(buf, sizeof(buf), "invalid input argument %d", i);
|
||||||
wasm_runtime_set_exception(module_inst, buf);
|
wasm_runtime_set_exception(module_inst, buf);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -2074,14 +2067,14 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (endptr && *endptr != '\0' && *endptr != '_') {
|
if (endptr && *endptr != '\0' && *endptr != '_') {
|
||||||
snprintf(buf, sizeof(buf), "invalid input argument %d: %s.",
|
snprintf(buf, sizeof(buf), "invalid input argument %d: %s",
|
||||||
i, argv[i]);
|
i, argv[i]);
|
||||||
wasm_runtime_set_exception(module_inst, buf);
|
wasm_runtime_set_exception(module_inst, buf);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
snprintf(buf, sizeof(buf),
|
snprintf(buf, sizeof(buf),
|
||||||
"prepare function argument error, errno: %d.", errno);
|
"prepare function argument error, errno: %d", errno);
|
||||||
wasm_runtime_set_exception(module_inst, buf);
|
wasm_runtime_set_exception(module_inst, buf);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,10 +79,6 @@ typedef struct WASMMemoryInstanceCommon {
|
||||||
typedef package_type_t PackageType;
|
typedef package_type_t PackageType;
|
||||||
typedef wasm_section_t WASMSection, AOTSection;
|
typedef wasm_section_t WASMSection, AOTSection;
|
||||||
|
|
||||||
void
|
|
||||||
set_error_buf_v(char *error_buf, uint32 error_buf_size, const char *format,
|
|
||||||
...);
|
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
bool
|
bool
|
||||||
wasm_runtime_init(void);
|
wasm_runtime_init(void);
|
||||||
|
|
|
@ -700,47 +700,6 @@ aot_compile_op_memory_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
PUSH_I32(ret_value);
|
PUSH_I32(ret_value);
|
||||||
|
|
||||||
/* To be simple, call wasm_runtime_set_exception() no matter
|
|
||||||
enlarge success or not */
|
|
||||||
param_types[1] = INT8_PTR_TYPE;
|
|
||||||
ret_type = VOID_TYPE;
|
|
||||||
if (!(func_type = LLVMFunctionType(ret_type, param_types, 2, false))) {
|
|
||||||
aot_set_last_error("llvm add function type failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comp_ctx->is_jit_mode) {
|
|
||||||
/* JIT mode, call the function directly */
|
|
||||||
if (!(func_ptr_type = LLVMPointerType(func_type, 0))) {
|
|
||||||
aot_set_last_error("llvm add pointer type failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!(value = I64_CONST((uint64)(uintptr_t)wasm_runtime_set_exception))
|
|
||||||
|| !(func = LLVMConstIntToPtr(value, func_ptr_type))) {
|
|
||||||
aot_set_last_error("create LLVM value failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
char *func_name = "wasm_runtime_set_exception";
|
|
||||||
/* AOT mode, delcare the function */
|
|
||||||
if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
|
|
||||||
&& !(func = LLVMAddFunction(comp_ctx->module,
|
|
||||||
func_name, func_type))) {
|
|
||||||
aot_set_last_error("llvm add function failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Call function wasm_runtime_set_exception(aot_inst, NULL) */
|
|
||||||
param_values[1] = LLVMConstNull(INT8_PTR_TYPE);
|
|
||||||
CHECK_LLVM_CONST(param_values[1]);
|
|
||||||
if (!(LLVMBuildCall(comp_ctx->builder, func, param_values, 2, ""))) {
|
|
||||||
aot_set_last_error("llvm build call failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
fail:
|
fail:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -903,7 +903,7 @@ ALLOC_FRAME(WASMExecEnv *exec_env, uint32 size, WASMInterpFrame *prev_frame)
|
||||||
frame->prev_frame = prev_frame;
|
frame->prev_frame = prev_frame;
|
||||||
else {
|
else {
|
||||||
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
||||||
"WASM interp failed: stack overflow.");
|
"stack overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
|
@ -1244,8 +1244,7 @@ label_pop_csp_n:
|
||||||
uint64 total_size = sizeof(uint32) * (uint64)count;
|
uint64 total_size = sizeof(uint32) * (uint64)count;
|
||||||
if (total_size >= UINT32_MAX
|
if (total_size >= UINT32_MAX
|
||||||
|| !(depths = wasm_runtime_malloc((uint32)total_size))) {
|
|| !(depths = wasm_runtime_malloc((uint32)total_size))) {
|
||||||
wasm_set_exception(module,
|
wasm_set_exception(module, "allocate memory failed");
|
||||||
"WASM interp failed: allocate memory failed.");
|
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1303,7 +1302,7 @@ label_pop_csp_n:
|
||||||
*/
|
*/
|
||||||
read_leb_uint32(frame_ip, frame_ip_end, tidx);
|
read_leb_uint32(frame_ip, frame_ip_end, tidx);
|
||||||
if (tidx >= module->module->type_count) {
|
if (tidx >= module->module->type_count) {
|
||||||
wasm_set_exception(module, "type index is overflow");
|
wasm_set_exception(module, "unknown type");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
cur_type = wasm_types[tidx];
|
cur_type = wasm_types[tidx];
|
||||||
|
@ -1839,10 +1838,6 @@ label_pop_csp_n:
|
||||||
if (!wasm_enlarge_memory(module, delta)) {
|
if (!wasm_enlarge_memory(module, delta)) {
|
||||||
/* fail to memory.grow, return -1 */
|
/* fail to memory.grow, return -1 */
|
||||||
PUSH_I32(-1);
|
PUSH_I32(-1);
|
||||||
if (wasm_get_exception(module)) {
|
|
||||||
os_printf("%s\n", wasm_get_exception(module));
|
|
||||||
wasm_set_exception(module, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* success, return previous page count */
|
/* success, return previous page count */
|
||||||
|
@ -2762,7 +2757,7 @@ label_pop_csp_n:
|
||||||
}
|
}
|
||||||
#endif /* WASM_ENABLE_BULK_MEMORY */
|
#endif /* WASM_ENABLE_BULK_MEMORY */
|
||||||
default:
|
default:
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "unsupported opcode");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3107,7 +3102,7 @@ label_pop_csp_n:
|
||||||
|
|
||||||
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
||||||
default:
|
default:
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "unsupported opcode");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3137,7 +3132,7 @@ label_pop_csp_n:
|
||||||
HANDLE_OP (EXT_OP_COPY_STACK_TOP_I64):
|
HANDLE_OP (EXT_OP_COPY_STACK_TOP_I64):
|
||||||
HANDLE_OP (EXT_OP_COPY_STACK_VALUES):
|
HANDLE_OP (EXT_OP_COPY_STACK_VALUES):
|
||||||
{
|
{
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "unsupported opcode");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3192,7 +3187,7 @@ label_pop_csp_n:
|
||||||
+ (uint64)cur_wasm_func->max_stack_cell_num
|
+ (uint64)cur_wasm_func->max_stack_cell_num
|
||||||
+ ((uint64)cur_wasm_func->max_block_num) * sizeof(WASMBranchBlock) / 4;
|
+ ((uint64)cur_wasm_func->max_block_num) * sizeof(WASMBranchBlock) / 4;
|
||||||
if (all_cell_num >= UINT32_MAX) {
|
if (all_cell_num >= UINT32_MAX) {
|
||||||
wasm_set_exception(module, "WASM interp failed: stack overflow.");
|
wasm_set_exception(module, "stack overflow");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3288,7 +3283,7 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if ((uint8*)&prev_frame < exec_env->native_stack_boundary) {
|
if ((uint8*)&prev_frame < exec_env->native_stack_boundary) {
|
||||||
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
||||||
"WASM interp failed: native stack overflow.");
|
"native stack overflow");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3310,20 +3305,16 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
if (function->import_module_inst) {
|
if (function->import_module_inst) {
|
||||||
LOG_DEBUG("it is a function of a sub module");
|
LOG_DEBUG("it is a function of a sub module");
|
||||||
wasm_interp_call_func_import(module_inst,
|
wasm_interp_call_func_import(module_inst, exec_env,
|
||||||
exec_env,
|
function, frame);
|
||||||
function,
|
|
||||||
frame);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
LOG_DEBUG("it is an native function");
|
LOG_DEBUG("it is an native function");
|
||||||
/* it is a native function */
|
/* it is a native function */
|
||||||
wasm_interp_call_func_native(module_inst,
|
wasm_interp_call_func_native(module_inst, exec_env,
|
||||||
exec_env,
|
function, frame);
|
||||||
function,
|
|
||||||
frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3339,10 +3330,12 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if (function->ret_cell_num) {
|
if (function->ret_cell_num) {
|
||||||
LOG_DEBUG("first return value argv[0]=%d", argv[0]);
|
LOG_DEBUG("first return value argv[0]=%d", argv[0]);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
LOG_DEBUG("no return value");
|
LOG_DEBUG("no return value");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
LOG_DEBUG("meet an exception %s", wasm_get_exception(module_inst));
|
LOG_DEBUG("meet an exception %s", wasm_get_exception(module_inst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -802,8 +802,7 @@ copy_stack_values(WASMModuleInstance *module,
|
||||||
uint64 total_size = sizeof(uint32) * (uint64)total_cell_num;
|
uint64 total_size = sizeof(uint32) * (uint64)total_cell_num;
|
||||||
if (total_size >= UINT32_MAX
|
if (total_size >= UINT32_MAX
|
||||||
|| !(tmp_buf = wasm_runtime_malloc((uint32)total_size))) {
|
|| !(tmp_buf = wasm_runtime_malloc((uint32)total_size))) {
|
||||||
wasm_set_exception(module,
|
wasm_set_exception(module, "allocate memory failed");
|
||||||
"WASM interp failed: allocate memory failed.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -951,7 +950,7 @@ ALLOC_FRAME(WASMExecEnv *exec_env, uint32 size, WASMInterpFrame *prev_frame)
|
||||||
frame->prev_frame = prev_frame;
|
frame->prev_frame = prev_frame;
|
||||||
else {
|
else {
|
||||||
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
||||||
"WASM interp failed: stack overflow.");
|
"stack overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
|
@ -1789,10 +1788,6 @@ recover_br_info:
|
||||||
if (!wasm_enlarge_memory(module, delta)) {
|
if (!wasm_enlarge_memory(module, delta)) {
|
||||||
/* fail to memory.grow, return -1 */
|
/* fail to memory.grow, return -1 */
|
||||||
frame_lp[addr_ret] = -1;
|
frame_lp[addr_ret] = -1;
|
||||||
if (wasm_get_exception(module)) {
|
|
||||||
os_printf("%s\n", wasm_get_exception(module));
|
|
||||||
wasm_set_exception(module, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* success, return previous page count */
|
/* success, return previous page count */
|
||||||
|
@ -2756,7 +2751,7 @@ recover_br_info:
|
||||||
}
|
}
|
||||||
#endif /* WASM_ENABLE_BULK_MEMORY */
|
#endif /* WASM_ENABLE_BULK_MEMORY */
|
||||||
default:
|
default:
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "unsupported opcode");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3111,7 +3106,7 @@ recover_br_info:
|
||||||
|
|
||||||
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
||||||
default:
|
default:
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "unsupported opcode");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3155,7 +3150,7 @@ recover_br_info:
|
||||||
HANDLE_OP (EXT_OP_LOOP):
|
HANDLE_OP (EXT_OP_LOOP):
|
||||||
HANDLE_OP (EXT_OP_IF):
|
HANDLE_OP (EXT_OP_IF):
|
||||||
{
|
{
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "unsupported opcode");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3234,7 +3229,7 @@ recover_br_info:
|
||||||
+ (uint64)cur_func->const_cell_num
|
+ (uint64)cur_func->const_cell_num
|
||||||
+ (uint64)cur_wasm_func->max_stack_cell_num;
|
+ (uint64)cur_wasm_func->max_stack_cell_num;
|
||||||
if (all_cell_num >= UINT32_MAX) {
|
if (all_cell_num >= UINT32_MAX) {
|
||||||
wasm_set_exception(module, "WASM interp failed: stack overflow.");
|
wasm_set_exception(module, "stack overflow");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3336,7 +3331,7 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if ((uint8*)&prev_frame < exec_env->native_stack_boundary) {
|
if ((uint8*)&prev_frame < exec_env->native_stack_boundary) {
|
||||||
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
wasm_set_exception((WASMModuleInstance*)exec_env->module_inst,
|
||||||
"WASM interp failed: native stack overflow.");
|
"native stack overflow");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3359,19 +3354,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
if (function->import_module_inst) {
|
if (function->import_module_inst) {
|
||||||
LOG_DEBUG("it is a function of a sub module");
|
LOG_DEBUG("it is a function of a sub module");
|
||||||
wasm_interp_call_func_import(module_inst,
|
wasm_interp_call_func_import(module_inst, exec_env,
|
||||||
exec_env,
|
function, frame);
|
||||||
function,
|
|
||||||
frame);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
LOG_DEBUG("it is an native function");
|
LOG_DEBUG("it is an native function");
|
||||||
wasm_interp_call_func_native(module_inst,
|
wasm_interp_call_func_native(module_inst, exec_env,
|
||||||
exec_env,
|
function, frame);
|
||||||
function,
|
|
||||||
frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,7 +21,8 @@ static void
|
||||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||||
{
|
{
|
||||||
if (error_buf != NULL)
|
if (error_buf != NULL)
|
||||||
snprintf(error_buf, error_buf_size, "%s", string);
|
snprintf(error_buf, error_buf_size,
|
||||||
|
"WASM module load failed: %s", string);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_BUF(buf, buf_end, length) do { \
|
#define CHECK_BUF(buf, buf_end, length) do { \
|
||||||
|
@ -168,8 +169,7 @@ loader_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
|
||||||
if (size >= UINT32_MAX
|
if (size >= UINT32_MAX
|
||||||
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM module load failed: "
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,8 +378,7 @@ load_function_import(const WASMModule *parent_module, WASMModule *sub_module,
|
||||||
is_built_in_module = wasm_runtime_is_built_in_module(sub_module_name);
|
is_built_in_module = wasm_runtime_is_built_in_module(sub_module_name);
|
||||||
if (is_built_in_module) {
|
if (is_built_in_module) {
|
||||||
LOG_DEBUG("%s is a function of a built-in module %s",
|
LOG_DEBUG("%s is a function of a built-in module %s",
|
||||||
function_name,
|
function_name, sub_module_name);
|
||||||
sub_module_name);
|
|
||||||
/* check built-in modules */
|
/* check built-in modules */
|
||||||
linked_func = wasm_native_resolve_symbol(sub_module_name,
|
linked_func = wasm_native_resolve_symbol(sub_module_name,
|
||||||
function_name,
|
function_name,
|
||||||
|
@ -391,15 +390,13 @@ load_function_import(const WASMModule *parent_module, WASMModule *sub_module,
|
||||||
|
|
||||||
if (!linked_func) {
|
if (!linked_func) {
|
||||||
#if WASM_ENABLE_SPEC_TEST != 0
|
#if WASM_ENABLE_SPEC_TEST != 0
|
||||||
set_error_buf(error_buf,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
error_buf_size,
|
|
||||||
"unknown import or incompatible import type");
|
"unknown import or incompatible import type");
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
#if WASM_ENABLE_WAMR_COMPILER == 0
|
#if WASM_ENABLE_WAMR_COMPILER == 0
|
||||||
LOG_WARNING(
|
LOG_WARNING("warning: fail to link import function (%s, %s)",
|
||||||
"warning: fail to link import function (%s, %s)",
|
sub_module_name, function_name);
|
||||||
sub_module_name, function_name);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -538,8 +535,8 @@ load_global_import(const WASMModule *parent_module,
|
||||||
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
set_error_buf_v(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"unknown import or incompatible import type");
|
"unknown import or incompatible import type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,6 +594,7 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
|
||||||
p_org = p;
|
p_org = p;
|
||||||
read_leb_uint32(p, p_end, memory->flags);
|
read_leb_uint32(p, p_end, memory->flags);
|
||||||
bh_assert(p - p_org <= 1);
|
bh_assert(p - p_org <= 1);
|
||||||
|
(void)p_org;
|
||||||
#if WASM_ENABLE_SHARED_MEMORY == 0
|
#if WASM_ENABLE_SHARED_MEMORY == 0
|
||||||
bh_assert(memory->flags <= 1);
|
bh_assert(memory->flags <= 1);
|
||||||
#else
|
#else
|
||||||
|
@ -1536,7 +1534,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM module load failed: invalid section id");
|
"invalid section id");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1934,8 +1932,7 @@ load(const uint8 *buf, uint32 size, WASMModule *module,
|
||||||
exchange32((uint8*)&version);
|
exchange32((uint8*)&version);
|
||||||
|
|
||||||
if (version != WASM_CURRENT_VERSION) {
|
if (version != WASM_CURRENT_VERSION) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown binary version");
|
||||||
"WASM module load failed: unknown binary version");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1959,7 +1956,6 @@ wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_bu
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load(buf, size, module, error_buf, error_buf_size)) {
|
if (!load(buf, size, module, error_buf, error_buf_size)) {
|
||||||
LOG_VERBOSE("Load module failed, %s", error_buf);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2459,7 +2455,7 @@ wasm_loader_find_block_addr(BlockAddr *block_addr_cache,
|
||||||
#if WASM_DEBUG_PREPROCESSOR != 0
|
#if WASM_DEBUG_PREPROCESSOR != 0
|
||||||
#define LOG_OP(...) os_printf(__VA_ARGS__)
|
#define LOG_OP(...) os_printf(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define LOG_OP(...)
|
#define LOG_OP(...) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PATCH_ELSE 0
|
#define PATCH_ELSE 0
|
||||||
|
@ -3878,7 +3874,7 @@ wasm_loader_check_br(WASMLoaderContext *loader_ctx, uint32 depth,
|
||||||
|
|
||||||
if (loader_ctx->csp_num < depth + 1) {
|
if (loader_ctx->csp_num < depth + 1) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM module load failed: unknown label, "
|
"unknown label, "
|
||||||
"unexpected end of section or function");
|
"unexpected end of section or function");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4196,7 +4192,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
||||||
|
|
||||||
if (!(loader_ctx = wasm_loader_ctx_init(func))) {
|
if (!(loader_ctx = wasm_loader_ctx_init(func))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM loader prepare bytecode failed: "
|
|
||||||
"allocate memory failed");
|
"allocate memory failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -4206,7 +4201,6 @@ re_scan:
|
||||||
if (loader_ctx->code_compiled_size > 0) {
|
if (loader_ctx->code_compiled_size > 0) {
|
||||||
if (!wasm_loader_ctx_reinit(loader_ctx)) {
|
if (!wasm_loader_ctx_reinit(loader_ctx)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM loader prepare bytecode failed: "
|
|
||||||
"allocate memory failed");
|
"allocate memory failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -5604,8 +5598,7 @@ handle_op_block_and_loop:
|
||||||
|
|
||||||
if (loader_ctx->csp_num > 0) {
|
if (loader_ctx->csp_num > 0) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM module load failed: "
|
"function body must end with END opcode");
|
||||||
"function body must end with END opcode.");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
static void
|
static void
|
||||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||||
{
|
{
|
||||||
if (error_buf != NULL)
|
if (error_buf != NULL) {
|
||||||
snprintf(error_buf, error_buf_size, "%s", string);
|
snprintf(error_buf, error_buf_size,
|
||||||
|
"WASM module instantiate failed: %s", string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WASMModule*
|
WASMModule*
|
||||||
|
@ -50,8 +52,7 @@ runtime_malloc(uint64 size, char *error_buf, uint32 error_buf_size)
|
||||||
if (size >= UINT32_MAX
|
if (size >= UINT32_MAX
|
||||||
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
|| !(mem = wasm_runtime_malloc((uint32)size))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"WASM module instantiate failed: "
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,17 +263,13 @@ memory_instantiate(WASMModuleInstance *module_inst,
|
||||||
if (heap_size > 0
|
if (heap_size > 0
|
||||||
&& !(memory->heap_handle =
|
&& !(memory->heap_handle =
|
||||||
mem_allocator_create(memory->heap_data, heap_size))) {
|
mem_allocator_create(memory->heap_data, heap_size))) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "init app heap failed");
|
||||||
"Instantiate memory failed: "
|
|
||||||
"init app heap failed.");
|
|
||||||
goto fail1;
|
goto fail1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||||
if (0 != os_mutex_init(&memory->mem_lock)) {
|
if (0 != os_mutex_init(&memory->mem_lock)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "init mutex failed");
|
||||||
"Instantiate memory failed: "
|
|
||||||
"init mutex failed.");
|
|
||||||
goto fail2;
|
goto fail2;
|
||||||
}
|
}
|
||||||
if (is_shared_memory) {
|
if (is_shared_memory) {
|
||||||
|
@ -281,8 +278,7 @@ memory_instantiate(WASMModuleInstance *module_inst,
|
||||||
(WASMModuleCommon *)module_inst->module,
|
(WASMModuleCommon *)module_inst->module,
|
||||||
(WASMMemoryInstanceCommon *)memory)) {
|
(WASMMemoryInstanceCommon *)memory)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Instantiate memory failed: "
|
"allocate memory failed");
|
||||||
"allocate memory failed.");
|
|
||||||
goto fail3;
|
goto fail3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -735,8 +731,7 @@ globals_instantiate(const WASMModule *module,
|
||||||
sub_module_inst->globals,
|
sub_module_inst->globals,
|
||||||
sub_module_inst->global_count, &(global->initial_value));
|
sub_module_inst->global_count, &(global->initial_value));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown global");
|
||||||
"Instantiate global failed: unknown global.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -774,8 +769,7 @@ globals_instantiate(const WASMModule *module,
|
||||||
parse_init_expr(init_expr, globals, global_count,
|
parse_init_expr(init_expr, globals, global_count,
|
||||||
&(global->initial_value));
|
&(global->initial_value));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown global");
|
||||||
"Instantiate global failed: unknown global.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,8 +805,7 @@ globals_instantiate_fix(WASMGlobalInstance *globals,
|
||||||
ret = parse_init_expr(init_expr, globals, global_count,
|
ret = parse_init_expr(init_expr, globals, global_count,
|
||||||
&global->initial_value);
|
&global->initial_value);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size, "unknown global");
|
||||||
"Instantiate global failed: unknown global.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1024,18 +1017,18 @@ sub_module_instantiate(WASMModule *module, WASMModuleInstance *module_inst,
|
||||||
bh_list_first_elem(module->import_module_list);
|
bh_list_first_elem(module->import_module_list);
|
||||||
|
|
||||||
while (sub_module_list_node) {
|
while (sub_module_list_node) {
|
||||||
|
WASMSubModInstNode *sub_module_inst_list_node;
|
||||||
WASMModule *sub_module = (WASMModule*)sub_module_list_node->module;
|
WASMModule *sub_module = (WASMModule*)sub_module_list_node->module;
|
||||||
WASMModuleInstance *sub_module_inst = wasm_instantiate(
|
WASMModuleInstance *sub_module_inst =
|
||||||
sub_module, false, stack_size, heap_size, error_buf, error_buf_size);
|
wasm_instantiate(sub_module, false, stack_size, heap_size,
|
||||||
|
error_buf, error_buf_size);
|
||||||
if (!sub_module_inst) {
|
if (!sub_module_inst) {
|
||||||
LOG_DEBUG("instantiate %s failed",
|
LOG_DEBUG("instantiate %s failed",
|
||||||
sub_module_list_node->module_name);
|
sub_module_list_node->module_name);
|
||||||
set_error_buf_v(error_buf, error_buf_size, "instantiate %s failed",
|
|
||||||
sub_module_list_node->module_name);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WASMSubModInstNode *sub_module_inst_list_node = runtime_malloc
|
sub_module_inst_list_node = runtime_malloc
|
||||||
(sizeof(WASMSubModInstNode), error_buf, error_buf_size);
|
(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",
|
||||||
|
@ -1102,7 +1095,6 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
|
||||||
error_buf, error_buf_size))) {
|
error_buf, error_buf_size))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(module_inst, 0, (uint32)sizeof(WASMModuleInstance));
|
|
||||||
|
|
||||||
module_inst->module = module;
|
module_inst->module = module;
|
||||||
|
|
||||||
|
@ -1264,7 +1256,7 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
|
||||||
LOG_DEBUG("base_offset(%d) > memory_size(%d)", base_offset,
|
LOG_DEBUG("base_offset(%d) > memory_size(%d)", base_offset,
|
||||||
memory_size);
|
memory_size);
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"data segment does not fit.");
|
"data segment does not fit");
|
||||||
wasm_deinstantiate(module_inst, false);
|
wasm_deinstantiate(module_inst, false);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1274,9 +1266,8 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
|
||||||
if (base_offset + length > memory_size) {
|
if (base_offset + length > memory_size) {
|
||||||
LOG_DEBUG("base_offset(%d) + length(%d) > memory_size(%d)",
|
LOG_DEBUG("base_offset(%d) + length(%d) > memory_size(%d)",
|
||||||
base_offset, length, memory_size);
|
base_offset, length, memory_size);
|
||||||
set_error_buf(
|
set_error_buf(error_buf, error_buf_size,
|
||||||
error_buf, error_buf_size,
|
"data segment does not fit");
|
||||||
"Instantiate module failed: data segment does not fit.");
|
|
||||||
wasm_deinstantiate(module_inst, false);
|
wasm_deinstantiate(module_inst, false);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1538,7 +1529,7 @@ wasm_create_exec_env_and_call_function(WASMModuleInstance *module_inst,
|
||||||
if (!(exec_env = wasm_exec_env_create(
|
if (!(exec_env = wasm_exec_env_create(
|
||||||
(WASMModuleInstanceCommon*)module_inst,
|
(WASMModuleInstanceCommon*)module_inst,
|
||||||
module_inst->default_wasm_stack_size))) {
|
module_inst->default_wasm_stack_size))) {
|
||||||
wasm_set_exception(module_inst, "allocate memory failed.");
|
wasm_set_exception(module_inst, "allocate memory failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1764,12 +1755,10 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||||
|
|
||||||
if (total_page_count < memory->cur_page_count /* integer overflow */
|
if (total_page_count < memory->cur_page_count /* integer overflow */
|
||||||
|| total_page_count > memory->max_page_count) {
|
|| total_page_count > memory->max_page_count) {
|
||||||
wasm_set_exception(module, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total_size >= UINT32_MAX) {
|
if (total_size >= UINT32_MAX) {
|
||||||
wasm_set_exception(module, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1793,7 +1782,6 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||||
/* Restore heap's lock if memory re-alloc failed */
|
/* Restore heap's lock if memory re-alloc failed */
|
||||||
mem_allocator_reinit_lock(memory->heap_handle);
|
mem_allocator_reinit_lock(memory->heap_handle);
|
||||||
}
|
}
|
||||||
wasm_set_exception(module, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bh_memcpy_s((uint8 *)new_memory, (uint32)total_size,
|
bh_memcpy_s((uint8 *)new_memory, (uint32)total_size,
|
||||||
|
@ -1809,7 +1797,6 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||||
((uint8 *)new_memory - (uint8 *)memory);
|
((uint8 *)new_memory - (uint8 *)memory);
|
||||||
if (mem_allocator_migrate(new_memory->heap_handle,
|
if (mem_allocator_migrate(new_memory->heap_handle,
|
||||||
heap_handle_old) != 0) {
|
heap_handle_old) != 0) {
|
||||||
wasm_set_exception(module, "fail to enlarge memory.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user