Commit Graph

1493 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
562a5dd1b6
Fix data/elem drop (#2747)
Currently, `data.drop` instruction is implemented by directly modifying the
underlying module. It breaks use cases where you have multiple instances
sharing a single loaded module. `elem.drop` has the same problem too.

This PR  fixes the issue by keeping track of which data/elem segments have
been dropped by using bitmaps for each module instances separately, and
add a sample to demonstrate the issue and make the CI run it.

Also add a missing check of dropped elements to the fast-jit `table.init`.

Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2735
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2772
2023-11-18 08:50:16 +08:00
TianlongLiang
08c0ec74c4
More precise help info of enabled targets for wamrc (#2783)
Instead of printing all support targets of wamrc, print only the targets
that are included in the LLVM library with which wamrc was compiled.
2023-11-17 19:05:00 +08:00
zoraaver
b39fd516d3
Use next generation crypto API on Windows (#2769)
CryptGenRandom is deprecated by Microsoft and may be removed in future
releases. They recommend to use the next generation API instead. See
https://learn.microsoft.com/en-us/windows/win32/seccng/cng-portal for
more details. Also, refactor the random functions to return error codes
rather than aborting the program if they fail.
2023-11-17 18:40:29 +08:00
YAMAMOTO Takashi
2d0d4a0be9
Remove unused JitBitmap (#2775)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2754
2023-11-16 18:48:06 +08:00
Wenyong Huang
a3349cc8c1
Fix compilation errors on zephyr platform (#2777)
Add dummy korp_rwlock struct and fix os_dir_stream definition on
platform zephyr/riot/rt-thread/alios to fix the compilation errors.
2023-11-16 18:39:41 +08:00
TianlongLiang
503d94ace2
Enable more LLVM backends for the release wamrc binary (#2778)
As mentioned in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2504,
the current release `wamrc` only has X86 target enabled. This PR enables
more targets for release `wamrc`, including AArch64, ARM, Mips and RISCV.
2023-11-16 18:32:28 +08:00
Huang Qi
b92906464e
Fix printing ref.extern addresses in wasm_application.c (#2774) 2023-11-16 15:10:58 +08:00
Wenyong Huang
dd0556a729
aot compiler: Disable musttail for thumb (#2771)
Error is reported when executing `wamrc --target=thumb -o <aot_file> <wasm_file>`:
```
LLVM ERROR: failed to perform tail call elimination on a call site marked musttail
Aborted (core dumped)
```
2023-11-16 11:05:23 +08:00
Wenyong Huang
9a32e0672c
Fix aot compiler issue reported by Coverity (#2770)
Set `abi` to "gnu" for the bare-metal target when `abi` is NULL,
or the below `bh_assert` and `bh_memcpy` may deference a NULL
pointer. Error is reported when running wamrc compiled with
`cmake .. -DCMAKE_BUILD_TYPE=Debug`:
```
core/iwasm/compilation/aot_llvm.c:2584:13: runtime error:
  null pointer passed as argument 1, which is declared to never be null
```
2023-11-16 10:54:39 +08:00
Huang Qi
24aa1cb408
Extend os_mmap to support map file from fd (#2763)
Add an extra argument `os_file_handle file` for `os_mmap` to support
mapping file from a file fd, and remove `os_get_invalid_handle` from
`posix_file.c` and `win_file.c`, instead, add it in the `platform_internal.h`
files to remove the dependency on libc-wasi.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-11-16 08:28:54 +08:00
Wenyong Huang
0b8a904193
Fix fast-jit callnative translation (#2765)
Lock i32 registers before and after preparing the function arguments
to prevent they are overwritten.
2023-11-15 18:30:51 +08:00
Wenyong Huang
40d33d806b
Add compilation flag to enable/disable heap corruption check (#2766)
Heap corruption check in ems memory allocator is enabled by default
to improve the security, but it may impact the performance a lot, this
PR adds cmake variable and compiler flag to enable/disable it.
2023-11-15 17:20:50 +08:00
Daniel Mangum
fc03bc073e
Fix log messages in Zephyr example (#2761)
Fixes typo of function in log messages in Zephyr example.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-14 09:27:57 +08:00
Huang Qi
56bfae774c
Update RISC-V compilers in Nuttx compilation CI and spec test CI (#2756)
Update RISC-V compilers in Nuttx compilation CI and spec test CI
to test workflows.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-11-14 09:21:58 +08:00
zoraaver
8c27676718
Return uint32 from WASI functions (#2749)
Returning uint16 from WASI functions is technically correct. However,
the smallest integer type in WASM is int32 and since we don't guarantee
that the upper 16 bits of the result are zero'ed, it can result in
tricky bugs if the language SDK being used in the WASM app does not cast
back immediately to uint16. To prevent this, we directly return uint32
instead, so that the result is well-defined as a 32-bit number.
2023-11-13 20:07:32 +08:00
Huang Qi
e4353b4e1f
Add eabihf ABI support and set vendor-sys of bare-metal targets (#2745)
Set the vendor-sys of bare-metal targets to "-unknown-none-",
and currently only add "thumbxxx" to the bare-metal target list.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-11-13 18:01:15 +08:00
Haiyue Wang
625c95816d
Fix switch-case fallthrough compilation warning (#2753)
The commit fa5e9d72b0 ("Abstract POSIX filesystem functions") introduces
the build warning:

./core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c: In function ‘fd_object_release’:
./core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:545:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
  545 |                 if (os_is_dir_stream_valid(&fo->directory.handle)) {
      |                    ^
./core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:549:13: note: here
  549 |             default:
      |             ^~~~~~~

Refer to the commit fb4afc7ca4 ("Apply clang-format for core/iwasm compilation and libraries"),
add one line "// Fallthrough." to make compiler happy.

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
2023-11-13 15:01:13 +08:00
Daniel Mangum
cf0da9a8c7
docs: Fix typo in export native APIs doc (#2750)
Fixes a small typo of conversion for native API documentation.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-12 08:42:36 +08:00
Wenyong Huang
71340b79a6
Merge pull request #2740 from bytecodealliance/dev/wasi-libc-windows
The implementation is already in a stage where it's possible to compile WAMR
with wasi libc enabled and run wasi modules without errors.
2023-11-10 16:58:31 +08:00
Daniel Mangum
314ecba388
Fix CMSIS import with Zephyr 3.4+ (#2744)
Fixes the import path for CMSIS in Zephyr versions > 3.4.

See https://github.com/zephyrproject-rtos/zephyr/pull/59855 for more
information.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-10 11:43:48 +08:00
Enrico Loparco
68b317c686
Remove TSAN suppression for execute_post_instantiate_functions (#2741)
The problem has been fixed: #2680.
2023-11-10 08:25:01 +08:00
YAMAMOTO Takashi
24c4d256b3
Grab cluster->lock when modifying exec_env->module_inst (#2685)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2680

And when switching back to the original module_inst, propagate exception if any.

cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2512
2023-11-09 18:56:02 +08:00
Wenyong Huang
20f1a8c86c Merge branch main into dev/wasi-libc-windows 2023-11-09 10:13:59 +08:00
Daniel Mangum
797e534cec
Fix typo in Zephyr simple example (#2738)
Fixes small typo of elapsed in Zephyr simple example.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-09 09:09:31 +08:00
Wenyong Huang
7f8292ffd1
Add more buffer boundary checks in wasm loader (#2734)
And fix exception not printed in `iwasm --repl` mode and resize the memory
data size to UINT32_MAX if the initial page number is 65536.
2023-11-09 08:42:05 +08:00
zoraaver
fa2839a805
Fix default vprintf on UWP (#2730)
`platform_common.h` already has a declaration for BH_VPRINTF so we can
get rid of the one in `platform_internal.h`. Also add some explicit
casts to avoid MSVC compiler warnings.
2023-11-08 20:28:34 +08:00
zoraaver
3c9cd40aa6
Provide default vprintf on UWP (#2725)
UWP apps do not have a console attached so any output to stdout/stderr
is lost. Therefore, provide a default BH_VPRINTF in that case for debug
builds which redirects output to the debugger.
2023-11-07 20:37:43 +08:00
zoraaver
77b6bce679
Move WASI types into separate header (#2724)
To allow anything to depend on WASI types, including platform-specific
data structures, move the WASI libc filesystem/clock interface into
`platform_api_extension.h`, which leaves just WASI types in
`platform_wasi.h`. And `platform_wasi.h` has been renamed to
`platform_wasi_types.h` to reflect that it only defines types now and no
function declarations. Finally, these changes allow us to remove the
`windows_fdflags` type which was essentially a duplicate of
`__wasi_fdflags_t`.
2023-11-07 09:39:15 +08:00
zoraaver
13875f43c6
Enable WASI tests on Windows CI (#2699)
Most of the WASI filesystem tests require at least creating/deleting a
file to test filesystem functionality so some additional filesystem APIs
have been implemented on Windows so we can test what has been
implemented so far. For those WASI functions which haven't been
implemented, we skip the tests. These will be implemented in a future PR
after which we can remove the relevant filters.

Additionally, in order to run the WASI socket and thread tests, we need
to install the wasi-sdk in CI and build the test source code prior to
running the tests.
2023-11-06 19:24:06 +08:00
Wenyong Huang
cc23c7ee7d
Use user defined malloc/free functions for user defined memory allocator (#2717)
Reported in #2617.
2023-11-03 15:23:31 +08:00
Wenyong Huang
e161205a27
Fix invalid use of jit_reg_is_const_val in fast-jit (#2718)
`jit_reg_is_const_val` only checks whether the register is a const register and
the const value is stored in the register.
Should use `jit_reg_is_const` instead in the front end.

Reported in #2710.
2023-11-03 14:25:26 +08:00
Wenyong Huang
caf805ece7
Fix AOT compiler simd shift opcodes (#2715) 2023-11-03 10:38:53 +08:00
Wenyong Huang
68a627ea2c
Fix several AOT compiler issues (#2697)
- Fix potential invalid push param phis and add incoming phis to a un-existed basic block
- Fix potential invalid shift count int rotl/rotr opcodes
- Resize memory_data_size to UINT32_MAX if it is 4G when hw bound check is enabled
- Fix negative linear memory offset is used for 64-bit target it is const and larger than INT32_MAX
2023-11-02 20:36:21 +08:00
Maks Litskevich
0b2313f6f8
Add tsan for fast interp and aot (#2679)
To run it locally:
```bash
export TSAN_OPTIONS=suppressions=<path_to_tsan_suppressions.txt>
./test_wamr.sh <your flags> -T tsan
```

An example for wasi-threads would look like:
```bash
export TSAN_OPTIONS=suppressions=<path_to_tsan_suppressions.txt>
./test_wamr.sh -w -s wasi_certification -t fast-interp -T tsan
```
2023-11-01 18:30:25 +08:00
Wenyong Huang
52db362b89
Refine lock/unlock shared memory (#2682)
Split memory instance's field `uint32 ref_count` into `bool is_shared_memory`
and `uint16 ref_count`, and lock the memory only when `is_shared_memory`
flag is true, no need to acquire a lock for non-shared memory when shared
memory feature is enabled.
2023-10-31 11:46:03 +08:00
Wenyong Huang
3570a94a08
Fix issues reported by Coverity (#2681)
Fix multi-module issues and gui sample issues reported by Coverity.
And refine the build script of go language-binding sample.
2023-10-31 10:48:51 +08:00
Benedikt Becker
613c7ca48f
Minor fixes for Go bindings (#2676) 2023-10-30 13:50:48 +08:00
Wenyong Huang
4b1a6e5017
Fix repeatedly initialize shared memory data and protect the memory's fields (#2673)
Avoid repeatedly initializing the shared memory data when creating the child
thread in lib-pthread or lib-wasi-threads.

Add shared memory lock when accessing some fields of the memory instance
if the memory instance is shared.

Init shared memory's memory_data_size/memory_data_end fields according to
the current page count but not max page count.

Add wasm_runtime_set_mem_bound_check_bytes, and refine the error message
when shared memory flag is found but the feature isn't enabled.
2023-10-30 11:07:01 +08:00
Gavin Hayes
51a6b069d2
Fix use getrandom on cosmopolitan libc (#2674)
Fixes the Cosmopolitan Libc platform attempting to use `/dev/urandom`
on operating systems that do not have it.

Signed-off-by: G4Vi <gavin@dylibso.com>
2023-10-27 14:07:16 +08:00
Alfred E. Neumayer
9b8fe049b3
core/iwasm: Support mapped file system access on non-libuv WASI (#2628)
This patch enables mapping host directories to guest directories by parsing
the `map_dir_list` argument in API `wasm_runtime_init_wasi` for libc-wasi. It
follows the format `<guest-path>::<host-path>`.

It also adds argument `--map-dir=<guest::host>` argument for `iwasm`
common line tool, and allows to add multiple mappings:
```bash
iwasm --map-dir=<guest-path1::host-path1> --map-dir=<guest-path2::host-path2> ...
```
2023-10-27 12:48:10 +08:00
Wenyong Huang
8038b9c524
Fix fast-jit f32/f64 truncate to i32/i64 (#2671)
The f32/f64 value to be truncated may be a const, add checks for
whether it is nan and whether it is out of the legal range.

Fixes issue #2661.
2023-10-27 12:20:25 +08:00
zoraaver
3624895204
Fix windows compilation on C++20 (#2670)
Since C++20, std::memory_order is defined as an enum class so requires
explicit casting to an int when adding enum values.
See https://en.cppreference.com/w/cpp/atomic/memory_order.
2023-10-25 20:47:56 +08:00
YAMAMOTO Takashi
9a5c777aff
Revert "Strip static and shared libraries of iwasm to reduce the binary size (#2431)" (#2669)
This reverts commit 7e3a29d5e4564406c91ada436b1e33d53d1232cf:
* it doesn't work for macOS. ("unrecognized option: --strip-all")
* it doesn't work for ubuntu.
  https://github.com/bytecodealliance/wasm-micro-runtime/issues/2665
2023-10-25 20:46:49 +08:00
zoraaver
e7a62d2099
Refactor clock functions to use WASI types (#2666)
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
https://github.com/bytecodealliance/wasm-micro-runtime/pull/2637#discussion_r1362202879
for details.
2023-10-25 18:06:04 +08:00
Wenyong Huang
4f5ad4dc12
Apply no_sanitize_address for clang compiler in several places (#2663)
Apply `no_sanitize_address` for clang compiler in several places in which
it has been applied to gcc compiler.

And refine the comment.
2023-10-25 08:05:26 +08:00
zoraaver
75208073c0
Partial windows filesystem implementation (#2657)
Implement the necessary os_ filesystem functions to enable successful
WASI initialization on Windows. Some small changes were also required to
the sockets implementation to use the new windows_handle type. The
remaining functions will be implemented in a future PR.
2023-10-25 08:01:11 +08:00
Wenyong Huang
d6bba13e86
Fix fast-interp "pre-compiled label offset out of range" issue (#2659)
When labels-as-values is enabled in a target which doesn't support
unaligned address access, 16-bit offset is used to store the relative
offset between two opcode labels. But it is a little small and the loader
may report "pre-compiled label offset out of range" error.

Emitting 32-bit data instead to resolve the issue: emit label address in
32-bit target and emit 32-bit relative offset in 64-bit target.

See also:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2635
2023-10-24 10:47:17 +08:00
Wenyong Huang
9d7931e1d2
Fix several typo/warning/unused-code issues (#2655)
- Fix typo in wamr-test-suites script
- Fix compilation warnings in libc-wasi posix.c
- Remove unused code fast-jit jit_frontend.c
- Remove duplicated exception print in `iwasm -f <function>`
- Fix return value in void function wasm_runtime_set_wasi_ctx
2023-10-24 09:19:45 +08:00
fadumina1
a874bf0ff8
Implement wasi clock_time/clock_res get (#2637)
Add os_clock_res_get and os_clock_time_get in platform_api_extension.h,
and implement them in posix like platforms and windows platform.
2023-10-22 21:11:29 +08:00
zoraaver
fa5e9d72b0
Abstract POSIX filesystem functions (#2585)
To allow non-POSIX platforms such as Windows to support WASI libc
filesystem functionality, create a set of wrapper functions which provide a
platform-agnostic interface to interact with the host filesystem. For now,
the Windows implementation is stubbed but this will be implemented
properly in a future PR. There are no functional changes in this change,
just a reorganization of code to move any direct POSIX references out of
posix.c in the libc implementation into posix_file.c under the shared
POSIX sources.

See https://github.com/bytecodealliance/wasm-micro-runtime/issues/2495 for a
more detailed overview of the plan to port the WASI libc filesystem to Windows.
2023-10-19 19:19:39 +08:00