Merge branch main into dev/exce_handling

This commit is contained in:
Wenyong Huang 2024-01-27 16:31:50 +08:00
commit 5c0d4ac598
101 changed files with 2380 additions and 1217 deletions

View File

@ -145,6 +145,7 @@ jobs:
"-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
"-DWAMR_ENABLE_SHARED_MEMORY_MMAP=1",
]
os: [ubuntu-22.04]
platform: [android, linux]
@ -322,7 +323,7 @@ jobs:
run: |
VERBOSE=1
cmake -S . -B build ${{ matrix.make_options }}
cmake --build build --config Release --parallel 4
cmake --build build --config Debug --parallel 4
ctest --test-dir build --output-on-failure
working-directory: samples/wasm-c-api
@ -393,7 +394,7 @@ jobs:
cd samples/file
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./src/iwasm -f wasm-app/file.wasm -d .
- name: Build Sample [multi-thread]
@ -401,7 +402,7 @@ jobs:
cd samples/multi-thread
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/test.wasm
- name: Build Sample [multi-module]
@ -409,7 +410,7 @@ jobs:
cd samples/multi-module
mkdir build && cd build
cmake .. -DWAMR_BUILD_AOT=1
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./multi_module mC.wasm
./multi_module mC.aot
@ -418,7 +419,7 @@ jobs:
cd samples/spawn-thread
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./spawn_thread
- name: Build Sample [ref-types]
@ -426,7 +427,7 @@ jobs:
cd samples/ref-types
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./hello
- name: Build Sample [simple]
@ -441,7 +442,7 @@ jobs:
cd samples/wasi-threads
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/no_pthread.wasm
- name: Build Sample [shared-module]
@ -450,6 +451,12 @@ jobs:
./build.sh
./run.sh
- name: Build Sample [terminate]
run: |
cd samples/terminate
./build.sh
./run.sh
test:
needs:
[

View File

@ -285,7 +285,7 @@ jobs:
cd samples/file
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./src/iwasm -f wasm-app/file.wasm -d .
- name: Build Sample [multi-thread]
@ -293,7 +293,7 @@ jobs:
cd samples/multi-thread
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/test.wasm
- name: Build Sample [multi-module]
@ -301,7 +301,7 @@ jobs:
cd samples/multi-module
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./multi_module mC.wasm
- name: Build Sample [spawn-thread]
@ -309,7 +309,7 @@ jobs:
cd samples/spawn-thread
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./spawn_thread
- name: Build Sample [ref-types]
@ -317,7 +317,7 @@ jobs:
cd samples/ref-types
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./hello
- name: Build Sample [wasi-threads]
@ -325,7 +325,7 @@ jobs:
cd samples/wasi-threads
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/no_pthread.wasm
- name: Build Sample [shared-module]
@ -333,3 +333,9 @@ jobs:
cd samples/shared-module
./build.sh
./run.sh
- name: Build Sample [terminate]
run: |
cd samples/terminate
./build.sh
./run.sh

View File

@ -52,7 +52,7 @@ jobs:
build_iwasm_on_nuttx:
runs-on: ubuntu-latest
container:
image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:4b4cbf0b70512e61ada9cdcb76b97e90ad478b85e4d0774d05a95fa32caa8c39
image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:d9261eacf6c6ebe656c571757751c803e8f04c3ae9b820320a5ea5dd57b7205a
strategy:
matrix:
@ -90,14 +90,14 @@ jobs:
uses: actions/checkout@v3
with:
repository: apache/incubator-nuttx
ref: releases/12.3
ref: releases/12.4
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v3
with:
repository: apache/incubator-nuttx-apps
ref: releases/12.3
ref: releases/12.4
path: apps
- name: Checkout WAMR

View File

@ -246,7 +246,7 @@ jobs:
cd samples/file
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cmake --build . --config Debug --parallel 4
cp wasm-app/file.wasm `pwd`/../../../product-mini/platforms/${{ matrix.platform }}/enclave-sample
- name: Test Sample [file] in non-aot mode

View File

@ -383,7 +383,9 @@ jobs:
- name: Build Sample [wasm-c-api]
run: |
VERBOSE=1
cmake -S . -B build ${{ matrix.make_options }} -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}"
cmake -S . -B build ${{ matrix.make_options }} \
-D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}" \
-D WAMR_BUILD_QUICK_AOT_ENTRY=0
cmake --build build --config Release --parallel 4
ctest --test-dir build --output-on-failure
working-directory: samples/wasm-c-api
@ -507,6 +509,12 @@ jobs:
cd samples/shared-module
./build.sh
./run.sh
- name: Build Sample [terminate]
run: |
cd samples/terminate
./build.sh
./run.sh
test:
needs:
[

View File

@ -28,13 +28,13 @@ jobs:
with:
os: "ubuntu-22.04"
arch: "ARM RISCV AArch64"
container_image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:4b4cbf0b70512e61ada9cdcb76b97e90ad478b85e4d0774d05a95fa32caa8c39
container_image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:d9261eacf6c6ebe656c571757751c803e8f04c3ae9b820320a5ea5dd57b7205a
spec_test_on_qemu:
runs-on: ubuntu-latest
needs: [build_llvm_libraries]
container:
image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:4b4cbf0b70512e61ada9cdcb76b97e90ad478b85e4d0774d05a95fa32caa8c39
image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:d9261eacf6c6ebe656c571757751c803e8f04c3ae9b820320a5ea5dd57b7205a
strategy:
matrix:
target_config: [
@ -99,14 +99,14 @@ jobs:
uses: actions/checkout@v3
with:
repository: apache/incubator-nuttx
ref: releases/12.3
ref: releases/12.4
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v3
with:
repository: apache/incubator-nuttx-apps
ref: releases/12.3
ref: releases/12.4
path: apps
- name: Checkout WAMR

View File

@ -75,9 +75,9 @@ The following platforms are supported, click each link below for how to build iw
- [Blog: The WAMR memory model](https://bytecodealliance.github.io/wamr.dev/blog/the-wamr-memory-model/)
- [Blog: Understand WAMR heaps](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-heaps/) and [stacks](https://bytecodealliance.github.io/wamr.dev/blog/understand-the-wamr-stacks/)
- [Blog: Introduction to WAMR running modes](https://bytecodealliance.github.io/wamr.dev/blog/introduction-to-wamr-running-modes/)
- [Memory usage tunning](./doc/memory_tune.md): the memory model and how to tune the memory usage
- [Memory usage tuning](./doc/memory_tune.md): the memory model and how to tune the memory usage
- [Memory usage profiling](./doc/build_wamr.md#enable-memory-profiling-experiment): how to profile the memory usage
- [Performance tunning](./doc/perf_tune.md): how to tune the performance
- [Performance tuning](./doc/perf_tune.md): how to tune the performance
- [Benchmarks](./tests/benchmarks): checkout these links for how to run the benchmarks: [PolyBench](./tests/benchmarks/polybench), [CoreMark](./tests/benchmarks/coremark), [Sightglass](./tests/benchmarks/sightglass), [JetStream2](./tests/benchmarks/jetstream)
- [Performance and footprint data](https://github.com/bytecodealliance/wasm-micro-runtime/wiki/Performance): the performance and footprint data

View File

@ -248,6 +248,12 @@ if (WAMR_BUILD_SHARED_MEMORY EQUAL 1)
else ()
add_definitions (-DWASM_ENABLE_SHARED_MEMORY=0)
endif ()
if (WAMR_ENABLE_SHARED_MEMORY_MMAP EQUAL 1)
add_definitions (-DWASM_ENABLE_SHARED_MEMORY_MMAP=1)
message (" Shared memory allocated using mmap enabled")
else ()
add_definitions (-DWASM_ENABLE_SHARED_MEMORY_MMAP=0)
endif ()
if (WAMR_BUILD_THREAD_MGR EQUAL 1)
message (" Thread manager enabled")
endif ()
@ -337,6 +343,9 @@ endif ()
if (DEFINED WAMR_BH_VPRINTF)
add_definitions (-DBH_VPRINTF=${WAMR_BH_VPRINTF})
endif ()
if (DEFINED WAMR_BH_LOG)
add_definitions (-DBH_LOG=${WAMR_BH_LOG})
endif ()
if (WAMR_DISABLE_APP_ENTRY EQUAL 1)
message (" WAMR application entry functions excluded")
endif ()
@ -420,11 +429,19 @@ if (WAMR_BUILD_STATIC_PGO EQUAL 1)
add_definitions (-DWASM_ENABLE_STATIC_PGO=1)
message (" AOT static PGO enabled")
endif ()
if (WAMR_DISABLE_WRITE_GS_BASE EQUAL 1)
add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1)
message (" Write linear memory base addr to x86 GS register disabled")
elseif (WAMR_BUILD_TARGET STREQUAL "X86_64"
if (WAMR_BUILD_TARGET STREQUAL "X86_64"
AND WAMR_BUILD_PLATFORM STREQUAL "linux")
if (WAMR_DISABLE_WRITE_GS_BASE EQUAL 1)
# disabled by user
set (DISABLE_WRITE_GS_BASE 1)
elseif (WAMR_DISABLE_WRITE_GS_BASE EQUAL 0)
# enabled by user
set (DISABLE_WRITE_GS_BASE 0)
elseif (CMAKE_CROSSCOMPILING)
# disabled in cross compilation environment
set (DISABLE_WRITE_GS_BASE 1)
else ()
# auto-detected by the compiler
set (TEST_WRGSBASE_SOURCE "${CMAKE_BINARY_DIR}/test_wrgsbase.c")
file (WRITE "${TEST_WRGSBASE_SOURCE}" "
#include <stdio.h>
@ -443,9 +460,18 @@ elseif (WAMR_BUILD_TARGET STREQUAL "X86_64"
CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)
#message("${TEST_WRGSBASE_COMPILED}, ${TEST_WRGSBASE_RESULT}")
if (NOT TEST_WRGSBASE_RESULT EQUAL 0)
if (TEST_WRGSBASE_RESULT EQUAL 0)
set (DISABLE_WRITE_GS_BASE 0)
else ()
set (DISABLE_WRITE_GS_BASE 1)
endif ()
endif ()
if (DISABLE_WRITE_GS_BASE EQUAL 1)
add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1)
message (" Write linear memory base addr to x86 GS register disabled")
else ()
add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=0)
message (" Write linear memory base addr to x86 GS register enabled")
endif ()
endif ()
if (WAMR_CONFIGUABLE_BOUNDS_CHECKS EQUAL 1)
@ -456,20 +482,19 @@ if (WAMR_BUILD_LINUX_PERF EQUAL 1)
add_definitions (-DWASM_ENABLE_LINUX_PERF=1)
message (" Linux perf support enabled")
endif ()
if (NOT DEFINED WAMR_BUILD_QUICK_AOT_ENTRY)
if (WAMR_BUILD_AOT EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
if (NOT DEFINED WAMR_BUILD_QUICK_AOT_ENTRY)
# Enable quick aot/jit entries by default
set (WAMR_BUILD_QUICK_AOT_ENTRY 1)
endif ()
if (WAMR_BUILD_QUICK_AOT_ENTRY EQUAL 1)
endif ()
if (WAMR_BUILD_QUICK_AOT_ENTRY EQUAL 1)
add_definitions (-DWASM_ENABLE_QUICK_AOT_ENTRY=1)
message (" Quick AOT/JIT entries enabled")
else ()
else ()
add_definitions (-DWASM_ENABLE_QUICK_AOT_ENTRY=0)
message (" Quick AOT/JIT entries disabled")
endif ()
if (APPLE)
# On recent macOS versions, by default, the size of page zero is 4GB.
# Shrink it to make MAP_32BIT mmap can work.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-pagezero_size,0x4000")
endif ()
else ()
# Disable quick aot/jit entries for interp and fast-jit
add_definitions (-DWASM_ENABLE_QUICK_AOT_ENTRY=0)
endif ()

View File

@ -231,6 +231,17 @@
#define WASM_ENABLE_LOG 1
#endif
/* When this flag is set, WAMR will not automatically
* initialize sockets on Windows platforms. The host
* application is responsible for calling WSAStartup()
* before executing WAMR code that uses sockets, and
* calling WSACleanup() after.
* This flag passes control of socket initialization from
* WAMR to the host application. */
#ifndef WASM_ENABLE_HOST_SOCKET_INIT
#define WASM_ENABLE_HOST_SOCKET_INIT 0
#endif
#ifndef WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS
#if defined(BUILD_TARGET_X86_32) || defined(BUILD_TARGET_X86_64) \
|| defined(BUILD_TARGET_AARCH64)
@ -397,7 +408,7 @@
#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
#define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
#else
#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
#define APP_THREAD_STACK_SIZE_DEFAULT (128 * 1024)
#define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
#endif
#endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
@ -510,4 +521,9 @@
#define WASM_ENABLE_QUICK_AOT_ENTRY 1
#endif
/* Disable mmap based shared memory by default */
#ifndef WASM_ENABLE_SHARED_MEMORY_MMAP
#define WASM_ENABLE_SHARED_MEMORY_MMAP 0
#endif
#endif /* end of _CONFIG_H_ */

View File

@ -66,15 +66,15 @@ exchange_uint32(uint8 *p_data)
}
static void
exchange_uint64(uint8 *pData)
exchange_uint64(uint8 *p_data)
{
uint32 value;
value = *(uint32 *)pData;
*(uint32 *)pData = *(uint32 *)(pData + 4);
*(uint32 *)(pData + 4) = value;
exchange_uint32(pData);
exchange_uint32(pData + 4);
value = *(uint32 *)p_data;
*(uint32 *)p_data = *(uint32 *)(p_data + 4);
*(uint32 *)(p_data + 4) = value;
exchange_uint32(p_data);
exchange_uint32(p_data + 4);
}
static union {
@ -214,6 +214,8 @@ GET_U16_FROM_ADDR(const uint8 *p)
p += sizeof(type); \
} while (0)
/* NOLINTBEGIN, disable lint for this region with clang-tidy */
#define read_byte_array(p, p_end, addr, len) \
do { \
CHECK_BUF(p, p_end, len); \
@ -236,6 +238,8 @@ GET_U16_FROM_ADDR(const uint8 *p)
#define read_uint32(p, p_end, res) TEMPLATE_READ(p, p_end, res, uint32)
#define read_uint64(p, p_end, res) TEMPLATE_READ(p, p_end, res, uint64)
/* NOLINTEND */
/* Legal values for bin_type */
#define BIN_TYPE_ELF32L 0 /* 32-bit little endian */
#define BIN_TYPE_ELF32B 1 /* 32-bit big endian */
@ -1975,6 +1979,12 @@ str2uint64(const char *buf, uint64 *p_res)
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
static bool
is_text_section(const char *section_name)
{
return !strcmp(section_name, ".text") || !strcmp(section_name, ".ltext");
}
static bool
do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
char *error_buf, uint32 error_buf_size)
@ -2063,7 +2073,7 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
symbol_addr = module->func_ptrs[func_index];
}
#endif
else if (!strcmp(symbol, ".text")) {
else if (is_text_section(symbol)) {
symbol_addr = module->code;
}
else if (!strcmp(symbol, ".data") || !strcmp(symbol, ".sdata")
@ -2235,7 +2245,7 @@ do_data_relocation(AOTModule *module, AOTRelocationGroup *group,
for (i = 0; i < group->relocation_count; i++, relocation++) {
symbol = relocation->symbol_name;
if (!strcmp(symbol, ".text")) {
if (is_text_section(symbol)) {
symbol_addr = module->code;
}
#if WASM_ENABLE_STATIC_PGO != 0
@ -2696,6 +2706,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
if (!strcmp(group->section_name, ".rel.text")
|| !strcmp(group->section_name, ".rela.text")
|| !strcmp(group->section_name, ".rel.ltext")
|| !strcmp(group->section_name, ".rela.ltext")
|| !strcmp(group->section_name, ".rela.literal")
#ifdef BH_PLATFORM_WINDOWS
|| !strcmp(group->section_name, ".text")
@ -3126,8 +3138,7 @@ resolve_execute_mode(const uint8 *buf, uint32 size, bool *p_mode,
p += 8;
while (p < p_end) {
read_uint32(p, p_end, section_type);
if (section_type <= AOT_SECTION_TYPE_SIGANATURE
|| section_type == AOT_SECTION_TYPE_TARGET_INFO) {
if (section_type <= AOT_SECTION_TYPE_SIGANATURE) {
read_uint32(p, p_end, section_size);
CHECK_BUF(p, p_end, section_size);
if (section_type == AOT_SECTION_TYPE_TARGET_INFO) {
@ -3142,7 +3153,7 @@ resolve_execute_mode(const uint8 *buf, uint32 size, bool *p_mode,
break;
}
}
else if (section_type > AOT_SECTION_TYPE_SIGANATURE) {
else { /* section_type > AOT_SECTION_TYPE_SIGANATURE */
set_error_buf(error_buf, error_buf_size,
"resolve execute mode failed");
break;

View File

@ -340,6 +340,9 @@ tables_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
static void
memories_deinstantiate(AOTModuleInstance *module_inst)
{
#ifdef WASM_LINEAR_MEMORY_MMAP
uint64 map_size;
#endif
uint32 i;
AOTMemoryInstance *memory_inst;
@ -362,14 +365,21 @@ memories_deinstantiate(AOTModuleInstance *module_inst)
if (memory_inst->memory_data) {
#ifndef OS_ENABLE_HW_BOUND_CHECK
#ifdef WASM_LINEAR_MEMORY_MMAP
if (shared_memory_is_shared(memory_inst)) {
map_size = (uint64)memory_inst->num_bytes_per_page
* memory_inst->max_page_count;
wasm_munmap_linear_memory(memory_inst->memory_data,
map_size, map_size);
}
else
#endif
wasm_runtime_free(memory_inst->memory_data);
#else
#ifdef BH_PLATFORM_WINDOWS
os_mem_decommit(memory_inst->memory_data,
memory_inst->num_bytes_per_page
* memory_inst->cur_page_count);
#endif
os_munmap(memory_inst->memory_data, 8 * (uint64)BH_GB);
map_size = (uint64)memory_inst->num_bytes_per_page
* memory_inst->cur_page_count;
wasm_munmap_linear_memory(memory_inst->memory_data, map_size,
8 * (uint64)BH_GB);
#endif
}
}
@ -392,10 +402,9 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
uint32 heap_offset = num_bytes_per_page * init_page_count;
uint64 memory_data_size, max_memory_data_size;
uint8 *p = NULL, *global_addr;
#ifdef OS_ENABLE_HW_BOUND_CHECK
uint8 *mapped_mem;
uint64 map_size = 8 * (uint64)BH_GB;
uint64 page_size = os_getpagesize();
#ifdef WASM_LINEAR_MEMORY_MMAP
uint8 *mapped_mem = NULL;
uint64 map_size;
#endif
#if WASM_ENABLE_SHARED_MEMORY != 0
@ -519,15 +528,25 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
#ifndef OS_ENABLE_HW_BOUND_CHECK
#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
#if WASM_ENABLE_SHARED_MEMORY_MMAP != 0
map_size = max_memory_data_size;
if (max_memory_data_size > 0
&& !(p = mapped_mem =
wasm_mmap_linear_memory(map_size, &max_memory_data_size,
error_buf, error_buf_size))) {
return NULL;
}
#else
/* Allocate maximum memory size when memory is shared */
if (max_memory_data_size > 0
&& !(p = runtime_malloc(max_memory_data_size, error_buf,
error_buf_size))) {
return NULL;
}
#endif
}
else
#endif
#endif /* end of WASM_ENABLE_SHARED_MEMORY != 0 */
{
/* Allocate initial memory size when memory is not shared */
if (memory_data_size > 0
@ -537,42 +556,17 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
}
}
#else /* else of OS_ENABLE_HW_BOUND_CHECK */
memory_data_size = (memory_data_size + page_size - 1) & ~(page_size - 1);
/* Totally 8G is mapped, the opcode load/store address range is 0 to 8G:
* ea = i + memarg.offset
* both i and memarg.offset are u32 in range 0 to 4G
* so the range of ea is 0 to 8G
*/
if (!(p = mapped_mem = os_mmap(NULL, map_size, MMAP_PROT_NONE,
MMAP_MAP_NONE, os_get_invalid_handle()))) {
map_size = 8 * (uint64)BH_GB;
if (!(p = mapped_mem = wasm_mmap_linear_memory(
map_size, &memory_data_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
return NULL;
}
#ifdef BH_PLATFORM_WINDOWS
if (!os_mem_commit(p, memory_data_size, MMAP_PROT_READ | MMAP_PROT_WRITE)) {
set_error_buf(error_buf, error_buf_size, "commit memory failed");
os_munmap(mapped_mem, map_size);
return NULL;
}
#endif
if (os_mprotect(p, memory_data_size, MMAP_PROT_READ | MMAP_PROT_WRITE)
!= 0) {
set_error_buf(error_buf, error_buf_size, "mprotect memory failed");
#ifdef BH_PLATFORM_WINDOWS
os_mem_decommit(p, memory_data_size);
#endif
os_munmap(mapped_mem, map_size);
return NULL;
}
/* Newly allocated pages are filled with zero by the OS, we don't fill it
* again here */
if (memory_data_size > UINT32_MAX)
memory_data_size = UINT32_MAX;
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
memory_inst->module_type = Wasm_Module_AoT;
@ -623,16 +617,15 @@ fail2:
if (heap_size > 0)
wasm_runtime_free(memory_inst->heap_handle);
fail1:
#ifndef OS_ENABLE_HW_BOUND_CHECK
#ifdef WASM_LINEAR_MEMORY_MMAP
if (mapped_mem)
wasm_munmap_linear_memory(mapped_mem, memory_data_size, map_size);
else
#endif
{
if (memory_inst->memory_data)
wasm_runtime_free(memory_inst->memory_data);
#else
#ifdef BH_PLATFORM_WINDOWS
if (memory_inst->memory_data)
os_mem_decommit(p, memory_data_size);
#endif
os_munmap(mapped_mem, map_size);
#endif
}
memory_inst->memory_data = NULL;
return NULL;
}
@ -1186,6 +1179,10 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
"failed to allocate bitmaps");
goto fail;
}
for (i = 0; i < module->mem_init_data_count; i++) {
if (!module->mem_init_data_list[i]->is_passive)
bh_bitmap_set_bit(common->data_dropped, i);
}
}
#endif
#if WASM_ENABLE_REF_TYPES != 0
@ -1197,6 +1194,10 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
"failed to allocate bitmaps");
goto fail;
}
for (i = 0; i < module->table_init_data_count; i++) {
if (wasm_elem_is_active(module->table_init_data_list[i]->mode))
bh_bitmap_set_bit(common->elem_dropped, i);
}
}
#endif
@ -1433,14 +1434,10 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
#if WASM_ENABLE_QUICK_AOT_ENTRY != 0
/* Quick call if the quick aot entry is registered */
if (!signature && func_type->quick_aot_entry) {
void (*invoke_native)(
void *func_ptr, uint8 ret_type, void *exec_env, uint32 *argv,
uint32 *argv_ret) = func_type->quick_aot_entry;
invoke_native(func_ptr,
func_type->result_count > 0
? func_type->types[func_type->param_count]
: VALUE_TYPE_VOID,
exec_env, argv, argv_ret);
void (*invoke_native)(void *func_ptr, void *exec_env, uint32 *argv,
uint32 *argv_ret) =
func_type->quick_aot_entry;
invoke_native(func_ptr, exec_env, argv, argv_ret);
ret = !aot_copy_exception(module_inst, NULL);
}
else
@ -1477,9 +1474,28 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
(void)jmpbuf_node_pop;
return ret;
}
#define invoke_native_internal invoke_native_with_hw_bound_check
#define invoke_native_internal invoke_native_with_hw_bound_check /* NOLINT */
#else /* else of OS_ENABLE_HW_BOUND_CHECK */
#define invoke_native_internal wasm_runtime_invoke_native
static inline bool
invoke_native_internal(WASMExecEnv *exec_env, void *func_ptr,
const WASMType *func_type, const char *signature,
void *attachment, uint32 *argv, uint32 argc,
uint32 *argv_ret)
{
#if WASM_ENABLE_QUICK_AOT_ENTRY != 0
/* Quick call if the quick aot entry is registered */
if (!signature && func_type->quick_aot_entry) {
AOTModuleInstance *module_inst =
(AOTModuleInstance *)exec_env->module_inst;
void (*invoke_native)(void *func_ptr, void *exec_env, uint32 *argv,
uint32 *argv_ret) = func_type->quick_aot_entry;
invoke_native(func_ptr, exec_env, argv, argv_ret);
return !aot_copy_exception(module_inst, NULL);
}
#endif
return wasm_runtime_invoke_native(exec_env, func_ptr, func_type, signature,
attachment, argv, argc, argv_ret);
}
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
bool
@ -2613,6 +2629,7 @@ aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
{
AOTTableInstance *tbl_inst;
AOTTableInitData *tbl_seg;
uint32 *tbl_seg_elems = NULL, tbl_seg_len = 0;
const AOTModule *module = (AOTModule *)module_inst->module;
tbl_inst = module_inst->tables[tbl_idx];
@ -2621,7 +2638,15 @@ aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
tbl_seg = module->table_init_data_list[tbl_seg_idx];
bh_assert(tbl_seg);
if (offset_len_out_of_bounds(src_offset, length, tbl_seg->func_index_count)
if (!bh_bitmap_get_bit(
((AOTModuleInstanceExtra *)module_inst->e)->common.elem_dropped,
tbl_seg_idx)) {
/* table segment isn't dropped */
tbl_seg_elems = tbl_seg->func_indexes;
tbl_seg_len = tbl_seg->func_index_count;
}
if (offset_len_out_of_bounds(src_offset, length, tbl_seg_len)
|| offset_len_out_of_bounds(dst_offset, length, tbl_inst->cur_size)) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
@ -2631,22 +2656,10 @@ aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
return;
}
if (bh_bitmap_get_bit(
((AOTModuleInstanceExtra *)module_inst->e)->common.elem_dropped,
tbl_seg_idx)) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
if (!wasm_elem_is_passive(tbl_seg->mode)) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
bh_memcpy_s((uint8 *)tbl_inst + offsetof(AOTTableInstance, elems)
+ dst_offset * sizeof(uint32),
(tbl_inst->cur_size - dst_offset) * sizeof(uint32),
tbl_seg->func_indexes + src_offset, length * sizeof(uint32));
tbl_seg_elems + src_offset, length * sizeof(uint32));
}
void
@ -2814,7 +2827,7 @@ aot_alloc_frame(WASMExecEnv *exec_env, uint32 func_index)
}
#if WASM_ENABLE_PERF_PROFILING != 0
frame->time_started = os_time_get_boot_microsecond();
frame->time_started = os_time_thread_cputime_us();
frame->func_perf_prof_info = func_perf_prof;
#endif
@ -2832,9 +2845,13 @@ aot_free_frame(WASMExecEnv *exec_env)
AOTFrame *prev_frame = cur_frame->prev_frame;
#if WASM_ENABLE_PERF_PROFILING != 0
cur_frame->func_perf_prof_info->total_exec_time +=
os_time_get_boot_microsecond() - cur_frame->time_started;
uint64 elapsed = os_time_thread_cputime_us() - cur_frame->time_started;
cur_frame->func_perf_prof_info->total_exec_time += elapsed;
cur_frame->func_perf_prof_info->total_exec_cnt++;
/* parent function */
if (prev_frame)
prev_frame->func_perf_prof_info->children_exec_time += elapsed;
#endif
wasm_exec_env_free_wasm_frame(exec_env, cur_frame);
@ -2971,22 +2988,65 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst)
os_printf("Performance profiler data:\n");
for (i = 0; i < total_func_count; i++, perf_prof++) {
if (perf_prof->total_exec_cnt == 0)
continue;
func_name = get_func_name_from_index(module_inst, i);
if (func_name)
os_printf(
" func %s, execution time: %.3f ms, execution count: %" PRIu32
" times\n",
" times, children execution time: %.3f ms\n",
func_name, perf_prof->total_exec_time / 1000.0f,
perf_prof->total_exec_cnt);
perf_prof->total_exec_cnt,
perf_prof->children_exec_time / 1000.0f);
else
os_printf(" func %" PRIu32
", execution time: %.3f ms, execution count: %" PRIu32
" times\n",
" times, children execution time: %.3f ms\n",
i, perf_prof->total_exec_time / 1000.0f,
perf_prof->total_exec_cnt);
perf_prof->total_exec_cnt,
perf_prof->children_exec_time / 1000.0f);
}
}
double
aot_summarize_wasm_execute_time(const AOTModuleInstance *inst)
{
double ret = 0;
AOTModule *module = (AOTModule *)inst->module;
uint32 total_func_count = module->import_func_count + module->func_count, i;
for (i = 0; i < total_func_count; i++) {
AOTFuncPerfProfInfo *perf_prof =
(AOTFuncPerfProfInfo *)inst->func_perf_profilings + i;
ret += (perf_prof->total_exec_time - perf_prof->children_exec_time)
/ 1000.0f;
}
return ret;
}
double
aot_get_wasm_func_exec_time(const AOTModuleInstance *inst,
const char *func_name)
{
AOTModule *module = (AOTModule *)inst->module;
uint32 total_func_count = module->import_func_count + module->func_count, i;
for (i = 0; i < total_func_count; i++) {
const char *name_in_wasm = get_func_name_from_index(inst, i);
if (name_in_wasm && strcmp(func_name, name_in_wasm) == 0) {
AOTFuncPerfProfInfo *perf_prof =
(AOTFuncPerfProfInfo *)inst->func_perf_profilings + i;
return (perf_prof->total_exec_time - perf_prof->children_exec_time)
/ 1000.0f;
}
}
return -1.0;
}
#endif /* end of WASM_ENABLE_PERF_PROFILING */
#if WASM_ENABLE_STATIC_PGO != 0

View File

@ -286,6 +286,8 @@ typedef struct AOTFuncPerfProfInfo {
uint64 total_exec_time;
/* total execution count */
uint32 total_exec_cnt;
/* children execution time */
uint64 children_exec_time;
} AOTFuncPerfProfInfo;
/* AOT auxiliary call stack */
@ -613,6 +615,13 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
void
aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
double
aot_summarize_wasm_execute_time(const AOTModuleInstance *inst);
double
aot_get_wasm_func_exec_time(const AOTModuleInstance *inst,
const char *func_name);
const uint8 *
aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);

View File

@ -163,7 +163,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
error_buf, error_buf_size,
"AOT module load failed: "
"relocation truncated to fit R_X86_64_PC32 failed. "
"Try using wamrc with --size-level=1 option.");
"Try using wamrc with --size-level=1 or 0 option.");
return false;
}
@ -196,7 +196,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
snprintf(buf, sizeof(buf),
"AOT module load failed: "
"relocation truncated to fit %s failed. "
"Try using wamrc with --size-level=1 option.",
"Try using wamrc with --size-level=1 or 0 option.",
reloc_type == R_X86_64_32 ? "R_X86_64_32"
: "R_X86_64_32S");
set_error_buf(error_buf, error_buf_size, buf);
@ -236,7 +236,8 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
target_addr -= sizeof(int32);
#endif
if ((int32)target_addr != target_addr) {
set_error_buf(error_buf, error_buf_size,
set_error_buf(
error_buf, error_buf_size,
"AOT module load failed: "
"relocation truncated to fit "
#if !defined(BH_PLATFORM_WINDOWS)
@ -244,7 +245,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
#else
"IMAGE_REL_AMD64_32 failed."
#endif
"Try using wamrc with --size-level=1 option.");
"Try using wamrc with --size-level=1 or 0 option.");
return false;
}
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;

View File

@ -100,6 +100,12 @@ get_section64(Elf64_Ehdr *eh, Elf64_Shdr *section_header)
return buf + section_header->sh_offset;
}
static bool
is_text_section(const char *section_name)
{
return !strcmp(section_name, ".text") || !strcmp(section_name, ".ltext");
}
bool
get_text_section(void *buf, uint64_t *offset, uint64_t *size)
{
@ -107,6 +113,7 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
uint32 i;
char *sh_str;
/* Assumption: Only one of .text or .ltext is non-empty. */
if (is64Bit(buf)) {
Elf64_Ehdr *eh = (Elf64_Ehdr *)buf;
Elf64_Shdr **sh_table =
@ -115,16 +122,18 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
read_section_header_table64(eh, sh_table);
sh_str = get_section64(eh, sh_table[eh->e_shstrndx]);
for (i = 0; i < eh->e_shnum; i++) {
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
if (is_text_section(sh_str + sh_table[i]->sh_name)) {
*offset = sh_table[i]->sh_offset;
*size = sh_table[i]->sh_size;
sh_table[i]->sh_addr =
(Elf64_Addr)(uintptr_t)((char *)buf
+ sh_table[i]->sh_offset);
ret = true;
if (*size > 0) {
break;
}
}
}
wasm_runtime_free(sh_table);
}
}
@ -136,16 +145,18 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
read_section_header_table(eh, sh_table);
sh_str = get_section(eh, sh_table[eh->e_shstrndx]);
for (i = 0; i < eh->e_shnum; i++) {
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
if (is_text_section(sh_str + sh_table[i]->sh_name)) {
*offset = sh_table[i]->sh_offset;
*size = sh_table[i]->sh_size;
sh_table[i]->sh_addr =
(Elf32_Addr)(uintptr_t)((char *)buf
+ sh_table[i]->sh_offset);
ret = true;
if (*size > 0) {
break;
}
}
}
wasm_runtime_free(sh_table);
}
}

