Compare commits

...

19 Commits

Author SHA1 Message Date
liang.he@intel.com
797a442ed1 Enhance build configuration to support optional gc
There will be two sets of binaries for iwasm and wamrc.
One set without a suffix indicates there is no GC support.
Another set with the suffixes "-gc" and "-gc-eh" includes GC support.
Users cannot disable GC through command line options; they need to
choose the appropriate set to use.
2025-08-31 08:33:04 +00:00
Oscar Spencer
6c3f6fd017
Update note on WAMR_BUILD_LIBC_UVWASI for Windows (#4583) 2025-08-27 13:57:30 +08:00
dependabot[bot]
42851ca821
build(deps): Bump github/codeql-action from 3.29.10 to 3.29.11 (#4579)
Some checks failed
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $FAST_INTERP_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $AOT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $CLASSIC_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $MULTI_TIER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}, macos-14) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, macos-13) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $AOT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $CLASSIC_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_JIT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $SIMD_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $XIP_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, fast-jit, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / build_wamrc (${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}, windows-latest) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.10 to 3.29.11.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Commits](https://github.com/github/codeql-action/compare/v3.29.10...v3.29.11)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-27 07:31:06 +08:00
dependabot[bot]
1a56951a6a
build(deps): Bump requests from 2.32.4 to 2.32.5 in /build-scripts (#4580)
Bumps [requests](https://github.com/psf/requests) from 2.32.4 to 2.32.5.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.32.4...v2.32.5)

---
updated-dependencies:
- dependency-name: requests
  dependency-version: 2.32.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-27 07:16:41 +08:00
liang.he
9cb1cc4af6
fix: cast file descriptor to size_t for comparison in fd_prestats functions (#4582)
```
comparison of integer expressions of different signedness:
  ‘__wasi_fd_t’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’}
  [-Werror=sign-compare]
  288 |     if (fd >= pt->size)
```
2025-08-27 07:15:08 +08:00
liang.he
0b97d0cb14
Merge dev/zephyr_file_socket into main (#4347)
Some checks failed
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $FAST_INTERP_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $AOT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $CLASSIC_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $MULTI_TIER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}, macos-14) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, macos-13) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $AOT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $CLASSIC_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_JIT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $SIMD_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $XIP_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, fast-jit, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / build_wamrc (${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}, windows-latest) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
zephyr: Enable WASI support for file system and sockets on zephyr (#3633)

This work also implements the WASI support on Zephyr.

* Added os_is_* methods for stdin/stdout/stderr.  Fixed issues in os_renameat
* Zephyr platform fixes for WASI sockets Addressed numerous of build warnings on Zephyr
* Updated `os_writev` to use `fwrite` for STDOUT/STDERR
* Temporarily reverted change to `writev` to work around an issue.
* Fixes: fstat, fstatat, and unlink
* Add initial support for directories in os_openat. Partial implementation — just avoids a hard fault.
* Directory support WIP. readdir works but I think we have a memory leak somewhere
* Fix: always use standard stream fds. Fix unlinkat and renameat. fd 0, 1, and 2 will always be supplied for standard streams. Unlinkat and renameat work exclusively based on supplied paths.
* Fix: use macro for free()
* Added a temporary workaround for issue identified in PR#4377
* Fixed reference to file descriptor and cleaned up dead/commented code.

Note that some comments haven't been addressed and will be fixed in the
further patches.

Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Co-authored-by: Lucas Abad <149054121+lucasAbadFr@users.noreply.github.com>
Co-authored-by: Stephen Berard <srberard@users.noreply.github.com>
Co-authored-by: Dan Kouba <dan@atym.io>
2025-08-25 16:55:23 +08:00
Zhenwei Jin
ddd3500602
update doc to state support for export/import mut globals (#4562)
Some checks failed
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $FAST_INTERP_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $AOT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $CLASSIC_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $MULTI_TIER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}, macos-14) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, macos-13) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $AOT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $CLASSIC_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_JIT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $SIMD_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $XIP_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, fast-jit, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / build_wamrc (${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}, windows-latest) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
2025-08-24 06:55:27 +08:00
Marcin Kolny
58fae578e7
Merge pull request #4568 from yamt/nn-51
Some checks failed
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $FAST_INTERP_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_iwasm (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, -DWAMR_DISABLE_HW_BOUND_CHECK=1, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13, darwin) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $AOT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $CLASSIC_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_INTERP_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $FAST_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_EAGER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $LLVM_LAZY_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_wasm_c_api (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, $MULTI_TIER_JIT_BUILD_OPTIONS, macos-13) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}, macos-14) (push) Has been cancelled
compilation on macos / build_samples_others (${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}, macos-13) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $AOT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $CLASSIC_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_JIT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $SIMD_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $XIP_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, fast-jit, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / build_wamrc (${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}, windows-latest) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (classic-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $DEFAULT_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $THREADS_TEST_OPTIONS) (push) Has been cancelled
compilation on windows-latest / test (fast-interp, $WASI_TEST_OPTIONS) (push) Has been cancelled
core/iwasm/libraries/wasi-nn/test/build.sh: set -e
2025-08-20 20:53:35 +02:00
Marcin Kolny
088197c0c3
Merge pull request #4573 from jammar1/jammar1/android-xip
Add Android macro check for indirect mode
2025-08-20 20:51:53 +02:00
James Marsh
9ee44bf2d0 Add Android macro check for indirect mode 2025-08-20 13:13:56 +01:00
dependabot[bot]
962511226f
build(deps): Bump actions/checkout from 3 to 5 (#4567)
Some checks failed
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Blocked by required conditions
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_JIT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $SIMD_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $XIP_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, classic-interp, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, fast-jit, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / build_llvm_libraries_on_windows (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_AOT=0) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=0) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_CUSTOM_NAME_SECTION=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_DEBUG_INTERP=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_LIB_PTHREAD=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_LIB_WASI_THREADS=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_REF_TYPES=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_SIMD=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_TAIL_CALL=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_DISABLE_HW_BOUND_CHECK=1) (push) Waiting to run
compilation on windows-latest / build_wamrc (${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}, windows-latest) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $THREADS_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $WASI_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $THREADS_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $WASI_TEST_OPTIONS) (push) Blocked by required conditions
compilation on zephyr / smoke_test (push) Waiting to run
hadolint dockerfiles / run-hadolint-on-dockerfiles (push) Has been cancelled
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](https://github.com/actions/checkout/compare/v3...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-20 09:24:38 +08:00
dependabot[bot]
6e8802f7b0
build(deps): Bump github/codeql-action from 3.29.8 to 3.29.10 (#4566)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.8 to 3.29.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Commits](https://github.com/github/codeql-action/compare/v3.29.8...v3.29.10)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.10
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-20 08:25:44 +08:00
YAMAMOTO Takashi
735b510437 core/iwasm/libraries/wasi-nn/test/build.sh: set -e 2025-08-19 14:58:27 +09:00
YAMAMOTO Takashi
80007d5b1f
ADOPTERS.md: Add EVP (#4554)
Some checks are pending
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $CLASSIC_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Blocked by required conditions
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_INTERP_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Blocked by required conditions
compilation on SGX / run_samples_file (-DWAMR_BUILD_SGX_IPFS=1, $FAST_JIT_BUILD_OPTIONS, ${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, linux-sgx) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $SIMD_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, aot, $XIP_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, classic-interp, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on SGX / spec_test_default (${{ needs.build_llvm_libraries.outputs.cache_key }}, ubuntu-22.04, fast-jit, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / build_llvm_libraries_on_windows (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_AOT=0) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=0) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_CUSTOM_NAME_SECTION=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_DEBUG_INTERP=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_LIB_PTHREAD=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_LIB_WASI_THREADS=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_REF_TYPES=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_SIMD=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_BUILD_TAIL_CALL=1) (push) Waiting to run
compilation on windows-latest / build_iwasm (-DWAMR_DISABLE_HW_BOUND_CHECK=1) (push) Waiting to run
compilation on windows-latest / build_wamrc (${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}, windows-latest) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $THREADS_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (classic-interp, $WASI_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $DEFAULT_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $THREADS_TEST_OPTIONS) (push) Blocked by required conditions
compilation on windows-latest / test (fast-interp, $WASI_TEST_OPTIONS) (push) Blocked by required conditions
compilation on zephyr / smoke_test (push) Waiting to run
2025-08-19 09:48:16 +08:00
Liu Jia
b0dae624a1
add comments about AOT crash when calling unlinked import func (#4559) 2025-08-19 08:53:51 +08:00
Zhenwei Jin
be3f1f88fe
remove duplicate parent type index validation (#4556)
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
2025-08-19 08:53:44 +08:00
Zhenwei Jin
ab2ff4a56d
add rec idx and rec count validation in aot loader (#4555)
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
2025-08-19 08:53:37 +08:00
Zhenwei Jin
d0c636bd80
fix integer overflow in gc threshold calculation (#4546)
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
2025-08-19 08:53:28 +08:00
YAMAMOTO Takashi
c661592edd
wasi_nn_onnx.cpp: fix debug build (#4564) 2025-08-19 08:23:00 +08:00
96 changed files with 10191 additions and 374 deletions

View File

@ -26,7 +26,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Build and save Docker image(wasm-debug-server:${{ inputs.ver_num }}) to tar file
run: |

View File

@ -104,7 +104,7 @@ jobs:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: get cached LLVM libraries
id: retrieve_llvm_libs

View File

@ -45,7 +45,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install dependencies for non macos-14
if: inputs.os != 'macos-14'

View File

@ -55,7 +55,7 @@ jobs:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: download and install wasi-sdk
run: |

View File

@ -45,7 +45,7 @@ jobs:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: download wamr-app-framework
run: |

View File

@ -24,7 +24,7 @@ jobs:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Use Node.js 18.x
uses: actions/setup-node@v4

View File

@ -28,7 +28,7 @@ jobs:
os: [ubuntu-22.04]
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt

View File

@ -37,11 +37,19 @@ permissions:
jobs:
build:
runs-on: ${{ inputs.runner }}
strategy:
matrix:
include:
- build_options: ""
suffix: ""
- build_options: "-DWAMR_BUILD_GC=1"
suffix: "-gc"
permissions:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: get cached LLVM libraries
id: retrieve_llvm_libs
@ -58,7 +66,7 @@ jobs:
- name: generate wamrc binary release
run: |
cmake -S . -B build
cmake -S . -B build ${{ matrix.build_options }}
cmake --build build --config Release --parallel 4
working-directory: wamr-compiler
@ -89,17 +97,17 @@ jobs:
- name: Compress the binary on Windows
if: inputs.runner == 'windows-latest' && inputs.release
run: |
tar -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
Compress-Archive -Path wamrc.exe -DestinationPath wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
mv wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
tar -czf wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
Compress-Archive -Path wamrc.exe -DestinationPath wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
mv wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
working-directory: wamr-compiler/build/Release
- name: compress the binary on non-Windows
if: inputs.runner != 'windows-latest' && inputs.release
run: |
# Follow the symlink to the actual binary file
tar --dereference -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
tar --dereference -czf wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
zip wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
working-directory: wamr-compiler/build
- name: upload release tar.gz
@ -109,8 +117,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: wamr-compiler/build/wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: wamrc-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_path: wamr-compiler/build/wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_content_type: application/x-gzip
- name: upload release zip
@ -120,6 +128,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: wamr-compiler/build/wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: wamrc-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_path: wamr-compiler/build/wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_content_type: application/zip

View File

@ -14,7 +14,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: cmake execute to generate version.h
run: cmake -B build_version -S .

View File

@ -47,13 +47,13 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v5
with:
submodules: recursive
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3.29.8
uses: github/codeql-action/init@v3.29.11
with:
languages: ${{ matrix.language }}
@ -70,7 +70,7 @@ jobs:
- run: |
./.github/scripts/codeql_buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3.29.8
uses: github/codeql-action/analyze@v3.29.11
with:
category: "/language:${{matrix.language}}"
upload: false
@ -99,7 +99,7 @@ jobs:
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
- name: Upload CodeQL results to code scanning
uses: github/codeql-action/upload-sarif@v3.29.8
uses: github/codeql-action/upload-sarif@v3.29.11
with:
sarif_file: ${{ steps.step1.outputs.sarif-output }}
category: "/language:${{matrix.language}}"

View File

@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 0

View File

@ -101,7 +101,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
# since jobs.id can't contain the dot character
# it is hard to use `format` to assemble the cache key
@ -269,7 +269,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
# only download llvm cache when needed
- name: Get LLVM libraries
@ -327,7 +327,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -384,7 +384,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -417,7 +417,6 @@ jobs:
[
build_iwasm,
build_llvm_libraries_on_ubuntu_2204,
build_wamrc,
]
runs-on: ${{ matrix.os }}
strategy:
@ -440,7 +439,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -464,14 +463,6 @@ jobs:
with:
os: ${{ matrix.os }}
- name: Build wamrc
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
- name: Build Sample [wasm-c-api]
run: |
VERBOSE=1
@ -502,7 +493,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -665,7 +656,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Set-up OCaml
uses: ocaml/setup-ocaml@v3

View File

@ -86,7 +86,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -190,7 +190,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
# only download llvm cache when needed
- name: Get LLVM libraries
@ -243,7 +243,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -301,7 +301,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt

View File

@ -85,21 +85,21 @@ jobs:
steps:
- name: Checkout NuttX
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: apache/nuttx
ref: releases/12.9
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: apache/nuttx-apps
ref: releases/12.9
path: apps
- name: Checkout WAMR
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: ${{ github.repository }}
path: apps/interpreters/wamr/wamr
@ -122,7 +122,7 @@ jobs:
run: make -j$(nproc) EXTRAFLAGS=-Werror
- name: Checkout Bloaty
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: google/bloaty
submodules: recursive

View File

@ -116,7 +116,7 @@ jobs:
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install SGX SDK and necessary libraries
uses: ./.github/actions/install-linux-sgx
@ -159,7 +159,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
@ -255,7 +255,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
if: matrix.running_mode == 'aot'

View File

@ -85,7 +85,7 @@ jobs:
"-DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1",
]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: clone uvwasi library
if: ${{ !contains(matrix.build_options, '-DWAMR_BUILD_LIBC_UVWASI=0') }}
@ -109,7 +109,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
# since jobs.id can't contain the dot character
# it is hard to use `format` to assemble the cache key
@ -151,7 +151,7 @@ jobs:
]
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: download and install wasi-sdk
if: matrix.test_option == '$WASI_TEST_OPTIONS'

View File

@ -78,7 +78,7 @@ jobs:
# └─── application/ --> DUMMY. keep west_lite.yml here
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v5
with:
path: modules/wasm-micro-runtime

View File

@ -29,7 +29,7 @@ jobs:
contents: write # create and push tags
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
# Full git history is needed to get a proper list of commits and tags
with:
fetch-depth: 0

View File

@ -37,7 +37,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
# on default, hadolint will fail on warnings and errors
- name: Run hadolint on dockerfiles

View File

@ -67,7 +67,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
# since jobs.id can't contain the dot character
# it is hard to use `format` to assemble the cache key
@ -233,7 +233,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
# only download llvm cache when needed
- name: Get LLVM libraries
@ -387,7 +387,7 @@ jobs:
sanitizer: asan
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -440,7 +440,7 @@ jobs:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
@ -626,7 +626,7 @@ jobs:
sanitizer: ubsan
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install-wasi-sdk-wabt
if: matrix.test_option == '$WASI_TEST_OPTIONS'

View File

@ -55,7 +55,7 @@ jobs:
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: prepare the release note
run: |

View File

@ -34,7 +34,7 @@ jobs:
contents: write # for creating realease and uploading release artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
# Full git history is needed to get a proper list of commits and tags
with:
fetch-depth: 0

View File

@ -143,21 +143,21 @@ jobs:
# Note: we use an unreleased version nuttx for xtensa because
# 12.4 doesn't contain necessary esp32s3 changes.
- name: Checkout NuttX
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: apache/nuttx
ref: ${{ matrix.target_config.target == 'xtensa' && '985d395b025cf2012b22f6bb4461959fa6d87645' || 'releases/12.9' }}
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: apache/nuttx-apps
ref: ${{ matrix.target_config.target == 'xtensa' && '2ef3eb25c0cec944b13792185f7e5d5a05990d5f' || 'releases/12.9' }}
path: apps
- name: Checkout WAMR
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: ${{ github.repository }}
path: apps/interpreters/wamr/wamr

View File

@ -34,7 +34,7 @@ jobs:
steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v3.1.0
with:
persist-credentials: false
@ -60,6 +60,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4474150eef8c855ab74a7f19f3ae525e469d2de6
uses: github/codeql-action/upload-sarif@5b49155c7f37b5ec074ffd26b428e6b64b1bf412
with:
sarif_file: results.sarif

View File

@ -30,7 +30,7 @@ jobs:
os: [ubuntu-22.04, macos-13, macos-14]
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt

View File

@ -26,6 +26,7 @@ _The list is in alphabetical order._
| Project | Reference |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [Apache Teaclave](https://github.com/apache/incubator-teaclave) | https://github.com/apache/incubator-teaclave/blob/master/docs/executing-wasm.md |
| [Edge Virtualization Platform](https://github.com/SonySemiconductorSolutions/edge-virtualization-platform) | https://github.com/SonySemiconductorSolutions/edge-virtualization-platform |
| [Envoy](https://github.com/envoyproxy/envoy) | https://github.com/envoyproxy/envoy/blob/main/docs/root/configuration/other_features/wasm.rst |
| [faasm](https://github.com/faasm/faasm) | https://github.com/faasm/faasm/blob/main/docs/source/wamr.md |
| [fluent-bit](https://github.com/fluent/fluent-bit) | https://github.com/fluent/fluent-bit/tree/master/lib/wasm-micro-runtime-WAMR-1.3.0 |

View File

@ -732,28 +732,28 @@ endif ()
message (
"-- About Wasm Proposals:\n"
" Always-on:\n"
" \"Import/Export of Mutable Globals\"\n"
" \"Multi-value\"\n"
" \"Non-trapping float-to-int conversions\"\n"
" \"Sign-extension operators\"\n"
" \"Non-trapping float-to-int Conversions\"\n"
" \"Sign-extension Operators\"\n"
" \"WebAssembly C and C++ API\"\n"
" Configurable. 0 is OFF. 1 is ON:\n"
" \"Bulk Memory Operation\" via WAMR_BUILD_BULK_MEMORY: ${WAMR_BUILD_BULK_MEMORY}\n"
" \"Extended Constant Expressions\" via WAMR_BUILD_EXTENDED_CONST_EXPR: ${WAMR_BUILD_EXTENDED_CONST_EXPR}\n"
" \"Fixed-width SIMD\" via WAMR_BUILD_SIMD: ${WAMR_BUILD_SIMD}\n"
" \"Garbage collection\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n"
" \"Legacy Exception handling\" via WAMR_BUILD_EXCE_HANDLING: ${WAMR_BUILD_EXCE_HANDLING}\n"
" \"Garbage Collection\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n"
" \"Legacy Exception Handling\" via WAMR_BUILD_EXCE_HANDLING: ${WAMR_BUILD_EXCE_HANDLING}\n"
" \"Memory64\" via WAMR_BUILD_MEMORY64: ${WAMR_BUILD_MEMORY64}\n"
" \"Multiple memories\" via WAMR_BUILD_MULTI_MEMORY: ${WAMR_BUILD_MULTI_MEMORY}\n"
" \"Multiple Memories\" via WAMR_BUILD_MULTI_MEMORY: ${WAMR_BUILD_MULTI_MEMORY}\n"
" \"Reference Types\" via WAMR_BUILD_REF_TYPES: ${WAMR_BUILD_REF_TYPES}\n"
" \"Reference-Typed Strings\" via WAMR_BUILD_STRINGREF: ${WAMR_BUILD_STRINGREF}\n"
" \"Tail call\" via WAMR_BUILD_TAIL_CALL: ${WAMR_BUILD_TAIL_CALL}\n"
" \"Tail Call\" via WAMR_BUILD_TAIL_CALL: ${WAMR_BUILD_TAIL_CALL}\n"
" \"Threads\" via WAMR_BUILD_SHARED_MEMORY: ${WAMR_BUILD_SHARED_MEMORY}\n"
" \"Typed Function References\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n"
" Unsupported (>= Phase4):\n"
" \"Branch Hinting\"\n"
" \"Custom Annotation Syntax in the Text Format\"\n"
" \"Exception handling\"\n"
" \"Import/Export of Mutable Globals\"\n"
" \"Exception Handling\"\n"
" \"JS String Builtins\"\n"
" \"Relaxed SIMD\"\n"
)

View File

@ -1 +1 @@
requests==2.32.4
requests==2.32.5

View File

@ -1807,8 +1807,12 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
read_uint16(buf, buf_end, rec_count);
read_uint16(buf, buf_end, rec_idx);
#if WASM_ENABLE_AOT_VALIDATOR != 0
if (rec_idx > i) {
set_error_buf(error_buf, error_buf_size, "invalid rec_idx");
if (rec_count > module->type_count) {
set_error_buf(error_buf, error_buf_size, "invalid rec count");
goto fail;
}
if (rec_idx > i || rec_idx >= rec_count) {
set_error_buf(error_buf, error_buf_size, "invalid rec idx");
goto fail;
}
if (parent_type_idx >= i) {
@ -2073,13 +2077,6 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
AOTType *cur_type = module->types[j];
parent_type_idx = cur_type->parent_type_idx;
if (parent_type_idx != (uint32)-1) { /* has parent */
#if WASM_ENABLE_AOT_VALIDATOR != 0
if (parent_type_idx >= module->type_count) {
set_error_buf(error_buf, error_buf_size,
"invalid parent type index");
goto fail;
}
#endif
AOTType *parent_type = module->types[parent_type_idx];
module->types[j]->parent_type = parent_type;
@ -2103,13 +2100,6 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
AOTType *cur_type = module->types[j];
parent_type_idx = cur_type->parent_type_idx;
if (parent_type_idx != (uint32)-1) { /* has parent */
#if WASM_ENABLE_AOT_VALIDATOR != 0
if (parent_type_idx >= module->type_count) {
set_error_buf(error_buf, error_buf_size,
"invalid parent type index");
goto fail;
}
#endif
AOTType *parent_type = module->types[parent_type_idx];
/* subtyping has been checked during compilation */
bh_assert(wasm_type_is_subtype_of(
@ -3909,8 +3899,9 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
|| !strcmp(group->section_name, ".text")
#endif
) {
#if !defined(BH_PLATFORM_LINUX) && !defined(BH_PLATFORM_LINUX_SGX) \
&& !defined(BH_PLATFORM_DARWIN) && !defined(BH_PLATFORM_WINDOWS)
#if !defined(BH_PLATFORM_LINUX) && !defined(BH_PLATFORM_LINUX_SGX) \
&& !defined(BH_PLATFORM_DARWIN) && !defined(BH_PLATFORM_WINDOWS) \
&& !defined(BH_PLATFORM_ANDROID)
if (module->is_indirect_mode) {
set_error_buf(error_buf, error_buf_size,
"cannot apply relocation to text section "

View File

@ -1385,6 +1385,16 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module,
if (!*func_ptrs) {
const char *module_name = module->import_funcs[i].module_name;
const char *field_name = module->import_funcs[i].func_name;
/* AOT mode: If linking an imported function fails, we only issue
* a warning here instead of throwing an error. However, during the
* subsequent `invoke_native` stage, calling this unresolved import
* will likely crash.
*
* See:
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/4539
*
* Debugging: Check if the import is resolved at link time */
LOG_WARNING("warning: failed to link import function (%s, %s)",
module_name, field_name);
}
@ -2460,6 +2470,14 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node);
/* In AOT mode, this is primarily a design choice for performance reasons.
* Before invoke_native, we do not check whether every imported caller is
* NULL, unlike wasm_interp_call_func_import() and
* wasm_interp_call_func_native().
*
* See: https://github.com/bytecodealliance/wasm-micro-runtime/issues/4539
*/
if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {
#if WASM_ENABLE_QUICK_AOT_ENTRY != 0
/* Quick call if the quick aot entry is registered */

View File

@ -712,7 +712,10 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
}
case VALUE_TYPE_F32:
{
os_printf("%.7g:f32", *(float32 *)(argv1 + k));
// Explicit cast to double to avoid warning.
// Float arguments are promoted to double in variadic
// functions per section 6.5.2.2 of the C99 standard.
os_printf("%.7g:f32", (double)*(float32 *)(argv1 + k));
k++;
break;
}

View File

@ -3953,15 +3953,7 @@ unsupport_simd:
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
unsupport_ref_types:
aot_set_last_error("reference type instruction was found, "
"try removing --disable-ref-types option "
"or adding --enable-gc option");
return false;
#endif
#if WASM_ENABLE_GC != 0
unsupport_gc:
aot_set_last_error("GC instruction was found, "
"try adding --enable-gc option");
"try removing --disable-ref-types option ");
return false;
#endif
@ -3969,7 +3961,7 @@ unsupport_gc:
unsupport_gc_and_ref_types:
aot_set_last_error(
"reference type or gc instruction was found, try removing "
"--disable-ref-types option or adding --enable-gc option");
"--disable-ref-types option");
return false;
#endif

View File

@ -1016,12 +1016,10 @@ update_clock_subscription_data(wasi_subscription_t *in, uint32 nsubscriptions,
}
static wasi_errno_t
execute_interruptible_poll_oneoff(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions,
size_t *nevents, wasm_exec_env_t exec_env)
execute_interruptible_poll_oneoff(struct fd_table *curfds,
const __wasi_subscription_t *in,
__wasi_event_t *out, size_t nsubscriptions,
size_t *nevents, wasm_exec_env_t exec_env)
{
if (nsubscriptions == 0) {
*nevents = 0;
@ -2118,15 +2116,16 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
wasi_roflags_t *ro_flags)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
__wasi_addr_t src_addr;
wasi_errno_t error;
if (!validate_native_addr(ro_flags, (uint64)sizeof(wasi_roflags_t)))
return __WASI_EINVAL;
// We call `recvfrom` with NULL source address as `recv` doesn't
// return the source address and this parameter is not used.
*ro_data_len = 0;
error = wasi_sock_recv_from(exec_env, sock, ri_data, ri_data_len, ri_flags,
&src_addr, ro_data_len);
*ro_flags = ri_flags;
NULL, ro_data_len);
return error;
}

View File

@ -175,14 +175,14 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
#ifndef BH_PLATFORM_WINDOWS
/* REVISIT: apply the os_file_handle style abstraction for pollfd? */
__wasi_errno_t
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
int timeout_ms, int *retp)
blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds,
os_nfds_t nfds, int timeout_ms, int *retp)
{
int ret;
if (!wasm_runtime_begin_blocking_op(exec_env)) {
return __WASI_EINTR;
}
ret = poll(pfds, nfds, timeout_ms);
ret = os_poll(pfds, nfds, timeout_ms);
wasm_runtime_end_blocking_op(exec_env);
if (ret == -1) {
return convert_errno(errno);

View File

@ -57,8 +57,8 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
#ifndef BH_PLATFORM_WINDOWS
__wasi_errno_t
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
int timeout, int *retp);
blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds,
os_nfds_t nfds, int timeout, int *retp);
#endif
#endif /* end of _BLOCKING_OP_H_ */

View File

@ -196,8 +196,12 @@ static inline bool
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
{
#if defined(BH_PLATFORM_ZEPHYR)
// TODO: Implement this for Zephyr
return false;
#else
int ret;
struct timespec ts = {
os_timespec ts = {
.tv_sec = (time_t)(timeout / 1000000000),
.tv_nsec = (long)(timeout % 1000000000),
};
@ -210,8 +214,8 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
* realtime clock.
*/
if (cond->clock != CLOCK_REALTIME) {
struct timespec ts_monotonic;
struct timespec ts_realtime;
os_timespec ts_monotonic;
os_timespec ts_realtime;
clock_gettime(cond->clock, &ts_monotonic);
ts.tv_sec -= ts_monotonic.tv_sec;
@ -229,7 +233,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
++ts.tv_sec;
}
}
#endif
#endif /* !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK */
}
else {
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
@ -241,7 +245,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
return ret == ETIMEDOUT;
#else
/* Convert to absolute timeout. */
struct timespec ts_now;
os_timespec ts_now;
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
clock_gettime(cond->clock, &ts_now);
#else
@ -253,13 +257,14 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
ts.tv_nsec -= 1000000000;
++ts.tv_sec;
}
#endif
#endif /* CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP */
}
ret = pthread_cond_timedwait(&cond->object, &lock->object, &ts);
bh_assert((ret == 0 || ret == ETIMEDOUT)
&& "pthread_cond_timedwait() failed");
return ret == ETIMEDOUT;
#endif /* BH_PLATFORM_ZEPHYR */
}
#endif

View File

@ -285,7 +285,7 @@ fd_prestats_get_entry(struct fd_prestats *pt, __wasi_fd_t fd,
struct fd_prestat **ret) REQUIRES_SHARED(pt->lock)
{
// Test for file descriptor existence.
if (fd >= pt->size)
if ((size_t)fd >= pt->size)
return __WASI_EBADF;
struct fd_prestat *prestat = &pt->prestats[fd];
if (prestat->dir == NULL)
@ -301,7 +301,7 @@ static __wasi_errno_t
fd_prestats_remove_entry(struct fd_prestats *pt, __wasi_fd_t fd)
{
// Test for file descriptor existence.
if (fd >= pt->size)
if ((size_t)fd >= pt->size)
return __WASI_EBADF;
struct fd_prestat *prestat = &pt->prestats[fd];
@ -356,16 +356,20 @@ fd_table_get_entry(struct fd_table *ft, __wasi_fd_t fd,
REQUIRES_SHARED(ft->lock)
{
// Test for file descriptor existence.
if (fd >= ft->size)
if ((size_t)fd >= ft->size) {
return __WASI_EBADF;
}
struct fd_entry *fe = &ft->entries[fd];
if (fe->object == NULL)
if (fe->object == NULL) {
return __WASI_EBADF;
}
// Validate rights.
if ((~fe->rights_base & rights_base) != 0
|| (~fe->rights_inheriting & rights_inheriting) != 0)
|| (~fe->rights_inheriting & rights_inheriting) != 0) {
return __WASI_ENOTCAPABLE;
}
*ret = fe;
return 0;
}
@ -426,15 +430,15 @@ fd_table_attach(struct fd_table *ft, __wasi_fd_t fd, struct fd_object *fo,
__wasi_rights_t rights_base, __wasi_rights_t rights_inheriting)
REQUIRES_EXCLUSIVE(ft->lock) CONSUMES(fo->refcount)
{
assert(ft->size > fd && "File descriptor table too small");
bh_assert(ft->size > fd && "File descriptor table too small");
struct fd_entry *fe = &ft->entries[fd];
assert(fe->object == NULL
&& "Attempted to overwrite an existing descriptor");
bh_assert(fe->object == NULL
&& "Attempted to overwrite an existing descriptor");
fe->object = fo;
fe->rights_base = rights_base;
fe->rights_inheriting = rights_inheriting;
++ft->used;
assert(ft->size >= ft->used * 2 && "File descriptor too full");
bh_assert(ft->size >= ft->used * 2 && "File descriptor too full");
}
// Detaches a file descriptor from the file descriptor table.
@ -442,12 +446,12 @@ static void
fd_table_detach(struct fd_table *ft, __wasi_fd_t fd, struct fd_object **fo)
REQUIRES_EXCLUSIVE(ft->lock) PRODUCES((*fo)->refcount)
{
assert(ft->size > fd && "File descriptor table too small");
bh_assert(ft->size > fd && "File descriptor table too small");
struct fd_entry *fe = &ft->entries[fd];
*fo = fe->object;
assert(*fo != NULL && "Attempted to detach nonexistent descriptor");
bh_assert(*fo != NULL && "Attempted to detach nonexistent descriptor");
fe->object = NULL;
assert(ft->used > 0 && "Reference count mismatch");
bh_assert(ft->used > 0 && "Reference count mismatch");
--ft->used;
}
@ -636,7 +640,7 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in,
static __wasi_errno_t
fd_table_unused(struct fd_table *ft, __wasi_fd_t *out) REQUIRES_SHARED(ft->lock)
{
assert(ft->size > ft->used && "File descriptor table has no free slots");
bh_assert(ft->size > ft->used && "File descriptor table has no free slots");
for (;;) {
uintmax_t random_fd = 0;
__wasi_errno_t error = random_uniform(ft->size, &random_fd);
@ -1550,7 +1554,8 @@ path_put(struct path_access *pa) UNLOCKS(pa->fd_object->refcount)
{
if (pa->path_start)
wasm_runtime_free(pa->path_start);
if (pa->fd_object->file_handle != pa->fd)
/* Can't use `!=` operator when `os_file_handle` is a struct */
if (!os_compare_file_handle(pa->fd_object->file_handle, pa->fd))
os_close(pa->fd, false);
fd_object_release(NULL, pa->fd_object);
}
@ -1891,7 +1896,7 @@ wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
}
static void
convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
convert_timestamp(__wasi_timestamp_t in, os_timespec *out)
{
// Store sub-second remainder.
#if defined(__SYSCALL_SLONG_TYPE)
@ -1899,10 +1904,10 @@ convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
#else
out->tv_nsec = (long)(in % 1000000000);
#endif
in /= 1000000000;
__wasi_timestamp_t temp = in / 1000000000;
// Clamp to the maximum in case it would overflow our system's time_t.
out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
out->tv_sec = (time_t)temp < BH_TIME_T_MAX ? (time_t)temp : BH_TIME_T_MAX;
}
__wasi_errno_t
@ -2089,7 +2094,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
size_t nsubscriptions,
size_t *nevents) NO_LOCK_ANALYSIS
{
#ifdef BH_PLATFORM_WINDOWS
#if defined(BH_PLATFORM_WINDOWS)
return __WASI_ENOSYS;
#else
// Sleeping.
@ -2101,7 +2106,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
#if CONFIG_HAS_CLOCK_NANOSLEEP
clockid_t clock_id;
if (wasi_clockid_to_clockid(in[0].u.u.clock.clock_id, &clock_id)) {
struct timespec ts;
os_timespec ts;
convert_timestamp(in[0].u.u.clock.timeout, &ts);
int ret = clock_nanosleep(
clock_id,
@ -2128,7 +2133,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
else {
// Perform relative sleeps on the monotonic clock also using
// nanosleep(). This is incorrect, but good enough for now.
struct timespec ts;
os_timespec ts;
convert_timestamp(in[0].u.u.clock.timeout, &ts);
nanosleep(&ts, NULL);
}
@ -2156,7 +2161,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
}
else {
// Relative sleeps can be done using nanosleep().
struct timespec ts;
os_timespec ts;
convert_timestamp(in[0].u.u.clock.timeout, &ts);
nanosleep(&ts, NULL);
}
@ -2181,7 +2186,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
wasm_runtime_malloc((uint32)(nsubscriptions * sizeof(*fos)));
if (fos == NULL)
return __WASI_ENOMEM;
struct pollfd *pfds =
os_poll_file_handle *pfds =
wasm_runtime_malloc((uint32)(nsubscriptions * sizeof(*pfds)));
if (pfds == NULL) {
wasm_runtime_free(fos);
@ -2205,9 +2210,16 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
fd_object_get_locked(&fos[i], ft, s->u.u.fd_readwrite.fd,
__WASI_RIGHT_POLL_FD_READWRITE, 0);
if (error == 0) {
// Temporary workaround (see PR#4377)
#ifdef BH_PLATFORM_ZEPHYR
os_file_handle tfd = fos[i]->file_handle->fd;
#else
os_file_handle tfd = fos[i]->file_handle;
#endif
// Proper file descriptor on which we can poll().
pfds[i] = (struct pollfd){
.fd = fos[i]->file_handle,
pfds[i] = (os_poll_file_handle){
.fd = tfd,
.events = s->u.type == __WASI_EVENTTYPE_FD_READ
? POLLIN
: POLLOUT,
@ -2216,7 +2228,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
else {
// Invalid file descriptor or rights missing.
fos[i] = NULL;
pfds[i] = (struct pollfd){ .fd = -1 };
pfds[i] = (os_poll_file_handle){ .fd = -1 };
out[(*nevents)++] = (__wasi_event_t){
.userdata = s->userdata,
.error = error,
@ -2231,7 +2243,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
== 0) {
// Relative timeout.
fos[i] = NULL;
pfds[i] = (struct pollfd){ .fd = -1 };
pfds[i] = (os_poll_file_handle){ .fd = -1 };
clock_subscription = s;
break;
}
@ -2239,7 +2251,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
default:
// Unsupported event.
fos[i] = NULL;
pfds[i] = (struct pollfd){ .fd = -1 };
pfds[i] = (os_poll_file_handle){ .fd = -1 };
out[(*nevents)++] = (__wasi_event_t){
.userdata = s->userdata,
.error = __WASI_ENOSYS,
@ -2283,7 +2295,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
__wasi_filesize_t nbytes = 0;
if (in[i].u.type == __WASI_EVENTTYPE_FD_READ) {
int l;
if (ioctl(fos[i]->file_handle, FIONREAD, &l) == 0)
if (os_ioctl(fos[i]->file_handle, FIONREAD, &l) == 0)
nbytes = (__wasi_filesize_t)l;
}
if ((pfds[i].revents & POLLNVAL) != 0) {
@ -2449,7 +2461,7 @@ wasi_addr_to_string(const __wasi_addr_t *addr, char *buf, size_t buflen)
if (addr->kind == IPv4) {
const char *format = "%u.%u.%u.%u";
assert(buflen >= 16);
bh_assert(buflen >= 16);
snprintf(buf, buflen, format, addr->addr.ip4.addr.n0,
addr->addr.ip4.addr.n1, addr->addr.ip4.addr.n2,
@ -2461,14 +2473,13 @@ wasi_addr_to_string(const __wasi_addr_t *addr, char *buf, size_t buflen)
const char *format = "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x";
__wasi_addr_ip6_t ipv6 = addr->addr.ip6.addr;
assert(buflen >= 40);
bh_assert(buflen >= 40);
snprintf(buf, buflen, format, ipv6.n0, ipv6.n1, ipv6.n2, ipv6.n3,
ipv6.h0, ipv6.h1, ipv6.h2, ipv6.h3);
return true;
}
return false;
}
@ -2575,9 +2586,11 @@ wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds,
}
error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_SOCK_BIND, 0);
if (error != __WASI_ESUCCESS)
if (error != __WASI_ESUCCESS) {
return error;
}
/* Consume __wasi_addr_t */
ret = blocking_op_socket_connect(exec_env, fo->file_handle, buf,
addr->kind == IPv4 ? addr->addr.ip4.port
: addr->addr.ip6.port);
@ -2726,10 +2739,10 @@ wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
}
if (SOCKET_DGRAM == socktype) {
assert(wasi_type == __WASI_FILETYPE_SOCKET_DGRAM);
bh_assert(wasi_type == __WASI_FILETYPE_SOCKET_DGRAM);
}
else {
assert(wasi_type == __WASI_FILETYPE_SOCKET_STREAM);
bh_assert(wasi_type == __WASI_FILETYPE_SOCKET_STREAM);
}
// TODO: base rights and inheriting rights ?
@ -2839,7 +2852,7 @@ wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds,
{
struct fd_object *fo;
__wasi_errno_t error;
bh_sockaddr_t sockaddr;
bh_sockaddr_t sockaddr, *sockaddr_ptr = NULL;
int ret;
error = fd_object_get(curfds, &fo, sock, __WASI_RIGHT_FD_READ, 0);
@ -2847,14 +2860,26 @@ wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds,
return error;
}
// If the source address is not NULL, the caller is requesting the source
// address to be returned if the protocol supports it. If the value is
// NULL, the POSIX standard states that the address is not returned.
if (src_addr != NULL) {
sockaddr_ptr = &sockaddr;
}
/* Consume bh_sockaddr_t instead of __wasi_addr_t */
ret = blocking_op_socket_recv_from(exec_env, fo->file_handle, buf, buf_len,
0, &sockaddr);
0, sockaddr_ptr);
fd_object_release(exec_env, fo);
if (-1 == ret) {
return convert_errno(errno);
}
bh_sockaddr_to_wasi_addr(&sockaddr, src_addr);
// If the source address is not NULL, we need to convert the sockaddr
// back to __wasi_addr_t format.
if (src_addr != NULL) {
bh_sockaddr_to_wasi_addr(sockaddr_ptr, src_addr);
}
*recv_len = (size_t)ret;
return __WASI_ESUCCESS;
@ -2912,6 +2937,7 @@ wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds,
wasi_addr_to_bh_sockaddr(dest_addr, &sockaddr);
/* Consume bh_sockaddr instead of __wasi_addr_t */
ret = blocking_op_socket_send_to(exec_env, fo->file_handle, buf, buf_len, 0,
&sockaddr);
fd_object_release(exec_env, fo);
@ -2943,8 +2969,10 @@ wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds,
__wasi_errno_t
wasmtime_ssp_sched_yield(void)
{
#ifdef BH_PLATFORM_WINDOWS
#if defined(BH_PLATFORM_WINDOWS)
SwitchToThread();
#elif defined(BH_PLATFORM_ZEPHYR)
k_yield();
#else
if (sched_yield() < 0)
return convert_errno(errno);

View File

@ -66,6 +66,20 @@ random_buf(void *buf, size_t len)
return ret ? __WASI_EINVAL : __WASI_ESUCCESS;
}
#elif defined(BH_PLATFORM_ZEPHYR)
#include <zephyr/random/random.h>
// Maybe having an OS abstraction api would be a good idea
// because every platform is implementing this function.
// we could have a function like `os_random_buf`
// and call `os_random_buf.` in the SSP wrapper `random_buf`.
__wasi_errno_t
random_buf(void *buf, size_t len)
{
sys_rand_get(buf, len);
return __WASI_ESUCCESS;
}
#else
static int urandom = -1;

View File

@ -42,7 +42,8 @@
#define CONFIG_HAS_GETRANDOM 0
#endif
#if defined(__CloudABI__) || defined(BH_PLATFORM_FREERTOS)
#if defined(__CloudABI__) || defined(BH_PLATFORM_FREERTOS) \
|| defined(BH_PLATFORM_ZEPHYR)
#define CONFIG_HAS_CAP_ENTER 1
#else
#define CONFIG_HAS_CAP_ENTER 0
@ -50,7 +51,7 @@
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__EMSCRIPTEN__) \
&& !defined(ESP_PLATFORM) && !defined(DISABLE_CLOCK_NANOSLEEP) \
&& !defined(BH_PLATFORM_FREERTOS)
&& !defined(BH_PLATFORM_FREERTOS) && !defined(BH_PLATFORM_ZEPHYR)
#define CONFIG_HAS_CLOCK_NANOSLEEP 1
#else
#define CONFIG_HAS_CLOCK_NANOSLEEP 0
@ -63,7 +64,8 @@
#endif
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) && !defined(_WIN32) \
&& !defined(__COSMOPOLITAN__) && !defined(BH_PLATFORM_FREERTOS)
&& !defined(__COSMOPOLITAN__) && !defined(BH_PLATFORM_FREERTOS) \
&& !defined(BH_PLATFORM_ZEPHYR)
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
#else
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0

View File

@ -296,7 +296,7 @@ load(void *onnx_ctx, graph_builder_array *builder, graph_encoding encoding,
return invalid_argument;
}
NN_INFO_PRINTF("[ONNX Runtime] Loading model of size %zu bytes...",
NN_INFO_PRINTF("[ONNX Runtime] Loading model of size %" PRIu32 " bytes...",
builder->buf[0].size);
if (builder->buf[0].size > 16) {

View File

@ -14,6 +14,8 @@
# https://github.com/tensorflow/tensorflow/releases/tag/v2.16.1
# https://blog.tensorflow.org/2024/03/whats-new-in-tensorflow-216.html
set -e
CURR_PATH=$(cd $(dirname $0) && pwd -P)
# WASM application that uses WASI-NN

View File

@ -6,7 +6,9 @@
#include "ems_gc.h"
#include "ems_gc_internal.h"
#ifndef GB // Some platforms define already, causing build warnings.
#define GB (1 << 30UL)
#endif
#define MARK_NODE_OBJ_CNT 256

View File

@ -338,8 +338,13 @@ typedef struct gc_heap_struct {
static inline void
gc_update_threshold(gc_heap_t *heap)
{
heap->gc_threshold =
heap->total_free_size * heap->gc_threshold_factor / 1000;
uint64_t result = (uint64_t)heap->total_free_size
* (uint64_t)heap->gc_threshold_factor / 1000;
/* heap->total_free_size * heap->gc_threshold_factor won't exceed
* 6^32(GC_HEAP_SIZE_MAX * GC_DEFAULT_THRESHOLD_FACTOR), so casting result
* to uint32_t is safe
*/
heap->gc_threshold = (uint32_t)result;
}
#define gct_vm_mutex_init os_mutex_init

View File

@ -75,6 +75,9 @@ int isnan(double x);
typedef int os_file_handle;
typedef void *os_dir_stream;
typedef int os_raw_file_handle;
typedef int os_poll_file_handle;
typedef unsigned int os_nfds_t;
typedef int os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)

View File

@ -150,6 +150,12 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
/* The below types are used in platform_api_extension.h,
we just define them to make the compiler happy */
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef struct timespec os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)
{

View File

@ -1039,3 +1039,31 @@ os_invalid_raw_handle(void)
{
return -1;
}
// Better to define the function here, as Linux-SGX will
// use this file to implement the `_os` functions.
// So we don't need to define them in the Linux-SGX platform.
int
os_ioctl(os_file_handle handle, int request, ...)
{
int ret = -1;
va_list args;
va_start(args, request);
ret = ioctl(handle, request, args);
va_end(args);
return ret;
}
int
os_poll(os_poll_file_handle *fds, os_nfds_t nfs, int timeout)
{
return poll(fds, nfs, timeout);
}
bool
os_compare_file_handle(os_file_handle handle1, os_file_handle handle2)
{
return handle1 == handle2;
}

View File

@ -1035,4 +1035,4 @@ os_socket_addr_remote(bh_socket_t socket, bh_sockaddr_t *sockaddr)
}
return sockaddr_to_bh_sockaddr((struct sockaddr *)&addr_storage, sockaddr);
}
}

View File

@ -67,6 +67,9 @@ typedef sem_t korp_sem;
typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef struct timespec os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)

View File

@ -112,6 +112,9 @@ os_set_signal_number_for_blocking_op(int signo);
typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef struct timespec os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)

View File

@ -1039,3 +1039,15 @@ os_invalid_raw_handle(void)
{
return -1;
}
int
os_ioctl(os_file_handle handle, int request, ...)
{
return BHT_ERROR;
}
int
os_poll(os_poll_file_handle *fds, os_nfds_t nfs, int timeout)
{
return BHT_ERROR;
}

View File

@ -144,6 +144,12 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
/* The below types are used in platform_api_extension.h,
we just define them to make the compiler happy */
typedef int os_poll_file_handle;
typedef unsigned int os_nfds_t;
typedef int os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)
{

View File

@ -69,6 +69,9 @@ typedef sem_t korp_sem;
typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef struct timespec os_timespec;
#if WASM_DISABLE_HW_BOUND_CHECK == 0
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \

View File

@ -1673,4 +1673,24 @@ os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
}
#endif
/* Experimental */
/* Used in posix.c around L2259 and expect the return code
* of ioctl() directly.
*/
int
os_ioctl(os_file_handle handle, int request, ...);
/* Higher level API:
* __wasi_errno_t
* blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds,
* os_nfds_t nfds, int timeout_ms, int *retp)
* Already format the errno and expect the return code of poll() directly.
*/
int
os_poll(os_poll_file_handle *pfds, os_nfds_t nfs, int timeout);
bool
os_compare_file_handle(os_file_handle handle1, os_file_handle handle2);
#endif /* #ifndef PLATFORM_API_EXTENSION_H */

View File

@ -173,7 +173,7 @@ typedef uint8_t __wasi_eventtype_t;
typedef uint32_t __wasi_exitcode_t;
typedef uint32_t __wasi_fd_t;
typedef int32_t __wasi_fd_t;
typedef uint16_t __wasi_fdflags_t;
#define __WASI_FDFLAG_APPEND (0x0001)
@ -539,7 +539,10 @@ typedef enum {
typedef uint16_t __wasi_ip_port_t;
typedef enum { IPv4 = 0, IPv6 } __wasi_addr_type_t;
/* Ensure that __wasi_addr_type_t has a size of 4 byte (I32).
However, it will not have the type safety of enum. */
typedef uint32_t __wasi_addr_type_t;
enum { IPv4 = 0, IPv6 };
/* n0.n1.n2.n3 */
typedef struct __wasi_addr_ip4_t {

View File

@ -73,6 +73,16 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
struct _pollfd {
int fd;
short events;
short revents;
};
typedef struct _pollfd os_poll_file_handle;
typedef unsigned long os_nfds_t;
typedef struct timespec os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)
{

View File

@ -126,6 +126,10 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef struct timespec os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)
{

View File

@ -132,9 +132,14 @@ fdopendir(int fd);
void
os_set_signal_number_for_blocking_op(int signo);
/* The below types are used in platform_api_extension.h,
we just define them to make the compiler happy */
typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef struct timespec os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)

View File

@ -63,6 +63,9 @@ typedef struct korp_cond {
typedef int os_file_handle;
typedef void *os_dir_stream;
typedef int os_raw_file_handle;
typedef int os_poll_file_handle;
typedef unsigned int os_nfds_t;
typedef int os_timespec;
#if WA_MATH
/* clang-format off */

View File

@ -122,6 +122,9 @@ typedef rt_int64_t int64_t;
typedef int os_file_handle;
typedef void *os_dir_stream;
typedef int os_raw_file_handle;
typedef int os_poll_file_handle;
typedef unsigned int os_nfds_t;
typedef int os_timespec;
static inline os_file_handle
os_get_invalid_handle(void)

View File

@ -65,6 +65,12 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
/* The below types are used in platform_api_extension.h,
we just define them to make the compiler happy */
typedef struct pollfd os_poll_file_handle;
typedef nfds_t os_nfds_t;
typedef timespec os_timespec;
#if WASM_DISABLE_HW_BOUND_CHECK == 0
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|| defined(BUILD_TARGET_AARCH64)

View File

@ -186,6 +186,12 @@ typedef uint32_t os_raw_file_handle;
#define bh_socket_t windows_handle *
/* The below types are used in platform_api_extension.h,
we just define them to make the compiler happy */
typedef int os_poll_file_handle;
typedef unsigned int os_nfds_t;
typedef struct timespec os_timespec;
// UWP apps do not have stdout/stderr handles so provide a default
// implementation of vprintf on debug builds so output from WASI libc is sent to
// the debugger and not lost completely.

View File

@ -1816,3 +1816,39 @@ os_invalid_raw_handle(void)
{
return INVALID_HANDLE_VALUE;
}
bool
os_compare_file_handle(os_file_handle handle1, os_file_handle handle2)
{
if (handle1->type != handle2->type) {
return false;
}
if (handle1->fdflags != handle2->fdflags
|| handle1->access_mode != handle2->access_mode) {
return false;
}
switch (handle1->type) {
case windows_handle_type_file:
return handle1->raw.handle == handle2->raw.handle;
case windows_handle_type_socket:
return handle1->raw.socket == handle2->raw.socket;
default:
// Unknown handle type
return false;
}
}
int
os_ioctl(os_file_handle handle, int request, ...)
{
return BHT_ERROR;
}
// Should not be called because locked by ifdef.
int
os_poll(os_poll_file_handle *fds, os_nfds_t nfs, int timeout)
{
return BHT_ERROR;
}

View File

@ -50,6 +50,7 @@
#include <zephyr/net/net_ip.h>
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_context.h>
#include <zephyr/net/socket.h>
#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */
#ifdef CONFIG_USERSPACE
@ -79,29 +80,51 @@
#define BH_PLATFORM_ZEPHYR
#endif
// Synchronization primitives for usermode
#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif
/* Synchronization primitives for usermode.
* The macros are prefixed with 'z' because when building
* with WAMR_BUILD_LIBC_WASI the same functions are defined,
* and used in the sandboxed-system-primitives (see locking.h)
*/
#ifdef CONFIG_USERSPACE
#define mutex_t struct sys_mutex
#define mutex_init(mtx) sys_mutex_init(mtx)
#define mutex_lock(mtx, timeout) sys_mutex_lock(mtx, timeout)
#define mutex_unlock(mtx) sys_mutex_unlock(mtx)
#define zmutex_t struct sys_mutex
#define zmutex_init(mtx) sys_mutex_init(mtx)
#define zmutex_lock(mtx, timeout) sys_mutex_lock(mtx, timeout)
#define zmutex_unlock(mtx) sys_mutex_unlock(mtx)
#define sem_t struct sys_sem
#define sem_init(sem, init_count, limit) sys_sem_init(sem, init_count, limit)
#define sem_give(sem) sys_sem_give(sem)
#define sem_take(sem, timeout) sys_sem_take(sem, timeout)
#define sem_count_get(sem) sys_sem_count_get(sem)
#define zsem_t struct sys_sem
#define zsem_init(sem, init_count, limit) sys_sem_init(sem, init_count, limit)
#define zsem_give(sem) sys_sem_give(sem)
#define zsem_take(sem, timeout) sys_sem_take(sem, timeout)
#define zsem_count_get(sem) sys_sem_count_get(sem)
#else /* else of CONFIG_USERSPACE */
#define mutex_t struct k_mutex
#define mutex_init(mtx) k_mutex_init(mtx)
#define mutex_lock(mtx, timeout) k_mutex_lock(mtx, timeout)
#define mutex_unlock(mtx) k_mutex_unlock(mtx)
#define zmutex_t struct k_mutex
#define zmutex_init(mtx) k_mutex_init(mtx)
#define zmutex_lock(mtx, timeout) k_mutex_lock(mtx, timeout)
#define zmutex_unlock(mtx) k_mutex_unlock(mtx)
#define sem_t struct k_sem
#define sem_init(sem, init_count, limit) k_sem_init(sem, init_count, limit)
#define sem_give(sem) k_sem_give(sem)
#define sem_take(sem, timeout) k_sem_take(sem, timeout)
#define sem_count_get(sem) k_sem_count_get(sem)
#define zsem_t struct k_sem
#define zsem_init(sem, init_count, limit) k_sem_init(sem, init_count, limit)
#define zsem_give(sem) k_sem_give(sem)
#define zsem_take(sem, timeout) k_sem_take(sem, timeout)
#define zsem_count_get(sem) k_sem_count_get(sem)
#endif /* end of CONFIG_USERSPACE */
#define BH_APPLET_PRESERVED_STACK_SIZE (2 * BH_KB)
@ -111,22 +134,32 @@
typedef struct k_thread korp_thread;
typedef korp_thread *korp_tid;
typedef mutex_t korp_mutex;
typedef zmutex_t korp_mutex;
typedef unsigned int korp_sem;
/* korp_rwlock is used in platform_api_extension.h,
we just define the type to make the compiler happy */
typedef struct {
int dummy;
} korp_rwlock;
struct os_thread_wait_node;
typedef struct os_thread_wait_node *os_thread_wait_list;
typedef struct korp_cond {
mutex_t wait_list_lock;
zmutex_t wait_list_lock;
os_thread_wait_list thread_wait_list;
} korp_cond;
typedef struct {
struct k_mutex mtx; // Mutex for exclusive access
struct k_sem sem; // Semaphore for shared access
int read_count; // Number of readers
} korp_rwlock;
// TODO: Conform to Zephyr POSIX definition of rwlock:
// struct posix_rwlock {
// struct k_sem rd_sem;
// struct k_sem wr_sem;
// struct k_sem reader_active; /* blocks WR till reader has acquired lock */
// k_tid_t wr_owner;
// };
#ifndef Z_TIMEOUT_MS
#define Z_TIMEOUT_MS(ms) ms
#endif
@ -204,14 +237,68 @@ set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
/* The below types are used in platform_api_extension.h,
we just define them to make the compiler happy */
typedef int os_file_handle;
typedef void *os_dir_stream;
typedef int os_dir_stream;
typedef int os_raw_file_handle;
#define OS_DIR_STREAM_INVALID 0
// handle for file system descriptor
typedef struct zephyr_fs_desc {
char *path;
union {
struct fs_file_t file;
struct fs_dir_t dir;
};
bool is_dir;
bool used;
uint32_t dir_index; // DSK: supprt for rewind and seek
} zephyr_fs_desc;
// definition of zephyr_handle
typedef struct zephyr_handle {
int fd;
bool is_sock;
} zephyr_handle;
typedef struct zephyr_handle *os_file_handle;
#define bh_socket_t zephyr_handle *
typedef struct zsock_pollfd os_poll_file_handle;
typedef unsigned int os_nfds_t;
// Some of these definitions will throw warning for macros
// redefinition if CONFIG_POSIX_API=y, but it's fine.
// Warning: the CONFIG_POSIX_API will surely be deprecated and
// split into more macros, so we may use some ifdefs to avoid
// the warning in the future.
#define POLLIN ZSOCK_POLLIN
#define POLLPRI ZSOCK_POLLPRI
#define POLLOUT ZSOCK_POLLOUT
#define POLLERR ZSOCK_POLLERR
#define POLLHUP ZSOCK_POLLHUP
#define POLLNVAL ZSOCK_POLLNVAL
#define FIONREAD ZFD_IOCTL_FIONREAD
typedef struct timespec os_timespec;
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 1
#endif
#define CLOCK_MONOTONIC 4
static inline int
os_sched_yield(void)
{
k_yield();
return 0;
}
static inline os_file_handle
os_get_invalid_handle(void)
{
return -1;
return NULL;
}
static inline int

View File

@ -8,11 +8,20 @@ add_definitions(-DBH_PLATFORM_ZEPHYR)
include_directories(${PLATFORM_SHARED_DIR})
include_directories(${PLATFORM_SHARED_DIR}/../include)
if(${CONFIG_MINIMAL_LIBC})
include (${CMAKE_CURRENT_LIST_DIR}/../common/math/platform_api_math.cmake)
endif()
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE})
if(${CONFIG_MINIMAL_LIBC})
include (${CMAKE_CURRENT_LIST_DIR}/../common/math/platform_api_math.cmake)
set (source_all ${source_all} ${PLATFORM_COMMON_MATH_SOURCE})
endif()
if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/zephyr_socket.c)
list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/zephyr_file.c)
list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/zephyr_clock.c)
else()
include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake)
set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE})
endif ()
set (PLATFORM_SHARED_SOURCE ${source_all})

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2024 Grenoble INP - ESISAR. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "platform_api_extension.h"
#include "platform_api_vmcore.h"
#include "libc_errno.h"
#include <zephyr/kernel.h>
/* Notes:
* We are using the same implementation for __WASI_CLOCK_REALTIME and
* __WASI_CLOCK_MONOTONIC, because it is a practical solution when there
* is no RTC or external time source available.
* The implementation is based on the Zephyr `k_cycle_get_32()` function or
* the 64bits variant if available.
* We could have used `k_uptime_get()` instead, but it is not as precise,
* it has a millisecond resolution or depend on CONFIG_SYS_CLOCK_TICKS_PER_SEC.
* Feel free to change the implementation if you have a better solution.
* May look at
* https://github.com/zephyrproject-rtos/zephyr/blob/main/lib/posix/options/clock.c
* for reference.
*/
#define NANOSECONDS_PER_SECOND 1000000000ULL
__wasi_errno_t
os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution)
{
switch (clock_id) {
case __WASI_CLOCK_PROCESS_CPUTIME_ID:
case __WASI_CLOCK_THREAD_CPUTIME_ID:
return __WASI_ENOTSUP;
case __WASI_CLOCK_REALTIME:
case __WASI_CLOCK_MONOTONIC:
*resolution =
NANOSECONDS_PER_SECOND / CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
return __WASI_ESUCCESS;
default:
return __WASI_EINVAL;
}
}
__wasi_errno_t
os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
__wasi_timestamp_t *time)
{
(void)precision;
switch (clock_id) {
case __WASI_CLOCK_PROCESS_CPUTIME_ID:
case __WASI_CLOCK_THREAD_CPUTIME_ID:
return __WASI_ENOTSUP;
case __WASI_CLOCK_REALTIME:
case __WASI_CLOCK_MONOTONIC:
#ifdef CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER
*time = k_cycle_get_64();
#else
*time = k_cycle_get_32();
#endif
return __WASI_ESUCCESS;
default:
return __WASI_EINVAL;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,22 +34,22 @@
static K_THREAD_STACK_ARRAY_DEFINE(mpu_stacks, BH_ZEPHYR_MPU_STACK_COUNT,
BH_ZEPHYR_MPU_STACK_SIZE);
static bool mpu_stack_allocated[BH_ZEPHYR_MPU_STACK_COUNT];
static mutex_t mpu_stack_lock;
static zmutex_t mpu_stack_lock;
static char *
mpu_stack_alloc()
{
int i;
mutex_lock(&mpu_stack_lock, K_FOREVER);
zmutex_lock(&mpu_stack_lock, K_FOREVER);
for (i = 0; i < BH_ZEPHYR_MPU_STACK_COUNT; i++) {
if (!mpu_stack_allocated[i]) {
mpu_stack_allocated[i] = true;
mutex_unlock(&mpu_stack_lock);
zmutex_unlock(&mpu_stack_lock);
return (char *)mpu_stacks[i];
}
}
mutex_unlock(&mpu_stack_lock);
zmutex_unlock(&mpu_stack_lock);
return NULL;
}
@ -58,17 +58,17 @@ mpu_stack_free(char *stack)
{
int i;
mutex_lock(&mpu_stack_lock, K_FOREVER);
zmutex_lock(&mpu_stack_lock, K_FOREVER);
for (i = 0; i < BH_ZEPHYR_MPU_STACK_COUNT; i++) {
if ((char *)mpu_stacks[i] == stack)
mpu_stack_allocated[i] = false;
}
mutex_unlock(&mpu_stack_lock);
zmutex_unlock(&mpu_stack_lock);
}
#endif
typedef struct os_thread_wait_node {
sem_t sem;
zsem_t sem;
os_thread_wait_list next;
} os_thread_wait_node;
@ -80,7 +80,7 @@ typedef struct os_thread_data {
/* Jeff thread local root */
void *tlr;
/* Lock for waiting list */
mutex_t wait_list_lock;
zmutex_t wait_list_lock;
/* Waiting list of other threads who are joining this thread */
os_thread_wait_list thread_wait_list;
/* Thread stack size */
@ -107,13 +107,13 @@ static bool is_thread_sys_inited = false;
static os_thread_data supervisor_thread_data;
/* Lock for thread data list */
static mutex_t thread_data_lock;
static zmutex_t thread_data_lock;
/* Thread data list */
static os_thread_data *thread_data_list = NULL;
/* Lock for thread object list */
static mutex_t thread_obj_lock;
static zmutex_t thread_obj_lock;
/* Thread object list */
static os_thread_obj *thread_obj_list = NULL;
@ -121,7 +121,7 @@ static os_thread_obj *thread_obj_list = NULL;
static void
thread_data_list_add(os_thread_data *thread_data)
{
mutex_lock(&thread_data_lock, K_FOREVER);
zmutex_lock(&thread_data_lock, K_FOREVER);
if (!thread_data_list)
thread_data_list = thread_data;
else {
@ -129,7 +129,7 @@ thread_data_list_add(os_thread_data *thread_data)
os_thread_data *p = thread_data_list;
while (p) {
if (p == thread_data) {
mutex_unlock(&thread_data_lock);
zmutex_unlock(&thread_data_lock);
return;
}
p = p->next;
@ -139,13 +139,13 @@ thread_data_list_add(os_thread_data *thread_data)
thread_data->next = thread_data_list;
thread_data_list = thread_data;
}
mutex_unlock(&thread_data_lock);
zmutex_unlock(&thread_data_lock);
}
static void
thread_data_list_remove(os_thread_data *thread_data)
{
mutex_lock(&thread_data_lock, K_FOREVER);
zmutex_lock(&thread_data_lock, K_FOREVER);
if (thread_data_list) {
if (thread_data_list == thread_data)
thread_data_list = thread_data_list->next;
@ -158,32 +158,32 @@ thread_data_list_remove(os_thread_data *thread_data)
p->next = p->next->next;
}
}
mutex_unlock(&thread_data_lock);
zmutex_unlock(&thread_data_lock);
}
static os_thread_data *
thread_data_list_lookup(k_tid_t tid)
{
mutex_lock(&thread_data_lock, K_FOREVER);
zmutex_lock(&thread_data_lock, K_FOREVER);
if (thread_data_list) {
os_thread_data *p = thread_data_list;
while (p) {
if (p->tid == tid) {
/* Found */
mutex_unlock(&thread_data_lock);
zmutex_unlock(&thread_data_lock);
return p;
}
p = p->next;
}
}
mutex_unlock(&thread_data_lock);
zmutex_unlock(&thread_data_lock);
return NULL;
}
static void
thread_obj_list_add(os_thread_obj *thread_obj)
{
mutex_lock(&thread_obj_lock, K_FOREVER);
zmutex_lock(&thread_obj_lock, K_FOREVER);
if (!thread_obj_list)
thread_obj_list = thread_obj;
else {
@ -191,14 +191,14 @@ thread_obj_list_add(os_thread_obj *thread_obj)
thread_obj->next = thread_obj_list;
thread_obj_list = thread_obj;
}
mutex_unlock(&thread_obj_lock);
zmutex_unlock(&thread_obj_lock);
}
static void
thread_obj_list_reclaim()
{
os_thread_obj *p, *p_prev;
mutex_lock(&thread_obj_lock, K_FOREVER);
zmutex_lock(&thread_obj_lock, K_FOREVER);
p_prev = NULL;
p = thread_obj_list;
while (p) {
@ -219,7 +219,7 @@ thread_obj_list_reclaim()
p = p->next;
}
}
mutex_unlock(&thread_obj_lock);
zmutex_unlock(&thread_obj_lock);
}
int
@ -229,10 +229,10 @@ os_thread_sys_init()
return BHT_OK;
#if BH_ENABLE_ZEPHYR_MPU_STACK != 0
mutex_init(&mpu_stack_lock);
zmutex_init(&mpu_stack_lock);
#endif
mutex_init(&thread_data_lock);
mutex_init(&thread_obj_lock);
zmutex_init(&thread_data_lock);
zmutex_init(&thread_obj_lock);
/* Initialize supervisor thread data */
memset(&supervisor_thread_data, 0, sizeof(supervisor_thread_data));
@ -265,19 +265,19 @@ os_thread_cleanup(void)
os_thread_data *thread_data = thread_data_current();
bh_assert(thread_data != NULL);
mutex_lock(&thread_data->wait_list_lock, K_FOREVER);
zmutex_lock(&thread_data->wait_list_lock, K_FOREVER);
if (thread_data->thread_wait_list) {
/* Signal each joining thread */
os_thread_wait_list head = thread_data->thread_wait_list;
while (head) {
os_thread_wait_list next = head->next;
sem_give(&head->sem);
zsem_give(&head->sem);
/* head will be freed by joining thread */
head = next;
}
thread_data->thread_wait_list = NULL;
}
mutex_unlock(&thread_data->wait_list_lock);
zmutex_unlock(&thread_data->wait_list_lock);
thread_data_list_remove(thread_data);
/* Set flag to true for the next thread creating to
@ -342,7 +342,7 @@ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
}
memset(thread_data, 0, thread_data_size);
mutex_init(&thread_data->wait_list_lock);
zmutex_init(&thread_data->wait_list_lock);
thread_data->stack_size = stack_size;
thread_data->tid = tid;
@ -407,10 +407,10 @@ os_thread_join(korp_tid thread, void **value_ptr)
if (!(node = BH_MALLOC(sizeof(os_thread_wait_node))))
return BHT_ERROR;
sem_init(&node->sem, 0, 1);
zsem_init(&node->sem, 0, 1);
node->next = NULL;
mutex_lock(&thread_data->wait_list_lock, K_FOREVER);
zmutex_lock(&thread_data->wait_list_lock, K_FOREVER);
if (!thread_data->thread_wait_list)
thread_data->thread_wait_list = node;
else {
@ -420,10 +420,10 @@ os_thread_join(korp_tid thread, void **value_ptr)
p = p->next;
p->next = node;
}
mutex_unlock(&thread_data->wait_list_lock);
zmutex_unlock(&thread_data->wait_list_lock);
/* Wait the sem */
sem_take(&node->sem, K_FOREVER);
zsem_take(&node->sem, K_FOREVER);
/* Wait some time for the thread to be actually terminated */
k_sleep(Z_TIMEOUT_MS(100));
@ -436,14 +436,14 @@ os_thread_join(korp_tid thread, void **value_ptr)
int
os_mutex_init(korp_mutex *mutex)
{
mutex_init(mutex);
zmutex_init(mutex);
return BHT_OK;
}
int
os_recursive_mutex_init(korp_mutex *mutex)
{
mutex_init(mutex);
zmutex_init(mutex);
return BHT_OK;
}
@ -457,16 +457,16 @@ os_mutex_destroy(korp_mutex *mutex)
int
os_mutex_lock(korp_mutex *mutex)
{
return mutex_lock(mutex, K_FOREVER);
return zmutex_lock(mutex, K_FOREVER);
}
int
os_mutex_unlock(korp_mutex *mutex)
{
#if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */
return mutex_unlock(mutex);
return zmutex_unlock(mutex);
#else
mutex_unlock(mutex);
zmutex_unlock(mutex);
return 0;
#endif
}
@ -474,7 +474,7 @@ os_mutex_unlock(korp_mutex *mutex)
int
os_cond_init(korp_cond *cond)
{
mutex_init(&cond->wait_list_lock);
zmutex_init(&cond->wait_list_lock);
cond->thread_wait_list = NULL;
return BHT_OK;
}
@ -495,10 +495,10 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed, int mills)
if (!(node = BH_MALLOC(sizeof(os_thread_wait_node))))
return BHT_ERROR;
sem_init(&node->sem, 0, 1);
zsem_init(&node->sem, 0, 1);
node->next = NULL;
mutex_lock(&cond->wait_list_lock, K_FOREVER);
zmutex_lock(&cond->wait_list_lock, K_FOREVER);
if (!cond->thread_wait_list)
cond->thread_wait_list = node;
else {
@ -508,15 +508,15 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed, int mills)
p = p->next;
p->next = node;
}
mutex_unlock(&cond->wait_list_lock);
zmutex_unlock(&cond->wait_list_lock);
/* Unlock mutex, wait sem and lock mutex again */
mutex_unlock(mutex);
sem_take(&node->sem, timed ? Z_TIMEOUT_MS(mills) : K_FOREVER);
mutex_lock(mutex, K_FOREVER);
zmutex_unlock(mutex);
zsem_take(&node->sem, timed ? Z_TIMEOUT_MS(mills) : K_FOREVER);
zmutex_lock(mutex, K_FOREVER);
/* Remove wait node from wait list */
mutex_lock(&cond->wait_list_lock, K_FOREVER);
zmutex_lock(&cond->wait_list_lock, K_FOREVER);
if (cond->thread_wait_list == node)
cond->thread_wait_list = node->next;
else {
@ -527,7 +527,7 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed, int mills)
p->next = node->next;
}
BH_FREE(node);
mutex_unlock(&cond->wait_list_lock);
zmutex_unlock(&cond->wait_list_lock);
return BHT_OK;
}
@ -565,10 +565,10 @@ int
os_cond_signal(korp_cond *cond)
{
/* Signal the head wait node of wait list */
mutex_lock(&cond->wait_list_lock, K_FOREVER);
zmutex_lock(&cond->wait_list_lock, K_FOREVER);
if (cond->thread_wait_list)
sem_give(&cond->thread_wait_list->sem);
mutex_unlock(&cond->wait_list_lock);
zsem_give(&cond->thread_wait_list->sem);
zmutex_unlock(&cond->wait_list_lock);
return BHT_OK;
}
@ -588,6 +588,67 @@ void
os_thread_jit_write_protect_np(bool enabled)
{}
int
os_rwlock_init(korp_rwlock *lock)
{
if (!lock) {
return BHT_ERROR;
}
k_mutex_init(&lock->mtx);
k_sem_init(&lock->sem, 0, K_SEM_MAX_LIMIT);
lock->read_count = 0;
return BHT_OK;
}
int
os_rwlock_rdlock(korp_rwlock *lock)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_rwlock_wrlock(korp_rwlock *lock)
{
// Acquire the mutex to ensure exclusive access
if (k_mutex_lock(&lock->mtx, K_FOREVER) != 0) {
return BHT_ERROR;
}
// Wait until there are no readers
while (lock->read_count > 0) {
// Release the mutex while we're waiting
k_mutex_unlock(&lock->mtx);
// Wait for a short time
k_sleep(K_MSEC(1));
// Re-acquire the mutex
if (k_mutex_lock(&lock->mtx, K_FOREVER) != 0) {
return BHT_ERROR;
}
}
// At this point, we hold the mutex and there are no readers, so we have the
// write lock
return BHT_OK;
}
int
os_rwlock_unlock(korp_rwlock *lock)
{
k_mutex_unlock(&lock->mtx);
return BHT_OK;
}
int
os_rwlock_destroy(korp_rwlock *lock)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_thread_detach(korp_tid thread)
{
@ -607,13 +668,88 @@ int
os_cond_broadcast(korp_cond *cond)
{
os_thread_wait_node *node;
mutex_lock(&cond->wait_list_lock, K_FOREVER);
zmutex_lock(&cond->wait_list_lock, K_FOREVER);
node = cond->thread_wait_list;
while (node) {
os_thread_wait_node *next = node->next;
sem_give(&node->sem);
zsem_give(&node->sem);
node = next;
}
mutex_unlock(&cond->wait_list_lock);
zmutex_unlock(&cond->wait_list_lock);
return BHT_OK;
}
korp_sem *
os_sem_open(const char *name, int oflags, int mode, int val)
{
/* Not implemented */
return NULL;
}
int
os_sem_close(korp_sem *sem)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_sem_wait(korp_sem *sem)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_sem_trywait(korp_sem *sem)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_sem_post(korp_sem *sem)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_sem_getvalue(korp_sem *sem, int *sval)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_sem_unlink(const char *name)
{
/* Not implemented */
return BHT_ERROR;
}
int
os_blocking_op_init()
{
/* Not implemented */
return BHT_ERROR;
}
void
os_begin_blocking_op()
{
/* Not implemented */
}
void
os_end_blocking_op()
{
/* Not implemented */
}
int
os_wakeup_blocking_op(korp_tid tid)
{
/* Not implemented */
return BHT_ERROR;
}

View File

@ -57,7 +57,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM
- **WAMR_BUILD_LIBC_UVWASI**=1/0 (Experiment), build the [WASI](https://github.com/WebAssembly/WASI) libc subset for WASM app based on [uvwasi](https://github.com/nodejs/uvwasi) implementation, default to disable if not set
> Note: for platform which doesn't support **WAMR_BUILD_LIBC_WASI**, e.g. Windows, developer can try using **WAMR_BUILD_LIBC_UVWASI**.
> Note: WAMR doesn't support a safe sandbox on all platforms. For platforms that do not support **WAMR_BUILD_LIBC_WASI**, e.g. Windows, developers can try using an unsafe uvwasi-based WASI implementation by using **WAMR_BUILD_LIBC_UVWASI**.
### **Enable Multi-Module feature**

View File

@ -14,37 +14,41 @@ Users can turn those features on or off by using compilation options. If a relev
| Proposal | >= Phase 4 | Compilation Option |
| ------------------------------------- | ---------- | ------------------------ |
| Bulk memory operations | Yes | `WAMR_BUILD_BULK_MEMORY` |
| Bulk Memory Operations | Yes | `WAMR_BUILD_BULK_MEMORY` |
| Fixed-width SIMD[^1] | Yes | `WAMR_BUILD_SIMD` |
| Import/Export of Mutable Globals[^2] | Yes | N/A |
| Multi-value | Yes | N/A |
| Non-trapping float-to-int conversions | Yes | N/A |
| Non-trapping float-to-int Conversions | Yes | N/A |
| Reference Types | Yes | `WAMR_BUILD_REF_TYPES` |
| Sign-extension operators | Yes | N/A |
| Sign-extension Operators | Yes | N/A |
| WebAssembly C and C++ API | No | N/A |
[^1]: llvm-jit and aot only.
[^2]: in WAMR's implementation, if a mutable global shared by several wasm instances, each instance maintains its own copy of the global rather than sharing it.
## Off-by-default Wasm Proposals
| Proposal | >= Phase 4 | Compilation Option |
| ----------------------------- | ---------- | -------------------------- |
| Garbage collection | Yes | `WAMR_BUILD_GC` |
| Legacy Exception handling[^2] | No | `WAMR_BUILD_EXCE_HANDLING` |
| Memory64 | Yes | `WAMR_BUILD_MEMORY64` |
| Multiple memories[^3] | Yes | `WAMR_BUILD_MULTI_MEMORY` |
| Reference-Typed Strings | No | `WAMR_BUILD_STRINGREF` |
| Tail call | Yes | `WAMR_BUILD_TAIL_CALL` |
| Threads[^4] | Yes | `WAMR_BUILD_SHARED_MEMORY` |
| Typed Function References | Yes | `WAMR_BUILD_GC` |
| Proposal | >= Phase 4 | Compilation Option |
| ----------------------------- | ---------- | ---------------------------------|
| Extended Constant Expressions | Yes | `WAMR_BUILD_EXTENDED_CONST_EXPR` |
| Garbage Collection | Yes | `WAMR_BUILD_GC` |
| Legacy Exception Handling[^3] | No | `WAMR_BUILD_EXCE_HANDLING` |
| Memory64 | Yes | `WAMR_BUILD_MEMORY64` |
| Multiple Memories[^4] | Yes | `WAMR_BUILD_MULTI_MEMORY` |
| Reference-Typed Strings | No | `WAMR_BUILD_STRINGREF` |
| Tail Call | Yes | `WAMR_BUILD_TAIL_CALL` |
| Threads[^5] | Yes | `WAMR_BUILD_SHARED_MEMORY` |
| Typed Function References | Yes | `WAMR_BUILD_GC` |
[^2]:
[^3]:
interpreter only. [a legacy version](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md).
This proposal is currently also known as the "legacy proposal" and still
supported in the web, but can be deprecated in future and the use of
this proposal is discouraged.
[^3]: interpreter only
[^4]: `WAMR_BUILD_LIB_PTHREAD` can also be used to enable
[^4]: interpreter only
[^5]: `WAMR_BUILD_LIB_PTHREAD` can also be used to enable
## Unimplemented Wasm Proposals
@ -52,13 +56,11 @@ Users can turn those features on or off by using compilation options. If a relev
| ------------------------------------------- | ---------- |
| Branch Hinting | Yes |
| Custom Annotation Syntax in the Text Format | Yes |
| Exception handling[^5] | Yes |
| Extended Constant Expressions | Yes |
| Import/Export of Mutable Globals | Yes |
| Exception Handling[^6] | Yes |
| JS String Builtins | Yes |
| Relaxed SIMD | Yes |
[^5]: [up-to-date version](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md)
[^6]: [up-to-date version](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md)
## On-by-default WASI Proposals

View File

@ -12,14 +12,15 @@ wasm_proposal_print_status(void)
{
printf("About Wasm Proposals:\n");
printf(" Always-on:\n");
printf(" - Import/Export of Mutable Globals\n");
printf(" - Multi-value\n");
printf(" - Non-trapping float-to-int conversions\n");
printf(" - Sign-extension operators\n");
printf(" - Non-trapping float-to-int Conversions\n");
printf(" - Sign-extension Operators\n");
printf(" - WebAssembly C and C++ API\n");
printf(" Compilation Configurable. 0 is OFF. 1 is ON:\n");
printf(" - Bulk Memory Operation via WASM_ENABLE_BULK_MEMORY: %u\n",
WASM_ENABLE_BULK_MEMORY);
printf(" - Fixed-Width SIMD via WASM_ENABLE_SIMD: %u\n",
printf(" - Fixed-width SIMD via WASM_ENABLE_SIMD: %u\n",
WASM_ENABLE_SIMD);
printf(" - Garbage Collection via WASM_ENABLE_GC: %u\n", WASM_ENABLE_GC);
printf(
@ -27,7 +28,7 @@ wasm_proposal_print_status(void)
WASM_ENABLE_EXCE_HANDLING);
printf(" - Memory64 via WASM_ENABLE_MEMORY64: %u\n",
WASM_ENABLE_MEMORY64);
printf(" - Multiple Memory via WASM_ENABLE_MULTI_MEMORY: %u\n",
printf(" - Multiple Memories via WASM_ENABLE_MULTI_MEMORY: %u\n",
WASM_ENABLE_MULTI_MEMORY);
printf(" - Reference Types via WASM_ENABLE_REF_TYPES: %u\n",
WASM_ENABLE_REF_TYPES);
@ -42,9 +43,7 @@ wasm_proposal_print_status(void)
printf(" Unsupported (>= Phase4):\n");
printf(" - Branch Hinting\n");
printf(" - Custom Annotation Syntax in the Text Format\n");
printf(" - Exception handling\n");
printf(" - Extended Constant Expressions\n");
printf(" - Import/Export of Mutable Globals\n");
printf(" - Exception Handling\n");
printf(" - JS String Builtins\n");
printf(" - Relaxed SIMD\n");
}

View File

@ -0,0 +1,91 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.8.2)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(wamr)
enable_language (ASM)
set (WAMR_BUILD_PLATFORM "zephyr")
# WAMR Configuration:
set (WAMR_BUILD_TARGET "THUMB")
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_FAST_INTERP 0)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_LIBC_BUILTIN 1) # printf
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_LIB_PTHREAD 0)
set (WAMR_BUILD_GLOBAL_HEAP_POOL 1)
set (WAMR_BUILD_GLOBAL_HEAP_SIZE 131072) # 128 KB
# set (WAMR_BUILD_GLOBAL_HEAP_SIZE 65536) # 64 KB
# Environment variables:
# Check if WAMR_ROOT_DIR is set
if(DEFINED ENV{WAMR_ROOT_DIR})
set(WAMR_ROOT_DIR $ENV{WAMR_ROOT_DIR})
else()
message(FATAL_ERROR "'WAMR_ROOT_DIR' need to be specified")
endif()
message("wasi-sdk was found at ${WAMR_ROOT_DIR}")
# Check if WASI_SDK_PATH is set
if(NOT $ENV{WASI_SDK_PATH} STREQUAL "")
set(WASI_SDK_PATH $ENV{WASI_SDK_PATH})
else()
find_program(WASM_C_COMPILER clang /opt/wasi-sdk/bin NO_DEFAULT_PATH)
if(NOT WASM_C_COMPILER)
message(FATAL_ERROR "'wasi-sdk' not found, please ensure wasi-sdk is installed.\
You can download and install it from\
https://github.com/WebAssembly/wasi-sdk/releases")
else()
set(WASI_SDK_PATH /opt/wasi-sdk)
endif()
endif()
message("wasi-sdk was found at ${WASI_SDK_PATH}")
# Check if WAMR_APP_FRAMEWORK_DIR is set
if (DEFINED ENV{WAMR_APP_FRAMEWORK_DIR})
set(WAMR_APP_FRAMEWORK_DIR $ENV{WAMR_APP_FRAMEWORK_DIR})
else()
message(FATAL_ERROR "'wamr-app-framework' not found, please ensure they are installed.\
You can download and install them from\
https://github.com/bytecodealliance/wamr-app-framework")
endif()
message("wamr-app-framework was found at ${WAMR_APP_FRAMEWORK_DIR}")
# set the WAMR_SDK_DIR with the path specified in the environment variable
set(WAMR_SDK_DIR
${WAMR_APP_FRAMEWORK_DIR}/wamr-sdk
)
# set the WAMR_LIBC_BUILTIN_DIR
set(WAMR_LIBC_BUILTIN_DIR
${WAMR_SDK_DIR}/wamr-sdk/app/libc-builtin-sysroot
)
# set the WAMR_SDK_PACKAGE_OUT_DIR
set(WAMR_SDK_PACKAGE_OUT_DIR
${CMAKE_CURRENT_BINARY_DIR}/wamr-sdk/app-sdk/wamr-app-framework
)
# # Reset linker flags
# set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
# set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
# include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) # in socket-api sample
# Build the WAMR runtime
target_sources(app PRIVATE
${WAMR_RUNTIME_LIB_SOURCE}
src/main.c)
# Link libraries like in samples.
set(WASI_LIBM "${WASI_SDK_PATH}/share/wasi-sysroot/lib/wasm32-wasi/libm.a")
set(WASI_LIBDL "${WASI_SDK_PATH}/share/wasi-sysroot/lib/wasm32-wasi/libdl.a")
target_link_libraries(app PUBLIC ${WASI_LIBM} ${WASI_LIBDL})

View File

@ -0,0 +1,91 @@
# File sample
This sample demonstrates the use of WASI API to interact with the file system.
> 🛠️ **Work in progress:** The sample is functional but be aware that just a small part of WASI File System API was tested.
> Actual Zephyr APIs:
> * directory creation = `fs_mkdir`
> * file opening/creation = `fs_open`
> * file write = `fs_write`
> * file offset = `fs_seek`
> * file read = `fs_read`
> * file close = `fs_close`
> * directory close = `fs_closedir`
## Run Command
* **Zephyr Build**
1. **Build:** Replace `nucleo_h743zi` with your board name and the `WAMR_BUILD_TARGET` in `CMakeList.txt` with your target architecture.
```bash
ZEPHYR_BASE=~/zephyrproject/zephyr \
WAMR_ROOT_DIR=~/wasm-micro-runtime \
WASI_SDK_PATH=~/wasi-sdk-21.0 \
WAMR_APP_FRAMEWORK_DIR=~/wamr-app-framework \
west build . -b nucleo_h563zi -p always
```
⚠️ **Warning:** The flags `ZEPHYR_BASE`, `WAMR_ROOT_DIR`, `WASI_SDK_PATH`, and `WAMR_APP_FRAMEWORK_DIR` need to be set otherwise the build will fail.
2. **Flash:**
```bash
ZEPHYR_BASE=~/zephyrproject/zephyr west flash
```
3. **Monitor:** Use a serial link to monitor the output. Personally, I use minicom.
```bash
minicom -D /dev/ttyACM0
```
4. **Debug:** Curently investigating.
* **WebAssembly Module**
**Important:** I used wasi-sdk 21 to compile the module. I still haven't tried the module with the new wasi-sdk 22.
1. **Compile:** in the `wasm-apps` folder.
```bash
~/wasi-sdk-21.0/bin/clang --sysroot=/home/user/wasi-sdk-21.0/share/wasi-sysroot -nodefaultlibs -lc -o file.wasm file.c -z stack-size=8192 -Wl,--initial-memory=65536 -Wl,--export=__heap_base -Wl,--export=__data_end
```
2. **generate a C header:** Use `xxd` or other tool, I also put simple python script. At application root `simple-file/`.
```bash
python3 to_c_header.py
```
Be free to modify the script to fit your needs.
## Output
The output should be similar to the following:
```bash
*** Booting Zephyr OS build v3.6.0-4305-g2ec8f442a505 ***
Area 3 at 0x1f0000 on flash-controller@40022000 for 65536 bytes
[00:00:00.067,000] <inf> littlefs: LittleFS version 2.8, disk version 2.1
[00:00:00.074,000] <inf> littlefs: FS at flash-controller@40022000:0x1f0000 is 8 0x2000-byte blocks with 512 cycle
[00:00:00.085,000] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[00:00:00.092,000] <err> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1351: Corrupted dir pair at {0x0, 0x1}
[00:00:00.103,000] <wrn> littlefs: can't mount (LFS -84); formatting
[00:00:00.114,000] <inf> littlefs: /lfs mounted
/lfs mount: 0
[00:00:00.120,000] <inf> main: stdin = 0
[00:00:00.124,000] <inf> main: stdout = 1
[00:00:00.128,000] <inf> main: stderr = 2
[00:00:00.133,000] <inf> main: global heap size: 131072
[00:00:00.142,000] <inf> main: Wasm file size: 34682
[00:00:00:000 - 2000AFE0]: WASI context initialization: START
[OS] os_rwlock_init
[OS] os_rwlock_init
[00:00:00:000 - 2000AFE0]: WASI context initialization: END
[00:00:00.190,000] <inf> main: main found
Hello WebAssembly Module !
mkdir returned 0
fopen Succeed
fwrite returned 13
fseek returned 0
fread returned 13
buffer read = Hello, World!
[00:00:00.225,000] <inf> main: main executed
[00:00:00.230,000] <inf> main: wasi exit code: 0
[00:00:00.239,000] <inf> main: elapsed: 178ms
[00:00:03.158,000] <inf> phy_mii: PHY (0) Link speed 100 Mb, full duplex
[00:00:00.051,000] <inf> phy_mii: PHY (0) ID 7C131
```

View File

@ -0,0 +1,40 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Log config
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
# CONFIG_LOG_MODE_DEFERRED=y
CONFIG_MAIN_STACK_SIZE=8192
# CONFIG_HEAP_MEM_POOL_SIZE=32768
CONFIG_REQUIRES_FULL_LIBC=y
# Config File System
CONFIG_POSIX_API=n
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
# CONFIG_FS_LITTLEFS_BLK_DEV=y
# Temp Build Network stack to compile.
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_NET_TCP=y
CONFIG_NET_SOCKETS=y
# Random generator
CONFIG_TEST_RANDOM_GENERATOR=y
# Stack conf
CONFIG_STACK_SENTINEL=y
CONFIG_HW_STACK_PROTECTION=y
# Flash
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
# Debug
CONFIG_DEBUG=y

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,225 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// #include <autoconf.h>
#include <stdlib.h>
#include <string.h>
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "wasm_export.h"
#include "file.h"
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/fs/fs.h>
#include <zephyr/fs/littlefs.h>
#include <zephyr/logging/log.h>
#include <unistd.h>
#define CONFIG_HEAP_MEM_POOL_SIZE WASM_GLOBAL_HEAP_SIZE
#define CONFIG_APP_STACK_SIZE 16384
#define CONFIG_APP_HEAP_SIZE 16384
LOG_MODULE_REGISTER(main);
static char global_heap_buf[CONFIG_HEAP_MEM_POOL_SIZE] = { 0 };
static int app_argc;
static char **app_argv;
//-------------------------------------------------------------------------------------------//
static int
littlefs_flash_erase(unsigned int id)
{
const struct flash_area *pfa;
int rc;
rc = flash_area_open(id, &pfa);
if (rc < 0) {
LOG_ERR("FAIL: unable to find flash area %u: %d\n", id, rc);
return rc;
}
LOG_PRINTK("Area %u at 0x%x on %s for %u bytes\n", id,
(unsigned int)pfa->fa_off, pfa->fa_dev->name,
(unsigned int)pfa->fa_size);
/* Optional wipe flash contents */
if (IS_ENABLED(CONFIG_APP_WIPE_STORAGE)) {
rc = flash_area_erase(pfa, 0, pfa->fa_size);
LOG_ERR("Erasing flash area ... %d", rc);
}
flash_area_close(pfa);
return rc;
}
#define PARTITION_NODE DT_NODELABEL(lfs1)
#if DT_NODE_EXISTS(PARTITION_NODE)
FS_FSTAB_DECLARE_ENTRY(PARTITION_NODE);
#else /* PARTITION_NODE */
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
static struct fs_mount_t lfs_storage_mnt = {
.type = FS_LITTLEFS,
.fs_data = &storage,
.storage_dev = (void *)FIXED_PARTITION_ID(storage_partition),
.mnt_point = "/lfs",
};
#endif /* PARTITION_NODE */
struct fs_mount_t *mountpoint =
#if DT_NODE_EXISTS(PARTITION_NODE)
&FS_FSTAB_ENTRY(PARTITION_NODE)
#else
&lfs_storage_mnt
#endif
;
static int
littlefs_mount(struct fs_mount_t *mp)
{
int rc;
rc = littlefs_flash_erase((uintptr_t)mp->storage_dev);
if (rc < 0) {
return rc;
}
/* Do not mount if auto-mount has been enabled */
#if !DT_NODE_EXISTS(PARTITION_NODE) \
|| !(FSTAB_ENTRY_DT_MOUNT_FLAGS(PARTITION_NODE) & FS_MOUNT_FLAG_AUTOMOUNT)
rc = fs_mount(mp);
if (rc < 0) {
LOG_PRINTK("FAIL: mount id %" PRIuPTR " at %s: %d\n",
(uintptr_t)mp->storage_dev, mp->mnt_point, rc);
return rc;
}
LOG_PRINTK("%s mount: %d\n", mp->mnt_point, rc);
#else
LOG_PRINTK("%s automounted\n", mp->mnt_point);
#endif
return 0;
}
//-------------------------------------------------------------------------------------------//
int
main(void)
{
int start, end;
start = k_uptime_get_32();
uint8 *wasm_file_buf = NULL;
uint32 wasm_file_size;
wasm_module_t wasm_module = NULL;
wasm_module_inst_t wasm_module_inst = NULL;
RuntimeInitArgs init_args;
char error_buf[128];
const char *exception;
int rc;
int log_verbose_level = 2;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
rc = littlefs_mount(mountpoint);
if (rc < 0) {
LOG_ERR("FAIL: mounting %s: %d\n", mountpoint->mnt_point, rc);
return 0;
}
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
LOG_INF("global heap size: %d", sizeof(global_heap_buf));
#else
#error "memory allocation scheme is not defined."
#endif
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
LOG_ERR("Init runtime environment failed.");
return;
}
/* load WASM byte buffer from byte buffer of include file */
wasm_file_buf = (uint8 *)wasm_test_file;
wasm_file_size = sizeof(wasm_test_file);
LOG_INF("Wasm file size: %d", wasm_file_size);
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
LOG_ERR("Failed to load module: %s", error_buf);
goto fail1;
}
/* Set the WASI context */
#if WASM_ENABLE_LIBC_WASI != 0
#define DIR_LIST_SIZE 1
const char *dir_list[DIR_LIST_SIZE] = {
"/lfs",
};
/* No dir list => No file system
* dir_cont = 0
* No mapped dir list => No file system
* map_dir_cont = 0
* No environment variables
* env_count = 0
* No command line arguments
* argv 0
*/
wasm_runtime_set_wasi_args(wasm_module, dir_list, DIR_LIST_SIZE, NULL, 0,
NULL, 0, NULL, 0);
#endif
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(
wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE,
error_buf, sizeof(error_buf)))) {
LOG_ERR("Failed to instantiate module: %s", error_buf);
goto fail2;
}
/* invoke the main function */
if (wasm_runtime_lookup_function(wasm_module_inst, "_start")
|| wasm_runtime_lookup_function(wasm_module_inst, "__main_argc_argv")
|| wasm_runtime_lookup_function(wasm_module_inst, "main")) {
LOG_INF("main found");
wasm_application_execute_main(wasm_module_inst, 0, NULL);
LOG_INF("main executed");
}
else {
LOG_ERR("Failed to lookup function main");
return -1;
}
if ((exception = wasm_runtime_get_exception(wasm_module_inst)))
LOG_ERR("get exception: %s", exception);
rc = wasm_runtime_get_wasi_exit_code(wasm_module_inst);
LOG_INF("wasi exit code: %d", rc);
/* destroy the module instance */
wasm_runtime_deinstantiate(wasm_module_inst);
fail2:
/* unload the module */
wasm_runtime_unload(wasm_module);
fail1:
/* destroy runtime environment */
wasm_runtime_destroy();
end = k_uptime_get_32();
LOG_INF("elapsed: %dms", (end - start));
return 0;
}

