Commit Graph

745 Commits

Author SHA1 Message Date
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
e516de8ec7
Fix possible data race in thread manager (#1973)
Destroy child thread's exec_env before destroying its module instance and
add the process into cluster's lock to avoid possible data race: if exec_env
is removed from custer's exec_env_list and destroyed later, the main thread
may not wait it and start to destroy the wasm runtime, and the destroying
of the sub thread's exec_env may free or overread/written an destroyed or
re-initialized resource.

And fix an issue in wasm_cluster_cancel_thread.
2023-02-20 17:11:21 +08:00
Wenyong Huang
739acfc908
Merge pull request #1966 from bytecodealliance/dev/wasi_threads
Merge wasi_threads to main
2023-02-17 17:42:47 +08:00
Wenyong Huang
ef3a683392
Don't call start/initialize in child thread's instantiation (#1967)
The start/initialize functions of wasi module are to do some initialization work
during instantiation, which should be only called one time in the instantiation
of main instance. For example, they may initialize the data in linear memory,
if the data is changed later by the main instance, and re-initialized again by
the child instance, unexpected behaviors may occur.

And clear a shadow warning in classic interpreter.
2023-02-17 15:11:05 +08:00
Wenyong Huang
e170c355a2 Merge branch main into dev/wasi_threads 2023-02-17 08:46:12 +08:00
Hritik Gupta
50650e4634
Modify poll_oneoff in libc-wasi to make it interruptible (#1951) 2023-02-16 21:03:33 +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
Charles Liu
1c17665f68
Fix libc-wasi build failure when using clang (#1950)
Resolves #1949
2023-02-14 18:28:00 +08:00
Xu Jun
531771eb11
Don't terminate other threads when create thread failed (#1955) 2023-02-13 16:23:24 +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
ocfox
427abf02c8
Fix potential integer overflow issue in wasm-c-api (#1954)
Fix potential integer overflow issue in wasm-c-api reported by CodeQL
2023-02-13 13:55:50 +08:00
Patrick Cook
89c11c5361
Fix explicit casts and types in espidf_socket.c (#1945)
In the esp-idf platform, Xtensa GCC 8.4.0 reported incompatible pointer warnings when
building with the lwip component.

Berkeley (POSIX) sockets uses composition in combination with type punning to handle
many protocol families, including IPv4 & IPv6. The type punning just has to be made
explicit with pointer casts from `sockaddr_in` for IPv4 to the generic `sockaddr`.
2023-02-09 09:34:26 +08:00
Hritik Gupta
f3c1ad4864
Fix terminating stale threads on trap/proc_exit (#1929)
This is to terminate suspended threads in case an atomic wait occurs with
a huge or indefinite (-1) timeout, followed by a proc exit or trap.
2023-02-07 20:56:23 +08:00
Marcin Kolny
e2c754f0a6
Fix data race when terminating or waiting for a thread (#1924)
There is a possibility that while iterating through a list of threads, the threads
finish by themselves, making a list of exec_env invalid.
2023-02-06 19:08:45 +08:00
Enrico Loparco
42ced88424
Fix stack alignment issue on ia32 (#1934)
The stack of Unix-like (GCC) system should be aligned on 16-byte boundary
according to the x86-32 ABI specification.
2023-02-06 09:07:00 +08:00
Wenyong Huang
c3e9b66b2a
Fix jit memory overwritten after instance deinstantiate (#1936)
When de-instantiating the wasm module instance, remove it from the module's
instance list before freeing func_ptrs and fast_jit_func_ptrs of the instance, to avoid
accessing these freed memory in the JIT backend compilation threads.
2023-02-03 11:15:03 +08:00
Marcin Kolny
17f3375d53
Enable gcc-4.8 compilation (#1928) 2023-02-02 19:34:20 +08:00
Wenyong Huang
40a14b51c5
Enable running mode control for runtime and module instance (#1923)
Enable setting running mode when executing a wasm bytecode file
- Four running modes are supported: interpreter, fast-jit, llvm-jit and multi-tier-jit
- Add APIs to set/get the default running mode of the runtime
- Add APIs to set/get the running mode of a wasm module instance
- Add running mode options for iwasm command line tool

And add size/opt level options for LLVM JIT
2023-02-02 18:16:01 +08:00
Wenyong Huang
7bb78dc260
Remove fast jit macro in enum WASMExceptionID (#1933)
The definitions `enum WASMExceptionID` in the compilation of wamrc and the compilation
of Fast JIT are different, since the latter enables the Fast JIT macro while the former doesn't.
This causes that the exception ID in AOT file generated by wamrc may be different from
iwasm binary compiled with Fast JIT enabled, and may result in unexpected behavior.
Remove the macro control to resolve it.
2023-02-02 15:23:44 +08:00
Wenyong Huang
edee2eb956
Loosen the wasi abi compatibility check in loader (#1932)
Change an error to warning when checking wasi abi compatibility in loader, for rust case below:
#[no_mangle]
pub extern "C" fn main() {
    println!("foo");
}
compile it with `cargo build --target wasm32-wasi`, a wasm file is generated with wasi apis imported
and a "void main(void)" function exported.

Other runtime e.g. wasmtime allows to load it and execute the main function with `--invoke` option.
2023-02-02 13:06:30 +08:00
tonibofarull
1614ce12fa
wasi-nn: Enable GPU support (#1922)
- Split logic in several dockers
  - runtime: wasi-nn-cpu and wasi-nn- Nvidia-gpu.
  - compilation: wasi-nn-compile. Prepare the testing wasm and generates the TFLites.
- Implement GPU support for TFLite with Opencl.
2023-02-02 08:09:46 +08:00
HongxiaWangSSSS
fe3347d5d2
Fixed the undef error about WAMR_BUILD_MEMORY_PROFILING (#1926) 2023-02-01 17:52:46 +08:00
YAMAMOTO Takashi
7d3b2a8773
Make memory profiling show native stack usage (#1917) 2023-02-01 11:52:15 +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
Huang Qi
58316635d4
ci: Enable libc-wasi compilation test on NuttX (#1918) 2023-01-28 12:39:14 +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
tonibofarull
9eed6686df
Refactor WASI-NN to simplify the support for multiple frameworks (#1834)
- Reorganize the library structure
- Use the latest version of `wasi-nn` wit (Oct 25, 2022):
    0f77c48ec1/wasi-nn.wit.md
- Split logic that converts WASM structs to native structs in a separate file
- Simplify addition of new frameworks
2023-01-25 18:32:40 +08:00
Enrico Loparco
b0b8843719
Implement opcode atomic.wait and atomic.notify for Fast JIT (#1914) 2023-01-25 09:53:40 +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
Huang Qi
cb7ac8fee3
nuttx: Mock socket APIs if NET is disabled (#1896) 2023-01-18 09:16:13 +08:00
Huang Qi
a1786428e6
nuttx: Remove fdopendir (#1895)
The newer version of nuttx has implemented fdopendir, and the compiler
reports multiple definitions of it.
2023-01-17 11:16:01 +08:00
Xu Jun
e696ac36d7
Fix potential block issue in source debugger (#1887)
Fix issue reported in #1860
2023-01-17 08:45:29 +08:00
YAMAMOTO Takashi
5f0f8fe7ee
Relax wasi memory export check when wasi-threads is enabled (#1893)
https://github.com/WebAssembly/wasi-threads/issues/22
https://github.com/WebAssembly/WASI/issues/502
2023-01-16 20:21:51 +08:00
Martin Klang
622cdbefd6
Prevent undefined behavior from c_api_func_imports == NULL (#1883)
The module instance's c_api_func_imports may be NULL under some circumstances,
add checks before accessing it.
2023-01-14 07:52:39 +08:00
Huang Qi
f818f4c43f
Simplify fcmp intrinsic logic for AOT/XIP (#1881) 2023-01-12 12:05:53 +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
Marcin Kolny
2615646c20
Fix on-heap aux stack allocation (#1865)
Because stack grows from high address towards low address, the value
returned by malloc is the end of the stack, not top of the stack. The top
of the stack is the end of the allocated space (i.e. address returned by
malloc + cluster size).

Refer to #1790.
2023-01-06 18:21:28 +08:00
Wenyong Huang
1f4580fbd8
Enable CI wasi test suite for x86-32 classic/fast interpreter (#1866)
The original CI didn't actually run wasi test suite for x86-32 since the `TEST_ON_X86_32=true`
isn't written into $GITHUB_ENV.

And refine the error output when failed to link import global.
2023-01-06 17:31:39 +08:00
liang.he
7401718311
Report error in instantiation when meeting unlinked import globals (#1859) 2023-01-06 15:24:11 +08:00
Wenyong Huang
0c4402293d
Refine Windows thread waiting list operations (#1853)
Add thread_wait_list_end node for thread data and cond for Windows platform
to speedup the thread join and cond wait operations: no need to traverse the
wait list to get the end node to append the wait node.
2023-01-06 14:51:07 +08:00
Enrico Loparco
4e5529f21f
Reserve TID values for WASI threads (#1862)
According to the [WASI thread specification](https://github.com/WebAssembly/wasi-threads/pull/16),
some thread identifiers are reserved and should not be used. In fact, only IDs between `1` and
`0x1FFFFFFF` are valid.

The thread ID allocator has been moved to a separate class to avoid polluting the
`lib_wasi_threads_wrapper` logic.
2023-01-06 10:28:25 +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
Huang Qi
d5aa354d41
Return result directly if float cmp is called in AOT XIP (#1851) 2022-12-30 16:45:39 +08:00
Huang Qi
d309091706
Register missing symbols for f32 to 64 bit integer conversion (#1850) 2022-12-30 15:21:25 +08:00
Wenyong Huang
0090d3e3fc
Fix issue of resolving func name in custom name section (#1849)
Should use import_function_count but not import_count to calculate
the func_index in handle_name_section when custom name section
feature is enabled.

And clear the compile warnings of mini loader.
2022-12-30 14:37:04 +08:00
Huang Qi
d1fe589d43
Fix fmin/fmax in AOT XIP intrinsics (#1848) 2022-12-29 18:48:55 +08:00