View File

@ -46,7 +46,7 @@ static union {
char b;
} __ue = { .a = 1 };
#define is_little_endian() (__ue.b == 1)
#define is_little_endian() (__ue.b == 1) /* NOLINT */
/**
* Implementation of wasm_application_execute_main()

View File

@ -1924,11 +1924,13 @@ wasm_frame_func_offset(const wasm_frame_t *frame)
void
wasm_frame_vec_clone_internal(Vector *src, Vector *out)
{
bh_assert(src->num_elems != 0 && src->data);
if (src->num_elems == 0) {
bh_vector_destroy(out);
return;
}
bh_vector_destroy(out);
if (!bh_vector_init(out, src->num_elems, sizeof(WASMCApiFrame), false)) {
bh_vector_destroy(out);
if (!bh_vector_destroy(out)
|| !bh_vector_init(out, src->num_elems, sizeof(WASMCApiFrame), false)) {
return;
}
@ -2292,7 +2294,7 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
(uint8 *)module_ex->binary->data, (uint32)module_ex->binary->size,
error_buf, (uint32)sizeof(error_buf));
if (!(module_ex->module_comm_rt)) {
LOG_ERROR(error_buf);
LOG_ERROR("%s", error_buf);
goto free_vec;
}
@ -2365,7 +2367,7 @@ wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary)
}
else {
ret = false;
LOG_VERBOSE(error_buf);
LOG_VERBOSE("%s", error_buf);
}
return ret;
@ -3357,7 +3359,7 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params,
wasm_runtime_set_exception(func->inst_comm_rt, NULL);
if (!wasm_runtime_call_wasm(exec_env, func_comm_rt, argc, argv)) {
if (wasm_runtime_get_exception(func->inst_comm_rt)) {
LOG_DEBUG(wasm_runtime_get_exception(func->inst_comm_rt));
LOG_DEBUG("%s", wasm_runtime_get_exception(func->inst_comm_rt));
goto failed;
}
}
@ -5042,7 +5044,7 @@ failed:
*trap = wasm_trap_new(store, &message);
wasm_byte_vec_delete(&message);
}
LOG_DEBUG(error_buf);
LOG_DEBUG("%s", error_buf);
wasm_instance_delete_internal(instance);
return NULL;
}

File diff suppressed because it is too large Load Diff

View File

@ -785,6 +785,7 @@ align_ptr(const uint8 *p, uint32 b)
return false; \
} while (0)
/* NOLINTNEXTLINE */
#define read_uint16(p, p_end, res) \
do { \
p = (uint8 *)align_ptr(p, sizeof(uint16)); \
@ -793,6 +794,7 @@ align_ptr(const uint8 *p, uint32 b)
p += sizeof(uint16); \
} while (0)
/* NOLINTNEXTLINE */
#define read_uint32(p, p_end, res) \
do { \
p = (uint8 *)align_ptr(p, sizeof(uint32)); \
@ -1690,8 +1692,43 @@ wasm_runtime_dump_perf_profiling(WASMModuleInstanceCommon *module_inst)
}
#endif
}
double
wasm_runtime_sum_wasm_exec_time(WASMModuleInstanceCommon *inst)
{
#if WASM_ENABLE_INTERP != 0
if (inst->module_type == Wasm_Module_Bytecode)
return wasm_summarize_wasm_execute_time((WASMModuleInstance *)inst);
#endif
#if WASM_ENABLE_AOT != 0
if (inst->module_type == Wasm_Module_AoT)
return aot_summarize_wasm_execute_time((AOTModuleInstance *)inst);
#endif
return 0.0;
}
double
wasm_runtime_get_wasm_func_exec_time(WASMModuleInstanceCommon *inst,
const char *func_name)
{
#if WASM_ENABLE_INTERP != 0
if (inst->module_type == Wasm_Module_Bytecode)
return wasm_get_wasm_func_exec_time((WASMModuleInstance *)inst,
func_name);
#endif
#if WASM_ENABLE_AOT != 0
if (inst->module_type == Wasm_Module_AoT)
return aot_get_wasm_func_exec_time((AOTModuleInstance *)inst,
func_name);
#endif
return 0.0;
}
#endif /* WASM_ENABLE_PERF_PROFILING != 0 */
WASMModuleInstanceCommon *
wasm_runtime_get_module_inst(WASMExecEnv *exec_env)
{
@ -2870,7 +2907,8 @@ copy_string_array(const char *array[], uint32 array_size, char **buf_ptr,
/* We add +1 to generate null-terminated array of strings */
total_size = sizeof(char *) * ((uint64)array_size + 1);
if (total_size >= UINT32_MAX
|| (total_size > 0 && !(list = wasm_runtime_malloc((uint32)total_size)))
/* total_size must be larger than 0, don' check it again */
|| !(list = wasm_runtime_malloc((uint32)total_size))
|| buf_size >= UINT32_MAX
|| (buf_size > 0 && !(buf = wasm_runtime_malloc((uint32)buf_size)))) {
@ -3501,7 +3539,7 @@ static union {
char b;
} __ue = { .a = 1 };
#define is_little_endian() (__ue.b == 1)
#define is_little_endian() (__ue.b == 1) /* NOLINT */
bool
wasm_runtime_register_natives(const char *module_name,
@ -4410,6 +4448,7 @@ typedef int64 (*Int64FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
typedef int32 (*Int32FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
typedef void (*VoidFuncPtr)(GenericFunctionPointer, uint64 *, uint64);
/* NOLINTBEGIN */
static volatile Float64FuncPtr invokeNative_Float64 =
(Float64FuncPtr)(uintptr_t)invokeNative;
static volatile Float32FuncPtr invokeNative_Float32 =
@ -4425,6 +4464,7 @@ static volatile VoidFuncPtr invokeNative_Void =
typedef v128 (*V128FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
static V128FuncPtr invokeNative_V128 = (V128FuncPtr)(uintptr_t)invokeNative;
#endif
/* NOLINTEND */
#if defined(_WIN32) || defined(_WIN32_)
#define MAX_REG_FLOATS 4
@ -6229,3 +6269,67 @@ wasm_runtime_set_linux_perf(bool flag)
enable_linux_perf = flag;
}
#endif
#ifdef WASM_LINEAR_MEMORY_MMAP
void
wasm_munmap_linear_memory(void *mapped_mem, uint64 commit_size, uint64 map_size)
{
#ifdef BH_PLATFORM_WINDOWS
os_mem_decommit(mapped_mem, commit_size);
#else
(void)commit_size;
#endif
os_munmap(mapped_mem, map_size);
}
void *
wasm_mmap_linear_memory(uint64_t map_size, uint64 *io_memory_data_size,
char *error_buf, uint32 error_buf_size)
{
uint64 page_size = os_getpagesize();
void *mapped_mem = NULL;
uint64 memory_data_size;
bh_assert(io_memory_data_size);
memory_data_size =
(*io_memory_data_size + page_size - 1) & ~(page_size - 1);
if (memory_data_size > UINT32_MAX)
memory_data_size = UINT32_MAX;
if (!(mapped_mem = os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE,
os_get_invalid_handle()))) {
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
goto fail1;
}
#ifdef BH_PLATFORM_WINDOWS
if (memory_data_size > 0
&& !os_mem_commit(mapped_mem, memory_data_size,
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
set_error_buf(error_buf, error_buf_size, "commit memory failed");
os_munmap(mapped_mem, map_size);
goto fail1;
}
#endif
if (os_mprotect(mapped_mem, memory_data_size,
MMAP_PROT_READ | MMAP_PROT_WRITE)
!= 0) {
set_error_buf(error_buf, error_buf_size, "mprotect memory failed");
goto fail2;
}
/* Newly allocated pages are filled with zero by the OS, we don't fill it
* again here */
*io_memory_data_size = memory_data_size;
return mapped_mem;
fail2:
wasm_munmap_linear_memory(mapped_mem, memory_data_size, map_size);
fail1:
return NULL;
}
#endif

View File

@ -320,6 +320,11 @@ LOAD_I16(void *addr)
#define SHARED_MEMORY_UNLOCK(memory) (void)0
#endif
#if defined(OS_ENABLE_HW_BOUND_CHECK) \
|| (WASM_ENABLE_SHARED_MEMORY != 0 && WASM_ENABLE_SHARED_MEMORY_MMAP != 0)
#define WASM_LINEAR_MEMORY_MMAP
#endif
typedef struct WASMModuleCommon {
/* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode, and this structure should
@ -1093,6 +1098,14 @@ wasm_runtime_quick_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
void
wasm_runtime_show_app_heap_corrupted_prompt();
void
wasm_munmap_linear_memory(void *mapped_mem, uint64 commit_size,
uint64 map_size);
void *
wasm_mmap_linear_memory(uint64_t map_size, uint64 *io_memory_data_size,
char *error_buf, uint32 error_buf_size);
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
void
wasm_runtime_destroy_custom_sections(WASMCustomSection *section_list);

View File

@ -176,7 +176,8 @@ acquire_wait_info(void *address, AtomicWaitNode *wait_node)
AtomicWaitInfo *wait_info = NULL;
bh_list_status ret;
if (address)
bh_assert(address != NULL);
wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address);
if (!wait_node) {

View File

@ -35,6 +35,8 @@ typedef union WASMSuspendFlags {
#define WASM_SUSPEND_FLAGS_FETCH_AND(s_flags, val) \
BH_ATOMIC_32_FETCH_AND(s_flags.flags, val)
#define WASM_SUSPEND_FLAG_INHERIT_MASK (~WASM_SUSPEND_FLAG_BLOCKING)
#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0
#define WASM_SUSPEND_FLAGS_LOCK(lock) (void)0
#define WASM_SUSPEND_FLAGS_UNLOCK(lock) (void)0

View File

@ -25,6 +25,7 @@
} \
} while (0)
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
static bool
check_utf8_str(const uint8 *str, uint32 len)
{
@ -89,6 +90,7 @@ check_utf8_str(const uint8 *str, uint32 len)
}
return (p == p_end);
}
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 */
/* Internal function in object file */
typedef struct AOTObjectFunc {
@ -652,7 +654,8 @@ get_relocations_size(AOTObjectData *obj_data,
/* ignore the relocations to aot_func_internal#n in text section
for windows platform since they will be applied in
aot_emit_text_section */
if (!strcmp(relocation_group->section_name, ".text")
if ((!strcmp(relocation_group->section_name, ".text")
|| !strcmp(relocation_group->section_name, ".ltext"))
&& !strncmp(relocation->symbol_name, AOT_FUNC_INTERNAL_PREFIX,
strlen(AOT_FUNC_INTERNAL_PREFIX))
&& ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6)
@ -1111,6 +1114,7 @@ static union {
EMIT_BUF(s, str_len); \
} while (0)
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
static bool
read_leb(uint8 **p_buf, const uint8 *buf_end, uint32 maxbits, bool sign,
uint64 *p_result)
@ -1309,6 +1313,7 @@ get_name_section_size(AOTCompData *comp_data)
fail:
return 0;
}
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 */
static uint32
get_custom_sections_size(AOTCompContext *comp_ctx, AOTCompData *comp_data)
@ -1815,7 +1820,8 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
for (i = 0; i < obj_data->relocation_group_count;
i++, relocation_group++) {
/* relocation in text section */
if (!strcmp(relocation_group->section_name, ".text")) {
if ((!strcmp(relocation_group->section_name, ".text")
|| !strcmp(relocation_group->section_name, ".ltext"))) {
relocation = relocation_group->relocations;
relocation_count = relocation_group->relocation_count;
for (j = 0; j < relocation_count; j++) {
@ -2065,6 +2071,7 @@ aot_emit_native_symbol(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
return true;
}
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
static bool
aot_emit_name_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
AOTCompData *comp_data, AOTCompContext *comp_ctx)
@ -2090,6 +2097,7 @@ aot_emit_name_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
LOG_DEBUG("emit name section");
return true;
}
#endif
static bool
aot_emit_custom_sections(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
@ -2374,17 +2382,19 @@ aot_resolve_text(AOTObjectData *obj_data)
while (
!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) {
if ((name = (char *)LLVMGetSectionName(sec_itr))) {
if (!strcmp(name, ".text")) {
if (!strcmp(name, ".text") || !strcmp(name, ".ltext")) {
obj_data->text = (char *)LLVMGetSectionContents(sec_itr);
obj_data->text_size = (uint32)LLVMGetSectionSize(sec_itr);
}
else if (!strcmp(name, ".text.unlikely.")) {
else if (!strcmp(name, ".text.unlikely.")
|| !strcmp(name, ".ltext.unlikely.")) {
obj_data->text_unlikely =
(char *)LLVMGetSectionContents(sec_itr);
obj_data->text_unlikely_size =
(uint32)LLVMGetSectionSize(sec_itr);
}
else if (!strcmp(name, ".text.hot.")) {
else if (!strcmp(name, ".text.hot.")
|| !strcmp(name, ".ltext.hot.")) {
obj_data->text_hot =
(char *)LLVMGetSectionContents(sec_itr);
obj_data->text_hot_size =
@ -2903,11 +2913,13 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
(char *)LLVMGetSectionName(contain_section);
LLVMDisposeSectionIterator(contain_section);
if (!strcmp(contain_section_name, ".text.unlikely.")) {
if (!strcmp(contain_section_name, ".text.unlikely.")
|| !strcmp(contain_section_name, ".ltext.unlikely.")) {
func->text_offset = align_uint(obj_data->text_size, 4)
+ LLVMGetSymbolAddress(sym_itr);
}
else if (!strcmp(contain_section_name, ".text.hot.")) {
else if (!strcmp(contain_section_name, ".text.hot.")
|| !strcmp(contain_section_name, ".ltext.hot.")) {
func->text_offset =
align_uint(obj_data->text_size, 4)
+ align_uint(obj_data->text_unlikely_size, 4)
@ -2939,12 +2951,14 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
(char *)LLVMGetSectionName(contain_section);
LLVMDisposeSectionIterator(contain_section);
if (!strcmp(contain_section_name, ".text.unlikely.")) {
if (!strcmp(contain_section_name, ".text.unlikely.")
|| !strcmp(contain_section_name, ".ltext.unlikely.")) {
func->text_offset_of_aot_func_internal =
align_uint(obj_data->text_size, 4)
+ LLVMGetSymbolAddress(sym_itr);
}
else if (!strcmp(contain_section_name, ".text.hot.")) {
else if (!strcmp(contain_section_name, ".text.hot.")
|| !strcmp(contain_section_name, ".ltext.hot.")) {
func->text_offset_of_aot_func_internal =
align_uint(obj_data->text_size, 4)
+ align_uint(obj_data->text_unlikely_size, 4)
@ -3205,6 +3219,12 @@ is_relocation_section_name(AOTObjectData *obj_data, char *section_name)
|| !strcmp(section_name, ".rel.text.unlikely.")
|| !strcmp(section_name, ".rela.text.hot.")
|| !strcmp(section_name, ".rel.text.hot.")
|| !strcmp(section_name, ".rela.ltext")
|| !strcmp(section_name, ".rel.ltext")
|| !strcmp(section_name, ".rela.ltext.unlikely.")
|| !strcmp(section_name, ".rel.ltext.unlikely.")
|| !strcmp(section_name, ".rela.ltext.hot.")
|| !strcmp(section_name, ".rel.ltext.hot.")
|| !strcmp(section_name, ".rela.literal")
|| !strcmp(section_name, ".rela.data")
|| !strcmp(section_name, ".rel.data")
@ -3243,7 +3263,9 @@ static bool
is_readonly_section(const char *name)
{
return !strcmp(name, ".rel.text") || !strcmp(name, ".rela.text")
|| !strcmp(name, ".rela.literal") || !strcmp(name, ".text");
|| !strcmp(name, ".rel.ltext") || !strcmp(name, ".rela.ltext")
|| !strcmp(name, ".rela.literal") || !strcmp(name, ".text")
|| !strcmp(name, ".ltext");
}
static bool
@ -3336,12 +3358,24 @@ aot_resolve_object_relocation_groups(AOTObjectData *obj_data)
|| !strcmp(relocation_group->section_name, ".rela.text.hot.")) {
relocation_group->section_name = ".rela.text";
}
else if (!strcmp(relocation_group->section_name,
".rela.ltext.unlikely.")
|| !strcmp(relocation_group->section_name,
".rela.ltext.hot.")) {
relocation_group->section_name = ".rela.ltext";
}
else if (!strcmp(relocation_group->section_name,
".rel.text.unlikely.")
|| !strcmp(relocation_group->section_name,
".rel.text.hot.")) {
relocation_group->section_name = ".rel.text";
}
else if (!strcmp(relocation_group->section_name,
".rel.ltext.unlikely.")
|| !strcmp(relocation_group->section_name,
".rel.ltext.hot.")) {
relocation_group->section_name = ".rel.ltext";
}
/*
* Relocations in read-only sections are problematic,

View File

@ -133,9 +133,10 @@ dwarf_gen_file_info(const AOTCompContext *comp_ctx)
file_name = filespec.GetFilename();
dir_name = filespec.GetDirectory();
if (file_name || dir_name) {
file_info = LLVMDIBuilderCreateFile(comp_ctx->debug_builder,
file_name, strlen(file_name),
dir_name, strlen(dir_name));
file_info = LLVMDIBuilderCreateFile(
comp_ctx->debug_builder, file_name,
file_name ? strlen(file_name) : 0, dir_name,
dir_name ? strlen(dir_name) : 0);
}
}
return file_info;
@ -298,7 +299,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
return NULL;
LLVMDIBuilderRef DIB = comp_ctx->debug_builder;
LLVMMetadataRef File = comp_ctx->debug_file;
LLVMMetadataRef File = comp_ctx->debug_file; /* a fallback */
LLVMMetadataRef ParamTypes[num_function_args + 1];
@ -315,6 +316,21 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
}
}
auto compile_unit = sc.GetCompileUnit();
auto file_spec = compile_unit.GetFileSpec();
const char *file_name = file_spec.GetFilename();
const char *dir_name = file_spec.GetDirectory();
LLVMMetadataRef file_info = NULL;
if (file_name || dir_name) {
file_info =
LLVMDIBuilderCreateFile(comp_ctx->debug_builder, file_name,
file_name ? strlen(file_name) : 0, dir_name,
dir_name ? strlen(dir_name) : 0);
}
if (file_info) {
File = file_info;
}
LLVMMetadataRef FunctionTy = LLVMDIBuilderCreateSubroutineType(
DIB, File, ParamTypes, num_function_args + 1, LLVMDIFlagZero);

View File

@ -396,9 +396,8 @@ handle_func_return(JitCompContext *cc, JitBlock *block)
#endif
#if WASM_ENABLE_PERF_PROFILING != 0
/* time_end = os_time_get_boot_microsecond() */
if (!jit_emit_callnative(cc, os_time_get_boot_microsecond, time_end, NULL,
0)) {
/* time_end = os_time_get_boot_us() */
if (!jit_emit_callnative(cc, os_time_get_boot_us, time_end, NULL, 0)) {
return false;
}
/* time_start = cur_frame->time_started */

View File

@ -88,17 +88,21 @@ fail:
}
static int
wasm_init_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 elem_idx,
wasm_init_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 seg_idx,
uint32 dst_offset, uint32 len, uint32 src_offset)
{
WASMTableInstance *tbl;
uint32 tbl_sz;
WASMTableSeg *elem;
uint32 elem_len;
WASMTableSeg *tbl_seg = inst->module->table_segments + seg_idx;
uint32 *tbl_seg_elems = NULL, tbl_seg_len = 0;
elem = inst->module->table_segments + elem_idx;
elem_len = elem->function_count;
if (offset_len_out_of_bounds(src_offset, len, elem_len))
if (!bh_bitmap_get_bit(inst->e->common.elem_dropped, seg_idx)) {
/* table segment isn't dropped */
tbl_seg_elems = tbl_seg->func_indexes;
tbl_seg_len = tbl_seg->function_count;
}
if (offset_len_out_of_bounds(src_offset, len, tbl_seg_len))
goto out_of_bounds;
tbl = inst->tables[tbl_idx];
@ -109,14 +113,10 @@ wasm_init_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 elem_idx,
if (!len)
return 0;
if (bh_bitmap_get_bit(inst->e->common.elem_dropped, elem_idx))
goto out_of_bounds;
bh_memcpy_s((uint8 *)tbl + offsetof(WASMTableInstance, elems)
+ dst_offset * sizeof(uint32),
(uint32)((tbl_sz - dst_offset) * sizeof(uint32)),
elem->func_indexes + src_offset,
(uint32)(len * sizeof(uint32)));
tbl_seg_elems + src_offset, (uint32)(len * sizeof(uint32)));
return 0;
out_of_bounds:

View File

@ -1157,11 +1157,10 @@ init_func_translation(JitCompContext *cc)
func_inst = jit_cc_new_reg_ptr(cc);
#if WASM_ENABLE_PERF_PROFILING != 0
time_started = jit_cc_new_reg_I64(cc);
/* Call os_time_get_boot_microsecond() to get time_started firstly
/* Call os_time_get_boot_us() to get time_started firstly
as there is stack frame switching below, calling native in them
may cause register spilling work inproperly */
if (!jit_emit_callnative(cc, os_time_get_boot_microsecond, time_started,
NULL, 0)) {
if (!jit_emit_callnative(cc, os_time_get_boot_us, time_started, NULL, 0)) {
return NULL;
}
#endif

View File

@ -22,12 +22,12 @@
#endif
#if defined(__GNUC__) || defined(__clang__)
#define DEPRECATED __attribute__((deprecated))
#define WASM_API_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#define WASM_API_DEPRECATED __declspec(deprecated)
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED
#define WASM_API_DEPRECATED
#endif
#ifdef __cplusplus
@ -231,7 +231,7 @@ WASM_DECLARE_OWN(engine)
*/
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(wasm_config_t*);
DEPRECATED WASM_API_EXTERN own wasm_engine_t *
WASM_API_DEPRECATED WASM_API_EXTERN own wasm_engine_t *
wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts);
// Store
@ -828,12 +828,12 @@ static inline void* wasm_val_ptr(const wasm_val_t* val) {
#endif
}
#define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}}
#define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}}
#define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}}
#define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}}
#define WASM_REF_VAL(r) {.kind = WASM_ANYREF, .of = {.ref = r}}
#define WASM_INIT_VAL {.kind = WASM_ANYREF, .of = {.ref = NULL}}
#define WASM_I32_VAL(i) {.kind = WASM_I32, .__paddings = {0}, .of = {.i32 = i}}
#define WASM_I64_VAL(i) {.kind = WASM_I64, .__paddings = {0}, .of = {.i64 = i}}
#define WASM_F32_VAL(z) {.kind = WASM_F32, .__paddings = {0}, .of = {.f32 = z}}
#define WASM_F64_VAL(z) {.kind = WASM_F64, .__paddings = {0}, .of = {.f64 = z}}
#define WASM_REF_VAL(r) {.kind = WASM_ANYREF, .__paddings = {0}, .of = {.ref = r}}
#define WASM_INIT_VAL {.kind = WASM_ANYREF, .__paddings = {0}, .of = {.ref = NULL}}
#define KILOBYTE(n) ((n) * 1024)

View File

@ -1274,6 +1274,26 @@ wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst);
/**
* Return total wasm functions' execution time in ms
*
* @param module_inst the WASM module instance to profile
*/
WASM_RUNTIME_API_EXTERN double
wasm_runtime_sum_wasm_exec_time(wasm_module_inst_t module_inst);
/**
* Return execution time in ms of a given wasm funciton with
* func_name. If the function is not found, return 0.
*
* @param module_inst the WASM module instance to profile
* @param func_name could be an export name or a name in the
* name section
*/
WASM_RUNTIME_API_EXTERN double
wasm_runtime_get_wasm_func_exec_time(wasm_module_inst_t inst,
const char *func_name);
/* wasm thread callback function type */
typedef void *(*wasm_thread_callback_t)(wasm_exec_env_t, void *);
/* wasm thread type */
@ -1587,6 +1607,9 @@ wasm_runtime_get_context(wasm_module_inst_t inst, void *key);
* host functions. It wraps an operation which possibly blocks for long
* to prepare for async termination.
*
* For simplicity, we recommend to wrap only the very minimum piece of
* the code with this. Ideally, just a single system call.
*
* eg.
*
* if (!wasm_runtime_begin_blocking_op(exec_env)) {

View File

@ -871,7 +871,7 @@ ALLOC_FRAME(WASMExecEnv *exec_env, uint32 size, WASMInterpFrame *prev_frame)
if (frame) {
frame->prev_frame = prev_frame;
#if WASM_ENABLE_PERF_PROFILING != 0
frame->time_started = os_time_get_boot_microsecond();
frame->time_started = os_time_thread_cputime_us();
#endif
}
else {
@ -887,9 +887,13 @@ FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame)
{
#if WASM_ENABLE_PERF_PROFILING != 0
if (frame->function) {
frame->function->total_exec_time +=
os_time_get_boot_microsecond() - frame->time_started;
WASMInterpFrame *prev_frame = frame->prev_frame;
uint64 elapsed = os_time_thread_cputime_us() - frame->time_started;
frame->function->total_exec_time += elapsed;
frame->function->total_exec_cnt++;
if (prev_frame && prev_frame->function)
prev_frame->function->children_exec_time += elapsed;
}
#endif
wasm_exec_env_free_wasm_frame(exec_env, frame);
@ -3654,6 +3658,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint32 tbl_idx, elem_idx;
uint32 n, s, d;
WASMTableInstance *tbl_inst;
uint32 *tbl_seg_elems = NULL, tbl_seg_len = 0;
read_leb_uint32(frame_ip, frame_ip_end, elem_idx);
bh_assert(elem_idx < module->module->table_seg_count);
@ -3667,10 +3672,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
s = (uint32)POP_I32();
d = (uint32)POP_I32();
if (offset_len_out_of_bounds(
s, n,
if (!bh_bitmap_get_bit(module->e->common.elem_dropped,
elem_idx)) {
/* table segment isn't dropped */
tbl_seg_elems =
module->module->table_segments[elem_idx]
.function_count)
.func_indexes;
tbl_seg_len =
module->module->table_segments[elem_idx]
.function_count;
}
if (offset_len_out_of_bounds(s, n, tbl_seg_len)
|| offset_len_out_of_bounds(d, n,
tbl_inst->cur_size)) {
wasm_set_exception(module,
@ -3682,30 +3695,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
break;
}
if (bh_bitmap_get_bit(module->e->common.elem_dropped,
elem_idx)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
}
if (!wasm_elem_is_passive(
module->module->table_segments[elem_idx]
.mode)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
}
bh_memcpy_s(
(uint8 *)tbl_inst
+ offsetof(WASMTableInstance, elems)
+ d * sizeof(uint32),
(uint32)((tbl_inst->cur_size - d) * sizeof(uint32)),
module->module->table_segments[elem_idx]
.func_indexes
+ s,
(uint32)(n * sizeof(uint32)));
tbl_seg_elems + s, (uint32)(n * sizeof(uint32)));
break;
}
@ -4240,6 +4235,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
HANDLE_OP(WASM_OP_DELEGATE)
HANDLE_OP(WASM_OP_CATCH_ALL)
HANDLE_OP(EXT_OP_TRY)
#endif
#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_SIMD != 0
/* SIMD isn't supported by interpreter, but when JIT is
enabled, `iwasm --interp <wasm_file>` may be run to
trigger the SIMD opcode in interpreter */
HANDLE_OP(WASM_OP_SIMD_PREFIX)
#endif
HANDLE_OP(WASM_OP_UNUSED_0x14)
HANDLE_OP(WASM_OP_UNUSED_0x15)
@ -4692,14 +4693,11 @@ llvm_jit_call_func_bytecode(WASMModuleInstance *module_inst,
#if WASM_ENABLE_QUICK_AOT_ENTRY != 0
/* Quick call if the quick jit entry is registered */
if (func_type->quick_aot_entry) {
void (*invoke_native)(
void *func_ptr, uint8 ret_type, void *exec_env, uint32 *argv,
uint32 *argv_ret) = func_type->quick_aot_entry;
invoke_native(module_inst->func_ptrs[func_idx],
func_type->result_count > 0
? func_type->types[func_type->param_count]
: VALUE_TYPE_VOID,
exec_env, argv, argv);
void (*invoke_native)(void *func_ptr, void *exec_env, uint32 *argv,
uint32 *argv_ret) =
func_type->quick_aot_entry;
invoke_native(module_inst->func_ptrs[func_idx], exec_env, argv,
argv);
ret = !wasm_copy_exception(module_inst, NULL);
}
else

View File

@ -884,7 +884,7 @@ ALLOC_FRAME(WASMExecEnv *exec_env, uint32 size, WASMInterpFrame *prev_frame)
if (frame) {
frame->prev_frame = prev_frame;
#if WASM_ENABLE_PERF_PROFILING != 0
frame->time_started = os_time_get_boot_microsecond();
frame->time_started = os_time_thread_cputime_us();
#endif
}
else {
@ -900,9 +900,13 @@ FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame)
{
#if WASM_ENABLE_PERF_PROFILING != 0
if (frame->function) {
frame->function->total_exec_time +=
os_time_get_boot_microsecond() - frame->time_started;
WASMInterpFrame *prev_frame = frame->prev_frame;
uint64 elapsed = os_time_thread_cputime_us() - frame->time_started;
frame->function->total_exec_time += elapsed;
frame->function->total_exec_cnt++;
if (prev_frame && prev_frame->function)
prev_frame->function->children_exec_time += elapsed;
}
#endif
wasm_exec_env_free_wasm_frame(exec_env, frame);
@ -3031,7 +3035,6 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
data = NULL;
}
else {
seg_len =
(uint64)module->module->data_segments[segment]
->data_length;
@ -3114,6 +3117,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint32 tbl_idx, elem_idx;
uint32 n, s, d;
WASMTableInstance *tbl_inst;
uint32 *tbl_seg_elems = NULL, tbl_seg_len = 0;
elem_idx = read_uint32(frame_ip);
bh_assert(elem_idx < module->module->table_seg_count);
@ -3127,10 +3131,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
s = (uint32)POP_I32();
d = (uint32)POP_I32();
if (offset_len_out_of_bounds(
s, n,
if (!bh_bitmap_get_bit(module->e->common.elem_dropped,
elem_idx)) {
/* table segment isn't dropped */
tbl_seg_elems =
module->module->table_segments[elem_idx]
.function_count)
.func_indexes;
tbl_seg_len =
module->module->table_segments[elem_idx]
.function_count;
}
if (offset_len_out_of_bounds(s, n, tbl_seg_len)
|| offset_len_out_of_bounds(d, n,
tbl_inst->cur_size)) {
wasm_set_exception(module,
@ -3142,30 +3154,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
break;
}
if (bh_bitmap_get_bit(module->e->common.elem_dropped,
elem_idx)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
}
if (!wasm_elem_is_passive(
module->module->table_segments[elem_idx]
.mode)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
}
bh_memcpy_s(
(uint8 *)tbl_inst
+ offsetof(WASMTableInstance, elems)
+ d * sizeof(uint32),
(uint32)((tbl_inst->cur_size - d) * sizeof(uint32)),
module->module->table_segments[elem_idx]
.func_indexes
+ s,
(uint32)(n * sizeof(uint32)));
tbl_seg_elems + s, (uint32)(n * sizeof(uint32)));
break;
}
case WASM_OP_ELEM_DROP:

View File

@ -327,7 +327,7 @@ check_utf8_str(const uint8 *str, uint32 len)
return false;
}
}
else if (chr >= 0xE1 && chr <= 0xEF) {
else { /* chr >= 0xE1 && chr <= 0xEF */
if (p[1] < 0x80 || p[1] > 0xBF || p[2] < 0x80 || p[2] > 0xBF) {
return false;
}
@ -341,13 +341,13 @@ check_utf8_str(const uint8 *str, uint32 len)
return false;
}
}
else if (chr >= 0xF1 && chr <= 0xF3) {
else if (chr <= 0xF3) { /* and also chr >= 0xF1 */
if (p[1] < 0x80 || p[1] > 0xBF || p[2] < 0x80 || p[2] > 0xBF
|| p[3] < 0x80 || p[3] > 0xBF) {
return false;
}
}
else if (chr == 0xF4) {
else { /* chr == 0xF4 */
if (p[1] < 0x80 || p[1] > 0x8F || p[2] < 0x80 || p[2] > 0xBF
|| p[3] < 0x80 || p[3] > 0xBF) {
return false;
@ -4317,15 +4317,6 @@ check_wasi_abi_compatibility(const WASMModule *module,
* according to the assumption, they should be all wasi compatiable
*/
/* always can not have both at the same time */
if (start && initialize) {
set_error_buf(
error_buf, error_buf_size,
"neither a command nor a reactor can both have _start function "
"and _initialize function at the same time");
return false;
}
#if WASM_ENABLE_MULTI_MODULE != 0
/* filter out commands (with `_start`) cases */
if (start && !main_module) {
@ -7994,6 +7985,15 @@ re_scan:
bh_memcpy_s(loader_ctx->frame_offset, size,
block->param_frame_offsets, size);
loader_ctx->frame_offset += (size / sizeof(int16));
/* recover dynamic offset */
for (i = 0; i < block->available_param_num; i++) {
if (block->param_frame_offsets[i]
>= loader_ctx->dynamic_offset) {
loader_ctx->dynamic_offset =
block->param_frame_offsets[i] + 1;
}
}
}
#endif

View File

@ -5824,6 +5824,15 @@ re_scan:
bh_memcpy_s(loader_ctx->frame_offset, size,
block->param_frame_offsets, size);
loader_ctx->frame_offset += (size / sizeof(int16));
/* recover dynamic offset */
for (i = 0; i < block->available_param_num; i++) {
if (block->param_frame_offsets[i]
>= loader_ctx->dynamic_offset) {
loader_ctx->dynamic_offset =
block->param_frame_offsets[i] + 1;
}
}
}
#endif

View File

@ -685,6 +685,13 @@ typedef enum WASMAtomicEXTOpcode {
#define SET_GOTO_TABLE_ELEM(opcode) [opcode] = HANDLE_OPCODE(opcode)
#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_SIMD != 0
#define SET_GOTO_TABLE_SIMD_PREFIX_ELEM() \
SET_GOTO_TABLE_ELEM(WASM_OP_SIMD_PREFIX),
#else
#define SET_GOTO_TABLE_SIMD_PREFIX_ELEM()
#endif
/*
* Macro used to generate computed goto tables for the C interpreter.
*/
@ -909,6 +916,7 @@ typedef enum WASMAtomicEXTOpcode {
HANDLE_OPCODE(EXT_OP_BR_TABLE_CACHE), /* 0xd6 */ \
HANDLE_OPCODE(EXT_OP_TRY), /* 0xd7 */ \
SET_GOTO_TABLE_ELEM(WASM_OP_MISC_PREFIX), /* 0xfc */ \
SET_GOTO_TABLE_SIMD_PREFIX_ELEM() /* 0xfd */ \
SET_GOTO_TABLE_ELEM(WASM_OP_ATOMIC_PREFIX), /* 0xfe */ \
DEF_DEBUG_BREAK_HANDLE() \
};

View File

@ -115,6 +115,9 @@ static void
memories_deinstantiate(WASMModuleInstance *module_inst,
WASMMemoryInstance **memories, uint32 count)
{
#ifdef WASM_LINEAR_MEMORY_MMAP
uint64 map_size;
#endif
uint32 i;
if (memories) {
for (i = 0; i < count; i++) {
@ -142,15 +145,21 @@ memories_deinstantiate(WASMModuleInstance *module_inst,
}
if (memories[i]->memory_data) {
#ifndef OS_ENABLE_HW_BOUND_CHECK
#ifdef WASM_LINEAR_MEMORY_MMAP
if (shared_memory_is_shared(memories[i])) {
map_size = (uint64)memories[i]->num_bytes_per_page
* memories[i]->max_page_count;
wasm_munmap_linear_memory(memories[i]->memory_data,
map_size, map_size);
}
else
#endif
wasm_runtime_free(memories[i]->memory_data);
#else
#ifdef BH_PLATFORM_WINDOWS
os_mem_decommit(memories[i]->memory_data,
memories[i]->num_bytes_per_page
* memories[i]->cur_page_count);
#endif
os_munmap((uint8 *)memories[i]->memory_data,
8 * (uint64)BH_GB);
map_size = (uint64)memories[i]->num_bytes_per_page
* memories[i]->cur_page_count;
wasm_munmap_linear_memory(memories[i]->memory_data,
map_size, 8 * (uint64)BH_GB);
#endif
}
}
@ -173,10 +182,9 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
uint32 inc_page_count, aux_heap_base, global_idx;
uint32 bytes_of_last_page, bytes_to_page_end;
uint8 *global_addr;
#ifdef OS_ENABLE_HW_BOUND_CHECK
uint8 *mapped_mem;
uint64 map_size = 8 * (uint64)BH_GB;
uint64 page_size = os_getpagesize();
#ifdef WASM_LINEAR_MEMORY_MMAP
uint8 *mapped_mem = NULL;
uint64 map_size;
#endif
#if WASM_ENABLE_SHARED_MEMORY != 0
@ -295,18 +303,29 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
(void)max_memory_data_size;
bh_assert(memory != NULL);
#ifndef OS_ENABLE_HW_BOUND_CHECK
#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
/* Allocate maximum memory size when memory is shared */
#if WASM_ENABLE_SHARED_MEMORY_MMAP != 0
map_size = max_memory_data_size;
if (max_memory_data_size > 0
&& !(memory->memory_data = mapped_mem =
wasm_mmap_linear_memory(map_size, &max_memory_data_size,
error_buf, error_buf_size))) {
goto fail1;
}
#else
if (max_memory_data_size > 0
&& !(memory->memory_data = runtime_malloc(
max_memory_data_size, error_buf, error_buf_size))) {
goto fail1;
}
#endif
}
else
#endif
#endif /* end of WASM_ENABLE_SHARED_MEMORY != 0 */
{
/* Allocate initial memory size when memory is not shared */
if (memory_data_size > 0
@ -316,42 +335,17 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
}
}
#else /* else of OS_ENABLE_HW_BOUND_CHECK */
memory_data_size = (memory_data_size + page_size - 1) & ~(page_size - 1);
/* Totally 8G is mapped, the opcode load/store address range is 0 to 8G:
* ea = i + memarg.offset
* both i and memarg.offset are u32 in range 0 to 4G
* so the range of ea is 0 to 8G
*/
if (!(memory->memory_data = mapped_mem =
os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE,
os_get_invalid_handle()))) {
map_size = 8 * (uint64)BH_GB;
if (!(memory->memory_data = mapped_mem = wasm_mmap_linear_memory(
map_size, &memory_data_size, error_buf, error_buf_size))) {
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
goto fail1;
}
#ifdef BH_PLATFORM_WINDOWS
if (memory_data_size > 0
&& !os_mem_commit(mapped_mem, memory_data_size,
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
set_error_buf(error_buf, error_buf_size, "commit memory failed");
os_munmap(mapped_mem, map_size);
goto fail1;
}
#endif
if (os_mprotect(mapped_mem, memory_data_size,
MMAP_PROT_READ | MMAP_PROT_WRITE)
!= 0) {
set_error_buf(error_buf, error_buf_size, "mprotect memory failed");
goto fail2;
}
/* Newly allocated pages are filled with zero by the OS, we don't fill it
* again here */
if (memory_data_size > UINT32_MAX)
memory_data_size = UINT32_MAX;
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
memory->module_type = Wasm_Module_Bytecode;
@ -398,15 +392,15 @@ fail3:
if (heap_size > 0)
wasm_runtime_free(memory->heap_handle);
fail2:
#ifndef OS_ENABLE_HW_BOUND_CHECK
#ifdef WASM_LINEAR_MEMORY_MMAP
if (mapped_mem)
wasm_munmap_linear_memory(mapped_mem, memory_data_size, map_size);
else
#endif
{
if (memory->memory_data)
wasm_runtime_free(memory->memory_data);
#else
#ifdef BH_PLATFORM_WINDOWS
os_mem_decommit(mapped_mem, memory_data_size);
#endif
os_munmap(mapped_mem, map_size);
#endif
}
fail1:
return NULL;
}
@ -1817,6 +1811,10 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
"failed to allocate bitmaps");
goto fail;
}
for (i = 0; i < module->data_seg_count; i++) {
if (!module->data_segments[i]->is_passive)
bh_bitmap_set_bit(module_inst->e->common.data_dropped, i);
}
}
#endif
#if WASM_ENABLE_REF_TYPES != 0
@ -1829,6 +1827,10 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
"failed to allocate bitmaps");
goto fail;
}
for (i = 0; i < module->table_seg_count; i++) {
if (wasm_elem_is_active(module->table_segments[i].mode))
bh_bitmap_set_bit(module_inst->e->common.elem_dropped, i);
}
}
#endif
@ -2577,53 +2579,103 @@ wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
return !wasm_copy_exception(module_inst, NULL);
}
#if WASM_ENABLE_PERF_PROFILING != 0
void
wasm_dump_perf_profiling(const WASMModuleInstance *module_inst)
#if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0
/* look for the function name */
static char *
get_func_name_from_index(const WASMModuleInstance *inst, uint32 func_index)
{
WASMExportFuncInstance *export_func;
WASMFunctionInstance *func_inst;
char *func_name;
uint32 i, j;
char *func_name = NULL;
WASMFunctionInstance *func_inst = inst->e->functions + func_index;
os_printf("Performance profiler data:\n");
for (i = 0; i < module_inst->e->function_count; i++) {
func_inst = module_inst->e->functions + i;
if (func_inst->is_import_func) {
func_name = func_inst->u.func_import->field_name;
}
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
else if (func_inst->u.func->field_name) {
func_name = func_inst->u.func->field_name;
}
#endif
else {
func_name = NULL;
for (j = 0; j < module_inst->export_func_count; j++) {
export_func = module_inst->export_functions + j;
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
func_name = func_inst->u.func->field_name;
#endif
/* if custom name section is not generated,
search symbols from export table */
if (!func_name) {
unsigned j;
for (j = 0; j < inst->export_func_count; j++) {
WASMExportFuncInstance *export_func =
inst->export_functions + j;
if (export_func->function == func_inst) {
func_name = export_func->name;
break;
}
}
}
}
return func_name;
}
#endif /*WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0*/
#if WASM_ENABLE_PERF_PROFILING != 0
void
wasm_dump_perf_profiling(const WASMModuleInstance *module_inst)
{
WASMFunctionInstance *func_inst;
char *func_name;
uint32 i;
os_printf("Performance profiler data:\n");
for (i = 0; i < module_inst->e->function_count; i++) {
func_inst = module_inst->e->functions + i;
if (func_inst->total_exec_cnt == 0)
continue;
func_name = get_func_name_from_index(module_inst, i);
if (func_name)
os_printf(
" func %s, execution time: %.3f ms, execution count: %" PRIu32
" times\n",
func_name,
module_inst->e->functions[i].total_exec_time / 1000.0f,
module_inst->e->functions[i].total_exec_cnt);
" times, children execution time: %.3f ms\n",
func_name, func_inst->total_exec_time / 1000.0f,
func_inst->total_exec_cnt,
func_inst->children_exec_time / 1000.0f);
else
os_printf(" func %" PRIu32
", execution time: %.3f ms, execution count: %" PRIu32
" times\n",
i, module_inst->e->functions[i].total_exec_time / 1000.0f,
module_inst->e->functions[i].total_exec_cnt);
" times, children execution time: %.3f ms\n",
i, func_inst->total_exec_time / 1000.0f,
func_inst->total_exec_cnt,
func_inst->children_exec_time / 1000.0f);
}
}
#endif
double
wasm_summarize_wasm_execute_time(const WASMModuleInstance *inst)
{
double ret = 0;
unsigned i;
for (i = 0; i < inst->e->function_count; i++) {
WASMFunctionInstance *func = inst->e->functions + i;
ret += (func->total_exec_time - func->children_exec_time) / 1000.0f;
}
return ret;
}
double
wasm_get_wasm_func_exec_time(const WASMModuleInstance *inst,
const char *func_name)
{
unsigned i;
for (i = 0; i < inst->e->function_count; i++) {
char *name_in_wasm = get_func_name_from_index(inst, i);
if (name_in_wasm && strcmp(name_in_wasm, func_name) == 0) {
WASMFunctionInstance *func = inst->e->functions + i;
return (func->total_exec_time - func->children_exec_time) / 1000.0f;
}
}
return -1.0;
}
#endif /*WASM_ENABLE_PERF_PROFILING != 0*/
uint32
wasm_module_malloc_internal(WASMModuleInstance *module_inst,
@ -3118,29 +3170,7 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
frame.func_offset = (uint32)(cur_frame->ip - func_code_base);
}
/* look for the function name */
if (func_inst->is_import_func) {
func_name = func_inst->u.func_import->field_name;
}
else {
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
func_name = func_inst->u.func->field_name;
#endif
/* if custom name section is not generated,
search symbols from export table */
if (!func_name) {
uint32 i;
for (i = 0; i < module_inst->export_func_count; i++) {
WASMExportFuncInstance *export_func =
module_inst->export_functions + i;
if (export_func->function == func_inst) {
func_name = export_func->name;
break;
}
}
}
}
func_name = get_func_name_from_index(module_inst, frame.func_index);
frame.func_name_wp = func_name;
if (!bh_vector_append(module_inst->frames, &frame)) {
@ -3435,6 +3465,7 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
{
WASMTableInstance *tbl_inst;
WASMTableSeg *tbl_seg;
uint32 *tbl_seg_elems = NULL, tbl_seg_len = 0;
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
@ -3444,7 +3475,13 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
bh_assert(tbl_inst);
bh_assert(tbl_seg);
if (offset_len_out_of_bounds(src_offset, length, tbl_seg->function_count)
if (!bh_bitmap_get_bit(module_inst->e->common.elem_dropped, tbl_seg_idx)) {
/* table segment isn't dropped */
tbl_seg_elems = tbl_seg->func_indexes;
tbl_seg_len = tbl_seg->function_count;
}
if (offset_len_out_of_bounds(src_offset, length, tbl_seg_len)
|| offset_len_out_of_bounds(dst_offset, length, tbl_inst->cur_size)) {
jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
@ -3454,21 +3491,10 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
return;
}
if (bh_bitmap_get_bit(module_inst->e->common.elem_dropped, tbl_seg_idx)) {
jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
if (!wasm_elem_is_passive(tbl_seg->mode)) {
jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
bh_memcpy_s((uint8 *)tbl_inst + offsetof(WASMTableInstance, elems)
+ dst_offset * sizeof(uint32),
(uint32)sizeof(uint32) * (tbl_inst->cur_size - dst_offset),
tbl_seg->func_indexes + src_offset,
(uint32)(length * sizeof(uint32)));
tbl_seg_elems + src_offset, (uint32)(length * sizeof(uint32)));
}
void
@ -3587,7 +3613,7 @@ llvm_jit_alloc_frame(WASMExecEnv *exec_env, uint32 func_index)
frame->ip = NULL;
frame->sp = frame->lp;
#if WASM_ENABLE_PERF_PROFILING != 0
frame->time_started = os_time_get_boot_microsecond();
frame->time_started = os_time_thread_cputime_us();
#endif
frame->prev_frame = wasm_exec_env_get_cur_frame(exec_env);
wasm_exec_env_set_cur_frame(exec_env, frame);
@ -3608,9 +3634,13 @@ llvm_jit_free_frame(WASMExecEnv *exec_env)
#if WASM_ENABLE_PERF_PROFILING != 0
if (frame->function) {
frame->function->total_exec_time +=
os_time_get_boot_microsecond() - frame->time_started;
uint64 elapsed = os_time_thread_cputime_us() - frame->time_started;
frame->function->total_exec_time += elapsed;
frame->function->total_exec_cnt++;
/* parent function */
if (prev_frame)
prev_frame->function->children_exec_time += elapsed;
}
#endif
wasm_exec_env_free_wasm_frame(exec_env, frame);

View File

@ -189,6 +189,8 @@ struct WASMFunctionInstance {
uint64 total_exec_time;
/* total execution count */
uint32 total_exec_cnt;
/* children execution time */
uint64 children_exec_time;
#endif
};
@ -474,6 +476,13 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
void
wasm_dump_perf_profiling(const WASMModuleInstance *module_inst);
double
wasm_summarize_wasm_execute_time(const WASMModuleInstance *inst);
double
wasm_get_wasm_func_exec_time(const WASMModuleInstance *inst,
const char *func_name);
void
wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst);

View File

@ -468,7 +468,7 @@ get_thread_info(wasm_exec_env_t exec_env, uint32 handle)
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
ClusterInfoNode *info = get_cluster_info(cluster);
if (!info) {
if (!info || !handle) {
return NULL;
}
@ -1144,6 +1144,10 @@ sem_open_wrapper(wasm_exec_env_t exec_env, const char *name, int32 oflags,
* For Unix like system, it's dedicated for multiple processes.
*/
if (!name) { /* avoid passing NULL to bh_hash_map_find and os_sem_open */
return -1;
}
if ((info_node = bh_hash_map_find(sem_info_map, (void *)name))) {
return info_node->handle;
}
@ -1276,7 +1280,13 @@ sem_unlink_wrapper(wasm_exec_env_t exec_env, const char *name)
(void)exec_env;
int32 ret_val;
ThreadInfoNode *info_node = bh_hash_map_find(sem_info_map, (void *)name);
ThreadInfoNode *info_node;
if (!name) { /* avoid passing NULL to bh_hash_map_find */
return -1;
}
info_node = bh_hash_map_find(sem_info_map, (void *)name);
if (!info_node || info_node->type != T_SEM)
return -1;

View File

@ -473,12 +473,16 @@ snprintf_wrapper(wasm_exec_env_t exec_env, char *str, uint32 size,
static int
puts_wrapper(wasm_exec_env_t exec_env, const char *str)
{
(void)exec_env;
return os_printf("%s\n", str);
}
static int
putchar_wrapper(wasm_exec_env_t exec_env, int c)
{
(void)exec_env;
os_printf("%c", c);
return 1;
}
@ -585,6 +589,8 @@ strchr_wrapper(wasm_exec_env_t exec_env, const char *s, int32 c)
static int32
strcmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2)
{
(void)exec_env;
/* s1 and s2 have been checked by runtime */
return strcmp(s1, s2);
}
@ -641,6 +647,8 @@ strncpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src,
static uint32
strlen_wrapper(wasm_exec_env_t exec_env, const char *s)
{
(void)exec_env;
/* s has been checked by runtime */
return (uint32)strlen(s);
}
@ -693,6 +701,7 @@ free_wrapper(wasm_exec_env_t exec_env, void *ptr)
static int32
atoi_wrapper(wasm_exec_env_t exec_env, const char *s)
{
(void)exec_env;
/* s has been checked by runtime */
return atoi(s);
}
@ -757,6 +766,8 @@ static int32
strncasecmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
uint32 n)
{
(void)exec_env;
/* s1 and s2 have been checked by runtime */
return strncasecmp(s1, s2, n);
}
@ -764,6 +775,8 @@ strncasecmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
static uint32
strspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *accept)
{
(void)exec_env;
/* s and accept have been checked by runtime */
return (uint32)strspn(s, accept);
}
@ -771,6 +784,8 @@ strspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *accept)
static uint32
strcspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *reject)
{
(void)exec_env;
/* s and reject have been checked by runtime */
return (uint32)strcspn(s, reject);
}
@ -787,60 +802,80 @@ strstr_wrapper(wasm_exec_env_t exec_env, const char *s, const char *find)
static int32
isupper_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isupper(c);
}
static int32
isalpha_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isalpha(c);
}
static int32
isspace_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isspace(c);
}
static int32
isgraph_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isgraph(c);
}
static int32
isprint_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isprint(c);
}
static int32
isdigit_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isdigit(c);
}
static int32
isxdigit_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isxdigit(c);
}
static int32
tolower_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return tolower(c);
}
static int32
toupper_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return toupper(c);
}
static int32
isalnum_wrapper(wasm_exec_env_t exec_env, int32 c)
{
(void)exec_env;
return isalnum(c);
}
@ -899,7 +934,10 @@ __cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env, uint32 thrown_size)
static void
__cxa_begin_catch_wrapper(wasm_exec_env_t exec_env, void *exception_object)
{}
{
(void)exec_env;
(void)exception_object;
}
static void
__cxa_throw_wrapper(wasm_exec_env_t exec_env, void *thrown_exception,
@ -908,6 +946,10 @@ __cxa_throw_wrapper(wasm_exec_env_t exec_env, void *thrown_exception,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
(void)thrown_exception;
(void)tinfo;
(void)table_elem_idx;
snprintf(buf, sizeof(buf), "%s", "exception thrown by stdc++");
wasm_runtime_set_exception(module_inst, buf);
}
@ -924,10 +966,12 @@ clock_gettime_wrapper(wasm_exec_env_t exec_env, uint32 clk_id,
wasm_module_inst_t module_inst = get_module_inst(exec_env);
uint64 time;
(void)clk_id;
if (!validate_native_addr(ts_app, sizeof(struct timespec_app)))
return (uint32)-1;
time = os_time_get_boot_microsecond();
time = os_time_get_boot_us();
ts_app->tv_sec = time / 1000000;
ts_app->tv_nsec = (time % 1000000) * 1000;
@ -937,9 +981,11 @@ clock_gettime_wrapper(wasm_exec_env_t exec_env, uint32 clk_id,
static uint64
clock_wrapper(wasm_exec_env_t exec_env)
{
(void)exec_env;
/* Convert to nano seconds as CLOCKS_PER_SEC in wasi-sdk */
return os_time_get_boot_microsecond() * 1000;
return os_time_get_boot_us() * 1000;
}
#if WASM_ENABLE_SPEC_TEST != 0

View File

@ -72,7 +72,7 @@ min_uint32(uint32_t a, uint32_t b)
}
static inline struct fd_table *
wasi_ctx_get_curfds(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
wasi_ctx_get_curfds(wasi_ctx_t wasi_ctx)
{
if (!wasi_ctx)
return NULL;
@ -88,7 +88,7 @@ wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
}
static inline struct fd_prestats *
wasi_ctx_get_prestats(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
wasi_ctx_get_prestats(wasi_ctx_t wasi_ctx)
{
if (!wasi_ctx)
return NULL;
@ -96,7 +96,7 @@ wasi_ctx_get_prestats(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
}
static inline struct addr_pool *
wasi_ctx_get_addr_pool(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
wasi_ctx_get_addr_pool(wasi_ctx_t wasi_ctx)
{
if (!wasi_ctx)
return NULL;
@ -292,7 +292,7 @@ wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
wasi_prestat_t prestat;
wasi_errno_t err;
@ -317,7 +317,7 @@ wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env, wasi_fd_t fd, char *path,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -330,8 +330,8 @@ wasi_fd_close(wasm_exec_env_t exec_env, wasi_fd_t fd)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -344,7 +344,7 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -358,7 +358,7 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
wasi_iovec_t *iovec, *iovec_begin;
uint64 total_size;
size_t nread;
@ -412,7 +412,7 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
wasi_ciovec_t *ciovec, *ciovec_begin;
uint64 total_size;
size_t nwritten;
@ -465,7 +465,7 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
wasi_iovec_t *iovec, *iovec_begin;
uint64 total_size;
size_t nread;
@ -517,8 +517,8 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -532,7 +532,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -549,7 +549,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -566,7 +566,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
wasi_fdstat_t fdstat;
wasi_errno_t err;
@ -590,7 +590,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -605,7 +605,7 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -619,7 +619,7 @@ wasi_fd_sync(wasm_exec_env_t exec_env, wasi_fd_t fd)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -634,7 +634,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
wasi_ciovec_t *ciovec, *ciovec_begin;
uint64 total_size;
size_t nwritten;
@ -687,7 +687,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -701,7 +701,7 @@ wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -715,7 +715,7 @@ wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -732,8 +732,8 @@ wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -752,7 +752,7 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
wasi_fd_t fd = (wasi_fd_t)-1; /* set fd_app -1 if path open failed */
wasi_errno_t err;
@ -776,7 +776,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
size_t bufused;
wasi_errno_t err;
@ -802,7 +802,7 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
size_t bufused;
wasi_errno_t err;
@ -828,7 +828,7 @@ wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -844,7 +844,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -862,7 +862,7 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -877,7 +877,7 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -892,7 +892,7 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -912,7 +912,7 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -929,8 +929,8 @@ wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
struct fd_prestats *prestats = wasi_ctx_get_prestats(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -945,7 +945,7 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -959,7 +959,7 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return (wasi_errno_t)-1;
@ -1076,7 +1076,7 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
size_t nevents = 0;
wasi_errno_t err;
@ -1128,6 +1128,8 @@ wasi_proc_raise(wasm_exec_env_t exec_env, wasi_signal_t sig)
static wasi_errno_t
wasi_random_get(wasm_exec_env_t exec_env, void *buf, uint32 buf_len)
{
(void)exec_env;
return wasmtime_ssp_random_get(buf, buf_len);
}
@ -1142,7 +1144,7 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new);
}
@ -1161,7 +1163,7 @@ wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(addr, sizeof(__wasi_addr_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasi_ssp_sock_addr_local(exec_env, curfds, fd, addr);
}
@ -1180,7 +1182,7 @@ wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(addr, sizeof(__wasi_addr_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasi_ssp_sock_addr_remote(exec_env, curfds, fd, addr);
}
@ -1200,7 +1202,7 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx);
return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host,
@ -1219,8 +1221,8 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(wasi_ctx);
return wasi_ssp_sock_bind(exec_env, curfds, addr_pool, fd, addr);
}
@ -1228,6 +1230,9 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
static wasi_errno_t
wasi_sock_close(wasm_exec_env_t exec_env, wasi_fd_t fd)
{
(void)exec_env;
(void)fd;
return __WASI_ENOSYS;
}
@ -1242,8 +1247,8 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(wasi_ctx);
return wasi_ssp_sock_connect(exec_env, curfds, addr_pool, fd, addr);
}
@ -1262,7 +1267,7 @@ wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_broadcast(exec_env, curfds, fd, is_enabled);
}
@ -1281,7 +1286,7 @@ wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_keep_alive(exec_env, curfds, fd, is_enabled);
}
@ -1301,7 +1306,7 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled,
|| !validate_native_addr(linger_s, sizeof(int)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled,
linger_s);
@ -1321,7 +1326,7 @@ wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(size, sizeof(wasi_size_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_recv_buf_size(exec_env, curfds, fd, size);
}
@ -1340,7 +1345,7 @@ wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(timeout_us, sizeof(uint64_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_recv_timeout(exec_env, curfds, fd, timeout_us);
}
@ -1359,7 +1364,7 @@ wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_reuse_addr(exec_env, curfds, fd, is_enabled);
}
@ -1378,7 +1383,7 @@ wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_reuse_port(exec_env, curfds, fd, is_enabled);
}
@ -1397,7 +1402,7 @@ wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(size, sizeof(__wasi_size_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_send_buf_size(exec_env, curfds, fd, size);
}
@ -1416,7 +1421,7 @@ wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(timeout_us, sizeof(uint64_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_send_timeout(exec_env, curfds, fd, timeout_us);
}
@ -1435,7 +1440,7 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd,
is_enabled);
@ -1455,7 +1460,7 @@ wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_tcp_no_delay(exec_env, curfds, fd, is_enabled);
}
@ -1474,7 +1479,7 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd,
is_enabled);
@ -1494,7 +1499,7 @@ wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(time_s, sizeof(uint32_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_tcp_keep_idle(exec_env, curfds, fd, time_s);
}
@ -1513,7 +1518,7 @@ wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(time_s, sizeof(uint32_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_tcp_keep_intvl(exec_env, curfds, fd, time_s);
}
@ -1532,7 +1537,7 @@ wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_ip_multicast_loop(exec_env, curfds, fd, ipv6,
is_enabled);
@ -1551,7 +1556,7 @@ wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s)
if (!validate_native_addr(ttl_s, sizeof(uint8_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_ip_ttl(exec_env, curfds, fd, ttl_s);
}
@ -1570,7 +1575,7 @@ wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(ttl_s, sizeof(uint8_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
}
@ -1589,7 +1594,7 @@ wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(is_enabled, sizeof(bool)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_get_ipv6_only(exec_env, curfds, fd, is_enabled);
}
@ -1604,7 +1609,7 @@ wasi_sock_listen(wasm_exec_env_t exec_env, wasi_fd_t fd, uint32 backlog)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasi_ssp_sock_listen(exec_env, curfds, fd, backlog);
}
@ -1621,7 +1626,7 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd);
}
@ -1636,7 +1641,7 @@ wasi_sock_set_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_broadcast(exec_env, curfds, fd, is_enabled);
}
@ -1652,7 +1657,7 @@ wasi_sock_set_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_keep_alive(exec_env, curfds, fd, is_enabled);
}
@ -1668,7 +1673,7 @@ wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled,
linger_s);
@ -1684,7 +1689,7 @@ wasi_sock_set_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_recv_buf_size(exec_env, curfds, fd, size);
}
@ -1700,7 +1705,7 @@ wasi_sock_set_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_recv_timeout(exec_env, curfds, fd, timeout_us);
}
@ -1716,7 +1721,7 @@ wasi_sock_set_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_reuse_addr(exec_env, curfds, fd, is_enabled);
}
@ -1732,7 +1737,7 @@ wasi_sock_set_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_reuse_port(exec_env, curfds, fd, is_enabled);
}
@ -1747,7 +1752,7 @@ wasi_sock_set_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_send_buf_size(exec_env, curfds, fd, size);
}
@ -1763,7 +1768,7 @@ wasi_sock_set_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_send_timeout(exec_env, curfds, fd, timeout_us);
}
@ -1779,7 +1784,7 @@ wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd,
is_enabled);
@ -1796,7 +1801,7 @@ wasi_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_tcp_no_delay(exec_env, curfds, fd, is_enabled);
}
@ -1812,7 +1817,7 @@ wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd,
is_enabled);
@ -1829,7 +1834,7 @@ wasi_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_tcp_keep_idle(exec_env, curfds, fd, time_s);
}
@ -1845,7 +1850,7 @@ wasi_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_tcp_keep_intvl(exec_env, curfds, fd, time_s);
}
@ -1861,7 +1866,7 @@ wasi_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_ip_multicast_loop(exec_env, curfds, fd, ipv6,
is_enabled);
@ -1882,7 +1887,7 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(imr_multiaddr, sizeof(__wasi_addr_ip_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_ip_add_membership(
exec_env, curfds, fd, imr_multiaddr, imr_interface);
@ -1903,7 +1908,7 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(imr_multiaddr, sizeof(__wasi_addr_ip_t)))
return __WASI_EINVAL;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_ip_drop_membership(
exec_env, curfds, fd, imr_multiaddr, imr_interface);
@ -1919,7 +1924,7 @@ wasi_sock_set_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t ttl_s)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_ip_ttl(exec_env, curfds, fd, ttl_s);
}
@ -1935,7 +1940,7 @@ wasi_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
}
@ -1950,7 +1955,7 @@ wasi_sock_set_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
if (!wasi_ctx)
return __WASI_EACCES;
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
curfds = wasi_ctx_get_curfds(wasi_ctx);
return wasmtime_ssp_sock_set_ipv6_only(exec_env, curfds, fd, is_enabled);
}
@ -2013,7 +2018,8 @@ copy_buffer_to_iovec_app(wasm_module_inst_t module_inst, uint8 *buf_begin,
}
if (buf >= buf_begin + buf_size
|| buf + data->buf_len < buf /* integer overflow */
/* integer overflow */
|| data->buf_len > UINTPTR_MAX - (uintptr_t)buf
|| buf + data->buf_len > buf_begin + buf_size
|| size_to_copy == 0) {
break;
@ -2048,7 +2054,7 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock,
**/
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
uint64 total_size;
uint8 *buf_begin = NULL;
wasi_errno_t err;
@ -2152,7 +2158,7 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
**/
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
uint64 buf_size = 0;
uint8 *buf = NULL;
wasi_errno_t err;
@ -2192,12 +2198,12 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock,
**/
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
uint64 buf_size = 0;
uint8 *buf = NULL;
wasi_errno_t err;
size_t send_bytes = 0;
struct addr_pool *addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
struct addr_pool *addr_pool = wasi_ctx_get_addr_pool(wasi_ctx);
if (!wasi_ctx) {
return __WASI_EINVAL;
@ -2226,7 +2232,7 @@ wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct fd_table *curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
struct fd_table *curfds = wasi_ctx_get_curfds(wasi_ctx);
if (!wasi_ctx)
return __WASI_EINVAL;
@ -2237,6 +2243,8 @@ wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
static wasi_errno_t
wasi_sched_yield(wasm_exec_env_t exec_env)
{
(void)exec_env;
return wasmtime_ssp_sched_yield();
}

View File

@ -7,6 +7,7 @@
#include "ssp_config.h"
#include "blocking_op.h"
#include "libc_errno.h"
__wasi_errno_t
blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle,
@ -170,3 +171,23 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
wasm_runtime_end_blocking_op(exec_env);
return error;
}
#ifndef BH_PLATFORM_WINDOWS
/* REVISIT: apply the os_file_handle style abstraction for pollfd? */
__wasi_errno_t
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
int timeout_ms, int *retp)
{
int ret;
if (!wasm_runtime_begin_blocking_op(exec_env)) {
return __WASI_EINTR;
}
ret = poll(pfds, nfds, timeout_ms);
wasm_runtime_end_blocking_op(exec_env);
if (ret == -1) {
return convert_errno(errno);
}
*retp = ret;
return 0;
}
#endif