View File

@ -0,0 +1,32 @@
# Copyright (C) 2024 Grenoble INP - ESISAR. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Python script to convert wasm file to byte array in a .h file
import os
CWD = os.getcwd()
CMAKE_CURRENT_BINARY_DIR = os.getenv('CMAKE_CURRENT_BINARY_DIR', CWD)
CMAKE_CURRENT_SOURCE_DIR = os.getenv('CMAKE_CURRENT_SOURCE_DIR', f'{CWD}/../src')
LICENCE_HEADER = """/*
* Copyright (C) 2024 Grenoble INP - ESISAR. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
"""
print('CMAKE_CURRENT_BINARY_DIR:', CMAKE_CURRENT_BINARY_DIR)
print('CMAKE_CURRENT_SOURCE_DIR:', CMAKE_CURRENT_SOURCE_DIR)
# Open the wasm file in binary mode and read the data
with open(f'{CWD}/wasm-apps/file.wasm', 'rb') as f:
wasm_bytes = f.read()
# Convert the bytes to a comma-separated string of hex values
byte_array = ', '.join(f'0x{byte:02x}' for byte in wasm_bytes)
# Create the output string
output = f'{LICENCE_HEADER}\nunsigned char __aligned(4) wasm_test_file[] = {{ {byte_array} }};'
# Write the output string to the .h file
with open(f'{CWD}/src/file.h', 'w') as f:
f.write(output)

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2024 Grenoble INP - ESISAR. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <errno.h>
// Zephyr
#define CWD "/lfs"
#define FOLDER_PATH CWD "/folder"
#define FILE_PATH CWD "folder/test.txt"
int
main(int argc, char **argv)
{
int rc;
const int zero = 0;
printf("Hello WebAssembly Module !\n");
rc = mkdir(FOLDER_PATH, 0777);
if (rc < 0) {
rc = errno;
printf("mkdir failed with error %d\n", rc);
return -1;
}
printf("mkdir returned %d\n", rc);
FILE *file = fopen(FILE_PATH, "w+");
if (!file) {
printf("fopen Failed to open\n");
return -1;
}
printf("fopen Succeed\n");
const char *data = "Hello, World!";
size_t len = 13;
size_t nitems = fwrite(data, sizeof(char), 13, file);
printf("fwrite returned %d\n", (int)nitems);
rc = fseek(file, 0, SEEK_SET);
printf("fseek returned %d\n", rc);
char buffer[32];
nitems = fread(buffer, sizeof(char), 32, file);
printf("fread returned %d\n", (int)nitems);
printf("buffer read = %s\n", buffer);
fclose(file);
return 0;
}

