|
@@ -4,8 +4,7 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
#include "wasm_loader.h"
|
|
#include "wasm_loader.h"
|
|
|
-#include "bh_common.h"
|
|
|
|
|
-#include "bh_log.h"
|
|
|
|
|
|
|
+#include "bh_platform.h"
|
|
|
#include "wasm.h"
|
|
#include "wasm.h"
|
|
|
#include "wasm_opcode.h"
|
|
#include "wasm_opcode.h"
|
|
|
#include "wasm_runtime.h"
|
|
#include "wasm_runtime.h"
|
|
@@ -51,6 +50,18 @@ has_module_memory64(WASMModule *module)
|
|
|
|
|
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+static bool
|
|
|
|
|
+is_table_64bit(WASMModule *module, uint32 table_idx)
|
|
|
|
|
+{
|
|
|
|
|
+ if (table_idx < module->import_table_count)
|
|
|
|
|
+ return !!(module->import_tables[table_idx].u.table.table_type.flags
|
|
|
|
|
+ & TABLE64_FLAG);
|
|
|
|
|
+ else
|
|
|
|
|
+ return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG);
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
static void
|
|
@@ -2201,10 +2212,14 @@ fail:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
static void
|
|
|
-adjust_table_max_size(uint32 init_size, uint32 max_size_flag, uint32 *max_size)
|
|
|
|
|
|
|
+adjust_table_max_size(bool is_table64, uint32 init_size, uint32 max_size_flag,
|
|
|
|
|
+ uint32 *max_size)
|
|
|
{
|
|
{
|
|
|
uint32 default_max_size;
|
|
uint32 default_max_size;
|
|
|
|
|
|
|
|
|
|
+ /* TODO: current still use UINT32_MAX as upper limit for table size to keep
|
|
|
|
|
+ * ABI unchanged */
|
|
|
|
|
+ (void)is_table64;
|
|
|
if (UINT32_MAX / 2 > init_size)
|
|
if (UINT32_MAX / 2 > init_size)
|
|
|
default_max_size = init_size * 2;
|
|
default_max_size = init_size * 2;
|
|
|
else
|
|
else
|
|
@@ -2246,60 +2261,6 @@ wasm_loader_find_export(const WASMModule *module, const char *module_name,
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
-static WASMFunction *
|
|
|
|
|
-wasm_loader_resolve_function(const char *module_name, const char *function_name,
|
|
|
|
|
- const WASMFuncType *expected_function_type,
|
|
|
|
|
- char *error_buf, uint32 error_buf_size)
|
|
|
|
|
-{
|
|
|
|
|
- WASMModuleCommon *module_reg;
|
|
|
|
|
- WASMFunction *function = NULL;
|
|
|
|
|
- WASMExport *export = NULL;
|
|
|
|
|
- WASMModule *module = NULL;
|
|
|
|
|
- WASMFuncType *target_function_type = NULL;
|
|
|
|
|
-
|
|
|
|
|
- module_reg = wasm_runtime_find_module_registered(module_name);
|
|
|
|
|
- if (!module_reg || module_reg->module_type != Wasm_Module_Bytecode) {
|
|
|
|
|
- LOG_DEBUG("can not find a module named %s for function %s", module_name,
|
|
|
|
|
- function_name);
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size, "unknown import");
|
|
|
|
|
- return NULL;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- module = (WASMModule *)module_reg;
|
|
|
|
|
- export =
|
|
|
|
|
- wasm_loader_find_export(module, module_name, function_name,
|
|
|
|
|
- EXPORT_KIND_FUNC, error_buf, error_buf_size);
|
|
|
|
|
- if (!export) {
|
|
|
|
|
- return NULL;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /* resolve function type and function */
|
|
|
|
|
- if (export->index < module->import_function_count) {
|
|
|
|
|
- target_function_type =
|
|
|
|
|
- module->import_functions[export->index].u.function.func_type;
|
|
|
|
|
- function = module->import_functions[export->index]
|
|
|
|
|
- .u.function.import_func_linked;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- target_function_type =
|
|
|
|
|
- module->functions[export->index - module->import_function_count]
|
|
|
|
|
- ->func_type;
|
|
|
|
|
- function =
|
|
|
|
|
- module->functions[export->index - module->import_function_count];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /* check function type */
|
|
|
|
|
- if (!wasm_type_equal((WASMType *)expected_function_type,
|
|
|
|
|
- (WASMType *)target_function_type, module->types,
|
|
|
|
|
- module->type_count)) {
|
|
|
|
|
- LOG_DEBUG("%s.%s failed the type check", module_name, function_name);
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size, "incompatible import type");
|
|
|
|
|
- return NULL;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return function;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
static WASMTable *
|
|
static WASMTable *
|
|
|
wasm_loader_resolve_table(const char *module_name, const char *table_name,
|
|
wasm_loader_resolve_table(const char *module_name, const char *table_name,
|
|
|
uint32 init_size, uint32 max_size, char *error_buf,
|
|
uint32 init_size, uint32 max_size, char *error_buf,
|
|
@@ -2474,7 +2435,8 @@ wasm_loader_resolve_tag(const char *module_name, const char *tag_name,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* check function type */
|
|
/* check function type */
|
|
|
- if (!wasm_type_equal(expected_tag_type, tag->tag_type)) {
|
|
|
|
|
|
|
+ if (!wasm_type_equal(expected_tag_type, tag->tag_type, module->types,
|
|
|
|
|
+ module->type_count)) {
|
|
|
LOG_DEBUG("%s.%s failed the type check", module_name, tag_name);
|
|
LOG_DEBUG("%s.%s failed the type check", module_name, tag_name);
|
|
|
set_error_buf(error_buf, error_buf_size, "incompatible import type");
|
|
set_error_buf(error_buf, error_buf_size, "incompatible import type");
|
|
|
return NULL;
|
|
return NULL;
|
|
@@ -2493,21 +2455,11 @@ static bool
|
|
|
load_function_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
load_function_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
const WASMModule *parent_module,
|
|
const WASMModule *parent_module,
|
|
|
const char *sub_module_name, const char *function_name,
|
|
const char *sub_module_name, const char *function_name,
|
|
|
- WASMFunctionImport *function, char *error_buf,
|
|
|
|
|
- uint32 error_buf_size)
|
|
|
|
|
|
|
+ WASMFunctionImport *function, bool no_resolve,
|
|
|
|
|
+ char *error_buf, uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
const uint8 *p = *p_buf, *p_end = buf_end;
|
|
const uint8 *p = *p_buf, *p_end = buf_end;
|
|
|
uint32 declare_type_index = 0;
|
|
uint32 declare_type_index = 0;
|
|
|
- WASMFuncType *declare_func_type = NULL;
|
|
|
|
|
- WASMFunction *linked_func = NULL;
|
|
|
|
|
-#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
|
- WASMModule *sub_module = NULL;
|
|
|
|
|
- bool is_built_in_module = false;
|
|
|
|
|
-#endif
|
|
|
|
|
- const char *linked_signature = NULL;
|
|
|
|
|
- void *linked_attachment = NULL;
|
|
|
|
|
- bool linked_call_conv_raw = false;
|
|
|
|
|
- bool is_native_symbol = false;
|
|
|
|
|
|
|
|
|
|
read_leb_uint32(p, p_end, declare_type_index);
|
|
read_leb_uint32(p, p_end, declare_type_index);
|
|
|
*p_buf = p;
|
|
*p_buf = p;
|
|
@@ -2526,43 +2478,19 @@ load_function_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
parent_module->types, parent_module->type_count, declare_type_index);
|
|
parent_module->types, parent_module->type_count, declare_type_index);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- declare_func_type =
|
|
|
|
|
|
|
+ function->func_type =
|
|
|
(WASMFuncType *)parent_module->types[declare_type_index];
|
|
(WASMFuncType *)parent_module->types[declare_type_index];
|
|
|
|
|
|
|
|
- /* lookup registered native symbols first */
|
|
|
|
|
- linked_func = wasm_native_resolve_symbol(
|
|
|
|
|
- sub_module_name, function_name, declare_func_type, &linked_signature,
|
|
|
|
|
- &linked_attachment, &linked_call_conv_raw);
|
|
|
|
|
- if (linked_func) {
|
|
|
|
|
- is_native_symbol = true;
|
|
|
|
|
- }
|
|
|
|
|
-#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
|
- else {
|
|
|
|
|
- if (!(is_built_in_module =
|
|
|
|
|
- wasm_runtime_is_built_in_module(sub_module_name))) {
|
|
|
|
|
- sub_module = (WASMModule *)wasm_runtime_load_depended_module(
|
|
|
|
|
- (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
|
|
|
|
|
- error_buf_size);
|
|
|
|
|
- }
|
|
|
|
|
- if (is_built_in_module || sub_module)
|
|
|
|
|
- linked_func = wasm_loader_resolve_function(
|
|
|
|
|
- sub_module_name, function_name, declare_func_type, error_buf,
|
|
|
|
|
- error_buf_size);
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
function->module_name = (char *)sub_module_name;
|
|
function->module_name = (char *)sub_module_name;
|
|
|
function->field_name = (char *)function_name;
|
|
function->field_name = (char *)function_name;
|
|
|
- function->func_type = declare_func_type;
|
|
|
|
|
- /* func_ptr_linked is for native registered symbol */
|
|
|
|
|
- function->func_ptr_linked = is_native_symbol ? linked_func : NULL;
|
|
|
|
|
- function->signature = linked_signature;
|
|
|
|
|
- function->attachment = linked_attachment;
|
|
|
|
|
- function->call_conv_raw = linked_call_conv_raw;
|
|
|
|
|
-#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
|
- function->import_module = is_native_symbol ? NULL : sub_module;
|
|
|
|
|
- function->import_func_linked = is_native_symbol ? NULL : linked_func;
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ function->attachment = NULL;
|
|
|
|
|
+ function->signature = NULL;
|
|
|
|
|
+ function->call_conv_raw = false;
|
|
|
|
|
+
|
|
|
|
|
+ /* lookup registered native symbols first */
|
|
|
|
|
+ if (!no_resolve) {
|
|
|
|
|
+ wasm_resolve_import_func(parent_module, function);
|
|
|
|
|
+ }
|
|
|
return true;
|
|
return true;
|
|
|
fail:
|
|
fail:
|
|
|
return false;
|
|
return false;
|
|
@@ -2586,9 +2514,9 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
const char *table_name, WASMTableImport *table,
|
|
const char *table_name, WASMTableImport *table,
|
|
|
char *error_buf, uint32 error_buf_size)
|
|
char *error_buf, uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
- const uint8 *p = *p_buf, *p_end = buf_end;
|
|
|
|
|
- uint32 declare_elem_type = 0, declare_max_size_flag = 0,
|
|
|
|
|
- declare_init_size = 0, declare_max_size = 0;
|
|
|
|
|
|
|
+ const uint8 *p = *p_buf, *p_end = buf_end, *p_org;
|
|
|
|
|
+ uint32 declare_elem_type = 0, table_flag = 0, declare_init_size = 0,
|
|
|
|
|
+ declare_max_size = 0;
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
WASMModule *sub_module = NULL;
|
|
WASMModule *sub_module = NULL;
|
|
|
WASMTable *linked_table = NULL;
|
|
WASMTable *linked_table = NULL;
|
|
@@ -2597,6 +2525,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
WASMRefType ref_type;
|
|
WASMRefType ref_type;
|
|
|
bool need_ref_type_map;
|
|
bool need_ref_type_map;
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+ bool is_table64 = false;
|
|
|
|
|
|
|
|
#if WASM_ENABLE_GC == 0
|
|
#if WASM_ENABLE_GC == 0
|
|
|
CHECK_BUF(p, p_end, 1);
|
|
CHECK_BUF(p, p_end, 1);
|
|
@@ -2635,23 +2564,29 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
#endif
|
|
#endif
|
|
|
#endif /* end of WASM_ENABLE_GC == 0 */
|
|
#endif /* end of WASM_ENABLE_GC == 0 */
|
|
|
|
|
|
|
|
- read_leb_uint32(p, p_end, declare_max_size_flag);
|
|
|
|
|
- if (declare_max_size_flag > 1) {
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size, "integer too large");
|
|
|
|
|
|
|
+ p_org = p;
|
|
|
|
|
+ read_leb_uint32(p, p_end, table_flag);
|
|
|
|
|
+ is_table64 = table_flag & TABLE64_FLAG;
|
|
|
|
|
+ if (p - p_org > 1) {
|
|
|
|
|
+ LOG_VERBOSE("integer representation too long(import table)");
|
|
|
|
|
+ set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!wasm_table_check_flags(table_flag, error_buf, error_buf_size, false)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
read_leb_uint32(p, p_end, declare_init_size);
|
|
read_leb_uint32(p, p_end, declare_init_size);
|
|
|
-
|
|
|
|
|
- if (declare_max_size_flag) {
|
|
|
|
|
|
|
+ if (table_flag & MAX_TABLE_SIZE_FLAG) {
|
|
|
read_leb_uint32(p, p_end, declare_max_size);
|
|
read_leb_uint32(p, p_end, declare_max_size);
|
|
|
if (!check_table_max_size(declare_init_size, declare_max_size,
|
|
if (!check_table_max_size(declare_init_size, declare_max_size,
|
|
|
error_buf, error_buf_size))
|
|
error_buf, error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- adjust_table_max_size(declare_init_size, declare_max_size_flag,
|
|
|
|
|
- &declare_max_size);
|
|
|
|
|
|
|
+ adjust_table_max_size(is_table64, declare_init_size,
|
|
|
|
|
+ table_flag & MAX_TABLE_SIZE_FLAG, &declare_max_size);
|
|
|
|
|
|
|
|
*p_buf = p;
|
|
*p_buf = p;
|
|
|
|
|
|
|
@@ -2669,7 +2604,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
declare_elem_type = linked_table->table_type.elem_type;
|
|
declare_elem_type = linked_table->table_type.elem_type;
|
|
|
declare_init_size = linked_table->table_type.init_size;
|
|
declare_init_size = linked_table->table_type.init_size;
|
|
|
declare_max_size = linked_table->table_type.max_size;
|
|
declare_max_size = linked_table->table_type.max_size;
|
|
|
- declare_max_size_flag = linked_table->table_type.flags;
|
|
|
|
|
|
|
+ table_flag = linked_table->table_type.flags;
|
|
|
table->import_table_linked = linked_table;
|
|
table->import_table_linked = linked_table;
|
|
|
table->import_module = sub_module;
|
|
table->import_module = sub_module;
|
|
|
}
|
|
}
|
|
@@ -2678,12 +2613,17 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
#endif /* WASM_ENABLE_MULTI_MODULE != 0 */
|
|
#endif /* WASM_ENABLE_MULTI_MODULE != 0 */
|
|
|
|
|
|
|
|
/* (table (export "table") 10 20 funcref) */
|
|
/* (table (export "table") 10 20 funcref) */
|
|
|
|
|
+ /* (table (export "table64") 10 20 funcref) */
|
|
|
/* we need this section working in wamrc */
|
|
/* we need this section working in wamrc */
|
|
|
if (!strcmp("spectest", sub_module_name)) {
|
|
if (!strcmp("spectest", sub_module_name)) {
|
|
|
const uint32 spectest_table_init_size = 10;
|
|
const uint32 spectest_table_init_size = 10;
|
|
|
const uint32 spectest_table_max_size = 20;
|
|
const uint32 spectest_table_max_size = 20;
|
|
|
|
|
|
|
|
- if (strcmp("table", table_name)) {
|
|
|
|
|
|
|
+ if (strcmp("table", table_name)
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ && strcmp("table64", table_name)
|
|
|
|
|
+#endif
|
|
|
|
|
+ ) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"incompatible import type or unknown import");
|
|
"incompatible import type or unknown import");
|
|
|
return false;
|
|
return false;
|
|
@@ -2703,7 +2643,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
/* now we believe all declaration are ok */
|
|
/* now we believe all declaration are ok */
|
|
|
table->table_type.elem_type = declare_elem_type;
|
|
table->table_type.elem_type = declare_elem_type;
|
|
|
table->table_type.init_size = declare_init_size;
|
|
table->table_type.init_size = declare_init_size;
|
|
|
- table->table_type.flags = declare_max_size_flag;
|
|
|
|
|
|
|
+ table->table_type.flags = table_flag;
|
|
|
table->table_type.max_size = declare_max_size;
|
|
table->table_type.max_size = declare_max_size;
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
@@ -2796,7 +2736,7 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
|
|
|
read_leb_uint32(p, p_end, mem_flag);
|
|
read_leb_uint32(p, p_end, mem_flag);
|
|
|
is_memory64 = mem_flag & MEMORY64_FLAG;
|
|
is_memory64 = mem_flag & MEMORY64_FLAG;
|
|
|
if (p - p_org > 1) {
|
|
if (p - p_org > 1) {
|
|
|
- LOG_VERBOSE("integer representation too long");
|
|
|
|
|
|
|
+ LOG_VERBOSE("integer representation too long(import memory)");
|
|
|
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -3111,6 +3051,7 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
|
|
|
WASMRefType ref_type;
|
|
WASMRefType ref_type;
|
|
|
bool need_ref_type_map;
|
|
bool need_ref_type_map;
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+ bool is_table64 = false;
|
|
|
|
|
|
|
|
#if WASM_ENABLE_GC == 0
|
|
#if WASM_ENABLE_GC == 0
|
|
|
CHECK_BUF(p, p_end, 1);
|
|
CHECK_BUF(p, p_end, 1);
|
|
@@ -3148,34 +3089,20 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
|
|
|
|
|
|
|
|
p_org = p;
|
|
p_org = p;
|
|
|
read_leb_uint32(p, p_end, table->table_type.flags);
|
|
read_leb_uint32(p, p_end, table->table_type.flags);
|
|
|
-#if WASM_ENABLE_SHARED_MEMORY == 0
|
|
|
|
|
- if (p - p_org > 1) {
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size,
|
|
|
|
|
- "integer representation too long");
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- if (table->table_type.flags > 1) {
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size, "integer too large");
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-#else
|
|
|
|
|
|
|
+ is_table64 = table->table_type.flags & TABLE64_FLAG;
|
|
|
if (p - p_org > 1) {
|
|
if (p - p_org > 1) {
|
|
|
|
|
+ LOG_VERBOSE("integer representation too long(table)");
|
|
|
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- if (table->table_type.flags == 2) {
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size, "tables cannot be shared");
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- if (table->table_type.flags > 1) {
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (!wasm_table_check_flags(table->table_type.flags, error_buf,
|
|
|
|
|
+ error_buf_size, false)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
read_leb_uint32(p, p_end, table->table_type.init_size);
|
|
read_leb_uint32(p, p_end, table->table_type.init_size);
|
|
|
-
|
|
|
|
|
- if (table->table_type.flags) {
|
|
|
|
|
|
|
+ if (table->table_type.flags & MAX_TABLE_SIZE_FLAG) {
|
|
|
read_leb_uint32(p, p_end, table->table_type.max_size);
|
|
read_leb_uint32(p, p_end, table->table_type.max_size);
|
|
|
if (!check_table_max_size(table->table_type.init_size,
|
|
if (!check_table_max_size(table->table_type.init_size,
|
|
|
table->table_type.max_size, error_buf,
|
|
table->table_type.max_size, error_buf,
|
|
@@ -3183,7 +3110,8 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- adjust_table_max_size(table->table_type.init_size, table->table_type.flags,
|
|
|
|
|
|
|
+ adjust_table_max_size(is_table64, table->table_type.init_size,
|
|
|
|
|
+ table->table_type.flags & MAX_TABLE_SIZE_FLAG,
|
|
|
&table->table_type.max_size);
|
|
&table->table_type.max_size);
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
@@ -3215,7 +3143,7 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
|
|
|
read_leb_uint32(p, p_end, memory->flags);
|
|
read_leb_uint32(p, p_end, memory->flags);
|
|
|
is_memory64 = memory->flags & MEMORY64_FLAG;
|
|
is_memory64 = memory->flags & MEMORY64_FLAG;
|
|
|
if (p - p_org > 1) {
|
|
if (p - p_org > 1) {
|
|
|
- LOG_VERBOSE("integer representation too long");
|
|
|
|
|
|
|
+ LOG_VERBOSE("integer representation too long(memory)");
|
|
|
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
set_error_buf(error_buf, error_buf_size, "invalid limits flags");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -3255,10 +3183,16 @@ fail:
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int
|
|
|
|
|
+cmp_export_name(const void *a, const void *b)
|
|
|
|
|
+{
|
|
|
|
|
+ return strcmp(*(char **)a, *(char **)b);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static bool
|
|
static bool
|
|
|
load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
- bool is_load_from_file_buf, char *error_buf,
|
|
|
|
|
- uint32 error_buf_size)
|
|
|
|
|
|
|
+ bool is_load_from_file_buf, bool no_resolve,
|
|
|
|
|
+ char *error_buf, uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
const uint8 *p = buf, *p_end = buf_end, *p_old;
|
|
const uint8 *p = buf, *p_end = buf_end, *p_old;
|
|
|
uint32 import_count, name_len, type_index, i, u32, flags;
|
|
uint32 import_count, name_len, type_index, i, u32, flags;
|
|
@@ -3441,9 +3375,10 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
case IMPORT_KIND_FUNC: /* import function */
|
|
case IMPORT_KIND_FUNC: /* import function */
|
|
|
bh_assert(import_functions);
|
|
bh_assert(import_functions);
|
|
|
import = import_functions++;
|
|
import = import_functions++;
|
|
|
- if (!load_function_import(
|
|
|
|
|
- &p, p_end, module, sub_module_name, field_name,
|
|
|
|
|
- &import->u.function, error_buf, error_buf_size)) {
|
|
|
|
|
|
|
+ if (!load_function_import(&p, p_end, module,
|
|
|
|
|
+ sub_module_name, field_name,
|
|
|
|
|
+ &import->u.function, no_resolve,
|
|
|
|
|
+ error_buf, error_buf_size)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -4124,17 +4059,53 @@ fail:
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static bool
|
|
|
|
|
+check_duplicate_exports(WASMModule *module, char *error_buf,
|
|
|
|
|
+ uint32 error_buf_size)
|
|
|
|
|
+{
|
|
|
|
|
+ uint32 i;
|
|
|
|
|
+ bool result = false;
|
|
|
|
|
+ char *names_buf[32], **names = names_buf;
|
|
|
|
|
+
|
|
|
|
|
+ if (module->export_count > 32) {
|
|
|
|
|
+ names = loader_malloc(module->export_count * sizeof(char *), error_buf,
|
|
|
|
|
+ error_buf_size);
|
|
|
|
|
+ if (!names) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < module->export_count; i++) {
|
|
|
|
|
+ names[i] = module->exports[i].name;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ qsort(names, module->export_count, sizeof(char *), cmp_export_name);
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 1; i < module->export_count; i++) {
|
|
|
|
|
+ if (!strcmp(names[i], names[i - 1])) {
|
|
|
|
|
+ set_error_buf(error_buf, error_buf_size, "duplicate export name");
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result = true;
|
|
|
|
|
+cleanup:
|
|
|
|
|
+ if (module->export_count > 32) {
|
|
|
|
|
+ wasm_runtime_free(names);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static bool
|
|
static bool
|
|
|
load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
bool is_load_from_file_buf, char *error_buf,
|
|
bool is_load_from_file_buf, char *error_buf,
|
|
|
uint32 error_buf_size)
|
|
uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
|
- uint32 export_count, i, j, index;
|
|
|
|
|
|
|
+ uint32 export_count, i, index;
|
|
|
uint64 total_size;
|
|
uint64 total_size;
|
|
|
uint32 str_len;
|
|
uint32 str_len;
|
|
|
WASMExport *export;
|
|
WASMExport *export;
|
|
|
- const char *name;
|
|
|
|
|
|
|
|
|
|
read_leb_uint32(p, p_end, export_count);
|
|
read_leb_uint32(p, p_end, export_count);
|
|
|
|
|
|
|
@@ -4160,15 +4131,6 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
read_leb_uint32(p, p_end, str_len);
|
|
read_leb_uint32(p, p_end, str_len);
|
|
|
CHECK_BUF(p, p_end, str_len);
|
|
CHECK_BUF(p, p_end, str_len);
|
|
|
|
|
|
|
|
- for (j = 0; j < i; j++) {
|
|
|
|
|
- name = module->exports[j].name;
|
|
|
|
|
- if (strlen(name) == str_len && memcmp(name, p, str_len) == 0) {
|
|
|
|
|
- set_error_buf(error_buf, error_buf_size,
|
|
|
|
|
- "duplicate export name");
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (!(export->name = wasm_const_str_list_insert(
|
|
if (!(export->name = wasm_const_str_list_insert(
|
|
|
p, str_len, module, is_load_from_file_buf, error_buf,
|
|
p, str_len, module, is_load_from_file_buf, error_buf,
|
|
|
error_buf_size))) {
|
|
error_buf_size))) {
|
|
@@ -4241,6 +4203,10 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (!check_duplicate_exports(module, error_buf, error_buf_size)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (p != p_end) {
|
|
if (p != p_end) {
|
|
@@ -4488,6 +4454,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
uint32 error_buf_size)
|
|
uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
|
|
|
+ uint8 table_elem_idx_type;
|
|
|
uint32 table_segment_count, i;
|
|
uint32 table_segment_count, i;
|
|
|
uint64 total_size;
|
|
uint64 total_size;
|
|
|
WASMTableSeg *table_segment;
|
|
WASMTableSeg *table_segment;
|
|
@@ -4510,6 +4477,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
"invalid elements segment kind");
|
|
"invalid elements segment kind");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ table_elem_idx_type = VALUE_TYPE_I32;
|
|
|
|
|
|
|
|
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
|
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
|
|
read_leb_uint32(p, p_end, table_segment->mode);
|
|
read_leb_uint32(p, p_end, table_segment->mode);
|
|
@@ -4545,9 +4513,17 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
if (!check_table_index(module, table_segment->table_index,
|
|
if (!check_table_index(module, table_segment->table_index,
|
|
|
error_buf, error_buf_size))
|
|
error_buf, error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
- if (!load_init_expr(
|
|
|
|
|
- module, &p, p_end, &table_segment->base_offset,
|
|
|
|
|
- VALUE_TYPE_I32, NULL, error_buf, error_buf_size))
|
|
|
|
|
|
|
+
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type =
|
|
|
|
|
+ is_table_64bit(module, table_segment->table_index)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
|
|
+ if (!load_init_expr(module, &p, p_end,
|
|
|
|
|
+ &table_segment->base_offset,
|
|
|
|
|
+ table_elem_idx_type, NULL, error_buf,
|
|
|
|
|
+ error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
if (table_segment->mode == 0) {
|
|
if (table_segment->mode == 0) {
|
|
@@ -4595,9 +4571,16 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
&table_segment->table_index,
|
|
&table_segment->table_index,
|
|
|
error_buf, error_buf_size))
|
|
error_buf, error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
- if (!load_init_expr(
|
|
|
|
|
- module, &p, p_end, &table_segment->base_offset,
|
|
|
|
|
- VALUE_TYPE_I32, NULL, error_buf, error_buf_size))
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type =
|
|
|
|
|
+ is_table_64bit(module, table_segment->table_index)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
|
|
+ if (!load_init_expr(module, &p, p_end,
|
|
|
|
|
+ &table_segment->base_offset,
|
|
|
|
|
+ table_elem_idx_type, NULL, error_buf,
|
|
|
|
|
+ error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
if (!load_elem_type(module, &p, p_end,
|
|
if (!load_elem_type(module, &p, p_end,
|
|
|
&table_segment->elem_type,
|
|
&table_segment->elem_type,
|
|
@@ -4649,7 +4632,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
"unknown element segment kind");
|
|
"unknown element segment kind");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-#else /* else of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
|
|
|
|
|
|
|
+#else /* else of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
|
|
|
/*
|
|
/*
|
|
|
* like: 00 41 05 0b 04 00 01 00 01
|
|
* like: 00 41 05 0b 04 00 01 00 01
|
|
|
* for: (elem 0 (offset (i32.const 5)) $f1 $f2 $f1 $f2)
|
|
* for: (elem 0 (offset (i32.const 5)) $f1 $f2 $f1 $f2)
|
|
@@ -4658,8 +4641,14 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
&table_segment->table_index, error_buf,
|
|
&table_segment->table_index, error_buf,
|
|
|
error_buf_size))
|
|
error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type =
|
|
|
|
|
+ is_table_64bit(module, table_segment->table_index)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
if (!load_init_expr(module, &p, p_end, &table_segment->base_offset,
|
|
if (!load_init_expr(module, &p, p_end, &table_segment->base_offset,
|
|
|
- VALUE_TYPE_I32, NULL, error_buf,
|
|
|
|
|
|
|
+ table_elem_idx_type, NULL, error_buf,
|
|
|
error_buf_size))
|
|
error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
if (!load_func_index_vec(&p, p_end, module, table_segment,
|
|
if (!load_func_index_vec(&p, p_end, module, table_segment,
|
|
@@ -4674,6 +4663,16 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
return false;
|
|
return false;
|
|
|
#endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
|
|
#endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
|
|
|
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ if (table_elem_idx_type == VALUE_TYPE_I64
|
|
|
|
|
+ && table_segment->base_offset.u.u64 > UINT32_MAX) {
|
|
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
|
|
+ "In table64, table base offset can't be "
|
|
|
|
|
+ "larger than UINT32_MAX");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
|
if (table_segment->elem_type == VALUE_TYPE_EXTERNREF)
|
|
if (table_segment->elem_type == VALUE_TYPE_EXTERNREF)
|
|
|
module->is_ref_types_used = true;
|
|
module->is_ref_types_used = true;
|
|
@@ -5406,7 +5405,8 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf,
|
|
|
option.enable_aux_stack_check = true;
|
|
option.enable_aux_stack_check = true;
|
|
|
#if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0 \
|
|
#if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0 \
|
|
|
|| WASM_ENABLE_AOT_STACK_FRAME != 0
|
|
|| WASM_ENABLE_AOT_STACK_FRAME != 0
|
|
|
- option.enable_aux_stack_frame = true;
|
|
|
|
|
|
|
+ option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD;
|
|
|
|
|
+ aot_call_stack_features_init_default(&option.call_stack_features);
|
|
|
#endif
|
|
#endif
|
|
|
#if WASM_ENABLE_PERF_PROFILING != 0
|
|
#if WASM_ENABLE_PERF_PROFILING != 0
|
|
|
option.enable_perf_profiling = true;
|
|
option.enable_perf_profiling = true;
|
|
@@ -5415,6 +5415,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf,
|
|
|
option.enable_memory_profiling = true;
|
|
option.enable_memory_profiling = true;
|
|
|
option.enable_stack_estimation = true;
|
|
option.enable_stack_estimation = true;
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+#if WASM_ENABLE_SHARED_HEAP != 0
|
|
|
|
|
+ option.enable_shared_heap = true;
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
module->comp_ctx = aot_create_comp_context(module->comp_data, &option);
|
|
module->comp_ctx = aot_create_comp_context(module->comp_data, &option);
|
|
|
if (!module->comp_ctx) {
|
|
if (!module->comp_ctx) {
|
|
@@ -5750,7 +5753,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
|
|
|
|
|
#if WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
#if WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
|
void **
|
|
void **
|
|
|
-wasm_interp_get_handle_table();
|
|
|
|
|
|
|
+wasm_interp_get_handle_table(void);
|
|
|
|
|
|
|
|
static void **handle_table;
|
|
static void **handle_table;
|
|
|
#endif
|
|
#endif
|
|
@@ -5758,7 +5761,7 @@ static void **handle_table;
|
|
|
static bool
|
|
static bool
|
|
|
load_from_sections(WASMModule *module, WASMSection *sections,
|
|
load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
bool is_load_from_file_buf, bool wasm_binary_freeable,
|
|
bool is_load_from_file_buf, bool wasm_binary_freeable,
|
|
|
- char *error_buf, uint32 error_buf_size)
|
|
|
|
|
|
|
+ bool no_resolve, char *error_buf, uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
WASMExport *export;
|
|
WASMExport *export;
|
|
|
WASMSection *section = sections;
|
|
WASMSection *section = sections;
|
|
@@ -5815,8 +5818,8 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
break;
|
|
break;
|
|
|
case SECTION_TYPE_IMPORT:
|
|
case SECTION_TYPE_IMPORT:
|
|
|
if (!load_import_section(buf, buf_end, module,
|
|
if (!load_import_section(buf, buf_end, module,
|
|
|
- reuse_const_strings, error_buf,
|
|
|
|
|
- error_buf_size))
|
|
|
|
|
|
|
+ reuse_const_strings, no_resolve,
|
|
|
|
|
+ error_buf, error_buf_size))
|
|
|
return false;
|
|
return false;
|
|
|
break;
|
|
break;
|
|
|
case SECTION_TYPE_FUNC:
|
|
case SECTION_TYPE_FUNC:
|
|
@@ -6195,6 +6198,12 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ if (!check_memory64_flags_consistency(module, error_buf, error_buf_size,
|
|
|
|
|
+ false))
|
|
|
|
|
+ return false;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
calculate_global_data_offset(module);
|
|
calculate_global_data_offset(module);
|
|
|
|
|
|
|
|
#if WASM_ENABLE_FAST_JIT != 0
|
|
#if WASM_ENABLE_FAST_JIT != 0
|
|
@@ -6341,7 +6350,7 @@ wasm_loader_load_from_sections(WASMSection *section_list, char *error_buf,
|
|
|
if (!module)
|
|
if (!module)
|
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
|
|
- if (!load_from_sections(module, section_list, false, true, error_buf,
|
|
|
|
|
|
|
+ if (!load_from_sections(module, section_list, false, true, false, error_buf,
|
|
|
error_buf_size)) {
|
|
error_buf_size)) {
|
|
|
wasm_loader_unload(module);
|
|
wasm_loader_unload(module);
|
|
|
return NULL;
|
|
return NULL;
|
|
@@ -6486,7 +6495,8 @@ static union {
|
|
|
|
|
|
|
|
static bool
|
|
static bool
|
|
|
load(const uint8 *buf, uint32 size, WASMModule *module,
|
|
load(const uint8 *buf, uint32 size, WASMModule *module,
|
|
|
- bool wasm_binary_freeable, char *error_buf, uint32 error_buf_size)
|
|
|
|
|
|
|
+ bool wasm_binary_freeable, bool no_resolve, char *error_buf,
|
|
|
|
|
+ uint32 error_buf_size)
|
|
|
{
|
|
{
|
|
|
const uint8 *buf_end = buf + size;
|
|
const uint8 *buf_end = buf + size;
|
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
@@ -6517,7 +6527,7 @@ load(const uint8 *buf, uint32 size, WASMModule *module,
|
|
|
|
|
|
|
|
if (!create_sections(buf, size, §ion_list, error_buf, error_buf_size)
|
|
if (!create_sections(buf, size, §ion_list, error_buf, error_buf_size)
|
|
|
|| !load_from_sections(module, section_list, true, wasm_binary_freeable,
|
|
|| !load_from_sections(module, section_list, true, wasm_binary_freeable,
|
|
|
- error_buf, error_buf_size)) {
|
|
|
|
|
|
|
+ no_resolve, error_buf, error_buf_size)) {
|
|
|
destroy_sections(section_list);
|
|
destroy_sections(section_list);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -6693,8 +6703,8 @@ wasm_loader_load(uint8 *buf, uint32 size,
|
|
|
module->load_size = size;
|
|
module->load_size = size;
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- if (!load(buf, size, module, args->wasm_binary_freeable, error_buf,
|
|
|
|
|
- error_buf_size)) {
|
|
|
|
|
|
|
+ if (!load(buf, size, module, args->wasm_binary_freeable, args->no_resolve,
|
|
|
|
|
+ error_buf, error_buf_size)) {
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -9692,6 +9702,7 @@ fail:
|
|
|
#define POP_REF(Type) TEMPLATE_POP_REF(Type)
|
|
#define POP_REF(Type) TEMPLATE_POP_REF(Type)
|
|
|
#define PUSH_MEM_OFFSET() TEMPLATE_PUSH_REF(mem_offset_type)
|
|
#define PUSH_MEM_OFFSET() TEMPLATE_PUSH_REF(mem_offset_type)
|
|
|
#define PUSH_PAGE_COUNT() PUSH_MEM_OFFSET()
|
|
#define PUSH_PAGE_COUNT() PUSH_MEM_OFFSET()
|
|
|
|
|
+#define PUSH_TBL_ELEM_IDX() TEMPLATE_PUSH_REF(table_elem_idx_type)
|
|
|
|
|
|
|
|
#define POP_I32() TEMPLATE_POP(I32)
|
|
#define POP_I32() TEMPLATE_POP(I32)
|
|
|
#define POP_F32() TEMPLATE_POP(F32)
|
|
#define POP_F32() TEMPLATE_POP(F32)
|
|
@@ -9702,6 +9713,7 @@ fail:
|
|
|
#define POP_EXTERNREF() TEMPLATE_POP(EXTERNREF)
|
|
#define POP_EXTERNREF() TEMPLATE_POP(EXTERNREF)
|
|
|
#define POP_STRINGREF() TEMPLATE_POP(STRINGREF)
|
|
#define POP_STRINGREF() TEMPLATE_POP(STRINGREF)
|
|
|
#define POP_MEM_OFFSET() TEMPLATE_POP_REF(mem_offset_type)
|
|
#define POP_MEM_OFFSET() TEMPLATE_POP_REF(mem_offset_type)
|
|
|
|
|
+#define POP_TBL_ELEM_IDX() TEMPLATE_POP_REF(table_elem_idx_type)
|
|
|
|
|
|
|
|
#if WASM_ENABLE_FAST_INTERP != 0
|
|
#if WASM_ENABLE_FAST_INTERP != 0
|
|
|
|
|
|
|
@@ -10887,7 +10899,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
{
|
|
{
|
|
|
uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org;
|
|
uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org;
|
|
|
uint32 param_count, local_count, global_count;
|
|
uint32 param_count, local_count, global_count;
|
|
|
- uint8 *param_types, *local_types, local_type, global_type, mem_offset_type;
|
|
|
|
|
|
|
+ uint8 *param_types, *local_types, local_type, global_type, mem_offset_type,
|
|
|
|
|
+ table_elem_idx_type;
|
|
|
BlockType func_block_type;
|
|
BlockType func_block_type;
|
|
|
uint16 *local_offsets, local_offset;
|
|
uint16 *local_offsets, local_offset;
|
|
|
uint32 type_idx, func_idx, local_idx, global_idx, table_idx;
|
|
uint32 type_idx, func_idx, local_idx, global_idx, table_idx;
|
|
@@ -10922,6 +10935,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
mem_offset_type = is_memory64 ? VALUE_TYPE_I64 : VALUE_TYPE_I32;
|
|
mem_offset_type = is_memory64 ? VALUE_TYPE_I64 : VALUE_TYPE_I32;
|
|
|
#else
|
|
#else
|
|
|
mem_offset_type = VALUE_TYPE_I32;
|
|
mem_offset_type = VALUE_TYPE_I32;
|
|
|
|
|
+ table_elem_idx_type = VALUE_TYPE_I32;
|
|
|
#endif
|
|
#endif
|
|
|
uint32 memidx;
|
|
uint32 memidx;
|
|
|
|
|
|
|
@@ -12081,8 +12095,13 @@ re_scan:
|
|
|
emit_uint32(loader_ctx, table_idx);
|
|
emit_uint32(loader_ctx, table_idx);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type = is_table_64bit(module, table_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
/* skip elem idx */
|
|
/* skip elem idx */
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
|
|
|
|
|
if (type_idx >= module->type_count) {
|
|
if (type_idx >= module->type_count) {
|
|
|
set_error_buf(error_buf, error_buf_size, "unknown type");
|
|
set_error_buf(error_buf, error_buf_size, "unknown type");
|
|
@@ -12459,8 +12478,8 @@ re_scan:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /* table.get x. tables[x]. [i32] -> [t] */
|
|
|
|
|
- /* table.set x. tables[x]. [i32 t] -> [] */
|
|
|
|
|
|
|
+ /* table.get x. tables[x]. [it] -> [t] */
|
|
|
|
|
+ /* table.set x. tables[x]. [it t] -> [] */
|
|
|
case WASM_OP_TABLE_GET:
|
|
case WASM_OP_TABLE_GET:
|
|
|
case WASM_OP_TABLE_SET:
|
|
case WASM_OP_TABLE_SET:
|
|
|
{
|
|
{
|
|
@@ -12491,8 +12510,13 @@ re_scan:
|
|
|
emit_uint32(loader_ctx, table_idx);
|
|
emit_uint32(loader_ctx, table_idx);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type = is_table_64bit(module, table_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
if (opcode == WASM_OP_TABLE_GET) {
|
|
if (opcode == WASM_OP_TABLE_GET) {
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
#if WASM_ENABLE_FAST_INTERP != 0
|
|
#if WASM_ENABLE_FAST_INTERP != 0
|
|
|
PUSH_OFFSET_TYPE(decl_ref_type);
|
|
PUSH_OFFSET_TYPE(decl_ref_type);
|
|
|
#endif
|
|
#endif
|
|
@@ -12503,7 +12527,7 @@ re_scan:
|
|
|
POP_OFFSET_TYPE(decl_ref_type);
|
|
POP_OFFSET_TYPE(decl_ref_type);
|
|
|
#endif
|
|
#endif
|
|
|
POP_TYPE(decl_ref_type);
|
|
POP_TYPE(decl_ref_type);
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
@@ -14786,7 +14810,12 @@ re_scan:
|
|
|
#endif
|
|
#endif
|
|
|
POP_I32();
|
|
POP_I32();
|
|
|
POP_I32();
|
|
POP_I32();
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type = is_table_64bit(module, table_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
|
module->is_ref_types_used = true;
|
|
module->is_ref_types_used = true;
|
|
@@ -14811,7 +14840,8 @@ re_scan:
|
|
|
}
|
|
}
|
|
|
case WASM_OP_TABLE_COPY:
|
|
case WASM_OP_TABLE_COPY:
|
|
|
{
|
|
{
|
|
|
- uint8 src_type, dst_type;
|
|
|
|
|
|
|
+ uint8 src_type, dst_type, src_tbl_idx_type,
|
|
|
|
|
+ dst_tbl_idx_type, min_tbl_idx_type;
|
|
|
#if WASM_ENABLE_GC != 0
|
|
#if WASM_ENABLE_GC != 0
|
|
|
WASMRefType *src_ref_type = NULL, *dst_ref_type = NULL;
|
|
WASMRefType *src_ref_type = NULL, *dst_ref_type = NULL;
|
|
|
#endif
|
|
#endif
|
|
@@ -14857,9 +14887,31 @@ re_scan:
|
|
|
emit_uint32(loader_ctx, dst_tbl_idx);
|
|
emit_uint32(loader_ctx, dst_tbl_idx);
|
|
|
emit_uint32(loader_ctx, src_tbl_idx);
|
|
emit_uint32(loader_ctx, src_tbl_idx);
|
|
|
#endif
|
|
#endif
|
|
|
- POP_I32();
|
|
|
|
|
- POP_I32();
|
|
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ src_tbl_idx_type = is_table_64bit(module, src_tbl_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+ dst_tbl_idx_type = is_table_64bit(module, dst_tbl_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+ min_tbl_idx_type =
|
|
|
|
|
+ (src_tbl_idx_type == VALUE_TYPE_I32
|
|
|
|
|
+ || dst_tbl_idx_type == VALUE_TYPE_I32)
|
|
|
|
|
+ ? VALUE_TYPE_I32
|
|
|
|
|
+ : VALUE_TYPE_I64;
|
|
|
|
|
+#else
|
|
|
|
|
+ src_tbl_idx_type = VALUE_TYPE_I32;
|
|
|
|
|
+ dst_tbl_idx_type = VALUE_TYPE_I32;
|
|
|
|
|
+ min_tbl_idx_type = VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ table_elem_idx_type = min_tbl_idx_type;
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
|
|
+ table_elem_idx_type = src_tbl_idx_type;
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
|
|
+ table_elem_idx_type = dst_tbl_idx_type;
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
|
module->is_ref_types_used = true;
|
|
module->is_ref_types_used = true;
|
|
@@ -14879,7 +14931,12 @@ re_scan:
|
|
|
emit_uint32(loader_ctx, table_idx);
|
|
emit_uint32(loader_ctx, table_idx);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- PUSH_I32();
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type = is_table_64bit(module, table_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
|
|
+ PUSH_TBL_ELEM_IDX();
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
|
module->is_ref_types_used = true;
|
|
module->is_ref_types_used = true;
|
|
@@ -14928,15 +14985,20 @@ re_scan:
|
|
|
emit_uint32(loader_ctx, table_idx);
|
|
emit_uint32(loader_ctx, table_idx);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+#if WASM_ENABLE_MEMORY64 != 0
|
|
|
|
|
+ table_elem_idx_type = is_table_64bit(module, table_idx)
|
|
|
|
|
+ ? VALUE_TYPE_I64
|
|
|
|
|
+ : VALUE_TYPE_I32;
|
|
|
|
|
+#endif
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
#if WASM_ENABLE_FAST_INTERP != 0
|
|
#if WASM_ENABLE_FAST_INTERP != 0
|
|
|
POP_OFFSET_TYPE(decl_type);
|
|
POP_OFFSET_TYPE(decl_type);
|
|
|
#endif
|
|
#endif
|
|
|
POP_TYPE(decl_type);
|
|
POP_TYPE(decl_type);
|
|
|
if (opcode1 == WASM_OP_TABLE_GROW)
|
|
if (opcode1 == WASM_OP_TABLE_GROW)
|
|
|
- PUSH_I32();
|
|
|
|
|
|
|
+ PUSH_TBL_ELEM_IDX();
|
|
|
else
|
|
else
|
|
|
- POP_I32();
|
|
|
|
|
|
|
+ POP_TBL_ELEM_IDX();
|
|
|
|
|
|
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
#if WASM_ENABLE_WAMR_COMPILER != 0
|
|
|
module->is_ref_types_used = true;
|
|
module->is_ref_types_used = true;
|