diff --git a/.github/workflows/build_docker_images.yml b/.github/workflows/build_docker_images.yml index 819bf94c3..d5bf682c4 100644 --- a/.github/workflows/build_docker_images.yml +++ b/.github/workflows/build_docker_images.yml @@ -21,7 +21,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build and save Docker image(wasm-debug-server:${{ inputs.ver_num }}) to tar file run: | diff --git a/.github/workflows/build_iwasm_release.yml b/.github/workflows/build_iwasm_release.yml index 64aa9a92c..86e50ede9 100644 --- a/.github/workflows/build_iwasm_release.yml +++ b/.github/workflows/build_iwasm_release.yml @@ -35,11 +35,11 @@ jobs: build: runs-on: ${{ inputs.runner }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: get cached LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin diff --git a/.github/workflows/build_llvm_libraries.yml b/.github/workflows/build_llvm_libraries.yml index a24e340fa..18b90e568 100644 --- a/.github/workflows/build_llvm_libraries.yml +++ b/.github/workflows/build_llvm_libraries.yml @@ -31,7 +31,7 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: install dependencies run: /usr/bin/env python3 -m pip install -r requirements.txt @@ -52,7 +52,7 @@ jobs: - name: Cache LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -62,7 +62,7 @@ jobs: ./core/deps/llvm/build/share key: ${{ steps.create_lib_cache_key.outputs.key}} - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/.ccache key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }} @@ -70,7 +70,7 @@ jobs: 0-ccache-${{ inputs.os }} if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-20.04' - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/.cache/ccache key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }} @@ -82,7 +82,7 @@ jobs: - run: sudo apt install -y ccache ninja-build if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu') && inputs.container_image == '' - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/Library/Caches/ccache key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }} diff --git a/.github/workflows/build_wamr_lldb.yml b/.github/workflows/build_wamr_lldb.yml index 1a73750a6..3e1e10ffd 100644 --- a/.github/workflows/build_wamr_lldb.yml +++ b/.github/workflows/build_wamr_lldb.yml @@ -47,7 +47,7 @@ jobs: PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz PYTHON_MACOS_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-apple-darwin-install_only.tar.gz steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: download and install wasi-sdk run: | @@ -60,7 +60,7 @@ jobs: - name: Cache build id: lldb_build_cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm-project/build/bin diff --git a/.github/workflows/build_wamr_sdk.yml b/.github/workflows/build_wamr_sdk.yml index fff6d85df..f4ca9afd4 100644 --- a/.github/workflows/build_wamr_sdk.yml +++ b/.github/workflows/build_wamr_sdk.yml @@ -35,7 +35,7 @@ jobs: build: runs-on: ${{ inputs.runner }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: download and install wasi-sdk run: | diff --git a/.github/workflows/build_wamr_vscode_ext.yml b/.github/workflows/build_wamr_vscode_ext.yml index 3dfb290cf..b91f054cf 100644 --- a/.github/workflows/build_wamr_vscode_ext.yml +++ b/.github/workflows/build_wamr_vscode_ext.yml @@ -18,7 +18,7 @@ jobs: build: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js 16.x uses: actions/setup-node@v3 diff --git a/.github/workflows/build_wamrc.yml b/.github/workflows/build_wamrc.yml index 11c5de9ba..7c4dab039 100644 --- a/.github/workflows/build_wamrc.yml +++ b/.github/workflows/build_wamrc.yml @@ -35,11 +35,11 @@ jobs: build: runs-on: ${{ inputs.runner }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: get cached LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index 17d60ac43..b0aa0a2b8 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index d6fe4b51d..99260bfc8 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -85,13 +85,13 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # since jobs.id can't contain the dot character # it is hard to use `format` to assemble the cache key - name: Get LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -214,13 +214,13 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # only download llvm cache when needed - name: Get LLVM libraries id: retrieve_llvm_libs if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -285,12 +285,12 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get LLVM libraries id: retrieve_llvm_libs if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -351,7 +351,7 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk run: | @@ -368,7 +368,7 @@ jobs: sudo mv wabt-1.0.31 wabt - name: Get LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -520,7 +520,7 @@ jobs: test_option: $SIMD_TEST_OPTIONS steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk if: matrix.test_option == '$WASI_TEST_OPTIONS' @@ -555,7 +555,7 @@ jobs: - name: Get LLVM libraries if: env.USE_LLVM == 'true' id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -617,7 +617,7 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: install dependencies run: | @@ -636,7 +636,7 @@ jobs: - name: Cache LLDB id: cache-lldb - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-lldb-vscode with: diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index fbf81ae1f..19ff1874a 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -71,11 +71,11 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -174,13 +174,13 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # only download llvm cache when needed - name: Get LLVM libraries id: retrieve_llvm_libs if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -226,7 +226,7 @@ jobs: ] steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wabt run: | @@ -258,7 +258,7 @@ jobs: ] steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk run: | diff --git a/.github/workflows/compilation_on_nuttx.yml b/.github/workflows/compilation_on_nuttx.yml index 5368b06a1..2eff73c2c 100644 --- a/.github/workflows/compilation_on_nuttx.yml +++ b/.github/workflows/compilation_on_nuttx.yml @@ -87,21 +87,21 @@ jobs: steps: - name: Checkout NuttX - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: apache/incubator-nuttx ref: releases/12.4 path: nuttx - name: Checkout NuttX Apps - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: apache/incubator-nuttx-apps ref: releases/12.4 path: apps - name: Checkout WAMR - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ github.repository }} path: apps/interpreters/wamr/wamr diff --git a/.github/workflows/compilation_on_sgx.yml b/.github/workflows/compilation_on_sgx.yml index 2cb37bdc6..8dadb518d 100644 --- a/.github/workflows/compilation_on_sgx.yml +++ b/.github/workflows/compilation_on_sgx.yml @@ -119,7 +119,7 @@ jobs: source /opt/intel/sgxsdk/environment - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build iwasm run: | @@ -165,7 +165,7 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk run: | @@ -221,7 +221,7 @@ jobs: - name: Get LLVM libraries if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS' id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -290,12 +290,12 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get LLVM libraries if: matrix.running_mode == 'aot' id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin diff --git a/.github/workflows/compilation_on_windows.yml b/.github/workflows/compilation_on_windows.yml index 97a4aaae2..a623ab1a7 100644 --- a/.github/workflows/compilation_on_windows.yml +++ b/.github/workflows/compilation_on_windows.yml @@ -74,7 +74,7 @@ jobs: "-DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1" ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: clone uvwasi library if: ${{ !contains(matrix.build_options, '-DWAMR_BUILD_LIBC_UVWASI=0') }} @@ -108,7 +108,7 @@ jobs: ] steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk if: matrix.test_option == '$WASI_TEST_OPTIONS' diff --git a/.github/workflows/create_tag.yml b/.github/workflows/create_tag.yml index 3a145bf04..27eee2acf 100644 --- a/.github/workflows/create_tag.yml +++ b/.github/workflows/create_tag.yml @@ -24,7 +24,7 @@ jobs: new_tag: ${{ steps.preparation.outputs.new_tag }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Full git history is needed to get a proper list of commits and tags with: fetch-depth: 0 diff --git a/.github/workflows/hadolint_dockerfiles.yml b/.github/workflows/hadolint_dockerfiles.yml index bdabeb6e5..c540649c8 100644 --- a/.github/workflows/hadolint_dockerfiles.yml +++ b/.github/workflows/hadolint_dockerfiles.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # on default, hadolint will fail on warnings and errors - name: Run hadolint on dockerfiles diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 17d6f35bd..8b9a0ed5e 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -68,13 +68,13 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # since jobs.id can't contain the dot character # it is hard to use `format` to assemble the cache key - name: Get LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -199,13 +199,13 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # only download llvm cache when needed - name: Get LLVM libraries id: retrieve_llvm_libs if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -347,12 +347,12 @@ jobs: sanitizer: asan steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get LLVM libraries id: retrieve_llvm_libs if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -414,7 +414,7 @@ jobs: llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk run: | @@ -431,7 +431,7 @@ jobs: - name: Get LLVM libraries id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin @@ -601,7 +601,7 @@ jobs: test_option: $SIMD_TEST_OPTIONS steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: download and install wasi-sdk if: matrix.test_option == '$WASI_TEST_OPTIONS' @@ -639,7 +639,7 @@ jobs: - name: Get LLVM libraries if: env.USE_LLVM == 'true' id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin diff --git a/.github/workflows/release_process.yml b/.github/workflows/release_process.yml index ef722acdb..5808b821c 100644 --- a/.github/workflows/release_process.yml +++ b/.github/workflows/release_process.yml @@ -28,7 +28,7 @@ jobs: outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: prepare the release note run: | diff --git a/.github/workflows/reuse_latest_release_binaries.yml b/.github/workflows/reuse_latest_release_binaries.yml index 7f82672a6..c9832cec9 100644 --- a/.github/workflows/reuse_latest_release_binaries.yml +++ b/.github/workflows/reuse_latest_release_binaries.yml @@ -28,7 +28,7 @@ jobs: outputs: result: ${{ steps.try_reuse.outputs.result }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Full git history is needed to get a proper list of commits and tags with: fetch-depth: 0 diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 864bb0b7c..5bdad8f23 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -96,21 +96,21 @@ jobs: steps: - name: Checkout NuttX - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: apache/incubator-nuttx ref: releases/12.4 path: nuttx - name: Checkout NuttX Apps - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: apache/incubator-nuttx-apps ref: releases/12.4 path: apps - name: Checkout WAMR - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ github.repository }} path: apps/interpreters/wamr/wamr @@ -118,7 +118,7 @@ jobs: - name: Get LLVM libraries if: contains(matrix.wamr_test_option.mode, 'aot') id: retrieve_llvm_libs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./core/deps/llvm/build/bin diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e2cda8858..3fcfaf4bc 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,79 @@ +## WAMR-1.3.2 + +### Breaking Changes + +### New Features +- Implement Exception Handling for classic interpreter (#3096) + - Use `cmake -DWAMR_BUILD_EXCE_HANDLING=1/0` option to enable/disable + the feature, and by default it is disabled + - It is still in highly experimental stage + +### Bug Fixes +- Fix build errors when initializing wasm_val_t values with macros (#3007) +- fix(wasm-c-api): Do not clone stack frames if there's no trap (#3008) +- classic-interp: Handle SIMD opcode when JIT is enabled (#3046) +- fast-interp: Fix dynamic offset error issue in else branch (#3058) +- wasm_cluster_destroy_spawned_exec_env: Avoid "invalid exec env" trap (#3068) +- thread-mgr: Fix locking problems around aux stack allocation (#3073) +- cosmopolitan: Update compiler and update platform_internal.h (#3079) +- wasi: Apply wasm_runtime_begin_blocking_op to poll as well (#3080) +- Fix memory/table segment checks in memory.init/table.init (#3081) +- perf profiling: Adjust the calculation of execution time (#3089) +- aot: Fix LLVMSetTailCallKind check (#3099) +- fast-interp: Fix stack recovery for else branch (#3100) +- fast-interp: Fix frame_offset pop order (#3101) +- Fix AOT compilation on MacOS (#3102) +- fast-interp: Fix block with parameter in polymorphic stack issue (#3112) +- Fix read and validation of misc/simd/atomic sub opcodes (#3115) + +### Enhancements +- Clear compilation warning and dead code (#3002) +- aot debug: Try to use a bit more appropriate file names (#3000) +- Increase default app thread stack size (#3010) +- Rename rwlock_init to avoid conflict (#3016) +- nuttx: Use larger alignment for os_mmap and comment why (#3017) +- Allow using mmap for shared memory if hw bound check is disabled (#3029) +- Don't redefine D_INO if already defined (#3036) +- Enhancements on wasm function execution time statistic (#2985) +- wamr-compiler: Fix non-x86{_64} host builds (#3037) +- Disable quick aot entry for interp and fast-jit (#3039) +- nuttx: Add option to enable quick aot entry (#3040) +- Set CONFIG_HAS_CAP_ENTER to support posix file api for freertos (#3041) +- Revert "Enable MAP_32BIT for macOS (#2992)" (#3032) +- Enable quick aot entry when hw bound check is disabled (#3044) +- Do not inherit WASM_SUSPEND_FLAG_BLOCKING from the parent thread (#3051) +- wasm_runtime_begin_blocking_op: A comment about usage expectation (#3056) +- Check arguments before calling bh_hash_map_find (#3055) +- Fix aot large model (--size-level=0) with LLVM 18 (#3057) +- Add flag to control Winsocket initialization (#3060) +- nuttx: If STACK_GUARD_SIZE is not set, leave it to config.h (#2927) +- Enhance setting write gs base with cmake variable (#3066) +- aot_reloc_x86_64.c: Suggest to try --size-level=0 as well (#3067) +- Fix some issues reported by CodeQL (#3064) +- Remove a lot of "unused parameter" warnings (#3075) +- Forward log and log level to custom bh_log callback (#3070) +- Fix inconsistent code style in aot_loader.c (#3082) +- freertos: Thread exit more common (#3094) +- Fix windows build error and compilation warnings (#3095) + +### Others +- Fix nightly-run CI failure (#3014) +- Build samples in debug mode (#3019) +- Remove deprecated tests in language-bindings python (#3018) +- Avoid unused thread_id warning and recompile multi-module sample (#3033) +- samples/terminate: Add a sample to demonstrate wasm_runtime_terminate (#3043) +- Bump NuttX version to 12.4.x in CI (#3047) +- perf_tune.md: Add refine the calling processes between host and wasm (#3065) +- build_wamr.md: Update the document (#3074) +- Fix download link for wasi-sdk (#3077) +- README.md: Fix typo tunning to tuning (#3078) +- Update outdated reference link in multi_module.md (#3092) +- Add comments to suppress warning from clang-tidy (#3088) +- CI: Update version of checkout to suppress warnings (#3093) +- test_wamr.sh: Allow using test script on different platforms (#3098) + +--- + ## WAMR-1.3.1 ### Breaking Changes diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 873dc3b3f..a9fac87ba 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -1934,8 +1934,8 @@ wasm_frame_vec_clone_internal(Vector *src, Vector *out) return; } - bh_memcpy_s(out->data, src->num_elems * sizeof(WASMCApiFrame), src->data, - src->num_elems * sizeof(WASMCApiFrame)); + bh_memcpy_s(out->data, (uint32)(src->num_elems * sizeof(WASMCApiFrame)), + src->data, (uint32)(src->num_elems * sizeof(WASMCApiFrame))); out->num_elems = src->num_elems; } @@ -2962,8 +2962,10 @@ wasm_func_new_basic(wasm_store_t *store, const wasm_functype_t *type, if (!(func->type = wasm_functype_copy(type))) { goto failed; } - func->param_count = func->type->params->num_elems; - func->result_count = func->type->results->num_elems; + /* func type's param_count and result_count were checked in + loader and are no larger than UINT16_MAX */ + func->param_count = (uint16)func->type->params->num_elems; + func->result_count = (uint16)func->type->results->num_elems; RETURN_OBJ(func, wasm_func_delete) } @@ -2994,8 +2996,10 @@ wasm_func_new_with_env_basic(wasm_store_t *store, const wasm_functype_t *type, if (!(func->type = wasm_functype_copy(type))) { goto failed; } - func->param_count = func->type->params->num_elems; - func->result_count = func->type->results->num_elems; + /* func type's param_count and result_count were checked in + loader and are no larger than UINT16_MAX */ + func->param_count = (uint16)func->type->params->num_elems; + func->result_count = (uint16)func->type->results->num_elems; RETURN_OBJ(func, wasm_func_delete) } @@ -3085,8 +3089,10 @@ wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt, if (!func->type) { goto failed; } - func->param_count = func->type->params->num_elems; - func->result_count = func->type->results->num_elems; + /* func type's param_count and result_count were checked in + loader and are no larger than UINT16_MAX */ + func->param_count = (uint16)func->type->params->num_elems; + func->result_count = (uint16)func->type->results->num_elems; /* will add name information when processing "exports" */ func->store = store; diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 464ca61f3..fada0abc8 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -1050,7 +1050,9 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) uint32 opcode1; read_leb_uint32(frame_ip, frame_ip_end, opcode1); - opcode = (uint32)opcode1; + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ + opcode = (uint8)opcode1; #if WASM_ENABLE_BULK_MEMORY != 0 if (WASM_OP_MEMORY_INIT <= opcode @@ -1211,10 +1213,13 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) case WASM_OP_ATOMIC_PREFIX: { uint8 bin_op, op_type; + uint32 opcode1; + + read_leb_uint32(frame_ip, frame_ip_end, opcode1); + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ + opcode = (uint8)opcode1; - if (frame_ip < frame_ip_end) { - opcode = *frame_ip++; - } if (opcode != WASM_OP_ATOMIC_FENCE) { read_leb_uint32(frame_ip, frame_ip_end, align); read_leb_uint32(frame_ip, frame_ip_end, offset); @@ -1364,11 +1369,17 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) #if WASM_ENABLE_SIMD != 0 case WASM_OP_SIMD_PREFIX: { + uint32 opcode1; + if (!comp_ctx->enable_simd) { goto unsupport_simd; } - opcode = *frame_ip++; + read_leb_uint32(frame_ip, frame_ip_end, opcode1); + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ + opcode = (uint8)opcode1; + /* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h */ switch (opcode) { diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 6f5cddcd9..028faf6e4 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -533,18 +533,12 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module, } wasm_runtime_free(params); params = NULL; - -#if LLVM_VERSION_MAJOR < 17 if (aot_target_precheck_can_use_musttail(comp_ctx)) { LLVMSetTailCallKind(retval, LLVMTailCallKindMustTail); } else { LLVMSetTailCallKind(retval, LLVMTailCallKindTail); } -#else - LLVMSetTailCall(retval, true); -#endif - if (ret_type == VOID_TYPE) { if (!LLVMBuildRetVoid(b)) { goto fail; diff --git a/core/iwasm/compilation/aot_llvm_extra2.cpp b/core/iwasm/compilation/aot_llvm_extra2.cpp index 42d9c4bee..ccbccd1e0 100644 --- a/core/iwasm/compilation/aot_llvm_extra2.cpp +++ b/core/iwasm/compilation/aot_llvm_extra2.cpp @@ -163,7 +163,7 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple, } /* https://reviews.llvm.org/D153107 */ -#if LLVM_VERSION_MAJOR < 17 +#if LLVM_VERSION_MAJOR < 18 using namespace llvm; LLVMTailCallKind diff --git a/core/iwasm/compilation/aot_llvm_extra2.h b/core/iwasm/compilation/aot_llvm_extra2.h index f3f897994..be89faae0 100644 --- a/core/iwasm/compilation/aot_llvm_extra2.h +++ b/core/iwasm/compilation/aot_llvm_extra2.h @@ -17,7 +17,7 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple, const char *StackUsageOutput); /* https://reviews.llvm.org/D153107 */ -#if LLVM_VERSION_MAJOR < 17 +#if LLVM_VERSION_MAJOR < 18 typedef enum { LLVMTailCallKindNone = 0, LLVMTailCallKindTail = 1, diff --git a/core/iwasm/fast-jit/jit_frontend.c b/core/iwasm/fast-jit/jit_frontend.c index e0b204ce9..e9d7a3ff3 100644 --- a/core/iwasm/fast-jit/jit_frontend.c +++ b/core/iwasm/fast-jit/jit_frontend.c @@ -2257,7 +2257,9 @@ jit_compile_func(JitCompContext *cc) uint32 opcode1; read_leb_uint32(frame_ip, frame_ip_end, opcode1); - opcode = (uint32)opcode1; + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ + opcode = (uint8)opcode1; switch (opcode) { case WASM_OP_I32_TRUNC_SAT_S_F32: @@ -2396,10 +2398,13 @@ jit_compile_func(JitCompContext *cc) case WASM_OP_ATOMIC_PREFIX: { uint8 bin_op, op_type; + uint32 opcode1; + + read_leb_uint32(frame_ip, frame_ip_end, opcode1); + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ + opcode = (uint8)opcode1; - if (frame_ip < frame_ip_end) { - opcode = *frame_ip++; - } if (opcode != WASM_OP_ATOMIC_FENCE) { read_leb_uint32(frame_ip, frame_ip_end, align); read_leb_uint32(frame_ip, frame_ip_end, offset); diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 10de23742..e4da90b9c 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1387,18 +1387,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, /* push exception_tag_index and * exception values for rethrow */ PUSH_I32(exception_tag_index); - word_copy(frame_sp, - frame_sp_old - - cell_num_to_copy, - cell_num_to_copy); - frame_sp += cell_num_to_copy; - /* push exception values for catch - */ - word_copy(frame_sp, - frame_sp_old - - cell_num_to_copy, - cell_num_to_copy); - frame_sp += cell_num_to_copy; + if (cell_num_to_copy > 0) { + word_copy( + frame_sp, + frame_sp_old + - cell_num_to_copy, + cell_num_to_copy); + frame_sp += cell_num_to_copy; + /* push exception values for + * catch + */ + word_copy( + frame_sp, + frame_sp_old + - cell_num_to_copy, + cell_num_to_copy); + frame_sp += cell_num_to_copy; + } /* advance to handler */ HANDLE_OP_END(); @@ -1427,11 +1432,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, frame_csp -= lookup_depth; /* push exception values for catch */ - word_copy(frame_sp, - frame_sp_old - - cell_num_to_copy, - cell_num_to_copy); - frame_sp += cell_num_to_copy; + if (cell_num_to_copy > 0) { + word_copy(frame_sp, + frame_sp_old + - cell_num_to_copy, + cell_num_to_copy); + frame_sp += cell_num_to_copy; + } /* tag_index is already stored in * exception_tag_index */ @@ -1452,11 +1459,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, /* push exception_tag_index and * exception values for rethrow */ PUSH_I32(exception_tag_index); - word_copy(frame_sp, - frame_sp_old - - cell_num_to_copy, - cell_num_to_copy); - frame_sp += cell_num_to_copy; + if (cell_num_to_copy > 0) { + word_copy(frame_sp, + frame_sp_old + - cell_num_to_copy, + cell_num_to_copy); + frame_sp += cell_num_to_copy; + } /* catch_all has no exception values */ /* advance to handler */ @@ -1483,10 +1492,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, * The values are copied to the CALLER FRAME * (prev_frame->sp) same behvior ad WASM_OP_RETURN */ - word_copy(prev_frame->sp, - frame_sp_old - cell_num_to_copy, - cell_num_to_copy); - prev_frame->sp += cell_num_to_copy; + if (cell_num_to_copy > 0) { + word_copy(prev_frame->sp, + frame_sp_old - cell_num_to_copy, + cell_num_to_copy); + prev_frame->sp += cell_num_to_copy; + } *((int32 *)(prev_frame->sp)) = exception_tag_index; prev_frame->sp++; @@ -3500,6 +3511,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint32 opcode1; read_leb_uint32(frame_ip, frame_ip_end, opcode1); + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ opcode = (uint8)opcode1; switch (opcode) { @@ -3832,8 +3845,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP(WASM_OP_ATOMIC_PREFIX) { uint32 offset = 0, align, addr; + uint32 opcode1; - opcode = *frame_ip++; + read_leb_uint32(frame_ip, frame_ip_end, opcode1); + /* opcode1 was checked in loader and is no larger than + UINT8_MAX */ + opcode = (uint8)opcode1; if (opcode != WASM_OP_ATOMIC_FENCE) { read_leb_uint32(frame_ip, frame_ip_end, align); diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 11417fa19..8ca3796bc 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -4679,6 +4679,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, return true; } else { + skip_leb(p); /* the DELEGATE opcode ends the tryblock, */ block_nested_depth--; if (block_nested_depth @@ -5091,9 +5092,13 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, #if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0) case WASM_OP_SIMD_PREFIX: { - /* TODO: shall we ceate a table to be friendly to branch - * prediction */ - opcode = read_uint8(p); + uint32 opcode1; + + read_leb_uint32(p, p_end, opcode1); + /* opcode1 was checked in wasm_loader_prepare_bytecode and + is no larger than UINT8_MAX */ + opcode = (uint8)opcode1; + /* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h */ switch (opcode) { @@ -5183,8 +5188,14 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, #if WASM_ENABLE_SHARED_MEMORY != 0 case WASM_OP_ATOMIC_PREFIX: { - /* atomic_op (1 u8) + memarg (2 u32_leb) */ - opcode = read_uint8(p); + uint32 opcode1; + + /* atomic_op (u32_leb) + memarg (2 u32_leb) */ + read_leb_uint32(p, p_end, opcode1); + /* opcode1 was checked in wasm_loader_prepare_bytecode and + is no larger than UINT8_MAX */ + opcode = (uint8)opcode1; + if (opcode != WASM_OP_ATOMIC_FENCE) { skip_leb_uint32(p, p_end); /* align */ skip_leb_uint32(p, p_end); /* offset */ @@ -5279,9 +5290,8 @@ typedef struct BranchBlock { BranchBlockPatch *patch_list; /* This is used to save params frame_offset of of if block */ int16 *param_frame_offsets; - /* This is used to store available param num for if/else branch, so the else - * opcode can know how many parameters should be copied to the stack */ - uint32 available_param_num; + /* This is used to recover dynamic offset for else branch */ + uint16 start_dynamic_offset; #endif /* Indicate the operand stack is in polymorphic state. @@ -7128,6 +7138,40 @@ fail: return NULL; } +#if WASM_ENABLE_EXCE_HANDLING != 0 +static BranchBlock * +check_branch_block_for_delegate(WASMLoaderContext *loader_ctx, uint8 **p_buf, + uint8 *buf_end, char *error_buf, + uint32 error_buf_size) +{ + uint8 *p = *p_buf, *p_end = buf_end; + BranchBlock *frame_csp_tmp; + uint32 depth; + + read_leb_uint32(p, p_end, depth); + /* + * Note: "delegate 0" means the surrounding block, not the + * try-delegate block itself. + * + * Note: the caller hasn't popped the try-delegate frame yet. + */ + bh_assert(loader_ctx->csp_num > 0); + if (loader_ctx->csp_num - 1 <= depth) { + set_error_buf(error_buf, error_buf_size, "unknown delegate label"); + goto fail; + } + frame_csp_tmp = loader_ctx->frame_csp - depth - 2; +#if WASM_ENABLE_FAST_INTERP != 0 + emit_br_info(frame_csp_tmp); +#endif + + *p_buf = p; + return frame_csp_tmp; +fail: + return NULL; +} +#endif + static bool check_block_stack(WASMLoaderContext *loader_ctx, BranchBlock *block, char *error_buf, uint32 error_buf_size) @@ -7218,18 +7262,15 @@ fail: * 1) POP original parameter out; * 2) Push and copy original values to dynamic space. * The copy instruction format: - * Part a: available param count + * Part a: param count * Part b: all param total cell num * Part c: each param's cell_num, src offset and dst offset * Part d: each param's src offset * Part e: each param's dst offset - * Note: if the stack is in polymorphic state, the actual copied parameters may - * be fewer than the defined number in block type */ static bool copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block, - uint32 *p_available_param_count, char *error_buf, - uint32 error_buf_size) + char *error_buf, uint32 error_buf_size) { bool ret = false; int16 *frame_offset = NULL; @@ -7241,91 +7282,72 @@ copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block, BlockType *block_type = &block->block_type; WASMType *wasm_type = block_type->u.type; uint32 param_count = block_type->u.type->param_count; - uint32 available_param_count = 0; int16 condition_offset = 0; bool disable_emit = false; int16 operand_offset = 0; - uint64 size; - if (is_if_block) - condition_offset = *loader_ctx->frame_offset; - - /* POP original parameter out */ - for (i = 0; i < param_count; i++) { - int32 available_stack_cell = - (int32)(loader_ctx->stack_cell_num - block->stack_cell_num); - - if (available_stack_cell <= 0 && block->is_stack_polymorphic) - break; - - POP_OFFSET_TYPE(wasm_type->types[param_count - i - 1]); - wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); - } - available_param_count = i; - - size = - (uint64)available_param_count * (sizeof(*cells) + sizeof(*src_offsets)); + uint64 size = (uint64)param_count * (sizeof(*cells) + sizeof(*src_offsets)); + bh_assert(size > 0); /* For if block, we also need copy the condition operand offset. */ if (is_if_block) size += sizeof(*cells) + sizeof(*src_offsets); /* Allocate memory for the emit data */ - if ((size > 0) - && !(emit_data = loader_malloc(size, error_buf, error_buf_size))) + if (!(emit_data = loader_malloc(size, error_buf, error_buf_size))) return false; cells = emit_data; src_offsets = (int16 *)(cells + param_count); + if (is_if_block) + condition_offset = *loader_ctx->frame_offset; + + /* POP original parameter out */ + for (i = 0; i < param_count; i++) { + POP_OFFSET_TYPE(wasm_type->types[param_count - i - 1]); + wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); + } frame_offset = loader_ctx->frame_offset; /* Get each param's cell num and src offset */ - for (i = 0; i < available_param_count; i++) { + for (i = 0; i < param_count; i++) { cell = (uint8)wasm_value_type_cell_num(wasm_type->types[i]); cells[i] = cell; src_offsets[i] = *frame_offset; frame_offset += cell; } - /* emit copy instruction */ emit_label(EXT_OP_COPY_STACK_VALUES); /* Part a) */ - emit_uint32(loader_ctx, is_if_block ? available_param_count + 1 - : available_param_count); + emit_uint32(loader_ctx, is_if_block ? param_count + 1 : param_count); /* Part b) */ emit_uint32(loader_ctx, is_if_block ? wasm_type->param_cell_num + 1 : wasm_type->param_cell_num); /* Part c) */ - for (i = 0; i < available_param_count; i++) + for (i = 0; i < param_count; i++) emit_byte(loader_ctx, cells[i]); if (is_if_block) emit_byte(loader_ctx, 1); /* Part d) */ - for (i = 0; i < available_param_count; i++) + for (i = 0; i < param_count; i++) emit_operand(loader_ctx, src_offsets[i]); if (is_if_block) emit_operand(loader_ctx, condition_offset); /* Part e) */ /* Push to dynamic space. The push will emit the dst offset. */ - for (i = 0; i < available_param_count; i++) + for (i = 0; i < param_count; i++) PUSH_OFFSET_TYPE(wasm_type->types[i]); if (is_if_block) PUSH_OFFSET_TYPE(VALUE_TYPE_I32); - if (p_available_param_count) { - *p_available_param_count = available_param_count; - } - ret = true; fail: /* Free the emit data */ - if (emit_data) { - wasm_runtime_free(emit_data); - } + wasm_runtime_free(emit_data); return ret; } @@ -7615,6 +7637,7 @@ re_scan: BranchBlock *cur_block = loader_ctx->frame_csp - 1; #if WASM_ENABLE_FAST_INTERP != 0 + uint32 cell_num; available_params = block_type.u.type->param_count; #endif for (i = 0; i < block_type.u.type->param_count; i++) { @@ -7632,6 +7655,13 @@ re_scan: POP_TYPE( wasm_type->types[wasm_type->param_count - i - 1]); +#if WASM_ENABLE_FAST_INTERP != 0 + /* decrease the frame_offset pointer accordingly to keep + * consistent with frame_ref stack */ + cell_num = wasm_value_type_cell_num( + wasm_type->types[wasm_type->param_count - i - 1]); + loader_ctx->frame_offset -= cell_num; +#endif } } PUSH_CSP(LABEL_TYPE_BLOCK + (opcode - WASM_OP_BLOCK), @@ -7640,12 +7670,26 @@ re_scan: /* Pass parameters to block */ if (BLOCK_HAS_PARAM(block_type)) { for (i = 0; i < block_type.u.type->param_count; i++) { - PUSH_TYPE(block_type.u.type->types[i]); #if WASM_ENABLE_FAST_INTERP != 0 + uint32 cell_num = wasm_value_type_cell_num( + block_type.u.type->types[i]); if (i >= available_params) { - PUSH_OFFSET_TYPE(block_type.u.type->types[i]); + /* If there isn't enough data on stack, push a dummy + * offset to keep the stack consistent with + * frame_ref. + * Since the stack is already in polymorphic state, + * the opcode will not be executed, so the dummy + * offset won't cause any error */ + *loader_ctx->frame_offset++ = 0; + if (cell_num > 1) { + *loader_ctx->frame_offset++ = 0; + } + } + else { + loader_ctx->frame_offset += cell_num; } #endif + PUSH_TYPE(block_type.u.type->types[i]); } } @@ -7655,9 +7699,8 @@ re_scan: if (BLOCK_HAS_PARAM(block_type)) { /* Make sure params are in dynamic space */ - if (!copy_params_to_dynamic_space(loader_ctx, false, - NULL, error_buf, - error_buf_size)) + if (!copy_params_to_dynamic_space( + loader_ctx, false, error_buf, error_buf_size)) goto fail; } @@ -7690,17 +7733,21 @@ re_scan: * recover them before entering else branch. * */ - if (if_condition_available && BLOCK_HAS_PARAM(block_type)) { + if (BLOCK_HAS_PARAM(block_type)) { uint64 size; - /* skip the if condition operand offset */ - wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); + /* In polymorphic state, there may be no if condition on + * the stack, so the offset may not emitted */ + if (if_condition_available) { + /* skip the if condition operand offset */ + wasm_loader_emit_backspace(loader_ctx, + sizeof(int16)); + } /* skip the if label */ skip_label(); /* Emit a copy instruction */ if (!copy_params_to_dynamic_space( - loader_ctx, true, &block->available_param_num, - error_buf, error_buf_size)) + loader_ctx, true, error_buf, error_buf_size)) goto fail; /* Emit the if instruction */ @@ -7721,9 +7768,8 @@ re_scan: - size / sizeof(int16), (uint32)size); } - else { - block->available_param_num = 0; - } + + block->start_dynamic_offset = loader_ctx->dynamic_offset; emit_empty_label_addr_and_frame_ip(PATCH_ELSE); emit_empty_label_addr_and_frame_ip(PATCH_END); @@ -7830,16 +7876,10 @@ re_scan: case WASM_OP_DELEGATE: { /* check target block is valid */ - if (!(frame_csp_tmp = check_branch_block( + if (!(frame_csp_tmp = check_branch_block_for_delegate( loader_ctx, &p, p_end, error_buf, error_buf_size))) goto fail; - /* valid types */ - if (LABEL_TYPE_TRY != frame_csp_tmp->label_type) { - snprintf(error_buf, error_buf_size, "unknown label"); - goto fail; - } - BranchBlock *cur_block = loader_ctx->frame_csp - 1; uint8 label_type = cur_block->label_type; @@ -7979,21 +8019,13 @@ re_scan: #if WASM_ENABLE_FAST_INTERP != 0 /* Recover top param_count values of frame_offset stack */ - if (block->available_param_num) { + if (BLOCK_HAS_PARAM((block_type))) { uint32 size; - size = sizeof(int16) * block->available_param_num; + size = sizeof(int16) * block_type.u.type->param_cell_num; bh_memcpy_s(loader_ctx->frame_offset, size, block->param_frame_offsets, size); loader_ctx->frame_offset += (size / sizeof(int16)); - - /* recover dynamic offset */ - for (i = 0; i < block->available_param_num; i++) { - if (block->param_frame_offsets[i] - >= loader_ctx->dynamic_offset) { - loader_ctx->dynamic_offset = - block->param_frame_offsets[i] + 1; - } - } + loader_ctx->dynamic_offset = block->start_dynamic_offset; } #endif @@ -8222,11 +8254,11 @@ re_scan: idx--) { ret_type = *(func->func_type->types + func->func_type->param_count + idx); - POP_TYPE(ret_type); #if WASM_ENABLE_FAST_INTERP != 0 /* emit the offset after return opcode */ POP_OFFSET_TYPE(ret_type); #endif + POP_TYPE(ret_type); } RESET_STACK(); @@ -8266,10 +8298,10 @@ re_scan: if (func_type->param_count > 0) { for (idx = (int32)(func_type->param_count - 1); idx >= 0; idx--) { - POP_TYPE(func_type->types[idx]); #if WASM_ENABLE_FAST_INTERP != 0 POP_OFFSET_TYPE(func_type->types[idx]); #endif + POP_TYPE(func_type->types[idx]); } } @@ -8367,10 +8399,10 @@ re_scan: if (func_type->param_count > 0) { for (idx = (int32)(func_type->param_count - 1); idx >= 0; idx--) { - POP_TYPE(func_type->types[idx]); #if WASM_ENABLE_FAST_INTERP != 0 POP_OFFSET_TYPE(func_type->types[idx]); #endif + POP_TYPE(func_type->types[idx]); } } @@ -9814,8 +9846,8 @@ re_scan: { uint32 opcode1; - CHECK_BUF(p, p_end, 1); - opcode1 = read_uint8(p); + read_leb_uint32(p, p_end, opcode1); + /* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h */ switch (opcode1) { @@ -10476,8 +10508,8 @@ re_scan: { uint32 opcode1; - CHECK_BUF(p, p_end, 1); - opcode1 = read_uint8(p); + read_leb_uint32(p, p_end, opcode1); + #if WASM_ENABLE_FAST_INTERP != 0 emit_byte(loader_ctx, opcode1); #endif diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 3abf4a96e..ba2c37fc7 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -3492,8 +3492,11 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, uint32 opcode1; read_leb_uint32(p, p_end, opcode1); + /* opcode1 was checked in wasm_loader_prepare_bytecode and + is no larger than UINT8_MAX */ + opcode = (uint8)opcode1; - switch (opcode1) { + switch (opcode) { case WASM_OP_I32_TRUNC_SAT_S_F32: case WASM_OP_I32_TRUNC_SAT_U_F32: case WASM_OP_I32_TRUNC_SAT_S_F64: @@ -3549,8 +3552,14 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, #if WASM_ENABLE_SHARED_MEMORY != 0 case WASM_OP_ATOMIC_PREFIX: { - /* atomic_op (1 u8) + memarg (2 u32_leb) */ - opcode = read_uint8(p); + uint32 opcode1; + + /* atomic_op (u32_leb) + memarg (2 u32_leb) */ + read_leb_uint32(p, p_end, opcode1); + /* opcode1 was checked in wasm_loader_prepare_bytecode and + is no larger than UINT8_MAX */ + opcode = (uint8)opcode1; + if (opcode != WASM_OP_ATOMIC_FENCE) { skip_leb_uint32(p, p_end); /* align */ skip_leb_uint32(p, p_end); /* offset */ @@ -3614,6 +3623,8 @@ typedef struct BranchBlock { /* This is used to store available param num for if/else branch, so the else * opcode can know how many parameters should be copied to the stack */ uint32 available_param_num; + /* This is used to recover dynamic offset for else branch */ + uint16 start_dynamic_offset; #endif /* Indicate the operand stack is in polymorphic state. @@ -5363,18 +5374,15 @@ fail: * 1) POP original parameter out; * 2) Push and copy original values to dynamic space. * The copy instruction format: - * Part a: available param count + * Part a: param count * Part b: all param total cell num * Part c: each param's cell_num, src offset and dst offset * Part d: each param's src offset * Part e: each param's dst offset - * Note: if the stack is in polymorphic state, the actual copied parameters may - * be fewer than the defined number in block type */ static bool copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block, - uint32 *p_available_param_count, char *error_buf, - uint32 error_buf_size) + char *error_buf, uint32 error_buf_size) { bool ret = false; int16 *frame_offset = NULL; @@ -5386,91 +5394,72 @@ copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block, BlockType *block_type = &block->block_type; WASMType *wasm_type = block_type->u.type; uint32 param_count = block_type->u.type->param_count; - uint32 available_param_count = 0; int16 condition_offset = 0; bool disable_emit = false; int16 operand_offset = 0; - uint64 size; - if (is_if_block) - condition_offset = *loader_ctx->frame_offset; - - /* POP original parameter out */ - for (i = 0; i < param_count; i++) { - int32 available_stack_cell = - (int32)(loader_ctx->stack_cell_num - block->stack_cell_num); - - if (available_stack_cell <= 0 && block->is_stack_polymorphic) - break; - - POP_OFFSET_TYPE(wasm_type->types[param_count - i - 1]); - wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); - } - available_param_count = i; - - size = - (uint64)available_param_count * (sizeof(*cells) + sizeof(*src_offsets)); + uint64 size = (uint64)param_count * (sizeof(*cells) + sizeof(*src_offsets)); + bh_assert(size > 0); /* For if block, we also need copy the condition operand offset. */ if (is_if_block) size += sizeof(*cells) + sizeof(*src_offsets); /* Allocate memory for the emit data */ - if ((size > 0) - && !(emit_data = loader_malloc(size, error_buf, error_buf_size))) + if (!(emit_data = loader_malloc(size, error_buf, error_buf_size))) return false; cells = emit_data; src_offsets = (int16 *)(cells + param_count); + if (is_if_block) + condition_offset = *loader_ctx->frame_offset; + + /* POP original parameter out */ + for (i = 0; i < param_count; i++) { + POP_OFFSET_TYPE(wasm_type->types[param_count - i - 1]); + wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); + } frame_offset = loader_ctx->frame_offset; /* Get each param's cell num and src offset */ - for (i = 0; i < available_param_count; i++) { + for (i = 0; i < param_count; i++) { cell = (uint8)wasm_value_type_cell_num(wasm_type->types[i]); cells[i] = cell; src_offsets[i] = *frame_offset; frame_offset += cell; } - /* emit copy instruction */ emit_label(EXT_OP_COPY_STACK_VALUES); /* Part a) */ - emit_uint32(loader_ctx, is_if_block ? available_param_count + 1 - : available_param_count); + emit_uint32(loader_ctx, is_if_block ? param_count + 1 : param_count); /* Part b) */ emit_uint32(loader_ctx, is_if_block ? wasm_type->param_cell_num + 1 : wasm_type->param_cell_num); /* Part c) */ - for (i = 0; i < available_param_count; i++) + for (i = 0; i < param_count; i++) emit_byte(loader_ctx, cells[i]); if (is_if_block) emit_byte(loader_ctx, 1); /* Part d) */ - for (i = 0; i < available_param_count; i++) + for (i = 0; i < param_count; i++) emit_operand(loader_ctx, src_offsets[i]); if (is_if_block) emit_operand(loader_ctx, condition_offset); /* Part e) */ /* Push to dynamic space. The push will emit the dst offset. */ - for (i = 0; i < available_param_count; i++) + for (i = 0; i < param_count; i++) PUSH_OFFSET_TYPE(wasm_type->types[i]); if (is_if_block) PUSH_OFFSET_TYPE(VALUE_TYPE_I32); - if (p_available_param_count) { - *p_available_param_count = available_param_count; - } - ret = true; fail: /* Free the emit data */ - if (emit_data) { - wasm_runtime_free(emit_data); - } + wasm_runtime_free(emit_data); return ret; } @@ -5672,6 +5661,7 @@ re_scan: BranchBlock *cur_block = loader_ctx->frame_csp - 1; #if WASM_ENABLE_FAST_INTERP != 0 + uint32 cell_num; available_params = block_type.u.type->param_count; #endif for (i = 0; i < block_type.u.type->param_count; i++) { @@ -5689,6 +5679,13 @@ re_scan: POP_TYPE( wasm_type->types[wasm_type->param_count - i - 1]); +#if WASM_ENABLE_FAST_INTERP != 0 + /* decrease the frame_offset pointer accordingly to keep + * consistent with frame_ref stack */ + cell_num = wasm_value_type_cell_num( + wasm_type->types[wasm_type->param_count - i - 1]); + loader_ctx->frame_offset -= cell_num; +#endif } } @@ -5698,12 +5695,26 @@ re_scan: /* Pass parameters to block */ if (BLOCK_HAS_PARAM(block_type)) { for (i = 0; i < block_type.u.type->param_count; i++) { - PUSH_TYPE(block_type.u.type->types[i]); #if WASM_ENABLE_FAST_INTERP != 0 + uint32 cell_num = wasm_value_type_cell_num( + block_type.u.type->types[i]); if (i >= available_params) { - PUSH_OFFSET_TYPE(block_type.u.type->types[i]); + /* If there isn't enough data on stack, push a dummy + * offset to keep the stack consistent with + * frame_ref. + * Since the stack is already in polymorphic state, + * the opcode will not be executed, so the dummy + * offset won't cause any error */ + *loader_ctx->frame_offset++ = 0; + if (cell_num > 1) { + *loader_ctx->frame_offset++ = 0; + } + } + else { + loader_ctx->frame_offset += cell_num; } #endif + PUSH_TYPE(block_type.u.type->types[i]); } } @@ -5712,9 +5723,8 @@ re_scan: skip_label(); if (BLOCK_HAS_PARAM(block_type)) { /* Make sure params are in dynamic space */ - if (!copy_params_to_dynamic_space(loader_ctx, false, - NULL, error_buf, - error_buf_size)) + if (!copy_params_to_dynamic_space( + loader_ctx, false, error_buf, error_buf_size)) goto fail; } if (opcode == WASM_OP_LOOP) { @@ -5741,17 +5751,21 @@ re_scan: * recover them before entering else branch. * */ - if (if_condition_available && BLOCK_HAS_PARAM(block_type)) { + if (BLOCK_HAS_PARAM(block_type)) { uint64 size; - /* skip the if condition operand offset */ - wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); + /* In polymorphic state, there may be no if condition on + * the stack, so the offset may not emitted */ + if (if_condition_available) { + /* skip the if condition operand offset */ + wasm_loader_emit_backspace(loader_ctx, + sizeof(int16)); + } /* skip the if label */ skip_label(); /* Emit a copy instruction */ if (!copy_params_to_dynamic_space( - loader_ctx, true, &block->available_param_num, - error_buf, error_buf_size)) + loader_ctx, true, error_buf, error_buf_size)) goto fail; /* Emit the if instruction */ @@ -5772,9 +5786,8 @@ re_scan: - size / sizeof(int16), (uint32)size); } - else { - block->available_param_num = 0; - } + + block->start_dynamic_offset = loader_ctx->dynamic_offset; emit_empty_label_addr_and_frame_ip(PATCH_ELSE); emit_empty_label_addr_and_frame_ip(PATCH_END); @@ -5818,21 +5831,13 @@ re_scan: #if WASM_ENABLE_FAST_INTERP != 0 /* Recover top param_count values of frame_offset stack */ - if (block->available_param_num) { + if (BLOCK_HAS_PARAM((block_type))) { uint32 size; - size = sizeof(int16) * block->available_param_num; + size = sizeof(int16) * block_type.u.type->param_cell_num; bh_memcpy_s(loader_ctx->frame_offset, size, block->param_frame_offsets, size); loader_ctx->frame_offset += (size / sizeof(int16)); - - /* recover dynamic offset */ - for (i = 0; i < block->available_param_num; i++) { - if (block->param_frame_offsets[i] - >= loader_ctx->dynamic_offset) { - loader_ctx->dynamic_offset = - block->param_frame_offsets[i] + 1; - } - } + loader_ctx->dynamic_offset = block->start_dynamic_offset; } #endif @@ -6019,11 +6024,11 @@ re_scan: idx--) { ret_type = *(func->func_type->types + func->func_type->param_count + idx); - POP_TYPE(ret_type); #if WASM_ENABLE_FAST_INTERP != 0 /* emit the offset after return opcode */ POP_OFFSET_TYPE(ret_type); #endif + POP_TYPE(ret_type); } RESET_STACK(); @@ -6062,10 +6067,10 @@ re_scan: if (func_type->param_count > 0) { for (idx = (int32)(func_type->param_count - 1); idx >= 0; idx--) { - POP_TYPE(func_type->types[idx]); #if WASM_ENABLE_FAST_INTERP != 0 POP_OFFSET_TYPE(func_type->types[idx]); #endif + POP_TYPE(func_type->types[idx]); } } @@ -6143,10 +6148,10 @@ re_scan: if (func_type->param_count > 0) { for (idx = (int32)(func_type->param_count - 1); idx >= 0; idx--) { - POP_TYPE(func_type->types[idx]); #if WASM_ENABLE_FAST_INTERP != 0 POP_OFFSET_TYPE(func_type->types[idx]); #endif + POP_TYPE(func_type->types[idx]); } } @@ -7468,11 +7473,14 @@ re_scan: #if WASM_ENABLE_SHARED_MEMORY != 0 case WASM_OP_ATOMIC_PREFIX: { - opcode = read_uint8(p); + uint32 opcode1; + + read_leb_uint32(p, p_end, opcode1); + #if WASM_ENABLE_FAST_INTERP != 0 - emit_byte(loader_ctx, opcode); + emit_byte(loader_ctx, opcode1); #endif - if (opcode != WASM_OP_ATOMIC_FENCE) { + if (opcode1 != WASM_OP_ATOMIC_FENCE) { CHECK_MEMORY(); read_leb_uint32(p, p_end, align); /* align */ read_leb_uint32(p, p_end, mem_offset); /* offset */ @@ -7483,7 +7491,7 @@ re_scan: #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 func->has_memory_operations = true; #endif - switch (opcode) { + switch (opcode1) { case WASM_OP_ATOMIC_NOTIFY: POP2_AND_PUSH(VALUE_TYPE_I32, VALUE_TYPE_I32); break; diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 44ef3db03..003ceb1f5 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1061,7 +1061,7 @@ export_tags_instantiate(const WASMModule *module, if (export->kind == EXPORT_KIND_TAG) { export_tag->name = export->name; - bh_assert((uint32)(module_inst->export_tags)); + bh_assert(module_inst->e->tags); export_tag->tag = &module_inst->e->tags[export->index]; export_tag++; diff --git a/core/shared/platform/common/posix/posix_memmap.c b/core/shared/platform/common/posix/posix_memmap.c index aeb4530ab..2baf5aeb7 100644 --- a/core/shared/platform/common/posix/posix_memmap.c +++ b/core/shared/platform/common/posix/posix_memmap.c @@ -7,6 +7,7 @@ #if defined(__APPLE__) || defined(__MACH__) #include +#include #endif #ifndef BH_ENABLE_TRACE_MMAP diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index b5d8035df..1195d80eb 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -9,6 +9,10 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" +#if defined(__APPLE__) || defined(__MACH__) +#include +#endif + typedef struct { thread_start_routine_t start; void *arg; diff --git a/core/version.h b/core/version.h index ec41ecd65..8f9f757a6 100644 --- a/core/version.h +++ b/core/version.h @@ -7,5 +7,5 @@ #define _WAMR_VERSION_H_ #define WAMR_VERSION_MAJOR 1 #define WAMR_VERSION_MINOR 3 -#define WAMR_VERSION_PATCH 1 +#define WAMR_VERSION_PATCH 2 #endif diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 3a16b3013..7f41fc43d 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -121,7 +121,7 @@ do ;; m) echo "set compile target of wamr" ${OPTARG} - TARGET=${OPTARG^^} # set target to uppercase if input x86_32 or x86_64 --> X86_32 and X86_64 + TARGET=$(echo "$OPTARG" | tr '[a-z]' '[A-Z]') # set target to uppercase if input x86_32 or x86_64 --> X86_32 and X86_64 ;; w) echo "enable WASI threads" diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index f7617fed9..84e8b524c 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -59,30 +59,31 @@ if (DEFINED WAMR_BUILD_AOT_FUNC_PREFIX) endif () if (NOT WAMR_BUILD_TARGET) - if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" HOST_SYSTEM_PROCESSOR) + if (${HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64") set (WAMR_BUILD_TARGET "X86_64") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "i686") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "i686") set (WAMR_BUILD_TARGET "X86_32") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "amd64") set (WAMR_BUILD_TARGET "AMD_64") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" - OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64" + OR ${HOST_SYSTEM_PROCESSOR} STREQUAL "arm64") set (WAMR_BUILD_TARGET "AARCH64") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm.*") + elseif (${HOST_SYSTEM_PROCESSOR} MATCHES "arm.*") message(STATUS "Assuming ${CMAKE_HOST_SYSTEM_PROCESSOR} as ARM_32") set (WAMR_BUILD_TARGET "ARM_32") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "mips") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "mips") set (WAMR_BUILD_TARGET "MIPS_32") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "xtensa") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "xtensa") set (WAMR_BUILD_TARGET "XTENSA_32") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv64") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "riscv64") set (WAMR_BUILD_TARGET "RISCV64") - elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv") + elseif (${HOST_SYSTEM_PROCESSOR} STREQUAL "riscv") message(STATUS "Assuming ${CMAKE_HOST_SYSTEM_PROCESSOR} as RISCV32") set (WAMR_BUILD_TARGET "RISCV32") else () message (FATAL_ERROR "Unsupported CMAKE_HOST_SYSTEM_PROCESSOR " - "${CMAKE_HOST_SYSTEM_PROCESSOR}") + "${CMAKE_HOST_SYSTEM_PROCESSOR}") endif() if (WAMR_BUILD_PLATFORM STREQUAL "windows") diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index f2e5efafd..17c19143c 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -627,8 +627,10 @@ main(int argc, char *argv[]) goto fail1; } - if (get_package_type(wasm_file, wasm_file_size) != Wasm_Module_Bytecode) { - printf("Invalid file type: expected wasm file but got other\n"); + if (wasm_file_size >= 4 /* length of MAGIC NUMBER */ + && get_package_type(wasm_file, wasm_file_size) + != Wasm_Module_Bytecode) { + printf("Invalid wasm file: magic header not detected\n"); goto fail2; }