View File

@ -0,0 +1,89 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.8.2)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(wamr)
enable_language (ASM)
set (WAMR_BUILD_PLATFORM "zephyr")
# WAMR Configuration:
set (WAMR_BUILD_TARGET "THUMB")
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1) # printf
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_LIB_PTHREAD 0)
set (WAMR_BUILD_GLOBAL_HEAP_POOL 1)
set (WAMR_BUILD_GLOBAL_HEAP_SIZE 98304) # 96 KB
# Environment variables:
# Check if WAMR_ROOT_DIR is set
if(DEFINED ENV{WAMR_ROOT_DIR})
set(WAMR_ROOT_DIR $ENV{WAMR_ROOT_DIR})
else()
message(FATAL_ERROR "'WAMR_ROOT_DIR' need to be specified")
endif()
message("wasi-sdk was found at ${WAMR_ROOT_DIR}")
# Check if WASI_SDK_PATH is set
if(NOT $ENV{WASI_SDK_PATH} STREQUAL "")
set(WASI_SDK_PATH $ENV{WASI_SDK_PATH})
else()
find_program(WASM_C_COMPILER clang /opt/wasi-sdk/bin NO_DEFAULT_PATH)
if(NOT WASM_C_COMPILER)
message(FATAL_ERROR "'wasi-sdk' not found, please ensure wasi-sdk is installed.\
You can download and install it from\
https://github.com/WebAssembly/wasi-sdk/releases")
else()
set(WASI_SDK_PATH /opt/wasi-sdk)
endif()
endif()
message("wasi-sdk was found at ${WASI_SDK_PATH}")
# Check if WAMR_APP_FRAMEWORK_DIR is set
if (DEFINED ENV{WAMR_APP_FRAMEWORK_DIR})
set(WAMR_APP_FRAMEWORK_DIR $ENV{WAMR_APP_FRAMEWORK_DIR})
else()
message(FATAL_ERROR "'wamr-app-framework' not found, please ensure they are installed.\
You can download and install them from\
https://github.com/bytecodealliance/wamr-app-framework")
endif()
message("wamr-app-framework was found at ${WAMR_APP_FRAMEWORK_DIR}")
# set the WAMR_SDK_DIR with the path specified in the environment variable
set(WAMR_SDK_DIR
${WAMR_APP_FRAMEWORK_DIR}/wamr-sdk
)
# set the WAMR_LIBC_BUILTIN_DIR
set(WAMR_LIBC_BUILTIN_DIR
${WAMR_SDK_DIR}/wamr-sdk/app/libc-builtin-sysroot
)
# set the WAMR_SDK_PACKAGE_OUT_DIR
set(WAMR_SDK_PACKAGE_OUT_DIR
${CMAKE_CURRENT_BINARY_DIR}/wamr-sdk/app-sdk/wamr-app-framework
)
# # Reset linker flags
# set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
# set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
# include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) # in socket-api sample
# Build the WAMR runtime
target_sources(app PRIVATE
${WAMR_RUNTIME_LIB_SOURCE}
src/main.c)
# Link libraries like in samples.
set(WASI_LIBM "${WASI_SDK_PATH}/share/wasi-sysroot/lib/wasm32-wasi/libm.a")
set(WASI_LIBDL "${WASI_SDK_PATH}/share/wasi-sysroot/lib/wasm32-wasi/libdl.a")
target_link_libraries(app PUBLIC ${WASI_LIBM} ${WASI_LIBDL})

