Просмотр исходного кода

Merge branch main into dev/gc_refactor

Wenyong Huang 2 лет назад
Родитель
Сommit
eab09a2af5
48 измененных файлов с 1129 добавлено и 456 удалено
  1. 9 1
      .github/workflows/build_llvm_libraries.yml
  2. 13 29
      .github/workflows/compilation_on_nuttx.yml
  3. 1 1
      .github/workflows/nightly_run.yml
  4. 31 55
      .github/workflows/spec_test_on_nuttx.yml
  5. 169 0
      RELEASE_NOTES.md
  6. 7 3
      build-scripts/build_llvm.py
  7. 5 0
      build-scripts/config_common.cmake
  8. 6 0
      core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c
  9. 144 80
      core/iwasm/aot/arch/aot_reloc_riscv.c
  10. 57 43
      core/iwasm/common/wasm_c_api.c
  11. 2 2
      core/iwasm/common/wasm_memory.c
  12. 10 0
      core/iwasm/common/wasm_memory.h
  13. 4 6
      core/iwasm/common/wasm_runtime_common.c
  14. 13 0
      core/iwasm/common/wasm_runtime_common.h
  15. 5 3
      core/iwasm/compilation/aot_llvm.c
  16. 19 4
      core/iwasm/compilation/aot_llvm_extra.cpp
  17. 8 26
      core/iwasm/fast-jit/fe/jit_emit_memory.c
  18. 340 64
      core/iwasm/fast-jit/jit_frontend.c
  19. 6 0
      core/iwasm/fast-jit/jit_frontend.h
  20. 2 0
      core/iwasm/fast-jit/jit_ir.h
  21. 53 27
      core/iwasm/include/wasm_c_api.h
  22. 14 8
      core/iwasm/include/wasm_export.h
  23. 16 6
      core/iwasm/interpreter/wasm_interp_classic.c
  24. 18 8
      core/iwasm/interpreter/wasm_interp_fast.c
  25. 53 35
      core/iwasm/interpreter/wasm_loader.c
  26. 7 7
      core/iwasm/interpreter/wasm_mini_loader.c
  27. 12 1
      core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
  28. 22 16
      core/iwasm/libraries/thread-mgr/thread_manager.c
  29. 4 4
      core/shared/platform/common/posix/posix_file.c
  30. 7 7
      core/shared/utils/bh_bitmap.h
  31. 2 2
      core/version.h
  32. 1 1
      doc/socket_api.md
  33. 1 1
      product-mini/platforms/common/libc_wasi.c
  34. 1 1
      product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp
  35. 1 1
      samples/basic/wasm-apps/testapp.c
  36. 6 2
      samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c
  37. 5 0
      samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h
  38. 5 0
      samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c
  39. 6 2
      samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c
  40. 5 0
      samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h
  41. 5 0
      samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c
  42. 3 3
      samples/multi-module/README.md
  43. 2 2
      samples/spawn-thread/CMakeLists.txt
  44. 1 0
      samples/spawn-thread/wasm-apps/CMakeLists.txt
  45. 12 1
      samples/spawn-thread/wasm-apps/sum.c
  46. 14 3
      tests/wamr-test-suites/spec-test-script/runtest.py
  47. 1 1
      tests/wamr-test-suites/test_wamr.sh
  48. 1 0
      tests/wamr-test-suites/tsan_suppressions.txt

+ 9 - 1
.github/workflows/build_llvm_libraries.yml

@@ -11,6 +11,9 @@ on:
       arch:
         required: true
         type: string
+      container_image:
+        required: false
+        type: string
     outputs:
       cache_key:
         description: "A cached key of LLVM libraries"
@@ -19,6 +22,10 @@ on:
 jobs:
   build_llvm_libraries:
     runs-on: ${{ inputs.os }}
+    # Using given container image if it is specified.
+    # Otherwise, it will be ignored by the runner.
+    container:
+      image: ${{ inputs.container_image }}
     outputs:
       key: ${{ steps.create_lib_cache_key.outputs.key}}
 
@@ -71,8 +78,9 @@ jobs:
             0-ccache-${{ inputs.os }}
         if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-22.04'
 
+      # Don't install dependencies if the cache is hit or running in docker container
       - run: sudo apt install -y ccache ninja-build
-        if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu')
+        if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu') && inputs.container_image == ''
 
       - uses: actions/cache@v3
         with:

+ 13 - 29
.github/workflows/compilation_on_nuttx.yml

@@ -50,7 +50,10 @@ env:
 
 jobs:
   build_iwasm_on_nuttx:
-    runs-on: ubuntu-22.04
+    runs-on: ubuntu-latest
+    container:
+      image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:4b4cbf0b70512e61ada9cdcb76b97e90ad478b85e4d0774d05a95fa32caa8c39
+
     strategy:
       matrix:
         nuttx_board_config: [
@@ -60,12 +63,14 @@ jobs:
           "boards/arm/rp2040/raspberrypi-pico/configs/nsh",
           # cortex-m7
           "boards/arm/stm32h7/nucleo-h743zi/configs/nsh",
-          # riscv32imac
+          # riscv32imc
+          "boards/risc-v/espressif/esp32c3-generic/configs/nsh",
+          # riscv32gc
           "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
-          # riscv64imac
-          "boards/risc-v/qemu-rv/rv-virt/configs/nsh64",
           # riscv64gc
-          "boards/risc-v/k210/maix-bit/configs/nsh",
+          "boards/risc-v/qemu-rv/rv-virt/configs/nsh64",
+          # arm64
+          "boards/arm64/qemu/qemu-armv8a/configs/nsh",
         ]
         wamr_config_option: [
           "CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\n",
@@ -81,39 +86,18 @@ jobs:
         ]
 
     steps:
-      - name: Install Utilities
-        run: |
-          sudo apt install -y kconfig-frontends-nox genromfs
-          pip3 install pyelftools
-          pip3 install cxxfilt
-
-      - name: Install ARM Compilers
-        if: contains(matrix.nuttx_board_config, 'arm')
-        run: sudo apt install -y gcc-arm-none-eabi
-
-      - name: Install RISC-V Compilers
-        if: contains(matrix.nuttx_board_config, 'risc-v')
-        run: |
-          curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.tar.gz > riscv.tar.gz
-          tar xvf riscv.tar.gz
-          echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH
-
-      - name: Install WASI-SDK
-        run: |
-          curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz > wasi-sdk.tar.gz
-          tar xvf wasi-sdk.tar.gz
-          sudo mv wasi-sdk-* /opt/wasi-sdk
-
       - name: Checkout NuttX
         uses: actions/checkout@v3
         with:
           repository: apache/incubator-nuttx
+          ref: releases/12.3
           path: nuttx
 
       - name: Checkout NuttX Apps
         uses: actions/checkout@v3
         with:
           repository: apache/incubator-nuttx-apps
+          ref: releases/12.3
           path: apps
 
       - name: Checkout WAMR
@@ -124,7 +108,7 @@ jobs:
 
       - name: Enable WAMR for NuttX
         run: |
-          find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\nCONFIG_PSEUDOFS_SOFTLINKS=y\n${{ matrix.wamr_config_option }}'
+          find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\n${{ matrix.wamr_config_option }}'
           find nuttx/boards/sim -name defconfig | xargs sed -i '$a\CONFIG_LIBM=y\n'
 
       - name: Build

+ 1 - 1
.github/workflows/nightly_run.yml

@@ -666,7 +666,7 @@ jobs:
 
       - name: run tests
         timeout-minutes: 40
-        run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} -T %{{matrix.sanitizer}}
+        run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} -T "${{ matrix.sanitizer }}"
         working-directory: ./tests/wamr-test-suites
 
       #only install x32 support libraries when to run x86_32 cases

+ 31 - 55
.github/workflows/spec_test_on_nuttx.yml

@@ -6,9 +6,10 @@ name: spec test on nuttx
 on:
   pull_request:
     types:
-      - closed
-    branches:
-      - main
+      - opened
+      - synchronize
+    paths:
+      - ".github/workflows/spec_test_on_nuttx.yml"
 
   schedule:
     - cron:  '0 0 * * *'
@@ -27,43 +28,46 @@ jobs:
     with:
       os: "ubuntu-22.04"
       arch: "ARM RISCV AArch64"
+      container_image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:4b4cbf0b70512e61ada9cdcb76b97e90ad478b85e4d0774d05a95fa32caa8c39
 
   spec_test_on_qemu:
-    runs-on: ubuntu-22.04
+    runs-on: ubuntu-latest
     needs: [build_llvm_libraries]
+    container:
+      image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:4b4cbf0b70512e61ada9cdcb76b97e90ad478b85e4d0774d05a95fa32caa8c39
     strategy:
       matrix:
         target_config: [
           # {
           #   config: "boards/arm64/qemu/qemu-armv8a/configs/nsh",
           #   target: "aarch64_vfp",
-          #   use_fpu: true
+          #   fpu_type: "fp"
           # },
           # {
           #   config: "boards/arm/imx6/sabre-6quad/configs/nsh",
           #   target: "thumbv7",
-          #   use_fpu: false
+          #   fpu_type: "none"
           # },
           {
             config: "boards/arm/imx6/sabre-6quad/configs/nsh",
             target: "thumbv7_vfp",
-            use_fpu: true
+            fpu_type: "dp"
           },
           {
             config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
             target: "riscv32",
-            use_fpu: false
+            fpu_type: "none"
           },
           # {
           #   config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
           #   target: "riscv32_ilp32d",
-          #   use_fpu: true
-          # },
-          # {
-          #   config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64",
-          #   target: "riscv64",
-          #   use_fpu: false
+          #   fpu_type: "dp"
           # },
+          {
+            config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64",
+            target: "riscv64",
+            fpu_type: "none"
+          },
         ]
 
         wamr_test_option: [
@@ -85,43 +89,24 @@ jobs:
           },
         ]
 
