Commit Graph

1235 Commits

Author SHA1 Message Date
TianlongLiang
30ed97cddc
Fix several typos and fix bh_log calculate mills (#3441) 2024-05-20 15:54:01 +08:00
YAMAMOTO Takashi
ec44f494cc
NuttX: Replace esp32s3 bits with the OS-provided APIs (#3439)
Expected merge order:
https://github.com/apache/nuttx/pull/12355
https://github.com/apache/nuttx-apps/pull/2395
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3439
2024-05-18 20:35:16 +08:00
Benbuck Nason
7744e84607
ssp_config.h: Fix ifdef for android random api (#3444)
It looks like the preferred preprocessor check for Android is `__ANDROID__`
instead of `ANDROID`:
https://groups.google.com/g/android-ndk/c/cf9_f1SLXls

Change `(defined(ANDROID) && __ANDROID_API__ < 28)` to
`((defined(ANDROID) || defined(__ANDROID__)) && (__ANDROID_API__ < 28))`.
2024-05-18 20:23:34 +08:00
liang.he
b2eb7d838d
Update spec test to latest commit (#3293)
- Update spec test cases to commit bc76fd79cfe61033d7f4ad4a7e8fc4f996dc5ba8 on Apr. 3
- Update wabt binary to 1.0.34 to support newer spec cases
- Add comparison between table declared elem type and table elem segment value type
- Add a function to decide whether to execute test cases in a running mode
- Keep using interpreter in GC spec because wat2wasm in wabt can't compile if.wast w/o errors
- Re-factoring threads spec test case processing
- Since wabt 1.0.34 release isn't compatible with ubuntu 20.04, compile it from source code
- Disable CI to run aot multi-module temporarily, and will enable it in another PR
2024-05-17 10:40:47 +08:00
Enrico Loparco
6b1d81650d
Allow not copying the wasm binary in wasm-c-api and not referring to the binary in wasm/aot loader (#3389)
Add flag `LoadArgs.clone_wasm_binary` to control whether to clone the wasm/aot
binary in wasm-c-api module. If false, API `wasm_module_new_ex` won't clone the
binary, which may reduce the footprint.

Add flag `LoadArgs.wasm_binary_freeable` to control whether the wasm/aot binary
may be freed after instantiation for wamr API `wasm_runtime_load_ex`, if yes, then
for some running modes, the wasm/aot module doesn't refer to the input binary
again so developer can free it after instantiation to reduce the footprint.

And add API `wasm_module_is_underlying_binary_freeable` and
`wasm_runtime_is_underlying_binary_freeable` to check whether the input binary
can be freed after instantiation for wasm-c-api and wamr api.

And add sample to illustrate it.
2024-05-17 09:00:08 +08:00
YAMAMOTO Takashi
51ecfd6673
libc-wasi: Fix a locking botch (#3437) 2024-05-15 15:41:40 +08:00
Wenyong Huang
7949df96f4
Fix fast interp RECOVER_BR_INFO and local set/tee (#3434)
When copying two cells from src offsets to dst offsets in RECOVER_BR_INFO,
the offsets may be overlapped and the src data may be overwritten, use
GET_I64_FROM_ADDR and then SET_I64_FROM_ADDR instead to resolve it.

And handling VALUE_TYPE_FUNCREF/VALUE_TYPE_EXTERNREF for opcode
local.set and local.tee when reference types feature is enabled.

This PR fixes issue #3401 and #3402.
2024-05-15 15:20:21 +08:00
Wenyong Huang
49c9fa31da
Fix typo of WAMR_CONFIGUABLE_BOUNDS_CHECKS (#3424)
Change to WAMR_CONFIGURABLE_BOUNDS_CHECKS, and fix CodeQL compilation errors
which were introduced by PR #3406.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3393#discussion_r1591810998
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/9055318553/job/24876266629
2024-05-14 14:33:09 +08:00
Benbuck Nason
0f17a1464e
Add comments to global type function declarations (#3431) 2024-05-14 11:38:18 +08:00
YAMAMOTO Takashi
b1529bc803
nuttx/esp32s3: Apply ibus/dbus adjustment to internal ram 1 as well (#3421) 2024-05-14 11:28:24 +08:00
Wenyong Huang
773efc006d
Change WASM_ANYREF to WASM_EXTERNREF (#3426)
wasm-c-api wasm.h had changed WASM_ANYREF to WASM_EXTERNREF,
we had better change it in WAMR also:
2ce1367c9d/include/wasm.h (L185)
2024-05-14 11:08:16 +08:00
Wenyong Huang
004d07bb86
Remove unused macros which were moved to wamr-app-framework (#3425)
Some macros are not related to WAMR and have been moved to wamr-app-framework,
we remove them in WAMR.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3393#discussion_r1591812319
https://github.com/bytecodealliance/wamr-app-framework/pull/9
2024-05-14 10:52:05 +08:00
Benbuck Nason
dbd8790681
Add WASM_V128 in wasm_valkind_enum (#3412)
Add WASM_V128 in wasm_valkind_enum and handle the the type accordingly
in wasm_c_api.c and wasm_runtime_common.c, and fix a typo in V128 union.
2024-05-14 10:22:42 +08:00
YAMAMOTO Takashi
456e2f6919
aot compiler: Fix a type mismatch in compile_op_float_min_max (#3423)
Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3422
2024-05-14 10:06:48 +08:00
YAMAMOTO Takashi
8f098a5905
aot: Make precheck functions use short-call for xtensa (#3418)
Note: this breaks AOT ABI for xtensa again because of a revert of an ABI-breaking change.
2024-05-13 16:55:00 +08:00
TianlongLiang
c6d42db598
Correct Exception Handling tag type when GC is enabled (#3413)
Use `WASMFuncType` to represent tag_type in `WASMTagImport` and
`WASMTag` so that the type definition is consistent no matter to GC is
enabled or not.

This PR fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3409.
2024-05-13 16:42:01 +08:00
Marcin Kolny
fe5e7a9981
Implement Memory64 support for AOT (#3362)
Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3266
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3091
2024-05-13 11:03:38 +08:00
Benbuck Nason
c85bada2a9
Add wasm module global type information APIs (#3406)
Support getting global type from `wasm_runtime_get_import_type` and
`wasm_runtime_get_export_type`, and add two APIs:

```C
wasm_valkind_t
wasm_global_type_get_valkind(const wasm_global_type_t global_type);

bool
wasm_global_type_get_mutable(const wasm_global_type_t global_type);
```
2024-05-10 09:15:58 +08:00
YAMAMOTO Takashi
46f83cf486
core/iwasm/compilation: Remove stale function prototypes (#3408) 2024-05-09 16:55:32 +08:00
Wenyong Huang
a6c0cb74c9
wasm loader: Fix handling if block without op else (#3404)
If there is no else branch, make a virtual else opcode for easier integrity
check and to copy the correct results to the block return address for
fast-interp mode: change if block from `if ... end` to `if ... else end`.

Reported in issue #3386, #3387, #3388.
2024-05-09 16:46:26 +08:00
TianlongLiang
ea13d47a41
ref-types: Correct default value for function local variables (#3397)
In classic interpreter, fast interpreter and fast-jit running modes, set the local
variables' default value to NULL_REF (0xFFFFFFFF) rather than 0 if they are type
of externref or funcref.

The issue was reported in #3390 and #3391.
2024-05-09 16:31:21 +08:00
Benbuck Nason
432a940735
Fix clang compile warnings (#3396) 2024-05-08 16:43:47 +08:00
Benbuck Nason
1c2a8fca4e
Fix some more spelling issues (#3393) 2024-05-08 09:30:29 +08:00
Benbuck Nason
ca61184ced
Fix some spelling issues (#3385)
Fix some of the spelling issues found by CSpell.
2024-05-06 07:56:48 +08:00
Benbuck Nason
c0e33f08b0
Expose API to get import/export function's param/result valkind (#3363)
Export API:
```C
   wasm_func_type_get_param_count
   wasm_func_type_get_param_valkind
   wasm_func_type_get_result_count
   wasm_func_type_get_result_valkind
```
And change wasm_import_type/wasm_export_type to wasm_import_t/wasm_export_t.
2024-05-03 09:41:08 +08:00
Wenyong Huang
835188cc53
aot compiler: Fix the length type passed to aot_memmove/aot_memset (#3378)
The current length type of aot_memmove/aot_memset is size_t, and on
a 64 bit host it is uint64, while what the aot code passes to it is uint32,
this might lead to unexpected behavior.

ps. https://github.com/bytecodealliance/wasm-micro-runtime/pull/3376.
2024-05-01 21:40:52 +08:00
YAMAMOTO Takashi
163f29e51b
Add some more comments on WASM_STACK_GUARD_SIZE (#3380) 2024-05-01 15:15:17 +08:00
Benbuck Nason
4abf288c94
Fix typo for 'native' in wasm_export.h (#3376)
Trivial spelling fix.
2024-04-30 08:57:49 +08:00
TianlongLiang
79ae910a7c
Fix loader and mini-loader select potiential error (#3374)
Fix the issue reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3361.
2024-04-29 12:27:55 +08:00
Wenyong Huang
e11eae93e2
Fix aot debugger compilation error on windows (#3370)
Fix aot debugger compilation error on windows as reported in #3184.

And update the stack size configuration for product-mini zephyr sample
since the native stack overflow check was enhanced and the zephyr-sdk
was also upgraded.
2024-04-29 10:38:43 +08:00
YAMAMOTO Takashi
120b9659dd
A few native stack detection fixes for macOS/arm64 (#3368) 2024-04-26 19:37:55 +08:00
YAMAMOTO Takashi
410ee580ae
Add wasm_runtime_detect_native_stack_overflow_size (#3355)
- Add a few API (https://github.com/bytecodealliance/wasm-micro-runtime/issues/3325)
   ```c
   wasm_runtime_detect_native_stack_overflow_size
   wasm_runtime_detect_native_stack_overflow
   ```
- Adapt the runtime to use them
- Adapt samples/native-stack-overflow to use them
- Add a few missing overflow checks in the interpreters
- Build and run the sample on the CI
2024-04-26 16:00:58 +08:00
dongheng
21cd423a72
Fix ESP32-S3 compiling error (#3359)
1. when enable SPIRAM
2. when using esp-idf v5.3
2024-04-25 20:42:16 +08:00
Wenyong Huang
e44465d259
Enhance wasm loader checks for opcode br_table (#3352)
Fix the integer overflow issue when checking target branch depth in opcode
br_table, and fix is_32bit_type not check VALUE_TYPE_ANY issue, which may
cause wasm_loader_push_frame_offset push extra unneeded offset.
2024-04-25 20:07:57 +08:00
YAMAMOTO Takashi
9d6d3466ff
Fix a few native stack address calculations (#3351) 2024-04-24 16:39:38 +08:00
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