Commit Graph

1146 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
8db6f5978b
aot_emit_aot_file.c: Convert switch lookup table relocation (#1149)
Fix the symbol resolving failure with recent version of wamrc:
```
AOT module load failed: resolve symbol .Lswitch.table.aot _func#82.2 failed
```
Replace the relocations for such symbols with .rodata section.
2022-05-07 08:41:53 +08:00
YAMAMOTO Takashi
6fb402aeec
wasm_export.h: Add a few comments about heap and threads (#1147) 2022-05-06 18:30:48 +08:00
YAMAMOTO Takashi
03f2153270
wasm_runtime_common.c: add assertion for BH_MALLOC/BH_FREE (#1139)
Add assertion for BH_MALLOC/BH_FREE in wasm_runtime_common.c,
when building runtime, the BH_MALLOC/BH_FREE macros should be
defined as wasm_runtime_malloc/wasm_runtime_free.
2022-05-06 13:47:56 +08:00
Xu Jun
16cfd4764d
Fix atomic wait not thread safe issue (#1146)
Add lock for acquire_wait_info and release_wait_info, and
remove release_wait_info in wasm_runtime_atomic_notify.
2022-05-06 12:52:17 +08:00
Wenyong Huang
07829b90d7
Fix allocate zero size memory warning (#1143)
Fix allocate zero size memory warning reported by wasm_runtime_malloc
when allocating the import fun pointers if the import func count is 0:
    `warning: wasm_runtime_malloc with size zero`
2022-05-05 12:43:00 +08:00
Wenyong Huang
749f2f1f34
Fix wamrc build error with llvm-14 (#1140)
Fix aot compiler compilation errors when the llvm version is 14.0,
and clear one compilation warning of thread_manager.c.
2022-05-03 09:12:03 +08:00
Wenyong Huang
c6997aa68a
Fix execute_main not wait for other threads (#1137)
Fix wasm_application_execute_main/wasm_application_execute_func not waiting for
other threads to terminate in multi-thread mode, which causes that the exception
thrown by other threads may haven't been spreaded to current main thread, and
cannot be detected by the caller, as reported in #1131.
2022-04-29 15:47:43 +08:00
YAMAMOTO Takashi
2e27d506d8
posix os_socket_inet_network: Use inet_addr instead of inet_network (#1133) 2022-04-28 13:53:01 +08:00
YAMAMOTO Takashi
d9d0777051
Move dlfcn.h availability check to platform_common.h (#1134) 2022-04-28 12:31:28 +08:00
YAMAMOTO Takashi
814a76ee89
product-mini/platforms/nuttx/wamr.mk: Provide BH_MALLOC/BH_FREE (#1135) 2022-04-28 12:03:29 +08:00
Xu Jun
98431225f2
Store import function pointer in module instance (#1130)
Fix the issue reported by #1118 , use this approach since it avoids copying
unnecessary static information into instance and reduces the footprint.
2022-04-27 20:21:51 +08:00
YAMAMOTO Takashi
f8b4ca2a70
sandboxed-system-primitives: Remove unused file signals.h (#1132) 2022-04-27 18:59:09 +08:00
YAMAMOTO Takashi
e1934f2478
sandboxed-system-primitives: Use d_ino=0 for NuttX (#1128)
NuttX doesn't have d_ino.
2022-04-27 17:49:06 +08:00
YAMAMOTO Takashi
5343411623
libc-wasi/sandboxed-system-primitives: Convert signals only when available (#1125)
Many of these signal constants are not available on NuttX.

Maybe we can remove these signal stuff sooner or later:
    https://github.com/WebAssembly/WASI/issues/7
    https://github.com/WebAssembly/wasi-libc/pull/278
2022-04-27 16:22:43 +08:00
YAMAMOTO Takashi
2fe83e29cd
sandboxed-system-primitives: make CPT/TCT clock ids optional (#1126)
NuttX doesn't have them.
2022-04-27 14:24:02 +08:00
liang.he
d7097fbce8
Add more checks for wasm-c-api interfaces (#1121)
Protect c-api from unlinked runtime objects
Fix a potential memory leak
Remove unused `imports` in `wasm_instance_t`
2022-04-27 13:28:27 +08:00
Wenyong Huang
2007ba38cf
Enable register native with iwasm (#1120)
Enable register native with iwasm application, add sample and update document.
2022-04-27 11:12:50 +08:00
Wenyong Huang
9013a474bc
Fix ref-types sample invalid externref signature (#1119)
Fix ref-types sample running error due to using invalid externref signatures
2022-04-25 12:59:37 +08:00
Xu Jun
5ab368dd00
Support va_args in libc-builtin (#1117)
Implement vprintf/sprintf/snprintf wrapper functions for libc-builtin.
2022-04-24 10:39:18 +08:00
Wenyong Huang
9b858c43cb
Fix build wamrc for xtensa failure (#1109)
Fix build wamrc failure when using llvm xtensa version, and update
xtensa llvm version to 13.0.0.
2022-04-23 20:25:40 +08:00
Wenyong Huang
adaaf348ed
Refine opcode br_table for classic interpreter (#1112)
Refine opcode br_table for classic interpreter as there may be a lot of
leb128 decoding when the br count is big:
1. Use the bytecode itself to store the decoded leb br depths if each
    decoded depth can be stored with one byte
2. Create br_table cache to store the decode leb br depths if the decoded
    depth cannot be stored with one byte
After the optimization, the class interpreter can access the br depths array
with index, no need to decode the leb128 again.

And fix function record_fast_op() return value unchecked issue in source
debugging feature.
2022-04-23 19:15:55 +08:00
YoungWenMing
5f8d1428d5
wasm_runtime.c: Fix fault modification on data segment (#1116)
Fix fault modification on data segment in wasm module which leads to
fail to instantiate wasm module next time, reported by #1115.

Co-authored-by: yangwenming <yangwenming@bytedance.com>
2022-04-23 17:38:11 +08:00
YAMAMOTO Takashi
91222e1e44
interpreter: Fix an UBSan complaint in word_copy (#1106)
Fix an UBSan complaint introduced by recent change by adding more checks
to word_copy:
```
wasm_interp_fast.c:792:9: runtime error: applying zero offset to null pointer
```
2022-04-21 12:21:37 +08:00
YAMAMOTO Takashi
67d6a2886e
core/iwasm/aot/aot_loader.c: Fix a zero-sized malloc warning (#1108)
Fix the following warning when loading an aot file without relocations:
```
[20:19:00:528 - 1119F1600]: warning: wasm_runtime_malloc with size zero
```
2022-04-20 18:27:13 +08:00
YAMAMOTO Takashi
a85f982297
wamr-compiler: Fix ubsan on macOS (#1105)
Supported on ubuntu as well
2022-04-20 16:59:13 +08:00
Wenyong Huang
d6e781af28
Add more operand stack overflow checks for fast-interp (#1104)
And clear some compile warnings on Windows
2022-04-20 16:19:12 +08:00
YAMAMOTO Takashi
0f505aafd9
aot_runtime.c: Add static assertions for some offset assumptions (#1103) 2022-04-20 13:58:02 +08:00
YAMAMOTO Takashi
b36931a589
aot_loader.c: Fix issues in "Refine interp/aot string storage" (#1102)
Fix issues in PR "Refine interp/aot string storage and emitting (#820)",
which had a few issues:
- It looks a wrong byte to mark the flag
- It doesn't work for long strings (>= 0x80 in case of little endian)

This commit fixes them by maintaining a list of loaded symbols while loading
relocation section to avoid reading a string repeatedly, and no need to mark
the flag again.
2022-04-19 15:44:30 +08:00
YAMAMOTO Takashi
87784cfb65
core/iwasm/aot/aot_runtime.c: Fix an unused function warning (#1099) 2022-04-19 09:48:28 +08:00
YAMAMOTO Takashi
b4574123c9
aot_get_module_mem_consumption: Fix const strings size (#1098)
Fix the issue that the `*(uint32 *)p_const_string_size` is added repeatedly
while calculating the aot module's memory consumption.
2022-04-19 08:57:44 +08:00
liang.he
78e099b6ab
Add more input checks for some wasm-c-api functions (#1090)
Protect wasm_valtype_new and wasm_tabletype_new from invalid inputs
2022-04-18 19:55:31 +08:00
Wenyong Huang
d4758d7380
Refine codes and fix several issues (#1094)
Add aot relocation for ".rodata.str" symbol to support more cases
Fix some coding style issues
Fix aot block/value stack destroy issue
Refine classic/fast interpreter codes
Clear compile warning of libc_builtin_wrapper.c in 32-bit platform
2022-04-18 17:33:30 +08:00
YAMAMOTO Takashi
2366e8c493
Fix a few signedness warnings (#1095)
Fix compile warnings in libc-wasi posix.c:
```
posix.c:880:41: warning: comparison of integers of different signs:
 'unsigned long' and 'ssize_t' (aka 'long') [-Wsign-compare]
            if (bufoff + iov[i].buf_len < len) {
posix.c:1359:32: warning: comparison of integers of different signs:
 'off_t' (aka 'long long') and 'unsigned long long' [-Wsign-compare]
    if (ret == 0 && sb.st_size < offset + len)
```
2022-04-18 16:54:15 +08:00
Xu Jun
8589ed155d
Fix %ld specifier issue in libc-builtin printf wrapper (#1088)
The format specifiers of %ld/%lu/%li/%lx/%lp/%lo (or %z* and %t* like) should
be treated as 32-bit integer in wasm.
And merge the handle of unsigned/signed for %u/%d and %llu/%lld specifier
when calling snprintf.
2022-04-14 14:02:19 +08:00
Xu Jun
87c67eb6f0
Enhance printf_wrapper in libc-builtin (#1074)
Use snprintf to format the string and then output it,
so as to support more formats and reduce the footprint.
2022-04-12 17:13:18 +08:00
Wenyong Huang
4864302a1f
Fix wasi implementation issues (#1078)
Fix args_get and environ_get issues in libc-wasi and libc-uvwasi implementation.
2022-04-11 11:55:37 +08:00
Xu Jun
fd9cce0eef
Add fast interpreter offset overflow check (#1076)
* check fast interpreter offset overflow
2022-04-07 21:07:32 +08:00
Xu Jun
ea63ba4bd0
source debugging: Fix step over was treated as step in issue (#1073) 2022-04-04 14:31:05 +08:00
Xu Jun
24afd4e7cb
Preserve execution memory for debug instance (#1072)
During debugging, the debug client may request to malloc a memory space
to evaluate the user expressions. If we malloc memory from the linear memory,
it may fail when the thread is in stop status. We preserve a buffer during
creating debug instance, and use a simple bump pointer allocator to serve lldb's
memory request.
2022-04-04 08:23:55 +08:00
Xu Jun
f0dc6a3015
Fix fast interpreter constant space overflow issue (#1071)
Fix the potential integer overflow of const index in const space of fast interpreter,
emit i32/i64.const opcode when the const index is larger than INT32_MAX.
And add check for the function local cell num.
2022-04-04 07:55:37 +08:00
Oscar Spencer
5e0ee67d48
Mention WAMR_BUILD_BULK_MEMORY in build_wamr.md (#1069) 2022-04-01 15:52:16 +08:00
liang.he
559a0502f1
Enable socket-api recvmsg() and sendmsg() (#1042)
Implement socket-api `recvmsg()` and `sendmsg()` for wasm app,
add sample and update document.
2022-03-30 15:57:40 +08:00
Jämes Ménétrey
106974d915
Implement Berkeley Socket API for Intel SGX (#1061)
Implement Berkeley Socket API for Intel SGX
- bring Berkeley socket API in Intel SGX enclaves,
- adapt the documentation of the socket API to mention Intel SGX enclaves,
- adapt _iwasm_ in the mini-product _linux-sgx_ to support the same option as the one for _linux_,
- tested on the socket sample as provided by WAMR (the TCP client/server).
2022-03-25 17:46:29 +08:00
Wenyong Huang
5264ce4118
Fix issues reported by klocwork (#1060)
Fix issues reported by klocwork, fix host_tool compile error,
and update build script of benchmark jetstream
2022-03-24 17:34:22 +08:00
Wenyong Huang
7262aebf77
Fix issues found by GC and Fast JIT, refine some codes (#1055)
Fix handle OP_TABLE_COPY issue
Fix loader handle OP_BLOCK/IF/LOOP issue if type_index is larger than 256
Fix loader handle OP_GET_GLOBAL, allow to change to GET_GLOBAL_64 for
aot compiler similiar to handling OP_SET_GLOBAL
Refine loader handle OP_GET/SET/TEE_LOCAL, disable changing opcode when
source debugging is enabled, so as no need to record the change of opcode
Refine wasm_interp_interp_frame_size to reduce the wasm operand stack usage

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2022-03-24 14:14:42 +08:00
Wenyong Huang
b6e5206e61
Fix wasm_runtime_load argument type invalid issue (#1059)
Remove the `const` flag for the first argument `buf` of wasm_runtime_load as
it might be modified by runtime for footprint and performance purpose, and
update the related functions and document.
2022-03-24 10:08:49 +08:00
Wenyong Huang
38b07b3614
Add libuv and uvwasi to attributions (#1057) 2022-03-24 10:05:10 +08:00
liang.he
86b79cfb93
Enable lock for Vector to protect wasm-c-api read/write/extend operations (#1010) 2022-03-23 11:42:57 +08:00
Wenyong Huang
e7079eeb17
Update document of embed wamr and code format check (#1054)
Update document embed wamr, add how to embed wamr in cmake and makefile
Update document coding guideline check, add how to install clang-format-12
2022-03-23 11:01:57 +08:00
lucianoiam
f8ee05db4b
Add a reference counter to wasm_engine_t (#1001)
This patch allows safer (note: safer, not safe) embedding in a plugin
environment where multiple instances of the engine could be needed.

Original code initializes and tears down the full runtime during
wasm_engine_new() and wasm_engine_delete() respectively. After this
update the C API implementation keeps track of engine instances count
and inits/deinits the runtime only when needed.

This allows for example to call wasm_engine_new() twice and then call
wasm_engine_delete() once without rendering the first engine instance
invalid.
2022-03-22 17:14:15 +08:00