Commit Graph

664 Commits

Author SHA1 Message Date
Xu Jun
3b641b17d8
Reserve one pointer size for fast-interp code_compiled_size (#1382)
Reserve one pointer size for fast-interp code_compiled_size: if the last opcode of
current function is to be dropped (e.g. OP_DROP), the peak memory usage will
be larger than the final code_compiled_size, we record the peak size to ensure
there won't be invalid memory access during the second traversing.
2022-08-15 11:33:20 +08:00
Wenyong Huang
6798637891
Remove some unused codes (#1379)
Remove some unused fields in module instance and the related codes,
which are introduced by emsdk some special mode (-DSIDE_MODULE=1),
and are not required now.
2022-08-15 10:13:37 +08:00
Xu Jun
872cc51881
Fix mini-loader issue (#1383) 2022-08-12 16:35:57 +08:00
Wenyong Huang
b65befd5e7
Fix load type not initialized issue for LLVMBuildLoad2 (#1381)
Fix the issue introduced by #1202, clear the compilation warning
when building wamrc based on LLVM 14/15.
2022-08-12 14:18:47 +08:00
Huang Qi
2178787664
Implement i64.div and i64.rem intrinsics (#1375) 2022-08-12 11:09:06 +08:00
Huang Qi
88cf1e36c1
Support custom stack guard size (#1368)
Add a new option WAMR_BUILD_STACK_GUARD_SIZE to set the custom
stack guard size. For most RTOS systems, we use the native stack base
address as the check boundary which may be not safe as POSIX based
systems (like Linux).
2022-08-12 10:17:11 +08:00
Wenyong Huang
e23acfab36
Fix windows thread data issue and enhance windows os_mmap (#1372)
Thread data should not be destroyed when thread exits, or other thread
may not be able to join it. This PR saves the thread data into thread data
list when thread exits, sets thread status and stores the return value, so
that other thread can join it.

Also set MEM_TOP_DOWN flag for Windows VirtualAlloc to yield LLVM
JIT relocation error.

And set opt/size level to 3 for LLVM JIT for future use, currently the flags
are not used by LLVM JIT.
2022-08-11 16:57:32 +08:00
Xu Jun
4653de90d2
Fix a maybe-uninitialized use warning (#1370)
When `OS_ENABLE_HW_BOUND_CHECK` isn't defined and
`WASM_ENABLE_THREAD_MGR == 0`, the `exec_env` is used
without initialization.
2022-08-10 12:26:17 +08:00
Huang Qi
f3f8d684b3
Implement POSIX semaphore support for linux platform (#1345)
Implement POSIX semaphore support for linux platform
2022-08-08 19:59:46 +08:00
YAMAMOTO Takashi
425efb875f
wasm_c_api.c: improve unimplemented cases (#1355)
ASSERT_NOT_IMPLEMENTED is bh_assert, which might be no-op.
in that case, it's better to fall back to the "default" case,
which reports an error properly.
2022-08-08 16:46:54 +08:00
Wenyong Huang
1fff8d5cbc
Fix wasm loader issues (#1363)
Should not clear last label's polymorphic state after current label is popped
Fix invalid func_idx check in opcode REF_FUNC
Add check when there are extra unneeded bytecodes for a wasm function
2022-08-08 13:22:23 +08:00
Xu Jun
4b00432c1a
Fix dump call stack issue in interpreter (#1358)
Fix dump call stack issue in interpreter introduced by hw bound check:
the call stack isn't dumped if the exception is thrown and caught by
signal handler.
And restore the wasm stack frame to the original status after calling a
wasm function.
2022-08-08 11:15:30 +08:00
Wenyong Huang
6922f3ac68
Implement xtensa XIP (#1202)
Lookup table for i32.const and i64.const for xtensa XIP
Lookup const offset from table for load/store opcodes for xtensa XIP
Fill capability flags for xtensa XIP
Enable lower switch pass for xtensa XIP
2022-08-04 14:42:28 +08:00
dongheng
b75ae3363d
esp32: Support app management and thread (#1350)
Support app management and thread on esp-idf platform:
- Fix compile issues when app management is enabled
- Add missing thread related APIs
2022-08-02 16:37:55 +08:00
Wenyong Huang
bf28030993
Import WAMR Fast JIT (#1343)
Import WAMR Fast JIT which is a lightweight JIT with quick startup, small footprint,
relatively good performance (~40% to ~50% of LLVM JIT) and good portability.

Platforms supported: Linux, MacOS and Linux SGX.
Arch supported: x86-64.
2022-08-02 16:03:50 +08:00
Xu Jun
1c6d10095e
add missing symbol for aot_reloc_arc.c (#1344) 2022-08-02 09:43:52 +08:00
Petr Penzin
c075844001
Add our own legacy loop unswitch pass (#1339)
Since legacy binding for loop unswitch pass was removed and we can't get
it back. Implement its equivalent in `aot_llvm_extra.cpp` and use it in
`aot_compiler.c`.

Follow up to #1183.
2022-07-29 10:29:02 +08:00
yaozhongxiao
efc8bc10a9
[bugfix] initialize "module->retain_function" for wasm_mini_loader (#1333)
Before resolving the module function's export in wasm_mini_loader,
"module->retain_function" need to be initialized, otherwise,
the "__new" function export will lead to abort.

issue: https://github.com/bytecodealliance/wasm-micro-runtime/issues/1332

Co-authored-by: yaozhongxiao <yaozhongxiao@bytedance.com>
2022-07-27 18:01:20 +08:00
Wenyong Huang
8de5168cea
Refine wasm_runtime_call_wasm_a/v (#1326)
Refine wasm_runtime_call_wasm_a/v by adding cache buf
for arguments/results to avoid allocating memory frequently.
2022-07-25 13:53:42 +08:00
Wenyong Huang
dd62b32b20
Fix interp hw bound check issues (#1322)
Fix build script to enable hw bound check for interpreter when
AOT is disabled, so as to enable spec cases test for interp with
hw bound check. And fix the issues found.
2022-07-23 20:39:01 +08:00
Wenyong Huang
fd5030e02e
Implement interpreter hw bound check (#1309)
Implement boundary check with hardware trap for interpreter on
64-bit platforms:
- To improve the performance of interpreter and Fast JIT
- To prepare for multi-tier compilation for the feature

Linux/MacOS/Windows 64-bit are enabled.
2022-07-22 11:05:40 +08:00
Wenyong Huang
32c94161d1
Clear compilation warnings on Windows (#1307) 2022-07-21 09:32:28 +08:00
Wenyong Huang
d955aa1bcc
Fix libc-wasi/uvwasi poll/environ_get issues (#1300)
Fix libc-wasi poll_oneoff hang issue
Fix libc-uvwasi environ_get sanity check issue
2022-07-20 20:02:26 +08:00
liang.he
1ee0d90d81
Add import subtyping validation (#1308)
According to import subtyping validation:
  https://webassembly.github.io/spec/core/valid/types.html#import-subtyping
wasm-c-api needs to check types when linking.
2022-07-20 18:31:19 +08:00
Wenyong Huang
0ec27af9df
Add API wasm_runtime_set_module_inst (#1286)
Add API wasm_runtime_set_module_inst, per request from #1275
2022-07-14 11:36:11 +08:00
Marcin Kolny
d08e13c5ad
Fix socket api verification of addresses in the address pool (#1270)
The existing validation didn't work as expected; e.g. for address
pool: 8.8.8.8/24 the application had access to the 127.0.0.1 address (which
should not).
2022-07-12 16:21:49 +08:00
Wenyong Huang
177aa4fc79
Fix aot rotl/rotr 0 issue (#1285)
Fix the issue reported in #1282.
When i32/i64 rotate (rotl/rotr) with 0, the LLVM IRs translated are:
left<<0 | left>>64 and left >>0 | left<<64
The value of left >> 64 and left <<64 in LLVM are treated as poison,
which causes invalid result when executing the aot function.

Directly return left when right is 0 to fix the issue.
2022-07-12 13:43:56 +08:00
liang.he
0f6e5a55a4
Fix sub module's aux stack info not synchronized to main module issue (#1279)
Sub module's auxiliary stack boundary and bottom may be different from
main module's counterpart, so when calling sub module, its aux stack info
should be gotten and set to exec_env firstly, or aux stack overflow and out
of bounds memory access exception may be thrown when calling sub
module's function.
Fix the issue reported in PR #1278.
2022-07-11 19:42:29 +08:00
Xu Jun
db210fbc66
Remove unnecessary memset after mmap (#1273)
Remove unnecessary memset after mmap to decrease the number of
page faults, as reported in #1269.
2022-07-07 13:53:50 +08:00
YAMAMOTO Takashi
be8ba9e1fd
wasm_export.h: mention module byte buffer mutability (#1271) 2022-07-07 10:06:31 +08:00
Wenyong Huang
daeb7a4265
Don't suppress prev signal handler in hw bound check (#1268)
Enhance the hw bound check reported in #1262:

When registering signal handlers for SIGSEGV & SIGBUS in boundary
check with hardware trap, preserve the previous handlers for signal
SIGSEGV and SIGBUS, and forward the signal to the preserved signal
handlers if it isn't handled by hw bound check.
2022-07-06 16:53:05 +08:00
YAMAMOTO Takashi
653efecd02
debug_engine: Fix a few typos (#1261)
no functional changes are intended.

cf.
https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html#General-Query-Packets
2022-06-30 15:45:46 +08:00
YAMAMOTO Takashi
2b49a0b817
wasm_cluster_spread_custom_data: Fix a crash when called before exec (#1257) 2022-06-29 13:21:03 +08:00
YAMAMOTO Takashi
d5d6b7284d
Fix a few redefinition warnings for WAMR_BUILD_DEBUG_INTERP=1 (#1256) 2022-06-29 12:23:58 +08:00
Wenyong Huang
625d59191d
Update spec cases to latest version (#1253)
Update spec cases of mvp/threads to latest version, update wabt
to 1.0.29. And enhance the wasm loader.
2022-06-28 16:05:16 +08:00
Wenyong Huang
5e238322c2
Enable aot compiler with llvm-14/15 (#1252)
Enable aot compiler and jit based on llvm-14.0 and llvm-15.0git,
replace LLVMBuildLoad/LLVMBuildInBoundsGEP/LLVMBuildCall with
LLVMBuildLoad2/LLVMBuildInBoundsGEP2/LLVMBuildCall2, and pass
them with related types, so as to meet the requirements of opaque
pointers.

And fix several compilation errors for llvm-14.0/15.0git.

Most spec cases and standalone cases are tested.
2022-06-28 14:53:01 +08:00
YAMAMOTO Takashi
eb3cdaaf32
Fix macro redifinition warning for NuttX (#1250)
Fix the following warning introduced by the recent change.

```
In file included from wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h:17,
                 from wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h:18,
                 from wamr/core/iwasm/aot/../common/wasm_runtime_common.h:18,
                 from wamr/core/iwasm/aot/aot_runtime.h:10,
                 from wamr/core/iwasm/aot/aot_loader.c:6:
wamr/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h:55: error: "CONFIG_HAS_ISATTY" redefined [-Werror]
 #define CONFIG_HAS_ISATTY 1

In file included from wamr/core/shared/utils/../platform/include/platform_common.h:13,
                 from wamr/core/shared/utils/bh_platform.h:9,
                 from wamr/core/iwasm/aot/aot_runtime.h:9,
                 from wamr/core/iwasm/aot/aot_loader.c:6:
wamr/core/shared/platform/nuttx/platform_internal.h:75: note: this is the location of the previous definition
 #define CONFIG_HAS_ISATTY 0
```
2022-06-26 10:06:34 +08:00
Wenyong Huang
114bf9408b
Fix get invokeNative float ret value issue with clang compiler (#1248)
When using clang compiler, the f32/f64 return value might be
invalid when calling invokeNative asm code. Declare the return
type of invokeNative as void, and set volatile for the converted
function pointers to resolve the issue.
2022-06-26 09:33:54 +08:00
Xu Jun
471cac4719
Enable dump call stack to a buffer (#1244)
Enable dump call stack to a buffer, use API
`wasm_runtime_get_call_stack_buf_size` to get the required buffer size
and use API
`wasm_runtime_dump_call_stack_to_buf` to dump call stack to a buffer
2022-06-25 21:38:43 +08:00
Xu Jun
53b775aa4b
Support integrate 3rd-party toolchains into wamrc (#1237)
Support integrating 3rd-party toolchain llc compiler or asm compiler
into wamrc by setting environment variable WAMRC_LLC_COMPILER
or WAMRC_ASM_COMPILER, wamrc will use these tools to generate
object file from LLVM IR firstly, and then refactor the object file into
aot file.
2022-06-20 13:13:41 +08:00
dongsheng28849455
bc6eda2803
Set nuttx isatty definition according to CONFIG_SERIAL_TERMIOS (#1234)
The isatty definition on nuttx depends on CONFIG_SERIAL_TERMIOS
2022-06-20 11:58:48 +08:00
Xu Jun
d0676930dc
Add arc compiler-rt functions and reloc type for mwdt (#1238)
Add arc compiler-rt functions and reloc type for arc MetaWare
Development Toolkit (mwdt), controlled by macro __CCAC__.
2022-06-20 09:03:31 +08:00
liang.he
f975a987bf
Separate MacOS workflows from the big one (#1236)
Separate MacOS workflows from the big one so as to avoid too much tasks
And optimize the total duration by reducing getting LLVM libraries times
2022-06-17 17:44:20 +08:00
dongsheng28849455
cc942e8c68
Add missing aot relocation symbols for xtensa target (#1235)
Some symbols are missing when loading the xtensa aot file.
2022-06-17 15:11:56 +08:00
Xu Jun
4b38205023
Fix some issues reported by klocwork (#1233)
Change memcpy to bh_memcpy_s and add some asserts to
enhance the security.
2022-06-16 19:50:47 +08:00
Xu Jun
188d5e70e9
Fix typo in wasm_mini_loader.c (#1232) 2022-06-16 12:07:32 +08:00
Xu Jun
b39f4c5c9b
Fix drop opcode issue in fast interpreter (#1231)
Fix fast interpreter issue reported in #1230
2022-06-16 09:51:01 +08:00
Xu Jun
e0a8aa09be
Fix build error when enable custom section without interpreter (#1229) 2022-06-15 18:14:39 +08:00
Xu Jun
77595c9560
Support emit specified custom sections into AoT file (#1207)
And add API to get the content of custom section with
section name for both wasm file and aot file.
2022-06-10 21:51:13 +08:00
Xu Jun
93607d0fac
Support print exception info in source debugger (#1212) 2022-06-08 12:17:48 +08:00
YAMAMOTO Takashi
ec299554dd
Remove the code for WASM_ENABLE_GC (#1200)
Remove the code for WASM_ENABLE_GC as it is for a dev branch
2022-06-01 16:46:11 +08:00
Wenyong Huang
5b1dcf2fa2
Implement Go language binding (#1196)
Implement Go binding APIs of runtime, module and instance
Add sample, build scripts and update the document

Co-authored-by: venus-taibai <97893654+venus-taibai@users.noreply.github.com>
2022-06-01 11:35:05 +08:00
YAMAMOTO Takashi
3168ba8dcf
Add comments on trailing uint8[1] members in the "Common" structures (#1189)
Add comments to avoid abusing these members to store extra data.
2022-05-26 11:53:50 +08:00
YAMAMOTO Takashi
3fd763a95c
wasm_export.h: Make RuntimeInitArgs less config dependent (#1190)
This header file is supposed to be used by user code, which is not
a part of WAMR. Usually WAMR configuration is not available there,
remove DEBUG_INTERP macro control in it.
2022-05-25 18:15:51 +08:00
YAMAMOTO Takashi
da3b519642
core/shared/platform/nuttx: mock several APIs for libc-wasi (#1127) 2022-05-24 12:03:40 +08:00
liang.he
565c1c04db
Fix bh_vector extend_vector not locked issue (#1187)
Fix issue that func `extend_vector` isn't locked in vector insert and append.
2022-05-24 09:10:43 +08:00
YAMAMOTO Takashi
723a808106
nuttx: Use text heap for executable memory (#1181)
Based on nuttx patch "Add up_textheap_heapmember":
  https://github.com/apache/incubator-nuttx/pull/6306
2022-05-23 10:58:09 +08:00
YAMAMOTO Takashi
69c23aa2d4
aot_reloc_xtensa.c: define __packed if not available (#1179) 2022-05-21 16:46:02 +08:00
YAMAMOTO Takashi
a50011a4dd
core/iwasm/common/wasm_application.c: Fix a typo of macro (#1180)
Change WAMR_ENABLE_PERF_PROFILING to WASM_ENABLE_PERF_PROFILING
2022-05-21 12:53:11 +08:00
Wenyong Huang
37cc6eac3b
Implement SGX getrandom/getentropy without ocall (#1176)
Implement SGX getrandom with sgx_read_rand and getentropy with `rdseed` instruction
instead of ocall to improve the security.
2022-05-21 12:21:09 +08:00
Wenyong Huang
c72501781a
Fix module_realloc with NULL ptr issue (#1175)
Fix module_realloc with NULL ptr issue reported by #1173.
2022-05-19 11:57:33 +08:00
Wenyong Huang
d7a2888b18
Fix Windows compilation warnings (#1171)
And update the Zephyr platform sample help, add arc target into usage list.
2022-05-16 09:12:58 +08:00
Namhyeon, Go
0993601d55
Add check for stack_min_addr in bound check with hardware trap (#1166)
Add return value check for os_thread_get_stack_boundary before touch_pages
in the initialization of memory access bound check with hardware trap.
2022-05-12 12:23:35 +08:00
Wenyong Huang
3d1dad7792
Fix x86-32 compile warning and update document (#1164) 2022-05-10 15:22:20 +08:00
liang.he
ceaf7dc660
Fix invalid calculation of total size of bytes to send and recv (#1162)
The total size of bytes to send and recv should be set to 0 before calculation,
but not including the size of iovec_app_t structure.
2022-05-10 10:43:34 +08:00
liang.he
3ba2d7e7de
Fix socket-api send/recv issue and c-api sample callback_chain issue (#1158)
Re-implement socket api send/recv in an atomic-like way, fix the return value
check in posix.c.
And fix wasm-c-api sample callback_chain calling malloc issue.
2022-05-09 16:52:43 +08:00
Wenyong Huang
ca4b60b335
Auto dump mem/perf profiling in execute_main/execute_func (#1157)
Automatically dump memory/performance profiling data in
wasm_application_execute_main and wasm_application_execute_func when
the related feature is enabled.

And remove unused aot_compile_wasm_file func declaration in aot_compiler.h.
2022-05-09 15:19:55 +08:00
Xu Jun
474f081f56
Fix return value not checked issue reported by Coverity (#1156)
Fix return value not checked issue in function init_wasm_timer,
reported by Coverity
2022-05-07 19:22:00 +08:00
liang.he
ed512c6867
Fix issues detected by Coverity (#1154)
wasm_c_api.c: add more checks, fix LOG_WARNING invalid specifier
aot_emit_aot_file: fix strncpy max size length to copy
posix.c: fix potential socket not close issue
wasm-c-api samples: add return value checks for fseek/ftell
cJSON.c: remove dead code
2022-05-07 18:53:02 +08:00
Wenyong Huang
2bac6a42a7
Fix some issues reported by Coverity (#1150)
module_wasm_app.c: add return value check for wasm_runtime_call_wasm
aot_runtime.c: add return value check for aot_get_default_memory
aot_runtime.c: add return value check before calling wasm app malloc/free func
wasm_runtime_common.c: fix dead code warning in wasm_runtime_load_from_sections
aot_emit_memory.c: fix potential integer overflow issue
wasm_runtime.c: remove dead code in memory_instantiate, add assertion for globals
samples simple/gui/littlevgl: fix fields of struct sigaction initialization issue
host-tool: add return value check for sendto
2022-05-07 16:51:43 +08:00
Wenyong Huang
d62543c99c
Enlarge max pool size and fix bh_memcpy_s dest max size check (#1151)
Enlarge max pool size and fix bh_memcpy_s dest max size check to support
large linear memory, e.g. with initial page count 65535.
2022-05-07 16:09:16 +08:00
Xu Jun
a7f4c3c15c
Fix app manager/framework issues reported by Coverity (#1155)
runtime_sensor.c: add return value check for os_mutex_init
                             fix find_sensor_client
sensor_mgr_ref.c: add return value check for init_sensor_framework
app_manager_host.c: add return value check for app_manager_host_init
module_wasm_app.c: add bh_assert for m_data
                                   fix mkdir potential issue
sample littlevgl/gui/simple: add return value check for init_sensor_framework
host_tool: add more check for g_conn_fd
2022-05-07 15:43:34 +08:00
YAMAMOTO Takashi
3edb832f76
aot_reloc_arm.c: Implement R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS (#1148)
Implement reloc type R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS for arm,
refer to:
https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#5614static-arm-relocations
2022-05-07 10:22:05 +08:00
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
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
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
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
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
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
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
Hanged Fish
a02cc6626d
Fix libc-wasi not working in spawned exec_env (#1053)
In thread_manager.c, `wasm_cluster_spawn_exec_env` creates a new module
instance but not sets wasi_ctx, so when the new exec_env calls wasm function
which uses WASI API, the WASI API functions in `libc_wasi_wrapper.c` will get
null result in calling `get_wasi_ctx`  and then return `wasi_errno`.

Signed-off-by: HangedFish <bravohangedman@outlook.com>
2022-03-22 12:17:14 +08:00
liang.he
310b9ca0d8
Fix classic interpreter handling BLOCK/IF/LOOP issue (#1051)
`PUSH_CSP()` should set label's begin frame_sp as the bottom of current label's stack
but not the top of it
2022-03-20 18:07:33 +08:00
Wenyong Huang
b1a4dd2e46
Fix Windows failed to relocate __ymm symbol error (#1047)
Resolve the "__ymm@" prefixed symbols like "__xmm@" and "__real@" symbols
in Windows platform.
2022-03-16 11:07:11 +08:00
Wenyong Huang
21d89135da
Enhance uvwasi build process and fix wamrc windows build error (#1046)
And update related document
2022-03-15 21:43:55 +08:00
Xu Jun
7a0ec1cd17
Use nanosecond for atomic wait (#1041)
Fix issue reported by #1038
2022-03-10 19:43:27 +08:00
Wenyong Huang
9c87a1ee17
Implement part of Berkeley Socket API for libc-wasi (#1036)
Refer to [Networking API design](https://github.com/WebAssembly/WASI/issues/370)
and [feat(socket): berkeley socket API v2](https://github.com/WebAssembly/WASI/pull/459):

- Support the socket API of synchronous mode, including `socket/bind/listen/accept/send/recv/close/shutdown`,
    the asynchronous mode isn't supported yet.
- Support adding `--addr-pool=<pool1,pool2,..>` argument for command line to identify the valid ip address range
- Add socket-api sample and update the document
2022-03-10 15:13:38 +08:00
Wenyong Huang
55ad4c7ec7
Fix wasm-c-api wasm_module_imports issues (#1021)
Fix several issues in wasm-c-api wasm_module_imports function:
1. Two of the if branches never set the module_name and name fields which are later passed as arguments to wasm_importtype_new, and eventually might cause double-free and/or use-after-free
2. Should zero module_name/name/extern_type at the start of loop iteration, and destroy their resources when failed at the end of loop iteration
2. No need to check `if (!extern_type) { continue; }`, as extern_type is converted from type and type is already checked
3. No need to wasm_importtype_vec_delete(out) when failed, as it is passed from outside and should be destroyed by outside
2022-02-24 09:36:46 +08:00
Wenyong Huang
25fc006c33
Refine call native function from AOT code (#1015)
When calling native function from AOT code, current implementation is to return
back to runtime to call aot_invoke_native, which calls wasm_runtime_invoke_native
and the latter calls assembly code. We did it before as there may be pointer and
string arguments to check and convert if the native function's registered signature
has character '*' and '$'.
As the built-in native function's signatures can be gotten in compilation time, we
check the pointer/string arguments and convert them into native address in AOT
code, and then invoke the native function directly, so as to improve performance.
2022-02-23 14:58:32 +08:00
Namhyeon, Go
0d1060b3cc
Fix ‘MADV_HUGEPAGE’ undeclared compilation error (#1012)
In some Linux systems whose kernel version is smaller than 2.6.38, the macro
MADV_HUGEPAGE isn't introduced yet which causes compilation error.
Add macro control to fix the compilation error.
2022-02-18 11:25:06 +08:00
Wenyong Huang
9fc124b06f
Enhance app manager (#1011)
Add app_manager_is_started API per requested by #1004 to support
checking the status of app manager in another thread.
2022-02-17 15:04:52 +08:00
Xu Jun
3fe191b0df
[debugger enhance] don't block gdbserver thread while executing (#989)
Allow to set break point again when all break points are removed and
wasm app starts running.
2022-02-16 17:35:35 +08:00
Wenyong Huang
a33a385caa
Fix littlevgl link error issues (#1006)
The littlevgl library had changed its name and domain to [LVGL](https://lvgl.io).
See https://blog.lvgl.io/2020-06-01/announcement
We change some names and links accordingly.

Also remove the cloning for tlsf library as it isn't used now.
2022-02-15 08:41:36 +08:00
Wenyong Huang
bb87180b72
Update document and fix wasm_runtime_call_wasm_a issue (#1005)
Update document memory_tune.md: fix embed wamr link error,
fix description error of wasm operand stack size, update picture.

Fix wasm_runtime_call_wasm_a issue reported by #1003 and update
sample basic to call this API.
2022-02-14 17:36:38 +08:00
Wenyong Huang
59282f7ddb
Fix native stack overflow check failed in interpreter (#992)
Increase default/min native stack size when UVWASI is enabled as
UVWASI requires larger native stack size.
Increase the reserved bytes to the native thread stack boundary to
better detect the native stack overflow.
Set WASM_DISABLE_HW_BOUND_CHECK to 0 when interpreter is
enabled and AOT is disabled, as memory access boundary check
with hardware trap is only enabled in AOT/JIT mode.
2022-02-11 11:43:03 +08:00
Karl Fessel
a22a5da40d
Correct RIOT os_mmap size type to size_t (#1002)
Change signature of riot `os_mmap` implementation to match declaration in core/shared/platform/include/platform_api_vmcore.h
2022-02-09 10:21:54 +08:00
lucianoiam
4bdeb909df
Enable Windows MinGW support (#1000)
Allow compilation on Windows MinGW, see build_wamr.md for more details.

Note that WASI and some other smallish details are still not supported, but
we have a starting point. See more discussion at #993
2022-02-06 13:20:38 +08:00
Xu Jun
5f8c7655a7
Fix pthread_getspecific return value (#999)
Fix pthread_getspecific return value as mentioned in #995
2022-02-05 22:45:59 +08:00
tonibofarull0
6ddfae6f66
Fix attr container forward declaration issue (#998)
Fix attr container forward declaration issue reported in #996
2022-02-05 21:46:18 +08:00
xingkaiyu
96a8bdf717
Fix win_thread.c timed wait always return 0 issue (#994)
win_thread.c os_cond_wait_internal returns os_sem_reltimed_wait or os_sem_wait result instead of always return BHT_OK before
2022-02-05 21:14:39 +08:00
Karl Fessel
770ca8c90c
Adapt to RIOT ztimer and ztimer64 (#988)
RIOT-OS currently changes xtimer to ztimer
2022-01-28 18:38:35 +08:00
Xu Jun
68fd6454c2
Fix debug thread not created issue (#983)
And fix a double free issue when starting debug server failed
2022-01-26 09:56:01 +08:00
Xu Jun
90a0057d33
Implement pthread_cond_broadcast wrapper for lib-pthread (#982)
Implement pthread_cond_broadcast wrapper for lib-pthread
- support pthread_cond_broadcast wrapper for posix/linux-sgx/windows
- update document for building multi-thread wasm app with emcc
2022-01-25 09:28:02 +08:00
Wenyong Huang
5631a2aa18
Use LLVM new pass manager for wamrc (#978)
Use LLVM new pass manager for wamrc to replace the legacy pass manger,
so as to gain better performance and reduce the compilation time.
Reference links:
- https://llvm.org/docs/NewPassManager.html
- https://blog.llvm.org/posts/2021-03-26-the-new-pass-manager

And add an option to use the legacy pm mode when building wamrc:
cmake .. -DWAMR_BUILD_LLVM_LEGACY_PM=1

For JIT mode, keep it unchanged as it only runs several function passes and
using new pass manager will increase the compilation time.

And refactor the codes of applying LLVM passes.
2022-01-24 11:10:37 +08:00
Wenyong Huang
7636d86a76
Refactor Orc JIT to enable lazy compilation (#974)
Refactor LLVM Orc JIT to actually enable the lazy compilation and speedup
the launching process:
  https://llvm.org/docs/ORCv2.html#laziness

Main modifications:
- Create LLVM module for each wasm function, wrap it with thread safe module
  so that the modules can be compiled parallelly
- Lookup function from aot module instance's func_ptrs but not directly call the
  function to decouple the module relationship
- Compile the function when it is first called and hasn't been compiled
- Create threads to pre-compile the WASM functions parallelly when loading
- Set Lazy JIT as default, update document and build/test scripts
2022-01-20 18:40:13 +08:00
Wenyong Huang
260d36a62d
Refactor externref related APIs of reference types feature (#971)
Currently when calling wasm_runtime_call_wasm() to invoke wasm function
with externref type argument from runtime embedder, developer needs to
use wasm_externref_obj2ref() to convert externref obj into an internal ref
index firstly, which is not convenient to developer.
To align with GC feature in which all the references passed to
wasm_runtime_call_wasm() can be object pointers directly, we change the
interface of wasm_runtime_call_wasm() to allow to pass object pointer
directly for the externref argument, and refactor the related codes, update
the related samples and the document.
2022-01-19 11:25:08 +08:00
Huang Qi
2c743dbd51
Add log info for heap and stack like wasm loader in aot loader (#968)
Add log info for heap and stack like wasm loader in aot loader

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Change-Id: I349848d75f1a26cde29217c14cfb6e779c976a8b
2022-01-19 08:55:59 +08:00
Wenyong Huang
8088783775
Refine is_xip_file and pointer range check (#965)
Refine is_xip_file check, when e_type isn't E_TYPE_XIP, just return false
and no need to go through all the other sections of the AOT file.

Refine pointer range check, convert pointer to uintptr_t type before
comparison to yield possible sanitizer pointer overflow error.
2022-01-18 11:05:58 +08:00
Wenyong Huang
552f85075d
Fix __wasi_subscription_t inconsistent with wasi-libc issue (#964)
Fix __wasi_subscription_t structure definition inconsistent with wasi-libc
definition issue, reported by #961, tested with sleep, poll API and other
wasi cases on x86-64, x86-32 and arm32 targets.
2022-01-17 20:52:45 +08:00
Huang Qi
e0511fe822
Correct stack base calculation on Mac and NuttX (#963)
The return address of pthread_get_stackaddr_np() in MacOS and NuttX
may be the base address or the end (boundary) address of the native stack,
if it is the end address, we get the base address according to it and the
stack size, so as to get the actual stack boundary address correctly.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-01-17 20:45:55 +08:00
Wenyong Huang
092efbfe21
Fix thread manager issues (#962)
Fix the issue that joining a detached thread might result in joining hang,
resolve the issue by adding wait_count for a thread's exec_env to indicate
whether a thread needs to detach itself or not when it exits.

And add checks for the input exec_env for cluster's join/detach/cancel thread.
2022-01-17 17:09:04 +08:00
Xu Jun
ee97e30a1a
Fix pointer unchecked issue in thread-mgr.c (#960)
And refine the code format of thread_manager.h
2022-01-14 17:57:59 +08:00
Wenyong Huang
30cb05f223
Refine llvm pass order (#948)
Put Vectorize passes before GVN/LICM passes as normally the former
gains more performance improvement and the latter might break the
optimizations for the former. Can improve performance of several
sightglass cases.

And don't check exception throw after calling an AOT function if it is
and recursive call, similar to handing of Spec tail call opcode.
2022-01-12 18:56:56 +08:00
Wenyong Huang
4b5543cc1a
Enable Windows XIP (#944)
Enable running XIP file on Windows platform.
And add more strict checks for wamrc to report error when the input file
is same with output file, or the input file is AOT file but not wasm file.
2022-01-10 15:59:58 +08:00
Wenyong Huang
f6197962ef
Fix MacOS invokeNative float ret type pass error (#940) 2022-01-07 18:17:37 +08:00
Wenyong Huang
78308e7bda
GetCurrentThreadStackLimits dynamically for Windows platform (#939)
GetCurrentThreadStackLimits dynamically for Windows platform
according to suggestion in #902
And fix some compiling warnings on Windows platform
2022-01-07 17:00:38 +08:00
Wenyong Huang
cb51dbb513
Fix some issues on MacOS platform (#937)
Fix some issues on MacOS platform
- Enable libc-wasi by default
- Set target abi to "gnu" if it is not set for wamrc to avoid generating
  object file of unsupported Mach-O format
- Set `<vendor>-<sys>` info according to target abi for wamrc to support
  generating AOT file for other OSs but not current host
- Set cpu name if arch/abi/cpu are not set to avoid checking SIMD
  capability failed
- Set size level to 1 for MacOS/Windows platform to avoid relocation type
  unsupported warning
- Clear posix_memmap.c compiling warning
- Fix spec case test script issues, enable test spec cases on MacOS

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2022-01-07 09:53:48 +08:00
Wenyong Huang
308d31c621
Upgrade uvwasi to 1.42.0 and fix Android link issues (#938)
Upgrade uvwasi to 1.42.0 and fix Android link issues reported by #934
2022-01-06 18:25:37 +08:00
Huang Qi
9d2576d8e0
Wrap data width according to atomic opcode specified (#936)
Wrap data width according to atomic opcode specified

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-01-06 11:43:34 +08:00
Huang Qi
9169eff8bb
Remove hardcoded stack size in thread_manager.c (#931)
Remove hardcoded stack size in thread_manager.c

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-01-05 13:16:25 +08:00
Stefan Wallentowitz
78414b627c
ESP IDF fixes (#927)
Various fixes and beautifications coordinated with @1c3t3a,
fixes 2 of the 3 all remaining issues from #892:
- enable to os_mmap executable memory
- fix os_malloc/os_realloc/os_free issues
- implement os_thread_get_stack_boundary
- add build scripts to include with esp-idf to use wamr as
  an ESP-IDF component
- update sample and document
2022-01-05 12:50:17 +08:00
Wenyong Huang
cdf306364e
Fix compile warning on non-x86 targets, fix alios build error (#923)
And fix os_thread_signal_init issue on windows platform
2021-12-30 10:07:50 +08:00
Wenyong Huang
90cccda68e
Refine some error msg, comment and document (#921) 2021-12-29 12:13:30 +08:00
liang.he
50b6474f54
Add WASI ABI compatibility check for multi-module (#913)
Refer to https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md
to check the WASI ABI compatibility:
- Command (main module) may export _start function with signature "()"
- Reactor (sub module) may export _initialize function with signature "()"
- _start and _initialize can not be exported at the same time
- Reactor cannot export _start function
- Command and Reactor must export memory

And
- Rename module->is_wasi_module to module->import_wasi_api
- Refactor wasm_loader_find_export()
- Remove MULTI_MODULE related codes from mini_loader
- Update multi-module samples
- Fix a "use-after-free" issue. Since we reuse the memory instance of sub module,
   just to protect it from freeing an imported memory instance
2021-12-29 11:04:36 +08:00
Wenyong Huang
98bacfe6bb
Fix sensor framework timer issue and update sensor sample (#917)
Fix the sensor framework timer issue reported by #884 when setting
`ms_to_next_check`, and unify the type of time related args/vars to
uint32 to avoid potential type conversion issues, and fix the compile
warnings.

And update the sensor sample by creating two sensors to confirm that
the fix works correctly.
2021-12-28 08:44:19 +08:00
Wenyong Huang
635084c9b2
Fix sgx platform issues (#916)
Fix ocall_poll incorrectly defined issue in which poll_fds should be defined as [in, out]
Fix is_xip_file incorrectly check issue
2021-12-28 08:41:43 +08:00
Wenyong Huang
89a1c8220d
Implement GetCurrentThreadStackLimits() for Windows 7 (#914)
And fix compilation error of when build wamrc, fix compilation warnings
2021-12-27 10:18:44 +08:00
Xu Jun
ccb2de35d7
Enable source debugging feature for windows platform (#910)
- use platform independent data types in debug-engine library
- add os_socket APIs and provide windows and posix implementation
- avoid using platform related header files in non-platform layer
- use format specifiers macros for sprintf and sscanf
- change thread handle type from uint64 to korp_tid
- add lock when sending socket packet to avoid thread racing
2021-12-22 19:52:07 +08:00
Wenyong Huang
af251e45ca
Remove PRI macro control in wasm_application.c (#905)
And fix read_leb byte count check issue in aot_compiler.c
2021-12-20 19:22:28 +08:00
Huang Qi
4cc4625a2b
Cleanup output format warnings (#904)
Use `PRIxxx` related macros to format the output strings so as to clear
compile warnings, e.g. PRIu32, PRId32, PRIX32, PRIX64 and so on.
And add the related macro definitions in platform_common.h if they
are not defined, as some compilers might not support them.
2021-12-20 15:51:36 +08:00
Huang Qi
a41c1ad85c
Don't use constant float table on arm and riscv (#903)
Don't use constant float table on arm and riscv as LLVM doesn't generate
.LPCI/.rodata like relocations on them, the float/double constants are encoded
into instructions directly, so no need to lookup them from constant table.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-12-20 11:10:52 +08:00
Bastian Kersting
a9f1c2b64a
Port WAMR to ESP-IDF (#892)
This PR introduces an implementation of the WAMR platform APIs for ESP-IDF and enables support for Espressif microcontrollers, and adds the documentation around how to build WAMR for ESP-IDF.

This PR is related to the following issues at WAMR: closes #883, #628, #449 and #668 as well as [#4735](https://github.com/espressif/esp-idf/issues/4735) at the esp-idf repo. It implements most functions required by [platform_api_vmcore.h](https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/shared/platform/include/platform_api_vmcore.h).

The PR works in interpreter mode on Esp32c3 and Esp32. For the AOT mode, currently errors occur on both platforms with `Guru Meditation Error`. It seems that the AOT code isn't run with shared memory as os_mmap() allocates memory with malloc() API, it is to be fixed in the future.
2021-12-20 10:52:59 +08:00
Wenyong Huang
5be427bfa2
xip: Lookup float constants from table to reduce relocations (#894)
Lookup float/double constants from exec_env->native_symbol table
but not construct them with LLVMBuildConst if XIP mode is enabled,
these constants are introduced by f32/f64.const opcodes and some
float/double conversion opcodes, and make wamrc generate some
relocations in text section of AOT XIP file. This patch eliminates such
relocations when "--enable-indirect-mode" is added to wamrc.
2021-12-16 21:39:23 +08:00
Wenyong Huang
66e6e1f7cd
Clear more compile warnings reported by -Wshadow flag (#899) 2021-12-16 14:47:44 +08:00
liang.he
e70867c64f
Update spec test cases to latest version (#889)
Update spec test cases to commit 2460ad02b51fb5ed5824f44de287a8638b19a5f8,
and modify wamr test suite script as the SIMD cases have been added into spec
main repo by default, no need to clone SIMD repo again when testing SIMD.
2021-12-15 14:39:54 +08:00
Wenyong Huang
bbaf0a3c37
Fix wamrc endian/bit-width check invalid issue on win32 target (#886)
Use the previous resolved binary type info (obj_data->target_info.bin_type) to
check the endian and bit-width but not the raw binary info, the latter is not
suitable for the check for Win32 object file type.

And fix the symbol comparison issue in resolve_target_sym(), as in Win32, the
symbol name of a function added by LLVMAddFunction() is prefixed by '_',
which leads to invalid result returned by strcmp().
2021-12-14 08:45:48 +08:00
zhouliang3
2917a0c814
libc-builtin: Fix the signature of strncasecmp native function (#888)
Fix the signature invalid issue in libc-builtin, modify signature of strncasecmp
native function from "($$i)" to "($$i)i".
2021-12-13 19:40:05 +08:00
Wenyong Huang
e3ef216258
Add mipsel to wamrc supported target list (#887)
Add "mipsel" (mips little endian) to wamrc supported target list
2021-12-13 17:49:21 +08:00
Wenyong Huang
5547924e28
Refine codes and fix several issues (#882)
Refine some codes in wasm loader
Add -Wshadow to gcc compile flags and fix some variable shadowed issues
Fix function parameter/return types not checked issue
Fix fast-interp loader reserve_block_ret() not handle V128 return type issue
Fix mini loader load_table_segment_section() failed issue
Add detailed comments for argc argument in wasm_runtime_call_wasm()
2021-12-10 18:13:17 +08:00
Huang Qi
915b26b0ec
Remove hardcoded stack size while creating pthread (#881)
Use original module instance's default_wasm_stack_size instead,
which is the stack size used to instantiate it.
2021-12-10 15:11:45 +08:00
Huang Qi
208cafc776
Add new E_TYPE_XIP to indicate XIP mode (#874)
Emit e_type = E_TYPE_XIP in target info section to indicate that it is
an XIP file, and replace related checks in aot loader.
2021-12-08 18:43:08 +08:00
Wenyong Huang
56ae28bb32
Implement relocation R_AARCH64_JUMP26 for aarch64 (#873)
Treat R_AARCH64_JUMP26 same as R_AARCH64_CALL26, both of their
relocation operation is S + A - P, the difference is that one is for call
(BL) instructions, the other is for jump (B) instructions.
2021-12-07 10:32:10 +08:00
Wenyong Huang
b490a229f6
Enhance XIP and add XIP document (#863)
Auto detect whether file is XIP file before loading module in posix like and
linux-sgx platforms, and if yes, mmap executable memory automatically to
run the XIP file.
Add document about XIP feature.
Enable test spec cases with XIP feature.
2021-12-06 17:25:10 +08:00
Xu Jun
2af5ae5abb
[source debug] refine some code in source debugging (#856)
- move the wait_cond from exec_env to debug_instance, so the debug thread can be waken up by any threads
- process more general query message from debugger
- refine debug instance create/destroy mechanism
- avoid creating debug instance during module instantiating
- avoid blocking execution thread during creating debug instance
- update related documents
2021-12-06 10:25:38 +08:00
Huang Qi
c8fe1004aa
Don't throw exception while module_malloc failed (#860)
Don't throw exception when module_malloc memory failed:
- Exception will terminate the wasm app, it's not necessary since app can
  check the result of dynamic allocation and do some cleanup or fallback
  operation on failure instead of 'crash' directly.
- In acquire_wait_info, call hasn_map_find only when the address isn't NULL,
  or there are many senseless error logs
2021-12-03 17:00:18 +08:00
Wenyong Huang
b73edc8587
Refine code when aux stack global isn't found (#862)
When auxiliary stack global isn't found in wasm app, it must be unused in
the wasm app, we set it to __heap_base global and set its size to 0, so as to
shrink the linear memory to reduce the memory consumption.
2021-12-03 15:30:32 +08:00
Javan
212810bc2f
Fix issue of wasm/aot file malformed format (#853)
Fix possible integer overflow unchecked issue when checking
wasm/aot file format.
2021-11-30 20:47:42 +08:00
Huang Qi
8d1c56bda4
Implement atomic and memset/memmove/memcpy intrinsic for riscv (#841)
- Lower aotmic instruction to non-atomic form on some platforms
- Lower memset/memmove/memcpy for XIP
- Disable rtti in cmake
2021-11-30 17:10:14 +08:00
Wenyong Huang
25b8f88dd4
Fix win32 aot endian and machine type check errors (#855)
Emit the correct binary type and machine type in AOT file
for win64/win32 system, and handle them in aot loader.
2021-11-30 14:16:21 +08:00
Xu Jun
9b0b33e4ae
fix duplicated debug instance id in multiple native thread issue (#847)
The debug_instance_list is not protected by mutex, and the debug instance uses
the length of this list as its id. If several threads create debug instance at the
same time, they may get duplicated/same ids. This patch adds mutex to protect
this list.
2021-11-25 12:15:37 +08:00
Wenyong Huang
39c68f66d7
Fix Win32 build error (#843)
Fix compilation error on Win32 platform.
2021-11-23 10:57:52 +08:00
zhouliang3
e64b6e8120
Fix bug of destroy_callback_list not cleared when thread mgr destroy (#844)
The destroy_callback_list variable in thread_manager_destroy is not cleared.
When wamr is started as a task, after exiting and restarting, it will loop
endlessly in traverse_list.

Signed-off-by: zhouliang3 <zhouliang3@xiaomi.com>
2021-11-23 10:57:01 +08:00
liang.he
1dccf39d16
Enable ref types and bulk memory by default for wamrc (#838)
Enable ref types feature and bulk memory feature by default for wamrc
and provide "--disable-ref-types", "--disable-bulk-memory"  to disable
them.
And remove the ref_type_flag option in wasm_loader.c which is used to
control whether to enable ref types or not when ENABLE_REF_TYPES
macro is enabled in wamrc. As the wasm binary format with ref types
is compatible with the binary format before, we can remove the option.
Also update the spec test scripts.
2021-11-18 17:42:49 +08:00
Wenyong Huang
37a14c9825
Add more reloc symbols for target arm/thumb/riscv (#834)
Add more reloc symbols for target arm/thumb/riscv and
implement relocation type R_ARM_ABS32 for thumb.
Tested in buildroot qemu.
2021-11-15 12:23:15 +08:00
Wenyong Huang
64be6ec9a7
Fix potential pointer overflows (#826)
Fix some potential pointer overflows in aot applying relocations and
several other places.
And add sanitizer compiler flags to wamrc CMakeLists.txt to detect
such issues.
2021-11-15 10:57:37 +08:00
Wenyong Huang
a1ad950ae1
Enable LLVM link time optimization (LTO) for AOT (#831)
Enable LLVM link time optimization for AOT and enable it by default,
and provide "wamrc --disable-llvm-lto" option to disable it.
And modify the spec test script, disable it by default when testing
spec cases.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2021-11-13 16:59:35 +08:00
Wenyong Huang
9281286181
Enable huge page for posix platforms (#825)
This patch enables huge page support for posix platforms for performance
reason, if the request size to mmap is larger than 2MB, then we use madvise
to set some pages to huge page.
And add macro control to enable tracing the mmap/munmap.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2021-11-12 16:19:26 +08:00
Huang Qi
0af7522e3e
Fix fail to get builtin functions in indirect call (XIP) mode (#829)
Fix fail to get builtin functions in indirect call (XIP) mode, e.g.
function aot_alloc_frame, aot_memory_init, aot_table_init and so on.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-11-11 14:14:21 +08:00
YAMAMOTO Takashi
6edabbf632
Add __umoddi3 to target symbol map in aot_reloc_arm.c (#828) 2021-11-10 16:53:14 +08:00
YAMAMOTO Takashi
2613a68108
aot_reloc_x86_64: Fix pointer overflows (#809)
Fix pointer overflow of `(uint8 *)symbol_addr + reloc_addend` detected by UBSan:
```
core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43: runtime error: addition of unsigned offset to 0x000041209004 overflowed to 0x000041209000
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior core/iwasm/aot/arch/aot_reloc_x86_64.c:232:43
```
2021-11-08 16:15:44 +08:00
Wenyong Huang
403a7d3f4f
Refine interp/aot string storage and emitting (#820)
Currently the string in the wasm/aot file will be duplicated and stored
into const string list/set in interpreter/aot loader, which leads to extra
unnecessary memory consumption if the file buffer can be referred to
after loading. We refine the string storage by:
- if the file buffer can be referred to after loading and it is writable, we
  reuse the file buffer to store the string but not store it into the const
  string set: move string backward and append '\0'
- emit string with '\0' only for XIP mode in which the AOT file is readonly
- if the file buffer cannot be referred to, e.g. in app manager, keep the
  same behavior as before

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2021-11-08 11:27:26 +08:00
Wenyong Huang
9424dad56a
Implement os_time_get_boot_microsecond() for sgx platform (#818) 2021-11-06 15:58:21 +08:00
Xu Jun
703e724c99
[source debug] process ModuleInfo query message (#815) 2021-11-02 12:09:15 +08:00
Huang Qi
3fa91df754
Simplify some string size calculation when emitting AOT file (#813)
Simplify some string size calculation when emitting AOT file

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2021-11-01 20:03:13 +08:00
Xu Jun
83df8600f7
Support random debug port by assigning port = 0 (#807)
Support random debug port by assigning port = 0,
and update help and document.
2021-10-30 02:44:41 -05:00