View File

@ -51,3 +51,9 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
const char *path, __wasi_oflags_t oflags,
__wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags,
wasi_libc_file_access_mode access_mode, os_file_handle *out);
#ifndef BH_PLATFORM_WINDOWS
__wasi_errno_t
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
int timeout, int *retp);
#endif

View File

@ -88,7 +88,7 @@ struct LOCKABLE rwlock {
};
static inline bool
rwlock_init(struct rwlock *lock) REQUIRES_UNLOCKED(*lock)
rwlock_initialize(struct rwlock *lock) REQUIRES_UNLOCKED(*lock)
{
return os_rwlock_init(&lock->object) == 0 ? true : false;
}

View File

@ -204,7 +204,7 @@ struct fd_prestat {
bool
fd_prestats_init(struct fd_prestats *pt)
{
if (!rwlock_init(&pt->lock))
if (!rwlock_initialize(&pt->lock))
return false;
pt->prestats = NULL;
pt->size = 0;
@ -340,7 +340,7 @@ struct fd_entry {
bool
fd_table_init(struct fd_table *ft)
{
if (!rwlock_init(&ft->lock))
if (!rwlock_initialize(&ft->lock))
return false;
ft->entries = NULL;
ft->size = 0;
@ -1017,9 +1017,13 @@ wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
__wasi_fd_t fd, __wasi_fdstat_t *buf)
{
struct fd_table *ft = curfds;
rwlock_rdlock(&ft->lock);
struct fd_entry *fe;
__wasi_errno_t error = fd_table_get_entry(ft, fd, 0, 0, &fe);
__wasi_errno_t error;
(void)exec_env;
rwlock_rdlock(&ft->lock);
error = fd_table_get_entry(ft, fd, 0, 0, &fe);
if (error != __WASI_ESUCCESS) {
rwlock_unlock(&ft->lock);
return error;
@ -1071,9 +1075,13 @@ wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
__wasi_rights_t fs_rights_inheriting)
{
struct fd_table *ft = curfds;
rwlock_wrlock(&ft->lock);
struct fd_entry *fe;
__wasi_errno_t error =
__wasi_errno_t error;
(void)exec_env;
rwlock_wrlock(&ft->lock);
error =
fd_table_get_entry(ft, fd, fs_rights_base, fs_rights_inheriting, &fe);
if (error != 0) {
rwlock_unlock(&ft->lock);
@ -2222,11 +2230,10 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
timeout = -1;
}
int ret = poll(pfds, nsubscriptions, timeout);
__wasi_errno_t error = 0;
if (ret == -1) {
error = convert_errno(errno);
int ret;
int error = blocking_op_poll(exec_env, pfds, nsubscriptions, timeout, &ret);
if (error != 0) {
/* got an error */
}
else if (ret == 0 && *nevents == 0 && clock_subscription != NULL) {
// No events triggered. Trigger the clock event.
@ -2980,7 +2987,9 @@ argv_environ_init(struct argv_environ_values *argv_environ, char *argv_buf,
void
argv_environ_destroy(struct argv_environ_values *argv_environ)
{}
{
(void)argv_environ;
}
void
fd_table_destroy(struct fd_table *ft)

View File

@ -34,7 +34,7 @@
#define CONFIG_HAS_GETRANDOM 0
#endif
#if defined(__CloudABI__)
#if defined(__CloudABI__) || defined(BH_PLATFORM_FREERTOS)
#define CONFIG_HAS_CAP_ENTER 1
#else
#define CONFIG_HAS_CAP_ENTER 0

View File

@ -137,9 +137,10 @@ final:
return ret;
}
/* The caller must lock cluster->lock */
static bool
allocate_aux_stack(WASMExecEnv *exec_env, uint32 *start, uint32 *size)
/* The caller must not have any locks */
bool
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
uint32 *p_size)
{
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
#if WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION != 0
@ -149,8 +150,8 @@ allocate_aux_stack(WASMExecEnv *exec_env, uint32 *start, uint32 *size)
stack_end = wasm_runtime_module_malloc_internal(module_inst, exec_env,
cluster->stack_size, NULL);
*start = stack_end + cluster->stack_size;
*size = cluster->stack_size;
*p_start = stack_end + cluster->stack_size;
*p_size = cluster->stack_size;
return stack_end != 0;
#else
@ -158,27 +159,33 @@ allocate_aux_stack(WASMExecEnv *exec_env, uint32 *start, uint32 *size)
/* If the module doesn't have aux stack info,
it can't create any threads */
if (!cluster->stack_segment_occupied)
os_mutex_lock(&cluster->lock);
if (!cluster->stack_segment_occupied) {
os_mutex_unlock(&cluster->lock);
return false;
}
for (i = 0; i < cluster_max_thread_num; i++) {
if (!cluster->stack_segment_occupied[i]) {
if (start)
*start = cluster->stack_tops[i];
if (size)
*size = cluster->stack_size;
if (p_start)
*p_start = cluster->stack_tops[i];
if (p_size)
*p_size = cluster->stack_size;
cluster->stack_segment_occupied[i] = true;
os_mutex_unlock(&cluster->lock);
return true;
}
}
os_mutex_unlock(&cluster->lock);
return false;
#endif
}
/* The caller must lock cluster->lock */
static bool
free_aux_stack(WASMExecEnv *exec_env, uint32 start)
/* The caller must not have any locks */
bool
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint32 start)
{
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
@ -199,43 +206,19 @@ free_aux_stack(WASMExecEnv *exec_env, uint32 start)
#else
uint32 i;
os_mutex_lock(&cluster->lock);
for (i = 0; i < cluster_max_thread_num; i++) {
if (start == cluster->stack_tops[i]) {
cluster->stack_segment_occupied[i] = false;
os_mutex_unlock(&cluster->lock);
return true;
}
}
os_mutex_unlock(&cluster->lock);
return false;
#endif
}
bool
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
uint32 *p_size)
{
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
bool ret;
os_mutex_lock(&cluster->lock);
ret = allocate_aux_stack(exec_env, p_start, p_size);
os_mutex_unlock(&cluster->lock);
return ret;
}
bool
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint32 start)
{
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
bool ret;
os_mutex_lock(&cluster->lock);
ret = free_aux_stack(exec_env, start);
os_mutex_unlock(&cluster->lock);
return ret;
}
WASMCluster *
wasm_cluster_create(WASMExecEnv *exec_env)
{
@ -535,6 +518,13 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
goto fail1;
}
if (!wasm_cluster_allocate_aux_stack(exec_env, &aux_stack_start,
&aux_stack_size)) {
LOG_ERROR("thread manager error: "
"failed to allocate aux stack space for new thread");
goto fail1;
}
os_mutex_lock(&cluster->lock);
if (cluster->has_exception || cluster->processing) {
@ -561,36 +551,30 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
goto fail2;
}
if (!allocate_aux_stack(exec_env, &aux_stack_start, &aux_stack_size)) {
LOG_ERROR("thread manager error: "
"failed to allocate aux stack space for new thread");
goto fail3;
}
/* Set aux stack for current thread */
if (!wasm_exec_env_set_aux_stack(new_exec_env, aux_stack_start,
aux_stack_size)) {
goto fail4;
goto fail3;
}
/* Inherit suspend_flags of parent thread */
new_exec_env->suspend_flags.flags = exec_env->suspend_flags.flags;
new_exec_env->suspend_flags.flags =
(exec_env->suspend_flags.flags & WASM_SUSPEND_FLAG_INHERIT_MASK);
if (!wasm_cluster_add_exec_env(cluster, new_exec_env)) {
goto fail4;
goto fail3;
}
os_mutex_unlock(&cluster->lock);
return new_exec_env;
fail4:
/* free the allocated aux stack space */
free_aux_stack(exec_env, aux_stack_start);
fail3:
wasm_exec_env_destroy_internal(new_exec_env);
fail2:
os_mutex_unlock(&cluster->lock);
/* free the allocated aux stack space */
wasm_cluster_free_aux_stack(exec_env, aux_stack_start);
fail1:
wasm_runtime_deinstantiate_internal(new_module_inst, true);
@ -603,11 +587,26 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
bh_assert(cluster != NULL);
WASMExecEnv *exec_env_tls = NULL;
#ifdef OS_ENABLE_HW_BOUND_CHECK
/* Note: free_aux_stack can execute the module's "free" function
* using the specified exec_env. In case of OS_ENABLE_HW_BOUND_CHECK,
* it needs to match the TLS exec_env if available. (Consider a native
* function which calls wasm_cluster_destroy_spawned_exec_env.)
*/
exec_env_tls = wasm_runtime_get_exec_env_tls();
#endif
if (exec_env_tls == NULL) {
exec_env_tls = exec_env;
}
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env_tls,
exec_env->aux_stack_bottom.bottom);
os_mutex_lock(&cluster->lock);
/* Free aux stack space */
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
/* Remove exec_env */
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
/* Destroy exec_env */
@ -653,6 +652,9 @@ thread_manager_start_routine(void *arg)
wasm_cluster_thread_exited(exec_env);
#endif
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
os_mutex_lock(&cluster_list_lock);
os_mutex_lock(&cluster->lock);
@ -667,8 +669,12 @@ thread_manager_start_routine(void *arg)
since we will exit soon */
}
/* Free aux stack space */
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
#if WASM_ENABLE_PERF_PROFILING != 0
os_printf("============= Spawned thread ===========\n");
wasm_runtime_dump_perf_profiling(module_inst);
os_printf("========================================\n");
#endif
/* Remove exec_env */
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
/* Destroy exec_env */
@ -723,7 +729,8 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
}
/* Inherit suspend_flags of parent thread */
new_exec_env->suspend_flags.flags = exec_env->suspend_flags.flags;
new_exec_env->suspend_flags.flags =
(exec_env->suspend_flags.flags & WASM_SUSPEND_FLAG_INHERIT_MASK);
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
goto fail2;
@ -766,7 +773,7 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
{
/* workaround about passing instantiate-linking information */
CApiFuncImport **new_c_api_func_imports = NULL;
CApiFuncImport *c_api_func_imports;
CApiFuncImport *c_api_func_imports = NULL;
uint32 import_func_count = 0;
uint32 size_in_bytes = 0;
@ -1042,6 +1049,9 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval)
wasm_cluster_thread_exited(exec_env);
#endif
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
/* App exit the thread, free the resources before exit native thread */
os_mutex_lock(&cluster_list_lock);
@ -1060,8 +1070,6 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval)
module_inst = exec_env->module_inst;
/* Free aux stack space */
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
/* Remove exec_env */
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
/* Destroy exec_env */