View File

@ -0,0 +1,143 @@
# Socket sample
this sample demonstrates the use of WASI API to interact with sockets.
> ❗ **Important:** This sample was ported/adapted from the http_get zephyr sample. The original sample can be found [here]( https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/net/sockets/http_get/src/http_get.c).
> 🛠️ **Work in progress:** The sample is functional but be aware that just a small part of WASI socket API was tested.
> Actual Zephyr APIs:
> * socket creation = `zsock_socket`
> * socket connection = `zsock_connect`
> * socket emission = `zsock_sendto`
> * socket reception = `zsock_recvfrom`
> * socket destruction = `zsock_close`
>
> With the sockets most API are in fact provided by the runtime instead of WASI because of the lack of socket support in WASI preview1.
## Setup
1. Connect a network cable to the board ethernet port.
2. Configure the network interface on the host machine
```
Internet Protocol Version 4 (TCP/IPv4) Properties:
IP Address: 192.0.2.10
Subnet Mask: 255.255.255.0
Default Gateway: 192.0.2.2
```
3. Start a simple HTTP server on the host machine.
```bash
python3 -m http.server --bind 0.0.0.0
```
4. Disable any firewall that may block the connection.
## Configuration
To configure the server side IP address and port modify the following lines in the `http_get.c` file.
1. The `HTTP_HOST` and `HTTP_PORT` macros define the server IP address and port.
```c
/* HTTP server to connect to */
#define HTTP_HOST "192.0.2.10"
/* Port to connect to, as string */
#define HTTP_PORT "8000"
/* HTTP path to request */
#define HTTP_PATH "/"
// ...
#define REQUEST "GET " HTTP_PATH " HTTP/1.0\r\nHost: " HTTP_HOST "\r\n\r\n"
```
> 📄 **Notes:** These macros are used to build the request string, but they are not used to instantiate the address structure. Because at one point we didn't want to use `inet_pton` to convert the string to an address and it remained like this.
2. The `addr` structure is used to store the server address.
```c
addr.sin_port = htons(8000);
addr.sin_addr.s_addr =
htonl(0xC000020A); // hard coded IP address for 192.0.2.10
```
To configure the authorized IP address(es) modify the following lines in the `main.c` file. WAMR will only allow the IP addresses in the pool to connect to the server.
```c
#define ADDRESS_POOL_SIZE 1
const char *addr_pool[ADDRESS_POOL_SIZE] = {
"192.0.2.10/24",
};
```
## Run Command
* **Zephyr Build**
1. **Build:** Replace `nucleo_h743zi` with your board name and the `WAMR_BUILD_TARGET` in `CMakeList.txt` with your target architecture.
```bash
ZEPHYR_BASE=~/zephyrproject/zephyr \
WAMR_ROOT_DIR=~/wasm-micro-runtime \
WASI_SDK_PATH=~/wasi-sdk-21.0 \
WAMR_APP_FRAMEWORK_DIR=~/wamr-app-framework \
west build . -b nucleo_h563zi -p always
```
⚠️ **Warning:** The flags `ZEPHYR_BASE`, `WAMR_ROOT_DIR`, `WASI_SDK_PATH`, and `WAMR_APP_FRAMEWORK_DIR` need to be set otherwise the build will fail.
2. **Flash:**
```bash
ZEPHYR_BASE=~/zephyrproject/zephyr west flash
```
3. **Monitor:** Use a serial link to monitor the output. Personally, I use minicom.
```bash
minicom -D /dev/ttyACM0
```
4. **Debug:** Curently investigating.
* **WebAssembly Module**
**Important:** I used wasi-sdk 21 to compile the module. I still haven't tried the module with the new wasi-sdk 22.
0. **Compile a static lib:** in the `wasm-apps` folder.
* **Compile the an object:**
```bash
~/wasi-sdk-21.0/bin/clang --sysroot=/home/user/wasi-sdk-21.0/share/wasi-sysroot -Iinc/ -c inc/wasi_socket_ext.c -o inc/wasi_socket_ext.o
```
* **Create a static lib:**
```bash
~/wasi-sdk-21.0/bin/llvm-ar rcs inc/libwasi_socket_ext.a inc/wasi_socket_ext.o
```
1. **Compile:** in the `wasm-apps` folder.
```bash
~/wasi-sdk-21.0/bin/clang --sysroot=/home/user/wasi-sdk-21.0/share/wasi-sysroot -Iinc/ -nodefaultlibs -o http_get.wasm http_get.c -lc -Linc/ -lwasi_socket_ext -z stack-size=8192 -Wl,--initial-memory=65536 -Wl,--export=__heap_base -Wl,--export=__data_end -Wl,--allow-undefined
```
2. **generate a C header:** Use `xxd` or other tool, I also put simple python script. At application root `simple-http/`.
```bash
python3 to_c_header.py
```
Be free to modify the script to fit your needs.
## Output
The output should be similar to the following:
```bash
*** Booting Zephyr OS build v3.6.0-4305-g2ec8f442a505 ***
[00:00:00.061,000] <inf> net_config: Initializing network
[00:00:00.067,000] <inf> net_config: Waiting interface 1 (0x2000a910) to be up...
[00:00:03.158,000] <inf> phy_mii: PHY (0) Link speed 100 Mb, full duplex
[00:00:03.288,000] <inf> net_config: Interface 1 (0x2000a910) coming up
[00:00:03.295,000] <inf> net_config: IPv4 address: 192.0.2.1
global heap size: 131072
Wasm file size: 36351
main found
[wasm-mod] Preparing HTTP GET request for http://192.0.2.10:8000/
[wasm-mod] sock = 3
[wasm-mod] connect rc = 0
[wasm-mod] send rc = 36
[wasm-mod] Response:
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.10.10
Date: Fri, 14 Jun 2024 07:26:56 GMT
Content-type: text/html; charset=utf-8
Content-Length: 2821
# Skip the HTML content
[wasm-mod] len = 0 break
[wasm-mod] Connection closed
main executed
wasi exit code: 0
elapsed: 405ms
```

