Commit Graph

183 Commits

Author SHA1 Message Date
Wenyong Huang
5a7fbda7ac
Enable to collect code coverage of samples/simple (#2003) 2023-03-07 08:45:03 +08:00
Wenyong Huang
1be202fad8
Fix several issues found (#1996)
- CMakeLists.txt: add lib_export.h to install list
- Fast JIT: enlarge spill cache size to enable several standalone cases
                when hw bound check is disabled
- Thread manager: wasm_cluster_exit_thread may destroy an invalid
               exec_env->module_inst when exec_env was destroyed before
- samples/socket-api: fix failure to run timeout_client.wasm
- enhance CI build wasi-libc and sample/wasm-c-api-imports CMakeLlist.txt
2023-03-03 15:00:54 +08:00
Wenyong Huang
9b9ae0cfac
Update cmake files and wamr-test-suites to support collect code coverage (#1992)
Support collecting code coverage with wamr-test-suites script by using
lcov and genhtml tools, eg.:
  cd tests/wamr-test-suites
  ./test_wamr.sh -s spec -b -P -C

The default code coverage and html files are generated at:
  tests/wamr-test-suites/workspace/wamr.lcov
  tests/wamr-test-suites/workspace/wamr-lcov.zip

And update wamr-test-suites scripts to support testing GC spec cases to
avoid frequent synchronization conflicts between branch main and dev/gc.
2023-02-28 17:38:18 +08:00
Wenyong Huang
38c67b3f48
thread-mgr: Fix spread "wasi proc exit" exception and atomic.wait issues (#1988)
Raising "wasi proc exit" exception, spreading it to other threads and then
clearing it in all threads may result in unexpected behavior: the sub thread
may end first, handle the "wasi proc exit" exception and clear exceptions
of other threads, including the main thread. And when main thread's
exception is cleared, it may continue to run and throw "unreachable"
exception. This also leads to some assertion failed.

Ignore exception spreading for "wasi proc exit" and don't clear exception
of other threads to resolve the issue.

And add suspend flag check after atomic wait since the atomic wait may
be notified by other thread when exception occurs.
2023-02-24 20:05:39 +08:00
YAMAMOTO Takashi
37b09d0f24
Expose wasm_runtime_call_indirect (#1969)
The function has been there for long. While what it does look a bit unsafe
as it calls a function which may be not wasm-wise exported explicitly, it's
useful and widely used when implementing callback-taking APIs, including
our pthread_create's implementation.
2023-02-20 18:56:55 +08:00
Wenyong Huang
e170c355a2 Merge branch main into dev/wasi_threads 2023-02-17 08:46:12 +08:00
Enrico Loparco
216dc43ab4
Use shared memory lock for threads generated from same module (#1960)
Multiple threads generated from the same module should use the same
lock to protect the atomic operations.

Before this PR, each thread used a different lock to protect atomic
operations (e.g. atomic add), making the lock ineffective.

Fix #1958.
2023-02-16 11:54:19 +08:00
liang.he
3698f2279b
Improve wasm-c-api instantiation-time linking (#1902)
Add APIs to help prepare the imports for the wasm-c-api `wasm_instance_new`:
- wasm_importtype_is_linked
- wasm_runtime_is_import_func_linked
- wasm_runtime_is_import_global_linked
- wasm_extern_new_empty

For wasm-c-api, developer may use `wasm_module_imports` to get the import
types info, check whether an import func/global is linked with the above API,
and ignore the linking of an import func/global with `wasm_extern_new_empty`.

Sample `wasm-c-api-import` is added and document is updated.
2023-02-13 15:06:04 +08:00
Wenyong Huang
27e7e160af
Upgrade toolkits (#1878)
Upgrade the version of related toolkits:
- upgrade llvm to 15.0
- upgrade wasi-sdk to 19.0
- upgrade emsdk to 3.1.28
- upgrade wabt to 1.0.31
- upgrade binaryen to 111

And upgrade the CI scripts, sample workload build scripts, Dockerfiles, and documents.
2023-02-02 09:42:25 +08:00
Jämes Ménétrey
0435acdd43
SGX IPFS: Fix a segfault and support seeking beyond the end of files while using SEEK_CUR/SEEK_END (#1916)
The current implementation throws a segmentation fault when padding
files using a large range, because the writing operation overflows the
source buffer, which was a single char.

IPFS previously assumed that the offset for the seek operation was related
to the start of the file (SEEK_SET). It now correctly checks the parameter
'whence' and computes the offset for SEEK_CUR (middle of the file) and
SEEK_END (end of the file).
2023-01-30 08:24:12 +08:00
Enrico Loparco
2eed50b303
Document how to use WASI threads in AOT mode (#1905)
Describe how to use WASI threads in AOT mode, following the discussion below:
  https://github.com/bytecodealliance/wasm-micro-runtime/pull/1867#discussion_r1070268062

Make aux stack boundary checks of wasi-threads always successful by setting
`exec_env->aux_stack_bottom` to UINT32_MAX and `exec_env->aux_stack_boundary` to 0
2023-01-27 18:32:33 +08:00
YAMAMOTO Takashi
42f8fed20e
Rename thread_spawn import (#1907)
Following the wit-defined ABI:
https://github.com/WebAssembly/wasi-threads/pull/26

cf. https://github.com/WebAssembly/wasi-libc/pull/387
2023-01-27 06:45:34 +08:00
Marcin Kolny
879563047f
Fix thread termination example (#1915)
The example wasn't fully implemented the intention - it didn't work as
expected when the trap/proc_exit was executed on the main thread,
because main thread never waited for all the threads to start.
2023-01-25 09:34:36 +08:00
Enrico Loparco
9cf55f953b
feat(wasi-threads): Change sample exception_propagation to thread_termination (#1869)
Trigger wasi_proc_exit in the sample
2023-01-23 10:36:58 +08:00
Wenyong Huang
c7141894fb Merge branch main into dev/wasi_threads 2023-01-21 13:18:55 +08:00
Xu Jun
cadf9d0ad3
Main thread spread exception when thread-mgr is enabled (#1889)
And refactor clear_wasi_proc_exit_exception, refer to
https://github.com/bytecodealliance/wasm-micro-runtime/pull/1869
2023-01-20 08:54:27 +08:00
Marcin Kolny
903f5212f1
Increase stack size in the example app (#1880) 2023-01-11 09:40:32 +08:00
Qiang
4cd88a96d5
Add more types and APIs for attr_container (#1841)
Add more types for attr_container, e.g. uint8, uint32, uint64
Add more APIs for attr_container for int8, int16 and int32 types
Rename fields of the union 'jvalue' and refactor some files that use attr_container
2023-01-09 21:05:30 +08:00
Marcin Kolny
0e2382a959
Disable aux stack allocations for threads spawned by wasi_thread_start (#1867)
This syscall doesn't need allocating stack or TLS and it's expected from the application
to do that instead. E.g. WASI-libc already does this for `pthread_create`.

Also fix some of the examples to allocate memory for stack and not use stack before
the stack pointer is set to a correct value.
2023-01-09 20:36:34 +08:00
Wenyong Huang
3403f0a7f4 Merge main into dev/wasi_threads 2023-01-03 18:15:23 +08:00
liang.he
bf2be805f9
Add more checks about the imports of wasm_instance_new (#1843)
Check whether the `imports` argument is NULL in wasm_instance_new and check
the import count of each kind.

Fix issue reported by https://github.com/bytecodealliance/wasm-micro-runtime/issues/1833
2023-01-03 17:16:49 +08:00
Enrico Loparco
7d19b229eb
feat(wasi-threads): Add CI for WASI threads (#1819)
Update wasi-sdk from 12.0 to 16.0 in CI
Build wasi-libc and build wai-threads sample in CI
2022-12-22 18:02:23 +08:00
liang.he
b826a84cd6 Use boringssl instead of openssl to implement wasm cache loading (#1804) 2022-12-20 14:37:07 +08:00
Enrico Loparco
8fc641377a
feat(wasi-threads): Add example of exception propagation (#1812) 2022-12-16 14:22:53 +08:00
Marcin Kolny
929d5942b9
Add implementation for wasi_thread_spawn() (#1786)
For now this implementation uses thread manager.

Not sure whether thread manager is needed in that case. In the future there'll be likely another syscall added (for pthread_exit) and for that we might need some kind of thread management - with that in mind, we keep thread manager for now and will refactor this later if needed.
2022-12-13 21:33:27 +08:00
liang.he
294a625fe5
Use boringssl instead of openssl to implement wasm cache loading (#1804) 2022-12-13 14:23:37 +08:00
Marcin Kolny
684ae6554d
Create a placeholder for WASI threads implementation (#1783)
This a simpler version of the PR: https://github.com/bytecodealliance/wasm-micro-runtime/pull/1638
2022-12-06 21:11:27 +08:00
liang.he
f6d67c1cda
Enable wasm cache loading in wasm-c-api (#1759)
Use sha256 to hash binary file content. If the incoming wasm binary is
cached before, wasm_module_new() simply returns the existed one.

Use -DWAMR_BUILD_WASM_CACHE=0/1 to control the feature.
OpenSSL 1.1.1 is required if the feature is enabled.
2022-12-05 12:25:26 +08:00
liang.he
fc8f70cfa4
Fix issues detected by Coverity (#1776)
- wasm_func_call always return trap if failed
- in Debug, always run LEAK_TEST in samples/wasm-c-api
2022-12-01 22:03:09 +08:00
Wenyong Huang
1652f22a77
Fix issues reported by Coverity (#1775)
Fix some issues reported by Coverity and fix windows exception
check with guard page issue
2022-12-01 19:24:13 +08:00
Wenyong Huang
29b76dd275
Create module hash for each module in SGX lib-rats (#1745)
Current SGX lib-rats wasm module hash is stored in a global buffer,
which may be overwritten if there are multiple wasm module loadings.
We move the module hash into the enclave module to resolve the issue.

And rename the SGX_IPFS macro/variable in Makefile and Enclave.edl to
make the code more consistent.

And refine the sgx-ra sample document.
2022-11-24 21:48:50 +08:00
Zeuson
656a8427e6
linux-sgx: Improve the remote attestation (#1695)
The current implementation of remote attestation does not take into
account the integrity of the wasm module. The SHA256 of the wasm
module has been put into user_data to generate the quote, and more
parameters are exposed for further verification.
2022-11-22 14:45:03 +08:00
Wenyong Huang
375a2c9a49
Fix sample ref-types/wasm-c-api build error with wat2wasm low version (#1702)
Fix build error in sample ref-types and wasm-c-api caused by the
version of wat2wasm: refine makefile to auto detect the wat2wasm
version and add the compile flag accordingly.
2022-11-15 13:51:03 +08:00
liang.he
30ee992762
Add wasm_module_obtain() to clone wasm_module_t (#1660)
Also add support for wasm_shared_module_t, and add lock for
wasm_module_t related operations.

And add wasm-c-api sample threads, update sample clone.
2022-11-09 12:50:58 +08:00
Jämes Ménétrey
328fd59f43
linux-sgx: Allow to open files with arbitrary paths in the sandbox using IPFS (#1685)
A limitation of the current implementation of SGX IPFS in WAMR is that
it prevents to open files which are not in the current directory.
This restriction is lifted and can now open files in paths, similarly to the
WASI openat call, which takes into account the sandbox of the file system.
2022-11-07 19:56:16 +08:00
Jämes Ménétrey
aba267afc7
linux-sgx: Improve the documentation of SGX-RA sample (#1679)
Improve the documentation for setting up SGX-RA using WAMR, based on
the feedback in #1670.

This notably highlights the dependency on Intel PCS and PCCS and how to
install/configure them.
2022-11-04 14:14:18 +08:00
YAMAMOTO Takashi
825544ddab
samples/native-lib: use the same shared lib name as product-mini (#1669)
Use the shared lib name `libiwasm` instead of static lib name `vmlib`
2022-11-01 21:55:43 +08:00
liang.he
a1f7832625
Remove an improper assumption when creating wasm_trap (#1657)
Allow to have multiple stores in an engine and multiple instances
in a store. Letting a wasm_function_t pass its wasm_store_t to make
it more efficient.
2022-11-01 11:56:28 +08:00
YAMAMOTO Takashi
960b613d10
samples/native-lib: Add an example to use wamr API from native lib (#1649)
Real world native libs likely need to access the wasm_runtime_xxx API.
This example demonstrates it.

Build vmlib as a shared lib to make it straightforward to share a
single runtime instance between iwasm and native libs.
2022-10-28 19:31:21 +08:00
Wenyong Huang
84161fe084
Add CIs to release new version and publish binary files (#1648)
Add CIs to enable the release process of a new version of WAMR,
and build and publish the binary files when a version is released,
including iwasm, wamrc, lldb, vscode-extension and wamr-ide for
Ubuntu-20.04, Ubuntu-22.04 and MacOS.

And refine the CIs to test spec cases.
2022-10-28 13:55:41 +08:00
YAMAMOTO Takashi
bc58778c34
samples/native-lib: Add a bit more complicated example (#1643)
Add test_hello sample and update the document
2022-10-27 15:06:14 +08:00
Jämes Ménétrey
264fdfafed
linux-sgx: Use non-destructive modes for opening files using SGX IPFS (#1645)
Refer to https://github.com/bytecodealliance/wasm-micro-runtime/pull/1645
2022-10-27 12:21:30 +08:00
Wenyong Huang
ef21f0c951
Implement Fast JIT dump call stack and perf profiling (#1633)
Implement dump call stack and perf profiling features for Fast JIT,
and refine some code.
2022-10-27 09:28:32 +08:00
YAMAMOTO Takashi
654ac5feca
Use cmake POSITION_INDEPENDENT_CODE instead of hardcoding -pie -fPIE (#1598)
This fixes unused option warnings on -pie for macOS.
(On macOS cmake produces "-fPIE -Xlinker -pie")

Bump required cmake version to 3.14 for CheckPIESupported.

References:
https://cmake.org/cmake/help/latest/prop_tgt/POSITION_INDEPENDENT_CODE.html
https://cmake.org/cmake/help/latest/module/CheckPIESupported.html#module:CheckPIESupported
2022-10-19 01:51:18 +08:00
Wenyong Huang
a182926a73
Refactor interpreter/AOT module instance layout (#1559)
Refactor the layout of interpreter and AOT module instance:
- Unify the interp/AOT module instance, use the same WASMModuleInstance/
  WASMMemoryInstance/WASMTableInstance data structures for both interpreter
  and AOT
- Make the offset of most fields the same in module instance for both interpreter
  and AOT, append memory instance structure, global data and table instances to
  the end of module instance for interpreter mode (like AOT mode)
- For extra fields in WASM module instance, use WASMModuleInstanceExtra to
  create a field `e` for interpreter
- Change the LLVM JIT module instance creating process, LLVM JIT uses the WASM
  module and module instance same as interpreter/Fast-JIT mode. So that Fast JIT
  and LLVM JIT can access the same data structures, and make it possible to
  implement the Multi-tier JIT (tier-up from Fast JIT to LLVM JIT) in the future
- Unify some APIs: merge some APIs for module instance and memory instance's
  related operations (only implement one copy)

Note that the AOT ABI is same, the AOT file format, AOT relocation types, how AOT
code accesses the AOT module instance and so on are kept unchanged.

Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/1384
2022-10-18 10:59:28 +08:00
Wenyong Huang
ace05b182d
Fix possible non null-terminated string issue in socket sample (#1612) 2022-10-17 22:45:10 +08:00
YAMAMOTO Takashi
9ba8c80850
samples/multi-module: Examine module registration a bit (#1595) 2022-10-14 16:37:57 +08:00
YAMAMOTO Takashi
1e22d1a9e5
Fix the "register native with iwasm" stuff for macOS (#1558)
- core/shared/platform/darwin/platform_internal.h: macOS has dlopen
- samples/native-lib/README.md: Mention macOS
2022-10-07 15:17:36 +08:00
Callum Macmillan
5ddc335a7f
Add timeout send/recv and multicast client/server socket examples (#1519)
Add a couple of socket examples that can be used with WAMR:
- The `timeout_client` and `timeout_server` examples demonstrate socket
  send and receive timeouts using the socket options
- The `multicast_client` and `multicast_server` examples demonstrate receiving
  multicast packets in WASM

And add several macro controls for `socket_opts` example.
2022-10-07 10:31:21 +08:00
YAMAMOTO Takashi
3094b20bd8
samples/native-lib: Fix exec_env type (#1557)
Change `wasm_exec_env_t *exec_env` to `wasm_exec_env_t exec_env`
2022-10-06 20:21:21 +08:00