mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-09 13:16:26 +00:00
Fix memory64 handling find_block_addr and execute_main (#3480)
This commit is contained in:
parent
1f8a78d61a
commit
5623e4d22a
|
@ -201,9 +201,23 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
|
||||||
if (func_type->param_count) {
|
if (func_type->param_count) {
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
total_argv_size += (uint32)(strlen(argv[i]) + 1);
|
total_argv_size += (uint32)(strlen(argv[i]) + 1);
|
||||||
|
#if WASM_ENABLE_MEMORY64 != 0
|
||||||
|
if (is_memory64)
|
||||||
|
/* `char **argv` is an array of 64-bit elements in memory64 */
|
||||||
|
total_argv_size = align_uint(total_argv_size, 8);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
total_argv_size = align_uint(total_argv_size, 4);
|
total_argv_size = align_uint(total_argv_size, 4);
|
||||||
|
|
||||||
total_size = (uint64)total_argv_size + sizeof(int32) * (uint64)argc;
|
#if WASM_ENABLE_MEMORY64 != 0
|
||||||
|
if (is_memory64)
|
||||||
|
/* `char **argv` is an array of 64-bit elements in memory64 */
|
||||||
|
total_size =
|
||||||
|
(uint64)total_argv_size + sizeof(uint64) * (uint64)argc;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
total_size =
|
||||||
|
(uint64)total_argv_size + sizeof(uint32) * (uint64)argc;
|
||||||
|
|
||||||
if (total_size >= UINT32_MAX
|
if (total_size >= UINT32_MAX
|
||||||
|| !(argv_buf_offset = wasm_runtime_module_malloc(
|
|| !(argv_buf_offset = wasm_runtime_module_malloc(
|
||||||
|
@ -219,7 +233,15 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
bh_memcpy_s(p, (uint32)(p_end - p), argv[i],
|
bh_memcpy_s(p, (uint32)(p_end - p), argv[i],
|
||||||
(uint32)(strlen(argv[i]) + 1));
|
(uint32)(strlen(argv[i]) + 1));
|
||||||
argv_offsets[i] = (uint32)argv_buf_offset + (uint32)(p - argv_buf);
|
#if WASM_ENABLE_MEMORY64 != 0
|
||||||
|
if (is_memory64)
|
||||||
|
/* `char **argv` is an array of 64-bit elements in memory64 */
|
||||||
|
((uint64 *)argv_offsets)[i] =
|
||||||
|
(uint32)argv_buf_offset + (uint32)(p - argv_buf);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
argv_offsets[i] =
|
||||||
|
(uint32)argv_buf_offset + (uint32)(p - argv_buf);
|
||||||
p += strlen(argv[i]) + 1;
|
p += strlen(argv[i]) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6414,7 +6414,7 @@ create_sections(const uint8 *buf, uint32 size, WASMSection **p_section_list,
|
||||||
char *error_buf, uint32 error_buf_size)
|
char *error_buf, uint32 error_buf_size)
|
||||||
{
|
{
|
||||||
WASMSection *section_list_end = NULL, *section;
|
WASMSection *section_list_end = NULL, *section;
|
||||||
const uint8 *p = buf, *p_end = buf + size /*, *section_body*/;
|
const uint8 *p = buf, *p_end = buf + size;
|
||||||
uint8 section_type, section_index, last_section_index = (uint8)-1;
|
uint8 section_type, section_index, last_section_index = (uint8)-1;
|
||||||
uint32 section_size;
|
uint32 section_size;
|
||||||
|
|
||||||
|
@ -7658,7 +7658,6 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
|
||||||
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0)
|
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0)
|
||||||
case WASM_OP_SIMD_PREFIX:
|
case WASM_OP_SIMD_PREFIX:
|
||||||
{
|
{
|
||||||
/* TODO: memory64 offset type changes */
|
|
||||||
uint32 opcode1;
|
uint32 opcode1;
|
||||||
|
|
||||||
read_leb_uint32(p, p_end, opcode1);
|
read_leb_uint32(p, p_end, opcode1);
|
||||||
|
@ -7683,8 +7682,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
|
||||||
case SIMD_v128_store:
|
case SIMD_v128_store:
|
||||||
/* memarg align */
|
/* memarg align */
|
||||||
skip_leb_uint32(p, p_end);
|
skip_leb_uint32(p, p_end);
|
||||||
/* memarg offset*/
|
/* memarg offset */
|
||||||
skip_leb_uint32(p, p_end);
|
skip_leb_mem_offset(p, p_end);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SIMD_v128_const:
|
case SIMD_v128_const:
|
||||||
|
@ -7723,8 +7722,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
|
||||||
case SIMD_v128_store64_lane:
|
case SIMD_v128_store64_lane:
|
||||||
/* memarg align */
|
/* memarg align */
|
||||||
skip_leb_uint32(p, p_end);
|
skip_leb_uint32(p, p_end);
|
||||||
/* memarg offset*/
|
/* memarg offset */
|
||||||
skip_leb_uint32(p, p_end);
|
skip_leb_mem_offset(p, p_end);
|
||||||
/* ImmLaneId */
|
/* ImmLaneId */
|
||||||
CHECK_BUF(p, p_end, 1);
|
CHECK_BUF(p, p_end, 1);
|
||||||
p++;
|
p++;
|
||||||
|
@ -7734,8 +7733,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
|
||||||
case SIMD_v128_load64_zero:
|
case SIMD_v128_load64_zero:
|
||||||
/* memarg align */
|
/* memarg align */
|
||||||
skip_leb_uint32(p, p_end);
|
skip_leb_uint32(p, p_end);
|
||||||
/* memarg offset*/
|
/* memarg offset */
|
||||||
skip_leb_uint32(p, p_end);
|
skip_leb_mem_offset(p, p_end);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -6942,7 +6942,8 @@ re_scan:
|
||||||
uint32 j;
|
uint32 j;
|
||||||
|
|
||||||
for (i = 0; i < module->global_count; i++) {
|
for (i = 0; i < module->global_count; i++) {
|
||||||
if (module->globals[i].type == VALUE_TYPE_FUNCREF
|
if (module->globals[i].type.val_type
|
||||||
|
== VALUE_TYPE_FUNCREF
|
||||||
&& module->globals[i].init_expr.init_expr_type
|
&& module->globals[i].init_expr.init_expr_type
|
||||||
== INIT_EXPR_TYPE_FUNCREF_CONST
|
== INIT_EXPR_TYPE_FUNCREF_CONST
|
||||||
&& module->globals[i].init_expr.u.u32 == func_idx) {
|
&& module->globals[i].init_expr.u.u32 == func_idx) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user