View File

@ -0,0 +1,61 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Log config
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_NET_LOG=y
CONFIG_MAIN_STACK_SIZE=8192
# CONFIG_HEAP_MEM_POOL_SIZE=32768
CONFIG_REQUIRES_FULL_LIBC=y
# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_NET_TCP=y
CONFIG_NET_SOCKETS=y
CONFIG_POSIX_API=n
# Stack conf
# CONFIG_NO_OPTIMIZATIONS=y
CONFIG_STACK_SENTINEL=y
CONFIG_HW_STACK_PROTECTION=y
# CONFIG_STACK_CANARIES=y
# CONFIG_ISR_STACK_SIZE=4096
# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y
# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
# Config File System
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
# Flash
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
# CONFIG_DNS_RESOLVER=y
# CONFIG_DNS_SERVER_IP_ADDRESSES=y
# CONFIG_DNS_SERVER1="192.0.2.2"
# Config init stack
# CONFIG_INIT_STACKS=y
# CONFIG_NET_PKT_RX_COUNT=100
# CONFIG_NET_PKT_TX_COUNT=100
# CONFIG_NET_BUF_RX_COUNT=100
# CONFIG_NET_BUF_TX_COUNT=100
# Flash
CONFIG_FLASH=y
# Debug
CONFIG_DEBUG=y

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,141 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// #include <autoconf.h>
#include <stdlib.h>
#include <string.h>
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "wasm_export.h"
#include "http_get.h"
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/http/client.h>
#define CONFIG_HEAP_MEM_POOL_SIZE WASM_GLOBAL_HEAP_SIZE
#define CONFIG_APP_STACK_SIZE 8192
#define CONFIG_APP_HEAP_SIZE 8192
static char global_heap_buf[CONFIG_HEAP_MEM_POOL_SIZE] = { 0 };
static int app_argc;
static char **app_argv;
int
main(void)
{
int start, end;
start = k_uptime_get_32();
uint8 *wasm_file_buf = NULL;
uint32 wasm_file_size;
wasm_module_t wasm_module = NULL;
wasm_module_inst_t wasm_module_inst = NULL;
RuntimeInitArgs init_args;
char error_buf[128];
const char *exception;
int log_verbose_level = 2;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
printf("global heap size: %d\n", sizeof(global_heap_buf));
#else
#error "memory allocation scheme is not defined."
#endif
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
printf("Init runtime environment failed.\n");
return;
}
bh_log_set_verbose_level(log_verbose_level);
/* load WASM byte buffer from byte buffer of include file */
wasm_file_buf = (uint8 *)wasm_test_file;
wasm_file_size = sizeof(wasm_test_file);
printf("Wasm file size: %d\n", wasm_file_size);
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
printf("Failed to load module: %s\n", error_buf);
goto fail1;
}
/* Set the WASI context */
#if WASM_ENABLE_LIBC_WASI != 0
#define ADDRESS_POOL_SIZE 1
const char *addr_pool[ADDRESS_POOL_SIZE] = {
"192.0.2.10/24",
};
/* No dir list => No file system
* dir_cont = 0
* No mapped dir list => No file system
* map_dir_cont = 0
* No environment variables
* env_count = 0
* No command line arguments
* argv 0
*/
wasm_runtime_set_wasi_args(wasm_module, NULL, 0, NULL, 0, NULL, 0, NULL, 0);
wasm_runtime_set_wasi_addr_pool(wasm_module, addr_pool, ADDRESS_POOL_SIZE);
wasm_runtime_set_wasi_ns_lookup_pool(wasm_module, NULL, 0);
#endif
/* instantiate the module */
if (!(wasm_module_inst = wasm_runtime_instantiate(
wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE,
error_buf, sizeof(error_buf)))) {
printf("Failed to instantiate module: %s\n", error_buf);
goto fail2;
}
/* invoke the main function */
if (wasm_runtime_lookup_function(wasm_module_inst, "_start")
|| wasm_runtime_lookup_function(wasm_module_inst, "__main_argc_argv")) {
printf("main found\n");
wasm_application_execute_main(wasm_module_inst, 0, NULL);
printf("main executed\n");
}
else {
printf("Failed to lookup function main\n");
return -1;
}
if ((exception = wasm_runtime_get_exception(wasm_module_inst)))
printf("%s\n", exception);
int rc = wasm_runtime_get_wasi_exit_code(wasm_module_inst);
printf("wasi exit code: %d\n", rc); // 1 = _WASI_E2BIG
/* destroy the module instance */
wasm_runtime_deinstantiate(wasm_module_inst);
fail2:
/* unload the module */
wasm_runtime_unload(wasm_module);
fail1:
/* destroy runtime environment */
wasm_runtime_destroy();
end = k_uptime_get_32();
printf("elapsed: %dms\n", (end - start));
return 0;
}

