Commit Graph

2040 Commits

Author SHA1 Message Date
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
YAMAMOTO Takashi
1b5ff93656
CI: Use macos-13 instead of macos-latest (#3366)
Our workflows assume macos-latest is intel, but now it's arm64.
Use macos-13, which is documented to be intel, instead.

reference:
https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners
2024-04-26 14:38:49 +08:00
TianlongLiang
f14a166466
Test more samples in nightly-run CI (#3358)
Build and run sample native-lib and wamr-app-framework's simple
in nightly-run CI.
2024-04-25 20:58:28 +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
a36c7d5aa9
Random improvements to samples/native-stack-overflow (#3353) 2024-04-25 11:22:08 +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
Wenyong Huang
ca5209cd9c
doc: Add ADOPTERS.md (#3324) 2024-04-24 16:17:00 +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
Huang Qi
0aeef69d23
Update binary size info in README.md (#3030)
And also show size in CI with NuttX.

The size info is from bloaty, which is a tool to measure binary size.
Example usage and output (WAMR stuff only):

```
➜  sim bloaty -s file nuttx/nuttx -d compileunits -n 10000 --source-filter wamr
    FILE SIZE        VM SIZE
 --------------  --------------
  13.1%   108Ki  19.4%  14.6Ki    wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
  12.2%   100Ki   0.1%      50    wamr/core/iwasm/common/wasm_c_api.c
  10.6%  87.1Ki   8.7%  6.54Ki    wamr/core/iwasm/common/wasm_runtime_common.c
   9.2%  76.1Ki  12.6%  9.45Ki    wamr/core/iwasm/aot/aot_loader.c
   8.9%  73.6Ki  12.5%  9.38Ki    wamr/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
   7.1%  58.7Ki   9.0%  6.79Ki    wamr/core/iwasm/aot/aot_runtime.c
   3.6%  29.3Ki   5.6%  4.21Ki    wamr/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c
   3.2%  26.2Ki   3.6%  2.73Ki    wamr/core/shared/platform/common/posix/posix_socket.c
   2.9%  24.0Ki   2.7%  2.01Ki    wamr/core/iwasm/common/wasm_memory.c
   2.8%  23.2Ki   2.3%  1.74Ki    wamr/core/iwasm/common/wasm_application.c
   2.6%  21.5Ki   3.3%  2.46Ki    wamr/core/shared/platform/common/posix/posix_file.c
   2.5%  20.4Ki   1.9%  1.45Ki    wamr/core/iwasm/common/wasm_native.c
   2.4%  20.0Ki   2.0%  1.51Ki    wamr/core/iwasm/aot/arch/aot_reloc_riscv.c
   2.1%  17.3Ki   1.6%  1.20Ki    wamr/core/iwasm/common/wasm_shared_memory.c
   2.0%  16.4Ki   2.4%  1.81Ki    wamr/core/shared/mem-alloc/ems/ems_alloc.c
   1.9%  15.9Ki   2.4%  1.81Ki    wamr/product-mini/platforms/nuttx/main.c
   1.7%  13.8Ki   1.4%  1.05Ki    wamr/core/iwasm/aot/aot_intrinsic.c
   1.5%  12.2Ki   0.4%     312    wamr/core/iwasm/common/wasm_exec_env.c
   1.4%  11.8Ki   0.8%     618    wamr/core/shared/platform/common/posix/posix_thread.c
   1.0%  8.20Ki   1.2%     952    wamr/core/shared/utils/bh_hashmap.c
   0.9%  7.52Ki   0.8%     636    wamr/core/shared/utils/bh_vector.c
   0.9%  7.46Ki   0.8%     618    wamr/core/shared/mem-alloc/ems/ems_kfc.c
   0.8%  6.89Ki   1.0%     744    wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c
   0.8%  6.65Ki   0.5%     356    wamr/core/shared/platform/nuttx/nuttx_platform.c
   0.5%  4.25Ki   0.4%     316    wamr/core/shared/utils/bh_common.c
   0.4%  3.70Ki   0.3%     248    wamr/core/shared/utils/bh_log.c
   0.4%  3.52Ki   0.4%     330    wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c
   0.4%  3.07Ki   0.1%      40    wamr/core/shared/mem-alloc/mem_alloc.c
   0.3%  2.52Ki   0.3%     196    wamr/core/shared/utils/uncommon/bh_read_file.c
   0.3%  2.36Ki   0.3%     216    wamr/core/shared/platform/common/posix/posix_clock.c
   0.3%  2.27Ki   0.1%     106    wamr/core/shared/utils/bh_list.c
   0.2%  1.91Ki   0.6%     430    wamr/core/shared/platform/common/libc-util/libc_errno.c
   0.2%  1.78Ki   0.1%      94    wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c
   0.2%  1.73Ki   0.0%       6    wamr/core/iwasm/common/wasm_blocking_op.c
   0.2%  1.42Ki   0.1%      74    wamr/core/shared/utils/bh_bitmap.c
   0.1%  1.02Ki   0.1%      82    wamr/core/shared/platform/common/posix/posix_time.c
   0.1%     751   0.2%     138    wamr/core/iwasm/common/arch/invokeNative_riscv.S
 100.0%   823Ki 100.0%  75.1Ki    TOTAL
```
2024-04-23 17:15:53 +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
Wenyong Huang
a6e008bca7
document: Update description about segue opt, update README (#3338) 2024-04-22 14:34:52 +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
d6e8d224ce
Add native-stack-overflow sample (#3321)
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

https://github.com/bytecodealliance/wasm-micro-runtime/issues/3325
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3320
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3314
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3297
2024-04-19 15:49:09 +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
TianlongLiang
30426be82c
Refactor CodeQL CI (#3319)
- Move CodeQL scripts to the scripts directory
- Only report error in CI if it's a CodeQL reported issue and was not dismissed
  before and is likely to be an actual error
2024-04-16 16:32:47 +08:00
liang.he
42199f163e
Log warning if growing table failed (#3310) 2024-04-15 18:29:54 +08:00
liang.he
fef26ead3e
addr2line.py: Support sourceMappingURL section produced by emcc (#3302)
And update the debug-tools sample.
2024-04-12 11:43:40 +08:00
dependabot[bot]
1a043b6eb5
Bump actions/upload-artifact from 3 to 4 (#3308)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 11:34:06 +08:00
dependabot[bot]
ff7bf7ad41
Bump actions/setup-node from 3 to 4 (#3307)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 11:33:30 +08:00
dependabot[bot]
b54551598a
Bump github/codeql-action from 2 to 3 (#3306)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 11:31:05 +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
liang.he
19a6eb98b0
Add dependabot (#3303) 2024-04-11 19:56:02 +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
TianlongLiang
4a29794a1b
Update release CI (#3295)
In the release CI and related scripts, when comparing and printing to the CI,
use the most recent **ancestor** tag(s) for the release branch rather than
the most recent one(s).

And fix the build_wamr_sdk.yml and build_wamr_lldb.yml CIs.
2024-04-09 16:51:36 +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
TianlongLiang
cee9b826a5
Update document for GC, exception handling and memory64 features (#3284)
Add GC, exception handling and memory64 to README.md post MVP feature list,
and update build_wamr.md for how to build them.

And remove `Non-trapping float-to-int conversions`, `Sign-extension operators`,
`Multi-value` links in README since they are in wasm MVP and very common now.
2024-04-07 14:54:02 +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
liang.he
202abc1937
Small enhancement on addr2line.py (#3276)
- If can't parse function name with dwarf information, use "name
  section" instead
- Add introduction about using custom section
2024-04-04 18:32:53 +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