Commit Graph

1400 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
09a5be411f
Reduce WASM_STACK_GUARD_SIZE a bit for posix-like platforms (#3350)
I found a few mistakes in my research on the stack consumption.
Update the comment and tweak WASM_STACK_GUARD_SIZE accordingly.
2024-04-24 16:18:58 +08:00
dongheng
6aa7cb85f6
Add WASI support for esp-idf platform (#3348)
Add WASI support for esp-idf platform:

1. add Kconfig and cmake scripts
2. add API "openat" when using littlefs
3. add clock/rwlock/file/socket OS adapter
2024-04-24 14:46:38 +08:00
YAMAMOTO Takashi
98ad36e35a
core/config.h: Bump the default WASM_STACK_GUARD_SIZE (#3344)
The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases.
But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls
host snprintf. (2000 bytes)

Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3314
2024-04-23 16:51:47 +08:00
YAMAMOTO Takashi
7bdea3c2ae
Add some more comments on WASM_STACK_GUARD_SIZE (#3341) 2024-04-22 15:00:09 +08:00
Wenyong Huang
18d363029c
wasm loader: Fix checks for opcode ref.func and opcode else (#3340)
Fix wasm loader integrity checks for opcode ref.func and opcode else:
for opcode ref.func, the function must be an import, exported, or present in a
table elem segment or global initializer to be used as the operand to ref.func,
for opcode else, there must not be an else opcode previously.

Reported in #3336 and #3337.

And fix mini loader PUSH_MEM_OFFSET/POP_MEM_OFFSET macro
definitions due to the introducing of memory64 feature.
2024-04-22 14:44:45 +08:00
komasayuki
67dc2ae0b2
Fix readdir for posix (#3339)
This PR fixes a readir for posix. readdir is not working correctly in rust.

The current WAMR's readdir implementation for posix is, if readdir returns 0,
it will exit with an error. But posix readdir returns 0 at the end of the directory.
To handle this correctly, if readdir returns 0, it should only raise an error if
errno has changed. We can reproduce it with the following rust code:

```rust
use std::fs;

fn main() {
    let entries  = fs::read_dir(".").unwrap();
    for entry in entries {
        println!("read_dir:{:?}", entry);
    }
}
```
2024-04-22 13:54:19 +08:00
Wenyong Huang
e7a8b3e743
Update version number to 2.0.0 and update release notes (#3327)
And enable code format check for wasm_export.h and add '\n' in os_printf
in sgx platform source files.
2024-04-20 10:16:34 +08:00
Benbuck Nason
8253c417a8
Add functions to expose module import/export info (#3330)
Resolves #3329.
2024-04-20 08:57:39 +08:00
Marcin Kolny
fd7f738451
Allow executing malloc/free from native in memory64 mode (#3315) 2024-04-19 17:15:54 +08:00
Wenyong Huang
902aa525d1
Fix windows relocation string parsing issue (#3333)
The AOT compiler emits string with '\0' now, some string parsing in aot loader
for Windows platform need to be updated.
2024-04-19 16:09:03 +08:00
YAMAMOTO Takashi
f6481cedec
Add a comment on WASM_STACK_GUARD_SIZE (#3332) 2024-04-19 10:19:59 +08:00
dongsheng28849455
ba59e56e19
User defined memory allocator for different purposes (#3316)
Some issues are related with memory fragmentation, which may cause
the linear memory cannot be allocated. In WAMR, the memory managed
by the system is often trivial, but linear memory usually directly allocates
a large block and often remains unchanged for a long time. Their sensitivity
and contribution to fragmentation are different, which is suitable for
different allocation strategies. If we can control the linear memory's allocation,
do not make it from system heap, the overhead of heap management might
be avoided.

Add `mem_alloc_usage_t usage` as the first argument for user defined
malloc/realloc/free functions when `WAMR_BUILD_ALLOC_WITH_USAGE` cmake
variable is set as 1, and make passing `Alloc_For_LinearMemory` to the
argument when allocating the linear memory.
2024-04-18 19:40:57 +08:00
Wenyong Huang
68bd30c6f9
Enhance GC subtyping checks (#3317)
Enhance the GC subtyping checks:
- Fix issues in the type equivalence check
- Enable the recursive type subtyping check
- Add a equivalence type flag in defined types of aot file, if there is an
  equivalence type before, just set it true and re-use the previous type
- Normalize the defined types for interpreter and AOT
- Enable spec test case type-equivalence.wast and type-subtyping.wast,
  and enable some commented cases
- Enable set WAMR_BUILD_SANITIZER from cmake variable
2024-04-18 12:32:01 +08:00
Yage Hu
d39d2ba3ca
Fix posix_fadvise error handling (#3323)
`posix_fadvise()` returns 0 on success and the errno on error.  This
commit fixes the handling of the return value such that it does not
always succeeds.

Fixes #3322.
2024-04-17 16:06:25 +08:00
liang.he
42199f163e
Log warning if growing table failed (#3310) 2024-04-15 18:29:54 +08:00
Wenyong Huang
1c690b7561
Add more checks in wasm loader (#3300)
In opcode f32.const, f64.const and memory.copy, check whether the buffer
to read is out of the range of wasm file before reading it.
2024-04-11 19:56:48 +08:00
dongheng
9b28a8a80e
Update esp-idf platform support in main (#3304)
1. Fix API "futimens" and "utimensat" compiling error in different esp-idf version
2. Update component registry description file

ps. refer to PR #3296 on branch release/1.3x
2024-04-11 19:46:34 +08:00
TianlongLiang
4e634bed3f
Add necessary comments for doxygen (#3299)
- Add necessary comments for doxygen to generate API documentation
- Update README.md to add a link for End-user APIs documentation
2024-04-11 07:50:08 +08:00
mkolchurin
8756d29e19
zephyr: Add missing pthread library functions (#3291)
For use with WAMR_BUILD_LIB_PTHREAD, add os_thread_detach,
os_thread_exit, os_cond_broadcast.

Signed-off-by: Maxim Kolchurin <maxim.kolchurin@gmail.com>
2024-04-10 08:19:46 +08:00
liang.he
bcc2a2d2e1
Sync simd opcode definitions spec (#3290)
Remove undefined simd opcodes.
2024-04-09 16:54:42 +08:00
dongheng
dacb3c4105
Add wamr to esp-idf components registry (#3287)
This PR is for the main branch, but only the released branch will be pushed
into Espressif component registry.

See also similar fixes in branch release/1.3.x:
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3264
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3288
2024-04-08 12:34:08 +08:00
Wenyong Huang
ef3babc658
interp: Restore context from prev_frame after tail calling a native function (#3283)
The current frame was freed before tail calling to an import or native function
and the prev_frame was set as exec_env's cur_frame, so after the tail calling,
we should recover context from prev_frame but not current frame.

Found in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3279.
2024-04-08 09:23:20 +08:00
Wenyong Huang
b11dbcba0a
thread mgr: Free aux stack only when it was allocated (#3282)
When thread manager is enabled, the aux stack of exec_env may be allocated
by wasm_cluster_allocate_aux_stack or disabled by setting aux_stack_bottom
as UINTPTR_MAX directly. For the latter, no need to free it.

And fix an issue when paring `--gc-heap-size=n` argument for iwasm, and
fix a variable shadowed warning in fast-jit.
2024-04-08 09:06:49 +08:00
liang.he
4ef724bbff
Enhance wasm loading with LoadArgs and support module names (#3265)
- Add new API wasm_runtime_load_ex() in wasm_export.h
  and wasm_module_new_ex in wasm_c_api.h
- Put aot_create_perf_map() into a separated file aot_perf_map.c
- In perf.map, function names include user specified module name
- Enhance the script to help flamegraph generations
2024-04-07 15:04:35 +08:00
Wenyong Huang
2013f1f7d7
Fix warnings/issues reported in Windows and by CodeQL/Coverity (#3275)
Fix the warnings and issues reported:
- in Windows platform
- by CodeQL static code analyzing
- by Coverity static code analyzing

And update CodeQL script to build exception handling and memory features.
2024-04-07 11:57:31 +08:00
YAMAMOTO Takashi
53f0941ffa
Revert "lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)" (#3281)
This reverts commit 0e8d949440.

Because it doesn't make much sense anymore after we disabled debug info
processing on C++ functions in:
"aot debug: process lldb_function_to_function_dbi only for C".
2024-04-06 15:00:48 +08:00
YAMAMOTO Takashi
b4cab84e5f
aot debug: Process lldb_function_to_function_dbi only for C (#3278)
This is a workaroud for:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3187
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3163
2024-04-03 18:03:31 +08:00
YAMAMOTO Takashi
dae09c0e03
aot debug: Fix a NULL dereference (#3274)
It happens on eg. a C function taking a structure argument.
2024-04-03 17:10:46 +08:00
YAMAMOTO Takashi
4806e4e298
LLVM 19: Switch to debug records (#3272)
References:
    https://llvm.org/docs/RemoveDIsDebugInfo.html
    https://github.com/llvm/llvm-project/pull/86529
2024-04-02 16:00:43 +08:00
Wenyong Huang
a23fa9f86c
Implement memory64 for classic interpreter (#3266)
Adding a new cmake flag (cache variable) `WAMR_BUILD_MEMORY64` to enable
the memory64 feature, it can only be enabled on the 64-bit platform/target and
can only use software boundary check. And when it is enabled, it can support both
i32 and i64 linear memory types. The main modifications are:

- wasm loader & mini-loader: loading and bytecode validating process 
- wasm runtime: memory instantiating process
- classic-interpreter: wasm code executing process
- Support memory64 memory in related runtime APIs
- Modify main function type check when it's memory64 wasm file
- Modify `wasm_runtime_invoke_native` and `wasm_runtime_invoke_native_raw` to
  handle registered native function pointer argument when memory64 is enabled
- memory64 classic-interpreter spec test in `test_wamr.sh` and in CI

Currently, it supports memory64 memory wasm file that uses core spec
(including bulk memory proposal) opcodes and threads opcodes.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3091
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3240
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3260
2024-04-02 15:22:07 +08:00
YAMAMOTO Takashi
6b0b5de1c5
aot debug: Fix a few NULL dereferences on errors (#3273) 2024-04-02 14:30:08 +08:00
dongsheng28849455
250829c0cc
Set is_vram_word_align as false in aot_const_str_set_insert function (#3271)
Set `is_vram_word_align` as false in aot_const_str_set_insert function when
`const char *name` is not from vram required word_align reading.
2024-04-02 14:17:30 +08:00
Xin Xu
bad9a2a231
nuttx: Migrate NuttX CMake build for WAMR (#3256)
Add NuttX CMake build support for platforms.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-04-02 08:53:30 +08:00
Wenyong Huang
6ee71000f9
Fix dynamic offset not updated in op_br for block with ret type (#3269)
The PR #3259 reverted PR #3192, it fixes #3210 but makes #3170 failed again.

The workaround is that we should update `ctx->dynamic_offset` only for opcode br
and should not update it for opcode br_if. This PR fixes both issue #3170 and #3210.
2024-04-01 15:40:20 +08:00
Wenyong Huang
ec15b6bbad
Add lock and ref_count for runtime init (#3263)
Some environment may call wasm_runtime_full_init/wasm_runtime_init multiple
times without knowing that runtime is initialized or not, it is better to add lock
and increase reference count during initialization.

ps. https://github.com/bytecodealliance/wasm-micro-runtime/discussions/3253.
2024-04-01 12:39:46 +08:00
Wenyong Huang
9c8551cf75
Add cmake flag to control aot intrinsics (#3261)
Add cmake variable `-DWAMR_BUILD_AOT_INTRINSICS=1/0` to enable/disable
the aot intrinsic functions, which are normally used by AOT XIP feature, and
can be disabled to reduce the aot runtime binary size.

And refactor the code in aot_intrinsics.h/.c.
2024-04-01 11:26:05 +08:00
Wenyong Huang
f933d4c829
loader: Remove updating ctx->dynamic_offset in emit_br_info (#3259)
Should not update `ctx->dynamic_offset` in emit_br_info, since the `Part e` only
sets the dst offsets, the operand stack should not be changed, e.g., the stack
operands are to be used by the opcodes followed by `br_if` opcode.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3210.
2024-03-28 16:07:02 +08:00
Wenyong Huang
89f4982123
Fix compilation errors on zephyr platform (#3255)
Refer to https://github.com/bytecodealliance/wasm-micro-runtime/issues/3252.
2024-03-26 17:55:53 +08:00
liang.he
498eb5d54a
Append \0 to every name string in aot name section (#3249)
Since strings in .name section in .wasm is not c-style, need to append
a `\0` to each string in .name section in AOT file when emitting.
2024-03-26 14:27:20 +08:00
liang.he
d8d8f8ce04
Implement apis to set and get the name of a wasm module (#3254)
Add API wasm_runtime_set_module_name and wasm_runtime_get_module_name,
and by default, a module's name is "" if the set module name api isn't called.
2024-03-26 12:10:13 +08:00
TianlongLiang
64b6c688a2
posix_file.c: Correct the dirfd argument that passes to fstatat (#3244)
This PR fixes the random failing test case `nofollow_errors` mentioned in
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3222

```C
// dirfd: This is the file descriptor of the directory relative to which the pathname is interpreted. 
int openat(int dirfd, const char *pathname, int flags, ...);
```
The value should be a directory handle instead of a file handle (which is always -1 in this context)
returned from `openat`.
2024-03-22 10:55:39 +08:00
Xu Jinyang
cef88deedb
Add wasi_ephemeral_nn module support (#3241)
Add `wasi_ephemeral_nn` module support with optional cmake variable,
which was mentioned in #3229.
2024-03-21 21:05:34 +08:00
Liangyu Zhang
b11a1d157d
GC: Add wasm_struct_obj_get_field_count API (#3236) 2024-03-18 16:26:30 +08:00
Wenyong Huang
ff296c1a62
Fix aot relocation symbols not found on windows 32-bit (#3231)
The symbols in windows 32-bit may start with '_' and can not be found
when resolving the relocations to them. This PR ignores the underscore
when handling the relocation name of AOT_FUNC_INTERNAL_PREFIX, and
redirect the relocation with name "_aot_stack_sizes" to the relocation with
name ".aot_stack_sizes" (the name of the data section created).

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3216
2024-03-18 09:51:38 +08:00
Wenyong Huang
5e2011ca1d
Fix compilation errors on esp-idf platform (#3224)
The issue was reported in #3208.
2024-03-14 21:31:44 +08:00
TianlongLiang
de803b2beb
Small refactor on WASMModuleInstance and fix Go/Python language bindings (#3227)
- Merge unused field `used_to_be_wasi_ctx` in `AOTModuleInstance` into `reserved` area
- Add field `memory_lock` in `WASMMemoryInstance` for future refactor
- Go binding: fix type error
    https://github.com/bytecodealliance/wasm-micro-runtime/issues/3220
- Python binding:
    type annotation uses the union operator "|", which requires Python version >=3.10
2024-03-14 15:30:28 +08:00
TianlongLiang
c3e33a96ea
Remove unused argument in wasm_runtime_lookup_function and refactor WASMModuleInstance (#3218)
Remove the unused parameter `signature` from `wasm_runtime_lookup_function`.

Refactor the layout of WASMModuleInstance structure:
- move common data members `c_api_func_imports` and `cur_exec_env` from
  `WASMModuleInstanceExtraCommon` to `WASMModuleInstance`
- In `WASMModuleInstance`, enlarge `reserved[3]` to `reserved[5]` in case that
  we need to add more fields in the future

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2530
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3202
2024-03-13 12:28:45 +08:00
Marcin Kolny
ce44e0ec0c
Allow converting the zero wasm address to native (#3215)
This allows to know the beginning of the wasm address space. At the moment
to achieve that, we need to apply a `hack wasm_runtime_addr_app_to_native(X)-X`
to get the beginning of WASM memory in the nativ code, but I don't see a good
reason why not to allow zero address as a parameter value for this function.
2024-03-12 17:46:11 +08:00
Wenyong Huang
0ee5ffce85
Refactor APIs and data structures as preliminary work for Memory64 (#3209)
# Change the data type representing linear memory address from u32 to u64

## APIs signature changes
- (Export)wasm_runtime_module_malloc
  - wasm_module_malloc
    - wasm_module_malloc_internal
  - aot_module_malloc
    - aot_module_malloc_internal
- wasm_runtime_module_realloc
  - wasm_module_realloc
    - wasm_module_realloc_internal
  - aot_module_realloc
    - aot_module_realloc_internal
- (Export)wasm_runtime_module_free
  - wasm_module_free
    - wasm_module_free_internal
  - aot_module_malloc
    - aot_module_free_internal
- (Export)wasm_runtime_module_dup_data
  - wasm_module_dup_data
  - aot_module_dup_data
- (Export)wasm_runtime_validate_app_addr
- (Export)wasm_runtime_validate_app_str_addr
- (Export)wasm_runtime_validate_native_addr
- (Export)wasm_runtime_addr_app_to_native
- (Export)wasm_runtime_addr_native_to_app
- (Export)wasm_runtime_get_app_addr_range
- aot_set_aux_stack
- aot_get_aux_stack
- wasm_set_aux_stack
- wasm_get_aux_stack
- aot_check_app_addr_and_convert, wasm_check_app_addr_and_convert
  and jit_check_app_addr_and_convert
- wasm_exec_env_set_aux_stack
- wasm_exec_env_get_aux_stack
- wasm_cluster_create_thread
- wasm_cluster_allocate_aux_stack
- wasm_cluster_free_aux_stack

## Data structure changes
- WASMModule and AOTModule
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMExecEnv
  - field aux_stack_boundary and aux_stack_bottom
- AOTCompData
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMMemoryInstance(AOTMemoryInstance)
  - field memory_data_size and change __padding to is_memory64
- WASMModuleInstMemConsumption
  - field total_size and memories_size
- WASMDebugExecutionMemory
  - field start_offset and current_pos
- WASMCluster
  - field stack_tops

## Components that are affected by the APIs and data structure changes
- libc-builtin
- libc-emcc
- libc-uvwasi
- libc-wasi
- Python and Go Language Embedding
- Interpreter Debug engine
- Multi-thread: lib-pthread, wasi-threads and thread manager
2024-03-12 11:38:50 +08:00
Wenyong Huang
b6216a5f8a
Fix ip (bytecode offset) not committed into the latest aot frame (#3213) 2024-03-11 18:11:43 +08:00
Enrico Loparco
7692f32a94
Allow overriding max memory on module instantiation (#3198)
This PR adds a max_memory_pages parameter to module instantiation APIs,
to allow overriding the max memory defined in the WASM module.

Sticking to the max memory defined in the module is quite limiting when
using shared memory in production. If targeted devices have different
memory constraints, many wasm files have to be generated with different
max memory values. And device constraints may not be known in advance.

Being able to set the max memory value during module instantiation allows
to reuse the same wasm module, e.g. by retrying instantiation with different
max memory value.
2024-03-05 17:53:26 +08:00
YAMAMOTO Takashi
0e8d949440
lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)
Also, print the function name on argument mismatch.
2024-03-04 17:08:11 +08:00
TianlongLiang
cd63b3b8f2
Fix LLVM assertion failure and update CONTRIBUTING.md (#3197)
The issue was reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3188.
2024-03-04 09:01:40 +08:00
Xu Jun
21819fcff6
Fix dynamic offset in BR for block with return type (#3192)
The issue was reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3170.
2024-03-01 10:15:17 +08:00
Wenyong Huang
5635244169
Remove unused core/app-mgr folder (#3186)
The app-manager and app-framework have been migrated to:
https://github.com/bytecodealliance/wamr-app-framework
2024-02-29 16:16:02 +08:00
YAMAMOTO Takashi
503c9694c8
lldb_function_to_function_dbi: Fix a null dereference (#3189)
C++ allows unnamed arguments.
In the debug info, they are represented as DW_TAG_formal_parameter
w/o DW_AT_name.
variable.GetName() here returns NULL for them.

cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3187
2024-02-29 14:03:49 +08:00
Marcin Kolny
bc4f8ab0a5
Specify language in the wasi socket ext project (#3183)
If the language is not specified, CMake will try to find C++ compiler, even
though it is not really needed in that case (as the project is only written in C).
2024-02-28 19:35:00 +08:00
mkolchurin
c949f3d2aa
zephyr: Implement Alloc_With_System_Allocator (#3179)
Add zephyr libc malloc/realloc/free which were introduced since version 1.13.0.
2024-02-28 11:18:23 +08:00
zoraaver
92bd3ba17d
Implement the remaining Windows filesystem functions (#3166)
Now that the filesystem implementation is now complete, the previous
test filters on Windows can be removed. Some of the tests only pass when
certain environment variables have been set on Windows so an extra step
has been added in the wasi test runner script to modify the test config
files before the tests begin.
2024-02-28 11:02:42 +08:00
dongsheng28849455
4f6d70bc52
Use indirect call in pre-checker function to avoid relocation in XIP mode (#3142)
The stack profiler `aot_func#xxx` calls the wrapped function of `aot_func_internal#xxx`
by using symbol reference,  but in some platform like xtensa, it’s translated into a native
long call, which needs to resolve the indirect address by relocation and breaks the XIP
feature which requires the eliminating of relocation.

The solution is to change the symbol reference into an indirect call through the lookup
table, the code will be like this:
```llvm
call_wrapped_func:                                ; preds = %stack_bound_check_block
  %func_addr1 = getelementptr inbounds ptr, ptr %func_ptrs_ptr, i32 75
  %func_tmp2 = load ptr, ptr %func_addr1, align 4
  tail call void %func_tmp2(ptr %exec_env)
  ret void
```
2024-02-27 11:17:57 +08:00
Wenyong Huang
2349df1271
Fix ref.func opcode check when GC is enabled (#3181)
The current code assumes that the element type of table segment can
be `funcref` only, but when GC is enabled, the type can be `(ref func)`
also.

Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3168.
2024-02-27 09:31:19 +08:00
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
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
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
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
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
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
Gavin Hayes
bf9fb2e680
cosmopolitan: Update compiler and update platform_internal.h (#3079)
This fixes the cosmopolitan platform.
- Switch `build_cosmocc.sh` and platform documentation to
  explicitly use the x86_64 cosmocc compiler as multi-arch
  cosmocc won't work here. Older version `cosmocc` just did
  a x86_64 build.
- Add missing items from `platform_internal.h` to fix build.
2024-01-24 16:04:48 +08:00
Enrico Loparco
3fcd79867d
Forward log and log level to custom bh_log callback (#3070)
Follow-up on #2907. The log level is needed in the host embedder to
better integrate with the embedder's logger.

Allow the developer to customize his bh_log callback with
`cmake -DWAMR_BH_LOG=<log_callback>`,
and update sample/basic to show the usage.
2024-01-24 13:05:07 +08:00
Marcin Kolny
1505e61704
Remove a lot of "unused parameter" warnings (#3075)
They might shadow some of the real issues, so better to keep the number
of warnings as low as possible.
2024-01-24 11:21:13 +08:00
YAMAMOTO Takashi
f56154ed80
thread-mgr: Fix locking problems around aux stack allocation (#3073)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3069
2024-01-24 09:46:53 +08:00
Wenyong Huang
9f64340529
Fix some issues reported by CodeQL (#3064)
Refer to https://github.com/bytecodealliance/wasm-micro-runtime/pull/2812
and https://github.com/bytecodealliance/wasm-micro-runtime/security/code-scanning?query=pr%3A2812+is%3Aopen
2024-01-23 21:38:30 +08:00
YAMAMOTO Takashi
ab97d543e0
wasm_cluster_destroy_spawned_exec_env: Avoid "invalid exec env" trap (#3068)
Possible alternatives:

* Make wasm_cluster_destroy_spawned_exec_env take two exec_env.
  One for wasm execution and another to specify the target to destroy.

* Make execute functions to switch exec_env as briefly discussed in
  https://github.com/bytecodealliance/wasm-micro-runtime/pull/2047
2024-01-23 15:20:01 +08:00
YAMAMOTO Takashi
b44aa654b8
aot_reloc_x86_64.c: Suggest to try --size-level=0 as well (#3067)
cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035
2024-01-23 13:00:19 +08:00
Marcin Kolny
627debcefb
Add flag to control Winsocket initialization (#3060)
When WAMR is embedded to other application, the lifecycle of the socket
might conflict with other usecases. E.g. if WAMR is deinitialized before any
other use of sockets, the application goes into the invalid state. The new
flag allows host application to take control over the socket initialization.
2024-01-22 07:33:26 +08:00
Xu Jun
1977ad23ef
fast-interp: Fix dynamic offset error issue in else branch (#3058)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3026.
2024-01-19 19:58:12 +08:00
YAMAMOTO Takashi
bc35602004
Fix aot large model (--size-level=0) with LLVM 18 (#3057)
The recent versions LLVM uses ".ltext" section for X86 large model.

cf. d8a04398f9

This fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3034
2024-01-19 19:43:41 +08:00
Wenyong Huang
ec6d9cb6be
Check arguments before calling bh_hash_map_find (#3055)
Check whether the arguments are NULL before calling bh_hash_map_find,
or lots of "HashMap find elem failed: map or key is NULL" warnings may
be dumped. Reported in #3053.
2024-01-19 19:29:21 +08:00
YAMAMOTO Takashi
17b0111577
wasm_runtime_begin_blocking_op: A comment about usage expectation (#3056) 2024-01-19 18:31:21 +08:00
Wenyong Huang
a7545df5d0
classic-interp: Handle SIMD opcode when JIT is enabled (#3046)
Though SIMD isn't supported by interpreter, when JIT is enabled,
developer may run `iwasm --interp <wasm_file>` to trigger the SIMD
opcode in interpreter, which isn't handled before this PR.
2024-01-19 12:31:18 +08:00
YAMAMOTO Takashi
8b37048823
Do not inherit WASM_SUSPEND_FLAG_BLOCKING from the parent thread (#3051)
It seems that some users want to wrap rather large chunk of code
with wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op.

If the wrapped code happens to have a call to
e.g. wasm_runtime_spawn_exec_env, WASM_SUSPEND_FLAG_BLOCKING is
inherited to the child exec_env and it may cause unexpected behaviors.
2024-01-19 09:55:01 +08:00
Wenyong Huang
9bcf6b4dd3
Enable quick aot entry when hw bound check is disabled (#3044)
- Enable quick aot entry when hw bound check is disabled
- Remove unnecessary ret_type argument in the quick aot entries
- Declare detailed prototype of aot function to call in each quick aot entry
2024-01-19 08:55:35 +08:00
YAMAMOTO Takashi
d13a54f860
Revert "Enable MAP_32BIT for macOS (#2992)" (#3032)
Revert "Do not use pagezero size option if osx version >= 13 (#3025)"
and  "Enable MAP_32BIT for macOS (#2992)".

Discussion: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3009
2024-01-18 09:22:09 +08:00
tkernelcn
a9807058a6
Set CONFIG_HAS_CAP_ENTER to support posix file api for freertos (#3041)
Since there is no so rich api in freertos like embedded system, simply set
CONFIG_HAS_CAP_ENTER to 1 to support posix file api for freertos.
Test file api in wasm app pass.
2024-01-17 21:20:35 +08:00
Huang Qi
64e82ca102
Disable WASM_ENABLE_SHARED_MEMORY_MMAP by default (#3042)
Fix compilation warning.
2024-01-17 19:29:31 +08:00
liang.he
5c8b8a17a6
Enhancements on wasm function execution time statistic (#2985)
Enhance the statistic of wasm function execution time, or the performance
profiling feature:
- Add os_time_thread_cputime_us() to get the cputime of a thread,
  and use it to calculate the execution time of a wasm function
- Support the statistic of the children execution time of a function,
  and dump it in wasm_runtime_dump_perf_profiling
- Expose two APIs:
  wasm_runtime_sum_wasm_exec_time
  wasm_runtime_get_wasm_func_exec_time

And rename os_time_get_boot_microsecond to os_time_get_boot_us.
2024-01-17 09:51:54 +08:00
Maks Litskevich
7b6d0a5d45
Don't redefine D_INO if already defined (#3036) 2024-01-16 22:28:06 +08:00
Marcin Kolny
ffa131b5ac
Allow using mmap for shared memory if hw bound check is disabled (#3029)
For shared memory, the max memory size must be defined in advanced. Re-allocation
for growing memory can't be used as it might change the base address, therefore when
OS_ENABLE_HW_BOUND_CHECK is enabled the memory is mmaped, and if the flag is
disabled, the memory is allocated. This change introduces a flag that allows users to use
mmap for reserving memory address space even if the OS_ENABLE_HW_BOUND_CHECK
is disabled.
2024-01-16 22:15:55 +08:00
Wenyong Huang
b3aaf2abc0
Check passive mode in fast-jit table.init (#3031)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3021.
2024-01-16 21:55:10 +08:00
YAMAMOTO Takashi
685d55d2e7
nuttx: Use larger alignment for os_mmap and comment why (#3017)
Other platforms with malloc-based os_mmap might need similar changes
too, depending on their target cpu arch.
2024-01-16 09:17:58 +08:00
Huang Qi
915adc433d
Rename rwlock_init to avoid conflict (#3016)
This symbol is too simple to cause conflict with others, such as the RW
spinlock in Linux kernel and NuttX, so rename it to avoid the conflict.
2024-01-16 08:53:18 +08:00
Enrico Loparco
54bc9f2053
Increase default app thread stack size (#3010) 2024-01-15 19:05:23 +08:00
Enrico Loparco
892a94fd05
fix(wasm-c-api): Do not clone stack frames if there's no trap (#3008)
When running the wasi-threads no_pthread sample, the assert was failing
on `src->num_elems != 0` in debug mode, it is because that the exception
is `proc_exit`, there is no trap (the execution didn't fail, no stack frames):
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/samples/wasi-threads/wasm-apps/no_pthread.c
2024-01-15 18:18:37 +08:00
YAMAMOTO Takashi
837b9904f5
aot debug: Try to use a bit more appropriate file names (#3000)
When the original wasm contains multiple compilation units, the current
logic uses the first one for everything. This commit tries to use a bit more
appropriate ones.
2024-01-15 15:02:12 +08:00
Wenyong Huang
23d2e0627c
Clear compilation warning and dead code (#3002) 2024-01-13 08:56:39 +08:00
Maks Litskevich
63012f0222
Fix build errors when initializing wasm_val_t values with macros (#3007)
Errors were reported when initializing wasm_val_t values with WASM_I32_VAL like macros.
```
 error: missing initializer for member ‘wasm_val_t::__paddings’ [-Werror=missing-field-initializers]
   64 |     wasm_val_t res = {WASM_INIT_VAL};
```
And rename DEPRECATED to WASM_API_DEPRECATED to avoid using defines with generic names.
2024-01-13 08:35:49 +08:00
YAMAMOTO Takashi
08442458b1
aot debug: Update DW_AT_producer (#3001)
Currently we are using "ant compiler", which is a bit historical.
This commit changes it to use "WAMR AoT compiler" instead.
2024-01-12 13:43:18 +08:00
Wenyong Huang
17e3bf255c
Update version number to 1.3.1 and update release notes (#2999) 2024-01-12 11:31:01 +08:00
Wenyong Huang
3198018214
Fix linux-sgx build error when libc-wasi is disabled (#2997)
Compilation error was reported when `cmake -DWAMR_BUILD_LIBC_WASI=0`
on linux-sgx platform:
```
core/shared/platform/linux-sgx/sgx_socket.c:8:10:
fatal error: libc_errno.h: No such file or directory
    8 | #include "libc_errno.h"
      |          ^~~~~~~~~~~~~~
```
After fixing, both `cmake -DWAMR_BUILD_LIBC_WASI=1` and
`WAMR_BUILD_LIBC_WASI=0` work good.
2024-01-11 14:26:39 +08:00
liang.he
9121db5671
Fix a bug when emit the custom name section to aot file (#2987)
The content in custom name section is changed after loaded since the strings
are adjusted with '\0' appended, the emitted AOT file then cannot be loaded.
The PR disables changing the content for AOT compiler to resolve it.

And disable emitting custom name section for `wamrc --enable-dump-call-stack`,
instead, use `wamrc --emit-custom-sections=name` to emit it.
2024-01-11 13:14:54 +08:00
modest
03a2af5095
Fix compilation error on iOS due to macOS-specific API (#2995)
`pthread_jit_write_protect_np` is only available on macOS, and
`sys_icache_invalidate` is available on both iOS and macOS and
has no restrictions on ARM architecture.
2024-01-11 12:35:44 +08:00
Enrico Loparco
ff25110840
Return stack frames of crashed thread when using wasm-c-api (#2908)
When using the wasm-c-api and there's a trap, `wasm_func_call()` returns
a `wasm_trap_t *` object. No matter which thread crashes, the trap contains
the stack frames of the main thread.

With this PR, when there's an exception, the stack frames of the thread
where the exception occurs are stored into the thread cluster.
`wasm_func_call()` can then return those stack frames.
2024-01-11 12:13:05 +08:00
Wenyong Huang
b21f17dd6d
Refine AOT/JIT code call wasm-c-api import process (#2982)
Allow to invoke the quick call entry wasm_runtime_quick_invoke_c_api_import to
call the wasm-c-api import functions to speedup the calling process, which reduces
the data copying.

Use `wamrc --invoke-c-api-import` to generate the optimized AOT code, and set
`jit_options->quick_invoke_c_api_import` true in wasm_engine_new when LLVM JIT
is enabled.
2024-01-10 18:37:02 +08:00
Wenyong Huang
7c7684819d
Register quick call entries to speedup the aot/jit func call process (#2978)
In some scenarios there may be lots of callings to AOT/JIT functions from the
host embedder, which expects good performance for the calling process, while
in the current implementation, runtime calls the wasm_runtime_invoke_native
to prepare the array of registers and stacks for the invokeNative assemble code,
and the latter then puts the elements in the array to physical registers and
native stacks and calls the AOT/JIT function, there may be many data copying
and handlings which impact the performance.

This PR registers some quick AOT/JIT entries for some simple wasm signatures,
and let runtime call the entry to directly invoke the AOT/JIT function instead of
calling wasm_runtime_invoke_native, which speedups the calling process.

We may extend the mechanism next to allow the developer to register his quick
AOT/JIT entries to speedup the calling process of invoking the AOT/JIT functions
for some specific signatures.
2024-01-10 16:44:09 +08:00
YAMAMOTO Takashi
6fa6d6d9a5
Enable MAP_32BIT for macOS (#2992)
On macOS, by default, the first 4GB is occupied by the pagezero.
While it can be controlled with link time options, as we are
an library, we usually don't have a control on how to link an
executable.
2024-01-10 16:19:06 +08:00
Wenyong Huang
0d4ade6b4c
Fix build failure on esp-idf platform (#2991)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2989.
2024-01-10 10:44:31 +08:00
YAMAMOTO Takashi
722381fcf2
aot compiler: Some updates for LLVM 18 (#2981)
Note: This commit includes copy-and-paste from LLVM and thus adds
the LLVM copyright notice.

cf. 0a1aa6cda2
cf. a1e9777b76
cf. 56c72c7f33
2024-01-08 10:15:31 +08:00
Wenyong Huang
c39214e8a5
Fix potential recursive lock in pthread_create_wrapper (#2980)
Potential recursive lock occurs in:
```
pthread_create_wrapper   (acquire exec_env->wait_lock)
  => wasm_cluster_create_thread
    => allocate_aux_stack
      => wasm_runtime_module_malloc_internal
        => wasm_call_function
          => wasm_exec_env_set_thread_info (acquire exec_env->wait_lock again)
```
Allocate aux stack before calling wasm_cluster_create_thread to resolve it.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/pull/2977.
2024-01-08 09:43:31 +08:00
tkernelcn
4a1ad9a160
freertos: Change ssp_config.h due to clock_nanosleep() not supported in freertos (#2979) 2024-01-04 20:01:54 +08:00
Xu Jun
f96257bade
Fix fast-interp polymorphic stack processing (#2974)
Fix issue #2951, #2952 and #2953.
2024-01-04 10:00:36 +08:00
tkernelcn
a2751903ff
freertos: Minor changes for freertos libc_wasi build adaption (#2973) 2024-01-04 09:49:24 +08:00
Wenyong Huang
1ee4767d97
Fix ref.func function declared check in wasm loader (#2972)
The forward-declare function reference in ref.func can be declared in table element segments,
no matter whether the segment mode is passive, active or declarative.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2944.
2024-01-03 11:43:03 +08:00
liutao
75a2b98eb4
simd-128: The input lanes of integer-to-integer narrowing ops should be interpreted as signed (#2850)
https://github.com/WebAssembly/spec/blob/main/proposals/simd/SIMD.md#integer-to-integer-narrowing
2024-01-03 09:51:58 +08:00
Wenyong Huang
c43e4505da
Allow to set segue flags for wasm-c-api JIT (#2926)
Add an API to set segue flags for wasm-c-api LLVM JIT mode:
```C
wasm_config_t *
wasm_config_set_segue_flags(wasm_config_t *config, uint32 segue_flags);
```
2024-01-02 19:34:18 +08:00
Wenyong Huang
aa4d68c2af
Refine AOT function call process (#2940)
Don't set exec_env's thread handle and stack boundary in the recursive
calling from host, since they have been initialized in the first time calling.
2024-01-02 19:10:31 +08:00
Wenyong Huang
3637f2df79
Refine LLVM JIT function call process (#2925)
- Don't allocate the implicit/unused frame when calling the LLVM JIT function
- Don't set exec_env's thread handle and stack boundary in the recursive
  calling from host, since they have been set in the first time calling
- Fix frame not freed in llvm_jit_call_func_bytecode
2024-01-02 18:46:02 +08:00
Xu Jun
d818672f62
Fix ref.is_null processing in fast-interp loader (#2971) 2024-01-02 18:10:01 +08:00
Wenyong Huang
2ee013faf3
fast-jit: Fix const shift and const i64 compare issues (#2969) 2024-01-02 17:56:34 +08:00
tkernelcn
286ea35508
fixed(freertos): Fix crash when wasm app call pthread_exit(NULL) (#2970)
before the change, only support wasm app exit like:
```c
void *thread_routine(void *arg)
{
    printf("Enter thread\n");
    return NULL;
}
```
if call pthread_exit, it will crash:
```c
void *thread_routine(void *arg)
{
    printf("Enter thread\n");
    pthread_exit(NULL);
    return NULL;
}
```
This commit lets both upstairs work correctly, test pass on stm32f103 mcu.
2024-01-02 17:32:09 +08:00
liang.he
5c3ad0279a
Enable AOT linux perf support (#2930)
And refactor the original perf support
- use WAMR_BUILD_LINUX_PERF as the cmake compilation control
- use WASM_ENABLE_LINUX_PERF as the compiler macro
- use `wamrc --enable-linux-perf` to generate aot file which contains fp operations
- use `iwasm --enable-linux-perf` to create perf map for `perf record`
2024-01-02 15:58:17 +08:00
tkernelcn
92bf8547aa
freertos: Add os_cond_broadcast for pthread wrapper (#2937) 2023-12-28 22:57:19 +08:00
Wenyong Huang
4a7a66e900
Enable wasm_runtime_terminate for single-threading (#2924)
The host embedder may also want to terminate the wasm instance
for single-threading mode, and it should work by setting exception
to the wasm instance.
2023-12-26 16:05:44 +08:00
Wenyong Huang
5a75c31c38
Add VectorCombine pass for JIT and AOT (#2923)
It improves performance for some cases.
And add several vectorize related passes for JIT mode.
2023-12-26 11:27:20 +08:00
Wenyong Huang
1055c9884b
Refine wasm-c-api wasm_func_call (#2922)
Refine params_to_argv, argv_to_results, wasm_func_param_arity,
wasm_func_result_arity to fasten the wasm-c-api call wasm function process.
2023-12-26 11:05:31 +08:00
Daniel Mangum
9779f922b9
Fix boundary check typo in AOT compiler context (#2913)
Fixes typo in docstrings for boundary check in the AOT compiler context.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-12-20 09:08:13 +08:00
Enrico Loparco
6dbfeb25dd
Expose API to set log level in embedder (#2907)
Expose API `void wasm_runtime_set_log_level(log_level_t level)`.
2023-12-15 18:49:33 +08:00
Enrico Loparco
b5022015fc
Avoid reporting timestamp if custom logger is used (#2905)
Loggers (e.g. glog) usually come with instrumentation to add timestamp
and other information when reporting. That results in the timestamp
being reported twice, making the output confusing.
2023-12-14 14:55:17 +08:00
YAMAMOTO Takashi
18529253d8
interpreter: Simplify memory.grow a bit (#2899) 2023-12-12 20:24:51 +08:00
Yage Hu
ef0cd22119
Fix memory size not updating after growing in interpreter (#2898)
This commit fixes linear memory size not updating after growing.
This causes `memory.fill` to throw an exception after `memory.grow`.
2023-12-12 08:36:59 +08:00
Enrico Loparco
4aee3cf14e
Avoid memory import failure when wasi-threads is enabled (#2893)
According to the specification:
```
When instantiating a module which is expected to run
with `wasi-threads`, the WASI host must first allocate shared memories to
satisfy the module's imports.
```
Currently, if a test from the spec is executed while having the `multi-module`
feature enabled, WAMR fails with `WASM module load failed: unknown import`.
That happens because spec tests use memory like this:
  `(memory (export "memory") (import "foo" "bar") 1 1 shared)`
and WAMR tries to find a registered module named `foo`.

At the moment, there is no specific module name that can be used to identify
that the memory is imported because using WASI threads:
  https://github.com/WebAssembly/wasi-threads/issues/33,
so this PR only avoids treating the submodule dependency not being found
as a failure.
2023-12-11 22:17:31 +08:00
Huang Qi
269b695f85
Refactor reloc symbols for riscv (#2894) 2023-12-11 14:44:41 +08:00
Yage Hu
bc2d8959dd
Handle ambiguous fstflags on fd_filestat_set_times (#2892)
It's possible to set both `atim` and `atim_now` in the `fstflags`
parameter.  Same goes for `mtin` and `mtim_now`.  However, it's
ambiguous which time should be set in these two cases.  This commit
checks this and returns `EINVAL`.
2023-12-11 14:16:58 +08:00
Enrico Loparco
6cb2ea4935
fix command-reactor: Look for _initialize only if _start not found (#2891)
A wasm module can be either a command or a reactor, so it can export
either `_start` or `_initialize`. Currently, if a command module is run,
`iwasm` still looks for `_initialize`, resulting in the warning:
  `can not find an export 0 named _initialize in the module`.

Change to look for `_initialize` only if `_start` not found to resolve the issue.
2023-12-11 10:10:26 +08:00
Maks Litskevich
63696ba603
Fix typo in CI config and suppress STORE_U8 in TSAN (#2802)
This typo prevented sanitizers to work in the CI.
2023-12-11 09:16:30 +08:00
Wenyong Huang
b008ab4fba
Fix possible dead lock in wasm_cluster_spawn_exec_env (#2882)
Fix a deadlock issue like:

wasm_runtime_spawn_exec_env
wasm_cluster_spawn_exec_env (hold cluster->lock)
wasm_runtime_instantiate_internal
wasm_instantiate
execute_post_instantiate_functions
wasm_exec_env_set_module_inst (grab the lock again)

Refer to #2879.
2023-12-08 17:28:57 +08:00
Stephen Berard
df83aef101
Corrects Zephyr include files for current versions of Zephyr (#2881)
This fixes bug #2880.  Zephyr 3.2 made changes to how headers are reference (see [release notes](https://docs.zephyrproject.org/latest/releases/release-notes-3.2.html)).  Work item [49578](https://github.com/zephyrproject-rtos/zephyr/issues/49578) deprecated the old headers names.
The current WAMR codebase references these old headers, thus causing compile errors with
current versions of Zephyr.

This update adds #ifdefs around the header names.  With this change, compiling with Zephyr 3.2.0
and above will use the new header files.  Prior versions will use the existing code.
2023-12-08 17:16:16 +08:00
Yage Hu
0b332d8987
Portably handle fd_advise on directory fd (#2875)
This commit adds a check to `fd_advise`.  If the fd is a directory,
return `ebadf`.  This brings iwasm in line with Wasmtime's behavior.
WASI folks have stated that fd_advise should not work on directories
as this is a Linux-specific behavior:
https://github.com/bytecodealliance/wasmtime/issues/6505#issuecomment-1574122949
2023-12-07 09:52:53 +08:00
Wenyong Huang
ac602bda32
Update version number to 1.3.0 and update release notes (#2821)
And refine the code format for wasm_export.h.
2023-12-06 16:27:21 +08:00
Wenyong Huang
67a887e2d3
Fix compilation warnings on Windows (#2868) 2023-12-06 16:12:33 +08:00
Huang Qi
49cd2e011b
Fix float argument handling for riscv32 ilp32d (#2871) 2023-12-06 11:30:07 +08:00
Xu Jun
53c3fa27d4
Fix block with type issue in fast interp (#2866)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2863.
2023-12-05 17:09:05 +08:00
Wenyong Huang
23c1343fb3
Fix wasm loader handle op_br_table and op_drop (#2864)
- Fix op_br_table arity type check when the dest block is loop block
- Fix op_drop issue when the stack is polymorphic and it is to drop
  an ANY type value in the stack
2023-12-05 16:59:13 +08:00
Huang Qi
e350e65b12
Don't add "+d" to riscv cpu features if already given (#2855) 2023-12-04 17:00:21 +08:00
Wenyong Huang
b0d5b8df1d
Fix issues of build/run with llvm-17 (#2853)
- Fix compilation error of using PGOOptions
- Fix LLVM JIT run error due to `llvm_orc_registerEHFrameSectionWrapper`
  symbol not found
2023-12-04 16:40:54 +08:00
Huang Qi
453a29a9d4
Enable spectest on riscv64 (#2843)
Fix relocation issues on riscv and update test scripts and CI to enable
test spec cases on riscv QEMU.
2023-12-04 14:22:47 +08:00
YAMAMOTO Takashi
73914caa9b
core/iwasm/interpreter/wasm_loader.c: remove an extra validation (#2845)
* Empty names are spec-wise valid.
* As we ignore unknown custom sections anyway, it's safe to
  accept empty names here.
* Currently, the problem is not exposed on our CI because
   the wabt version used there is a bit old.
2023-12-01 18:29:15 +08:00
TianlongLiang
3d0342fbc8
Fix fast-jit accessing shared memory's fields issue (#2841)
For shared memory, runtime should get the memories pointer from
module_inst first, then get memory instance from memories array,
and then get the fields of the memory instance.
2023-12-01 17:41:24 +08:00
liang.he
162a977006
Use wasm_config_t to pass private configuration to wasm_engine_new (#2837)
Support new a wasm_config_t, set allocation and linux_perf_support
options to it, and then pass it to wasm_engine_new_with_config to
new an engine with private configuration.
2023-12-01 12:34:11 +08:00
liang.he
718f0671e7
Output warning and quit if import/export name contains '\00' (#2806)
Leave it as a limitation when import/export name contains '\00' in wasm file.
p.s. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2789
2023-12-01 11:14:13 +08:00
Enrico Loparco
873558c40e
Get rid of compilation warnings and minor doc fix (#2839) 2023-11-30 08:49:58 +08:00
Enrico Loparco
0455071fc1
Access linear memory size atomically (#2834)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2804
2023-11-29 20:27:17 +08:00
liang.he
8aa813f44a
Generate jitdump to support linux perf for LLVM JIT (#2788) 2023-11-27 15:42:00 +08:00
Marcin Kolny
5f7079f0f5
Return error when shutdown() fails (#2801)
Fix issue reported in #2787.
2023-11-24 21:03:59 +08:00
Daniel Mangum
2a3c93f502
Fix typos in zephyr platform struct descriptions (#2818)
Fixes typos in zephyr platform struct descriptions.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-24 08:47:38 +08:00
Huang Qi
cb44e56b4e
Fix Zifencei extension issue in RISC-V (#2807)
Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/pull/2805
2023-11-23 10:23:33 +08:00
Jämes Ménétrey
f9e8b9535e
Attestation: Free JSON from the Wasm module heap (#2803)
The JSON evidence is allocated on the module instance heap, but no API
was given to dispose of this memory buffer. The sample mentions using
the function free, which behaves differently depending on the
execution context.

This fix provides a new function called librats_dispose_evidence_json,
enabling freeing the JSON evidence directly from the Wasm app.
2023-11-22 10:48:14 +08:00
Wenyong Huang
4d5eb346fc
Change is_shared_memory type from bool to uint8 (#2800)
Change WASMMemoryInstance's field is_shared_memory's type from bool
to uint8 whose size is fixed, so as to make WASMMemoryInstance's size
and layout fixed and not break AOT ABI.

See discussion in https://github.com/bytecodealliance/wasm-micro-runtime/pull/2682.
2023-11-22 10:38:08 +08:00
Huang Qi
0b29904f26
Fix configurable bounds checks typo (#2809) 2023-11-21 17:32:45 +08:00
Huang Qi
9ad42290d8
Fix formatting in wasm_dump_perf_profiling (#2799)
Changes %d to %PRIu32.
2023-11-20 18:06:35 +08:00
Wenyong Huang
103cb89593
aot compiler: Fix handle next reachable if block (#2793)
The popped reachable block may be if block whose else branch hasn't been
translated, and should push the params for the else block if there are.

And use LLVMDisposeMessage to free memory allocated in is_win_platform.
2023-11-20 17:14:10 +08:00
TianlongLiang
a57e70016a
Fix memory.init opcode issue in fast-interp (#2798)
Fix fast interpreter didn't throw OOB exception correctly in some scenarios.
Reported in #2797.
2023-11-20 16:25:43 +08:00
Huang Qi
aebe30426f
Fix formatting in aot_dump_perf_profiling (#2796)
Changes %d to %PRIu32.
2023-11-20 12:11:02 +08:00
Huang Qi
e8c8f7fca6
Fix return type in wasm_loader_get_custom_section (#2794)
Should return NULL instead of false.
2023-11-20 10:36:15 +08:00
Daniel Mangum
0bb157b88a
Fix comment in WAMR_MEM_DUAL_BUS_MIRROR (#2791)
Fixes a small typo in the WAMR_MEM_DUAL_BUS_MIRROR description.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-20 10:25:00 +08:00
Daniel Mangum
657fd7bb42
Fix broken links in app-mgr README.md (#2786)
Fixes a few relative path broken links in app-mgr README.md.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2023-11-20 10:04:45 +08:00
Huang Qi
be05af79fb
Refine atomic operation flags in bh_atomic.h (#2780) 2023-11-18 08:59:58 +08:00
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
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
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
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
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
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
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
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
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
Marcin Kolny
72b34eaf30
Fix AOT shift operations for indirect constants (#2627)
When doing more investigations related to this PR:
  https://github.com/bytecodealliance/wasm-micro-runtime/pull/2619
We found that in some scenarios the constant might not be directly
available to the LLVM IR builder, e.g.:
```
  (func $const_ret (result i32)
    i32.const -5
  )
  (func $foo
    (i32.shr_u (i32.const -1) (call $const_ret))
    (i32.const 31)
  )
```
In that case, the right parameter to `i32.shr_u` is not constant, therefore
the `SHIFT_COUNT_MASK` isn't applied. However, when the optimization
is enabled (`--opt-level` is 2 or 3), the optimization passes resolve the
call into constant, and that constant is poisoned, causing the compiler to
resolve the whole function to an exception.
2023-10-11 11:22:34 +08:00
liang.he
e73993709e
Use another default pipeline when opt-level is 0 (#2624)
According to the description of `buildPerModuleDefaultPipeline()` and
`buildLTOPreLinkDefaultPipeline()`, it is not allowed to call them with `O0` level.
Use `buildO0DefaultPipeline` instead when the opt-level is 0.
2023-10-10 10:52:37 +08:00
Wenyong Huang
e222955f31 Merge branch main into dev/wasi-libc-windows 2023-10-09 09:24:00 +08:00
TianlongLiang
059fbfc252
Fix potential issue in aot compiler when translating block opcodes (#2622)
The LLVM zext IR may be inserted after the terminator of a basic block
when popping the arguments of a wasm block. Change to insert the
zext IR before the terminator of the basic block to resolve the issue.

Reported in #2620.
2023-10-08 09:17:54 +08:00
Wenyong Huang
7c22bde8dc
CI: Enable testing AOT multi-module feature (#2621)
And refine some code pieces.
2023-10-08 08:36:49 +08:00