View File

@ -6,7 +6,14 @@
#include "platform_api_vmcore.h"
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
return (uint64)aos_now_ms() * 1000;
}
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}

View File

@ -80,8 +80,6 @@ typedef jmp_buf korp_jmpbuf;
#define os_longjmp longjmp
#define os_alloca alloca
#define os_getpagesize getpagesize
typedef void (*os_signal_handler)(void *sig_addr);
int
@ -101,6 +99,8 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
#define os_getpagesize getpagesize
typedef long int __syscall_slong_t;
#if __ANDROID_API__ < 19

View File

@ -204,7 +204,7 @@ os_thread_wrapper(void *arg)
thread_data_list_add(thread_data);
thread_data->start_routine(thread_data->arg);
os_thread_cleanup();
os_thread_exit(NULL);
}
int

View File

@ -6,8 +6,15 @@
#include "platform_api_vmcore.h"
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
TickType_t ticks = xTaskGetTickCount();
return (uint64)1000 * 1000 / configTICK_RATE_HZ * ticks;
}
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}

View File

@ -15,6 +15,7 @@ static void
blocking_op_sighandler(int signo)
{
/* nothing */
(void)signo;
}
void

View File

@ -73,6 +73,8 @@ os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
clockid_t nclock_id;
__wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id);
(void)precision;
if (error != __WASI_ESUCCESS)
return error;

