diff --git a/ATTRIBUTIONS.md b/ATTRIBUTIONS.md index cba0e5c4b..ce0d4f852 100644 --- a/ATTRIBUTIONS.md +++ b/ATTRIBUTIONS.md @@ -60,7 +60,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### llvm -[LICENSE](./LICENCE.txt) +[LICENSE](./LICENSE) ### wasm-c-api diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 1a4a6d1e1..df06e8706 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2760,7 +2760,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, const uint8 *buf = *p_buf; AOTExport *exports; uint64 size; - uint32 i; + uint32 i, j; /* Allocate memory */ size = sizeof(AOTExport) * (uint64)module->export_count; @@ -2774,14 +2774,60 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, read_uint32(buf, buf_end, exports[i].index); read_uint8(buf, buf_end, exports[i].kind); read_string(buf, buf_end, exports[i].name); -#if 0 /* TODO: check kind and index */ - if (export_funcs[i].index >= - module->func_count + module->import_func_count) { - set_error_buf(error_buf, error_buf_size, - "function index is out of range"); - return false; + + for (j = 0; j < i; j++) { + if (!strcmp(exports[i].name, exports[j].name)) { + set_error_buf(error_buf, error_buf_size, + "duplicate export name"); + return false; + } } + + /* Check export kind and index */ + switch (exports[i].kind) { + case EXPORT_KIND_FUNC: + if (exports[i].index + >= module->import_func_count + module->func_count) { + set_error_buf(error_buf, error_buf_size, + "unknown function"); + return false; + } + break; + case EXPORT_KIND_TABLE: + if (exports[i].index + >= module->import_table_count + module->table_count) { + set_error_buf(error_buf, error_buf_size, "unknown table"); + return false; + } + break; + case EXPORT_KIND_MEMORY: + if (exports[i].index + >= module->import_memory_count + module->memory_count) { + set_error_buf(error_buf, error_buf_size, "unknown memory"); + return false; + } + break; + case EXPORT_KIND_GLOBAL: + if (exports[i].index + >= module->import_global_count + module->global_count) { + set_error_buf(error_buf, error_buf_size, "unknown global"); + return false; + } + break; +#if WASM_ENABLE_TAGS != 0 + /* TODO + case EXPORT_KIND_TAG: + if (index >= module->import_tag_count + module->tag_count) { + set_error_buf(error_buf, error_buf_size, "unknown tag"); + return false; + } + break; + */ #endif + default: + set_error_buf(error_buf, error_buf_size, "invalid export kind"); + return false; + } } *p_buf = buf; diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 9f9783102..48b3b4b73 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -137,6 +137,7 @@ is_frame_per_function(WASMExecEnv *exec_env) return module->feature_flags & WASM_FEATURE_FRAME_PER_FUNCTION; } +#if WASM_ENABLE_DUMP_CALL_STACK != 0 static bool is_frame_func_idx_disabled(WASMExecEnv *exec_env) { @@ -145,6 +146,7 @@ is_frame_func_idx_disabled(WASMExecEnv *exec_env) return module->feature_flags & WASM_FEATURE_FRAME_NO_FUNC_IDX; } +#endif static void * get_top_frame(WASMExecEnv *exec_env) @@ -1478,9 +1480,7 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module, } } -#if WASM_ENABLE_MULTI_MEMORY == 0 - bh_assert(module_inst->export_memory_count <= 1); -#else +#if WASM_ENABLE_MULTI_MEMORY != 0 if (module_inst->export_memory_count) { module_inst->export_memories = export_memories_instantiate( module, module_inst, module_inst->export_memory_count, error_buf, diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 5f52652b0..cc3b4bb95 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3610,7 +3610,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, char mapping_copy_buf[256]; char *mapping_copy = mapping_copy_buf; char *map_mapped = NULL, *map_host = NULL; - const unsigned long max_len = strlen(map_dir_list[i]) * 2 + 3; + const unsigned long max_len = + (unsigned long)strlen(map_dir_list[i]) * 2 + 3; /* Allocation limit for runtime environments with reduced stack size */ if (max_len > 256) { diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 945f63952..1c50fe75f 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -912,7 +912,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build LOAD failed"); return false; } - /* Set terminate_flags memory accecc to volatile, so that the value + /* Set terminate_flags memory access to volatile, so that the value will always be loaded from memory rather than register */ LLVMSetVolatile(terminate_flags, true); diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index 167acc62f..49b1ac1cb 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2090,7 +2090,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef *param_values = NULL, *value_rets = NULL; LLVMValueRef *result_phis = NULL, value_ret, import_func_count; #if WASM_ENABLE_MEMORY64 != 0 - LLVMValueRef u32_max, u32_cmp_result; + LLVMValueRef u32_max, u32_cmp_result = NULL; #endif LLVMTypeRef *param_types = NULL, ret_type; LLVMTypeRef llvm_func_type, llvm_func_ptr_type; diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index d65d2f413..e8dae410b 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -10,6 +10,8 @@ #include "aot_emit_gc.h" #endif +#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_MEMORY64 != 0 static bool zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) { @@ -23,6 +25,7 @@ zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) } return true; } +#endif /* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw * exception, otherwise trunc it to uint32 */ @@ -30,10 +33,10 @@ static bool check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef *elem_idx, uint32 tbl_idx) { +#if WASM_ENABLE_MEMORY64 != 0 LLVMValueRef u32_max, u32_cmp_result; LLVMBasicBlockRef check_elem_idx_succ; -#if WASM_ENABLE_MEMORY64 != 0 if (!IS_TABLE64(tbl_idx)) { return true; } @@ -69,12 +72,15 @@ check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS, true, u32_cmp_result, check_elem_idx_succ))) goto fail; -#endif return true; fail: return false; +#else + return true; +#endif } +#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ uint64 get_tbl_inst_offset(const AOTCompContext *comp_ctx, @@ -738,4 +744,4 @@ fail: return false; } -#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ +#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 016cc2cb1..dfb6b8023 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1166,8 +1166,8 @@ wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc, char *argv[]); /** - * Find the specified function in argv[0] from a WASM module instance - * and execute that function. + * Find the specified function from a WASM module instance and execute + * that function. * * @param module_inst the WASM module instance * @param name the name of the function to execute. diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index aef8f1703..6d057a6a1 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -1022,8 +1022,8 @@ execute_interruptible_poll_oneoff( uint32 i; const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff( - in, nsubscriptions), - time_quant = 1e9; + in, (uint32)nsubscriptions), + time_quant = (__wasi_timestamp_t)1e9; const uint64 size_to_copy = nsubscriptions * (uint64)sizeof(wasi_subscription_t); __wasi_subscription_t *in_copy = NULL; @@ -1034,12 +1034,13 @@ execute_interruptible_poll_oneoff( return __WASI_ENOMEM; } - bh_memcpy_s(in_copy, size_to_copy, in, size_to_copy); + bh_memcpy_s(in_copy, (uint32)size_to_copy, in, (uint32)size_to_copy); while (timeout == (__wasi_timestamp_t)-1 || elapsed <= timeout) { /* update timeout for clock subscription events */ update_clock_subscription_data( - in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed)); + in_copy, (uint32)nsubscriptions, + min_uint64(time_quant, timeout - elapsed)); err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, nsubscriptions, nevents); elapsed += time_quant; diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index a313b9be5..d26c460fe 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -3130,7 +3130,7 @@ compare_address(const struct addr_pool *addr_pool_entry, } addr_size = 16; } - max_addr_mask = addr_size * 8; + max_addr_mask = (uint8)(addr_size * 8); /* IPv4 0.0.0.0 or IPv6 :: means any address */ if (basebuf[0] == 0 && !memcmp(basebuf, basebuf + 1, addr_size - 1)) { diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index 826004f7c..ec0bc8566 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -58,7 +58,7 @@ os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution) case __WASI_CLOCK_PROCESS_CPUTIME_ID: case __WASI_CLOCK_THREAD_CPUTIME_ID: { -#if WINAPI_PARTITION_DESKTOP +#if WINAPI_PARTITION_DESKTOP && WASM_ENABLE_WAMR_COMPILER == 0 ULONG maximum_time; ULONG minimum_time; ULONG current_time; diff --git a/samples/multi-thread/wasm-apps/CMakeLists.txt b/samples/multi-thread/wasm-apps/CMakeLists.txt index d7352e427..5442398f9 100644 --- a/samples/multi-thread/wasm-apps/CMakeLists.txt +++ b/samples/multi-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) @@ -43,4 +43,4 @@ add_executable(main_thread_exception.wasm main_thread_exception.c) target_link_libraries(main_thread_exception.wasm) add_executable(main_global_atomic.wasm main_global_atomic.c) -target_link_libraries(main_global_atomic.wasm) \ No newline at end of file +target_link_libraries(main_global_atomic.wasm) diff --git a/samples/spawn-thread/wasm-apps/CMakeLists.txt b/samples/spawn-thread/wasm-apps/CMakeLists.txt index 0996d5841..df21b4485 100644 --- a/samples/spawn-thread/wasm-apps/CMakeLists.txt +++ b/samples/spawn-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/tests/unit/runtime-common/wasm-apps/main.aot b/tests/unit/runtime-common/wasm-apps/main.aot deleted file mode 100644 index 79319145a..000000000 Binary files a/tests/unit/runtime-common/wasm-apps/main.aot and /dev/null differ diff --git a/tests/unit/wasm-vm/wasm-apps/binarydump b/tests/unit/wasm-vm/wasm-apps/binarydump deleted file mode 100755 index e7c4d2a1d..000000000 Binary files a/tests/unit/wasm-vm/wasm-apps/binarydump and /dev/null differ diff --git a/tests/unit/wasm-vm/wasm-apps/build.sh b/tests/unit/wasm-vm/wasm-apps/build.sh index dbf062ae7..28496ff2f 100755 --- a/tests/unit/wasm-vm/wasm-apps/build.sh +++ b/tests/unit/wasm-vm/wasm-apps/build.sh @@ -1,6 +1,17 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +readonly CURR_DIR=$PWD +readonly BINARYDUMP_DIR=$PWD/../../../../test-tools/binarydump-tool + +# build binarydump +cd $BINARYDUMP_DIR +mkdir -p build && cd build +cmake .. && make -j +cp -a binarydump $CURR_DIR + +cd $CURR_DIR + ## build app1 /opt/wasi-sdk/bin/clang -O3 \ -z stack-size=4096 -Wl,--initial-memory=65536 \ diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 4893bb65d..70a8b687c 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -502,7 +502,7 @@ function spec_test() # Reset to commit: "Merge remote-tracking branch 'upstream/main' into merge2" git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6 git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast - # Patch table64 extension + # Patch table64 extension git checkout 940398cd4823522a9b36bec4984be4b153dedb81 -- test/core/call_indirect.wast test/core/table.wast test/core/table_copy.wast test/core/table_copy_mixed.wast test/core/table_fill.wast test/core/table_get.wast test/core/table_grow.wast test/core/table_init.wast test/core/table_set.wast test/core/table_size.wast git apply ../../spec-test-script/memory64_ignore_cases.patch || exit 1 elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then