-    steps:
-      - name: Install Utilities
-        run: |
-          sudo apt install -y kconfig-frontends-nox genromfs
-
-      - name: Install ARM Compilers
-        if: startsWith(matrix.target_config.config, 'boards/arm')
-        run: |
-          sudo apt install -y gcc-arm-none-eabi
-          wget --quiet https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar.xz
-          xz -d gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar.xz
-          tar xf gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar
-          echo "$PWD/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf/bin" >> $GITHUB_PATH
-
-      - name: Install RISC-V Compilers
-        if: startsWith(matrix.target_config.config, 'boards/risc-v')
-        run: |
-          curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.tar.gz > riscv.tar.gz
-          tar xvf riscv.tar.gz
-          echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH
-
-      - name: Install WASI-SDK
-        run: |
-          curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz > wasi-sdk.tar.gz
-          tar xvf wasi-sdk.tar.gz
-          sudo mv wasi-sdk-* /opt/wasi-sdk
+        exclude:
+          # XIP is not fully supported yet on RISCV64, some relocations can not be resolved
+          - target_config: { config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64" }
+            wamr_test_option: { mode: "-t aot -X" }
 
+    steps:
       - name: Checkout NuttX
         uses: actions/checkout@v3
         with:
           repository: apache/incubator-nuttx
+          ref: releases/12.3
           path: nuttx
 
       - name: Checkout NuttX Apps
         uses: actions/checkout@v3
         with:
           repository: apache/incubator-nuttx-apps
+          ref: releases/12.3
           path: apps
 
       - name: Checkout WAMR
@@ -160,10 +145,15 @@ jobs:
           find nuttx/boards -name defconfig | xargs sed -i '$a\${{ matrix.wamr_test_option.option }}'
 
       - name: Disable FPU for NuttX
-        if: matrix.target_config.use_fpu== false
+        if: matrix.target_config.fpu_type == 'none'
         run: |
           find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_FPU is not set\n'
 
+      - name: Disable DPFPU for NuttX
+        if: matrix.target_config.fpu_type == 'fp'
+        run: |
+          find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_DPFPU is not set\n'
+
       - name: Build wamrc
         if: contains(matrix.wamr_test_option.mode, 'aot')
         working-directory: apps/interpreters/wamr/wamr/wamr-compiler
@@ -178,20 +168,6 @@ jobs:
           tools/configure.sh ${{ matrix.target_config.config }}
           make -j$(nproc)
           echo "firmware=$PWD/nuttx" >> $GITHUB_OUTPUT
-
-      - name: Install QEMU for ARM
-        if: startsWith(matrix.target_config.config, 'boards/arm')
-        run: |
-          curl -L https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz > xpack-qemu-arm.tar.gz
-          tar xvf xpack-qemu-arm.tar.gz
-          echo $PWD/xpack-qemu-arm-7.1.0-1/bin >> $GITHUB_PATH
-
-      - name: Install QEMU for RISC-V
-        if: startsWith(matrix.target_config.config, 'boards/risc-v')
-        run: |
-          curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz
-          tar xvf xpack-qemu-riscv.tar.gz
-          echo PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin >> $GITHUB_PATH
       
       - name: Test
         run: |

+ 169 - 0
RELEASE_NOTES.md

@@ -1,3 +1,172 @@
+## WAMR-1.3.0
+
+### Breaking Changes
+- Abstract POSIX filesystem functions (#2585)
+  - Change API wasm_runtime_set_wasi_args_ex's arguments
+    `int stdinfd/stdoutfd/stderrfd` to `int64_t stdinfd/stdoutfd/stderrfd`
+- core/iwasm: Support mapped file system access on non-libuv WASI (#2628)
+  - Enable mapping host directories to guest directories by parsing
+    the `map_dir_list` argument in API `wasm_runtime_init_wasi` for libc-wasi
+- Support muti-module for AOT mode (#2482)
+  - Add argument `package_type_t module_type` for module_reader callback
+- Generate jitdump to support linux perf for LLVM JIT (#2788)
+  - Add a field `bool linux_perf_support` in RuntimeInitArgs
+- Remove provision of unnecessary fd rights (#2579)
+- libc-wasi: Conditionally support SYNC flags (#2581)
+
+### New Features
+- Support muti-module for AOT mode (#2482)
+- Implement libc-wasi for Windows platform (#2740)
+- Implement module instance context APIs (#2436)
+- Implement async termination of blocking thread (#2516)
+- Generate jitdump to support linux perf for LLVM JIT (#2788)
+- Add Cosmopolitan Libc Platform (#2598)
+
+### Bug Fixes
+- sgx-ra: Disable the building of samples (#2507)
+- Handle a return from wasi _start function correctly (#2529)
+- fd_object_release: Preserve errno (#2535)
+- Fix build error with ancient GCC (4.8) (#2553)
+- Fix compiling error for RT-Thread (#2569)
+- Fix potential unaligned store issue when extra return value is v128 (#2583)
+- Fix loader push_pop_frame_ref_offset (#2590)
+- Fix compilation error on Android platform (#2594)
+- Ignore handling SIG_DFL/SIG_IGN for previous sig action (#2589)
+- Fix nightly run sanitizer error in Fast JIT (#2601)
+- Check ValueKind before extracting a constant int value (#2595)
+- Patch implementations of vfbinop(min,max,pmin,pax) (#2584)
+- Improve stack trace dump and fix coding guideline CI (#2599)
+- aot_resolve_stack_sizes: Disable the size check for now (#2608)
+- Remove module instance from hashmap in wasi_nn_destroy (#2613)
+- Fix label index out-of-range references in op_br_table_cache (#2615)
+- Fix compilation of shift opcodes on x86_64 and i386 architectures (#2619)
+- Fix potential issue in aot compiler when translating block opcodes (#2622)
+- Use another default pipeline when opt-level is 0 (#2624)
+- Fix AOT shift operations for indirect constants (#2627)
+- Fix fast-interp "pre-compiled label offset out of range" issue (#2659)
+- Revert "Strip static and shared libraries of iwasm to reduce the binary size (#2431)" (#2669)
+- Fix windows compilation on C++20 (#2670)
+- Fix fast-jit f32/f64 truncate to i32/i64 (#2671)
+- Fix use getrandom on cosmopolitan libc (#2674)
+- Fix repeatedly initialize shared memory data and protect the memory's fields (#2673)
+- Minor fixes for Go bindings (#2676)
+- Fix issues reported by Coverity (#2681)
+- Add more buffer boundary checks in wasm loader (#2734)
+- Grab cluster->lock when modifying exec_env->module_inst (#2685)
+- Fix CMSIS import with Zephyr 3.4+ (#2744)
+- Fix log messages in Zephyr example (#2761)
+- Fix fast-jit callnative translation (#2765)
+- aot compiler: Disable musttail for thumb (#2771)
+- Fix data/elem drop (#2747)
+- Fix formatting in aot_dump_perf_profiling (#2796)
+- Fix formatting in wasm_dump_perf_profiling (#2799)
+- Fix memory.init opcode issue in fast-interp (#2798)
+- aot compiler: Fix handle next reachable if block (#2793)
+- Fix configurable bounds checks typo (#2809)
+- Attestation: Free JSON from the Wasm module heap (#2803)
+- Update Zephyr support to v3.5.0 and make instructions generic to boards (#2805)
+- Return error when shutdown() fails (#2801)
+- iwasm: Print help when meeting unknown cmd options (#2824)
+- Fix fast-jit accessing shared memory's fields issue (#2841)
+- Fix wasm loader handle op_br_table and op_drop (#2864)
+- Fix block with type issue in fast interp (#2866)
+- Fix float argument handling for riscv32 ilp32d (#2871)
+- Portably handle fd_advise on directory fd (#2875)
+- Fix sample basic intToStr was called with wrong length (#2876)
+
+### Enhancements
+- Implement strict validation of thread IDs according to the specification (#2521)
+- Stop abusing shared memory lock to protect exception (#2509)
+- Implement os_usleep for posix (#2517)
+- set_exception_visitor: Remove the special case for wasi proc exit (#2525)
+- Revert "Return error when exception was raised after main thread finishes" (#2524)
+- libc-wasi: Remove unused code (#2528)
+- Add callback to handle memory.grow failures (#2522)
+- Add context to enlarge memory error callback (#2546)
+- Add ARM aeabi symbol for clearing memory content in a specific range (#2531)
+- Unifdef -U WASMTIME_SSP_STATIC_CURFDS (#2533)
+- Fix typo for IP address buffer (#2532)
+- Add an API to terminate instance (#2538)
+- Add user to enlarge memory error callback (#2546)
+- runtest.py: Show accurate case amount in summary (#2549)
+- Allow using custom signal handler from non-main thread (#2551)
+- Return __WASI_EINVAL from fd_prestat_dir_name (#2580)
+- Support AOT compiler with LLVM 17 (#2567)
+- Add support for closing/renumbering preopen fds (#2578)
+- Enable AOT usage on M1 mac (#2618)
+- core/iwasm: Support mapped file system access on non-libuv WASI (#2628)
+- Enable MASM automatically in runtime_lib.cmake (#2634)
+- Abstract POSIX filesystem functions (#2585)
+- Implement wasi clock_time/clock_res get (#2637)
+- Fix several typo/warning/unused-code issues (#2655)
+- Partial windows filesystem implementation (#2657)
+- Apply no_sanitize_address for clang compiler in several places (#2663)
+- Refactor clock functions to use WASI types (#2666)
+- Refine lock/unlock shared memory (#2682)
+- Fix several AOT compiler issues (#2697)
+- Fix AOT compiler simd shift opcodes (#2715)
+- Fix invalid use of jit_reg_is_const_val in fast-jit (#2718)
+- Use user defined malloc/free functions for user defined memory allocator (#2717)
+- Move WASI types into separate header (#2724)
+- Provide default vprintf on UWP (#2725)
+- Fix typo in Zephyr simple example (#2738)
+- Fix switch-case fallthrough compilation warning (#2753)
+- Add eabihf ABI support and set vendor-sys of bare-metal targets (#2745)
+- Return uint32 from WASI functions (#2749)
+- Add compilation flag to enable/disable heap corruption check (#2766)
+- Extend os_mmap to support map file from fd (#2763)
+- Fix printing ref.extern addresses in wasm_application.c (#2774)
+- Remove unused JitBitmap (#2775)
+- Use next generation crypto API on Windows (#2769)
+- More precise help info of enabled targets for wamrc (#2783)
+- Refine atomic operation flags in bh_atomic.h (#2780)
+- Fix comment in WAMR_MEM_DUAL_BUS_MIRROR (#2791)
+- Fix return type in wasm_loader_get_custom_section (#2794)
+- Add support for custom sections in nuttx (#2795)
+- Change is_shared_memory type from bool to uint8 (#2800)
+- Fix typos in zephyr platform struct descriptions (#2818)
+- Access linear memory size atomically (#2834)
+- Output warning and quit if import/export name contains '\00' (#2806)
+- Use wasm_config_t to pass private configuration to wasm_engine_new (#2837)
+- core/iwasm/interpreter/wasm_loader.c: remove an extra validation (#2845)
+- Don't add "+d" to riscv cpu features if already given (#2855)
+- Fix compilation warnings on Windows (#2868)
+
+### Others
+- Add mutex stress test (#2472)
+- Add unit tests for the tid allocator (#2519)
+- Add support for running tests on apple M1 macs (#2554)
+- export_native_api.md: Add a note about thread termination (#2572)
+- test_wamr.sh: Print a bit more meaningful message (#2574)
+- run_wasi_tests.sh: Provide stdin by ourselves (#2576)
+- Fix a few issues in "run_wasi_tests.sh: provide stdin by ourselves" (#2582)
+- Fix compile error of tsf benchmark (#2588)
+- test_wamr.sh: Bump wasi-testsuite version (#2568)
+- samples/inst-context-threads: Add a brief explanation (#2592)
+- doc/memory_tune.md: "remove malloc" hack is not relevant to wasi-threads (#2603)
+- Refactor stress tests to make them runnable in reactor mode (#2614)
+- Run rust tests from wasi-testsuite (#2484)
+- spec-test-script: Fix NaN comparision between v128 values (#2605)
+- CI: Enable testing AOT multi-module feature (#2621)
+- Vote for nomination of Woods, Chris and Trenner, Thomas as TSC members (#2638)
+- Add tsan for fast interp and aot (#2679)
+- Enable WASI tests on Windows CI (#2699)
+- docs: Fix typo in export native APIs doc (#2750)
+- Update RISC-V compilers in Nuttx compilation CI and spec test CI (#2756)
+- Enable more LLVM backends for the release wamrc binary (#2778)
+- Disable FPU in NuttX spec test (#2781)
+- Fix broken links in app-mgr README.md (#2786)
+- Fix build error of libsodium benchmark (#2792)
+- Fix wamr-test-suites script for macos (#2819)
+- Run spec test for classic/fast-interp in NuttX CI (#2817)
+- test_wamr.sh: Don't bother to build shared library (#2844)
+- doc/build_wamr.md: Fix links to RISC-V named ABIs (#2852)
+- Fix typos of CIDR in docs and help text (#2851)
+- Enable spectest on riscv64 (#2843)
+- Update FPU configuration in spec_test_on_nuttx.yml (#2856)
+
+---
+
 ## WAMR-1.2.3
 
 ### Breaking Changes

+ 7 - 3
build-scripts/build_llvm.py

@@ -55,8 +55,6 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
         "-DLLVM_APPEND_VC_REV:BOOL=ON",
         "-DLLVM_BUILD_EXAMPLES:BOOL=OFF",
         "-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF",
-        "-DLLVM_BUILD_TESTS:BOOL=OFF",
-        "-DLLVM_CCACHE_BUILD:BOOL=ON",
         "-DLLVM_ENABLE_BINDINGS:BOOL=OFF",
         "-DLLVM_ENABLE_IDE:BOOL=OFF",
         "-DLLVM_ENABLE_LIBEDIT=OFF",
@@ -68,9 +66,15 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
         "-DLLVM_INCLUDE_UTILS:BOOL=OFF",
         "-DLLVM_INCLUDE_TESTS:BOOL=OFF",
         "-DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON",
-        "-DLLVM_USE_PERF:BOOL=ON",
     ]
 
+    # ccache is not available on Windows
+    if not "windows" == platform:
+        LLVM_COMPILE_OPTIONS.append("-DLLVM_CCACHE_BUILD:BOOL=ON")
+    # perf support is available on Linux only
+    if "linux" == platform:
+        LLVM_COMPILE_OPTIONS.append("-DLLVM_USE_PERF:BOOL=ON")
+
     # use clang/clang++/lld. but macos doesn't support lld
     if not sys.platform.startswith("darwin") and use_clang:
         if shutil.which("clang") and shutil.which("clang++") and shutil.which("lld"):

+ 5 - 0
build-scripts/config_common.cmake

@@ -122,6 +122,11 @@ if (WAMR_BUILD_JIT EQUAL 1)
     if (CXX_SUPPORTS_REDUNDANT_MOVE_FLAG)
       set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")
     endif ()
+    # Enable exporting symbols after llvm-17, or LLVM JIT may run failed
+    # with `llvm_orc_registerEHFrameSectionWrapper` symbol not found error
+    if (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "17.0.0")
+      set (CMAKE_ENABLE_EXPORTS 1)
+    endif ()
   endif ()
 else ()
   unset (LLVM_AVAILABLE_LIBS)

+ 6 - 0
core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c

@@ -6,8 +6,14 @@
 #include "app_manager.h"
 #include "bh_platform.h"
 #include <autoconf.h>
+
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
 #include <zephyr.h>
 #include <kernel.h>
+#else
+#include <zephyr/kernel.h>
+#endif
+
 #if 0
 #include <sigverify.h>
 #endif

+ 144 - 80
core/iwasm/aot/arch/aot_reloc_riscv.c

@@ -11,21 +11,52 @@
 #define R_RISCV_CALL_PLT 19
 #define R_RISCV_PCREL_HI20 23
 #define R_RISCV_PCREL_LO12_I 24
+#define R_RISCV_PCREL_LO12_S 25
 #define R_RISCV_HI20 26
 #define R_RISCV_LO12_I 27
 #define R_RISCV_LO12_S 28
 
 #define RV_OPCODE_SW 0x23
 
+#undef NEED_SOFT_FP
+#undef NEED_SOFT_DP
+#undef NEED_SOFT_I32_MUL
+#undef NEED_SOFT_I32_DIV
+#undef NEED_SOFT_I64_MUL
+#undef NEED_SOFT_I64_DIV
+
+#ifdef __riscv_flen
+#if __riscv_flen == 32
+#define NEED_SOFT_DP
+#endif
+#else
+#define NEED_SOFT_FP
+#define NEED_SOFT_DP
+#endif
+
+#ifndef __riscv_mul
+#define NEED_SOFT_I32_MUL
+#define NEED_SOFT_I64_MUL
+#elif __riscv_xlen == 32
+#define NEED_SOFT_I64_MUL
+#endif
+
+#ifndef __riscv_div
+#define NEED_SOFT_I32_DIV
+#define NEED_SOFT_I64_DIV
+#elif __riscv_xlen == 32
+#define NEED_SOFT_I64_DIV
+#endif
+
 /* clang-format off */
 void __adddf3();
 void __addsf3();
-void __divdi3();
-void __divsi3();
 void __divdf3();
+void __divdi3();
 void __divsf3();
-void __eqsf2();
+void __divsi3();
 void __eqdf2();
+void __eqsf2();
 void __extendsfdf2();
 void __fixdfdi();
 void __fixdfsi();
@@ -37,12 +68,12 @@ void __fixunssfdi();
 void __fixunssfsi();
 void __floatdidf();
 void __floatdisf();
-void __floatsisf();
 void __floatsidf();
+void __floatsisf();
 void __floatundidf();
 void __floatundisf();
-void __floatunsisf();
 void __floatunsidf();
+void __floatunsisf();
 void __gedf2();
 void __gesf2();
 void __gtdf2();
@@ -58,6 +89,8 @@ void __muldi3();
 void __mulsf3();
 void __mulsi3();
 void __nedf2();
+void __negdf2();
+void __negsf2();
 void __nesf2();
 void __subdf3();
 void __subsf3();
@@ -73,60 +106,74 @@ void __unordsf2();
 static SymbolMap target_sym_map[] = {
     /* clang-format off */
     REG_COMMON_SYMBOLS
-#ifndef __riscv_flen
-    REG_SYM(__adddf3),
+#ifdef NEED_SOFT_FP
     REG_SYM(__addsf3),
-    REG_SYM(__divdf3),
     REG_SYM(__divsf3),
-    REG_SYM(__eqdf2),
     REG_SYM(__eqsf2),
-    REG_SYM(__extendsfdf2),
-    REG_SYM(__fixunsdfdi),
-    REG_SYM(__fixunsdfsi),
+    REG_SYM(__fixsfdi),
     REG_SYM(__fixunssfdi),
     REG_SYM(__fixunssfsi),
-    REG_SYM(__gedf2),
+    REG_SYM(__floatsidf),
     REG_SYM(__gesf2),
-    REG_SYM(__gtdf2),
     REG_SYM(__gtsf2),
-    REG_SYM(__ledf2),
     REG_SYM(__lesf2),
-    REG_SYM(__ltdf2),
-    REG_SYM(__ltsf2),
-    REG_SYM(__muldf3),
-    REG_SYM(__nedf2),
+    REG_SYM(__mulsf3),
+    REG_SYM(__negsf2),
     REG_SYM(__nesf2),
-    REG_SYM(__subdf3),
     REG_SYM(__subsf3),
-    REG_SYM(__truncdfsf2),
-    REG_SYM(__unorddf2),
     REG_SYM(__unordsf2),
-#if __riscv_xlen == 32
+#elif __riscv_xlen == 32
+    /* rv32f, support FP instruction but need soft routines
+     * to convert float and long long
+     */
+    REG_SYM(__floatundisf),
+#endif
+#ifdef NEED_SOFT_DP
+    REG_SYM(__adddf3),
+    REG_SYM(__divdf3),
+    REG_SYM(__eqdf2),
+    REG_SYM(__extendsfdf2),
     REG_SYM(__fixdfdi),
-    REG_SYM(__fixdfsi),
-    REG_SYM(__fixsfdi),
-    REG_SYM(__fixsfsi),
+    REG_SYM(__fixunsdfdi),
+    REG_SYM(__fixunsdfsi),
     REG_SYM(__floatdidf),
-    REG_SYM(__floatdisf),
     REG_SYM(__floatsidf),
-    REG_SYM(__floatsisf),
     REG_SYM(__floatundidf),
-    REG_SYM(__floatundisf),
     REG_SYM(__floatunsidf),
-    REG_SYM(__floatunsisf),
-    REG_SYM(__mulsf3),
-    REG_SYM(__mulsi3),
+    REG_SYM(__gedf2),
+    REG_SYM(__gtdf2),
+    REG_SYM(__ledf2),
+    REG_SYM(__muldf3),
+    REG_SYM(__nedf2),
+    REG_SYM(__negdf2),
+    REG_SYM(__subdf3),
+    REG_SYM(__truncdfsf2),
+    REG_SYM(__unorddf2),
+#elif __riscv_xlen == 32
+    /* rv32d, support DP instruction but need soft routines
+     * to convert double and long long
+     */
+    REG_SYM(__fixdfdi),
+    REG_SYM(__floatundidf),
 #endif
+#ifdef NEED_SOFT_I32_MUL
+    REG_SYM(__mulsi3),
 #endif
-    REG_SYM(__divdi3),
+#ifdef NEED_SOFT_I32_DIV
     REG_SYM(__divsi3),
-    REG_SYM(__moddi3),
     REG_SYM(__modsi3),
+    REG_SYM(__udivsi3),
+    REG_SYM(__umodsi3),
+#endif
+#ifdef NEED_SOFT_I64_MUL
     REG_SYM(__muldi3),
+#endif
+#ifdef NEED_SOFT_I64_DIV
+    REG_SYM(__divdi3),
+    REG_SYM(__moddi3),
     REG_SYM(__udivdi3),
-    REG_SYM(__udivsi3),
     REG_SYM(__umoddi3),
-    REG_SYM(__umodsi3),
+#endif
     /* clang-format on */
 };
 
@@ -269,9 +316,10 @@ typedef struct RelocTypeStrMap {
     }
 
 static RelocTypeStrMap reloc_type_str_maps[] = {
-    RELOC_TYPE_MAP(R_RISCV_32),           RELOC_TYPE_MAP(R_RISCV_CALL),
-    RELOC_TYPE_MAP(R_RISCV_CALL_PLT),     RELOC_TYPE_MAP(R_RISCV_PCREL_HI20),
-    RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_I), RELOC_TYPE_MAP(R_RISCV_HI20),
+    RELOC_TYPE_MAP(R_RISCV_32),           RELOC_TYPE_MAP(R_RISCV_64),
+    RELOC_TYPE_MAP(R_RISCV_CALL),         RELOC_TYPE_MAP(R_RISCV_CALL_PLT),
+    RELOC_TYPE_MAP(R_RISCV_PCREL_HI20),   RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_I),
+    RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_S), RELOC_TYPE_MAP(R_RISCV_HI20),
     RELOC_TYPE_MAP(R_RISCV_LO12_I),       RELOC_TYPE_MAP(R_RISCV_LO12_S),
 };
 
@@ -327,21 +375,37 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
             rv_set_val((uint16 *)addr, val_32);
             break;
         }
+
+#if __riscv_xlen == 64
         case R_RISCV_64:
         {
             uint64 val_64 =
-                (uint64)((uintptr_t)symbol_addr + (intptr_t)reloc_addend);
+                (uint64)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
+
             CHECK_RELOC_OFFSET(sizeof(uint64));
+            if (val_64
+                != (uint64)((intptr_t)symbol_addr + (intptr_t)reloc_addend)) {
+                goto fail_addr_out_of_range;
+            }
+
             bh_memcpy_s(addr, 8, &val_64, 8);
+#ifdef __riscv_zifencei
+            __asm__ volatile("fence.i");
+#else
+            __asm__ volatile("fence");
+#endif
             break;
         }
+#endif
+
         case R_RISCV_CALL:
         case R_RISCV_CALL_PLT:
+        case R_RISCV_PCREL_HI20: /* S + A - P */
         {
-            val = (int32)(intptr_t)((uint8 *)symbol_addr - addr);
+            val = (int32)(intptr_t)((uint8 *)symbol_addr + reloc_addend - addr);
 
             CHECK_RELOC_OFFSET(sizeof(uint32));
-            if (val != (intptr_t)((uint8 *)symbol_addr - addr)) {
+            if (val != (intptr_t)((uint8 *)symbol_addr + reloc_addend - addr)) {
                 if (symbol_index >= 0) {
                     /* Call runtime function by plt code */
                     symbol_addr = (uint8 *)module->code + module->code_size
@@ -351,7 +415,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
                 }
             }
 
-            if (val != (intptr_t)((uint8 *)symbol_addr - addr)) {
+            if (val != (intptr_t)((uint8 *)symbol_addr + reloc_addend - addr)) {
                 goto fail_addr_out_of_range;
             }
 
@@ -372,32 +436,15 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
             break;
         }
 
-        case R_RISCV_HI20:       /* S + A */
-        case R_RISCV_PCREL_HI20: /* S + A - P */
+        case R_RISCV_HI20: /* S + A */
         {
-            if (reloc_type == R_RISCV_PCREL_HI20) {
-                val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend
-                              - (intptr_t)addr);
-            }
-            else {
-                val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
-            }
+            val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
 
             CHECK_RELOC_OFFSET(sizeof(uint32));
-            if (reloc_type == R_RISCV_PCREL_HI20) {
-                if (val
-                    != ((intptr_t)symbol_addr + (intptr_t)reloc_addend
-                        - (intptr_t)addr)) {
-                    goto fail_addr_out_of_range;
-                }
-            }
-            else {
-                if (val != ((intptr_t)symbol_addr + (intptr_t)reloc_addend)) {
-                    goto fail_addr_out_of_range;
-                }
+            if (val != ((intptr_t)symbol_addr + (intptr_t)reloc_addend)) {
+                goto fail_addr_out_of_range;
             }
 
-            addr = target_section_addr + reloc_offset;
             insn = rv_get_val((uint16 *)addr);
             rv_calc_imm(val, &imm_hi, &imm_lo);
             insn = (insn & 0x00000fff) | (imm_hi << 12);
@@ -405,27 +452,44 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
             break;
         }
 
-        case R_RISCV_LO12_I:       /* S + A */
         case R_RISCV_PCREL_LO12_I: /* S - P */
+        case R_RISCV_PCREL_LO12_S: /* S - P */
         {
-            if (reloc_type == R_RISCV_PCREL_LO12_I) {
-                /* A = 0 */
-                val = (int32)((intptr_t)symbol_addr - (intptr_t)addr);
-            }
-            else {
-                val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
+            /* Already handled in R_RISCV_PCREL_HI20, it should be skipped for
+             * most cases. But it is still needed for some special cases, e.g.
+             * ```
+             * label:
+             *    auipc t0, %pcrel_hi(symbol)   # R_RISCV_PCREL_HI20 (symbol)
+             *    lui t1, 1
+             *    lw t2, t0, %pcrel_lo(label)   # R_RISCV_PCREL_LO12_I (label)
+             *    add t2, t2, t1
+             *    sw t2, t0, %pcrel_lo(label)   # R_RISCV_PCREL_LO12_S (label)
+             * ```
+             * In this case, the R_RISCV_PCREL_LO12_I/S relocation should be
+             * handled after R_RISCV_PCREL_HI20 relocation.
+             *
+             * So, if the R_RISCV_PCREL_LO12_I/S relocation is not followed by
+             * R_RISCV_PCREL_HI20 relocation, it should be handled here but
+             * not implemented yet.
+             */
+
+            if ((uintptr_t)addr - (uintptr_t)symbol_addr
+                    - (uintptr_t)reloc_addend
+                != 4) {
+                goto fail_addr_out_of_range;
             }
+            break;
+        }
+
+        case R_RISCV_LO12_I: /* S + A */
+        {
+
+            val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
 
             CHECK_RELOC_OFFSET(sizeof(uint32));
-            if (reloc_type == R_RISCV_PCREL_LO12_I) {
-                if (val != (intptr_t)symbol_addr - (intptr_t)addr) {
-                    goto fail_addr_out_of_range;
-                }
-            }
-            else {
-                if (val != (intptr_t)symbol_addr + (intptr_t)reloc_addend) {
-                    goto fail_addr_out_of_range;
-                }
+
+            if (val != (intptr_t)symbol_addr + (intptr_t)reloc_addend) {
+                goto fail_addr_out_of_range;
             }
 
             addr = target_section_addr + reloc_offset;

+ 57 - 43
core/iwasm/common/wasm_c_api.c

@@ -292,13 +292,46 @@ WASM_DEFINE_VEC_OWN(valtype, wasm_valtype_delete)
 own wasm_config_t *
 wasm_config_new(void)
 {
-    return NULL;
+    /* since wasm_runtime_malloc is not ready */
+    wasm_config_t *config = os_malloc(sizeof(wasm_config_t));
+    if (!config)
+        return NULL;
+
+    memset(config, 0, sizeof(wasm_config_t));
+    config->mem_alloc_type = Alloc_With_System_Allocator;
+    return config;
 }
 
 void
 wasm_config_delete(own wasm_config_t *config)
 {
-    (void)config;
+    if (config)
+        os_free(config);
+}
+
+wasm_config_t *
+wasm_config_set_mem_alloc_opt(wasm_config_t *config,
+                              mem_alloc_type_t mem_alloc_type,
+                              MemAllocOption *mem_alloc_option)
+{
+    if (!config)
+        return NULL;
+
+    config->mem_alloc_type = mem_alloc_type;
+    if (mem_alloc_option)
+        memcpy(&config->mem_alloc_option, mem_alloc_option,
+               sizeof(MemAllocOption));
+    return config;
+}
+
+wasm_config_t *
+wasm_config_set_linux_perf_opt(wasm_config_t *config, bool enable)
+{
+    if (!config)
+        return NULL;
+
+    config->linux_perf_support = enable;
+    return config;
 }
 
 static void
@@ -329,12 +362,11 @@ wasm_engine_delete_internal(wasm_engine_t *engine)
 }
 
 static wasm_engine_t *
-wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
+wasm_engine_new_internal(wasm_config_t *config)
 {
     wasm_engine_t *engine = NULL;
     /* init runtime */
     RuntimeInitArgs init_args = { 0 };
-    init_args.mem_alloc_type = type;
 
 #ifndef NDEBUG
     bh_log_set_verbose_level(BH_LOG_LEVEL_VERBOSE);
@@ -344,34 +376,11 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
 
     WASM_C_DUMP_PROC_MEM();
 
-    if (type == Alloc_With_Pool) {
-        if (!opts) {
-            return NULL;
-        }
-
-        init_args.mem_alloc_option.pool.heap_buf = opts->pool.heap_buf;
-        init_args.mem_alloc_option.pool.heap_size = opts->pool.heap_size;
-    }
-    else if (type == Alloc_With_Allocator) {
-        if (!opts) {
-            return NULL;
-        }
-
-        init_args.mem_alloc_option.allocator.malloc_func =
-            opts->allocator.malloc_func;
-        init_args.mem_alloc_option.allocator.free_func =
-            opts->allocator.free_func;
-        init_args.mem_alloc_option.allocator.realloc_func =
-            opts->allocator.realloc_func;
-#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
-        init_args.mem_alloc_option.allocator.user_data =
-            opts->allocator.user_data;
-#endif
-    }
-    else {
-        init_args.mem_alloc_option.pool.heap_buf = NULL;
-        init_args.mem_alloc_option.pool.heap_size = 0;
-    }
+    /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */
+    init_args.mem_alloc_type = config->mem_alloc_type;
+    memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option,
+           sizeof(MemAllocOption));
+    init_args.linux_perf_support = config->linux_perf_support;
 
     if (!wasm_runtime_full_init(&init_args)) {
         LOG_DEBUG("wasm_runtime_full_init failed");
@@ -418,14 +427,23 @@ static korp_mutex engine_lock = OS_THREAD_MUTEX_INITIALIZER;
 #endif
 
 own wasm_engine_t *
-wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
+wasm_engine_new()
+{
+    wasm_config_t config = { 0 };
+    wasm_config_set_mem_alloc_opt(&config, Alloc_With_System_Allocator, NULL);
+    wasm_engine_t *engine = wasm_engine_new_with_config(&config);
+    return engine;
+}
+
+own wasm_engine_t *
+wasm_engine_new_with_config(wasm_config_t *config)
 {
 #if defined(OS_THREAD_MUTEX_INITIALIZER)
     os_mutex_lock(&engine_lock);
 #endif
 
     if (!singleton_engine)
-        singleton_engine = wasm_engine_new_internal(type, opts);
+        singleton_engine = wasm_engine_new_internal(config);
     else
         singleton_engine->ref_count++;
 
@@ -437,16 +455,12 @@ wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
 }
 
 own wasm_engine_t *
-wasm_engine_new()
-{
-    return wasm_engine_new_with_args(Alloc_With_System_Allocator, NULL);
-}
-
-own wasm_engine_t *
-wasm_engine_new_with_config(own wasm_config_t *config)
+wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
 {
-    (void)config;
-    return wasm_engine_new_with_args(Alloc_With_System_Allocator, NULL);
+    wasm_config_t config = { 0 };
+    config.mem_alloc_type = type;
+    memcpy(&config.mem_alloc_option, opts, sizeof(MemAllocOption));
+    return wasm_engine_new_with_config(&config);
 }
 
 void

+ 2 - 2
core/iwasm/common/wasm_memory.c

@@ -686,7 +686,7 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
         memory->num_bytes_per_page = num_bytes_per_page;
         memory->cur_page_count = total_page_count;
         memory->max_page_count = max_page_count;
-        memory->memory_data_size = (uint32)total_size_new;
+        SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new);
         memory->memory_data_end = memory->memory_data + (uint32)total_size_new;
 
         wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new);
@@ -844,7 +844,7 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
     memory->num_bytes_per_page = num_bytes_per_page;
     memory->cur_page_count = total_page_count;
     memory->max_page_count = max_page_count;
-    memory->memory_data_size = (uint32)total_size_new;
+    SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new);
     memory->memory_data_end = memory->memory_data + (uint32)total_size_new;
 
     wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new);

+ 10 - 0
core/iwasm/common/wasm_memory.h

@@ -14,6 +14,16 @@
 extern "C" {
 #endif
 
+#if WASM_ENABLE_SHARED_MEMORY != 0
+#define GET_LINEAR_MEMORY_SIZE(memory) \
+    BH_ATOMIC_32_LOAD(memory->memory_data_size)
+#define SET_LINEAR_MEMORY_SIZE(memory, size) \
+    BH_ATOMIC_32_STORE(memory->memory_data_size, size)
+#else
+#define GET_LINEAR_MEMORY_SIZE(memory) memory->memory_data_size
+#define SET_LINEAR_MEMORY_SIZE(memory, size) memory->memory_data_size = size
+#endif
+
 bool
 wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
                          const MemAllocOption *alloc_option);

+ 4 - 6
core/iwasm/common/wasm_runtime_common.c

@@ -4170,16 +4170,14 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
                     if (n_stacks & 1)
                         n_stacks++;
                     if (func_type->types[i] == VALUE_TYPE_F32) {
-                        *(float32 *)&stacks[n_stacks] = *(float32 *)argv_src++;
-                        /* NaN boxing, the upper bits of a valid NaN-boxed
-                          value must be all 1s. */
-                        stacks[n_stacks + 1] = 0xFFFFFFFF;
+                        *(float32 *)&stacks[n_stacks++] =
+                            *(float32 *)argv_src++;
                     }
                     else {
                         *(float64 *)&stacks[n_stacks] = *(float64 *)argv_src;
                         argv_src += 2;
+                        n_stacks += 2;
                     }
-                    n_stacks += 2;
                 }
                 break;
             }
@@ -6143,7 +6141,7 @@ wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
 {
     /* register sub_module into its parent sub module list */
     WASMRegisteredModule *node = NULL;
-    bh_list_status ret;
+    bh_list_status ret = BH_LIST_ERROR;
 
     if (wasm_runtime_search_sub_module(parent_module, sub_module_name)) {
         LOG_DEBUG("%s has been registered in its parent", sub_module_name);

+ 13 - 0
core/iwasm/common/wasm_runtime_common.h

@@ -62,6 +62,12 @@ STORE_U16(void *addr, uint16_t value)
 {
     *(uint16_t *)(addr) = (uint16_t)(value);
 }
+static inline void
+STORE_U8(void *addr, uint8_t value)
+{
+    *(uint8 *)addr = value;
+}
+
 /* For LOAD opcodes */
 #define LOAD_I64(addr) (*(int64 *)(addr))
 #define LOAD_F64(addr) (*(float64 *)(addr))
@@ -215,6 +221,13 @@ STORE_U32(void *addr, uint32_t value)
         }
     }
 }
+
+static inline void
+STORE_U8(void *addr, uint8_t value)
+{
+    *(uint8 *)addr = value;
+}
+
 static inline void
 STORE_U16(void *addr, uint16_t value)
 {

+ 5 - 3
core/iwasm/compilation/aot_llvm.c

@@ -727,7 +727,8 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
         const char *key = "frame-pointer";
         const char *val = "all";
         LLVMAttributeRef no_omit_fp = LLVMCreateStringAttribute(
-            comp_ctx->context, key, strlen(key), val, strlen(val));
+            comp_ctx->context, key, (unsigned)strlen(key), val,
+            (unsigned)strlen(val));
         if (!no_omit_fp) {
             aot_set_last_error("create LLVM attribute (frame-pointer) failed.");
             goto fail;
@@ -2890,13 +2891,14 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
                               meta_target_abi);
 
             if (!strcmp(abi, "lp64d") || !strcmp(abi, "ilp32d")) {
-                if (features) {
+                if (features && !strstr(features, "+d")) {
                     snprintf(features_buf, sizeof(features_buf), "%s%s",
                              features, ",+d");
                     features = features_buf;
                 }
-                else
+                else if (!features) {
                     features = "+d";
+                }
             }
         }
 

+ 19 - 4
core/iwasm/compilation/aot_llvm_extra.cpp

@@ -36,6 +36,7 @@
 #include <llvm/Support/ErrorHandling.h>
 #if LLVM_VERSION_MAJOR >= 17
 #include <llvm/Support/PGOOptions.h>
+#include <llvm/Support/VirtualFileSystem.h>
 #endif
 #include <llvm/Target/CodeGenCWrappers.h>
 #include <llvm/Target/TargetMachine.h>
@@ -203,19 +204,27 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)
     Optional<PGOOptions> PGO = llvm::None;
 #endif
 
-// TODO
-#if LLVM_VERSION_MAJOR < 17
     if (comp_ctx->enable_llvm_pgo) {
         /* Disable static counter allocation for value profiler,
            it will be allocated by runtime */
         const char *argv[] = { "", "-vp-static-alloc=false" };
         cl::ParseCommandLineOptions(2, argv);
+#if LLVM_VERSION_MAJOR < 17
         PGO = PGOOptions("", "", "", PGOOptions::IRInstr);
+#else
+        auto FS = vfs::getRealFileSystem();
+        PGO = PGOOptions("", "", "", "", FS, PGOOptions::IRInstr);
+#endif
     }
     else if (comp_ctx->use_prof_file) {
+#if LLVM_VERSION_MAJOR < 17
         PGO = PGOOptions(comp_ctx->use_prof_file, "", "", PGOOptions::IRUse);
-    }
+#else
+        auto FS = vfs::getRealFileSystem();
+        PGO = PGOOptions(comp_ctx->use_prof_file, "", "", "", FS,
+                         PGOOptions::IRUse);
 #endif
+    }
 
 #ifdef DEBUG_PASS
     PassInstrumentationCallbacks PIC;
@@ -343,7 +352,13 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)
             ExitOnErr(PB.parsePassPipeline(MPM, comp_ctx->llvm_passes));
         }
 
-        if (OptimizationLevel::O0 == OL) {
+        if (
+#if LLVM_VERSION_MAJOR <= 13
+            PassBuilder::OptimizationLevel::O0 == OL
+#else
+            OptimizationLevel::O0 == OL
+#endif
+        ) {
             MPM.addPass(PB.buildO0DefaultPipeline(OL));
         }
         else {

+ 8 - 26
core/iwasm/fast-jit/fe/jit_emit_memory.c

@@ -137,6 +137,7 @@ check_and_seek(JitCompContext *cc, JitReg addr, uint32 offset, uint32 bytes)
 {
     JitReg memory_boundary = 0, offset1;
 #ifndef OS_ENABLE_HW_BOUND_CHECK
+    JitReg cur_page_count;
     /* the default memory */
     uint32 mem_idx = 0;
 #endif
@@ -146,16 +147,10 @@ check_and_seek(JitCompContext *cc, JitReg addr, uint32 offset, uint32 bytes)
     /* 1. shortcut if the memory size is 0 */
     if (cc->cur_wasm_module->memories != NULL
         && 0 == cc->cur_wasm_module->memories[mem_idx].init_page_count) {
-        JitReg module_inst, cur_page_count;
-        uint32 cur_page_count_offset =
-            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-            + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+
+        cur_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx);
 
         /* if (cur_mem_page_count == 0) goto EXCEPTION */
-        module_inst = get_module_inst_reg(cc->jit_frame);
-        cur_page_count = jit_cc_new_reg_I32(cc);
-        GEN_INSN(LDI32, cur_page_count, module_inst,
-                 NEW_CONST(I32, cur_page_count_offset));
         GEN_INSN(CMP, cc->cmp_reg, cur_page_count, NEW_CONST(I32, 0));
         if (!jit_emit_exception(cc, EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS,
                                 JIT_OP_BEQ, cc->cmp_reg, NULL)) {
@@ -580,15 +575,9 @@ fail:
 bool
 jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx)
 {
-    JitReg module_inst, cur_page_count;
-    uint32 cur_page_count_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+    JitReg cur_page_count;
 
-    module_inst = get_module_inst_reg(cc->jit_frame);
-    cur_page_count = jit_cc_new_reg_I32(cc);
-    GEN_INSN(LDI32, cur_page_count, module_inst,
-             NEW_CONST(I32, cur_page_count_offset));
+    cur_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx);
 
     PUSH_I32(cur_page_count);
 
@@ -600,18 +589,11 @@ fail:
 bool
 jit_compile_op_memory_grow(JitCompContext *cc, uint32 mem_idx)
 {
-    JitReg module_inst, grow_res, res;
+    JitReg grow_res, res;
     JitReg prev_page_count, inc_page_count, args[2];
 
-    /* Get current page count */
-    uint32 cur_page_count_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
-
-    module_inst = get_module_inst_reg(cc->jit_frame);
-    prev_page_count = jit_cc_new_reg_I32(cc);
-    GEN_INSN(LDI32, prev_page_count, module_inst,
-             NEW_CONST(I32, cur_page_count_offset));
+    /* Get current page count as prev_page_count */
+    prev_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx);
 
     /* Call wasm_enlarge_memory */
     POP_I32(inc_page_count);

+ 340 - 64
core/iwasm/fast-jit/jit_frontend.c

@@ -218,42 +218,149 @@ get_aux_stack_bottom_reg(JitFrame *frame)
     return frame->aux_stack_bottom_reg;
 }
 
+#if WASM_ENABLE_SHARED_MEMORY != 0
+static bool
+is_shared_memory(WASMModule *module, uint32 mem_idx)
+{
+    WASMMemory *memory;
+    WASMMemoryImport *memory_import;
+    bool is_shared;
+
+    if (mem_idx < module->import_memory_count) {
+        memory_import = &(module->import_memories[mem_idx].u.memory);
+        is_shared = memory_import->flags & 0x02 ? true : false;
+    }
+    else {
+        memory = &module->memories[mem_idx - module->import_memory_count];
+        is_shared = memory->flags & 0x02 ? true : false;
+    }
+    return is_shared;
+}
+#endif
+
 JitReg
-get_memory_data_reg(JitFrame *frame, uint32 mem_idx)
+get_memory_inst_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
     JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 memory_data_offset;
+    uint32 memory_inst_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memories_addr;
+    uint32 memories_offset;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].memory_inst)
+        return frame->memory_regs[mem_idx].memory_inst;
+
+    frame->memory_regs[mem_idx].memory_inst =
+        cc->memory_regs[mem_idx].memory_inst;
 
     bh_assert(mem_idx == 0);
 #if WASM_ENABLE_SHARED_MEMORY != 0
-    uint32 memories_offset = (uint32)offsetof(WASMModuleInstance, memories);
-    JitReg memories_addr = jit_cc_new_reg_ptr(cc);
-    JitReg memories_0_addr = jit_cc_new_reg_ptr(cc);
-    memory_data_offset = (uint32)offsetof(WASMMemoryInstance, memory_data);
-    if (!frame->memory_regs[mem_idx].memory_data) {
-        frame->memory_regs[mem_idx].memory_data =
-            cc->memory_regs[mem_idx].memory_data;
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memories_addr = jit_cc_new_reg_ptr(cc);
+        memories_offset = (uint32)offsetof(WASMModuleInstance, memories);
         /* module_inst->memories */
         GEN_INSN(LDPTR, memories_addr, module_inst_reg,
                  NEW_CONST(I32, memories_offset));
-        /* module_inst->memories[0] */
-        GEN_INSN(LDPTR, memories_0_addr, memories_addr, NEW_CONST(I32, 0));
-        /* memories[0]->memory_data */
+        /* module_inst->memories[mem_idx], mem_idx can only be 0 now */
+        GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_inst, memories_addr,
+                 NEW_CONST(I32, mem_idx));
+    }
+    else
+#endif
+    {
+        memory_inst_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes);
+        GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_inst,
+                 module_inst_reg, NEW_CONST(I32, memory_inst_offset));
+    }
+
+    return frame->memory_regs[mem_idx].memory_inst;
+}
+
+JitReg
+get_cur_page_count_reg(JitFrame *frame, uint32 mem_idx)
+{
+    JitCompContext *cc = frame->cc;
+    JitReg module_inst_reg;
+    uint32 cur_page_count_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].cur_page_count)
+        return frame->memory_regs[mem_idx].cur_page_count;
+
+    frame->memory_regs[mem_idx].cur_page_count =
+        cc->memory_regs[mem_idx].cur_page_count;
+
+    /* Get current page count */
+    bh_assert(mem_idx == 0);
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        cur_page_count_offset =
+            (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+        /* memories[mem_idx]->cur_page_count_offset */
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].cur_page_count,
+                 memory_inst_reg, NEW_CONST(I32, cur_page_count_offset));
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        cur_page_count_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].cur_page_count,
+                 module_inst_reg, NEW_CONST(I32, cur_page_count_offset));
+    }
+
+    return frame->memory_regs[mem_idx].cur_page_count;
+}
+
+JitReg
+get_memory_data_reg(JitFrame *frame, uint32 mem_idx)
+{
+    JitCompContext *cc = frame->cc;
+    JitReg module_inst_reg;
+    uint32 memory_data_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].memory_data)
+        return frame->memory_regs[mem_idx].memory_data;
+
+    frame->memory_regs[mem_idx].memory_data =
+        cc->memory_regs[mem_idx].memory_data;
+
+    bh_assert(mem_idx == 0);
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        memory_data_offset = (uint32)offsetof(WASMMemoryInstance, memory_data);
+        /* memories[mem_idx]->memory_data */
         GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data,
-                 memories_0_addr, NEW_CONST(I32, memory_data_offset));
+                 memory_inst_reg, NEW_CONST(I32, memory_data_offset));
     }
-#else
-    memory_data_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, memory_data);
-    if (!frame->memory_regs[mem_idx].memory_data) {
-        frame->memory_regs[mem_idx].memory_data =
-            cc->memory_regs[mem_idx].memory_data;
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        memory_data_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, memory_data);
         GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data,
                  module_inst_reg, NEW_CONST(I32, memory_data_offset));
     }
-#endif
     return frame->memory_regs[mem_idx].memory_data;
 }
 
@@ -261,16 +368,37 @@ JitReg
 get_memory_data_end_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
-    JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 memory_data_end_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, memory_data_end);
+    JitReg module_inst_reg;
+    uint32 memory_data_end_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
 
-    bh_assert(mem_idx == 0);
+    if (frame->memory_regs[mem_idx].memory_data_end)
+        return frame->memory_regs[mem_idx].memory_data_end;
+
+    frame->memory_regs[mem_idx].memory_data_end =
+        cc->memory_regs[mem_idx].memory_data_end;
 
-    if (!frame->memory_regs[mem_idx].memory_data_end) {
-        frame->memory_regs[mem_idx].memory_data_end =
-            cc->memory_regs[mem_idx].memory_data_end;
+    bh_assert(mem_idx == 0);
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        memory_data_end_offset =
+            (uint32)offsetof(WASMMemoryInstance, memory_data_end);
+        /* memories[mem_idx]->memory_data_end */
+        GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data_end,
+                 memory_inst_reg, NEW_CONST(I32, memory_data_end_offset));
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        memory_data_end_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, memory_data_end);
         GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data_end,
                  module_inst_reg, NEW_CONST(I32, memory_data_end_offset));
     }
@@ -281,16 +409,43 @@ JitReg
 get_mem_bound_check_1byte_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
-    JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 mem_bound_check_1byte_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte);
+    JitReg module_inst_reg;
+    uint32 mem_bound_check_1byte_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].mem_bound_check_1byte)
+        return frame->memory_regs[mem_idx].mem_bound_check_1byte;
+
+    frame->memory_regs[mem_idx].mem_bound_check_1byte =
+        cc->memory_regs[mem_idx].mem_bound_check_1byte;
 
     bh_assert(mem_idx == 0);
 
-    if (!frame->memory_regs[mem_idx].mem_bound_check_1byte) {
-        frame->memory_regs[mem_idx].mem_bound_check_1byte =
-            cc->memory_regs[mem_idx].mem_bound_check_1byte;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        mem_bound_check_1byte_offset =
+            (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte);
+        /* memories[mem_idx]->mem_bound_check_1byte */
+#if UINTPTR_MAX == UINT64_MAX
+        GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_1byte,
+                 memory_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset));
+#else
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_1byte,
+                 memory_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset));
+#endif
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        mem_bound_check_1byte_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte);
 #if UINTPTR_MAX == UINT64_MAX
         GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_1byte,
                  module_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset));
@@ -306,16 +461,45 @@ JitReg
 get_mem_bound_check_2bytes_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
-    JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 mem_bound_check_2bytes_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes);
+    JitReg module_inst_reg;
+    uint32 mem_bound_check_2bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].mem_bound_check_2bytes)
+        return frame->memory_regs[mem_idx].mem_bound_check_2bytes;
+
+    frame->memory_regs[mem_idx].mem_bound_check_2bytes =
+        cc->memory_regs[mem_idx].mem_bound_check_2bytes;
 
     bh_assert(mem_idx == 0);
 
-    if (!frame->memory_regs[mem_idx].mem_bound_check_2bytes) {
-        frame->memory_regs[mem_idx].mem_bound_check_2bytes =
-            cc->memory_regs[mem_idx].mem_bound_check_2bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        mem_bound_check_2bytes_offset =
+            (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes);
+        /* memories[mem_idx]->mem_bound_check_2bytes */
+#if UINTPTR_MAX == UINT64_MAX
+        GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_2bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_2bytes_offset));
+#else
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_2bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_2bytes_offset));
+#endif
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        mem_bound_check_2bytes_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes);
 #if UINTPTR_MAX == UINT64_MAX
         GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_2bytes,
                  module_inst_reg,
@@ -333,16 +517,45 @@ JitReg
 get_mem_bound_check_4bytes_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
-    JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 mem_bound_check_4bytes_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes);
+    JitReg module_inst_reg;
+    uint32 mem_bound_check_4bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].mem_bound_check_4bytes)
+        return frame->memory_regs[mem_idx].mem_bound_check_4bytes;
+
+    frame->memory_regs[mem_idx].mem_bound_check_4bytes =
+        cc->memory_regs[mem_idx].mem_bound_check_4bytes;
 
     bh_assert(mem_idx == 0);
 
-    if (!frame->memory_regs[mem_idx].mem_bound_check_4bytes) {
-        frame->memory_regs[mem_idx].mem_bound_check_4bytes =
-            cc->memory_regs[mem_idx].mem_bound_check_4bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        mem_bound_check_4bytes_offset =
+            (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes);
+        /* memories[mem_idx]->mem_bound_check_4bytes */
+#if UINTPTR_MAX == UINT64_MAX
+        GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_4bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_4bytes_offset));
+#else
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_4bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_4bytes_offset));
+#endif
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        mem_bound_check_4bytes_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes);
 #if UINTPTR_MAX == UINT64_MAX
         GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_4bytes,
                  module_inst_reg,
@@ -360,16 +573,45 @@ JitReg
 get_mem_bound_check_8bytes_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
-    JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 mem_bound_check_8bytes_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes);
+    JitReg module_inst_reg;
+    uint32 mem_bound_check_8bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].mem_bound_check_8bytes)
+        return frame->memory_regs[mem_idx].mem_bound_check_8bytes;
+
+    frame->memory_regs[mem_idx].mem_bound_check_8bytes =
+        cc->memory_regs[mem_idx].mem_bound_check_8bytes;
 
     bh_assert(mem_idx == 0);
 
-    if (!frame->memory_regs[mem_idx].mem_bound_check_8bytes) {
-        frame->memory_regs[mem_idx].mem_bound_check_8bytes =
-            cc->memory_regs[mem_idx].mem_bound_check_8bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        mem_bound_check_8bytes_offset =
+            (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes);
+        /* memories[mem_idx]->mem_bound_check_8bytes */
+#if UINTPTR_MAX == UINT64_MAX
+        GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_8bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_8bytes_offset));
+#else
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_8bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_8bytes_offset));
+#endif
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        mem_bound_check_8bytes_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes);
 #if UINTPTR_MAX == UINT64_MAX
         GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_8bytes,
                  module_inst_reg,
@@ -387,16 +629,45 @@ JitReg
 get_mem_bound_check_16bytes_reg(JitFrame *frame, uint32 mem_idx)
 {
     JitCompContext *cc = frame->cc;
-    JitReg module_inst_reg = get_module_inst_reg(frame);
-    uint32 mem_bound_check_16bytes_offset =
-        (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
-        + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes);
+    JitReg module_inst_reg;
+    uint32 mem_bound_check_16bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    JitReg memory_inst_reg;
+    bool is_shared;
+#endif
+
+    if (frame->memory_regs[mem_idx].mem_bound_check_16bytes)
+        return frame->memory_regs[mem_idx].mem_bound_check_16bytes;
+
+    frame->memory_regs[mem_idx].mem_bound_check_16bytes =
+        cc->memory_regs[mem_idx].mem_bound_check_16bytes;
 
     bh_assert(mem_idx == 0);
 
-    if (!frame->memory_regs[mem_idx].mem_bound_check_16bytes) {
-        frame->memory_regs[mem_idx].mem_bound_check_16bytes =
-            cc->memory_regs[mem_idx].mem_bound_check_16bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+    is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+    if (is_shared) {
+        memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+        mem_bound_check_16bytes_offset =
+            (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes);
+        /* memories[mem_idx]->mem_bound_check_16bytes */
+#if UINTPTR_MAX == UINT64_MAX
+        GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_16bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_16bytes_offset));
+#else
+        GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_16bytes,
+                 memory_inst_reg,
+                 NEW_CONST(I32, mem_bound_check_16bytes_offset));
+#endif
+    }
+    else
+#endif
+    {
+        module_inst_reg = get_module_inst_reg(frame);
+        mem_bound_check_16bytes_offset =
+            (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+            + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes);
 #if UINTPTR_MAX == UINT64_MAX
         GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_16bytes,
                  module_inst_reg,
@@ -462,6 +733,8 @@ clear_fixed_virtual_regs(JitFrame *frame)
 
     count = module->import_memory_count + module->memory_count;
     for (i = 0; i < count; i++) {
+        frame->memory_regs[i].memory_inst = 0;
+        frame->memory_regs[i].cur_page_count = 0;
         frame->memory_regs[i].memory_data = 0;
         frame->memory_regs[i].memory_data_end = 0;
         frame->memory_regs[i].mem_bound_check_1byte = 0;
@@ -486,6 +759,7 @@ clear_memory_regs(JitFrame *frame)
 
     count = module->import_memory_count + module->memory_count;
     for (i = 0; i < count; i++) {
+        frame->memory_regs[i].cur_page_count = 0;
         frame->memory_regs[i].memory_data = 0;
         frame->memory_regs[i].memory_data_end = 0;
         frame->memory_regs[i].mem_bound_check_1byte = 0;
@@ -654,6 +928,8 @@ create_fixed_virtual_regs(JitCompContext *cc)
         }
 
         for (i = 0; i < count; i++) {
+            cc->memory_regs[i].memory_inst = jit_cc_new_reg_ptr(cc);
+            cc->memory_regs[i].cur_page_count = jit_cc_new_reg_I32(cc);
             cc->memory_regs[i].memory_data = jit_cc_new_reg_ptr(cc);
             cc->memory_regs[i].memory_data_end = jit_cc_new_reg_ptr(cc);
             cc->memory_regs[i].mem_bound_check_1byte = jit_cc_new_reg_ptr(cc);

+ 6 - 0
core/iwasm/fast-jit/jit_frontend.h

@@ -192,6 +192,12 @@ get_aux_stack_bound_reg(JitFrame *frame);
 JitReg
 get_aux_stack_bottom_reg(JitFrame *frame);
 
+JitReg
+get_memory_inst_reg(JitFrame *frame, uint32 mem_idx);
+
+JitReg
+get_cur_page_count_reg(JitFrame *frame, uint32 mem_idx);
+
 JitReg
 get_memory_data_reg(JitFrame *frame, uint32 mem_idx);
 

+ 2 - 0
core/iwasm/fast-jit/jit_ir.h

@@ -866,6 +866,8 @@ typedef struct JitValueSlot {
 typedef struct JitMemRegs {
     /* The following registers should be re-loaded after
        memory.grow, callbc and callnative */
+    JitReg memory_inst;
+    JitReg cur_page_count;
     JitReg memory_data;
     JitReg memory_data_end;
     JitReg mem_bound_check_1byte;

+ 53 - 27
core/iwasm/include/wasm_c_api.h

@@ -21,6 +21,15 @@
 #endif
 #endif
 
+#if defined(__GNUC__) || defined(__clang__)
+#define DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#define DEPRECATED __declspec(deprecated)
+#else
+#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
+#define DEPRECATED
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -136,31 +145,6 @@ static inline void wasm_name_new_from_string_nt(
 
 WASM_DECLARE_OWN(config)
 
-WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
-
-// Embedders may provide custom functions for manipulating configs.
-
-
-// Engine
-
-WASM_DECLARE_OWN(engine)
-
-/**
- * Create a new engine
- *
- * Note: for the engine new/delete operations, including this,
- * wasm_engine_new_with_config, wasm_engine_new_with_args, and
- * wasm_engine_delete, if the platform has mutex initializer,
- * then they are thread-safe: we use a global lock to lock the
- * operations of the engine. Otherwise they are not thread-safe:
- * when there are engine new/delete operations happening
- * simultaneously in multiple threads, developer must create
- * the lock by himself, and add the lock when calling these
- * functions.
- */
-WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
-WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*);
-
 #ifndef MEM_ALLOC_OPTION_DEFINED
 #define MEM_ALLOC_OPTION_DEFINED
 /* same definition from wasm_export.h */
@@ -191,9 +175,51 @@ typedef union MemAllocOption {
         void *user_data;
     } allocator;
 } MemAllocOption;
-#endif
+#endif /* MEM_ALLOC_OPTION_DEFINED */
+
+/* Runtime configration */
+struct wasm_config_t {
+    mem_alloc_type_t mem_alloc_type;
+    MemAllocOption mem_alloc_option;
+    bool linux_perf_support;
+    /*TODO: wasi args*/
+};
+
+/*
+ * by default:
+ * - mem_alloc_type is Alloc_With_System_Allocator
+ * - mem_alloc_option is all 0
+ * - linux_perf_support is false
+ */
+WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
+
+// Embedders may provide custom functions for manipulating configs.
+WASM_API_EXTERN own wasm_config_t*
+wasm_config_set_mem_alloc_opt(wasm_config_t *, mem_alloc_type_t, MemAllocOption *);
 
-WASM_API_EXTERN own wasm_engine_t *
+WASM_API_EXTERN own wasm_config_t*
+wasm_config_set_linux_perf_opt(wasm_config_t *, bool);
+
+// Engine
+
+WASM_DECLARE_OWN(engine)
+
+/**
+ * Create a new engine
+ *
+ * Note: for the engine new/delete operations, including this,
+ * wasm_engine_new_with_config, wasm_engine_new_with_args, and
+ * wasm_engine_delete, if the platform has mutex initializer,
+ * then they are thread-safe: we use a global lock to lock the
+ * operations of the engine. Otherwise they are not thread-safe:
+ * when there are engine new/delete operations happening
+ * simultaneously in multiple threads, developer must create
+ * the lock by himself, and add the lock when calling these
+ * functions.
+ */
+WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
+WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(wasm_config_t*);
+DEPRECATED WASM_API_EXTERN own wasm_engine_t *
 wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts);
 
 // Store

+ 14 - 8
core/iwasm/include/wasm_export.h

@@ -118,7 +118,7 @@ typedef union MemAllocOption {
         void *realloc_func;
         void *free_func;
         /* allocator user data, only used when
-            WASM_MEM_ALLOC_WITH_USER_DATA is defined */
+           WASM_MEM_ALLOC_WITH_USER_DATA is defined */
         void *user_data;
     } allocator;
 } MemAllocOption;
@@ -149,7 +149,7 @@ typedef struct RuntimeInitArgs {
     uint32_t n_native_symbols;
 
     /* maximum thread number, only used when
-        WASM_ENABLE_THREAD_MGR is defined */
+       WASM_ENABLE_THREAD_MGR is defined */
     uint32_t max_thread_num;
 
     /* Debug settings, only used when
@@ -323,7 +323,8 @@ wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size);
 /**
  * Callback to load a module file into a buffer in multi-module feature
  */
-typedef bool (*module_reader)(package_type_t module_type,const char *module_name,
+typedef bool (*module_reader)(package_type_t module_type,
+                              const char *module_name,
                               uint8_t **p_buffer, uint32_t *p_size);
 
 /**
@@ -883,6 +884,7 @@ wasm_application_execute_main(wasm_module_inst_t module_inst,
 WASM_RUNTIME_API_EXTERN bool
 wasm_application_execute_func(wasm_module_inst_t module_inst,
                               const char *name, int32_t argc, char *argv[]);
+
 /**
  * Get exception info of the WASM module instance.
  *
@@ -945,6 +947,7 @@ wasm_runtime_terminate(wasm_module_inst_t module_inst);
 WASM_RUNTIME_API_EXTERN void
 wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
                              void *custom_data);
+
 /**
  * Get the custom data within a WASM module instance.
  *
@@ -964,6 +967,7 @@ wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
 WASM_RUNTIME_API_EXTERN void
 wasm_runtime_set_bounds_checks(wasm_module_inst_t module_inst,
                                bool enable);
+
 /**
  * Check if the memory bounds checks flag is enabled for a WASM module instance.
  *
@@ -973,6 +977,7 @@ wasm_runtime_set_bounds_checks(wasm_module_inst_t module_inst,
 WASM_RUNTIME_API_EXTERN bool
 wasm_runtime_is_bounds_checks_enabled(
     wasm_module_inst_t module_inst);
+
 /**
  * Allocate memory from the heap of WASM module instance
  *
@@ -1347,7 +1352,8 @@ wasm_externref_objdel(wasm_module_inst_t module_inst, void *extern_obj);
  *
  * @param module_inst the WASM module instance that the extern object
  *        belongs to
- * @param extern_obj the external object to which to set the `extern_obj_cleanup` cleanup callback.
+ * @param extern_obj the external object to which to set the
+ *        `extern_obj_cleanup` cleanup callback.
  * @param extern_obj_cleanup a callback to release `extern_obj`
  *
  * @return true if success, false otherwise
@@ -1555,11 +1561,11 @@ WASM_RUNTIME_API_EXTERN void
 wasm_runtime_destroy_context_key(void *key);
 
 WASM_RUNTIME_API_EXTERN void
-wasm_runtime_set_context(wasm_module_inst_t inst, void *key,
-                                         void *ctx);
+wasm_runtime_set_context(wasm_module_inst_t inst, void *key, void *ctx);
+
 WASM_RUNTIME_API_EXTERN void
-wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key,
-                                         void *ctx);
+wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, void *ctx);
+
 WASM_RUNTIME_API_EXTERN void *
 wasm_runtime_get_context(wasm_module_inst_t inst, void *key);
 

+ 16 - 6
core/iwasm/interpreter/wasm_interp_classic.c

@@ -43,7 +43,7 @@ typedef float64 CellType_F64;
  * multi-threading mode since it may be changed by other
  * threads in memory.grow
  */
-#define get_linear_mem_size() memory->memory_data_size
+#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory)
 #endif
 
 #if !defined(OS_ENABLE_HW_BOUND_CHECK) \
@@ -1346,7 +1346,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
 #if !defined(OS_ENABLE_HW_BOUND_CHECK)              \
     || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
     || WASM_ENABLE_BULK_MEMORY != 0
-    uint32 linear_mem_size = memory ? memory->memory_data_size : 0;
+    uint32 linear_mem_size = 0;
+    if (memory)
+#if WASM_ENABLE_THREAD_MGR == 0
+        linear_mem_size = memory->memory_data_size;
+#else
+        linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
+#endif
 #endif
     WASMFuncType **wasm_types = (WASMFuncType **)module->module->types;
     WASMGlobalInstance *globals = module->e->globals, *global;
@@ -3993,7 +3999,11 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
 #if !defined(OS_ENABLE_HW_BOUND_CHECK)              \
     || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
     || WASM_ENABLE_BULK_MEMORY != 0
+#if WASM_ENABLE_THREAD_MGR == 0
                     linear_mem_size = memory->memory_data_size;
+#else
+                    linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
+#endif
 #endif
                 }
 
@@ -4998,7 +5008,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                         addr = (uint32)POP_I32();
 
 #if WASM_ENABLE_THREAD_MGR != 0
-                        linear_mem_size = memory->memory_data_size;
+                        linear_mem_size = get_linear_mem_size();
 #endif
 
 #ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -5049,7 +5059,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                         dst = POP_I32();
 
 #if WASM_ENABLE_THREAD_MGR != 0
-                        linear_mem_size = memory->memory_data_size;
+                        linear_mem_size = get_linear_mem_size();
 #endif
 
 #ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -5080,7 +5090,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                         dst = POP_I32();
 
 #if WASM_ENABLE_THREAD_MGR != 0
-                        linear_mem_size = memory->memory_data_size;
+                        linear_mem_size = get_linear_mem_size();
 #endif
 
 #ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -5795,7 +5805,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
     || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
     || WASM_ENABLE_BULK_MEMORY != 0
             if (memory)
-                linear_mem_size = memory->memory_data_size;
+                linear_mem_size = get_linear_mem_size();
 #endif
             if (wasm_copy_exception(module, NULL))
                 goto got_exception;

+ 18 - 8
core/iwasm/interpreter/wasm_interp_fast.c

@@ -34,7 +34,7 @@ typedef float64 CellType_F64;
  * multi-threading mode since it may be changed by other
  * threads in memory.grow
  */
-#define get_linear_mem_size() memory->memory_data_size
+#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory)
 #endif
 
 #if !defined(OS_ENABLE_HW_BOUND_CHECK) \
@@ -1438,7 +1438,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
 #if !defined(OS_ENABLE_HW_BOUND_CHECK)              \
     || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
     || WASM_ENABLE_BULK_MEMORY != 0
-    uint32 linear_mem_size = memory ? memory->memory_data_size : 0;
+    uint32 linear_mem_size = 0;
+    if (memory)
+#if WASM_ENABLE_THREAD_MGR == 0
+        linear_mem_size = memory->memory_data_size;
+#else
+        linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
+#endif
 #endif
     WASMGlobalInstance *globals = module->e ? module->e->globals : NULL;
     WASMGlobalInstance *global;
@@ -3586,7 +3592,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                 frame_ip += 2;
                 addr_ret = GET_OFFSET();
                 CHECK_MEMORY_OVERFLOW(1);
-                frame_lp[addr_ret] = (uint32)(*(uint8 *)maddr);
+                frame_lp[addr_ret] = (uint32)(*(uint8 *)(maddr));
                 HANDLE_OP_END();
             }
 
@@ -3711,7 +3717,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                 addr = GET_OPERAND(uint32, I32, 2);
                 frame_ip += 4;
                 CHECK_MEMORY_OVERFLOW(1);
-                *(uint8 *)maddr = (uint8)sval;
+                STORE_U8(maddr, (uint8_t)sval);
                 HANDLE_OP_END();
             }
 
@@ -3811,7 +3817,11 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
 #if !defined(OS_ENABLE_HW_BOUND_CHECK)              \
     || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
     || WASM_ENABLE_BULK_MEMORY != 0
+#if WASM_ENABLE_THREAD_MGR == 0
                     linear_mem_size = memory->memory_data_size;
+#else
+                    linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
+#endif
 #endif
                 }
 
@@ -4935,7 +4945,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                         addr = POP_I32();
 
 #if WASM_ENABLE_THREAD_MGR
-                        linear_mem_size = memory->memory_data_size;
+                        linear_mem_size = get_linear_mem_size();
 #endif
 
 #ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -4984,7 +4994,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                         dst = POP_I32();
 
 #if WASM_ENABLE_THREAD_MGR
-                        linear_mem_size = memory->memory_data_size;
+                        linear_mem_size = get_linear_mem_size();
 #endif
 
 #ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -5014,7 +5024,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
                         dst = POP_I32();
 
 #if WASM_ENABLE_THREAD_MGR
-                        linear_mem_size = memory->memory_data_size;
+                        linear_mem_size = get_linear_mem_size();
 #endif
 
 #ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -5846,7 +5856,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
     || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
     || WASM_ENABLE_BULK_MEMORY != 0
             if (memory)
-                linear_mem_size = memory->memory_data_size;
+                linear_mem_size = get_linear_mem_size();
 #endif
             if (wasm_copy_exception(module, NULL))
                 goto got_exception;

+ 53 - 35
core/iwasm/interpreter/wasm_loader.c

@@ -376,7 +376,13 @@ check_utf8_str(const uint8 *str, uint32 len)
 
     while (p < p_end) {
         chr = *p;
-        if (chr < 0x80) {
+
+        if (chr == 0) {
+            LOG_WARNING(
+                "LIMITATION: a string which contains '\\00' is unsupported");
+            return false;
+        }
+        else if (chr < 0x80) {
             p++;
         }
         else if (chr >= 0xC2 && chr <= 0xDF && p + 1 < p_end) {
@@ -2691,23 +2697,31 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
             (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
             error_buf_size);
         if (!sub_module) {
+#if WASM_ENABLE_LIB_WASI_THREADS != 0
+            /* Avoid memory import failure when wasi-threads is enabled
+               and the memory is shared */
+            if (!(declare_max_page_count_flag & 2))
+                return false;
+#else
             return false;
+#endif /* WASM_ENABLE_LIB_WASI_THREADS */
         }
+        else {
+            linked_memory = wasm_loader_resolve_memory(
+                sub_module_name, memory_name, declare_init_page_count,
+                declare_max_page_count, error_buf, error_buf_size);
+            if (!linked_memory) {
+                return false;
+            }
 
-        linked_memory = wasm_loader_resolve_memory(
-            sub_module_name, memory_name, declare_init_page_count,
-            declare_max_page_count, error_buf, error_buf_size);
-        if (!linked_memory) {
-            return false;
+            /**
+             * reset with linked memory limit
+             */
+            memory->import_module = sub_module;
+            memory->import_memory_linked = linked_memory;
+            declare_init_page_count = linked_memory->init_page_count;
+            declare_max_page_count = linked_memory->max_page_count;
         }
-
-        /**
-         * reset with linked memory limit
-         */
-        memory->import_module = sub_module;
-        memory->import_memory_linked = linked_memory;
-        declare_init_page_count = linked_memory->init_page_count;
-        declare_max_page_count = linked_memory->max_page_count;
     }
 #endif
 
@@ -4653,7 +4667,7 @@ load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
 
     read_leb_uint32(p, p_end, name_len);
 
-    if (name_len == 0 || p + name_len > p_end) {
+    if (p + name_len > p_end) {
         set_error_buf(error_buf, error_buf_size, "unexpected end");
         return false;
     }
@@ -5992,19 +6006,23 @@ check_wasi_abi_compatibility(const WASMModule *module,
             return false;
         }
     }
-
-    /* (func (export "_initialize") (...) */
-    initialize = wasm_loader_find_export(
-        module, "", "_initialize", EXPORT_KIND_FUNC, error_buf, error_buf_size);
-    if (initialize) {
-        WASMFuncType *func_type =
-            module->functions[initialize->index - module->import_function_count]
-                ->func_type;
-        if (func_type->param_count || func_type->result_count) {
-            set_error_buf(
-                error_buf, error_buf_size,
-                "the signature of builtin _initialize function is wrong");
-            return false;
+    else {
+        /* (func (export "_initialize") (...) */
+        initialize =
+            wasm_loader_find_export(module, "", "_initialize", EXPORT_KIND_FUNC,
+                                    error_buf, error_buf_size);
+        if (initialize) {
+            WASMFuncType *func_type =
+                module
+                    ->functions[initialize->index
+                                - module->import_function_count]
+                    ->func_type;
+            if (func_type->param_count || func_type->result_count) {
+                set_error_buf(
+                    error_buf, error_buf_size,
+                    "the signature of builtin _initialize function is wrong");
+                return false;
+            }
         }
     }
 
@@ -10183,10 +10201,7 @@ re_scan:
                 }
 
 #if WASM_ENABLE_FAST_INTERP != 0
-                if (opcode == WASM_OP_BLOCK) {
-                    skip_label();
-                }
-                else if (opcode == WASM_OP_LOOP) {
+                if (opcode == WASM_OP_BLOCK || opcode == WASM_OP_LOOP) {
                     skip_label();
                     if (BLOCK_HAS_PARAM(block_type)) {
                         /* Make sure params are in dynamic space */
@@ -10194,8 +10209,10 @@ re_scan:
                                 loader_ctx, false, error_buf, error_buf_size))
                             goto fail;
                     }
-                    (loader_ctx->frame_csp - 1)->code_compiled =
-                        loader_ctx->p_code_compiled;
+                    if (opcode == WASM_OP_LOOP) {
+                        (loader_ctx->frame_csp - 1)->code_compiled =
+                            loader_ctx->p_code_compiled;
+                    }
                 }
                 else if (opcode == WASM_OP_IF) {
                     /* If block has parameters, we should make sure they are in
@@ -10873,7 +10890,8 @@ re_scan:
                         loader_ctx->reftype_map_num--;
                     }
 #endif
-                    if (is_32bit_type(*(loader_ctx->frame_ref - 1))) {
+                    if (is_32bit_type(*(loader_ctx->frame_ref - 1))
+                        || *(loader_ctx->frame_ref - 1) == VALUE_TYPE_ANY) {
                         loader_ctx->frame_ref--;
                         loader_ctx->stack_cell_num--;
 #if WASM_ENABLE_FAST_INTERP != 0

+ 7 - 7
core/iwasm/interpreter/wasm_mini_loader.c

@@ -5851,10 +5851,7 @@ re_scan:
                 }
 
 #if WASM_ENABLE_FAST_INTERP != 0
-                if (opcode == WASM_OP_BLOCK) {
-                    skip_label();
-                }
-                else if (opcode == WASM_OP_LOOP) {
+                if (opcode == WASM_OP_BLOCK || opcode == WASM_OP_LOOP) {
                     skip_label();
                     if (BLOCK_HAS_PARAM(block_type)) {
                         /* Make sure params are in dynamic space */
@@ -5862,8 +5859,10 @@ re_scan:
                                 loader_ctx, false, error_buf, error_buf_size))
                             goto fail;
                     }
-                    (loader_ctx->frame_csp - 1)->code_compiled =
-                        loader_ctx->p_code_compiled;
+                    if (opcode == WASM_OP_LOOP) {
+                        (loader_ctx->frame_csp - 1)->code_compiled =
+                            loader_ctx->p_code_compiled;
+                    }
                 }
                 else if (opcode == WASM_OP_IF) {
                     /* If block has parameters, we should make sure they are in
@@ -6317,7 +6316,8 @@ re_scan:
                             && !cur_block->is_stack_polymorphic));
 
                 if (available_stack_cell > 0) {
-                    if (is_32bit_type(*(loader_ctx->frame_ref - 1))) {
+                    if (is_32bit_type(*(loader_ctx->frame_ref - 1))
+                        || *(loader_ctx->frame_ref - 1) == VALUE_TYPE_ANY) {
                         loader_ctx->frame_ref--;
                         loader_ctx->stack_cell_num--;
 #if WASM_ENABLE_FAST_INTERP != 0

+ 12 - 1
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

@@ -1155,6 +1155,11 @@ wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds,
     if (error != 0)
         return error;
 
+    if (fo->type == __WASI_FILETYPE_DIRECTORY) {
+        fd_object_release(exec_env, fo);
+        return __WASI_EBADF;
+    }
+
     error = os_fadvise(fo->file_handle, offset, len, advice);
 
     fd_object_release(exec_env, fo);
@@ -1886,7 +1891,13 @@ wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env,
     if ((fstflags
          & ~(__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW
              | __WASI_FILESTAT_SET_MTIM | __WASI_FILESTAT_SET_MTIM_NOW))
-        != 0)
+            != 0
+        || (fstflags
+            & (__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW))
+               == (__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW)
+        || (fstflags
+            & (__WASI_FILESTAT_SET_MTIM | __WASI_FILESTAT_SET_MTIM_NOW))
+               == (__WASI_FILESTAT_SET_MTIM | __WASI_FILESTAT_SET_MTIM_NOW))
         return __WASI_EINVAL;
 
     struct fd_object *fo;

+ 22 - 16
core/iwasm/libraries/thread-mgr/thread_manager.c

@@ -488,10 +488,25 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
         return NULL;
     }
 
+    if (!(new_module_inst = wasm_runtime_instantiate_internal(
+              module, module_inst, exec_env, stack_size, 0, NULL, 0))) {
+        return NULL;
+    }
+
+    /* Set custom_data to new module instance */
+    wasm_runtime_set_custom_data_internal(
+        new_module_inst, wasm_runtime_get_custom_data(module_inst));
+
+    wasm_native_inherit_contexts(new_module_inst, module_inst);
+
+    if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst))) {
+        goto fail1;
+    }
+
     os_mutex_lock(&cluster->lock);
 
     if (cluster->has_exception || cluster->processing) {
-        goto fail1;
+        goto fail2;
     }
 
 #if WASM_ENABLE_INTERP != 0
@@ -508,21 +523,11 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
     }
 #endif
 
-    if (!(new_module_inst = wasm_runtime_instantiate_internal(
-              module, module_inst, exec_env, stack_size, 0, NULL, 0))) {
-        goto fail1;
-    }
-
-    /* Set custom_data to new module instance */
-    wasm_runtime_set_custom_data_internal(
-        new_module_inst, wasm_runtime_get_custom_data(module_inst));
-
-    wasm_native_inherit_contexts(new_module_inst, module_inst);
-
     new_exec_env = wasm_exec_env_create_internal(new_module_inst,
                                                  exec_env->wasm_stack_size);
-    if (!new_exec_env)
+    if (!new_exec_env) {
         goto fail2;
+    }
 
     if (!allocate_aux_stack(exec_env, &aux_stack_start, &aux_stack_size)) {
         LOG_ERROR("thread manager error: "
@@ -539,8 +544,9 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
     /* Inherit suspend_flags of parent thread */
     new_exec_env->suspend_flags.flags = exec_env->suspend_flags.flags;
 
-    if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
+    if (!wasm_cluster_add_exec_env(cluster, new_exec_env)) {
         goto fail4;
+    }
 
     os_mutex_unlock(&cluster->lock);
 
@@ -552,9 +558,9 @@ fail4:
 fail3:
     wasm_exec_env_destroy_internal(new_exec_env);
 fail2:
-    wasm_runtime_deinstantiate_internal(new_module_inst, true);
-fail1:
     os_mutex_unlock(&cluster->lock);
+fail1:
+    wasm_runtime_deinstantiate_internal(new_module_inst, true);
 
     return NULL;
 }

+ 4 - 4
core/shared/platform/common/posix/posix_file.c

@@ -479,7 +479,7 @@ os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
 
     // Allocate a single buffer to fit all data.
     size_t totalsize = 0;
-    for (size_t i = 0; i < iovcnt; ++i)
+    for (int i = 0; i < iovcnt; ++i)
         totalsize += iov[i].buf_len;
 
     char *buf = BH_MALLOC(totalsize);
@@ -498,7 +498,7 @@ os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
 
     // Copy data back to vectors.
     size_t bufoff = 0;
-    for (size_t i = 0; i < iovcnt; ++i) {
+    for (int i = 0; i < iovcnt; ++i) {
         if (bufoff + iov[i].buf_len < (size_t)len) {
             memcpy(iov[i].buf, buf + bufoff, iov[i].buf_len);
             bufoff += iov[i].buf_len;
@@ -533,14 +533,14 @@ os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
     else {
         // Allocate a single buffer to fit all data.
         size_t totalsize = 0;
-        for (size_t i = 0; i < iovcnt; ++i)
+        for (int i = 0; i < iovcnt; ++i)
             totalsize += iov[i].buf_len;
         char *buf = BH_MALLOC(totalsize);
         if (buf == NULL) {
             return __WASI_ENOMEM;
         }
         size_t bufoff = 0;
-        for (size_t i = 0; i < iovcnt; ++i) {
+        for (int i = 0; i < iovcnt; ++i) {
             memcpy(buf + bufoff, iov[i].buf, iov[i].buf_len);
             bufoff += iov[i].buf_len;
         }

+ 7 - 7
core/shared/utils/bh_bitmap.h

@@ -58,7 +58,7 @@ bh_bitmap_delete(bh_bitmap *bitmap)
  * @return true if the index is in range, false otherwise
  */
 static inline bool
-bh_bitmap_is_in_range(bh_bitmap *bitmap, unsigned n)
+bh_bitmap_is_in_range(bh_bitmap *bitmap, uintptr_t n)
 {
     return n >= bitmap->begin_index && n < bitmap->end_index;
 }
@@ -72,9 +72,9 @@ bh_bitmap_is_in_range(bh_bitmap *bitmap, unsigned n)
  * @return value of the bit
  */
 static inline int
-bh_bitmap_get_bit(bh_bitmap *bitmap, unsigned n)
+bh_bitmap_get_bit(bh_bitmap *bitmap, uintptr_t n)
 {
-    unsigned idx = n - bitmap->begin_index;
+    uintptr_t idx = n - bitmap->begin_index;
     bh_assert(n >= bitmap->begin_index && n < bitmap->end_index);
     return (bitmap->map[idx / 8] >> (idx % 8)) & 1;
 }
@@ -86,9 +86,9 @@ bh_bitmap_get_bit(bh_bitmap *bitmap, unsigned n)
  * @param n the n-th bit to be set
  */
 static inline void
-bh_bitmap_set_bit(bh_bitmap *bitmap, unsigned n)
+bh_bitmap_set_bit(bh_bitmap *bitmap, uintptr_t n)
 {
-    unsigned idx = n - bitmap->begin_index;
+    uintptr_t idx = n - bitmap->begin_index;
     bh_assert(n >= bitmap->begin_index && n < bitmap->end_index);
     bitmap->map[idx / 8] |= 1 << (idx % 8);
 }
@@ -100,9 +100,9 @@ bh_bitmap_set_bit(bh_bitmap *bitmap, unsigned n)
  * @param n the n-th bit to be cleared
  */
 static inline void
-bh_bitmap_clear_bit(bh_bitmap *bitmap, unsigned n)
+bh_bitmap_clear_bit(bh_bitmap *bitmap, uintptr_t n)
 {
-    unsigned idx = n - bitmap->begin_index;
+    uintptr_t idx = n - bitmap->begin_index;
     bh_assert(n >= bitmap->begin_index && n < bitmap->end_index);
     bitmap->map[idx / 8] &= ~(1 << (idx % 8));
 }

+ 2 - 2
core/version.h

@@ -6,6 +6,6 @@
 #ifndef _WAMR_VERSION_H_
 #define _WAMR_VERSION_H_
 #define WAMR_VERSION_MAJOR 1
-#define WAMR_VERSION_MINOR 2
-#define WAMR_VERSION_PATCH 3
+#define WAMR_VERSION_MINOR 3
+#define WAMR_VERSION_PATCH 0
 #endif

+ 1 - 1
doc/socket_api.md

@@ -58,7 +58,7 @@ enabled.
 
 _iwasm_ accepts address ranges via an option, `--addr-pool`, to implement
 the capability control. All IP address the WebAssembly application may need to `bind()` or `connect()`
-should be announced first. Every IP address should be in CIRD notation.
+should be announced first. Every IP address should be in CIDR notation.
 
 ```bash
 $ iwasm --addr-pool=1.2.3.4/15,2.3.4.6/16 socket_example.wasm

+ 1 - 1
product-mini/platforms/common/libc_wasi.c

@@ -47,7 +47,7 @@ libc_wasi_print_help()
            "--map-dir=<guest-path2::host-path2>\n");
     printf("  --addr-pool=<addrs>      Grant wasi access to the given network "
            "addresses in\n");
-    printf("                           CIRD notation to the program, seperated "
+    printf("                           CIDR notation to the program, seperated "
            "with ',',\n");
     printf("                           for example:\n");
     printf("                             --addr-pool=1.2.3.4/15,2.3.4.5/16\n");

+ 1 - 1
product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp

@@ -228,7 +228,7 @@ print_help()
     printf("                         to the program, for example:\n");
     printf("                           --dir=<dir1> --dir=<dir2>\n");
     printf("  --addr-pool=           Grant wasi access to the given network addresses in\n");
-    printf("                         CIRD notation to the program, seperated with ',',\n");
+    printf("                         CIDR notation to the program, seperated with ',',\n");
     printf("                         for example:\n");
     printf("                           --addr-pool=1.2.3.4/15,2.3.4.5/16\n");
     printf("  --max-threads=n        Set maximum thread number per cluster, default is 4\n");

+ 1 - 1
samples/basic/wasm-apps/testapp.c

@@ -58,7 +58,7 @@ float_to_string(float n, char *res, int res_size, int afterpoint)
         // is needed to handle cases like 233.007
         fpart = fpart * get_pow(10, afterpoint);
 
-        intToStr((int)fpart, res + i + 1, sizeof(res + i + 1), afterpoint);
+        intToStr((int)fpart, res + i + 1, res_size - i - 1, afterpoint);
     }
 }
 

+ 6 - 2
samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c

@@ -10,8 +10,12 @@
 #include <string.h>
 #include "drivers/spi.h"
 
-#include "zephyr.h"
-#include "kernel.h"
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
+#include <zephyr.h>
+#include <kernel.h>
+#else
+#include <zephyr/kernel.h>
+#endif
 
 #if USE_XPT2046
 

+ 5 - 0
samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h

@@ -7,7 +7,12 @@
 #define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
 #include "board_config.h"
 #include <autoconf.h>
+
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
 #include <zephyr.h>
+#else
+#include <zephyr/kernel.h>
+#endif
 
 #define ILI9340_CMD_ENTER_SLEEP 0x10
 #define ILI9340_CMD_EXIT_SLEEP 0x11

+ 5 - 0
samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c

@@ -31,7 +31,12 @@ xpt2046_init(void);
 extern void
 wgl_init();
 
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
 #include <zephyr.h>
+#else
+#include <zephyr/kernel.h>
+#endif
+
 #include <drivers/uart.h>
 #include <device.h>
 

+ 6 - 2
samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c

@@ -10,8 +10,12 @@
 #include <string.h>
 #include "drivers/spi.h"
 
-#include "zephyr.h"
-#include "kernel.h"
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
+#include <zephyr.h>
+#include <kernel.h>
+#else
+#include <zephyr/kernel.h>
+#endif
 
 #if USE_XPT2046
 

+ 5 - 0
samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h

@@ -7,7 +7,12 @@
 #define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
 #include "board_config.h"
 #include <autoconf.h>
+
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
 #include <zephyr.h>
+#else
+#include <zephyr/kernel.h>
+#endif
 
 #define ILI9340_CMD_ENTER_SLEEP 0x10
 #define ILI9340_CMD_EXIT_SLEEP 0x11

+ 5 - 0
samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c

@@ -16,7 +16,12 @@
 #include "connection_native_api.h"
 #include "display_indev.h"
 
+#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
 #include <zephyr.h>
+#else
+#include <zephyr/kernel.h>
+#endif
+
 #include <drivers/uart.h>
 #include <device.h>
 

+ 3 - 3
samples/multi-module/README.md

@@ -9,12 +9,12 @@ $ mkdir build
 $ cd build
 $ cmake ..
 $ make
-$ # It will build multi-module runtime and 
+$ # It will build multi_module runtime and 
 $ # wasm file under the ./build .
 $ # If you have built wamrc,
 $ # aot file will also genrate.
-$ ./multi-module mC.wasm
+$ ./multi_module mC.wasm
 $ ...
-$ ./multi-module mC.aot
+$ ./multi_module mC.aot
 $ ...
 

+ 2 - 2
samples/spawn-thread/CMakeLists.txt

@@ -45,9 +45,9 @@ endif ()
 set(WAMR_BUILD_INTERP 1)
 set(WAMR_BUILD_AOT 1)
 set(WAMR_BUILD_JIT 0)
-set(WAMR_BUILD_LIBC_BUILTIN 1)
 set(WAMR_BUILD_FAST_INTERP 1)
-set(WAMR_BUILD_LIB_PTHREAD 1)
+set(WAMR_BUILD_THREAD_MGR 1)
+set(WAMR_BUILD_SHARED_MEMORY 1)
 
 # compiling and linking flags
 if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))

+ 1 - 0
samples/spawn-thread/wasm-apps/CMakeLists.txt

@@ -29,6 +29,7 @@ set (DEFINED_SYMBOLS
 set (CMAKE_EXE_LINKER_FLAGS
     "-Wl,--shared-memory,--max-memory=131072,       \
     -Wl,--no-entry,--strip-all,--export=sum,        \
+    -Wl,--export=return_bss,        \
     -Wl,--export=__heap_base,--export=__data_end    \
     -Wl,--export=__wasm_call_ctors  \
     -Wl,--allow-undefined-file=${DEFINED_SYMBOLS}"

+ 12 - 1
samples/spawn-thread/wasm-apps/sum.c

@@ -3,6 +3,17 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
+/*
+ * have something in bss so that llvm synthesizes
+ * wasm start function for this module.
+ */
+char *
+return_bss()
+{
+    static char bss[4096];
+    return bss;
+}
+
 int
 sum(int start, int length)
 {
@@ -13,4 +24,4 @@ sum(int start, int length)
     }
 
     return sum;
-}
+}

+ 14 - 3
tests/wamr-test-suites/spec-test-script/runtest.py

@@ -1075,6 +1075,17 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = '
     # exception isn't thrown in several cases
     cmd.append("--disable-llvm-lto")
 
+    # Bounds checks is disabled by default for 64-bit targets, to
+    # use the hardware based bounds checks. But it is not supported
+    # in QEMU with NuttX.
+    # Enable bounds checks explicitly for all targets if running in QEMU.
+    if opts.qemu:
+        cmd.append("--bounds-checks=1")
+
+    # RISCV64 requires -mcmodel=medany, which can be set by --size-level=1
+    if test_target.startswith("riscv64"):
+        cmd.append("--size-level=1")
+
     cmd += ["-o", aot_tempfile, wasm_tempfile]
 
     log("Running: %s" % " ".join(cmd))
@@ -1103,13 +1114,13 @@ def run_wasm_with_repl(wasm_tempfile, aot_tempfile, opts, r):
             cmd = "qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel".split()
             cmd.append(opts.qemu_firmware)
         elif opts.target.startswith("thumbv7"):
-            cmd = "qemu-system-arm -semihosting -M sabrelite -m 1024 -smp 4 -nographic -kernel".split()
+            cmd = "qemu-system-arm -semihosting -M sabrelite -m 1024 -smp 1 -nographic -kernel".split()
             cmd.append(opts.qemu_firmware)
         elif opts.target.startswith("riscv32"):
-            cmd = "qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 -nographic -bios none -kernel".split()
+            cmd = "qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 1 -nographic -bios none -kernel".split()
             cmd.append(opts.qemu_firmware)
         elif opts.target.startswith("riscv64"):
-            cmd = "qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 -nographic -bios none -kernel".split()
+            cmd = "qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 1 -nographic -bios none -kernel".split()
             cmd.append(opts.qemu_firmware)
         else:
             raise Exception("Unknwon target for QEMU: %s" % opts.target)

+ 1 - 1
tests/wamr-test-suites/test_wamr.sh

@@ -706,7 +706,7 @@ function build_iwasm_with_cfg()
         && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
         && cd build \
         && cmake $* .. \
-        && cmake --build . -j 4 --config RelWithDebInfo
+        && cmake --build . -j 4 --config RelWithDebInfo --target iwasm
     fi
 
     if [ "$?" != 0 ];then

+ 1 - 0
tests/wamr-test-suites/tsan_suppressions.txt

@@ -1,6 +1,7 @@
 # Proposing to accept this risk for now. It might be wasi-libc related.
 # https://github.com/bytecodealliance/wasm-micro-runtime/pull/1963#issuecomment-1455342931
 race:STORE_U32
+race:STORE_U8
 
 # Suppressing signal-unsafe inside of a signal for AOT mode 
 # see https://github.com/bytecodealliance/wasm-micro-runtime/issues/2248#issuecomment-1630189656