View File

@ -25,12 +25,14 @@
* For NuttX, CONFIG_HAS_ISATTY is provided by its platform header.
* (platform_internal.h)
*/
#if !defined(CONFIG_HAS_D_INO)
#if !defined(__NuttX__)
#define CONFIG_HAS_D_INO 1
#define CONFIG_HAS_ISATTY 1
#else
#define CONFIG_HAS_D_INO 0
#endif
#endif
#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(__COSMOPOLITAN__)
#define CONFIG_HAS_POSIX_FALLOCATE 1

View File

@ -78,19 +78,15 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
map_prot |= PROT_EXEC;
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
#ifndef __APPLE__
if (flags & MMAP_MAP_32BIT)
map_flags |= MAP_32BIT;
#endif
#endif
if (flags & MMAP_MAP_FIXED)
map_flags |= MAP_FIXED;
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
#if defined(__APPLE__)
retry_without_map_32bit:
#endif
#endif
#if defined(BUILD_TARGET_RISCV64_LP64D) || defined(BUILD_TARGET_RISCV64_LP64)
/* As AOT relocation in RISCV64 may require that the code/data mapped
* is in range 0 to 2GB, we try to map the memory with hint address
@ -148,14 +144,6 @@ retry_without_map_32bit:
}
if (addr == MAP_FAILED) {
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
#if defined(__APPLE__)
if ((map_flags & MAP_32BIT) != 0) {
map_flags &= ~MAP_32BIT;
goto retry_without_map_32bit;
}
#endif
#endif
#if BH_ENABLE_TRACE_MMAP != 0
os_printf("mmap failed\n");
#endif
@ -278,5 +266,8 @@ os_icache_flush(void *start, size_t len)
{
#if defined(__APPLE__) || defined(__MACH__)
sys_icache_invalidate(start, len);
#else
(void)start;
(void)len;
#endif
}

View File

@ -884,7 +884,7 @@ os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s)
int
os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
socklen_t opt_len = sizeof(ttl_s);
socklen_t opt_len = sizeof(*ttl_s);
if (getsockopt(socket, IPPROTO_IP, IP_TTL, ttl_s, &opt_len) != 0) {
return BHT_ERROR;
}
@ -906,7 +906,7 @@ os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s)
int
os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
socklen_t opt_len = sizeof(ttl_s);
socklen_t opt_len = sizeof(*ttl_s);
if (getsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, &opt_len)
!= 0) {
return BHT_ERROR;

View File

@ -6,7 +6,7 @@
#include "platform_api_vmcore.h"
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
@ -15,3 +15,14 @@ os_time_get_boot_microsecond()
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
}
uint64
os_time_thread_cputime_us()
{
struct timespec ts;
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {
return 0;
}
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
}

View File

@ -55,6 +55,7 @@ typedef pthread_t korp_tid;
typedef pthread_mutex_t korp_mutex;
typedef pthread_cond_t korp_cond;
typedef pthread_t korp_thread;
typedef pthread_rwlock_t korp_rwlock;
typedef sem_t korp_sem;
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@ -67,6 +68,12 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
static inline os_file_handle
os_get_invalid_handle()
{
return -1;
}
#if WASM_DISABLE_WRITE_GS_BASE == 0
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
#define os_writegsbase(base_addr) \
@ -98,8 +105,6 @@ typedef jmp_buf korp_jmpbuf;
#define os_longjmp longjmp
#define os_alloca alloca
#define os_getpagesize getpagesize
typedef void (*os_signal_handler)(void *sig_addr);
int
@ -119,6 +124,8 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
#define os_getpagesize getpagesize
#ifdef __cplusplus
}
#endif

View File

@ -82,8 +82,6 @@ typedef jmp_buf korp_jmpbuf;
#define os_longjmp longjmp
#define os_alloca alloca
#define os_getpagesize getpagesize
typedef void (*os_signal_handler)(void *sig_addr);
int
@ -103,6 +101,8 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
#define os_getpagesize getpagesize
#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0
#define OS_ENABLE_WAKEUP_BLOCKING_OP
#endif

View File

@ -36,11 +36,18 @@ os_vprintf(const char *format, va_list ap)
}
uint64
os_time_get_boot_microsecond(void)
os_time_get_boot_us(void)
{
return (uint64)esp_timer_get_time();
}
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}
uint8 *
os_thread_get_stack_boundary(void)
{

View File

@ -85,8 +85,6 @@ typedef jmp_buf korp_jmpbuf;
#define os_longjmp longjmp
#define os_alloca alloca
#define os_getpagesize getpagesize
typedef void (*os_signal_handler)(void *sig_addr);
int
@ -106,6 +104,8 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
#define os_getpagesize getpagesize
#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0
#define OS_ENABLE_WAKEUP_BLOCKING_OP
#endif

View File

@ -64,7 +64,13 @@ os_vprintf(const char *format, va_list ap);
* Get microseconds after boot.
*/
uint64
os_time_get_boot_microsecond(void);
os_time_get_boot_us(void);
/**
* Get thread-specific CPU-time clock in microseconds
*/
uint64
os_time_thread_cputime_us(void);
/**
* Get current thread id.

View File

@ -26,7 +26,7 @@ ocall_clock_nanosleep(int *p_ret, unsigned clock_id, int flags,
const void *rem_buf, unsigned int rem_buf_size);
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
#ifndef SGX_DISABLE_WASI
struct timespec ts;
@ -40,6 +40,21 @@ os_time_get_boot_microsecond()
#endif
}
uint64
os_time_thread_cputime_us(void)
{
#ifndef SGX_DISABLE_WASI
struct timespec ts;
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {
return 0;
}
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
#else
return 0;
#endif
}
#ifndef SGX_DISABLE_WASI
int

View File

@ -95,8 +95,6 @@ typedef jmp_buf korp_jmpbuf;
#define os_longjmp longjmp
#define os_alloca alloca
#define os_getpagesize getpagesize
typedef void (*os_signal_handler)(void *sig_addr);
int
@ -116,6 +114,8 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
#define os_getpagesize getpagesize
#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0
#define OS_ENABLE_WAKEUP_BLOCKING_OP
#endif

View File

@ -87,6 +87,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
void *
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
{
void *p;
#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
void *i_addr, *d_addr;
#endif
@ -110,7 +111,21 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
return in_ibus_ext(i_addr) ? i_addr : d_addr;
}
#endif
return malloc((uint32)size);
/* Note: aot_loader.c assumes that os_mmap provides large enough
* alignment for any data sections. Some sections like rodata.cst32
* actually require alignment larger than the natural alignment
* provided by malloc.
*
* Probably it's cleaner to add an explicit alignment argument to
* os_mmap. However, it only makes sense if we change our aot format
* to keep the necessary alignment.
*
* For now, let's assume 32 byte alignment is enough.
*/
if (posix_memalign(&p, 32, size)) {
return NULL;
}
return p;
}
void

