Commit Graph

1074 Commits

Author SHA1 Message Date
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