View File

@ -0,0 +1,34 @@
# Copyright (C) 2024 Grenoble INP - ESISAR. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Python script to convert wasm file to byte array in a .h file
import os
CWD = os.getcwd()
CMAKE_CURRENT_BINARY_DIR = os.getenv('CMAKE_CURRENT_BINARY_DIR', CWD)
CMAKE_CURRENT_SOURCE_DIR = os.getenv('CMAKE_CURRENT_SOURCE_DIR', f'{CWD}/../src')
LICENCE_HEADER = """/*
* Copyright (c) 2017 Linaro Limited
* Copyright (C) 2024 Grenoble INP - ESISAR Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
"""
print('CMAKE_CURRENT_BINARY_DIR:', CMAKE_CURRENT_BINARY_DIR)
print('CMAKE_CURRENT_SOURCE_DIR:', CMAKE_CURRENT_SOURCE_DIR)
# Open the wasm file in binary mode and read the data
with open(f'{CWD}/wasm-apps/http_get.wasm', 'rb') as f:
wasm_bytes = f.read()
# Convert the bytes to a comma-separated string of hex values
byte_array = ', '.join(f'0x{byte:02x}' for byte in wasm_bytes)
# Create the output string
output = f'unsigned char __aligned(4) wasm_test_file[] = {{ {byte_array} }};'
# Write the output string to the .h file
with open(f'{CWD}/src/http_get.h', 'w') as f:
f.write(output)

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2017 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#ifdef __wasi__
#include <wasi_socket_ext.h>
#endif
/* HTTP server to connect to */
#define HTTP_HOST "192.0.2.10"
/* Port to connect to, as string */
#define HTTP_PORT "8000"
/* HTTP path to request */
#define HTTP_PATH "/"
#define SSTRLEN(s) (sizeof(s) - 1)
// #define CHECK(r) { if (r == -1) { printf("Error %d: " #r "\n", errno);
// exit(1); } }
#define REQUEST "GET " HTTP_PATH " HTTP/1.0\r\nHost: " HTTP_HOST "\r\n\r\n"
static char response[1024];
int
main(int argc, char **argv)
{
int st, sock;
struct sockaddr_in addr;
int rc = 0;
printf("[wasm-mod] Preparing HTTP GET request for http://" HTTP_HOST
":" HTTP_PORT HTTP_PATH "\n");
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(8000);
addr.sin_addr.s_addr =
htonl(0xC000020A); // hard coded IP address for 192.0.2.10
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
printf("[wasm-mod] sock = %d\n", sock);
rc = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
printf("[wasm-mod] connect rc = %d\n", rc);
rc = sendto(sock, (const void *)REQUEST, SSTRLEN(REQUEST), 0,
(struct sockaddr *)&addr, sizeof(addr));
printf("[wasm-mod] send rc = %d\n", rc);
if (rc < 0) {
printf("[wasm-mod] Error %d\n", errno);
return 0;
}
printf("[wasm-mod] Response:\n\n");
while (1) {
socklen_t socklen = sizeof(struct sockaddr_in);
int len = recvfrom(sock, response, sizeof(response) - 1, 0,
(struct sockaddr *)&addr, &socklen);
if (len < 0) {
printf("[wasm-mod] Error %d\n", errno);
return 0;
}
response[len] = 0;
printf("%s", response);
if (len == 0) {
printf("[wasm-mod] len = 0 break\n");
break;
}
}
printf("\n");
(void)close(sock);
printf("[wasm-mod] Connection closed\n");
return 0;
}