View File

@ -10,25 +10,32 @@
#if IS_USED(MODULE_ZTIMER64_USEC)
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
return ztimer64_now(ZTIMER64_USEC);
}
#elif IS_USED(MODULE_ZTIMER64_MSEC)
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
return ztimer64_now(ZTIMER64_MSEC) * 1000;
}
#else
#ifdef __GNUC__
__attribute__((weak)) uint64
os_time_get_boot_microsecond();
os_time_get_boot_us();
#endif
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
static uint64_t times;
return ++times;
}
#endif
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}

View File

@ -120,13 +120,20 @@ os_vprintf(const char *format, va_list ap)
}
uint64
os_time_get_boot_microsecond(void)
os_time_get_boot_us(void)
{
uint64 ret = rt_tick_get() * 1000;
ret /= RT_TICK_PER_SECOND;
return ret;
}
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}
korp_tid
os_self_thread(void)
{

View File

@ -79,8 +79,6 @@ typedef jmp_buf korp_jmpbuf;
#define os_longjmp longjmp
#define os_alloca alloca
#define os_getpagesize getpagesize
typedef void (*os_signal_handler)(void *sig_addr);
int
@ -100,6 +98,8 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
#define os_getpagesize getpagesize
static inline os_file_handle
os_get_invalid_handle()
{

View File

@ -32,6 +32,7 @@ static bool is_winsock_inited = false;
int
init_winsock()
{
#if WASM_ENABLE_HOST_SOCKET_INIT == 0
WSADATA wsaData;
if (!is_winsock_inited) {
@ -42,6 +43,7 @@ init_winsock()
is_winsock_inited = true;
}
#endif
return BHT_OK;
}
@ -49,9 +51,11 @@ init_winsock()
void
deinit_winsock()
{
#if WASM_ENABLE_HOST_SOCKET_INIT == 0
if (is_winsock_inited) {
WSACleanup();
}
#endif
}
int

View File

@ -6,7 +6,7 @@
#include "platform_api_vmcore.h"
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
struct timespec ts;
#if defined(__MINGW32__)
@ -18,3 +18,10 @@ os_time_get_boot_microsecond()
return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
}
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}

