Commit Graph

250 Commits

Author SHA1 Message Date
Enrico Loparco
3b8ef89110
Clone data segments when specified with load args (#3463)
Follow-up on https://github.com/bytecodealliance/wasm-micro-runtime/pull/3389, specifically: https://github.com/bytecodealliance/wasm-micro-runtime/pull/3389#discussion_r1600872451

If we want to free the wasm binary buffer early, we need to clone the data segments into the module.
That's because, in case of [passive data segments](https://webassembly.github.io/threads/core/syntax/modules.html#syntax-data),
they can be referred during wasm execution.
2024-05-27 09:59:24 +08:00
Byeongjee Kang
33aada2133
Remove install_wasi_sdk from workload preparation script (#3445)
This function was removed in 7be0d38 while building a customized wasi-sdk.
2024-05-20 16:18:34 +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
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
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
Hendra Darwintha
22eef3d88d
Fix basic example, parameter missmatch between host and wasm (#3415)
Revert the mistaken change by PR #3209.
2024-05-13 12:37:28 +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
YAMAMOTO Takashi
3e5361f76d
samples/native-stack-overflow: Examine native functions with signature (#3382)
Note: wamrc chooses different methods to call native functions
with and without signatures.
2024-05-03 09:16:35 +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
a36c7d5aa9
Random improvements to samples/native-stack-overflow (#3353) 2024-04-25 11:22:08 +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
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
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
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
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
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
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
Enrico Loparco
0e4c4799b1
Get location info from function indexes in addr2line script (#3206)
Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script 

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).
2024-03-08 10:20:04 +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
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
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
Bruce Mitchener
61fe78c9ff
Fix download link for wasi-sdk (#3077)
The wasi-sdk repo moved from CraneStation to the WebAssembly org
on GitHub.
2024-01-24 13:42:45 +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
YAMAMOTO Takashi
fde98331ff
examples/terminate: Use wasm_runtime_spawn_exec_env as well (#3049) 2024-01-18 20:44:09 +08:00
YAMAMOTO Takashi
b97370e3a8
samples/terminate: Add a sample to demonstrate wasm_runtime_terminate (#3043)
This is basically a modified copy of the "shared-module" example.
2024-01-18 15:01:03 +08:00
Enrico Loparco
25ccc9f2d5
Avoid unused thread_id warning and recompile multi-module sample (#3033)
- Unused variable warning (when building in release mode):
```bash
wasm-micro-runtime/samples/wasi-threads/wasm-apps/no_pthread.c:44:9:
warning: variable 'thread_id' set but not used [-Wunused-but-set-variable]
    int thread_id;
```
- When using the multi-module example and changing the files in `wasm-apps`,
  they don't get recompiled when the sample is rebuilt. Adding `BUILD_ALWAYS`
  as it's done in other samples.
2024-01-17 08:06:02 +08:00
Enrico Loparco
c9fd44e8b8
Build samples in debug mode (#3019)
Follow-up on #3008. Compiling samples in Debug mode allows us to
take advantage of asserts and would have prevented the fix in #3008.
2024-01-16 09:36: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
Haoxuan Xu
ef5e74fd8a
fix(sgx-ra): Fix building when enclave is built without librats ahead (#2968)
This PR addresses the issue with building the sgx-ra sample when the enclave under
the path product-mini/platforms/linux-sgx/enclave-sample is built beforehand.

When the enclave is built without librats ahead, an error occurs as the following
without the changes:
```bash
...
CP libvmlib.a  <=  /home/haoxuan/wasm-micro-runtime/samples/sgx-ra/build/libvmlib.a
/usr/local/bin/ld: libvmlib.a(lib_rats_wrapper.c.o): in function `librats_collect_wrapper':
lib_rats_wrapper.c:(.text.librats_collect_wrapper+0x4a): undefined reference to `wasm_runtime_get_module_hash'
collect2: error: ld returned 1 exit status
```
2024-01-02 16:32:16 +08:00
YAMAMOTO Takashi
1dbae404b4
samples/spawn-thread: Tweak to expose a bug (#2888)
this would expose the deadlock bug, which has been fixed by
https://github.com/bytecodealliance/wasm-micro-runtime/pull/2882
2023-12-08 18:35:40 +08:00
YAMAMOTO Takashi
9c3581c179
samples/spawn-thread: Disable libc and pthread (#2883)
because this sample doesn't really require them.
2023-12-08 18:12:37 +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
Wenyong Huang
f42ffe1d9d
Fix sample basic intToStr was called with wrong length (#2876)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2874.
2023-12-07 10:26:28 +08:00
Enrico Loparco
873558c40e
Get rid of compilation warnings and minor doc fix (#2839) 2023-11-30 08:49:58 +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
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
Wenyong Huang
20f1a8c86c Merge branch main into dev/wasi-libc-windows 2023-11-09 10:13:59 +08:00
Wenyong Huang
3570a94a08
Fix issues reported by Coverity (#2681)
Fix multi-module issues and gui sample issues reported by Coverity.
And refine the build script of go language-binding sample.
2023-10-31 10:48:51 +08:00
zoraaver
5fd530610a
Enable MASM automatically in runtime_lib.cmake (#2634)
MASM (Microsoft Macro Assembler) needs to be enabled to successfully
compile .asm files on Windows. Without enabling this language
automatically in runtime_lib.cmake, Windows cmake projects using WAMR
get hard-to-diagnose linker errors about missing symbols as the assembly
file is not compiled at all.
2023-10-12 20:42:25 +08:00
dongsheng28849455
79b27c1934
Support muti-module for AOT mode (#2482)
Support muti-module for AOT mode, currently only implement the
multi-module's function import feature for AOT, the memory/table/
global import are not implemented yet.

And update wamr-test-suites scripts, multi-module sample and some
CIs accordingly.
2023-09-28 08:56:11 +08:00
YAMAMOTO Takashi
b622622096
samples/inst-context-threads: Add a brief explanation (#2592) 2023-09-26 10:00:33 +08:00
YAMAMOTO Takashi
6c846acc59
Implement module instance context APIs (#2436)
Introduce module instance context APIs which can set one or more contexts created
by the embedder for a wasm module instance:
```C
    wasm_runtime_create_context_key
    wasm_runtime_destroy_context_key
    wasm_runtime_set_context
    wasm_runtime_set_context_spread
    wasm_runtime_get_context
```

And make libc-wasi use it and set wasi context as the first context bound to the wasm
module instance.

Also add samples.

Refer to https://github.com/bytecodealliance/wasm-micro-runtime/issues/2460.
2023-09-07 14:54:11 +08:00
Marcin Kolny
53d7027de0
Implement strict validation of thread IDs according to the specification (#2521) 2023-08-31 20:23:54 +08:00
liang.he
f0632edc37
Clone the input binary during wasm_module_validate (#2483) 2023-08-21 19:43:28 +08:00
Jämes Ménétrey
365cdfeb71
Upgrade SGX-RA integration for 0.1.2 and Ubuntu 20.04 (#2454) 2023-08-15 10:12:43 +08:00
Wenyong Huang
923e8d6471
Fix windows link error and clear windows warnings (#2463)
- Fix windows wamrc link error: aot_generate_tempfile_name undefined.
- Clear windows compile warnings.
- And rename folder `samples/bh_atomic` and `samples/mem_allocator` to
  `samples/bh-atomic` and `samples/mem-allocator`.
2023-08-14 19:04:49 +08:00
YAMAMOTO Takashi
a550f4d9f7
iwasm: call native lib init/deinit if exists (#2439) 2023-08-10 09:26:52 +08:00
Wenyong Huang
43a3cbf2ce
Build more benchmarks in workload XNNPACK (#2417)
Build 3 more benchmarks in workload XNNPACK and fix a typo.
2023-08-03 08:39:22 +08:00