From 837ff636620a012d92400d58f3af1d388674545d Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Wed, 26 Jun 2024 23:34:43 -0700 Subject: [PATCH 01/18] Use 64-bit wasm_runtime_enlarge_memory() increment (#3573) ps. https://github.com/bytecodealliance/wasm-micro-runtime/pull/3569#discussion_r1654398315 --- core/iwasm/common/wasm_memory.c | 6 +++++- core/iwasm/include/wasm_export.h | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index cde2de4d..de1d54ed 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -921,8 +921,12 @@ return_func: bool wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst, - uint32_t inc_page_count) + uint64 inc_page_count) { + if (inc_page_count > UINT32_MAX) { + return false; + } + #if WASM_ENABLE_AOT != 0 if (module_inst->module_type == Wasm_Module_AoT) { return aot_enlarge_memory((AOTModuleInstance *)module_inst, diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 0d5f9572..b917ee6d 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1842,9 +1842,17 @@ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_global_linked(const char *module_name, const char *global_name); +/** + * Enlarge the memory region for a module instance + * + * @param module_inst the module instance + * @param inc_page_count the number of pages to add + * + * @return true if success, false otherwise + */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst, - uint32_t inc_page_count); + uint64_t inc_page_count); typedef enum { INTERNAL_ERROR, From ea582fbc07468b2ef11a13d5ac18058047e50ef7 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 1 Jul 2024 09:43:33 +0900 Subject: [PATCH 02/18] wasm-mutator-fuzz: Make compilers overridable (#3578) eg. ```shell cmake .. \ -DCMAKE_C_COMPILER=/usr/local/opt/llvm@15/bin/clang \ -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@15/bin/clang++ ``` --- tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt b/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt index 6bb7fc75..020d3e7f 100644 --- a/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt +++ b/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt @@ -7,8 +7,12 @@ project(wasm_mutator) set (CMAKE_BUILD_TYPE Debug) +if (NOT DEFINED CMAKE_C_COMPILER) set (CMAKE_C_COMPILER "clang") +endif () +if (NOT DEFINED CMAKE_CXX_COMPILER) set (CMAKE_CXX_COMPILER "clang++") +endif () string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) From 77da87ca519d67233d7eb24812bc30410e4e953d Mon Sep 17 00:00:00 2001 From: tonibofarull Date: Tue, 2 Jul 2024 03:39:46 +0200 Subject: [PATCH 03/18] wasi-nn: Use numpy v1 in wasi-nn test requirements.txt (#3582) We need to fix numpy version since the latest is incompatible. > A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. --- core/iwasm/libraries/wasi-nn/test/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/iwasm/libraries/wasi-nn/test/requirements.txt b/core/iwasm/libraries/wasi-nn/test/requirements.txt index 4cf2910d..0d031ffd 100644 --- a/core/iwasm/libraries/wasi-nn/test/requirements.txt +++ b/core/iwasm/libraries/wasi-nn/test/requirements.txt @@ -1 +1,2 @@ -tensorflow==2.11.1 \ No newline at end of file +tensorflow==2.11.1 +numpy==1.26.4 From a5753ea920a5a63a5b202d663c2f86cfc678f307 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:03:49 +0800 Subject: [PATCH 04/18] interp debugger: Fix setting invalid value to step_count (#3583) The `exec_env->current_status->step_count` should be set same as the handling when WASM_ENABLE_LABELS_AS_VALUES is not 0. Fixes issue https://github.com/bytecodealliance/wasm-micro-runtime/issues/3475. --- core/iwasm/interpreter/wasm_interp_classic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index f7193c95..b4128392 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1424,7 +1424,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst, #define HANDLE_OP_END() \ os_mutex_lock(&exec_env->wait_lock); \ if (exec_env->current_status->signal_flag == WAMR_SIG_SINGSTEP \ - && exec_env->current_status->step_count++ == 2) { \ + && exec_env->current_status->step_count++ == 1) { \ exec_env->current_status->step_count = 0; \ SYNC_ALL_TO_FRAME(); \ wasm_cluster_thread_waiting_run(exec_env); \ From fe4ed6adf237e38ce686bf745c32745112eb832a Mon Sep 17 00:00:00 2001 From: HongxiaWangSSSS <103626902+HongxiaWangSSSS@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:26:13 +0800 Subject: [PATCH 05/18] Fix compilation errors in aot-analyzer tool (#3584) Corrected compilation failures due to structure changes, like AOTImportTable. --- test-tools/aot-analyzer/src/main.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test-tools/aot-analyzer/src/main.cc b/test-tools/aot-analyzer/src/main.cc index 1b5b1188..44e57854 100644 --- a/test-tools/aot-analyzer/src/main.cc +++ b/test-tools/aot-analyzer/src/main.cc @@ -272,8 +272,8 @@ DumpDetails(AoTFile *aot) AOTImportMemory memory = import_memories[index]; printf(" -[%u] num_bytes_per_page:%5u init_page_count:%5u " "max_page_count:%5u module_name: %s memory_name: %s\n", - index, memory.memory.num_bytes_per_page, - memory.memory.init_page_count, memory.memory.max_page_count, + index, memory.mem_type.num_bytes_per_page, + memory.mem_type.init_page_count, memory.mem_type.max_page_count, memory.module_name, memory.memory_name); } printf("\n"); @@ -285,14 +285,15 @@ DumpDetails(AoTFile *aot) printf(" -[%u] ", index); printf("elem_type: "); #if WASM_ENABLE_GC != 0 - wasm_dump_value_type(table.elem_type, table.elem_ref_type); + wasm_dump_value_type(table.table_type.elem_type, + table.table_type.elem_ref_type); #else - dump_value_type(table.elem_type); + dump_value_type(table.table_type.elem_type); #endif printf(" init_size:%5u max_size:%5u " "module_name: %s table_name: %s\n", table.table_type.init_size, table.table_type.max_size, - table.module_name, table.table_type.name); + table.module_name, table.table_name); } printf("\n"); @@ -302,7 +303,7 @@ DumpDetails(AoTFile *aot) AOTImportGlobal global = import_globals[index]; printf(" -[%u] ", index); printf("type: "); - dump_value_type(global.type); + dump_value_type(global.type.val_type); printf(" module_name: %s global_name: %s\n", global.module_name, global.global_name); } @@ -348,9 +349,10 @@ DumpDetails(AoTFile *aot) printf(" -[%u] ", index); printf("elem_type: "); #if WASM_ENABLE_GC != 0 - wasm_dump_value_type(table.elem_type, table.elem_ref_type); + wasm_dump_value_type(table.table_type.elem_type, + table.table_type.elem_ref_type); #else - dump_value_type(table.elem_type); + dump_value_type(table.table_type.elem_type); #endif printf(" init_size:%5u max_size:%5u\n", table.table_type.init_size, table.table_type.max_size); @@ -382,9 +384,9 @@ DumpDetails(AoTFile *aot) AOTGlobal global = globals[index]; printf(" -[%u] ", index); printf("type: "); - dump_value_type(global.type); + dump_value_type(global.type.val_type); printf(" is_mutable: %d size: %u data_offset: %u\n", - global.is_mutable, global.size, global.data_offset); + global.type.is_mutable, global.size, global.data_offset); } printf("\n\n"); From 0d9cea434c16e51e5f5d3fe6b3f9f323f512bd1b Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 2 Jul 2024 12:27:31 +0900 Subject: [PATCH 06/18] wasm-mutator-fuzz: Set compilers earlier (#3585) CMAKE_C_COMPILER etc should be set before project(), in which cmake tries to decide which compiler to use. --- tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt b/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt index 020d3e7f..356869d1 100644 --- a/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt +++ b/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt @@ -3,10 +3,6 @@ cmake_minimum_required (VERSION 2.8) -project(wasm_mutator) - -set (CMAKE_BUILD_TYPE Debug) - if (NOT DEFINED CMAKE_C_COMPILER) set (CMAKE_C_COMPILER "clang") endif () @@ -14,6 +10,10 @@ if (NOT DEFINED CMAKE_CXX_COMPILER) set (CMAKE_CXX_COMPILER "clang++") endif () +project(wasm_mutator) + +set (CMAKE_BUILD_TYPE Debug) + string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) # Reset default linker flags From 212d830eb73e6c53aeb48cf07441a6a9492d44c2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 2 Jul 2024 16:25:03 +0900 Subject: [PATCH 07/18] aot-analyzer: Fix macos build (#3589) * macOS doesn't have -lrt. * this program doesn't seem to require librt even on ubuntu. build tested on macOS and ubuntu. --- test-tools/aot-analyzer/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-tools/aot-analyzer/CMakeLists.txt b/test-tools/aot-analyzer/CMakeLists.txt index b1a11b54..6f5f588c 100644 --- a/test-tools/aot-analyzer/CMakeLists.txt +++ b/test-tools/aot-analyzer/CMakeLists.txt @@ -85,4 +85,4 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) add_executable (aot-analyzer src/main.cc src/aot_file.cc src/binary_file.cc src/option_parser.cc src/wasm_file.cc ${UNCOMMON_SHARED_SOURCE}) -target_link_libraries (aot-analyzer vmlib -lm -ldl -lpthread -lrt) \ No newline at end of file +target_link_libraries (aot-analyzer vmlib -lm -ldl -lpthread) From 3d4d8e61f0547d65cd96e48d0be89ecba8ca85cc Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 2 Jul 2024 16:32:38 +0900 Subject: [PATCH 08/18] aot-analyzer: Fix a few printf formats (#3590) --- test-tools/aot-analyzer/src/main.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-tools/aot-analyzer/src/main.cc b/test-tools/aot-analyzer/src/main.cc index 44e57854..f42e9217 100644 --- a/test-tools/aot-analyzer/src/main.cc +++ b/test-tools/aot-analyzer/src/main.cc @@ -169,8 +169,8 @@ DumpInfo(AoTFile *aot) aot->GetExectuionMachineName(target_info.e_machine).c_str()); printf("Exectuion version: %u\n", target_info.e_version); printf("Exectuion flags: %u\n", target_info.e_flags); - printf("Feature flags: %ld\n", target_info.feature_flags); - printf("Reserved: %ld\n", target_info.reserved); + printf("Feature flags: %" PRId64 "\n", target_info.feature_flags); + printf("Reserved: %" PRId64 "\n", target_info.reserved); printf("Arch: %s\n", target_info.arch); } From f118492b1d4a7d5e1984a1aa02c8d4016e61bccf Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 2 Jul 2024 15:48:37 +0800 Subject: [PATCH 09/18] Add integer overflow check for some indices in wasm/aot loader (#3579) Check whether the indices overflow UINT32_MAX or not for: - import function count + function count - import global count + global count - import tag count + tag count This PR fixes the issue reported by Oss-fuzz test (#69920). --- core/iwasm/aot/aot_loader.c | 7 +++++++ core/iwasm/common/wasm_loader_common.c | 17 +++++++++++++++++ core/iwasm/common/wasm_loader_common.h | 4 ++++ core/iwasm/interpreter/wasm_loader.c | 11 +++++++++++ core/iwasm/interpreter/wasm_mini_loader.c | 4 ++++ 5 files changed, 43 insertions(+) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 11a67dc6..0116ae76 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2217,6 +2217,9 @@ load_global_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, const uint8 *buf = *p_buf; read_uint32(buf, buf_end, module->global_count); + if (is_indices_overflow(module->import_global_count, module->global_count, + error_buf, error_buf_size)) + return false; /* load globals */ if (module->global_count > 0 @@ -2481,6 +2484,10 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end, /* load function count and start function index */ read_uint32(p, p_end, module->func_count); + if (is_indices_overflow(module->import_func_count, module->func_count, + error_buf, error_buf_size)) + return false; + read_uint32(p, p_end, module->start_func_index); /* check start function index */ diff --git a/core/iwasm/common/wasm_loader_common.c b/core/iwasm/common/wasm_loader_common.c index 98199885..da5b7d45 100644 --- a/core/iwasm/common/wasm_loader_common.c +++ b/core/iwasm/common/wasm_loader_common.c @@ -96,3 +96,20 @@ is_valid_func_type(const WASMFuncType *func_type) return true; } + +/* + * Indices are represented as a u32. + */ +bool +is_indices_overflow(uint32 import, uint32 other, char *error_buf, + uint32 error_buf_size) +{ + if (import > UINT32_MAX - other) { + snprintf(error_buf, error_buf_size, + "too many items in the index space(%" PRIu32 "+%" PRIu32 ").", + import, other); + return true; + } + + return false; +} diff --git a/core/iwasm/common/wasm_loader_common.h b/core/iwasm/common/wasm_loader_common.h index 189b78f0..197df915 100644 --- a/core/iwasm/common/wasm_loader_common.h +++ b/core/iwasm/common/wasm_loader_common.h @@ -23,6 +23,10 @@ is_valid_value_type(uint8 value_tpye); bool is_valid_func_type(const WASMFuncType *func_type); +bool +is_indices_overflow(uint32 import, uint32 other, char *error_buf, + uint32 error_buf_size); + #ifdef __cplusplus } #endif diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 92ae2117..fe300ec2 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -3627,6 +3627,10 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, return false; } + if (is_indices_overflow(module->import_function_count, func_count, + error_buf, error_buf_size)) + return false; + if (func_count) { module->function_count = func_count; total_size = sizeof(WASMFunction *) * (uint64)func_count; @@ -4022,6 +4026,9 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, #endif read_leb_uint32(p, p_end, global_count); + if (is_indices_overflow(module->import_global_count, global_count, + error_buf, error_buf_size)) + return false; module->global_count = 0; if (global_count) { @@ -4921,6 +4928,10 @@ load_tag_section(const uint8 *buf, const uint8 *buf_end, const uint8 *buf_code, /* get tag count */ read_leb_uint32(p, p_end, section_tag_count); + if (is_indices_overflow(module->import_tag_count, section_tag_count, + error_buf, error_buf_size)) + return false; + module->tag_count = section_tag_count; if (section_tag_count) { diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index ad61f59e..2bca20a8 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -1139,6 +1139,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, bh_assert(func_count == code_count); + bh_assert(module->import_function_count <= UINT32_MAX - func_count); + if (func_count) { module->function_count = func_count; total_size = sizeof(WASMFunction *) * (uint64)func_count; @@ -1321,6 +1323,8 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, read_leb_uint32(p, p_end, global_count); + bh_assert(module->import_global_count <= UINT32_MAX - global_count); + module->global_count = 0; if (global_count) { total_size = sizeof(WASMGlobal) * (uint64)global_count; From e3074dc49613c1dd426b6a1c0595344ece350b3b Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Tue, 2 Jul 2024 23:44:40 -0700 Subject: [PATCH 10/18] Add more arm AOT reloc entries (#3587) Add missing reloc entries for Arm AOT. Also sort and remove duplicate. --- core/iwasm/aot/arch/aot_reloc_arm.c | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/core/iwasm/aot/arch/aot_reloc_arm.c b/core/iwasm/aot/arch/aot_reloc_arm.c index 5d79e8a6..808af89f 100644 --- a/core/iwasm/aot/arch/aot_reloc_arm.c +++ b/core/iwasm/aot/arch/aot_reloc_arm.c @@ -14,33 +14,48 @@ /* clang-format off */ void __adddf3(); void __addsf3(); +void __aeabi_d2f(); void __aeabi_d2iz(); void __aeabi_d2lz(); +void __aeabi_d2uiz(); void __aeabi_d2ulz(); void __aeabi_dadd(); +void __aeabi_dcmpeq(); void __aeabi_dcmpge(); +void __aeabi_dcmpgt(); void __aeabi_dcmple(); void __aeabi_dcmplt(); void __aeabi_dcmpun(); void __aeabi_ddiv(); +void __aeabi_dmul(); +void __aeabi_dsub(); void __aeabi_f2d(); void __aeabi_f2iz(); void __aeabi_f2lz(); void __aeabi_f2ulz(); +void __aeabi_fadd(); +void __aeabi_fcmpeq(); void __aeabi_fcmpge(); +void __aeabi_fcmpgt(); void __aeabi_fcmple(); void __aeabi_fcmplt(); void __aeabi_fcmpun(); +void __aeabi_fdiv(); +void __aeabi_fmul(); +void __aeabi_fsub(); void __aeabi_i2d(); +void __aeabi_i2f(); void __aeabi_idiv(); void __aeabi_idivmod(); void __aeabi_l2d(); void __aeabi_l2f(); void __aeabi_ldivmod(); +void __aeabi_memclr(); void __aeabi_memcpy(); void __aeabi_memmove(); void __aeabi_memset(); -void __aeabi_memclr(); +void __aeabi_ui2d(); +void __aeabi_ui2f(); void __aeabi_uidiv(); void __aeabi_uidivmod(); void __aeabi_ul2d(); @@ -101,33 +116,48 @@ static SymbolMap target_sym_map[] = { REG_SYM(__adddf3), REG_SYM(__addsf3), /* clang-format on */ + REG_SYM(__aeabi_d2f), REG_SYM(__aeabi_d2iz), REG_SYM(__aeabi_d2lz), + REG_SYM(__aeabi_d2uiz), REG_SYM(__aeabi_d2ulz), REG_SYM(__aeabi_dadd), + REG_SYM(__aeabi_dcmpeq), REG_SYM(__aeabi_dcmpge), + REG_SYM(__aeabi_dcmpgt), REG_SYM(__aeabi_dcmple), REG_SYM(__aeabi_dcmplt), REG_SYM(__aeabi_dcmpun), REG_SYM(__aeabi_ddiv), + REG_SYM(__aeabi_dmul), + REG_SYM(__aeabi_dsub), REG_SYM(__aeabi_f2d), REG_SYM(__aeabi_f2iz), REG_SYM(__aeabi_f2lz), REG_SYM(__aeabi_f2ulz), + REG_SYM(__aeabi_fadd), + REG_SYM(__aeabi_fcmpeq), REG_SYM(__aeabi_fcmpge), + REG_SYM(__aeabi_fcmpgt), REG_SYM(__aeabi_fcmple), REG_SYM(__aeabi_fcmplt), REG_SYM(__aeabi_fcmpun), + REG_SYM(__aeabi_fdiv), + REG_SYM(__aeabi_fmul), + REG_SYM(__aeabi_fsub), REG_SYM(__aeabi_i2d), + REG_SYM(__aeabi_i2f), REG_SYM(__aeabi_idiv), REG_SYM(__aeabi_idivmod), REG_SYM(__aeabi_l2d), REG_SYM(__aeabi_l2f), REG_SYM(__aeabi_ldivmod), + REG_SYM(__aeabi_memclr), REG_SYM(__aeabi_memcpy), REG_SYM(__aeabi_memmove), REG_SYM(__aeabi_memset), - REG_SYM(__aeabi_memclr), + REG_SYM(__aeabi_ui2d), + REG_SYM(__aeabi_ui2f), REG_SYM(__aeabi_uidiv), REG_SYM(__aeabi_uidivmod), REG_SYM(__aeabi_ul2d), @@ -166,7 +196,6 @@ static SymbolMap target_sym_map[] = { REG_SYM(__moddi3), REG_SYM(__modsi3), REG_SYM(__muldf3), - REG_SYM(__muldf3), REG_SYM(__mulsf3), REG_SYM(__nedf2), REG_SYM(__nesf2), From 1f94cd4ee506b063d0698d6b40bcff69d5d6f27f Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Wed, 3 Jul 2024 15:18:42 +0800 Subject: [PATCH 11/18] wasm loader: Fix push_frame_offset when pushing v128 type (#3588) Fixes issue https://github.com/bytecodealliance/wasm-micro-runtime/issues/3580. --- core/iwasm/interpreter/wasm_loader.c | 27 ++++++++++++++--------- core/iwasm/interpreter/wasm_mini_loader.c | 26 +++++++++++++--------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index fe300ec2..c026a75f 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -9315,6 +9315,8 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type, bool disable_emit, int16 operand_offset, char *error_buf, uint32 error_buf_size) { + uint32 cell_num_to_push, i; + if (type == VALUE_TYPE_VOID) return true; @@ -9341,21 +9343,24 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type, if (is_32bit_type(type)) return true; - if (ctx->p_code_compiled == NULL) { - if (!check_offset_push(ctx, error_buf, error_buf_size)) - return false; - } + cell_num_to_push = wasm_value_type_cell_num(type) - 1; + for (i = 0; i < cell_num_to_push; i++) { + if (ctx->p_code_compiled == NULL) { + if (!check_offset_push(ctx, error_buf, error_buf_size)) + return false; + } - ctx->frame_offset++; - if (!disable_emit) { - ctx->dynamic_offset++; - if (ctx->dynamic_offset > ctx->max_dynamic_offset) { - ctx->max_dynamic_offset = ctx->dynamic_offset; - if (ctx->max_dynamic_offset >= INT16_MAX) { - goto fail; + ctx->frame_offset++; + if (!disable_emit) { + ctx->dynamic_offset++; + if (ctx->dynamic_offset > ctx->max_dynamic_offset) { + ctx->max_dynamic_offset = ctx->dynamic_offset; + if (ctx->max_dynamic_offset >= INT16_MAX) + goto fail; } } } + return true; fail: diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 2bca20a8..7cef4165 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -4869,6 +4869,8 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type, bool disable_emit, int16 operand_offset, char *error_buf, uint32 error_buf_size) { + uint32 cell_num_to_push, i; + if (type == VALUE_TYPE_VOID) return true; @@ -4893,19 +4895,23 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type, if (is_32bit_type(type)) return true; - if (ctx->p_code_compiled == NULL) { - if (!check_offset_push(ctx, error_buf, error_buf_size)) - return false; - } + cell_num_to_push = wasm_value_type_cell_num(type) - 1; + for (i = 0; i < cell_num_to_push; i++) { + if (ctx->p_code_compiled == NULL) { + if (!check_offset_push(ctx, error_buf, error_buf_size)) + return false; + } - ctx->frame_offset++; - if (!disable_emit) { - ctx->dynamic_offset++; - if (ctx->dynamic_offset > ctx->max_dynamic_offset) { - ctx->max_dynamic_offset = ctx->dynamic_offset; - bh_assert(ctx->max_dynamic_offset < INT16_MAX); + ctx->frame_offset++; + if (!disable_emit) { + ctx->dynamic_offset++; + if (ctx->dynamic_offset > ctx->max_dynamic_offset) { + ctx->max_dynamic_offset = ctx->dynamic_offset; + bh_assert(ctx->max_dynamic_offset < INT16_MAX); + } } } + return true; } From 777121217ecf52fa2e73bb64a3ae0dbaf5950cc8 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Wed, 3 Jul 2024 19:07:57 -0700 Subject: [PATCH 12/18] CMakeLists.txt: Fix Android pthread linkage (#3591) https://developer.android.com/ndk/guides/stable_apis#core_cc > Note that on Android, unlike Linux, there are no separate libpthread or librt libraries. That functionality is included directly in libc, which does not need to be explicitly linked against. Set `THREADS_PREFER_PTHREAD_FLAG` ON and find package `Threads`, then link `${CMAKE_THREAD_LIBS_INIT}` instead of `-lpthread`. ps. https://cmake.org/cmake/help/latest/module/FindThreads.html --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 761ac574..bedf0af6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,12 +142,15 @@ endif () include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) +set (THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + # STATIC LIBRARY if (WAMR_BUILD_STATIC) add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib) target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) + target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_static INTERFACE boringssl_crypto) endif () @@ -160,7 +163,7 @@ if (WAMR_BUILD_SHARED) add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm) target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) + target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_shared INTERFACE boringssl_crypto) endif () From 0feae05379feb856f6b1af6c0dc5cf57f87155b7 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 5 Jul 2024 19:15:58 +0800 Subject: [PATCH 13/18] wasm loader: Fix several issues in GC and exception handling (#3586) Fix several issues of GC and exception handling in wasm loader: - Should restore param_reftype_maps/param_reftype_map_count/param_count in the handling of opcode throw - Should set wasm_ref_type when pushing param types of tag type and block type if the type is a multi-byte type - Should set init_values.data as NULL for opcode struct.new_default in load_init_expr This PR fixes the issues reported in #3411. --- core/iwasm/interpreter/wasm_loader.c | 66 +++++++++++++++++++++------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index c026a75f..cc6914e4 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -1039,6 +1039,7 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end, } cur_value.type_index = type_idx; + cur_value.data = NULL; wasm_set_refheaptype_typeidx( &cur_ref_type.ref_ht_typeidx, false, type_idx); if (!push_const_expr_stack( @@ -11201,10 +11202,15 @@ re_scan: /* Pass parameters to block */ if (BLOCK_HAS_PARAM(block_type)) { - for (i = 0; i < block_type.u.type->param_count; i++) { + WASMFuncType *func_type = block_type.u.type; +#if WASM_ENABLE_GC != 0 + WASMRefType *ref_type; + uint32 j = 0; +#endif + for (i = 0; i < func_type->param_count; i++) { #if WASM_ENABLE_FAST_INTERP != 0 - uint32 cell_num = wasm_value_type_cell_num( - block_type.u.type->types[i]); + uint32 cell_num = + wasm_value_type_cell_num(func_type->types[i]); if (i >= available_params) { /* If there isn't enough data on stack, push a dummy * offset to keep the stack consistent with @@ -11228,7 +11234,17 @@ re_scan: loader_ctx->frame_offset += cell_num; } #endif - PUSH_TYPE(block_type.u.type->types[i]); +#if WASM_ENABLE_GC != 0 + if (wasm_is_type_multi_byte_type(func_type->types[i])) { + bh_assert(func_type->ref_type_maps[j].index == i); + ref_type = func_type->ref_type_maps[j].ref_type; + bh_memcpy_s(&wasm_ref_type, sizeof(WASMRefType), + ref_type, + wasm_reftype_struct_size(ref_type)); + j++; + } +#endif + PUSH_TYPE(func_type->types[i]); } } @@ -11356,6 +11372,7 @@ re_scan: int32 available_stack_cell = (int32)(loader_ctx->stack_cell_num - cur_block->stack_cell_num); + int32 tti; /* Check stack values match return types by comparing tag param * types with stack cells */ @@ -11364,19 +11381,21 @@ re_scan: WASMRefTypeMap *frame_reftype_map = loader_ctx->frame_reftype_map; uint32 frame_reftype_map_num = loader_ctx->reftype_map_num; + + /* Temporarily set these values since they may be used in + GET_LOCAL_REFTYPE(), remember they must be restored later */ param_reftype_maps = tag_type->ref_type_maps; /* For tag_type function, it shouldn't have result_count = 0 */ param_reftype_map_count = tag_type->ref_type_map_count; - param_count = (int32)tag_type->param_count; + param_count = tag_type->param_count; #endif - for (int tti = (int32)tag_type->param_count - 1; tti >= 0; - tti--) { + for (tti = (int32)tag_type->param_count - 1; tti >= 0; tti--) { #if WASM_ENABLE_GC != 0 local_type = tag_type->types[tti]; local_idx = tti; /* Get the wasm_ref_type if the local_type is multibyte - * type */ + type */ GET_LOCAL_REFTYPE(); #endif @@ -11406,6 +11425,13 @@ re_scan: wasm_value_type_cell_num(tag_type->types[tti]); } +#if WASM_ENABLE_GC != 0 + /* Restore the values */ + param_reftype_maps = func->func_type->ref_type_maps; + param_reftype_map_count = func->func_type->ref_type_map_count; + param_count = func->func_type->param_count; +#endif + /* throw is stack polymorphic */ (void)label_type; RESET_STACK(); @@ -11497,10 +11523,6 @@ re_scan: goto fail; } - BlockType new_block_type; - new_block_type.is_value_type = false; - new_block_type.u.type = func_type; - /* * replace frame_csp by LABEL_TYPE_CATCH */ @@ -11510,10 +11532,24 @@ re_scan: * CATCH Blocks */ RESET_STACK(); +#if WASM_ENABLE_GC != 0 + WASMRefType *ref_type; + uint32 j = 0; +#endif + /* push types on the stack according to caught type */ - if (BLOCK_HAS_PARAM(new_block_type)) { - for (i = 0; i < new_block_type.u.type->param_count; i++) - PUSH_TYPE(new_block_type.u.type->types[i]); + for (i = 0; i < func_type->param_count; i++) { +#if WASM_ENABLE_GC != 0 + if (wasm_is_type_multi_byte_type(func_type->types[i])) { + bh_assert(func_type->ref_type_maps[j].index == i); + ref_type = func_type->ref_type_maps[j].ref_type; + bh_memcpy_s(&wasm_ref_type, sizeof(WASMRefType), + ref_type, + wasm_reftype_struct_size(ref_type)); + j++; + } +#endif + PUSH_TYPE(func_type->types[i]); } break; } From 8aba85825c9104ecc43e3b4ebad7bb06ce75bf2e Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Tue, 9 Jul 2024 19:05:47 -0700 Subject: [PATCH 14/18] Avoid redefining WASMMemoryType (#3602) --- core/iwasm/include/wasm_export.h | 3 +++ core/iwasm/interpreter/wasm.h | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index b917ee6d..fa84afc3 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -81,8 +81,11 @@ typedef struct WASMTableType *wasm_table_type_t; struct WASMGlobalType; typedef struct WASMGlobalType *wasm_global_type_t; +#ifndef WASM_MEMORY_T_DEFINED +#define WASM_MEMORY_T_DEFINED struct WASMMemory; typedef struct WASMMemory WASMMemoryType; +#endif typedef WASMMemoryType *wasm_memory_type_t; typedef struct wasm_import_t { diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index f7b34bd4..0755d10e 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -518,7 +518,11 @@ typedef struct WASMMemory { uint32 num_bytes_per_page; uint32 init_page_count; uint32 max_page_count; -} WASMMemory, WASMMemoryType; +} WASMMemory; +#ifndef WASM_MEMORY_T_DEFINED +#define WASM_MEMORY_T_DEFINED +typedef struct WASMMemory WASMMemoryType; +#endif typedef struct WASMTableImport { char *module_name; From 8a6379bd0a156de1fe46cc20dc15309e2bd680a7 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Tue, 9 Jul 2024 19:45:19 -0700 Subject: [PATCH 15/18] Add wasm_runtime_get_module_package_type() and wasm_runtime_get_file_package_type() (#3600) wasm_runtime_get_file_package_type() is the counterpart of get_file_package_type(). See discussion in #3595. --- core/iwasm/common/wasm_runtime_common.c | 16 ++++++++++++++++ core/iwasm/include/wasm_export.h | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index e6477d48..dad2eb29 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -871,6 +871,22 @@ get_package_type(const uint8 *buf, uint32 size) return Package_Type_Unknown; } +PackageType +wasm_runtime_get_file_package_type(const uint8 *buf, uint32 size) +{ + return get_package_type(buf, size); +} + +PackageType +wasm_runtime_get_module_package_type(WASMModuleCommon *module) +{ + if (!module) { + return Package_Type_Unknown; + } + + return module->module_type; +} + #if WASM_ENABLE_AOT != 0 static uint8 * align_ptr(const uint8 *p, uint32 b) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index fa84afc3..4cdc10e1 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -422,6 +422,28 @@ wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info); WASM_RUNTIME_API_EXTERN package_type_t get_package_type(const uint8_t *buf, uint32_t size); +/** + * Get the package type of a buffer (same as get_package_type). + * + * @param buf the package buffer + * @param size the package buffer size + * + * @return the package type, return Package_Type_Unknown if the type is unknown + */ +WASM_RUNTIME_API_EXTERN package_type_t +wasm_runtime_get_file_package_type(const uint8_t *buf, uint32_t size); + +/** + * Get the package type of a module. + * + * @param module the module + * + * @return the package type, return Package_Type_Unknown if the type is + * unknown + */ +WASM_RUNTIME_API_EXTERN package_type_t +wasm_runtime_get_module_package_type(wasm_module_t module); + /** * Check whether a file is an AOT XIP (Execution In Place) file * From fc34151df9f263c155c140924549140d0df98718 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:24:15 +0800 Subject: [PATCH 16/18] Bump ocaml/setup-ocaml from 2 to 3 (#3604) Bumps [ocaml/setup-ocaml](https://github.com/ocaml/setup-ocaml) from 2 to 3. - [Release notes](https://github.com/ocaml/setup-ocaml/releases) - [Changelog](https://github.com/ocaml/setup-ocaml/blob/master/CHANGELOG.md) - [Commits](https://github.com/ocaml/setup-ocaml/compare/v2...v3) --- updated-dependencies: - dependency-name: ocaml/setup-ocaml dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/compilation_on_android_ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 934e839c..d4d32908 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -645,7 +645,7 @@ jobs: uses: actions/checkout@v4 - name: Set-up OCaml - uses: ocaml/setup-ocaml@v2 + uses: ocaml/setup-ocaml@v3 if: matrix.test_option == '$GC_TEST_OPTIONS' || matrix.test_option == '$MEMORY64_TEST_OPTIONS' with: ocaml-compiler: 4.13 From 2cf48c8b9fbf2cb13b1e47b5b5ff8c63dcd729c5 Mon Sep 17 00:00:00 2001 From: Byeongjee Kang Date: Wed, 10 Jul 2024 00:05:58 -0400 Subject: [PATCH 17/18] Fix typos in wamrc and wasm_export.h (#3609) --- core/iwasm/include/wasm_export.h | 4 ++-- wamr-compiler/main.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 4cdc10e1..72f36b81 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1227,7 +1227,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst, void *native_ptr, uint64_t size); /** - * Convert app address(relative address) to native address(absolute address) + * Convert app address (relative address) to native address (absolute address) * * Note that native addresses to module instance memory can be invalidated * on a memory growth. (Except shared memory, whose native addresses are @@ -1243,7 +1243,7 @@ wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst, uint64_t app_offset); /** - * Convert native address(absolute address) to app address(relative address) + * Convert native address (absolute address) to app address (relative address) * * @param module_inst the WASM module instance * @param native_ptr the native address diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 1044014c..ae24ee5b 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -160,9 +160,9 @@ print_help() printf(" --enable-dump-call-stack Enable stack trace feature\n"); printf(" --enable-perf-profiling Enable function performance profiling\n"); printf(" --enable-memory-profiling Enable memory usage profiling\n"); - printf(" --xip A shorthand of --enalbe-indirect-mode --disable-llvm-intrinsics\n"); - printf(" --enable-indirect-mode Enalbe call function through symbol table but not direct call\n"); - printf(" --enable-gc Enalbe GC (Garbage Collection) feature\n"); + printf(" --xip A shorthand of --enable-indirect-mode --disable-llvm-intrinsics\n"); + printf(" --enable-indirect-mode Enable call function through symbol table but not direct call\n"); + printf(" --enable-gc Enable GC (Garbage Collection) feature\n"); printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\n"); printf(" --enable-builtin-intrinsics=\n"); printf(" Enable the specified built-in intrinsics, it will override the default\n"); From 1b1ec715e9b16c23f146333de846fb0285ec2401 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 10 Jul 2024 14:50:52 +0900 Subject: [PATCH 18/18] wasm loader: Reject v128 for interpreters (#3611) discussed in: https://github.com/bytecodealliance/wasm-micro-runtime/pull/3592 --- core/iwasm/common/wasm_loader_common.c | 15 +++++++++++++++ core/iwasm/common/wasm_loader_common.h | 5 ++++- core/iwasm/interpreter/wasm_loader.c | 18 ++++++++++-------- core/iwasm/interpreter/wasm_mini_loader.c | 9 +++++---- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/core/iwasm/common/wasm_loader_common.c b/core/iwasm/common/wasm_loader_common.c index da5b7d45..773e78c5 100644 --- a/core/iwasm/common/wasm_loader_common.c +++ b/core/iwasm/common/wasm_loader_common.c @@ -85,6 +85,21 @@ is_valid_value_type(uint8 type) return false; } +bool +is_valid_value_type_for_interpreter(uint8 value_type) +{ +#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) + /* + * Note: regardless of WASM_ENABLE_SIMD, our interpreters don't have + * SIMD implemented. It's safer to reject v128, especially for the + * fast interpreter. + */ + if (value_type == VALUE_TYPE_V128) + return false; +#endif + return is_valid_value_type(value_type); +} + bool is_valid_func_type(const WASMFuncType *func_type) { diff --git a/core/iwasm/common/wasm_loader_common.h b/core/iwasm/common/wasm_loader_common.h index 197df915..6bd0cf6c 100644 --- a/core/iwasm/common/wasm_loader_common.h +++ b/core/iwasm/common/wasm_loader_common.h @@ -20,6 +20,9 @@ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf, bool is_valid_value_type(uint8 value_tpye); +bool +is_valid_value_type_for_interpreter(uint8 value_tpye); + bool is_valid_func_type(const WASMFuncType *func_type); @@ -31,4 +34,4 @@ is_indices_overflow(uint32 import, uint32 other, char *error_buf, } #endif -#endif /* end of _WASM_LOADER_COMMON_H */ \ No newline at end of file +#endif /* end of _WASM_LOADER_COMMON_H */ diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index cc6914e4..ec40bbf3 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -334,8 +334,10 @@ is_packed_type(uint8 type) static bool is_byte_a_type(uint8 type) { - return (is_valid_value_type(type) || (type == VALUE_TYPE_VOID)) ? true - : false; + return (is_valid_value_type_for_interpreter(type) + || (type == VALUE_TYPE_VOID)) + ? true + : false; } #if WASM_ENABLE_SIMD != 0 @@ -1443,7 +1445,7 @@ resolve_value_type(const uint8 **p_buf, const uint8 *buf_end, } else { /* type which can be represented by one byte */ - if (!is_valid_value_type(type) + if (!is_valid_value_type_for_interpreter(type) && !(allow_packed_type && is_packed_type(type))) { set_error_buf(error_buf, error_buf_size, "type mismatch"); return false; @@ -1953,7 +1955,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, type->types[param_count + j] = read_uint8(p); } for (j = 0; j < param_count + result_count; j++) { - if (!is_valid_value_type(type->types[j])) { + if (!is_valid_value_type_for_interpreter(type->types[j])) { set_error_buf(error_buf, error_buf_size, "unknown value type"); return false; @@ -3049,7 +3051,7 @@ load_global_import(const uint8 **p_buf, const uint8 *buf_end, CHECK_BUF(p, p_end, 2); /* global type */ declare_type = read_uint8(p); - if (!is_valid_value_type(declare_type)) { + if (!is_valid_value_type_for_interpreter(declare_type)) { set_error_buf(error_buf, error_buf_size, "type mismatch"); return false; } @@ -3766,7 +3768,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, CHECK_BUF(p_code, buf_code_end, 1); /* 0x7F/0x7E/0x7D/0x7C */ type = read_uint8(p_code); - if (!is_valid_value_type(type)) { + if (!is_valid_value_type_for_interpreter(type)) { if (type == VALUE_TYPE_V128) set_error_buf(error_buf, error_buf_size, "v128 value type requires simd feature"); @@ -4046,7 +4048,7 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, CHECK_BUF(p, p_end, 2); /* global type */ global->type.val_type = read_uint8(p); - if (!is_valid_value_type(global->type.val_type)) { + if (!is_valid_value_type_for_interpreter(global->type.val_type)) { set_error_buf(error_buf, error_buf_size, "type mismatch"); return false; } @@ -12367,7 +12369,7 @@ re_scan: #if WASM_ENABLE_GC == 0 CHECK_BUF(p, p_end, 1); type = read_uint8(p); - if (!is_valid_value_type(type)) { + if (!is_valid_value_type_for_interpreter(type)) { set_error_buf(error_buf, error_buf_size, "unknown value type"); goto fail; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 7cef4165..0012b84a 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -91,7 +91,8 @@ is_64bit_type(uint8 type) static bool is_byte_a_type(uint8 type) { - return is_valid_value_type(type) || (type == VALUE_TYPE_VOID); + return is_valid_value_type_for_interpreter(type) + || (type == VALUE_TYPE_VOID); } static void @@ -568,7 +569,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, type->types[param_count + j] = read_uint8(p); } for (j = 0; j < param_count + result_count; j++) { - bh_assert(is_valid_value_type(type->types[j])); + bh_assert(is_valid_value_type_for_interpreter(type->types[j])); } param_cell_num = wasm_get_cell_num(type->types, param_count); @@ -1218,7 +1219,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, CHECK_BUF(p_code, buf_code_end, 1); /* 0x7F/0x7E/0x7D/0x7C */ type = read_uint8(p_code); - bh_assert(is_valid_value_type(type)); + bh_assert(is_valid_value_type_for_interpreter(type)); for (k = 0; k < sub_local_count; k++) { func->local_types[local_type_index++] = type; } @@ -6828,7 +6829,7 @@ re_scan: CHECK_BUF(p, p_end, 1); ref_type = read_uint8(p); - if (!is_valid_value_type(ref_type)) { + if (!is_valid_value_type_for_interpreter(ref_type)) { set_error_buf(error_buf, error_buf_size, "unknown value type"); goto fail;