From 46695b992ce4501bd9de847f835dc09a6095bc5c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 12 Jul 2024 12:00:55 +0900 Subject: [PATCH 1/7] EH: Use the consistent type for EH handlers (#3619) The "handlers" on the interpreter stack is sometimes treated as host pointers and sometimes treated as i64 values. It's quite broken for targets where pointers are not 64-bit. This commit makes them host pointers consistently. (at least for 32-bit and 64-bit pointers. We don't support other pointer sizes anyway.) Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3110 --- core/iwasm/interpreter/wasm_interp_classic.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index b41283929..6a5e9ae1a 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -495,6 +495,12 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) } while (0) #endif +#if UINTPTR_MAX == UINT64_MAX +#define PUSH_PTR(value) PUSH_I64(value) +#else +#define PUSH_PTR(value) PUSH_I32(value) +#endif + /* in exception handling, label_type needs to be stored to lookup exception * handlers */ @@ -1892,19 +1898,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, switch (handler_opcode) { case WASM_OP_CATCH: skip_leb(lookup_cursor); /* skip tag_index */ - PUSH_I64(end_addr); + PUSH_PTR(end_addr); break; case WASM_OP_CATCH_ALL: - PUSH_I64(end_addr); + PUSH_PTR(end_addr); break; case WASM_OP_DELEGATE: skip_leb(lookup_cursor); /* skip depth */ - PUSH_I64(end_addr); + PUSH_PTR(end_addr); /* patch target_addr */ (frame_csp - 1)->target_addr = lookup_cursor; break; case WASM_OP_END: - PUSH_I64(0); + PUSH_PTR(0); /* patch target_addr */ (frame_csp - 1)->target_addr = end_addr; break; From 73caf19e6960cc81aac1ec3afcd914632129d1d3 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 12 Jul 2024 16:43:22 +0800 Subject: [PATCH 2/7] Fix compile warnings/error reported in Windows (#3616) Clear some compile warnings and fix undefined reference error for symbol ffs in Windows platform. --- core/iwasm/aot/aot_runtime.c | 10 +++++----- core/iwasm/common/wasm_loader_common.c | 4 +++- core/iwasm/common/wasm_memory.c | 4 ++-- core/iwasm/compilation/aot_emit_memory.c | 19 ++++++++++++++++++- core/iwasm/compilation/aot_llvm.c | 7 ++++--- core/iwasm/compilation/aot_llvm.h | 6 +++--- core/iwasm/compilation/aot_llvm_extra.cpp | 2 +- core/iwasm/compilation/aot_orc_extra.cpp | 2 +- core/iwasm/compilation/simd/simd_load_store.c | 2 +- core/iwasm/interpreter/wasm_interp_classic.c | 8 +++++++- core/iwasm/interpreter/wasm_runtime.c | 8 ++++---- 11 files changed, 49 insertions(+), 23 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index e297833b3..bfe691ea2 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1139,7 +1139,7 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent, if (memory_inst->memory_data) { bh_memcpy_s((uint8 *)memory_inst->memory_data + base_offset, - (uint32)memory_inst->memory_data_size - base_offset, + (uint32)(memory_inst->memory_data_size - base_offset), data_seg->bytes, length); } } @@ -1212,7 +1212,7 @@ aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx) return NULL; } - extra->function_count = func_count; + extra->function_count = (uint32)func_count; } /* instantiate function if needed */ @@ -1764,8 +1764,8 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent, aot_get_data_section_addr(module, AOT_STACK_SIZES_SECTION_NAME, NULL); #if WASM_ENABLE_PERF_PROFILING != 0 - total_size = (uint64)sizeof(AOTFuncPerfProfInfo) - * (module->import_func_count + module->func_count); + total_size = sizeof(AOTFuncPerfProfInfo) + * ((uint64)module->import_func_count + module->func_count); if (!(module_inst->func_perf_profilings = runtime_malloc(total_size, error_buf, error_buf_size))) { goto fail; @@ -2536,7 +2536,7 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, if (ret) { #if WASM_ENABLE_MEMORY64 != 0 if (is_memory64) - *p_result = GET_I64_FROM_ADDR(&argv.u64); + *p_result = argv.u64; else #endif { diff --git a/core/iwasm/common/wasm_loader_common.c b/core/iwasm/common/wasm_loader_common.c index 773e78c51..179639fca 100644 --- a/core/iwasm/common/wasm_loader_common.c +++ b/core/iwasm/common/wasm_loader_common.c @@ -104,7 +104,9 @@ bool is_valid_func_type(const WASMFuncType *func_type) { unsigned i; - for (i = 0; i < func_type->param_count + func_type->result_count; i++) { + for (i = 0; + i < (unsigned)(func_type->param_count + func_type->result_count); + i++) { if (!is_valid_value_type(func_type->types[i])) return false; } diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index de1d54ed3..187b4de03 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -930,13 +930,13 @@ wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst, #if WASM_ENABLE_AOT != 0 if (module_inst->module_type == Wasm_Module_AoT) { return aot_enlarge_memory((AOTModuleInstance *)module_inst, - inc_page_count); + (uint32)inc_page_count); } #endif #if WASM_ENABLE_INTERP != 0 if (module_inst->module_type == Wasm_Module_Bytecode) { return wasm_enlarge_memory((WASMModuleInstance *)module_inst, - inc_page_count); + (uint32)inc_page_count); } #endif diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index ff4923966..e7c9b679b 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -91,6 +91,23 @@ get_memory_check_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return mem_check_bound; } +#if defined(_WIN32) || defined(_WIN32_) +static inline int +ffs(int n) +{ + int pos = 0; + + if (n == 0) + return 0; + + while (!(n & 1)) { + pos++; + n >>= 1; + } + return pos + 1; +} +#endif + static LLVMValueRef get_memory_curr_page_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); @@ -198,7 +215,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, * has the natural alignment. for platforms using mmap, it can * be even larger. for now, use a conservative value. */ - const int max_align = 8; + const unsigned int max_align = 8; int shift = ffs((int)(unsigned int)mem_offset); if (shift == 0) { *alignp = max_align; diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index df07c3ca6..6471c9c3e 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -749,7 +749,8 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module, * and more importantly doesn't involve relocations. */ LLVMAttributeRef attr_short_call = LLVMCreateStringAttribute( - comp_ctx->context, "short-call", strlen("short-call"), "", 0); + comp_ctx->context, "short-call", (unsigned)strlen("short-call"), + "", 0); LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, attr_short_call); } @@ -3529,7 +3530,7 @@ aot_block_destroy(AOTCompContext *comp_ctx, AOTBlock *block) bool aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx, - uint32 offset, uint32 bytes) + uint64 offset, uint32 bytes) { AOTCheckedAddr *node = func_ctx->checked_addr_list; @@ -3573,7 +3574,7 @@ aot_checked_addr_list_del(AOTFuncContext *func_ctx, uint32 local_idx) bool aot_checked_addr_list_find(AOTFuncContext *func_ctx, uint32 local_idx, - uint32 offset, uint32 bytes) + uint64 offset, uint32 bytes) { AOTCheckedAddr *node = func_ctx->checked_addr_list; diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index ab5242173..270e5ae45 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -197,7 +197,7 @@ typedef struct AOTBlockStack { typedef struct AOTCheckedAddr { struct AOTCheckedAddr *next; uint32 local_idx; - uint32 offset; + uint64 offset; uint32 bytes; } AOTCheckedAddr, *AOTCheckedAddrList; @@ -574,14 +574,14 @@ wasm_type_to_llvm_type(const AOTCompContext *comp_ctx, bool aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx, - uint32 offset, uint32 bytes); + uint64 offset, uint32 bytes); void aot_checked_addr_list_del(AOTFuncContext *func_ctx, uint32 local_idx); bool aot_checked_addr_list_find(AOTFuncContext *func_ctx, uint32 local_idx, - uint32 offset, uint32 bytes); + uint64 offset, uint32 bytes); void aot_checked_addr_list_destroy(AOTFuncContext *func_ctx); diff --git a/core/iwasm/compilation/aot_llvm_extra.cpp b/core/iwasm/compilation/aot_llvm_extra.cpp index dd1a1e845..fdd5517b9 100644 --- a/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/core/iwasm/compilation/aot_llvm_extra.cpp @@ -411,7 +411,7 @@ aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size) return NULL; } - compressed_str_len = Result.size(); + compressed_str_len = (uint32)Result.size(); if (!(compressed_str = (char *)wasm_runtime_malloc(compressed_str_len))) { aot_set_last_error("allocate memory failed"); return NULL; diff --git a/core/iwasm/compilation/aot_orc_extra.cpp b/core/iwasm/compilation/aot_orc_extra.cpp index 4f7a55d94..dad9e04c0 100644 --- a/core/iwasm/compilation/aot_orc_extra.cpp +++ b/core/iwasm/compilation/aot_orc_extra.cpp @@ -189,7 +189,7 @@ PartitionFunction(GlobalValueSet Requested) auto GVName = GV->getName(); /* get the function name */ const char *gvname = GVName.begin(); /* C function name */ const char *wrapper; - uint32 prefix_len = strlen(AOT_FUNC_PREFIX); + uint32 prefix_len = (uint32)strlen(AOT_FUNC_PREFIX); LOG_DEBUG("requested func %s", gvname); /* Convert "aot_func#n_wrapper" to "aot_func#n" */ diff --git a/core/iwasm/compilation/simd/simd_load_store.c b/core/iwasm/compilation/simd/simd_load_store.c index 3b5023937..d3bbcc965 100644 --- a/core/iwasm/compilation/simd/simd_load_store.c +++ b/core/iwasm/compilation/simd/simd_load_store.c @@ -281,7 +281,7 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, /* data_length in bytes */ static bool simd_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, - uint32 offset, uint32 data_length, LLVMValueRef value, + mem_offset_t offset, uint32 data_length, LLVMValueRef value, LLVMTypeRef value_ptr_type, bool enable_segue) { LLVMValueRef maddr, result; diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 6a5e9ae1a..bd8a4eeb1 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -5644,8 +5644,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #endif /* allowing the destination and source to overlap */ +#if WASM_ENABLE_MEMORY64 == 0 bh_memmove_s(mdst, (uint32)(linear_mem_size - dst), - msrc, len); + msrc, (uint32)len); +#else + /* use memmove when memory64 is enabled since len + may be larger than UINT32_MAX */ + memmove(mdst, msrc, len); +#endif break; } case WASM_OP_MEMORY_FILL: diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index b17bd54df..0d4d0b37d 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1608,7 +1608,7 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, if (ret) { #if WASM_ENABLE_MEMORY64 != 0 if (is_memory64) - *p_result = GET_I64_FROM_ADDR(&argv.u64); + *p_result = argv.u64; else #endif { @@ -2184,8 +2184,8 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, heap_size = APP_HEAP_SIZE_MAX; module_inst_mem_inst_size = - (uint64)sizeof(WASMMemoryInstance) - * (module->import_memory_count + module->memory_count); + sizeof(WASMMemoryInstance) + * ((uint64)module->import_memory_count + module->memory_count); #if WASM_ENABLE_JIT != 0 /* If the module doesn't have memory, reserve one mem_info space @@ -2615,7 +2615,7 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, if (memory_data) { bh_memcpy_s(memory_data + base_offset, - (uint32)memory_size - base_offset, data_seg->data, + (uint32)(memory_size - base_offset), data_seg->data, length); } } From c254bffbc56fc89be33ae4940762348936fddc14 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 12 Jul 2024 16:58:10 +0800 Subject: [PATCH 3/7] Fix compile errors on workload bwa and benchmark jetstream (#3617) Error was reported when building jetstream benchmark with emsdk: ``` clang: error: unsupported option '-msse2' for target 'wasm32-wasi' ``` Error was reported when building bwa workload: ``` fatal: reference is not a tree: 139f68fc4c3747813783a488aef2adc86626b01b ``` --- samples/workload/bwa/CMakeLists.txt | 3 +-- samples/workload/bwa/README.md | 2 +- tests/benchmarks/jetstream/build.sh | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/workload/bwa/CMakeLists.txt b/samples/workload/bwa/CMakeLists.txt index 5db52a38b..45097ab26 100644 --- a/samples/workload/bwa/CMakeLists.txt +++ b/samples/workload/bwa/CMakeLists.txt @@ -35,9 +35,8 @@ ExternalProject_Add(libz_src ################ bwa ################ ExternalProject_Add(bwa GIT_REPOSITORY https://github.com/lh3/bwa.git - GIT_TAG 139f68fc4c3747813783a488aef2adc86626b01b + GIT_TAG v0.7.18 GIT_PROGRESS ON - GIT_SHALLOW ON SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bwa DEPENDS libz_src UPDATE_COMMAND git clean -ffdx && git checkout -- * diff --git a/samples/workload/bwa/README.md b/samples/workload/bwa/README.md index a8fbe3e69..e665db895 100644 --- a/samples/workload/bwa/README.md +++ b/samples/workload/bwa/README.md @@ -42,5 +42,5 @@ Then compile wasm file to aot file and run: ``` shell $ cd /samples/workload/bwa/build $ /wamr-compiler/build/wamrc -o bwa.aot bwa.wasm -$ /product-mini/platforms/linux/iwasm --dir=. bwa.aot index hs38DH.fa +$ /product-mini/platforms/linux/iwasm --dir=. bwa.aot index hs38DH-extra.fa ``` diff --git a/tests/benchmarks/jetstream/build.sh b/tests/benchmarks/jetstream/build.sh index 019b4073d..ed49cd6a7 100755 --- a/tests/benchmarks/jetstream/build.sh +++ b/tests/benchmarks/jetstream/build.sh @@ -16,7 +16,7 @@ mkdir -p ${OUT_DIR} if [[ $1 != "--no-simd" ]];then NATIVE_SIMD_FLAGS="-msse2 -msse3 -msse4" - WASM_SIMD_FLAGS="-msimd128 -msse2 -msse3 -msse4" + WASM_SIMD_FLAGS="-msimd128" else NATIVE_SIMD_FLAGS="" WASM_SIMD_FLAGS="" From 7affac0ed35d7feec1cbe20f443248027b764435 Mon Sep 17 00:00:00 2001 From: HongxiaWangSSSS <103626902+HongxiaWangSSSS@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:59:59 +0800 Subject: [PATCH 4/7] wasm_application.c: Avoid null pointer dereference (#3620) --- core/iwasm/common/wasm_application.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/common/wasm_application.c b/core/iwasm/common/wasm_application.c index da3b31c95..3b3be16c0 100644 --- a/core/iwasm/common/wasm_application.c +++ b/core/iwasm/common/wasm_application.c @@ -513,7 +513,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, bh_memcpy_s(&u.val, sizeof(double), &ud.d, sizeof(double)); } - if (endptr[0] == ':') { + if (endptr && endptr[0] == ':') { uint64 sig; union ieee754_double ud; sig = strtoull(endptr + 1, &endptr, 0); From 501d7d5adf648edd438603decb071c7c8f64a9c4 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Mon, 15 Jul 2024 17:15:59 -0700 Subject: [PATCH 5/7] Add apis to get package version (#3601) Add three APIs: - wasm_runtime_get_file_package_version - wasm_runtime_get_module_package_version - wasm_runtime_get_current_package_version --- core/iwasm/aot/aot_loader.c | 2 + core/iwasm/aot/aot_runtime.h | 3 ++ core/iwasm/common/wasm_runtime_common.c | 64 +++++++++++++++++++++++-- core/iwasm/include/wasm_export.h | 33 ++++++++++++- core/iwasm/interpreter/wasm.h | 3 ++ core/iwasm/interpreter/wasm_loader.c | 2 + 6 files changed, 102 insertions(+), 5 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 0116ae765..645f68b1d 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -4168,6 +4168,8 @@ load(const uint8 *buf, uint32 size, AOTModule *module, return false; } + module->package_version = version; + if (!create_sections(module, buf, size, §ion_list, error_buf, error_buf_size)) return false; diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index 34d1babd1..e3704f827 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -130,6 +130,9 @@ typedef struct LocalRefFlag { typedef struct AOTModule { uint32 module_type; + /* the package version read from the AOT file */ + uint32 package_version; + /* import memories */ uint32 import_memory_count; AOTImportMemory *import_memories; diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index dad2eb29b..803261539 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -858,11 +858,11 @@ wasm_runtime_set_default_running_mode(RunningMode running_mode) PackageType get_package_type(const uint8 *buf, uint32 size) { -#if (WASM_ENABLE_WORD_ALIGN_READ != 0) - uint32 buf32 = *(uint32 *)buf; - buf = (const uint8 *)&buf32; -#endif if (buf && size >= 4) { +#if (WASM_ENABLE_WORD_ALIGN_READ != 0) + uint32 buf32 = *(uint32 *)buf; + buf = (const uint8 *)&buf32; +#endif if (buf[0] == '\0' && buf[1] == 'a' && buf[2] == 's' && buf[3] == 'm') return Wasm_Module_Bytecode; if (buf[0] == '\0' && buf[1] == 'a' && buf[2] == 'o' && buf[3] == 't') @@ -887,6 +887,62 @@ wasm_runtime_get_module_package_type(WASMModuleCommon *module) return module->module_type; } +uint32 +wasm_runtime_get_file_package_version(const uint8 *buf, uint32 size) +{ + if (buf && size >= 8) { + uint32 version; +#if (WASM_ENABLE_WORD_ALIGN_READ != 0) + uint32 buf32 = *(uint32 *)(buf + sizeof(uint32)); + buf = (const uint8 *)&buf32; + version = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; +#else + version = buf[4] | buf[5] << 8 | buf[6] << 16 | buf[7] << 24; +#endif + return version; + } + + return 0; +} + +uint32 +wasm_runtime_get_module_package_version(WASMModuleCommon *module) +{ + if (!module) { + return 0; + } + +#if WASM_ENABLE_INTERP != 0 + if (module->module_type == Wasm_Module_Bytecode) { + WASMModule *wasm_module = (WASMModule *)module; + return wasm_module->package_version; + } +#endif + +#if WASM_ENABLE_AOT != 0 + if (module->module_type == Wasm_Module_AoT) { + AOTModule *aot_module = (AOTModule *)module; + return aot_module->package_version; + } +#endif + + return 0; +} + +uint32 +wasm_runtime_get_current_package_version(package_type_t package_type) +{ + switch (package_type) { + case Wasm_Module_Bytecode: + return WASM_CURRENT_VERSION; + case Wasm_Module_AoT: + return AOT_CURRENT_VERSION; + case Package_Type_Unknown: + default: + return 0; + } +} + #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 72f36b819..569c4deaa 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -442,7 +442,38 @@ wasm_runtime_get_file_package_type(const uint8_t *buf, uint32_t size); * unknown */ WASM_RUNTIME_API_EXTERN package_type_t -wasm_runtime_get_module_package_type(wasm_module_t module); +wasm_runtime_get_module_package_type(const wasm_module_t module); + +/** + * Get the package version of a buffer. + * + * @param buf the package buffer + * @param size the package buffer size + * + * @return the package version, return zero if the version is unknown + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_runtime_get_file_package_version(const uint8_t *buf, uint32_t size); + +/** + * Get the package version of a module + * + * @param module the module + * + * @return the package version, or zero if version is unknown + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_runtime_get_module_package_version(const wasm_module_t module); + +/** + * Get the currently supported version of the package type + * + * @param package_type the package type + * + * @return the currently supported version, or zero if package type is unknown + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_runtime_get_current_package_version(package_type_t package_type); /** * Check whether a file is an AOT XIP (Execution In Place) file diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index 0755d10e0..ea93adb03 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -836,6 +836,9 @@ struct WASMModule { AOTModule structure. */ uint32 module_type; + /* the package version read from the WASM file */ + uint32 package_version; + uint32 type_count; uint32 import_count; uint32 function_count; diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index ec40bbf34..785b28980 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -6542,6 +6542,8 @@ load(const uint8 *buf, uint32 size, WASMModule *module, return false; } + module->package_version = version; + if (!create_sections(buf, size, §ion_list, error_buf, error_buf_size) || !load_from_sections(module, section_list, true, wasm_binary_freeable, error_buf, error_buf_size)) { From f1fabd55594070ba521fb11408e2927d4fdd4f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Freitas?= Date: Tue, 16 Jul 2024 01:38:55 +0100 Subject: [PATCH 6/7] Update devcontainer.md (#3628) Tiny typo fix: from `.devontainer` to `.devcontainer`. --- doc/devcontainer.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/devcontainer.md b/doc/devcontainer.md index b75f13ec9..65458a3d5 100644 --- a/doc/devcontainer.md +++ b/doc/devcontainer.md @@ -2,7 +2,7 @@ We all know Docker containers and may use them a lot in school or work. It resolves dependency management for our projects/applications, prevents package version confusion and conflict, and contamination of the local environment. -Now WAMR has a Dockerfile under path `.devontainer` to create a container image, dev container images that you could easily use in VS Code. In case you prefer other IDE like Clion, you can also build it and use for the IDE you like. +Now WAMR has a Dockerfile under path `.devcontainer` to create a container image, dev container images that you could easily use in VS Code. In case you prefer other IDE like Clion, you can also build it and use for the IDE you like. ## How to use it @@ -22,4 +22,4 @@ If you encounter any problems or get stuck somewhere, may this video [demo](http [Remote development with Docker in VS Code](https://code.visualstudio.com/docs/remote/containers#_getting-started) -[What is dev container image in VS Code](https://code.visualstudio.com/docs/remote/containers#_prebuilding-dev-container-images) \ No newline at end of file +[What is dev container image in VS Code](https://code.visualstudio.com/docs/remote/containers#_prebuilding-dev-container-images) From 8af155076c6c62d9766ede640cf3f29fa73a4b53 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 16 Jul 2024 09:50:11 +0800 Subject: [PATCH 7/7] Update version to 2.1.1 and update release notes (#3618) --- RELEASE_NOTES.md | 71 +++++++++++++++++++++++++ core/iwasm/common/wasm_runtime_common.c | 4 +- core/version.h | 2 +- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 59ce379fc..988315ef2 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,74 @@ +## WAMR-2.1.1 + +### Breaking Changes + - Sync up with latest wasi-nn spec (#3530) + +### New Features + - Add APIs to get package version (#3601) + - Export API wasm_runtime_enlarge_memory (#3569) + - Add table type API support (#3515) + - Add wasm_runtime_get_module_package_type() and wasm_runtime_get_file_package_type() (#3600) + +### Bug Fixes + - wasm_application.c: Avoid null pointer dereference (#3620) + - EH: Use the consistent type for EH handlers (#3619) + - wasm loader: Fix several issues in GC and exception handling (#3586) + - wasm loader: Fix push_frame_offset when pushing v128 type (#3588) + - Add integer overflow check for some indices in wasm/aot loader (#3579) + - aot-analyzer: Fix a few printf formats (#3590) + - aot-analyzer: Fix macos build (#3589) + - Fix compilation errors in aot-analyzer tool (#3584) + - interp debugger: Fix setting invalid value to step_count (#3583) + - aot loader: Check import global value type before using (#3571) + - Fix missing stack frame alloc/free in AOT multi-module invoke (#3562) + - aot loader: Verify global value type (#3560) + - aot loader: Add more checks in load_native_symbol_section() (#3559) + - core/shared/platform: Zero memory returned by os_mmap in some platforms (#3551) + - dwarf_extractor.cpp: Fix buffer overruns (#3541) + - aot loader: Prevent loading multiple native symbol sections (#3538) + - Validate func type in aot loader (#3535) + - wamrc: Fix truncated DW_AT_producer (#3537) + - wasm loader: Fix pop invalid offset count when stack top is ANY (#3516) + - Fix two fuzz issues (#3529) + - Fix several issues reported by oss-fuzz (#3526) + +### Enhancements + - Fix compile warnings/error reported in Windows (#3616) + - wasm loader: Reject v128 for interpreters (#3611) + - Fix typos in wamrc and wasm_export.h (#3609) + - Bump ocaml/setup-ocaml from 2 to 3 (#3604) + - CMakeLists.txt: Fix Android pthread linkage (#3591) + - Add more arm AOT reloc entries (#3587) + - wasi-nn: Use numpy v1 in wasi-nn test requirements.txt (#3582) + - Optimize for multi-module support in AOT mode (#3563) + - aot compiler: Propagate const-ness by ourselves (#3567) + - aot_resolve_target_info: Avoid in-place modification of e_type (#3564) + - Allow missing imports in wasm loader and report error in wasm instantiation instead (#3539) + - aot compiler: Use larger alignment for load/store when possible (#3552) + - Consistent const keyword position in wasm_export.h (#3558) + - wasm_memory.c: Fix typo: hasn't been initialize -> `hasn't been initialized` (#3547) + - dwarf_extractor.cpp: Try to preserve link name (#3542) + - dwarf_extractor.cpp: Enable limited support for C++ (#3540) + - Sync up with latest wasi-nn spec (#3530) + - Expose more functions related to emitting AOT files (#3520) + - Make wasi-nn backends as separated shared libraries (#3509) + - build_llvm.py: Speed up llvm build with multi procs on windows (#3512) + - Fix compilation warnings of wasi-nn (#3497) + - Add missing functions to make RIOT work with the 2.x.x version (#3508) + +### Others + - Update devcontainer.md (#3628) + - Fix compile errors on workload bwa and benchmark jetstream (#3617) + - wasm-mutator-fuzz: Set compilers earlier (#3585) + - wasm-mutator-fuzz: Make compilers overridable (#3578) + - wasi-nn: Add wasmedge-wasinn-example as smoke test (#3554) + - Add standalone cases (#3536) + - wasm-mutator-fuzz: Fix build errors and warnings for macOS (#3519) + - wasm-mutator-fuzz: Use another variable to check if in oss-fuzz environment (#3518) + - Add wasi-nn example as smoke test case (#3501) + +--- + ## WAMR-2.1.0 ### Breaking Changes diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 803261539..8ed14ec40 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -878,7 +878,7 @@ wasm_runtime_get_file_package_type(const uint8 *buf, uint32 size) } PackageType -wasm_runtime_get_module_package_type(WASMModuleCommon *module) +wasm_runtime_get_module_package_type(WASMModuleCommon *const module) { if (!module) { return Package_Type_Unknown; @@ -906,7 +906,7 @@ wasm_runtime_get_file_package_version(const uint8 *buf, uint32 size) } uint32 -wasm_runtime_get_module_package_version(WASMModuleCommon *module) +wasm_runtime_get_module_package_version(WASMModuleCommon *const module) { if (!module) { return 0; diff --git a/core/version.h b/core/version.h index e321744e3..a1626f83c 100644 --- a/core/version.h +++ b/core/version.h @@ -7,5 +7,5 @@ #define _WAMR_VERSION_H_ #define WAMR_VERSION_MAJOR 2 #define WAMR_VERSION_MINOR 1 -#define WAMR_VERSION_PATCH 0 +#define WAMR_VERSION_PATCH 1 #endif