View File

@ -6,7 +6,14 @@
#include "platform_api_vmcore.h"
uint64
os_time_get_boot_microsecond()
os_time_get_boot_us()
{
return k_uptime_get() * 1000;
}
uint64
os_time_thread_cputime_us(void)
{
/* FIXME if u know the right api */
return os_time_get_boot_us();
}

View File

@ -51,7 +51,9 @@ bh_hash_map_create(uint32 size, bool use_lock, HashFunc hash_func,
+ sizeof(HashMapElem *) * (uint64)size
+ (use_lock ? sizeof(korp_mutex) : 0);
if (total_size >= UINT32_MAX || !(map = BH_MALLOC((uint32)total_size))) {
/* size <= HASH_MAP_MAX_SIZE, so total_size won't be larger than
UINT32_MAX, no need to check integer overflow */
if (!(map = BH_MALLOC((uint32)total_size))) {
LOG_ERROR("HashMap create failed: alloc memory failed.\n");
return NULL;
}

View File

@ -17,6 +17,7 @@ bh_log_set_verbose_level(uint32 level)
log_verbose_level = level;
}
#ifndef BH_LOG
void
bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
{
@ -31,7 +32,7 @@ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
self = os_self_thread();
usec = os_time_get_boot_microsecond();
usec = os_time_get_boot_us();
t = (uint32)(usec / 1000000) % (24 * 60 * 60);
h = t / (60 * 60);
t = t % (60 * 60);
@ -56,6 +57,7 @@ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
os_printf("\n");
}
#endif
static uint32 last_time_ms = 0;
static uint32 total_time_ms = 0;

View File

@ -38,8 +38,14 @@ typedef enum {
void
bh_log_set_verbose_level(uint32 level);
#ifndef BH_LOG
void
bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
#else
void
BH_LOG(uint32 log_level, const char *file, int line, const char *fmt, ...);
#define bh_log BH_LOG
#endif
#ifdef BH_PLATFORM_NUTTX

View File

@ -38,7 +38,7 @@ struct _timer_ctx {
uint64
bh_get_tick_ms()
{
return os_time_get_boot_microsecond() / 1000;
return os_time_get_boot_us() / 1000;
}
uint32

View File

@ -62,6 +62,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM
#### **Enable Multi-Module feature**
- **WAMR_BUILD_MULTI_MODULE**=1/0, default to disable if not set
> Note: See [Multiple Modules as Dependencies](./multi_module.md) for more details.
#### **Enable WASM mini loader**
@ -82,6 +83,8 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM
- **WAMR_BUILD_LIB_PTHREAD**=1/0, default to disable if not set
> Note: The dependent feature of lib pthread such as the `shared memory` and `thread manager` will be enabled automatically.
> See [WAMR pthread library](./pthread_library.md) for more details.
#### **Enable lib-pthread-semaphore**
- **WAMR_BUILD_LIB_PTHREAD_SEMAPHORE**=1/0, default to disable if not set
> Note: This feature depends on `lib-pthread`, it will be enabled automatically if this feature is enabled.
@ -90,8 +93,11 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM
- **WAMR_BUILD_LIB_WASI_THREADS**=1/0, default to disable if not set
> Note: The dependent feature of lib wasi-threads such as the `shared memory` and `thread manager` will be enabled automatically.
> See [wasi-threads](./pthread_impls.md#wasi-threads-new) and [Introduction to WAMR WASI threads](https://bytecodealliance.github.io/wamr.dev/blog/introduction-to-wamr-wasi-threads) for more details.
#### **Enable lib wasi-nn**
- **WAMR_BUILD_WASI_NN**=1/0, default to disable if not set
> Note: See [WASI-NN](../core/iwasm/libraries/wasi-nn) for more details.
#### **Enable lib wasi-nn GPU mode**
- **WAMR_BUILD_WASI_NN_ENABLE_GPU**=1/0, default to disable if not set
@ -137,12 +143,17 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM
> Note: if it is enabled, developer can use API `void wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env)` to dump the memory consumption info.
Currently we only profile the memory consumption of module, module_instance and exec_env, the memory consumed by other components such as `wasi-ctx`, `multi-module` and `thread-manager` are not included.
> Also refer to [Memory usage estimation for a module](./memory_usage.md).
#### **Enable performance profiling (Experiment)**
- **WAMR_BUILD_PERF_PROFILING**=1/0, default to disable if not set
> Note: if it is enabled, developer can use API `void wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst)` to dump the performance consumption info. Currently we only profile the performance consumption of each WASM function.
> The function name searching sequence is the same with dump call stack feature.
> Also refer to [Tune the performance of running wasm/aot file](./perf_tune.md).
#### **Enable the global heap**
- **WAMR_BUILD_GLOBAL_HEAP_POOL**=1/0, default to disable if not set for all *iwasm* applications, except for the platforms Alios and Zephyr.
@ -179,7 +190,17 @@ Currently we only profile the memory consumption of module, module_instance and
> }
> ```
>
> and then use `cmake -DWAMR_BH_VPRINTF=my_vprintf ..` to pass the callback function, or add `BH_VPRINTF=my_vprintf` macro for the compiler, e.g. add line `add_defintions(-DBH_VPRINTF=my_vprintf)` in CMakeListst.txt.
> and then use `cmake -DWAMR_BH_VPRINTF=my_vprintf ..` to pass the callback function, or add `BH_VPRINTF=my_vprintf` macro for the compiler, e.g. add line `add_defintions(-DBH_VPRINTF=my_vprintf)` in CMakeListst.txt. See [basic sample](../samples/basic/src/main.c) for a usage example.
#### **WAMR_BH_LOG**=<log_callback>, default to disable if not set
> Note: if the log_callback function is provided by the developer, WAMR logs are redirected to such callback. For example:
> ```C
> void my_log(uint32 log_level, const char *file, int line, const char *fmt, ...)
> {
> /* Usage of custom logger */
> }
> ```
> See [basic sample](../samples/basic/src/main.c) for a usage example.
#### **Enable reference types feature**
- **WAMR_BUILD_REF_TYPES**=1/0, default to disable if not set
@ -192,7 +213,7 @@ Currently we only profile the memory consumption of module, module_instance and
#### **Enable source debugging features**
- **WAMR_BUILD_DEBUG_INTERP**=1/0, default to 0 if not set
> Note: There are some other setup required by source debugging, please refer to [source_debugging.md](./source_debugging.md) for more details.
> Note: There are some other setup required by source debugging, please refer to [source_debugging.md](./source_debugging.md) and [WAMR source debugging basic](https://bytecodealliance.github.io/wamr.dev/blog/wamr-source-debugging-basic) for more details.
#### **Enable load wasm custom sections**
- **WAMR_BUILD_LOAD_CUSTOM_SECTION**=1/0, default to disable if not set
@ -207,12 +228,34 @@ Currently we only profile the memory consumption of module, module_instance and
- **WAMR_BUILD_STACK_GUARD_SIZE**=n, default to N/A if not set.
> Note: By default, the stack guard size is 1K (1024) or 24K (if uvwasi enabled).
### **Disable the writing linear memory base address to x86 GS segment register
### **Disable the writing linear memory base address to x86 GS segment register**
- **WAMR_DISABLE_WRITE_GS_BASE**=1/0, default to enable if not set and supported by platform
> Note: by default only platform [linux x86-64](https://github.com/bytecodealliance/wasm-micro-runtime/blob/5fb5119239220b0803e7045ca49b0a29fe65e70e/core/shared/platform/linux/platform_internal.h#L67) will enable this feature, for 32-bit platforms it's automatically disabled even when the flag is set to 0. In linux x86-64, writing the linear memory base address to x86 GS segment register may be used to speedup the linear memory access for LLVM AOT/JIT, when `--enable-segue=[<flags>]` option is added for `wamrc` or `iwasm`.
> See [Enable segue optimization for wamrc when generating the aot file](./perf_tune.md#3-enable-segue-optimization-for-wamrc-when-generating-the-aot-file) for more details.
### **Enable running PGO(Profile-Guided Optimization) instrumented AOT file**
- **WAMR_BUILD_STATIC_PGO**=1/0, default to disable if not set
> Note: See [Use the AOT static PGO method](./perf_tune.md#5-use-the-aot-static-pgo-method) for more details.
### **Enable linux perf support**
- **WAMR_BUILD_LINUX_PERF**=1/0, enable linux perf support to generate the flamegraph to analyze the performance of a wasm application, default to disable if not set
> Note: See [Use linux-perf](./perf_tune.md#7-use-linux-perf) for more details.
### **Enable module instance context APIs**
- **WAMR_BUILD_MODULE_INST_CONTEXT**=1/0, enable module instance context APIs which can set one or more contexts created by the embedder for a wasm module instance, default to enable if not set:
```C
wasm_runtime_create_context_key
wasm_runtime_destroy_context_key
wasm_runtime_set_context
wasm_runtime_set_context_spread
wasm_runtime_get_context
```
> Note: See [wasm_export.h](../core/iwasm/include/wasm_export.h) for more details.
### **Enable quick AOT/JTI entries**
- **WAMR_BUILD_QUICK_AOT_ENTRY**=1/0, enable registering quick call entries to speedup the aot/jit func call process, default to enable if not set
> Note: See [Refine callings to AOT/JIT functions from host native](./perf_tune.md#83-refine-callings-to-aotjit-functions-from-host-native) for more details.
**Combination of configurations:**

View File

@ -5,7 +5,7 @@ Prepare WASM building environments
For C and C++, WASI-SDK version 19.0+ is the major tool supported by WAMR to build WASM applications. Also, we can use [Emscripten SDK (EMSDK)](https://github.com/emscripten-core/emsdk), but it is not recommended. And there are some other compilers such as the standard clang compiler, which might also work [here](./other_wasm_compilers.md).
To install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
To install WASI SDK, please download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
The official *wasi-sdk release* doesn't fully support *latest 128-bit SIMD spec* yet. WAMR provides a script in [build-wasi-sdk](../test-tools/build-wasi-sdk/) to generate
another wasi-sdk with *llvm-15* from source code and installs it at *../test-tools/wasi-sdk*. If you plan to build WASM applications with *latest 128-bit SIMD*, please use it instead of the official release.

View File

@ -6,7 +6,7 @@ WAMR loads all dependencies recursively according to the _import section_ of a m
> WAMR only implements the load-time dynamic linking. Please refer to [dynamic linking](https://webassembly.org/docs/dynamic-linking/) for more details.
WAMR follows [WASI Command/Reactor Model](https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md#current-unstable-abi). The WASI model separates modules into commands and reactors. A Command is the main module that requires exports of reactors(submodules).
WAMR follows [WASI Command/Reactor Model](https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md#current-unstable-abi). The WASI model separates modules into commands and reactors. A Command is the main module that requires exports of reactors(submodules).
if `WASM_ENABLE_LIBC_WASI` is enabled, any module imports a WASI APIs, like `(import "wasi_snapshot_preview1" "XXX")`, should follow restrictions of the _WASI application ABI_:

View File

@ -190,3 +190,112 @@ $ ./FlameGraph/flamegraph.pl out.folded > perf.foo.wasm.svg
>
> Then you will see a new file named _out.folded.translated_ which contains the translated folded stacks.
> All wasm functions are translated to its original names with a prefix like "[Wasm]"
## 8. Refine the calling processes between host native and wasm application
In some scenarios, there may be lots of callings between host native and wasm application, e.g. frequent callings to AOT/JIT functions from host native or frequent callings to host native from AOT/JIT functions. It is important to refine these calling processes to speedup them, WAMR provides several methods:
### 8.1 Refine callings to native APIs registered by `wasm_runtime_register_natives` from AOT code
When wamrc compiles the wasm file to AOT code, it may generate LLVM IR to call the native API from an AOT function, and if it doesn't know the native API's signature, the generated LLVM IR has to call the runtime API `aot_invoke_native` to invoke the native API, which is a relatively slow way. If developer registers native APIs during execution by calling `wasm_runtime_register_natives` or by `iwasm --native-lib=<lib>`, then developer can also register native APIs with the same signatures to the AOT compiler by `wamrc --native-lib=<lib>`, so as to let the AOT compiler pre-know the native API's signature, and generate optimized LLVM IR to quickly call to the native API.
The below sample registers an API `int test_add(int, int)` to the AOT compiler:
```C
/* test_add.c */
#include "wasm_export.h"
static int
test_add_wrapper(wasm_exec_env_t exec_env, int x, int y) {
return 0; /* empty function is enough */
}
#define REG_NATIVE_FUNC(func_name, signature) \
{ #func_name, func_name##_wrapper, signature, NULL }
static NativeSymbol native_symbols[] = {
REG_NATIVE_FUNC(test_add, "(ii)i")
};
uint32_t
get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols)
{
*p_module_name = "env";
*p_native_symbols = native_symbols;
return sizeof(native_symbols) / sizeof(NativeSymbol);
}
```
```bash
# build native lib
gcc -O3 -fPIC -shared -I <wamr_root>/core/iwasm/include -o libtest_add.so test_add.c
# register native lib to aot compiler
wamrc --native-lib=./libtest_add.so -o <aot_file> <wasm_file>
```
> Note: no need to do anything for LLVM JIT since the native APIs must have been registered before execution and JIT compiler already knows the native APIs' signatures.
### 8.2 Refine callings to native APIs registered by wasm-c-api `wasm_instance_new` from AOT code
In wasm-c-api mode, when the native APIs are registered by `wasm_instance_new(..., imports, ...)`, developer can use `wamrc --invoke-c-api-import` option to generate the AOT file, which treats the unknown import function as wasm-c-api import function and generates optimized LLVM IR to speedup the calling process.
> Note: no need to do anything for LLVM JIT since the similar flag has been set to JIT compiler in wasm-c-api `wasm_engine_new` when LLVM JIT is enabled.
### 8.3 Refine callings to AOT/JIT functions from host native
Currently by default WAMR runtime has registered many quick AOT/JIT entries to speedup the calling processes to call AOT/JIT functions from host native, as long as developer doesn't disable it by using `cmake -DWAMR_BUILD_QUICK_AOT_ENTRY=0` or setting the compiler macro `WASM_ENABLE_QUICK_AOT_ENTRY` to 0 in the makefile. These quick AOT/JIT entries include:
1. wasm function contains 0 to 4 arguments and 0 to 1 results, with the type of each argument is i32 or i64 and the type of result is i32, i64 or void. These functions are like:
```C
// no argument
i32 foo(), i64 foo(), void foo()
// one argument, each argument is i32 or i64
i32 foo(i32/i64), i64 foo(i32/i64), void(i32/i64)
// two arguments, each argument is i32 or i64
i32 foo(i32/i64, i32/i64), i64 foo(i32/i64, i32/i64), void(i32/i64, i32/i64)
// three arguments, each argument is i32 or i64
i32 foo(i32/i64, i32/i64, i32/i64), i64 foo(i32/i64, i32/i64, i32/i64), void(i32/i64, i32/i64, i32/i64)
// four arguments, each argument is i32 or i64
i32 foo(i32/i64, i32/i64, i32/i64, i32/i64)
i64 foo(i32/i64, i32/i64, i32/i64, i32/i64)
void(i32/i64, i32/i64, i32/i64, i32/i64)
```
2. wasm function contains 5 arguments and 0 to 1 results, with the type of each argument is i32 and the type of result is i32, i64 or void. These functions are like:
```C
i32 foo(i32, i32, i32, i32, i32)
i64 foo(i32, i32, i32, i32, i32)
void foo(i32, i32, i32, i32, i32)
```
To speedup the calling processes, developer had better ensure that the signatures of the wasm functions to expose are like above, or add some conversions to achieve it. For example, if a wasm function to call is `f32 foo(f32)`, developer can define a new function `i32 foo1(i32)` like below and export it:
```C
int32 foo1(int32 arg_i32)
{
float arg_f32 = *(float *)&arg_i32;
float res_f32 = foo(f32);
int32 res_i32 = *(int32 *)&res_i32;
return res_i32;
}
```
And in the host embedder:
```
uint32 argv[2];
float arg_f32 = ...; /* argument to foo */
float res_f32;
bool ret;
argv[0] = *(uint32 *)&arg_f32;
func = wasm_runtime_lookup_function(module_inst, "foo1", NULL);
ret = wasm_runtime_call_wasm(exec_env, func, 1, argv);
if (!ret) {
/* handle exception */
printf("%s\n", wasm_runtime_get_exception(module_inst));
}
else {
/* the return value is stored in argv[0] */
res_f32 = *(float *)&argv[0];
}
```

View File

@ -188,18 +188,6 @@ class AdvancedTestSuite(unittest.TestCase):
ffi.wasm_func_call(func, params, results)
self.assertEqual(params.data[0].of.f32 * 2, results.data[0].of.f64)
def test_wasm_func_call_wrong_params(self):
export_list = ffi.wasm_vec_to_list(self.exports)
func = ffi.wasm_extern_as_func(export_list[0])
# make a call
params = ffi.wasm_val_vec_t()
ffi.wasm_val_vec_new_empty(params)
results = ffi.wasm_val_vec_t()
ffi.wasm_val_vec_new_empty(results)
trap = ffi.wasm_func_call(func, params, results)
self.assertIsNotNullPointer(trap)
def test_wasm_func_call_unlinked(self):
ft = ffi.wasm_functype_new_0_0()
func = ffi.wasm_func_new(self._wasm_store, ft, callback)
@ -453,26 +441,6 @@ class AdvancedTestSuite(unittest.TestCase):
ffi.wasm_memory_data_size(mem)
ffi.wasm_memory_delete(mem)
def test_wasm_trap(self):
export_list = ffi.wasm_vec_to_list(self.exports)
func = ffi.wasm_extern_as_func(export_list[0])
# make a call
params = ffi.wasm_val_vec_t()
ffi.wasm_val_vec_new_empty(params)
results = ffi.wasm_val_vec_t()
ffi.wasm_val_vec_new_empty(results)
trap = ffi.wasm_func_call(func, params, results)
self.assertIsNotNullPointer(trap)
message = ffi.wasm_message_t()
ffi.wasm_trap_message(trap, message)
self.assertIsNotNullPointer(c.pointer(message))
# not a function internal exception
frame = ffi.wasm_trap_origin(trap)
self.assertIsNullPointer(frame)
@unittest.skipUnless(
TEST_WITH_WAMR_BUILD_DUMP_CALL_STACK,
"need to enable WAMR_BUILD_DUMP_CALL_STACK",

View File

@ -447,12 +447,12 @@ make
## Cosmopolitan Libc
Currently, only x86_64 architecture with interpreter modes is supported.
Clone the Cosmopolitan Libc. Setup `cosmocc` as described in [Getting Started](https://github.com/jart/cosmopolitan/#getting-started) being sure to get it into `PATH`.
Setup `cosmocc` as described in [Getting Started](https://github.com/jart/cosmopolitan/#getting-started) being sure to get its `bin` directory into `PATH`.
Build iwasm
``` Bash
export CC=cosmocc
export CXX=cosmoc++
export CC=x86_64-unknown-cosmo-cc
export CXX=x86_64-unknown-cosmo-c++
rm -rf build
mkdir build
cmake -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 -B build

View File

@ -2,8 +2,8 @@
# Copyright (C) 2023 Dylibso. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
export CC=cosmocc
export CXX=cosmoc++
export CC=x86_64-unknown-cosmo-cc
export CXX=x86_64-unknown-cosmo-c++
rm -rf build
mkdir build
cmake -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 -B build

View File

@ -142,6 +142,12 @@ else
CFLAGS += -DWASM_ENABLE_AOT=0
endif
ifeq ($(CONFIG_INTERPRETERS_WAMR_AOT_QUICK_ENTRY),y)
CFLAGS += -DWASM_ENABLE_QUICK_AOT_ENTRY=1
else
CFLAGS += -DWASM_ENABLE_QUICK_AOT_ENTRY=0
endif
ifeq ($(CONFIG_INTERPRETERS_WAMR_AOT_WORD_ALIGN_READ),y)
CFLAGS += -DWASM_ENABLE_WORD_ALIGN_READ=1
else
@ -192,9 +198,7 @@ CSRCS += utils.c
VPATH += $(IWASM_ROOT)/libraries/debug-engine
endif
ifeq ($(CONFIG_INTERPRETERS_WAMR_STACK_GUARD_SIZE),)
CFLAGS += -DWASM_STACK_GUARD_SIZE=0
else
ifneq ($(CONFIG_INTERPRETERS_WAMR_STACK_GUARD_SIZE),)
CFLAGS += -DWASM_STACK_GUARD_SIZE=CONFIG_INTERPRETERS_WAMR_STACK_GUARD_SIZE
endif

View File

@ -21,7 +21,7 @@ echo "#####################build basic project"
cd ${CURR_DIR}
mkdir -p cmake_build
cd cmake_build
cmake ..
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BH_VPRINTF=my_vprintf -DWAMR_BH_LOG=my_log
make -j ${nproc}
if [ $? != 0 ];then
echo "BUILD_FAIL basic exit as $?\n"

View File

@ -15,6 +15,30 @@ get_pow(int x, int y);
int32_t
calculate_native(int32_t n, int32_t func1, int32_t func2);
void
my_log(uint32 log_level, const char *file, int line, const char *fmt, ...)
{
char buf[200];
snprintf(buf, 200,
log_level == WASM_LOG_LEVEL_VERBOSE ? "[WamrLogger - VERBOSE] %s"
: "[WamrLogger] %s",
fmt);
va_list ap;
va_start(ap, fmt);
vprintf(buf, ap);
va_end(ap);
}
int
my_vprintf(const char *format, va_list ap)
{
/* Print in blue */
char buf[200];
snprintf(buf, 200, "\x1b[34m%s\x1b[0m", format);
return vprintf(buf, ap);
}
void
print_usage(void)
{
@ -95,6 +119,7 @@ main(int argc, char *argv_main[])
printf("Init runtime environment failed.\n");
return -1;
}
wasm_runtime_set_log_level(WASM_LOG_LEVEL_VERBOSE);
buffer = bh_read_file_to_buffer(wasm_path, &buf_size);
@ -103,7 +128,8 @@ main(int argc, char *argv_main[])
goto fail;
}
module = wasm_runtime_load(buffer, buf_size, error_buf, sizeof(error_buf));
module = wasm_runtime_load((uint8 *)buffer, buf_size, error_buf,
sizeof(error_buf));
if (!module) {
printf("Load wasm module failed. error: %s\n", error_buf);
goto fail;

View File

@ -5,7 +5,7 @@ This sample can also demonstrate the SGX IPFS (Intel Protected File System), ena
## Preparation
Please install WASI SDK, download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
Please install WASI SDK, download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
For testing with SGX IPFS, follow the instructions in [the documentation of SGX for WAMR](../../doc/linux_sgx.md#sgx-intel-protected-file-system).
## Build the sample

View File

@ -132,6 +132,7 @@ endif()
# .c -> .wasm
ExternalProject_Add(WASM_MODULE
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND}

View File

@ -29,7 +29,7 @@ get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols)
## Preparation
Please install WASI SDK, download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
Please install WASI SDK, download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
## Build the sample

View File

@ -21,7 +21,7 @@ echo "##################### build shared-module project"
cd ${CURR_DIR}
mkdir -p cmake_build
cd cmake_build
cmake ..
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j ${nproc}
if [ $? != 0 ];then
echo "BUILD_FAIL shared-module exit as $?\n"

View File

@ -17,7 +17,7 @@ APP_LIB_SRC="${APP_FRAMEWORK_DIR}/base/app/*.c ${APP_FRAMEWORK_DIR}/sensor/app/*
${APP_FRAMEWORK_DIR}/connection/app/*.c ${NATIVE_LIBS}/*.c"
WASM_APPS=${PWD}/wasm-apps
CLEAN=
CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Release"
CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug"
CM_TOOLCHAIN=""
usage ()

View File

@ -6,7 +6,7 @@ how they communicate with each other.
## Preparation
Please install WASI SDK, download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
Please install WASI SDK, download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And install wabt, download the [wabt release](https://github.com/WebAssembly/wabt/releases) and extract the archive to default path `/opt/wabt`
## Build the sample

1
samples/terminate/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/out/

View File

@ -0,0 +1,98 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.14)
include(CheckPIESupported)
project (terminate)
set (CMAKE_CXX_STANDARD 17)
################ runtime settings ################
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
if (APPLE)
add_definitions(-DBH_PLATFORM_DARWIN)
endif ()
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# WAMR features switch
# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Debug)
endif ()
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_LIB_WASI_THREADS 1)
set (WAMR_BUILD_THREAD_MGR 1)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
# fast interpreter
# set (WAMR_BUILD_FAST_INTERP 1)
# fast-jit
# set (WAMR_BUILD_FAST_JIT 1)
# llvm jit
# set (WAMR_BUILD_JIT 1)
# set (LLVM_DIR /usr/local/opt/llvm@14/lib/cmake/llvm)
set (WAMR_BUILD_REF_TYPES 1)
if (NOT MSVC)
# linker flags
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
endif ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
endif ()
endif ()
endif ()
# build out vmlib
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
################ application related ################
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable (terminate src/main.c ${UNCOMMON_SHARED_SOURCE})
check_pie_supported()
set_target_properties (terminate PROPERTIES POSITION_INDEPENDENT_CODE ON)
if (APPLE)
target_link_libraries (terminate vmlib -lm -ldl -lpthread ${LLVM_AVAILABLE_LIBS})
else ()
target_link_libraries (terminate vmlib -lm -ldl -lpthread -lrt ${LLVM_AVAILABLE_LIBS})
endif ()

View File

@ -0,0 +1,4 @@
The "terminate" sample project
==============================
This sample demonstrates wasm_runtime_terminate API.

63
samples/terminate/build.sh Executable file
View File

@ -0,0 +1,63 @@
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#!/bin/bash
CURR_DIR=$PWD
WAMR_DIR=${PWD}/../..
OUT_DIR=${PWD}/out
WASM_APPS=${PWD}/wasm-apps
rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
mkdir ${OUT_DIR}/wasm-apps
echo "##################### build terminate project"
cd ${CURR_DIR}
mkdir -p cmake_build
cd cmake_build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j ${nproc}
if [ $? != 0 ];then
echo "BUILD_FAIL terminate exit as $?\n"
exit 2
fi
cp -a terminate ${OUT_DIR}
printf "\n"
echo "##################### build wasm apps"
cd ${WASM_APPS}
for i in `ls *.wat`
do
APP_SRC="$i"
OUT_FILE=${i%.*}.wasm
# Note: the CI installs wabt in /opt/wabt
if type wat2wasm; then
WAT2WASM=${WAT2WASM:-wat2wasm}
elif [ -x /opt/wabt/bin/wat2wasm ]; then
WAT2WASM=${WAT2WASM:-/opt/wabt/bin/wat2wasm}
fi
${WAT2WASM} -o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
# aot
# wamrc -o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot ${OUT_DIR}/wasm-apps/${OUT_FILE}
# mv ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot ${OUT_DIR}/wasm-apps/${OUT_FILE}
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
echo "build ${OUT_FILE} success"
else
echo "build ${OUT_FILE} fail"
fi
done
echo "##################### build wasm apps done"

3
samples/terminate/run.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
out/terminate -f out/wasm-apps/testapp.wasm

View File

@ -0,0 +1,219 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include "wasm_export.h"
#include "bh_read_file.h"
#include "bh_getopt.h"
void
print_usage(void)
{
fprintf(stdout, "Options:\r\n");
fprintf(stdout, " -f [path of wasm file] \n");
}
static void *
runner_with_sigleton_exec_env(void *vp)
{
wasm_module_inst_t inst = vp;
bool ok = wasm_runtime_init_thread_env();
assert(ok);
wasm_application_execute_main(inst, 0, NULL);
wasm_runtime_destroy_thread_env();
return inst;
}
static void *
runner_with_spawn_exec_env(void *vp)
{
wasm_exec_env_t env = vp;
wasm_module_inst_t inst = wasm_runtime_get_module_inst(env);
wasm_function_inst_t func;
bool ok = wasm_runtime_init_thread_env();
assert(ok);
func = wasm_runtime_lookup_function(inst, "block_forever", NULL);
assert(func != NULL);
wasm_runtime_call_wasm(env, func, 0, NULL);
wasm_runtime_destroy_spawned_exec_env(env);
wasm_runtime_destroy_thread_env();
return inst;
}
int
main(int argc, char *argv_main[])
{
int exit_code = 1;
static char global_heap_buf[512 * 1024];
char *buffer;
char error_buf[128];
int opt;
char *wasm_path = NULL;
int ret;
int pipe_fds[2];
const unsigned int N = 4;
wasm_module_t module = NULL;
wasm_module_inst_t module_inst[N];
pthread_t th[N];
unsigned int i;
uint32 buf_size, stack_size = 8092, heap_size = 8092;
for (i = 0; i < N; i++) {
module_inst[i] = NULL;
}
RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
while ((opt = getopt(argc, argv_main, "hf:")) != -1) {
switch (opt) {
case 'f':
wasm_path = optarg;
break;
case 'h':
print_usage();
return 0;
case '?':
print_usage();
return 0;
}
}
if (optind == 1) {
print_usage();
return 0;
}
memset(&init_args, 0, sizeof(init_args));
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
if (!wasm_runtime_full_init(&init_args)) {
printf("Init runtime environment failed.\n");
return -1;
}
buffer = bh_read_file_to_buffer(wasm_path, &buf_size);
if (!buffer) {
printf("Open wasm app file [%s] failed.\n", wasm_path);
goto fail;
}
module = wasm_runtime_load((uint8 *)buffer, buf_size, error_buf,
sizeof(error_buf));
if (!module) {
printf("Load wasm module failed. error: %s\n", error_buf);
goto fail;
}
/* Ensure that fd_read on FD 0 blocks. */
ret = pipe(pipe_fds);
if (ret != 0) {
goto fail;
}
wasm_runtime_set_wasi_args_ex(module, NULL, 0, NULL, 0, NULL, 0, NULL, 0,
pipe_fds[0], -1, -1);
for (i = 0; i < N; i++) {
bool use_wasm_runtime_spawn_exec_env = i / 2 == 0;
wasm_exec_env_t env;
module_inst[i] = wasm_runtime_instantiate(module, stack_size, heap_size,
error_buf, sizeof(error_buf));
if (!module_inst[i]) {
printf("Instantiate wasm module failed. error: %s\n", error_buf);
goto fail;
}
/* Note: ensure that module inst has an exec env so that
* it can receive the termination request.
*/
env = wasm_runtime_get_exec_env_singleton(module_inst[i]);
assert(env != NULL);
if (use_wasm_runtime_spawn_exec_env) {
env = wasm_runtime_spawn_exec_env(env);
assert(env != NULL);
}
if ((i % 2) == 0) {
printf("terminating thread %u before starting\n", i);
wasm_runtime_terminate(module_inst[i]);
}
if (use_wasm_runtime_spawn_exec_env) {
printf("starting thread %u (spawn_exec_env)\n", i);
ret = pthread_create(&th[i], NULL, runner_with_spawn_exec_env, env);
if (ret != 0) {
wasm_runtime_destroy_spawned_exec_env(env);
goto fail;
}
}
else {
printf("starting thread %u (singleton exec_env)\n", i);
ret = pthread_create(&th[i], NULL, runner_with_sigleton_exec_env,
module_inst[i]);
if (ret != 0) {
goto fail;
}
}
}
printf("sleeping a bit to ensure that the threads actually started\n");
sleep(1);
for (i = 0; i < N; i++) {
if ((i % 2) != 0) {
printf("terminating thread %u\n", i);
wasm_runtime_terminate(module_inst[i]);
}
}
for (i = 0; i < N; i++) {
printf("joining thread %u\n", i);
void *status;
ret = pthread_join(th[i], &status);
if (ret != 0) {
printf("pthread_join failed for thread %u\n", i);
goto fail;
}
}
for (i = 0; i < N; i++) {
const char *exception = wasm_runtime_get_exception(module_inst[i]);
if (exception != NULL) {
if (!strstr(exception, "terminated by user")) {
printf("thread %u got an exception: %s (unexpected)\n", i,
exception);
goto fail;
}
printf("thread %u got an exception: %s (expected)\n", i, exception);
}
else {
printf("thread %u got no exception (unexpected)\n", i);
goto fail;
}
}
exit_code = 0;
fail:
for (i = 0; i < N; i++) {
if (module_inst[i])
wasm_runtime_deinstantiate(module_inst[i]);
}
if (module)
wasm_runtime_unload(module);
if (buffer)
BH_FREE(buffer);
wasm_runtime_destroy();
return exit_code;
}

View File

@ -0,0 +1,53 @@
;; Copyright (C) 2024 YAMAMOTO Takashi
;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
(module
(func $fd_read (import "wasi_snapshot_preview1" "fd_read") (param i32 i32 i32 i32) (result i32))
(func $block_forever (export "block_forever")
;; read from FD 0
i32.const 100 ;; iov_base
i32.const 200 ;; buffer
i32.store
i32.const 104 ;; iov_len
i32.const 1
i32.store
i32.const 0 ;; fd 0
i32.const 100 ;; iov_base
i32.const 1 ;; iov count
i32.const 300 ;; retp (out)
call $fd_read
unreachable
)
(func (export "_start")
call $block_forever
)
;; a dumb malloc/free implementation
(func (export "malloc") (param i32) (result i32)
local.get 0
i32.const 65535
i32.add
i32.const 65536
i32.div_u
memory.grow
local.set 0
local.get 0
i32.const -1
i32.eq
if
i32.const 0
return
end
local.get 0
i32.const 65536
i32.mul
)
(func (export "free") (param i32))
(memory (export "memory") 1)
;; fake globals to make wasm_set_aux_stack happy
(global (export "__heap_base") i32 (i32.const 0x10000))
(global (export "__data_end") i32 (i32.const 0x10000))
(global (mut i32) (i32.const 0x10000))
)

View File

@ -9,6 +9,7 @@
/* See https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
#define ASSERT_VALID_TID(TID) \
(void)TID; \
assert(TID >= 1 && TID <= 0x1FFFFFFF && "Invalid thread ID")
typedef struct {

View File

@ -10,7 +10,7 @@ Please build iwasm and wamrc, refer to:
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And install WASI SDK, please download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And then run `./build.sh` to build the source code, file `coremark.exe`, `coremark.wasm` and `coremark.aot` will be generated.

View File

@ -10,7 +10,7 @@ Please build iwasm and wamrc, refer to:
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And install WASI SDK, please download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And then run `./build.sh` to build the source code, the folder `out` will be created and files will be generated under it.

View File

@ -10,7 +10,7 @@ Please build iwasm and wamrc, refer to:
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And install WASI SDK, please download the [wasi-sdk release](https://github.com/WebAssembly/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
And then run `./build.sh` to build the source code, the folder `out` will be created and files will be generated under it.

View File

@ -58,25 +58,38 @@ if (DEFINED WAMR_BUILD_AOT_FUNC_PREFIX)
add_definitions(-DAOT_FUNC_PREFIX="${WAMR_BUILD_AOT_FUNC_PREFIX}")
endif ()
# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
if (NOT WAMR_BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "i686")
set (WAMR_BUILD_TARGET "X86_32")
endif ()
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64")
set (WAMR_BUILD_TARGET "AMD_64")
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64"
OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm.*")
message(STATUS "Assuming ${CMAKE_HOST_SYSTEM_PROCESSOR} as ARM_32")
set (WAMR_BUILD_TARGET "ARM_32")
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "mips")
set (WAMR_BUILD_TARGET "MIPS_32")
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "xtensa")
set (WAMR_BUILD_TARGET "XTENSA_32")
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv")
message(STATUS "Assuming ${CMAKE_HOST_SYSTEM_PROCESSOR} as RISCV32")
set (WAMR_BUILD_TARGET "RISCV32")
else ()
message (FATAL_ERROR "Unsupported CMAKE_HOST_SYSTEM_PROCESSOR "
"${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
if (("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32"))
set (WAMR_BUILD_TARGET "X86_32")
endif()
elseif (WAMR_BUILD_PLATFORM STREQUAL "darwin")
if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
endif ()
endif()
endif ()
string(TOUPPER ${WAMR_BUILD_TARGET} WAMR_BUILD_TARGET)

Some files were not shown because too many files have changed in this diff Show More