View File

@ -0,0 +1,5 @@
The lib source code are located there:
* [wasi_socket_ext.h](../../../../../../core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h)
* [wasi_socket_ext.c](../../../../../../core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c)

View File

@ -46,15 +46,14 @@ set(WAMR_BUILD_INTERP 1)
if (NOT DEFINED WAMR_BUILD_AOT)
set(WAMR_BUILD_AOT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_JIT)
set(WAMR_BUILD_JIT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_DUMP_CALL_STACK)
set(WAMR_BUILD_DUMP_CALL_STACK 0)
endif ()
if (NOT DEFINED WAMR_BUILD_GC)
set(WAMR_BUILD_GC 0)
endif ()
set(WAMR_BUILD_GC 0)
set(WAMR_BUILD_SIMD 1)
set(WAMR_BUILD_REF_TYPES 1)
set(WAMR_BUILD_LIBC_BUILTIN 1)
@ -160,45 +159,30 @@ ExternalProject_Add(WASM_MODULE
################ WASM MODULES TO AOT
if (WAMR_BUILD_AOT EQUAL 1)
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build)
message(CHECK_START "Detecting WAMR_COMPILER at ${WAMR_COMPILER_DIR}")
find_file(WAMR_COMPILER
wamrc
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler)
ExternalProject_Add(wamrc_local
SOURCE_DIR ${WAMR_ROOT_DIR}/wamr-compiler
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT_DIR}/wamr-compiler -B build --install-prefix ${CMAKE_CURRENT_BINARY_DIR}
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build
)
if(WAMR_COMPILER)
message(CHECK_PASS "found")
else()
message(CHECK_FAIL "not found")
endif()
if((NOT EXISTS ${WAMR_COMPILER}) )
message(FATAL_ERROR "Please build wamrc under the path=${WAMR_ROOT_DIR}/wamr-compiler/ ")
else()
message(STATUS "WAMR_COMPILER is ${WAMR_COMPILER}")
endif()
if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-dump-call-stack")
endif ()
if (WAMR_BUILD_GC EQUAL 1)
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-gc")
endif ()
add_custom_target(
wasm_to_aot
ALL
DEPENDS
WASM_MODULE ${WAMR_COMPILER}
COMMAND
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
COMMAND
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
COMMAND
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
DEPENDS WASM_MODULE wamrc_local
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()

View File

@ -1,20 +1,23 @@
# WAMR MULTI-MODUEL SAMPLE
**WAMR supports *multi-module* in both *interpreter* mode and *aot* mode.**
**WAMR supports _multi-module_ in both _interpreter_ mode and _aot_ mode.**
Multi-modules will determine the running mode based on the type of the main module.
## Interpreter mode
``` shell
$ mkdir build
```bash
$ cmake -S . -B build
$ cmake --build
$ cd build
$ cmake ..
$ make
$ # It will build multi_module runtime and
$ # wasm file under the ./build .
$ # If you have built wamrc,
$ # aot file will also generate.
$ ./multi_module mC.wasm
$ ...
$ ./multi_module mC.aot
$ ...
```
## Aot mode
```bash
$ cmake -S . -B build -DWAMR_BUILD_AOT=1
$ cmake --build
$ cd build
$ ./multi_module mC.aot
```

View File

@ -88,4 +88,4 @@ compile_with_clang(udp_server.c)
compile_with_clang(multicast_client.c)
compile_with_clang(multicast_server.c)
compile_with_clang(timeout_client.c)
compile_with_clang(timeout_server.c)
compile_with_clang(timeout_server.c)

View File

@ -62,6 +62,9 @@ if(NOT DEFINED WAMR_BUILD_AOT)
set(WAMR_BUILD_AOT 0)
endif()
include(CMakePrintHelpers)
cmake_print_variables(WAMR_BUILD_INTERP WAMR_BUILD_AOT)
if(NOT DEFINED WAMR_BUILD_JIT)
set(WAMR_BUILD_JIT 0)
endif()
@ -71,11 +74,7 @@ set(WAMR_BUILD_LIBC_WASI 0)
set(WAMR_BUILD_MULTI_MODULE 1)
set(WAMR_BUILD_DUMP_CALL_STACK 1)
set(WAMR_BUILD_REF_TYPES 1)
# If not defined WAMR_BUILD_GC, set it to 0
if(NOT DEFINED WAMRC_BUILD_WITH_GC)
set(WAMRC_BUILD_WITH_GC 0)
endif()
set(WAMR_BUILD_GC 0)
if(NOT DEFINED WAMR_BUILD_FAST_INTERP)
set(WAMR_BUILD_FAST_INTERP 1)
@ -130,17 +129,16 @@ if (${WAT2WASM_VERSION} VERSION_LESS 1.0.26)
endif ()
if(${WAMR_BUILD_AOT} EQUAL 1 AND ${WAMR_BUILD_INTERP} EQUAL 0)
## locate wamrc
find_program(WAMRC
wamrc
PATHS ${WAMR_ROOT_DIR}/wamr-compiler/build/
include(ExternalProject)
ExternalProject_Add(wamrc_local
SOURCE_DIR ${WAMR_ROOT_DIR}/wamr-compiler
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT_DIR}/wamr-compiler -B build --install-prefix ${CMAKE_CURRENT_BINARY_DIR}
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build
)
if(NOT WAMRC)
message(SEND_ERROR "can not find wamrc. refer to \
https://github.com/bytecodealliance/wasm-micro-runtime#build-wamrc-aot-compiler"
)
endif()
endif()
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
@ -182,16 +180,11 @@ foreach(EX ${EXAMPLES})
add_dependencies(${EX} ${EX}_WASM)
# generate .aot file
if(${WAMR_BUILD_AOT} EQUAL 1)
if(${WAMRC_BUILD_WITH_GC} EQUAL 1)
set(WAMRC_GC_FLAGS "--enable-gc")
else()
set(WAMRC_GC_FLAGS "")
endif()
if(${WAMR_BUILD_AOT} EQUAL 1 AND ${WAMR_BUILD_INTERP} EQUAL 0)
add_custom_target(${EX}_AOT
COMMAND ${WAMRC} ${WAMRC_GC_FLAGS} -o ${PROJECT_BINARY_DIR}/${EX}.aot
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc -o ${PROJECT_BINARY_DIR}/${EX}.aot
${PROJECT_BINARY_DIR}/${EX}.wasm
DEPENDS ${EX}_WASM
DEPENDS ${EX}_WASM wamrc_local
BYPRODUCTS ${PROJECT_BINARY_DIR}/${EX}.aot
VERBATIM
COMMENT "generate a aot file ${PROJECT_BINARY_DIR}/${EX}.aot"

View File

@ -1162,7 +1162,6 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output='de
cmd.append("--enable-multi-thread")
if opts.gc:
cmd.append("--enable-gc")
cmd.append("--enable-tail-call")
if output == 'object':

View File

@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14)
project(wasm-apps-aot-stack-frame)
set (WAMRC_OPTION --enable-dump-call-stack --bounds-checks=1 --enable-gc)
set (WAMRC_OPTION --enable-dump-call-stack --bounds-checks=1)
if (WAMR_BUILD_TARGET STREQUAL "X86_32")
set (WAMRC_OPTION ${WAMRC_OPTION} --target=i386)

View File

@ -1157,7 +1157,6 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = '
cmd.append("--enable-multi-thread")
if opts.gc:
cmd.append("--enable-gc")
cmd.append("--enable-tail-call")
if opts.extended_const:

View File

@ -835,7 +835,7 @@ function build_iwasm_with_cfg()
fi
}
function build_wamrc()
function build_wamrc_with_cfg()
{
if [[ "${TARGET_LIST[*]}" =~ "${TARGET}" ]]; then
echo "suppose wamrc is already built"
@ -852,10 +852,7 @@ function build_wamrc()
&& ./${BUILD_LLVM_SH} \
&& if [ -d build ]; then rm -r build/*; else mkdir build; fi \
&& cd build \
&& cmake .. \
-DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \
-DWAMR_BUILD_SHRUNK_MEMORY=0 \
-DWAMR_BUILD_EXTENDED_CONST_EXPR=${ENABLE_EXTENDED_CONST_EXPR} \
&& cmake $* .. \
&& make -j 4
}
@ -1073,6 +1070,18 @@ function trigger()
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=$WAMR_BUILD_SANITIZER"
fi
local WAMRC_BUILD_FLAGS=""
WAMRC_BUILD_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_SHRUNK_MEMORY=0"
if [[ ${ENABLE_GC} == 1 ]]; then
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_GC=1"
fi
if [[ ${ENABLE_EXTENDED_CONST_EXPR} == 1 ]]; then
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_EXTENDED_CONST_EXPR=1"
fi
# Make sure we're using the builtin WASI libc implementation
# if we're running the wasi certification tests.
if [[ $TEST_CASE_ARR ]]; then
@ -1148,7 +1157,7 @@ function trigger()
build_iwasm_with_cfg $BUILD_FLAGS
fi
if [ -z "${WAMRC_CMD}" ]; then
build_wamrc
build_wamrc_with_cfg $WAMRC_BUILD_FLAGS
WAMRC_CMD=${WAMRC_CMD_DEFAULT}
fi
for suite in "${TEST_CASE_ARR[@]}"; do

View File

@ -55,7 +55,17 @@ add_definitions(-DWASM_ENABLE_MODULE_INST_CONTEXT=1)
add_definitions(-DWASM_ENABLE_MEMORY64=1)
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=1)
add_definitions(-DWASM_ENABLE_GC=1)
# Sync with iwasm in config_common.cmake. Turn off GC by default.
# can be turned on by setting WAMR_BUILD_GC to 1
if (NOT DEFINED WAMR_BUILD_GC)
message ("-- GC disabled")
set(WAMR_BUILD_GC 0)
add_definitions(-DWASM_ENABLE_GC=0)
else ()
message ("-- GC enabled")
set(WAMR_BUILD_GC 1)
add_definitions(-DWASM_ENABLE_GC=1)
endif ()
set (WAMR_BUILD_STRINGREF 1)
set (WAMR_STRINGREF_IMPL_SOURCE "STUB")
@ -285,7 +295,11 @@ include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake)
include (${IWASM_DIR}/common/iwasm_common.cmake)
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
if (WAMR_BUILD_GC EQUAL 1)
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
else ()
message (STATUS "WAMR GC is disabled")
endif ()
include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)

View File

@ -179,7 +179,6 @@ print_help()
printf(" --enable-memory-profiling Enable memory usage profiling\n");
printf(" --xip A shorthand of --enable-indirect-mode --disable-llvm-intrinsics\n");
printf(" --enable-indirect-mode Enable call function through symbol table but not direct call\n");
printf(" --enable-gc Enable GC (Garbage Collection) feature\n");
printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\n");
printf(" --enable-builtin-intrinsics=<flags>\n");
printf(" Enable the specified built-in intrinsics, it will override the default\n");
@ -424,7 +423,13 @@ main(int argc, char *argv[])
option.enable_aux_stack_check = true;
option.enable_bulk_memory = true;
option.enable_ref_types = true;
#if WASM_ENABLE_GC != 0
/* gc depends on AOT_STACK_FRAME */
option.enable_gc = true;
option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD;
#else
option.enable_gc = false;
#endif
option.enable_extended_const = false;
aot_call_stack_features_init_default(&option.call_stack_features);
@ -573,10 +578,6 @@ main(int argc, char *argv[])
else if (!strcmp(argv[0], "--enable-indirect-mode")) {
option.is_indirect_mode = true;
}
else if (!strcmp(argv[0], "--enable-gc")) {
option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD;
option.enable_gc = true;
}
else if (!strcmp(argv[0], "--disable-llvm-intrinsics")) {
option.disable_llvm_intrinsics = true;
}