Commit Graph

1739 Commits

Author SHA1 Message Date
Wenyong Huang
169e164815
Fix wasm loader handling opcode br_table (#3176)
Fix the errors reported in the sanitizer test of nightly run CI.
When the stack is in polymorphic state, the stack operands may be changed
after pop and push operations (e.g. stack is empty but pop op can succeed
in polymorphic, and the push op can push a new operand to stack), this may
impact the following checks to other target blocks of the br_table opcode.
2024-02-23 14:56:20 +08:00
mkolchurin
88bfbcf89e
zephyr: include math only with minimal libc (#3177)
Use math functions only with `CONFIG_MINIMAL_LIBC=y`.

`CONFIG_PICOLIBC=y` or `CONFIG_NEWLIB_LIBC=y` provides math functions
that are used by wasm, and compilation fails when they are selected.

Signed-off-by: Maxim Kolchurin <maxim.kolchurin@gmail.com>
2024-02-23 11:24:51 +08:00
Huang Qi
94db327f06
Add comments to suppress warning from wamrc (#3175) 2024-02-22 18:57:00 +08:00
Enrico Loparco
8493ffa1cc
Add vprintf override for android and esp-idf (#3174)
And update document.
2024-02-22 17:02:46 +08:00
TianlongLiang
0fa0beba94
VSCode IDE enhancement and readme update (#3172)
- Temporarily disable the deque test for the VS Code extension, as the
  Rust formatter seems to malfunction after a recent VS Code update.
- Add configuration for iwasm host managed heap size, allowing users
  to flexibly `malloc` memory. This also fixes the current bug that when
  default size is 0, it can't run and debug.
- Apply coding style formatting for WAMR IDE source code and add a
  format check for it in CI.
- Update document and some screenshots.
2024-02-22 12:36:49 +08:00
Huang Qi
1429d8cc03
Fix inconsistent coding convention (#3171) 2024-02-22 10:40:50 +08:00
TianlongLiang
58c980c4df
Fix llvm jit push funcref/externref result type issue (#3169)
When dealing with non-gc enabled funcref/externref, need to make sure
to push them as i32 type.
2024-02-21 12:15:18 +08:00
Wenyong Huang
63cd567b3f
Separate app-manager and app-framework from WAMR (#3129)
As planned, the app-manager and app-framework are to be migrated to
https://github.com/bytecodealliance/wamr-app-framework.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2329
https://github.com/bytecodealliance/wasm-micro-runtime/wiki/TSC-meeting-notes
2024-02-20 18:12:36 +08:00
mkolchurin
b9db23b983
zephyr: Use zephyr sys_cache instead of CMSIS (#3162)
When running AOT code in Zephyr on STM32H743VIT6 without
CONFIG_CACHE_MANAGEMENT=y, a hard fault occurs, which leads to
SCB_CleanDCache().

It’s better to use the functions built into Zephyr.
2024-02-20 09:34:25 +08:00
Jämes Ménétrey
8b8c59589d
Clarify how to verify SGX evidence without an Intel SGX-enabled platform (#3158)
This PR encompasses two complementing purposes:

A documentation on verifying an Intel SGX evidence as produced by WAMR,
including a guide for verification without an Intel SGX-enabled platform.
This also contains a small addition to the RA sample to extract specific
information, such as whether the enclave is running in debug mode.

A C# sample to verify evidence on trusted premises (and without Intel SGX).
Evidence is generated on untrusted environments, using Intel SGX.
2024-02-17 18:44:22 +08:00
Wenyong Huang
b6adec373e
shared-platform: Remove dependency on shared-utils' bh_memory_remap_slow (#3153)
As an original design rule, the code in `core/shared/platform` should not
rely on the code in `core/share/utils`. In the current implementation,
platform layer calls function `bh_memory_remap_slow` in utils layer.

This PR adds inline function `os_mremap_slow` in platform_api_vmcore.h,
and lets os_remap call it if mremap fails. And remove bh_memutils.h/c as
as they are unused.

And resolve the compilation warning in wamrc:
```bash
core/shared/platform/common/posix/posix_memmap.c:255:16:
warning: implicit declaration of function ‘bh_memory_remap_slow’
  255 |         return bh_memory_remap_slow(old_addr, old_size, new_size);
```
2024-02-17 13:44:33 +08:00
Wenyong Huang
3a0e86454e
fast-interp: Fix GC opcode ref.as_non_null (#3156)
The issue was found in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3151.
2024-02-17 11:54:49 +08:00
YAMAMOTO Takashi
b0c54c8a86
Fix a ubsan complaint "applying zero offset to null pointer" (#3160)
Set a type's `result_ref_type_maps` only when `ref_type_map_count > 0`.
2024-02-17 10:11:10 +08:00
Marcin Kolny
e792c35822
Fix null pointer access in fast-interp when configurable soft bound check is enabled (#3150)
The wasm_interp_call_func_bytecode is called for the first time with the empty
module/exec_env to generate a global_handle_table. Before that happens though,
the function checks if the module instance has bounds check enabled. Because
the module instance is null, the program crashes. This PR added an extra check to
prevent the crashes.
2024-02-14 17:18:37 +08:00
Xu Jun
12f834aebd
fast-interp: Fix frame_offset overflow issue (#3149)
The issue was found in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3137.
2024-02-08 11:32:17 +08:00
Xu Jun
7cac0531ad
fast-interp: Fix copy_stack_top_i64 overlap issue (#3146)
This fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3145.
2024-02-07 13:24:47 +08:00
Wenyong Huang
16a4d71b34
Implement GC (Garbage Collection) feature for interpreter, AOT and LLVM-JIT (#3125)
Implement the GC (Garbage Collection) feature for interpreter mode,
AOT mode and LLVM-JIT mode, and support most features of the latest
spec proposal, and also enable the stringref feature.

Use `cmake -DWAMR_BUILD_GC=1/0` to enable/disable the feature,
and `wamrc --enable-gc` to generate the AOT file with GC supported.

And update the AOT file version from 2 to 3 since there are many AOT
ABI breaks, including the changes of AOT file format, the changes of
AOT module/memory instance layouts, the AOT runtime APIs for the
AOT code to invoke and so on.
2024-02-06 20:47:11 +08:00
YAMAMOTO Takashi
5931aaacbe
aot compiler: Place precheck wrapper before the corresponding wrapped function (#3141)
This increases the chance to use "short" calls.

Assumptions:
- LLVM preserves the order of functions in a module
- The wrapper function are smaller than the wrapped functions
- The target CPU has "short" PC-relative variation of call/jmp instructions
  and they are preferrable over the "long" ones.

A motivation:
- To avoid some relocations for XIP, I want to use xtensa PC-relative
  call instructions, which can only reach ~512KB.
2024-02-06 15:05:32 +08:00
YAMAMOTO Takashi
6e547baf46
aot_compile_op_call: Stop setting calling convention explicitly (#3140)
The current logic doesn't work for some cases.
cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3138

It's unclear why we are setting the calling convention explicitly here
at all. In many cases, the default just seems working.
2024-02-06 13:14:25 +08:00
Enrico Loparco
cfa90ca44f
Use logger for runtime error/debug prints (#3097)
Change runtime internal error/debug prints from using `os_printf()`
to using `LOG_ERROR()`/`LOG_DEBUG()`.
2024-02-06 13:02:54 +08:00
TianlongLiang
f359b51525
Fix threads opcodes' boundary check in classic-interp and fast-interp (#3136)
Using `CHECK_BULK_MEMORY_OVERFLOW(addr + offset, n, maddr)` to do the
boundary check may encounter integer overflow in `addr + offset`, change to
use `CHECK_MEMORY_OVERFLOW(n)` instead, which converts `addr` and `offset`
to uint64 first and then add them to avoid integer overflow.
2024-02-06 11:52:30 +08:00
Xu Jun
d6d5072cc6
Fix locel.set in polymorphic stack (#3135)
The issue was reported in #3123.
2024-02-05 17:41:33 +08:00
Wenyong Huang
b8ff98c810
Fix possible integer overflow in loader target block check (#3133)
Checking with `loader_ctx->csp_num < depth + 1` has potential integer overflow
issue when depth is UINT_MAX, change to `loader_ctx->csp_num - 1 < depth`
instead.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3130.
2024-02-05 16:00:58 +08:00
Huang Qi
1a676f212b
Zero the memory mapped from os_mmap in NuttX (#3132)
Zero the memory which is required by os_mmap.

This fixes the nuttx spec test CI failure:
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/7777804669
2024-02-05 15:45:22 +08:00
Wenyong Huang
06df58f20e
Fix loader check_wasi_abi_compatibility (#3126)
Assume that wasi exported `_start` and `_initialize` functions can not
be an import function.

Fixes issue #3122.
2024-02-04 17:27:43 +08:00
YAMAMOTO Takashi
529fa9dd17
EH: Fix broken stack usage calculation (#3121)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3108
2024-02-03 12:21:15 +08:00
Enrico Loparco
a32b082d2a
Add ARM MacOS to the CI (#3120)
Add ARM MacOS to the CI, to prevent regressions like the one fixed in #3102 in the future.
And add the AOT compilation to the wasi-threads example.
2024-02-03 11:51:02 +08:00
Marcin Kolny
a27ddece7f
Always allocate linear memory using mmap (#3052)
With this approach we can omit using memset() for the newly allocated memory
therefore the physical pages are not being used unless touched by the program.

This also simplifies the implementation.
2024-02-02 22:17:44 +08:00
Wenyong Huang
2eb60060d8
Fix read and validation of misc/simd/atomic sub opcodes (#3115)
The format of sub opcodes after misc, simd and atomic prefix is leb u32.

The issue was found in #2921.
2024-02-02 12:03:58 +08:00
Wenyong Huang
b3f728ceb3
Update version number to 1.3.2 and update release notes (#3083) 2024-02-01 12:42:12 +08:00
YAMAMOTO Takashi
edc3643909
EH: Fix validation of delegate opcode (#3107)
cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/1884#issuecomment-1914000294
2024-02-01 12:32:06 +08:00
Xu Jun
40e51faca8
fast-interp: Fix block with parameter in polymorphic stack issue (#3112)
The issue was reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3061.
2024-02-01 11:55:29 +08:00
YAMAMOTO Takashi
3111a86cb3
EH: Fix delegate parsing in wasm_loader_find_block_addr (#3106) 2024-02-01 07:46:49 +08:00
YAMAMOTO Takashi
10e87d2966
EH: Don't call word_copy with zero size (#3105) 2024-01-31 21:54:19 +08:00
YAMAMOTO Takashi
43c4a5c434
exception handling: Fix build error (#3104) 2024-01-31 20:24:34 +08:00
Enrico Loparco
dfd2a5b0b4
Fix AOT compilation on MacOS (#3102)
After #2995, AOT may stop working properly on arm MacOS:
```bash
wasm-micro-runtime/core/iwasm/common/wasm_runtime_common.c,
line 1270, WASM module load failed
AOT module load failed: mmap memory failed
```
That's because, without `#include <TargetConditionals.h>`, `TARGET_OS_OSX` is undefined,
since it's definition is in that header file.
2024-01-31 20:06:22 +08:00
Xu Jun
51e25ef01f
fast-interp: Fix frame_offset pop order (#3101)
The issue was reported in #3062.
2024-01-31 19:26:27 +08:00
Xu Jun
5a99866c01
fast-interp: Fix stack recovery for else branch (#3100)
The issue was reported in #3090.
2024-01-31 11:23:23 +08:00
Wenyong Huang
af318bac81
Implement Exception Handling for classic interpreter (#3096)
This PR adds the initial support for WASM exception handling:
* Inside the classic interpreter only:
  * Initial handling of Tags
  * Initial handling of Exceptions based on W3C Exception Proposal
  * Import and Export of Exceptions and Tags
* Add `cmake -DWAMR_BUILD_EXCE_HANDLING=1/0` option to enable/disable
  the feature, and by default it is disabled
* Update the wamr-test-suites scripts to test the feature
* Additional CI/CD changes to validate the exception spec proposal cases

Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/1884
587513f3c6
8bebfe9ad7
59bccdfed8

Signed-off-by: Ricardo Aguilar <ricardoaguilar@siemens.com>
Co-authored-by: Chris Woods <chris.woods@siemens.com>
Co-authored-by: Rene Ermler <rene.ermler@siemens.com>
Co-authored-by: Trenner Thomas <trenner.thomas@siemens.com>
2024-01-31 08:27:17 +08:00
YAMAMOTO Takashi
7e65f9a244
aot: Fix LLVMSetTailCallKind check (#3099) 2024-01-30 20:50:33 +08:00
Enrico Loparco
170ae35131
test_wamr.sh: Allow using test script on different platforms (#3098)
The `^^` for uppercase is not widely supported, e.g. not working on some MacOS M1.
2024-01-30 11:02:40 +08:00
Wenyong Huang
7f8e2133ec
Fix windows build error and compilation warnings (#3095)
Fix wamrc build error reported on Windows:
```bash
CMake Error at CMakeLists.txt:84 (message):
  Unsupported CMAKE_HOST_SYSTEM_PROCESSOR AMD64
```
And clear several compilation warnings.
2024-01-29 18:57:57 +08:00
Huang Qi
b98f150f82
CI: Update version of checkout to suppress warnings (#3093) 2024-01-27 07:55:49 +08:00
tkernelcn
83c3ef0f46
freertos: Thread exit more common (#3094)
In native side,  even not call `os_thread_exit` at end of thread code,
can also exit correctly.
2024-01-26 18:38:55 +08:00
liang.he
99bbad8cdb
perf profiling: Adjust the calculation of execution time (#3089) 2024-01-26 18:06:21 +08:00
Huang Qi
9fb5fcc709
Add comments to suppress warning from clang-tidy (#3088)
Suppress style warnings for macro definition, name of these macros is
inconsistent with others (upper case).
2024-01-26 17:02:24 +08:00
Huang Qi
ad46290770
Update outdated reference link in multi_module.md (#3092) 2024-01-26 16:55:27 +08:00
Wenyong Huang
313ce8cb61
Fix memory/table segment checks in memory.init/table.init (#3081)
According to the wasm core spec, the checks for the table segments in
`table.init` opcode are similar to the checks for `memory.init` opcode:
- The size of a passive segment is shrunk to zero after `data.drop`
  (or `elem.drop`) opcode is executed, and the segment can be used to do
  `memory.init` (or `table.init`) again
- The `memory.init` only traps when `s+n > len(data.data)` or `d+n > len(mem.data)`
  and `table.init` only traps when `s+n > len(elem.elem)` or `d+n > len(tab.elem)`
- The active segment can also be used to do `memory.init` (or `table.init`),
  while it behaves like a dropped passive segment

https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
```
Segments can also be shrunk to size zero by using the following new instructions:
- data.drop: discard the data in an data segment
- elem.drop: discard the data in an element segment

An active segment is equivalent to a passive segment, but with an implicit
memory.init followed by a data.drop (or table.init followed by a elem.drop)
that is prepended to the module's start function.
```
ps.
https://webassembly.github.io/spec/core/bikeshed/#-hrefsyntax-instr-memorymathsfmemoryinitx%E2%91%A0
https://webassembly.github.io/spec/core/bikeshed/#-hrefsyntax-instr-tablemathsftableinitxy%E2%91%A0
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3020
2024-01-26 09:45:59 +08:00
Huang Qi
6daaf6d27a
Fix inconsistent code style in aot_loader.c (#3082) 2024-01-25 17:19:14 +08:00
YAMAMOTO Takashi
9afbeab1c8
wasi: Apply wasm_runtime_begin_blocking_op to poll as well (#3080)
While we used a different approach for poll_oneoff [1],
the implementation works only when the poll list includes
an absolute clock event. That is, if we have a thread which is
polling on descriptors without a timeout, we fail to terminate
the thread.

This commit fixes it by applying wasm_runtime_begin_blocking_op
to poll as well.

[1] https://github.com/bytecodealliance/wasm-micro-runtime/pull/1951
2024-01-25 16:29:34 +08:00