diff --git a/cmake/libraries.cmake b/cmake/libraries.cmake
index 1b43d523bfa..8cf2ec8b3f0 100644
--- a/cmake/libraries.cmake
+++ b/cmake/libraries.cmake
@@ -23,4 +23,4 @@ set(FLB_PATH_LIB_CARES "lib/c-ares-1.24.0")
set(FLB_PATH_LIB_SNAPPY "lib/snappy-fef67ac")
set(FLB_PATH_LIB_RDKAFKA "lib/librdkafka-2.1.0")
set(FLB_PATH_LIB_RING_BUFFER "lib/lwrb")
-set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.2.2")
+set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.3.0")
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml b/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml
deleted file mode 100644
index 7b8403777fa..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml
+++ /dev/null
@@ -1,145 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-name: spec test on nuttx
-
-on:
- schedule:
- - cron: '0 0 * * *'
-
- workflow_dispatch:
-
-env:
- LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex"
- WASI_SDK_PATH: "/opt/wasi-sdk"
-
-jobs:
- build_llvm_libraries:
- uses: ./.github/workflows/build_llvm_libraries.yml
- with:
- os: "ubuntu-22.04"
- arch: "ARM RISCV AArch64"
-
- spec_test_on_qemu:
- runs-on: ${{ matrix.os }}
- needs: [build_llvm_libraries]
- strategy:
- matrix:
- os: [ubuntu-22.04]
- nuttx_board_config: [
- # cortex-a9
- "boards/arm/imx6/sabre-6quad/configs/nsh",
- # riscv32imac
- "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
- # riscv64imac
- # "boards/risc-v/qemu-rv/rv-virt/configs/nsh64",
- ]
- wamr_test_option: [
- # "-t fast-interp",
- "-t aot",
- "-t aot -X"
- ]
- llvm_cache_key: [ "${{ needs.build_llvm_libraries.outputs.cache_key }}" ]
- steps:
- - name: Install Utilities
- run: |
- sudo apt install -y kconfig-frontends-nox genromfs
-
- - name: Install ARM Compilers
- if: contains(matrix.nuttx_board_config, 'arm')
- run: sudo apt install -y gcc-arm-none-eabi
-
- - name: Install RISC-V Compilers
- if: contains(matrix.nuttx_board_config, 'risc-v')
- run: |
- curl -L https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz > riscv.tar.gz
- tar xvf riscv.tar.gz
- echo "$PWD/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH
-
- - name: Install WASI-SDK
- run: |
- curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz > wasi-sdk.tar.gz
- tar xvf wasi-sdk.tar.gz
- sudo mv wasi-sdk-* /opt/wasi-sdk
-
- - name: Checkout NuttX
- uses: actions/checkout@v3
- with:
- repository: apache/incubator-nuttx
- path: nuttx
-
- - name: Checkout NuttX Apps
- uses: actions/checkout@v3
- with:
- repository: apache/incubator-nuttx-apps
- path: apps
-
- - name: Checkout WAMR
- uses: actions/checkout@v3
- with:
- repository: ${{ github.repository }}
- path: apps/interpreters/wamr/wamr
-
- - name: Get LLVM libraries
- id: retrieve_llvm_libs
- uses: actions/cache@v3
- with:
- path: |
- ./core/deps/llvm/build/bin
- ./core/deps/llvm/build/include
- ./core/deps/llvm/build/lib
- ./core/deps/llvm/build/libexec
- ./core/deps/llvm/build/share
- key: ${{ matrix.llvm_cache_key }}
-
- - name: Quit if cache miss
- if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
- run: echo "::error::can not get prebuilt llvm libraries" && exit 1
-
- - name: Copy LLVM
- run: cp -r core/deps/llvm apps/interpreters/wamr/wamr/core/deps/llvm
-
- - name: Enable WAMR for NuttX
- run: |
- find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_INTERPRETERS_WAMR=y\nCONFIG_INTERPRETERS_WAMR_STACKSIZE=32768\nCONFIG_INTERPRETERS_WAMR_AOT=y\nCONFIG_INTERPRETERS_WAMR_FAST=y\nCONFIG_INTERPRETERS_WAMR_LOG=y\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\nCONFIG_INTERPRETERS_WAMR_REF_TYPES=y\nCONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST=y\nCONFIG_INTERPRETERS_WAMR_SHARED_MEMORY=y\nCONFIG_INTERPRETERS_WAMR_BULK_MEMORY=y\n'
- find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\nCONFIG_ARM_SEMIHOSTING_HOSTFS=y\nCONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y\nCONFIG_RISCV_SEMIHOSTING_HOSTFS=y\nCONFIG_FS_HOSTFS=y\nCONFIG_LIBC_FLOATINGPOINT=y\n'
-
- - name: Build wamrc
- working-directory: apps/interpreters/wamr/wamr/wamr-compiler
- run: |
- cmake -Bbuild .
- cmake --build build
-
- - name: Build
- run: |
- cd nuttx
- tools/configure.sh ${{ matrix.nuttx_board_config }}
- make -j$(nproc)
- echo "firmware=$PWD/nuttx" >> $GITHUB_ENV
-
- - name: Test on ARM
- if: endsWith(matrix.nuttx_board_config, 'sabre-6quad/configs/nsh')
- run: |
- curl -L https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz > xpack-qemu-arm.tar.gz
- tar xvf xpack-qemu-arm.tar.gz
- export PATH=$PATH:$PWD/xpack-qemu-arm-7.1.0-1/bin
- cd apps/interpreters/wamr/wamr/tests/wamr-test-suites
- ./test_wamr.sh -s spec ${{ matrix.wamr_test_option }} -m thumbv7_vfp -b -Q -P -F ${{ env.firmware }}
-
- - name: Test on RISCV32
- if: endsWith(matrix.nuttx_board_config, 'rv-virt/configs/nsh')
- run: |
- curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz
- tar xvf xpack-qemu-riscv.tar.gz
- export PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin
- cd apps/interpreters/wamr/wamr/tests/wamr-test-suites
- ./test_wamr.sh -s spec ${{ matrix.wamr_test_option }} -m RISCV32 -b -Q -P -F ${{ env.firmware }}
-
- - name: Test on RISCV64
- if: endsWith(matrix.nuttx_board_config, 'rv-virt/configs/nsh64')
- run: |
- curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz
- tar xvf xpack-qemu-riscv.tar.gz
- export PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin
- cd apps/interpreters/wamr/wamr/tests/wamr-test-suites
- ./test_wamr.sh -s spec ${{ matrix.wamr_test_option }} -m riscv64 -b -Q -P -F ${{ env.firmware }}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt
deleted file mode 100644
index bf0d9d41143..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-requests==2.28.2
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md b/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md
deleted file mode 100644
index 31c705e1fb5..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-# Remote application management
-
-The WAMR application manager supports [remote application management](../core/app-mgr) from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes.
-
-The tool [host_tool](../test-tools/host-tool) communicates to the WAMR app manager for installing/uninstalling the WASM applications on companion chip from the host system. And the [IoT App Store Demo](../test-tools/IoT-APP-Store-Demo/) shows the conception of remotely managing the device applications from the cloud.
-
-
-
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake
deleted file mode 100644
index 8014f237216..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-set (IWASM_AOT_DIR ${CMAKE_CURRENT_LIST_DIR})
-
-add_definitions (-DWASM_ENABLE_AOT=1)
-
-include_directories (${IWASM_AOT_DIR})
-
-file (GLOB c_source_all ${IWASM_AOT_DIR}/*.c)
-
-if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c)
-elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c)
-elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_aarch64.c)
-elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arm.c)
-elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_thumb.c)
-elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_mips.c)
-elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_xtensa.c)
-elseif (WAMR_BUILD_TARGET MATCHES "RISCV*")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_riscv.c)
-elseif (WAMR_BUILD_TARGET STREQUAL "ARC")
- set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arc.c)
-else ()
- message (FATAL_ERROR "Build target isn't set")
-endif ()
-
-if (WAMR_BUILD_DEBUG_AOT EQUAL 1)
- add_definitions(-DWASM_ENABLE_DEBUG_AOT=1)
- file(GLOB debug_source ${IWASM_AOT_DIR}/debug/*.c)
-endif()
-
-set (IWASM_AOT_SOURCE ${c_source_all} ${arch_source} ${debug_source})
-
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h
deleted file mode 100644
index 1324742fe34..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#ifndef _WASM_MEMORY_H
-#define _WASM_MEMORY_H
-
-#include "bh_common.h"
-#include "../include/wasm_export.h"
-#include "../interpreter/wasm_runtime.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool
-wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
- const MemAllocOption *alloc_option);
-
-void
-wasm_runtime_memory_destroy();
-
-unsigned
-wasm_runtime_memory_pool_size();
-
-#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
- || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
- || WASM_ENABLE_BULK_MEMORY != 0
-uint32
-wasm_get_num_bytes_per_page(WASMMemoryInstance *memory, void *node);
-
-uint32
-wasm_get_linear_memory_size(WASMMemoryInstance *memory, void *node);
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* end of _WASM_MEMORY_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h
deleted file mode 100644
index 6c1c49210f2..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#ifndef _WASM_SHARED_MEMORY_H
-#define _WASM_SHARED_MEMORY_H
-
-#include "bh_common.h"
-#if WASM_ENABLE_INTERP != 0
-#include "wasm_runtime.h"
-#endif
-#if WASM_ENABLE_AOT != 0
-#include "aot_runtime.h"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct WASMSharedMemNode {
- bh_list_link l;
- /* Lock */
- korp_mutex lock;
- /* The module reference */
- WASMModuleCommon *module;
- /* The memory information */
- WASMMemoryInstanceCommon *memory_inst;
- /* Lock used for atomic operations */
- korp_mutex shared_mem_lock;
-
- /* reference count */
- uint32 ref_count;
-} WASMSharedMemNode;
-
-bool
-wasm_shared_memory_init();
-
-void
-wasm_shared_memory_destroy();
-
-WASMSharedMemNode *
-wasm_module_get_shared_memory(WASMModuleCommon *module);
-
-int32
-shared_memory_inc_reference(WASMModuleCommon *module);
-
-int32
-shared_memory_dec_reference(WASMModuleCommon *module);
-
-WASMMemoryInstanceCommon *
-shared_memory_get_memory_inst(WASMSharedMemNode *node);
-
-WASMSharedMemNode *
-shared_memory_set_memory_inst(WASMModuleCommon *module,
- WASMMemoryInstanceCommon *memory);
-
-uint32
-wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
- uint64 expect, int64 timeout, bool wait64);
-
-uint32
-wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
- uint32 count);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* end of _WASM_SHARED_MEMORY_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c
deleted file mode 100644
index 57a3e8f678c..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) 2021 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#include "jit_utils.h"
-
-JitBitmap *
-jit_bitmap_new(uintptr_t begin_index, unsigned bitnum)
-{
- JitBitmap *bitmap;
-
- if ((bitmap = jit_calloc(offsetof(JitBitmap, map) + (bitnum + 7) / 8))) {
- bitmap->begin_index = begin_index;
- bitmap->end_index = begin_index + bitnum;
- }
-
- return bitmap;
-}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c
deleted file mode 100644
index 49231de8999..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-#include
-#include
-#include
-#ifdef __wasi__
-#include
-#include
-#include
-#endif
-#include
-#include
-#define SERVER_MSG "Message from server."
-#define PORT 8989
-pthread_mutex_t mut;
-pthread_cond_t cond;
-int server_init_complete = 0;
-char buffer[sizeof(SERVER_MSG) + 1];
-
-struct socket_info {
- union {
- struct sockaddr_in addr_ipv4;
- struct sockaddr_in6 addr_ipv6;
- } addr;
- int sock;
-};
-
-struct thread_args {
- int family;
- int protocol;
-};
-
-struct socket_info
-init_socket_addr(int family, int protocol)
-{
- int sock = socket(family, protocol, 0);
- assert(sock != -1);
-
- struct socket_info info;
- if (family == AF_INET) {
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(PORT);
- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- info.addr.addr_ipv4 = addr;
- }
- else if (family == AF_INET6) {
- struct sockaddr_in6 addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin6_family = AF_INET6;
- addr.sin6_port = htons(PORT);
- addr.sin6_addr = in6addr_loopback;
- info.addr.addr_ipv6 = addr;
- }
- info.sock = sock;
- return info;
-}
-
-void
-assert_thread_args(struct thread_args *args)
-{
- assert(args->family == AF_INET || args->family == AF_INET6);
- assert(args->protocol == SOCK_STREAM || args->protocol == SOCK_DGRAM);
-}
-
-void *
-server(void *arg)
-{
- server_init_complete = 0;
- struct thread_args *args = (struct thread_args *)arg;
- assert_thread_args(args);
-
- struct socket_info init_server_sock =
- init_socket_addr(args->family, args->protocol);
-
- int server_sock = init_server_sock.sock;
- socklen_t addr_size;
- struct sockaddr_storage client_addr;
- strcpy(buffer, SERVER_MSG);
-
- struct sockaddr *server_addr = (struct sockaddr *)&init_server_sock.addr;
- int ret = bind(server_sock, server_addr,
- args->family == AF_INET ? sizeof(struct sockaddr_in)
- : sizeof(struct sockaddr_in6));
- assert(ret == 0);
-
- (args->protocol == SOCK_STREAM) && listen(server_sock, 1);
- pthread_mutex_lock(&mut);
- server_init_complete = 1;
- pthread_mutex_unlock(&mut);
- pthread_cond_signal(&cond);
-
- addr_size = sizeof(client_addr);
- if (args->protocol == SOCK_STREAM) {
- int client_sock =
- accept(server_sock, (struct sockaddr *)&client_addr, &addr_size);
- assert(client_sock >= 0);
- sendto(client_sock, buffer, strlen(buffer), 0,
- (struct sockaddr *)&client_addr, addr_size);
-
- assert(close(client_sock) == 0);
- }
- else {
- recvfrom(server_sock, buffer, sizeof(buffer), 0,
- (struct sockaddr *)&client_addr, &addr_size);
- sendto(server_sock, buffer, strlen(buffer), 0,
- (struct sockaddr *)&client_addr, addr_size);
-
- assert(close(server_sock) == 0);
- }
-
- return NULL;
-}
-
-void *
-client(void *arg)
-{
- struct thread_args *args = (struct thread_args *)arg;
- assert_thread_args(args);
-
- pthread_mutex_lock(&mut);
-
- while (server_init_complete == 0) {
- pthread_cond_wait(&cond, &mut);
- }
-
- struct socket_info init_client_sock =
- init_socket_addr(args->family, args->protocol);
- int sock = init_client_sock.sock;
- pthread_mutex_unlock(&mut);
-
- if (args->family == AF_INET) {
- struct sockaddr_in addr = init_client_sock.addr.addr_ipv4;
- if (args->protocol == SOCK_STREAM) {
- assert(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != -1);
- }
- else {
- assert(sendto(sock, buffer, strlen(buffer), 0,
- (struct sockaddr *)&addr, sizeof(addr))
- != -1);
- }
- }
- else {
- struct sockaddr_in6 addr = init_client_sock.addr.addr_ipv6;
- if (args->protocol == SOCK_STREAM) {
- assert(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != -1);
- }
- else {
- assert(sendto(sock, buffer, strlen(buffer), 0,
- (struct sockaddr *)&addr, sizeof(addr))
- != -1);
- }
- }
-
- recv(sock, buffer, sizeof(buffer), 0);
- assert(strcmp(buffer, SERVER_MSG) == 0);
- assert(close(sock) == 0);
- return NULL;
-}
-
-void
-test_protocol(int family, int protocol)
-{
- pthread_t server_thread, client_thread;
- assert(pthread_cond_init(&cond, NULL) == 0);
- assert(pthread_mutex_init(&mut, NULL) == 0);
-
- struct thread_args args = { family, protocol };
- assert(pthread_create(&server_thread, NULL, server, (void *)&args) == 0);
- assert(pthread_create(&client_thread, NULL, client, (void *)&args) == 0);
- assert(pthread_join(server_thread, NULL) == 0);
- assert(pthread_join(client_thread, NULL) == 0);
-
- assert(pthread_mutex_destroy(&mut) == 0);
- assert(pthread_cond_destroy(&cond) == 0);
-}
-
-int
-main(int argc, char **argv)
-{
- /* test tcp with ipv4 and ipv6 */
- test_protocol(AF_INET, SOCK_STREAM);
- test_protocol(AF_INET6, SOCK_STREAM);
-
- /* test udp with ipv4 and ipv6 */
- test_protocol(AF_INET, SOCK_DGRAM);
- test_protocol(AF_INET6, SOCK_DGRAM);
-
- return 0;
-}
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh
deleted file mode 100755
index 32586c20c88..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-
-set -eo pipefail
-CC=${CC:=/opt/wasi-sdk/bin/clang}
-WAMR_DIR=../../../../..
-
-for test_c in *.c; do
- test_wasm="$(basename $test_c .c).wasm"
-
- if [ $test_wasm = "linear_memory_size_update.wasm" ]; then
- thread_start_file=""
- else
- thread_start_file=$WAMR_DIR/samples/wasi-threads/wasm-apps/wasi_thread_start.S
- fi
-
- echo "Compiling $test_c to $test_wasm"
- $CC \
- -target wasm32-wasi-threads \
- -pthread -ftls-model=local-exec \
- -z stack-size=32768 \
- -Wl,--export=__heap_base \
- -Wl,--export=__data_end \
- -Wl,--shared-memory,--max-memory=1966080 \
- -Wl,--export=wasi_thread_start \
- -Wl,--export=malloc \
- -Wl,--export=free \
- -I $WAMR_DIR/samples/wasi-threads/wasm-apps \
- $thread_start_file \
- $test_c -o $test_wasm
-done
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json
deleted file mode 100644
index 9dc1e30d2b1..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "exit_code": 1
-}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
deleted file mode 100644
index e0c8afa21f3..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-set (LIBC_WASI_DIR ${CMAKE_CURRENT_LIST_DIR})
-
-set (LIBUV_VERSION v1.44.2)
-
-add_definitions (-DWASM_ENABLE_LIBC_WASI=1 -DWASM_ENABLE_UVWASI=1)
-
-include(FetchContent)
-
-## libuv
-FetchContent_Declare(
- libuv
- GIT_REPOSITORY https://github.com/libuv/libuv.git
- GIT_TAG ${LIBUV_VERSION}
-)
-FetchContent_GetProperties(libuv)
-if (NOT libuv_POPULATED)
- message("-- Fetching libuv ..")
- FetchContent_Populate(libuv)
- include_directories("${libuv_SOURCE_DIR}/include")
- add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
- set (UV_A_LIBS uv_a)
- set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1)
-endif()
-
-## uvwasi
-FetchContent_Declare(
- uvwasi
- GIT_REPOSITORY https://github.com/nodejs/uvwasi.git
- GIT_TAG main
-)
-FetchContent_GetProperties(uvwasi)
-if (NOT uvwasi_POPULATED)
- message("-- Fetching uvwasi ..")
- FetchContent_Populate(uvwasi)
- include_directories("${uvwasi_SOURCE_DIR}/include")
- add_subdirectory(${uvwasi_SOURCE_DIR} ${uvwasi_BINARY_DIR} EXCLUDE_FROM_ALL)
-endif()
-
-file (GLOB_RECURSE source_all ${LIBC_WASI_DIR}/*.c ${uvwasi_SOURCE_DIR}/src/*.c)
-
-set (LIBC_WASI_SOURCE ${source_all})
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h
deleted file mode 100644
index feadf2f9586..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h
+++ /dev/null
@@ -1,1508 +0,0 @@
-/*
- * Part of the Wasmtime Project, under the Apache License v2.0 with
- * LLVM Exceptions. See
- * https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE
- * for license information.
- *
- * This file declares an interface similar to WASI, but augmented to expose
- * some implementation details such as the curfds arguments that we pass
- * around to avoid storing them in TLS.
- */
-
-/**
- * The defitions of type, macro and structure in this file should be
- * consistent with those in wasi-libc:
- * https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h
- */
-
-#ifndef WASMTIME_SSP_H
-#define WASMTIME_SSP_H
-
-#include
-#include
-#include
-
-/* clang-format off */
-
-#ifdef __cplusplus
-#ifndef _Static_assert
-#define _Static_assert static_assert
-#endif /* _Static_assert */
-
-#ifndef _Alignof
-#define _Alignof alignof
-#endif /* _Alignof */
-
-#ifndef _Noreturn
-#define _Noreturn [[ noreturn ]]
-#endif /* _Noreturn */
-extern "C" {
-#endif
-
-_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
-_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
-_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
-_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
-_Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
-_Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
-#if 0
-_Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
-_Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
-#endif
-
-typedef uint32_t __wasi_size_t;
-_Static_assert(_Alignof(__wasi_size_t) == 4, "non-wasi data layout");
-
-typedef uint8_t __wasi_advice_t;
-#define __WASI_ADVICE_NORMAL (0)
-#define __WASI_ADVICE_SEQUENTIAL (1)
-#define __WASI_ADVICE_RANDOM (2)
-#define __WASI_ADVICE_WILLNEED (3)
-#define __WASI_ADVICE_DONTNEED (4)
-#define __WASI_ADVICE_NOREUSE (5)
-
-typedef uint32_t __wasi_clockid_t;
-#define __WASI_CLOCK_REALTIME (0)
-#define __WASI_CLOCK_MONOTONIC (1)
-#define __WASI_CLOCK_PROCESS_CPUTIME_ID (2)
-#define __WASI_CLOCK_THREAD_CPUTIME_ID (3)
-
-typedef uint64_t __wasi_device_t;
-
-typedef uint64_t __wasi_dircookie_t;
-#define __WASI_DIRCOOKIE_START (0)
-
-typedef uint32_t __wasi_dirnamlen_t;
-
-typedef uint16_t __wasi_errno_t;
-#define __WASI_ESUCCESS (0)
-#define __WASI_E2BIG (1)
-#define __WASI_EACCES (2)
-#define __WASI_EADDRINUSE (3)
-#define __WASI_EADDRNOTAVAIL (4)
-#define __WASI_EAFNOSUPPORT (5)
-#define __WASI_EAGAIN (6)
-#define __WASI_EALREADY (7)
-#define __WASI_EBADF (8)
-#define __WASI_EBADMSG (9)
-#define __WASI_EBUSY (10)
-#define __WASI_ECANCELED (11)
-#define __WASI_ECHILD (12)
-#define __WASI_ECONNABORTED (13)
-#define __WASI_ECONNREFUSED (14)
-#define __WASI_ECONNRESET (15)
-#define __WASI_EDEADLK (16)
-#define __WASI_EDESTADDRREQ (17)
-#define __WASI_EDOM (18)
-#define __WASI_EDQUOT (19)
-#define __WASI_EEXIST (20)
-#define __WASI_EFAULT (21)
-#define __WASI_EFBIG (22)
-#define __WASI_EHOSTUNREACH (23)
-#define __WASI_EIDRM (24)
-#define __WASI_EILSEQ (25)
-#define __WASI_EINPROGRESS (26)
-#define __WASI_EINTR (27)
-#define __WASI_EINVAL (28)
-#define __WASI_EIO (29)
-#define __WASI_EISCONN (30)
-#define __WASI_EISDIR (31)
-#define __WASI_ELOOP (32)
-#define __WASI_EMFILE (33)
-#define __WASI_EMLINK (34)
-#define __WASI_EMSGSIZE (35)
-#define __WASI_EMULTIHOP (36)
-#define __WASI_ENAMETOOLONG (37)
-#define __WASI_ENETDOWN (38)
-#define __WASI_ENETRESET (39)
-#define __WASI_ENETUNREACH (40)
-#define __WASI_ENFILE (41)
-#define __WASI_ENOBUFS (42)
-#define __WASI_ENODEV (43)
-#define __WASI_ENOENT (44)
-#define __WASI_ENOEXEC (45)
-#define __WASI_ENOLCK (46)
-#define __WASI_ENOLINK (47)
-#define __WASI_ENOMEM (48)
-#define __WASI_ENOMSG (49)
-#define __WASI_ENOPROTOOPT (50)
-#define __WASI_ENOSPC (51)
-#define __WASI_ENOSYS (52)
-#define __WASI_ENOTCONN (53)
-#define __WASI_ENOTDIR (54)
-#define __WASI_ENOTEMPTY (55)
-#define __WASI_ENOTRECOVERABLE (56)
-#define __WASI_ENOTSOCK (57)
-#define __WASI_ENOTSUP (58)
-#define __WASI_ENOTTY (59)
-#define __WASI_ENXIO (60)
-#define __WASI_EOVERFLOW (61)
-#define __WASI_EOWNERDEAD (62)
-#define __WASI_EPERM (63)
-#define __WASI_EPIPE (64)
-#define __WASI_EPROTO (65)
-#define __WASI_EPROTONOSUPPORT (66)
-#define __WASI_EPROTOTYPE (67)
-#define __WASI_ERANGE (68)
-#define __WASI_EROFS (69)
-#define __WASI_ESPIPE (70)
-#define __WASI_ESRCH (71)
-#define __WASI_ESTALE (72)
-#define __WASI_ETIMEDOUT (73)
-#define __WASI_ETXTBSY (74)
-#define __WASI_EXDEV (75)
-#define __WASI_ENOTCAPABLE (76)
-
-typedef uint16_t __wasi_eventrwflags_t;
-#define __WASI_EVENT_FD_READWRITE_HANGUP (0x0001)
-
-typedef uint8_t __wasi_eventtype_t;
-#define __WASI_EVENTTYPE_CLOCK (0)
-#define __WASI_EVENTTYPE_FD_READ (1)
-#define __WASI_EVENTTYPE_FD_WRITE (2)
-
-typedef uint32_t __wasi_exitcode_t;
-
-typedef uint32_t __wasi_fd_t;
-
-typedef uint16_t __wasi_fdflags_t;
-#define __WASI_FDFLAG_APPEND (0x0001)
-#define __WASI_FDFLAG_DSYNC (0x0002)
-#define __WASI_FDFLAG_NONBLOCK (0x0004)
-#define __WASI_FDFLAG_RSYNC (0x0008)
-#define __WASI_FDFLAG_SYNC (0x0010)
-
-typedef int64_t __wasi_filedelta_t;
-
-typedef uint64_t __wasi_filesize_t;
-
-typedef uint8_t __wasi_filetype_t;
-#define __WASI_FILETYPE_UNKNOWN (0)
-#define __WASI_FILETYPE_BLOCK_DEVICE (1)
-#define __WASI_FILETYPE_CHARACTER_DEVICE (2)
-#define __WASI_FILETYPE_DIRECTORY (3)
-#define __WASI_FILETYPE_REGULAR_FILE (4)
-#define __WASI_FILETYPE_SOCKET_DGRAM (5)
-#define __WASI_FILETYPE_SOCKET_STREAM (6)
-#define __WASI_FILETYPE_SYMBOLIC_LINK (7)
-
-typedef uint16_t __wasi_fstflags_t;
-#define __WASI_FILESTAT_SET_ATIM (0x0001)
-#define __WASI_FILESTAT_SET_ATIM_NOW (0x0002)
-#define __WASI_FILESTAT_SET_MTIM (0x0004)
-#define __WASI_FILESTAT_SET_MTIM_NOW (0x0008)
-
-typedef uint64_t __wasi_inode_t;
-
-typedef uint64_t __wasi_linkcount_t __attribute__((aligned(8)));
-
-typedef uint32_t __wasi_lookupflags_t;
-#define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001)
-
-typedef uint16_t __wasi_oflags_t;
-#define __WASI_O_CREAT (0x0001)
-#define __WASI_O_DIRECTORY (0x0002)
-#define __WASI_O_EXCL (0x0004)
-#define __WASI_O_TRUNC (0x0008)
-
-typedef uint16_t __wasi_riflags_t;
-#define __WASI_SOCK_RECV_PEEK (0x0001)
-#define __WASI_SOCK_RECV_WAITALL (0x0002)
-
-typedef uint64_t __wasi_rights_t;
-
-/**
- * Observe that WASI defines rights in the plural form
- * TODO: refactor to use RIGHTS instead of RIGHT
- */
-#define __WASI_RIGHT_FD_DATASYNC ((__wasi_rights_t)(UINT64_C(1) << 0))
-#define __WASI_RIGHT_FD_READ ((__wasi_rights_t)(UINT64_C(1) << 1))
-#define __WASI_RIGHT_FD_SEEK ((__wasi_rights_t)(UINT64_C(1) << 2))
-#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(UINT64_C(1) << 3))
-#define __WASI_RIGHT_FD_SYNC ((__wasi_rights_t)(UINT64_C(1) << 4))
-#define __WASI_RIGHT_FD_TELL ((__wasi_rights_t)(UINT64_C(1) << 5))
-#define __WASI_RIGHT_FD_WRITE ((__wasi_rights_t)(UINT64_C(1) << 6))
-#define __WASI_RIGHT_FD_ADVISE ((__wasi_rights_t)(UINT64_C(1) << 7))
-#define __WASI_RIGHT_FD_ALLOCATE ((__wasi_rights_t)(UINT64_C(1) << 8))
-#define __WASI_RIGHT_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 9))
-#define __WASI_RIGHT_PATH_CREATE_FILE ((__wasi_rights_t)(UINT64_C(1) << 10))
-#define __WASI_RIGHT_PATH_LINK_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 11))
-#define __WASI_RIGHT_PATH_LINK_TARGET ((__wasi_rights_t)(UINT64_C(1) << 12))
-#define __WASI_RIGHT_PATH_OPEN ((__wasi_rights_t)(UINT64_C(1) << 13))
-#define __WASI_RIGHT_FD_READDIR ((__wasi_rights_t)(UINT64_C(1) << 14))
-#define __WASI_RIGHT_PATH_READLINK ((__wasi_rights_t)(UINT64_C(1) << 15))
-#define __WASI_RIGHT_PATH_RENAME_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 16))
-#define __WASI_RIGHT_PATH_RENAME_TARGET ((__wasi_rights_t)(UINT64_C(1) << 17))
-#define __WASI_RIGHT_PATH_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 18))
-#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 19))
-#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 20))
-#define __WASI_RIGHT_FD_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 21))
-#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 22))
-#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 23))
-#define __WASI_RIGHT_PATH_SYMLINK ((__wasi_rights_t)(UINT64_C(1) << 24))
-#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 25))
-#define __WASI_RIGHT_PATH_UNLINK_FILE ((__wasi_rights_t)(UINT64_C(1) << 26))
-#define __WASI_RIGHT_POLL_FD_READWRITE ((__wasi_rights_t)(UINT64_C(1) << 27))
-#define __WASI_RIGHT_SOCK_CONNECT ((__wasi_rights_t)(UINT64_C(1) << 28))
-#define __WASI_RIGHT_SOCK_LISTEN ((__wasi_rights_t)(UINT64_C(1) << 29))
-#define __WASI_RIGHT_SOCK_BIND ((__wasi_rights_t)(UINT64_C(1) << 30))
-#define __WASI_RIGHT_SOCK_ACCEPT ((__wasi_rights_t)(UINT64_C(1) << 31))
-#define __WASI_RIGHT_SOCK_RECV ((__wasi_rights_t)(UINT64_C(1) << 32))
-#define __WASI_RIGHT_SOCK_SEND ((__wasi_rights_t)(UINT64_C(1) << 33))
-#define __WASI_RIGHT_SOCK_ADDR_LOCAL ((__wasi_rights_t)(UINT64_C(1) << 34))
-#define __WASI_RIGHT_SOCK_ADDR_REMOTE ((__wasi_rights_t)(UINT64_C(1) << 35))
-#define __WASI_RIGHT_SOCK_RECV_FROM ((__wasi_rights_t)(UINT64_C(1) << 36))
-#define __WASI_RIGHT_SOCK_SEND_TO ((__wasi_rights_t)(UINT64_C(1) << 37))
-
-typedef uint16_t __wasi_roflags_t;
-#define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001)
-
-typedef uint8_t __wasi_sdflags_t;
-#define __WASI_SHUT_RD (0x01)
-#define __WASI_SHUT_WR (0x02)
-
-typedef uint16_t __wasi_siflags_t;
-
-typedef uint8_t __wasi_signal_t;
-// 0 is reserved; POSIX has special semantics for kill(pid, 0).
-#define __WASI_SIGHUP (1)
-#define __WASI_SIGINT (2)
-#define __WASI_SIGQUIT (3)
-#define __WASI_SIGILL (4)
-#define __WASI_SIGTRAP (5)
-#define __WASI_SIGABRT (6)
-#define __WASI_SIGBUS (7)
-#define __WASI_SIGFPE (8)
-#define __WASI_SIGKILL (9)
-#define __WASI_SIGUSR1 (10)
-#define __WASI_SIGSEGV (11)
-#define __WASI_SIGUSR2 (12)
-#define __WASI_SIGPIPE (13)
-#define __WASI_SIGALRM (14)
-#define __WASI_SIGTERM (15)
-#define __WASI_SIGCHLD (16)
-#define __WASI_SIGCONT (17)
-#define __WASI_SIGSTOP (18)
-#define __WASI_SIGTSTP (19)
-#define __WASI_SIGTTIN (20)
-#define __WASI_SIGTTOU (21)
-#define __WASI_SIGURG (22)
-#define __WASI_SIGXCPU (23)
-#define __WASI_SIGXFSZ (24)
-#define __WASI_SIGVTALRM (25)
-#define __WASI_SIGPROF (26)
-#define __WASI_SIGWINCH (27)
-#define __WASI_SIGPOLL (28)
-#define __WASI_SIGPWR (29)
-#define __WASI_SIGSYS (30)
-
-typedef uint16_t __wasi_subclockflags_t;
-#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001)
-
-typedef uint64_t __wasi_timestamp_t;
-
-typedef uint64_t __wasi_userdata_t;
-
-typedef uint8_t __wasi_whence_t;
-#define __WASI_WHENCE_SET (0)
-#define __WASI_WHENCE_CUR (1)
-#define __WASI_WHENCE_END (2)
-
-typedef uint8_t __wasi_preopentype_t;
-#define __WASI_PREOPENTYPE_DIR (0)
-
-struct fd_table;
-struct fd_prestats;
-struct argv_environ_values;
-struct addr_pool;
-
-typedef struct __wasi_dirent_t {
- __wasi_dircookie_t d_next;
- __wasi_inode_t d_ino;
- __wasi_dirnamlen_t d_namlen;
- __wasi_filetype_t d_type;
-} __wasi_dirent_t __attribute__((aligned(8)));
-_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout");
-_Static_assert(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_event_t {
- __wasi_userdata_t userdata;
- __wasi_errno_t error;
- __wasi_eventtype_t type;
- uint8_t __paddings[5];
- union __wasi_event_u {
- struct __wasi_event_u_fd_readwrite_t {
- __wasi_filesize_t nbytes;
- __wasi_eventrwflags_t flags;
- uint8_t __paddings[6];
- } fd_readwrite;
- } u;
-} __wasi_event_t __attribute__((aligned(8)));
-_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout");
-_Static_assert(sizeof(__wasi_event_t) == 32, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_event_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_prestat_t {
- __wasi_preopentype_t pr_type;
- union __wasi_prestat_u {
- struct __wasi_prestat_u_dir_t {
- size_t pr_name_len;
- } dir;
- } u;
-} __wasi_prestat_t;
-_Static_assert(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- sizeof(__wasi_prestat_t) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- sizeof(__wasi_prestat_t) == 16, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- _Alignof(__wasi_prestat_t) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- _Alignof(__wasi_prestat_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_fdstat_t {
- __wasi_filetype_t fs_filetype;
- __wasi_fdflags_t fs_flags;
- uint8_t __paddings[4];
- __wasi_rights_t fs_rights_base;
- __wasi_rights_t fs_rights_inheriting;
-} __wasi_fdstat_t __attribute__((aligned(8)));
-_Static_assert(
- offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16,
- "non-wasi data layout");
-_Static_assert(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_filestat_t {
- __wasi_device_t st_dev;
- __wasi_inode_t st_ino;
- __wasi_filetype_t st_filetype;
- __wasi_linkcount_t st_nlink;
- __wasi_filesize_t st_size;
- __wasi_timestamp_t st_atim;
- __wasi_timestamp_t st_mtim;
- __wasi_timestamp_t st_ctim;
-} __wasi_filestat_t __attribute__((aligned(8)));
-_Static_assert(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_filestat_t, st_nlink) == 24, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_filestat_t, st_size) == 32, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_filestat_t, st_atim) == 40, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_filestat_t, st_mtim) == 48, "non-wasi data layout");
-_Static_assert(
- offsetof(__wasi_filestat_t, st_ctim) == 56, "non-wasi data layout");
-_Static_assert(sizeof(__wasi_filestat_t) == 64, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_ciovec_t {
- const void *buf;
- size_t buf_len;
-} __wasi_ciovec_t;
-_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- _Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- _Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_iovec_t {
- void *buf;
- size_t buf_len;
-} __wasi_iovec_t;
-_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- sizeof(__wasi_iovec_t) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- sizeof(__wasi_iovec_t) == 16, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
- _Alignof(__wasi_iovec_t) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
- _Alignof(__wasi_iovec_t) == 8, "non-wasi data layout");
-
-/**
- * The contents of a `subscription` when type is `eventtype::clock`.
- */
-typedef struct __wasi_subscription_clock_t {
- /**
- * The clock against which to compare the timestamp.
- */
- __wasi_clockid_t clock_id;
-
- uint8_t __paddings1[4];
-
- /**
- * The absolute or relative timestamp.
- */
- __wasi_timestamp_t timeout;
-
- /**
- * The amount of time that the implementation may wait additionally
- * to coalesce with other events.
- */
- __wasi_timestamp_t precision;
-
- /**
- * Flags specifying whether the timeout is absolute or relative
- */
- __wasi_subclockflags_t flags;
-
- uint8_t __paddings2[4];
-
-} __wasi_subscription_clock_t __attribute__((aligned(8)));
-
-_Static_assert(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size");
-_Static_assert(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align");
-_Static_assert(offsetof(__wasi_subscription_clock_t, clock_id) == 0, "witx calculated offset");
-_Static_assert(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset");
-_Static_assert(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset");
-_Static_assert(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset");
-
-/**
- * The contents of a `subscription` when type is type is
- * `eventtype::fd_read` or `eventtype::fd_write`.
- */
-typedef struct __wasi_subscription_fd_readwrite_t {
- /**
- * The file descriptor on which to wait for it to become ready for reading or writing.
- */
- __wasi_fd_t fd;
-
-} __wasi_subscription_fd_readwrite_t;
-
-_Static_assert(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size");
-_Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align");
-_Static_assert(offsetof(__wasi_subscription_fd_readwrite_t, fd) == 0, "witx calculated offset");
-
-/**
- * The contents of a `subscription`.
- */
-typedef union __wasi_subscription_u_u_t {
- __wasi_subscription_clock_t clock;
- __wasi_subscription_fd_readwrite_t fd_readwrite;
-} __wasi_subscription_u_u_t ;
-
-typedef struct __wasi_subscription_u_t {
- __wasi_eventtype_t type;
- __wasi_subscription_u_u_t u;
-} __wasi_subscription_u_t __attribute__((aligned(8)));
-
-_Static_assert(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size");
-_Static_assert(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align");
-_Static_assert(offsetof(__wasi_subscription_u_t, u) == 8, "witx calculated union offset");
-_Static_assert(sizeof(__wasi_subscription_u_u_t) == 32, "witx calculated union size");
-_Static_assert(_Alignof(__wasi_subscription_u_u_t) == 8, "witx calculated union align");
-
-/**
- * Subscription to an event.
- */
-typedef struct __wasi_subscription_t {
- /**
- * User-provided value that is attached to the subscription in the
- * implementation and returned through `event::userdata`.
- */
- __wasi_userdata_t userdata;
-
- /**
- * The type of the event to which to subscribe, and its contents
- */
- __wasi_subscription_u_t u;
-
-} __wasi_subscription_t;
-
-_Static_assert(sizeof(__wasi_subscription_t) == 48, "witx calculated size");
-_Static_assert(_Alignof(__wasi_subscription_t) == 8, "witx calculated align");
-_Static_assert(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset");
-_Static_assert(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset");
-
-/* keep syncing with wasi_socket_ext.h */
-typedef enum {
- SOCKET_DGRAM = 0,
- SOCKET_STREAM,
-} __wasi_sock_type_t;
-
-typedef uint16_t __wasi_ip_port_t;
-
-typedef enum { IPv4 = 0, IPv6 } __wasi_addr_type_t;
-
-/* n0.n1.n2.n3 */
-typedef struct __wasi_addr_ip4_t {
- uint8_t n0;
- uint8_t n1;
- uint8_t n2;
- uint8_t n3;
-} __wasi_addr_ip4_t;
-
-typedef struct __wasi_addr_ip4_port_t {
- __wasi_addr_ip4_t addr;
- __wasi_ip_port_t port;
-} __wasi_addr_ip4_port_t;
-
-typedef struct __wasi_addr_ip6_t {
- uint16_t n0;
- uint16_t n1;
- uint16_t n2;
- uint16_t n3;
- uint16_t h0;
- uint16_t h1;
- uint16_t h2;
- uint16_t h3;
-} __wasi_addr_ip6_t;
-
-typedef struct __wasi_addr_ip6_port_t {
- __wasi_addr_ip6_t addr;
- __wasi_ip_port_t port;
-} __wasi_addr_ip6_port_t;
-
-typedef struct __wasi_addr_ip_t {
- __wasi_addr_type_t kind;
- union {
- __wasi_addr_ip4_t ip4;
- __wasi_addr_ip6_t ip6;
- } addr;
-} __wasi_addr_ip_t;
-
-typedef struct __wasi_addr_t {
- __wasi_addr_type_t kind;
- union {
- __wasi_addr_ip4_port_t ip4;
- __wasi_addr_ip6_port_t ip6;
- } addr;
-} __wasi_addr_t;
-
-typedef enum { INET4 = 0, INET6 } __wasi_address_family_t;
-
-typedef struct __wasi_addr_info_t {
- __wasi_addr_t addr;
- __wasi_sock_type_t type;
-} __wasi_addr_info_t;
-
-typedef struct __wasi_addr_info_hints_t {
- __wasi_sock_type_t type;
- __wasi_address_family_t family;
- // this is to workaround lack of optional parameters
- uint8_t hints_enabled;
-} __wasi_addr_info_hints_t;
-
-#if defined(WASMTIME_SSP_WASI_API)
-#define WASMTIME_SSP_SYSCALL_NAME(name) \
- asm("__wasi_" #name)
-#else
-#define WASMTIME_SSP_SYSCALL_NAME(name)
-#endif
-
-__wasi_errno_t wasmtime_ssp_args_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *arg_environ,
-#endif
- char **argv,
- char *argv_buf
-) WASMTIME_SSP_SYSCALL_NAME(args_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_args_sizes_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *arg_environ,
-#endif
- size_t *argc,
- size_t *argv_buf_size
-) WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_clock_res_get(
- __wasi_clockid_t clock_id,
- __wasi_timestamp_t *resolution
-) WASMTIME_SSP_SYSCALL_NAME(clock_res_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_clock_time_get(
- __wasi_clockid_t clock_id,
- __wasi_timestamp_t precision,
- __wasi_timestamp_t *time
-) WASMTIME_SSP_SYSCALL_NAME(clock_time_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_environ_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *arg_environ,
-#endif
- char **environ,
- char *environ_buf
-) WASMTIME_SSP_SYSCALL_NAME(environ_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_environ_sizes_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *arg_environ,
-#endif
- size_t *environ_count,
- size_t *environ_buf_size
-) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_prestat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t fd,
- __wasi_prestat_t *buf
-) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_prestat_dir_name(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t fd,
- char *path,
- size_t path_len
-) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_close(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t fd
-) WASMTIME_SSP_SYSCALL_NAME(fd_close) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_datasync(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd
-) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_pread(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const __wasi_iovec_t *iovs,
- size_t iovs_len,
- __wasi_filesize_t offset,
- size_t *nread
-) WASMTIME_SSP_SYSCALL_NAME(fd_pread) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_pwrite(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const __wasi_ciovec_t *iovs,
- size_t iovs_len,
- __wasi_filesize_t offset,
- size_t *nwritten
-) WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_read(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const __wasi_iovec_t *iovs,
- size_t iovs_len,
- size_t *nread
-) WASMTIME_SSP_SYSCALL_NAME(fd_read) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_renumber(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t from,
- __wasi_fd_t to
-) WASMTIME_SSP_SYSCALL_NAME(fd_renumber) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_seek(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_filedelta_t offset,
- __wasi_whence_t whence,
- __wasi_filesize_t *newoffset
-) WASMTIME_SSP_SYSCALL_NAME(fd_seek) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_tell(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_filesize_t *newoffset
-) WASMTIME_SSP_SYSCALL_NAME(fd_tell) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_fdstat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_fdstat_t *buf
-) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_fdstat_set_flags(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_fdflags_t flags
-) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_rights_t fs_rights_base,
- __wasi_rights_t fs_rights_inheriting
-) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_sync(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd
-) WASMTIME_SSP_SYSCALL_NAME(fd_sync) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_write(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const __wasi_ciovec_t *iovs,
- size_t iovs_len,
- size_t *nwritten
-) WASMTIME_SSP_SYSCALL_NAME(fd_write) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_advise(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_filesize_t offset,
- __wasi_filesize_t len,
- __wasi_advice_t advice
-) WASMTIME_SSP_SYSCALL_NAME(fd_advise) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_allocate(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_filesize_t offset,
- __wasi_filesize_t len
-) WASMTIME_SSP_SYSCALL_NAME(fd_allocate) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_create_directory(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const char *path,
- size_t path_len
-) WASMTIME_SSP_SYSCALL_NAME(path_create_directory) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_link(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t old_fd,
- __wasi_lookupflags_t old_flags,
- const char *old_path,
- size_t old_path_len,
- __wasi_fd_t new_fd,
- const char *new_path,
- size_t new_path_len
-) WASMTIME_SSP_SYSCALL_NAME(path_link) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_open(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t dirfd,
- __wasi_lookupflags_t dirflags,
- const char *path,
- size_t path_len,
- __wasi_oflags_t oflags,
- __wasi_rights_t fs_rights_base,
- __wasi_rights_t fs_rights_inheriting,
- __wasi_fdflags_t fs_flags,
- __wasi_fd_t *fd
-) WASMTIME_SSP_SYSCALL_NAME(path_open) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_readdir(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- void *buf,
- size_t buf_len,
- __wasi_dircookie_t cookie,
- size_t *bufused
-) WASMTIME_SSP_SYSCALL_NAME(fd_readdir) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_readlink(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const char *path,
- size_t path_len,
- char *buf,
- size_t buf_len,
- size_t *bufused
-) WASMTIME_SSP_SYSCALL_NAME(path_readlink) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_rename(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t old_fd,
- const char *old_path,
- size_t old_path_len,
- __wasi_fd_t new_fd,
- const char *new_path,
- size_t new_path_len
-) WASMTIME_SSP_SYSCALL_NAME(path_rename) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_filestat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_filestat_t *buf
-) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_filestat_set_times(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_timestamp_t st_atim,
- __wasi_timestamp_t st_mtim,
- __wasi_fstflags_t fstflags
-) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_fd_filestat_set_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_filesize_t st_size
-) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_filestat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_lookupflags_t flags,
- const char *path,
- size_t path_len,
- __wasi_filestat_t *buf
-) WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_filestat_set_times(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- __wasi_lookupflags_t flags,
- const char *path,
- size_t path_len,
- __wasi_timestamp_t st_atim,
- __wasi_timestamp_t st_mtim,
- __wasi_fstflags_t fstflags
-) WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_symlink(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
- struct fd_prestats *prestats,
-#endif
- const char *old_path,
- size_t old_path_len,
- __wasi_fd_t fd,
- const char *new_path,
- size_t new_path_len
-) WASMTIME_SSP_SYSCALL_NAME(path_symlink) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_unlink_file(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const char *path,
- size_t path_len
-) WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_path_remove_directory(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd,
- const char *path,
- size_t path_len
-) WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_poll_oneoff(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- const __wasi_subscription_t *in,
- __wasi_event_t *out,
- size_t nsubscriptions,
- size_t *nevents
-) WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) __attribute__((__warn_unused_result__));
-
-#if 0
-/**
- * We throw exception in libc-wasi wrapper function wasi_proc_exit()
- * but not call this function.
- */
-_Noreturn void wasmtime_ssp_proc_exit(
- __wasi_exitcode_t rval
-) WASMTIME_SSP_SYSCALL_NAME(proc_exit);
-#endif
-
-__wasi_errno_t wasmtime_ssp_proc_raise(
- __wasi_signal_t sig
-) WASMTIME_SSP_SYSCALL_NAME(proc_raise) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_random_get(
- void *buf,
- size_t buf_len
-) WASMTIME_SSP_SYSCALL_NAME(random_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_accept(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_addr_local(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_addr_remote(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_open(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype,
- __wasi_fd_t *sockfd
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_bind(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct addr_pool *addr_pool,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_addr_resolve(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, char **ns_lookup_list,
-#endif
- const char *host, const char* service,
- __wasi_addr_info_hints_t *hints, __wasi_addr_info_t *addr_info,
- __wasi_size_t addr_info_size, __wasi_size_t *max_info_size
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_connect(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct addr_pool *addr_pool,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_get_recv_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t *size
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_get_reuse_addr(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t *reuse
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_get_reuse_port(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t *reuse
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_get_send_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t *size
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_set_recv_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t size
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_set_reuse_addr(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t reuse
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_set_reuse_port(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t reuse
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_set_send_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t size
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t
-wasi_ssp_sock_listen(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t backlog
-) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_recv(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- void *buf,
- size_t buf_len,
- size_t *recv_len
-) WASMTIME_SSP_SYSCALL_NAME(sock_recv) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_recv_from(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- void *buf,
- size_t buf_len,
- __wasi_riflags_t ri_flags,
- __wasi_addr_t *src_addr,
- size_t *recv_len
-) WASMTIME_SSP_SYSCALL_NAME(sock_recv_from) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_send(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- const void *buf,
- size_t buf_len,
- size_t *sent_len
-) WASMTIME_SSP_SYSCALL_NAME(sock_send) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_send_to(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct addr_pool *addr_pool,
-#endif
- __wasi_fd_t sock,
- const void *buf,
- size_t buf_len,
- __wasi_siflags_t si_flags,
- const __wasi_addr_t *dest_addr,
- size_t *sent_len
-) WASMTIME_SSP_SYSCALL_NAME(sock_send_to) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_shutdown(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock
-) WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_recv_timeout(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint64_t timeout_us
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_timeout) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_recv_timeout(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint64_t *timeout_us
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_timeout) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_send_timeout(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint64_t timeout_us
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_timeout) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_send_timeout(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint64_t *timeout_us
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_timeout) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_send_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- size_t bufsiz
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_buf_size) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_send_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- size_t *bufsiz
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_buf_size) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_recv_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- size_t bufsiz
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_buf_size) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_recv_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- size_t *bufsiz
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_buf_size) __attribute__((__warn_unused_result__));
-
-
-__wasi_errno_t wasmtime_ssp_sock_set_keep_alive(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_keep_alive) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_keep_alive(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_keep_alive) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_reuse_addr(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_addr) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_reuse_addr(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_addr) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_reuse_port(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_port) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_reuse_port(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_port) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_linger(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled,
- int linger_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_linger) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_linger(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, bool *is_enabled, int *linger_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_linger) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_broadcast(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_broadcast) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_broadcast(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_broadcast) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_tcp_no_delay(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_no_delay) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_tcp_no_delay(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_no_delay) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_tcp_quick_ack(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_quick_ack) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_tcp_quick_ack(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_quick_ack) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_idle(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint32_t time_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_idle) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_idle(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint32_t *time_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_idle) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_intvl(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint32_t time_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_intvl) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_intvl(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint32_t *time_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_intvl) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_tcp_fastopen_connect(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_fastopen_connect) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_tcp_fastopen_connect(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_fastopen_connect) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_loop(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool ipv6,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_loop) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_loop(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool ipv6,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_loop) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_ip_add_membership(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- __wasi_addr_ip_t *imr_multiaddr,
- uint32_t imr_interface
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_add_membership) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_ip_drop_membership(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- __wasi_addr_ip_t *imr_multiaddr,
- uint32_t imr_interface
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_drop_membership) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_ip_ttl(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint8_t ttl_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_ttl) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_ip_ttl(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint8_t *ttl_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_ttl) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_ttl(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint8_t ttl_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_ttl) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_ttl(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- uint8_t *ttl_s
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_ttl) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_set_ipv6_only(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_set_ipv6_only) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sock_get_ipv6_only(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock,
- bool *is_enabled
-) WASMTIME_SSP_SYSCALL_NAME(sock_get_ipv6_only) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t wasmtime_ssp_sched_yield(void)
- WASMTIME_SSP_SYSCALL_NAME(sched_yield) __attribute__((__warn_unused_result__));
-
-#ifdef __cplusplus
-}
-#endif
-
-#undef WASMTIME_SSP_SYSCALL_NAME
-
-/* clang-format on */
-
-#endif /* end of WASMTIME_SSP_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake
deleted file mode 100644
index bbeac3b148b..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-
-find_library(TENSORFLOW_LITE
- NAMES tensorflow-lite
-)
-
-if(NOT EXISTS ${TENSORFLOW_LITE})
- if (NOT EXISTS "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
- execute_process(COMMAND ${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh
- RESULT_VARIABLE TENSORFLOW_RESULT
- )
- else ()
- message("Tensorflow is already downloaded.")
- endif()
- set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
-
- if (WASI_NN_ENABLE_GPU EQUAL 1)
- # Tensorflow specific:
- # * https://www.tensorflow.org/lite/guide/build_cmake#available_options_to_build_tensorflow_lite
- set (TFLITE_ENABLE_GPU ON)
- endif ()
-
- include_directories (${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include)
- include_directories (${TENSORFLOW_SOURCE_DIR})
- add_subdirectory(
- "${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
- "${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
-
-else()
- find_path(TENSORFLOW_LITE_INCLUDE_DIR
- NAMES tensorflow/lite/interpreter.h
- )
- find_path(FLATBUFFER_INCLUDE_DIR
- NAMES flatbuffers/flatbuffers.h
- )
- include_directories (${TENSORFLOW_LITE_INCLUDE_DIR})
- include_directories (${FLATBUFFER_INCLUDE_DIR})
-endif()
-
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake
deleted file mode 100644
index 019782c2e42..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
-
-# Find tensorflow-lite
-find_package(tensorflow_lite REQUIRED)
-
-set (WASI_NN_DIR ${CMAKE_CURRENT_LIST_DIR})
-
-include_directories (${WASI_NN_DIR})
-include_directories (${WASI_NN_DIR}/src)
-include_directories (${WASI_NN_DIR}/src/utils)
-
-set (
- LIBC_WASI_NN_SOURCE
- ${WASI_NN_DIR}/src/wasi_nn.c
- ${WASI_NN_DIR}/src/wasi_nn_tensorflowlite.cpp
- ${WASI_NN_DIR}/src/utils/wasi_nn_app_native.c
-)
-
-set (TENSORFLOW_LIB tensorflow-lite)
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake
deleted file mode 100644
index 4abefff1ea8..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-set (PLATFORM_COMMON_POSIX_DIR ${CMAKE_CURRENT_LIST_DIR})
-
-file (GLOB_RECURSE source_all ${PLATFORM_COMMON_POSIX_DIR}/*.c)
-
-set (PLATFORM_COMMON_POSIX_SOURCE ${source_all} )
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c b/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c
deleted file mode 100644
index 693094a6344..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#include "platform_api_vmcore.h"
-#include "platform_api_extension.h"
-
-void *
-os_mmap(void *hint, size_t size, int prot, int flags)
-{
- if (prot & MMAP_PROT_EXEC) {
- // Memory allocation with MALLOC_CAP_EXEC will return 4-byte aligned
- // Reserve extra 4 byte to fixup alignment and size for the pointer to
- // the originally allocated address
- void *buf_origin =
- heap_caps_malloc(size + 4 + sizeof(uintptr_t), MALLOC_CAP_EXEC);
- if (!buf_origin) {
- return NULL;
- }
- void *buf_fixed = buf_origin + sizeof(void *);
- if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
- buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7));
- }
-
- uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
- *addr_field = (uintptr_t)buf_origin;
- return buf_fixed;
- }
- else {
- return os_malloc(size);
- }
-}
-
-void
-os_munmap(void *addr, size_t size)
-{
- // We don't need special handling of the executable allocations
- // here, free() of esp-idf handles it properly
- return os_free(addr);
-}
-
-int
-os_mprotect(void *addr, size_t size, int prot)
-{
- return 0;
-}
-
-void
-os_dcache_flush()
-{}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md b/lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md
deleted file mode 100644
index d6c5a370124..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md
+++ /dev/null
@@ -1,14 +0,0 @@
-# WAMR XIP (Execution In Place) feature introduction
-
-Some IoT devices may require to run the AOT file from flash or ROM which is read-only, so as to reduce the memory consumption, or resolve the issue that there is no executable memory available to run AOT code. In such case, the AOT code inside the AOT file shouldn't be duplicated into memory and shouldn't be modified (or patched) by the AOT relocations. To address this, WAMR implements the XIP (Execution In Place) feature, which generates the AOT relocations as few as possible:
-- In the AOT code, an AOT function calls other functions with indirect mode: it doesn't call other functions directly, but looks up their pointers from the function pointer table passed by its first argument exec_env, and then calls the function pointer found. By this way the relocations to other functions are eliminated.
-- Eliminate the calls to the LLVM intrinsic functions, or, replace calling them with calling runtime self implemented functions instead, e.g. the calling to `llvm.experimental.constrained.fadd.f32` is replaced by the calling to `aot_intrinsic_fadd_f32`.
-
-The XIP file is an AOT file without (or with few) relocations to patch the AOT code (or text section). Developer can use the option `--enable-indirect-mode --disable-llvm-intrinsics` for wamrc to generate the AOT file, e.g.:
-```bash
-wamrc --enable-indirect-mode --disable-llvm-intrinsics -o
-```
-
-## Known issues
-
-There may be some relocations to the ".rodata" like sections which require to patch the AOT code. More work will be done to resolve it in the future.
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod b/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod
deleted file mode 100644
index 60afebbff6e..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod
+++ /dev/null
@@ -1,5 +0,0 @@
-module gitlab.alipay-inc.com/TNT_Runtime/ant-runtime/bindings/go
-
-go 1.15
-
-require github.com/stretchr/testify v1.7.0
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh
deleted file mode 100755
index 1b0a80719c1..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-PLATFORM=$(uname -s | tr A-Z a-z)
-CUR_DIR=$PWD
-WAMR_DIR=$PWD/../../..
-WAMR_GO_DIR=$PWD/../wamr
-
-cp -a ${WAMR_DIR}/core/iwasm/include/*.h ${WAMR_GO_DIR}/packaged/include
-
-mkdir -p build && cd build
-cmake ${WAMR_DIR}/product-mini/platforms/${PLATFORM} \
- -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_DUMP_CALL_STACK=1 \
- -DWAMR_BUILD_MEMORY_PROFILING=1
-make -j ${nproc}
-cp -a libvmlib.a ${WAMR_GO_DIR}/packaged/lib/${PLATFORM}-amd64
-
-cd ${CUR_DIR}
-rm -f test
-go build test.go
-./test
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md
deleted file mode 100644
index e02398b0b44..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md
+++ /dev/null
@@ -1,25 +0,0 @@
-# Build with Docker
-
-To have a quicker start, a Docker container of the Zephyr setup can be generated.
-
-## Build Docker container
-
-``` Bash
-docker build --build-arg DOCKER_UID=$(id -u) . -t wamr-zephyr
-```
-
-## Run Docker container to build images
-
-Enter the docker container (maps the toplevel wasm-micro-runtime repo as volume):
-
-``` Bash
-docker run -ti -v $PWD/../../../..:/home/wamr/source --device=/dev/ttyUSB0 wamr-zephyr
-```
-
-Adopt the device or remove if not needed.
-
-And then in the docker container:
-
-``` Bash
-./build_and_run.sh esp32c3
-```
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf
deleted file mode 100644
index 5d6a67f9da2..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-CONFIG_STACK_SENTINEL=y
-CONFIG_PRINTK=y
-CONFIG_LOG=y
-CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
-CONFIG_CUSTOM_LINKER_SCRIPT="esp32_custom_linker.ld"
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf
deleted file mode 100644
index f3705504b5a..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-CONFIG_STACK_SENTINEL=y
-CONFIG_PRINTK=y
-CONFIG_LOG=n
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf
deleted file mode 100644
index f3705504b5a..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-CONFIG_STACK_SENTINEL=y
-CONFIG_PRINTK=y
-CONFIG_LOG=n
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf
deleted file mode 100644
index 7f4a3283220..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-CONFIG_STACK_SENTINEL=y
-CONFIG_PRINTK=y
-CONFIG_LOG=y
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf
deleted file mode 100644
index 7f4a3283220..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-CONFIG_STACK_SENTINEL=y
-CONFIG_PRINTK=y
-CONFIG_LOG=y
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld
deleted file mode 100644
index 35932050fc9..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright (c) 2016 Cadence Design Systems, Inc.
- * Copyright (c) 2017 Intel Corporation
- * SPDX-License-Identifier: Apache-2.0
- */
-
-/**
- * @file
- * @brief Linker command/script file
- *
- * Linker script for the Xtensa platform.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-#define RAMABLE_REGION dram0_0_seg :dram0_0_phdr
-#define RAMABLE_REGION1 dram0_1_seg :dram0_0_phdr
-#define ROMABLE_REGION iram0_0_seg :iram0_0_phdr
-
-PROVIDE ( __stack = 0x3ffe3f20 );
-
-PROVIDE ( esp32_rom_uart_tx_one_char = 0x40009200 );
-PROVIDE ( esp32_rom_uart_rx_one_char = 0x400092d0 );
-PROVIDE ( esp32_rom_uart_attach = 0x40008fd0 );
-PROVIDE ( esp32_rom_intr_matrix_set = 0x4000681c );
-PROVIDE ( esp32_rom_gpio_matrix_in = 0x40009edc );
-PROVIDE ( esp32_rom_gpio_matrix_out = 0x40009f0c );
-PROVIDE ( esp32_rom_Cache_Flush = 0x40009a14 );
-PROVIDE ( esp32_rom_Cache_Read_Enable = 0x40009a84 );
-PROVIDE ( esp32_rom_ets_set_appcpu_boot_addr = 0x4000689c );
-
-MEMORY
-{
- iram0_0_seg(RX): org = 0x40080000, len = 0x20000
- iram0_2_seg(RX): org = 0x400D0018, len = 0x330000
- dram0_0_seg(RW): org = 0x3FFB0000, len = 0x30000
- dram0_1_seg(RWX):org = 0x400A0000, len = 0x20000
- drom0_0_seg(R): org = 0x3F400010, len = 0x800000
- rtc_iram_seg(RWX): org = 0x400C0000, len = 0x2000
- rtc_slow_seg(RW): org = 0x50000000, len = 0x1000
-#ifdef CONFIG_GEN_ISR_TABLES
- IDT_LIST(RW): org = 0x3ebfe010, len = 0x2000
-#endif
-}
-
-PHDRS
-{
- iram0_0_phdr PT_LOAD;
- dram0_0_phdr PT_LOAD;
-}
-
-/* Default entry point: */
-PROVIDE ( _ResetVector = 0x40000400 );
-ENTRY(CONFIG_KERNEL_ENTRY)
-
-_rom_store_table = 0;
-
-PROVIDE(_memmap_vecbase_reset = 0x40000450);
-PROVIDE(_memmap_reset_vector = 0x40000400);
-
-SECTIONS
-{
-
-#include
-
- /* RTC fast memory holds RTC wake stub code,
- including from any source file named rtc_wake_stub*.c
- */
- .rtc.text :
- {
- . = ALIGN(4);
- *(.rtc.literal .rtc.text)
- *rtc_wake_stub*.o(.literal .text .literal.* .text.*)
- } >rtc_iram_seg
-
- /* RTC slow memory holds RTC wake stub
- data/rodata, including from any source file
- named rtc_wake_stub*.c
- */
- .rtc.data :
- {
- _rtc_data_start = ABSOLUTE(.);
- *(.rtc.data)
- *(.rtc.rodata)
- *rtc_wake_stub*.o(.data .rodata .data.* .rodata.* .bss .bss.*)
- _rtc_data_end = ABSOLUTE(.);
- } > rtc_slow_seg
-
- /* RTC bss, from any source file named rtc_wake_stub*.c */
- .rtc.bss (NOLOAD) :
- {
- _rtc_bss_start = ABSOLUTE(.);
- *rtc_wake_stub*.o(.bss .bss.*)
- *rtc_wake_stub*.o(COMMON)
- _rtc_bss_end = ABSOLUTE(.);
- } > rtc_slow_seg
-
- /* Send .iram0 code to iram */
- .iram0.vectors : ALIGN(4)
- {
- /* Vectors go to IRAM */
- _init_start = ABSOLUTE(.);
- /* Vectors according to builds/RF-2015.2-win32/esp108_v1_2_s5_512int_2/config.html */
- . = 0x0;
- KEEP(*(.WindowVectors.text));
- . = 0x180;
- KEEP(*(.Level2InterruptVector.text));
- . = 0x1c0;
- KEEP(*(.Level3InterruptVector.text));
- . = 0x200;
- KEEP(*(.Level4InterruptVector.text));
- . = 0x240;
- KEEP(*(.Level5InterruptVector.text));
- . = 0x280;
- KEEP(*(.DebugExceptionVector.text));
- . = 0x2c0;
- KEEP(*(.NMIExceptionVector.text));
- . = 0x300;
- KEEP(*(.KernelExceptionVector.text));
- . = 0x340;
- KEEP(*(.UserExceptionVector.text));
- . = 0x3C0;
- KEEP(*(.DoubleExceptionVector.text));
- . = 0x400;
- *(.*Vector.literal)
-
- *(.UserEnter.literal);
- *(.UserEnter.text);
- . = ALIGN (16);
- *(.entry.text)
- *(.init.literal)
- *(.init)
- _init_end = ABSOLUTE(.);
-
- /* This goes here, not at top of linker script, so addr2line finds it last,
- and uses it in preference to the first symbol in IRAM */
- _iram_start = ABSOLUTE(0);
- } GROUP_LINK_IN(ROMABLE_REGION)
-
-#include
-#include
-
- SECTION_PROLOGUE(_TEXT_SECTION_NAME, , ALIGN(4))
- {
- /* Code marked as running out of IRAM */
- _iram_text_start = ABSOLUTE(.);
- *(.iram1 .iram1.*)
- *(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text)
- *(.literal .text .literal.* .text.*)
- _iram_text_end = ABSOLUTE(.);
- } GROUP_LINK_IN(ROMABLE_REGION)
-
- .dram0.text :
- {
- _data_start = ABSOLUTE(.);
- *(.aot_code_buf)
- _data_end = ABSOLUTE(.);
- . = ALIGN(4);
- } GROUP_LINK_IN(RAMABLE_REGION1)
-
-
- .dram0.data :
- {
- _data_start = ABSOLUTE(.);
- *(.data)
- *(.data.*)
- *(.gnu.linkonce.d.*)
- *(.data1)
- *(.sdata)
- *(.sdata.*)
- *(.gnu.linkonce.s.*)
- *(.sdata2)
- *(.sdata2.*)
- *(.gnu.linkonce.s2.*)
- KEEP(*(.jcr))
- *(.dram1 .dram1.*)
- _data_end = ABSOLUTE(.);
- . = ALIGN(4);
- } GROUP_LINK_IN(RAMABLE_REGION)
-
- SECTION_PROLOGUE(_RODATA_SECTION_NAME,,ALIGN(4))
- {
- _rodata_start = ABSOLUTE(.);
- *(.rodata)
- *(.rodata.*)
- *(.gnu.linkonce.r.*)
- *(.rodata1)
- __XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
- KEEP (*(.xt_except_table))
- KEEP (*(.gcc_except_table .gcc_except_table.*))
- *(.gnu.linkonce.e.*)
- *(.gnu.version_r)
- KEEP (*(.eh_frame))
- /* C++ constructor and destructor tables, properly ordered: */
- KEEP (*crtbegin.o(.ctors))
- KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
- KEEP (*(SORT(.ctors.*)))
- KEEP (*(.ctors))
- KEEP (*crtbegin.o(.dtors))
- KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
- KEEP (*(SORT(.dtors.*)))
- KEEP (*(.dtors))
- /* C++ exception handlers table: */
- __XT_EXCEPTION_DESCS__ = ABSOLUTE(.);
- *(.xt_except_desc)
- *(.gnu.linkonce.h.*)
- __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
- *(.xt_except_desc_end)
- *(.dynamic)
- *(.gnu.version_d)
- . = ALIGN(4); /* this table MUST be 4-byte aligned */
- _rodata_end = ABSOLUTE(.);
- } GROUP_LINK_IN(RAMABLE_REGION)
-
-
- /* Shared RAM */
- SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
- {
- . = ALIGN (8);
- _bss_start = ABSOLUTE(.);
- *(.dynsbss)
- *(.sbss)
- *(.sbss.*)
- *(.gnu.linkonce.sb.*)
- *(.scommon)
- *(.sbss2)
- *(.sbss2.*)
- *(.gnu.linkonce.sb2.*)
- *(.dynbss)
- *(.bss)
- *(.bss.*)
- *(.share.mem)
- *(.gnu.linkonce.b.*)
- *(COMMON)
- . = ALIGN (8);
- _bss_end = ABSOLUTE(.);
- } GROUP_LINK_IN(RAMABLE_REGION)
-
-
- SECTION_DATA_PROLOGUE(_APP_NOINIT_SECTION_NAME, (NOLOAD),)
- {
- . = ALIGN (8);
- *(.app_noinit)
- *("app_noinit.*")
- . = ALIGN (8);
- _app_end = ABSOLUTE(.);
- } GROUP_LINK_IN(RAMABLE_REGION)
-
-
- SECTION_DATA_PROLOGUE(_NOINIT_SECTION_NAME, (NOLOAD),)
- {
- . = ALIGN (8);
- *(.noinit)
- *(".noinit.*")
- . = ALIGN (8);
- _heap_start = ABSOLUTE(.);
- } GROUP_LINK_IN(RAMABLE_REGION)
-
-#ifdef CONFIG_GEN_ISR_TABLES
-#include
-#endif
-
-#include
-
- SECTION_PROLOGUE(.xtensa.info, 0,)
- {
- *(.xtensa.info)
- }
-
-}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt
deleted file mode 100644
index aef138d5e85..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt
+++ /dev/null
@@ -1,147 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-cmake_minimum_required (VERSION 3.0)
-
-project(xnnpack_wasm)
-
-################ EMCC ################
-include(ExternalProject)
-
-ExternalProject_Add(xnnpack
- PREFIX xnnpack
- GIT_REPOSITORY https://github.com/google/XNNPACK.git
- GIT_TAG 4570a7151aa4f3e57eca14a575eeff6bb13e26be
- GIT_PROGRESS ON
- SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
- UPDATE_COMMAND git restore .
- && cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/google3/third_party/XNNPACK/microkernels.bzl
- ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/
- && git apply ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack.patch
- CONFIGURE_COMMAND ""
- # grep xnnpack_benchmark -A 1 BUILD.bazel \
- # | grep "name =" \
- # | awk '{print $3}' \
- # | sed -e 's/\"//g' -e 's/,//g' -e 's/^/\/\/:/g'
- BUILD_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack
- && bazel --output_user_root=build-user-output build -c opt --config=wasm
- //:qs8_dwconv_bench.wasm
- //:qs8_f32_vcvt_bench.wasm
- //:qs8_gemm_bench.wasm
- //:qs8_requantization_bench.wasm
- //:qs8_vadd_bench.wasm
- //:qs8_vaddc_bench.wasm
- //:qs8_vcvt_bench.wasm
- //:qs8_vlrelu_bench.wasm
- //:qs8_vmul_bench.wasm
- //:qs8_vmulc_bench.wasm
- //:qu8_f32_vcvt_bench.wasm
- //:qu8_gemm_bench.wasm
- //:qu8_requantization_bench.wasm
- //:qu8_vadd_bench.wasm
- //:qu8_vaddc_bench.wasm
- //:qu8_vcvt_bench.wasm
- //:qu8_vlrelu_bench.wasm
- //:qu8_vmul_bench.wasm
- //:qu8_vmulc_bench.wasm
- //:bf16_gemm_bench.wasm
- //:f16_igemm_bench.wasm
- //:f16_gemm_bench.wasm
- //:f16_raddstoreexpminusmax_bench.wasm
- //:f16_spmm_bench.wasm
- //:f16_vsigmoid_bench.wasm
- //:f16_f32_vcvt_bench.wasm
- //:f32_igemm_bench.wasm
- //:f32_conv_hwc_bench.wasm
- //:f16_conv_hwc2chw_bench.wasm
- //:f16_gavgpool_cw_bench.wasm
- //:f32_gavgpool_cw_bench.wasm
- //:f32_conv_hwc2chw_bench.wasm
- //:f16_dwconv_bench.wasm
- //:f32_dwconv_bench.wasm
- //:f32_dwconv2d_chw_bench.wasm
- //:f16_dwconv2d_chw_bench.wasm
- //:f32_f16_vcvt_bench.wasm
- //:xx_transpose_bench.wasm
- //:x8_transpose_bench.wasm
- //:x16_transpose_bench.wasm
- //:x24_transpose_bench.wasm
- //:x32_transpose_bench.wasm
- //:x64_transpose_bench.wasm
- //:f32_gemm_bench.wasm
- //:f32_qs8_vcvt_bench.wasm
- //:f32_qu8_vcvt_bench.wasm
- //:f32_raddexpminusmax_bench.wasm
- //:f32_raddextexp_bench.wasm
- //:f32_raddstoreexpminusmax_bench.wasm
- //:f32_rmax_bench.wasm
- //:f32_spmm_bench.wasm
- //:f32_softmax_bench.wasm
- //:f16_velu_bench.wasm
- //:f32_velu_bench.wasm
- //:f32_vhswish_bench.wasm
- //:f32_vlrelu_bench.wasm
- //:f32_vrelu_bench.wasm
- //:f32_vscaleexpminusmax_bench.wasm
- //:f32_vscaleextexp_bench.wasm
- //:f32_vsigmoid_bench.wasm
- //:f16_vsqrt_bench.wasm
- //:f32_vsqrt_bench.wasm
- //:f32_im2col_gemm_bench.wasm
- //:rounding_bench.wasm
- //:s16_rmaxabs_bench.wasm
- //:s16_window_bench.wasm
- //:u32_filterbank_accumulate_bench.wasm
- //:u32_filterbank_subtract_bench.wasm
- //:u32_vlog_bench.wasm
- //:u64_u32_vsqrtshift_bench.wasm
- //:i16_vlshift_bench.wasm
- //:cs16_vsquareabs_bench.wasm
- //:cs16_bfly4_bench.wasm
- //:cs16_fftr_bench.wasm
- //:x8_lut_bench.wasm
- //:abs_bench.wasm
- //:average_pooling_bench.wasm
- //:bankers_rounding_bench.wasm
- //:ceiling_bench.wasm
- //:channel_shuffle_bench.wasm
- //:convert_bench.wasm
- //:convolution_bench.wasm
- //:deconvolution_bench.wasm
- //:elu_bench.wasm
- //:floor_bench.wasm
- //:global_average_pooling_bench.wasm
- //:hardswish_bench.wasm
- //:leaky_relu_bench.wasm
- //:max_pooling_bench.wasm
- //:negate_bench.wasm
- //:sigmoid_bench.wasm
- //:prelu_bench.wasm
- //:softmax_bench.wasm
- //:square_bench.wasm
- //:square_root_bench.wasm
- //:truncation_bench.wasm
- //:f16_gemm_e2e_bench.wasm
- //:f32_dwconv_e2e_bench.wasm
- //:f32_gemm_e2e_bench.wasm
- //:qs8_dwconv_e2e_bench.wasm
- //:qs8_gemm_e2e_bench.wasm
- //:qu8_gemm_e2e_bench.wasm
- //:qu8_dwconv_e2e_bench.wasm
- //:end2end_bench.wasm
- //:f16_exp_ulp_eval.wasm
- //:f16_expminus_ulp_eval.wasm
- //:f16_expm1minus_ulp_eval.wasm
- //:f16_sigmoid_ulp_eval.wasm
- //:f16_sqrt_ulp_eval.wasm
- //:f32_exp_ulp_eval.wasm
- //:f32_expminus_ulp_eval.wasm
- //:f32_expm1minus_ulp_eval.wasm
- //:f32_extexp_ulp_eval.wasm
- //:f32_sigmoid_ulp_eval.wasm
- //:f32_sqrt_ulp_eval.wasm
- //:f32_tanh_ulp_eval.wasm
- INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
- ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/bazel-out/wasm-opt/bin/
- ${CMAKE_BINARY_DIR}/wasm-opt
-)
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch b/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch
deleted file mode 100644
index 3fb6b230be9..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch
+++ /dev/null
@@ -1,141 +0,0 @@
-diff --git a/.bazelrc b/.bazelrc
-index 688279da1..376996885 100644
---- a/.bazelrc
-+++ b/.bazelrc
-@@ -53,4 +53,9 @@ build:ios_fat --watchos_cpus=armv7k
- build:macos --apple_platform_type=macos
-
- build:macos_arm64 --config=macos
--build:macos_arm64 --cpu=darwin_arm64
-\ No newline at end of file
-+build:macos_arm64 --cpu=darwin_arm64
-+
-+build:wasm --cpu=wasm
-+build:wasm --features=wasm_simd
-+build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
-+build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
-diff --git a/WORKSPACE b/WORKSPACE
-index cd8960ffa..787e03ca8 100644
---- a/WORKSPACE
-+++ b/WORKSPACE
-@@ -29,8 +29,9 @@ http_archive(
- # Google Benchmark library, used in micro-benchmarks.
- http_archive(
- name = "com_google_benchmark",
-- strip_prefix = "benchmark-main",
-- urls = ["https://github.com/google/benchmark/archive/main.zip"],
-+ sha256 = "1ba14374fddcd9623f126b1a60945e4deac4cdc4fb25a5f25e7f779e36f2db52",
-+ strip_prefix = "benchmark-d2a8a4ee41b923876c034afb939c4fc03598e622",
-+ urls = ["https://github.com/google/benchmark/archive/d2a8a4ee41b923876c034afb939c4fc03598e622.zip"],
- )
-
- # FP16 library, used for half-precision conversions
-@@ -92,8 +93,25 @@ http_archive(
- ],
- )
-
-+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-+http_archive(
-+ name = "emsdk",
-+ # Use emsdk-3.0.0 since the larger version may:
-+ # - compress the wasm file into a tar file but not directly generate wasm file
-+ # - generate incomplete implementation of libc API, e.g. throw exception in getentropy
-+ strip_prefix = "emsdk-3.0.0/bazel",
-+ url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.0.0.tar.gz",
-+ sha256 = "a41dccfd15be9e85f923efaa0ac21943cbab77ec8d39e52f25eca1ec61a9ac9e"
-+)
-+
-+load("@emsdk//:deps.bzl", emsdk_deps = "deps")
-+emsdk_deps()
-+
-+load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
-+emsdk_emscripten_deps()
-+
- # Android NDK location and version is auto-detected from $ANDROID_NDK_HOME environment variable
--android_ndk_repository(name = "androidndk")
-+#android_ndk_repository(name = "androidndk")
-
- # Android SDK location and API is auto-detected from $ANDROID_HOME environment variable
--android_sdk_repository(name = "androidsdk")
-+#android_sdk_repository(name = "androidsdk")
-diff --git a/build_defs.bzl b/build_defs.bzl
-index b8217a18d..6f2d1675e 100644
---- a/build_defs.bzl
-+++ b/build_defs.bzl
-@@ -380,7 +380,7 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
- explicitly specified.
- """
- native.cc_binary(
-- name = name,
-+ name = name + ".wasm",
- srcs = srcs,
- copts = xnnpack_std_cxxopts() + [
- "-Iinclude",
-@@ -405,5 +405,5 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
- ":emscripten": xnnpack_emscripten_deps(),
- "//conditions:default": [],
- }),
-- tags = tags,
-+ tags = tags,
- )
-diff --git a/emscripten.bzl b/emscripten.bzl
-index f1557a7b1..7f964a094 100644
---- a/emscripten.bzl
-+++ b/emscripten.bzl
-@@ -25,12 +25,19 @@ def xnnpack_emscripten_benchmark_linkopts():
- """Emscripten-specific linkopts for benchmarks."""
- return [
- "-s ASSERTIONS=1",
-- "-s ENVIRONMENT=node,shell,web",
-- "-s ERROR_ON_UNDEFINED_SYMBOLS=1",
-- "-s EXIT_RUNTIME=1",
-+ "-s ERROR_ON_UNDEFINED_SYMBOLS=0",
- "-s ALLOW_MEMORY_GROWTH=1",
- "-s TOTAL_MEMORY=536870912", # 512M
-- "--pre-js $(location :preamble.js.lds)",
-+ "-s USE_PTHREADS=0",
-+ "-s STANDALONE_WASM=1",
-+ "-Wno-unused",
-+ "-Wno-unused-variable",
-+ "-Wno-unused-command-line-argument",
-+ "-Wl,--export=__heap_base",
-+ "-Wl,--export=__data_end",
-+ "-Wl,--export=malloc",
-+ "-Wl,--export=free",
-+ "--oformat=wasm",
- ]
-
- def xnnpack_emscripten_deps():
-diff --git a/src/log.c b/src/log.c
-index 5715f2f85..4b3e4261b 100644
---- a/src/log.c
-+++ b/src/log.c
-@@ -55,7 +55,7 @@
- #endif
-
- #if XNN_LOG_TO_STDIO
--static void xnn_vlog(int output_handle, const char* prefix, size_t prefix_length, const char* format, va_list args) {
-+void xnn_vlog(int output_handle, const char* prefix, size_t prefix_length, const char* format, va_list args) {
- char stack_buffer[XNN_LOG_STACK_BUFFER_SIZE];
- char* heap_buffer = NULL;
- char* out_buffer = &stack_buffer[0];
-diff --git a/third_party/cpuinfo.BUILD b/third_party/cpuinfo.BUILD
-index 1997f4e3a..5e03c43af 100644
---- a/third_party/cpuinfo.BUILD
-+++ b/third_party/cpuinfo.BUILD
-@@ -150,7 +150,7 @@ cc_library(
- "src/arm/midr.h",
- ],
- deps = [
-- "@clog",
-+ "//deps/clog"
- ],
- )
-
-@@ -352,5 +352,5 @@ config_setting(
-
- config_setting(
- name = "emscripten",
-- values = {"crosstool_top": "//toolchain:emscripten"},
-+ values = {"crosstool_top": "@emsdk//emscripten_toolchain:everything"},
- )
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore
deleted file mode 100644
index 417c854d242..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-out
-dist
-node_modules
-.vscode-test/
-*.vsix
-package-lock.json
-src/test
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json
deleted file mode 100644
index b1a2d99f09e..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- // See http://go.microsoft.com/fwlink/?LinkId=827846
- // for the documentation about the extensions.json format
- "recommendations": ["dbaeumer.vscode-eslint"]
-}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json
deleted file mode 100644
index 4e9ccc24b5d..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json
+++ /dev/null
@@ -1,15 +0,0 @@
-// A launch configuration that compiles the extension and then opens it inside a new window
-
-{
- "version": "0.2.0",
- "configurations": [
- {
- "name": "Launch Extension",
- "type": "extensionHost",
- "request": "launch",
- "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
- "outFiles": ["${workspaceFolder}/out/**/*.js"],
- "preLaunchTask": "${defaultBuildTask}"
- }
- ]
-}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json
deleted file mode 100644
index 5deb2bccd09..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json
+++ /dev/null
@@ -1,20 +0,0 @@
-// See https://go.microsoft.com/fwlink/?LinkId=733558
-// for the documentation about the tasks.json format
-{
- "version": "2.0.0",
- "tasks": [
- {
- "type": "npm",
- "script": "watch",
- "problemMatcher": "$tsc-watch",
- "isBackground": true,
- "presentation": {
- "reveal": "never"
- },
- "group": {
- "kind": "build",
- "isDefault": true
- }
- }
- ]
-}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore
deleted file mode 100644
index b2d2b478746..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore
+++ /dev/null
@@ -1,11 +0,0 @@
-.gitignore
-.yarnrc
-
-.vscode/**
-.vscode-test/**
-out/test/**
-
-**/tsconfig.json
-**/.eslintrc.json
-**/*.map
-**/*.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md
deleted file mode 100644
index 403e35ae9cf..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-### If you want to enable `source debugging` for this extension and use your own patched `lldb`, please build `lldb` firstly following this [instruction](../../../../../doc/source_debugging.md#debugging-with-interpreter)
-
-### After building(`linux` for example), create `bin` folder and `lib` folder respectively in `linux` directory, add following necessary target files into the folders
-
-```shell
-/llvm/build-lldb/bin/lldb # move this file to {VS Code directory}/resource/debug/linux/bin/
-/llvm/build-lldb/bin/lldb-vscode # move this file to {VS Code directory}/resource/debug/linux/bin/
-/llvm/build-lldb/lib/liblldb.so.13 # move this file to {VS Code directory}/resource/debug/linux/lib/
-```
-
-> If you are debugging this extension following this [tutorial](../../README.md), {VS Code directory} will be `{WAMR root directory}/test-tools/wamr-ide/VSCode-Extension`. If you want to replace the current lldb with your own patched version so that you can use your patched lldb in VS Code, {VS Code directory} will be `~/.vscode/extensions/wamr.wamride-1.1.2` or `~/.vscode-server/extensions/wamr.wamride-1.1.2`.
-
-Note: For macOS, the library is named like `liblldb.13.0.1.dylib`.
-
-### Then you can start the extension and run the execute source debugging by clicking the `debug` button in the extension panel.
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/darwin/.placeholder b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/darwin/.placeholder
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/linux/.placeholder b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/linux/.placeholder
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/windows/.placeholder b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/windows/.placeholder
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh
deleted file mode 100755
index a1ea7f6b75d..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-IWASM="../../../product-mini/platforms/linux/build/iwasm"
-WAMRC="../../../wamr-compiler/build/wamrc"
-
-echo "Run coremark with native .."
-./coremark.exe
-
-echo "Run coremark with iwasm mode .."
-${IWASM} coremark.aot
-
-echo "Run coremakr with iwasm interpreter .."
-${IWASM} coremark.wasm
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh
deleted file mode 100755
index 030b8d3a0d0..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-OUT_DIR=$PWD/out
-WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc
-
-mkdir -p jetstream
-mkdir -p ${OUT_DIR}
-
-cd jetstream
-
-echo "Download source files .."
-wget https://browserbench.org/JetStream/wasm/gcc-loops.cpp
-wget https://browserbench.org/JetStream/wasm/quicksort.c
-wget https://browserbench.org/JetStream/wasm/HashSet.cpp
-wget https://browserbench.org/JetStream/simple/float-mm.c
-
-patch -p1 < ../jetstream.patch
-
-echo "Build gcc-loops with g++ .."
-g++ -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/gcc-loops_native gcc-loops.cpp
-
-echo "Build gcc-loops with em++ .."
-em++ -O3 -s STANDALONE_WASM=1 -msimd128 \
- -s INITIAL_MEMORY=1048576 \
- -s TOTAL_STACK=32768 \
- -s "EXPORTED_FUNCTIONS=['_main']" \
- -s ERROR_ON_UNDEFINED_SYMBOLS=0 \
- -o ${OUT_DIR}/gcc-loops.wasm gcc-loops.cpp
-
-echo "Compile gcc-loops.wasm to gcc-loops.aot"
-${WAMRC_CMD} -o ${OUT_DIR}/gcc-loops.aot ${OUT_DIR}/gcc-loops.wasm
-
-echo "Build quicksort with gcc .."
-gcc -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/quicksort_native quicksort.c
-
-echo "Build quicksort with emcc .."
-emcc -O3 -s STANDALONE_WASM=1 -msimd128 \
- -s INITIAL_MEMORY=1048576 \
- -s TOTAL_STACK=32768 \
- -s "EXPORTED_FUNCTIONS=['_main']" \
- -o ${OUT_DIR}/quicksort.wasm quicksort.c
-
-echo "Compile quicksort.wasm to quicksort.aot"
-${WAMRC_CMD} -o ${OUT_DIR}/quicksort.aot ${OUT_DIR}/quicksort.wasm
-
-echo "Build HashSet with g++ .."
-g++ -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/HashSet_native HashSet.cpp \
- -lstdc++
-
-echo "Build HashSet with em++ .."
-em++ -O3 -s STANDALONE_WASM=1 -msimd128 \
- -s INITIAL_MEMORY=1048576 \
- -s TOTAL_STACK=32768 \
- -s "EXPORTED_FUNCTIONS=['_main']" \
- -o ${OUT_DIR}/HashSet.wasm HashSet.cpp
-
-echo "Compile HashSet.wasm to HashSet.aot"
-${WAMRC_CMD} -o ${OUT_DIR}/HashSet.aot ${OUT_DIR}/HashSet.wasm
-
-echo "Build float-mm with gcc .."
-gcc -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/float-mm_native float-mm.c
-
-echo "Build float-mm with emcc .."
-emcc -O3 -s STANDALONE_WASM=1 -msimd128 \
- -s INITIAL_MEMORY=1048576 \
- -s TOTAL_STACK=32768 \
- -s "EXPORTED_FUNCTIONS=['_main']" \
- -o ${OUT_DIR}/float-mm.wasm float-mm.c
-
-echo "Compile float-mm.wasm to float-mm.aot"
-${WAMRC_CMD} -o ${OUT_DIR}/float-mm.aot ${OUT_DIR}/float-mm.wasm
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh
deleted file mode 100755
index 2e4e3e357c4..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \
- aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \
- box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \
- core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \
- generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \
- onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \
- pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \
- scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \
- scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \
- secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \
- sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \
- xchacha20"
-
-readonly OUT_DIR=$PWD/libsodium/zig-out/bin
-readonly REPORT=$PWD/report.txt
-readonly IWASM_CMD=$PWD/../../../product-mini/platforms/linux/build/iwasm
-
-BENCH_NAME_MAX_LEN=20
-
-rm -f $REPORT
-touch $REPORT
-
-function print_bench_name()
-{
- name=$1
- echo -en "$name" >> $REPORT
- name_len=${#name}
- if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
- then
- spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
- for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
- fi
-}
-
-# run benchmarks
-cd $OUT_DIR
-
-echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT
-
-for t in $libsodium_CASES
-do
- print_bench_name $t
-
- echo "run $t with native..."
- echo -en "\t" >> $REPORT
- ./${t} | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT
-
- echo "run $t with iwasm aot..."
- echo -en "\t \t" >> $REPORT
- $IWASM_CMD ${t}.aot | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT
-
- echo -en "\n" >> $REPORT
-done
-
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh
deleted file mode 100755
index eb6cf3f91e1..00000000000
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-
-readonly MODE=$1
-readonly TARGET=$2
-
-readonly WORK_DIR=$PWD
-readonly PLATFORM=$(uname -s | tr A-Z a-z)
-readonly WAMR_DIR="${WORK_DIR}/../../../.."
-readonly IWASM_CMD="${WORK_DIR}/../../../../product-mini/platforms/${PLATFORM}/build/iwasm"
-readonly WAMRC_CMD="${WORK_DIR}/../../../../wamr-compiler/build/wamrc"
-readonly C_TESTS="tests/c/testsuite/"
-readonly ASSEMBLYSCRIPT_TESTS="tests/assemblyscript/testsuite/"
-readonly THREAD_PROPOSAL_TESTS="tests/proposals/wasi-threads/"
-readonly THREAD_INTERNAL_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/test/"
-readonly LIB_SOCKET_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-socket/test/"
-
-run_aot_tests () {
- local tests=("$@")
- for test_wasm in ${tests[@]}; do
- test_aot="${test_wasm%.wasm}.aot"
- test_json="${test_wasm%.wasm}.json"
-
- if [ -f ${test_wasm} ]; then
- expected=$(jq .exit_code ${test_json})
- fi
-
- echo "Compiling $test_wasm to $test_aot"
- ${WAMRC_CMD} --enable-multi-thread ${target_option} \
- -o ${test_aot} ${test_wasm}
-
- echo "Running $test_aot"
- expected=0
- if [ -f ${test_json} ]; then
- expected=$(jq .exit_code ${test_json})
- fi
-
- ${IWASM_CMD} $test_aot
-
- ret=${PIPESTATUS[0]}
-
- echo "expected=$expected, actual=$ret"
- if [[ $expected != "" ]] && [[ $expected != $ret ]];then
- exit_code=1
- fi
- done
-}
-
-if [[ $MODE != "aot" ]];then
- python3 -m venv wasi-env && source wasi-env/bin/activate
- python3 -m pip install -r test-runner/requirements.txt
- TEST_RUNTIME_EXE="${IWASM_CMD}" python3 test-runner/wasi_test_runner.py \
- -r adapters/wasm-micro-runtime.py \
- -t \
- ${C_TESTS} \
- ${ASSEMBLYSCRIPT_TESTS} \
- ${THREAD_PROPOSAL_TESTS} \
- ${THREAD_INTERNAL_TESTS} \
- ${LIB_SOCKET_TESTS} \
- exit_code=${PIPESTATUS[0]}
- deactivate
-else
- target_option=""
- if [[ $TARGET == "X86_32" ]];then
- target_option="--target=i386"
- fi
-
- exit_code=0
- for testsuite in ${THREAD_PROPOSAL_TESTS} ${THREAD_INTERNAL_TESTS}; do
- tests=$(ls ${testsuite}*.wasm)
- tests_array=($tests)
- run_aot_tests "${tests_array[@]}"
- done
-fi
-
-exit ${exit_code}
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.clang-tidy b/lib/wasm-micro-runtime-WAMR-1.3.0/.clang-tidy
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.clang-tidy
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.clang-tidy
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile
new file mode 100644
index 00000000000..1587a7ddc75
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile
@@ -0,0 +1,150 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/cpp/.devcontainer/base.Dockerfile
+# [Choice] Debian / Ubuntu version (use Debian 12/11/9, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-12, debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
+ARG VARIANT=debian-12
+FROM mcr.microsoft.com/vscode/devcontainers/cpp:${VARIANT}
+
+ARG DEBIAN_FRONTEND=noninteractive
+ENV TZ=Asian/Shanghai
+
+# hadolint ignore=DL3008
+RUN apt-get update \
+ && apt-get upgrade -y \
+ && apt-get install -y apt-transport-https apt-utils build-essential \
+ ca-certificates ccache cmake curl g++-multilib git gnupg \
+ libgcc-12-dev lib32gcc-12-dev lsb-release \
+ ninja-build ocaml ocamlbuild \
+ software-properties-common tree tzdata \
+ unzip valgrind vim wget zip --no-install-recommends \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/*
+
+#
+# binaryen
+ARG BINARYEN_VER=114
+WORKDIR /opt
+RUN wget -c --progress=dot:giga https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VER}/binaryen-version_${BINARYEN_VER}-x86_64-linux.tar.gz \
+ && tar xf binaryen-version_${BINARYEN_VER}-x86_64-linux.tar.gz \
+ && ln -sf /opt/binaryen-version_${BINARYEN_VER} /opt/binaryen \
+ && rm binaryen-version_${BINARYEN_VER}-x86_64-linux.tar.gz
+
+#
+# CMAKE (https://apt.kitware.com/)
+SHELL ["/bin/bash", "-o", "pipefail", "-c"]
+# hadolint ignore=DL3008
+ARG CMAKE_VER=3.27.0
+RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
+ -q -O /tmp/cmake-install.sh \
+ && chmod u+x /tmp/cmake-install.sh \
+ && mkdir /opt/cmake-${CMAKE_VER} \
+ && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
+ && rm /tmp/cmake-install.sh \
+ && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
+
+#
+# install emsdk
+WORKDIR /opt
+RUN git clone https://github.com/emscripten-core/emsdk.git
+
+ARG EMSDK_VER=3.1.43
+WORKDIR /opt/emsdk
+RUN git pull \
+ && ./emsdk install ${EMSDK_VER} \
+ && ./emsdk activate ${EMSDK_VER} \
+ && echo "source /opt/emsdk/emsdk_env.sh" >> /root/.bashrc
+
+#
+# install wasi-sdk
+ARG WASI_SDK_VER=20
+RUN wget -c --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VER}/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -P /opt \
+ && tar xf /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -C /opt \
+ && ln -sf /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk \
+ && rm /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz
+
+#
+#install wabt
+ARG WABT_VER=1.0.33
+RUN wget -c --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/${WABT_VER}/wabt-${WABT_VER}-ubuntu.tar.gz -P /opt \
+ && tar xf /opt/wabt-${WABT_VER}-ubuntu.tar.gz -C /opt \
+ && ln -sf /opt/wabt-${WABT_VER} /opt/wabt \
+ && rm /opt/wabt-${WABT_VER}-ubuntu.tar.gz
+
+#
+# install bazelisk
+ARG BAZELISK_VER=1.17.0
+RUN mkdir /opt/bazelisk \
+ && wget -c --progress=dot:giga https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VER}/bazelisk-linux-amd64 -P /opt/bazelisk \
+ && chmod a+x /opt/bazelisk/bazelisk-linux-amd64 \
+ && ln -fs /opt/bazelisk/bazelisk-linux-amd64 /opt/bazelisk/bazel
+
+#
+# install clang+llvm
+ARG LLVM_VER=16
+RUN apt-get purge -y clang-14 llvm-14 && apt-get autoremove -y
+WORKDIR /etc/apt/apt.conf.d
+RUN touch 99verfiy-peer.conf \
+ && echo "Acquire { https::Verify-Peer false }" > 99verfiy-peer.conf
+
+WORKDIR /tmp
+#RUN wget --progress=dot:giga https://apt.llvm.org/llvm.sh \
+# && chmod a+x ./llvm.sh \
+# && ./llvm.sh ${LLVM_VER} all
+
+# Workaround due to https://github.com/llvm/llvm-project/issues/62475
+# hadolint ignore=DL3008
+RUN set -ex \
+ && echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${LLVM_VER} main" > /etc/apt/sources.list.d/apt.llvm.org.list \
+ && wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \
+ && apt-get update \
+ && apt-get install -y \
+ clang-${LLVM_VER} lldb-${LLVM_VER} lld-${LLVM_VER} clangd-${LLVM_VER} clang-tidy-${LLVM_VER} clang-format-${LLVM_VER} clang-tools-${LLVM_VER} \
+ llvm-${LLVM_VER}-dev lld-${LLVM_VER} lldb-${LLVM_VER} llvm-${LLVM_VER}-tools libomp-${LLVM_VER}-dev libc++-${LLVM_VER}-dev libc++abi-${LLVM_VER}-dev \
+ libclang-common-${LLVM_VER}-dev libclang-${LLVM_VER}-dev libclang-cpp${LLVM_VER}-dev libunwind-${LLVM_VER}-dev \
+ libclang-rt-${LLVM_VER}-dev libpolly-${LLVM_VER}-dev --no-install-recommends \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/*
+
+#
+# [Optional]
+
+#
+# Install pip
+# hadolint ignore=DL3008
+RUN apt-get update \
+ && apt-get install -y --reinstall python3-venv python3-pip --no-install-recommends \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/*
+
+#
+# Install required python packages
+# hadolint ignore=DL3013
+RUN python3 -m pip install --no-cache-dir --break-system-packages --upgrade pip \
+ && pip3 install --no-cache-dir --break-system-packages black nose pycparser pylint
+
+#
+# Install github-cli. It doens't work as a feature of devcontainer.json
+ARG GH_CLI_VER=2.32.0
+WORKDIR /tmp
+RUN wget -q https://github.com/cli/cli/releases/download/v${GH_CLI_VER}/gh_${GH_CLI_VER}_linux_amd64.deb \
+ && dpkg -i gh_${GH_CLI_VER}_linux_amd64.deb
+
+#
+# Install NodeJS
+RUN wget -qO- https://deb.nodesource.com/setup_20.x | bash -
+# hadolint ignore=DL3008
+RUN apt-get install -y nodejs --no-install-recommends
+
+# set path
+ENV PATH="/opt/bazelisk:/usr/lib/llvm-${LLVM_VER}/bin:${PATH}"
+ENV CC=/usr/lib/llvm-${LLVM_VER}/bin/clang CXX=/usr/lib/llvm-${LLVM_VER}/bin/clang++
+RUN printf "%s\n" "PS1='\n[ \u@wamr-dev-docker \W ]\n$ '" >> /root/.bashrc \
+ && apt-get autoremove -y \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/* \
+ && rm -rf /tmp/*
+
+# set workdir when container run
+VOLUME /workspaces
+WORKDIR /workspaces
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.devcontainer/devcontainer.json b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/devcontainer.json
similarity index 70%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.devcontainer/devcontainer.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/devcontainer.json
index 24e1bdfd61f..5feb175640b 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.devcontainer/devcontainer.json
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/devcontainer.json
@@ -1,20 +1,23 @@
// Copyright (C) 2019 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
-// https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/cpp
+// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/cpp
{
"name": "WAMR-Dev",
"build": {
"dockerfile": "Dockerfile",
- // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
- // Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
+ // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-12, debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
+ // Use Debian 12, Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
"args": {
- "BINARYEN_VER": "111",
- "EMSDK_VER": "3.0.0",
- "LLVM_VER": "15",
- "VARIANT": "ubuntu-20.04",
- "WASI_SDK_VER": "19",
- "WABT_VER": "1.0.31"
+ "BINARYEN_VER": "114",
+ "BAZELISK_VER": "1.17.0",
+ "CMAKE_VER": "3.27.0",
+ "EMSDK_VER": "3.1.43",
+ "GH_CLI_VER": "2.32.0",
+ "LLVM_VER": "16",
+ "VARIANT": "debian-12",
+ "WASI_SDK_VER": "20",
+ "WABT_VER": "1.0.33"
}
},
"runArgs": [
@@ -34,7 +37,7 @@
"llvm-vs-code-extensions.vscode-clangd",
"ms-python.python",
"ms-python.vscode-pylance",
- "ms-vscode.cmake-tools",
+ "ms-vscode.cmake-tools"
]
}
},
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/extract_from_release_notes.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/extract_from_release_notes.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/fetch_and_compare_version.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/fetch_and_compare_version.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/reuse_latest_release_binaries.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/reuse_latest_release_binaries.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_docker_images.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_docker_images.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_docker_images.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_docker_images.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_iwasm_release.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_iwasm_release.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_iwasm_release.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_iwasm_release.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_llvm_libraries.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_llvm_libraries.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_llvm_libraries.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_llvm_libraries.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_lldb.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_lldb.yml
similarity index 63%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_lldb.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_lldb.yml
index ba491ad3ad1..1a73750a642 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_lldb.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_lldb.yml
@@ -22,6 +22,11 @@ on:
description: a semantic version number
type: string
required: true
+ wasi_sdk_url:
+ description: download WASI_SDK from this URL
+ type: string
+ required: false
+ default: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz"
jobs:
try_reuse:
@@ -29,16 +34,30 @@ jobs:
with:
binary_name_stem: "wamr-lldb-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}"
last_commit: "ea63ba4bd010c2285623ad4acc0262a4d63bcfea"
- the_path: "./build-scripts/lldb-wasm.patch"
+ the_path: "./build-scripts/lldb_wasm.patch"
upload_url: ${{ inputs.upload_url }}
build:
needs: try_reuse
if: needs.try_reuse.outputs.result != 'hit'
runs-on: ${{ inputs.runner }}
+
+ env:
+ PYTHON_VERSION: '3.10'
+ PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz
+ PYTHON_MACOS_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-apple-darwin-install_only.tar.gz
steps:
- uses: actions/checkout@v3
+ - name: download and install wasi-sdk
+ run: |
+ cd /opt
+ basename=$(basename ${{ inputs.wasi_sdk_url }})
+ sudo wget --progress=dot:giga ${{ inputs.wasi_sdk_url }}
+ sudo tar -xzf ${basename}
+ sudo rm ${basename}
+ sudo mv wasi-sdk-* wasi-sdk
+
- name: Cache build
id: lldb_build_cache
uses: actions/cache@v3
@@ -63,10 +82,12 @@ jobs:
- name: install utils macos
if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos')
run: |
- brew install swig cmake ninja libedit
+ brew remove swig
+ brew install swig@4.1 cmake ninja libedit
+ brew link --overwrite swig@4.1
sudo rm -rf /Library/Developer/CommandLineTools
- - name: intsall utils ubuntu
+ - name: install utils ubuntu
if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu')
run: sudo apt update && sudo apt-get install -y lld ninja-build
@@ -85,9 +106,23 @@ jobs:
git init
git config user.email "action@github.com"
git config user.name "github action"
- git apply ../../../build-scripts/lldb-wasm.patch
+ git apply ../../../build-scripts/lldb_wasm.patch
working-directory: core/deps/llvm-project
+ - name: get stand-alone python ubuntu
+ if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu')
+ run: |
+ wget ${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }} -O python.tar.gz
+ tar -xvf python.tar.gz
+ working-directory: core/deps
+
+ - name: get stand-alone python macos
+ if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos')
+ run: |
+ wget ${{ env.PYTHON_MACOS_STANDALONE_BUILD }} -O python.tar.gz
+ tar -xvf python.tar.gz
+ working-directory: core/deps
+
- name: build lldb ubuntu
if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu')
run: |
@@ -102,20 +137,35 @@ jobs:
-DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \
-DLLVM_BUILD_BENCHMARKS:BOOL=OFF \
-DLLVM_BUILD_DOCS:BOOL=OFF \
- -DLLVM_BUILD_EXAMPLES:BOOL=OFF \
+ -DLLVM_BUILD_EXAMPLES:BOOL=OFF \
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
- -DLLVM_BUILD_TESTS:BOOL=OFF \
- -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
+ -DLLVM_BUILD_TESTS:BOOL=OFF \
+ -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
-DLLVM_INCLUDE_DOCS:BOOL=OFF \
-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \
-DLLVM_INCLUDE_TESTS:BOOL=OFF \
-DLLVM_ENABLE_BINDINGS:BOOL=OFF \
-DLLVM_ENABLE_LIBXML2:BOOL=ON \
- -DLLDB_ENABLE_PYTHON:BOOL=OFF \
- -DLLVM_ENABLE_LLD:BOOL=ON
+ -DLLVM_ENABLE_LLD:BOOL=ON \
+ -DLLDB_ENABLE_PYTHON:BOOL=ON \
+ -DLLDB_EMBED_PYTHON_HOME=ON \
+ -DLLDB_PYTHON_HOME=.. \
+ -DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \
+ -DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}"
cmake --build build --target lldb install --parallel $(nproc)
working-directory: core/deps/llvm-project
+ - name: validate lldb ubuntu
+ if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu')
+ run: |
+ echo "start to validate lldb..."
+ mkdir -p wamr-debug
+ cmake -S product-mini/platforms/linux -B wamr-debug -DWAMR_BUILD_DEBUG_INTERP=1
+ cmake --build wamr-debug --parallel $(nproc)
+ export LD_LIBRARY_PATH=$(pwd)/core/deps/python/lib:${LD_LIBRARY_PATH}
+ python3 ci/validate_lldb.py --port 1239 --lldb core/deps/wamr-lldb/bin/lldb --wamr wamr-debug/iwasm --verbose
+ working-directory: .
+
- name: build lldb macos
if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos')
run: |
@@ -130,20 +180,21 @@ jobs:
-DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \
-DLLVM_BUILD_BENCHMARKS:BOOL=OFF \
-DLLVM_BUILD_DOCS:BOOL=OFF \
- -DLLVM_BUILD_EXAMPLES:BOOL=OFF \
+ -DLLVM_BUILD_EXAMPLES:BOOL=OFF \
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
- -DLLVM_BUILD_TESTS:BOOL=OFF \
- -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
+ -DLLVM_BUILD_TESTS:BOOL=OFF \
+ -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
-DLLVM_INCLUDE_DOCS:BOOL=OFF \
-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \
-DLLVM_INCLUDE_TESTS:BOOL=OFF \
- -DLLVM_BUILD_BENCHMARKS:BOOL=OFF \
- -DLLVM_BUILD_DOCS:BOOL=OFF \
- -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
-DLLVM_ENABLE_BINDINGS:BOOL=OFF \
-DLLVM_ENABLE_LIBXML2:BOOL=ON \
- -DLLDB_ENABLE_PYTHON:BOOL=OFF \
- -DLLDB_BUILD_FRAMEWORK:BOOL=OFF
+ -DLLDB_BUILD_FRAMEWORK:BOOL=OFF \
+ -DLLDB_ENABLE_PYTHON:BOOL=ON \
+ -DLLDB_EMBED_PYTHON_HOME=ON \
+ -DLLDB_PYTHON_HOME=.. \
+ -DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \
+ -DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}"
cmake --build build --target lldb install --parallel $(nproc)
working-directory: core/deps/llvm-project
@@ -154,7 +205,7 @@ jobs:
mkdir -p wamr-lldb/lib
cp build/bin/lldb* wamr-lldb/bin
cp lldb/tools/lldb-vscode/package.json wamr-lldb
- cp -r lldb/tools/lldb-vscode/syntaxes/ wamr-lldb
+ cp -r lldb/tools/lldb-vscode/syntaxes/ wamr-lldb
working-directory: core/deps/llvm-project
- name: pack ubuntu specific libraries
@@ -162,12 +213,20 @@ jobs:
run: |
cp build/lib/liblldb*.so wamr-lldb/lib
cp build/lib/liblldb*.so.* wamr-lldb/lib
+ cp -R build/lib/lldb-python wamr-lldb/lib
+ cp -R ../python/lib/python* wamr-lldb/lib
+ cp ../python/lib/libpython${{ env.PYTHON_VERSION }}.so.1.0 wamr-lldb/lib
working-directory: core/deps/llvm-project
- name: pack macos specific libraries
if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos')
run: |
cp build/lib/liblldb*.dylib wamr-lldb/lib
+ cp -R build/lib/lldb-python wamr-lldb/lib
+ cp -R ../python/lib/python* wamr-lldb/lib
+ cp ../python/lib/libpython*.dylib wamr-lldb/lib
+ install_name_tool -change /install/lib/libpython${{ env.PYTHON_VERSION }}.dylib @rpath/libpython${{ env.PYTHON_VERSION }}.dylib wamr-lldb/lib/liblldb.*.dylib
+ # Patch path of python library -> https://github.com/indygreg/python-build-standalone/blob/85923ca3911784e6978b85d56e06e9ae75cb2dc4/docs/quirks.rst?plain=1#L412-L446
working-directory: core/deps/llvm-project
- name: compress the binary
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_sdk.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_sdk.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_sdk.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_sdk.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_vscode_ext.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_vscode_ext.yml
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_vscode_ext.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_vscode_ext.yml
index 297dc9b9e72..3dfb290cf77 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_vscode_ext.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_vscode_ext.yml
@@ -20,10 +20,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- - name: Use Node.js 14.x
+ - name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
- node-version: 14.x
+ node-version: 16.x
- name: set vscode extension to correct version
run: |
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamrc.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamrc.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamrc.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamrc.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/coding_guidelines.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/coding_guidelines.yml
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/coding_guidelines.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/coding_guidelines.yml
index 259e84fe51b..17d60ac43d7 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/coding_guidelines.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/coding_guidelines.yml
@@ -16,7 +16,7 @@ concurrency:
jobs:
compliance_job:
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v3
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml
new file mode 100644
index 00000000000..98d346f9ebb
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml
@@ -0,0 +1,713 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+name: compilation on android, ubuntu-22.04
+
+on:
+ # will be triggered on PR events
+ pull_request:
+ types:
+ - opened
+ - synchronize
+ paths:
+ - ".github/workflows/build_llvm_libraries.yml"
+ - ".github/workflows/compilation_on_android_ubuntu.yml"
+ - "build-scripts/**"
+ - "core/**"
+ - "!core/deps/**"
+ - "product-mini/**"
+ - "samples/**"
+ - "!samples/workload/**"
+ - "tests/wamr-test-suites/**"
+ - "wamr-compiler/**"
+ - "wamr-sdk/**"
+ - "test-tools/wamr-ide/**"
+ # will be triggered on push events
+ push:
+ branches:
+ - main
+ - "dev/**"
+ paths:
+ - ".github/workflows/build_llvm_libraries.yml"
+ - ".github/workflows/compilation_on_android_ubuntu.yml"
+ - "build-scripts/**"
+ - "core/**"
+ - "!core/deps/**"
+ - "product-mini/**"
+ - "samples/**"
+ - "!samples/workload/**"
+ - "tests/wamr-test-suites/**"
+ - "wamr-compiler/**"
+ - "wamr-sdk/**"
+ - "test-tools/wamr-ide/**"
+ # allow to be triggered manually
+ workflow_dispatch:
+
+# Cancel any in-flight jobs for the same PR/branch so there's only one active
+# at a time
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+env:
+ # For BUILD
+ AOT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
+ CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
+ FAST_INTERP_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
+ FAST_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
+ LLVM_LAZY_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
+ LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
+ MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
+ # For Spec Test
+ DEFAULT_TEST_OPTIONS: "-s spec -b -P"
+ MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M -P"
+ SIMD_TEST_OPTIONS: "-s spec -b -S -P"
+ THREADS_TEST_OPTIONS: "-s spec -b -p -P"
+ X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
+ WASI_TEST_OPTIONS: "-s wasi_certification -w"
+ WAMR_COMPILER_TEST_OPTIONS: "-s wamr_compiler -b -P"
+
+jobs:
+ build_llvm_libraries_on_ubuntu_2204:
+ uses: ./.github/workflows/build_llvm_libraries.yml
+ with:
+ os: "ubuntu-22.04"
+ arch: "X86"
+
+ build_wamrc:
+ needs:
+ [build_llvm_libraries_on_ubuntu_2204]
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ include:
+ - os: ubuntu-22.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ # since jobs.id can't contain the dot character
+ # it is hard to use `format` to assemble the cache key
+ - name: Get LLVM libraries
+ id: retrieve_llvm_libs
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+
+ - name: Quit if cache miss
+ if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
+ run: echo "::error::can not get prebuilt llvm libraries" && exit 1
+
+ - name: Build wamrc
+ run: |
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ working-directory: wamr-compiler
+
+ build_iwasm:
+ needs:
+ [build_llvm_libraries_on_ubuntu_2204]
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ make_options_run_mode: [
+ # Running mode
+ $AOT_BUILD_OPTIONS,
+ $CLASSIC_INTERP_BUILD_OPTIONS,
+ $FAST_INTERP_BUILD_OPTIONS,
+ $FAST_JIT_BUILD_OPTIONS,
+ $LLVM_LAZY_JIT_BUILD_OPTIONS,
+ $LLVM_EAGER_JIT_BUILD_OPTIONS,
+ $MULTI_TIER_JIT_BUILD_OPTIONS,
+ ]
+ make_options_feature: [
+ # Features
+ "-DWAMR_BUILD_CUSTOM_NAME_SECTION=1",
+ "-DWAMR_BUILD_DEBUG_AOT=1",
+ "-DWAMR_BUILD_DEBUG_INTERP=1",
+ "-DWAMR_BUILD_DUMP_CALL_STACK=1",
+ "-DWAMR_BUILD_LIB_PTHREAD=1",
+ "-DWAMR_BUILD_LIB_WASI_THREADS=1",
+ "-DWAMR_BUILD_LOAD_CUSTOM_SECTION=1",
+ "-DWAMR_BUILD_MINI_LOADER=1",
+ "-DWAMR_BUILD_MEMORY_PROFILING=1",
+ "-DWAMR_BUILD_MULTI_MODULE=1",
+ "-DWAMR_BUILD_PERF_PROFILING=1",
+ "-DWAMR_BUILD_REF_TYPES=1",
+ "-DWAMR_BUILD_SIMD=1",
+ "-DWAMR_BUILD_TAIL_CALL=1",
+ "-DWAMR_DISABLE_HW_BOUND_CHECK=1",
+ ]
+ os: [ubuntu-22.04]
+ platform: [android, linux]
+ exclude:
+ # uncompatiable feature and platform
+ # uncompatiable mode and feature
+ # MULTI_MODULE only on INTERP mode and AOT mode
+ - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ # SIMD only on JIT/AOT mode
+ - make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_SIMD=1"
+ - make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_SIMD=1"
+ # DEBUG_INTERP only on CLASSIC INTERP mode
+ - make_options_run_mode: $AOT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ # DEBUG_AOT only on JIT/AOT mode
+ - make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ # TODO: DEBUG_AOT on JIT
+ - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ # MINI_LOADER only on INTERP mode
+ - make_options_run_mode: $AOT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ # Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32)
+ - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
+ platform: android
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ platform: android
+ include:
+ - os: ubuntu-22.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ # only download llvm cache when needed
+ - name: Get LLVM libraries
+ id: retrieve_llvm_libs
+ if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS')
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+
+ - name: Quit if cache miss
+ if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
+ run: echo "::error::can not get prebuilt llvm libraries" && exit 1
+
+ - name: Build iwasm
+ run: |
+ mkdir build && cd build
+ cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
+ cmake --build . --config Release --parallel 4
+ working-directory: product-mini/platforms/${{ matrix.platform }}
+
+ - name: Build and run unit tests
+ run: |
+ mkdir build-unittests && cd build-unittests
+ cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
+ cmake --build . --config Release --parallel 4
+ ctest
+ working-directory: tests/unit
+
+ build_samples_wasm_c_api:
+ needs:
+ [
+ build_iwasm,
+ build_llvm_libraries_on_ubuntu_2204,
+ build_wamrc,
+ ]
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ make_options: [
+ # Running mode
+ $AOT_BUILD_OPTIONS,
+ $CLASSIC_INTERP_BUILD_OPTIONS,
+ $FAST_INTERP_BUILD_OPTIONS,
+ $FAST_JIT_BUILD_OPTIONS,
+ $LLVM_LAZY_JIT_BUILD_OPTIONS,
+ $LLVM_EAGER_JIT_BUILD_OPTIONS,
+ $MULTI_TIER_JIT_BUILD_OPTIONS,
+ ]
+ os: [ubuntu-22.04]
+ wasi_sdk_release:
+ [
+ "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
+ ]
+ wabt_release:
+ [
+ "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
+ ]
+ include:
+ - os: ubuntu-22.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ - name: Get LLVM libraries
+ id: retrieve_llvm_libs
+ if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+
+ - name: Quit if cache miss
+ if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
+ run: echo "::error::can not get prebuilt llvm libraries" && exit 1
+
+ - name: download and install wabt
+ run: |
+ cd /opt
+ sudo wget ${{ matrix.wabt_release }}
+ sudo tar -xzf wabt-1.0.31-*.tar.gz
+ sudo mv wabt-1.0.31 wabt
+
+ - name: Build wamrc
+ if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
+ run: |
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ working-directory: wamr-compiler
+
+ - name: Build Sample [wasm-c-api]
+ run: |
+ VERBOSE=1
+ cmake -S . -B build ${{ matrix.make_options }}
+ cmake --build build --config Release --parallel 4
+ ctest --test-dir build --output-on-failure
+ working-directory: samples/wasm-c-api
+
+ build_samples_others:
+ needs:
+ [
+ build_iwasm,
+ build_llvm_libraries_on_ubuntu_2204,
+ build_wamrc,
+ ]
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-22.04]
+ wasi_sdk_release:
+ [
+ "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
+ ]
+ wabt_release:
+ [
+ "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
+ ]
+ include:
+ - os: ubuntu-22.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ - name: download and install wasi-sdk
+ run: |
+ cd /opt
+ sudo wget ${{ matrix.wasi_sdk_release }}
+ sudo tar -xzf wasi-sdk-*.tar.gz
+ sudo mv wasi-sdk-20.0 wasi-sdk
+
+ - name: download and install wabt
+ run: |
+ cd /opt
+ sudo wget ${{ matrix.wabt_release }}
+ sudo tar -xzf wabt-1.0.31-*.tar.gz
+ sudo mv wabt-1.0.31 wabt
+ - name: Get LLVM libraries
+ id: retrieve_llvm_libs
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+ - name: Build wamrc
+ run: |
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ working-directory: wamr-compiler
+ - name: Build Sample [basic]
+ run: |
+ cd samples/basic
+ ./build.sh
+ ./run.sh
+
+ - name: Build Sample [file]
+ run: |
+ cd samples/file
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ ./src/iwasm -f wasm-app/file.wasm -d .
+
+ - name: Build Sample [multi-thread]
+ run: |
+ cd samples/multi-thread
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ ./iwasm wasm-apps/test.wasm
+
+ - name: Build Sample [multi-module]
+ run: |
+ cd samples/multi-module
+ mkdir build && cd build
+ cmake .. -DWAMR_BUILD_AOT=1
+ cmake --build . --config Release --parallel 4
+ ./multi_module mC.wasm
+ ./multi_module mC.aot
+
+ - name: Build Sample [spawn-thread]
+ run: |
+ cd samples/spawn-thread
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ ./spawn_thread
+
+ - name: Build Sample [ref-types]
+ run: |
+ cd samples/ref-types
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ ./hello
+
+ - name: Build Sample [simple]
+ run: |
+ ./build.sh -p host-interp
+ python3 ./sample_test_run.py $(pwd)/out
+ exit $?
+ working-directory: ./samples/simple
+
+ - name: Build Sample [wasi-threads]
+ run: |
+ cd samples/wasi-threads
+ mkdir build && cd build
+ cmake ..
+ cmake --build . --config Release --parallel 4
+ ./iwasm wasm-apps/no_pthread.wasm
+
+ - name: Build Sample [shared-module]
+ run: |
+ cd samples/shared-module
+ ./build.sh
+ ./run.sh
+
+ test:
+ needs:
+ [
+ build_iwasm,
+ build_llvm_libraries_on_ubuntu_2204,
+ build_wamrc,
+ ]
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-22.04]
+ running_mode:
+ [
+ "classic-interp",
+ "fast-interp",
+ "jit",
+ "aot",
+ "fast-jit",
+ "multi-tier-jit",
+ ]
+ test_option:
+ [
+ $DEFAULT_TEST_OPTIONS,
+ $MULTI_MODULES_TEST_OPTIONS,
+ $SIMD_TEST_OPTIONS,
+ $THREADS_TEST_OPTIONS,
+ $WASI_TEST_OPTIONS,
+ ]
+ wasi_sdk_release:
+ [
+ "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
+ ]
+ include:
+ - os: ubuntu-22.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+ ubuntu_version: "22.04"
+ - os: ubuntu-22.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+ running_mode: aot
+ test_option: $WAMR_COMPILER_TEST_OPTIONS
+ exclude:
+ # uncompatiable modes and features
+ # classic-interp and fast-interp don't support simd
+ - running_mode: "classic-interp"
+ test_option: $SIMD_TEST_OPTIONS
+ - running_mode: "fast-interp"
+ test_option: $SIMD_TEST_OPTIONS
+ # llvm jit doesn't support multi module
+ - running_mode: "jit"
+ test_option: $MULTI_MODULES_TEST_OPTIONS
+ # fast-jit doesn't support multi module, simd
+ - running_mode: "fast-jit"
+ test_option: $MULTI_MODULES_TEST_OPTIONS
+ - running_mode: "fast-jit"
+ test_option: $SIMD_TEST_OPTIONS
+ # multi-tier-jit doesn't support multi module, simd
+ - running_mode: "multi-tier-jit"
+ test_option: $MULTI_MODULES_TEST_OPTIONS
+ - running_mode: "multi-tier-jit"
+ test_option: $SIMD_TEST_OPTIONS
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ - name: download and install wasi-sdk
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: |
+ cd /opt
+ sudo wget ${{ matrix.wasi_sdk_release }}
+ sudo tar -xzf wasi-sdk-*.tar.gz
+ sudo mv wasi-sdk-20.0 wasi-sdk
+
+ # It is a temporary solution until new wasi-sdk that includes bug fixes is released
+ - name: build wasi-libc from source
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: |
+ git clone https://github.com/WebAssembly/wasi-libc
+ cd wasi-libc
+ make -j AR=/opt/wasi-sdk/bin/llvm-ar NM=/opt/wasi-sdk/bin/llvm-nm CC=/opt/wasi-sdk/bin/clang THREAD_MODEL=posix
+ echo "SYSROOT_PATH=$PWD/sysroot" >> $GITHUB_ENV
+
+
+ - name: set env variable(if llvm are used)
+ if: matrix.running_mode == 'aot' || matrix.running_mode == 'jit' || matrix.running_mode == 'multi-tier-jit'
+ run: echo "USE_LLVM=true" >> $GITHUB_ENV
+
+ - name: set env variable(if x86_32 test needed)
+ if: >
+ (matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS'
+ || matrix.test_option == '$WASI_TEST_OPTIONS')
+ && matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit'
+ run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV
+
+ #only download llvm libraries in jit and aot mode
+ - name: Get LLVM libraries
+ if: env.USE_LLVM == 'true'
+ id: retrieve_llvm_libs
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+
+ - name: Quit if cache miss
+ if: env.USE_LLVM == 'true' && steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
+ run: echo "::error::can not get prebuilt llvm libraries" && exit 1
+
+ - name: install jq JSON processor
+ if: matrix.running_mode == 'aot' && matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: sudo apt-get update && sudo apt install -y jq
+
+ - name: Build WASI thread tests
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: bash build.sh --sysroot "$SYSROOT_PATH"
+ working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/
+
+ - name: build socket api tests
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: bash build.sh
+ working-directory: ./core/iwasm/libraries/lib-socket/test/
+
+ - name: run tests
+ timeout-minutes: 30
+ run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
+ working-directory: ./tests/wamr-test-suites
+
+ #only install x32 support libraries when to run x86_32 cases
+ - name: install x32 support libraries
+ if: env.TEST_ON_X86_32 == 'true'
+ run:
+ # Add another apt repository as some packages cannot
+ # be downloaded with the github default repository
+ sudo curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc &&
+ sudo apt-add-repository https://packages.microsoft.com/ubuntu/${{ matrix.ubuntu_version }}/prod &&
+ sudo apt-get update &&
+ sudo apt install -y g++-multilib lib32gcc-9-dev
+
+ - name: run tests x86_32
+ timeout-minutes: 30
+ if: env.TEST_ON_X86_32 == 'true'
+ run: ./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
+ working-directory: ./tests/wamr-test-suites
+
+ test-wamr-ide:
+ needs:
+ [
+ build_iwasm
+ ]
+ runs-on: ubuntu-22.04
+ env:
+ PYTHON_VERSION: '3.10'
+ PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz
+
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ - name: install dependencies
+ run: |
+ rustup target add wasm32-wasi
+ sudo apt update && sudo apt-get install -y lld ninja-build
+ npm install
+ working-directory: test-tools/wamr-ide/VSCode-Extension
+
+ - name: build iwasm with source debugging feature
+ run: |
+ mkdir build
+ cd build
+ cmake .. -DWAMR_BUILD_DEBUG_INTERP=1
+ make
+ working-directory: product-mini/platforms/linux
+
+ - name: Cache LLDB
+ id: cache-lldb
+ uses: actions/cache@v3
+ env:
+ cache-name: cache-lldb-vscode
+ with:
+ path: test-tools/wamr-ide/VSCode-Extension/resource/debug/linux
+ key: ${{ env.cache-name }}-${{ hashFiles('build-scripts/lldb_wasm.patch') }}-${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }}
+
+ - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
+ name: get stand-alone python ubuntu
+ run: |
+ wget ${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }} -O python.tar.gz
+ tar -xvf python.tar.gz
+ working-directory: core/deps
+
+ - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
+ name: download llvm
+ run: |
+ wget https://github.com/llvm/llvm-project/archive/1f27fe6128769f00197925c3b8f6abb9d0e5cd2e.zip
+ unzip -q 1f27fe6128769f00197925c3b8f6abb9d0e5cd2e.zip
+ mv llvm-project-1f27fe6128769f00197925c3b8f6abb9d0e5cd2e llvm-project
+ working-directory: core/deps
+
+ - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
+ name: apply wamr patch
+ run: |
+ git init
+ git config user.email "action@github.com"
+ git config user.name "github action"
+ git apply ../../../build-scripts/lldb_wasm.patch
+ working-directory: core/deps/llvm-project
+
+ - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
+ name: build lldb ubuntu
+ run: |
+ echo "start to build lldb..."
+ mkdir -p wamr-lldb
+ cmake -S ./llvm -B build \
+ -G Ninja \
+ -DCMAKE_INSTALL_PREFIX=../wamr-lldb \
+ -DCMAKE_BUILD_TYPE:STRING="Release" \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -DLLVM_ENABLE_PROJECTS="clang;lldb" \
+ -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \
+ -DLLVM_BUILD_BENCHMARKS:BOOL=OFF \
+ -DLLVM_BUILD_DOCS:BOOL=OFF \
+ -DLLVM_BUILD_EXAMPLES:BOOL=OFF \
+ -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
+ -DLLVM_BUILD_TESTS:BOOL=OFF \
+ -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
+ -DLLVM_INCLUDE_DOCS:BOOL=OFF \
+ -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \
+ -DLLVM_INCLUDE_TESTS:BOOL=OFF \
+ -DLLVM_ENABLE_BINDINGS:BOOL=OFF \
+ -DLLVM_ENABLE_LIBXML2:BOOL=ON \
+ -DLLVM_ENABLE_LLD:BOOL=ON \
+ -DLLDB_ENABLE_PYTHON:BOOL=ON \
+ -DLLDB_EMBED_PYTHON_HOME=ON \
+ -DLLDB_PYTHON_HOME=.. \
+ -DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \
+ -DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}"
+ cmake --build build --target lldb install --parallel $(nproc)
+ working-directory: core/deps/llvm-project
+
+ - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
+ name: copy lldb to extension folder
+ run: |
+ mkdir -p bin
+ mkdir -p lib
+ cp ../../../../../../core/deps/llvm-project/lldb/tools/lldb-vscode/package.json ./
+ cp -r ../../../../../../core/deps/llvm-project/lldb/tools/lldb-vscode/syntaxes/ ./
+ cp ../../../../../../core/deps/llvm-project/build/bin/lldb* bin
+ cp ../../../../../../core/deps/llvm-project/build/lib/liblldb*.so lib
+ cp ../../../../../../core/deps/llvm-project/build/lib/liblldb*.so.* lib
+ cp -R ../../../../../../core/deps/llvm-project/build/lib/lldb-python lib
+ cp -R ../../../../../../core/deps/python/lib/python* lib
+ cp ../../../../../../core/deps/python/lib/libpython${{ env.PYTHON_VERSION }}.so.1.0 lib
+ working-directory: test-tools/wamr-ide/VSCode-Extension/resource/debug/linux
+
+ - name: run tests
+ timeout-minutes: 5
+ run: xvfb-run npm run test
+ working-directory: test-tools/wamr-ide/VSCode-Extension
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_macos.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_macos.yml
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_macos.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_macos.yml
index aaa97d038cd..12f1d73cb91 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_macos.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_macos.yml
@@ -133,13 +133,11 @@ jobs:
exclude:
# uncompatiable feature and platform
# uncompatiable mode and feature
- # MULTI_MODULE only on INTERP mode
+ # MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- - make_options_run_mode: $AOT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
# SIMD only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
@@ -245,7 +243,7 @@ jobs:
working-directory: samples/wasm-c-api
build_samples_others:
- needs: [build_iwasm]
+ needs: [build_iwasm, build_wamrc]
runs-on: ${{ matrix.os }}
strategy:
matrix:
@@ -304,7 +302,7 @@ jobs:
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
- ./multi_module
+ ./multi_module mC.wasm
- name: Build Sample [spawn-thread]
run: |
@@ -329,3 +327,9 @@ jobs:
cmake ..
cmake --build . --config Release --parallel 4
./iwasm wasm-apps/no_pthread.wasm
+
+ - name: Build Sample [shared-module]
+ run: |
+ cd samples/shared-module
+ ./build.sh
+ ./run.sh
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_nuttx.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_nuttx.yml
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_nuttx.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_nuttx.yml
index f338c8dea7b..77b3da75a10 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_nuttx.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_nuttx.yml
@@ -94,9 +94,9 @@ jobs:
- name: Install RISC-V Compilers
if: contains(matrix.nuttx_board_config, 'risc-v')
run: |
- curl -L https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz > riscv.tar.gz
+ curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.tar.gz > riscv.tar.gz
tar xvf riscv.tar.gz
- echo "$PWD/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH
+ echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH
- name: Install WASI-SDK
run: |
@@ -108,12 +108,14 @@ jobs:
uses: actions/checkout@v3
with:
repository: apache/incubator-nuttx
+ ref: releases/12.3
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v3
with:
repository: apache/incubator-nuttx-apps
+ ref: releases/12.3
path: apps
- name: Checkout WAMR
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_sgx.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_sgx.yml
similarity index 69%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_sgx.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_sgx.yml
index f17261118fe..0d19d83ad94 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_sgx.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_sgx.yml
@@ -51,6 +51,7 @@ env:
AOT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
+ FAST_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
@@ -70,6 +71,7 @@ jobs:
$AOT_BUILD_OPTIONS,
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
+ $FAST_JIT_BUILD_OPTIONS,
# Running modes unsupported
#$LLVM_LAZY_JIT_BUILD_OPTIONS,
#$LLVM_EAGER_JIT_BUILD_OPTIONS,
@@ -99,9 +101,6 @@ jobs:
platform: [linux-sgx]
exclude:
# uncompatiable mode and feature
- # MULTI_MODULE only on INTERP mode
- - make_options_run_mode: $AOT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
# MINI_LOADER only on INTERP mode
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
@@ -127,69 +126,24 @@ jobs:
mkdir build && cd build
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
cmake --build . --config Release --parallel 4
+ cd ../enclave-sample
+ make
working-directory: product-mini/platforms/${{ matrix.platform }}
- build_wamrc:
- needs: [build_llvm_libraries]
+ run_samples_file:
+ needs: [build_iwasm, build_llvm_libraries]
runs-on: ${{ matrix.os }}
strategy:
matrix:
- include:
- - os: ubuntu-20.04
- llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
- steps:
- - name: install SGX SDK and necessary libraries
- run: |
- mkdir -p /opt/intel
- cd /opt/intel
- wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin
- chmod +x sgx_linux_x64_sdk_2.15.100.3.bin
- echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin
- echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
- wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
- sudo apt update
- sudo apt install -y libsgx-launch libsgx-urts
- source /opt/intel/sgxsdk/environment
-
- - name: checkout
- uses: actions/checkout@v3
-
- - name: Get LLVM libraries
- id: retrieve_llvm_libs
- uses: actions/cache@v3
- with:
- path: |
- ./core/deps/llvm/build/bin
- ./core/deps/llvm/build/include
- ./core/deps/llvm/build/lib
- ./core/deps/llvm/build/libexec
- ./core/deps/llvm/build/share
- key: ${{ matrix.llvm_cache_key }}
-
- - name: Quit if cache miss
- if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
- run: echo "::error::can not get prebuilt llvm libraries" && exit 1
-
- - name: Build wamrc
- run: |
- mkdir build && cd build
- cmake ..
- cmake --build . --config Release --parallel 4
- working-directory: wamr-compiler
-
- build_samples_wasm_c_api:
- needs: [build_iwasm]
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- make_options: [
+ iwasm_make_options_run_mode: [
# Running modes supported
+ $AOT_BUILD_OPTIONS,
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
+ $FAST_JIT_BUILD_OPTIONS,
# Running modes unsupported
- #$LLVM_EAGER_JIT_BUILD_OPTIONS,
#$LLVM_LAZY_JIT_BUILD_OPTIONS,
- #$AOT_BUILD_OPTIONS,
+ #$LLVM_EAGER_JIT_BUILD_OPTIONS,
]
os: [ubuntu-20.04]
wasi_sdk_release:
@@ -200,51 +154,15 @@ jobs:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
- steps:
- - name: checkout
- uses: actions/checkout@v3
-
- - name: download and install wabt
- run: |
- cd /opt
- sudo wget ${{ matrix.wabt_release }}
- sudo tar -xzf wabt-1.0.31-*.tar.gz
- sudo mv wabt-1.0.31 wabt
-
- - name: install SGX SDK and necessary libraries
- run: |
- mkdir -p /opt/intel
- cd /opt/intel
- wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin
- chmod +x sgx_linux_x64_sdk_2.15.100.3.bin
- echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin
- echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
- wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
- sudo apt update
- sudo apt install -y libsgx-launch libsgx-urts
- source /opt/intel/sgxsdk/environment
-
- - name: Build Sample [wasm-c-api]
- run: |
- cmake -S . -B build ${{ matrix.make_options }}
- cmake --build build --config Release --parallel 4
- ctest --test-dir build
- working-directory: samples/wasm-c-api
-
- build_samples_others:
- needs: [build_iwasm]
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- os: [ubuntu-20.04]
- wasi_sdk_release:
- [
- "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz",
- ]
- wabt_release:
- [
- "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
+ iwasm_make_options_feature: [
+ # Features to be tested: IPFS
+ "-DWAMR_BUILD_SGX_IPFS=1",
]
+ platform: [linux-sgx]
+ include:
+ - os: ubuntu-20.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
+
steps:
- name: checkout
uses: actions/checkout@v3
@@ -290,76 +208,85 @@ jobs:
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
sudo apt update
sudo apt install -y libsgx-launch libsgx-urts
- source /opt/intel/sgxsdk/environment
-
- - name: Build Sample [basic]
- run: |
- cd samples/basic
- ./build.sh
- ./run.sh
- - name: Build Sample [file]
+ - name: Build iwasm for testing samples
run: |
- cd samples/file
mkdir build && cd build
- cmake ..
+ cmake .. ${{ matrix.iwasm_make_options_run_mode }} ${{ matrix.iwasm_make_options_feature }}
cmake --build . --config Release --parallel 4
- ./src/iwasm -f wasm-app/file.wasm -d .
+ cd ../enclave-sample
+ make
+ working-directory: product-mini/platforms/${{ matrix.platform }}
- - name: Build Sample [multi-thread]
- run: |
- cd samples/multi-thread
- mkdir build && cd build
- cmake ..
- cmake --build . --config Release --parallel 4
- ./iwasm wasm-apps/test.wasm
+ - name: Get LLVM libraries
+ if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS'
+ id: retrieve_llvm_libs
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+ fail-on-cache-miss: true
- - name: Build Sample [multi-module]
+ - name: Build wamrc only for testing samples in aot mode
+ if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS'
run: |
- cd samples/multi-module
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
- ./multi_module
+ cp wamrc `pwd`/../../product-mini/platforms/${{ matrix.platform }}/enclave-sample
+ working-directory: wamr-compiler
- - name: Build Sample [spawn-thread]
+ - name: Build Sample [file]
run: |
- cd samples/spawn-thread
+ cd samples/file
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
- ./spawn_thread
+ cp wasm-app/file.wasm `pwd`/../../../product-mini/platforms/${{ matrix.platform }}/enclave-sample
- - name: Build Sample [ref-types]
+ - name: Test Sample [file] in non-aot mode
+ if: matrix.iwasm_make_options_run_mode != '$AOT_BUILD_OPTIONS'
run: |
- cd samples/ref-types
- mkdir build && cd build
- cmake ..
- cmake --build . --config Release --parallel 4
- ./hello
+ source /opt/intel/sgxsdk/environment
+ ./iwasm --dir=. file.wasm
+ working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample
- - name: Build Sample [wasi-threads]
+ - name: Test Sample [file] in aot mode
+ if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS'
run: |
- cd samples/wasi-threads
- mkdir build && cd build
- cmake -DWASI_SYSROOT=`pwd`/../../../core/deps/wasi-libc/sysroot ..
- cmake --build . --config Release --parallel 4
- ./iwasm wasm-apps/no_pthread.wasm
+ source /opt/intel/sgxsdk/environment
+ ./wamrc -sgx -o file.aot file.wasm
+ ./iwasm --dir=. file.aot
+ working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample
spec_test_default:
- needs: [build_iwasm, build_llvm_libraries, build_wamrc]
+ needs: [build_iwasm, build_llvm_libraries]
runs-on: ubuntu-20.04
strategy:
matrix:
- running_mode: ["classic-interp", "fast-interp", "aot"]
- test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P"]
+ running_mode: ["classic-interp", "fast-interp", "aot", "fast-jit"]
+ test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P", "-x -p -s spec -X -b -P"]
llvm_cache_key: ["${{ needs.build_llvm_libraries.outputs.cache_key }}"]
- # classic-interp and fast-interp don't support simd
exclude:
+ # classic-interp, fast-interp and fast-jit don't support simd
- running_mode: "classic-interp"
test_option: "-x -p -s spec -S -b -P"
- running_mode: "fast-interp"
test_option: "-x -p -s spec -S -b -P"
+ - running_mode: "fast-jit"
+ test_option: "-x -p -s spec -S -b -P"
+ # classic-interp, fast-interp and fast jit don't support XIP
+ - running_mode: "classic-interp"
+ test_option: "-x -p -s spec -X -b -P"
+ - running_mode: "fast-interp"
+ test_option: "-x -p -s spec -X -b -P"
+ - running_mode: "fast-jit"
+ test_option: "-x -p -s spec -X -b -P"
steps:
- name: checkout
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_windows.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_windows.yml
similarity index 50%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_windows.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_windows.yml
index 0d38e8ae554..97a4aaae20e 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_windows.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_windows.yml
@@ -39,6 +39,16 @@ on:
# allow to be triggered manually
workflow_dispatch:
+env:
+ # For Spec Test
+ DEFAULT_TEST_OPTIONS: "-s spec -b"
+ MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M"
+ THREADS_TEST_OPTIONS: "-s spec -b -p"
+ WASI_TEST_OPTIONS: "-s wasi_certification -w"
+ WASI_TEST_FILTER: ${{ github.workspace }}/product-mini/platforms/windows/wasi_filtered_tests.json
+ # Used when building the WASI socket and thread tests
+ CC: ${{ github.workspace }}/wasi-sdk/bin/clang
+
# Cancel any in-flight jobs for the same PR/branch so there's only one active
# at a time
concurrency:
@@ -60,12 +70,14 @@ jobs:
"-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_DEBUG_INTERP=1",
"-DWAMR_BUILD_LIB_PTHREAD=1",
- "-DWAMR_BUILD_LIB_WASI_THREADS=1"
+ "-DWAMR_BUILD_LIB_WASI_THREADS=1",
+ "-DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1"
]
steps:
- uses: actions/checkout@v3
- name: clone uvwasi library
+ if: ${{ !contains(matrix.build_options, '-DWAMR_BUILD_LIBC_UVWASI=0') }}
run: |
cd core/deps
git clone https://github.com/nodejs/uvwasi.git
@@ -75,3 +87,50 @@ jobs:
mkdir build && cd build
cmake .. ${{ matrix.build_options }}
cmake --build . --config Release --parallel 4
+
+ test:
+ runs-on: windows-latest
+ needs: [build]
+ strategy:
+ fail-fast: false
+ matrix:
+ running_mode:
+ [
+ "classic-interp",
+ "fast-interp",
+ ]
+ test_option:
+ [
+ $DEFAULT_TEST_OPTIONS,
+ $MULTI_MODULES_TEST_OPTIONS,
+ $THREADS_TEST_OPTIONS,
+ $WASI_TEST_OPTIONS,
+ ]
+ steps:
+ - name: checkout
+ uses: actions/checkout@v3
+
+ - name: download and install wasi-sdk
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: |
+ curl "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0.m-mingw.tar.gz" -o wasi-sdk.tar.gz -L
+ mkdir wasi-sdk
+ tar -xzf wasi-sdk.tar.gz -C wasi-sdk --strip-components 1
+
+ - name: build socket api tests
+ shell: bash
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: ./build.sh
+ working-directory: ./core/iwasm/libraries/lib-socket/test/
+
+ - name: Build WASI thread tests
+ shell: bash
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: ./build.sh
+ working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/
+
+ - name: run tests
+ shell: bash
+ timeout-minutes: 20
+ run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
+ working-directory: ./tests/wamr-test-suites
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/create_tag.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/create_tag.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/create_tag.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/create_tag.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml
new file mode 100644
index 00000000000..bdabeb6e5d4
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml
@@ -0,0 +1,47 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+name: hadolint dockerfiles
+
+on:
+ # will be triggered on PR events
+ pull_request:
+ types:
+ - opened
+ - synchronize
+ paths:
+ - "**/Dockerfile*"
+ - ".github/workflows/hadolint_dockerfiles.yml"
+ push:
+ branches:
+ - main
+ - "dev/**"
+ paths:
+ - "**/Dockerfile*"
+ - ".github/workflows/hadolint_dockerfiles.yml"
+ # allow to be triggered manually
+ workflow_dispatch:
+
+# Cancel any in-flight jobs for the same PR/branch so there's only one active
+# at a time
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ run-hadolint-on-dockerfiles:
+ runs-on: ubuntu-22.04
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ # on default, hadolint will fail on warnings and errors
+ - name: Run hadolint on dockerfiles
+ run: |
+ docker pull hadolint/hadolint:latest-debian
+ find . -name "*Dockerfile*" | while read dockerfile; do
+ echo "run hadolint on $dockerfile:"
+ docker run --rm -i hadolint/hadolint:latest-debian hadolint - <"$dockerfile"
+ echo "successful"
+ done
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml
similarity index 84%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml
index 2a57f621955..8153cea99f4 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml
@@ -1,43 +1,22 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-name: compilation on android, ubuntu-20.04, ubuntu-22.04
+name: nightly_run
on:
- # will be triggered on PR events
pull_request:
types:
- opened
- synchronize
+ # running nightly pipeline if you're changing it
+ # stress tests are run only in nightly at the moment, so running them in they are changed
paths:
- - ".github/workflows/build_llvm_libraries.yml"
- - ".github/workflows/compilation_on_android_ubuntu.yml"
- - "build-scripts/**"
- - "core/**"
- - "!core/deps/**"
- - "product-mini/**"
- - "samples/**"
- - "!samples/workload/**"
- - "tests/wamr-test-suites/**"
- - "wamr-compiler/**"
- - "wamr-sdk/**"
- # will be triggered on push events
- push:
- branches:
- - main
- - "dev/**"
- paths:
- - ".github/workflows/build_llvm_libraries.yml"
- - ".github/workflows/compilation_on_android_ubuntu.yml"
- - "build-scripts/**"
- - "core/**"
- - "!core/deps/**"
- - "product-mini/**"
- - "samples/**"
- - "!samples/workload/**"
- - "tests/wamr-test-suites/**"
- - "wamr-compiler/**"
- - "wamr-sdk/**"
+ - ".github/workflows/nightly_run.yml"
+ - "core/iwasm/libraries/lib-wasi-threads/stress-test/**"
+
+ # midnight UTC
+ schedule:
+ - cron: "0 0 * * *"
# allow to be triggered manually
workflow_dispatch:
@@ -70,24 +49,23 @@ jobs:
with:
os: "ubuntu-20.04"
arch: "X86"
-
build_llvm_libraries_on_ubuntu_2204:
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
arch: "X86"
-
+
build_wamrc:
needs:
- [build_llvm_libraries_on_ubuntu_2004, build_llvm_libraries_on_ubuntu_2204]
+ [
+ build_llvm_libraries_on_ubuntu_2004,
+ ]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-20.04
- llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
- - os: ubuntu-22.04
- llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v3
@@ -117,17 +95,23 @@ jobs:
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
- build_iwasm_linux_gcc4_8:
- runs-on: ubuntu-latest
- container:
- image: ubuntu:14.04
+ build_iwasm:
+ needs:
+ [
+ build_llvm_libraries_on_ubuntu_2004,
+ ]
+ runs-on: ${{ matrix.os }}
strategy:
matrix:
make_options_run_mode: [
# Running mode
+ $AOT_BUILD_OPTIONS,
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
$FAST_JIT_BUILD_OPTIONS,
+ $LLVM_LAZY_JIT_BUILD_OPTIONS,
+ $LLVM_EAGER_JIT_BUILD_OPTIONS,
+ $MULTI_TIER_JIT_BUILD_OPTIONS,
]
make_options_feature: [
# Features
@@ -147,22 +131,38 @@ jobs:
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
]
+ os: [ubuntu-20.04]
+ platform: [android, linux]
exclude:
# uncompatiable feature and platform
# uncompatiable mode and feature
- # MULTI_MODULE only on INTERP mode
+ # MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
# SIMD only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
# DEBUG_INTERP only on CLASSIC INTERP mode
+ - make_options_run_mode: $AOT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
# DEBUG_AOT only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
@@ -171,45 +171,72 @@ jobs:
# TODO: DEBUG_AOT on JIT
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
# MINI_LOADER only on INTERP mode
+ - make_options_run_mode: $AOT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
+ # Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32)
+ - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
+ platform: android
+ - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
+ platform: android
+ include:
+ - os: ubuntu-20.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
+
steps:
- name: checkout
uses: actions/checkout@v3
- - name: Install dependencies
- run: apt update && apt install -y make g++-4.8 gcc-4.8 wget git
+ # only download llvm cache when needed
+ - name: Get LLVM libraries
+ id: retrieve_llvm_libs
+ if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS')
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
- - name: Install cmake
- run: |
- wget https://github.com/Kitware/CMake/releases/download/v3.26.1/cmake-3.26.1-linux-x86_64.tar.gz -O cmake.tar.gz
- tar xzf cmake.tar.gz
- cp cmake-3.26.1-linux-x86_64/bin/cmake /usr/local/bin
- cp -r cmake-3.26.1-linux-x86_64/share/cmake-3.26/ /usr/local/share/
+ - name: Quit if cache miss
+ if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
+ run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: Build iwasm
run: |
mkdir build && cd build
- cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8
+ cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
cmake --build . --config Release --parallel 4
- working-directory: product-mini/platforms/linux
+ working-directory: product-mini/platforms/${{ matrix.platform }}
- build_iwasm:
- needs:
- [build_llvm_libraries_on_ubuntu_2004, build_llvm_libraries_on_ubuntu_2204]
- runs-on: ${{ matrix.os }}
+ build_iwasm_linux_gcc4_8:
+ runs-on: ubuntu-latest
+ container:
+ image: ubuntu:14.04
strategy:
matrix:
make_options_run_mode: [
# Running mode
- $AOT_BUILD_OPTIONS,
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
$FAST_JIT_BUILD_OPTIONS,
- $LLVM_LAZY_JIT_BUILD_OPTIONS,
- $LLVM_EAGER_JIT_BUILD_OPTIONS,
- $MULTI_TIER_JIT_BUILD_OPTIONS,
]
make_options_feature: [
# Features
@@ -229,40 +256,22 @@ jobs:
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
]
- os: [ubuntu-20.04, ubuntu-22.04]
- platform: [android, linux]
exclude:
# uncompatiable feature and platform
# uncompatiable mode and feature
- # MULTI_MODULE only on INTERP mode
- - make_options_run_mode: $AOT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
+ # MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
# SIMD only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
# DEBUG_INTERP only on CLASSIC INTERP mode
- - make_options_run_mode: $AOT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
# DEBUG_AOT only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
@@ -271,78 +280,46 @@ jobs:
# TODO: DEBUG_AOT on JIT
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
- - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
- - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
- - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
# MINI_LOADER only on INTERP mode
- - make_options_run_mode: $AOT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
- make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- # Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32)
- - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
- platform: android
- - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
- platform: android
- # only test andorid on ubuntu latest
- - os: ubuntu-20.04
- platform: android
- include:
- - os: ubuntu-20.04
- llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
- - os: ubuntu-22.04
- llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v3
- # only download llvm cache when needed
- - name: Get LLVM libraries
- id: retrieve_llvm_libs
- if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS')
- uses: actions/cache@v3
+ - name: Install dependencies
+ uses: nick-fields/retry@v2
with:
- path: |
- ./core/deps/llvm/build/bin
- ./core/deps/llvm/build/include
- ./core/deps/llvm/build/lib
- ./core/deps/llvm/build/libexec
- ./core/deps/llvm/build/share
- key: ${{ matrix.llvm_cache_key }}
-
- - name: Quit if cache miss
- if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
- run: echo "::error::can not get prebuilt llvm libraries" && exit 1
+ timeout_minutes: 10
+ max_attempts: 3
+ command: apt update && apt install -y make g++-4.8 gcc-4.8 wget git
+ on_retry_command: sudo rm -r /var/lib/apt/lists/*
+ - name: Install cmake
+ run: |
+ wget https://github.com/Kitware/CMake/releases/download/v3.26.1/cmake-3.26.1-linux-x86_64.tar.gz -O cmake.tar.gz
+ tar xzf cmake.tar.gz
+ cp cmake-3.26.1-linux-x86_64/bin/cmake /usr/local/bin
+ cp -r cmake-3.26.1-linux-x86_64/share/cmake-3.26/ /usr/local/share/
- name: Build iwasm
run: |
mkdir build && cd build
- cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
+ cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8
cmake --build . --config Release --parallel 4
- working-directory: product-mini/platforms/${{ matrix.platform }}
+ working-directory: product-mini/platforms/linux
build_samples_wasm_c_api:
needs:
[
build_iwasm,
build_llvm_libraries_on_ubuntu_2004,
- build_llvm_libraries_on_ubuntu_2204,
build_wamrc,
]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
- sanitizer: ["", "ubsan"]
+ sanitizer: ["", "ubsan", "asan"]
make_options: [
# Running mode
$AOT_BUILD_OPTIONS,
@@ -353,7 +330,7 @@ jobs:
$LLVM_EAGER_JIT_BUILD_OPTIONS,
$MULTI_TIER_JIT_BUILD_OPTIONS,
]
- os: [ubuntu-20.04, ubuntu-22.04]
+ os: [ubuntu-20.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
@@ -365,9 +342,9 @@ jobs:
include:
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
- - os: ubuntu-22.04
- llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
-
+ exclude:
+ - make_options: $MULTI_TIER_JIT_BUILD_OPTIONS
+ sanitizer: asan
steps:
- name: checkout
uses: actions/checkout@v3
@@ -395,29 +372,33 @@ jobs:
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
-
- name: Build wamrc
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
run: |
mkdir build && cd build
- cmake -DSANITIZER="${{matrix.sanitizer}}" ..
+ cmake -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}" ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
- name: Build Sample [wasm-c-api]
run: |
VERBOSE=1
- cmake -S . -B build ${{ matrix.make_options }} -DSANITIZER="${{matrix.sanitizer}}"
+ cmake -S . -B build ${{ matrix.make_options }} -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}"
cmake --build build --config Release --parallel 4
ctest --test-dir build --output-on-failure
working-directory: samples/wasm-c-api
build_samples_others:
- needs: [build_iwasm]
+ needs:
+ [
+ build_iwasm,
+ build_llvm_libraries_on_ubuntu_2004,
+ build_wamrc,
+ ]
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [ubuntu-20.04, ubuntu-22.04]
+ os: [ubuntu-20.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
@@ -426,6 +407,9 @@ jobs:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
+ include:
+ - os: ubuntu-20.04
+ llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v3
@@ -436,7 +420,6 @@ jobs:
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
-
- name: download and install wabt
run: |
cd /opt
@@ -444,12 +427,30 @@ jobs:
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
+ - name: Get LLVM libraries
+ id: retrieve_llvm_libs
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ matrix.llvm_cache_key }}
+
+ - name: Build wamrc
+ run: |
+ mkdir build && cd build
+ cmake -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}" ..
+ cmake --build . --config Release --parallel 4
+ working-directory: wamr-compiler
+
- name: Build Sample [basic]
run: |
cd samples/basic
./build.sh
./run.sh
-
- name: Build Sample [file]
run: |
cd samples/file
@@ -457,7 +458,6 @@ jobs:
cmake ..
cmake --build . --config Release --parallel 4
./src/iwasm -f wasm-app/file.wasm -d .
-
- name: Build Sample [multi-thread]
run: |
cd samples/multi-thread
@@ -465,15 +465,14 @@ jobs:
cmake ..
cmake --build . --config Release --parallel 4
./iwasm wasm-apps/test.wasm
-
- name: Build Sample [multi-module]
run: |
cd samples/multi-module
mkdir build && cd build
- cmake ..
+ cmake .. -DWAMR_BUILD_AOT=1
cmake --build . --config Release --parallel 4
- ./multi_module
-
+ ./multi_module mC.wasm
+ ./multi_module mC.aot
- name: Build Sample [spawn-thread]
run: |
cd samples/spawn-thread
@@ -481,7 +480,6 @@ jobs:
cmake ..
cmake --build . --config Release --parallel 4
./spawn_thread
-
- name: Build Sample [ref-types]
run: |
cd samples/ref-types
@@ -489,7 +487,6 @@ jobs:
cmake ..
cmake --build . --config Release --parallel 4
./hello
-
- name: Build Sample [simple]
run: |
./build.sh -p host-interp
@@ -505,6 +502,11 @@ jobs:
cmake --build . --config Release --parallel 4
./iwasm wasm-apps/no_pthread.wasm
+ - name: Build Sample [shared-module]
+ run: |
+ cd samples/shared-module
+ ./build.sh
+ ./run.sh
test:
needs:
[
@@ -515,8 +517,10 @@ jobs:
]
runs-on: ${{ matrix.os }}
strategy:
+ fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
+ sanitizer: ["", "ubsan", "asan", "tsan"]
running_mode:
[
"classic-interp",
@@ -545,16 +549,36 @@ jobs:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
ubuntu_version: "22.04"
+
exclude:
# uncompatiable modes and features
+ - os: ubuntu-20.04
+ sanitizer: tsan
+ # asan works only for aot now
+ - running_mode: "classic-interp"
+ sanitizer: asan
+ - running_mode: "fast-interp"
+ sanitizer: asan
+ - running_mode: "jit"
+ sanitizer: asan
+ - running_mode: "fast-jit"
+ sanitizer: asan
+ - running_mode: "multi-tier-jit"
+ sanitizer: asan
+ - running_mode: "classic-interp"
+ sanitizer: tsan
+ - running_mode: "jit"
+ sanitizer: tsan
+ - running_mode: "fast-jit"
+ sanitizer: tsan
+ - running_mode: "multi-tier-jit"
+ sanitizer: tsan
# classic-interp and fast-interp don't support simd
- running_mode: "classic-interp"
test_option: $SIMD_TEST_OPTIONS
- running_mode: "fast-interp"
test_option: $SIMD_TEST_OPTIONS
- # aot and jit don't support multi module
- - running_mode: "aot"
- test_option: $MULTI_MODULES_TEST_OPTIONS
+ # llvm jit doesn't support multi module
- running_mode: "jit"
test_option: $MULTI_MODULES_TEST_OPTIONS
# fast-jit doesn't support multi module, simd
@@ -579,6 +603,15 @@ jobs:
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
+ # It is a temporary solution until new wasi-sdk that includes bug fixes is released
+ - name: build wasi-libc from source
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: |
+ git clone https://github.com/WebAssembly/wasi-libc
+ cd wasi-libc
+ make -j AR=/opt/wasi-sdk/bin/llvm-ar NM=/opt/wasi-sdk/bin/llvm-nm CC=/opt/wasi-sdk/bin/clang THREAD_MODEL=posix
+ echo "SYSROOT_PATH=$PWD/sysroot" >> $GITHUB_ENV
+
- name: set env variable(if llvm are used)
if: matrix.running_mode == 'aot' || matrix.running_mode == 'jit' || matrix.running_mode == 'multi-tier-jit'
run: echo "USE_LLVM=true" >> $GITHUB_ENV
@@ -590,6 +623,10 @@ jobs:
&& matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit'
run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV
+ - name: set additional tsan options
+ run: echo "TSAN_OPTIONS=suppressions=$PWD/tsan_suppressions.txt" >> $GITHUB_ENV
+ working-directory: tests/wamr-test-suites
+
#only download llvm libraries in jit and aot mode
- name: Get LLVM libraries
if: env.USE_LLVM == 'true'
@@ -614,17 +651,22 @@ jobs:
- name: Build WASI thread tests
if: matrix.test_option == '$WASI_TEST_OPTIONS'
- run: bash build.sh
+ run: bash build.sh --sysroot "$SYSROOT_PATH"
working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/
+ - name: Build WASI thread stress tests
+ if: matrix.test_option == '$WASI_TEST_OPTIONS'
+ run: bash build.sh --sysroot "$SYSROOT_PATH"
+ working-directory: ./core/iwasm/libraries/lib-wasi-threads/stress-test/
+
- name: build socket api tests
if: matrix.test_option == '$WASI_TEST_OPTIONS'
run: bash build.sh
working-directory: ./core/iwasm/libraries/lib-socket/test/
- name: run tests
- timeout-minutes: 10
- run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
+ timeout-minutes: 40
+ run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} -T %{{matrix.sanitizer}}
working-directory: ./tests/wamr-test-suites
#only install x32 support libraries when to run x86_32 cases
@@ -639,7 +681,7 @@ jobs:
sudo apt install -y g++-multilib lib32gcc-9-dev
- name: run tests x86_32
- timeout-minutes: 10
+ timeout-minutes: 40
if: env.TEST_ON_X86_32 == 'true'
run: ./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
working-directory: ./tests/wamr-test-suites
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/release_process.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/release_process.yml
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/release_process.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/release_process.yml
index 4188b4d40ad..ef722acdb1f 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/release_process.yml
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/release_process.yml
@@ -56,21 +56,21 @@ jobs:
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-20.04"
- arch: "X86"
+ arch: "AArch64 ARM Mips RISCV X86"
build_llvm_libraries_on_ubuntu_2204:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
- arch: "X86"
+ arch: "AArch64 ARM Mips RISCV X86"
build_llvm_libraries_on_macos:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "macos-latest"
- arch: "X86"
+ arch: "AArch64 ARM Mips RISCV X86"
#
# WAMRC
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/reuse_latest_release_binaries.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/reuse_latest_release_binaries.yml
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/reuse_latest_release_binaries.yml
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/reuse_latest_release_binaries.yml
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml
new file mode 100644
index 00000000000..48fff2d23c0
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml
@@ -0,0 +1,211 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+name: spec test on nuttx
+
+on:
+ pull_request:
+ types:
+ - closed
+ branches:
+ - main
+
+ schedule:
+ - cron: '0 0 * * *'
+
+ workflow_dispatch:
+
+env:
+ LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex"
+ WASI_SDK_PATH: "/opt/wasi-sdk"
+ WAMR_COMMON_OPTION:
+ "CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_STACKSIZE=32768\\nCONFIG_INTERPRETERS_WAMR_LOG=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\nCONFIG_INTERPRETERS_WAMR_REF_TYPES=y\\nCONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST=y\\nCONFIG_INTERPRETERS_WAMR_SHARED_MEMORY=y\\nCONFIG_INTERPRETERS_WAMR_BULK_MEMORY=y\\nCONFIG_EOL_IS_LF=y\\nCONFIG_ARM_SEMIHOSTING_HOSTFS=y\\nCONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y\\nCONFIG_RISCV_SEMIHOSTING_HOSTFS=y\\nCONFIG_FS_HOSTFS=y\\nCONFIG_LIBC_FLOATINGPOINT=y\\n"
+
+jobs:
+ build_llvm_libraries:
+ uses: ./.github/workflows/build_llvm_libraries.yml
+ with:
+ os: "ubuntu-22.04"
+ arch: "ARM RISCV AArch64"
+
+ spec_test_on_qemu:
+ runs-on: ubuntu-22.04
+ needs: [build_llvm_libraries]
+ strategy:
+ matrix:
+ target_config: [
+ # {
+ # config: "boards/arm64/qemu/qemu-armv8a/configs/nsh",
+ # target: "aarch64_vfp",
+ # fpu_type: "fp"
+ # },
+ # {
+ # config: "boards/arm/imx6/sabre-6quad/configs/nsh",
+ # target: "thumbv7",
+ # fpu_type: "none"
+ # },
+ {
+ config: "boards/arm/imx6/sabre-6quad/configs/nsh",
+ target: "thumbv7_vfp",
+ fpu_type: "dp"
+ },
+ {
+ config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
+ target: "riscv32",
+ fpu_type: "none"
+ },
+ # {
+ # config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
+ # target: "riscv32_ilp32d",
+ # fpu_type: "dp"
+ # },
+ {
+ config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64",
+ target: "riscv64",
+ fpu_type: "none"
+ },
+ ]
+
+ wamr_test_option: [
+ {
+ mode: "-t aot",
+ option: "CONFIG_INTERPRETERS_WAMR_AOT=y\\n"
+ },
+ {
+ mode: "-t aot -X",
+ option: "CONFIG_INTERPRETERS_WAMR_AOT=y\\n"
+ },
+ {
+ mode: "-t classic-interp",
+ option: "CONFIG_INTERPRETERS_WAMR_CLASSIC=y\\n"
+ },
+ {
+ mode: "-t fast-interp",
+ option: "CONFIG_INTERPRETERS_WAMR_FAST=y\\n"
+ },
+ ]
+
+ exclude:
+ # XIP is not fully supported yet on RISCV64, some relocations can not be resolved
+ - target_config: { config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64" }
+ wamr_test_option: { mode: "-t aot -X" }
+
+ steps:
+ - name: Install Utilities
+ run: |
+ sudo apt install -y kconfig-frontends-nox genromfs
+
+ - name: Install ARM Compilers
+ if: startsWith(matrix.target_config.config, 'boards/arm')
+ run: |
+ sudo apt install -y gcc-arm-none-eabi
+ wget --quiet https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar.xz
+ xz -d gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar.xz
+ tar xf gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar
+ echo "$PWD/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf/bin" >> $GITHUB_PATH
+
+ - name: Install RISC-V Compilers
+ if: startsWith(matrix.target_config.config, 'boards/risc-v')
+ run: |
+ curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.tar.gz > riscv.tar.gz
+ tar xvf riscv.tar.gz
+ echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH
+
+ - name: Install WASI-SDK
+ run: |
+ curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz > wasi-sdk.tar.gz
+ tar xvf wasi-sdk.tar.gz
+ sudo mv wasi-sdk-* /opt/wasi-sdk
+
+ - name: Checkout NuttX
+ uses: actions/checkout@v3
+ with:
+ repository: apache/incubator-nuttx
+ ref: releases/12.3
+ path: nuttx
+
+ - name: Checkout NuttX Apps
+ uses: actions/checkout@v3
+ with:
+ repository: apache/incubator-nuttx-apps
+ ref: releases/12.3
+ path: apps
+
+ - name: Checkout WAMR
+ uses: actions/checkout@v3
+ with:
+ repository: ${{ github.repository }}
+ path: apps/interpreters/wamr/wamr
+
+ - name: Get LLVM libraries
+ if: contains(matrix.wamr_test_option.mode, 'aot')
+ id: retrieve_llvm_libs
+ uses: actions/cache@v3
+ with:
+ path: |
+ ./core/deps/llvm/build/bin
+ ./core/deps/llvm/build/include
+ ./core/deps/llvm/build/lib
+ ./core/deps/llvm/build/libexec
+ ./core/deps/llvm/build/share
+ key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
+
+ - name: Quit if cache miss
+ if: contains(matrix.wamr_test_option.mode, 'aot') && steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
+ run: echo "::error::can not get prebuilt llvm libraries" && exit 1
+
+ - name: Copy LLVM
+ if: contains(matrix.wamr_test_option.mode, 'aot')
+ run: cp -r core/deps/llvm apps/interpreters/wamr/wamr/core/deps/llvm
+
+ - name: Enable WAMR for NuttX
+ run: |
+ find nuttx/boards -name defconfig | xargs sed -i '$a\${{ env.WAMR_COMMON_OPTION }}'
+
+ - name: Enable WAMR Interpreter for NuttX
+ run: |
+ find nuttx/boards -name defconfig | xargs sed -i '$a\${{ matrix.wamr_test_option.option }}'
+
+ - name: Disable FPU for NuttX
+ if: matrix.target_config.fpu_type == 'none'
+ run: |
+ find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_FPU is not set\n'
+
+ - name: Disable DPFPU for NuttX
+ if: matrix.target_config.fpu_type == 'fp'
+ run: |
+ find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_DPFPU is not set\n'
+
+ - name: Build wamrc
+ if: contains(matrix.wamr_test_option.mode, 'aot')
+ working-directory: apps/interpreters/wamr/wamr/wamr-compiler
+ run: |
+ cmake -Bbuild .
+ cmake --build build
+
+ - name: Build
+ id: build_firmware
+ run: |
+ cd nuttx
+ tools/configure.sh ${{ matrix.target_config.config }}
+ make -j$(nproc)
+ echo "firmware=$PWD/nuttx" >> $GITHUB_OUTPUT
+
+ - name: Install QEMU for ARM
+ if: startsWith(matrix.target_config.config, 'boards/arm')
+ run: |
+ curl -L https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz > xpack-qemu-arm.tar.gz
+ tar xvf xpack-qemu-arm.tar.gz
+ echo $PWD/xpack-qemu-arm-7.1.0-1/bin >> $GITHUB_PATH
+
+ - name: Install QEMU for RISC-V
+ if: startsWith(matrix.target_config.config, 'boards/risc-v')
+ run: |
+ curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz
+ tar xvf xpack-qemu-riscv.tar.gz
+ echo PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin >> $GITHUB_PATH
+
+ - name: Test
+ run: |
+ cd apps/interpreters/wamr/wamr/tests/wamr-test-suites
+ ./test_wamr.sh -s spec ${{ matrix.wamr_test_option.mode }} -m ${{ matrix.target_config.target }} -b -Q -P -F ${{ steps.build_firmware.outputs.firmware }}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/.gitignore
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/.gitignore
rename to lib/wasm-micro-runtime-WAMR-1.3.0/.gitignore
index a4889fb7f5f..99f1a502e45 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/.gitignore
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.gitignore
@@ -1,4 +1,5 @@
.cache
+.clangd
.vs
.vscode
.venv
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ATTRIBUTIONS.md b/lib/wasm-micro-runtime-WAMR-1.3.0/ATTRIBUTIONS.md
similarity index 92%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/ATTRIBUTIONS.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/ATTRIBUTIONS.md
index 0cf62f499e1..c772b96911d 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/ATTRIBUTIONS.md
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ATTRIBUTIONS.md
@@ -16,12 +16,13 @@ WAMR project reused some components from other open source project:
- **asmjit**: for the Fast JIT x86-64 codegen implementation
- **zydis**: for the Fast JIT x86-64 codegen implementation
- **NuttX ELF headers**: used in core/iwasm/aot/debug/elf_parser.c
+- **Dhrystone**: for the test benchmakr dhrystone
The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.
| third party components | version number | latest release | vendor pages | CVE details |
| --- | --- | --- | --- | --- |
-| cjson | 1.7.10 | 1.7.14 | https://github.com/DaveGamble/cJSON | https://www.cvedetails.com/vendor/19164/Cjson-Project.html |
+| cjson | 1.7.16 | 1.7.16 | https://github.com/DaveGamble/cJSON | https://www.cvedetails.com/vendor/19164/Cjson-Project.html |
| contiki-ng (er-coap) | unspecified | 3.0 | https://github.com/contiki-os/contiki | https://www.cvedetails.com/vendor/16528/Contiki-os.html |
| freebsd libm | unspecified | 13.0 | https://www.freebsd.org/ | https://www.cvedetails.com/vendor/6/Freebsd.html |
| LVGL | 6.0.1 | 7.11.0 | https://lvgl.io/ | |
@@ -30,11 +31,12 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
| wasmtime | unspecified | v0.26.0 | https://github.com/bytecodealliance/wasmtime | |
| zephyr | unspecified | v2.5.0 | https://www.zephyrproject.org/ | https://www.cvedetails.com/vendor/19255/Zephyrproject.html |
| WebAssembly debugging patch for LLDB | unspecified | unspecified | https://reviews.llvm.org/D78801 | |
-| libuv | v1.42.0 | v1.44.1 | https://github.com/libuv/libuv | https://www.cvedetails.com/vendor/15402/Libuv-Project.html |
+| libuv | v1.46.0 | v1.46.0 | https://github.com/libuv/libuv | https://www.cvedetails.com/vendor/15402/Libuv-Project.html |
| uvwasi | unspecified | v0.0.12 | https://github.com/nodejs/uvwasi | |
| asmjit | unspecified | unspecified | https://github.com/asmjit/asmjit | |
| zydis | unspecified | e14a07895136182a5b53e181eec3b1c6e0b434de | https://github.com/zyantific/zydis | |
| NuttX ELF headers | 72313301e23f9c2de969fb64b9a0f67bb4c284df | 10.3.0 | https://github.com/apache/incubator-nuttx | |
+| Dhrystone | 2.1 | 2.1 | https://fossies.org/linux/privat/old/ | |
## Licenses
@@ -81,15 +83,19 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
[LICENSE](./tests/wamr-test-suites/spec-test-script/LICENSE)
### libuv
+
[LICENSE](./core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV)
### uvwasi
+
[LICENSE](./core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI)
### asmjit
+
[LICENSE](./core/iwasm/fast-jit/cg/LICENSE_ASMJIT)
### zydis
+
[LICENSE](./core/iwasm/fast-jit/cg/LICENSE_ZYDIS)
### NuttX ELF headers
@@ -97,3 +103,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
[LICENSE](./core/iwasm/aot/debug/LICENSE_NUTTX)
[NOTICE](./core/iwasm/aot/debug/NOTICE_NUTTX)
+
+### Dhrystone
+
+[LICENSE](./tests/benchmarks/dhrystone/LICENSE)
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/CMakeLists.txt
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/CMakeLists.txt
rename to lib/wasm-micro-runtime-WAMR-1.3.0/CMakeLists.txt
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/CODE_OF_CONDUCT.md b/lib/wasm-micro-runtime-WAMR-1.3.0/CODE_OF_CONDUCT.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/CODE_OF_CONDUCT.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/CODE_OF_CONDUCT.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/CONTRIBUTING.md b/lib/wasm-micro-runtime-WAMR-1.3.0/CONTRIBUTING.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/CONTRIBUTING.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/CONTRIBUTING.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/LICENSE
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/LICENSE
rename to lib/wasm-micro-runtime-WAMR-1.3.0/LICENSE
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ORG_CODE_OF_CONDUCT.md b/lib/wasm-micro-runtime-WAMR-1.3.0/ORG_CODE_OF_CONDUCT.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/ORG_CODE_OF_CONDUCT.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/ORG_CODE_OF_CONDUCT.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/README.md
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/README.md
index 8cbdcf49592..dfdae2da894 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/README.md
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/README.md
@@ -77,6 +77,7 @@ The following platforms are supported, click each link below for how to build iw
- [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 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
- [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
@@ -91,8 +92,10 @@ The current TSC members:
- [lum1n0us](https://github.com/lum1n0us) - **Liang He**,
- [no1wudi](https://github.com/no1wudi) **Qi Huang**,
- [qinxk-inter](https://github.com/qinxk-inter) - **Xiaokang Qin**,
+- [ttrenner ](https://github.com/ttrenner) - **Trenner, Thomas**,
- [wei-tang](https://github.com/wei-tang) - **Wei Tang**,
- [wenyongh](https://github.com/wenyongh) - **Wenyong Huang**,
+- [woodsmc](https://github.com/woodsmc) - **Woods, Chris**,
- [xujuntwt95329](https://github.com/xujuntwt95329) - **Jun Xu**,
- [xwang98](https://github.com/xwang98) - **Xin Wang**, (chair)
- [yamt](https://github.com/yamt) - **Takashi Yamamoto**,
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/RELEASE_NOTES.md b/lib/wasm-micro-runtime-WAMR-1.3.0/RELEASE_NOTES.md
similarity index 52%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/RELEASE_NOTES.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/RELEASE_NOTES.md
index d6308ce671e..fbb97f5d756 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/RELEASE_NOTES.md
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/RELEASE_NOTES.md
@@ -1,3 +1,308 @@
+## WAMR-1.3.0
+
+### Breaking Changes
+- Abstract POSIX filesystem functions (#2585)
+ - Change API wasm_runtime_set_wasi_args_ex's arguments
+ `int stdinfd/stdoutfd/stderrfd` to `int64_t stdinfd/stdoutfd/stderrfd`
+- core/iwasm: Support mapped file system access on non-libuv WASI (#2628)
+ - Enable mapping host directories to guest directories by parsing
+ the `map_dir_list` argument in API `wasm_runtime_init_wasi` for libc-wasi
+- Support muti-module for AOT mode (#2482)
+ - Add argument `package_type_t module_type` for module_reader callback
+- Generate jitdump to support linux perf for LLVM JIT (#2788)
+ - Add a field `bool linux_perf_support` in RuntimeInitArgs
+- Remove provision of unnecessary fd rights (#2579)
+- libc-wasi: Conditionally support SYNC flags (#2581)
+
+### New Features
+- Support muti-module for AOT mode (#2482)
+- Implement libc-wasi for Windows platform (#2740)
+- Implement module instance context APIs (#2436)
+- Implement async termination of blocking thread (#2516)
+- Generate jitdump to support linux perf for LLVM JIT (#2788)
+- Add Cosmopolitan Libc Platform (#2598)
+
+### Bug Fixes
+- sgx-ra: Disable the building of samples (#2507)
+- Handle a return from wasi _start function correctly (#2529)
+- fd_object_release: Preserve errno (#2535)
+- Fix build error with ancient GCC (4.8) (#2553)
+- Fix compiling error for RT-Thread (#2569)
+- Fix potential unaligned store issue when extra return value is v128 (#2583)
+- Fix loader push_pop_frame_ref_offset (#2590)
+- Fix compilation error on Android platform (#2594)
+- Ignore handling SIG_DFL/SIG_IGN for previous sig action (#2589)
+- Fix nightly run sanitizer error in Fast JIT (#2601)
+- Check ValueKind before extracting a constant int value (#2595)
+- Patch implementations of vfbinop(min,max,pmin,pax) (#2584)
+- Improve stack trace dump and fix coding guideline CI (#2599)
+- aot_resolve_stack_sizes: Disable the size check for now (#2608)
+- Remove module instance from hashmap in wasi_nn_destroy (#2613)
+- Fix label index out-of-range references in op_br_table_cache (#2615)
+- Fix compilation of shift opcodes on x86_64 and i386 architectures (#2619)
+- Fix potential issue in aot compiler when translating block opcodes (#2622)
+- Use another default pipeline when opt-level is 0 (#2624)
+- Fix AOT shift operations for indirect constants (#2627)
+- Fix fast-interp "pre-compiled label offset out of range" issue (#2659)
+- Revert "Strip static and shared libraries of iwasm to reduce the binary size (#2431)" (#2669)
+- Fix windows compilation on C++20 (#2670)
+- Fix fast-jit f32/f64 truncate to i32/i64 (#2671)
+- Fix use getrandom on cosmopolitan libc (#2674)
+- Fix repeatedly initialize shared memory data and protect the memory's fields (#2673)
+- Minor fixes for Go bindings (#2676)
+- Fix issues reported by Coverity (#2681)
+- Add more buffer boundary checks in wasm loader (#2734)
+- Grab cluster->lock when modifying exec_env->module_inst (#2685)
+- Fix CMSIS import with Zephyr 3.4+ (#2744)
+- Fix log messages in Zephyr example (#2761)
+- Fix fast-jit callnative translation (#2765)
+- aot compiler: Disable musttail for thumb (#2771)
+- Fix data/elem drop (#2747)
+- Fix formatting in aot_dump_perf_profiling (#2796)
+- Fix formatting in wasm_dump_perf_profiling (#2799)
+- Fix memory.init opcode issue in fast-interp (#2798)
+- aot compiler: Fix handle next reachable if block (#2793)
+- Fix configurable bounds checks typo (#2809)
+- Attestation: Free JSON from the Wasm module heap (#2803)
+- Update Zephyr support to v3.5.0 and make instructions generic to boards (#2805)
+- Return error when shutdown() fails (#2801)
+- iwasm: Print help when meeting unknown cmd options (#2824)
+- Fix fast-jit accessing shared memory's fields issue (#2841)
+- Fix wasm loader handle op_br_table and op_drop (#2864)
+- Fix block with type issue in fast interp (#2866)
+- Fix float argument handling for riscv32 ilp32d (#2871)
+- Portably handle fd_advise on directory fd (#2875)
+- Fix sample basic intToStr was called with wrong length (#2876)
+
+### Enhancements
+- Implement strict validation of thread IDs according to the specification (#2521)
+- Stop abusing shared memory lock to protect exception (#2509)
+- Implement os_usleep for posix (#2517)
+- set_exception_visitor: Remove the special case for wasi proc exit (#2525)
+- Revert "Return error when exception was raised after main thread finishes" (#2524)
+- libc-wasi: Remove unused code (#2528)
+- Add callback to handle memory.grow failures (#2522)
+- Add context to enlarge memory error callback (#2546)
+- Add ARM aeabi symbol for clearing memory content in a specific range (#2531)
+- Unifdef -U WASMTIME_SSP_STATIC_CURFDS (#2533)
+- Fix typo for IP address buffer (#2532)
+- Add an API to terminate instance (#2538)
+- Add user to enlarge memory error callback (#2546)
+- runtest.py: Show accurate case amount in summary (#2549)
+- Allow using custom signal handler from non-main thread (#2551)
+- Return __WASI_EINVAL from fd_prestat_dir_name (#2580)
+- Support AOT compiler with LLVM 17 (#2567)
+- Add support for closing/renumbering preopen fds (#2578)
+- Enable AOT usage on M1 mac (#2618)
+- core/iwasm: Support mapped file system access on non-libuv WASI (#2628)
+- Enable MASM automatically in runtime_lib.cmake (#2634)
+- Abstract POSIX filesystem functions (#2585)
+- Implement wasi clock_time/clock_res get (#2637)
+- Fix several typo/warning/unused-code issues (#2655)
+- Partial windows filesystem implementation (#2657)
+- Apply no_sanitize_address for clang compiler in several places (#2663)
+- Refactor clock functions to use WASI types (#2666)
+- Refine lock/unlock shared memory (#2682)
+- Fix several AOT compiler issues (#2697)
+- Fix AOT compiler simd shift opcodes (#2715)
+- Fix invalid use of jit_reg_is_const_val in fast-jit (#2718)
+- Use user defined malloc/free functions for user defined memory allocator (#2717)
+- Move WASI types into separate header (#2724)
+- Provide default vprintf on UWP (#2725)
+- Fix typo in Zephyr simple example (#2738)
+- Fix switch-case fallthrough compilation warning (#2753)
+- Add eabihf ABI support and set vendor-sys of bare-metal targets (#2745)
+- Return uint32 from WASI functions (#2749)
+- Add compilation flag to enable/disable heap corruption check (#2766)
+- Extend os_mmap to support map file from fd (#2763)
+- Fix printing ref.extern addresses in wasm_application.c (#2774)
+- Remove unused JitBitmap (#2775)
+- Use next generation crypto API on Windows (#2769)
+- More precise help info of enabled targets for wamrc (#2783)
+- Refine atomic operation flags in bh_atomic.h (#2780)
+- Fix comment in WAMR_MEM_DUAL_BUS_MIRROR (#2791)
+- Fix return type in wasm_loader_get_custom_section (#2794)
+- Add support for custom sections in nuttx (#2795)
+- Change is_shared_memory type from bool to uint8 (#2800)
+- Fix typos in zephyr platform struct descriptions (#2818)
+- Access linear memory size atomically (#2834)
+- Output warning and quit if import/export name contains '\00' (#2806)
+- Use wasm_config_t to pass private configuration to wasm_engine_new (#2837)
+- core/iwasm/interpreter/wasm_loader.c: remove an extra validation (#2845)
+- Don't add "+d" to riscv cpu features if already given (#2855)
+- Fix compilation warnings on Windows (#2868)
+
+### Others
+- Add mutex stress test (#2472)
+- Add unit tests for the tid allocator (#2519)
+- Add support for running tests on apple M1 macs (#2554)
+- export_native_api.md: Add a note about thread termination (#2572)
+- test_wamr.sh: Print a bit more meaningful message (#2574)
+- run_wasi_tests.sh: Provide stdin by ourselves (#2576)
+- Fix a few issues in "run_wasi_tests.sh: provide stdin by ourselves" (#2582)
+- Fix compile error of tsf benchmark (#2588)
+- test_wamr.sh: Bump wasi-testsuite version (#2568)
+- samples/inst-context-threads: Add a brief explanation (#2592)
+- doc/memory_tune.md: "remove malloc" hack is not relevant to wasi-threads (#2603)
+- Refactor stress tests to make them runnable in reactor mode (#2614)
+- Run rust tests from wasi-testsuite (#2484)
+- spec-test-script: Fix NaN comparision between v128 values (#2605)
+- CI: Enable testing AOT multi-module feature (#2621)
+- Vote for nomination of Woods, Chris and Trenner, Thomas as TSC members (#2638)
+- Add tsan for fast interp and aot (#2679)
+- Enable WASI tests on Windows CI (#2699)
+- docs: Fix typo in export native APIs doc (#2750)
+- Update RISC-V compilers in Nuttx compilation CI and spec test CI (#2756)
+- Enable more LLVM backends for the release wamrc binary (#2778)
+- Disable FPU in NuttX spec test (#2781)
+- Fix broken links in app-mgr README.md (#2786)
+- Fix build error of libsodium benchmark (#2792)
+- Fix wamr-test-suites script for macos (#2819)
+- Run spec test for classic/fast-interp in NuttX CI (#2817)
+- test_wamr.sh: Don't bother to build shared library (#2844)
+- doc/build_wamr.md: Fix links to RISC-V named ABIs (#2852)
+- Fix typos of CIDR in docs and help text (#2851)
+- Enable spectest on riscv64 (#2843)
+- Update FPU configuration in spec_test_on_nuttx.yml (#2856)
+
+---
+
+## WAMR-1.2.3
+
+### Breaking Changes
+- Increase default native stack size (#2332)
+
+### New Features
+- Implement the segue optimization for LLVM AOT/JIT (#2230)
+- Implement AOT static PGO (#2243)
+- Enable static PGO for Linux SGX (#2270)
+- Add Rust Formatters to Debugger (Vector, Map etc.) (#2219)
+
+### Bug Fixes
+- The Python language-binding needs python>=3.9 (#2228)
+- aot_compile_op_call: Remove a wrong optimization (#2233)
+- Fix typo in samples/ref-types (#2236)
+- Update thread proposal ignore cases (#2246)
+- Disable writting GS register on linux-sgx platform (#2255)
+- Fix compile error of wamrc with llvm-13/llvm-14 (#2261)
+- aot/jit: Set module layout (#2260)
+- Fix build error with LLVM 16 (#2259)
+- spec-test-script: Disable conversions.wast on i386 (#2269)
+- Fix a heap corruption bug in ems realloc (#2279)
+- Fix fast-interp issue of LAST_OP_OUTPUT_I32/64 check (#2295)
+- Fix wamrc build issues with LLVM 13 and LLVM 16 (#2313)
+- aot: Move stack_sizes table to a dedicated section (#2317)
+- product-mini/platforms/linux: Mark vmlib POSITION_INDEPENDENT_CODE (#2323)
+- aot: Avoid possible relocations around "stack_sizes" for XIP mode (#2322)
+- Avoid switch lowering to lookup tables for XIP (#2339)
+- Fix typo in zephyr's Dockerfile.old (#2354)
+- Fix typo (dwarf) in the codebase (#2367)
+- Implement suspend flags as atomic variable (#2361)
+- Fix llvm jit failed to lookup aot_stack_sizes symbol issue (#2384)
+- Fix some check issues on table operations (#2392)
+- Fix ExpandMemoryOpPass doesn't work properly (#2399)
+- Fix non-builtin BH_ATOMIC_32_FETCH_OR and BH_ATOMIC_32_FETCH_AND (#2400)
+- Fix wasi-sockets tests (#2389)
+- Fix result arity check on select_t opcode (#2406)
+- Re-organize intrinsics in aot_reloc_riscv.c to fix some FPU issues (#2414)
+- Fix lib-pthread issues (#2410)
+- Fix typo in test_wamr.sh (#2421)
+- Fix memory sharing (#2415)
+- wasm_export.h: Fix struct wasm_val_t (#2435)
+- Fix typos in wamrc print_help() (#2442)
+- iwasm: Fix native lib cleanup after error occurs (#2443)
+- Correct --heap-size option in messages (#2458)
+- wasm_instantiate: Fix a potential integer overflow issue (#2459)
+- Fix windows link error and clear windows warnings (#2463)
+- aot: Disable musttail for mips (#2457)
+- Fix opcode overwrite issue in fast interp (#2476)
+- wamrc: Fix windows relocation to `aot_func_internal#n` (#2474)
+- Fix windows AOT hw bound check (#2475)
+- Fix typo in aot_emit_aot_file.c (#2478)
+
+### Enhancements
+- A few changes related to WAMRC_LLC_COMPILER (#2218)
+- Enhance linux-sgx CI (#2102)
+- Add asan and ubsan to WAMR CI (#2161)
+- Update doc on WAMR_DISABLE_HW_BOUND_CHECK 32-bit (#2262)
+- wamrc: Add an incompatibility note in the help message (#2276)
+- Add cmake variable to disable writing gs register (#2284)
+- Make hmu_tree_node 4 byte aligned to reduce compiler warning (#2268)
+- Appease unused warning on min_uint64 (#2277)
+- Fix format warning by PRIu32 in [wasm|aot] dump call stack (#2251)
+- Fix a compile warning due to missing include (#2293)
+- Fix dockerfile linter warnings (#2291)
+- Enable windows x86-32 AOT relocations (#2285)
+- wamr-ide: Add vscode extension tests (#2292)
+- AOT/JIT native stack bound check improvement (#2244)
+- Add retries to flaky step in nightly run CI (#2306)
+- Use system libuv if available (#1861)
+- wasi-nn: Simplify cmake and headers' location (#2308)
+- wasi-nn: Improve tests paths for local dev (#2309)
+- aot: Implement a few more relocation types for riscv (#2318)
+- wasi-nn: Add support of wasi-nn as shared lib (#2310)
+- Add a few more assertions on structures to which aot abi is sensitive (#2326)
+- Fix sanitizer errors in posix socket (#2331)
+- Add "--xip" option for wamrc (#2336)
+- Add "--enable-llvm-passes=" option to wamrc (#2335)
+- Make memory access boundary check behavior configurable (#2289)
+- Migrate ExpandMemoryOpPass to llvm new pass manager (#2334)
+- Allow defining hints without exact socket type or address family (#2337)
+- wamrc: Warn on text relocations for XIP (#2340)
+- Add scripts to validate lldb source debugger (#2150)
+- Add docker file to fix Zephy ESP32 linking issue (#2314)
+- Add "--native-lib=" option to wamrc (#2342)
+- Fix unused warnings on disable_bounds_checks (#2347)
+- Add "--enable-builtin-intrinsics=" option to wamrc (#2341)
+- nuttx: Add a kconfig for wasi-threads (#2343)
+- iwasm: Disable app heap by default if wasi is enabled (#2346)
+- Fix some static scan issues (#2362)
+- Bring up WAMR on esp32-s3 device (#2348)
+- ESP-IDF platform supports to load AOT to PSRAM and run it (#2385)
+- Add hadolint CI for Dockerfile linting (#2387)
+- Move generic parts of wasm_suspend_flags.h to bh_atomic.h (#2393)
+- bh_atomic.h: Add comments (#2398)
+- bh_atomic.h: Add BH_ATOMIC_32_FETCH_ADD/BH_ATOMIC_32_FETCH_SUB (#2408)
+- Update libuv version to v1.46.0 (#2405)
+- Remove a few unused functions (#2409)
+- Add initial stress test (#2364)
+- Move wasm_runtime_destroy_wasi and wasi_nn_destroy calls together (#2418)
+- embed_wamr.md: Improvements about threads (#2420)
+- Add runtime inited checks in Enclave command handlings to improve security (#2416)
+- Add some relocation symbols for xtensa target (#2422)
+- Remove unnecessary and extra zero length check in mem functions' macro (#2428)
+- Introduce WASMModuleInstanceExtraCommon (#2429)
+- Strip static and shared libraries of iwasm to reduce the binary size (#2431)
+- Auto-check wrgsbase in cmake script (#2437)
+- iwasm: call native lib init/deinit if exists (#2439)
+- wasi-nn: Support uint8 quantized networks (#2433)
+- Implement `wasm_externref_objdel` and `wasm_externref_set_cleanup` (#2455)
+- wasi-nn: Improve TPU support (#2447)
+- wamr-python: Enable debugging WASM and grant dir access (#2449)
+- Build wasi-libc from source in WAMR CI (#2465)
+- wamrc: More friendly to print help info (#2451)
+- Add another wamr test (#2411)
+- Fix issues reported by Coverity and clear windows warnings (#2467)
+- Clone the input binary during wasm_module_validate (#2483)
+
+### Others
+- Nuttx CI: Ignore the expired certificate for riscv gcc toolchain (#2222)
+- core/iwasm/compilation: constify a bit (#2223)
+- Bump requests from 2.28.2 to 2.31.0 in /build-scripts (#2229)
+- dwarf_extractor: Constify a bit (#2278)
+- AOTFuncContext: Remove a stale comment (#2283)
+- Add performance tunning document (#2286)
+- Reduce CI jobs number (#2296)
+- CI: Update used node version to 16 (#2303)
+- Update Docker image for latest version of external libraries & tools (#2374)
+- Upgrade cJSON version to v1.7.16 (#2404)
+- Upgrade XNNPACK workload (#2394)
+- Build more benchmarks in workload XNNPACK (#2417)
+- Upgrade SGX-RA integration for 0.1.2 and Ubuntu 20.04 (#2454)
+- Add sample pre-commit hook (#2470)
+
+---
+
## WAMR-1.2.2
### Breaking Changes
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/SECURITY.md b/lib/wasm-micro-runtime-WAMR-1.3.0/SECURITY.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/SECURITY.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/SECURITY.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/TSC_Charter.md b/lib/wasm-micro-runtime-WAMR-1.3.0/TSC_Charter.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/TSC_Charter.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/TSC_Charter.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/.gitignore
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/.gitignore
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/.gitignore
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package-lock.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package-lock.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package-lock.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package-lock.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_publisher.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_publisher.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_subscriber.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_subscriber.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_handler.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_handler.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_sender.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_sender.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/timer.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/timer.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/tsconfig.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/tsconfig.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/console.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/console.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/console.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/console.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/request.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/request.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/request.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/request.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/timer.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/timer.ts
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/timer.ts
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/timer.ts
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/tsconfig.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/tsconfig.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/tsconfig.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/tsconfig.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript_config b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript_config
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript_config
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript_config
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/build_llvm.py b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/build_llvm.py
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/build_llvm.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/build_llvm.py
index 3957f4b8950..e5036e5cae8 100755
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/build_llvm.py
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/build_llvm.py
@@ -55,22 +55,26 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
"-DLLVM_APPEND_VC_REV:BOOL=ON",
"-DLLVM_BUILD_EXAMPLES:BOOL=OFF",
"-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF",
- "-DLLVM_BUILD_TESTS:BOOL=OFF",
- "-DLLVM_CCACHE_BUILD:BOOL=ON",
"-DLLVM_ENABLE_BINDINGS:BOOL=OFF",
"-DLLVM_ENABLE_IDE:BOOL=OFF",
"-DLLVM_ENABLE_LIBEDIT=OFF",
"-DLLVM_ENABLE_TERMINFO:BOOL=OFF",
- "-DLLVM_ENABLE_ZLIB:BOOL=OFF",
+ "-DLLVM_ENABLE_ZLIB:BOOL=ON",
"-DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF",
"-DLLVM_INCLUDE_DOCS:BOOL=OFF",
"-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF",
"-DLLVM_INCLUDE_UTILS:BOOL=OFF",
"-DLLVM_INCLUDE_TESTS:BOOL=OFF",
- "-DLLVM_BUILD_TESTS:BOOL=OFF",
"-DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON",
]
+ # ccache is not available on Windows
+ if not "windows" == platform:
+ LLVM_COMPILE_OPTIONS.append("-DLLVM_CCACHE_BUILD:BOOL=ON")
+ # perf support is available on Linux only
+ if "linux" == platform:
+ LLVM_COMPILE_OPTIONS.append("-DLLVM_USE_PERF:BOOL=ON")
+
# use clang/clang++/lld. but macos doesn't support lld
if not sys.platform.startswith("darwin") and use_clang:
if shutil.which("clang") and shutil.which("clang++") and shutil.which("lld"):
@@ -255,7 +259,7 @@ def main():
"branch": "release/15.x",
},
"xtensa": {
- "repo": "https://github.com/espressif/llvm-project.git",
+ "repo": "https://github.com/espressif/llvm-project.git",
"repo_ssh": "git@github.com:espressif/llvm-project.git",
"branch": "xtensa_release_15.x",
},
@@ -281,13 +285,13 @@ def main():
commit_hash = query_llvm_version(llvm_info)
print(commit_hash)
return commit_hash is not None
-
+
repo_addr = llvm_info["repo"]
if os.environ.get('USE_GIT_SSH') == "true":
repo_addr = llvm_info["repo_ssh"]
else:
print("To use ssh for git clone, run: export USE_GIT_SSH=true")
-
+
llvm_dir = clone_llvm(deps_dir, repo_addr, llvm_info["branch"])
if (
build_llvm(
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/config_common.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake
similarity index 78%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/config_common.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake
index ea8ad1f3204..e73ebc85f1f 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/config_common.cmake
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake
@@ -122,11 +122,38 @@ if (WAMR_BUILD_JIT EQUAL 1)
if (CXX_SUPPORTS_REDUNDANT_MOVE_FLAG)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")
endif ()
+ # Enable exporting symbols after llvm-17, or LLVM JIT may run failed
+ # with `llvm_orc_registerEHFrameSectionWrapper` symbol not found error
+ if (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "17.0.0")
+ set (CMAKE_ENABLE_EXPORTS 1)
+ endif ()
endif ()
else ()
unset (LLVM_AVAILABLE_LIBS)
endif ()
+# Sanitizers
+
+set(WAMR_BUILD_SANITIZER $ENV{WAMR_BUILD_SANITIZER})
+
+if (NOT DEFINED WAMR_BUILD_SANITIZER)
+ set(WAMR_BUILD_SANITIZER "")
+elseif (WAMR_BUILD_SANITIZER STREQUAL "ubsan")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=alignment" )
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
+elseif (WAMR_BUILD_SANITIZER STREQUAL "asan")
+ if (NOT WAMR_BUILD_JIT EQUAL 1)
+ set (ASAN_OPTIONS "verbosity=2 debug=true ")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=address -fno-sanitize-recover=all" )
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
+ endif()
+elseif (WAMR_BUILD_SANITIZER STREQUAL "tsan")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=thread -fno-sanitize-recover=all" )
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
+elseif (NOT (WAMR_BUILD_SANITIZER STREQUAL "") )
+ message(SEND_ERROR "Unsupported sanitizer: ${WAMR_BUILD_SANITIZER}")
+endif()
+
########################################
message ("-- Build Configurations:")
@@ -251,6 +278,13 @@ else ()
add_definitions (-DWASM_DISABLE_STACK_HW_BOUND_CHECK=0)
endif ()
endif ()
+if (WAMR_DISABLE_WAKEUP_BLOCKING_OP EQUAL 1)
+ add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=1)
+ message (" Wakeup of blocking operations disabled")
+else ()
+ add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=0)
+ message (" Wakeup of blocking operations enabled")
+endif ()
if (WAMR_BUILD_SIMD EQUAL 1)
if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*")
add_definitions (-DWASM_ENABLE_SIMD=1)
@@ -337,16 +371,16 @@ endif ()
if (WAMR_BUILD_WASI_NN EQUAL 1)
message (" WASI-NN enabled")
add_definitions (-DWASM_ENABLE_WASI_NN=1)
- if (WASI_NN_ENABLE_GPU EQUAL 1)
+ if (WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1)
message (" WASI-NN: GPU enabled")
- add_definitions (-DWASI_NN_ENABLE_GPU=1)
+ add_definitions (-DWASM_ENABLE_WASI_NN_GPU=1)
endif ()
- if (WAMR_BUILD_WASI_NN_ENABLE_EXT EQUAL 1)
+ if (WAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE EQUAL 1)
message (" WASI-NN: External Delegation enabled")
- add_definitions (-DWASI_NN_ENABLE_EXTERNAL_DELEGATE=1)
+ add_definitions (-DWASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE=1)
endif ()
- if (DEFINED WASI_NN_EXT_DELEGATE_PATH)
- add_definitions (-DWASI_NN_EXT_DELEGATE_PATH="${WASI_NN_EXT_DELEGATE_PATH}")
+ if (DEFINED WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH)
+ add_definitions (-DWASM_WASI_NN_EXTERNAL_DELEGATE_PATH="${WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH}")
endif ()
endif ()
if (WAMR_BUILD_ALLOC_WITH_USER_DATA EQUAL 1)
@@ -356,6 +390,10 @@ if (WAMR_BUILD_WASM_CACHE EQUAL 1)
add_definitions (-DWASM_ENABLE_WASM_CACHE=1)
message (" Wasm files cache enabled")
endif ()
+if (WAMR_BUILD_MODULE_INST_CONTEXT EQUAL 1)
+ add_definitions (-DWASM_ENABLE_MODULE_INST_CONTEXT=1)
+ message (" Module instance context enabled")
+endif ()
if (WAMR_BUILD_GC_HEAP_VERIFY EQUAL 1)
add_definitions (-DWASM_ENABLE_GC_VERIFY=1)
message (" GC heap verification enabled")
@@ -366,3 +404,39 @@ if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
add_definitions (-DCOLLECT_CODE_COVERAGE)
message (" Collect code coverage enabled")
endif ()
+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"
+ AND WAMR_BUILD_PLATFORM STREQUAL "linux")
+ set (TEST_WRGSBASE_SOURCE "${CMAKE_BINARY_DIR}/test_wrgsbase.c")
+ file (WRITE "${TEST_WRGSBASE_SOURCE}" "
+ #include
+ #include
+ int main() {
+ uint64_t value;
+ asm volatile (\"wrgsbase %0\" : : \"r\"(value));
+ printf(\"WRGSBASE instruction is available.\\n\");
+ return 0;
+ }")
+ # Try to compile and run the test program
+ try_run (TEST_WRGSBASE_RESULT
+ TEST_WRGSBASE_COMPILED
+ ${CMAKE_BINARY_DIR}/test_wrgsbase
+ SOURCES ${TEST_WRGSBASE_SOURCE}
+ CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+ )
+ #message("${TEST_WRGSBASE_COMPILED}, ${TEST_WRGSBASE_RESULT}")
+ if (NOT TEST_WRGSBASE_RESULT EQUAL 0)
+ add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1)
+ message (" Write linear memory base addr to x86 GS register disabled")
+ endif ()
+endif ()
+if (WAMR_CONFIGUABLE_BOUNDS_CHECKS EQUAL 1)
+ add_definitions (-DWASM_CONFIGURABLE_BOUNDS_CHECKS=1)
+ message (" Configurable bounds checks enabled")
+endif ()
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/wamr/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/wamr/CMakeLists.txt
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/wamr/CMakeLists.txt
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/wamr/CMakeLists.txt
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/involve_boringssl.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/involve_boringssl.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/involve_boringssl.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/involve_boringssl.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch
index d6044e3a3ee..83221ef6ac6 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch
@@ -1,5 +1,44 @@
+diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
+index 9759b069fdc4..25b427f8bcf2 100644
+--- a/lldb/bindings/CMakeLists.txt
++++ b/lldb/bindings/CMakeLists.txt
+@@ -26,8 +26,6 @@ set(SWIG_COMMON_FLAGS
+ -features autodoc
+ -I${LLDB_SOURCE_DIR}/include
+ -I${CMAKE_CURRENT_SOURCE_DIR}
+- -D__STDC_LIMIT_MACROS
+- -D__STDC_CONSTANT_MACROS
+ ${DARWIN_EXTRAS}
+ )
+
+diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
+index c9a6d0f06056..021c7683d170 100644
+--- a/lldb/bindings/interfaces.swig
++++ b/lldb/bindings/interfaces.swig
+@@ -1,8 +1,5 @@
+ /* Various liblldb typedefs that SWIG needs to know about. */
+ #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */
+-/* The ISO C99 standard specifies that in C++ implementations limit macros such
+- as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
+-#define __STDC_LIMIT_MACROS
+ %include "stdint.i"
+
+ %include "lldb/lldb-defines.h"
+diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig
+index b1ace4ff3b1e..5f8f4aa678c4 100644
+--- a/lldb/bindings/python/python-typemaps.swig
++++ b/lldb/bindings/python/python-typemaps.swig
+@@ -439,7 +439,7 @@ bool SetNumberFromPyObject(double &number, PyObject *obj) {
+
+ %typemap(out) lldb::FileSP {
+ $result = nullptr;
+- lldb::FileSP &sp = $1;
++ const lldb::FileSP &sp = $1;
+ if (sp) {
+ PythonFile pyfile = unwrapOrSetPythonException(PythonFile::FromFile(*sp));
+ if (!pyfile.IsValid())
diff --git a/lldb/include/lldb/Breakpoint/Breakpoint.h b/lldb/include/lldb/Breakpoint/Breakpoint.h
-index f2e2a0d22..426d1129b 100644
+index f2e2a0d22784..426d1129bd10 100644
--- a/lldb/include/lldb/Breakpoint/Breakpoint.h
+++ b/lldb/include/lldb/Breakpoint/Breakpoint.h
@@ -9,6 +9,7 @@
@@ -11,7 +50,7 @@ index f2e2a0d22..426d1129b 100644
#include
#include
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
-index dd7100c46..97d70daad 100644
+index dd7100c4616c..97d70daadbdc 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -41,6 +41,7 @@
@@ -41,7 +80,7 @@ index dd7100c46..97d70daad 100644
///
/// Tries to resolve \a vm_addr as a file address (if \a
diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h
-index be91929c6..8d876fc1f 100644
+index be91929c62e1..8d876fc1fa2f 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -508,6 +508,17 @@ public:
@@ -64,7 +103,7 @@ index be91929c6..8d876fc1f 100644
} // namespace lldb_private
diff --git a/lldb/include/lldb/Expression/DWARFEvaluator.h b/lldb/include/lldb/Expression/DWARFEvaluator.h
new file mode 100644
-index 000000000..6811cbeae
+index 000000000000..6811cbeae3d3
--- /dev/null
+++ b/lldb/include/lldb/Expression/DWARFEvaluator.h
@@ -0,0 +1,110 @@
@@ -180,7 +219,7 @@ index 000000000..6811cbeae
+#endif // LLDB_EXPRESSION_DWARFEVALUATOR_H
diff --git a/lldb/include/lldb/Expression/DWARFEvaluatorFactory.h b/lldb/include/lldb/Expression/DWARFEvaluatorFactory.h
new file mode 100644
-index 000000000..f3b496c58
+index 000000000000..f3b496c580e4
--- /dev/null
+++ b/lldb/include/lldb/Expression/DWARFEvaluatorFactory.h
@@ -0,0 +1,56 @@
@@ -241,7 +280,7 @@ index 000000000..f3b496c58
+
+#endif // LLDB_EXPRESSION_DWARFEVALUATORFACTORY_H
diff --git a/lldb/include/lldb/Expression/DWARFExpression.h b/lldb/include/lldb/Expression/DWARFExpression.h
-index 1490ac2d6..35c741d4e 100644
+index 1490ac2d614a..35c741d4e6ba 100644
--- a/lldb/include/lldb/Expression/DWARFExpression.h
+++ b/lldb/include/lldb/Expression/DWARFExpression.h
@@ -120,6 +120,10 @@ public:
@@ -275,7 +314,7 @@ index 1490ac2d6..35c741d4e 100644
GetLocationExpression(lldb::addr_t load_function_start,
lldb::addr_t addr) const;
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
-index aaa2470d2..c15f2db52 100644
+index aaa2470d2931..c15f2db52fbc 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1434,7 +1434,7 @@ public:
@@ -288,7 +327,7 @@ index aaa2470d2..c15f2db52 100644
/// Read of memory from a process.
///
diff --git a/lldb/include/lldb/Target/ProcessTrace.h b/lldb/include/lldb/Target/ProcessTrace.h
-index 7b9d6b13d..9525fc975 100644
+index 7b9d6b13dd6f..9525fc9750fd 100644
--- a/lldb/include/lldb/Target/ProcessTrace.h
+++ b/lldb/include/lldb/Target/ProcessTrace.h
@@ -59,7 +59,7 @@ public:
@@ -301,7 +340,7 @@ index 7b9d6b13d..9525fc975 100644
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
Status &error) override;
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
-index ad5298151..5a3c0b27a 100644
+index ad5298151e4a..5a3c0b27a738 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -74,6 +74,7 @@ class Disassembler;
@@ -313,7 +352,7 @@ index ad5298151..5a3c0b27a 100644
class EmulateInstruction;
class Environment;
diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h
-index 2ed083ec8..f4d500d19 100644
+index 2ed083ec8ae9..f4d500d198e8 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -113,6 +113,8 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
@@ -326,7 +365,7 @@ index 2ed083ec8..f4d500d19 100644
/// \{
typedef llvm::Expected (*TraceCreateInstanceForSessionFile)(
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
-index 19c97be15..1647f93ec 100644
+index 19c97be15066..1647f93ec4f3 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -16,6 +16,7 @@
@@ -348,7 +387,7 @@ index 19c97be15..1647f93ec 100644
+ return m_dwarf_evaluator_factory.get();
+}
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
-index fcaa868b0..59a404d4a 100644
+index fcaa868b083e..59a404d4a7e1 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -1597,3 +1597,32 @@ bool PluginManager::CreateSettingForStructuredDataPlugin(
@@ -385,7 +424,7 @@ index fcaa868b0..59a404d4a 100644
+ return GetDWARFEvaluatorFactoryInstances().GetCallbackAtIndex(idx);
+}
diff --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp
-index fb57c0fed..f92d6a54d 100644
+index fb57c0fedf04..f92d6a54de94 100644
--- a/lldb/source/Core/Value.cpp
+++ b/lldb/source/Core/Value.cpp
@@ -538,7 +538,7 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
@@ -398,7 +437,7 @@ index fb57c0fed..f92d6a54d 100644
error.SetErrorStringWithFormat(
"read memory from 0x%" PRIx64 " failed (%u of %u bytes read)",
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
-index 9c1ba99da..b15b214b2 100644
+index 9c1ba99da1d0..b15b214b2a2f 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -735,7 +735,7 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
@@ -411,7 +450,7 @@ index 9c1ba99da..b15b214b2 100644
data.SetData(data_sp);
return bytes_read;
diff --git a/lldb/source/Expression/CMakeLists.txt b/lldb/source/Expression/CMakeLists.txt
-index bf94361dd..4e76d547a 100644
+index bf94361dd6c1..4e76d547aeaf 100644
--- a/lldb/source/Expression/CMakeLists.txt
+++ b/lldb/source/Expression/CMakeLists.txt
@@ -1,5 +1,7 @@
@@ -424,7 +463,7 @@ index bf94361dd..4e76d547a 100644
ExpressionVariable.cpp
diff --git a/lldb/source/Expression/DWARFEvaluator.cpp b/lldb/source/Expression/DWARFEvaluator.cpp
new file mode 100644
-index 000000000..06107e136
+index 000000000000..06107e136197
--- /dev/null
+++ b/lldb/source/Expression/DWARFEvaluator.cpp
@@ -0,0 +1,1952 @@
@@ -2382,7 +2421,7 @@ index 000000000..06107e136
+}
diff --git a/lldb/source/Expression/DWARFEvaluatorFactory.cpp b/lldb/source/Expression/DWARFEvaluatorFactory.cpp
new file mode 100644
-index 000000000..c06126412
+index 000000000000..c0612641204a
--- /dev/null
+++ b/lldb/source/Expression/DWARFEvaluatorFactory.cpp
@@ -0,0 +1,57 @@
@@ -2444,7 +2483,7 @@ index 000000000..c06126412
+ object_address_ptr);
+}
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
-index a10546c1d..4d13e4642 100644
+index a10546c1deae..4d13e4642af3 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -15,6 +15,8 @@
@@ -4261,7 +4300,7 @@ index a10546c1d..4d13e4642 100644
static DataExtractor ToDataExtractor(const llvm::DWARFLocationExpression &loc,
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
-index 00e9ccb76..2137a1ac8 100644
+index 00e9ccb762c3..2137a1ac8324 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -759,6 +759,24 @@ void CommandInterpreter::LoadCommandDictionary() {
@@ -4290,7 +4329,7 @@ index 00e9ccb76..2137a1ac8 100644
new CommandObjectRegexCommand(
*this, "kdp-remote",
diff --git a/lldb/source/Plugins/CMakeLists.txt b/lldb/source/Plugins/CMakeLists.txt
-index 9181a4e47..2be6ec365 100644
+index 9181a4e47675..2be6ec3657c0 100644
--- a/lldb/source/Plugins/CMakeLists.txt
+++ b/lldb/source/Plugins/CMakeLists.txt
@@ -2,6 +2,7 @@ add_subdirectory(ABI)
@@ -4320,14 +4359,14 @@ index 9181a4e47..2be6ec365 100644
endif()
diff --git a/lldb/source/Plugins/DWARFEvaluator/CMakeLists.txt b/lldb/source/Plugins/DWARFEvaluator/CMakeLists.txt
new file mode 100644
-index 000000000..73fad41e1
+index 000000000000..73fad41e1a72
--- /dev/null
+++ b/lldb/source/Plugins/DWARFEvaluator/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(wasm)
diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/CMakeLists.txt b/lldb/source/Plugins/DWARFEvaluator/wasm/CMakeLists.txt
new file mode 100644
-index 000000000..e50b1bef7
+index 000000000000..e50b1bef7e69
--- /dev/null
+++ b/lldb/source/Plugins/DWARFEvaluator/wasm/CMakeLists.txt
@@ -0,0 +1,10 @@
@@ -4343,7 +4382,7 @@ index 000000000..e50b1bef7
+ )
diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.cpp b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.cpp
new file mode 100644
-index 000000000..fdda1991d
+index 000000000000..fdda1991d19f
--- /dev/null
+++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.cpp
@@ -0,0 +1,126 @@
@@ -4475,7 +4514,7 @@ index 000000000..fdda1991d
+}
diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.h b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.h
new file mode 100644
-index 000000000..a01159064
+index 000000000000..a01159064a39
--- /dev/null
+++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.h
@@ -0,0 +1,47 @@
@@ -4528,7 +4567,7 @@ index 000000000..a01159064
+#endif // LLDB_SOURCE_PLUGINS_DWARFEVALUATOR_WASM_WASMDWARFEVALUATOR_H
diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.cpp b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.cpp
new file mode 100644
-index 000000000..d43e96a34
+index 000000000000..d43e96a34d37
--- /dev/null
+++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.cpp
@@ -0,0 +1,64 @@
@@ -4598,7 +4637,7 @@ index 000000000..d43e96a34
+}
diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.h b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.h
new file mode 100644
-index 000000000..8a946592a
+index 000000000000..8a946592a09a
--- /dev/null
+++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.h
@@ -0,0 +1,55 @@
@@ -4658,7 +4697,7 @@ index 000000000..8a946592a
+
+#endif // LLDB_SOURCE_PLUGINS_DWARFEVALUATOR_WASM_WASMDWARFEVALUATORFACTORY_H
diff --git a/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp b/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp
-index ae7e011ea..24ea75d19 100644
+index ae7e011eaa52..24ea75d1971c 100644
--- a/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp
@@ -62,6 +62,15 @@ void DynamicLoaderWasmDYLD::DidAttach() {
@@ -4678,7 +4717,7 @@ index ae7e011ea..24ea75d19 100644
ThreadPlanSP DynamicLoaderWasmDYLD::GetStepThroughTrampolinePlan(Thread &thread,
diff --git a/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp b/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
-index 5272da9ab..abc5523bf 100644
+index 5272da9ab33a..abc5523bfd70 100644
--- a/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ b/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -23,6 +23,7 @@
@@ -4718,7 +4757,7 @@ index 5272da9ab..abc5523bf 100644
}
}
diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt b/lldb/source/Plugins/Platform/CMakeLists.txt
-index 5f284e517..6084cbc93 100644
+index 5f284e517dca..6084cbc9378d 100644
--- a/lldb/source/Plugins/Platform/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/CMakeLists.txt
@@ -15,3 +15,4 @@
@@ -4728,7 +4767,7 @@ index 5f284e517..6084cbc93 100644
+add_subdirectory(wasm-remote)
diff --git a/lldb/source/Plugins/Platform/wasm-remote/CMakeLists.txt b/lldb/source/Plugins/Platform/wasm-remote/CMakeLists.txt
new file mode 100644
-index 000000000..4a65765a5
+index 000000000000..4a65765a5659
--- /dev/null
+++ b/lldb/source/Plugins/Platform/wasm-remote/CMakeLists.txt
@@ -0,0 +1,10 @@
@@ -4744,7 +4783,7 @@ index 000000000..4a65765a5
+ )
diff --git a/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.cpp b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.cpp
new file mode 100644
-index 000000000..f26d11f00
+index 000000000000..f26d11f00e5c
--- /dev/null
+++ b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.cpp
@@ -0,0 +1,139 @@
@@ -4890,7 +4929,7 @@ index 000000000..f26d11f00
\ No newline at end of file
diff --git a/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.h b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.h
new file mode 100644
-index 000000000..f306a79d3
+index 000000000000..f306a79d3f4f
--- /dev/null
+++ b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.h
@@ -0,0 +1,37 @@
@@ -4933,7 +4972,7 @@ index 000000000..f306a79d3
+#endif
\ No newline at end of file
diff --git a/lldb/source/Plugins/Plugins.def.in b/lldb/source/Plugins/Plugins.def.in
-index bf54598fb..b0bd7b996 100644
+index bf54598fb2f3..b0bd7b9965fe 100644
--- a/lldb/source/Plugins/Plugins.def.in
+++ b/lldb/source/Plugins/Plugins.def.in
@@ -31,6 +31,7 @@
@@ -4945,7 +4984,7 @@ index bf54598fb..b0bd7b996 100644
#undef LLDB_PLUGIN
diff --git a/lldb/source/Plugins/Process/CMakeLists.txt b/lldb/source/Plugins/Process/CMakeLists.txt
-index bea5bac9e..7a0855e02 100644
+index bea5bac9eb21..7a0855e02ca2 100644
--- a/lldb/source/Plugins/Process/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/CMakeLists.txt
@@ -18,3 +18,4 @@ add_subdirectory(Utility)
@@ -4954,7 +4993,7 @@ index bea5bac9e..7a0855e02 100644
add_subdirectory(minidump)
+add_subdirectory(wasm)
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
-index 12bc7390c..707ab85e5 100644
+index 12bc7390c729..707ab85e5615 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -285,7 +285,7 @@ bool ProcessElfCore::IsAlive() { return true; }
@@ -4967,7 +5006,7 @@ index 12bc7390c..707ab85e5 100644
// in core files we have it all cached our our core file anyway.
return DoReadMemory(addr, buf, size, error);
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
-index d8e3cc9ae..f0bf9c4d3 100644
+index d8e3cc9ae3e1..f0bf9c4d3b00 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -84,7 +84,8 @@ public:
@@ -4981,7 +5020,7 @@ index d8e3cc9ae..f0bf9c4d3 100644
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb_private::Status &error) override;
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
-index 6914b3734..bb8a05604 100644
+index 6914b37348ea..bb8a056049f3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -334,6 +334,11 @@ ConstString ProcessGDBRemote::GetPluginName() { return GetPluginNameStatic(); }
@@ -5015,7 +5054,7 @@ index 6914b3734..bb8a05604 100644
}
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
-index fe04cdddd..e4a14c645 100644
+index fe04cdddd0f5..e4a14c64579a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -237,6 +237,8 @@ protected:
@@ -5028,7 +5067,7 @@ index fe04cdddd..e4a14c645 100644
enum {
eBroadcastBitAsyncContinue = (1 << 0),
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
-index 84548edb5..0ae6f7e4a 100644
+index 84548edb5caa..0ae6f7e4a177 100644
--- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -596,7 +596,7 @@ bool ProcessMachCore::WarnBeforeDetach() const { return false; }
@@ -5041,7 +5080,7 @@ index 84548edb5..0ae6f7e4a 100644
// in core files we have it all cached our our core file anyway.
return DoReadMemory(addr, buf, size, error);
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
-index db77e96f1..1c930896c 100644
+index db77e96f1072..1c930896c743 100644
--- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
+++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
@@ -65,7 +65,8 @@ public:
@@ -5055,7 +5094,7 @@ index db77e96f1..1c930896c 100644
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb_private::Status &error) override;
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
-index 385557422..d8bb21581 100644
+index 385557422758..d8bb21581086 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -374,7 +374,7 @@ bool ProcessMinidump::IsAlive() { return true; }
@@ -5068,7 +5107,7 @@ index 385557422..d8bb21581 100644
// we have it all cached in our dump file anyway.
return DoReadMemory(addr, buf, size, error);
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.h b/lldb/source/Plugins/Process/minidump/ProcessMinidump.h
-index 27b0da004..e94ecab43 100644
+index 27b0da0047a5..e94ecab430c1 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.h
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.h
@@ -69,8 +69,8 @@ public:
@@ -5084,7 +5123,7 @@ index 27b0da004..e94ecab43 100644
Status &error) override;
diff --git a/lldb/source/Plugins/Process/wasm/CMakeLists.txt b/lldb/source/Plugins/Process/wasm/CMakeLists.txt
new file mode 100644
-index 000000000..61efb933f
+index 000000000000..61efb933fa62
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/CMakeLists.txt
@@ -0,0 +1,12 @@
@@ -5102,7 +5141,7 @@ index 000000000..61efb933f
+ )
diff --git a/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp b/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp
new file mode 100644
-index 000000000..9c0fc7b7f
+index 000000000000..9c0fc7b7f270
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp
@@ -0,0 +1,261 @@
@@ -5369,7 +5408,7 @@ index 000000000..9c0fc7b7f
+}
diff --git a/lldb/source/Plugins/Process/wasm/ProcessWasm.h b/lldb/source/Plugins/Process/wasm/ProcessWasm.h
new file mode 100644
-index 000000000..d3aece7a6
+index 000000000000..d3aece7a6554
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/ProcessWasm.h
@@ -0,0 +1,128 @@
@@ -5503,7 +5542,7 @@ index 000000000..d3aece7a6
+#endif // LLDB_SOURCE_PLUGINS_PROCESS_WASM_PROCESSWASM_H
diff --git a/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp b/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp
new file mode 100644
-index 000000000..fa02073e7
+index 000000000000..fa02073e7a52
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp
@@ -0,0 +1,35 @@
@@ -5544,7 +5583,7 @@ index 000000000..fa02073e7
+}
diff --git a/lldb/source/Plugins/Process/wasm/ThreadWasm.h b/lldb/source/Plugins/Process/wasm/ThreadWasm.h
new file mode 100644
-index 000000000..0a33c07de
+index 000000000000..0a33c07de994
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/ThreadWasm.h
@@ -0,0 +1,41 @@
@@ -5591,7 +5630,7 @@ index 000000000..0a33c07de
+#endif // LLDB_SOURCE_PLUGINS_PROCESS_WASM_THREADWASM_H
diff --git a/lldb/source/Plugins/Process/wasm/UnwindWasm.cpp b/lldb/source/Plugins/Process/wasm/UnwindWasm.cpp
new file mode 100644
-index 000000000..1a195cb93
+index 000000000000..1a195cb9361a
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/UnwindWasm.cpp
@@ -0,0 +1,74 @@
@@ -5672,7 +5711,7 @@ index 000000000..1a195cb93
\ No newline at end of file
diff --git a/lldb/source/Plugins/Process/wasm/UnwindWasm.h b/lldb/source/Plugins/Process/wasm/UnwindWasm.h
new file mode 100644
-index 000000000..9bd1dac9a
+index 000000000000..9bd1dac9a98a
--- /dev/null
+++ b/lldb/source/Plugins/Process/wasm/UnwindWasm.h
@@ -0,0 +1,55 @@
@@ -5732,7 +5771,7 @@ index 000000000..9bd1dac9a
+
+#endif // lldb_UnwindWasm_h_
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
-index ccaf31317..c3ef5aebd 100644
+index ccaf31317d75..c3ef5aebd46d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3212,8 +3212,13 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
@@ -5751,7 +5790,7 @@ index ccaf31317..c3ef5aebd 100644
// DWARF doesn't specify if a DW_TAG_variable is a local, global
// or static variable, so we have to do a little digging:
diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp
-index b660c310e..cd76421ce 100644
+index b660c310ef31..cd76421cec18 100644
--- a/lldb/source/Target/PathMappingList.cpp
+++ b/lldb/source/Target/PathMappingList.cpp
@@ -218,7 +218,12 @@ bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) co
@@ -5769,7 +5808,7 @@ index b660c310e..cd76421ce 100644
return {};
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
-index a77ecddfb..e257f9350 100644
+index a77ecddfbab6..e257f93508f6 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1970,6 +1970,12 @@ size_t Platform::GetSoftwareBreakpointTrapOpcode(Target &target,
@@ -5786,7 +5825,7 @@ index a77ecddfb..e257f9350 100644
return 0;
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
-index 8ecc66b59..f14898791 100644
+index 8ecc66b592ea..f148987915de 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1892,7 +1892,8 @@ Status Process::DisableSoftwareBreakpoint(BreakpointSite *bp_site) {
@@ -5800,7 +5839,7 @@ index 8ecc66b59..f14898791 100644
if (!GetDisableMemoryCache()) {
#if defined(VERIFY_MEMORY_READS)
diff --git a/lldb/source/Target/ProcessTrace.cpp b/lldb/source/Target/ProcessTrace.cpp
-index c878a2ac4..ad5945b0a 100644
+index c878a2ac4eb9..ad5945b0ad1f 100644
--- a/lldb/source/Target/ProcessTrace.cpp
+++ b/lldb/source/Target/ProcessTrace.cpp
@@ -88,7 +88,7 @@ void ProcessTrace::RefreshStateAfterStop() {}
@@ -5813,7 +5852,7 @@ index c878a2ac4..ad5945b0a 100644
// we have it all cached in the trace files.
return DoReadMemory(addr, buf, size, error);
diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp
-index 896e647bb..f76307016 100644
+index 896e647bbb52..f76307016102 100644
--- a/lldb/source/Target/ThreadPlanStepRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepRange.cpp
@@ -334,7 +334,10 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() {
@@ -5829,7 +5868,7 @@ index 896e647bb..f76307016 100644
instructions->GetInstructionAtIndex(last_index);
size_t last_inst_size = last_inst->GetOpcode().GetByteSize();
diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp
-index 4ec2e25c7..24c88fe9a 100644
+index 4ec2e25c7e3b..24c88fe9ae4f 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -46,6 +46,8 @@ lldb::UnixSignalsSP UnixSignals::Create(const ArchSpec &arch) {
@@ -5842,7 +5881,7 @@ index 4ec2e25c7..24c88fe9a 100644
return std::make_shared();
}
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h
-index 4310ba9ce..297b33879 100644
+index 4310ba9ce9e0..297b3387999d 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h
@@ -13,6 +13,7 @@
@@ -5854,7 +5893,7 @@ index 4310ba9ce..297b33879 100644
#include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h"
#include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h"
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
-index 753b1998c..27370c62d 100644
+index 753b1998c40c..27370c62dd6e 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -16,6 +16,7 @@
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt
new file mode 100644
index 00000000000..077c95d8a43
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt
@@ -0,0 +1 @@
+requests==2.31.0
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/runtime_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/runtime_lib.cmake
similarity index 95%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/runtime_lib.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/runtime_lib.cmake
index 6931ece74b9..811009df6ec 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/runtime_lib.cmake
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/runtime_lib.cmake
@@ -91,8 +91,10 @@ endif ()
if (WAMR_BUILD_LIBC_UVWASI EQUAL 1)
include (${IWASM_DIR}/libraries/libc-uvwasi/libc_uvwasi.cmake)
+ set (WAMR_BUILD_MODULE_INST_CONTEXT 1)
elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
+ set (WAMR_BUILD_MODULE_INST_CONTEXT 1)
endif ()
if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
@@ -101,7 +103,7 @@ if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
endif ()
if (WAMR_BUILD_WASI_NN EQUAL 1)
- include (${IWASM_DIR}/libraries/wasi-nn/wasi_nn.cmake)
+ include (${IWASM_DIR}/libraries/wasi-nn/cmake/wasi_nn.cmake)
endif ()
if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
@@ -163,7 +165,11 @@ file (GLOB header
)
LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
-enable_language (ASM)
+if (WAMR_BUILD_PLATFORM STREQUAL "windows")
+ enable_language (ASM_MASM)
+else()
+ enable_language (ASM)
+endif()
include (${SHARED_PLATFORM_CONFIG})
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
@@ -177,7 +183,7 @@ set (source_all
${UTILS_SHARED_SOURCE}
${LIBC_BUILTIN_SOURCE}
${LIBC_WASI_SOURCE}
- ${LIBC_WASI_NN_SOURCE}
+ ${WASI_NN_SOURCES}
${IWASM_COMMON_SOURCE}
${IWASM_INTERP_SOURCE}
${IWASM_AOT_SOURCE}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ci/build_wamr.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/build_wamr.sh
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/ci/build_wamr.sh
rename to lib/wasm-micro-runtime-WAMR-1.3.0/ci/build_wamr.sh
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ci/coding_guidelines_check.py b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/coding_guidelines_check.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/ci/coding_guidelines_check.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/ci/coding_guidelines_check.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample
new file mode 100755
index 00000000000..682e7894644
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# This is a sample of pre-commit hook that can be used to make your code fit the WAMR CI code style requirements.
+# You need to have clang-format-12 installed to use this hook.
+# To add this pre-commit hook, copy it to /.git/hooks/pre-commit
+# (you don't need any extensions here)
+
+# Function to check if a file has a C or C++ extension
+
+is_c_or_cpp_file() {
+ file="$1"
+ if [[ "$filename" =~ \.(h|c|cpp)$ ]]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+# Loop through staged files and apply command "abc" to C and C++ files
+for staged_file in $(git diff --cached --name-only); do
+ if is_c_or_cpp_file "$staged_file"; then
+ clang-format-12 -Werror --style file --dry-run "$staged_file" 2>/dev/null
+ if [ $? -ne 0 ]; then
+ echo "Issues are found in $staged_file. Applying the fix"
+ clang-format-12 --style file -i "$staged_file"
+ fi
+ git add "$staged_file" # Add the modified file back to staging
+ fi
+done
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh
new file mode 100755
index 00000000000..ebdf73af553
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# This script executes some commands to make your onboarding with WAMR easier.
+# For example, setting pre-commit hook that will make your code complaint with the
+# code style requirements checked in WAMR CI
+
+echo "Copy the pre-commit hook to your hooks folder"
+cp pre_commit_hook_sample ../.git/hooks/pre-commit
+
+# Feel free to propose your commands to this script to make developing WAMR easier
+
+echo "Setup is done"
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py
new file mode 100755
index 00000000000..1b431ada853
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py
@@ -0,0 +1,128 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+
+import argparse
+import time
+from pathlib import Path
+import subprocess, shlex
+
+SCRIPT_DIR = Path(__file__).parent.resolve()
+REPO_ROOT_DIR = SCRIPT_DIR.parent
+SAMPLE_CODE_FILE = REPO_ROOT_DIR / 'product-mini/app-samples/hello-world/main.c'
+WASM_OUT_FILE = SCRIPT_DIR / 'out.wasm'
+
+parser = argparse.ArgumentParser(
+ description="Validate the customized lldb with sample code"
+)
+parser.add_argument(
+ "-l", "--lldb", dest='lldb', default='lldb', help="path to lldb executable"
+)
+parser.add_argument(
+ "-w", "--wamr", dest='wamr', default='iwasm', help="path to iwasm executable"
+)
+parser.add_argument(
+ "-p", "--port", dest='port', default='1234', help="debug server listen port"
+)
+parser.add_argument(
+ "-v", "--verbose", dest='verbose', action='store_true', default=False, help="display lldb stdout"
+)
+
+options = parser.parse_args()
+
+lldb_command_epilogue = '-o q'
+
+test_cases = {
+ 'run_to_exit': '-o c',
+ 'func_breakpoint': '-o "b main" -o c -o c',
+ 'line_breakpoint': '-o "b main.c:12" -o c -o c',
+ 'break_on_unknown_func': '-o "b not_a_func" -o c',
+ 'watch_point': '-o "b main" -o c -o "watchpoint set variable buf" -o c -o "fr v buf" -o c',
+}
+
+# Step1: Build wasm module with debug information
+build_cmd = f'/opt/wasi-sdk/bin/clang -g -O0 -o {WASM_OUT_FILE} {SAMPLE_CODE_FILE}'
+try:
+ print(f'building wasm module ...', end='', flush=True)
+ subprocess.check_call(shlex.split(build_cmd))
+ print(f'\t OK')
+except subprocess.CalledProcessError:
+ print("Failed to build wasm module with debug information")
+ exit(1)
+
+def print_process_output(p):
+ try:
+ outs, errs = p.communicate(timeout=2)
+ print("stdout:")
+ print(outs)
+ print("stderr:")
+ print(errs)
+ except subprocess.TimeoutExpired:
+ print("Failed to get process output")
+
+# Step2: Launch WAMR in debug mode and validate lldb commands
+
+iteration = 0
+for case, cmd in test_cases.items():
+ lldb_command_prologue = f'{options.lldb} -o "process connect -p wasm connect://127.0.0.1:{int(options.port) + iteration}"'
+ wamr_cmd = f'{options.wamr} -g=127.0.0.1:{int(options.port) + iteration} {WASM_OUT_FILE}'
+ iteration += 1
+
+ has_error = False
+ print(f'validating case [{case}] ...', end='', flush=True)
+ lldb_cmd = f'{lldb_command_prologue} {cmd} {lldb_command_epilogue}'
+
+ wamr_process = subprocess.Popen(shlex.split(
+ wamr_cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+
+ time.sleep(0.1)
+ if (wamr_process.poll() != None):
+ print("\nWAMR doesn't wait for lldb connection")
+ print_process_output(wamr_process)
+ exit(1)
+
+ lldb_process = subprocess.Popen(shlex.split(
+ lldb_cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+
+ if (options.verbose):
+ while (lldb_process.poll() is None):
+ print(lldb_process.stdout.read(), end='', flush=True)
+
+ try:
+ if (lldb_process.wait(5) != 0):
+ print(f"\nFailed to validate case [{case}]")
+ print_process_output(lldb_process)
+ has_error = True
+
+ if wamr_process.wait(2) != 0:
+ print("\nWAMR process doesn't exit normally")
+ print_process_output(wamr_process)
+ has_error = True
+
+ except subprocess.TimeoutExpired:
+ print(f"\nFailed to validate case [{case}]")
+ print("wamr output:")
+ print_process_output(wamr_process)
+ print("lldb output:")
+ print_process_output(lldb_process)
+ has_error = True
+ finally:
+ if (lldb_process.poll() == None):
+ print(f'\nterminating lldb process [{lldb_process.pid}]')
+ lldb_process.kill()
+ if (wamr_process.poll() == None):
+ print(f'terminating wamr process [{wamr_process.pid}]')
+ wamr_process.kill()
+
+ if (has_error):
+ exit(1)
+
+ print(f'\t OK')
+
+ # wait 100ms to ensure the socket is closed
+ time.sleep(0.1)
+
+print('Validate lldb success')
+exit(0)
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/attr_container.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/attr_container.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/attr_container.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/attr_container.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/attr_container.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/attr_container.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/attr_container.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/attr_container.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/shared_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/shared_utils.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/shared_utils.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/shared_utils.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/restful_utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/restful_utils.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/restful_utils.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/restful_utils.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_ext_lib_export.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_ext_lib_export.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_ext_lib_export.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_ext_lib_export.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_framework.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_framework.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_framework.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_framework.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/req_resp_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/req_resp_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/req_resp_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/req_resp_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/request.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/request.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/request.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/request.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/request.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/request.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/request.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/request.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/timer_wasm_app.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/timer_wasm_app.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/timer_wasm_app.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/timer_wasm_app.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib.inl
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib.inl
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib.inl
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib_export.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib_export.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib_export.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib_export.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/req_resp_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/req_resp_native_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/req_resp_native_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/req_resp_native_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/request_response.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/request_response.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/request_response.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/request_response.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/runtime_lib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/runtime_lib.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/runtime_lib.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/runtime_lib.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_native_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_native_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_native_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_wrapper.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_wrapper.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/wasm_lib.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/wasm_lib.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/wasm_lib.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wa-inc/connection.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wa-inc/connection.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wa-inc/connection.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wa-inc/connection.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wasm_app.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wasm_app.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wasm_app.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection.inl
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection.inl
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection.inl
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_lib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_lib.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_lib.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_lib.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_native_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_native_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_native_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_wrapper.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_wrapper.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/wasm_lib.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/wasm_lib.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/wasm_lib.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_lib_impl.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_lib_impl.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_lib_impl.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_lib_impl.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_mgr.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_mgr.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_mgr.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wa-inc/sensor.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wa-inc/sensor.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wa-inc/sensor.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wa-inc/sensor.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wasm_app.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wasm_app.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wasm_app.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.inl
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.inl
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.inl
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_mgr_ref.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_mgr_ref.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_mgr_ref.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_mgr_ref.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_native_api.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_native_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_native_api.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/wasm_lib.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/wasm_lib.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/wasm_lib.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wa-inc/app_xxx.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wa-inc/app_xxx.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wa-inc/app_xxx.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wa-inc/app_xxx.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wasm_app.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wasm_app.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wasm_app.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/app_xxx.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/app_xxx.inl
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/app_xxx.inl
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/app_xxx.inl
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/wasm_lib.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/wasm_lib.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/wasm_lib.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md
new file mode 100644
index 00000000000..7a561897e17
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md
@@ -0,0 +1,8 @@
+# Remote application management
+
+The WAMR application manager supports [remote application management](../../core/app-mgr) from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes.
+
+The tool [host_tool](../../test-tools/host-tool) communicates to the WAMR app manager for installing/uninstalling the WASM applications on companion chip from the host system. And the [IoT App Store Demo](../../test-tools/IoT-APP-Store-Demo/) shows the conception of remotely managing the device applications from the cloud.
+
+
+
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_mgr.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_mgr.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_mgr.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/ble_msg.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/ble_msg.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/ble_msg.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/ble_msg.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/coding_rule.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/coding_rule.txt
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/coding_rule.txt
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/coding_rule.txt
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/message.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/message.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/message.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/message.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_config.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_config.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_config.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_utils.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_utils.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_utils.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.c
index 2005ad8e846..6fd929b10f1 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.c
@@ -1467,7 +1467,7 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch, int request_total_size,
if (total_size >= UINT32_MAX
|| !(section->section_body =
os_mmap(NULL, (uint32)total_size, map_prot,
- map_flags))) {
+ map_flags, os_get_invalid_handle()))) {
app_manager_printf(
"Allocate executable memory failed!\n");
SEND_ERR_RESPONSE(recv_ctx.message.request_mid,
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/resource_reg.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/resource_reg.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/resource_reg.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/resource_reg.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_manager_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_manager_export.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_manager_export.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_manager_export.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/host_link.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/host_link.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/host_link.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/host_link.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/module.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/module.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/module.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/module.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/config.h
similarity index 88%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/config.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/config.h
index feedb13fa62..acf70ff081b 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/config.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/config.h
@@ -144,6 +144,14 @@
#define WASM_ENABLE_WASI_NN 0
#endif
+#ifndef WASM_ENABLE_WASI_NN_GPU
+#define WASM_ENABLE_WASI_NN_GPU 0
+#endif
+
+#ifndef WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE
+#define WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE 0
+#endif
+
/* Default disable libc emcc */
#ifndef WASM_ENABLE_LIBC_EMCC
#define WASM_ENABLE_LIBC_EMCC 0
@@ -307,6 +315,11 @@
#define BH_ENABLE_GC_VERIFY 0
#endif
+/* Heap corruption check, enabled by default */
+#ifndef BH_ENABLE_GC_CORRUPTION_CHECK
+#define BH_ENABLE_GC_CORRUPTION_CHECK 1
+#endif
+
/* Enable global heap pool if heap verification is enabled */
#if BH_ENABLE_GC_VERIFY != 0
#define WASM_ENABLE_GLOBAL_HEAP_POOL 1
@@ -384,7 +397,7 @@
#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
#define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
#else
-#define APP_THREAD_STACK_SIZE_DEFAULT (32 * 1024)
+#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
#define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
#endif
#endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
@@ -445,4 +458,36 @@
#define WASM_ENABLE_WASM_CACHE 0
#endif
+#ifndef WASM_ENABLE_STATIC_PGO
+#define WASM_ENABLE_STATIC_PGO 0
+#endif
+
+/* Disable writing linear memory base address to GS segment register,
+ by default only in linux x86-64, linear memory base addr is written
+ to GS segment register before calling wasm/aot function. */
+#ifndef WASM_DISABLE_WRITE_GS_BASE
+#define WASM_DISABLE_WRITE_GS_BASE 0
+#endif
+
+/* Configurable bounds checks */
+#ifndef WASM_CONFIGURABLE_BOUNDS_CHECKS
+#define WASM_CONFIGURABLE_BOUNDS_CHECKS 0
+#endif
+
+/* Some chip cannot support external ram with rwx attr at the same time,
+ it has to map it into 2 spaces of idbus and dbus, code in dbus can be
+ read/written and read/executed in ibus. so there are 2 steps to execute
+ the code, first, copy & do relocation in dbus space, and second execute
+ it in ibus space, since in the 2 spaces the contents are the same,
+ so we call it bus mirror.
+ */
+#ifndef WASM_MEM_DUAL_BUS_MIRROR
+#define WASM_MEM_DUAL_BUS_MIRROR 0
+#endif
+
+/* The max number of module instance contexts. */
+#ifndef WASM_MAX_INSTANCE_CONTEXTS
+#define WASM_MAX_INSTANCE_CONTEXTS 8
+#endif
+
#endif /* end of _CONFIG_H_ */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.c
similarity index 82%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.c
index 319eeda5cbc..189b43b09b0 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.c
@@ -648,6 +648,42 @@ add_f64_common_intrinsics(AOTCompContext *comp_ctx)
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CMP);
}
+static void
+add_f32xi32_intrinsics(AOTCompContext *comp_ctx)
+{
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_I32);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_U32);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_TO_F32);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U32_TO_F32);
+}
+
+static void
+add_f64xi32_intrinsics(AOTCompContext *comp_ctx)
+{
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_I32);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_U32);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_TO_F64);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U32_TO_F64);
+}
+
+static void
+add_f32xi64_intrinsics(AOTCompContext *comp_ctx)
+{
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_I64);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_U64);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_TO_F32);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U64_TO_F32);
+}
+
+static void
+add_f64xi64_intrinsics(AOTCompContext *comp_ctx)
+{
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_I64);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_U64);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_TO_F64);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U64_TO_F64);
+}
+
static void
add_common_float_integer_convertion(AOTCompContext *comp_ctx)
{
@@ -705,8 +741,101 @@ aot_intrinsic_check_capability(const AOTCompContext *comp_ctx,
void
aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
{
+ uint32 i;
+
memset(comp_ctx->flags, 0, sizeof(comp_ctx->flags));
+ /* Intrinsics from command line have highest priority */
+
+ if (comp_ctx->builtin_intrinsics) {
+
+ /* Handle 'all' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "all")) {
+ for (i = 0; i < g_intrinsic_count; i++) {
+ add_intrinsic_capability(comp_ctx, g_intrinsic_mapping[i].flag);
+ }
+ return;
+ }
+
+ /* Handle 'i32.common' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "i32.common")) {
+ add_i32_common_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'i64.common' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "i64.common")) {
+ add_i64_common_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'fp.common' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "fp.common")) {
+ add_f32_common_intrinsics(comp_ctx);
+ add_f64_common_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'f32.common' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "f32.common")) {
+ add_f32_common_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'f64.common' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "f64.common")) {
+ add_f64_common_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'f32xi32' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "f32xi32")) {
+ add_f32xi32_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'f64xi32' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "f64xi32")) {
+ add_f64xi32_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'f32xi64' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "f32xi64")) {
+ add_f32xi64_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'f64xi64' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "f64xi64")) {
+ add_f64xi64_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'fpxint' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "fpxint")) {
+ add_f32xi32_intrinsics(comp_ctx);
+ add_f64xi32_intrinsics(comp_ctx);
+ add_f32xi64_intrinsics(comp_ctx);
+ add_f64xi64_intrinsics(comp_ctx);
+ }
+
+ /* Handle 'constop' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "constop")) {
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CONST);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_CONST);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST);
+ add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST);
+ }
+
+ /* Handle 'fp.common' group */
+ if (strstr(comp_ctx->builtin_intrinsics, "fp.common")) {
+ add_f32_common_intrinsics(comp_ctx);
+ add_f64_common_intrinsics(comp_ctx);
+ }
+
+ /* Handle other single items */
+ for (i = 0; i < g_intrinsic_count; i++) {
+ if (strstr(comp_ctx->builtin_intrinsics,
+ g_intrinsic_mapping[i].llvm_intrinsic)) {
+ add_intrinsic_capability(comp_ctx, g_intrinsic_mapping[i].flag);
+ }
+ }
+
+ return;
+ }
+
if (!comp_ctx->target_cpu)
return;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_loader.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_loader.c
similarity index 86%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_loader.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_loader.c
index 5345fb2d72e..abffd6438a7 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_loader.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_loader.c
@@ -558,6 +558,56 @@ str2uint32(const char *buf, uint32 *p_res);
static bool
str2uint64(const char *buf, uint64 *p_res);
+#if WASM_ENABLE_MULTI_MODULE != 0
+static void *
+aot_loader_resolve_function(const char *module_name, const char *function_name,
+ const AOTFuncType *expected_function_type,
+ char *error_buf, uint32 error_buf_size)
+{
+ WASMModuleCommon *module_reg;
+ void *function = NULL;
+ AOTExport *export = NULL;
+ AOTModule *module = NULL;
+ AOTFuncType *target_function_type = NULL;
+
+ module_reg = wasm_runtime_find_module_registered(module_name);
+ if (!module_reg || module_reg->module_type != Wasm_Module_AoT) {
+ LOG_DEBUG("can not find a module named %s for function %s", module_name,
+ function_name);
+ set_error_buf(error_buf, error_buf_size, "unknown import");
+ return NULL;
+ }
+
+ module = (AOTModule *)module_reg;
+ export = loader_find_export(module_reg, module_name, function_name,
+ EXPORT_KIND_FUNC, error_buf, error_buf_size);
+ if (!export) {
+ return NULL;
+ }
+
+ /* resolve function type and function */
+ if (export->index < module->import_func_count) {
+ target_function_type = module->import_funcs[export->index].func_type;
+ function = module->import_funcs[export->index].func_ptr_linked;
+ }
+ else {
+ target_function_type =
+ module->func_types[module->func_type_indexes
+ [export->index - module->import_func_count]];
+ function =
+ (module->func_ptrs[export->index - module->import_func_count]);
+ }
+ /* check function type */
+ if (!wasm_type_equal(expected_function_type, target_function_type)) {
+ LOG_DEBUG("%s.%s failed the type check", module_name, function_name);
+ set_error_buf(error_buf, error_buf_size, "incompatible import type");
+ return NULL;
+ }
+ return function;
+}
+
+#endif /* end of WASM_ENABLE_MULTI_MODULE */
+
static bool
load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,
AOTModule *module, bool is_load_from_file_buf,
@@ -1045,7 +1095,6 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
data_list[i]->mode = mode;
data_list[i]->elem_type = elem_type;
- data_list[i]->is_dropped = false;
data_list[i]->table_index = table_index;
data_list[i]->offset.init_expr_type = (uint8)init_expr_type;
data_list[i]->offset.u.i64 = (int64)init_expr_value;
@@ -1357,11 +1406,16 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
bool is_load_from_file_buf, char *error_buf,
uint32 error_buf_size)
{
- const char *module_name, *field_name;
+ char *module_name, *field_name;
const uint8 *buf = *p_buf;
AOTImportFunc *import_funcs;
uint64 size;
uint32 i;
+#if WASM_ENABLE_MULTI_MODULE != 0
+ AOTModule *sub_module = NULL;
+ AOTFunc *linked_func = NULL;
+ WASMType *declare_func_type = NULL;
+#endif
/* Allocate memory */
size = sizeof(AOTImportFunc) * (uint64)module->import_func_count;
@@ -1377,17 +1431,46 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
set_error_buf(error_buf, error_buf_size, "unknown type");
return false;
}
+
+#if WASM_ENABLE_MULTI_MODULE != 0
+ declare_func_type = module->func_types[import_funcs[i].func_type_index];
+ read_string(buf, buf_end, module_name);
+ read_string(buf, buf_end, field_name);
+
+ import_funcs[i].module_name = module_name;
+ import_funcs[i].func_name = field_name;
+ linked_func = wasm_native_resolve_symbol(
+ module_name, field_name, declare_func_type,
+ &import_funcs[i].signature, &import_funcs[i].attachment,
+ &import_funcs[i].call_conv_raw);
+ if (!linked_func) {
+ if (!wasm_runtime_is_built_in_module(module_name)) {
+ sub_module = (AOTModule *)wasm_runtime_load_depended_module(
+ (WASMModuleCommon *)module, module_name, error_buf,
+ error_buf_size);
+ if (!sub_module) {
+ return false;
+ }
+ }
+ linked_func = aot_loader_resolve_function(
+ module_name, field_name, declare_func_type, error_buf,
+ error_buf_size);
+ }
+ import_funcs[i].func_ptr_linked = linked_func;
+ import_funcs[i].func_type = declare_func_type;
+
+#else
import_funcs[i].func_type =
module->func_types[import_funcs[i].func_type_index];
read_string(buf, buf_end, import_funcs[i].module_name);
read_string(buf, buf_end, import_funcs[i].func_name);
-
module_name = import_funcs[i].module_name;
field_name = import_funcs[i].func_name;
import_funcs[i].func_ptr_linked = wasm_native_resolve_symbol(
module_name, field_name, import_funcs[i].func_type,
&import_funcs[i].signature, &import_funcs[i].attachment,
&import_funcs[i].call_conv_raw);
+#endif
#if WASM_ENABLE_LIBC_WASI != 0
if (!strcmp(import_funcs[i].module_name, "wasi_unstable")
@@ -1430,8 +1513,28 @@ destroy_object_data_sections(AOTObjectDataSection *data_sections,
uint32 i;
AOTObjectDataSection *data_section = data_sections;
for (i = 0; i < data_section_count; i++, data_section++)
- if (data_section->data)
+ if (data_section->data) {
+#if WASM_ENABLE_STATIC_PGO != 0
+ if (!strncmp(data_section->name, "__llvm_prf_data", 15)) {
+ LLVMProfileData *data = (LLVMProfileData *)data_section->data;
+ if (data->values) {
+ uint32 num_value_sites =
+ data->num_value_sites[0] + data->num_value_sites[1];
+ uint32 j;
+ for (j = 0; j < num_value_sites; j++) {
+ ValueProfNode *node = data->values[j], *node_next;
+ while (node) {
+ node_next = node->next;
+ wasm_runtime_free(node);
+ node = node_next;
+ }
+ }
+ wasm_runtime_free(data->values);
+ }
+ }
+#endif
os_munmap(data_section->data, data_section->size);
+ }
wasm_runtime_free(data_sections);
}
@@ -1470,8 +1573,9 @@ load_object_data_sections(const uint8 **p_buf, const uint8 *buf_end,
/* Allocate memory for data */
if (data_sections[i].size > 0
- && !(data_sections[i].data = os_mmap(NULL, data_sections[i].size,
- map_prot, map_flags))) {
+ && !(data_sections[i].data =
+ os_mmap(NULL, data_sections[i].size, map_prot, map_flags,
+ os_get_invalid_handle()))) {
set_error_buf(error_buf, error_buf_size, "allocate memory failed");
return false;
}
@@ -1624,27 +1728,6 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
const uint8 *p = buf, *p_end = buf_end;
uint32 i;
uint64 size, text_offset;
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- RUNTIME_FUNCTION *rtl_func_table;
- AOTUnwindInfo *unwind_info;
- uint32 unwind_info_offset = module->code_size - sizeof(AOTUnwindInfo);
- uint32 unwind_code_offset = unwind_info_offset - PLT_ITEM_SIZE;
-#endif
-
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- unwind_info = (AOTUnwindInfo *)((uint8 *)module->code + module->code_size
- - sizeof(AOTUnwindInfo));
- unwind_info->Version = 1;
- unwind_info->Flags = UNW_FLAG_NHANDLER;
- *(uint32 *)&unwind_info->UnwindCode[0] = unwind_code_offset;
-
- size = sizeof(RUNTIME_FUNCTION) * (uint64)module->func_count;
- if (size > 0
- && !(rtl_func_table = module->rtl_func_table =
- loader_malloc(size, error_buf, error_buf_size))) {
- return false;
- }
-#endif
size = sizeof(void *) * (uint64)module->func_count;
if (size > 0
@@ -1671,33 +1754,9 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
#if defined(BUILD_TARGET_THUMB) || defined(BUILD_TARGET_THUMB_VFP)
/* bits[0] of thumb function address must be 1 */
module->func_ptrs[i] = (void *)((uintptr_t)module->func_ptrs[i] | 1);
-#endif
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- rtl_func_table[i].BeginAddress = (DWORD)text_offset;
- if (i > 0) {
- rtl_func_table[i - 1].EndAddress = rtl_func_table[i].BeginAddress;
- }
- rtl_func_table[i].UnwindInfoAddress = (DWORD)unwind_info_offset;
#endif
}
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- if (module->func_count > 0) {
- uint32 plt_table_size =
- module->is_indirect_mode ? 0 : get_plt_table_size();
- rtl_func_table[module->func_count - 1].EndAddress =
- (DWORD)(module->code_size - plt_table_size);
-
- if (!RtlAddFunctionTable(rtl_func_table, module->func_count,
- (DWORD64)(uintptr_t)module->code)) {
- set_error_buf(error_buf, error_buf_size,
- "add dynamic function table failed");
- return false;
- }
- module->rtl_func_table_registered = true;
- }
-#endif
-
/* Set start function when function pointers are resolved */
if (module->start_func_index != (uint32)-1) {
if (module->start_func_index >= module->import_func_count)
@@ -1823,6 +1882,13 @@ get_data_section_addr(AOTModule *module, const char *section_name,
return NULL;
}
+const void *
+aot_get_data_section_addr(AOTModule *module, const char *section_name,
+ uint32 *p_data_size)
+{
+ return get_data_section_addr(module, section_name, p_data_size);
+}
+
static void *
resolve_target_sym(const char *symbol, int32 *p_index)
{
@@ -1900,6 +1966,8 @@ str2uint64(const char *buf, uint64 *p_res)
return true;
}
+#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
+
static bool
do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
char *error_buf, uint32 error_buf_size)
@@ -1937,6 +2005,14 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
bh_memcpy_s(symbol, symbol_len, relocation->symbol_name, symbol_len);
symbol[symbol_len] = '\0';
+#if WASM_ENABLE_STATIC_PGO != 0
+ if (!strcmp(symbol, "__llvm_profile_runtime")
+ || !strcmp(symbol, "__llvm_profile_register_function")
+ || !strcmp(symbol, "__llvm_profile_register_names_function")) {
+ continue;
+ }
+#endif
+
if (!strncmp(symbol, AOT_FUNC_PREFIX, strlen(AOT_FUNC_PREFIX))) {
p = symbol + strlen(AOT_FUNC_PREFIX);
if (*p == '\0'
@@ -1945,8 +2021,41 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
"invalid import symbol %s", symbol);
goto check_symbol_fail;
}
+#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \
+ && !defined(BH_PLATFORM_WINDOWS)
+ if (relocation->relocation_type == R_X86_64_GOTPCREL) {
+ GOTItem *got_item = module->got_item_list;
+ uint32 got_item_idx = 0;
+
+ while (got_item) {
+ if (got_item->func_idx == func_index)
+ break;
+ got_item_idx++;
+ got_item = got_item->next;
+ }
+ /* Calculate `GOT + G` */
+ symbol_addr = module->got_func_ptrs + got_item_idx;
+ }
+ else
+ symbol_addr = module->func_ptrs[func_index];
+#else
symbol_addr = module->func_ptrs[func_index];
+#endif
}
+#if defined(BH_PLATFORM_WINDOWS) && defined(BUILD_TARGET_X86_32)
+ /* AOT function name starts with '_' in windows x86-32 */
+ else if (!strncmp(symbol, "_" AOT_FUNC_PREFIX,
+ strlen("_" AOT_FUNC_PREFIX))) {
+ p = symbol + strlen("_" AOT_FUNC_PREFIX);
+ if (*p == '\0'
+ || (func_index = (uint32)atoi(p)) > module->func_count) {
+ set_error_buf_v(error_buf, error_buf_size, "invalid symbol %s",
+ symbol);
+ goto check_symbol_fail;
+ }
+ symbol_addr = module->func_ptrs[func_index];
+ }
+#endif
else if (!strcmp(symbol, ".text")) {
symbol_addr = module->code;
}
@@ -1956,7 +2065,14 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
/* ".rodata.cst4/8/16/.." */
|| !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst"))
/* ".rodata.strn.m" */
- || !strncmp(symbol, ".rodata.str", strlen(".rodata.str"))) {
+ || !strncmp(symbol, ".rodata.str", strlen(".rodata.str"))
+ || !strcmp(symbol, AOT_STACK_SIZES_SECTION_NAME)
+#if WASM_ENABLE_STATIC_PGO != 0
+ || !strncmp(symbol, "__llvm_prf_cnts", 15)
+ || !strncmp(symbol, "__llvm_prf_data", 15)
+ || !strncmp(symbol, "__llvm_prf_names", 16)
+#endif
+ ) {
symbol_addr = get_data_section_addr(module, symbol, NULL);
if (!symbol_addr) {
set_error_buf_v(error_buf, error_buf_size,
@@ -2088,6 +2204,14 @@ do_data_relocation(AOTModule *module, AOTRelocationGroup *group,
else if (!strcmp(group->section_name, ".rdata")) {
data_section_name = group->section_name;
}
+#if WASM_ENABLE_STATIC_PGO != 0
+ else if (!strncmp(group->section_name, ".rel__llvm_prf_data", 19)) {
+ data_section_name = group->section_name + strlen(".rel");
+ }
+ else if (!strncmp(group->section_name, ".rela__llvm_prf_data", 20)) {
+ data_section_name = group->section_name + strlen(".rela");
+ }
+#endif
else {
set_error_buf(error_buf, error_buf_size,
"invalid data relocation section name");
@@ -2107,6 +2231,49 @@ do_data_relocation(AOTModule *module, AOTRelocationGroup *group,
if (!strcmp(symbol, ".text")) {
symbol_addr = module->code;
}
+#if WASM_ENABLE_STATIC_PGO != 0
+ else if (!strncmp(symbol, AOT_FUNC_PREFIX, strlen(AOT_FUNC_PREFIX))) {
+ char *p = symbol + strlen(AOT_FUNC_PREFIX);
+ uint32 func_index;
+ if (*p == '\0'
+ || (func_index = (uint32)atoi(p)) > module->func_count) {
+ set_error_buf_v(error_buf, error_buf_size,
+ "invalid relocation symbol %s", symbol);
+ return false;
+ }
+ symbol_addr = module->func_ptrs[func_index];
+ }
+ else if (!strcmp(symbol, "__llvm_prf_cnts")) {
+ uint32 j;
+ for (j = 0; j < module->data_section_count; j++) {
+ if (!strncmp(module->data_sections[j].name, symbol, 15)) {
+ bh_assert(relocation->relocation_addend + sizeof(uint64)
+ <= module->data_sections[j].size);
+ symbol_addr = module->data_sections[j].data;
+ break;
+ }
+ }
+ if (j == module->data_section_count) {
+ set_error_buf_v(error_buf, error_buf_size,
+ "invalid relocation symbol %s", symbol);
+ return false;
+ }
+ }
+ else if (!strncmp(symbol, "__llvm_prf_cnts", 15)) {
+ uint32 j;
+ for (j = 0; j < module->data_section_count; j++) {
+ if (!strcmp(module->data_sections[j].name, symbol)) {
+ symbol_addr = module->data_sections[j].data;
+ break;
+ }
+ }
+ if (j == module->data_section_count) {
+ set_error_buf_v(error_buf, error_buf_size,
+ "invalid relocation symbol %s", symbol);
+ return false;
+ }
+ }
+#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
else {
set_error_buf_v(error_buf, error_buf_size,
"invalid relocation symbol %s", symbol);
@@ -2154,7 +2321,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
{
AOTRelocationGroup *groups = NULL, *group;
uint32 symbol_count = 0;
- uint32 group_count = 0, i, j;
+ uint32 group_count = 0, i, j, got_item_count = 0;
uint64 size;
uint32 *symbol_offsets, total_string_len;
uint8 *symbol_buf, *symbol_buf_end;
@@ -2216,6 +2383,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
for (j = 0; j < relocation_count; j++) {
AOTRelocation relocation = { 0 };
+ char group_name_buf[128] = { 0 };
+ char symbol_name_buf[128] = { 0 };
uint32 symbol_index, offset32;
int32 addend32;
uint16 symbol_name_len;
@@ -2244,10 +2413,10 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
symbol_name_len = *(uint16 *)symbol_name;
symbol_name += sizeof(uint16);
- char group_name_buf[128] = { 0 };
- char symbol_name_buf[128] = { 0 };
- memcpy(group_name_buf, group_name, group_name_len);
- memcpy(symbol_name_buf, symbol_name, symbol_name_len);
+ bh_memcpy_s(group_name_buf, (uint32)sizeof(group_name_buf),
+ group_name, group_name_len);
+ bh_memcpy_s(symbol_name_buf, (uint32)sizeof(symbol_name_buf),
+ symbol_name, symbol_name_len);
if ((group_name_len == strlen(".text")
|| (module->is_indirect_mode
@@ -2301,7 +2470,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
if (size > UINT32_MAX
|| !(module->extra_plt_data =
- os_mmap(NULL, (uint32)size, map_prot, map_flags))) {
+ os_mmap(NULL, (uint32)size, map_prot, map_flags,
+ os_get_invalid_handle()))) {
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
goto fail;
}
@@ -2309,6 +2479,140 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
}
#endif /* end of defined(BH_PLATFORM_WINDOWS) */
+#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \
+ && !defined(BH_PLATFORM_WINDOWS)
+ buf = symbol_buf_end;
+ read_uint32(buf, buf_end, group_count);
+
+ /* Resolve the relocations of type R_X86_64_GOTPCREL */
+ for (i = 0; i < group_count; i++) {
+ uint32 name_index, relocation_count;
+ uint16 group_name_len;
+ uint8 *group_name;
+
+ /* section name address is 4 bytes aligned. */
+ buf = (uint8 *)align_ptr(buf, sizeof(uint32));
+ read_uint32(buf, buf_end, name_index);
+
+ if (name_index >= symbol_count) {
+ set_error_buf(error_buf, error_buf_size,
+ "symbol index out of range");
+ goto fail;
+ }
+
+ group_name = symbol_buf + symbol_offsets[name_index];
+ group_name_len = *(uint16 *)group_name;
+ group_name += sizeof(uint16);
+
+ read_uint32(buf, buf_end, relocation_count);
+
+ for (j = 0; j < relocation_count; j++) {
+ AOTRelocation relocation = { 0 };
+ char group_name_buf[128] = { 0 };
+ char symbol_name_buf[128] = { 0 };
+ uint32 symbol_index;
+ uint16 symbol_name_len;
+ uint8 *symbol_name;
+
+ /* relocation offset and addend */
+ buf += sizeof(void *) * 2;
+
+ read_uint32(buf, buf_end, relocation.relocation_type);
+ read_uint32(buf, buf_end, symbol_index);
+
+ if (symbol_index >= symbol_count) {
+ set_error_buf(error_buf, error_buf_size,
+ "symbol index out of range");
+ goto fail;
+ }
+
+ symbol_name = symbol_buf + symbol_offsets[symbol_index];
+ symbol_name_len = *(uint16 *)symbol_name;
+ symbol_name += sizeof(uint16);
+
+ bh_memcpy_s(group_name_buf, (uint32)sizeof(group_name_buf),
+ group_name, group_name_len);
+ bh_memcpy_s(symbol_name_buf, (uint32)sizeof(symbol_name_buf),
+ symbol_name, symbol_name_len);
+
+ if (relocation.relocation_type == R_X86_64_GOTPCREL
+ && !strncmp(symbol_name_buf, AOT_FUNC_PREFIX,
+ strlen(AOT_FUNC_PREFIX))) {
+ uint32 func_idx =
+ atoi(symbol_name_buf + strlen(AOT_FUNC_PREFIX));
+ GOTItem *got_item = module->got_item_list;
+
+ if (func_idx >= module->func_count) {
+ set_error_buf(error_buf, error_buf_size,
+ "func index out of range");
+ goto fail;
+ }
+
+ while (got_item) {
+ if (got_item->func_idx == func_idx)
+ break;
+ got_item = got_item->next;
+ }
+
+ if (!got_item) {
+ /* Create the got item and append to the list */
+ got_item = wasm_runtime_malloc(sizeof(GOTItem));
+ if (!got_item) {
+ set_error_buf(error_buf, error_buf_size,
+ "allocate memory failed");
+ goto fail;
+ }
+
+ got_item->func_idx = func_idx;
+ got_item->next = NULL;
+ if (!module->got_item_list) {
+ module->got_item_list = module->got_item_list_end =
+ got_item;
+ }
+ else {
+ module->got_item_list_end->next = got_item;
+ module->got_item_list_end = got_item;
+ }
+
+ got_item_count++;
+ }
+ }
+ }
+ }
+
+ if (got_item_count) {
+ GOTItem *got_item = module->got_item_list;
+ uint32 got_item_idx = 0;
+
+ map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE;
+ /* aot code and data in x86_64 must be in range 0 to 2G due to
+ relocation for R_X86_64_32/32S/PC32 */
+ map_flags = MMAP_MAP_32BIT;
+
+ /* Create the GOT for func_ptrs, note that it is different from
+ the .got section of a dynamic object file */
+ size = (uint64)sizeof(void *) * got_item_count;
+ if (size > UINT32_MAX
+ || !(module->got_func_ptrs =
+ os_mmap(NULL, (uint32)size, map_prot, map_flags,
+ os_get_invalid_handle()))) {
+ set_error_buf(error_buf, error_buf_size, "mmap memory failed");
+ goto fail;
+ }
+
+ while (got_item) {
+ module->got_func_ptrs[got_item_idx++] =
+ module->func_ptrs[got_item->func_idx];
+ got_item = got_item->next;
+ }
+
+ module->got_item_count = got_item_count;
+ }
+#else
+ (void)got_item_count;
+#endif /* (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) && \
+ !defined(BH_PLATFORM_WINDOWS) */
+
buf = symbol_buf_end;
read_uint32(buf, buf_end, group_count);
@@ -2653,6 +2957,7 @@ create_module(char *error_buf, uint32 error_buf_size)
{
AOTModule *module =
loader_malloc(sizeof(AOTModule), error_buf, error_buf_size);
+ bh_list_status ret;
if (!module) {
return NULL;
@@ -2660,6 +2965,13 @@ create_module(char *error_buf, uint32 error_buf_size)
module->module_type = Wasm_Module_AoT;
+#if WASM_ENABLE_MULTI_MODULE != 0
+ module->import_module_list = &module->import_module_list_head;
+ ret = bh_list_init(module->import_module_list);
+ bh_assert(ret == BH_LIST_SUCCESS);
+#endif
+ (void)ret;
+
return module;
}
@@ -2750,6 +3062,9 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
uint32 section_size;
uint64 total_size;
uint8 *aot_text;
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ uint8 *mirrored_text;
+#endif
if (!resolve_execute_mode(buf, size, &is_indirect_mode, error_buf,
error_buf_size)) {
@@ -2793,8 +3108,9 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
(uint64)section_size + aot_get_plt_table_size();
total_size = (total_size + 3) & ~((uint64)3);
if (total_size >= UINT32_MAX
- || !(aot_text = os_mmap(NULL, (uint32)total_size,
- map_prot, map_flags))) {
+ || !(aot_text =
+ os_mmap(NULL, (uint32)total_size, map_prot,
+ map_flags, os_get_invalid_handle()))) {
wasm_runtime_free(section);
set_error_buf(error_buf, error_buf_size,
"mmap memory failed");
@@ -2808,8 +3124,17 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
bh_assert((uintptr_t)aot_text < INT32_MAX);
#endif
#endif
+
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ mirrored_text = os_get_dbus_mirror(aot_text);
+ bh_assert(mirrored_text != NULL);
+ bh_memcpy_s(mirrored_text, (uint32)total_size,
+ section->section_body, (uint32)section_size);
+ os_dcache_flush();
+#else
bh_memcpy_s(aot_text, (uint32)total_size,
section->section_body, (uint32)section_size);
+#endif
section->section_body = aot_text;
destroy_aot_text = true;
@@ -2889,6 +3214,16 @@ load(const uint8 *buf, uint32 size, AOTModule *module, char *error_buf,
module->code and will be destroyed in aot_unload() */
destroy_sections(section_list, false);
}
+
+#if 0
+ {
+ uint32 i;
+ for (i = 0; i < module->func_count; i++) {
+ os_printf("AOT func %u, addr: %p\n", i, module->func_ptrs[i]);
+ }
+ }
+#endif
+
return ret;
fail:
return false;
@@ -2903,10 +3238,13 @@ aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf,
if (!module)
return NULL;
+ os_thread_jit_write_protect_np(false); /* Make memory writable */
if (!load(buf, size, module, error_buf, error_buf_size)) {
aot_unload(module);
return NULL;
}
+ os_thread_jit_write_protect_np(true); /* Make memory executable */
+ os_icache_flush(module->code, module->code_size);
LOG_VERBOSE("Load module success.\n");
return module;
@@ -2961,6 +3299,19 @@ aot_unload(AOTModule *module)
if (module->const_str_set)
bh_hash_map_destroy(module->const_str_set);
+#if WASM_ENABLE_MULTI_MODULE != 0
+ /* just release the sub module list */
+ if (module->import_module_list) {
+ WASMRegisteredModule *node =
+ bh_list_first_elem(module->import_module_list);
+ while (node) {
+ WASMRegisteredModule *next = bh_list_elem_next(node);
+ bh_list_remove(module->import_module_list, node);
+ wasm_runtime_free(node);
+ node = next;
+ }
+ }
+#endif
if (module->code && !module->is_indirect_mode) {
/* The layout is: literal size + literal + code (with plt table) */
@@ -2976,17 +3327,27 @@ aot_unload(AOTModule *module)
}
#endif
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- if (module->rtl_func_table) {
- if (module->rtl_func_table_registered)
- RtlDeleteFunctionTable(module->rtl_func_table);
- wasm_runtime_free(module->rtl_func_table);
+#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \
+ && !defined(BH_PLATFORM_WINDOWS)
+ {
+ GOTItem *got_item = module->got_item_list, *got_item_next;
+
+ if (module->got_func_ptrs) {
+ os_munmap(module->got_func_ptrs,
+ sizeof(void *) * module->got_item_count);
+ }
+ while (got_item) {
+ got_item_next = got_item->next;
+ wasm_runtime_free(got_item);
+ got_item = got_item_next;
+ }
}
#endif
if (module->data_sections)
destroy_object_data_sections(module->data_sections,
module->data_section_count);
+
#if WASM_ENABLE_DEBUG_AOT != 0
jit_code_entry_destroy(module->elf_hdr);
#endif
@@ -3033,3 +3394,23 @@ aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len)
return NULL;
}
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION */
+
+#if WASM_ENABLE_STATIC_PGO != 0
+void
+aot_exchange_uint16(uint8 *p_data)
+{
+ return exchange_uint16(p_data);
+}
+
+void
+aot_exchange_uint32(uint8 *p_data)
+{
+ return exchange_uint32(p_data);
+}
+
+void
+aot_exchange_uint64(uint8 *p_data)
+{
+ return exchange_uint64(p_data);
+}
+#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_reloc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_reloc.h
similarity index 95%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_reloc.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_reloc.h
index 9f5c2d57fd8..98df09cb4f2 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_reloc.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_reloc.h
@@ -121,6 +121,14 @@ typedef struct {
REG_SYM(aot_intrinsic_i32_rem_s), \
REG_SYM(aot_intrinsic_i32_rem_u), \
+#if WASM_ENABLE_STATIC_PGO != 0
+#define REG_LLVM_PGO_SYM() \
+ { "__llvm_profile_instrument_target", llvm_profile_instrument_target }, \
+ { "__llvm_profile_instrument_memop", llvm_profile_instrument_memop },
+#else
+#define REG_LLVM_PGO_SYM()
+#endif
+
#define REG_COMMON_SYMBOLS \
REG_SYM(aot_set_exception_with_id), \
REG_SYM(aot_invoke_native), \
@@ -150,6 +158,7 @@ typedef struct {
REG_REF_TYPES_SYM() \
REG_AOT_TRACE_SYM() \
REG_INTRINSIC_SYM() \
+ REG_LLVM_PGO_SYM() \
#define CHECK_RELOC_OFFSET(data_size) do { \
if (!check_reloc_offset(target_section_size, \
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.c
similarity index 73%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.c
index b5c406b960d..076574cb737 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.c
@@ -7,6 +7,7 @@
#include "bh_log.h"
#include "mem_alloc.h"
#include "../common/wasm_runtime_common.h"
+#include "../common/wasm_memory.h"
#include "../interpreter/wasm_runtime.h"
#if WASM_ENABLE_SHARED_MEMORY != 0
#include "../common/wasm_shared_memory.h"
@@ -42,6 +43,11 @@ bh_static_assert(offsetof(AOTModuleInstance, cur_exception)
bh_static_assert(offsetof(AOTModuleInstance, global_table_data)
== 13 * sizeof(uint64) + 128 + 11 * sizeof(uint64));
+bh_static_assert(sizeof(AOTMemoryInstance) == 104);
+bh_static_assert(offsetof(AOTTableInstance, elems) == 8);
+
+bh_static_assert(offsetof(AOTModuleInstanceExtra, stack_sizes) == 0);
+
static void
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
{
@@ -334,11 +340,8 @@ memories_deinstantiate(AOTModuleInstance *module_inst)
memory_inst = module_inst->memories[i];
if (memory_inst) {
#if WASM_ENABLE_SHARED_MEMORY != 0
- if (memory_inst->is_shared) {
- int32 ref_count = shared_memory_dec_reference(
- (WASMModuleCommon *)module_inst->module);
- bh_assert(ref_count >= 0);
-
+ if (shared_memory_is_shared(memory_inst)) {
+ uint32 ref_count = shared_memory_dec_reference(memory_inst);
/* if the reference count is not zero,
don't free the memory */
if (ref_count > 0)
@@ -368,9 +371,10 @@ memories_deinstantiate(AOTModuleInstance *module_inst)
}
static AOTMemoryInstance *
-memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
- AOTMemoryInstance *memory_inst, AOTMemory *memory,
- uint32 heap_size, char *error_buf, uint32 error_buf_size)
+memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
+ AOTModule *module, AOTMemoryInstance *memory_inst,
+ AOTMemory *memory, uint32 memory_idx, uint32 heap_size,
+ char *error_buf, uint32 error_buf_size)
{
void *heap_handle;
uint32 num_bytes_per_page = memory->num_bytes_per_page;
@@ -379,7 +383,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
uint32 inc_page_count, aux_heap_base, global_idx;
uint32 bytes_of_last_page, bytes_to_page_end;
uint32 heap_offset = num_bytes_per_page * init_page_count;
- uint64 total_size;
+ uint64 memory_data_size, max_memory_data_size;
uint8 *p = NULL, *global_addr;
#ifdef OS_ENABLE_HW_BOUND_CHECK
uint8 *mapped_mem;
@@ -391,23 +395,13 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
bool is_shared_memory = memory->memory_flags & 0x02 ? true : false;
/* Shared memory */
- if (is_shared_memory) {
+ if (is_shared_memory && parent != NULL) {
AOTMemoryInstance *shared_memory_instance;
- WASMSharedMemNode *node =
- wasm_module_get_shared_memory((WASMModuleCommon *)module);
- /* If the memory of this module has been instantiated,
- return the memory instance directly */
- if (node) {
- uint32 ref_count;
- ref_count = shared_memory_inc_reference((WASMModuleCommon *)module);
- bh_assert(ref_count > 0);
- shared_memory_instance =
- (AOTMemoryInstance *)shared_memory_get_memory_inst(node);
- bh_assert(shared_memory_instance);
-
- (void)ref_count;
- return shared_memory_instance;
- }
+ bh_assert(memory_idx == 0);
+ bh_assert(parent->memory_count > memory_idx);
+ shared_memory_instance = parent->memories[memory_idx];
+ shared_memory_inc_reference(shared_memory_instance);
+ return shared_memory_instance;
}
#endif
@@ -427,7 +421,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
if (num_bytes_per_page < heap_size) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
- "try using `--heap_size=0` option");
+ "try using `--heap-size=0` option");
return NULL;
}
}
@@ -485,7 +479,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
if (init_page_count > DEFAULT_MAX_PAGES) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
- "try using `--heap_size=0` option");
+ "try using `--heap-size=0` option");
return NULL;
}
else if (init_page_count == DEFAULT_MAX_PAGES) {
@@ -495,6 +489,12 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
if (max_page_count > DEFAULT_MAX_PAGES)
max_page_count = DEFAULT_MAX_PAGES;
}
+ else { /* heap_size == 0 */
+ if (init_page_count == DEFAULT_MAX_PAGES) {
+ num_bytes_per_page = UINT32_MAX;
+ init_page_count = max_page_count = 1;
+ }
+ }
LOG_VERBOSE("Memory instantiate:");
LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u",
@@ -503,67 +503,80 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
module->aux_stack_size);
LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size);
- total_size = (uint64)num_bytes_per_page * init_page_count;
+ memory_data_size = (uint64)num_bytes_per_page * init_page_count;
+ max_memory_data_size = (uint64)num_bytes_per_page * max_page_count;
+ bh_assert(memory_data_size <= UINT32_MAX);
+ bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB);
+ (void)max_memory_data_size;
+
+#ifndef OS_ENABLE_HW_BOUND_CHECK
#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
- /* Allocate max page for shared memory */
- total_size = (uint64)num_bytes_per_page * max_page_count;
+ /* 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;
+ }
}
+ else
#endif
- bh_assert(total_size <= UINT32_MAX);
-
-#ifndef OS_ENABLE_HW_BOUND_CHECK
- /* Allocate memory */
- if (total_size > 0
- && !(p = runtime_malloc(total_size, error_buf, error_buf_size))) {
- return NULL;
+ {
+ /* Allocate initial memory size when memory is not shared */
+ if (memory_data_size > 0
+ && !(p = runtime_malloc(memory_data_size, error_buf,
+ error_buf_size))) {
+ return NULL;
+ }
}
-#else
- total_size = (total_size + page_size - 1) & ~(page_size - 1);
+#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))) {
+ if (!(p = 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");
return NULL;
}
#ifdef BH_PLATFORM_WINDOWS
- if (!os_mem_commit(p, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE)) {
+ 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, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) {
+ 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, total_size);
+ 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 */
-#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
- if (total_size > UINT32_MAX)
- total_size = UINT32_MAX;
+ 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;
memory_inst->num_bytes_per_page = num_bytes_per_page;
memory_inst->cur_page_count = init_page_count;
memory_inst->max_page_count = max_page_count;
- memory_inst->memory_data_size = (uint32)total_size;
+ memory_inst->memory_data_size = (uint32)memory_data_size;
/* Init memory info */
memory_inst->memory_data = p;
- memory_inst->memory_data_end = p + (uint32)total_size;
+ memory_inst->memory_data_end = p + (uint32)memory_data_size;
/* Initialize heap info */
memory_inst->heap_data = p + heap_offset;
@@ -586,41 +599,19 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
}
}
- if (total_size > 0) {
-#if UINTPTR_MAX == UINT64_MAX
- memory_inst->mem_bound_check_1byte.u64 = total_size - 1;
- memory_inst->mem_bound_check_2bytes.u64 = total_size - 2;
- memory_inst->mem_bound_check_4bytes.u64 = total_size - 4;
- memory_inst->mem_bound_check_8bytes.u64 = total_size - 8;
- memory_inst->mem_bound_check_16bytes.u64 = total_size - 16;
-#else
- memory_inst->mem_bound_check_1byte.u32[0] = (uint32)total_size - 1;
- memory_inst->mem_bound_check_2bytes.u32[0] = (uint32)total_size - 2;
- memory_inst->mem_bound_check_4bytes.u32[0] = (uint32)total_size - 4;
- memory_inst->mem_bound_check_8bytes.u32[0] = (uint32)total_size - 8;
- memory_inst->mem_bound_check_16bytes.u32[0] = (uint32)total_size - 16;
-#endif
+ if (memory_data_size > 0) {
+ wasm_runtime_set_mem_bound_check_bytes(memory_inst, memory_data_size);
}
#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
- memory_inst->is_shared = true;
- if (!shared_memory_set_memory_inst(
- (WASMModuleCommon *)module,
- (WASMMemoryInstanceCommon *)memory_inst)) {
- set_error_buf(error_buf, error_buf_size, "allocate memory failed");
- goto fail3;
- }
+ memory_inst->is_shared_memory = 1;
+ memory_inst->ref_count = 1;
}
#endif
return memory_inst;
-#if WASM_ENABLE_SHARED_MEMORY != 0
-fail3:
- if (heap_size > 0)
- mem_allocator_destroy(memory_inst->heap_handle);
-#endif
fail2:
if (heap_size > 0)
wasm_runtime_free(memory_inst->heap_handle);
@@ -631,7 +622,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
#else
#ifdef BH_PLATFORM_WINDOWS
if (memory_inst->memory_data)
- os_mem_decommit(p, total_size);
+ os_mem_decommit(p, memory_data_size);
#endif
os_munmap(mapped_mem, map_size);
#endif
@@ -649,8 +640,9 @@ aot_get_default_memory(AOTModuleInstance *module_inst)
}
static bool
-memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
- uint32 heap_size, char *error_buf, uint32 error_buf_size)
+memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
+ AOTModule *module, uint32 heap_size, char *error_buf,
+ uint32 error_buf_size)
{
uint32 global_index, global_data_offset, base_offset, length;
uint32 i, memory_count = module->memory_count;
@@ -667,8 +659,8 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
memories = module_inst->global_table_data.memory_instances;
for (i = 0; i < memory_count; i++, memories++) {
- memory_inst = memory_instantiate(module_inst, module, memories,
- &module->memories[i], heap_size,
+ memory_inst = memory_instantiate(module_inst, parent, module, memories,
+ &module->memories[i], i, heap_size,
error_buf, error_buf_size);
if (!memory_inst) {
return false;
@@ -690,6 +682,10 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
if (data_seg->is_passive)
continue;
#endif
+ if (parent != NULL)
+ /* Ignore setting memory init data if the memory has been
+ initialized */
+ continue;
bh_assert(data_seg->offset.init_expr_type == INIT_EXPR_TYPE_I32_CONST
|| data_seg->offset.init_expr_type
@@ -986,7 +982,8 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst,
wasm functions, and ensure that the exec_env's module inst
is the correct one. */
module_inst_main = exec_env_main->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(exec_env,
+ (WASMModuleInstanceCommon *)module_inst);
}
else {
/* Try using the existing exec_env */
@@ -1011,10 +1008,20 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst,
module inst to ensure that the exec_env's module inst
is the correct one. */
module_inst_main = exec_env->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(
+ exec_env, (WASMModuleInstanceCommon *)module_inst);
}
}
+#if defined(os_writegsbase)
+ {
+ AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
+ if (memory_inst)
+ /* write base addr of linear memory to GS segment register */
+ os_writegsbase(memory_inst->memory_data);
+ }
+#endif
+
/* Execute start function for both main insance and sub instance */
if (module->start_function) {
AOTFunctionInstance start_func = { 0 };
@@ -1052,12 +1059,12 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst,
fail:
if (is_sub_inst) {
/* Restore the parent exec_env's module inst */
- exec_env_main->module_inst = module_inst_main;
+ wasm_exec_env_restore_module_inst(exec_env_main, module_inst_main);
}
else {
if (module_inst_main)
/* Restore the existing exec_env's module inst */
- exec_env->module_inst = module_inst_main;
+ wasm_exec_env_restore_module_inst(exec_env, module_inst_main);
if (exec_env_created)
wasm_exec_env_destroy(exec_env_created);
}
@@ -1086,11 +1093,14 @@ check_linked_symbol(AOTModule *module, char *error_buf, uint32 error_buf_size)
}
AOTModuleInstance *
-aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
- uint32 stack_size, uint32 heap_size, char *error_buf,
- uint32 error_buf_size)
+aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
+ WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
+ char *error_buf, uint32 error_buf_size)
{
AOTModuleInstance *module_inst;
+#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_REF_TYPES != 0
+ WASMModuleInstanceExtraCommon *common;
+#endif
const uint32 module_inst_struct_size =
offsetof(AOTModuleInstance, global_table_data.bytes);
const uint64 module_inst_mem_inst_size =
@@ -1098,6 +1108,10 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
uint64 total_size, table_size = 0;
uint8 *p;
uint32 i, extra_info_offset;
+ const bool is_sub_inst = parent != NULL;
+#if WASM_ENABLE_MULTI_MODULE != 0
+ bool ret = false;
+#endif
/* Check heap size */
heap_size = align_uint(heap_size, 8);
@@ -1141,6 +1155,44 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
module_inst->e =
(WASMModuleInstanceExtra *)((uint8 *)module_inst + extra_info_offset);
+#if WASM_ENABLE_MULTI_MODULE != 0
+ ((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list =
+ &((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list_head;
+ ret = wasm_runtime_sub_module_instantiate(
+ (WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
+ stack_size, heap_size, error_buf, error_buf_size);
+ if (!ret) {
+ LOG_DEBUG("build a sub module list failed");
+ goto fail;
+ }
+#endif
+
+#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_REF_TYPES != 0
+ common = &((AOTModuleInstanceExtra *)module_inst->e)->common;
+#endif
+#if WASM_ENABLE_BULK_MEMORY != 0
+ if (module->mem_init_data_count > 0) {
+ common->data_dropped = bh_bitmap_new(0, module->mem_init_data_count);
+ if (common->data_dropped == NULL) {
+ LOG_DEBUG("failed to allocate bitmaps");
+ set_error_buf(error_buf, error_buf_size,
+ "failed to allocate bitmaps");
+ goto fail;
+ }
+ }
+#endif
+#if WASM_ENABLE_REF_TYPES != 0
+ if (module->table_init_data_count > 0) {
+ common->elem_dropped = bh_bitmap_new(0, module->table_init_data_count);
+ if (common->elem_dropped == NULL) {
+ LOG_DEBUG("failed to allocate bitmaps");
+ set_error_buf(error_buf, error_buf_size,
+ "failed to allocate bitmaps");
+ goto fail;
+ }
+ }
+#endif
+
/* Initialize global info */
p = (uint8 *)module_inst + module_inst_struct_size
+ module_inst_mem_inst_size;
@@ -1157,7 +1209,7 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
goto fail;
/* Initialize memory space */
- if (!memories_instantiate(module_inst, module, heap_size, error_buf,
+ if (!memories_instantiate(module_inst, parent, module, heap_size, error_buf,
error_buf_size))
goto fail;
@@ -1192,17 +1244,6 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
}
#endif
-#if WASM_ENABLE_WASI_NN != 0
- if (!is_sub_inst) {
- if (!(((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx =
- wasi_nn_initialize())) {
- set_error_buf(error_buf, error_buf_size,
- "wasi nn initialization failed");
- goto fail;
- }
- }
-#endif
-
/* Initialize the thread related data */
if (stack_size == 0)
stack_size = DEFAULT_WASM_STACK_SIZE;
@@ -1212,6 +1253,9 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
#endif
module_inst->default_wasm_stack_size = stack_size;
+ ((AOTModuleInstanceExtra *)module_inst->e)->stack_sizes =
+ aot_get_data_section_addr(module, AOT_STACK_SIZES_SECTION_NAME, NULL);
+
#if WASM_ENABLE_PERF_PROFILING != 0
total_size = (uint64)sizeof(AOTFuncPerfProfInfo)
* (module->import_func_count + module->func_count);
@@ -1249,6 +1293,8 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
void
aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
{
+ WASMModuleInstanceExtraCommon *common =
+ &((AOTModuleInstanceExtra *)module_inst->e)->common;
if (module_inst->exec_env_singleton) {
/* wasm_exec_env_destroy will call
wasm_cluster_wait_for_all_except_self to wait for other
@@ -1258,16 +1304,6 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
wasm_exec_env_destroy((WASMExecEnv *)module_inst->exec_env_singleton);
}
-#if WASM_ENABLE_LIBC_WASI != 0
- /* Destroy wasi resource before freeing app heap, since some fields of
- wasi contex are allocated from app heap, and if app heap is freed,
- these fields will be set to NULL, we cannot free their internal data
- which may allocated from global heap. */
- /* Only destroy wasi ctx in the main module instance */
- if (!is_sub_inst)
- wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst);
-#endif
-
#if WASM_ENABLE_PERF_PROFILING != 0
if (module_inst->func_perf_profilings)
wasm_runtime_free(module_inst->func_perf_profilings);
@@ -1281,6 +1317,11 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
}
#endif
+#if WASM_ENABLE_MULTI_MODULE != 0
+ wasm_runtime_sub_module_deinstantiate(
+ (WASMModuleInstanceCommon *)module_inst);
+#endif
+
if (module_inst->tables)
wasm_runtime_free(module_inst->tables);
@@ -1296,17 +1337,22 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
if (module_inst->func_type_indexes)
wasm_runtime_free(module_inst->func_type_indexes);
- if (((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports)
- wasm_runtime_free(
- ((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports);
+ if (common->c_api_func_imports)
+ wasm_runtime_free(((AOTModuleInstanceExtra *)module_inst->e)
+ ->common.c_api_func_imports);
-#if WASM_ENABLE_WASI_NN != 0
if (!is_sub_inst) {
- WASINNContext *wasi_nn_ctx =
- ((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx;
- if (wasi_nn_ctx)
- wasi_nn_destroy(wasi_nn_ctx);
+#if WASM_ENABLE_WASI_NN != 0
+ wasi_nn_destroy(module_inst);
+#endif
+ wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
}
+
+#if WASM_ENABLE_BULK_MEMORY != 0
+ bh_bitmap_delete(common->data_dropped);
+#endif
+#if WASM_ENABLE_REF_TYPES != 0
+ bh_bitmap_delete(common->elem_dropped);
#endif
wasm_runtime_free(module_inst);
@@ -1438,10 +1484,43 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
unsigned argc, uint32 argv[])
{
AOTModuleInstance *module_inst = (AOTModuleInstance *)exec_env->module_inst;
- AOTFuncType *func_type = function->u.func.func_type;
+ AOTFuncType *func_type = function->is_import_func
+ ? function->u.func_import->func_type
+ : function->u.func.func_type;
uint32 result_count = func_type->result_count;
uint32 ext_ret_count = result_count > 1 ? result_count - 1 : 0;
bool ret;
+ void *func_ptr = function->is_import_func
+ ? function->u.func_import->func_ptr_linked
+ : function->u.func.func_ptr;
+#if WASM_ENABLE_MULTI_MODULE != 0
+ bh_list *sub_module_list_node = NULL;
+ const char *sub_inst_name = NULL;
+ const char *func_name = function->u.func_import->module_name;
+ if (function->is_import_func) {
+ sub_module_list_node =
+ ((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list;
+ sub_module_list_node = bh_list_first_elem(sub_module_list_node);
+ while (sub_module_list_node) {
+ sub_inst_name =
+ ((AOTSubModInstNode *)sub_module_list_node)->module_name;
+ if (strcmp(sub_inst_name, func_name) == 0) {
+ exec_env = wasm_runtime_get_exec_env_singleton(
+ (WASMModuleInstanceCommon *)((AOTSubModInstNode *)
+ sub_module_list_node)
+ ->module_inst);
+ module_inst = (AOTModuleInstance *)exec_env->module_inst;
+ break;
+ }
+ sub_module_list_node = bh_list_elem_next(sub_module_list_node);
+ }
+ if (exec_env == NULL) {
+ wasm_runtime_set_exception((WASMModuleInstanceCommon *)module_inst,
+ "create singleton exec_env failed");
+ return false;
+ }
+ }
+#endif
if (argc < func_type->param_cell_num) {
char buf[108];
@@ -1453,12 +1532,23 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
}
argc = func_type->param_cell_num;
- /* func pointer was looked up previously */
- bh_assert(function->u.func.func_ptr != NULL);
+#if defined(os_writegsbase)
+ {
+ AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
+ if (memory_inst)
+ /* write base addr of linear memory to GS segment register */
+ os_writegsbase(memory_inst->memory_data);
+ }
+#endif
+ /* func pointer was looked up previously */
+ bh_assert(func_ptr != NULL);
/* set thread handle and stack boundary */
wasm_exec_env_set_thread_info(exec_env);
+ /* set exec env so it can be later retrieved from instance */
+ ((AOTModuleInstanceExtra *)module_inst->e)->common.cur_exec_env = exec_env;
+
if (ext_ret_count > 0) {
uint32 cell_num = 0, i;
uint8 *ext_ret_types = func_type->types + func_type->param_count + 1;
@@ -1561,8 +1651,8 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
}
#endif
- ret = invoke_native_internal(exec_env, function->u.func.func_ptr,
- func_type, NULL, NULL, argv, argc, argv);
+ ret = invoke_native_internal(exec_env, func_ptr, func_type, NULL, NULL,
+ argv, argc, argv);
#if WASM_ENABLE_DUMP_CALL_STACK != 0
if (aot_copy_exception(module_inst, NULL)) {
@@ -1663,7 +1753,8 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
module inst to ensure that the exec_env's module inst
is the correct one. */
module_inst_old = exec_env->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(
+ exec_env, (WASMModuleInstanceCommon *)module_inst);
}
}
@@ -1674,7 +1765,7 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
if (module_inst_old)
/* Restore the existing exec_env's module inst */
- exec_env->module_inst = module_inst_old;
+ wasm_exec_env_restore_module_inst(exec_env, module_inst_old);
if (exec_env_created)
wasm_exec_env_destroy(exec_env_created);
@@ -1730,7 +1821,8 @@ execute_free_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
module inst to ensure that the exec_env's module inst
is the correct one. */
module_inst_old = exec_env->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(
+ exec_env, (WASMModuleInstanceCommon *)module_inst);
}
}
@@ -1738,7 +1830,7 @@ execute_free_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
if (module_inst_old)
/* Restore the existing exec_env's module inst */
- exec_env->module_inst = module_inst_old;
+ wasm_exec_env_restore_module_inst(exec_env, module_inst_old);
if (exec_env_created)
wasm_exec_env_destroy(exec_env_created);
@@ -1860,6 +1952,13 @@ aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
if (ptr) {
uint8 *addr = memory_inst->memory_data + ptr;
+ uint8 *memory_data_end;
+
+ /* memory->memory_data_end may be changed in memory grow */
+ SHARED_MEMORY_LOCK(memory_inst);
+ memory_data_end = memory_inst->memory_data_end;
+ SHARED_MEMORY_UNLOCK(memory_inst);
+
if (memory_inst->heap_handle && memory_inst->heap_data < addr
&& addr < memory_inst->heap_data_end) {
mem_allocator_free(memory_inst->heap_handle, addr);
@@ -1867,7 +1966,7 @@ aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
else if (module->malloc_func_index != (uint32)-1
&& module->free_func_index != (uint32)-1
&& memory_inst->memory_data <= addr
- && addr < memory_inst->memory_data_end) {
+ && addr < memory_data_end) {
AOTFunctionInstance *free_func;
char *free_func_name;
@@ -1941,8 +2040,8 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
AOTModuleInstanceExtra *module_inst_extra =
(AOTModuleInstanceExtra *)module_inst->e;
CApiFuncImport *c_api_func_import =
- module_inst_extra->c_api_func_imports
- ? module_inst_extra->c_api_func_imports + func_idx
+ module_inst_extra->common.c_api_func_imports
+ ? module_inst_extra->common.c_api_func_imports + func_idx
: NULL;
uint32 *func_type_indexes = module_inst->func_type_indexes;
uint32 func_type_idx = func_type_indexes[func_idx];
@@ -1954,7 +2053,10 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
void *attachment;
char buf[96];
bool ret = false;
-
+#if WASM_ENABLE_MULTI_MODULE != 0
+ bh_list *sub_module_list_node = NULL;
+ const char *sub_inst_name = NULL;
+#endif
bh_assert(func_idx < aot_module->import_func_count);
import_func = aot_module->import_funcs + func_idx;
@@ -1978,6 +2080,28 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
}
else if (!import_func->call_conv_raw) {
signature = import_func->signature;
+#if WASM_ENABLE_MULTI_MODULE != 0
+ sub_module_list_node =
+ ((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list;
+ sub_module_list_node = bh_list_first_elem(sub_module_list_node);
+ while (sub_module_list_node) {
+ sub_inst_name =
+ ((AOTSubModInstNode *)sub_module_list_node)->module_name;
+ if (strcmp(sub_inst_name, import_func->module_name) == 0) {
+ exec_env = wasm_runtime_get_exec_env_singleton(
+ (WASMModuleInstanceCommon *)((AOTSubModInstNode *)
+ sub_module_list_node)
+ ->module_inst);
+ break;
+ }
+ sub_module_list_node = bh_list_elem_next(sub_module_list_node);
+ }
+ if (exec_env == NULL) {
+ wasm_runtime_set_exception((WASMModuleInstanceCommon *)module_inst,
+ "create singleton exec_env failed");
+ goto fail;
+ }
+#endif
ret =
wasm_runtime_invoke_native(exec_env, func_ptr, func_type, signature,
attachment, argv, argc, argv);
@@ -2216,13 +2340,21 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
{
AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst);
AOTModule *aot_module;
- uint8 *data = NULL;
+ uint8 *data;
uint8 *maddr;
- uint64 seg_len = 0;
+ uint64 seg_len;
- aot_module = (AOTModule *)module_inst->module;
- seg_len = aot_module->mem_init_data_list[seg_index]->byte_count;
- data = aot_module->mem_init_data_list[seg_index]->bytes;
+ if (bh_bitmap_get_bit(
+ ((AOTModuleInstanceExtra *)module_inst->e)->common.data_dropped,
+ seg_index)) {
+ seg_len = 0;
+ data = NULL;
+ }
+ else {
+ aot_module = (AOTModule *)module_inst->module;
+ seg_len = aot_module->mem_init_data_list[seg_index]->byte_count;
+ data = aot_module->mem_init_data_list[seg_index]->bytes;
+ }
if (!wasm_runtime_validate_app_addr((WASMModuleInstanceCommon *)module_inst,
dst, len))
@@ -2236,16 +2368,18 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
maddr = wasm_runtime_addr_app_to_native(
(WASMModuleInstanceCommon *)module_inst, dst);
+ SHARED_MEMORY_LOCK(memory_inst);
bh_memcpy_s(maddr, memory_inst->memory_data_size - dst, data + offset, len);
+ SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}
bool
aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index)
{
- AOTModule *aot_module = (AOTModule *)module_inst->module;
-
- aot_module->mem_init_data_list[seg_index]->byte_count = 0;
+ bh_bitmap_set_bit(
+ ((AOTModuleInstanceExtra *)module_inst->e)->common.data_dropped,
+ seg_index);
/* Currently we can't free the dropped data segment
as the mem_init_data_count is a continuous array */
return true;
@@ -2458,9 +2592,9 @@ aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst,
void
aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx)
{
- AOTModule *module = (AOTModule *)module_inst->module;
- AOTTableInitData *tbl_seg = module->table_init_data_list[tbl_seg_idx];
- tbl_seg->is_dropped = true;
+ bh_bitmap_set_bit(
+ ((AOTModuleInstanceExtra *)module_inst->e)->common.elem_dropped,
+ tbl_seg_idx);
}
void
@@ -2478,17 +2612,19 @@ aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
tbl_seg = module->table_init_data_list[tbl_seg_idx];
bh_assert(tbl_seg);
- if (!length) {
+ if (offset_len_out_of_bounds(src_offset, length, tbl_seg->func_index_count)
+ || 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;
}
- if (length + src_offset > tbl_seg->func_index_count
- || dst_offset + length > tbl_inst->cur_size) {
- aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
+ if (!length) {
return;
}
- if (tbl_seg->is_dropped) {
+ 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;
}
@@ -2517,8 +2653,9 @@ aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
dst_tbl_inst = module_inst->tables[dst_tbl_idx];
bh_assert(dst_tbl_inst);
- if ((uint64)dst_offset + length > dst_tbl_inst->cur_size
- || (uint64)src_offset + length > src_tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(dst_offset, length, dst_tbl_inst->cur_size)
+ || offset_len_out_of_bounds(src_offset, length,
+ src_tbl_inst->cur_size)) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
@@ -2543,7 +2680,7 @@ aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
tbl_inst = module_inst->tables[tbl_idx];
bh_assert(tbl_inst);
- if (data_offset + length > tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(data_offset, length, tbl_inst->cur_size)) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
@@ -2744,6 +2881,7 @@ aot_create_call_stack(struct WASMExecEnv *exec_env)
total_len += \
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
if ((!print) && buf && (len == 0)) { \
+ exception_unlock(module_inst); \
return total_len; \
} \
} while (0)
@@ -2766,6 +2904,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
return 0;
}
+ exception_lock(module_inst);
snprintf(line_buf, sizeof(line_buf), "\n");
PRINT_OR_DUMP();
@@ -2774,17 +2913,20 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
uint32 line_length, i;
if (!bh_vector_get(module_inst->frames, n, &frame)) {
+ exception_unlock(module_inst);
return 0;
}
/* function name not exported, print number instead */
if (frame.func_name_wp == NULL) {
- line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n",
- n, frame.func_index);
+ line_length =
+ snprintf(line_buf, sizeof(line_buf),
+ "#%02" PRIu32 " $f%" PRIu32 "\n", n, frame.func_index);
}
else {
- line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
- frame.func_name_wp);
+ line_length =
+ snprintf(line_buf, sizeof(line_buf), "#%02" PRIu32 " %s\n", n,
+ frame.func_name_wp);
}
if (line_length >= sizeof(line_buf)) {
@@ -2802,6 +2944,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
}
snprintf(line_buf, sizeof(line_buf), "\n");
PRINT_OR_DUMP();
+ exception_unlock(module_inst);
return total_len + 1;
}
@@ -2822,15 +2965,534 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst)
func_name = get_func_name_from_index(module_inst, i);
if (func_name)
- os_printf(" func %s, execution time: %.3f ms, execution count: %d "
- "times\n",
- func_name, perf_prof->total_exec_time / 1000.0f,
- perf_prof->total_exec_cnt);
+ os_printf(
+ " func %s, execution time: %.3f ms, execution count: %" PRIu32
+ " times\n",
+ func_name, perf_prof->total_exec_time / 1000.0f,
+ perf_prof->total_exec_cnt);
else
- os_printf(" func %d, execution time: %.3f ms, execution count: %d "
- "times\n",
+ os_printf(" func %" PRIu32
+ ", execution time: %.3f ms, execution count: %" PRIu32
+ " times\n",
i, perf_prof->total_exec_time / 1000.0f,
perf_prof->total_exec_cnt);
}
}
#endif /* end of WASM_ENABLE_PERF_PROFILING */
+
+#if WASM_ENABLE_STATIC_PGO != 0
+
+/* indirect call target */
+#define IPVK_IndirectCallTarget 0
+/* memory intrinsic functions size */
+#define IPVK_MemOPSize 1
+#define IPVK_First IPVK_IndirectCallTarget
+#define IPVK_Last IPVK_MemOPSize
+
+#define INSTR_PROF_DEFAULT_NUM_VAL_PER_SITE 24
+#define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255
+
+static int hasNonDefaultValsPerSite = 0;
+static uint32 VPMaxNumValsPerSite = INSTR_PROF_DEFAULT_NUM_VAL_PER_SITE;
+
+static bool
+cmpxchg_ptr(void **ptr, void *old_val, void *new_val)
+{
+#if defined(os_atomic_cmpxchg)
+ return os_atomic_cmpxchg(ptr, &old_val, new_val);
+#else
+ /* TODO: add lock when thread-manager is enabled */
+ void *read = *ptr;
+ if (read == old_val) {
+ *ptr = new_val;
+ return true;
+ }
+ return false;
+#endif
+}
+
+static int
+allocateValueProfileCounters(LLVMProfileData *Data)
+{
+ ValueProfNode **Mem;
+ uint64 NumVSites = 0, total_size;
+ uint32 VKI;
+
+ /* When dynamic allocation is enabled, allow tracking the max number of
+ values allowed. */
+ if (!hasNonDefaultValsPerSite)
+ VPMaxNumValsPerSite = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
+
+ for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
+ NumVSites += Data->num_value_sites[VKI];
+
+ /* If NumVSites = 0, calloc is allowed to return a non-null pointer. */
+ bh_assert(NumVSites > 0 && "NumVSites can't be zero");
+
+ total_size = (uint64)sizeof(ValueProfNode *) * NumVSites;
+ if (total_size > UINT32_MAX
+ || !(Mem = (ValueProfNode **)wasm_runtime_malloc((uint32)total_size))) {
+ return 0;
+ }
+ memset(Mem, 0, (uint32)total_size);
+
+ if (!cmpxchg_ptr((void **)&Data->values, NULL, Mem)) {
+ wasm_runtime_free(Mem);
+ return 0;
+ }
+ return 1;
+}
+
+static ValueProfNode *
+allocateOneNode(void)
+{
+ ValueProfNode *Node;
+
+ Node = wasm_runtime_malloc((uint32)sizeof(ValueProfNode));
+ if (Node)
+ memset(Node, 0, sizeof(ValueProfNode));
+ return Node;
+}
+
+static void
+instrumentTargetValueImpl(uint64 TargetValue, void *Data, uint32 CounterIndex,
+ uint64 CountValue)
+{
+ ValueProfNode **ValueCounters;
+ ValueProfNode *PrevVNode = NULL, *MinCountVNode = NULL, *CurVNode;
+ LLVMProfileData *PData = (LLVMProfileData *)Data;
+ uint64 MinCount = UINT64_MAX;
+ uint8 VDataCount = 0;
+ bool success = false;
+
+ if (!PData)
+ return;
+ if (!CountValue)
+ return;
+ if (!PData->values) {
+ if (!allocateValueProfileCounters(PData))
+ return;
+ }
+
+ ValueCounters = (ValueProfNode **)PData->values;
+ CurVNode = ValueCounters[CounterIndex];
+
+ while (CurVNode) {
+ if (TargetValue == CurVNode->value) {
+ CurVNode->count += CountValue;
+ return;
+ }
+ if (CurVNode->count < MinCount) {
+ MinCount = CurVNode->count;
+ MinCountVNode = CurVNode;
+ }
+ PrevVNode = CurVNode;
+ CurVNode = CurVNode->next;
+ ++VDataCount;
+ }
+
+ if (VDataCount >= VPMaxNumValsPerSite) {
+ if (MinCountVNode->count <= CountValue) {
+ CurVNode = MinCountVNode;
+ CurVNode->value = TargetValue;
+ CurVNode->count = CountValue;
+ }
+ else
+ MinCountVNode->count -= CountValue;
+
+ return;
+ }
+
+ CurVNode = allocateOneNode();
+ if (!CurVNode)
+ return;
+ CurVNode->value = TargetValue;
+ CurVNode->count += CountValue;
+
+ if (!ValueCounters[CounterIndex]) {
+ success =
+ cmpxchg_ptr((void **)&ValueCounters[CounterIndex], NULL, CurVNode);
+ }
+ else if (PrevVNode && !PrevVNode->next) {
+ success = cmpxchg_ptr((void **)&PrevVNode->next, 0, CurVNode);
+ }
+
+ if (!success) {
+ wasm_runtime_free(CurVNode);
+ }
+}
+
+void
+llvm_profile_instrument_target(uint64 target_value, void *data,
+ uint32 counter_idx)
+{
+ instrumentTargetValueImpl(target_value, data, counter_idx, 1);
+}
+
+static inline uint32
+popcount64(uint64 u)
+{
+ uint32 ret = 0;
+ while (u) {
+ u = (u & (u - 1));
+ ret++;
+ }
+ return ret;
+}
+
+static inline uint32
+clz64(uint64 type)
+{
+ uint32 num = 0;
+ if (type == 0)
+ return 64;
+ while (!(type & 0x8000000000000000LL)) {
+ num++;
+ type <<= 1;
+ }
+ return num;
+}
+
+/* Map an (observed) memop size value to the representative value of its range.
+ For example, 5 -> 5, 22 -> 17, 99 -> 65, 256 -> 256, 1001 -> 513. */
+static uint64
+InstrProfGetRangeRepValue(uint64 Value)
+{
+ if (Value <= 8)
+ /* The first ranges are individually tracked. Use the value as is. */
+ return Value;
+ else if (Value >= 513)
+ /* The last range is mapped to its lowest value. */
+ return 513;
+ else if (popcount64(Value) == 1)
+ /* If it's a power of two, use it as is. */
+ return Value;
+ else
+ /* Otherwise, take to the previous power of two + 1. */
+ return (((uint64)1) << (64 - clz64(Value) - 1)) + 1;
+}
+
+void
+llvm_profile_instrument_memop(uint64 target_value, void *data,
+ uint32 counter_idx)
+{
+ uint64 rep_value = InstrProfGetRangeRepValue(target_value);
+ instrumentTargetValueImpl(rep_value, data, counter_idx, 1);
+}
+
+static uint32
+get_pgo_prof_data_size(AOTModuleInstance *module_inst, uint32 *p_num_prof_data,
+ uint32 *p_num_prof_counters, uint32 *p_padding_size,
+ uint32 *p_prof_counters_size, uint32 *p_prof_names_size,
+ uint32 *p_value_counters_size, uint8 **p_prof_names)
+{
+ AOTModule *module = (AOTModule *)module_inst->module;
+ LLVMProfileData *prof_data;
+ uint8 *prof_names = NULL;
+ uint32 num_prof_data = 0, num_prof_counters = 0, padding_size, i;
+ uint32 prof_counters_size = 0, prof_names_size = 0;
+ uint32 total_size, total_size_wo_value_counters;
+
+ for (i = 0; i < module->data_section_count; i++) {
+ if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) {
+ bh_assert(module->data_sections[i].size == sizeof(LLVMProfileData));
+ num_prof_data++;
+ prof_data = (LLVMProfileData *)module->data_sections[i].data;
+ num_prof_counters += prof_data->num_counters;
+ }
+ else if (!strncmp(module->data_sections[i].name, "__llvm_prf_cnts",
+ 15)) {
+ prof_counters_size += module->data_sections[i].size;
+ }
+ else if (!strncmp(module->data_sections[i].name, "__llvm_prf_names",
+ 16)) {
+ prof_names_size = module->data_sections[i].size;
+ prof_names = module->data_sections[i].data;
+ }
+ }
+
+ if (prof_counters_size != num_prof_counters * sizeof(uint64))
+ return 0;
+
+ total_size = sizeof(LLVMProfileRawHeader)
+ + num_prof_data * sizeof(LLVMProfileData_64)
+ + prof_counters_size + prof_names_size;
+ padding_size = sizeof(uint64) - (prof_names_size % sizeof(uint64));
+ if (padding_size != sizeof(uint64))
+ total_size += padding_size;
+
+ /* Total size excluding value counters */
+ total_size_wo_value_counters = total_size;
+
+ for (i = 0; i < module->data_section_count; i++) {
+ if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) {
+ uint32 j, k, num_value_sites, num_value_nodes;
+ ValueProfNode **values, *value_node;
+
+ prof_data = (LLVMProfileData *)module->data_sections[i].data;
+ values = prof_data->values;
+
+ if (prof_data->num_value_sites[0] > 0
+ || prof_data->num_value_sites[1] > 0) {
+ /* TotalSize (uint32) and NumValueKinds (uint32) */
+ total_size += 8;
+ for (j = 0; j < 2; j++) {
+ if ((num_value_sites = prof_data->num_value_sites[j]) > 0) {
+ /* ValueKind (uint32) and NumValueSites (uint32) */
+ total_size += 8;
+ /* (Value + Counter) group counts of each value site,
+ each count is one byte */
+ total_size += align_uint(num_value_sites, 8);
+
+ if (values) {
+ for (k = 0; k < num_value_sites; k++) {
+ num_value_nodes = 0;
+ value_node = *values;
+ while (value_node) {
+ num_value_nodes++;
+ value_node = value_node->next;
+ }
+ if (num_value_nodes) {
+ /* (Value + Counter) groups */
+ total_size += num_value_nodes * 8 * 2;
+ }
+ values++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (p_num_prof_data)
+ *p_num_prof_data = num_prof_data;
+ if (p_num_prof_counters)
+ *p_num_prof_counters = num_prof_counters;
+ if (p_padding_size)
+ *p_padding_size = padding_size;
+ if (p_prof_counters_size)
+ *p_prof_counters_size = prof_counters_size;
+ if (p_prof_names_size)
+ *p_prof_names_size = prof_names_size;
+ if (p_value_counters_size)
+ *p_value_counters_size = total_size - total_size_wo_value_counters;
+ if (p_prof_names)
+ *p_prof_names = prof_names;
+
+ return total_size;
+}
+
+uint32
+aot_get_pgo_prof_data_size(AOTModuleInstance *module_inst)
+{
+ return get_pgo_prof_data_size(module_inst, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL);
+}
+
+static union {
+ int a;
+ char b;
+} __ue = { .a = 1 };
+
+#define is_little_endian() (__ue.b == 1)
+
+uint32
+aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf,
+ uint32 len)
+{
+ AOTModule *module = (AOTModule *)module_inst->module;
+ LLVMProfileRawHeader prof_header = { 0 };
+ LLVMProfileData *prof_data;
+ uint8 *prof_names = NULL;
+ uint32 num_prof_data = 0, num_prof_counters = 0, padding_size, i;
+ uint32 prof_counters_size = 0, prof_names_size = 0;
+ uint32 value_counters_size = 0, value_counters_size_backup = 0;
+ uint32 total_size, size;
+ int64 counters_delta, offset_counters;
+
+ total_size = get_pgo_prof_data_size(module_inst, &num_prof_data,
+ &num_prof_counters, &padding_size,
+ &prof_counters_size, &prof_names_size,
+ &value_counters_size, &prof_names);
+ if (len < total_size)
+ return 0;
+
+ value_counters_size_backup = value_counters_size;
+ value_counters_size = 0;
+
+ prof_header.counters_delta = counters_delta =
+ sizeof(LLVMProfileData_64) * num_prof_data;
+ offset_counters = 0;
+ for (i = 0; i < module->data_section_count; i++) {
+ if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) {
+ prof_data = (LLVMProfileData *)module->data_sections[i].data;
+ prof_data->offset_counters = counters_delta + offset_counters;
+ offset_counters += prof_data->num_counters * sizeof(uint64);
+ counters_delta -= sizeof(LLVMProfileData_64);
+ }
+ }
+
+ prof_header.magic = 0xFF6C70726F667281LL;
+ /* Version 8 */
+ prof_header.version = 0x0000000000000008LL;
+ /* with VARIANT_MASK_IR_PROF (IR Instrumentation) */
+ prof_header.version |= 0x1ULL << 56;
+ /* with VARIANT_MASK_MEMPROF (Memory Profile) */
+ prof_header.version |= 0x1ULL << 62;
+ prof_header.num_prof_data = num_prof_data;
+ prof_header.num_prof_counters = num_prof_counters;
+ prof_header.names_size = prof_names_size;
+ prof_header.value_kind_last = 1;
+
+ if (!is_little_endian()) {
+ aot_exchange_uint64((uint8 *)&prof_header.magic);
+ aot_exchange_uint64((uint8 *)&prof_header.version);
+ aot_exchange_uint64((uint8 *)&prof_header.num_prof_data);
+ aot_exchange_uint64((uint8 *)&prof_header.num_prof_counters);
+ aot_exchange_uint64((uint8 *)&prof_header.names_size);
+ aot_exchange_uint64((uint8 *)&prof_header.counters_delta);
+ aot_exchange_uint64((uint8 *)&prof_header.value_kind_last);
+ }
+
+ size = sizeof(LLVMProfileRawHeader);
+ bh_memcpy_s(buf, size, &prof_header, size);
+ buf += size;
+
+ for (i = 0; i < module->data_section_count; i++) {
+ if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) {
+ LLVMProfileData_64 *prof_data_64 = (LLVMProfileData_64 *)buf;
+
+ /* Convert LLVMProfileData to LLVMProfileData_64, the pointer width
+ in the output file is alawys 8 bytes */
+ prof_data = (LLVMProfileData *)module->data_sections[i].data;
+ prof_data_64->func_md5 = prof_data->func_md5;
+ prof_data_64->func_hash = prof_data->func_hash;
+ prof_data_64->offset_counters = prof_data->offset_counters;
+ prof_data_64->func_ptr = prof_data->func_ptr;
+ prof_data_64->values = (uint64)(uintptr_t)prof_data->values;
+ prof_data_64->num_counters = prof_data->num_counters;
+ prof_data_64->num_value_sites[0] = prof_data->num_value_sites[0];
+ prof_data_64->num_value_sites[1] = prof_data->num_value_sites[1];
+
+ if (!is_little_endian()) {
+ aot_exchange_uint64((uint8 *)&prof_data_64->func_hash);
+ aot_exchange_uint64((uint8 *)&prof_data_64->offset_counters);
+ aot_exchange_uint64((uint8 *)&prof_data_64->offset_counters);
+ aot_exchange_uint64((uint8 *)&prof_data_64->func_ptr);
+ aot_exchange_uint64((uint8 *)&prof_data_64->values);
+ aot_exchange_uint32((uint8 *)&prof_data_64->num_counters);
+ aot_exchange_uint16((uint8 *)&prof_data_64->num_value_sites[0]);
+ aot_exchange_uint16((uint8 *)&prof_data_64->num_value_sites[1]);
+ }
+ buf += sizeof(LLVMProfileData_64);
+ }
+ }
+
+ for (i = 0; i < module->data_section_count; i++) {
+ if (!strncmp(module->data_sections[i].name, "__llvm_prf_cnts", 15)) {
+ size = module->data_sections[i].size;
+ bh_memcpy_s(buf, size, module->data_sections[i].data, size);
+ buf += size;
+ }
+ }
+
+ if (prof_names && prof_names_size > 0) {
+ size = prof_names_size;
+ bh_memcpy_s(buf, size, prof_names, size);
+ buf += size;
+ padding_size = sizeof(uint64) - (prof_names_size % sizeof(uint64));
+ if (padding_size != sizeof(uint64)) {
+ char padding_buf[8] = { 0 };
+ bh_memcpy_s(buf, padding_size, padding_buf, padding_size);
+ buf += padding_size;
+ }
+ }
+
+ for (i = 0; i < module->data_section_count; i++) {
+ if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) {
+ uint32 j, k, num_value_sites, num_value_nodes;
+ ValueProfNode **values, **values_tmp, *value_node;
+
+ prof_data = (LLVMProfileData *)module->data_sections[i].data;
+ values = values_tmp = prof_data->values;
+
+ if (prof_data->num_value_sites[0] > 0
+ || prof_data->num_value_sites[1] > 0) {
+ uint32 *buf_total_size = (uint32 *)buf;
+
+ buf += 4; /* emit TotalSize later */
+ *(uint32 *)buf = (prof_data->num_value_sites[0] > 0
+ && prof_data->num_value_sites[1] > 0)
+ ? 2
+ : 1;
+ if (!is_little_endian())
+ aot_exchange_uint32((uint8 *)buf);
+ buf += 4;
+
+ for (j = 0; j < 2; j++) {
+ if ((num_value_sites = prof_data->num_value_sites[j]) > 0) {
+ /* ValueKind */
+ *(uint32 *)buf = j;
+ if (!is_little_endian())
+ aot_exchange_uint32((uint8 *)buf);
+ buf += 4;
+ /* NumValueSites */
+ *(uint32 *)buf = num_value_sites;
+ if (!is_little_endian())
+ aot_exchange_uint32((uint8 *)buf);
+ buf += 4;
+
+ for (k = 0; k < num_value_sites; k++) {
+ num_value_nodes = 0;
+ if (values_tmp) {
+ value_node = *values_tmp;
+ while (value_node) {
+ num_value_nodes++;
+ value_node = value_node->next;
+ }
+ values_tmp++;
+ }
+ bh_assert(num_value_nodes < 255);
+ *(uint8 *)buf++ = (uint8)num_value_nodes;
+ }
+ if (num_value_sites % 8) {
+ buf += 8 - (num_value_sites % 8);
+ }
+
+ for (k = 0; k < num_value_sites; k++) {
+ if (values) {
+ value_node = *values;
+ while (value_node) {
+ *(uint64 *)buf = value_node->value;
+ if (!is_little_endian())
+ aot_exchange_uint64((uint8 *)buf);
+ buf += 8;
+ *(uint64 *)buf = value_node->count;
+ if (!is_little_endian())
+ aot_exchange_uint64((uint8 *)buf);
+ buf += 8;
+ value_node = value_node->next;
+ }
+ values++;
+ }
+ }
+ }
+ }
+
+ /* TotalSize */
+ *(uint32 *)buf_total_size =
+ (uint8 *)buf - (uint8 *)buf_total_size;
+ if (!is_little_endian())
+ aot_exchange_uint64((uint8 *)buf_total_size);
+ value_counters_size += (uint8 *)buf - (uint8 *)buf_total_size;
+ }
+ }
+ }
+
+ bh_assert(value_counters_size == value_counters_size_backup);
+ (void)value_counters_size_backup;
+
+ return total_size;
+}
+#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.h
similarity index 80%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.h
index bcd06534e6e..35c78bfa082 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.h
@@ -41,6 +41,10 @@ typedef struct AOTObjectDataSection {
char *name;
uint8 *data;
uint32 size;
+#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
+ bool is_name_allocated;
+ bool is_data_allocated;
+#endif
} AOTObjectDataSection;
/* Relocation info */
@@ -51,6 +55,9 @@ typedef struct AOTRelocation {
char *symbol_name;
/* index in the symbol offset field */
uint32 symbol_index;
+#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
+ bool is_symbol_name_allocated;
+#endif
} AOTRelocation;
/* Relocation Group */
@@ -60,6 +67,9 @@ typedef struct AOTRelocationGroup {
uint32 name_index;
uint32 relocation_count;
AOTRelocation *relocations;
+#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
+ bool is_section_name_allocated;
+#endif
} AOTRelocationGroup;
/* AOT function instance */
@@ -78,34 +88,19 @@ typedef struct AOTFunctionInstance {
} AOTFunctionInstance;
typedef struct AOTModuleInstanceExtra {
- CApiFuncImport *c_api_func_imports;
-#if WASM_ENABLE_WASI_NN != 0
- WASINNContext *wasi_nn_ctx;
+ DefPointer(const uint32 *, stack_sizes);
+ WASMModuleInstanceExtraCommon common;
+#if WASM_ENABLE_MULTI_MODULE != 0
+ bh_list sub_module_inst_list_head;
+ bh_list *sub_module_inst_list;
#endif
} AOTModuleInstanceExtra;
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
-/* clang-format off */
-typedef struct AOTUnwindInfo {
- uint8 Version : 3;
- uint8 Flags : 5;
- uint8 SizeOfProlog;
- uint8 CountOfCodes;
- uint8 FrameRegister : 4;
- uint8 FrameOffset : 4;
- struct {
- struct {
- uint8 CodeOffset;
- uint8 UnwindOp : 4;
- uint8 OpInfo : 4;
- };
- uint16 FrameOffset;
- } UnwindCode[1];
-} AOTUnwindInfo;
-/* clang-format on */
-
-/* size of mov instruction and jmp instruction */
-#define PLT_ITEM_SIZE 12
+#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
+typedef struct GOTItem {
+ uint32 func_idx;
+ struct GOTItem *next;
+} GOTItem, *GOTItemList;
#endif
typedef struct AOTModule {
@@ -196,12 +191,11 @@ typedef struct AOTModule {
uint32 float_plt_count;
#endif
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- /* dynamic function table to be added by RtlAddFunctionTable(),
- used to unwind the call stack and register exception handler
- for AOT functions */
- RUNTIME_FUNCTION *rtl_func_table;
- bool rtl_func_table_registered;
+#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
+ uint32 got_item_count;
+ GOTItemList got_item_list;
+ GOTItemList got_item_list_end;
+ void **got_func_ptrs;
#endif
/* data sections in AOT object file, including .data, .rodata
@@ -239,6 +233,12 @@ typedef struct AOTModule {
WASIArguments wasi_args;
bool import_wasi_api;
#endif
+
+#if WASM_ENABLE_MULTI_MODULE != 0
+ /* TODO: add mutex for mutli-thread? */
+ bh_list import_module_list_head;
+ bh_list *import_module_list;
+#endif
#if WASM_ENABLE_DEBUG_AOT != 0
void *elf_hdr;
uint32 elf_size;
@@ -257,6 +257,10 @@ typedef struct AOTModule {
#define AOTTableInstance WASMTableInstance
#define AOTModuleInstance WASMModuleInstance
+#if WASM_ENABLE_MULTI_MODULE != 0
+#define AOTSubModInstNode WASMSubModInstNode
+#endif
+
/* Target info, read from ELF header of object file */
typedef struct AOTTargetInfo {
/* Binary type, elf32l/elf32b/elf64l/elf64b */
@@ -294,6 +298,54 @@ typedef struct AOTFrame {
#endif
} AOTFrame;
+#if WASM_ENABLE_STATIC_PGO != 0
+typedef struct LLVMProfileRawHeader {
+ uint64 magic;
+ uint64 version;
+ uint64 binary_ids_size;
+ uint64 num_prof_data;
+ uint64 padding_bytes_before_counters;
+ uint64 num_prof_counters;
+ uint64 padding_bytes_after_counters;
+ uint64 names_size;
+ uint64 counters_delta;
+ uint64 names_delta;
+ uint64 value_kind_last;
+} LLVMProfileRawHeader;
+
+typedef struct ValueProfNode {
+ uint64 value;
+ uint64 count;
+ struct ValueProfNode *next;
+} ValueProfNode;
+
+/* The profiling data of data sections created by aot compiler and
+ used when profiling, the width of pointer can be 8 bytes (64-bit)
+ or 4 bytes (32-bit) */
+typedef struct LLVMProfileData {
+ uint64 func_md5;
+ uint64 func_hash;
+ uint64 offset_counters;
+ uintptr_t func_ptr;
+ ValueProfNode **values;
+ uint32 num_counters;
+ uint16 num_value_sites[2];
+} LLVMProfileData;
+
+/* The profiling data for writting to the output file, the width of
+ pointer is 8 bytes suppose we always use wamrc and llvm-profdata
+ with 64-bit mode */
+typedef struct LLVMProfileData_64 {
+ uint64 func_md5;
+ uint64 func_hash;
+ uint64 offset_counters;
+ uint64 func_ptr;
+ uint64 values;
+ uint32 num_counters;
+ uint16 num_value_sites[2];
+} LLVMProfileData_64;
+#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
+
/**
* Load a AOT module from aot file buffer
* @param buf the byte buffer which contains the AOT file data
@@ -332,7 +384,7 @@ aot_unload(AOTModule *module);
* Instantiate a AOT module.
*
* @param module the AOT module to instantiate
- * @param is_sub_inst the flag of sub instance
+ * @param parent the parent module instance
* @param heap_size the default heap size of the module instance, a heap will
* be created besides the app memory space. Both wasm app and native
* function can allocate memory from the heap. If heap_size is 0, the
@@ -343,9 +395,9 @@ aot_unload(AOTModule *module);
* @return return the instantiated AOT module instance, NULL if failed
*/
AOTModuleInstance *
-aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main,
- uint32 stack_size, uint32 heap_size, char *error_buf,
- uint32 error_buf_size);
+aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
+ WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
+ char *error_buf, uint32 error_buf_size);
/**
* Deinstantiate a AOT module instance, destroy the resources.
@@ -564,6 +616,36 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
const uint8 *
aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);
+const void *
+aot_get_data_section_addr(AOTModule *module, const char *section_name,
+ uint32 *p_data_size);
+
+#if WASM_ENABLE_STATIC_PGO != 0
+void
+llvm_profile_instrument_target(uint64 target_value, void *data,
+ uint32 counter_idx);
+
+void
+llvm_profile_instrument_memop(uint64 target_value, void *data,
+ uint32 counter_idx);
+
+uint32
+aot_get_pgo_prof_data_size(AOTModuleInstance *module_inst);
+
+uint32
+aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf,
+ uint32 len);
+
+void
+aot_exchange_uint16(uint8 *p_data);
+
+void
+aot_exchange_uint32(uint8 *p_data);
+
+void
+aot_exchange_uint64(uint8 *p_data);
+#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
+
#ifdef __cplusplus
} /* end of extern "C" */
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_aarch64.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_aarch64.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_aarch64.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_aarch64.c
index 4c46eaa003c..b4bb6024a47 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_aarch64.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_aarch64.c
@@ -53,7 +53,12 @@ get_target_symbol_map(uint32 *sym_num)
return target_sym_map;
}
+#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__)
+#define BUILD_TARGET_AARCH64_DEFAULT "arm64"
+#else
#define BUILD_TARGET_AARCH64_DEFAULT "aarch64v8"
+#endif
+
void
get_current_target(char *target_buf, uint32 target_buf_size)
{
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arc.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arc.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arm.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arm.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arm.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arm.c
index fbf9be13c86..5d79e8a68ac 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arm.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arm.c
@@ -40,6 +40,7 @@ void __aeabi_ldivmod();
void __aeabi_memcpy();
void __aeabi_memmove();
void __aeabi_memset();
+void __aeabi_memclr();
void __aeabi_uidiv();
void __aeabi_uidivmod();
void __aeabi_ul2d();
@@ -126,6 +127,7 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__aeabi_memcpy),
REG_SYM(__aeabi_memmove),
REG_SYM(__aeabi_memset),
+ REG_SYM(__aeabi_memclr),
REG_SYM(__aeabi_uidiv),
REG_SYM(__aeabi_uidivmod),
REG_SYM(__aeabi_ul2d),
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_mips.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_mips.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_mips.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_mips.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_riscv.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_riscv.c
similarity index 80%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_riscv.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_riscv.c
index 75fee56fda1..045cab6412c 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_riscv.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_riscv.c
@@ -9,6 +9,9 @@
#define R_RISCV_64 2
#define R_RISCV_CALL 18
#define R_RISCV_CALL_PLT 19
+#define R_RISCV_PCREL_HI20 23
+#define R_RISCV_PCREL_LO12_I 24
+#define R_RISCV_PCREL_LO12_S 25
#define R_RISCV_HI20 26
#define R_RISCV_LO12_I 27
#define R_RISCV_LO12_S 28
@@ -76,6 +79,13 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__addsf3),
REG_SYM(__divdf3),
REG_SYM(__divsf3),
+ REG_SYM(__eqdf2),
+ REG_SYM(__eqsf2),
+ REG_SYM(__extendsfdf2),
+ REG_SYM(__fixunsdfdi),
+ REG_SYM(__fixunsdfsi),
+ REG_SYM(__fixunssfdi),
+ REG_SYM(__fixunssfsi),
REG_SYM(__gedf2),
REG_SYM(__gesf2),
REG_SYM(__gtdf2),
@@ -87,44 +97,33 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__muldf3),
REG_SYM(__nedf2),
REG_SYM(__nesf2),
- REG_SYM(__eqsf2),
- REG_SYM(__eqdf2),
- REG_SYM(__extendsfdf2),
- REG_SYM(__fixunsdfdi),
- REG_SYM(__fixunsdfsi),
- REG_SYM(__fixunssfsi),
REG_SYM(__subdf3),
REG_SYM(__subsf3),
REG_SYM(__truncdfsf2),
REG_SYM(__unorddf2),
REG_SYM(__unordsf2),
-#endif
- REG_SYM(__divdi3),
- REG_SYM(__divsi3),
-#if __riscv_xlen == 32
+ REG_SYM(__mulsf3),
+ REG_SYM(__floatundidf),
REG_SYM(__fixdfdi),
+ REG_SYM(__floatsidf),
+ REG_SYM(__floatunsidf),
+#if __riscv_xlen == 32
REG_SYM(__fixdfsi),
REG_SYM(__fixsfdi),
REG_SYM(__fixsfsi),
-#endif
- REG_SYM(__fixunssfdi),
-#if __riscv_xlen == 32
REG_SYM(__floatdidf),
REG_SYM(__floatdisf),
REG_SYM(__floatsisf),
- REG_SYM(__floatsidf),
- REG_SYM(__floatundidf),
REG_SYM(__floatundisf),
REG_SYM(__floatunsisf),
- REG_SYM(__floatunsidf),
+ REG_SYM(__mulsi3),
#endif
+#endif
+ REG_SYM(__divdi3),
+ REG_SYM(__divsi3),
REG_SYM(__moddi3),
REG_SYM(__modsi3),
REG_SYM(__muldi3),
-#if __riscv_xlen == 32
- REG_SYM(__mulsf3),
- REG_SYM(__mulsi3),
-#endif
REG_SYM(__udivdi3),
REG_SYM(__udivsi3),
REG_SYM(__umoddi3),
@@ -179,7 +178,11 @@ rv_set_val(uint16 *addr, uint32 val)
*addr = (val & 0xffff);
*(addr + 1) = (val >> 16);
+#ifdef __riscv_zifencei
__asm__ volatile("fence.i");
+#else
+ __asm__ volatile("fence");
+#endif
}
/* Add a val to given address */
@@ -267,9 +270,11 @@ typedef struct RelocTypeStrMap {
}
static RelocTypeStrMap reloc_type_str_maps[] = {
- RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_CALL),
- RELOC_TYPE_MAP(R_RISCV_CALL_PLT), RELOC_TYPE_MAP(R_RISCV_HI20),
- RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S),
+ RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_64),
+ RELOC_TYPE_MAP(R_RISCV_CALL), RELOC_TYPE_MAP(R_RISCV_CALL_PLT),
+ RELOC_TYPE_MAP(R_RISCV_PCREL_HI20), RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_I),
+ RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_S), RELOC_TYPE_MAP(R_RISCV_HI20),
+ RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S),
};
static const char *
@@ -324,21 +329,37 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
rv_set_val((uint16 *)addr, val_32);
break;
}
+
+#if __riscv_xlen == 64
case R_RISCV_64:
{
uint64 val_64 =
- (uint64)((uintptr_t)symbol_addr + (intptr_t)reloc_addend);
+ (uint64)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
+
CHECK_RELOC_OFFSET(sizeof(uint64));
+ if (val_64
+ != (uint64)((intptr_t)symbol_addr + (intptr_t)reloc_addend)) {
+ goto fail_addr_out_of_range;
+ }
+
bh_memcpy_s(addr, 8, &val_64, 8);
+#ifdef __riscv_zifencei
+ __asm__ volatile("fence.i");
+#else
+ __asm__ volatile("fence");
+#endif
break;
}
+#endif
+
case R_RISCV_CALL:
case R_RISCV_CALL_PLT:
+ case R_RISCV_PCREL_HI20: /* S + A - P */
{
- val = (int32)(intptr_t)((uint8 *)symbol_addr - addr);
+ val = (int32)(intptr_t)((uint8 *)symbol_addr + reloc_addend - addr);
CHECK_RELOC_OFFSET(sizeof(uint32));
- if (val != (intptr_t)((uint8 *)symbol_addr - addr)) {
+ if (val != (intptr_t)((uint8 *)symbol_addr + reloc_addend - addr)) {
if (symbol_index >= 0) {
/* Call runtime function by plt code */
symbol_addr = (uint8 *)module->code + module->code_size
@@ -348,7 +369,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
}
}
- if (val != (intptr_t)((uint8 *)symbol_addr - addr)) {
+ if (val != (intptr_t)((uint8 *)symbol_addr + reloc_addend - addr)) {
goto fail_addr_out_of_range;
}
@@ -369,7 +390,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
break;
}
- case R_RISCV_HI20:
+ case R_RISCV_HI20: /* S + A */
{
val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
@@ -378,7 +399,6 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
goto fail_addr_out_of_range;
}
- addr = target_section_addr + reloc_offset;
insn = rv_get_val((uint16 *)addr);
rv_calc_imm(val, &imm_hi, &imm_lo);
insn = (insn & 0x00000fff) | (imm_hi << 12);
@@ -386,11 +406,42 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
break;
}
- case R_RISCV_LO12_I:
+ case R_RISCV_PCREL_LO12_I: /* S - P */
+ case R_RISCV_PCREL_LO12_S: /* S - P */
+ {
+ /* Already handled in R_RISCV_PCREL_HI20, it should be skipped for
+ * most cases. But it is still needed for some special cases, e.g.
+ * ```
+ * label:
+ * auipc t0, %pcrel_hi(symbol) # R_RISCV_PCREL_HI20 (symbol)
+ * lui t1, 1
+ * lw t2, t0, %pcrel_lo(label) # R_RISCV_PCREL_LO12_I (label)
+ * add t2, t2, t1
+ * sw t2, t0, %pcrel_lo(label) # R_RISCV_PCREL_LO12_S (label)
+ * ```
+ * In this case, the R_RISCV_PCREL_LO12_I/S relocation should be
+ * handled after R_RISCV_PCREL_HI20 relocation.
+ *
+ * So, if the R_RISCV_PCREL_LO12_I/S relocation is not followed by
+ * R_RISCV_PCREL_HI20 relocation, it should be handled here but
+ * not implemented yet.
+ */
+
+ if ((uintptr_t)addr - (uintptr_t)symbol_addr
+ - (uintptr_t)reloc_addend
+ != 4) {
+ goto fail_addr_out_of_range;
+ }
+ break;
+ }
+
+ case R_RISCV_LO12_I: /* S + A */
{
+
val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend);
CHECK_RELOC_OFFSET(sizeof(uint32));
+
if (val != (intptr_t)symbol_addr + (intptr_t)reloc_addend) {
goto fail_addr_out_of_range;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_thumb.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_thumb.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_thumb.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_thumb.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_32.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_32.c
similarity index 82%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_32.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_32.c
index af3e0bb8ef0..0a423c398c3 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_32.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_32.c
@@ -5,9 +5,19 @@
#include "aot_reloc.h"
+/* clang-format off */
+#if !defined(BH_PLATFORM_WINDOWS)
#define R_386_32 1 /* Direct 32 bit */
#define R_386_PC32 2 /* PC relative 32 bit */
#define R_386_PLT32 4 /* 32-bit address ProcedureLinkageTable */
+#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic
+ thread local data */
+#else
+#define IMAGE_REL_I386_DIR32 6 /* The target's 32-bit VA */
+#define IMAGE_REL_I386_REL32 20 /* The 32-bit relative displacement
+ to the target */
+#endif
+/* clang-format on */
#if !defined(_WIN32) && !defined(_WIN32_)
/* clang-format off */
@@ -45,6 +55,12 @@ __umoddi3(uint64 a, uint64 b)
}
#endif
+static uint64
+__aulldiv(uint64 a, uint64 b)
+{
+ return a / b;
+}
+
/* clang-format off */
static SymbolMap target_sym_map[] = {
REG_COMMON_SYMBOLS
@@ -52,7 +68,8 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__divdi3),
REG_SYM(__udivdi3),
REG_SYM(__moddi3),
- REG_SYM(__umoddi3)
+ REG_SYM(__umoddi3),
+ REG_SYM(__aulldiv)
};
/* clang-format on */
@@ -109,7 +126,14 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
int32 symbol_index, char *error_buf, uint32 error_buf_size)
{
switch (reloc_type) {
+#if !defined(BH_PLATFORM_WINDOWS)
case R_386_32:
+#if WASM_ENABLE_STATIC_PGO != 0
+ case R_386_TLS_GD_32:
+#endif
+#else
+ case IMAGE_REL_I386_DIR32:
+#endif
{
intptr_t value;
@@ -121,12 +145,16 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
break;
}
+#if !defined(BH_PLATFORM_WINDOWS)
/*
* Handle R_386_PLT32 like R_386_PC32 since it should be able to reach
* any 32 bit address
*/
case R_386_PLT32:
case R_386_PC32:
+#else
+ case IMAGE_REL_I386_REL32:
+#endif
{
int32 value;
@@ -136,6 +164,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
(uint32)((uintptr_t)symbol_addr + (intptr_t)reloc_addend
- (uintptr_t)(target_section_addr
+ (uint32)reloc_offset)
+#if defined(BH_PLATFORM_WINDOWS)
+ - sizeof(int32)
+#endif
+ value); /* S + A - P */
break;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_64.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_64.c
similarity index 89%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_64.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_64.c
index f4d8eeabd29..b5be2459322 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_64.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_64.c
@@ -6,11 +6,13 @@
#include "aot_reloc.h"
#if !defined(BH_PLATFORM_WINDOWS)
-#define R_X86_64_64 1 /* Direct 64 bit */
-#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
-#define R_X86_64_PLT32 4 /* 32 bit PLT address */
-#define R_X86_64_32 10 /* Direct 32 bit zero extended */
-#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
+#define R_X86_64_64 1 /* Direct 64 bit */
+#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
+#define R_X86_64_PLT32 4 /* 32 bit PLT address */
+#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
+#define R_X86_64_32 10 /* Direct 32 bit zero extended */
+#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
+#define R_X86_64_PC64 24 /* PC relative 64 bit */
#else
#ifndef IMAGE_REL_AMD64_ADDR64
#define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */
@@ -67,9 +69,6 @@ get_plt_table_size()
{
uint32 size =
get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- size += get_plt_item_size() + sizeof(AOTUnwindInfo);
-#endif
return size;
}
@@ -91,18 +90,6 @@ init_plt_table(uint8 *plt)
*p++ = 0xE0;
plt += get_plt_item_size();
}
-
-#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
- p = plt;
- /* mov exception_handler, rax */
- *p++ = 0x48;
- *p++ = 0xB8;
- *(uint64 *)p = 0; /*(uint64)(uintptr_t)aot_exception_handler;*/
- p += sizeof(uint64);
- /* jmp rax */
- *p++ = 0xFF;
- *p++ = 0xE0;
-#endif
}
static bool
@@ -164,6 +151,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
#endif
#if !defined(BH_PLATFORM_WINDOWS)
case R_X86_64_PC32:
+ case R_X86_64_GOTPCREL: /* GOT + G has been calculated as symbol_addr */
{
intptr_t target_addr = (intptr_t) /* S + A - P */
((uintptr_t)symbol_addr + reloc_addend
@@ -182,6 +170,16 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
break;
}
+ case R_X86_64_PC64:
+ {
+ intptr_t target_addr = (intptr_t) /* S + A - P */
+ ((uintptr_t)symbol_addr + reloc_addend
+ - (uintptr_t)(target_section_addr + reloc_offset));
+
+ CHECK_RELOC_OFFSET(sizeof(int64));
+ *(int64 *)(target_section_addr + reloc_offset) = (int64)target_addr;
+ break;
+ }
case R_X86_64_32:
case R_X86_64_32S:
{
@@ -229,7 +227,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
- (uintptr_t)(target_section_addr + reloc_offset));
}
else {
- target_addr = (intptr_t) /* L + A - P */
+ target_addr = (intptr_t) /* S + A - P */
((uintptr_t)symbol_addr + reloc_addend
- (uintptr_t)(target_section_addr + reloc_offset));
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_xtensa.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_xtensa.c
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_xtensa.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_xtensa.c
index 3327c396fb5..a29c9f2b9e8 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_xtensa.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_xtensa.c
@@ -43,6 +43,11 @@ void __floatdidf();
void __divsf3();
void __fixdfdi();
void __floatundidf();
+void __fixsfdi();
+void __fixunssfdi();
+void __fixunsdfdi();
+void __floatdisf();
+void __floatundisf();
static SymbolMap target_sym_map[] = {
@@ -85,6 +90,11 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__divsf3),
REG_SYM(__fixdfdi),
REG_SYM(__floatundidf),
+ REG_SYM(__fixsfdi),
+ REG_SYM(__fixunssfdi),
+ REG_SYM(__fixunsdfdi),
+ REG_SYM(__floatdisf),
+ REG_SYM(__floatundisf),
};
/* clang-format on */
@@ -207,6 +217,10 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
case R_XTENSA_32:
{
uint8 *insn_addr = target_section_addr + reloc_offset;
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ insn_addr = os_get_dbus_mirror((void *)insn_addr);
+ bh_assert(insn_addr != NULL);
+#endif
int32 initial_addend;
/* (S + A) */
if ((intptr_t)insn_addr & 3) {
@@ -265,6 +279,11 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
return false;
}
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ insn_addr = os_get_dbus_mirror((void *)insn_addr);
+ bh_assert(insn_addr != NULL);
+ l32r_insn = (l32r_insn_t *)insn_addr;
+#endif
imm16 = (int16)(relative_offset >> 2);
/* write back the imm16 to the l32r instruction */
@@ -285,7 +304,6 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
#if __GNUC__ >= 9
#pragma GCC diagnostic pop
#endif
-
break;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/LICENSE_NUTTX b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/LICENSE_NUTTX
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/LICENSE_NUTTX
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/LICENSE_NUTTX
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/NOTICE_NUTTX b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/NOTICE_NUTTX
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/NOTICE_NUTTX
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/NOTICE_NUTTX
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf32.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf32.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf32.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf32.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf64.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf64.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf64.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf64.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake
new file mode 100644
index 00000000000..efff88dd079
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake
@@ -0,0 +1,84 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set (IWASM_AOT_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+add_definitions (-DWASM_ENABLE_AOT=1)
+
+include_directories (${IWASM_AOT_DIR})
+
+file (GLOB c_source_all ${IWASM_AOT_DIR}/*.c)
+
+if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c)
+elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c)
+elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_aarch64.c)
+elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arm.c)
+elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_thumb.c)
+elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_mips.c)
+elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_xtensa.c)
+elseif (WAMR_BUILD_TARGET MATCHES "RISCV*")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_riscv.c)
+elseif (WAMR_BUILD_TARGET STREQUAL "ARC")
+ set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arc.c)
+else ()
+ message (FATAL_ERROR "Build target isn't set")
+endif ()
+
+if (WAMR_BUILD_DEBUG_AOT EQUAL 1)
+ add_definitions(-DWASM_ENABLE_DEBUG_AOT=1)
+ file(GLOB debug_source ${IWASM_AOT_DIR}/debug/*.c)
+endif()
+
+if ((WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
+ AND (WAMR_BUILD_PLATFORM STREQUAL "windows")
+ AND (NOT WAMR_DISABLE_HW_BOUND_CHECK EQUAL 1))
+ include(FetchContent)
+
+ FetchContent_Declare(
+ zycore
+ GIT_REPOSITORY https://github.com/zyantific/zycore-c.git
+ )
+ FetchContent_GetProperties(zycore)
+ if (NOT zycore_POPULATED)
+ message ("-- Fetching zycore ..")
+ FetchContent_Populate(zycore)
+ include_directories("${zycore_SOURCE_DIR}/include")
+ include_directories("${zycore_BINARY_DIR}")
+ add_definitions(-DZYCORE_STATIC_BUILD=1)
+ add_subdirectory(${zycore_SOURCE_DIR} ${zycore_BINARY_DIR} EXCLUDE_FROM_ALL)
+ file (GLOB_RECURSE c_source_zycore ${zycore_SOURCE_DIR}/src/*.c)
+ endif ()
+
+ FetchContent_Declare(
+ zydis
+ GIT_REPOSITORY https://github.com/zyantific/zydis.git
+ GIT_TAG e14a07895136182a5b53e181eec3b1c6e0b434de
+ )
+ FetchContent_GetProperties(zydis)
+ if (NOT zydis_POPULATED)
+ message ("-- Fetching zydis ..")
+ FetchContent_Populate(zydis)
+ option(ZYDIS_FEATURE_ENCODER "" OFF)
+ option(ZYDIS_BUILD_TOOLS "" OFF)
+ option(ZYDIS_BUILD_EXAMPLES "" OFF)
+ option(ZYDIS_BUILD_MAN "" OFF)
+ option(ZYDIS_BUILD_DOXYGEN "" OFF)
+ include_directories("${zydis_BINARY_DIR}")
+ include_directories("${zydis_SOURCE_DIR}/include")
+ include_directories("${zydis_SOURCE_DIR}/src")
+ add_definitions(-DZYDIS_STATIC_BUILD=1)
+ add_subdirectory(${zydis_SOURCE_DIR} ${zydis_BINARY_DIR} EXCLUDE_FROM_ALL)
+ file (GLOB_RECURSE c_source_zydis ${zydis_SOURCE_DIR}/src/*.c)
+ endif ()
+endif ()
+
+
+set (IWASM_AOT_SOURCE ${c_source_all} ${arch_source} ${debug_source}
+ ${c_source_zycore} ${c_source_zydis})
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64_simd.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64_simd.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64_simd.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64_simd.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arc.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arc.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arc.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arc.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm_vfp.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm_vfp.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm_vfp.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm_vfp.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.asm b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.asm
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.asm
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.asm
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.asm b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.asm
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.asm
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.asm
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_general.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_general.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_general.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_general.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.asm b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.asm
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.asm
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.asm
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mips.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mips.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mips.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mips.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_osx_universal.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_osx_universal.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_osx_universal.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_osx_universal.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_riscv.S b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_riscv.S
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_riscv.S
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_riscv.S
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb_vfp.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb_vfp.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb_vfp.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb_vfp.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_xtensa.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_xtensa.s
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_xtensa.s
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_xtensa.s
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/iwasm_common.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/iwasm_common.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/iwasm_common.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/iwasm_common.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_application.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_application.c
similarity index 90%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_application.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_application.c
index 2ed217e7a96..93c9342dace 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_application.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_application.c
@@ -107,7 +107,34 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
the actual main function. Directly calling main function
may cause exception thrown. */
if ((func = wasm_runtime_lookup_wasi_start_function(module_inst))) {
- return wasm_runtime_call_wasm(exec_env, func, 0, NULL);
+ const char *wasi_proc_exit_exception = "wasi proc exit";
+
+ ret = wasm_runtime_call_wasm(exec_env, func, 0, NULL);
+#if WASM_ENABLE_THREAD_MGR != 0
+ if (ret) {
+ /* On a successful return from the `_start` function,
+ we terminate other threads by mimicing wasi:proc_exit(0).
+
+ Note:
+ - A return from the `main` function is an equivalent of
+ exit(). (C standard)
+ - When exit code is 0, wasi-libc's `_start` function just
+ returns w/o calling `proc_exit`.
+ - A process termination should terminate threads in
+ the process. */
+
+ wasm_runtime_set_exception(module_inst, wasi_proc_exit_exception);
+ /* exit_code is zero-initialized */
+ ret = false;
+ }
+#endif
+ /* report wasm proc exit as a success */
+ WASMModuleInstance *inst = (WASMModuleInstance *)module_inst;
+ if (!ret && strstr(inst->cur_exception, wasi_proc_exit_exception)) {
+ inst->cur_exception[0] = 0;
+ ret = true;
+ }
+ return ret;
}
#endif /* end of WASM_ENABLE_LIBC_WASI */
@@ -204,7 +231,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
char *argv[])
{
bool ret;
-#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0)
+#if (WASM_ENABLE_MEMORY_PROFILING != 0)
WASMExecEnv *exec_env;
#endif
@@ -224,14 +251,6 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
if (ret)
ret = wasm_runtime_get_exception(module_inst) == NULL;
-#if WASM_ENABLE_DUMP_CALL_STACK != 0
- if (!ret) {
- exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
- if (exec_env)
- wasm_runtime_dump_call_stack(exec_env);
- }
-#endif
-
return ret;
}
@@ -293,7 +312,6 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
#endif
int32 i, p, module_type;
uint64 total_size;
- const char *exception;
char buf[128];
bh_assert(argc >= 0);
@@ -370,6 +388,18 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
{
float32 f32 = strtof(argv[i], &endptr);
if (isnan(f32)) {
+#ifdef _MSC_VER
+ /*
+ * Spec tests require the binary representation of NaN to be
+ * 0x7fc00000 for float and 0x7ff8000000000000 for float;
+ * however, in MSVC compiler, strtof doesn't return this
+ * exact value, causing some of the spec test failures. We
+ * use the value returned by nan/nanf as it is the one
+ * expected by spec tests.
+ *
+ */
+ f32 = nanf("");
+#endif
if (argv[i][0] == '-') {
union ieee754_float u;
u.f = f32;
@@ -404,6 +434,9 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
} u;
u.val = strtod(argv[i], &endptr);
if (isnan(u.val)) {
+#ifdef _MSC_VER
+ u.val = nan("");
+#endif
if (argv[i][0] == '-') {
union ieee754_double ud;
ud.d = u.val;
@@ -567,7 +600,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
{
#if UINTPTR_MAX == UINT32_MAX
if (argv1[k] != 0 && argv1[k] != (uint32)-1)
- os_printf("%p:ref.extern", (void *)argv1[k]);
+ os_printf("0x%" PRIxPTR ":ref.extern", (uintptr_t)argv1[k]);
else
os_printf("extern:ref.null");
k++;
@@ -580,7 +613,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
u.parts[1] = argv1[k + 1];
k += 2;
if (u.val && u.val != (uintptr_t)-1LL)
- os_printf("%p:ref.extern", (void *)u.val);
+ os_printf("0x%" PRIxPTR ":ref.extern", u.val);
else
os_printf("extern:ref.null");
#endif
@@ -613,9 +646,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
if (argv1)
wasm_runtime_free(argv1);
- exception = wasm_runtime_get_exception(module_inst);
- bh_assert(exception);
- os_printf("%s\n", exception);
+ bh_assert(wasm_runtime_get_exception(module_inst));
return false;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c
new file mode 100644
index 00000000000..25777c8d746
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "wasm_runtime_common.h"
+
+#include "bh_platform.h"
+#include "bh_common.h"
+#include "bh_assert.h"
+
+#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP)
+
+#define LOCK(env) WASM_SUSPEND_FLAGS_LOCK((env)->wait_lock)
+#define UNLOCK(env) WASM_SUSPEND_FLAGS_UNLOCK((env)->wait_lock)
+
+#define ISSET(env, bit) \
+ ((WASM_SUSPEND_FLAGS_GET((env)->suspend_flags) & WASM_SUSPEND_FLAG_##bit) \
+ != 0)
+#define SET(env, bit) \
+ WASM_SUSPEND_FLAGS_FETCH_OR((env)->suspend_flags, WASM_SUSPEND_FLAG_##bit)
+#define CLR(env, bit) \
+ WASM_SUSPEND_FLAGS_FETCH_AND((env)->suspend_flags, ~WASM_SUSPEND_FLAG_##bit)
+
+bool
+wasm_runtime_begin_blocking_op(wasm_exec_env_t env)
+{
+ LOCK(env);
+ bh_assert(!ISSET(env, BLOCKING));
+ SET(env, BLOCKING);
+ if (ISSET(env, TERMINATE)) {
+ CLR(env, BLOCKING);
+ UNLOCK(env);
+ return false;
+ }
+ UNLOCK(env);
+ os_begin_blocking_op();
+ return true;
+}
+
+void
+wasm_runtime_end_blocking_op(wasm_exec_env_t env)
+{
+ int saved_errno = errno;
+ LOCK(env);
+ bh_assert(ISSET(env, BLOCKING));
+ CLR(env, BLOCKING);
+ UNLOCK(env);
+ os_end_blocking_op();
+ errno = saved_errno;
+}
+
+void
+wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env)
+{
+ /*
+ * ISSET(BLOCKING) here means that the target thread
+ * is in somewhere between wasm_begin_blocking_op and
+ * wasm_end_blocking_op.
+ * keep waking it up until it reaches wasm_end_blocking_op,
+ * which clears the BLOCKING bit.
+ *
+ * this dumb loop is necessary because posix doesn't provide
+ * a way to unmask signal and block atomically.
+ */
+
+ LOCK(env);
+ SET(env, TERMINATE);
+ while (ISSET(env, BLOCKING)) {
+ UNLOCK(env);
+ os_wakeup_blocking_op(env->handle);
+
+ /* relax a bit */
+ os_usleep(50 * 1000);
+ LOCK(env);
+ }
+ UNLOCK(env);
+}
+
+#else /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */
+
+bool
+wasm_runtime_begin_blocking_op(wasm_exec_env_t env)
+{
+ return true;
+}
+
+void
+wasm_runtime_end_blocking_op(wasm_exec_env_t env)
+{}
+
+#endif /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api.c
index 7b8cf477974..57c3ebd0d0c 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api.c
@@ -292,13 +292,46 @@ WASM_DEFINE_VEC_OWN(valtype, wasm_valtype_delete)
own wasm_config_t *
wasm_config_new(void)
{
- return NULL;
+ /* since wasm_runtime_malloc is not ready */
+ wasm_config_t *config = os_malloc(sizeof(wasm_config_t));
+ if (!config)
+ return NULL;
+
+ memset(config, 0, sizeof(wasm_config_t));
+ config->mem_alloc_type = Alloc_With_System_Allocator;
+ return config;
}
void
wasm_config_delete(own wasm_config_t *config)
{
- (void)config;
+ if (config)
+ os_free(config);
+}
+
+wasm_config_t *
+wasm_config_set_mem_alloc_opt(wasm_config_t *config,
+ mem_alloc_type_t mem_alloc_type,
+ MemAllocOption *mem_alloc_option)
+{
+ if (!config)
+ return NULL;
+
+ config->mem_alloc_type = mem_alloc_type;
+ if (mem_alloc_option)
+ memcpy(&config->mem_alloc_option, mem_alloc_option,
+ sizeof(MemAllocOption));
+ return config;
+}
+
+wasm_config_t *
+wasm_config_set_linux_perf_opt(wasm_config_t *config, bool enable)
+{
+ if (!config)
+ return NULL;
+
+ config->linux_perf_support = enable;
+ return config;
}
static void
@@ -329,12 +362,11 @@ wasm_engine_delete_internal(wasm_engine_t *engine)
}
static wasm_engine_t *
-wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
+wasm_engine_new_internal(wasm_config_t *config)
{
wasm_engine_t *engine = NULL;
/* init runtime */
RuntimeInitArgs init_args = { 0 };
- init_args.mem_alloc_type = type;
#ifndef NDEBUG
bh_log_set_verbose_level(BH_LOG_LEVEL_VERBOSE);
@@ -344,34 +376,11 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
WASM_C_DUMP_PROC_MEM();
- if (type == Alloc_With_Pool) {
- if (!opts) {
- return NULL;
- }
-
- init_args.mem_alloc_option.pool.heap_buf = opts->pool.heap_buf;
- init_args.mem_alloc_option.pool.heap_size = opts->pool.heap_size;
- }
- else if (type == Alloc_With_Allocator) {
- if (!opts) {
- return NULL;
- }
-
- init_args.mem_alloc_option.allocator.malloc_func =
- opts->allocator.malloc_func;
- init_args.mem_alloc_option.allocator.free_func =
- opts->allocator.free_func;
- init_args.mem_alloc_option.allocator.realloc_func =
- opts->allocator.realloc_func;
-#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
- init_args.mem_alloc_option.allocator.user_data =
- opts->allocator.user_data;
-#endif
- }
- else {
- init_args.mem_alloc_option.pool.heap_buf = NULL;
- init_args.mem_alloc_option.pool.heap_size = 0;
- }
+ /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */
+ init_args.mem_alloc_type = config->mem_alloc_type;
+ memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option,
+ sizeof(MemAllocOption));
+ init_args.linux_perf_support = config->linux_perf_support;
if (!wasm_runtime_full_init(&init_args)) {
LOG_DEBUG("wasm_runtime_full_init failed");
@@ -418,14 +427,23 @@ static korp_mutex engine_lock = OS_THREAD_MUTEX_INITIALIZER;
#endif
own wasm_engine_t *
-wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
+wasm_engine_new()
+{
+ wasm_config_t config = { 0 };
+ wasm_config_set_mem_alloc_opt(&config, Alloc_With_System_Allocator, NULL);
+ wasm_engine_t *engine = wasm_engine_new_with_config(&config);
+ return engine;
+}
+
+own wasm_engine_t *
+wasm_engine_new_with_config(wasm_config_t *config)
{
#if defined(OS_THREAD_MUTEX_INITIALIZER)
os_mutex_lock(&engine_lock);
#endif
if (!singleton_engine)
- singleton_engine = wasm_engine_new_internal(type, opts);
+ singleton_engine = wasm_engine_new_internal(config);
else
singleton_engine->ref_count++;
@@ -437,16 +455,12 @@ wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
}
own wasm_engine_t *
-wasm_engine_new()
-{
- return wasm_engine_new_with_args(Alloc_With_System_Allocator, NULL);
-}
-
-own wasm_engine_t *
-wasm_engine_new_with_config(own wasm_config_t *config)
+wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts)
{
- (void)config;
- return wasm_engine_new_with_args(Alloc_With_System_Allocator, NULL);
+ wasm_config_t config = { 0 };
+ config.mem_alloc_type = type;
+ memcpy(&config.mem_alloc_option, opts, sizeof(MemAllocOption));
+ return wasm_engine_new_with_config(&config);
}
void
@@ -2290,8 +2304,10 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
bool
wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary)
{
+ wasm_byte_vec_t local_binary = { 0 };
struct WASMModuleCommon *module_rt;
char error_buf[128] = { 0 };
+ bool ret;
bh_assert(singleton_engine);
@@ -2300,15 +2316,25 @@ wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary)
return false;
}
- if ((module_rt = wasm_runtime_load((uint8 *)binary->data,
- (uint32)binary->size, error_buf, 128))) {
+ /* make a copy of binary */
+ wasm_byte_vec_copy(&local_binary, binary);
+
+ if (binary->size && !local_binary.data)
+ return false;
+
+ module_rt = wasm_runtime_load((uint8 *)local_binary.data,
+ (uint32)local_binary.size, error_buf, 128);
+ wasm_byte_vec_delete(&local_binary);
+ if (module_rt) {
wasm_runtime_unload(module_rt);
- return true;
+ ret = true;
}
else {
+ ret = false;
LOG_VERBOSE(error_buf);
- return false;
}
+
+ return ret;
}
static void
@@ -4858,7 +4884,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
if (instance->inst_comm_rt->module_type == Wasm_Module_Bytecode) {
WASMModuleInstanceExtra *e =
((WASMModuleInstance *)instance->inst_comm_rt)->e;
- p_func_imports = &(e->c_api_func_imports);
+ p_func_imports = &(e->common.c_api_func_imports);
import_func_count = MODULE_INTERP(module)->import_function_count;
}
#endif
@@ -4868,7 +4894,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
(AOTModuleInstanceExtra *)((AOTModuleInstance *)
instance->inst_comm_rt)
->e;
- p_func_imports = &(e->c_api_func_imports);
+ p_func_imports = &(e->common.c_api_func_imports);
import_func_count = MODULE_AOT(module)->import_func_count;
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api_internal.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api_internal.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.c
similarity index 81%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.c
index 622bcd71ee7..d524c7de093 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.c
@@ -58,7 +58,8 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
#ifdef OS_ENABLE_HW_BOUND_CHECK
if (!(exec_env->exce_check_guard_page =
- os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE)))
+ os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE,
+ os_get_invalid_handle())))
goto fail5;
#endif
@@ -201,7 +202,52 @@ void
wasm_exec_env_set_module_inst(WASMExecEnv *exec_env,
WASMModuleInstanceCommon *const module_inst)
{
+#if WASM_ENABLE_THREAD_MGR != 0
+ wasm_cluster_traverse_lock(exec_env);
+#endif
exec_env->module_inst = module_inst;
+#if WASM_ENABLE_THREAD_MGR != 0
+ wasm_cluster_traverse_unlock(exec_env);
+#endif
+}
+
+void
+wasm_exec_env_restore_module_inst(
+ WASMExecEnv *exec_env, WASMModuleInstanceCommon *const module_inst_common)
+{
+ WASMModuleInstanceCommon *old_module_inst_common = exec_env->module_inst;
+ WASMModuleInstance *old_module_inst =
+ (WASMModuleInstance *)old_module_inst_common;
+ WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_common;
+ char cur_exception[EXCEPTION_BUF_LEN];
+
+#if WASM_ENABLE_THREAD_MGR != 0
+ wasm_cluster_traverse_lock(exec_env);
+#endif
+ exec_env->module_inst = module_inst_common;
+ /*
+ * propagate an exception if any.
+ */
+ exception_lock(old_module_inst);
+ if (old_module_inst->cur_exception[0] != '\0') {
+ bh_memcpy_s(cur_exception, sizeof(cur_exception),
+ old_module_inst->cur_exception,
+ sizeof(old_module_inst->cur_exception));
+ }
+ else {
+ cur_exception[0] = '\0';
+ }
+ exception_unlock(old_module_inst);
+#if WASM_ENABLE_THREAD_MGR != 0
+ wasm_cluster_traverse_unlock(exec_env);
+#endif
+ if (cur_exception[0] != '\0') {
+ exception_lock(module_inst);
+ bh_memcpy_s(module_inst->cur_exception,
+ sizeof(module_inst->cur_exception), cur_exception,
+ sizeof(cur_exception));
+ exception_unlock(module_inst);
+ }
}
void
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.h
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.h
index 29b28a15922..132642ea8eb 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.h
@@ -7,6 +7,7 @@
#define _WASM_EXEC_ENV_H
#include "bh_assert.h"
+#include "wasm_suspend_flags.h"
#if WASM_ENABLE_INTERP != 0
#include "../interpreter/wasm.h"
#endif
@@ -57,15 +58,8 @@ typedef struct WASMExecEnv {
exception. */
uint8 *native_stack_boundary;
- /* Used to terminate or suspend current thread
- bit 0: need to terminate
- bit 1: need to suspend
- bit 2: need to go into breakpoint
- bit 3: return from pthread_exit */
- union {
- uint32 flags;
- uintptr_t __padding__;
- } suspend_flags;
+ /* Used to terminate or suspend current thread */
+ WASMSuspendFlags suspend_flags;
/* Auxiliary stack boundary */
union {
@@ -297,6 +291,10 @@ void
wasm_exec_env_set_module_inst(
WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst);
+void
+wasm_exec_env_restore_module_inst(
+ WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst);
+
void
wasm_exec_env_set_thread_info(WASMExecEnv *exec_env);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.c
similarity index 73%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.c
index 82676ae271d..3941c224aa2 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.c
@@ -5,8 +5,10 @@
#include "wasm_runtime_common.h"
#include "../interpreter/wasm_runtime.h"
+#include "../aot/aot_runtime.h"
#include "bh_platform.h"
#include "mem_alloc.h"
+#include "wasm_memory.h"
#if WASM_ENABLE_SHARED_MEMORY != 0
#include "../common/wasm_shared_memory.h"
@@ -23,6 +25,9 @@ static Memory_Mode memory_mode = MEMORY_MODE_UNKNOWN;
static mem_allocator_t pool_allocator = NULL;
+static enlarge_memory_error_callback_t enlarge_memory_error_cb;
+static void *enlarge_memory_error_user_data;
+
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
static void *allocator_user_data = NULL;
static void *(*malloc_func)(void *user_data, unsigned int size) = NULL;
@@ -87,6 +92,16 @@ wasm_memory_init_with_allocator(void *_malloc_func, void *_realloc_func,
}
#endif
+static inline bool
+is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst)
+{
+#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
+ return wasm_runtime_is_bounds_checks_enabled(module_inst);
+#else
+ return true;
+#endif
+}
+
bool
wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
const MemAllocOption *alloc_option)
@@ -269,6 +284,10 @@ wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst_comm,
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|| module_inst_comm->module_type == Wasm_Module_AoT);
+ if (!is_bounds_checks_enabled(module_inst_comm)) {
+ return true;
+ }
+
memory_inst = wasm_get_default_memory(module_inst);
if (!memory_inst) {
goto fail;
@@ -279,10 +298,15 @@ wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst_comm,
goto fail;
}
+ SHARED_MEMORY_LOCK(memory_inst);
+
if (app_offset + size <= memory_inst->memory_data_size) {
+ SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}
+ SHARED_MEMORY_UNLOCK(memory_inst);
+
fail:
wasm_set_exception(module_inst, "out of bounds memory access");
return false;
@@ -299,6 +323,10 @@ wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst_comm,
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|| module_inst_comm->module_type == Wasm_Module_AoT);
+ if (!is_bounds_checks_enabled(module_inst_comm)) {
+ return true;
+ }
+
if (!wasm_runtime_get_app_addr_range(module_inst_comm, app_str_offset, NULL,
&app_end_offset))
goto fail;
@@ -327,6 +355,10 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst_comm,
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|| module_inst_comm->module_type == Wasm_Module_AoT);
+ if (!is_bounds_checks_enabled(module_inst_comm)) {
+ return true;
+ }
+
memory_inst = wasm_get_default_memory(module_inst);
if (!memory_inst) {
goto fail;
@@ -337,11 +369,16 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst_comm,
goto fail;
}
+ SHARED_MEMORY_LOCK(memory_inst);
+
if (memory_inst->memory_data <= addr
&& addr + size <= memory_inst->memory_data_end) {
+ SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}
+ SHARED_MEMORY_UNLOCK(memory_inst);
+
fail:
wasm_set_exception(module_inst, "out of bounds memory access");
return false;
@@ -354,20 +391,36 @@ wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst_comm,
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
WASMMemoryInstance *memory_inst;
uint8 *addr;
+ bool bounds_checks;
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|| module_inst_comm->module_type == Wasm_Module_AoT);
+ bounds_checks = is_bounds_checks_enabled(module_inst_comm);
+
memory_inst = wasm_get_default_memory(module_inst);
if (!memory_inst) {
return NULL;
}
+ SHARED_MEMORY_LOCK(memory_inst);
+
addr = memory_inst->memory_data + app_offset;
- if (memory_inst->memory_data <= addr && addr < memory_inst->memory_data_end)
+ if (bounds_checks) {
+ if (memory_inst->memory_data <= addr
+ && addr < memory_inst->memory_data_end) {
+ SHARED_MEMORY_UNLOCK(memory_inst);
+ return addr;
+ }
+ }
+ /* If bounds checks is disabled, return the address directly */
+ else if (app_offset != 0) {
+ SHARED_MEMORY_UNLOCK(memory_inst);
return addr;
+ }
+ SHARED_MEMORY_UNLOCK(memory_inst);
return NULL;
}
@@ -378,18 +431,37 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst_comm,
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
WASMMemoryInstance *memory_inst;
uint8 *addr = (uint8 *)native_ptr;
+ bool bounds_checks;
+ uint32 ret;
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|| module_inst_comm->module_type == Wasm_Module_AoT);
+ bounds_checks = is_bounds_checks_enabled(module_inst_comm);
+
memory_inst = wasm_get_default_memory(module_inst);
if (!memory_inst) {
return 0;
}
- if (memory_inst->memory_data <= addr && addr < memory_inst->memory_data_end)
- return (uint32)(addr - memory_inst->memory_data);
+ SHARED_MEMORY_LOCK(memory_inst);
+
+ if (bounds_checks) {
+ if (memory_inst->memory_data <= addr
+ && addr < memory_inst->memory_data_end) {
+ ret = (uint32)(addr - memory_inst->memory_data);
+ SHARED_MEMORY_UNLOCK(memory_inst);
+ return ret;
+ }
+ }
+ /* If bounds checks is disabled, return the offset directly */
+ else if (addr != NULL) {
+ ret = (uint32)(addr - memory_inst->memory_data);
+ SHARED_MEMORY_UNLOCK(memory_inst);
+ return ret;
+ }
+ SHARED_MEMORY_UNLOCK(memory_inst);
return 0;
}
@@ -410,6 +482,8 @@ wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst_comm,
return false;
}
+ SHARED_MEMORY_LOCK(memory_inst);
+
memory_data_size = memory_inst->memory_data_size;
if (app_offset < memory_data_size) {
@@ -417,9 +491,11 @@ wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst_comm,
*p_app_start_offset = 0;
if (p_app_end_offset)
*p_app_end_offset = memory_data_size;
+ SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}
+ SHARED_MEMORY_UNLOCK(memory_inst);
return false;
}
@@ -441,15 +517,19 @@ wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst_comm,
return false;
}
+ SHARED_MEMORY_LOCK(memory_inst);
+
if (memory_inst->memory_data <= addr
&& addr < memory_inst->memory_data_end) {
if (p_native_start_addr)
*p_native_start_addr = memory_inst->memory_data;
if (p_native_end_addr)
*p_native_end_addr = memory_inst->memory_data_end;
+ SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}
+ SHARED_MEMORY_UNLOCK(memory_inst);
return false;
}
@@ -460,16 +540,29 @@ wasm_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
{
WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst);
uint8 *native_addr;
+ bool bounds_checks;
if (!memory_inst) {
- goto fail;
+ wasm_set_exception(module_inst, "out of bounds memory access");
+ return false;
}
native_addr = memory_inst->memory_data + app_buf_addr;
+ bounds_checks = is_bounds_checks_enabled((wasm_module_inst_t)module_inst);
+
+ if (!bounds_checks) {
+ if (app_buf_addr == 0) {
+ native_addr = NULL;
+ }
+ goto success;
+ }
+
/* No need to check the app_offset and buf_size if memory access
boundary check with hardware trap is enabled */
#ifndef OS_ENABLE_HW_BOUND_CHECK
+ SHARED_MEMORY_LOCK(memory_inst);
+
if (app_buf_addr >= memory_inst->memory_data_size) {
goto fail;
}
@@ -490,13 +583,20 @@ wasm_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
if (str == str_end)
goto fail;
}
+
+ SHARED_MEMORY_UNLOCK(memory_inst);
#endif
+success:
*p_native_addr = (void *)native_addr;
return true;
+
+#ifndef OS_ENABLE_HW_BOUND_CHECK
fail:
+ SHARED_MEMORY_UNLOCK(memory_inst);
wasm_set_exception(module_inst, "out of bounds memory access");
return false;
+#endif
}
WASMMemoryInstance *
@@ -508,19 +608,43 @@ wasm_get_default_memory(WASMModuleInstance *module_inst)
return NULL;
}
+void
+wasm_runtime_set_mem_bound_check_bytes(WASMMemoryInstance *memory,
+ uint64 memory_data_size)
+{
+#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 || WASM_ENABLE_AOT != 0
+#if UINTPTR_MAX == UINT64_MAX
+ memory->mem_bound_check_1byte.u64 = memory_data_size - 1;
+ memory->mem_bound_check_2bytes.u64 = memory_data_size - 2;
+ memory->mem_bound_check_4bytes.u64 = memory_data_size - 4;
+ memory->mem_bound_check_8bytes.u64 = memory_data_size - 8;
+ memory->mem_bound_check_16bytes.u64 = memory_data_size - 16;
+#else
+ memory->mem_bound_check_1byte.u32[0] = (uint32)memory_data_size - 1;
+ memory->mem_bound_check_2bytes.u32[0] = (uint32)memory_data_size - 2;
+ memory->mem_bound_check_4bytes.u32[0] = (uint32)memory_data_size - 4;
+ memory->mem_bound_check_8bytes.u32[0] = (uint32)memory_data_size - 8;
+ memory->mem_bound_check_16bytes.u32[0] = (uint32)memory_data_size - 16;
+#endif
+#endif
+}
+
#ifndef OS_ENABLE_HW_BOUND_CHECK
bool
wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
{
WASMMemoryInstance *memory = wasm_get_default_memory(module);
uint8 *memory_data_old, *memory_data_new, *heap_data_old;
- uint32 num_bytes_per_page, heap_size, total_size_old;
+ uint32 num_bytes_per_page, heap_size, total_size_old = 0;
uint32 cur_page_count, max_page_count, total_page_count;
uint64 total_size_new;
bool ret = true;
+ enlarge_memory_error_reason_t failure_reason = INTERNAL_ERROR;
- if (!memory)
- return false;
+ if (!memory) {
+ ret = false;
+ goto return_func;
+ }
heap_data_old = memory->heap_data;
heap_size = (uint32)(memory->heap_data_end - memory->heap_data);
@@ -538,9 +662,15 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
/* No need to enlarge memory */
return true;
- if (total_page_count < cur_page_count /* integer overflow */
- || total_page_count > max_page_count) {
- return false;
+ if (total_page_count < cur_page_count) { /* integer overflow */
+ ret = false;
+ goto return_func;
+ }
+
+ if (total_page_count > max_page_count) {
+ failure_reason = MAX_SIZE_REACHED;
+ ret = false;
+ goto return_func;
}
bh_assert(total_size_new <= 4 * (uint64)BH_GB);
@@ -552,13 +682,14 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
}
#if WASM_ENABLE_SHARED_MEMORY != 0
- if (memory->is_shared) {
+ if (shared_memory_is_shared(memory)) {
memory->num_bytes_per_page = num_bytes_per_page;
memory->cur_page_count = total_page_count;
memory->max_page_count = max_page_count;
- /* No need to update memory->memory_data_size as it is
- initialized with the maximum memory data size for
- shared memory */
+ SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new);
+ memory->memory_data_end = memory->memory_data + (uint32)total_size_new;
+
+ wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new);
return true;
}
#endif
@@ -566,14 +697,16 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
if (heap_size > 0) {
if (mem_allocator_is_heap_corrupted(memory->heap_handle)) {
wasm_runtime_show_app_heap_corrupted_prompt();
- return false;
+ ret = false;
+ goto return_func;
}
}
if (!(memory_data_new =
wasm_runtime_realloc(memory_data_old, (uint32)total_size_new))) {
if (!(memory_data_new = wasm_runtime_malloc((uint32)total_size_new))) {
- return false;
+ ret = false;
+ goto return_func;
}
if (memory_data_old) {
bh_memcpy_s(memory_data_new, (uint32)total_size_new,
@@ -608,22 +741,34 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
memory->memory_data = memory_data_new;
memory->memory_data_end = memory_data_new + (uint32)total_size_new;
-#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 || WASM_ENABLE_AOT != 0
-#if UINTPTR_MAX == UINT64_MAX
- memory->mem_bound_check_1byte.u64 = total_size_new - 1;
- memory->mem_bound_check_2bytes.u64 = total_size_new - 2;
- memory->mem_bound_check_4bytes.u64 = total_size_new - 4;
- memory->mem_bound_check_8bytes.u64 = total_size_new - 8;
- memory->mem_bound_check_16bytes.u64 = total_size_new - 16;
-#else
- memory->mem_bound_check_1byte.u32[0] = (uint32)total_size_new - 1;
- memory->mem_bound_check_2bytes.u32[0] = (uint32)total_size_new - 2;
- memory->mem_bound_check_4bytes.u32[0] = (uint32)total_size_new - 4;
- memory->mem_bound_check_8bytes.u32[0] = (uint32)total_size_new - 8;
- memory->mem_bound_check_16bytes.u32[0] = (uint32)total_size_new - 16;
+ wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new);
+
+#if defined(os_writegsbase)
+ /* write base addr of linear memory to GS segment register */
+ os_writegsbase(memory_data_new);
#endif
+
+return_func:
+ if (!ret && enlarge_memory_error_cb) {
+ WASMExecEnv *exec_env = NULL;
+
+#if WASM_ENABLE_INTERP != 0
+ if (module->module_type == Wasm_Module_Bytecode)
+ exec_env =
+ ((WASMModuleInstanceExtra *)module->e)->common.cur_exec_env;
+#endif
+#if WASM_ENABLE_AOT != 0
+ if (module->module_type == Wasm_Module_AoT)
+ exec_env =
+ ((AOTModuleInstanceExtra *)module->e)->common.cur_exec_env;
#endif
+ enlarge_memory_error_cb(inc_page_count, total_size_old, 0,
+ failure_reason,
+ (WASMModuleInstanceCommon *)module, exec_env,
+ enlarge_memory_error_user_data);
+ }
+
return ret;
}
#else
@@ -631,12 +776,16 @@ bool
wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
{
WASMMemoryInstance *memory = wasm_get_default_memory(module);
- uint32 num_bytes_per_page, total_size_old;
+ uint32 num_bytes_per_page, total_size_old = 0;
uint32 cur_page_count, max_page_count, total_page_count;
uint64 total_size_new;
+ bool ret = true;
+ enlarge_memory_error_reason_t failure_reason = INTERNAL_ERROR;
- if (!memory)
- return false;
+ if (!memory) {
+ ret = false;
+ goto return_func;
+ }
num_bytes_per_page = memory->num_bytes_per_page;
cur_page_count = memory->cur_page_count;
@@ -649,9 +798,15 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
/* No need to enlarge memory */
return true;
- if (total_page_count < cur_page_count /* integer overflow */
- || total_page_count > max_page_count) {
- return false;
+ if (total_page_count < cur_page_count) { /* integer overflow */
+ ret = false;
+ goto return_func;
+ }
+
+ if (total_page_count > max_page_count) {
+ failure_reason = MAX_SIZE_REACHED;
+ ret = false;
+ goto return_func;
}
bh_assert(total_size_new <= 4 * (uint64)BH_GB);
@@ -666,7 +821,8 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
if (!os_mem_commit(memory->memory_data_end,
(uint32)total_size_new - total_size_old,
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
- return false;
+ ret = false;
+ goto return_func;
}
#endif
@@ -678,7 +834,8 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
os_mem_decommit(memory->memory_data_end,
(uint32)total_size_new - total_size_old);
#endif
- return false;
+ ret = false;
+ goto return_func;
}
/* The increased pages are filled with zero by the OS when os_mmap,
@@ -687,73 +844,58 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
memory->num_bytes_per_page = num_bytes_per_page;
memory->cur_page_count = total_page_count;
memory->max_page_count = max_page_count;
- memory->memory_data_size = (uint32)total_size_new;
+ SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new);
memory->memory_data_end = memory->memory_data + (uint32)total_size_new;
-#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 || WASM_ENABLE_AOT != 0
- memory->mem_bound_check_1byte.u64 = total_size_new - 1;
- memory->mem_bound_check_2bytes.u64 = total_size_new - 2;
- memory->mem_bound_check_4bytes.u64 = total_size_new - 4;
- memory->mem_bound_check_8bytes.u64 = total_size_new - 8;
- memory->mem_bound_check_16bytes.u64 = total_size_new - 16;
+ wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new);
+
+return_func:
+ if (!ret && enlarge_memory_error_cb) {
+ WASMExecEnv *exec_env = NULL;
+
+#if WASM_ENABLE_INTERP != 0
+ if (module->module_type == Wasm_Module_Bytecode)
+ exec_env =
+ ((WASMModuleInstanceExtra *)module->e)->common.cur_exec_env;
+#endif
+#if WASM_ENABLE_AOT != 0
+ if (module->module_type == Wasm_Module_AoT)
+ exec_env =
+ ((AOTModuleInstanceExtra *)module->e)->common.cur_exec_env;
#endif
- return true;
+ enlarge_memory_error_cb(inc_page_count, total_size_old, 0,
+ failure_reason,
+ (WASMModuleInstanceCommon *)module, exec_env,
+ enlarge_memory_error_user_data);
+ }
+
+ return ret;
}
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
+void
+wasm_runtime_set_enlarge_mem_error_callback(
+ const enlarge_memory_error_callback_t callback, void *user_data)
+{
+ enlarge_memory_error_cb = callback;
+ enlarge_memory_error_user_data = user_data;
+}
+
bool
wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
{
bool ret = false;
#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *node =
- wasm_module_get_shared_memory((WASMModuleCommon *)module->module);
- if (node)
- os_mutex_lock(&node->shared_mem_lock);
+ if (module->memory_count > 0)
+ shared_memory_lock(module->memories[0]);
#endif
ret = wasm_enlarge_memory_internal(module, inc_page_count);
#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_unlock(&node->shared_mem_lock);
+ if (module->memory_count > 0)
+ shared_memory_unlock(module->memories[0]);
#endif
return ret;
}
-
-#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
- || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
- || WASM_ENABLE_BULK_MEMORY != 0
-uint32
-wasm_get_num_bytes_per_page(WASMMemoryInstance *memory, void *node)
-{
- uint32 num_bytes_per_page;
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_lock(&((WASMSharedMemNode *)node)->shared_mem_lock);
-#endif
- num_bytes_per_page = memory->num_bytes_per_page;
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_unlock(&((WASMSharedMemNode *)node)->shared_mem_lock);
-#endif
- return num_bytes_per_page;
-}
-
-uint32
-wasm_get_linear_memory_size(WASMMemoryInstance *memory, void *node)
-{
- uint32 linear_mem_size;
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_lock(&((WASMSharedMemNode *)node)->shared_mem_lock);
-#endif
- linear_mem_size = memory->num_bytes_per_page * memory->cur_page_count;
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_unlock(&((WASMSharedMemNode *)node)->shared_mem_lock);
-#endif
- return linear_mem_size;
-}
-#endif
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h
new file mode 100644
index 00000000000..9b74db5262a
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef _WASM_MEMORY_H
+#define _WASM_MEMORY_H
+
+#include "bh_common.h"
+#include "../include/wasm_export.h"
+#include "../interpreter/wasm_runtime.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if WASM_ENABLE_SHARED_MEMORY != 0
+#define GET_LINEAR_MEMORY_SIZE(memory) \
+ BH_ATOMIC_32_LOAD(memory->memory_data_size)
+#define SET_LINEAR_MEMORY_SIZE(memory, size) \
+ BH_ATOMIC_32_STORE(memory->memory_data_size, size)
+#else
+#define GET_LINEAR_MEMORY_SIZE(memory) memory->memory_data_size
+#define SET_LINEAR_MEMORY_SIZE(memory, size) memory->memory_data_size = size
+#endif
+
+bool
+wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
+ const MemAllocOption *alloc_option);
+
+void
+wasm_runtime_memory_destroy();
+
+unsigned
+wasm_runtime_memory_pool_size();
+
+void
+wasm_runtime_set_mem_bound_check_bytes(WASMMemoryInstance *memory,
+ uint64 memory_data_size);
+
+void
+wasm_runtime_set_enlarge_mem_error_callback(
+ const enlarge_memory_error_callback_t callback, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* end of _WASM_MEMORY_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.c
similarity index 75%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.c
index 1acaed6eee5..c42bf7b318a 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.c
@@ -6,6 +6,15 @@
#include "wasm_native.h"
#include "wasm_runtime_common.h"
#include "bh_log.h"
+#if WASM_ENABLE_INTERP != 0
+#include "../interpreter/wasm_runtime.h"
+#endif
+#if WASM_ENABLE_AOT != 0
+#include "../aot/aot_runtime.h"
+#endif
+#if WASM_ENABLE_THREAD_MGR != 0
+#include "../libraries/thread-mgr/thread_manager.h"
+#endif
#if !defined(BH_PLATFORM_ZEPHYR) && !defined(BH_PLATFORM_ALIOS_THINGS) \
&& !defined(BH_PLATFORM_OPENRTOS) && !defined(BH_PLATFORM_ESP_IDF)
@@ -22,6 +31,10 @@
static NativeSymbolsList g_native_symbols_list = NULL;
+#if WASM_ENABLE_LIBC_WASI != 0
+static void *g_wasi_context_key;
+#endif /* WASM_ENABLE_LIBC_WASI */
+
uint32
get_libc_builtin_export_apis(NativeSymbol **p_libc_builtin_apis);
@@ -394,6 +407,154 @@ wasm_native_unregister_natives(const char *module_name,
return false;
}
+#if WASM_ENABLE_MODULE_INST_CONTEXT != 0
+static uint32
+context_key_to_idx(void *key)
+{
+ bh_assert(key != NULL);
+ uint32 idx = (uint32)(uintptr_t)key;
+ bh_assert(idx > 0);
+ bh_assert(idx <= WASM_MAX_INSTANCE_CONTEXTS);
+ return idx - 1;
+}
+
+static void *
+context_idx_to_key(uint32 idx)
+{
+ bh_assert(idx < WASM_MAX_INSTANCE_CONTEXTS);
+ return (void *)(uintptr_t)(idx + 1);
+}
+
+typedef void (*dtor_t)(WASMModuleInstanceCommon *, void *);
+static dtor_t g_context_dtors[WASM_MAX_INSTANCE_CONTEXTS];
+
+static void
+dtor_noop(WASMModuleInstanceCommon *inst, void *ctx)
+{}
+
+void *
+wasm_native_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
+ void *ctx))
+{
+ uint32 i;
+ for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
+ if (g_context_dtors[i] == NULL) {
+ if (dtor == NULL) {
+ dtor = dtor_noop;
+ }
+ g_context_dtors[i] = dtor;
+ return context_idx_to_key(i);
+ }
+ }
+ LOG_ERROR("failed to allocate instance context key");
+ return NULL;
+}
+
+void
+wasm_native_destroy_context_key(void *key)
+{
+ uint32 idx = context_key_to_idx(key);
+ bh_assert(g_context_dtors[idx] != NULL);
+ g_context_dtors[idx] = NULL;
+}
+
+static WASMModuleInstanceExtraCommon *
+wasm_module_inst_extra_common(WASMModuleInstanceCommon *inst)
+{
+#if WASM_ENABLE_INTERP != 0
+ if (inst->module_type == Wasm_Module_Bytecode) {
+ return &((WASMModuleInstance *)inst)->e->common;
+ }
+#endif
+#if WASM_ENABLE_AOT != 0
+ if (inst->module_type == Wasm_Module_AoT) {
+ return &((AOTModuleInstanceExtra *)((AOTModuleInstance *)inst)->e)
+ ->common;
+ }
+#endif
+ bh_assert(false);
+ return NULL;
+}
+
+void
+wasm_native_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx)
+{
+ uint32 idx = context_key_to_idx(key);
+ WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
+ common->contexts[idx] = ctx;
+}
+
+void
+wasm_native_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
+ void *ctx)
+{
+#if WASM_ENABLE_THREAD_MGR != 0
+ wasm_cluster_set_context(inst, key, ctx);
+#else
+ wasm_native_set_context(inst, key, ctx);
+#endif
+}
+
+void *
+wasm_native_get_context(WASMModuleInstanceCommon *inst, void *key)
+{
+ uint32 idx = context_key_to_idx(key);
+ WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
+ return common->contexts[idx];
+}
+
+void
+wasm_native_call_context_dtors(WASMModuleInstanceCommon *inst)
+{
+ WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
+ uint32 i;
+ for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
+ dtor_t dtor = g_context_dtors[i];
+ if (dtor != NULL) {
+ dtor(inst, common->contexts[i]);
+ }
+ }
+}
+
+void
+wasm_native_inherit_contexts(WASMModuleInstanceCommon *child,
+ WASMModuleInstanceCommon *parent)
+{
+ WASMModuleInstanceExtraCommon *parent_common =
+ wasm_module_inst_extra_common(parent);
+ WASMModuleInstanceExtraCommon *child_common =
+ wasm_module_inst_extra_common(child);
+ bh_memcpy_s(child_common->contexts,
+ sizeof(*child_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS,
+ parent_common->contexts,
+ sizeof(*parent_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS);
+}
+#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
+
+#if WASM_ENABLE_LIBC_WASI != 0
+WASIContext *
+wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm)
+{
+ return wasm_native_get_context(module_inst_comm, g_wasi_context_key);
+}
+
+void
+wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm,
+ WASIContext *wasi_ctx)
+{
+ wasm_native_set_context(module_inst_comm, g_wasi_context_key, wasi_ctx);
+}
+
+static void
+wasi_context_dtor(WASMModuleInstanceCommon *inst, void *ctx)
+{
+ if (ctx == NULL) {
+ return;
+ }
+ wasm_runtime_destroy_wasi(inst);
+}
+#endif /* end of WASM_ENABLE_LIBC_WASI */
+
bool
wasm_native_init()
{
@@ -420,6 +581,10 @@ wasm_native_init()
#endif /* WASM_ENABLE_SPEC_TEST */
#if WASM_ENABLE_LIBC_WASI != 0
+ g_wasi_context_key = wasm_native_create_context_key(wasi_context_dtor);
+ if (g_wasi_context_key == NULL) {
+ goto fail;
+ }
n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
if (!wasm_native_register_natives("wasi_unstable", native_symbols,
n_native_symbols))
@@ -507,6 +672,12 @@ wasm_native_destroy()
{
NativeSymbolsNode *node, *node_next;
+#if WASM_ENABLE_LIBC_WASI != 0
+ if (g_wasi_context_key != NULL) {
+ wasm_native_destroy_context_key(g_wasi_context_key);
+ g_wasi_context_key = NULL;
+ }
+#endif
#if WASM_ENABLE_LIB_PTHREAD != 0
lib_pthread_destroy();
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.h
similarity index 70%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.h
index 4f6645d25d8..9ca5265c3ba 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.h
@@ -68,6 +68,36 @@ bool
wasm_native_unregister_natives(const char *module_name,
NativeSymbol *native_symbols);
+#if WASM_ENABLE_MODULE_INST_CONTEXT != 0
+struct WASMModuleInstanceCommon;
+
+void *
+wasm_native_create_context_key(
+ void (*dtor)(struct WASMModuleInstanceCommon *inst, void *ctx));
+
+void
+wasm_native_destroy_context_key(void *key);
+
+void
+wasm_native_set_context(struct WASMModuleInstanceCommon *inst, void *key,
+ void *ctx);
+void
+wasm_native_set_context_spread(struct WASMModuleInstanceCommon *inst, void *key,
+ void *ctx);
+void *
+wasm_native_get_context(struct WASMModuleInstanceCommon *inst, void *key);
+
+void
+wasm_native_call_context_dtors(struct WASMModuleInstanceCommon *inst);
+
+void
+wasm_native_inherit_contexts(struct WASMModuleInstanceCommon *child,
+ struct WASMModuleInstanceCommon *parent);
+#else /* WASM_ENABLE_MODULE_INST_CONTEXT */
+#define wasm_native_call_context_dtors(inst) (void)(inst)
+#define wasm_native_inherit_contexts(child, parent) (void)(parent)
+#endif /* WASM_ENABLE_MODULE_INST_CONTEXT */
+
bool
wasm_native_init();
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.c
similarity index 85%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.c
index 452a2661b93..567e77bec40 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.c
@@ -125,12 +125,40 @@ runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst,
return mem;
}
+#if WASM_ENABLE_MULTI_MODULE != 0
+/* TODO: Let loader_malloc be a general API both for AOT and WASM. */
+
+#define loader_malloc(size, error_buf, error_buf_size) \
+ runtime_malloc(size, NULL, error_buf, error_buf_size)
+
+static void
+set_error_buf_v(const WASMModuleCommon *module, char *error_buf,
+ uint32 error_buf_size, const char *format, ...)
+{
+ va_list args;
+ char buf[128];
+ if (error_buf != NULL) {
+ va_start(args, format);
+ vsnprintf(buf, sizeof(buf), format, args);
+ va_end(args);
+ if (module->module_type == Wasm_Module_AoT) {
+ snprintf(error_buf, error_buf_size, "AOT module load failed: %s",
+ buf);
+ }
+ else if (module->module_type == Wasm_Module_Bytecode) {
+ snprintf(error_buf, error_buf_size, "WASM module load failed: %s",
+ buf);
+ }
+ }
+}
+#endif
+
#if WASM_ENABLE_FAST_JIT != 0
static JitCompOptions jit_options = { 0 };
#endif
#if WASM_ENABLE_JIT != 0
-static LLVMJITOptions llvm_jit_options = { 3, 3 };
+static LLVMJITOptions llvm_jit_options = { 3, 3, 0, false };
#endif
static RunningMode runtime_running_mode = Mode_Default;
@@ -199,7 +227,90 @@ runtime_signal_handler(void *sig_addr)
}
}
}
-#else
+#else /* else of BH_PLATFORM_WINDOWS */
+
+#if WASM_ENABLE_AOT != 0
+#include
+
+static uint32
+decode_insn(uint8 *insn)
+{
+ uint8 *data = (uint8 *)insn;
+ uint32 length = 32; /* reserve enough size */
+
+ /* Initialize decoder context */
+ ZydisDecoder decoder;
+ ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64,
+ ZYDIS_STACK_WIDTH_64);
+
+ /* Initialize formatter */
+ ZydisFormatter formatter;
+ ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
+
+ /* Loop over the instructions in our buffer */
+ ZyanU64 runtime_address = (ZyanU64)(uintptr_t)data;
+ ZyanUSize offset = 0;
+ ZydisDecodedInstruction instruction;
+ ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
+ char buffer[256];
+
+ if (ZYAN_SUCCESS(ZydisDecoderDecodeFull(
+ &decoder, data + offset, length - offset, &instruction, operands,
+ ZYDIS_MAX_OPERAND_COUNT_VISIBLE,
+ ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY))) {
+
+ /* Format & print the binary instruction structure to
+ human readable format */
+ ZydisFormatterFormatInstruction(&formatter, &instruction, operands,
+ instruction.operand_count_visible,
+ buffer, sizeof(buffer),
+ runtime_address);
+
+ /* Print current instruction */
+ /*
+ os_printf("%012" PRIX64 " ", runtime_address);
+ puts(buffer);
+ */
+
+ return instruction.length;
+ }
+
+ /* Decode failed */
+ return 0;
+}
+#endif /* end of WASM_ENABLE_AOT != 0 */
+
+static LONG
+next_action(WASMModuleInstance *module_inst, EXCEPTION_POINTERS *exce_info)
+{
+#if WASM_ENABLE_AOT != 0
+ uint32 insn_size;
+#endif
+
+ if (module_inst->module_type == Wasm_Module_Bytecode
+ && module_inst->e->running_mode == Mode_Interp) {
+ /* Continue to search next exception handler for
+ interpreter mode as it can be caught by
+ `__try { .. } __except { .. }` sentences in
+ wasm_runtime.c */
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+
+#if WASM_ENABLE_AOT != 0
+ /* Skip current instruction and continue to run for AOT/JIT mode.
+ TODO: implement unwind support for AOT/JIT code in Windows platform */
+ insn_size = decode_insn((uint8 *)exce_info->ContextRecord->Rip);
+ if (insn_size > 0) {
+ exce_info->ContextRecord->Rip += insn_size;
+ return EXCEPTION_CONTINUE_EXECUTION;
+ }
+#endif
+
+ /* return different value from EXCEPTION_CONTINUE_SEARCH (= 0)
+ and EXCEPTION_CONTINUE_EXECUTION (= -1) */
+ return -2;
+}
+
static LONG
runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
{
@@ -211,6 +322,7 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
uint8 *mapped_mem_start_addr = NULL;
uint8 *mapped_mem_end_addr = NULL;
uint32 page_size = os_getpagesize();
+ LONG ret;
if (exec_env_tls && exec_env_tls->handle == os_self_thread()
&& (jmpbuf_node = exec_env_tls->jmpbuf_stack_top)) {
@@ -232,32 +344,19 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
the wasm func returns, the caller will check whether the
exception is thrown and return to runtime. */
wasm_set_exception(module_inst, "out of bounds memory access");
- if (module_inst->module_type == Wasm_Module_Bytecode) {
- /* Continue to search next exception handler for
- interpreter mode as it can be caught by
- `__try { .. } __except { .. }` sentences in
- wasm_runtime.c */
- return EXCEPTION_CONTINUE_SEARCH;
- }
- else {
- /* Skip current instruction and continue to run for
- AOT mode. TODO: implement unwind support for AOT
- code in Windows platform */
- exce_info->ContextRecord->Rip++;
- return EXCEPTION_CONTINUE_EXECUTION;
- }
+ ret = next_action(module_inst, exce_info);
+ if (ret == EXCEPTION_CONTINUE_SEARCH
+ || ret == EXCEPTION_CONTINUE_EXECUTION)
+ return ret;
}
else if (exec_env_tls->exce_check_guard_page <= (uint8 *)sig_addr
&& (uint8 *)sig_addr
< exec_env_tls->exce_check_guard_page + page_size) {
bh_assert(wasm_copy_exception(module_inst, NULL));
- if (module_inst->module_type == Wasm_Module_Bytecode) {
- return EXCEPTION_CONTINUE_SEARCH;
- }
- else {
- exce_info->ContextRecord->Rip++;
- return EXCEPTION_CONTINUE_EXECUTION;
- }
+ ret = next_action(module_inst, exce_info);
+ if (ret == EXCEPTION_CONTINUE_SEARCH
+ || ret == EXCEPTION_CONTINUE_EXECUTION)
+ return ret;
}
}
#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
@@ -267,12 +366,10 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
whether the exception is thrown and return to runtime, and
the damaged stack will be recovered by _resetstkoflw(). */
wasm_set_exception(module_inst, "native stack overflow");
- if (module_inst->module_type == Wasm_Module_Bytecode) {
- return EXCEPTION_CONTINUE_SEARCH;
- }
- else {
- return EXCEPTION_CONTINUE_EXECUTION;
- }
+ ret = next_action(module_inst, exce_info);
+ if (ret == EXCEPTION_CONTINUE_SEARCH
+ || ret == EXCEPTION_CONTINUE_EXECUTION)
+ return ret;
}
#endif
}
@@ -388,8 +485,21 @@ wasm_runtime_env_init()
}
#endif
+#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP)
+ if (os_blocking_op_init() != BHT_OK) {
+ goto fail11;
+ }
+ os_end_blocking_op();
+#endif
+
return true;
+#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP)
+fail11:
+#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
+ aot_compiler_destroy();
+#endif
+#endif
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
fail10:
#if WASM_ENABLE_FAST_JIT != 0
@@ -552,8 +662,14 @@ wasm_runtime_full_init(RuntimeInitArgs *init_args)
#endif
#if WASM_ENABLE_JIT != 0
+ LOG_DEBUG("Start LLVM_JIT, opt_sz=%u, opt_lvl=%u, segue=%s, linux_perf=%s",
+ init_args->llvm_jit_size_level, init_args->llvm_jit_opt_level,
+ init_args->segue_flags ? "Yes" : "No",
+ init_args->linux_perf_support ? "Yes" : "No");
llvm_jit_options.size_level = init_args->llvm_jit_size_level;
llvm_jit_options.opt_level = init_args->llvm_jit_opt_level;
+ llvm_jit_options.segue_flags = init_args->segue_flags;
+ llvm_jit_options.linux_perf_support = init_args->linux_perf_support;
#endif
if (!wasm_runtime_env_init()) {
@@ -1115,27 +1231,34 @@ wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf,
if (get_package_type(buf, size) == Wasm_Module_Bytecode) {
#if WASM_ENABLE_INTERP != 0
module_common =
- (WASMModuleCommon *)wasm_load(buf, size, error_buf, error_buf_size);
- return register_module_with_null_name(module_common, error_buf,
- error_buf_size);
+ (WASMModuleCommon *)wasm_load(buf, size,
+#if WASM_ENABLE_MULTI_MODULE != 0
+ true,
+#endif
+ error_buf, error_buf_size);
#endif
}
else if (get_package_type(buf, size) == Wasm_Module_AoT) {
#if WASM_ENABLE_AOT != 0
module_common = (WASMModuleCommon *)aot_load_from_aot_file(
buf, size, error_buf, error_buf_size);
- return register_module_with_null_name(module_common, error_buf,
- error_buf_size);
#endif
}
-
- if (size < 4)
- set_error_buf(error_buf, error_buf_size,
- "WASM module load failed: unexpected end");
- else
- set_error_buf(error_buf, error_buf_size,
- "WASM module load failed: magic header not detected");
- return NULL;
+ else {
+ if (size < 4)
+ set_error_buf(error_buf, error_buf_size,
+ "WASM module load failed: unexpected end");
+ else
+ set_error_buf(error_buf, error_buf_size,
+ "WASM module load failed: magic header not detected");
+ return NULL;
+ }
+ if (!module_common) {
+ LOG_DEBUG("WASM module load failed");
+ return NULL;
+ }
+ return register_module_with_null_name(module_common, error_buf,
+ error_buf_size);
}
WASMModuleCommon *
@@ -1148,6 +1271,10 @@ wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
#if WASM_ENABLE_INTERP != 0
module_common = (WASMModuleCommon *)wasm_load_from_sections(
section_list, error_buf, error_buf_size);
+ if (!module_common) {
+ LOG_DEBUG("WASM module load failed from sections");
+ return NULL;
+ }
return register_module_with_null_name(module_common, error_buf,
error_buf_size);
#endif
@@ -1156,6 +1283,10 @@ wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
#if WASM_ENABLE_AOT != 0
module_common = (WASMModuleCommon *)aot_load_from_sections(
section_list, error_buf, error_buf_size);
+ if (!module_common) {
+ LOG_DEBUG("WASM module load failed from sections");
+ return NULL;
+ }
return register_module_with_null_name(module_common, error_buf,
error_buf_size);
#endif
@@ -1195,7 +1326,8 @@ wasm_runtime_unload(WASMModuleCommon *module)
}
WASMModuleInstanceCommon *
-wasm_runtime_instantiate_internal(WASMModuleCommon *module, bool is_sub_inst,
+wasm_runtime_instantiate_internal(WASMModuleCommon *module,
+ WASMModuleInstanceCommon *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, char *error_buf,
uint32 error_buf_size)
@@ -1203,14 +1335,14 @@ wasm_runtime_instantiate_internal(WASMModuleCommon *module, bool is_sub_inst,
#if WASM_ENABLE_INTERP != 0
if (module->module_type == Wasm_Module_Bytecode)
return (WASMModuleInstanceCommon *)wasm_instantiate(
- (WASMModule *)module, is_sub_inst, exec_env_main, stack_size,
- heap_size, error_buf, error_buf_size);
+ (WASMModule *)module, (WASMModuleInstance *)parent, exec_env_main,
+ stack_size, heap_size, error_buf, error_buf_size);
#endif
#if WASM_ENABLE_AOT != 0
if (module->module_type == Wasm_Module_AoT)
return (WASMModuleInstanceCommon *)aot_instantiate(
- (AOTModule *)module, is_sub_inst, exec_env_main, stack_size,
- heap_size, error_buf, error_buf_size);
+ (AOTModule *)module, (AOTModuleInstance *)parent, exec_env_main,
+ stack_size, heap_size, error_buf, error_buf_size);
#endif
set_error_buf(error_buf, error_buf_size,
"Instantiate module failed, invalid module type");
@@ -1223,7 +1355,7 @@ wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size,
uint32 error_buf_size)
{
return wasm_runtime_instantiate_internal(
- module, false, NULL, stack_size, heap_size, error_buf, error_buf_size);
+ module, NULL, NULL, stack_size, heap_size, error_buf, error_buf_size);
}
void
@@ -1321,6 +1453,10 @@ wasm_runtime_init_thread_env(void)
}
#endif
+#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP)
+ os_end_blocking_op();
+#endif
+
return true;
}
@@ -1867,33 +2003,6 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env,
}
#endif
-static bool
-clear_wasi_proc_exit_exception(WASMModuleInstanceCommon *module_inst_comm)
-{
-#if WASM_ENABLE_LIBC_WASI != 0
- bool has_exception;
- char exception[EXCEPTION_BUF_LEN];
- WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
-
- bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
- || module_inst_comm->module_type == Wasm_Module_AoT);
-
- has_exception = wasm_copy_exception(module_inst, exception);
- if (has_exception && !strcmp(exception, "Exception: wasi proc exit")) {
- /* The "wasi proc exit" exception is thrown by native lib to
- let wasm app exit, which is a normal behavior, we clear
- the exception here. And just clear the exception of current
- thread, don't call `wasm_set_exception(module_inst, NULL)`
- which will clear the exception of all threads. */
- module_inst->cur_exception[0] = '\0';
- return true;
- }
- return false;
-#else
- return false;
-#endif
-}
-
bool
wasm_runtime_call_wasm(WASMExecEnv *exec_env,
WASMFunctionInstanceCommon *function, uint32 argc,
@@ -1934,15 +2043,10 @@ wasm_runtime_call_wasm(WASMExecEnv *exec_env,
param_argc, new_argv);
#endif
if (!ret) {
- if (clear_wasi_proc_exit_exception(exec_env->module_inst)) {
- ret = true;
- }
- else {
- if (new_argv != argv) {
- wasm_runtime_free(new_argv);
- }
- return false;
+ if (new_argv != argv) {
+ wasm_runtime_free(new_argv);
}
+ return false;
}
#if WASM_ENABLE_REF_TYPES != 0
@@ -2303,17 +2407,10 @@ wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst_comm)
return module_inst->exec_env_singleton;
}
-void
-wasm_set_exception(WASMModuleInstance *module_inst, const char *exception)
+static void
+wasm_set_exception_local(WASMModuleInstance *module_inst, const char *exception)
{
- WASMExecEnv *exec_env = NULL;
-
-#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *node =
- wasm_module_get_shared_memory((WASMModuleCommon *)module_inst->module);
- if (node)
- os_mutex_lock(&node->shared_mem_lock);
-#endif
+ exception_lock(module_inst);
if (exception) {
snprintf(module_inst->cur_exception, sizeof(module_inst->cur_exception),
"Exception: %s", exception);
@@ -2321,19 +2418,23 @@ wasm_set_exception(WASMModuleInstance *module_inst, const char *exception)
else {
module_inst->cur_exception[0] = '\0';
}
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_unlock(&node->shared_mem_lock);
-#endif
+ exception_unlock(module_inst);
+}
+void
+wasm_set_exception(WASMModuleInstance *module_inst, const char *exception)
+{
#if WASM_ENABLE_THREAD_MGR != 0
- exec_env =
+ WASMExecEnv *exec_env =
wasm_clusters_search_exec_env((WASMModuleInstanceCommon *)module_inst);
if (exec_env) {
- wasm_cluster_spread_exception(exec_env, exception ? false : true);
+ wasm_cluster_set_exception(exec_env, exception);
+ }
+ else {
+ wasm_set_exception_local(module_inst, exception);
}
#else
- (void)exec_env;
+ wasm_set_exception_local(module_inst, exception);
#endif
}
@@ -2384,12 +2485,7 @@ wasm_copy_exception(WASMModuleInstance *module_inst, char *exception_buf)
{
bool has_exception = false;
-#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *node =
- wasm_module_get_shared_memory((WASMModuleCommon *)module_inst->module);
- if (node)
- os_mutex_lock(&node->shared_mem_lock);
-#endif
+ exception_lock(module_inst);
if (module_inst->cur_exception[0] != '\0') {
/* NULL is passed if the caller is not interested in getting the
* exception content, but only in knowing if an exception has been
@@ -2401,10 +2497,7 @@ wasm_copy_exception(WASMModuleInstance *module_inst, char *exception_buf)
sizeof(module_inst->cur_exception));
has_exception = true;
}
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (node)
- os_mutex_unlock(&node->shared_mem_lock);
-#endif
+ exception_unlock(module_inst);
return has_exception;
}
@@ -2449,6 +2542,18 @@ wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst_comm)
wasm_runtime_set_exception(module_inst_comm, NULL);
}
+#if WASM_ENABLE_THREAD_MGR != 0
+void
+wasm_runtime_terminate(WASMModuleInstanceCommon *module_inst_comm)
+{
+ WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
+
+ bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
+ || module_inst_comm->module_type == Wasm_Module_AoT);
+ wasm_set_exception(module_inst, "terminated by user");
+}
+#endif
+
void
wasm_runtime_set_custom_data_internal(
WASMModuleInstanceCommon *module_inst_comm, void *custom_data)
@@ -2481,6 +2586,54 @@ wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst_comm)
return module_inst->custom_data;
}
+#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
+void
+wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
+ bool enable)
+{
+ /* Alwary disable bounds checks if hw bounds checks enabled */
+#ifdef OS_ENABLE_HW_BOUND_CHECK
+ enable = false;
+#endif
+#if WASM_ENABLE_INTERP != 0
+ if (module_inst->module_type == Wasm_Module_Bytecode) {
+ ((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e)
+ ->common.disable_bounds_checks = enable ? false : true;
+ }
+#endif
+
+#if WASM_ENABLE_AOT != 0
+ if (module_inst->module_type == Wasm_Module_AoT) {
+ ((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
+ ->common.disable_bounds_checks = enable ? false : true;
+ }
+#endif
+}
+
+bool
+wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst)
+{
+
+#if WASM_ENABLE_INTERP != 0
+ if (module_inst->module_type == Wasm_Module_Bytecode) {
+ return !((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)
+ ->e)
+ ->common.disable_bounds_checks;
+ }
+#endif
+
+#if WASM_ENABLE_AOT != 0
+ if (module_inst->module_type == Wasm_Module_AoT) {
+ return !((AOTModuleInstanceExtra *)((WASMModuleInstance *)module_inst)
+ ->e)
+ ->common.disable_bounds_checks;
+ }
+#endif
+
+ return true;
+}
+#endif
+
uint32
wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
WASMExecEnv *exec_env, uint32 size,
@@ -2630,7 +2783,7 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
uint32 dir_count, const char *map_dir_list[],
uint32 map_dir_count, const char *env_list[],
uint32 env_count, char *argv[], int argc,
- int stdinfd, int stdoutfd, int stderrfd)
+ int64 stdinfd, int64 stdoutfd, int64 stderrfd)
{
WASIArguments *wasi_args = get_wasi_args_from_module(module);
@@ -2644,9 +2797,9 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
wasi_args->env_count = env_count;
wasi_args->argv = argv;
wasi_args->argc = (uint32)argc;
- wasi_args->stdio[0] = stdinfd;
- wasi_args->stdio[1] = stdoutfd;
- wasi_args->stdio[2] = stderrfd;
+ wasi_args->stdio[0] = (os_raw_file_handle)stdinfd;
+ wasi_args->stdio[1] = (os_raw_file_handle)stdoutfd;
+ wasi_args->stdio[2] = (os_raw_file_handle)stderrfd;
#if WASM_ENABLE_MULTI_MODULE != 0
#if WASM_ENABLE_INTERP != 0
@@ -2741,8 +2894,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
const char *env[], uint32 env_count,
const char *addr_pool[], uint32 addr_pool_size,
const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
- char *argv[], uint32 argc, int stdinfd, int stdoutfd,
- int stderrfd, char *error_buf, uint32 error_buf_size)
+ char *argv[], uint32 argc, os_raw_file_handle stdinfd,
+ os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
+ char *error_buf, uint32 error_buf_size)
{
WASIContext *wasi_ctx;
char *argv_buf = NULL;
@@ -2760,7 +2914,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
bool argv_environ_inited = false;
bool addr_pool_inited = false;
__wasi_fd_t wasm_fd = 3;
- int32 raw_fd;
+ os_file_handle file_handle;
char *path, resolved_path[PATH_MAX];
uint32 i;
@@ -2830,15 +2984,19 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
}
addr_pool_inited = true;
- /* Prepopulate curfds with stdin, stdout, and stderr file descriptors.
- *
- * If -1 is given, use STDIN_FILENO (0), STDOUT_FILENO (1),
- * STDERR_FILENO (2) respectively.
- */
- if (!fd_table_insert_existing(curfds, 0, (stdinfd != -1) ? stdinfd : 0)
- || !fd_table_insert_existing(curfds, 1, (stdoutfd != -1) ? stdoutfd : 1)
- || !fd_table_insert_existing(curfds, 2,
- (stderrfd != -1) ? stderrfd : 2)) {
+ os_file_handle stdin_file_handle = os_convert_stdin_handle(stdinfd);
+ os_file_handle stdout_file_handle = os_convert_stdout_handle(stdoutfd);
+ os_file_handle stderr_file_handle = os_convert_stderr_handle(stderrfd);
+
+ if (!os_is_handle_valid(&stdin_file_handle)
+ || !os_is_handle_valid(&stdout_file_handle)
+ || !os_is_handle_valid(&stderr_file_handle))
+ goto fail;
+
+ /* Prepopulate curfds with stdin, stdout, and stderr file descriptors. */
+ if (!fd_table_insert_existing(curfds, 0, stdin_file_handle, true)
+ || !fd_table_insert_existing(curfds, 1, stdout_file_handle, true)
+ || !fd_table_insert_existing(curfds, 2, stderr_file_handle, true)) {
set_error_buf(error_buf, error_buf_size,
"Init wasi environment failed: init fd table failed");
goto fail;
@@ -2846,7 +3004,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
wasm_fd = 3;
for (i = 0; i < dir_count; i++, wasm_fd++) {
- path = realpath(dir_list[i], resolved_path);
+ path = os_realpath(dir_list[i], resolved_path);
if (!path) {
if (error_buf)
snprintf(error_buf, error_buf_size,
@@ -2855,17 +3013,101 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
goto fail;
}
- raw_fd = open(path, O_RDONLY | O_DIRECTORY, 0);
- if (raw_fd == -1) {
+ __wasi_errno_t error = os_open_preopendir(path, &file_handle);
+
+ if (error != __WASI_ESUCCESS) {
if (error_buf)
snprintf(error_buf, error_buf_size,
"error while pre-opening directory %s: %d\n",
- dir_list[i], errno);
+ dir_list[i], error);
goto fail;
}
- fd_table_insert_existing(curfds, wasm_fd, raw_fd);
- fd_prestats_insert(prestats, dir_list[i], wasm_fd);
+ if (!fd_table_insert_existing(curfds, wasm_fd, file_handle, false)) {
+ if (error_buf)
+ snprintf(error_buf, error_buf_size,
+ "error inserting preopen fd %u (directory %s) into fd "
+ "table",
+ (unsigned int)wasm_fd, dir_list[i]);
+ goto fail;
+ }
+
+ if (!fd_prestats_insert(prestats, dir_list[i], wasm_fd)) {
+ if (error_buf)
+ snprintf(error_buf, error_buf_size,
+ "error inserting preopen fd %u (directory %s) into "
+ "prestats table",
+ (unsigned int)wasm_fd, dir_list[i]);
+ goto fail;
+ }
+ }
+
+ for (i = 0; i < map_dir_count; i++, wasm_fd++) {
+ char mapping_copy_buf[256];
+ char *mapping_copy = mapping_copy_buf;
+ char *map_mapped = NULL, *map_host = NULL;
+ const unsigned long max_len = strlen(map_dir_list[i]) * 2 + 3;
+
+ /* Allocation limit for runtime environments with reduced stack size */
+ if (max_len > 256) {
+ if (!(mapping_copy = wasm_runtime_malloc(max_len))) {
+ snprintf(error_buf, error_buf_size,
+ "error while allocating for directory mapping\n");
+ goto fail;
+ }
+ }
+
+ bh_memcpy_s(mapping_copy, max_len, map_dir_list[i],
+ (uint32)(strlen(map_dir_list[i]) + 1));
+ map_mapped = strtok(mapping_copy, "::");
+ map_host = strtok(NULL, "::");
+
+ if (!map_mapped || !map_host) {
+ if (error_buf)
+ snprintf(error_buf, error_buf_size,
+ "error while pre-opening mapped directory: "
+ "invalid map\n");
+ if (mapping_copy != mapping_copy_buf)
+ wasm_runtime_free(mapping_copy);
+ goto fail;
+ }
+
+ path = os_realpath(map_host, resolved_path);
+ if (!path) {
+ if (error_buf)
+ snprintf(error_buf, error_buf_size,
+ "error while pre-opening mapped directory %s: %d\n",
+ map_host, errno);
+ if (mapping_copy != mapping_copy_buf)
+ wasm_runtime_free(mapping_copy);
+ goto fail;
+ }
+
+ __wasi_errno_t error = os_open_preopendir(path, &file_handle);
+ if (error != __WASI_ESUCCESS) {
+ if (error_buf)
+ snprintf(error_buf, error_buf_size,
+ "error while pre-opening mapped directory %s: %d\n",
+ map_host, errno);
+ if (mapping_copy != mapping_copy_buf)
+ wasm_runtime_free(mapping_copy);
+ goto fail;
+ }
+
+ if (!fd_table_insert_existing(curfds, wasm_fd, file_handle, false)
+ || !fd_prestats_insert(prestats, map_mapped, wasm_fd)) {
+ if (error_buf)
+ snprintf(error_buf, error_buf_size,
+ "error while pre-opening mapped directory %s: "
+ "insertion failed\n",
+ dir_list[i]);
+ if (mapping_copy != mapping_copy_buf)
+ wasm_runtime_free(mapping_copy);
+ goto fail;
+ }
+
+ if (mapping_copy != mapping_copy_buf)
+ wasm_runtime_free(mapping_copy);
}
/* addr_pool(textual) -> apool */
@@ -2993,8 +3235,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
const char *env[], uint32 env_count,
const char *addr_pool[], uint32 addr_pool_size,
const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
- char *argv[], uint32 argc, int stdinfd, int stdoutfd,
- int stderrfd, char *error_buf, uint32 error_buf_size)
+ char *argv[], uint32 argc, os_raw_file_handle stdinfd,
+ os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
+ char *error_buf, uint32 error_buf_size)
{
WASIContext *ctx;
uvwasi_t *uvwasi;
@@ -3212,27 +3455,6 @@ wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst)
#endif
return wasi_ctx->exit_code;
}
-
-WASIContext *
-wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm)
-{
- WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
-
- bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
- || module_inst_comm->module_type == Wasm_Module_AoT);
- return module_inst->wasi_ctx;
-}
-
-void
-wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm,
- WASIContext *wasi_ctx)
-{
- WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
-
- bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
- || module_inst_comm->module_type == Wasm_Module_AoT);
- module_inst->wasi_ctx = wasi_ctx;
-}
#endif /* end of WASM_ENABLE_LIBC_WASI */
WASMModuleCommon *
@@ -3801,16 +4023,14 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
if (n_stacks & 1)
n_stacks++;
if (func_type->types[i] == VALUE_TYPE_F32) {
- *(float32 *)&stacks[n_stacks] = *(float32 *)argv_src++;
- /* NaN boxing, the upper bits of a valid NaN-boxed
- value must be all 1s. */
- stacks[n_stacks + 1] = 0xFFFFFFFF;
+ *(float32 *)&stacks[n_stacks++] =
+ *(float32 *)argv_src++;
}
else {
*(float64 *)&stacks[n_stacks] = *(float64 *)argv_src;
argv_src += 2;
+ n_stacks += 2;
}
- n_stacks += 2;
}
break;
}
@@ -4212,6 +4432,14 @@ static V128FuncPtr invokeNative_V128 = (V128FuncPtr)(uintptr_t)invokeNative;
|| defined(BUILD_TARGET_RISCV64_LP64) */
#endif /* end of defined(_WIN32) || defined(_WIN32_) */
+/*
+ * ASAN is not designed to work with custom stack unwind or other low-level
+ * things. Ignore a function that does some low-level magic. (e.g. walking
+ * through the thread's stack bypassing the frame boundaries)
+ */
+#if defined(__GNUC__) || defined(__clang__)
+__attribute__((no_sanitize_address))
+#endif
bool
wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
const WASMType *func_type, const char *signature,
@@ -4489,10 +4717,6 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_index,
ret = aot_call_indirect(exec_env, 0, element_index, argc, argv);
#endif
- if (!ret && clear_wasi_proc_exit_exception(exec_env->module_inst)) {
- ret = true;
- }
-
return ret;
}
@@ -4629,6 +4853,8 @@ typedef struct ExternRefMapNode {
bool retained;
/* Whether it is marked by runtime */
bool marked;
+ /* cleanup function called when the externref is freed */
+ void (*cleanup)(void *);
} ExternRefMapNode;
static uint32
@@ -4691,6 +4917,81 @@ lookup_extobj_callback(void *key, void *value, void *user_data)
}
}
+static void
+delete_externref(void *key, ExternRefMapNode *node)
+{
+ bh_hash_map_remove(externref_map, key, NULL, NULL);
+ if (node->cleanup) {
+ (*node->cleanup)(node->extern_obj);
+ }
+ wasm_runtime_free(node);
+}
+
+static void
+delete_extobj_callback(void *key, void *value, void *user_data)
+{
+ ExternRefMapNode *node = (ExternRefMapNode *)value;
+ LookupExtObj_UserData *lookup_user_data =
+ (LookupExtObj_UserData *)user_data;
+
+ if (node->extern_obj == lookup_user_data->node.extern_obj
+ && node->module_inst == lookup_user_data->node.module_inst) {
+ lookup_user_data->found = true;
+ delete_externref(key, node);
+ }
+}
+
+bool
+wasm_externref_objdel(WASMModuleInstanceCommon *module_inst, void *extern_obj)
+{
+ LookupExtObj_UserData lookup_user_data = { 0 };
+ bool ok = false;
+
+ /* in a wrapper, extern_obj could be any value */
+ lookup_user_data.node.extern_obj = extern_obj;
+ lookup_user_data.node.module_inst = module_inst;
+ lookup_user_data.found = false;
+
+ os_mutex_lock(&externref_lock);
+ /* Lookup hashmap firstly */
+ bh_hash_map_traverse(externref_map, delete_extobj_callback,
+ (void *)&lookup_user_data);
+ if (lookup_user_data.found) {
+ ok = true;
+ }
+ os_mutex_unlock(&externref_lock);
+
+ return ok;
+}
+
+bool
+wasm_externref_set_cleanup(WASMModuleInstanceCommon *module_inst,
+ void *extern_obj, void (*extern_obj_cleanup)(void *))
+{
+
+ LookupExtObj_UserData lookup_user_data = { 0 };
+ bool ok = false;
+
+ /* in a wrapper, extern_obj could be any value */
+ lookup_user_data.node.extern_obj = extern_obj;
+ lookup_user_data.node.module_inst = module_inst;
+ lookup_user_data.found = false;
+
+ os_mutex_lock(&externref_lock);
+ /* Lookup hashmap firstly */
+ bh_hash_map_traverse(externref_map, lookup_extobj_callback,
+ (void *)&lookup_user_data);
+ if (lookup_user_data.found) {
+ void *key = (void *)(uintptr_t)lookup_user_data.externref_idx;
+ ExternRefMapNode *node = bh_hash_map_find(externref_map, key);
+ node->cleanup = extern_obj_cleanup;
+ ok = true;
+ }
+ os_mutex_unlock(&externref_lock);
+
+ return ok;
+}
+
bool
wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj,
uint32 *p_externref_idx)
@@ -4740,6 +5041,7 @@ wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj,
memset(node, 0, sizeof(ExternRefMapNode));
node->extern_obj = extern_obj;
node->module_inst = module_inst;
+ node->cleanup = NULL;
externref_idx = externref_global_id;
@@ -4790,8 +5092,7 @@ reclaim_extobj_callback(void *key, void *value, void *user_data)
if (node->module_inst == module_inst) {
if (!node->marked && !node->retained) {
- bh_hash_map_remove(externref_map, key, NULL, NULL);
- wasm_runtime_free(value);
+ delete_externref(key, node);
}
else {
node->marked = false;
@@ -4906,8 +5207,7 @@ cleanup_extobj_callback(void *key, void *value, void *user_data)
(WASMModuleInstanceCommon *)user_data;
if (node->module_inst == module_inst) {
- bh_hash_map_remove(externref_map, key, NULL, NULL);
- wasm_runtime_free(value);
+ delete_externref(key, node);
}
}
@@ -5026,6 +5326,33 @@ wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
}
#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */
+#if WASM_ENABLE_STATIC_PGO != 0
+uint32
+wasm_runtime_get_pgo_prof_data_size(WASMModuleInstanceCommon *module_inst)
+{
+#if WASM_ENABLE_AOT != 0
+ if (module_inst->module_type == Wasm_Module_AoT) {
+ AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst;
+ return aot_get_pgo_prof_data_size(aot_inst);
+ }
+#endif
+ return 0;
+}
+
+uint32
+wasm_runtime_dump_pgo_prof_data_to_buf(WASMModuleInstanceCommon *module_inst,
+ char *buf, uint32 len)
+{
+#if WASM_ENABLE_AOT != 0
+ if (module_inst->module_type == Wasm_Module_AoT) {
+ AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst;
+ return aot_dump_pgo_prof_data_to_buf(aot_inst, buf, len);
+ }
+#endif
+ return 0;
+}
+#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
+
bool
wasm_runtime_get_table_elem_type(const WASMModuleCommon *module_comm,
uint32 table_idx, uint8 *out_elem_type,
@@ -5473,3 +5800,345 @@ wasm_runtime_is_import_global_linked(const char *module_name,
return false;
#endif
}
+
+#if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0
+WASMExport *
+loader_find_export(const WASMModuleCommon *module, const char *module_name,
+ const char *field_name, uint8 export_kind, char *error_buf,
+ uint32 error_buf_size)
+{
+ WASMExport *exports = NULL, *result = NULL, *export;
+ uint32 export_count = 0, i;
+#if WASM_ENABLE_AOT != 0
+ if (module->module_type == Wasm_Module_AoT) {
+ AOTModule *aot_module = (AOTModule *)module;
+ exports = (WASMExport *)aot_module->exports;
+ export_count = aot_module->export_count;
+ }
+#endif
+#if WASM_ENABLE_INTERP != 0
+ if (module->module_type == Wasm_Module_Bytecode) {
+ WASMModule *wasm_module = (WASMModule *)module;
+ exports = wasm_module->exports;
+ export_count = wasm_module->export_count;
+ }
+#endif
+ for (i = 0, export = exports; i < export_count; ++i, ++export) {
+ if (export->kind == export_kind && !strcmp(field_name, export->name)) {
+ result = export;
+ goto exit;
+ }
+ }
+ if (i == export_count) {
+ LOG_DEBUG("can not find an export %d named %s in the module %s",
+ export_kind, field_name, module_name);
+ set_error_buf(error_buf, error_buf_size,
+ "unknown import or incompatible import type");
+ }
+exit:
+ return result;
+}
+#endif
+
+#if WASM_ENABLE_MULTI_MODULE != 0
+WASMModuleCommon *
+wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module,
+ const char *sub_module_name)
+{
+ WASMRegisteredModule *node = NULL;
+#if WASM_ENABLE_AOT != 0
+ if (parent_module->module_type == Wasm_Module_AoT) {
+ node = bh_list_first_elem(
+ ((AOTModule *)parent_module)->import_module_list);
+ }
+#endif
+#if WASM_ENABLE_INTERP != 0
+ if (parent_module->module_type == Wasm_Module_Bytecode) {
+ node = bh_list_first_elem(
+ ((WASMModule *)parent_module)->import_module_list);
+ }
+#endif
+ while (node && strcmp(sub_module_name, node->module_name)) {
+ node = bh_list_elem_next(node);
+ }
+ return node ? node->module : NULL;
+}
+
+bool
+wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
+ const char *sub_module_name,
+ WASMModuleCommon *sub_module)
+{
+ /* register sub_module into its parent sub module list */
+ WASMRegisteredModule *node = NULL;
+ bh_list_status ret = BH_LIST_ERROR;
+
+ if (wasm_runtime_search_sub_module(parent_module, sub_module_name)) {
+ LOG_DEBUG("%s has been registered in its parent", sub_module_name);
+ return true;
+ }
+
+ node = loader_malloc(sizeof(WASMRegisteredModule), NULL, 0);
+ if (!node) {
+ return false;
+ }
+
+ node->module_name = sub_module_name;
+ node->module = sub_module;
+#if WASM_ENABLE_AOT != 0
+ if (parent_module->module_type == Wasm_Module_AoT) {
+ ret = bh_list_insert(((AOTModule *)parent_module)->import_module_list,
+ node);
+ }
+#endif
+#if WASM_ENABLE_INTERP != 0
+ if (parent_module->module_type == Wasm_Module_Bytecode) {
+ ret = bh_list_insert(((WASMModule *)parent_module)->import_module_list,
+ node);
+ }
+#endif
+ bh_assert(BH_LIST_SUCCESS == ret);
+ (void)ret;
+ return true;
+}
+
+WASMModuleCommon *
+wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
+ const char *sub_module_name, char *error_buf,
+ uint32 error_buf_size)
+{
+ WASMModuleCommon *sub_module = NULL;
+ bool ret = false;
+ uint8 *buffer = NULL;
+ uint32 buffer_size = 0;
+
+ /* check the registered module list of the parent */
+ sub_module = wasm_runtime_search_sub_module(parent_module, sub_module_name);
+ if (sub_module) {
+ LOG_DEBUG("%s has been loaded before", sub_module_name);
+ return sub_module;
+ }
+
+ /* check the global registered module list */
+ sub_module = wasm_runtime_find_module_registered(sub_module_name);
+ if (sub_module) {
+ LOG_DEBUG("%s has been loaded", sub_module_name);
+ goto wasm_runtime_register_sub_module;
+ }
+ LOG_VERBOSE("loading %s", sub_module_name);
+ if (!reader) {
+ set_error_buf_v(parent_module, error_buf, error_buf_size,
+ "no sub module reader to load %s", sub_module_name);
+ return NULL;
+ }
+ /* start to maintain a loading module list */
+ ret = wasm_runtime_is_loading_module(sub_module_name);
+ if (ret) {
+ set_error_buf_v(parent_module, error_buf, error_buf_size,
+ "found circular dependency on %s", sub_module_name);
+ return NULL;
+ }
+ ret = wasm_runtime_add_loading_module(sub_module_name, error_buf,
+ error_buf_size);
+ if (!ret) {
+ LOG_DEBUG("can not add %s into loading module list\n", sub_module_name);
+ return NULL;
+ }
+
+ ret = reader(parent_module->module_type, sub_module_name, &buffer,
+ &buffer_size);
+ if (!ret) {
+ LOG_DEBUG("read the file of %s failed", sub_module_name);
+ set_error_buf_v(parent_module, error_buf, error_buf_size,
+ "unknown import", sub_module_name);
+ goto delete_loading_module;
+ }
+ if (get_package_type(buffer, buffer_size) != parent_module->module_type) {
+ LOG_DEBUG("moudle %s type error", sub_module_name);
+ goto delete_loading_module;
+ }
+ if (get_package_type(buffer, buffer_size) == Wasm_Module_Bytecode) {
+#if WASM_ENABLE_INTERP != 0
+ sub_module = (WASMModuleCommon *)wasm_load(buffer, buffer_size, false,
+ error_buf, error_buf_size);
+#endif
+ }
+ else if (get_package_type(buffer, buffer_size) == Wasm_Module_AoT) {
+#if WASM_ENABLE_AOT != 0
+ sub_module = (WASMModuleCommon *)aot_load_from_aot_file(
+ buffer, buffer_size, error_buf, error_buf_size);
+#endif
+ }
+ if (!sub_module) {
+ LOG_DEBUG("error: can not load the sub_module %s", sub_module_name);
+ /* others will be destroyed in runtime_destroy() */
+ goto destroy_file_buffer;
+ }
+ wasm_runtime_delete_loading_module(sub_module_name);
+ /* register on a global list */
+ ret = wasm_runtime_register_module_internal(
+ sub_module_name, (WASMModuleCommon *)sub_module, buffer, buffer_size,
+ error_buf, error_buf_size);
+ if (!ret) {
+ LOG_DEBUG("error: can not register module %s globally\n",
+ sub_module_name);
+ /* others will be unloaded in runtime_destroy() */
+ goto unload_module;
+ }
+
+ /* register into its parent list */
+wasm_runtime_register_sub_module:
+ ret = wasm_runtime_register_sub_module(parent_module, sub_module_name,
+ sub_module);
+ if (!ret) {
+ set_error_buf_v(parent_module, error_buf, error_buf_size,
+ "failed to register sub module %s", sub_module_name);
+ /* since it is in the global module list, no need to
+ * unload the module. the runtime_destroy() will do it
+ */
+ return NULL;
+ }
+
+ return sub_module;
+
+unload_module:
+ wasm_runtime_unload(sub_module);
+
+destroy_file_buffer:
+ if (destroyer) {
+ destroyer(buffer, buffer_size);
+ }
+ else {
+ LOG_WARNING("need to release the reading buffer of %s manually",
+ sub_module_name);
+ }
+
+delete_loading_module:
+ wasm_runtime_delete_loading_module(sub_module_name);
+ return NULL;
+}
+
+bool
+wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
+ WASMModuleInstanceCommon *module_inst,
+ uint32 stack_size, uint32 heap_size,
+ char *error_buf, uint32 error_buf_size)
+{
+ bh_list *sub_module_inst_list = NULL;
+ WASMRegisteredModule *sub_module_list_node = NULL;
+
+#if WASM_ENABLE_AOT != 0
+ if (module->module_type == Wasm_Module_AoT) {
+ sub_module_inst_list =
+ ((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
+ ->sub_module_inst_list;
+ sub_module_list_node =
+ bh_list_first_elem(((AOTModule *)module)->import_module_list);
+ }
+#endif
+#if WASM_ENABLE_INTERP != 0
+ if (module->module_type == Wasm_Module_Bytecode) {
+ sub_module_inst_list =
+ ((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e)
+ ->sub_module_inst_list;
+ sub_module_list_node =
+ bh_list_first_elem(((WASMModule *)module)->import_module_list);
+ }
+#endif
+ while (sub_module_list_node) {
+ WASMSubModInstNode *sub_module_inst_list_node = NULL;
+ WASMModuleCommon *sub_module = sub_module_list_node->module;
+ WASMModuleInstanceCommon *sub_module_inst = NULL;
+ sub_module_inst = wasm_runtime_instantiate_internal(
+ sub_module, NULL, NULL, stack_size, heap_size, error_buf,
+ error_buf_size);
+ if (!sub_module_inst) {
+ LOG_DEBUG("instantiate %s failed",
+ sub_module_list_node->module_name);
+ return false;
+ }
+ sub_module_inst_list_node = loader_malloc(sizeof(WASMSubModInstNode),
+ error_buf, error_buf_size);
+ if (!sub_module_inst_list_node) {
+ LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d",
+ sizeof(WASMSubModInstNode));
+ if (sub_module_inst)
+ wasm_runtime_deinstantiate_internal(sub_module_inst, false);
+ return false;
+ }
+ sub_module_inst_list_node->module_inst =
+ (WASMModuleInstance *)sub_module_inst;
+ sub_module_inst_list_node->module_name =
+ sub_module_list_node->module_name;
+ bh_list_status ret =
+ bh_list_insert(sub_module_inst_list, sub_module_inst_list_node);
+ bh_assert(BH_LIST_SUCCESS == ret);
+ (void)ret;
+ sub_module_list_node = bh_list_elem_next(sub_module_list_node);
+ }
+
+ return true;
+}
+
+void
+wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst)
+{
+ bh_list *list = NULL;
+#if WASM_ENABLE_AOT != 0
+ if (module_inst->module_type == Wasm_Module_AoT) {
+ list = ((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
+ ->sub_module_inst_list;
+ }
+#endif
+#if WASM_ENABLE_INTERP != 0
+ if (module_inst->module_type == Wasm_Module_Bytecode) {
+ list =
+ ((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e)
+ ->sub_module_inst_list;
+ }
+#endif
+
+ WASMSubModInstNode *node = bh_list_first_elem(list);
+ while (node) {
+ WASMSubModInstNode *next_node = bh_list_elem_next(node);
+ bh_list_remove(list, node);
+ wasm_runtime_deinstantiate_internal(
+ (WASMModuleInstanceCommon *)node->module_inst, false);
+ wasm_runtime_free(node);
+ node = next_node;
+ }
+}
+#endif /* end of WASM_ENABLE_MULTI_MODULE */
+#if WASM_ENABLE_MODULE_INST_CONTEXT != 0
+void *
+wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
+ void *ctx))
+{
+ return wasm_native_create_context_key(dtor);
+}
+
+void
+wasm_runtime_destroy_context_key(void *key)
+{
+ wasm_native_destroy_context_key(key);
+}
+
+void
+wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx)
+{
+ wasm_native_set_context(inst, key, ctx);
+}
+
+void
+wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
+ void *ctx)
+{
+ wasm_native_set_context_spread(inst, key, ctx);
+}
+
+void *
+wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key)
+{
+ return wasm_native_get_context(inst, key);
+}
+#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.h
similarity index 87%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.h
index 00d5ba23714..2908cafb5f8 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.h
@@ -12,9 +12,9 @@
#include "wasm_native.h"
#include "../include/wasm_export.h"
#include "../interpreter/wasm.h"
+
#if WASM_ENABLE_LIBC_WASI != 0
#if WASM_ENABLE_UVWASI == 0
-#include "wasmtime_ssp.h"
#include "posix.h"
#else
#include "uvwasi.h"
@@ -44,15 +44,16 @@ extern "C" {
/* For STORE opcodes */
#define STORE_I64 PUT_I64_TO_ADDR
-#define STORE_U32(addr, value) \
- do { \
- *(uint32 *)(addr) = (uint32)(value); \
- } while (0)
-#define STORE_U16(addr, value) \
- do { \
- *(uint16 *)(addr) = (uint16)(value); \
- } while (0)
-
+static inline void
+STORE_U32(void *addr, uint32_t value)
+{
+ *(uint32_t *)(addr) = (uint32_t)(value);
+}
+static inline void
+STORE_U16(void *addr, uint16_t value)
+{
+ *(uint16_t *)(addr) = (uint16_t)(value);
+}
/* For LOAD opcodes */
#define LOAD_I64(addr) (*(int64 *)(addr))
#define LOAD_F64(addr) (*(float64 *)(addr))
@@ -147,42 +148,42 @@ GET_F64_FROM_ADDR(uint32 *addr)
} \
} while (0)
-#define STORE_U32(addr, value) \
- do { \
- uintptr_t addr_ = (uintptr_t)(addr); \
- union { \
- uint32 val; \
- uint16 u16[2]; \
- uint8 u8[4]; \
- } u; \
- if ((addr_ & (uintptr_t)3) == 0) \
- *(uint32 *)(addr) = (uint32)(value); \
- else { \
- u.val = (uint32)(value); \
- if ((addr_ & (uintptr_t)1) == 0) { \
- ((uint16 *)(addr))[0] = u.u16[0]; \
- ((uint16 *)(addr))[1] = u.u16[1]; \
- } \
- else { \
- ((uint8 *)(addr))[0] = u.u8[0]; \
- ((uint8 *)(addr))[1] = u.u8[1]; \
- ((uint8 *)(addr))[2] = u.u8[2]; \
- ((uint8 *)(addr))[3] = u.u8[3]; \
- } \
- } \
- } while (0)
-
-#define STORE_U16(addr, value) \
- do { \
- union { \
- uint16 val; \
- uint8 u8[2]; \
- } u; \
- u.val = (uint16)(value); \
- ((uint8 *)(addr))[0] = u.u8[0]; \
- ((uint8 *)(addr))[1] = u.u8[1]; \
- } while (0)
-
+static inline void
+STORE_U32(void *addr, uint32_t value)
+{
+ uintptr_t addr_ = (uintptr_t)(addr);
+ union {
+ uint32_t val;
+ uint16_t u16[2];
+ uint8_t u8[4];
+ } u;
+ if ((addr_ & (uintptr_t)3) == 0)
+ *(uint32_t *)(addr) = (uint32_t)(value);
+ else {
+ u.val = (uint32_t)(value);
+ if ((addr_ & (uintptr_t)1) == 0) {
+ ((uint16_t *)(addr))[0] = u.u16[0];
+ ((uint16_t *)(addr))[1] = u.u16[1];
+ }
+ else {
+ ((uint8_t *)(addr))[0] = u.u8[0];
+ ((uint8_t *)(addr))[1] = u.u8[1];
+ ((uint8_t *)(addr))[2] = u.u8[2];
+ ((uint8_t *)(addr))[3] = u.u8[3];
+ }
+ }
+}
+static inline void
+STORE_U16(void *addr, uint16_t value)
+{
+ union {
+ uint16_t val;
+ uint8_t u8[2];
+ } u;
+ u.val = (uint16_t)(value);
+ ((uint8_t *)(addr))[0] = u.u8[0];
+ ((uint8_t *)(addr))[1] = u.u8[1];
+}
/* For LOAD opcodes */
static inline int64
LOAD_I64(void *addr)
@@ -298,6 +299,14 @@ LOAD_I16(void *addr)
#endif /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
+#if WASM_ENABLE_SHARED_MEMORY != 0
+#define SHARED_MEMORY_LOCK(memory) shared_memory_lock(memory)
+#define SHARED_MEMORY_UNLOCK(memory) shared_memory_unlock(memory)
+#else
+#define SHARED_MEMORY_LOCK(memory) (void)0
+#define SHARED_MEMORY_UNLOCK(memory) (void)0
+#endif
+
typedef struct WASMModuleCommon {
/* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode, and this structure should
@@ -420,6 +429,8 @@ typedef struct wasm_frame_t {
typedef struct LLVMJITOptions {
uint32 opt_level;
uint32 size_level;
+ uint32 segue_flags;
+ bool linux_perf_support;
} LLVMJITOptions;
#endif
@@ -497,7 +508,8 @@ wasm_runtime_unload(WASMModuleCommon *module);
/* Internal API */
WASMModuleInstanceCommon *
-wasm_runtime_instantiate_internal(WASMModuleCommon *module, bool is_sub_inst,
+wasm_runtime_instantiate_internal(WASMModuleCommon *module,
+ WASMModuleInstanceCommon *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, char *error_buf,
uint32 error_buf_size);
@@ -592,6 +604,17 @@ wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_get_user_data(WASMExecEnv *exec_env);
+#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
+ bool enable);
+
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN bool
+wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst);
+#endif
+
#ifdef OS_ENABLE_HW_BOUND_CHECK
/* Access exception check guard page to trigger the signal handler */
void
@@ -662,6 +685,10 @@ wasm_runtime_get_exception(WASMModuleInstanceCommon *module);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst);
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_terminate(WASMModuleInstanceCommon *module);
+
/* Internal API */
void
wasm_runtime_set_custom_data_internal(WASMModuleInstanceCommon *module_inst,
@@ -771,6 +798,9 @@ wasm_runtime_register_module_internal(const char *module_name,
void
wasm_runtime_unregister_module(const WASMModuleCommon *module);
+WASMModuleCommon *
+wasm_runtime_find_module_registered(const char *module_name);
+
bool
wasm_runtime_add_loading_module(const char *module_name, char *error_buf,
uint32 error_buf_size);
@@ -783,6 +813,35 @@ wasm_runtime_is_loading_module(const char *module_name);
void
wasm_runtime_destroy_loading_module_list();
+
+WASMModuleCommon *
+wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module,
+ const char *sub_module_name);
+
+bool
+wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
+ const char *sub_module_name,
+ WASMModuleCommon *sub_module);
+
+WASMModuleCommon *
+wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
+ const char *sub_module_name, char *error_buf,
+ uint32 error_buf_size);
+
+bool
+wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
+ WASMModuleInstanceCommon *module_inst,
+ uint32 stack_size, uint32 heap_size,
+ char *error_buf, uint32 error_buf_size);
+void
+wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
+#endif
+
+#if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0
+WASMExport *
+loader_find_export(const WASMModuleCommon *module, const char *module_name,
+ const char *field_name, uint8 export_kind, char *error_buf,
+ uint32 error_buf_size);
#endif /* WASM_ENALBE_MULTI_MODULE */
bool
@@ -804,7 +863,7 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
uint32 dir_count, const char *map_dir_list[],
uint32 map_dir_count, const char *env_list[],
uint32 env_count, char *argv[], int argc,
- int stdinfd, int stdoutfd, int stderrfd);
+ int64 stdinfd, int64 stdoutfd, int64 stderrfd);
/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN void
@@ -832,8 +891,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
const char *env[], uint32 env_count,
const char *addr_pool[], uint32 addr_pool_size,
const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
- char *argv[], uint32 argc, int stdinfd, int stdoutfd,
- int stderrfd, char *error_buf, uint32 error_buf_size);
+ char *argv[], uint32 argc, os_raw_file_handle stdinfd,
+ os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
+ char *error_buf, uint32 error_buf_size);
void
wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst);
@@ -926,6 +986,26 @@ WASM_RUNTIME_API_EXTERN bool
wasm_runtime_unregister_natives(const char *module_name,
NativeSymbol *native_symbols);
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void *
+wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
+ void *ctx));
+
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_destroy_context_key(void *key);
+
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx);
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
+ void *ctx);
+/* See wasm_export.h for description */
+WASM_RUNTIME_API_EXTERN void *
+wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key);
+
bool
wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
const WASMType *func_type, const char *signature,
@@ -1003,6 +1083,15 @@ WASM_RUNTIME_API_EXTERN bool
wasm_runtime_is_import_global_linked(const char *module_name,
const char *global_name);
+WASM_RUNTIME_API_EXTERN bool
+wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env);
+
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_end_blocking_op(WASMExecEnv *exec_env);
+
+void
+wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.c
similarity index 71%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.c
index 54fc8200f0b..70e84a37504 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.c
@@ -9,9 +9,16 @@
#include "../libraries/thread-mgr/thread_manager.h"
#endif
-static bh_list shared_memory_list_head;
-static bh_list *const shared_memory_list = &shared_memory_list_head;
-static korp_mutex shared_memory_list_lock;
+/*
+ * Note: this lock can be per memory.
+ *
+ * For now, just use a global because:
+ * - it's a bit cumbersome to extend WASMMemoryInstance w/o breaking
+ * the AOT ABI.
+ * - If you care performance, it's better to make the interpreters
+ * use atomic ops.
+ */
+korp_mutex g_shared_memory_lock;
/* clang-format off */
enum {
@@ -37,7 +44,7 @@ typedef struct AtomicWaitNode {
static HashMap *wait_map;
static uint32
-wait_address_hash(void *address);
+wait_address_hash(const void *address);
static bool
wait_address_equal(void *h1, void *h2);
@@ -48,17 +55,15 @@ destroy_wait_info(void *wait_info);
bool
wasm_shared_memory_init()
{
- if (os_mutex_init(&shared_memory_list_lock) != 0)
+ if (os_mutex_init(&g_shared_memory_lock) != 0)
return false;
-
/* wait map not exists, create new map */
if (!(wait_map = bh_hash_map_create(32, true, (HashFunc)wait_address_hash,
(KeyEqualFunc)wait_address_equal, NULL,
destroy_wait_info))) {
- os_mutex_destroy(&shared_memory_list_lock);
+ os_mutex_destroy(&g_shared_memory_lock);
return false;
}
-
return true;
}
@@ -66,115 +71,52 @@ void
wasm_shared_memory_destroy()
{
bh_hash_map_destroy(wait_map);
- os_mutex_destroy(&shared_memory_list_lock);
-}
-
-static WASMSharedMemNode *
-search_module(WASMModuleCommon *module)
-{
- WASMSharedMemNode *node;
-
- os_mutex_lock(&shared_memory_list_lock);
- node = bh_list_first_elem(shared_memory_list);
-
- while (node) {
- if (module == node->module) {
- os_mutex_unlock(&shared_memory_list_lock);
- return node;
- }
- node = bh_list_elem_next(node);
- }
-
- os_mutex_unlock(&shared_memory_list_lock);
- return NULL;
-}
-
-WASMSharedMemNode *
-wasm_module_get_shared_memory(WASMModuleCommon *module)
-{
- return search_module(module);
-}
-
-int32
-shared_memory_inc_reference(WASMModuleCommon *module)
-{
- WASMSharedMemNode *node = search_module(module);
- uint32 ref_count = -1;
- if (node) {
- os_mutex_lock(&node->lock);
- ref_count = ++node->ref_count;
- os_mutex_unlock(&node->lock);
- }
- return ref_count;
+ os_mutex_destroy(&g_shared_memory_lock);
}
-int32
-shared_memory_dec_reference(WASMModuleCommon *module)
+uint16
+shared_memory_inc_reference(WASMMemoryInstance *memory)
{
- WASMSharedMemNode *node = search_module(module);
- uint32 ref_count = 0;
- if (node) {
- os_mutex_lock(&node->lock);
- ref_count = --node->ref_count;
- os_mutex_unlock(&node->lock);
- if (ref_count == 0) {
- os_mutex_lock(&shared_memory_list_lock);
- bh_list_remove(shared_memory_list, node);
- os_mutex_unlock(&shared_memory_list_lock);
-
- os_mutex_destroy(&node->shared_mem_lock);
- os_mutex_destroy(&node->lock);
- wasm_runtime_free(node);
- }
- return ref_count;
- }
-
- return -1;
+ bh_assert(shared_memory_is_shared(memory));
+ uint16 old;
+#if BH_ATOMIC_16_IS_ATOMIC == 0
+ os_mutex_lock(&g_shared_memory_lock);
+#endif
+ old = BH_ATOMIC_16_FETCH_ADD(memory->ref_count, 1);
+#if BH_ATOMIC_16_IS_ATOMIC == 0
+ os_mutex_unlock(&g_shared_memory_lock);
+#endif
+ bh_assert(old >= 1);
+ bh_assert(old < UINT16_MAX);
+ return old + 1;
}
-WASMMemoryInstanceCommon *
-shared_memory_get_memory_inst(WASMSharedMemNode *node)
+uint16
+shared_memory_dec_reference(WASMMemoryInstance *memory)
{
- return node->memory_inst;
+ bh_assert(shared_memory_is_shared(memory));
+ uint16 old;
+#if BH_ATOMIC_16_IS_ATOMIC == 0
+ os_mutex_lock(&g_shared_memory_lock);
+#endif
+ old = BH_ATOMIC_16_FETCH_SUB(memory->ref_count, 1);
+#if BH_ATOMIC_16_IS_ATOMIC == 0
+ os_mutex_unlock(&g_shared_memory_lock);
+#endif
+ bh_assert(old > 0);
+ return old - 1;
}
-WASMSharedMemNode *
-shared_memory_set_memory_inst(WASMModuleCommon *module,
- WASMMemoryInstanceCommon *memory)
+static korp_mutex *
+shared_memory_get_lock_pointer(WASMMemoryInstance *memory)
{
- WASMSharedMemNode *node;
- bh_list_status ret;
-
- if (!(node = wasm_runtime_malloc(sizeof(WASMSharedMemNode))))
- return NULL;
-
- node->module = module;
- node->memory_inst = memory;
- node->ref_count = 1;
-
- if (os_mutex_init(&node->shared_mem_lock) != 0) {
- wasm_runtime_free(node);
- return NULL;
- }
-
- if (os_mutex_init(&node->lock) != 0) {
- os_mutex_destroy(&node->shared_mem_lock);
- wasm_runtime_free(node);
- return NULL;
- }
-
- os_mutex_lock(&shared_memory_list_lock);
- ret = bh_list_insert(shared_memory_list, node);
- bh_assert(ret == BH_LIST_SUCCESS);
- os_mutex_unlock(&shared_memory_list_lock);
-
- (void)ret;
- return node;
+ bh_assert(memory != NULL);
+ return &g_shared_memory_lock;
}
/* Atomics wait && notify APIs */
static uint32
-wait_address_hash(void *address)
+wait_address_hash(const void *address)
{
return (uint32)(uintptr_t)address;
}
@@ -307,7 +249,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
WASMModuleInstance *module_inst = (WASMModuleInstance *)module;
AtomicWaitInfo *wait_info;
AtomicWaitNode *wait_node;
- WASMSharedMemNode *node;
+ korp_mutex *lock;
#if WASM_ENABLE_THREAD_MGR != 0
WASMExecEnv *exec_env;
#endif
@@ -322,17 +264,20 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
}
/* Currently we have only one memory instance */
- if (!module_inst->memories[0]->is_shared) {
+ if (!shared_memory_is_shared(module_inst->memories[0])) {
wasm_runtime_set_exception(module, "expected shared memory");
return -1;
}
+ shared_memory_lock(module_inst->memories[0]);
if ((uint8 *)address < module_inst->memories[0]->memory_data
|| (uint8 *)address + (wait64 ? 8 : 4)
> module_inst->memories[0]->memory_data_end) {
+ shared_memory_unlock(module_inst->memories[0]);
wasm_runtime_set_exception(module, "out of bounds memory access");
return -1;
}
+ shared_memory_unlock(module_inst->memories[0]);
#if WASM_ENABLE_THREAD_MGR != 0
exec_env =
@@ -340,30 +285,29 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
bh_assert(exec_env);
#endif
- node = search_module((WASMModuleCommon *)module_inst->module);
- bh_assert(node);
+ lock = shared_memory_get_lock_pointer(module_inst->memories[0]);
/* Lock the shared_mem_lock for the whole atomic wait process,
and use it to os_cond_reltimedwait */
- os_mutex_lock(&node->shared_mem_lock);
+ os_mutex_lock(lock);
no_wait = (!wait64 && *(uint32 *)address != (uint32)expect)
|| (wait64 && *(uint64 *)address != expect);
if (no_wait) {
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
return 1;
}
if (!(wait_node = wasm_runtime_malloc(sizeof(AtomicWaitNode)))) {
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
wasm_runtime_set_exception(module, "failed to create wait node");
return -1;
}
memset(wait_node, 0, sizeof(AtomicWaitNode));
if (0 != os_cond_init(&wait_node->wait_cond)) {
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
wasm_runtime_free(wait_node);
wasm_runtime_set_exception(module, "failed to init wait cond");
return -1;
@@ -375,7 +319,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
wait_info = acquire_wait_info(address, wait_node);
if (!wait_info) {
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
os_cond_destroy(&wait_node->wait_cond);
wasm_runtime_free(wait_node);
wasm_runtime_set_exception(module, "failed to acquire wait_info");
@@ -390,7 +334,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
if (timeout < 0) {
/* wait forever until it is notified or terminatied
here we keep waiting and checking every second */
- os_cond_reltimedwait(&wait_node->wait_cond, &node->shared_mem_lock,
+ os_cond_reltimedwait(&wait_node->wait_cond, lock,
(uint64)timeout_1sec);
if (wait_node->status == S_NOTIFIED /* notified by atomic.notify */
#if WASM_ENABLE_THREAD_MGR != 0
@@ -404,8 +348,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
else {
timeout_wait =
timeout_left < timeout_1sec ? timeout_left : timeout_1sec;
- os_cond_reltimedwait(&wait_node->wait_cond, &node->shared_mem_lock,
- timeout_wait);
+ os_cond_reltimedwait(&wait_node->wait_cond, lock, timeout_wait);
if (wait_node->status == S_NOTIFIED /* notified by atomic.notify */
|| timeout_left <= timeout_wait /* time out */
#if WASM_ENABLE_THREAD_MGR != 0
@@ -433,7 +376,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
/* Release wait info if no wait nodes are attached */
map_try_release_wait_info(wait_map, wait_info, address);
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
return is_timeout ? 2 : 0;
}
@@ -445,15 +388,17 @@ wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
WASMModuleInstance *module_inst = (WASMModuleInstance *)module;
uint32 notify_result;
AtomicWaitInfo *wait_info;
- WASMSharedMemNode *node;
+ korp_mutex *lock;
bool out_of_bounds;
bh_assert(module->module_type == Wasm_Module_Bytecode
|| module->module_type == Wasm_Module_AoT);
+ shared_memory_lock(module_inst->memories[0]);
out_of_bounds =
((uint8 *)address < module_inst->memories[0]->memory_data
|| (uint8 *)address + 4 > module_inst->memories[0]->memory_data_end);
+ shared_memory_unlock(module_inst->memories[0]);
if (out_of_bounds) {
wasm_runtime_set_exception(module, "out of bounds memory access");
@@ -461,31 +406,30 @@ wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
}
/* Currently we have only one memory instance */
- if (!module_inst->memories[0]->is_shared) {
+ if (!shared_memory_is_shared(module_inst->memories[0])) {
/* Always return 0 for ushared linear memory since there is
no way to create a waiter on it */
return 0;
}
- node = search_module((WASMModuleCommon *)module_inst->module);
- bh_assert(node);
+ lock = shared_memory_get_lock_pointer(module_inst->memories[0]);
/* Lock the shared_mem_lock for the whole atomic notify process,
and use it to os_cond_signal */
- os_mutex_lock(&node->shared_mem_lock);
+ os_mutex_lock(lock);
wait_info = acquire_wait_info(address, NULL);
/* Nobody wait on this address */
if (!wait_info) {
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
return 0;
}
/* Notify each wait node in the wait list */
notify_result = notify_wait_list(wait_info->wait_list, count);
- os_mutex_unlock(&node->shared_mem_lock);
+ os_mutex_unlock(lock);
return notify_result;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h
new file mode 100644
index 00000000000..8bbc4a80045
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef _WASM_SHARED_MEMORY_H
+#define _WASM_SHARED_MEMORY_H
+
+#include "bh_common.h"
+#include "../interpreter/wasm_runtime.h"
+#include "wasm_runtime_common.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern korp_mutex g_shared_memory_lock;
+
+bool
+wasm_shared_memory_init();
+
+void
+wasm_shared_memory_destroy();
+
+uint16
+shared_memory_inc_reference(WASMMemoryInstance *memory);
+
+uint16
+shared_memory_dec_reference(WASMMemoryInstance *memory);
+
+#define shared_memory_is_shared(memory) memory->is_shared_memory
+
+#define shared_memory_lock(memory) \
+ do { \
+ /* \
+ * Note: exception logic is currently abusing this lock. \
+ * cf. \
+ * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2407 \
+ */ \
+ bh_assert(memory != NULL); \
+ if (memory->is_shared_memory) \
+ os_mutex_lock(&g_shared_memory_lock); \
+ } while (0)
+
+#define shared_memory_unlock(memory) \
+ do { \
+ if (memory->is_shared_memory) \
+ os_mutex_unlock(&g_shared_memory_lock); \
+ } while (0)
+
+uint32
+wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
+ uint64 expect, int64 timeout, bool wait64);
+
+uint32
+wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
+ uint32 count);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* end of _WASM_SHARED_MEMORY_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h
new file mode 100644
index 00000000000..b182b2b5f00
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2023 Amazon Inc. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef _WASM_SUSPEND_FLAGS_H
+#define _WASM_SUSPEND_FLAGS_H
+
+#include "bh_atomic.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Need to terminate */
+#define WASM_SUSPEND_FLAG_TERMINATE 0x1
+/* Need to suspend */
+#define WASM_SUSPEND_FLAG_SUSPEND 0x2
+/* Need to go into breakpoint */
+#define WASM_SUSPEND_FLAG_BREAKPOINT 0x4
+/* Return from pthread_exit */
+#define WASM_SUSPEND_FLAG_EXIT 0x8
+/* The thread might be blocking */
+#define WASM_SUSPEND_FLAG_BLOCKING 0x10
+
+typedef union WASMSuspendFlags {
+ bh_atomic_32_t flags;
+ uintptr_t __padding__;
+} WASMSuspendFlags;
+
+#define WASM_SUSPEND_FLAGS_IS_ATOMIC BH_ATOMIC_32_IS_ATOMIC
+#define WASM_SUSPEND_FLAGS_GET(s_flags) BH_ATOMIC_32_LOAD(s_flags.flags)
+#define WASM_SUSPEND_FLAGS_FETCH_OR(s_flags, val) \
+ BH_ATOMIC_32_FETCH_OR(s_flags.flags, val)
+#define WASM_SUSPEND_FLAGS_FETCH_AND(s_flags, val) \
+ BH_ATOMIC_32_FETCH_AND(s_flags.flags, val)
+
+#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0
+#define WASM_SUSPEND_FLAGS_LOCK(lock) (void)0
+#define WASM_SUSPEND_FLAGS_UNLOCK(lock) (void)0
+#else /* else of WASM_SUSPEND_FLAGS_IS_ATOMIC */
+#define WASM_SUSPEND_FLAGS_LOCK(lock) os_mutex_lock(&lock)
+#define WASM_SUSPEND_FLAGS_UNLOCK(lock) os_mutex_unlock(&lock);
+#endif /* WASM_SUSPEND_FLAGS_IS_ATOMIC */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* end of _WASM_SUSPEND_FLAGS_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.c
index e836df28fb9..8162d006e10 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.c
@@ -129,7 +129,6 @@ aot_create_table_init_data_list(const WASMModule *module)
data_list[i]->mode = module->table_segments[i].mode;
data_list[i]->elem_type = module->table_segments[i].elem_type;
/* runtime control it */
- data_list[i]->is_dropped = false;
data_list[i]->table_index = module->table_segments[i].table_index;
bh_memcpy_s(&data_list[i]->offset, sizeof(AOTInitExpr),
&module->table_segments[i].base_offset,
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.h
similarity index 92%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.h
index c67251a6ff6..4bee70f9cea 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.h
@@ -19,12 +19,31 @@ extern "C" {
#define AOT_FUNC_PREFIX "aot_func#"
#endif
+#ifndef AOT_FUNC_INTERNAL_PREFIX
+#define AOT_FUNC_INTERNAL_PREFIX "aot_func_internal#"
+#endif
+
+#ifndef AOT_STACK_SIZES_NAME
+#define AOT_STACK_SIZES_NAME "aot_stack_sizes"
+#endif
+extern const char *aot_stack_sizes_name;
+
+#ifndef AOT_STACK_SIZES_ALIAS_NAME
+#define AOT_STACK_SIZES_ALIAS_NAME "aot_stack_sizes_alias"
+#endif
+extern const char *aot_stack_sizes_alias_name;
+
+#ifndef AOT_STACK_SIZES_SECTION_NAME
+#define AOT_STACK_SIZES_SECTION_NAME ".aot_stack_sizes"
+#endif
+extern const char *aot_stack_sizes_section_name;
+
typedef InitializerExpression AOTInitExpr;
typedef WASMType AOTFuncType;
typedef WASMExport AOTExport;
#if WASM_ENABLE_DEBUG_AOT != 0
-typedef void *dwar_extractor_handle_t;
+typedef void *dwarf_extractor_handle_t;
#endif
typedef enum AOTIntCond {
@@ -124,7 +143,6 @@ typedef struct AOTTableInitData {
uint32 mode;
/* funcref or externref, elemkind will be considered as funcref */
uint32 elem_type;
- bool is_dropped;
/* optional, only for active */
uint32 table_index;
/* Start address of init data */
@@ -266,7 +284,7 @@ typedef struct AOTCompData {
WASMModule *wasm_module;
#if WASM_ENABLE_DEBUG_AOT != 0
- dwar_extractor_handle_t extractor;
+ dwarf_extractor_handle_t extractor;
#endif
} AOTCompData;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.c
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.c
index 06235fe3173..464ca61f321 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.c
@@ -2617,64 +2617,6 @@ verify_module(AOTCompContext *comp_ctx)
return true;
}
-/* Check whether the target supports hardware atomic instructions */
-static bool
-aot_require_lower_atomic_pass(AOTCompContext *comp_ctx)
-{
- bool ret = false;
- if (!strncmp(comp_ctx->target_arch, "riscv", 5)) {
- char *feature =
- LLVMGetTargetMachineFeatureString(comp_ctx->target_machine);
-
- if (feature) {
- if (!strstr(feature, "+a")) {
- ret = true;
- }
- LLVMDisposeMessage(feature);
- }
- }
- return ret;
-}
-
-/* Check whether the target needs to expand switch to if/else */
-static bool
-aot_require_lower_switch_pass(AOTCompContext *comp_ctx)
-{
- bool ret = false;
-
- /* IR switch/case will cause .rodata relocation on riscv/xtensa */
- if (!strncmp(comp_ctx->target_arch, "riscv", 5)
- || !strncmp(comp_ctx->target_arch, "xtensa", 6)) {
- ret = true;
- }
-
- return ret;
-}
-
-static bool
-apply_passes_for_indirect_mode(AOTCompContext *comp_ctx)
-{
- LLVMPassManagerRef common_pass_mgr;
-
- if (!(common_pass_mgr = LLVMCreatePassManager())) {
- aot_set_last_error("create pass manager failed");
- return false;
- }
-
- aot_add_expand_memory_op_pass(common_pass_mgr);
-
- if (aot_require_lower_atomic_pass(comp_ctx))
- LLVMAddLowerAtomicPass(common_pass_mgr);
-
- if (aot_require_lower_switch_pass(comp_ctx))
- LLVMAddLowerSwitchPass(common_pass_mgr);
-
- LLVMRunPassManager(common_pass_mgr, comp_ctx->module);
-
- LLVMDisposePassManager(common_pass_mgr);
- return true;
-}
-
bool
aot_compile_wasm(AOTCompContext *comp_ctx)
{
@@ -2714,17 +2656,6 @@ aot_compile_wasm(AOTCompContext *comp_ctx)
possible core dump. */
bh_print_time("Begin to run llvm optimization passes");
aot_apply_llvm_new_pass_manager(comp_ctx, comp_ctx->module);
-
- /* Run specific passes for AOT indirect mode in last since general
- optimization may create some intrinsic function calls like
- llvm.memset, so let's remove these function calls here. */
- if (!comp_ctx->is_jit_mode && comp_ctx->is_indirect_mode) {
- bh_print_time("Begin to run optimization passes "
- "for indirect mode");
- if (!apply_passes_for_indirect_mode(comp_ctx)) {
- return false;
- }
- }
bh_print_time("Finish llvm optimization passes");
}
@@ -2761,6 +2692,16 @@ aot_compile_wasm(AOTCompContext *comp_ctx)
aot_handle_llvm_errmsg("failed to addIRModule", err);
return false;
}
+
+ if (comp_ctx->stack_sizes != NULL) {
+ LLVMOrcJITTargetAddress addr;
+ if ((err = LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &addr,
+ aot_stack_sizes_alias_name))) {
+ aot_handle_llvm_errmsg("failed to look up stack_sizes", err);
+ return false;
+ }
+ comp_ctx->jit_stack_sizes = (uint32 *)addr;
+ }
}
return true;
@@ -2794,6 +2735,33 @@ aot_generate_tempfile_name(const char *prefix, const char *extension,
snprintf(buffer + name_len, len - name_len, ".%s", extension);
return buffer;
}
+#else
+
+errno_t
+_mktemp_s(char *nameTemplate, size_t sizeInChars);
+
+char *
+aot_generate_tempfile_name(const char *prefix, const char *extension,
+ char *buffer, uint32 len)
+{
+ int name_len;
+
+ name_len = snprintf(buffer, len, "%s-XXXXXX", prefix);
+
+ if (_mktemp_s(buffer, name_len + 1) != 0) {
+ return NULL;
+ }
+
+ /* Check if buffer length is enough */
+ /* name_len + '.' + extension + '\0' */
+ if (name_len + 1 + strlen(extension) + 1 > len) {
+ aot_set_last_error("temp file name too long.");
+ return NULL;
+ }
+
+ snprintf(buffer + name_len, len - name_len, ".%s", extension);
+ return buffer;
+}
#endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */
bool
@@ -2815,6 +2783,55 @@ aot_emit_llvm_file(AOTCompContext *comp_ctx, const char *file_name)
return true;
}
+static bool
+aot_move_file(const char *dest, const char *src)
+{
+ FILE *dfp = fopen(dest, "w");
+ FILE *sfp = fopen(src, "r");
+ size_t rsz;
+ char buf[128];
+ bool success = false;
+
+ if (dfp == NULL || sfp == NULL) {
+ LOG_DEBUG("open error %s %s", dest, src);
+ goto fail;
+ }
+ do {
+ rsz = fread(buf, 1, sizeof(buf), sfp);
+ if (rsz > 0) {
+ size_t wsz = fwrite(buf, 1, rsz, dfp);
+ if (wsz < rsz) {
+ LOG_DEBUG("write error");
+ goto fail;
+ }
+ }
+ if (rsz < sizeof(buf)) {
+ if (ferror(sfp)) {
+ LOG_DEBUG("read error");
+ goto fail;
+ }
+ }
+ } while (rsz > 0);
+ success = true;
+fail:
+ if (dfp != NULL) {
+ if (fclose(dfp)) {
+ LOG_DEBUG("close error");
+ success = false;
+ }
+ if (!success) {
+ (void)unlink(dest);
+ }
+ }
+ if (sfp != NULL) {
+ (void)fclose(sfp);
+ }
+ if (success) {
+ (void)unlink(src);
+ }
+ return success;
+}
+
bool
aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
{
@@ -2830,7 +2847,25 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
int ret;
if (comp_ctx->external_llc_compiler) {
+ const char *stack_usage_flag = "";
char bc_file_name[64];
+ char su_file_name[65]; /* See the comment below */
+
+ if (comp_ctx->stack_usage_file != NULL) {
+ /*
+ * Note: we know the caller uses 64 byte buffer for
+ * file_name. It will get 1 byte longer because we
+ * replace ".o" with ".su".
+ */
+ size_t len = strlen(file_name);
+ bh_assert(len + 1 <= sizeof(su_file_name));
+ bh_assert(len > 3);
+ bh_assert(file_name[len - 2] == '.');
+ bh_assert(file_name[len - 1] == 'o');
+ snprintf(su_file_name, sizeof(su_file_name), "%.*s.su",
+ (int)(len - 2), file_name);
+ stack_usage_flag = " -fstack-usage";
+ }
if (!aot_generate_tempfile_name("wamrc-bc", "bc", bc_file_name,
sizeof(bc_file_name))) {
@@ -2842,8 +2877,8 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
return false;
}
- snprintf(cmd, sizeof(cmd), "%s %s -o %s %s",
- comp_ctx->external_llc_compiler,
+ snprintf(cmd, sizeof(cmd), "%s%s %s -o %s %s",
+ comp_ctx->external_llc_compiler, stack_usage_flag,
comp_ctx->llc_compiler_flags ? comp_ctx->llc_compiler_flags
: "-O3 -c",
file_name, bc_file_name);
@@ -2858,6 +2893,22 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
"with external LLC compiler.");
return false;
}
+ if (comp_ctx->stack_usage_file != NULL) {
+ /*
+ * move the temporary .su file to the specified location.
+ *
+ * Note: the former is automatimally inferred from the output
+ * filename (file_name here) by clang.
+ *
+ * Note: the latter might be user-specified.
+ * (wamrc --stack-usage=)
+ */
+ if (!aot_move_file(comp_ctx->stack_usage_file, su_file_name)) {
+ aot_set_last_error("failed to move su file.");
+ (void)unlink(su_file_name);
+ return false;
+ }
+ }
}
else if (comp_ctx->external_asm_compiler) {
char asm_file_name[64];
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.h
similarity index 95%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.h
index e6031ab892f..b6347c89d78 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.h
@@ -239,6 +239,13 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
#define FUNC_REF_TYPE comp_ctx->basic_types.funcref_type
#define EXTERN_REF_TYPE comp_ctx->basic_types.externref_type
+#define INT8_PTR_TYPE_GS comp_ctx->basic_types.int8_ptr_type_gs
+#define INT16_PTR_TYPE_GS comp_ctx->basic_types.int16_ptr_type_gs
+#define INT32_PTR_TYPE_GS comp_ctx->basic_types.int32_ptr_type_gs
+#define INT64_PTR_TYPE_GS comp_ctx->basic_types.int64_ptr_type_gs
+#define F32_PTR_TYPE_GS comp_ctx->basic_types.float32_ptr_type_gs
+#define F64_PTR_TYPE_GS comp_ctx->basic_types.float64_ptr_type_gs
+
#define I32_CONST(v) LLVMConstInt(I32_TYPE, v, true)
#define I64_CONST(v) LLVMConstInt(I64_TYPE, v, true)
#define F32_CONST(v) LLVMConstReal(F32_TYPE, v)
@@ -272,6 +279,7 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
#define V128_TYPE comp_ctx->basic_types.v128_type
#define V128_PTR_TYPE comp_ctx->basic_types.v128_ptr_type
+#define V128_PTR_TYPE_GS comp_ctx->basic_types.v128_ptr_type_gs
#define V128_i8x16_TYPE comp_ctx->basic_types.i8x16_vec_type
#define V128_i16x8_TYPE comp_ctx->basic_types.i16x8_vec_type
#define V128_i32x4_TYPE comp_ctx->basic_types.i32x4_vec_type
@@ -355,6 +363,19 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
} \
} while (0)
+/* if val is a constant integer and its value is not undef or poison */
+static inline bool
+LLVMIsEfficientConstInt(LLVMValueRef val)
+{
+ return LLVMIsConstant(val)
+ && LLVMGetValueKind(val) == LLVMConstantIntValueKind
+ && !LLVMIsUndef(val)
+#if LLVM_VERSION_NUMBER >= 12
+ && !LLVMIsPoison(addr)
+#endif
+ ;
+}
+
bool
aot_compile_wasm(AOTCompContext *comp_ctx);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_aot_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_aot_file.c
similarity index 72%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_aot_file.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_aot_file.c
index 62bb809daa1..80bcdc7db48 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_aot_file.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_aot_file.c
@@ -93,7 +93,10 @@ check_utf8_str(const uint8 *str, uint32 len)
/* Internal function in object file */
typedef struct AOTObjectFunc {
char *func_name;
+ /* text offset of aot_func#n */
uint64 text_offset;
+ /* text offset of aot_func_internal#n */
+ uint64 text_offset_of_aot_func_internal;
} AOTObjectFunc;
/* Symbol table list node */
@@ -111,6 +114,8 @@ typedef struct AOTSymbolList {
/* AOT object data */
typedef struct AOTObjectData {
+ AOTCompContext *comp_ctx;
+
LLVMMemoryBufferRef mem_buf;
LLVMBinaryRef binary;
@@ -119,6 +124,12 @@ typedef struct AOTObjectData {
void *text;
uint32 text_size;
+ void *text_unlikely;
+ uint32 text_unlikely_size;
+
+ void *text_hot;
+ uint32 text_hot_size;
+
/* literal data and size */
void *literal;
uint32 literal_size;
@@ -132,6 +143,10 @@ typedef struct AOTObjectData {
AOTSymbolList symbol_list;
AOTRelocationGroup *relocation_groups;
uint32 relocation_group_count;
+
+ const char *stack_sizes_section_name;
+ uint32 stack_sizes_offset;
+ uint32 *stack_sizes;
} AOTObjectData;
#if 0
@@ -254,7 +269,7 @@ static uint32
get_table_init_data_size(AOTTableInitData *table_init_data)
{
/*
- * mode (4 bytes), elem_type (4 bytes), do not need is_dropped field
+ * mode (4 bytes), elem_type (4 bytes)
*
* table_index(4 bytes) + init expr type (4 bytes) + init expr value (8
* bytes)
@@ -558,8 +573,10 @@ get_init_data_section_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
static uint32
get_text_section_size(AOTObjectData *obj_data)
{
- return (sizeof(uint32) + obj_data->literal_size + obj_data->text_size + 3)
- & ~3;
+ return sizeof(uint32) + align_uint(obj_data->literal_size, 4)
+ + align_uint(obj_data->text_size, 4)
+ + align_uint(obj_data->text_unlikely_size, 4)
+ + align_uint(obj_data->text_hot_size, 4);
}
static uint32
@@ -623,13 +640,33 @@ get_relocation_size(AOTRelocation *relocation, bool is_32bin)
}
static uint32
-get_relocations_size(AOTRelocation *relocations, uint32 relocation_count,
+get_relocations_size(AOTObjectData *obj_data,
+ AOTRelocationGroup *relocation_group,
+ AOTRelocation *relocations, uint32 relocation_count,
bool is_32bin)
{
AOTRelocation *relocation = relocations;
uint32 size = 0, i;
for (i = 0; i < relocation_count; i++, relocation++) {
+ /* 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")
+ && !strncmp(relocation->symbol_name, AOT_FUNC_INTERNAL_PREFIX,
+ strlen(AOT_FUNC_INTERNAL_PREFIX))
+ && ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6)
+ /* Windows AOT_COFF64_BIN_TYPE */
+ && obj_data->target_info.bin_type == 6
+ /* IMAGE_REL_AMD64_REL32 in windows x86_64 */
+ && relocation->relocation_type == 4)
+ || (!strncmp(obj_data->comp_ctx->target_arch, "i386", 4)
+ /* Windows AOT_COFF32_BIN_TYPE */
+ && obj_data->target_info.bin_type == 4
+ /* IMAGE_REL_I386_REL32 in windows x86_32 */
+ && relocation->relocation_type == 20))) {
+ continue;
+ }
size = align_uint(size, 4);
size += get_relocation_size(relocation, is_32bin);
}
@@ -637,19 +674,22 @@ get_relocations_size(AOTRelocation *relocations, uint32 relocation_count,
}
static uint32
-get_relocation_group_size(AOTRelocationGroup *relocation_group, bool is_32bin)
+get_relocation_group_size(AOTObjectData *obj_data,
+ AOTRelocationGroup *relocation_group, bool is_32bin)
{
uint32 size = 0;
/* section name index + relocation count + relocations */
size += (uint32)sizeof(uint32);
size += (uint32)sizeof(uint32);
- size += get_relocations_size(relocation_group->relocations,
+ size += get_relocations_size(obj_data, relocation_group,
+ relocation_group->relocations,
relocation_group->relocation_count, is_32bin);
return size;
}
static uint32
-get_relocation_groups_size(AOTRelocationGroup *relocation_groups,
+get_relocation_groups_size(AOTObjectData *obj_data,
+ AOTRelocationGroup *relocation_groups,
uint32 relocation_group_count, bool is_32bin)
{
AOTRelocationGroup *relocation_group = relocation_groups;
@@ -657,7 +697,7 @@ get_relocation_groups_size(AOTRelocationGroup *relocation_groups,
for (i = 0; i < relocation_group_count; i++, relocation_group++) {
size = align_uint(size, 4);
- size += get_relocation_group_size(relocation_group, is_32bin);
+ size += get_relocation_group_size(obj_data, relocation_group, is_32bin);
}
return size;
}
@@ -850,7 +890,7 @@ get_relocation_section_size(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
/* relocation group count + symbol_table + relocation groups */
return (uint32)sizeof(uint32) + symbol_table_size
- + get_relocation_groups_size(relocation_groups,
+ + get_relocation_groups_size(obj_data, relocation_groups,
relocation_group_count,
is_32bit_binary(obj_data));
}
@@ -1624,7 +1664,31 @@ aot_emit_object_data_section_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
EMIT_STR(data_section->name);
offset = align_uint(offset, 4);
EMIT_U32(data_section->size);
- EMIT_BUF(data_section->data, data_section->size);
+ if (obj_data->stack_sizes_section_name != NULL
+ && !strcmp(obj_data->stack_sizes_section_name,
+ data_section->name)) {
+ uint32 ss_offset = obj_data->stack_sizes_offset;
+ uint32 ss_size =
+ obj_data->func_count * sizeof(*obj_data->stack_sizes);
+ LOG_VERBOSE("Replacing stack_sizes in %s section, offset %" PRIu32
+ ", size %" PRIu32,
+ obj_data->stack_sizes_section_name, ss_offset, ss_size);
+ bh_assert(ss_offset + ss_size <= data_section->size);
+ /* 0 .. ss_offset */
+ if (ss_offset > 0) {
+ EMIT_BUF(data_section->data, ss_offset);
+ }
+ /* ss_offset .. ss_offset+ss_size */
+ EMIT_BUF(obj_data->stack_sizes, ss_size);
+ /* ss_offset+ss_size .. data_section->size */
+ if (data_section->size > ss_offset + ss_size) {
+ EMIT_BUF(data_section->data + ss_offset + ss_size,
+ data_section->size - (ss_offset + ss_size));
+ }
+ }
+ else {
+ EMIT_BUF(data_section->data, data_section->size);
+ }
}
if (offset - *p_offset
@@ -1696,24 +1760,107 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
uint32 section_size = get_text_section_size(obj_data);
uint32 offset = *p_offset;
uint8 placeholder = 0;
+ AOTRelocationGroup *relocation_group;
+ AOTRelocation *relocation;
+ uint32 i, j, relocation_count;
+ uint8 *text;
*p_offset = offset = align_uint(offset, 4);
EMIT_U32(AOT_SECTION_TYPE_TEXT);
EMIT_U32(section_size);
EMIT_U32(obj_data->literal_size);
- if (obj_data->literal_size > 0)
+
+ if (obj_data->literal_size > 0) {
EMIT_BUF(obj_data->literal, obj_data->literal_size);
- EMIT_BUF(obj_data->text, obj_data->text_size);
+ while (offset & 3)
+ EMIT_BUF(&placeholder, 1);
+ }
- while (offset & 3)
- EMIT_BUF(&placeholder, 1);
+ text = buf + offset;
+
+ if (obj_data->text_size > 0) {
+ EMIT_BUF(obj_data->text, obj_data->text_size);
+ while (offset & 3)
+ EMIT_BUF(&placeholder, 1);
+ }
+ if (obj_data->text_unlikely_size > 0) {
+ EMIT_BUF(obj_data->text_unlikely, obj_data->text_unlikely_size);
+ while (offset & 3)
+ EMIT_BUF(&placeholder, 1);
+ }
+ if (obj_data->text_hot_size > 0) {
+ EMIT_BUF(obj_data->text_hot, obj_data->text_hot_size);
+ while (offset & 3)
+ EMIT_BUF(&placeholder, 1);
+ }
if (offset - *p_offset != section_size + sizeof(uint32) * 2) {
aot_set_last_error("emit text section failed.");
return false;
}
+ /* apply relocations to aot_func_internal#n in text section for
+ windows platform */
+ if ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6)
+ /* Windows AOT_COFF64_BIN_TYPE */
+ && obj_data->target_info.bin_type == 6)
+ || (!strncmp(obj_data->comp_ctx->target_arch, "i386", 4)
+ /* Windows AOT_COFF32_BIN_TYPE */
+ && obj_data->target_info.bin_type == 4)) {
+ relocation_group = obj_data->relocation_groups;
+ for (i = 0; i < obj_data->relocation_group_count;
+ i++, relocation_group++) {
+ /* relocation in text section */
+ if (!strcmp(relocation_group->section_name, ".text")) {
+ relocation = relocation_group->relocations;
+ relocation_count = relocation_group->relocation_count;
+ for (j = 0; j < relocation_count; j++) {
+ /* relocation to aot_func_internal#n */
+ if (str_starts_with(relocation->symbol_name,
+ AOT_FUNC_INTERNAL_PREFIX)
+ && ((obj_data->target_info.bin_type
+ == 6 /* AOT_COFF64_BIN_TYPE */
+ && relocation->relocation_type
+ == 4 /* IMAGE_REL_AMD64_REL32 */)
+ || (obj_data->target_info.bin_type
+ == 4 /* AOT_COFF32_BIN_TYPE */
+ && relocation->relocation_type
+ == 20 /* IMAGE_REL_I386_REL32 */))) {
+ uint32 func_idx =
+ atoi(relocation->symbol_name
+ + strlen(AOT_FUNC_INTERNAL_PREFIX));
+ uint64 text_offset, reloc_offset, reloc_addend;
+
+ bh_assert(func_idx < obj_data->func_count);
+
+ text_offset = obj_data->funcs[func_idx]
+ .text_offset_of_aot_func_internal;
+ reloc_offset = relocation->relocation_offset;
+ reloc_addend = relocation->relocation_addend;
+ /* S + A - P */
+ *(uint32 *)(text + reloc_offset) =
+ (uint32)(text_offset + reloc_addend - reloc_offset
+ - 4);
+
+ /* remove current relocation as it has been applied */
+ if (j < relocation_count - 1) {
+ uint32 move_size =
+ (uint32)(sizeof(AOTRelocation)
+ * (relocation_count - 1 - j));
+ bh_memmove_s(relocation, move_size, relocation + 1,
+ move_size);
+ }
+ relocation_group->relocation_count--;
+ }
+ else {
+ relocation++;
+ }
+ }
+ }
+ }
+ }
+
*p_offset = offset;
return true;
@@ -2211,11 +2358,23 @@ aot_resolve_text(AOTObjectData *obj_data)
}
while (
!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) {
- if ((name = (char *)LLVMGetSectionName(sec_itr))
- && !strcmp(name, ".text")) {
- obj_data->text = (char *)LLVMGetSectionContents(sec_itr);
- obj_data->text_size = (uint32)LLVMGetSectionSize(sec_itr);
- break;
+ if ((name = (char *)LLVMGetSectionName(sec_itr))) {
+ if (!strcmp(name, ".text")) {
+ obj_data->text = (char *)LLVMGetSectionContents(sec_itr);
+ obj_data->text_size = (uint32)LLVMGetSectionSize(sec_itr);
+ }
+ else if (!strcmp(name, ".text.unlikely.")) {
+ obj_data->text_unlikely =
+ (char *)LLVMGetSectionContents(sec_itr);
+ obj_data->text_unlikely_size =
+ (uint32)LLVMGetSectionSize(sec_itr);
+ }
+ else if (!strcmp(name, ".text.hot.")) {
+ obj_data->text_hot =
+ (char *)LLVMGetSectionContents(sec_itr);
+ obj_data->text_hot_size =
+ (uint32)LLVMGetSectionSize(sec_itr);
+ }
}
LLVMMoveToNextSection(sec_itr);
}
@@ -2253,7 +2412,8 @@ static bool
get_relocations_count(LLVMSectionIteratorRef sec_itr, uint32 *p_count);
static bool
-is_data_section(LLVMSectionIteratorRef sec_itr, char *section_name)
+is_data_section(AOTObjectData *obj_data, LLVMSectionIteratorRef sec_itr,
+ char *section_name)
{
uint32 relocation_count = 0;
@@ -2265,7 +2425,12 @@ is_data_section(LLVMSectionIteratorRef sec_itr, char *section_name)
|| !strncmp(section_name, ".rodata.str", strlen(".rodata.str"))
|| (!strcmp(section_name, ".rdata")
&& get_relocations_count(sec_itr, &relocation_count)
- && relocation_count > 0));
+ && relocation_count > 0)
+ || !strcmp(section_name, aot_stack_sizes_section_name)
+ || (obj_data->comp_ctx->enable_llvm_pgo
+ && (!strncmp(section_name, "__llvm_prf_cnts", 15)
+ || !strncmp(section_name, "__llvm_prf_data", 15)
+ || !strncmp(section_name, "__llvm_prf_names", 16))));
}
static bool
@@ -2281,7 +2446,7 @@ get_object_data_sections_count(AOTObjectData *obj_data, uint32 *p_count)
}
while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) {
if ((name = (char *)LLVMGetSectionName(sec_itr))
- && (is_data_section(sec_itr, name))) {
+ && (is_data_section(obj_data, sec_itr, name))) {
count++;
}
LLVMMoveToNextSection(sec_itr);
@@ -2306,6 +2471,9 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data)
}
if (sections_count > 0) {
+ uint32 llvm_prf_cnts_idx = 0, llvm_prf_data_idx = 0;
+ char buf[32];
+
size = (uint32)sizeof(AOTObjectDataSection) * sections_count;
if (!(data_section = obj_data->data_sections =
wasm_runtime_malloc(size))) {
@@ -2322,10 +2490,46 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data)
while (
!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) {
if ((name = (char *)LLVMGetSectionName(sec_itr))
- && (is_data_section(sec_itr, name))) {
+ && (is_data_section(obj_data, sec_itr, name))) {
data_section->name = name;
- data_section->data = (uint8 *)LLVMGetSectionContents(sec_itr);
- data_section->size = (uint32)LLVMGetSectionSize(sec_itr);
+ if (obj_data->comp_ctx->enable_llvm_pgo
+ && !strcmp(name, "__llvm_prf_cnts")) {
+ snprintf(buf, sizeof(buf), "%s%u", name,
+ llvm_prf_cnts_idx++);
+ size = (uint32)(strlen(buf) + 1);
+ if (!(data_section->name = wasm_runtime_malloc(size))) {
+ aot_set_last_error(
+ "allocate memory for data section name failed.");
+ return false;
+ }
+ bh_memcpy_s(data_section->name, size, buf, size);
+ data_section->is_name_allocated = true;
+ }
+ else if (obj_data->comp_ctx->enable_llvm_pgo
+ && !strcmp(name, "__llvm_prf_data")) {
+ snprintf(buf, sizeof(buf), "%s%u", name,
+ llvm_prf_data_idx++);
+ size = (uint32)(strlen(buf) + 1);
+ if (!(data_section->name = wasm_runtime_malloc(size))) {
+ aot_set_last_error(
+ "allocate memory for data section name failed.");
+ return false;
+ }
+ bh_memcpy_s(data_section->name, size, buf, size);
+ data_section->is_name_allocated = true;
+ }
+
+ if (obj_data->comp_ctx->enable_llvm_pgo
+ && !strcmp(name, "__llvm_prf_names")) {
+ data_section->data = (uint8 *)aot_compress_aot_func_names(
+ obj_data->comp_ctx, &data_section->size);
+ data_section->is_data_allocated = true;
+ }
+ else {
+ data_section->data =
+ (uint8 *)LLVMGetSectionContents(sec_itr);
+ data_section->size = (uint32)LLVMGetSectionSize(sec_itr);
+ }
data_section++;
}
LLVMMoveToNextSection(sec_itr);
@@ -2336,6 +2540,303 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data)
return true;
}
+static bool
+read_stack_usage_file(const AOTCompContext *comp_ctx, const char *filename,
+ uint32 *sizes, uint32 count)
+{
+ FILE *fp = NULL;
+ if (filename == NULL) {
+ aot_set_last_error("no stack usage file is specified.");
+ return false;
+ }
+ fp = fopen(filename, "r");
+ if (fp == NULL) {
+ LOG_ERROR("failed to open stack usage file: %s", filename);
+ goto fail;
+ }
+ /*
+ * the file consists of lines like:
+ *
+ * WASM Module:aot_func#9 72 static
+ */
+ const char *aot_func_prefix = AOT_FUNC_PREFIX;
+ const char *aot_func_internal_prefix = AOT_FUNC_INTERNAL_PREFIX;
+ uint32 precheck_found = 0;
+ uint32 precheck_stack_size_max = 0;
+ uint32 precheck_stack_size_min = UINT32_MAX;
+ uint32 found = 0;
+ while (true) {
+ const char *prefix;
+ char line[100];
+ char *cp = fgets(line, sizeof(line), fp);
+ char *fn;
+ char *colon;
+ uintmax_t func_idx;
+ uintmax_t sz;
+ int ret;
+
+ if (cp == NULL) {
+ break;
+ }
+ /*
+ * Note: strrchr (not strchr) because a module name can contain
+ * colons.
+ */
+ colon = strrchr(cp, ':');
+ if (colon == NULL) {
+ goto fail;
+ }
+ fn = strstr(colon, aot_func_prefix);
+ if (fn != NULL) {
+ prefix = aot_func_prefix;
+ }
+ else {
+ fn = strstr(colon, aot_func_internal_prefix);
+ if (fn == NULL) {
+ LOG_ERROR("failed to parse stack usage line: %s", cp);
+ goto fail;
+ }
+ prefix = aot_func_internal_prefix;
+ }
+ ret = sscanf(fn + strlen(prefix), "%ju %ju static", &func_idx, &sz);
+ if (ret != 2) {
+ goto fail;
+ }
+ if (sz > UINT32_MAX) {
+ goto fail;
+ }
+ if (func_idx > UINT32_MAX) {
+ goto fail;
+ }
+ if (func_idx >= count) {
+ goto fail;
+ }
+ if (prefix == aot_func_prefix) {
+ if (sz < precheck_stack_size_min) {
+ precheck_stack_size_min = (uint32)sz;
+ }
+ if (sz > precheck_stack_size_max) {
+ precheck_stack_size_max = (uint32)sz;
+ }
+ precheck_found++;
+ continue;
+ }
+ sizes[func_idx] = (uint32)sz;
+ found++;
+ }
+ fclose(fp);
+ if (precheck_found != count) {
+ LOG_ERROR("%" PRIu32 " precheck entries found while %" PRIu32
+ " entries are expected",
+ precheck_found, count);
+ return false;
+ }
+ if (found != count) {
+ /*
+ * LLVM seems to eliminate calls to an empty function
+ * (and eliminate the function) even if it's marked noinline.
+ */
+ LOG_VERBOSE("%" PRIu32 " entries found while %" PRIu32
+ " entries are expected. Maybe LLVM optimization eliminated "
+ "some functions.",
+ found, count);
+ }
+ if (precheck_stack_size_min != precheck_stack_size_max) {
+ /*
+ * Note: this is too strict.
+ *
+ * actually, the stack consumption of the precheck functions
+ * can depend on the type of them.
+ * that is, depending on various factors including
+ * calling conventions and compilers, a function with many
+ * parameters can consume more stack, even if it merely does
+ * a tail-call to another function.
+ */
+ bool musttail = aot_target_precheck_can_use_musttail(comp_ctx);
+ if (musttail) {
+ LOG_WARNING(
+ "precheck functions use variable amount of stack. (%" PRIu32
+ " - %" PRIu32 ")",
+ precheck_stack_size_min, precheck_stack_size_max);
+ }
+ else {
+ LOG_VERBOSE("precheck functions use %" PRIu32 " - %" PRIu32
+ " bytes of stack.",
+ precheck_stack_size_min, precheck_stack_size_max);
+ }
+ }
+ else {
+ LOG_VERBOSE("precheck functions use %" PRIu32 " bytes of stack.",
+ precheck_stack_size_max);
+ }
+ if (precheck_stack_size_max >= 1024) {
+ LOG_WARNING("precheck functions themselves consume relatively large "
+ "amount of stack (%" PRIu32
+ "). Please ensure the runtime has large enough "
+ "WASM_STACK_GUARD_SIZE.",
+ precheck_stack_size_max);
+ }
+ return true;
+fail:
+ if (fp != NULL)
+ fclose(fp);
+ aot_set_last_error("failed to read stack usage file.");
+ return false;
+}
+
+static bool
+aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
+{
+ LLVMSectionIteratorRef sec_itr = NULL;
+ LLVMSymbolIteratorRef sym_itr;
+ const char *name;
+
+ if (!(sym_itr = LLVMObjectFileCopySymbolIterator(obj_data->binary))) {
+ aot_set_last_error("llvm get symbol iterator failed.");
+ return false;
+ }
+
+ while (!LLVMObjectFileIsSymbolIteratorAtEnd(obj_data->binary, sym_itr)) {
+ if ((name = LLVMGetSymbolName(sym_itr))
+ && (!strcmp(name, aot_stack_sizes_alias_name)
+ /* symbol of COFF32 starts with "_" */
+ || (obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE
+ && !strncmp(name, "_", 1)
+ && !strcmp(name + 1, aot_stack_sizes_alias_name)))) {
+#if 0 /* cf. https://github.com/llvm/llvm-project/issues/67765 */
+ uint64 sz = LLVMGetSymbolSize(sym_itr);
+ if (sz != sizeof(uint32) * obj_data->func_count
+ /* sz of COFF64/COFF32 is 0, ignore the check */
+ && obj_data->target_info.bin_type != AOT_COFF64_BIN_TYPE
+ && obj_data->target_info.bin_type != AOT_COFF32_BIN_TYPE) {
+ aot_set_last_error("stack_sizes had unexpected size.");
+ goto fail;
+ }
+#endif
+ uint64 addr = LLVMGetSymbolAddress(sym_itr);
+ if (!(sec_itr =
+ LLVMObjectFileCopySectionIterator(obj_data->binary))) {
+ aot_set_last_error("llvm get section iterator failed.");
+ goto fail;
+ }
+ LLVMMoveToContainingSection(sec_itr, sym_itr);
+ const char *sec_name = LLVMGetSectionName(sec_itr);
+ LOG_VERBOSE("stack_sizes found in section %s offset %" PRIu64 ".",
+ sec_name, addr);
+ if (strcmp(sec_name, aot_stack_sizes_section_name) || addr != 0) {
+ aot_set_last_error(
+ "stack_sizes found at an unexpected location.");
+ goto fail;
+ }
+ /*
+ * Note: We can't always modify stack_sizes in-place.
+ * Eg. When WAMRC_LLC_COMPILER is used, LLVM sometimes uses
+ * read-only mmap of the temporary file to back
+ * LLVMGetSectionContents.
+ */
+ const uint32 *ro_stack_sizes =
+ (const uint32 *)(LLVMGetSectionContents(sec_itr) + addr);
+ uint32 i;
+ for (i = 0; i < obj_data->func_count; i++) {
+ /* Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes */
+ if (ro_stack_sizes[i] != (uint32)-1) {
+ aot_set_last_error("unexpected data in stack_sizes.");
+ goto fail;
+ }
+ }
+ /*
+ * Record section/offset and construct a copy of stack_sizes.
+ * aot_emit_object_data_section_info will emit this copy.
+ */
+ obj_data->stack_sizes_section_name = sec_name;
+ obj_data->stack_sizes_offset = (uint32)addr;
+ obj_data->stack_sizes = wasm_runtime_malloc(
+ obj_data->func_count * sizeof(*obj_data->stack_sizes));
+ if (obj_data->stack_sizes == NULL) {
+ aot_set_last_error("failed to allocate memory.");
+ goto fail;
+ }
+ uint32 *stack_sizes = obj_data->stack_sizes;
+ for (i = 0; i < obj_data->func_count; i++) {
+ stack_sizes[i] = (uint32)-1;
+ }
+ if (!read_stack_usage_file(comp_ctx, comp_ctx->stack_usage_file,
+ stack_sizes, obj_data->func_count)) {
+ goto fail;
+ }
+ for (i = 0; i < obj_data->func_count; i++) {
+ const AOTFuncContext *func_ctx = comp_ctx->func_ctxes[i];
+ bool musttail = aot_target_precheck_can_use_musttail(comp_ctx);
+ unsigned int stack_consumption_to_call_wrapped_func =
+ musttail ? 0
+ : aot_estimate_stack_usage_for_function_call(
+ comp_ctx, func_ctx->aot_func->func_type);
+
+ /*
+ * LLVM seems to eliminate calls to an empty function
+ * (and eliminate the function) even if it's marked noinline.
+ *
+ * Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes
+ */
+ if (stack_sizes[i] == (uint32)-1) {
+ if (func_ctx->stack_consumption_for_func_call != 0) {
+ /*
+ * This happens if a function calling another
+ * function has been optimized out.
+ *
+ * for example,
+ *
+ * (func $func
+ * (local i32)
+ * local.get 0
+ * if
+ * call $another
+ * end
+ * )
+ */
+ LOG_VERBOSE("AOT func#%" PRIu32
+ " had call(s) but eliminated?",
+ i);
+ }
+ else {
+ LOG_VERBOSE("AOT func#%" PRIu32 " eliminated?", i);
+ }
+ stack_sizes[i] = 0;
+ }
+ else {
+ LOG_VERBOSE("AOT func#%" PRIu32 " stack_size %u + %" PRIu32
+ " + %u",
+ i, stack_consumption_to_call_wrapped_func,
+ stack_sizes[i],
+ func_ctx->stack_consumption_for_func_call);
+ if (UINT32_MAX - stack_sizes[i]
+ < func_ctx->stack_consumption_for_func_call) {
+ aot_set_last_error("stack size overflow.");
+ goto fail;
+ }
+ stack_sizes[i] += func_ctx->stack_consumption_for_func_call;
+ if (UINT32_MAX - stack_sizes[i]
+ < stack_consumption_to_call_wrapped_func) {
+ aot_set_last_error("stack size overflow.");
+ goto fail;
+ }
+ stack_sizes[i] += stack_consumption_to_call_wrapped_func;
+ }
+ }
+ LLVMDisposeSectionIterator(sec_itr);
+ LLVMDisposeSymbolIterator(sym_itr);
+ return true;
+ }
+ LLVMMoveToNextSymbol(sym_itr);
+ }
+ aot_set_last_error("stack_sizes not found.");
+fail:
+ if (sec_itr)
+ LLVMDisposeSectionIterator(sec_itr);
+ LLVMDisposeSymbolIterator(sym_itr);
+ return false;
+}
+
static bool
aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
{
@@ -2347,6 +2848,10 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
/* allocate memory for aot function */
obj_data->func_count = comp_ctx->comp_data->func_count;
if (obj_data->func_count) {
+ if ((comp_ctx->enable_stack_bound_check
+ || comp_ctx->enable_stack_estimation)
+ && !aot_resolve_stack_sizes(comp_ctx, obj_data))
+ return false;
total_size = (uint32)sizeof(AOTObjectFunc) * obj_data->func_count;
if (!(obj_data->funcs = wasm_runtime_malloc(total_size))) {
aot_set_last_error("allocate memory for functions failed.");
@@ -2363,11 +2868,77 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
while (!LLVMObjectFileIsSymbolIteratorAtEnd(obj_data->binary, sym_itr)) {
if ((name = (char *)LLVMGetSymbolName(sym_itr))
&& str_starts_with(name, prefix)) {
+ /* symbol aot_func#n */
func_index = (uint32)atoi(name + strlen(prefix));
if (func_index < obj_data->func_count) {
+ LLVMSectionIteratorRef contain_section;
+ char *contain_section_name;
+
func = obj_data->funcs + func_index;
func->func_name = name;
- func->text_offset = LLVMGetSymbolAddress(sym_itr);
+
+ if (!(contain_section = LLVMObjectFileCopySectionIterator(
+ obj_data->binary))) {
+ aot_set_last_error("llvm get section iterator failed.");
+ LLVMDisposeSymbolIterator(sym_itr);
+ return false;
+ }
+ LLVMMoveToContainingSection(contain_section, sym_itr);
+ contain_section_name =
+ (char *)LLVMGetSectionName(contain_section);
+ LLVMDisposeSectionIterator(contain_section);
+
+ if (!strcmp(contain_section_name, ".text.unlikely.")) {
+ func->text_offset = align_uint(obj_data->text_size, 4)
+ + LLVMGetSymbolAddress(sym_itr);
+ }
+ else if (!strcmp(contain_section_name, ".text.hot.")) {
+ func->text_offset =
+ align_uint(obj_data->text_size, 4)
+ + align_uint(obj_data->text_unlikely_size, 4)
+ + LLVMGetSymbolAddress(sym_itr);
+ }
+ else {
+ func->text_offset = LLVMGetSymbolAddress(sym_itr);
+ }
+ }
+ }
+ else if ((name = (char *)LLVMGetSymbolName(sym_itr))
+ && str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)) {
+ /* symbol aot_func_internal#n */
+ func_index = (uint32)atoi(name + strlen(AOT_FUNC_INTERNAL_PREFIX));
+ if (func_index < obj_data->func_count) {
+ LLVMSectionIteratorRef contain_section;
+ char *contain_section_name;
+
+ func = obj_data->funcs + func_index;
+
+ if (!(contain_section = LLVMObjectFileCopySectionIterator(
+ obj_data->binary))) {
+ aot_set_last_error("llvm get section iterator failed.");
+ LLVMDisposeSymbolIterator(sym_itr);
+ return false;
+ }
+ LLVMMoveToContainingSection(contain_section, sym_itr);
+ contain_section_name =
+ (char *)LLVMGetSectionName(contain_section);
+ LLVMDisposeSectionIterator(contain_section);
+
+ if (!strcmp(contain_section_name, ".text.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.")) {
+ func->text_offset_of_aot_func_internal =
+ align_uint(obj_data->text_size, 4)
+ + align_uint(obj_data->text_unlikely_size, 4)
+ + LLVMGetSymbolAddress(sym_itr);
+ }
+ else {
+ func->text_offset_of_aot_func_internal =
+ LLVMGetSymbolAddress(sym_itr);
+ }
}
}
LLVMMoveToNextSymbol(sym_itr);
@@ -2478,9 +3049,95 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
}
/* set relocation fields */
- relocation->relocation_offset = offset;
relocation->relocation_type = (uint32)type;
relocation->symbol_name = (char *)LLVMGetSymbolName(rel_sym);
+ relocation->relocation_offset = offset;
+ if (!strcmp(group->section_name, ".rela.text.unlikely.")
+ || !strcmp(group->section_name, ".rel.text.unlikely.")) {
+ relocation->relocation_offset += align_uint(obj_data->text_size, 4);
+ }
+ else if (!strcmp(group->section_name, ".rela.text.hot.")
+ || !strcmp(group->section_name, ".rel.text.hot.")) {
+ relocation->relocation_offset +=
+ align_uint(obj_data->text_size, 4)
+ + align_uint(obj_data->text_unlikely_size, 4);
+ }
+ if (!strcmp(relocation->symbol_name, ".text.unlikely.")) {
+ relocation->symbol_name = ".text";
+ relocation->relocation_addend += align_uint(obj_data->text_size, 4);
+ }
+ if (!strcmp(relocation->symbol_name, ".text.hot.")) {
+ relocation->symbol_name = ".text";
+ relocation->relocation_addend +=
+ align_uint(obj_data->text_size, 4)
+ + align_uint(obj_data->text_unlikely_size, 4);
+ }
+
+ /*
+ * Note: aot_stack_sizes_section_name section only contains
+ * stack_sizes table.
+ */
+ if (!strcmp(relocation->symbol_name, aot_stack_sizes_name)) {
+ /* discard const */
+ relocation->symbol_name = (char *)aot_stack_sizes_section_name;
+ }
+
+ if (obj_data->comp_ctx->enable_llvm_pgo
+ && (!strcmp(relocation->symbol_name, "__llvm_prf_cnts")
+ || !strcmp(relocation->symbol_name, "__llvm_prf_data"))) {
+ LLVMSectionIteratorRef sec_itr;
+ char buf[32], *section_name;
+ uint32 prof_section_idx = 0;
+
+ if (!(sec_itr =
+ LLVMObjectFileCopySectionIterator(obj_data->binary))) {
+ aot_set_last_error("llvm get section iterator failed.");
+ LLVMDisposeSymbolIterator(rel_sym);
+ goto fail;
+ }
+ while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary,
+ sec_itr)) {
+ section_name = (char *)LLVMGetSectionName(sec_itr);
+ if (section_name
+ && !strcmp(section_name, relocation->symbol_name)) {
+ if (LLVMGetSectionContainsSymbol(sec_itr, rel_sym))
+ break;
+ prof_section_idx++;
+ }
+ LLVMMoveToNextSection(sec_itr);
+ }
+ LLVMDisposeSectionIterator(sec_itr);
+
+ if (!strcmp(group->section_name, ".rela.text")
+ || !strcmp(group->section_name, ".rel.text")) {
+ snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name,
+ prof_section_idx);
+ size = (uint32)(strlen(buf) + 1);
+ if (!(relocation->symbol_name = wasm_runtime_malloc(size))) {
+ aot_set_last_error(
+ "allocate memory for relocation symbol name failed.");
+ LLVMDisposeSymbolIterator(rel_sym);
+ goto fail;
+ }
+ bh_memcpy_s(relocation->symbol_name, size, buf, size);
+ relocation->is_symbol_name_allocated = true;
+ }
+ else if (!strncmp(group->section_name, ".rela__llvm_prf_data", 20)
+ || !strncmp(group->section_name, ".rel__llvm_prf_data",
+ 19)) {
+ snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name,
+ prof_section_idx);
+ size = (uint32)(strlen(buf) + 1);
+ if (!(relocation->symbol_name = wasm_runtime_malloc(size))) {
+ aot_set_last_error(
+ "allocate memory for relocation symbol name failed.");
+ LLVMDisposeSymbolIterator(rel_sym);
+ goto fail;
+ }
+ bh_memcpy_s(relocation->symbol_name, size, buf, size);
+ relocation->is_symbol_name_allocated = true;
+ }
+ }
/* for ".LCPIxxx", ".LJTIxxx", ".LBBxxx" and switch lookup table
* relocation, transform the symbol name to real section name and set
@@ -2525,10 +3182,14 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
}
static bool
-is_relocation_section_name(char *section_name)
+is_relocation_section_name(AOTObjectData *obj_data, char *section_name)
{
return (!strcmp(section_name, ".rela.text")
|| !strcmp(section_name, ".rel.text")
+ || !strcmp(section_name, ".rela.text.unlikely.")
+ || !strcmp(section_name, ".rel.text.unlikely.")
+ || !strcmp(section_name, ".rela.text.hot.")
+ || !strcmp(section_name, ".rel.text.hot.")
|| !strcmp(section_name, ".rela.literal")
|| !strcmp(section_name, ".rela.data")
|| !strcmp(section_name, ".rel.data")
@@ -2536,6 +3197,9 @@ is_relocation_section_name(char *section_name)
|| !strcmp(section_name, ".rel.sdata")
|| !strcmp(section_name, ".rela.rodata")
|| !strcmp(section_name, ".rel.rodata")
+ || (obj_data->comp_ctx->enable_llvm_pgo
+ && (!strcmp(section_name, ".rela__llvm_prf_data")
+ || !strcmp(section_name, ".rel__llvm_prf_data")))
/* ".rela.rodata.cst4/8/16/.." */
|| !strncmp(section_name, ".rela.rodata.cst",
strlen(".rela.rodata.cst"))
@@ -2545,20 +3209,28 @@ is_relocation_section_name(char *section_name)
}
static bool
-is_relocation_section(LLVMSectionIteratorRef sec_itr)
+is_relocation_section(AOTObjectData *obj_data, LLVMSectionIteratorRef sec_itr)
{
uint32 count = 0;
char *name = (char *)LLVMGetSectionName(sec_itr);
if (name) {
- if (is_relocation_section_name(name))
+ if (is_relocation_section_name(obj_data, name))
return true;
- else if ((!strcmp(name, ".text") || !strcmp(name, ".rdata"))
+ else if ((!strcmp(name, ".text") || !strcmp(name, ".text.unlikely.")
+ || !strcmp(name, ".text.hot.") || !strcmp(name, ".rdata"))
&& get_relocations_count(sec_itr, &count) && count > 0)
return true;
}
return false;
}
+static bool
+is_readonly_section(const char *name)
+{
+ return !strcmp(name, ".rel.text") || !strcmp(name, ".rela.text")
+ || !strcmp(name, ".rela.literal") || !strcmp(name, ".text");
+}
+
static bool
get_relocation_groups_count(AOTObjectData *obj_data, uint32 *p_count)
{
@@ -2570,7 +3242,7 @@ get_relocation_groups_count(AOTObjectData *obj_data, uint32 *p_count)
return false;
}
while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) {
- if (is_relocation_section(sec_itr)) {
+ if (is_relocation_section(obj_data, sec_itr)) {
count++;
}
LLVMMoveToNextSection(sec_itr);
@@ -2586,7 +3258,7 @@ aot_resolve_object_relocation_groups(AOTObjectData *obj_data)
{
LLVMSectionIteratorRef sec_itr;
AOTRelocationGroup *relocation_group;
- uint32 group_count;
+ uint32 group_count, llvm_prf_data_idx = 0;
char *name;
uint32 size;
@@ -2612,14 +3284,63 @@ aot_resolve_object_relocation_groups(AOTObjectData *obj_data)
return false;
}
while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) {
- if (is_relocation_section(sec_itr)) {
+ if (is_relocation_section(obj_data, sec_itr)) {
name = (char *)LLVMGetSectionName(sec_itr);
relocation_group->section_name = name;
+
+ if (obj_data->comp_ctx->enable_llvm_pgo
+ && (!strcmp(name, ".rela__llvm_prf_data")
+ || !strcmp(name, ".rel__llvm_prf_data"))) {
+ char buf[32];
+ snprintf(buf, sizeof(buf), "%s%u", name, llvm_prf_data_idx);
+ size = (uint32)(strlen(buf) + 1);
+ if (!(relocation_group->section_name =
+ wasm_runtime_malloc(size))) {
+ aot_set_last_error(
+ "allocate memory for section name failed.");
+ LLVMDisposeSectionIterator(sec_itr);
+ return false;
+ }
+ bh_memcpy_s(relocation_group->section_name, size, buf, size);
+ relocation_group->is_section_name_allocated = true;
+ }
+
if (!aot_resolve_object_relocation_group(obj_data, relocation_group,
sec_itr)) {
LLVMDisposeSectionIterator(sec_itr);
return false;
}
+
+ if (obj_data->comp_ctx->enable_llvm_pgo
+ && (!strcmp(name, ".rela__llvm_prf_data")
+ || !strcmp(name, ".rel__llvm_prf_data"))) {
+ llvm_prf_data_idx++;
+ }
+
+ if (!strcmp(relocation_group->section_name, ".rela.text.unlikely.")
+ || !strcmp(relocation_group->section_name, ".rela.text.hot.")) {
+ relocation_group->section_name = ".rela.text";
+ }
+ else if (!strcmp(relocation_group->section_name,
+ ".rel.text.unlikely.")
+ || !strcmp(relocation_group->section_name,
+ ".rel.text.hot.")) {
+ relocation_group->section_name = ".rel.text";
+ }
+
+ /*
+ * Relocations in read-only sections are problematic,
+ * especially for XIP on platforms which don't have
+ * copy-on-write mappings.
+ */
+ if (obj_data->comp_ctx->is_indirect_mode
+ && is_readonly_section(relocation_group->section_name)) {
+ LOG_WARNING("%" PRIu32
+ " text relocations in %s section for indirect mode",
+ relocation_group->relocation_count,
+ relocation_group->section_name);
+ }
+
relocation_group++;
}
LLVMMoveToNextSection(sec_itr);
@@ -2633,12 +3354,21 @@ static void
destroy_relocation_groups(AOTRelocationGroup *relocation_groups,
uint32 relocation_group_count)
{
- uint32 i;
+ uint32 i, j;
AOTRelocationGroup *relocation_group = relocation_groups;
- for (i = 0; i < relocation_group_count; i++, relocation_group++)
- if (relocation_group->relocations)
+ for (i = 0; i < relocation_group_count; i++, relocation_group++) {
+ if (relocation_group->relocations) {
+ for (j = 0; j < relocation_group->relocation_count; j++) {
+ if (relocation_group->relocations[j].is_symbol_name_allocated)
+ wasm_runtime_free(
+ relocation_group->relocations[j].symbol_name);
+ }
wasm_runtime_free(relocation_group->relocations);
+ }
+ if (relocation_group->is_section_name_allocated)
+ wasm_runtime_free(relocation_group->section_name);
+ }
wasm_runtime_free(relocation_groups);
}
@@ -2664,13 +3394,27 @@ aot_obj_data_destroy(AOTObjectData *obj_data)
LLVMDisposeMemoryBuffer(obj_data->mem_buf);
if (obj_data->funcs)
wasm_runtime_free(obj_data->funcs);
- if (obj_data->data_sections)
+ if (obj_data->data_sections) {
+ uint32 i;
+ for (i = 0; i < obj_data->data_sections_count; i++) {
+ if (obj_data->data_sections[i].name
+ && obj_data->data_sections[i].is_name_allocated) {
+ wasm_runtime_free(obj_data->data_sections[i].name);
+ }
+ if (obj_data->data_sections[i].data
+ && obj_data->data_sections[i].is_data_allocated) {
+ wasm_runtime_free(obj_data->data_sections[i].data);
+ }
+ }
wasm_runtime_free(obj_data->data_sections);
+ }
if (obj_data->relocation_groups)
destroy_relocation_groups(obj_data->relocation_groups,
obj_data->relocation_group_count);
if (obj_data->symbol_list.len)
destroy_relocation_symbol_list(&obj_data->symbol_list);
+ if (obj_data->stack_sizes)
+ wasm_runtime_free(obj_data->stack_sizes);
wasm_runtime_free(obj_data);
}
@@ -2688,6 +3432,7 @@ aot_obj_data_create(AOTCompContext *comp_ctx)
return false;
}
memset(obj_data, 0, sizeof(AOTObjectData));
+ obj_data->comp_ctx = comp_ctx;
bh_print_time("Begin to emit object file");
if (comp_ctx->external_llc_compiler || comp_ctx->external_asm_compiler) {
@@ -2821,8 +3566,8 @@ aot_obj_data_create(AOTCompContext *comp_ctx)
if (!aot_resolve_target_info(comp_ctx, obj_data)
|| !aot_resolve_text(obj_data) || !aot_resolve_literal(obj_data)
|| !aot_resolve_object_data_sections(obj_data)
- || !aot_resolve_object_relocation_groups(obj_data)
- || !aot_resolve_functions(comp_ctx, obj_data))
+ || !aot_resolve_functions(comp_ctx, obj_data)
+ || !aot_resolve_object_relocation_groups(obj_data))
goto fail;
return obj_data;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.c
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.c
index 2cf51cf6727..a8ee938f253 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.c
@@ -4,6 +4,7 @@
*/
#include "aot_emit_control.h"
+#include "aot_compiler.h"
#include "aot_emit_exception.h"
#include "../aot/aot_runtime.h"
#include "../interpreter/wasm_loader.h"
@@ -201,6 +202,9 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
*p_frame_ip = block->wasm_code_else + 1;
/* Push back the block */
aot_block_stack_push(&func_ctx->block_stack, block);
+ /* Recover parameters of else branch */
+ for (i = 0; i < block->param_count; i++)
+ PUSH(block->else_param_phis[i], block->param_types[i]);
return true;
}
else if (block->llvm_end_block) {
@@ -220,6 +224,19 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return true;
}
+ if (block->label_type == LABEL_TYPE_IF && block->llvm_else_block
+ && !block->skip_wasm_code_else
+ && *p_frame_ip <= block->wasm_code_else) {
+ /* Clear value stack and start to translate else branch */
+ aot_value_stack_destroy(&block->value_stack);
+ /* Recover parameters of else branch */
+ for (i = 0; i < block->param_count; i++)
+ PUSH(block->else_param_phis[i], block->param_types[i]);
+ SET_BUILDER_POS(block->llvm_else_block);
+ *p_frame_ip = block->wasm_code_else + 1;
+ return true;
+ }
+
*p_frame_ip = block->wasm_code_end + 1;
SET_BUILDER_POS(block->llvm_end_block);
@@ -234,13 +251,15 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
else {
/* Store extra return values to function parameters */
if (i != 0) {
+ LLVMValueRef res;
uint32 param_index = func_type->param_count + i;
- if (!LLVMBuildStore(
- comp_ctx->builder, block->result_phis[i],
- LLVMGetParam(func_ctx->func, param_index))) {
+ if (!(res = LLVMBuildStore(
+ comp_ctx->builder, block->result_phis[i],
+ LLVMGetParam(func_ctx->func, param_index)))) {
aot_set_last_error("llvm build store failed.");
goto fail;
}
+ LLVMSetAlignment(res, 1);
}
}
}
@@ -278,7 +297,7 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
AOTBlock *block)
{
uint32 i, param_index;
- LLVMValueRef value;
+ LLVMValueRef value, br_inst;
uint64 size;
char name[32];
LLVMBasicBlockRef block_curr = CURR_BLOCK();
@@ -326,7 +345,14 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
}
}
}
- SET_BUILDER_POS(block_curr);
+
+ /* At this point, the branch instruction was already built to jump to
+ * the new BB, to avoid generating zext instruction from the popped
+ * operand that would come after branch instruction, we should position
+ * the builder before the last branch instruction */
+ br_inst = LLVMGetLastInstruction(block_curr);
+ bh_assert(LLVMGetInstructionOpcode(br_inst) == LLVMBr);
+ LLVMPositionBuilderBefore(comp_ctx->builder, br_inst);
/* Pop param values from current block's
* value stack and add to param phis.
@@ -334,7 +360,9 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
for (i = 0; i < block->param_count; i++) {
param_index = block->param_count - 1 - i;
POP(value, block->param_types[param_index]);
- ADD_TO_PARAM_PHIS(block, value, param_index);
+ if (block->llvm_entry_block)
+ /* Only add incoming phis if the entry block was created */
+ ADD_TO_PARAM_PHIS(block, value, param_index);
if (block->label_type == LABEL_TYPE_IF
&& !block->skip_wasm_code_else) {
if (block->llvm_else_block) {
@@ -356,7 +384,17 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
/* Push param phis to the new block */
for (i = 0; i < block->param_count; i++) {
- PUSH(block->param_phis[i], block->param_types[i]);
+ if (block->llvm_entry_block)
+ /* Push param phis if the entry basic block was created */
+ PUSH(block->param_phis[i], block->param_types[i]);
+ else {
+ bh_assert(block->label_type == LABEL_TYPE_IF
+ && block->llvm_else_block && block->else_param_phis
+ && !block->skip_wasm_code_else);
+ /* Push else param phis if we start to translate the
+ else branch */
+ PUSH(block->else_param_phis[i], block->param_types[i]);
+ }
}
return true;
@@ -467,7 +505,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
p_frame_ip);
}
- if (!LLVMIsConstant(value)) {
+ if (!LLVMIsEfficientConstInt(value)) {
/* Compare value is not constant, create condition br IR */
/* Create entry block */
format_block_name(name, sizeof(name), block->block_index,
@@ -833,7 +871,7 @@ aot_compile_op_br_if(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
}
- if (!LLVMIsConstant(value_cmp)) {
+ if (!LLVMIsEfficientConstInt(value_cmp)) {
/* Compare value is not constant, create condition br IR */
if (!(block_dst = get_target_block(func_ctx, br_depth))) {
return false;
@@ -970,7 +1008,7 @@ aot_compile_op_br_table(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
}
- if (!LLVMIsConstant(value_cmp)) {
+ if (!LLVMIsEfficientConstInt(value_cmp)) {
/* Compare value is not constant, create switch IR */
for (i = 0; i <= br_count; i++) {
target_block = get_target_block(func_ctx, br_depths[i]);
@@ -1102,14 +1140,17 @@ aot_compile_op_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
if (block_func->result_count) {
/* Store extra result values to function parameters */
for (i = 0; i < block_func->result_count - 1; i++) {
+ LLVMValueRef res;
result_index = block_func->result_count - 1 - i;
POP(value, block_func->result_types[result_index]);
param_index = func_type->param_count + result_index;
- if (!LLVMBuildStore(comp_ctx->builder, value,
- LLVMGetParam(func_ctx->func, param_index))) {
+ if (!(res = LLVMBuildStore(
+ comp_ctx->builder, value,
+ LLVMGetParam(func_ctx->func, param_index)))) {
aot_set_last_error("llvm build store failed.");
goto fail;
}
+ LLVMSetAlignment(res, 1);
}
/* Return the first result value */
POP(value, block_func->result_types[0]);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.c
similarity index 90%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.c
index 9ba8baa24f9..bc8cb0a55a6 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.c
@@ -18,6 +18,20 @@
} \
} while (0)
+static bool
+is_win_platform(AOTCompContext *comp_ctx)
+{
+ char *triple = LLVMGetTargetMachineTriple(comp_ctx->target_machine);
+ bool ret;
+
+ bh_assert(triple);
+ ret = (strstr(triple, "win32") || strstr(triple, "win")) ? true : false;
+
+ LLVMDisposeMessage(triple);
+
+ return ret;
+}
+
static bool
create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
{
@@ -366,143 +380,6 @@ call_aot_free_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
#endif /* end of (WASM_ENABLE_DUMP_CALL_STACK != 0) \
|| (WASM_ENABLE_PERF_PROFILING != 0) */
-static bool
-record_stack_usage(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint32 callee_cell_num)
-{
- LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder);
- LLVMBasicBlockRef block_update;
- LLVMBasicBlockRef block_after_update;
- LLVMValueRef callee_local_size, new_sp, cmp;
- LLVMValueRef native_stack_top_min;
- LLVMTypeRef ptrdiff_type;
- if (comp_ctx->pointer_size == sizeof(uint64_t)) {
- ptrdiff_type = I64_TYPE;
- }
- else {
- ptrdiff_type = I32_TYPE;
- }
-
- /*
- * new_sp = last_alloca - callee_local_size;
- * if (*native_stack_top_min_addr > new_sp) {
- * *native_stack_top_min_addr = new_sp;
- * }
- */
-
- if (!(callee_local_size = LLVMConstInt(
- ptrdiff_type, -(int64_t)callee_cell_num * 4, true))) {
- aot_set_last_error("llvm build const failed.");
- return false;
- }
- if (!(new_sp = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
- func_ctx->last_alloca,
- &callee_local_size, 1, "new_sp"))) {
- aot_set_last_error("llvm build gep failed");
- return false;
- }
- if (!(native_stack_top_min = LLVMBuildLoad2(
- comp_ctx->builder, OPQ_PTR_TYPE,
- func_ctx->native_stack_top_min_addr, "native_stack_top_min"))) {
- aot_set_last_error("llvm build load failed");
- return false;
- }
- if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT, new_sp,
- native_stack_top_min, "cmp"))) {
- aot_set_last_error("llvm build icmp failed.");
- return false;
- }
-
- if (!(block_update = LLVMAppendBasicBlockInContext(
- comp_ctx->context, func_ctx->func, "block_update"))) {
- aot_set_last_error("llvm add basic block failed.");
- return false;
- }
- if (!(block_after_update = LLVMAppendBasicBlockInContext(
- comp_ctx->context, func_ctx->func, "block_after_update"))) {
- aot_set_last_error("llvm add basic block failed.");
- return false;
- }
- LLVMMoveBasicBlockAfter(block_update, block_curr);
- LLVMMoveBasicBlockAfter(block_after_update, block_update);
-
- if (!LLVMBuildCondBr(comp_ctx->builder, cmp, block_update,
- block_after_update)) {
- aot_set_last_error("llvm build cond br failed.");
- return false;
- }
-
- LLVMPositionBuilderAtEnd(comp_ctx->builder, block_update);
- if (!LLVMBuildStore(comp_ctx->builder, new_sp,
- func_ctx->native_stack_top_min_addr)) {
- aot_set_last_error("llvm build store failed");
- return false;
- }
- if (!LLVMBuildBr(comp_ctx->builder, block_after_update)) {
- aot_set_last_error("llvm build br failed.");
- return false;
- }
-
- LLVMPositionBuilderAtEnd(comp_ctx->builder, block_after_update);
- return true;
-}
-
-static bool
-check_stack_boundary(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint32 callee_cell_num)
-{
- LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder);
- LLVMBasicBlockRef check_stack;
- LLVMValueRef callee_local_size, stack_bound, cmp;
-
- if (!(callee_local_size = I32_CONST(callee_cell_num * 4))) {
- aot_set_last_error("llvm build const failed.");
- return false;
- }
-
- if (!(stack_bound = LLVMBuildInBoundsGEP2(
- comp_ctx->builder, INT8_TYPE, func_ctx->native_stack_bound,
- &callee_local_size, 1, "stack_bound"))) {
- aot_set_last_error("llvm build inbound gep failed.");
- return false;
- }
-
- if (!(check_stack = LLVMAppendBasicBlockInContext(
- comp_ctx->context, func_ctx->func, "check_stack"))) {
- aot_set_last_error("llvm add basic block failed.");
- return false;
- }
-
- LLVMMoveBasicBlockAfter(check_stack, block_curr);
-
- if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT,
- func_ctx->last_alloca, stack_bound, "cmp"))) {
- aot_set_last_error("llvm build icmp failed.");
- return false;
- }
-
- if (!aot_emit_exception(comp_ctx, func_ctx, EXCE_NATIVE_STACK_OVERFLOW,
- true, cmp, check_stack)) {
- return false;
- }
-
- LLVMPositionBuilderAtEnd(comp_ctx->builder, check_stack);
- return true;
-}
-
-static bool
-check_stack(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint32 callee_cell_num)
-{
- if (comp_ctx->enable_stack_estimation
- && !record_stack_usage(comp_ctx, func_ctx, callee_cell_num))
- return false;
- if (comp_ctx->enable_stack_bound_check
- && !check_stack_boundary(comp_ctx, func_ctx, callee_cell_num))
- return false;
- return true;
-}
-
/**
* Check whether the app address and its buffer are inside the linear memory,
* if no, throw exception
@@ -595,7 +472,7 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
/* Check whether exception was thrown when executing the function */
- if (comp_ctx->enable_bound_check
+ if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_call_return(comp_ctx, func_ctx, res)) {
return false;
}
@@ -610,6 +487,30 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return true;
}
+static void
+aot_estimate_and_record_stack_usage_for_function_call(
+ const AOTCompContext *comp_ctx, AOTFuncContext *caller_func_ctx,
+ const AOTFuncType *callee_func_type)
+{
+ unsigned int size;
+
+ if (!(comp_ctx->enable_stack_bound_check
+ || comp_ctx->enable_stack_estimation)) {
+ return;
+ }
+
+ size =
+ aot_estimate_stack_usage_for_function_call(comp_ctx, callee_func_type);
+ /*
+ * only record the max value, assuming that LLVM emits machine code
+ * which rewinds the stack before making the next call in the
+ * function.
+ */
+ if (caller_func_ctx->stack_consumption_for_func_call < size) {
+ caller_func_ctx->stack_consumption_for_func_call = size;
+ }
+}
+
bool
aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 func_idx, bool tail_call)
@@ -620,7 +521,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 ext_ret_cell_num = 0, cell_num = 0;
AOTFuncContext **func_ctxes = comp_ctx->func_ctxes;
AOTFuncType *func_type;
- AOTFunc *aot_func;
LLVMTypeRef *param_types = NULL, ret_type;
LLVMTypeRef ext_ret_ptr_type;
LLVMValueRef *param_values = NULL, value_ret = NULL, func;
@@ -628,7 +528,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef ext_ret, ext_ret_ptr, ext_ret_idx;
int32 i, j = 0, param_count, result_count, ext_ret_count;
uint64 total_size;
- uint32 callee_cell_num;
uint8 wasm_ret_type;
uint8 *ext_ret_types = NULL;
const char *signature = NULL;
@@ -658,6 +557,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
func_type =
func_ctxes[func_idx - import_func_count]->aot_func->func_type;
}
+ aot_estimate_and_record_stack_usage_for_function_call(comp_ctx, func_ctx,
+ func_type);
/* Get param cell number */
param_cell_num = func_type->param_cell_num;
@@ -809,7 +710,7 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail;
/* Check whether there was exception thrown when executing
the function */
- if (comp_ctx->enable_bound_check
+ if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_call_return(comp_ctx, func_ctx, res))
goto fail;
}
@@ -868,10 +769,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
#if LLVM_VERSION_MAJOR >= 14
LLVMTypeRef llvm_func_type;
#endif
- bool recursive_call =
- (func_ctx == func_ctxes[func_idx - import_func_count]) ? true
- : false;
-
if (comp_ctx->is_indirect_mode) {
LLVMTypeRef func_ptr_type;
@@ -889,15 +786,17 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
else {
if (func_ctxes[func_idx - import_func_count] == func_ctx) {
/* recursive call */
- func = func_ctx->func;
+ func = func_ctx->precheck_func;
}
else {
if (!comp_ctx->is_jit_mode) {
- func = func_ctxes[func_idx - import_func_count]->func;
+ func =
+ func_ctxes[func_idx - import_func_count]->precheck_func;
}
else {
#if !(WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0)
- func = func_ctxes[func_idx - import_func_count]->func;
+ func =
+ func_ctxes[func_idx - import_func_count]->precheck_func;
#else
/* JIT tier-up, load func ptr from func_ptrs[func_idx] */
LLVMValueRef func_ptr, func_idx_const;
@@ -942,13 +841,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
}
- aot_func = func_ctxes[func_idx - import_func_count]->aot_func;
- callee_cell_num =
- aot_func->param_cell_num + aot_func->local_cell_num + 1;
-
- if (!check_stack(comp_ctx, func_ctx, callee_cell_num))
- goto fail;
-
#if LLVM_VERSION_MAJOR >= 14
llvm_func_type = func_ctxes[func_idx - import_func_count]->func_type;
#endif
@@ -971,7 +863,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* Check whether there was exception thrown when executing
the function */
- if (!tail_call && !recursive_call && comp_ctx->enable_bound_check
+ if (!tail_call
+ && (comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_exception_thrown(comp_ctx, func_ctx))
goto fail;
}
@@ -1217,6 +1110,8 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
CHECK_LLVM_CONST(ftype_idx_const);
func_type = comp_ctx->comp_data->func_types[type_idx];
+ aot_estimate_and_record_stack_usage_for_function_call(comp_ctx, func_ctx,
+ func_type);
func_param_count = func_type->param_count;
func_result_count = func_type->result_count;
@@ -1551,7 +1446,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail;
/* Check whether exception was thrown when executing the function */
- if (comp_ctx->enable_bound_check
+ if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_call_return(comp_ctx, func_ctx, res))
goto fail;
@@ -1568,13 +1463,6 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* Translate call non-import block */
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_call_non_import);
- if (!check_stack(comp_ctx, func_ctx,
- param_cell_num + ext_cell_num
- + 1
- /* Reserve some local variables */
- + 16))
- goto fail;
-
/* Load function pointer */
if (!(func_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE,
func_ctx->func_ptrs, &func_idx, 1,
@@ -1610,7 +1498,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
/* Check whether exception was thrown when executing the function */
- if (comp_ctx->enable_bound_check
+ if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_exception_thrown(comp_ctx, func_ctx))
goto fail;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.h
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.h
index 26f09c66030..798243e60ef 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.h
@@ -29,6 +29,7 @@ aot_compile_op_ref_is_null(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
bool
aot_compile_op_ref_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 func_idx);
+
#ifdef __cplusplus
} /* end of extern "C" */
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c
similarity index 85%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c
index 4da4cc807f5..8c35c3fe650 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c
@@ -4,6 +4,7 @@
*/
#include "aot_emit_memory.h"
+#include "aot_compiler.h"
#include "aot_emit_exception.h"
#include "../aot/aot_runtime.h"
#include "aot_intrinsic.h"
@@ -81,7 +82,7 @@ get_memory_curr_page_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
LLVMValueRef
aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint32 offset, uint32 bytes)
+ uint32 offset, uint32 bytes, bool enable_segue)
{
LLVMValueRef offset_const = I32_CONST(offset);
LLVMValueRef addr, maddr, offset1, cmp1, cmp2, cmp;
@@ -145,11 +146,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
* have been thrown when converting float to integer before
*/
/* return addres directly if constant offset and inside memory space */
- if (LLVMIsConstant(addr) && !LLVMIsUndef(addr)
-#if LLVM_VERSION_NUMBER >= 12
- && !LLVMIsPoison(addr)
-#endif
- ) {
+ if (LLVMIsEfficientConstInt(addr)) {
uint64 mem_offset =
(uint64)LLVMConstIntGetZExtValue(addr) + (uint64)offset;
uint32 num_bytes_per_page =
@@ -160,13 +157,25 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
if (mem_offset + bytes <= mem_data_size) {
/* inside memory space */
- offset1 = I32_CONST((uint32)mem_offset);
+ if (comp_ctx->pointer_size == sizeof(uint64))
+ offset1 = I64_CONST((uint32)mem_offset);
+ else
+ offset1 = I32_CONST((uint32)mem_offset);
CHECK_LLVM_CONST(offset1);
- if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
- mem_base_addr, &offset1, 1,
- "maddr"))) {
- aot_set_last_error("llvm build add failed.");
- goto fail;
+ if (!enable_segue) {
+ if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder,
+ INT8_TYPE, mem_base_addr,
+ &offset1, 1, "maddr"))) {
+ aot_set_last_error("llvm build add failed.");
+ goto fail;
+ }
+ }
+ else {
+ if (!(maddr = LLVMBuildIntToPtr(comp_ctx->builder, offset1,
+ INT8_PTR_TYPE_GS, "maddr"))) {
+ aot_set_last_error("llvm build IntToPtr failed.");
+ goto fail;
+ }
}
return maddr;
}
@@ -244,11 +253,29 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
}
- /* maddr = mem_base_addr + offset1 */
- if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
+ if (!enable_segue) {
+ /* maddr = mem_base_addr + offset1 */
+ if (!(maddr =
+ LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
mem_base_addr, &offset1, 1, "maddr"))) {
- aot_set_last_error("llvm build add failed.");
- goto fail;
+ aot_set_last_error("llvm build add failed.");
+ goto fail;
+ }
+ }
+ else {
+ LLVMValueRef maddr_base;
+
+ if (!(maddr_base = LLVMBuildIntToPtr(comp_ctx->builder, addr,
+ INT8_PTR_TYPE_GS, "maddr_base"))) {
+ aot_set_last_error("llvm build int to ptr failed.");
+ goto fail;
+ }
+ if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
+ maddr_base, &offset_const, 1,
+ "maddr"))) {
+ aot_set_last_error("llvm build inboundgep failed.");
+ goto fail;
+ }
}
return maddr;
fail:
@@ -388,13 +415,18 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
{
LLVMValueRef maddr, value = NULL;
LLVMTypeRef data_type;
+ bool enable_segue = comp_ctx->enable_segue_i32_load;
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ enable_segue)))
return false;
switch (bytes) {
case 4:
- BUILD_PTR_CAST(INT32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT32_PTR_TYPE_GS);
#if WASM_ENABLE_SHARED_MEMORY != 0
if (atomic)
BUILD_ATOMIC_LOAD(align, I32_TYPE);
@@ -405,11 +437,17 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
case 2:
case 1:
if (bytes == 2) {
- BUILD_PTR_CAST(INT16_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT16_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT16_PTR_TYPE_GS);
data_type = INT16_TYPE;
}
else {
- BUILD_PTR_CAST(INT8_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT8_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT8_PTR_TYPE_GS);
data_type = INT8_TYPE;
}
@@ -447,13 +485,18 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
{
LLVMValueRef maddr, value = NULL;
LLVMTypeRef data_type;
+ bool enable_segue = comp_ctx->enable_segue_i64_load;
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ enable_segue)))
return false;
switch (bytes) {
case 8:
- BUILD_PTR_CAST(INT64_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT64_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT64_PTR_TYPE_GS);
#if WASM_ENABLE_SHARED_MEMORY != 0
if (atomic)
BUILD_ATOMIC_LOAD(align, I64_TYPE);
@@ -465,15 +508,24 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
case 2:
case 1:
if (bytes == 4) {
- BUILD_PTR_CAST(INT32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT32_PTR_TYPE_GS);
data_type = I32_TYPE;
}
else if (bytes == 2) {
- BUILD_PTR_CAST(INT16_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT16_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT16_PTR_TYPE_GS);
data_type = INT16_TYPE;
}
else {
- BUILD_PTR_CAST(INT8_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT8_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT8_PTR_TYPE_GS);
data_type = INT8_TYPE;
}
@@ -509,12 +561,18 @@ aot_compile_op_f32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset)
{
LLVMValueRef maddr, value;
+ bool enable_segue = comp_ctx->enable_segue_f32_load;
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4,
+ enable_segue)))
return false;
- BUILD_PTR_CAST(F32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(F32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(F32_PTR_TYPE_GS);
BUILD_LOAD(F32_TYPE);
+
PUSH_F32(value);
return true;
fail:
@@ -526,12 +584,18 @@ aot_compile_op_f64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset)
{
LLVMValueRef maddr, value;
+ bool enable_segue = comp_ctx->enable_segue_f64_load;
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8,
+ enable_segue)))
return false;
- BUILD_PTR_CAST(F64_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(F64_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(F64_PTR_TYPE_GS);
BUILD_LOAD(F64_TYPE);
+
PUSH_F64(value);
return true;
fail:
@@ -543,22 +607,33 @@ aot_compile_op_i32_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset, uint32 bytes, bool atomic)
{
LLVMValueRef maddr, value;
+ bool enable_segue = comp_ctx->enable_segue_i32_store;
POP_I32(value);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ enable_segue)))
return false;
switch (bytes) {
case 4:
- BUILD_PTR_CAST(INT32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT32_PTR_TYPE_GS);
break;
case 2:
- BUILD_PTR_CAST(INT16_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT16_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT16_PTR_TYPE_GS);
BUILD_TRUNC(value, INT16_TYPE);
break;
case 1:
- BUILD_PTR_CAST(INT8_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT8_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT8_PTR_TYPE_GS);
BUILD_TRUNC(value, INT8_TYPE);
break;
default:
@@ -582,26 +657,40 @@ aot_compile_op_i64_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset, uint32 bytes, bool atomic)
{
LLVMValueRef maddr, value;
+ bool enable_segue = comp_ctx->enable_segue_i64_store;
POP_I64(value);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ enable_segue)))
return false;
switch (bytes) {
case 8:
- BUILD_PTR_CAST(INT64_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT64_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT64_PTR_TYPE_GS);
break;
case 4:
- BUILD_PTR_CAST(INT32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT32_PTR_TYPE_GS);
BUILD_TRUNC(value, I32_TYPE);
break;
case 2:
- BUILD_PTR_CAST(INT16_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT16_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT16_PTR_TYPE_GS);
BUILD_TRUNC(value, INT16_TYPE);
break;
case 1:
- BUILD_PTR_CAST(INT8_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT8_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT8_PTR_TYPE_GS);
BUILD_TRUNC(value, INT8_TYPE);
break;
default:
@@ -625,13 +714,18 @@ aot_compile_op_f32_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset)
{
LLVMValueRef maddr, value;
+ bool enable_segue = comp_ctx->enable_segue_f32_store;
POP_F32(value);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4,
+ enable_segue)))
return false;
- BUILD_PTR_CAST(F32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(F32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(F32_PTR_TYPE_GS);
BUILD_STORE();
return true;
fail:
@@ -643,13 +737,18 @@ aot_compile_op_f64_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset)
{
LLVMValueRef maddr, value;
+ bool enable_segue = comp_ctx->enable_segue_f64_store;
POP_F64(value);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8,
+ enable_segue)))
return false;
- BUILD_PTR_CAST(F64_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(F64_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(F64_PTR_TYPE_GS);
BUILD_STORE();
return true;
fail:
@@ -812,11 +911,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
* have been thrown when converting float to integer before
*/
/* return addres directly if constant offset and inside memory space */
- if (!LLVMIsUndef(offset) && !LLVMIsUndef(bytes)
-#if LLVM_VERSION_NUMBER >= 12
- && !LLVMIsPoison(offset) && !LLVMIsPoison(bytes)
-#endif
- && LLVMIsConstant(offset) && LLVMIsConstant(bytes)) {
+ if (LLVMIsEfficientConstInt(offset) && LLVMIsEfficientConstInt(bytes)) {
uint64 mem_offset = (uint64)LLVMConstIntGetZExtValue(offset);
uint64 mem_len = (uint64)LLVMConstIntGetZExtValue(bytes);
uint32 num_bytes_per_page =
@@ -1140,13 +1235,19 @@ aot_compile_op_atomic_rmw(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 offset, uint32 bytes)
{
LLVMValueRef maddr, value, result;
+ bool enable_segue = (op_type == VALUE_TYPE_I32)
+ ? comp_ctx->enable_segue_i32_load
+ && comp_ctx->enable_segue_i32_store
+ : comp_ctx->enable_segue_i64_load
+ && comp_ctx->enable_segue_i64_store;
if (op_type == VALUE_TYPE_I32)
POP_I32(value);
else
POP_I64(value);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ enable_segue)))
return false;
if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align))
@@ -1154,19 +1255,31 @@ aot_compile_op_atomic_rmw(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
switch (bytes) {
case 8:
- BUILD_PTR_CAST(INT64_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT64_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT64_PTR_TYPE_GS);
break;
case 4:
- BUILD_PTR_CAST(INT32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT32_PTR_TYPE_GS);
if (op_type == VALUE_TYPE_I64)
BUILD_TRUNC(value, I32_TYPE);
break;
case 2:
- BUILD_PTR_CAST(INT16_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT16_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT16_PTR_TYPE_GS);
BUILD_TRUNC(value, INT16_TYPE);
break;
case 1:
- BUILD_PTR_CAST(INT8_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT8_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT8_PTR_TYPE_GS);
BUILD_TRUNC(value, INT8_TYPE);
break;
default:
@@ -1208,6 +1321,11 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx,
uint32 align, uint32 offset, uint32 bytes)
{
LLVMValueRef maddr, value, expect, result;
+ bool enable_segue = (op_type == VALUE_TYPE_I32)
+ ? comp_ctx->enable_segue_i32_load
+ && comp_ctx->enable_segue_i32_store
+ : comp_ctx->enable_segue_i64_load
+ && comp_ctx->enable_segue_i64_store;
if (op_type == VALUE_TYPE_I32) {
POP_I32(value);
@@ -1218,7 +1336,8 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx,
POP_I64(expect);
}
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ enable_segue)))
return false;
if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align))
@@ -1226,22 +1345,34 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx,
switch (bytes) {
case 8:
- BUILD_PTR_CAST(INT64_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT64_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT64_PTR_TYPE_GS);
break;
case 4:
- BUILD_PTR_CAST(INT32_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT32_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT32_PTR_TYPE_GS);
if (op_type == VALUE_TYPE_I64) {
BUILD_TRUNC(value, I32_TYPE);
BUILD_TRUNC(expect, I32_TYPE);
}
break;
case 2:
- BUILD_PTR_CAST(INT16_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT16_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT16_PTR_TYPE_GS);
BUILD_TRUNC(value, INT16_TYPE);
BUILD_TRUNC(expect, INT16_TYPE);
break;
case 1:
- BUILD_PTR_CAST(INT8_PTR_TYPE);
+ if (!enable_segue)
+ BUILD_PTR_CAST(INT8_PTR_TYPE);
+ else
+ BUILD_PTR_CAST(INT8_PTR_TYPE_GS);
BUILD_TRUNC(value, INT8_TYPE);
BUILD_TRUNC(expect, INT8_TYPE);
break;
@@ -1318,7 +1449,8 @@ aot_compile_op_atomic_wait(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
CHECK_LLVM_CONST(is_wait64);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ false)))
return false;
if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align))
@@ -1393,7 +1525,8 @@ aot_compiler_op_atomic_notify(AOTCompContext *comp_ctx,
POP_I32(count);
- if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
+ if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes,
+ false)))
return false;
if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align))
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.h
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.h
index e49582e3c0c..1c2db503a85 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.h
@@ -53,7 +53,7 @@ aot_compile_op_f64_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef
aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint32 offset, uint32 bytes);
+ uint32 offset, uint32 bytes, bool enable_segue);
bool
aot_compile_op_memory_size(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.c
index 4c63e8a40be..8b6ec02d64b 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.c
@@ -54,13 +54,13 @@
} while (0)
#if LLVM_VERSION_NUMBER >= 12
-#define IS_CONST_ZERO(val) \
- (!LLVMIsUndef(val) && !LLVMIsPoison(val) && LLVMIsConstant(val) \
- && ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \
+#define IS_CONST_ZERO(val) \
+ (LLVMIsEfficientConstInt(val) \
+ && ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \
|| (!is_i32 && (int64)LLVMConstIntGetSExtValue(val) == 0)))
#else
#define IS_CONST_ZERO(val) \
- (!LLVMIsUndef(val) && LLVMIsConstant(val) \
+ (LLVMIsEfficientConstInt(val) \
&& ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \
|| (!is_i32 && (int64)LLVMConstIntGetSExtValue(val) == 0)))
#endif
@@ -473,7 +473,7 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
}
- if (LLVMIsConstant(right)) {
+ if (LLVMIsEfficientConstInt(right)) {
int64 right_val = (int64)LLVMConstIntGetSExtValue(right);
switch (right_val) {
case 0:
@@ -728,9 +728,7 @@ compile_int_shl(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right,
{
LLVMValueRef res;
- if (strcmp(comp_ctx->target_arch, "x86_64") != 0
- && strcmp(comp_ctx->target_arch, "i386") != 0)
- SHIFT_COUNT_MASK;
+ SHIFT_COUNT_MASK;
/* Build shl */
LLVM_BUILD_OP(Shl, left, right, res, "shl", NULL);
@@ -744,9 +742,7 @@ compile_int_shr_s(AOTCompContext *comp_ctx, LLVMValueRef left,
{
LLVMValueRef res;
- if (strcmp(comp_ctx->target_arch, "x86_64") != 0
- && strcmp(comp_ctx->target_arch, "i386") != 0)
- SHIFT_COUNT_MASK;
+ SHIFT_COUNT_MASK;
/* Build shl */
LLVM_BUILD_OP(AShr, left, right, res, "shr_s", NULL);
@@ -760,9 +756,7 @@ compile_int_shr_u(AOTCompContext *comp_ctx, LLVMValueRef left,
{
LLVMValueRef res;
- if (strcmp(comp_ctx->target_arch, "x86_64") != 0
- && strcmp(comp_ctx->target_arch, "i386") != 0)
- SHIFT_COUNT_MASK;
+ SHIFT_COUNT_MASK;
/* Build shl */
LLVM_BUILD_OP(LShr, left, right, res, "shr_u", NULL);
@@ -783,17 +777,25 @@ compile_int_rot(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right,
if (IS_CONST_ZERO(right))
return left;
- /* Calculate (bits - shif_count) */
+ /* Calculate (bits - shift_count) */
LLVM_BUILD_OP(Sub, is_i32 ? I32_32 : I64_64, right, bits_minus_shift_count,
"bits_minus_shift_count", NULL);
+ /* Calculate (bits - shift_count) & mask */
+ bits_minus_shift_count =
+ LLVMBuildAnd(comp_ctx->builder, bits_minus_shift_count,
+ is_i32 ? I32_31 : I64_63, "bits_minus_shift_count_and");
+ if (!bits_minus_shift_count) {
+ aot_set_last_error("llvm build and failed.");
+ return NULL;
+ }
if (is_rotl) {
- /* left<>(BITS-count) */
+ /* (left << count) | (left >> ((BITS - count) & mask)) */
LLVM_BUILD_OP(Shl, left, right, tmp_l, "tmp_l", NULL);
LLVM_BUILD_OP(LShr, left, bits_minus_shift_count, tmp_r, "tmp_r", NULL);
}
else {
- /* left>>count | left<<(BITS-count) */
+ /* (left >> count) | (left << ((BITS - count) & mask)) */
LLVM_BUILD_OP(LShr, left, right, tmp_l, "tmp_l", NULL);
LLVM_BUILD_OP(Shl, left, bits_minus_shift_count, tmp_r, "tmp_r", NULL);
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.c
index 70487d4dedb..31d803553a4 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.c
@@ -112,7 +112,7 @@ static bool
compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 global_idx, bool is_set, bool is_aux_stack)
{
- AOTCompData *comp_data = comp_ctx->comp_data;
+ const AOTCompData *comp_data = comp_ctx->comp_data;
uint32 import_global_count = comp_data->import_global_count;
uint32 global_base_offset;
uint32 global_offset;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.c
similarity index 74%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.c
index dc3fe7f5959..bbf16f55c49 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.c
@@ -7,6 +7,7 @@
#include "aot_llvm_extra2.h"
#include "aot_compiler.h"
#include "aot_emit_exception.h"
+#include "aot_emit_table.h"
#include "../aot/aot_runtime.h"
#include "../aot/aot_intrinsic.h"
@@ -14,8 +15,17 @@
#include "debug/dwarf_extractor.h"
#endif
+static bool
+create_native_symbol(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
+static bool
+create_native_stack_bound(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx);
+static bool
+create_native_stack_top_min(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx);
+
LLVMTypeRef
-wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type)
+wasm_type_to_llvm_type(const AOTLLVMTypes *llvm_types, uint8 wasm_type)
{
switch (wasm_type) {
case VALUE_TYPE_I32:
@@ -38,17 +48,533 @@ wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type)
return NULL;
}
+static LLVMValueRef
+aot_add_llvm_func1(const AOTCompContext *comp_ctx, LLVMModuleRef module,
+ uint32 func_index, uint32 param_count, LLVMTypeRef func_type,
+ const char *prefix)
+{
+ char func_name[48];
+ LLVMValueRef func;
+ LLVMValueRef local_value;
+ uint32 i, j;
+
+ /* Add LLVM function */
+ snprintf(func_name, sizeof(func_name), "%s%d", prefix, func_index);
+ if (!(func = LLVMAddFunction(module, func_name, func_type))) {
+ aot_set_last_error("add LLVM function failed.");
+ return NULL;
+ }
+
+ j = 0;
+ local_value = LLVMGetParam(func, j++);
+ LLVMSetValueName(local_value, "exec_env");
+
+ /* Set parameter names */
+ for (i = 0; i < param_count; i++) {
+ local_value = LLVMGetParam(func, j++);
+ LLVMSetValueName(local_value, "");
+ }
+
+ return func;
+}
+
+/*
+ * create a basic func_ctx enough to call aot_emit_exception.
+ *
+ * that is:
+ * - exec_env
+ * - aot_inst
+ * - native_symbol (if is_indirect_mode)
+ */
+static bool
+create_basic_func_context(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx)
+{
+ LLVMValueRef aot_inst_offset = I32_TWO, aot_inst_addr;
+
+ /* Save the pameters for fast access */
+ func_ctx->exec_env = LLVMGetParam(func_ctx->func, 0);
+
+ /* Get aot inst address, the layout of exec_env is:
+ exec_env->next, exec_env->prev, exec_env->module_inst, and argv_buf */
+ if (!(aot_inst_addr = LLVMBuildInBoundsGEP2(
+ comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
+ &aot_inst_offset, 1, "aot_inst_addr"))) {
+ aot_set_last_error("llvm build in bounds gep failed");
+ goto fail;
+ }
+
+ /* Load aot inst */
+ if (!(func_ctx->aot_inst = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
+ aot_inst_addr, "aot_inst"))) {
+ aot_set_last_error("llvm build load failed");
+ goto fail;
+ }
+
+ if (comp_ctx->is_indirect_mode
+ && !create_native_symbol(comp_ctx, func_ctx)) {
+ goto fail;
+ }
+
+ return true;
+fail:
+ return false;
+}
+
+/*
+ * return if the "precheck" wrapper function can use tail call optimization
+ */
+bool
+aot_target_precheck_can_use_musttail(const AOTCompContext *comp_ctx)
+{
+ if (!strcmp(comp_ctx->target_arch, "xtensa")) {
+ /*
+ * xtensa windowed ABI doesn't have tail call optimization.
+ *
+ * Note: as of writing this, the xtensa version of LLVM
+ * simply ignores the musttail attribute.
+ * https://github.com/espressif/llvm-project/pull/73
+ */
+ return false;
+ }
+ if (!strcmp(comp_ctx->target_arch, "riscv32")
+ || !strcmp(comp_ctx->target_arch, "riscv64")) {
+ /*
+ * REVISIT: actually, riscv can use tail call optimization
+ * in some cases. I (yamamoto) don't know the exact conditions
+ * though.
+ */
+ return false;
+ }
+ if (!strcmp(comp_ctx->target_arch, "mips")) {
+ /*
+ * cf.
+ * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2412
+ */
+ return false;
+ }
+ if (strstr(comp_ctx->target_arch, "thumb")) {
+ /*
+ * cf.
+ * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2412
+ */
+ return false;
+ }
+ /*
+ * x86-64/i386: true
+ *
+ * others: assume true for now
+ */
+ return true;
+}
+
+unsigned int
+aot_estimate_stack_usage_for_function_call(const AOTCompContext *comp_ctx,
+ const AOTFuncType *callee_func_type)
+{
+ /*
+ * Estimate how much stack is necessary to make a function call.
+ * This does not include the stack consumption of the callee function.
+ *
+ * For precise estimation, ideally this function needs to be
+ * target-specific.
+ * However, this implementation aims to be target-independent,
+ * allowing a small overstimation, which is probably ok for our purpose.
+ * (overflow detection and memory profiling)
+ * On the other hand, an underestimation should be avoided as it
+ * can cause more serious problems like silent data corruptions.
+ *
+ * Assumptions:
+ *
+ * - the first result is returned via a register.
+ *
+ * - all parameters, including exec_env and pointers to non-first
+ * results, are passed via stack.
+ * (this is a bit pessimistic than many of real calling conventions,
+ * where some of parameters are passed via register.)
+ *
+ * - N-byte value needs N-byte alignment on stack.
+ *
+ * - a value smaller than a pointer is extended.
+ * (eg. 4 byte values are extended to 8 byte on x86-64.)
+ */
+
+ const unsigned int param_count = callee_func_type->param_count;
+ const unsigned int result_count = callee_func_type->result_count;
+ unsigned int size = 0;
+ unsigned int i;
+ unsigned int nb;
+
+ if (!strcmp(comp_ctx->target_arch, "xtensa")) {
+ /*
+ * In the xtensa windowed ABI, outgoing arguments are already
+ * included in the callee's stack frame size, which equals to
+ * the operand of the ENTRY instruction and what LLVM
+ * MFI->getStackSize returns.
+ */
+ return 0;
+ }
+
+ /* exec_env */
+ size = comp_ctx->pointer_size;
+
+ /* parameters */
+ for (i = 0; i < param_count; i++) {
+ nb = wasm_value_type_cell_num(callee_func_type->types[i]) * 4;
+ if (nb < comp_ctx->pointer_size) {
+ nb = comp_ctx->pointer_size;
+ }
+ size = align_uint(size, nb) + nb;
+ }
+
+ /* pointers to results */
+ nb = comp_ctx->pointer_size;
+ for (i = 1; i < result_count; i++) {
+ size = align_uint(size, nb) + nb;
+ }
+
+ /* return address */
+ nb = comp_ctx->pointer_size;
+ size = align_uint(size, nb) + nb;
+
+ /*
+ * some extra for possible arch-dependent things like
+ * 16-byte alignment for x86_64.
+ */
+ size += 16;
+ return size;
+}
+
+static uint32
+get_inst_extra_offset(AOTCompContext *comp_ctx)
+{
+ const AOTCompData *comp_data = comp_ctx->comp_data;
+ uint32 table_count = comp_data->import_table_count + comp_data->table_count;
+ uint64 offset = get_tbl_inst_offset(comp_ctx, NULL, table_count);
+ uint32 offset_32 = (uint32)offset;
+ bh_assert(offset <= UINT32_MAX);
+ offset_32 = align_uint((uint32)offset_32, 8);
+ return offset_32;
+}
+
+/*
+ * a "precheck" function performs a few things before calling wrapped_func.
+ *
+ * - update native_stack_top_min if necessary
+ * - stack overflow check (if it does, trap)
+ */
+static LLVMValueRef
+aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
+ uint32 func_index, uint32 orig_param_count,
+ LLVMTypeRef func_type, LLVMValueRef wrapped_func)
+{
+ LLVMValueRef precheck_func;
+ LLVMBasicBlockRef begin = NULL;
+ LLVMBasicBlockRef check_top_block = NULL;
+ LLVMBasicBlockRef update_top_block = NULL;
+ LLVMBasicBlockRef stack_bound_check_block = NULL;
+ LLVMBasicBlockRef call_wrapped_func_block = NULL;
+ LLVMValueRef *params = NULL;
+
+ precheck_func =
+ aot_add_llvm_func1(comp_ctx, module, func_index, orig_param_count,
+ func_type, AOT_FUNC_PREFIX);
+ if (!precheck_func) {
+ goto fail;
+ }
+ begin = LLVMAppendBasicBlockInContext(comp_ctx->context, precheck_func,
+ "begin");
+ check_top_block = LLVMAppendBasicBlockInContext(
+ comp_ctx->context, precheck_func, "check_top_block");
+ if (comp_ctx->enable_stack_estimation) {
+ update_top_block = LLVMAppendBasicBlockInContext(
+ comp_ctx->context, precheck_func, "update_top_block");
+ if (!update_top_block) {
+ goto fail;
+ }
+ }
+ stack_bound_check_block = LLVMAppendBasicBlockInContext(
+ comp_ctx->context, precheck_func, "stack_bound_check_block");
+ call_wrapped_func_block = LLVMAppendBasicBlockInContext(
+ comp_ctx->context, precheck_func, "call_wrapped_func");
+ if (!begin || !check_top_block || !stack_bound_check_block
+ || !call_wrapped_func_block) {
+ goto fail;
+ }
+ LLVMBuilderRef b = comp_ctx->builder;
+ LLVMPositionBuilderAtEnd(b, begin);
+
+ /* create a temporary minimum func_ctx */
+ AOTFuncContext tmp;
+ AOTFuncContext *func_ctx = &tmp;
+ memset(func_ctx, 0, sizeof(*func_ctx));
+ func_ctx->func = precheck_func;
+ func_ctx->module = module;
+ func_ctx->aot_func = comp_ctx->comp_data->funcs[func_index];
+#if WASM_ENABLE_DEBUG_AOT != 0
+ func_ctx->debug_func = NULL;
+#endif
+ if (!create_basic_func_context(comp_ctx, func_ctx))
+ goto fail;
+ if (comp_ctx->enable_stack_bound_check
+ && !create_native_stack_bound(comp_ctx, func_ctx))
+ goto fail;
+ if (comp_ctx->enable_stack_estimation
+ && !create_native_stack_top_min(comp_ctx, func_ctx)) {
+ goto fail;
+ }
+
+ uint32 param_count = LLVMCountParams(precheck_func);
+ uint32 sz = param_count * (uint32)sizeof(LLVMValueRef);
+ params = wasm_runtime_malloc(sz);
+ if (params == NULL) {
+ goto fail;
+ }
+ LLVMGetParams(precheck_func, params);
+
+ const bool is_64bit = comp_ctx->pointer_size == sizeof(uint64);
+ LLVMTypeRef uintptr_type;
+ if (is_64bit)
+ uintptr_type = I64_TYPE;
+ else
+ uintptr_type = I32_TYPE;
+
+ /*
+ * load the stack pointer
+ */
+ LLVMValueRef sp_ptr = LLVMBuildAlloca(b, I32_TYPE, "sp_ptr");
+ if (!sp_ptr) {
+ goto fail;
+ }
+ LLVMValueRef sp = LLVMBuildPtrToInt(b, sp_ptr, uintptr_type, "sp");
+ if (!sp) {
+ goto fail;
+ }
+
+ /*
+ * load the value for this wrapped function from the stack_sizes array
+ */
+ LLVMValueRef stack_sizes;
+ if (comp_ctx->is_indirect_mode) {
+ uint32 offset_u32;
+ LLVMValueRef offset;
+ LLVMValueRef stack_sizes_p;
+
+ offset_u32 = get_inst_extra_offset(comp_ctx);
+ offset_u32 += offsetof(AOTModuleInstanceExtra, stack_sizes);
+ offset = I32_CONST(offset_u32);
+ if (!offset) {
+ goto fail;
+ }
+ stack_sizes_p =
+ LLVMBuildInBoundsGEP2(b, INT8_TYPE, func_ctx->aot_inst, &offset, 1,
+ "aot_inst_stack_sizes_p");
+ if (!stack_sizes_p) {
+ goto fail;
+ }
+ stack_sizes =
+ LLVMBuildLoad2(b, INT32_PTR_TYPE, stack_sizes_p, "stack_sizes");
+ if (!stack_sizes) {
+ goto fail;
+ }
+ }
+ else {
+ stack_sizes = comp_ctx->stack_sizes;
+ }
+ LLVMValueRef func_index_const = I32_CONST(func_index);
+ LLVMValueRef sizes =
+ LLVMBuildBitCast(b, stack_sizes, INT32_PTR_TYPE, "sizes");
+ if (!sizes) {
+ goto fail;
+ }
+ LLVMValueRef sizep = LLVMBuildInBoundsGEP2(b, I32_TYPE, sizes,
+ &func_index_const, 1, "sizep");
+ if (!sizep) {
+ goto fail;
+ }
+ LLVMValueRef size32 = LLVMBuildLoad2(b, I32_TYPE, sizep, "size32");
+ if (!size32) {
+ goto fail;
+ }
+ LLVMValueRef size;
+ if (is_64bit) {
+ size = LLVMBuildZExt(b, size32, uintptr_type, "size");
+ if (!size) {
+ goto fail;
+ }
+ }
+ else {
+ size = size32;
+ }
+ /*
+ * calculate new sp
+ */
+ LLVMValueRef underflow =
+ LLVMBuildICmp(b, LLVMIntULT, sp, size, "underflow");
+ if (!underflow) {
+ goto fail;
+ }
+ LLVMValueRef new_sp = LLVMBuildSub(b, sp, size, "new_sp");
+ if (!new_sp) {
+ goto fail;
+ }
+ if (!LLVMBuildBr(b, check_top_block)) {
+ goto fail;
+ }
+
+ LLVMPositionBuilderAtEnd(b, check_top_block);
+ if (comp_ctx->enable_stack_estimation) {
+ /*
+ * load native_stack_top_min from the exec_env
+ */
+ LLVMValueRef top_min =
+ LLVMBuildLoad2(b, OPQ_PTR_TYPE, func_ctx->native_stack_top_min_addr,
+ "native_stack_top_min");
+ if (!top_min) {
+ goto fail;
+ }
+ LLVMValueRef top_min_int = LLVMBuildPtrToInt(
+ b, top_min, uintptr_type, "native_stack_top_min_int");
+ if (!top_min_int) {
+ goto fail;
+ }
+
+ bh_assert(update_top_block);
+
+ /*
+ * update native_stack_top_min if
+ * new_sp = sp - size < native_stack_top_min
+ *
+ * Note: unless the stack has already overflown in this exec_env,
+ * native_stack_bound <= native_stack_top_min
+ */
+ LLVMValueRef cmp_top =
+ LLVMBuildICmp(b, LLVMIntULT, new_sp, top_min_int, "cmp_top");
+ if (!cmp_top) {
+ goto fail;
+ }
+ cmp_top = LLVMBuildOr(b, underflow, cmp_top, "cmp_top2");
+ if (!cmp_top) {
+ goto fail;
+ }
+ if (!LLVMBuildCondBr(b, cmp_top, update_top_block,
+ call_wrapped_func_block)) {
+ aot_set_last_error("llvm build cond br failed.");
+ goto fail;
+ }
+
+ /*
+ * update native_stack_top_min
+ */
+ LLVMPositionBuilderAtEnd(b, update_top_block);
+ LLVMValueRef new_sp_ptr =
+ LLVMBuildIntToPtr(b, new_sp, INT8_PTR_TYPE, "new_sp_ptr");
+ if (!new_sp_ptr) {
+ goto fail;
+ }
+ if (!LLVMBuildStore(b, new_sp_ptr,
+ func_ctx->native_stack_top_min_addr)) {
+ goto fail;
+ }
+ if (!LLVMBuildBr(b, stack_bound_check_block)) {
+ goto fail;
+ }
+ }
+ else {
+ if (!LLVMBuildBr(b, stack_bound_check_block)) {
+ goto fail;
+ }
+ }
+
+ LLVMPositionBuilderAtEnd(b, stack_bound_check_block);
+ if (comp_ctx->enable_stack_bound_check) {
+ /*
+ * trap if new_sp < native_stack_bound
+ */
+ LLVMValueRef bound_int = LLVMBuildPtrToInt(
+ b, func_ctx->native_stack_bound, uintptr_type, "bound_base_int");
+ if (!bound_int) {
+ goto fail;
+ }
+ LLVMValueRef cmp =
+ LLVMBuildICmp(b, LLVMIntULT, new_sp, bound_int, "cmp");
+ if (!cmp) {
+ goto fail;
+ }
+ cmp = LLVMBuildOr(b, underflow, cmp, "cmp2");
+ if (!cmp) {
+ goto fail;
+ }
+ /* todo: @llvm.expect.i1(i1 %cmp, i1 0) */
+ if (!aot_emit_exception(comp_ctx, func_ctx, EXCE_NATIVE_STACK_OVERFLOW,
+ true, cmp, call_wrapped_func_block))
+ goto fail;
+ }
+ else {
+ if (!LLVMBuildBr(b, call_wrapped_func_block)) {
+ goto fail;
+ }
+ }
+
+ /*
+ * call the wrapped function
+ * use a tail-call if possible
+ */
+ LLVMPositionBuilderAtEnd(b, call_wrapped_func_block);
+ const char *name = "tail_call";
+ LLVMTypeRef ret_type = LLVMGetReturnType(func_type);
+ if (ret_type == VOID_TYPE) {
+ name = "";
+ }
+ LLVMValueRef retval =
+ LLVMBuildCall2(b, func_type, wrapped_func, params, param_count, name);
+ if (!retval) {
+ goto fail;
+ }
+ wasm_runtime_free(params);
+ params = NULL;
+
+#if LLVM_VERSION_MAJOR < 17
+ if (aot_target_precheck_can_use_musttail(comp_ctx)) {
+ LLVMSetTailCallKind(retval, LLVMTailCallKindMustTail);
+ }
+ else {
+ LLVMSetTailCallKind(retval, LLVMTailCallKindTail);
+ }
+#else
+ LLVMSetTailCall(retval, true);
+#endif
+
+ if (ret_type == VOID_TYPE) {
+ if (!LLVMBuildRetVoid(b)) {
+ goto fail;
+ }
+ }
+ else {
+ if (!LLVMBuildRet(b, retval)) {
+ goto fail;
+ }
+ }
+
+ return precheck_func;
+fail:
+ if (params != NULL) {
+ wasm_runtime_free(params);
+ }
+ aot_set_last_error("failed to build precheck wrapper function.");
+ return NULL;
+}
+
/**
* Add LLVM function
*/
static LLVMValueRef
aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
- AOTFuncType *aot_func_type, uint32 func_index,
- LLVMTypeRef *p_func_type)
+ const AOTFuncType *aot_func_type, uint32 func_index,
+ LLVMTypeRef *p_func_type, LLVMValueRef *p_precheck_func)
{
LLVMValueRef func = NULL;
LLVMTypeRef *param_types, ret_type, func_type;
- LLVMValueRef local_value;
LLVMTypeRef func_type_wrapper;
LLVMValueRef func_wrapper;
LLVMBasicBlockRef func_begin;
@@ -101,21 +627,67 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
goto fail;
}
- /* Add LLVM function */
- snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, func_index);
- if (!(func = LLVMAddFunction(module, func_name, func_type))) {
- aot_set_last_error("add LLVM function failed.");
+ bh_assert(func_index < comp_ctx->func_ctx_count);
+ bh_assert(LLVMGetReturnType(func_type) == ret_type);
+ const char *prefix = AOT_FUNC_PREFIX;
+ const bool need_precheck =
+ comp_ctx->enable_stack_bound_check || comp_ctx->enable_stack_estimation;
+ if (need_precheck) {
+ /*
+ * REVISIT: probably this breaks windows hw bound check
+ * (the RtlAddFunctionTable stuff)
+ */
+ prefix = AOT_FUNC_INTERNAL_PREFIX;
+ }
+ if (!(func = aot_add_llvm_func1(comp_ctx, module, func_index,
+ aot_func_type->param_count, func_type,
+ prefix)))
goto fail;
+
+ if (comp_ctx->is_indirect_mode) {
+ /* avoid LUT relocations ("switch-table") */
+ LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute(
+ comp_ctx->context, "no-jump-tables",
+ (uint32)strlen("no-jump-tables"), "true", (uint32)strlen("true"));
+ LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex,
+ attr_no_jump_tables);
+ }
+
+ /* spread fp.all to every function */
+ if (comp_ctx->emit_frame_pointer) {
+ const char *key = "frame-pointer";
+ const char *val = "all";
+ LLVMAttributeRef no_omit_fp = LLVMCreateStringAttribute(
+ comp_ctx->context, key, (unsigned)strlen(key), val,
+ (unsigned)strlen(val));
+ if (!no_omit_fp) {
+ aot_set_last_error("create LLVM attribute (frame-pointer) failed.");
+ goto fail;
+ }
+ LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, no_omit_fp);
}
- j = 0;
- local_value = LLVMGetParam(func, j++);
- LLVMSetValueName(local_value, "exec_env");
+ if (need_precheck) {
+ if (!comp_ctx->is_jit_mode)
+ LLVMSetLinkage(func, LLVMInternalLinkage);
+ unsigned int kind =
+ LLVMGetEnumAttributeKindForName("noinline", strlen("noinline"));
+ LLVMAttributeRef attr_noinline =
+ LLVMCreateEnumAttribute(comp_ctx->context, kind, 0);
+ LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex,
+ attr_noinline);
- /* Set parameter names */
- for (i = 0; i < aot_func_type->param_count; i++) {
- local_value = LLVMGetParam(func, j++);
- LLVMSetValueName(local_value, "");
+ LLVMValueRef precheck_func = aot_add_precheck_function(
+ comp_ctx, module, func_index, aot_func_type->param_count, func_type,
+ func);
+ if (!precheck_func)
+ goto fail;
+ LLVMAddAttributeAtIndex(precheck_func, LLVMAttributeFunctionIndex,
+ attr_noinline);
+ *p_precheck_func = precheck_func;
+ }
+ else {
+ *p_precheck_func = func;
}
if (p_func_type)
@@ -177,8 +749,9 @@ free_block_memory(AOTBlock *block)
* Create first AOTBlock, or function block for the function
*/
static AOTBlock *
-aot_create_func_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- AOTFunc *func, AOTFuncType *aot_func_type)
+aot_create_func_block(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx, const AOTFunc *func,
+ const AOTFuncType *aot_func_type)
{
AOTBlock *aot_block;
uint32 param_count = aot_func_type->param_count,
@@ -266,7 +839,8 @@ create_argv_buf(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_native_stack_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_native_stack_bound(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx)
{
LLVMValueRef stack_bound_offset = I32_FOUR, stack_bound_addr;
@@ -288,7 +862,8 @@ create_native_stack_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_native_stack_top_min(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_native_stack_top_min(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx)
{
LLVMValueRef offset = I32_NINE;
@@ -303,7 +878,7 @@ create_native_stack_top_min(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_aux_stack_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_aux_stack_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
{
LLVMValueRef aux_stack_bound_offset = I32_SIX, aux_stack_bound_addr;
LLVMValueRef aux_stack_bottom_offset = I32_SEVEN, aux_stack_bottom_addr;
@@ -355,7 +930,7 @@ create_aux_stack_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_native_symbol(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_native_symbol(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
{
LLVMValueRef native_symbol_offset = I32_EIGHT, native_symbol_addr;
@@ -384,8 +959,9 @@ create_native_symbol(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_local_variables(AOTCompData *comp_data, AOTCompContext *comp_ctx,
- AOTFuncContext *func_ctx, AOTFunc *func)
+create_local_variables(const AOTCompData *comp_data,
+ const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
+ const AOTFunc *func)
{
AOTFuncType *aot_func_type = comp_data->func_types[func->func_type_index];
char local_name[32];
@@ -450,32 +1026,11 @@ create_local_variables(AOTCompData *comp_data, AOTCompContext *comp_ctx,
}
}
- if (comp_ctx->enable_stack_bound_check
- || comp_ctx->enable_stack_estimation) {
- if (aot_func_type->param_count + func->local_count > 0) {
- func_ctx->last_alloca = func_ctx->locals[aot_func_type->param_count
- + func->local_count - 1];
- if (!(func_ctx->last_alloca =
- LLVMBuildBitCast(comp_ctx->builder, func_ctx->last_alloca,
- INT8_PTR_TYPE, "stack_ptr"))) {
- aot_set_last_error("llvm build bit cast failed.");
- return false;
- }
- }
- else {
- if (!(func_ctx->last_alloca = LLVMBuildAlloca(
- comp_ctx->builder, INT8_TYPE, "stack_ptr"))) {
- aot_set_last_error("llvm build alloca failed.");
- return false;
- }
- }
- }
-
return true;
}
static bool
-create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
+create_memory_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMTypeRef int8_ptr_type, uint32 func_index)
{
LLVMValueRef offset, mem_info_base;
@@ -807,7 +1362,7 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
static bool
-create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_cur_exception(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
{
LLVMValueRef offset;
@@ -823,7 +1378,8 @@ create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_func_type_indexes(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_func_type_indexes(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx)
{
LLVMValueRef offset, func_type_indexes_ptr;
LLVMTypeRef int32_ptr_type;
@@ -861,7 +1417,7 @@ create_func_type_indexes(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
static bool
-create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+create_func_ptrs(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
{
LLVMValueRef offset;
@@ -899,11 +1455,95 @@ create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
return true;
}
+const char *aot_stack_sizes_name = AOT_STACK_SIZES_NAME;
+const char *aot_stack_sizes_alias_name = AOT_STACK_SIZES_ALIAS_NAME;
+const char *aot_stack_sizes_section_name = AOT_STACK_SIZES_SECTION_NAME;
+
+static bool
+aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx)
+{
+ LLVMValueRef stack_sizes, *values, array, alias;
+ LLVMTypeRef stack_sizes_type;
+#if LLVM_VERSION_MAJOR <= 13
+ LLVMTypeRef alias_type;
+#endif
+ uint64 size;
+ uint32 i;
+
+ stack_sizes_type = LLVMArrayType(I32_TYPE, comp_data->func_count);
+ if (!stack_sizes_type) {
+ aot_set_last_error("failed to create stack_sizes type.");
+ return false;
+ }
+
+ stack_sizes =
+ LLVMAddGlobal(comp_ctx->module, stack_sizes_type, aot_stack_sizes_name);
+ if (!stack_sizes) {
+ aot_set_last_error("failed to create stack_sizes global.");
+ return false;
+ }
+
+ size = sizeof(LLVMValueRef) * comp_data->func_count;
+ if (size >= UINT32_MAX || !(values = wasm_runtime_malloc((uint32)size))) {
+ aot_set_last_error("allocate memory failed.");
+ return false;
+ }
+
+ for (i = 0; i < comp_data->func_count; i++) {
+ /*
+ * This value is a placeholder, which will be replaced
+ * after the corresponding functions are compiled.
+ *
+ * Don't use zeros becasue LLVM can optimize them to
+ * zeroinitializer.
+ */
+ values[i] = I32_NEG_ONE;
+ }
+
+ array = LLVMConstArray(I32_TYPE, values, comp_data->func_count);
+ wasm_runtime_free(values);
+ if (!array) {
+ aot_set_last_error("failed to create stack_sizes initializer.");
+ return false;
+ }
+ LLVMSetInitializer(stack_sizes, array);
+
+ /*
+ * create an alias so that aot_resolve_stack_sizes can find it.
+ */
+#if LLVM_VERSION_MAJOR > 13
+ alias = LLVMAddAlias2(comp_ctx->module, stack_sizes_type, 0, stack_sizes,
+ aot_stack_sizes_alias_name);
+#else
+ alias_type = LLVMPointerType(stack_sizes_type, 0);
+ if (!alias_type) {
+ aot_set_last_error("failed to create alias type.");
+ return false;
+ }
+ alias = LLVMAddAlias(comp_ctx->module, alias_type, stack_sizes,
+ aot_stack_sizes_alias_name);
+#endif
+ if (!alias) {
+ aot_set_last_error("failed to create stack_sizes alias.");
+ return false;
+ }
+
+ /*
+ * make the original symbol internal. we mainly use this version to
+ * avoid creating extra relocations in the precheck functions.
+ */
+ LLVMSetLinkage(stack_sizes, LLVMInternalLinkage);
+ LLVMSetSection(stack_sizes, aot_stack_sizes_section_name);
+ comp_ctx->stack_sizes_type = stack_sizes_type;
+ comp_ctx->stack_sizes = stack_sizes;
+ return true;
+}
+
/**
* Create function compiler context
*/
static AOTFuncContext *
-aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
+aot_create_func_context(const AOTCompData *comp_data, AOTCompContext *comp_ctx,
AOTFunc *func, uint32 func_index)
{
AOTFuncContext *func_ctx;
@@ -912,7 +1552,6 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
WASMFunction *wasm_func = module->functions[func_index];
AOTBlock *aot_block;
LLVMTypeRef int8_ptr_type;
- LLVMValueRef aot_inst_offset = I32_TWO, aot_inst_addr;
uint64 size;
/* Allocate memory for the function context */
@@ -930,9 +1569,9 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
func_ctx->module = comp_ctx->module;
/* Add LLVM function */
- if (!(func_ctx->func =
- aot_add_llvm_func(comp_ctx, func_ctx->module, aot_func_type,
- func_index, &func_ctx->func_type))) {
+ if (!(func_ctx->func = aot_add_llvm_func(
+ comp_ctx, func_ctx->module, aot_func_type, func_index,
+ &func_ctx->func_type, &func_ctx->precheck_func))) {
goto fail;
}
@@ -951,22 +1590,7 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
/* Add local variables */
LLVMPositionBuilderAtEnd(comp_ctx->builder, aot_block->llvm_entry_block);
- /* Save the pameters for fast access */
- func_ctx->exec_env = LLVMGetParam(func_ctx->func, 0);
-
- /* Get aot inst address, the layout of exec_env is:
- exec_env->next, exec_env->prev, exec_env->module_inst, and argv_buf */
- if (!(aot_inst_addr = LLVMBuildInBoundsGEP2(
- comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
- &aot_inst_offset, 1, "aot_inst_addr"))) {
- aot_set_last_error("llvm build in bounds gep failed");
- goto fail;
- }
-
- /* Load aot inst */
- if (!(func_ctx->aot_inst = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
- aot_inst_addr, "aot_inst"))) {
- aot_set_last_error("llvm build load failed");
+ if (!create_basic_func_context(comp_ctx, func_ctx)) {
goto fail;
}
@@ -975,28 +1599,12 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
goto fail;
}
- /* Get native stack boundary address */
- if (comp_ctx->enable_stack_bound_check
- && !create_native_stack_bound(comp_ctx, func_ctx)) {
- goto fail;
- }
- if (comp_ctx->enable_stack_estimation
- && !create_native_stack_top_min(comp_ctx, func_ctx)) {
- goto fail;
- }
-
/* Get auxiliary stack info */
if (wasm_func->has_op_set_global_aux_stack
&& !create_aux_stack_info(comp_ctx, func_ctx)) {
goto fail;
}
- /* Get native symbol list */
- if (comp_ctx->is_indirect_mode
- && !create_native_symbol(comp_ctx, func_ctx)) {
- goto fail;
- }
-
/* Create local variables */
if (!create_local_variables(comp_data, comp_ctx, func_ctx, func)) {
goto fail;
@@ -1059,12 +1667,17 @@ aot_destroy_func_contexts(AOTFuncContext **func_ctxes, uint32 count)
* Create function compiler contexts
*/
static AOTFuncContext **
-aot_create_func_contexts(AOTCompData *comp_data, AOTCompContext *comp_ctx)
+aot_create_func_contexts(const AOTCompData *comp_data, AOTCompContext *comp_ctx)
{
AOTFuncContext **func_ctxes;
uint64 size;
uint32 i;
+ if ((comp_ctx->enable_stack_bound_check
+ || comp_ctx->enable_stack_estimation)
+ && !aot_create_stack_sizes(comp_data, comp_ctx))
+ return NULL;
+
/* Allocate memory */
size = sizeof(AOTFuncContext *) * (uint64)comp_data->func_count;
if (size >= UINT32_MAX
@@ -1127,6 +1740,28 @@ aot_set_llvm_basic_types(AOTLLVMTypes *basic_types, LLVMContextRef context)
basic_types->v128_type = basic_types->i64x2_vec_type;
basic_types->v128_ptr_type = LLVMPointerType(basic_types->v128_type, 0);
+ basic_types->int8_ptr_type_gs =
+ LLVMPointerType(basic_types->int8_type, 256);
+ basic_types->int16_ptr_type_gs =
+ LLVMPointerType(basic_types->int16_type, 256);
+ basic_types->int32_ptr_type_gs =
+ LLVMPointerType(basic_types->int32_type, 256);
+ basic_types->int64_ptr_type_gs =
+ LLVMPointerType(basic_types->int64_type, 256);
+ basic_types->float32_ptr_type_gs =
+ LLVMPointerType(basic_types->float32_type, 256);
+ basic_types->float64_ptr_type_gs =
+ LLVMPointerType(basic_types->float64_type, 256);
+ basic_types->v128_ptr_type_gs =
+ LLVMPointerType(basic_types->v128_type, 256);
+ if (!basic_types->int8_ptr_type_gs || !basic_types->int16_ptr_type_gs
+ || !basic_types->int32_ptr_type_gs || !basic_types->int64_ptr_type_gs
+ || !basic_types->float32_ptr_type_gs
+ || !basic_types->float64_ptr_type_gs
+ || !basic_types->v128_ptr_type_gs) {
+ return false;
+ }
+
basic_types->i1x2_vec_type = LLVMVectorType(basic_types->int1_type, 2);
basic_types->funcref_type = LLVMInt32TypeInContext(context);
@@ -1301,6 +1936,7 @@ static ArchItem valid_archs[] = {
static const char *valid_abis[] = {
"gnu",
"eabi",
+ "eabihf",
"gnueabihf",
"msvc",
"ilp32",
@@ -1316,13 +1952,33 @@ static void
print_supported_targets()
{
uint32 i;
+ const char *target_name;
+
os_printf("Supported targets:\n");
- for (i = 0; i < sizeof(valid_archs) / sizeof(ArchItem); i++) {
- os_printf("%s ", valid_archs[i].arch);
- if (valid_archs[i].support_eb)
- os_printf("%seb ", valid_archs[i].arch);
+ /* over the list of all available targets */
+ for (LLVMTargetRef target = LLVMGetFirstTarget(); target != NULL;
+ target = LLVMGetNextTarget(target)) {
+ target_name = LLVMGetTargetName(target);
+ /* Skip mipsel, aarch64_be since prefix mips, aarch64 will cover them */
+ if (strcmp(target_name, "mipsel") == 0)
+ continue;
+ else if (strcmp(target_name, "aarch64_be") == 0)
+ continue;
+
+ if (strcmp(target_name, "x86-64") == 0)
+ os_printf(" x86_64\n");
+ else if (strcmp(target_name, "x86") == 0)
+ os_printf(" i386\n");
+ else {
+ for (i = 0; i < sizeof(valid_archs) / sizeof(ArchItem); i++) {
+ /* If target_name is prefix for valid_archs[i].arch */
+ if ((strncmp(target_name, valid_archs[i].arch,
+ strlen(target_name))
+ == 0))
+ os_printf(" %s\n", valid_archs[i].arch);
+ }
+ }
}
- os_printf("\n");
}
static void
@@ -1378,6 +2034,18 @@ get_target_arch_from_triple(const char *triple, char *arch_buf, uint32 buf_size)
bh_assert(*triple == '-' || *triple == '\0');
}
+static bool
+is_baremetal_target(const char *target, const char *cpu, const char *abi)
+{
+ /* TODO: support more baremetal targets */
+ if (target) {
+ /* If target is thumbxxx, then it is baremetal target */
+ if (!strncmp(target, "thumb", strlen("thumb")))
+ return true;
+ }
+ return false;
+}
+
void
aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err)
{
@@ -1456,8 +2124,57 @@ create_target_machine_detect_host(AOTCompContext *comp_ctx)
return ret;
}
+static void
+jit_stack_size_callback(void *user_data, const char *name, size_t namelen,
+ size_t stack_size)
+{
+ AOTCompContext *comp_ctx = user_data;
+ /*
+ * Note: the longest name we care is
+ * something like "aot_func_internal#4294967295".
+ */
+ char buf[64];
+ uint32 func_idx;
+ const AOTFuncContext *func_ctx;
+ bool musttail;
+ unsigned int stack_consumption_to_call_wrapped_func;
+ unsigned int call_size;
+ int ret;
+
+ bh_assert(comp_ctx != NULL);
+ bh_assert(comp_ctx->jit_stack_sizes != NULL);
+
+ if (namelen >= sizeof(buf)) {
+ LOG_DEBUG("too long name: %.*s", (int)namelen, name);
+ return;
+ }
+ /* ensure NUL termination */
+ bh_memcpy_s(buf, (uint32)sizeof(buf), name, (uint32)namelen);
+ buf[namelen] = 0;
+
+ ret = sscanf(buf, AOT_FUNC_INTERNAL_PREFIX "%" SCNu32, &func_idx);
+ if (ret != 1) {
+ return;
+ }
+
+ bh_assert(func_idx < comp_ctx->func_ctx_count);
+ func_ctx = comp_ctx->func_ctxes[func_idx];
+ call_size = func_ctx->stack_consumption_for_func_call;
+ musttail = aot_target_precheck_can_use_musttail(comp_ctx);
+ stack_consumption_to_call_wrapped_func =
+ musttail ? 0
+ : aot_estimate_stack_usage_for_function_call(
+ comp_ctx, func_ctx->aot_func->func_type);
+ LOG_VERBOSE("func %.*s stack %u + %zu + %u", (int)namelen, name,
+ stack_consumption_to_call_wrapped_func, stack_size, call_size);
+
+ /* Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes */
+ bh_assert(comp_ctx->jit_stack_sizes[func_idx] == (uint32)-1);
+ comp_ctx->jit_stack_sizes[func_idx] = (uint32)stack_size + call_size;
+}
+
static bool
-orc_jit_create(AOTCompContext *comp_ctx)
+orc_jit_create(AOTCompContext *comp_ctx, bool linux_perf_support)
{
LLVMErrorRef err;
LLVMOrcLLLazyJITRef orc_jit = NULL;
@@ -1471,6 +2188,10 @@ orc_jit_create(AOTCompContext *comp_ctx)
goto fail;
}
+ if (comp_ctx->enable_stack_bound_check || comp_ctx->enable_stack_estimation)
+ LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback(
+ builder, jit_stack_size_callback, comp_ctx);
+
err = LLVMOrcJITTargetMachineBuilderDetectHost(&jtmb);
if (err != LLVMErrorSuccess) {
aot_handle_llvm_errmsg(
@@ -1493,6 +2214,14 @@ orc_jit_create(AOTCompContext *comp_ctx)
/* Ownership transfer: LLVMOrcLLJITBuilderRef -> LLVMOrcLLJITRef */
builder = NULL;
+ if (linux_perf_support) {
+ LOG_DEBUG("Enable linux perf support");
+ LLVMOrcObjectLayerRef obj_linking_layer =
+ (LLVMOrcObjectLayerRef)LLVMOrcLLLazyJITGetObjLinkingLayer(orc_jit);
+ LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(
+ obj_linking_layer, LLVMCreatePerfJITEventListener());
+ }
+
/* Ownership transfer: local -> AOTCompContext */
comp_ctx->orc_jit = orc_jit;
orc_jit = NULL;
@@ -1511,8 +2240,10 @@ bool
aot_compiler_init(void)
{
/* Initialize LLVM environment */
-
+#if LLVM_VERSION_MAJOR < 17
LLVMInitializeCore(LLVMGetGlobalPassRegistry());
+#endif
+
#if WASM_ENABLE_WAMR_COMPILER != 0
/* Init environment of all targets for AOT compiler */
LLVMInitializeAllTargetInfos();
@@ -1536,7 +2267,7 @@ aot_compiler_destroy(void)
}
AOTCompContext *
-aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
+aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
{
AOTCompContext *comp_ctx, *ret = NULL;
LLVMTargetRef target;
@@ -1545,7 +2276,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
char *triple_norm_new = NULL, *cpu_new = NULL;
char *err = NULL, *fp_round = "round.tonearest",
*fp_exce = "fpexcept.strict";
- char triple_buf[32] = { 0 }, features_buf[128] = { 0 };
+ char triple_buf[128] = { 0 }, features_buf[128] = { 0 };
uint32 opt_level, size_level, i;
LLVMCodeModel code_model;
LLVMTargetDataRef target_data_ref;
@@ -1589,6 +2320,17 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
goto fail;
}
+ if (option->linux_perf_support) {
+ /* FramePointerKind.All */
+ LLVMMetadataRef val =
+ LLVMValueAsMetadata(LLVMConstInt(LLVMInt32Type(), 2, false));
+ const char *key = "frame-pointer";
+ LLVMAddModuleFlag(comp_ctx->module, LLVMModuleFlagBehaviorWarning, key,
+ strlen(key), val);
+
+ comp_ctx->emit_frame_pointer = true;
+ }
+
if (BH_LIST_ERROR == bh_list_init(&comp_ctx->native_symbols)) {
goto fail;
}
@@ -1643,9 +2385,21 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
if (option->disable_llvm_lto)
comp_ctx->disable_llvm_lto = true;
+ if (option->enable_llvm_pgo)
+ comp_ctx->enable_llvm_pgo = true;
+
+ if (option->use_prof_file)
+ comp_ctx->use_prof_file = option->use_prof_file;
+
if (option->enable_stack_estimation)
comp_ctx->enable_stack_estimation = true;
+ if (option->llvm_passes)
+ comp_ctx->llvm_passes = option->llvm_passes;
+
+ if (option->builtin_intrinsics)
+ comp_ctx->builtin_intrinsics = option->builtin_intrinsics;
+
comp_ctx->opt_level = option->opt_level;
comp_ctx->size_level = option->size_level;
@@ -1655,14 +2409,6 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
if (option->is_jit_mode) {
comp_ctx->is_jit_mode = true;
- /* Create TargetMachine */
- if (!create_target_machine_detect_host(comp_ctx))
- goto fail;
-
- /* Create LLJIT Instance */
- if (!orc_jit_create(comp_ctx))
- goto fail;
-
#ifndef OS_ENABLE_HW_BOUND_CHECK
comp_ctx->enable_bound_check = true;
/* Always enable stack boundary check if `bounds-checks`
@@ -1682,6 +2428,14 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
comp_ctx->enable_stack_bound_check = false;
#endif
#endif
+
+ /* Create TargetMachine */
+ if (!create_target_machine_detect_host(comp_ctx))
+ goto fail;
+
+ /* Create LLJIT Instance */
+ if (!orc_jit_create(comp_ctx, option->linux_perf_support))
+ goto fail;
}
else {
/* Create LLVM target machine */
@@ -1829,6 +2583,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
* for Windows/MacOS under Linux host, or generating AOT file for
* Linux/MacOS under Windows host.
*/
+
if (!strcmp(abi, "msvc")) {
if (!strcmp(arch1, "i386"))
vendor_sys = "-pc-win32-";
@@ -1836,7 +2591,10 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
vendor_sys = "-pc-windows-";
}
else {
- vendor_sys = "-pc-linux-";
+ if (is_baremetal_target(arch, cpu, abi))
+ vendor_sys = "-unknown-none-";
+ else
+ vendor_sys = "-pc-linux-";
}
bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi)
@@ -1872,6 +2630,11 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
if (!abi)
abi = "msvc";
}
+ else if (is_baremetal_target(arch, cpu, abi)) {
+ vendor_sys = "-unknown-none-";
+ if (!abi)
+ abi = "gnu";
+ }
else {
vendor_sys = "-pc-linux-";
if (!abi)
@@ -1946,13 +2709,14 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
meta_target_abi);
if (!strcmp(abi, "lp64d") || !strcmp(abi, "ilp32d")) {
- if (features) {
+ if (features && !strstr(features, "+d")) {
snprintf(features_buf, sizeof(features_buf), "%s%s",
features, ",+d");
features = features_buf;
}
- else
+ else if (!features) {
features = "+d";
+ }
}
}
@@ -2004,9 +2768,23 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
(option->stack_bounds_checks == 1) ? true : false;
}
+ if ((comp_ctx->enable_stack_bound_check
+ || comp_ctx->enable_stack_estimation)
+ && option->stack_usage_file == NULL) {
+ if (!aot_generate_tempfile_name(
+ "wamrc-su", "su", comp_ctx->stack_usage_temp_file,
+ sizeof(comp_ctx->stack_usage_temp_file)))
+ goto fail;
+ comp_ctx->stack_usage_file = comp_ctx->stack_usage_temp_file;
+ }
+ else {
+ comp_ctx->stack_usage_file = option->stack_usage_file;
+ }
+
os_printf("Create AoT compiler with:\n");
os_printf(" target: %s\n", comp_ctx->target_arch);
os_printf(" target cpu: %s\n", cpu);
+ os_printf(" target triple: %s\n", triple_norm);
os_printf(" cpu features: %s\n", features);
os_printf(" opt level: %d\n", opt_level);
os_printf(" size level: %d\n", size_level);
@@ -2025,6 +2803,8 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
break;
}
+ LLVMSetTarget(comp_ctx->module, triple_norm);
+
if (!LLVMTargetHasTargetMachine(target)) {
snprintf(buf, sizeof(buf),
"no target machine for this target (%s).", triple_norm);
@@ -2059,11 +2839,52 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
if (!(comp_ctx->target_machine = LLVMCreateTargetMachineWithOpts(
target, triple_norm, cpu, features, opt_level,
LLVMRelocStatic, code_model, false,
- option->stack_usage_file))) {
+ comp_ctx->stack_usage_file))) {
aot_set_last_error("create LLVM target machine failed.");
goto fail;
}
+
+ /* If only to create target machine for querying information, early stop
+ */
+ if ((arch && !strcmp(arch, "help")) || (abi && !strcmp(abi, "help"))
+ || (cpu && !strcmp(cpu, "help"))
+ || (features && !strcmp(features, "+help"))) {
+ LOG_DEBUG(
+ "create LLVM target machine only for printing help info.");
+ goto fail;
+ }
+ }
+
+ triple = LLVMGetTargetMachineTriple(comp_ctx->target_machine);
+ if (!triple) {
+ aot_set_last_error("get target machine triple failed.");
+ goto fail;
}
+ if (strstr(triple, "linux") && !strcmp(comp_ctx->target_arch, "x86_64")) {
+ if (option->segue_flags) {
+ if (option->segue_flags & (1 << 0))
+ comp_ctx->enable_segue_i32_load = true;
+ if (option->segue_flags & (1 << 1))
+ comp_ctx->enable_segue_i64_load = true;
+ if (option->segue_flags & (1 << 2))
+ comp_ctx->enable_segue_f32_load = true;
+ if (option->segue_flags & (1 << 3))
+ comp_ctx->enable_segue_f64_load = true;
+ if (option->segue_flags & (1 << 4))
+ comp_ctx->enable_segue_v128_load = true;
+ if (option->segue_flags & (1 << 8))
+ comp_ctx->enable_segue_i32_store = true;
+ if (option->segue_flags & (1 << 9))
+ comp_ctx->enable_segue_i64_store = true;
+ if (option->segue_flags & (1 << 10))
+ comp_ctx->enable_segue_f32_store = true;
+ if (option->segue_flags & (1 << 11))
+ comp_ctx->enable_segue_f64_store = true;
+ if (option->segue_flags & (1 << 12))
+ comp_ctx->enable_segue_v128_store = true;
+ }
+ }
+ LLVMDisposeMessage(triple);
if (option->enable_simd && strcmp(comp_ctx->target_arch, "x86_64") != 0
&& strncmp(comp_ctx->target_arch, "aarch64", 7) != 0) {
@@ -2098,6 +2919,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
aot_set_last_error("create LLVM target data layout failed.");
goto fail;
}
+ LLVMSetModuleDataLayout(comp_ctx->module, target_data_ref);
comp_ctx->pointer_size = LLVMPointerSize(target_data_ref);
LLVMDisposeTargetData(target_data_ref);
@@ -2171,6 +2993,10 @@ aot_destroy_comp_context(AOTCompContext *comp_ctx)
if (!comp_ctx)
return;
+ if (comp_ctx->stack_usage_file == comp_ctx->stack_usage_temp_file) {
+ (void)unlink(comp_ctx->stack_usage_temp_file);
+ }
+
if (comp_ctx->target_machine)
LLVMDisposeTargetMachine(comp_ctx->target_machine);
@@ -2466,8 +3292,8 @@ aot_checked_addr_list_destroy(AOTFuncContext *func_ctx)
}
bool
-aot_build_zero_function_ret(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- AOTFuncType *func_type)
+aot_build_zero_function_ret(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx, AOTFuncType *func_type)
{
LLVMValueRef ret = NULL;
@@ -2506,9 +3332,12 @@ aot_build_zero_function_ret(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return false;
}
#if WASM_ENABLE_DEBUG_AOT != 0
- LLVMMetadataRef return_location =
- dwarf_gen_func_ret_location(comp_ctx, func_ctx);
- LLVMInstructionSetDebugLoc(ret, return_location);
+ /* debug_func is NULL for precheck function */
+ if (func_ctx->debug_func != NULL) {
+ LLVMMetadataRef return_location =
+ dwarf_gen_func_ret_location(comp_ctx, func_ctx);
+ LLVMInstructionSetDebugLoc(ret, return_location);
+ }
#endif
return true;
}
@@ -2768,3 +3597,23 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
(void)const_type;
return const_value;
}
+
+bool
+aot_set_cond_br_weights(AOTCompContext *comp_ctx, LLVMValueRef cond_br,
+ int32 weights_true, int32 weights_false)
+{
+ LLVMMetadataRef md_nodes[3], meta_data;
+ LLVMValueRef meta_data_as_value;
+
+ md_nodes[0] = LLVMMDStringInContext2(comp_ctx->context, "branch_weights",
+ strlen("branch_weights"));
+ md_nodes[1] = LLVMValueAsMetadata(I32_CONST(weights_true));
+ md_nodes[2] = LLVMValueAsMetadata(I32_CONST(weights_false));
+
+ meta_data = LLVMMDNodeInContext2(comp_ctx->context, md_nodes, 3);
+ meta_data_as_value = LLVMMetadataAsValue(comp_ctx->context, meta_data);
+
+ LLVMSetMetadata(cond_br, 2, meta_data_as_value);
+
+ return true;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.h
similarity index 85%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.h
index 2a1564019d7..32d7bbebacd 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.h
@@ -12,18 +12,22 @@
#include "llvm-c/Target.h"
#include "llvm-c/Core.h"
#include "llvm-c/Object.h"
+#include "llvm-c/OrcEE.h"
#include "llvm-c/ExecutionEngine.h"
#include "llvm-c/Analysis.h"
#include "llvm-c/BitWriter.h"
+#if LLVM_VERSION_MAJOR < 17
#include "llvm-c/Transforms/Utils.h"
#include "llvm-c/Transforms/Scalar.h"
#include "llvm-c/Transforms/Vectorize.h"
#include "llvm-c/Transforms/PassManagerBuilder.h"
+#include "llvm-c/Initialization.h"
+#endif
#include "llvm-c/Orc.h"
#include "llvm-c/Error.h"
#include "llvm-c/Support.h"
-#include "llvm-c/Initialization.h"
+
#include "llvm-c/TargetMachine.h"
#include "llvm-c/LLJIT.h"
#if WASM_ENABLE_DEBUG_AOT != 0
@@ -153,9 +157,8 @@ typedef struct AOTMemInfo {
typedef struct AOTFuncContext {
AOTFunc *aot_func;
LLVMValueRef func;
+ LLVMValueRef precheck_func;
LLVMTypeRef func_type;
- /* LLVM module for this function, note that in LAZY JIT mode,
- each aot function belongs to an individual module */
LLVMModuleRef module;
AOTBlockStack block_stack;
@@ -167,7 +170,6 @@ typedef struct AOTFuncContext {
LLVMValueRef aux_stack_bound;
LLVMValueRef aux_stack_bottom;
LLVMValueRef native_symbol;
- LLVMValueRef last_alloca;
LLVMValueRef func_ptrs;
AOTMemInfo *mem_info;
@@ -184,6 +186,9 @@ typedef struct AOTFuncContext {
#if WASM_ENABLE_DEBUG_AOT != 0
LLVMMetadataRef debug_func;
#endif
+
+ unsigned int stack_consumption_for_func_call;
+
LLVMValueRef locals[1];
} AOTFuncContext;
@@ -214,6 +219,14 @@ typedef struct AOTLLVMTypes {
LLVMTypeRef f32x4_vec_type;
LLVMTypeRef f64x2_vec_type;
+ LLVMTypeRef int8_ptr_type_gs;
+ LLVMTypeRef int16_ptr_type_gs;
+ LLVMTypeRef int32_ptr_type_gs;
+ LLVMTypeRef int64_ptr_type_gs;
+ LLVMTypeRef float32_ptr_type_gs;
+ LLVMTypeRef float64_ptr_type_gs;
+ LLVMTypeRef v128_ptr_type_gs;
+
LLVMTypeRef i1x2_vec_type;
LLVMTypeRef meta_data_type;
@@ -275,7 +288,7 @@ typedef struct AOTLLVMConsts {
* Compiler context
*/
typedef struct AOTCompContext {
- AOTCompData *comp_data;
+ const AOTCompData *comp_data;
/* LLVM variables required to emit LLVM IR */
LLVMContextRef context;
@@ -341,6 +354,25 @@ typedef struct AOTCompContext {
/* Disable LLVM link time optimization */
bool disable_llvm_lto;
+ /* Enable LLVM PGO (Profile-Guided Optimization) */
+ bool enable_llvm_pgo;
+
+ /* Use profile file collected by LLVM PGO */
+ char *use_prof_file;
+
+ /* Enable to use segument register as the base addr
+ of linear memory for load/store operations */
+ bool enable_segue_i32_load;
+ bool enable_segue_i64_load;
+ bool enable_segue_f32_load;
+ bool enable_segue_f64_load;
+ bool enable_segue_v128_load;
+ bool enable_segue_i32_store;
+ bool enable_segue_i64_store;
+ bool enable_segue_f32_store;
+ bool enable_segue_f64_store;
+ bool enable_segue_v128_store;
+
/* Whether optimize the JITed code */
bool optimize;
@@ -353,6 +385,11 @@ typedef struct AOTCompContext {
/* LLVM floating-point exception behavior metadata */
LLVMValueRef fp_exception_behavior;
+ /* a global array to store stack sizes */
+ LLVMTypeRef stack_sizes_type;
+ LLVMValueRef stack_sizes;
+ uint32 *jit_stack_sizes; /* for JIT */
+
/* LLVM data types */
AOTLLVMTypes basic_types;
LLVMTypeRef exec_env_type;
@@ -381,6 +418,13 @@ typedef struct AOTCompContext {
* file for some architecture (such as arc) */
const char *external_asm_compiler;
const char *asm_compiler_flags;
+
+ const char *stack_usage_file;
+ char stack_usage_temp_file[64];
+ const char *llvm_passes;
+ const char *builtin_intrinsics;
+
+ bool emit_frame_pointer;
} AOTCompContext;
enum {
@@ -390,6 +434,7 @@ enum {
AOT_LLVMIR_OPT_FILE,
};
+/* always sync it with AOTCompOption in aot_export.h */
typedef struct AOTCompOption {
bool is_jit_mode;
bool is_indirect_mode;
@@ -407,15 +452,21 @@ typedef struct AOTCompOption {
bool enable_aux_stack_frame;
bool disable_llvm_intrinsics;
bool disable_llvm_lto;
+ bool enable_llvm_pgo;
bool enable_stack_estimation;
+ char *use_prof_file;
uint32 opt_level;
uint32 size_level;
uint32 output_format;
uint32 bounds_checks;
uint32 stack_bounds_checks;
+ uint32 segue_flags;
+ bool linux_perf_support;
char **custom_sections;
uint32 custom_sections_count;
const char *stack_usage_file;
+ const char *llvm_passes;
+ const char *builtin_intrinsics;
} AOTCompOption, *aot_comp_option_t;
bool
@@ -425,7 +476,7 @@ void
aot_compiler_destroy(void);
AOTCompContext *
-aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option);
+aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option);
void
aot_destroy_comp_context(AOTCompContext *comp_ctx);
@@ -464,7 +515,7 @@ void
aot_block_destroy(AOTBlock *block);
LLVMTypeRef
-wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type);
+wasm_type_to_llvm_type(const AOTLLVMTypes *llvm_types, uint8 wasm_type);
bool
aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx,
@@ -481,8 +532,8 @@ void
aot_checked_addr_list_destroy(AOTFuncContext *func_ctx);
bool
-aot_build_zero_function_ret(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- AOTFuncType *func_type);
+aot_build_zero_function_ret(const AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx, AOTFuncType *func_type);
LLVMValueRef
aot_call_llvm_intrinsic(const AOTCompContext *comp_ctx,
@@ -519,6 +570,20 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module);
void
aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err);
+char *
+aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size);
+
+bool
+aot_set_cond_br_weights(AOTCompContext *comp_ctx, LLVMValueRef cond_br,
+ int32 weights_true, int32 weights_false);
+
+bool
+aot_target_precheck_can_use_musttail(const AOTCompContext *comp_ctx);
+
+unsigned int
+aot_estimate_stack_usage_for_function_call(const AOTCompContext *comp_ctx,
+ const AOTFuncType *callee_func_type);
+
#ifdef __cplusplus
} /* end of extern "C" */
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra.cpp
similarity index 52%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra.cpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra.cpp
index 9b77f5e6a1e..ed0205c3c93 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra.cpp
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra.cpp
@@ -5,9 +5,13 @@
#include
#include
+#if LLVM_VERSION_MAJOR < 17
+#include
+#include
+#include
+#endif
#include
#include
-#include
#include
#include
#include
@@ -16,7 +20,9 @@
#include
#include
#include
+#if LLVM_VERSION_MAJOR < 17
#include
+#endif
#include
#include
#include
@@ -25,9 +31,13 @@
#include
#include
#include
-#include
+#include
#include
#include
+#if LLVM_VERSION_MAJOR >= 17
+#include
+#include
+#endif
#include
#include
#include
@@ -44,6 +54,7 @@
#if LLVM_VERSION_MAJOR >= 12
#include
#endif
+#include
#include
#include "../aot/aot_runtime.h"
@@ -52,6 +63,13 @@
using namespace llvm;
using namespace llvm::orc;
+#if LLVM_VERSION_MAJOR >= 17
+namespace llvm {
+template
+using Optional = std::optional;
+}
+#endif
+
LLVM_C_EXTERN_C_BEGIN
bool
@@ -70,115 +88,63 @@ LLVM_C_EXTERN_C_END
ExitOnError ExitOnErr;
-class ExpandMemoryOpPass : public llvm::ModulePass
+class ExpandMemoryOpPass : public PassInfoMixin
{
public:
- static char ID;
-
- ExpandMemoryOpPass()
- : ModulePass(ID)
- {}
-
- bool runOnModule(Module &M) override;
-
- bool expandMemIntrinsicUses(Function &F);
- StringRef getPassName() const override
- {
- return "Expand memory operation intrinsics";
- }
-
- void getAnalysisUsage(AnalysisUsage &AU) const override
- {
- AU.addRequired();
- }
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
-char ExpandMemoryOpPass::ID = 0;
-
-bool
-ExpandMemoryOpPass::expandMemIntrinsicUses(Function &F)
+PreservedAnalyses
+ExpandMemoryOpPass::run(Function &F, FunctionAnalysisManager &AM)
{
- Intrinsic::ID ID = F.getIntrinsicID();
- bool Changed = false;
-
- for (auto I = F.user_begin(), E = F.user_end(); I != E;) {
- Instruction *Inst = cast(*I);
- ++I;
-
- switch (ID) {
- case Intrinsic::memcpy:
- {
- auto *Memcpy = cast(Inst);
- Function *ParentFunc = Memcpy->getParent()->getParent();
- const TargetTransformInfo &TTI =
- getAnalysis().getTTI(
- *ParentFunc);
- expandMemCpyAsLoop(Memcpy, TTI);
- Changed = true;
- Memcpy->eraseFromParent();
- break;
+ SmallVector MemCalls;
+
+ /* Iterate over all instructions in the function, looking for memcpy,
+ * memmove, and memset. When we find one, expand it into a loop. */
+
+ for (auto &BB : F) {
+ for (auto &Inst : BB) {
+ if (auto *Memcpy = dyn_cast_or_null(&Inst)) {
+ MemCalls.push_back(Memcpy);
}
- case Intrinsic::memmove:
- {
- auto *Memmove = cast(Inst);
- expandMemMoveAsLoop(Memmove);
- Changed = true;
- Memmove->eraseFromParent();
- break;
+ else if (auto *Memmove = dyn_cast_or_null(&Inst)) {
+ MemCalls.push_back(Memmove);
}
- case Intrinsic::memset:
- {
- auto *Memset = cast(Inst);
- expandMemSetAsLoop(Memset);
- Changed = true;
- Memset->eraseFromParent();
- break;
+ else if (auto *Memset = dyn_cast_or_null(&Inst)) {
+ MemCalls.push_back(Memset);
}
- default:
- break;
}
}
- return Changed;
-}
-
-bool
-ExpandMemoryOpPass::runOnModule(Module &M)
-{
- bool Changed = false;
-
- for (Function &F : M) {
- if (!F.isDeclaration())
- continue;
-
- switch (F.getIntrinsicID()) {
- case Intrinsic::memcpy:
- case Intrinsic::memmove:
- case Intrinsic::memset:
- if (expandMemIntrinsicUses(F))
- Changed = true;
- break;
-
- default:
- break;
+ for (MemIntrinsic *MemCall : MemCalls) {
+ if (MemCpyInst *Memcpy = dyn_cast(MemCall)) {
+ Function *ParentFunc = Memcpy->getParent()->getParent();
+ const TargetTransformInfo &TTI =
+ AM.getResult(*ParentFunc);
+ expandMemCpyAsLoop(Memcpy, TTI);
+ Memcpy->eraseFromParent();
+ }
+ else if (MemMoveInst *Memmove = dyn_cast(MemCall)) {
+#if LLVM_VERSION_MAJOR >= 17
+ Function *ParentFunc = Memmove->getParent()->getParent();
+ const TargetTransformInfo &TTI =
+ AM.getResult(*ParentFunc);
+ expandMemMoveAsLoop(Memmove, TTI);
+#else
+ expandMemMoveAsLoop(Memmove);
+#endif
+ Memmove->eraseFromParent();
+ }
+ else if (MemSetInst *Memset = dyn_cast(MemCall)) {
+ expandMemSetAsLoop(Memset);
+ Memset->eraseFromParent();
}
}
- return Changed;
-}
-
-void
-aot_add_expand_memory_op_pass(LLVMPassManagerRef pass)
-{
- reinterpret_cast(pass)->add(
- new ExpandMemoryOpPass());
-}
+ PreservedAnalyses PA;
+ PA.preserveSet();
-void
-aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass)
-{
- reinterpret_cast(pass)->add(
- createSimpleLoopUnswitchLegacyPass());
+ return PA;
}
bool
@@ -232,14 +198,42 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)
PTO.SLPVectorization = true;
PTO.LoopUnrolling = true;
+#if LLVM_VERSION_MAJOR >= 16
+ Optional PGO = std::nullopt;
+#else
+ Optional PGO = llvm::None;
+#endif
+
+ if (comp_ctx->enable_llvm_pgo) {
+ /* Disable static counter allocation for value profiler,
+ it will be allocated by runtime */
+ const char *argv[] = { "", "-vp-static-alloc=false" };
+ cl::ParseCommandLineOptions(2, argv);
+#if LLVM_VERSION_MAJOR < 17
+ PGO = PGOOptions("", "", "", PGOOptions::IRInstr);
+#else
+ auto FS = vfs::getRealFileSystem();
+ PGO = PGOOptions("", "", "", "", FS, PGOOptions::IRInstr);
+#endif
+ }
+ else if (comp_ctx->use_prof_file) {
+#if LLVM_VERSION_MAJOR < 17
+ PGO = PGOOptions(comp_ctx->use_prof_file, "", "", PGOOptions::IRUse);
+#else
+ auto FS = vfs::getRealFileSystem();
+ PGO = PGOOptions(comp_ctx->use_prof_file, "", "", "", FS,
+ PGOOptions::IRUse);
+#endif
+ }
+
#ifdef DEBUG_PASS
PassInstrumentationCallbacks PIC;
- PassBuilder PB(TM, PTO, None, &PIC);
+ PassBuilder PB(TM, PTO, PGO, &PIC);
#else
#if LLVM_VERSION_MAJOR == 12
- PassBuilder PB(false, TM, PTO);
+ PassBuilder PB(false, TM, PTO, PGO);
#else
- PassBuilder PB(TM, PTO);
+ PassBuilder PB(TM, PTO, PGO);
#endif
#endif
@@ -334,27 +328,95 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)
FPM.addPass(SLPVectorizerPass());
FPM.addPass(LoadStoreVectorizerPass());
+ if (comp_ctx->enable_llvm_pgo || comp_ctx->use_prof_file) {
+ /* LICM pass: loop invariant code motion, attempting to remove
+ as much code from the body of a loop as possible. Experiments
+ show it is good to enable it when pgo is enabled. */
+#if LLVM_VERSION_MAJOR >= 15
+ LICMOptions licm_opt;
+ FPM.addPass(
+ createFunctionToLoopPassAdaptor(LICMPass(licm_opt), true));
+#else
+ FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), true));
+#endif
+ }
+
/*
- FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass()));
FPM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass()));
FPM.addPass(createFunctionToLoopPassAdaptor(SimpleLoopUnswitchPass()));
*/
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
- if (!disable_llvm_lto) {
- /* Apply LTO for AOT mode */
- if (comp_ctx->comp_data->func_count >= 10)
- /* Adds the pre-link optimizations if the func count
- is large enough */
- MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL));
- else
- MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL));
+ if (comp_ctx->llvm_passes) {
+ ExitOnErr(PB.parsePassPipeline(MPM, comp_ctx->llvm_passes));
+ }
+
+ if (
+#if LLVM_VERSION_MAJOR <= 13
+ PassBuilder::OptimizationLevel::O0 == OL
+#else
+ OptimizationLevel::O0 == OL
+#endif
+ ) {
+ MPM.addPass(PB.buildO0DefaultPipeline(OL));
}
else {
- MPM.addPass(PB.buildPerModuleDefaultPipeline(OL));
+ if (!disable_llvm_lto) {
+ /* Apply LTO for AOT mode */
+ if (comp_ctx->comp_data->func_count >= 10
+ || comp_ctx->enable_llvm_pgo || comp_ctx->use_prof_file)
+ /* Add the pre-link optimizations if the func count
+ is large enough or PGO is enabled */
+ MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL));
+ else
+ MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL));
+ }
+ else {
+ MPM.addPass(PB.buildPerModuleDefaultPipeline(OL));
+ }
+ }
+
+ /* Run specific passes for AOT indirect mode in last since general
+ optimization may create some intrinsic function calls like
+ llvm.memset, so let's remove these function calls here. */
+ if (comp_ctx->is_indirect_mode) {
+ FunctionPassManager FPM1;
+ FPM1.addPass(ExpandMemoryOpPass());
+ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM1)));
}
}
MPM.run(*M, MAM);
}
+
+char *
+aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size)
+{
+ std::vector NameStrs;
+ std::string Result;
+ char buf[32], *compressed_str;
+ uint32 compressed_str_len, i;
+
+ for (i = 0; i < comp_ctx->func_ctx_count; i++) {
+ snprintf(buf, sizeof(buf), "%s%d", AOT_FUNC_PREFIX, i);
+ std::string str(buf);
+ NameStrs.push_back(str);
+ }
+
+ if (collectPGOFuncNameStrings(NameStrs, true, Result)) {
+ aot_set_last_error("collect pgo func name strings failed");
+ return NULL;
+ }
+
+ compressed_str_len = Result.size();
+ if (!(compressed_str = (char *)wasm_runtime_malloc(compressed_str_len))) {
+ aot_set_last_error("allocate memory failed");
+ return NULL;
+ }
+
+ bh_memcpy_s(compressed_str, compressed_str_len, Result.c_str(),
+ compressed_str_len);
+ *p_size = compressed_str_len;
+ return compressed_str;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.cpp
similarity index 76%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.cpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.cpp
index 9bd44bbff77..8364e5ebf42 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.cpp
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.cpp
@@ -4,19 +4,39 @@
*/
#include
+#if LLVM_VERSION_MAJOR < 17
+#include
+#include
+#endif
+#include
+#if LLVM_VERSION_MAJOR >= 14
#include
+#else
+#include
+#endif
#include
#include "bh_assert.h"
#include "aot_llvm_extra2.h"
+#if LLVM_VERSION_MAJOR >= 17
+namespace llvm {
+template
+using Optional = std::optional;
+}
+#endif
+
static llvm::Optional
convert(LLVMRelocMode reloc_mode)
{
switch (reloc_mode) {
case LLVMRelocDefault:
+#if LLVM_VERSION_MAJOR >= 16
+ return std::nullopt;
+#else
return llvm::None;
+#endif
case LLVMRelocStatic:
return llvm::Reloc::Static;
case LLVMRelocPIC:
@@ -31,7 +51,11 @@ convert(LLVMRelocMode reloc_mode)
return llvm::Reloc::ROPI_RWPI;
}
bh_assert(0);
+#if LLVM_VERSION_MAJOR >= 16
+ return std::nullopt;
+#else
return llvm::None;
+#endif
}
static llvm::CodeGenOpt::Level
@@ -57,10 +81,18 @@ convert(LLVMCodeModel code_model, bool *jit)
*jit = false;
switch (code_model) {
case LLVMCodeModelDefault:
+#if LLVM_VERSION_MAJOR >= 16
+ return std::nullopt;
+#else
return llvm::None;
+#endif
case LLVMCodeModelJITDefault:
*jit = true;
+#if LLVM_VERSION_MAJOR >= 16
+ return std::nullopt;
+#else
return llvm::None;
+#endif
case LLVMCodeModelTiny:
return llvm::CodeModel::Tiny;
case LLVMCodeModelSmall:
@@ -73,7 +105,11 @@ convert(LLVMCodeModel code_model, bool *jit)
return llvm::CodeModel::Large;
}
bh_assert(0);
+#if LLVM_VERSION_MAJOR >= 16
+ return std::nullopt;
+#else
return llvm::None;
+#endif
}
LLVMTargetMachineRef
@@ -106,3 +142,20 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple,
opts, rm, cm, ol, jit);
return reinterpret_cast(targetmachine);
}
+
+/* https://reviews.llvm.org/D153107 */
+#if LLVM_VERSION_MAJOR < 17
+using namespace llvm;
+
+LLVMTailCallKind
+LLVMGetTailCallKind(LLVMValueRef Call)
+{
+ return (LLVMTailCallKind)unwrap(Call)->getTailCallKind();
+}
+
+void
+LLVMSetTailCallKind(LLVMValueRef Call, LLVMTailCallKind kind)
+{
+ unwrap(Call)->setTailCallKind((CallInst::TailCallKind)kind);
+}
+#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.h
similarity index 62%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.h
index ef99622a431..f3f89799436 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.h
@@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
+#include
#include
LLVM_C_EXTERN_C_BEGIN
@@ -14,4 +15,20 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple,
LLVMCodeModel code_model,
bool EmitStackSizeSection,
const char *StackUsageOutput);
+
+/* https://reviews.llvm.org/D153107 */
+#if LLVM_VERSION_MAJOR < 17
+typedef enum {
+ LLVMTailCallKindNone = 0,
+ LLVMTailCallKindTail = 1,
+ LLVMTailCallKindMustTail = 2,
+ LLVMTailCallKindNoTail = 3,
+} LLVMTailCallKind;
+
+LLVMTailCallKind
+LLVMGetTailCallKind(LLVMValueRef CallInst);
+void
+LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind kind);
+#endif
+
LLVM_C_EXTERN_C_END
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.cpp
similarity index 81%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.cpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.cpp
index 8cf253e9487..ad8c41c3fdd 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.cpp
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.cpp
@@ -8,17 +8,30 @@
#include "llvm-c/OrcEE.h"
#include "llvm-c/TargetMachine.h"
+#if LLVM_VERSION_MAJOR < 17
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#endif
+#include "llvm/ExecutionEngine/JITEventListener.h"
+#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
-#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/Support/CBindingWrapping.h"
#include "aot_orc_extra.h"
#include "aot.h"
+#if LLVM_VERSION_MAJOR >= 17
+namespace llvm {
+template
+using Optional = std::optional;
+}
+#endif
+
using namespace llvm;
using namespace llvm::orc;
using GlobalValueSet = std::set;
@@ -97,6 +110,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectTransformLayer,
LLVMOrcObjectTransformLayerRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcV2CAPIHelper::PoolEntry,
LLVMOrcSymbolStringPoolEntryRef)
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectLayer, LLVMOrcObjectLayerRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SymbolStringPool, LLVMOrcSymbolStringPoolRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
@@ -155,13 +169,29 @@ PartitionFunction(GlobalValueSet Requested)
const char *wrapper;
uint32 prefix_len = strlen(AOT_FUNC_PREFIX);
+ LOG_DEBUG("requested func %s", gvname);
/* Convert "aot_func#n_wrapper" to "aot_func#n" */
- if (strstr(gvname, AOT_FUNC_PREFIX)
- && (wrapper = strstr(gvname + prefix_len, "_wrapper"))) {
+ if (strstr(gvname, AOT_FUNC_PREFIX)) {
char buf[16] = { 0 };
char func_name[64];
int group_stride, i, j;
-
+ int num;
+
+ /*
+ * if the jit wrapper (which has "_wrapper" suffix in
+ * the name) is requested, compile others in the group too.
+ * otherwise, only compile the requested one.
+ * (and possibly the correspondig wrapped function,
+ * which has AOT_FUNC_INTERNAL_PREFIX.)
+ */
+ wrapper = strstr(gvname + prefix_len, "_wrapper");
+ if (wrapper != NULL) {
+ num = WASM_ORC_JIT_COMPILE_THREAD_NUM;
+ }
+ else {
+ num = 1;
+ wrapper = strchr(gvname + prefix_len, 0);
+ }
bh_assert(wrapper - (gvname + prefix_len) > 0);
/* Get AOT function index */
bh_memcpy_s(buf, (uint32)sizeof(buf), gvname + prefix_len,
@@ -171,10 +201,18 @@ PartitionFunction(GlobalValueSet Requested)
group_stride = WASM_ORC_JIT_BACKEND_THREAD_NUM;
/* Compile some functions each time */
- for (j = 0; j < WASM_ORC_JIT_COMPILE_THREAD_NUM; j++) {
+ for (j = 0; j < num; j++) {
+ Function *F1;
snprintf(func_name, sizeof(func_name), "%s%d",
AOT_FUNC_PREFIX, i + j * group_stride);
- Function *F1 = M->getFunction(func_name);
+ F1 = M->getFunction(func_name);
+ if (F1) {
+ LOG_DEBUG("compile func %s", func_name);
+ GVsToAdd.push_back(cast(F1));
+ }
+ snprintf(func_name, sizeof(func_name), "%s%d",
+ AOT_FUNC_INTERNAL_PREFIX, i + j * group_stride);
+ F1 = M->getFunction(func_name);
if (F1) {
LOG_DEBUG("compile func %s", func_name);
GVsToAdd.push_back(cast(F1));
@@ -287,3 +325,9 @@ LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J)
{
return wrap(&unwrap(J)->getObjTransformLayer());
}
+
+LLVMOrcObjectLayerRef
+LLVMOrcLLLazyJITGetObjLinkingLayer(LLVMOrcLLLazyJITRef J)
+{
+ return wrap(&unwrap(J)->getObjLinkingLayer());
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.h
similarity index 89%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.h
index e152b877843..32ece4de4e1 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.h
@@ -71,5 +71,13 @@ LLVMOrcLLLazyJITGetIRTransformLayer(LLVMOrcLLLazyJITRef J);
LLVMOrcObjectTransformLayerRef
LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J);
+void
+LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback(
+ LLVMOrcLLLazyJITBuilderRef Builder,
+ void (*cb)(void *, const char *, size_t, size_t), void *cb_data);
+
+LLVMOrcObjectLayerRef
+LLVMOrcLLLazyJITGetObjLinkingLayer(LLVMOrcLLLazyJITRef J);
+
LLVM_C_EXTERN_C_END
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp
new file mode 100644
index 00000000000..515f7209f96
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+
+#include "aot_orc_extra.h"
+#include "bh_log.h"
+
+typedef void (*cb_t)(void *, const char *, size_t, size_t);
+
+class MyCompiler : public llvm::orc::IRCompileLayer::IRCompiler
+{
+ public:
+ MyCompiler(llvm::orc::JITTargetMachineBuilder JTMB, cb_t cb, void *cb_data);
+ llvm::Expected operator()(
+ llvm::Module &M) override;
+
+ private:
+ llvm::orc::JITTargetMachineBuilder JTMB;
+
+ cb_t cb;
+ void *cb_data;
+};
+
+MyCompiler::MyCompiler(llvm::orc::JITTargetMachineBuilder JTMB, cb_t cb,
+ void *cb_data)
+ : IRCompiler(llvm::orc::irManglingOptionsFromTargetOptions(JTMB.getOptions()))
+ , JTMB(std::move(JTMB))
+ , cb(cb)
+ , cb_data(cb_data)
+{}
+
+class PrintStackSizes : public llvm::MachineFunctionPass
+{
+ public:
+ PrintStackSizes(cb_t cb, void *cb_data);
+ bool runOnMachineFunction(llvm::MachineFunction &MF) override;
+ static char ID;
+
+ private:
+ cb_t cb;
+ void *cb_data;
+};
+
+PrintStackSizes::PrintStackSizes(cb_t cb, void *cb_data)
+ : MachineFunctionPass(ID)
+ , cb(cb)
+ , cb_data(cb_data)
+{}
+
+char PrintStackSizes::ID = 0;
+
+bool
+PrintStackSizes::runOnMachineFunction(llvm::MachineFunction &MF)
+{
+ auto name = MF.getName();
+ auto MFI = &MF.getFrameInfo();
+ size_t sz = MFI->getStackSize();
+ cb(cb_data, name.data(), name.size(), sz);
+ return false;
+}
+
+class MyPassManager : public llvm::legacy::PassManager
+{
+ public:
+ void add(llvm::Pass *P) override;
+};
+
+void
+MyPassManager::add(llvm::Pass *P)
+{
+ // a hack to avoid having a copy of the whole addPassesToEmitMC.
+ // we want to add PrintStackSizes before FreeMachineFunctionPass.
+ if (P->getPassName() == "Free MachineFunction") {
+ return;
+ }
+ llvm::legacy::PassManager::add(P);
+}
+
+// a modified copy from llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
+llvm::Expected
+MyCompiler::operator()(llvm::Module &M)
+{
+ auto TM = cantFail(JTMB.createTargetMachine());
+ llvm::SmallVector ObjBufferSV;
+
+ {
+ llvm::raw_svector_ostream ObjStream(ObjBufferSV);
+
+ MyPassManager PM;
+ llvm::MCContext *Ctx;
+ if (TM->addPassesToEmitMC(PM, Ctx, ObjStream))
+ return llvm::make_error(
+ "Target does not support MC emission",
+ llvm::inconvertibleErrorCode());
+ PM.add(new PrintStackSizes(cb, cb_data));
+ dynamic_cast(&PM)->add(
+ llvm::createFreeMachineFunctionPass());
+ PM.run(M);
+ }
+
+#if LLVM_VERSION_MAJOR > 13
+ auto ObjBuffer = std::make_unique(
+ std::move(ObjBufferSV),
+ M.getModuleIdentifier() + "-jitted-objectbuffer",
+ /*RequiresNullTerminator=*/false);
+#else
+ auto ObjBuffer = std::make_unique(
+ std::move(ObjBufferSV),
+ M.getModuleIdentifier() + "-jitted-objectbuffer");
+#endif
+
+ return std::move(ObjBuffer);
+}
+
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::LLLazyJITBuilder,
+ LLVMOrcLLLazyJITBuilderRef)
+
+void
+LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback(
+ LLVMOrcLLLazyJITBuilderRef Builder,
+ void (*cb)(void *, const char *, size_t, size_t), void *cb_data)
+{
+ auto b = unwrap(Builder);
+ b->setCompileFunctionCreator(
+ [cb, cb_data](llvm::orc::JITTargetMachineBuilder JTMB)
+ -> llvm::Expected<
+ std::unique_ptr> {
+ return std::make_unique(
+ MyCompiler(std::move(JTMB), cb, cb_data));
+ });
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.cpp
similarity index 92%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.cpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.cpp
index d5a1be85e06..99182f82f99 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.cpp
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.cpp
@@ -28,25 +28,25 @@
using namespace lldb;
-typedef struct dwar_extractor {
+typedef struct dwarf_extractor {
SBDebugger debugger;
SBTarget target;
SBModule module;
-} dwar_extractor;
+} dwarf_extractor;
-#define TO_HANDLE(extractor) (dwar_extractor_handle_t)(extractor)
+#define TO_HANDLE(extractor) (dwarf_extractor_handle_t)(extractor)
-#define TO_EXTACTOR(handle) (dwar_extractor *)(handle)
+#define TO_EXTACTOR(handle) (dwarf_extractor *)(handle)
static bool is_debugger_initialized;
-dwar_extractor_handle_t
+dwarf_extractor_handle_t
create_dwarf_extractor(AOTCompData *comp_data, char *file_name)
{
char *arch = NULL;
char *platform = NULL;
- dwar_extractor *extractor = NULL;
+ dwarf_extractor *extractor = NULL;
//__attribute__((constructor)) may be better?
if (!is_debugger_initialized) {
@@ -61,7 +61,7 @@ create_dwarf_extractor(AOTCompData *comp_data, char *file_name)
SBError error;
SBFileSpec exe_file_spec(file_name, true);
- if (!(extractor = new dwar_extractor())) {
+ if (!(extractor = new dwarf_extractor())) {
LOG_ERROR("Create Dwarf Extractor error: failed to allocate memory");
goto fail3;
}
@@ -101,9 +101,9 @@ create_dwarf_extractor(AOTCompData *comp_data, char *file_name)
}
void
-destroy_dwarf_extractor(dwar_extractor_handle_t handle)
+destroy_dwarf_extractor(dwarf_extractor_handle_t handle)
{
- dwar_extractor *extractor = TO_EXTACTOR(handle);
+ dwarf_extractor *extractor = TO_EXTACTOR(handle);
if (!extractor)
return;
extractor->debugger.DeleteTarget(extractor->target);
@@ -114,9 +114,9 @@ destroy_dwarf_extractor(dwar_extractor_handle_t handle)
}
LLVMMetadataRef
-dwarf_gen_file_info(AOTCompContext *comp_ctx)
+dwarf_gen_file_info(const AOTCompContext *comp_ctx)
{
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
int units_number;
LLVMMetadataRef file_info = NULL;
const char *file_name;
@@ -191,9 +191,9 @@ dwarf_gen_mock_vm_info(AOTCompContext *comp_ctx)
#endif
LLVMMetadataRef
-dwarf_gen_comp_unit_info(AOTCompContext *comp_ctx)
+dwarf_gen_comp_unit_info(const AOTCompContext *comp_ctx)
{
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
int units_number;
LLVMMetadataRef comp_unit = NULL;
@@ -257,7 +257,7 @@ lldb_get_basic_type_encoding(BasicType basic_type)
}
static LLVMMetadataRef
-lldb_type_to_type_dbi(AOTCompContext *comp_ctx, SBType &type)
+lldb_type_to_type_dbi(const AOTCompContext *comp_ctx, SBType &type)
{
LLVMMetadataRef type_info = NULL;
BasicType basic_type = type.GetBasicType();
@@ -282,8 +282,9 @@ lldb_type_to_type_dbi(AOTCompContext *comp_ctx, SBType &type)
}
static LLVMMetadataRef
-lldb_function_to_function_dbi(AOTCompContext *comp_ctx, SBSymbolContext &sc,
- AOTFuncContext *func_ctx)
+lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
+ SBSymbolContext &sc,
+ const AOTFuncContext *func_ctx)
{
SBFunction function(sc.GetFunction());
const char *function_name = function.GetName();
@@ -291,7 +292,7 @@ lldb_function_to_function_dbi(AOTCompContext *comp_ctx, SBSymbolContext &sc,
SBTypeList function_args = function.GetType().GetFunctionArgumentTypes();
SBType return_type = function.GetType().GetFunctionReturnType();
const size_t num_function_args = function_args.GetSize();
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor)))
return NULL;
@@ -388,10 +389,11 @@ lldb_function_to_function_dbi(AOTCompContext *comp_ctx, SBSymbolContext &sc,
}
LLVMMetadataRef
-dwarf_gen_func_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+dwarf_gen_func_info(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx)
{
LLVMMetadataRef func_info = NULL;
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
uint64_t vm_offset;
AOTFunc *func = func_ctx->aot_func;
@@ -417,11 +419,11 @@ dwarf_gen_func_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}
void
-dwarf_get_func_name(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- char *name, int len)
+dwarf_get_func_name(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx, char *name, int len)
{
LLVMMetadataRef func_info = NULL;
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
uint64_t vm_offset;
AOTFunc *func = func_ctx->aot_func;
@@ -448,11 +450,11 @@ dwarf_get_func_name(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
LLVMMetadataRef
-dwarf_gen_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint64_t vm_offset)
+dwarf_gen_location(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx, uint64_t vm_offset)
{
LLVMMetadataRef location_info = NULL;
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
AOTFunc *func = func_ctx->aot_func;
if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor)))
@@ -487,10 +489,11 @@ dwarf_gen_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
LLVMMetadataRef
-dwarf_gen_func_ret_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
+dwarf_gen_func_ret_location(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx)
{
LLVMMetadataRef func_info = NULL;
- dwar_extractor *extractor;
+ dwarf_extractor *extractor;
uint64_t vm_offset;
AOTFunc *func = func_ctx->aot_func;
LLVMMetadataRef location_info = NULL;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.h
similarity index 55%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.h
index 449d4d57c51..0bacb97fa2e 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.h
@@ -18,7 +18,7 @@ typedef unsigned int LLDBLangType;
struct AOTCompData;
typedef struct AOTCompData *aot_comp_data_t;
-typedef void *dwar_extractor_handle_t;
+typedef void *dwarf_extractor_handle_t;
struct AOTCompContext;
typedef struct AOTCompContext AOTCompContext;
@@ -26,28 +26,30 @@ typedef struct AOTCompContext AOTCompContext;
struct AOTFuncContext;
typedef struct AOTFuncContext AOTFuncContext;
-dwar_extractor_handle_t
+dwarf_extractor_handle_t
create_dwarf_extractor(aot_comp_data_t comp_data, char *file_name);
LLVMMetadataRef
-dwarf_gen_file_info(AOTCompContext *comp_ctx);
+dwarf_gen_file_info(const AOTCompContext *comp_ctx);
LLVMMetadataRef
-dwarf_gen_comp_unit_info(AOTCompContext *comp_ctx);
+dwarf_gen_comp_unit_info(const AOTCompContext *comp_ctx);
LLVMMetadataRef
-dwarf_gen_func_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
+dwarf_gen_func_info(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx);
LLVMMetadataRef
-dwarf_gen_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- uint64_t vm_offset);
+dwarf_gen_location(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx, uint64_t vm_offset);
LLVMMetadataRef
-dwarf_gen_func_ret_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);
+dwarf_gen_func_ret_location(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx);
void
-dwarf_get_func_name(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- char *name, int len);
+dwarf_get_func_name(const AOTCompContext *comp_ctx,
+ const AOTFuncContext *func_ctx, char *name, int len);
#ifdef __cplusplus
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/iwasm_compl.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/iwasm_compl.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/iwasm_compl.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/iwasm_compl.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.c
similarity index 89%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.c
index 675ffbcfe06..1d645ed7146 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.c
@@ -30,11 +30,11 @@ simd_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVM_CONST(i16x8_vec_zero),
LLVM_CONST(i32x4_vec_zero),
LLVM_CONST(i64x2_vec_zero) };
- LLVMValueRef lane_bits[] = {
- LLVM_CONST(i32_eight),
- LLVMConstInt(I32_TYPE, 16, true),
- LLVMConstInt(I32_TYPE, 32, true),
- LLVMConstInt(I32_TYPE, 64, true),
+ LLVMValueRef lane_shift_masks[] = {
+ LLVMConstInt(I32_TYPE, 7, true),
+ LLVMConstInt(I32_TYPE, 15, true),
+ LLVMConstInt(I32_TYPE, 31, true),
+ LLVMConstInt(I32_TYPE, 63, true),
};
POP_I32(offset);
@@ -44,11 +44,11 @@ simd_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return false;
}
- /* offset mod LaneBits */
- if (!lane_bits[itype]
- || !(offset = LLVMBuildSRem(comp_ctx->builder, offset, lane_bits[itype],
- "offset_fix"))) {
- HANDLE_FAILURE("LLVMBuildSRem");
+ /* offset = offset & shift_mask */
+ if (!lane_shift_masks[itype]
+ || !(offset = LLVMBuildAnd(comp_ctx->builder, offset,
+ lane_shift_masks[itype], "offset_fix"))) {
+ HANDLE_FAILURE("LLVMBuildAnd");
return false;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.c
similarity index 62%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.c
index d850fe8f75e..7fcc1ab655d 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.c
@@ -217,10 +217,9 @@ aot_compile_simd_f64x2_nearest(AOTCompContext *comp_ctx,
static bool
simd_float_cmp(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- FloatArithmetic arith_op, LLVMTypeRef vector_type)
+ FloatArithmetic op, LLVMTypeRef vector_type)
{
- LLVMValueRef lhs, rhs, result;
- LLVMRealPredicate op = FLOAT_MIN == arith_op ? LLVMRealULT : LLVMRealUGT;
+ LLVMValueRef lhs, rhs, cmp, selected;
if (!(rhs =
simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, "rhs"))
@@ -229,47 +228,122 @@ simd_float_cmp(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return false;
}
- if (!(result = LLVMBuildFCmp(comp_ctx->builder, op, lhs, rhs, "cmp"))) {
+ if (!(cmp = LLVMBuildFCmp(comp_ctx->builder,
+ op == FLOAT_MIN ? LLVMRealOLT : LLVMRealOGT, rhs,
+ lhs, "cmp"))) {
HANDLE_FAILURE("LLVMBuildFCmp");
return false;
}
- if (!(result =
- LLVMBuildSelect(comp_ctx->builder, result, lhs, rhs, "select"))) {
+ if (!(selected =
+ LLVMBuildSelect(comp_ctx->builder, cmp, rhs, lhs, "selected"))) {
HANDLE_FAILURE("LLVMBuildSelect");
return false;
}
- return simd_bitcast_and_push_v128(comp_ctx, func_ctx, result, "result");
+ return simd_bitcast_and_push_v128(comp_ctx, func_ctx, selected, "result");
}
-/*TODO: sugggest non-IA platforms check with "llvm.minimum.*" and
- * "llvm.maximum.*" firstly */
-bool
-aot_compile_simd_f32x4_min_max(AOTCompContext *comp_ctx,
- AOTFuncContext *func_ctx, bool run_min)
+static bool
+simd_float_min(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
+ LLVMTypeRef vector_type)
{
- return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX,
- V128_f32x4_TYPE);
-}
+ LLVMValueRef lhs, rhs, lhs_nan, rhs_nan, olt_ret, ogt_ret, or_ret, ret1,
+ ret2, ret3, ret4;
-bool
-aot_compile_simd_f64x2_min_max(AOTCompContext *comp_ctx,
- AOTFuncContext *func_ctx, bool run_min)
-{
- return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX,
- V128_f64x2_TYPE);
+ if (!(rhs =
+ simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, "rhs"))
+ || !(lhs = simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type,
+ "lhs"))) {
+ return false;
+ }
+
+ if (!(lhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, lhs, lhs,
+ "lhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO");
+ return false;
+ }
+
+ if (!(rhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, rhs, rhs,
+ "rhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO");
+ return false;
+ }
+
+ if (!(olt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOLT, lhs, rhs,
+ "olt_ret"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOLT");
+ return false;
+ }
+
+ if (!(ogt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOGT, lhs, rhs,
+ "ogt_ret"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOGT");
+ return false;
+ }
+
+ /* lhs or rhs */
+ {
+ LLVMValueRef integer_l, integer_r, integer_or;
+
+ if (!(integer_l = LLVMBuildBitCast(comp_ctx->builder, lhs,
+ V128_i64x2_TYPE, "lhs_to_int"))) {
+ HANDLE_FAILURE("LLVMBuildBitCas");
+ return false;
+ }
+
+ if (!(integer_r = LLVMBuildBitCast(comp_ctx->builder, rhs,
+ V128_i64x2_TYPE, "rhs_to_int"))) {
+ HANDLE_FAILURE("LLVMBuildBitCas");
+ return false;
+ }
+
+ if (!(integer_or =
+ LLVMBuildOr(comp_ctx->builder, integer_l, integer_r, "or"))) {
+ HANDLE_FAILURE("LLVMBuildOr");
+ return false;
+ }
+
+ if (!(or_ret = LLVMBuildBitCast(comp_ctx->builder, integer_or,
+ vector_type, "holder"))) {
+ HANDLE_FAILURE("LLVMBuildBitCast");
+ return false;
+ }
+ }
+
+ if (!(ret1 = LLVMBuildSelect(comp_ctx->builder, olt_ret, lhs, or_ret,
+ "sel_olt"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ if (!(ret2 = LLVMBuildSelect(comp_ctx->builder, ogt_ret, rhs, ret1,
+ "sel_ogt"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ if (!(ret3 = LLVMBuildSelect(comp_ctx->builder, lhs_nan, lhs, ret2,
+ "sel_lhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ if (!(ret4 = LLVMBuildSelect(comp_ctx->builder, rhs_nan, rhs, ret3,
+ "sel_rhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ return simd_bitcast_and_push_v128(comp_ctx, func_ctx, ret4, "result");
}
static bool
-simd_float_pmin_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
- LLVMTypeRef vector_type, const char *intrinsic)
+simd_float_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
+ LLVMTypeRef vector_type)
{
- LLVMValueRef lhs, rhs, result;
- LLVMTypeRef param_types[2];
-
- param_types[0] = vector_type;
- param_types[1] = vector_type;
+ LLVMValueRef lhs, rhs, lhs_nan, rhs_nan, olt_ret, ogt_ret, and_ret, ret1,
+ ret2, ret3, ret4;
if (!(rhs =
simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, "rhs"))
@@ -278,31 +352,116 @@ simd_float_pmin_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return false;
}
- if (!(result =
- aot_call_llvm_intrinsic(comp_ctx, func_ctx, intrinsic,
- vector_type, param_types, 2, lhs, rhs))) {
+ if (!(lhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, lhs, lhs,
+ "lhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO");
return false;
}
- return simd_bitcast_and_push_v128(comp_ctx, func_ctx, result, "result");
+ if (!(rhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, rhs, rhs,
+ "rhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO");
+ return false;
+ }
+
+ if (!(olt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOLT, lhs, rhs,
+ "olt_ret"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOLT");
+ return false;
+ }
+
+ if (!(ogt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOGT, lhs, rhs,
+ "ogt_ret"))) {
+ HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOGT");
+ return false;
+ }
+
+ /* lhs and rhs */
+ {
+ LLVMValueRef integer_l, integer_r, integer_and;
+
+ if (!(integer_l = LLVMBuildBitCast(comp_ctx->builder, lhs,
+ V128_i64x2_TYPE, "lhs_to_int"))) {
+ HANDLE_FAILURE("LLVMBuildBitCas");
+ return false;
+ }
+
+ if (!(integer_r = LLVMBuildBitCast(comp_ctx->builder, rhs,
+ V128_i64x2_TYPE, "rhs_to_int"))) {
+ HANDLE_FAILURE("LLVMBuildBitCas");
+ return false;
+ }
+
+ if (!(integer_and = LLVMBuildAnd(comp_ctx->builder, integer_l,
+ integer_r, "and"))) {
+ HANDLE_FAILURE("LLVMBuildOr");
+ return false;
+ }
+
+ if (!(and_ret = LLVMBuildBitCast(comp_ctx->builder, integer_and,
+ vector_type, "holder"))) {
+ HANDLE_FAILURE("LLVMBuildBitCast");
+ return false;
+ }
+ }
+
+ if (!(ret1 = LLVMBuildSelect(comp_ctx->builder, ogt_ret, lhs, and_ret,
+ "sel_ogt"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ if (!(ret2 = LLVMBuildSelect(comp_ctx->builder, olt_ret, rhs, ret1,
+ "sel_olt"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ if (!(ret3 = LLVMBuildSelect(comp_ctx->builder, lhs_nan, lhs, ret2,
+ "sel_lhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ if (!(ret4 = LLVMBuildSelect(comp_ctx->builder, rhs_nan, rhs, ret3,
+ "sel_rhs_nan"))) {
+ HANDLE_FAILURE("LLVMBuildSelect");
+ return false;
+ }
+
+ return simd_bitcast_and_push_v128(comp_ctx, func_ctx, ret4, "result");
+}
+
+bool
+aot_compile_simd_f32x4_min_max(AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx, bool run_min)
+{
+ return run_min ? simd_float_min(comp_ctx, func_ctx, V128_f32x4_TYPE)
+ : simd_float_max(comp_ctx, func_ctx, V128_f32x4_TYPE);
+}
+
+bool
+aot_compile_simd_f64x2_min_max(AOTCompContext *comp_ctx,
+ AOTFuncContext *func_ctx, bool run_min)
+{
+ return run_min ? simd_float_min(comp_ctx, func_ctx, V128_f64x2_TYPE)
+ : simd_float_max(comp_ctx, func_ctx, V128_f64x2_TYPE);
}
bool
aot_compile_simd_f32x4_pmin_pmax(AOTCompContext *comp_ctx,
AOTFuncContext *func_ctx, bool run_min)
{
- return simd_float_pmin_max(comp_ctx, func_ctx, V128_f32x4_TYPE,
- run_min ? "llvm.minnum.v4f32"
- : "llvm.maxnum.v4f32");
+ return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX,
+ V128_f32x4_TYPE);
}
bool
aot_compile_simd_f64x2_pmin_pmax(AOTCompContext *comp_ctx,
AOTFuncContext *func_ctx, bool run_min)
{
- return simd_float_pmin_max(comp_ctx, func_ctx, V128_f64x2_TYPE,
- run_min ? "llvm.minnum.v2f64"
- : "llvm.maxnum.v2f64");
+ return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX,
+ V128_f64x2_TYPE);
}
bool
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.c
similarity index 76%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.c
index d166e954c59..0e869727a0b 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.c
@@ -14,12 +14,12 @@
static LLVMValueRef
simd_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
uint32 offset, uint32 data_length, LLVMTypeRef ptr_type,
- LLVMTypeRef data_type)
+ LLVMTypeRef data_type, bool enable_segue)
{
LLVMValueRef maddr, data;
if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset,
- data_length))) {
+ data_length, enable_segue))) {
HANDLE_FAILURE("aot_check_memory_overflow");
return NULL;
}
@@ -44,10 +44,12 @@ bool
aot_compile_simd_v128_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset)
{
+ bool enable_segue = comp_ctx->enable_segue_v128_load;
+ LLVMTypeRef v128_ptr_type = enable_segue ? V128_PTR_TYPE_GS : V128_PTR_TYPE;
LLVMValueRef result;
if (!(result = simd_load(comp_ctx, func_ctx, align, offset, 16,
- V128_PTR_TYPE, V128_TYPE))) {
+ v128_ptr_type, V128_TYPE, enable_segue))) {
return false;
}
@@ -75,6 +77,7 @@ aot_compile_simd_load_extend(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMVectorType(I32_TYPE, 2), LLVMVectorType(I32_TYPE, 2),
};
LLVMTypeRef sub_vector_type, sub_vector_ptr_type;
+ bool enable_segue = comp_ctx->enable_segue_v128_load;
bh_assert(opcode_index < 6);
@@ -82,13 +85,15 @@ aot_compile_simd_load_extend(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* to vector ptr type */
if (!sub_vector_type
- || !(sub_vector_ptr_type = LLVMPointerType(sub_vector_type, 0))) {
+ || !(sub_vector_ptr_type =
+ LLVMPointerType(sub_vector_type, enable_segue ? 256 : 0))) {
HANDLE_FAILURE("LLVMPointerType");
return false;
}
- if (!(sub_vector = simd_load(comp_ctx, func_ctx, align, offset, 8,
- sub_vector_ptr_type, sub_vector_type))) {
+ if (!(sub_vector =
+ simd_load(comp_ctx, func_ctx, align, offset, 8,
+ sub_vector_ptr_type, sub_vector_type, enable_segue))) {
return false;
}
@@ -118,6 +123,9 @@ aot_compile_simd_load_splat(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef element, result;
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
INT32_PTR_TYPE, INT64_PTR_TYPE };
+ LLVMTypeRef element_ptr_types_gs[] = { INT8_PTR_TYPE_GS, INT16_PTR_TYPE_GS,
+ INT32_PTR_TYPE_GS,
+ INT64_PTR_TYPE_GS };
LLVMTypeRef element_data_types[] = { INT8_TYPE, INT16_TYPE, I32_TYPE,
I64_TYPE };
uint32 data_lengths[] = { 1, 2, 4, 8 };
@@ -133,13 +141,16 @@ aot_compile_simd_load_splat(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVM_CONST(i32x4_zero),
LLVM_CONST(i32x2_zero),
};
+ bool enable_segue = comp_ctx->enable_segue_v128_load;
bh_assert(opcode_index < 4);
- if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
- data_lengths[opcode_index],
- element_ptr_types[opcode_index],
- element_data_types[opcode_index]))) {
+ if (!(element = simd_load(
+ comp_ctx, func_ctx, align, offset, data_lengths[opcode_index],
+ comp_ctx->enable_segue_v128_load
+ ? element_ptr_types_gs[opcode_index]
+ : element_ptr_types[opcode_index],
+ element_data_types[opcode_index], enable_segue))) {
return false;
}
@@ -170,11 +181,15 @@ aot_compile_simd_load_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 data_lengths[] = { 1, 2, 4, 8 };
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
INT32_PTR_TYPE, INT64_PTR_TYPE };
+ LLVMTypeRef element_ptr_types_gs[] = { INT8_PTR_TYPE_GS, INT16_PTR_TYPE_GS,
+ INT32_PTR_TYPE_GS,
+ INT64_PTR_TYPE_GS };
LLVMTypeRef element_data_types[] = { INT8_TYPE, INT16_TYPE, I32_TYPE,
I64_TYPE };
LLVMTypeRef vector_types[] = { V128_i8x16_TYPE, V128_i16x8_TYPE,
V128_i32x4_TYPE, V128_i64x2_TYPE };
LLVMValueRef lane = simd_lane_id_to_llvm_value(comp_ctx, lane_id);
+ bool enable_segue = comp_ctx->enable_segue_v128_load;
bh_assert(opcode_index < 4);
@@ -183,10 +198,12 @@ aot_compile_simd_load_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return false;
}
- if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
- data_lengths[opcode_index],
- element_ptr_types[opcode_index],
- element_data_types[opcode_index]))) {
+ if (!(element = simd_load(
+ comp_ctx, func_ctx, align, offset, data_lengths[opcode_index],
+ comp_ctx->enable_segue_v128_load
+ ? element_ptr_types_gs[opcode_index]
+ : element_ptr_types[opcode_index],
+ element_data_types[opcode_index], enable_segue))) {
return false;
}
@@ -207,6 +224,8 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 opcode_index = opcode - SIMD_v128_load32_zero;
uint32 data_lengths[] = { 4, 8 };
LLVMTypeRef element_ptr_types[] = { INT32_PTR_TYPE, INT64_PTR_TYPE };
+ LLVMTypeRef element_ptr_types_gs[] = { INT32_PTR_TYPE_GS,
+ INT64_PTR_TYPE_GS };
LLVMTypeRef element_data_types[] = { I32_TYPE, I64_TYPE };
LLVMValueRef zero[] = {
LLVM_CONST(i32x4_vec_zero),
@@ -222,13 +241,16 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVM_CONST(i32_six) },
{ LLVM_CONST(i32_zero), LLVM_CONST(i32_two) },
};
+ bool enable_segue = comp_ctx->enable_segue_v128_load;
bh_assert(opcode_index < 2);
- if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
- data_lengths[opcode_index],
- element_ptr_types[opcode_index],
- element_data_types[opcode_index]))) {
+ if (!(element = simd_load(
+ comp_ctx, func_ctx, align, offset, data_lengths[opcode_index],
+ comp_ctx->enable_segue_v128_load
+ ? element_ptr_types_gs[opcode_index]
+ : element_ptr_types[opcode_index],
+ element_data_types[opcode_index], enable_segue))) {
return false;
}
@@ -260,12 +282,12 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
static bool
simd_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
uint32 offset, uint32 data_length, LLVMValueRef value,
- LLVMTypeRef value_ptr_type)
+ LLVMTypeRef value_ptr_type, bool enable_segue)
{
LLVMValueRef maddr, result;
if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset,
- data_length)))
+ data_length, enable_segue)))
return false;
if (!(maddr = LLVMBuildBitCast(comp_ctx->builder, maddr, value_ptr_type,
@@ -288,12 +310,14 @@ bool
aot_compile_simd_v128_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 align, uint32 offset)
{
+ bool enable_segue = comp_ctx->enable_segue_v128_store;
+ LLVMTypeRef v128_ptr_type = enable_segue ? V128_PTR_TYPE_GS : V128_PTR_TYPE;
LLVMValueRef value;
POP_V128(value);
return simd_store(comp_ctx, func_ctx, align, offset, 16, value,
- V128_PTR_TYPE);
+ v128_ptr_type, enable_segue);
fail:
return false;
}
@@ -307,10 +331,14 @@ aot_compile_simd_store_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 data_lengths[] = { 1, 2, 4, 8 };
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
INT32_PTR_TYPE, INT64_PTR_TYPE };
+ LLVMTypeRef element_ptr_types_gs[] = { INT8_PTR_TYPE_GS, INT16_PTR_TYPE_GS,
+ INT32_PTR_TYPE_GS,
+ INT64_PTR_TYPE_GS };
uint32 opcode_index = opcode - SIMD_v128_store8_lane;
LLVMTypeRef vector_types[] = { V128_i8x16_TYPE, V128_i16x8_TYPE,
V128_i32x4_TYPE, V128_i64x2_TYPE };
LLVMValueRef lane = simd_lane_id_to_llvm_value(comp_ctx, lane_id);
+ bool enable_segue = comp_ctx->enable_segue_v128_store;
bh_assert(opcode_index < 4);
@@ -327,5 +355,7 @@ aot_compile_simd_store_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return simd_store(comp_ctx, func_ctx, align, offset,
data_lengths[opcode_index], element,
- element_ptr_types[opcode_index]);
+ enable_segue ? element_ptr_types_gs[opcode_index]
+ : element_ptr_types[opcode_index],
+ enable_segue);
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/classic_interpreter.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/classic_interpreter.MD
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/classic_interpreter.MD
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/classic_interpreter.MD
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/export_function.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/export_function.excalidraw
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/export_function.excalidraw
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/export_function.excalidraw
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.excalidraw
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.excalidraw
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.excalidraw
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.svg
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.svg
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.svg
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_exports.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_exports.svg
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_exports.svg
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_exports.svg
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.excalidraw
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.excalidraw
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.excalidraw
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.svg
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.svg
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.svg
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.excalidraw
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.excalidraw
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.excalidraw
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.svg
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.svg
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.svg
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_exports.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_exports.MD
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_exports.MD
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_exports.MD
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_function.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_function.MD
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_function.MD
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_function.MD
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_globals.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_globals.MD
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_globals.MD
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_globals.MD
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/asmjit_sgx_patch.diff b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/asmjit_sgx_patch.diff
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/asmjit_sgx_patch.diff
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/asmjit_sgx_patch.diff
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ASMJIT b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ASMJIT
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ASMJIT
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ASMJIT
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ZYDIS b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ZYDIS
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ZYDIS
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ZYDIS
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.c
index d41249346bc..8fe48f142b3 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.c
@@ -227,7 +227,7 @@ jit_compile_op_f32_compare(JitCompContext *cc, FloatCond cond)
POP_F32(rhs);
POP_F32(lhs);
- if (jit_reg_is_const_val(lhs) && jit_reg_is_const_val(rhs)) {
+ if (jit_reg_is_const(lhs) && jit_reg_is_const(rhs)) {
float32 lvalue = jit_cc_get_const_F32(cc, lhs);
float32 rvalue = jit_cc_get_const_F32(cc, rhs);
@@ -290,7 +290,7 @@ jit_compile_op_f64_compare(JitCompContext *cc, FloatCond cond)
POP_F64(rhs);
POP_F64(lhs);
- if (jit_reg_is_const_val(lhs) && jit_reg_is_const_val(rhs)) {
+ if (jit_reg_is_const(lhs) && jit_reg_is_const(rhs)) {
float64 lvalue = jit_cc_get_const_F64(cc, lhs);
float64 rvalue = jit_cc_get_const_F64(cc, rhs);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.c
index f7536c73ea1..5438bc62cfe 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.c
@@ -808,7 +808,7 @@ jit_compile_op_block(JitCompContext *cc, uint8 **p_frame_ip,
else if (label_type == LABEL_TYPE_IF) {
POP_I32(value);
- if (!jit_reg_is_const_val(value)) {
+ if (!jit_reg_is_const(value)) {
/* Compare value is not constant, create condition br IR */
/* Create entry block */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.c
similarity index 87%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.c
index 8308a3ca945..89d84f142ee 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.c
@@ -192,6 +192,55 @@ jit_compile_check_value_range(JitCompContext *cc, JitReg value, JitReg min_fp,
bh_assert(JIT_REG_KIND_F32 == kind || JIT_REG_KIND_F64 == kind);
+ if (JIT_REG_KIND_F32 == kind && jit_reg_is_const(value)) {
+ /* value is an f32 const */
+ float value_f32_const = jit_cc_get_const_F32(cc, value);
+ float min_fp_f32_const = jit_cc_get_const_F32(cc, min_fp);
+ float max_fp_f32_const = jit_cc_get_const_F32(cc, max_fp);
+
+ if (isnan(value_f32_const)) {
+ /* throw exception if value is nan */
+ if (!jit_emit_exception(cc, EXCE_INVALID_CONVERSION_TO_INTEGER,
+ JIT_OP_JMP, 0, NULL))
+ goto fail;
+ }
+
+ if (value_f32_const <= min_fp_f32_const
+ || value_f32_const >= max_fp_f32_const) {
+ /* throw exception if value is out of range */
+ if (!jit_emit_exception(cc, EXCE_INTEGER_OVERFLOW, JIT_OP_JMP, 0,
+ NULL))
+ goto fail;
+ }
+
+ /* value is in range, do nothing */
+ return true;
+ }
+ else if (JIT_REG_KIND_F64 == kind && jit_reg_is_const(value)) {
+ /* value is an f64 const */
+ double value_f64_const = jit_cc_get_const_F64(cc, value);
+ double min_fp_f64_const = jit_cc_get_const_F64(cc, min_fp);
+ double max_fp_f64_const = jit_cc_get_const_F64(cc, max_fp);
+
+ if (isnan(value_f64_const)) {
+ /* throw exception if value is nan */
+ if (!jit_emit_exception(cc, EXCE_INVALID_CONVERSION_TO_INTEGER,
+ JIT_OP_JMP, 0, NULL))
+ goto fail;
+ }
+
+ if (value_f64_const <= min_fp_f64_const
+ || value_f64_const >= max_fp_f64_const) {
+ /* throw exception if value is out of range */
+ if (!jit_emit_exception(cc, EXCE_INTEGER_OVERFLOW, JIT_OP_JMP, 0,
+ NULL))
+ goto fail;
+ }
+
+ /* value is in range, do nothing */
+ return true;
+ }
+
/* If value is NaN, throw exception */
if (JIT_REG_KIND_F32 == kind)
emit_ret = jit_emit_callnative(cc, local_isnanf, nan_ret, &value, 1);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.c
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.c
index 3ac9e3ed6bb..43a71e26aee 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.c
@@ -827,23 +827,45 @@ emit_callnative(JitCompContext *cc, JitReg native_func_reg, JitReg res,
JitReg *params, uint32 param_count)
{
JitInsn *insn;
+ char *i32_arg_names[] = { "edi", "esi", "edx", "ecx" };
char *i64_arg_names[] = { "rdi", "rsi", "rdx", "rcx", "r8", "r9" };
char *f32_arg_names[] = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" };
char *f64_arg_names[] = { "xmm0_f64", "xmm1_f64", "xmm2_f64",
"xmm3_f64", "xmm4_f64", "xmm5_f64" };
- JitReg i64_arg_regs[6], f32_arg_regs[6], f64_arg_regs[6], res_reg = 0;
+ JitReg i32_arg_regs[4], i64_arg_regs[6];
+ JitReg f32_arg_regs[6], f64_arg_regs[6], res_reg = 0;
JitReg eax_hreg = jit_codegen_get_hreg_by_name("eax");
JitReg xmm0_hreg = jit_codegen_get_hreg_by_name("xmm0");
- uint32 i, i64_reg_idx, float_reg_idx;
+ uint32 i, i64_reg_idx, float_reg_idx, lock_i32_reg_num;
bh_assert(param_count <= 6);
+ for (i = 0; i < 4; i++) {
+ i32_arg_regs[i] = jit_codegen_get_hreg_by_name(i32_arg_names[i]);
+ }
+
for (i = 0; i < 6; i++) {
i64_arg_regs[i] = jit_codegen_get_hreg_by_name(i64_arg_names[i]);
f32_arg_regs[i] = jit_codegen_get_hreg_by_name(f32_arg_names[i]);
f64_arg_regs[i] = jit_codegen_get_hreg_by_name(f64_arg_names[i]);
}
+ lock_i32_reg_num = param_count < 4 ? param_count : 4;
+
+ /*
+ * Lock i32 registers so that they won't be allocated for the operand
+ * of below I32TOI64 insn, which may have been overwritten in the
+ * previous MOV, for example, in the below insns:
+ * MOV I5, I15
+ * I32TOI64 I6, i5
+ * CALLNATIVE VOID, native_func, I5, I6
+ * i5 is used in the second insn, but it has been overwritten in I5
+ * by the first insn
+ */
+ for (i = 0; i < lock_i32_reg_num; i++) {
+ GEN_INSN(MOV, i32_arg_regs[i], i32_arg_regs[i]);
+ }
+
i64_reg_idx = float_reg_idx = 0;
for (i = 0; i < param_count; i++) {
switch (jit_reg_kind(params[i])) {
@@ -865,6 +887,14 @@ emit_callnative(JitCompContext *cc, JitReg native_func_reg, JitReg res,
}
}
+ /*
+ * Announce the locked i32 registers are being used, and do necessary
+ * spill ASAP
+ */
+ for (i = 0; i < lock_i32_reg_num; i++) {
+ GEN_INSN(MOV, i32_arg_regs[i], i32_arg_regs[i]);
+ }
+
if (res) {
switch (jit_reg_kind(res)) {
case JIT_REG_KIND_I32:
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.c
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.c
index 9635d4e57e2..420b4dd8e52 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.c
@@ -137,6 +137,7 @@ check_and_seek(JitCompContext *cc, JitReg addr, uint32 offset, uint32 bytes)
{
JitReg memory_boundary = 0, offset1;
#ifndef OS_ENABLE_HW_BOUND_CHECK
+ JitReg cur_page_count;
/* the default memory */
uint32 mem_idx = 0;
#endif
@@ -146,16 +147,10 @@ check_and_seek(JitCompContext *cc, JitReg addr, uint32 offset, uint32 bytes)
/* 1. shortcut if the memory size is 0 */
if (cc->cur_wasm_module->memories != NULL
&& 0 == cc->cur_wasm_module->memories[mem_idx].init_page_count) {
- JitReg module_inst, cur_page_count;
- uint32 cur_page_count_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+
+ cur_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx);
/* if (cur_mem_page_count == 0) goto EXCEPTION */
- module_inst = get_module_inst_reg(cc->jit_frame);
- cur_page_count = jit_cc_new_reg_I32(cc);
- GEN_INSN(LDI32, cur_page_count, module_inst,
- NEW_CONST(I32, cur_page_count_offset));
GEN_INSN(CMP, cc->cmp_reg, cur_page_count, NEW_CONST(I32, 0));
if (!jit_emit_exception(cc, EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS,
JIT_OP_BEQ, cc->cmp_reg, NULL)) {
@@ -580,15 +575,9 @@ jit_compile_op_f64_store(JitCompContext *cc, uint32 align, uint32 offset)
bool
jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx)
{
- JitReg module_inst, cur_page_count;
- uint32 cur_page_count_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+ JitReg cur_page_count;
- module_inst = get_module_inst_reg(cc->jit_frame);
- cur_page_count = jit_cc_new_reg_I32(cc);
- GEN_INSN(LDI32, cur_page_count, module_inst,
- NEW_CONST(I32, cur_page_count_offset));
+ cur_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx);
PUSH_I32(cur_page_count);
@@ -600,18 +589,11 @@ jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx)
bool
jit_compile_op_memory_grow(JitCompContext *cc, uint32 mem_idx)
{
- JitReg module_inst, grow_res, res;
+ JitReg grow_res, res;
JitReg prev_page_count, inc_page_count, args[2];
- /* Get current page count */
- uint32 cur_page_count_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
-
- module_inst = get_module_inst_reg(cc->jit_frame);
- prev_page_count = jit_cc_new_reg_I32(cc);
- GEN_INSN(LDI32, prev_page_count, module_inst,
- NEW_CONST(I32, cur_page_count_offset));
+ /* Get current page count as prev_page_count */
+ prev_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx);
/* Call wasm_enlarge_memory */
POP_I32(inc_page_count);
@@ -650,6 +632,7 @@ wasm_init_memory(WASMModuleInstance *inst, uint32 mem_idx, uint32 seg_idx,
WASMDataSeg *data_segment;
uint32 mem_size;
uint8 *mem_addr, *data_addr;
+ uint32 seg_len;
/* if d + n > the length of mem.data */
mem_inst = inst->memories[mem_idx];
@@ -659,13 +642,19 @@ wasm_init_memory(WASMModuleInstance *inst, uint32 mem_idx, uint32 seg_idx,
/* if s + n > the length of data.data */
bh_assert(seg_idx < inst->module->data_seg_count);
- data_segment = inst->module->data_segments[seg_idx];
- if (data_segment->data_length < data_offset
- || data_segment->data_length - data_offset < len)
+ if (bh_bitmap_get_bit(inst->e->common.data_dropped, seg_idx)) {
+ seg_len = 0;
+ data_addr = NULL;
+ }
+ else {
+ data_segment = inst->module->data_segments[seg_idx];
+ seg_len = data_segment->data_length;
+ data_addr = data_segment->data + data_offset;
+ }
+ if (seg_len < data_offset || seg_len - data_offset < len)
goto out_of_bounds;
mem_addr = mem_inst->memory_data + mem_offset;
- data_addr = data_segment->data + data_offset;
bh_memcpy_s(mem_addr, mem_size - mem_offset, data_addr, len);
return 0;
@@ -706,21 +695,22 @@ jit_compile_op_memory_init(JitCompContext *cc, uint32 mem_idx, uint32 seg_idx)
return false;
}
+static void
+wasm_data_drop(WASMModuleInstance *inst, uint32 seg_idx)
+{
+ bh_bitmap_set_bit(inst->e->common.data_dropped, seg_idx);
+}
+
bool
jit_compile_op_data_drop(JitCompContext *cc, uint32 seg_idx)
{
- JitReg module = get_module_reg(cc->jit_frame);
- JitReg data_segments = jit_cc_new_reg_ptr(cc);
- JitReg data_segment = jit_cc_new_reg_ptr(cc);
+ JitReg args[2] = { 0 };
- GEN_INSN(LDPTR, data_segments, module,
- NEW_CONST(I32, offsetof(WASMModule, data_segments)));
- GEN_INSN(LDPTR, data_segment, data_segments,
- NEW_CONST(I32, seg_idx * sizeof(WASMDataSeg *)));
- GEN_INSN(STI32, NEW_CONST(I32, 0), data_segment,
- NEW_CONST(I32, offsetof(WASMDataSeg, data_length)));
+ args[0] = get_module_inst_reg(cc->jit_frame);
+ args[1] = NEW_CONST(I32, seg_idx);
- return true;
+ return jit_emit_callnative(cc, wasm_data_drop, 0, args,
+ sizeof(args) / sizeof(args[0]));
}
static int
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.c
index 03491e691b8..6a1e93edeee 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.c
@@ -298,7 +298,15 @@ jit_compile_op_i64_popcnt(JitCompContext *cc)
/* macros for integer binary operations (ibinop) */
+#if defined(__GNUC__)
+#define NO_SANITIZER_INTEGER \
+ __attribute__((no_sanitize("signed-integer-overflow")))
+#else
+#define NO_SANITIZER_INTEGER
+#endif
+
#define __DEF_BI_INT_CONST_OPS(bits, opname, op) \
+ NO_SANITIZER_INTEGER \
static int##bits do_i##bits##_const_##opname(int##bits lhs, int##bits rhs) \
{ \
return lhs op rhs; \
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.c
similarity index 86%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.c
index 9fb61931f2d..b8ed6a1d502 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.c
@@ -10,21 +10,22 @@
#include "../jit_frontend.h"
#if WASM_ENABLE_REF_TYPES != 0
+static void
+wasm_elem_drop(WASMModuleInstance *inst, uint32 tbl_seg_idx)
+{
+ bh_bitmap_set_bit(inst->e->common.elem_dropped, tbl_seg_idx);
+}
+
bool
jit_compile_op_elem_drop(JitCompContext *cc, uint32 tbl_seg_idx)
{
- JitReg module, tbl_segs;
+ JitReg args[2] = { 0 };
- module = get_module_reg(cc->jit_frame);
-
- tbl_segs = jit_cc_new_reg_ptr(cc);
- GEN_INSN(LDPTR, tbl_segs, module,
- NEW_CONST(I32, offsetof(WASMModule, table_segments)));
+ args[0] = get_module_inst_reg(cc->jit_frame);
+ args[1] = NEW_CONST(I32, tbl_seg_idx);
- GEN_INSN(STI32, NEW_CONST(I32, true), tbl_segs,
- NEW_CONST(I32, tbl_seg_idx * sizeof(WASMTableSeg)
- + offsetof(WASMTableSeg, is_dropped)));
- return true;
+ return jit_emit_callnative(cc, wasm_elem_drop, 0, args,
+ sizeof(args) / sizeof(args[0]));
}
bool
@@ -88,27 +89,34 @@ jit_compile_op_table_set(JitCompContext *cc, uint32 tbl_idx)
static int
wasm_init_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 elem_idx,
- uint32 dst, uint32 len, uint32 src)
+ uint32 dst_offset, uint32 len, uint32 src_offset)
{
WASMTableInstance *tbl;
uint32 tbl_sz;
WASMTableSeg *elem;
uint32 elem_len;
+ elem = inst->module->table_segments + elem_idx;
+ elem_len = elem->function_count;
+ if (offset_len_out_of_bounds(src_offset, len, elem_len))
+ goto out_of_bounds;
+
tbl = inst->tables[tbl_idx];
tbl_sz = tbl->cur_size;
- if (dst > tbl_sz || tbl_sz - dst < len)
+ if (offset_len_out_of_bounds(dst_offset, len, tbl_sz))
goto out_of_bounds;
- elem = inst->module->table_segments + elem_idx;
- elem_len = elem->function_count;
- if (src > elem_len || elem_len - src < len)
+ 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 * sizeof(uint32),
- (uint32)((tbl_sz - dst) * sizeof(uint32)),
- elem->func_indexes + src, (uint32)(len * sizeof(uint32)));
+ + dst_offset * sizeof(uint32),
+ (uint32)((tbl_sz - dst_offset) * sizeof(uint32)),
+ elem->func_indexes + src_offset,
+ (uint32)(len * sizeof(uint32)));
return 0;
out_of_bounds:
@@ -157,14 +165,14 @@ wasm_copy_table(WASMModuleInstance *inst, uint32 src_tbl_idx,
WASMTableInstance *src_tbl, *dst_tbl;
uint32 src_tbl_sz, dst_tbl_sz;
- src_tbl = inst->tables[src_tbl_idx];
- src_tbl_sz = src_tbl->cur_size;
- if (src_offset > src_tbl_sz || src_tbl_sz - src_offset < len)
- goto out_of_bounds;
-
dst_tbl = inst->tables[dst_tbl_idx];
dst_tbl_sz = dst_tbl->cur_size;
- if (dst_offset > dst_tbl_sz || dst_tbl_sz - dst_offset < len)
+ if (offset_len_out_of_bounds(dst_offset, len, dst_tbl_sz))
+ goto out_of_bounds;
+
+ src_tbl = inst->tables[src_tbl_idx];
+ src_tbl_sz = src_tbl->cur_size;
+ if (offset_len_out_of_bounds(src_offset, len, src_tbl_sz))
goto out_of_bounds;
bh_memmove_s((uint8 *)dst_tbl + offsetof(WASMTableInstance, elems)
@@ -263,7 +271,7 @@ jit_compile_op_table_grow(JitCompContext *cc, uint32 tbl_idx)
}
static int
-wasm_fill_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 dst,
+wasm_fill_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 dst_offset,
uint32 val, uint32 len)
{
WASMTableInstance *tbl;
@@ -272,11 +280,11 @@ wasm_fill_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 dst,
tbl = inst->tables[tbl_idx];
tbl_sz = tbl->cur_size;
- if (dst > tbl_sz || tbl_sz - dst < len)
+ if (offset_len_out_of_bounds(dst_offset, len, tbl_sz))
goto out_of_bounds;
- for (; len != 0; dst++, len--) {
- tbl->elems[dst] = val;
+ for (; len != 0; dst_offset++, len--) {
+ tbl->elems[dst_offset] = val;
}
return 0;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/iwasm_fast_jit.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/iwasm_fast_jit.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/iwasm_fast_jit.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/iwasm_fast_jit.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.c
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.c
index 73a034f3497..ef207474780 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.c
@@ -17,8 +17,8 @@ jit_code_cache_init(uint32 code_cache_size)
int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC;
int map_flags = MMAP_MAP_NONE;
- if (!(code_cache_pool =
- os_mmap(NULL, code_cache_size, map_prot, map_flags))) {
+ if (!(code_cache_pool = os_mmap(NULL, code_cache_size, map_prot, map_flags,
+ os_get_invalid_handle()))) {
return false;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.h
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.h
index 9a49cffdd1a..dee2631d14a 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.h
@@ -70,6 +70,7 @@ typedef struct JitInterpSwitchInfo {
typedef struct JitCompOptions {
uint32 code_cache_size;
uint32 opt_level;
+ bool linux_perf_support;
} JitCompOptions;
bool
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.c
similarity index 86%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.c
index ec68ad91d8e..c9c22e0adf3 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.c
@@ -218,42 +218,149 @@ get_aux_stack_bottom_reg(JitFrame *frame)
return frame->aux_stack_bottom_reg;
}
+#if WASM_ENABLE_SHARED_MEMORY != 0
+static bool
+is_shared_memory(WASMModule *module, uint32 mem_idx)
+{
+ WASMMemory *memory;
+ WASMMemoryImport *memory_import;
+ bool is_shared;
+
+ if (mem_idx < module->import_memory_count) {
+ memory_import = &(module->import_memories[mem_idx].u.memory);
+ is_shared = memory_import->flags & 0x02 ? true : false;
+ }
+ else {
+ memory = &module->memories[mem_idx - module->import_memory_count];
+ is_shared = memory->flags & 0x02 ? true : false;
+ }
+ return is_shared;
+}
+#endif
+
JitReg
-get_memory_data_reg(JitFrame *frame, uint32 mem_idx)
+get_memory_inst_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 memory_data_offset;
+ uint32 memory_inst_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memories_addr;
+ uint32 memories_offset;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].memory_inst)
+ return frame->memory_regs[mem_idx].memory_inst;
+
+ frame->memory_regs[mem_idx].memory_inst =
+ cc->memory_regs[mem_idx].memory_inst;
bh_assert(mem_idx == 0);
#if WASM_ENABLE_SHARED_MEMORY != 0
- uint32 memories_offset = (uint32)offsetof(WASMModuleInstance, memories);
- JitReg memories_addr = jit_cc_new_reg_ptr(cc);
- JitReg memories_0_addr = jit_cc_new_reg_ptr(cc);
- memory_data_offset = (uint32)offsetof(WASMMemoryInstance, memory_data);
- if (!frame->memory_regs[mem_idx].memory_data) {
- frame->memory_regs[mem_idx].memory_data =
- cc->memory_regs[mem_idx].memory_data;
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memories_addr = jit_cc_new_reg_ptr(cc);
+ memories_offset = (uint32)offsetof(WASMModuleInstance, memories);
/* module_inst->memories */
GEN_INSN(LDPTR, memories_addr, module_inst_reg,
NEW_CONST(I32, memories_offset));
- /* module_inst->memories[0] */
- GEN_INSN(LDPTR, memories_0_addr, memories_addr, NEW_CONST(I32, 0));
- /* memories[0]->memory_data */
+ /* module_inst->memories[mem_idx], mem_idx can only be 0 now */
+ GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_inst, memories_addr,
+ NEW_CONST(I32, mem_idx));
+ }
+ else
+#endif
+ {
+ memory_inst_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes);
+ GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_inst,
+ module_inst_reg, NEW_CONST(I32, memory_inst_offset));
+ }
+
+ return frame->memory_regs[mem_idx].memory_inst;
+}
+
+JitReg
+get_cur_page_count_reg(JitFrame *frame, uint32 mem_idx)
+{
+ JitCompContext *cc = frame->cc;
+ JitReg module_inst_reg;
+ uint32 cur_page_count_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].cur_page_count)
+ return frame->memory_regs[mem_idx].cur_page_count;
+
+ frame->memory_regs[mem_idx].cur_page_count =
+ cc->memory_regs[mem_idx].cur_page_count;
+
+ /* Get current page count */
+ bh_assert(mem_idx == 0);
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ cur_page_count_offset =
+ (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+ /* memories[mem_idx]->cur_page_count_offset */
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].cur_page_count,
+ memory_inst_reg, NEW_CONST(I32, cur_page_count_offset));
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ cur_page_count_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, cur_page_count);
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].cur_page_count,
+ module_inst_reg, NEW_CONST(I32, cur_page_count_offset));
+ }
+
+ return frame->memory_regs[mem_idx].cur_page_count;
+}
+
+JitReg
+get_memory_data_reg(JitFrame *frame, uint32 mem_idx)
+{
+ JitCompContext *cc = frame->cc;
+ JitReg module_inst_reg;
+ uint32 memory_data_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].memory_data)
+ return frame->memory_regs[mem_idx].memory_data;
+
+ frame->memory_regs[mem_idx].memory_data =
+ cc->memory_regs[mem_idx].memory_data;
+
+ bh_assert(mem_idx == 0);
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ memory_data_offset = (uint32)offsetof(WASMMemoryInstance, memory_data);
+ /* memories[mem_idx]->memory_data */
GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data,
- memories_0_addr, NEW_CONST(I32, memory_data_offset));
+ memory_inst_reg, NEW_CONST(I32, memory_data_offset));
}
-#else
- memory_data_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, memory_data);
- if (!frame->memory_regs[mem_idx].memory_data) {
- frame->memory_regs[mem_idx].memory_data =
- cc->memory_regs[mem_idx].memory_data;
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ memory_data_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, memory_data);
GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data,
module_inst_reg, NEW_CONST(I32, memory_data_offset));
}
-#endif
return frame->memory_regs[mem_idx].memory_data;
}
@@ -261,16 +368,37 @@ JitReg
get_memory_data_end_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
- JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 memory_data_end_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, memory_data_end);
+ JitReg module_inst_reg;
+ uint32 memory_data_end_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
- bh_assert(mem_idx == 0);
+ if (frame->memory_regs[mem_idx].memory_data_end)
+ return frame->memory_regs[mem_idx].memory_data_end;
+
+ frame->memory_regs[mem_idx].memory_data_end =
+ cc->memory_regs[mem_idx].memory_data_end;
- if (!frame->memory_regs[mem_idx].memory_data_end) {
- frame->memory_regs[mem_idx].memory_data_end =
- cc->memory_regs[mem_idx].memory_data_end;
+ bh_assert(mem_idx == 0);
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ memory_data_end_offset =
+ (uint32)offsetof(WASMMemoryInstance, memory_data_end);
+ /* memories[mem_idx]->memory_data_end */
+ GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data_end,
+ memory_inst_reg, NEW_CONST(I32, memory_data_end_offset));
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ memory_data_end_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, memory_data_end);
GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data_end,
module_inst_reg, NEW_CONST(I32, memory_data_end_offset));
}
@@ -281,16 +409,43 @@ JitReg
get_mem_bound_check_1byte_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
- JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 mem_bound_check_1byte_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte);
+ JitReg module_inst_reg;
+ uint32 mem_bound_check_1byte_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].mem_bound_check_1byte)
+ return frame->memory_regs[mem_idx].mem_bound_check_1byte;
+
+ frame->memory_regs[mem_idx].mem_bound_check_1byte =
+ cc->memory_regs[mem_idx].mem_bound_check_1byte;
bh_assert(mem_idx == 0);
- if (!frame->memory_regs[mem_idx].mem_bound_check_1byte) {
- frame->memory_regs[mem_idx].mem_bound_check_1byte =
- cc->memory_regs[mem_idx].mem_bound_check_1byte;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ mem_bound_check_1byte_offset =
+ (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte);
+ /* memories[mem_idx]->mem_bound_check_1byte */
+#if UINTPTR_MAX == UINT64_MAX
+ GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_1byte,
+ memory_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset));
+#else
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_1byte,
+ memory_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset));
+#endif
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ mem_bound_check_1byte_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte);
#if UINTPTR_MAX == UINT64_MAX
GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_1byte,
module_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset));
@@ -306,16 +461,45 @@ JitReg
get_mem_bound_check_2bytes_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
- JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 mem_bound_check_2bytes_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes);
+ JitReg module_inst_reg;
+ uint32 mem_bound_check_2bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].mem_bound_check_2bytes)
+ return frame->memory_regs[mem_idx].mem_bound_check_2bytes;
+
+ frame->memory_regs[mem_idx].mem_bound_check_2bytes =
+ cc->memory_regs[mem_idx].mem_bound_check_2bytes;
bh_assert(mem_idx == 0);
- if (!frame->memory_regs[mem_idx].mem_bound_check_2bytes) {
- frame->memory_regs[mem_idx].mem_bound_check_2bytes =
- cc->memory_regs[mem_idx].mem_bound_check_2bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ mem_bound_check_2bytes_offset =
+ (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes);
+ /* memories[mem_idx]->mem_bound_check_2bytes */
+#if UINTPTR_MAX == UINT64_MAX
+ GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_2bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_2bytes_offset));
+#else
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_2bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_2bytes_offset));
+#endif
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ mem_bound_check_2bytes_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes);
#if UINTPTR_MAX == UINT64_MAX
GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_2bytes,
module_inst_reg,
@@ -333,16 +517,45 @@ JitReg
get_mem_bound_check_4bytes_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
- JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 mem_bound_check_4bytes_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes);
+ JitReg module_inst_reg;
+ uint32 mem_bound_check_4bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].mem_bound_check_4bytes)
+ return frame->memory_regs[mem_idx].mem_bound_check_4bytes;
+
+ frame->memory_regs[mem_idx].mem_bound_check_4bytes =
+ cc->memory_regs[mem_idx].mem_bound_check_4bytes;
bh_assert(mem_idx == 0);
- if (!frame->memory_regs[mem_idx].mem_bound_check_4bytes) {
- frame->memory_regs[mem_idx].mem_bound_check_4bytes =
- cc->memory_regs[mem_idx].mem_bound_check_4bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ mem_bound_check_4bytes_offset =
+ (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes);
+ /* memories[mem_idx]->mem_bound_check_4bytes */
+#if UINTPTR_MAX == UINT64_MAX
+ GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_4bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_4bytes_offset));
+#else
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_4bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_4bytes_offset));
+#endif
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ mem_bound_check_4bytes_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes);
#if UINTPTR_MAX == UINT64_MAX
GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_4bytes,
module_inst_reg,
@@ -360,16 +573,45 @@ JitReg
get_mem_bound_check_8bytes_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
- JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 mem_bound_check_8bytes_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes);
+ JitReg module_inst_reg;
+ uint32 mem_bound_check_8bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].mem_bound_check_8bytes)
+ return frame->memory_regs[mem_idx].mem_bound_check_8bytes;
+
+ frame->memory_regs[mem_idx].mem_bound_check_8bytes =
+ cc->memory_regs[mem_idx].mem_bound_check_8bytes;
bh_assert(mem_idx == 0);
- if (!frame->memory_regs[mem_idx].mem_bound_check_8bytes) {
- frame->memory_regs[mem_idx].mem_bound_check_8bytes =
- cc->memory_regs[mem_idx].mem_bound_check_8bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ mem_bound_check_8bytes_offset =
+ (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes);
+ /* memories[mem_idx]->mem_bound_check_8bytes */
+#if UINTPTR_MAX == UINT64_MAX
+ GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_8bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_8bytes_offset));
+#else
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_8bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_8bytes_offset));
+#endif
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ mem_bound_check_8bytes_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes);
#if UINTPTR_MAX == UINT64_MAX
GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_8bytes,
module_inst_reg,
@@ -387,16 +629,45 @@ JitReg
get_mem_bound_check_16bytes_reg(JitFrame *frame, uint32 mem_idx)
{
JitCompContext *cc = frame->cc;
- JitReg module_inst_reg = get_module_inst_reg(frame);
- uint32 mem_bound_check_16bytes_offset =
- (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
- + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes);
+ JitReg module_inst_reg;
+ uint32 mem_bound_check_16bytes_offset;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ JitReg memory_inst_reg;
+ bool is_shared;
+#endif
+
+ if (frame->memory_regs[mem_idx].mem_bound_check_16bytes)
+ return frame->memory_regs[mem_idx].mem_bound_check_16bytes;
+
+ frame->memory_regs[mem_idx].mem_bound_check_16bytes =
+ cc->memory_regs[mem_idx].mem_bound_check_16bytes;
bh_assert(mem_idx == 0);
- if (!frame->memory_regs[mem_idx].mem_bound_check_16bytes) {
- frame->memory_regs[mem_idx].mem_bound_check_16bytes =
- cc->memory_regs[mem_idx].mem_bound_check_16bytes;
+#if WASM_ENABLE_SHARED_MEMORY != 0
+ is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx);
+ if (is_shared) {
+ memory_inst_reg = get_memory_inst_reg(frame, mem_idx);
+ mem_bound_check_16bytes_offset =
+ (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes);
+ /* memories[mem_idx]->mem_bound_check_16bytes */
+#if UINTPTR_MAX == UINT64_MAX
+ GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_16bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_16bytes_offset));
+#else
+ GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_16bytes,
+ memory_inst_reg,
+ NEW_CONST(I32, mem_bound_check_16bytes_offset));
+#endif
+ }
+ else
+#endif
+ {
+ module_inst_reg = get_module_inst_reg(frame);
+ mem_bound_check_16bytes_offset =
+ (uint32)offsetof(WASMModuleInstance, global_table_data.bytes)
+ + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes);
#if UINTPTR_MAX == UINT64_MAX
GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_16bytes,
module_inst_reg,
@@ -462,6 +733,8 @@ clear_fixed_virtual_regs(JitFrame *frame)
count = module->import_memory_count + module->memory_count;
for (i = 0; i < count; i++) {
+ frame->memory_regs[i].memory_inst = 0;
+ frame->memory_regs[i].cur_page_count = 0;
frame->memory_regs[i].memory_data = 0;
frame->memory_regs[i].memory_data_end = 0;
frame->memory_regs[i].mem_bound_check_1byte = 0;
@@ -486,6 +759,7 @@ clear_memory_regs(JitFrame *frame)
count = module->import_memory_count + module->memory_count;
for (i = 0; i < count; i++) {
+ frame->memory_regs[i].cur_page_count = 0;
frame->memory_regs[i].memory_data = 0;
frame->memory_regs[i].memory_data_end = 0;
frame->memory_regs[i].mem_bound_check_1byte = 0;
@@ -654,6 +928,8 @@ create_fixed_virtual_regs(JitCompContext *cc)
}
for (i = 0; i < count; i++) {
+ cc->memory_regs[i].memory_inst = jit_cc_new_reg_ptr(cc);
+ cc->memory_regs[i].cur_page_count = jit_cc_new_reg_I32(cc);
cc->memory_regs[i].memory_data = jit_cc_new_reg_ptr(cc);
cc->memory_regs[i].memory_data_end = jit_cc_new_reg_ptr(cc);
cc->memory_regs[i].mem_bound_check_1byte = jit_cc_new_reg_ptr(cc);
@@ -2311,77 +2587,3 @@ jit_frontend_get_jitted_return_addr_offset()
{
return (uint32)offsetof(WASMInterpFrame, jitted_return_addr);
}
-
-#if 0
-#if WASM_ENABLE_THREAD_MGR != 0
-bool
-check_suspend_flags(JitCompContext *cc, JITFuncContext *func_ctx)
-{
- LLVMValueRef terminate_addr, terminate_flags, flag, offset, res;
- JitBasicBlock *terminate_check_block, non_terminate_block;
- JITFuncType *jit_func_type = func_ctx->jit_func->func_type;
- JitBasicBlock *terminate_block;
-
- /* Offset of suspend_flags */
- offset = I32_FIVE;
-
- if (!(terminate_addr = LLVMBuildInBoundsGEP(
- cc->builder, func_ctx->exec_env, &offset, 1, "terminate_addr"))) {
- jit_set_last_error("llvm build in bounds gep failed");
- return false;
- }
- if (!(terminate_addr =
- LLVMBuildBitCast(cc->builder, terminate_addr, INT32_PTR_TYPE,
- "terminate_addr_ptr"))) {
- jit_set_last_error("llvm build bit cast failed");
- return false;
- }
-
- if (!(terminate_flags =
- LLVMBuildLoad(cc->builder, terminate_addr, "terminate_flags"))) {
- jit_set_last_error("llvm build bit cast failed");
- return false;
- }
- /* Set terminate_flags memory accecc to volatile, so that the value
- will always be loaded from memory rather than register */
- LLVMSetVolatile(terminate_flags, true);
-
- CREATE_BASIC_BLOCK(terminate_check_block, "terminate_check");
- MOVE_BASIC_BLOCK_AFTER_CURR(terminate_check_block);
-
- CREATE_BASIC_BLOCK(non_terminate_block, "non_terminate");
- MOVE_BASIC_BLOCK_AFTER_CURR(non_terminate_block);
-
- BUILD_ICMP(LLVMIntSGT, terminate_flags, I32_ZERO, res, "need_terminate");
- BUILD_COND_BR(res, terminate_check_block, non_terminate_block);
-
- /* Move builder to terminate check block */
- SET_BUILDER_POS(terminate_check_block);
-
- CREATE_BASIC_BLOCK(terminate_block, "terminate");
- MOVE_BASIC_BLOCK_AFTER_CURR(terminate_block);
-
- if (!(flag = LLVMBuildAnd(cc->builder, terminate_flags, I32_ONE,
- "termination_flag"))) {
- jit_set_last_error("llvm build AND failed");
- return false;
- }
-
- BUILD_ICMP(LLVMIntSGT, flag, I32_ZERO, res, "need_terminate");
- BUILD_COND_BR(res, terminate_block, non_terminate_block);
-
- /* Move builder to terminate block */
- SET_BUILDER_POS(terminate_block);
- if (!jit_build_zero_function_ret(cc, func_ctx, jit_func_type)) {
- goto fail;
- }
-
- /* Move builder to terminate block */
- SET_BUILDER_POS(non_terminate_block);
- return true;
-
-fail:
- return false;
-}
-#endif /* End of WASM_ENABLE_THREAD_MGR */
-#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.h
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.h
index 7aa460fd9b3..9065d23ec89 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.h
@@ -192,6 +192,12 @@ get_aux_stack_bound_reg(JitFrame *frame);
JitReg
get_aux_stack_bottom_reg(JitFrame *frame);
+JitReg
+get_memory_inst_reg(JitFrame *frame, uint32 mem_idx);
+
+JitReg
+get_cur_page_count_reg(JitFrame *frame, uint32 mem_idx);
+
JitReg
get_memory_data_reg(JitFrame *frame, uint32 mem_idx);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.def b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.def
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.def
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.def
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.h
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.h
index e13a41d1d21..bef3fcc0c4b 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.h
@@ -866,6 +866,8 @@ typedef struct JitValueSlot {
typedef struct JitMemRegs {
/* The following registers should be re-loaded after
memory.grow, callbc and callnative */
+ JitReg memory_inst;
+ JitReg cur_page_count;
JitReg memory_data;
JitReg memory_data_end;
JitReg mem_bound_check_1byte;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_regalloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_regalloc.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_regalloc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_regalloc.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h
new file mode 100644
index 00000000000..a533c70bc6f
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef _JIT_UTILS_H_
+#define _JIT_UTILS_H_
+
+#include "bh_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline void *
+jit_malloc(unsigned int size)
+{
+ return wasm_runtime_malloc(size);
+}
+
+static inline void *
+jit_calloc(unsigned int size)
+{
+ void *ret = wasm_runtime_malloc(size);
+ if (ret) {
+ memset(ret, 0, size);
+ }
+ return ret;
+}
+
+static inline void
+jit_free(void *ptr)
+{
+ if (ptr)
+ wasm_runtime_free(ptr);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/aot_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/aot_export.h
similarity index 88%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/aot_export.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/aot_export.h
index e58873bfd8b..f2184033a54 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/aot_export.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/aot_export.h
@@ -26,8 +26,8 @@ void
aot_destroy_comp_data(aot_comp_data_t comp_data);
#if WASM_ENABLE_DEBUG_AOT != 0
-typedef void *dwar_extractor_handle_t;
-dwar_extractor_handle_t
+typedef void *dwarf_extractor_handle_t;
+dwarf_extractor_handle_t
create_dwarf_extractor(aot_comp_data_t comp_data, char *file_name);
#endif
@@ -38,6 +38,7 @@ enum {
AOT_LLVMIR_OPT_FILE,
};
+/* always sync it with AOTCompOption in compilation/aot_llvm.h */
typedef struct AOTCompOption {
bool is_jit_mode;
bool is_indirect_mode;
@@ -55,15 +56,21 @@ typedef struct AOTCompOption {
bool enable_aux_stack_frame;
bool disable_llvm_intrinsics;
bool disable_llvm_lto;
+ bool enable_llvm_pgo;
bool enable_stack_estimation;
+ char *use_prof_file;
uint32_t opt_level;
uint32_t size_level;
uint32_t output_format;
uint32_t bounds_checks;
uint32_t stack_bounds_checks;
+ uint32_t segue_flags;
+ bool linux_perf_support;
char **custom_sections;
uint32_t custom_sections_count;
const char *stack_usage_file;
+ const char *llvm_passes;
+ const char *builtin_intrinsics;
} AOTCompOption, *aot_comp_option_t;
bool
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/lib_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/lib_export.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/lib_export.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/lib_export.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_c_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_c_api.h
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_c_api.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_c_api.h
index 324a43bd52d..eaad941e45f 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_c_api.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_c_api.h
@@ -21,6 +21,15 @@
#endif
#endif
+#if defined(__GNUC__) || defined(__clang__)
+#define DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#define DEPRECATED __declspec(deprecated)
+#else
+#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
+#define DEPRECATED
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -136,31 +145,6 @@ static inline void wasm_name_new_from_string_nt(
WASM_DECLARE_OWN(config)
-WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
-
-// Embedders may provide custom functions for manipulating configs.
-
-
-// Engine
-
-WASM_DECLARE_OWN(engine)
-
-/**
- * Create a new engine
- *
- * Note: for the engine new/delete operations, including this,
- * wasm_engine_new_with_config, wasm_engine_new_with_args, and
- * wasm_engine_delete, if the platform has mutex initializer,
- * then they are thread-safe: we use a global lock to lock the
- * operations of the engine. Otherwise they are not thread-safe:
- * when there are engine new/delete operations happening
- * simultaneously in multiple threads, developer must create
- * the lock by himself, and add the lock when calling these
- * functions.
- */
-WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
-WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*);
-
#ifndef MEM_ALLOC_OPTION_DEFINED
#define MEM_ALLOC_OPTION_DEFINED
/* same definition from wasm_export.h */
@@ -191,9 +175,51 @@ typedef union MemAllocOption {
void *user_data;
} allocator;
} MemAllocOption;
-#endif
+#endif /* MEM_ALLOC_OPTION_DEFINED */
+
+/* Runtime configration */
+struct wasm_config_t {
+ mem_alloc_type_t mem_alloc_type;
+ MemAllocOption mem_alloc_option;
+ bool linux_perf_support;
+ /*TODO: wasi args*/
+};
+
+/*
+ * by default:
+ * - mem_alloc_type is Alloc_With_System_Allocator
+ * - mem_alloc_option is all 0
+ * - linux_perf_support is false
+ */
+WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
+
+// Embedders may provide custom functions for manipulating configs.
+WASM_API_EXTERN own wasm_config_t*
+wasm_config_set_mem_alloc_opt(wasm_config_t *, mem_alloc_type_t, MemAllocOption *);
-WASM_API_EXTERN own wasm_engine_t *
+WASM_API_EXTERN own wasm_config_t*
+wasm_config_set_linux_perf_opt(wasm_config_t *, bool);
+
+// Engine
+
+WASM_DECLARE_OWN(engine)
+
+/**
+ * Create a new engine
+ *
+ * Note: for the engine new/delete operations, including this,
+ * wasm_engine_new_with_config, wasm_engine_new_with_args, and
+ * wasm_engine_delete, if the platform has mutex initializer,
+ * then they are thread-safe: we use a global lock to lock the
+ * operations of the engine. Otherwise they are not thread-safe:
+ * when there are engine new/delete operations happening
+ * simultaneously in multiple threads, developer must create
+ * the lock by himself, and add the lock when calling these
+ * functions.
+ */
+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_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts);
// Store
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_export.h
similarity index 82%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_export.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_export.h
index f6c0107b9ff..d8e761e83e5 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_export.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_export.h
@@ -118,7 +118,7 @@ typedef union MemAllocOption {
void *realloc_func;
void *free_func;
/* allocator user data, only used when
- WASM_MEM_ALLOC_WITH_USER_DATA is defined */
+ WASM_MEM_ALLOC_WITH_USER_DATA is defined */
void *user_data;
} allocator;
} MemAllocOption;
@@ -149,7 +149,7 @@ typedef struct RuntimeInitArgs {
uint32_t n_native_symbols;
/* maximum thread number, only used when
- WASM_ENABLE_THREAD_MGR is defined */
+ WASM_ENABLE_THREAD_MGR is defined */
uint32_t max_thread_num;
/* Debug settings, only used when
@@ -167,6 +167,17 @@ typedef struct RuntimeInitArgs {
/* LLVM JIT opt and size level */
uint32_t llvm_jit_opt_level;
uint32_t llvm_jit_size_level;
+ /* Segue optimization flags for LLVM JIT */
+ uint32_t segue_flags;
+ /**
+ * If enabled
+ * - llvm-jit will output a jitdump file for `perf inject`
+ * - aot. TBD
+ * - fast-jit. TBD
+ * - multi-tier-jit. TBD
+ * - interpreter. TBD
+ */
+ bool linux_perf_support;
} RuntimeInitArgs;
#ifndef WASM_VALKIND_T_DEFINED
@@ -184,6 +195,7 @@ enum wasm_valkind_enum {
#ifndef WASM_VAL_T_DEFINED
#define WASM_VAL_T_DEFINED
+struct wasm_ref_t;
typedef struct wasm_val_t {
wasm_valkind_t kind;
@@ -195,6 +207,7 @@ typedef struct wasm_val_t {
double f64;
/* represent a foreign object, aka externref in .wat */
uintptr_t foreign;
+ struct wasm_ref_t *ref;
} of;
} wasm_val_t;
#endif
@@ -307,7 +320,8 @@ wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size);
/**
* Callback to load a module file into a buffer in multi-module feature
*/
-typedef bool (*module_reader)(const char *module_name,
+typedef bool (*module_reader)(package_type_t module_type,
+ const char *module_name,
uint8_t **p_buffer, uint32_t *p_size);
/**
@@ -419,6 +433,7 @@ wasm_runtime_get_module_hash(wasm_module_t module);
* @param dir_list The list of directories to preopen. (real path)
* @param dir_count The number of elements in dir_list.
* @param map_dir_list The list of directories to preopen. (mapped path)
+ * Format for each map entry: ::
* @param map_dir_count The number of elements in map_dir_list.
* If map_dir_count is smaller than dir_count,
* mapped path is assumed to be same as the
@@ -427,26 +442,31 @@ wasm_runtime_get_module_hash(wasm_module_t module);
* @param env_count The number of elements in env.
* @param argv The list of command line arguments.
* @param argc The number of elements in argv.
- * @param stdinfd The host file descriptor to back WASI STDIN_FILENO.
- * If -1 is specified, STDIN_FILENO is used.
- * @param stdoutfd The host file descriptor to back WASI STDOUT_FILENO.
- * If -1 is specified, STDOUT_FILENO is used.
- * @param stderrfd The host file descriptor to back WASI STDERR_FILENO.
- * If -1 is specified, STDERR_FILENO is used.
+ * @param stdin_handle The raw host handle to back WASI STDIN_FILENO.
+ * If an invalid handle is specified (e.g. -1 on POSIX,
+ * INVALID_HANDLE_VALUE on Windows), the platform default
+ * for STDIN is used.
+ * @param stdoutfd The raw host handle to back WASI STDOUT_FILENO.
+ * If an invalid handle is specified (e.g. -1 on POSIX,
+ * INVALID_HANDLE_VALUE on Windows), the platform default
+ * for STDOUT is used.
+ * @param stderrfd The raw host handle to back WASI STDERR_FILENO.
+ * If an invalid handle is specified (e.g. -1 on POSIX,
+ * INVALID_HANDLE_VALUE on Windows), the platform default
+ * for STDERR is used.
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_wasi_args_ex(wasm_module_t module,
const char *dir_list[], uint32_t dir_count,
const char *map_dir_list[], uint32_t map_dir_count,
const char *env[], uint32_t env_count,
- char *argv[], int argc,
- int stdinfd, int stdoutfd, int stderrfd);
+ char *argv[], int argc, int64_t stdinfd,
+ int64_t stdoutfd, int64_t stderrfd);
/**
* Set WASI parameters.
*
- * Same as wasm_runtime_set_wasi_args_ex with stdinfd = -1, stdoutfd = -1,
- * stderrfd = -1.
+ * Same as wasm_runtime_set_wasi_args_ex but with default stdio handles
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_wasi_args(wasm_module_t module,
@@ -861,6 +881,7 @@ wasm_application_execute_main(wasm_module_inst_t module_inst,
WASM_RUNTIME_API_EXTERN bool
wasm_application_execute_func(wasm_module_inst_t module_inst,
const char *name, int32_t argc, char *argv[]);
+
/**
* Get exception info of the WASM module instance.
*
@@ -890,6 +911,27 @@ wasm_runtime_set_exception(wasm_module_inst_t module_inst,
WASM_RUNTIME_API_EXTERN void
wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
+/**
+ * Terminate the WASM module instance.
+ *
+ * This function causes the module instance fail as if it raised a trap.
+ *
+ * This is intended to be used in situations like:
+ *
+ * - A thread is executing the WASM module instance
+ * (eg. it's in the middle of `wasm_application_execute_main`)
+ *
+ * - Another thread has a copy of `wasm_module_inst_t` of
+ * the module instance and wants to terminate it asynchronously.
+ *
+ * This function is provided only when WAMR is built with threading enabled.
+ * (`WASM_ENABLE_THREAD_MGR=1`)
+ *
+ * @param module_inst the WASM module instance
+ */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_terminate(wasm_module_inst_t module_inst);
+
/**
* Set custom data to WASM module instance.
* Note:
@@ -902,6 +944,7 @@ wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
void *custom_data);
+
/**
* Get the custom data within a WASM module instance.
*
@@ -912,6 +955,26 @@ wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
+/**
+ * Set the memory bounds checks flag of a WASM module instance.
+ *
+ * @param module_inst the WASM module instance
+ * @param enable the flag to enable/disable the memory bounds checks
+ */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_bounds_checks(wasm_module_inst_t module_inst,
+ bool enable);
+
+/**
+ * Check if the memory bounds checks flag is enabled for a WASM module instance.
+ *
+ * @param module_inst the WASM module instance
+ * @return true if the memory bounds checks flag is enabled, false otherwise
+ */
+WASM_RUNTIME_API_EXTERN bool
+wasm_runtime_is_bounds_checks_enabled(
+ wasm_module_inst_t module_inst);
+
/**
* Allocate memory from the heap of WASM module instance
*
@@ -1269,6 +1332,33 @@ WASM_RUNTIME_API_EXTERN bool
wasm_externref_obj2ref(wasm_module_inst_t module_inst,
void *extern_obj, uint32_t *p_externref_idx);
+/**
+ * Delete external object registered by `wasm_externref_obj2ref`.
+ *
+ * @param module_inst the WASM module instance that the extern object
+ * belongs to
+ * @param extern_obj the external object to be deleted
+ *
+ * @return true if success, false otherwise
+ */
+WASM_RUNTIME_API_EXTERN bool
+wasm_externref_objdel(wasm_module_inst_t module_inst, void *extern_obj);
+
+/**
+ * Set cleanup callback to release external object.
+ *
+ * @param module_inst the WASM module instance that the extern object
+ * belongs to
+ * @param extern_obj the external object to which to set the
+ * `extern_obj_cleanup` cleanup callback.
+ * @param extern_obj_cleanup a callback to release `extern_obj`
+ *
+ * @return true if success, false otherwise
+ */
+WASM_RUNTIME_API_EXTERN bool
+wasm_externref_set_cleanup(wasm_module_inst_t module_inst, void *extern_obj,
+ void (*extern_obj_cleanup)(void *));
+
/**
* Retrieve the external object from an internal externref index
*
@@ -1329,6 +1419,30 @@ WASM_RUNTIME_API_EXTERN uint32_t
wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
uint32_t len);
+/**
+ * Get the size required to store the LLVM PGO profile data
+ *
+ * @param module_inst the WASM module instance
+ *
+ * @return size required to store the contents, 0 means error
+ */
+WASM_RUNTIME_API_EXTERN uint32_t
+wasm_runtime_get_pgo_prof_data_size(wasm_module_inst_t module_inst);
+
+/**
+ * Dump the LLVM PGO profile data to buffer
+ *
+ * @param module_inst the WASM module instance
+ * @param buf buffer to store the dumped content
+ * @param len length of the buffer
+ *
+ * @return bytes dumped to the buffer, 0 means error and data in buf
+ * may be invalid
+ */
+WASM_RUNTIME_API_EXTERN uint32_t
+wasm_runtime_dump_pgo_prof_data_to_buf(wasm_module_inst_t module_inst,
+ char *buf, uint32_t len);
+
/**
* Get a custom section by name
*
@@ -1351,20 +1465,151 @@ WASM_RUNTIME_API_EXTERN void
wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch);
/**
- * Check whether an import func `(import (func ...))` is linked or not
- * with runtime registered natvie functions
+ * Check whether an import func `(import (func ...))`
+ * is linked or not with runtime registered natvie functions
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_is_import_func_linked(const char *module_name,
const char *func_name);
/**
- * Check whether an import global `(import (global ...))` is linked or not
- * with runtime registered natvie globals
+ * Check whether an import global `(import (global ...))`
+ * is linked or not with runtime registered natvie globals
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_is_import_global_linked(const char *module_name,
const char *global_name);
+
+typedef enum {
+ INTERNAL_ERROR,
+ MAX_SIZE_REACHED,
+} enlarge_memory_error_reason_t;
+
+typedef void (*enlarge_memory_error_callback_t)(
+ uint32_t inc_page_count, uint64_t current_memory_size,
+ uint32_t memory_index, enlarge_memory_error_reason_t failure_reason,
+ wasm_module_inst_t instance, wasm_exec_env_t exec_env,
+ void* user_data);
+
+/**
+ * Setup callback invoked when memory.grow fails
+ */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_enlarge_mem_error_callback(
+ const enlarge_memory_error_callback_t callback, void *user_data);
+
+/*
+ * module instance context APIs
+ * wasm_runtime_create_context_key
+ * wasm_runtime_destroy_context_key
+ * wasm_runtime_set_context
+ * wasm_runtime_set_context_spread
+ * wasm_runtime_get_context
+ *
+ * This set of APIs is intended to be used by an embedder which provides
+ * extra sets of native functions, which need per module instance state
+ * and are maintained outside of the WAMR tree.
+ *
+ * It's modelled after the pthread specific API.
+ *
+ * wasm_runtime_set_context_spread is similar to
+ * wasm_runtime_set_context, except that
+ * wasm_runtime_set_context_spread applies the change
+ * to all threads in the cluster.
+ * It's an undefined behavior if multiple threads in a cluster call
+ * wasm_runtime_set_context_spread on the same key
+ * simultaneously. It's a caller's resposibility to perform necessary
+ * serialization if necessary. For example:
+ *
+ * if (wasm_runtime_get_context(inst, key) == NULL) {
+ * newctx = alloc_and_init(...);
+ * lock(some_lock);
+ * if (wasm_runtime_get_context(inst, key) == NULL) {
+ * // this thread won the race
+ * wasm_runtime_set_context_spread(inst, key, newctx);
+ * newctx = NULL;
+ * }
+ * unlock(some_lock);
+ * if (newctx != NULL) {
+ * // this thread lost the race, free it
+ * cleanup_and_free(newctx);
+ * }
+ * }
+ *
+ * Note: dynamic key create/destroy while instances are live is not
+ * implemented as of writing this.
+ * it's caller's resposibility to ensure destorying all module instances
+ * before calling wasm_runtime_create_context_key or
+ * wasm_runtime_destroy_context_key.
+ * otherwise, it's an undefined behavior.
+ *
+ * Note about threads:
+ * - When spawning a thread, the contexts (the pointers given to
+ * wasm_runtime_set_context) are copied from the parent
+ * instance.
+ * - The destructor is called only on the main instance.
+ */
+
+WASM_RUNTIME_API_EXTERN void *
+wasm_runtime_create_context_key(
+ void (*dtor)(wasm_module_inst_t inst, void *ctx));
+
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_destroy_context_key(void *key);
+
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_context(wasm_module_inst_t inst, void *key, void *ctx);
+
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, void *ctx);
+
+WASM_RUNTIME_API_EXTERN void *
+wasm_runtime_get_context(wasm_module_inst_t inst, void *key);
+
+/*
+ * wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op
+ *
+ * These APIs are intended to be used by the implementations of
+ * host functions. It wraps an operation which possibly blocks for long
+ * to prepare for async termination.
+ *
+ * eg.
+ *
+ * if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ * return EINTR;
+ * }
+ * ret = possibly_blocking_op();
+ * wasm_runtime_end_blocking_op(exec_env);
+ * return ret;
+ *
+ * If threading support (WASM_ENABLE_THREAD_MGR) is not enabled,
+ * these functions are no-op.
+ *
+ * If the underlying platform support (OS_ENABLE_WAKEUP_BLOCKING_OP) is
+ * not available, these functions are no-op. In that case, the runtime
+ * might not terminate a blocking thread in a timely manner.
+ *
+ * If the underlying platform support is available, it's used to wake up
+ * the thread for async termination. The expectation here is that a
+ * `os_wakeup_blocking_op` call makes the blocking operation
+ * (`possibly_blocking_op` in the above example) return in a timely manner.
+ *
+ * The actual wake up mechanism used by `os_wakeup_blocking_op` is
+ * platform-dependent. It might impose some platform-dependent restrictions
+ * on the implementation of the blocking opearation.
+ *
+ * For example, on POSIX-like platforms, a signal (by default SIGUSR1) is
+ * used. The signal delivery configurations (eg. signal handler, signal mask,
+ * etc) for the signal are set up by the runtime. You can change the signal
+ * to use for this purpose by calling os_set_signal_number_for_blocking_op
+ * before the runtime initialization.
+ */
+WASM_RUNTIME_API_EXTERN bool
+wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env);
+
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_end_blocking_op(wasm_exec_env_t exec_env);
+
/* clang-format on */
#ifdef __cplusplus
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/iwasm_interp.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/iwasm_interp.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/iwasm_interp.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/iwasm_interp.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm.h
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm.h
index 0797a018b88..ee537aa63b2 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm.h
@@ -311,7 +311,6 @@ typedef struct WASMTableSeg {
uint32 mode;
/* funcref or externref, elemkind will be considered as funcref */
uint32 elem_type;
- bool is_dropped;
/* optional, only for active */
uint32 table_index;
InitializerExpression base_offset;
@@ -350,7 +349,7 @@ typedef struct WASIArguments {
uint32 ns_lookup_count;
char **argv;
uint32 argc;
- int stdio[3];
+ os_raw_file_handle stdio[3];
} WASIArguments;
#endif
@@ -627,7 +626,6 @@ typedef struct WASMBranchBlock {
uint32 cell_num;
} WASMBranchBlock;
-/* Execution environment, e.g. stack info */
/**
* Align an unsigned value on a alignment boundary.
*
@@ -643,6 +641,24 @@ align_uint(unsigned v, unsigned b)
return (v + m) & ~m;
}
+/**
+ * Check whether a piece of data is out of range
+ *
+ * @param offset the offset that the data starts
+ * @param len the length of the data
+ * @param max_size the maximum size of the data range
+ *
+ * @return true if out of range, false otherwise
+ */
+inline static bool
+offset_len_out_of_bounds(uint32 offset, uint32 len, uint32 max_size)
+{
+ if (offset + len < offset /* integer overflow */
+ || offset + len > max_size)
+ return true;
+ return false;
+}
+
/**
* Return the hash value of c string.
*/
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_classic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_classic.c
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_classic.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_classic.c
index 4cc47014335..e27b16544f2 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_classic.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_classic.c
@@ -36,31 +36,33 @@ typedef float64 CellType_F64;
* multi-threading mode since it may be changed by other
* threads in memory.grow
*/
-#define get_linear_mem_size() memory->memory_data_size
+#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory)
#endif
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
-#define CHECK_MEMORY_OVERFLOW(bytes) \
- do { \
- uint64 offset1 = (uint64)offset + (uint64)addr; \
- if (offset1 + bytes <= (uint64)get_linear_mem_size()) \
- /* If offset1 is in valid range, maddr must also \
- be in valid range, no need to check it again. */ \
- maddr = memory->memory_data + offset1; \
- else \
- goto out_of_bounds; \
+#define CHECK_MEMORY_OVERFLOW(bytes) \
+ do { \
+ uint64 offset1 = (uint64)offset + (uint64)addr; \
+ if (disable_bounds_checks \
+ || offset1 + bytes <= (uint64)get_linear_mem_size()) \
+ /* If offset1 is in valid range, maddr must also \
+ be in valid range, no need to check it again. */ \
+ maddr = memory->memory_data + offset1; \
+ else \
+ goto out_of_bounds; \
} while (0)
-#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
- do { \
- uint64 offset1 = (uint32)(start); \
- if (offset1 + bytes <= (uint64)get_linear_mem_size()) \
- /* App heap space is not valid space for \
- bulk memory operation */ \
- maddr = memory->memory_data + offset1; \
- else \
- goto out_of_bounds; \
+#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
+ do { \
+ uint64 offset1 = (uint32)(start); \
+ if (disable_bounds_checks \
+ || offset1 + bytes <= (uint64)get_linear_mem_size()) \
+ /* App heap space is not valid space for \
+ bulk memory operation */ \
+ maddr = memory->memory_data + offset1; \
+ else \
+ goto out_of_bounds; \
} while (0)
#else
#define CHECK_MEMORY_OVERFLOW(bytes) \
@@ -708,28 +710,28 @@ trunc_f64_to_int(WASMModuleInstance *module, uint32 *frame_sp, float64 src_min,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint32)(*(uint8 *)maddr); \
*(uint8 *)maddr = (uint8)(readv op sval); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else if (opcode == WASM_OP_ATOMIC_RMW_I32_##OP_NAME##16_U) { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint32)LOAD_U16(maddr); \
STORE_U16(maddr, (uint16)(readv op sval)); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = LOAD_I32(maddr); \
STORE_U32(maddr, readv op sval); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
PUSH_I32(readv); \
break; \
@@ -748,39 +750,39 @@ trunc_f64_to_int(WASMModuleInstance *module, uint32 *frame_sp, float64 src_min,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)(*(uint8 *)maddr); \
*(uint8 *)maddr = (uint8)(readv op sval); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##16_U) { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)LOAD_U16(maddr); \
STORE_U16(maddr, (uint16)(readv op sval)); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##32_U) { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)LOAD_U32(maddr); \
STORE_U32(maddr, (uint32)(readv op sval)); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else { \
uint64 op_result; \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)LOAD_I64(maddr); \
op_result = readv op sval; \
STORE_I64(maddr, op_result); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
PUSH_I64(readv); \
break; \
@@ -903,8 +905,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
if (!func_import->call_conv_wasm_c_api) {
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
}
- else if (module_inst->e->c_api_func_imports) {
- c_api_func_import = module_inst->e->c_api_func_imports + cur_func_index;
+ else if (module_inst->e->common.c_api_func_imports) {
+ c_api_func_import =
+ module_inst->e->common.c_api_func_imports + cur_func_index;
native_func_pointer = c_api_func_import->func_ptr_linked;
}
@@ -1010,7 +1013,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
}
/* - module_inst */
- exec_env->module_inst = (WASMModuleInstanceCommon *)sub_module_inst;
+ wasm_exec_env_set_module_inst(exec_env,
+ (WASMModuleInstanceCommon *)sub_module_inst);
/* - aux_stack_boundary */
aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary;
exec_env->aux_stack_boundary.boundary =
@@ -1032,15 +1036,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
prev_frame->ip = ip;
exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
-
- /* transfer exception if it is thrown */
- if (wasm_copy_exception(sub_module_inst, NULL)) {
- bh_memcpy_s(module_inst->cur_exception,
- sizeof(module_inst->cur_exception),
- sub_module_inst->cur_exception,
- sizeof(sub_module_inst->cur_exception));
- }
+ wasm_exec_env_restore_module_inst(exec_env,
+ (WASMModuleInstanceCommon *)module_inst);
}
#endif
@@ -1060,21 +1057,33 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
os_mutex_unlock(&exec_env->wait_lock); \
} while (0)
#else
-#define CHECK_SUSPEND_FLAGS() \
- do { \
- os_mutex_lock(&exec_env->wait_lock); \
- if (exec_env->suspend_flags.flags != 0) { \
- if (exec_env->suspend_flags.flags & 0x01) { \
- /* terminate current thread */ \
- os_mutex_unlock(&exec_env->wait_lock); \
- return; \
- } \
- while (exec_env->suspend_flags.flags & 0x02) { \
- /* suspend current thread */ \
- os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock); \
- } \
- } \
- os_mutex_unlock(&exec_env->wait_lock); \
+#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0
+/* The lock is only needed when the suspend_flags is atomic; otherwise
+ the lock is already taken at the time when SUSPENSION_LOCK() is called. */
+#define SUSPENSION_LOCK() os_mutex_lock(&exec_env->wait_lock);
+#define SUSPENSION_UNLOCK() os_mutex_unlock(&exec_env->wait_lock);
+#else
+#define SUSPENSION_LOCK()
+#define SUSPENSION_UNLOCK()
+#endif
+
+#define CHECK_SUSPEND_FLAGS() \
+ do { \
+ WASM_SUSPEND_FLAGS_LOCK(exec_env->wait_lock); \
+ if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \
+ & WASM_SUSPEND_FLAG_TERMINATE) { \
+ /* terminate current thread */ \
+ WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \
+ return; \
+ } \
+ while (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \
+ & WASM_SUSPEND_FLAG_SUSPEND) { \
+ /* suspend current thread */ \
+ SUSPENSION_LOCK() \
+ os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock); \
+ SUSPENSION_UNLOCK() \
+ } \
+ WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \
} while (0)
#endif /* WASM_ENABLE_DEBUG_INTERP */
#endif /* WASM_ENABLE_THREAD_MGR */
@@ -1142,15 +1151,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
WASMFunctionInstance *cur_func,
WASMInterpFrame *prev_frame)
{
-#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *node =
- wasm_module_get_shared_memory((WASMModuleCommon *)module->module);
-#endif
WASMMemoryInstance *memory = wasm_get_default_memory(module);
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
- uint32 linear_mem_size = memory ? memory->memory_data_size : 0;
+ uint32 linear_mem_size = 0;
+ if (memory)
+#if WASM_ENABLE_THREAD_MGR == 0
+ linear_mem_size = memory->memory_data_size;
+#else
+ linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
+#endif
#endif
WASMType **wasm_types = module->module->types;
WASMGlobalInstance *globals = module->e->globals, *global;
@@ -1174,6 +1185,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint8 local_type, *global_addr;
uint32 cache_index, type_index, param_cell_num, cell_num;
uint8 value_type;
+#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
+ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
+#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
+ bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled(
+ (WASMModuleInstanceCommon *)module);
+#else
+ bool disable_bounds_checks = false;
+#endif
+#endif
#if WASM_ENABLE_DEBUG_INTERP != 0
uint8 *frame_ip_orig = NULL;
@@ -1398,6 +1418,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
while (node_cache) {
node_next = bh_list_elem_next(node_cache);
if (node_cache->br_table_op_addr == frame_ip - 1) {
+ if (lidx > node_cache->br_count)
+ lidx = node_cache->br_count;
depth = node_cache->br_depths[lidx];
goto label_pop_csp_n;
}
@@ -2127,7 +2149,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
}
@@ -3132,7 +3154,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
addr = (uint32)POP_I32();
#if WASM_ENABLE_THREAD_MGR != 0
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -3144,9 +3166,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
maddr = memory->memory_data + (uint32)addr;
#endif
- seg_len = (uint64)module->module->data_segments[segment]
- ->data_length;
- data = module->module->data_segments[segment]->data;
+ if (bh_bitmap_get_bit(module->e->common.data_dropped,
+ segment)) {
+ seg_len = 0;
+ data = NULL;
+ }
+ else {
+ seg_len =
+ (uint64)module->module->data_segments[segment]
+ ->data_length;
+ data = module->module->data_segments[segment]->data;
+ }
if (offset + bytes > seg_len)
goto out_of_bounds;
@@ -3159,7 +3189,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint32 segment;
read_leb_uint32(frame_ip, frame_ip_end, segment);
- module->module->data_segments[segment]->data_length = 0;
+ bh_bitmap_set_bit(module->e->common.data_dropped,
+ segment);
break;
}
case WASM_OP_MEMORY_COPY:
@@ -3174,7 +3205,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
dst = POP_I32();
#if WASM_ENABLE_THREAD_MGR != 0
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -3205,7 +3236,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
dst = POP_I32();
#if WASM_ENABLE_THREAD_MGR != 0
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -3224,7 +3255,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
case WASM_OP_TABLE_INIT:
{
uint32 tbl_idx, elem_idx;
- uint64 n, s, d;
+ uint32 n, s, d;
WASMTableInstance *tbl_inst;
read_leb_uint32(frame_ip, frame_ip_end, elem_idx);
@@ -3239,22 +3270,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
s = (uint32)POP_I32();
d = (uint32)POP_I32();
- /* TODO: what if the element is not passive? */
-
- if (!n) {
- break;
- }
-
- if (n + s > module->module->table_segments[elem_idx]
- .function_count
- || d + n > tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(
+ s, n,
+ module->module->table_segments[elem_idx]
+ .function_count)
+ || offset_len_out_of_bounds(d, n,
+ tbl_inst->cur_size)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
}
- if (module->module->table_segments[elem_idx]
- .is_dropped) {
+ if (!n) {
+ 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;
@@ -3286,14 +3318,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
read_leb_uint32(frame_ip, frame_ip_end, elem_idx);
bh_assert(elem_idx < module->module->table_seg_count);
- module->module->table_segments[elem_idx].is_dropped =
- true;
+ bh_bitmap_set_bit(module->e->common.elem_dropped,
+ elem_idx);
break;
}
case WASM_OP_TABLE_COPY:
{
uint32 src_tbl_idx, dst_tbl_idx;
- uint64 n, s, d;
+ uint32 n, s, d;
WASMTableInstance *src_tbl_inst, *dst_tbl_inst;
read_leb_uint32(frame_ip, frame_ip_end, dst_tbl_idx);
@@ -3310,8 +3342,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
s = (uint32)POP_I32();
d = (uint32)POP_I32();
- if (d + n > dst_tbl_inst->cur_size
- || s + n > src_tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(d, n,
+ dst_tbl_inst->cur_size)
+ || offset_len_out_of_bounds(
+ s, n, src_tbl_inst->cur_size)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
@@ -3381,11 +3415,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
fill_val = POP_I32();
i = POP_I32();
- /* TODO: what if the element is not passive? */
- /* TODO: what if the element is dropped? */
-
- if (i + n > tbl_inst->cur_size) {
- /* TODO: verify warning content */
+ if (offset_len_out_of_bounds(i, n,
+ tbl_inst->cur_size)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
@@ -3503,23 +3534,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I32_LOAD8_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)(*(uint8 *)maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I32_LOAD16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)LOAD_U16(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = LOAD_I32(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I32(readv);
@@ -3538,30 +3569,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I64_LOAD8_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)(*(uint8 *)maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_LOAD16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U16(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_LOAD32_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U32(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = LOAD_I64(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I64(readv);
@@ -3580,23 +3611,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I32_STORE8) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
*(uint8 *)maddr = (uint8)sval;
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I32_STORE16) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U16(maddr, (uint16)sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U32(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
break;
}
@@ -3614,30 +3645,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I64_STORE8) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
*(uint8 *)maddr = (uint8)sval;
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_STORE16) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U16(maddr, (uint16)sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_STORE32) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U32(maddr, (uint32)sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
PUT_I64_TO_ADDR((uint32 *)maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
break;
}
@@ -3657,32 +3688,32 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_ATOMIC_MEMORY_ACCESS();
expect = (uint8)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)(*(uint8 *)maddr);
if (readv == expect)
*(uint8 *)maddr = (uint8)(sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_RMW_I32_CMPXCHG16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
expect = (uint16)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)LOAD_U16(maddr);
if (readv == expect)
STORE_U16(maddr, (uint16)(sval));
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = LOAD_I32(maddr);
if (readv == expect)
STORE_U32(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I32(readv);
break;
@@ -3703,43 +3734,43 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_ATOMIC_MEMORY_ACCESS();
expect = (uint8)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)(*(uint8 *)maddr);
if (readv == expect)
*(uint8 *)maddr = (uint8)(sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
expect = (uint16)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U16(maddr);
if (readv == expect)
STORE_U16(maddr, (uint16)(sval));
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG32_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
expect = (uint32)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U32(maddr);
if (readv == expect)
STORE_U32(maddr, (uint32)(sval));
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_I64(maddr);
if (readv == expect)
STORE_I64(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I64(readv);
break;
@@ -3772,7 +3803,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
HANDLE_OP(DEBUG_OP_BREAK)
{
wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TRAP);
- exec_env->suspend_flags.flags |= 2;
+ WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags,
+ WASM_SUSPEND_FLAG_SUSPEND);
frame_ip--;
SYNC_ALL_TO_FRAME();
CHECK_SUSPEND_FLAGS();
@@ -3881,7 +3913,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
if (memory)
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
if (wasm_copy_exception(module, NULL))
goto got_exception;
@@ -3986,6 +4018,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
}
#if WASM_ENABLE_FAST_JIT != 0
+/*
+ * ASAN is not designed to work with custom stack unwind or other low-level
+ * things. Ignore a function that does some low-level magic. (e.g. walking
+ * through the thread's stack bypassing the frame boundaries)
+ */
+#if defined(__GNUC__) || defined(__clang__)
+__attribute__((no_sanitize_address))
+#endif
static void
fast_jit_call_func_bytecode(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env,
@@ -4182,7 +4222,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
unsigned i;
bool copy_argv_from_frame = true;
- char exception[EXCEPTION_BUF_LEN];
if (argc < function->param_cell_num) {
char buf[128];
@@ -4225,6 +4264,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
wasm_exec_env_set_cur_frame(exec_env, frame);
+#if defined(os_writegsbase)
+ {
+ WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst);
+ if (memory_inst)
+ /* write base addr of linear memory to GS segment register */
+ os_writegsbase(memory_inst->memory_data);
+ }
+#endif
+
if (function->is_import_func) {
#if WASM_ENABLE_MULTI_MODULE != 0
if (function->import_module_inst) {
@@ -4306,8 +4354,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
}
#endif
- wasm_copy_exception(module_inst, exception);
- LOG_DEBUG("meet an exception %s", exception);
}
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_fast.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_fast.c
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_fast.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_fast.c
index 6ddeaa9c0e4..d3cebc334b3 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_fast.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_fast.c
@@ -27,7 +27,7 @@ typedef float64 CellType_F64;
* multi-threading mode since it may be changed by other
* threads in memory.grow
*/
-#define get_linear_mem_size() memory->memory_data_size
+#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory)
#endif
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
@@ -35,7 +35,8 @@ typedef float64 CellType_F64;
#define CHECK_MEMORY_OVERFLOW(bytes) \
do { \
uint64 offset1 = (uint64)offset + (uint64)addr; \
- if (offset1 + bytes <= (uint64)get_linear_mem_size()) \
+ if (disable_bounds_checks \
+ || offset1 + bytes <= (uint64)get_linear_mem_size()) \
/* If offset1 is in valid range, maddr must also \
be in valid range, no need to check it again. */ \
maddr = memory->memory_data + offset1; \
@@ -43,15 +44,15 @@ typedef float64 CellType_F64;
goto out_of_bounds; \
} while (0)
-#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
- do { \
- uint64 offset1 = (uint32)(start); \
- if (offset1 + bytes <= get_linear_mem_size()) \
- /* App heap space is not valid space for \
- bulk memory operation */ \
- maddr = memory->memory_data + offset1; \
- else \
- goto out_of_bounds; \
+#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
+ do { \
+ uint64 offset1 = (uint32)(start); \
+ if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \
+ /* App heap space is not valid space for \
+ bulk memory operation */ \
+ maddr = memory->memory_data + offset1; \
+ else \
+ goto out_of_bounds; \
} while (0)
#else
#define CHECK_MEMORY_OVERFLOW(bytes) \
@@ -481,28 +482,28 @@ LOAD_PTR(void *addr)
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(1); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint32)(*(uint8 *)maddr); \
*(uint8 *)maddr = (uint8)(readv op sval); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else if (opcode == WASM_OP_ATOMIC_RMW_I32_##OP_NAME##16_U) { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(2); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint32)LOAD_U16(maddr); \
STORE_U16(maddr, (uint16)(readv op sval)); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(4); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = LOAD_I32(maddr); \
STORE_U32(maddr, readv op sval); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
PUSH_I32(readv); \
break; \
@@ -521,39 +522,39 @@ LOAD_PTR(void *addr)
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(1); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)(*(uint8 *)maddr); \
*(uint8 *)maddr = (uint8)(readv op sval); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##16_U) { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(2); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)LOAD_U16(maddr); \
STORE_U16(maddr, (uint16)(readv op sval)); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##32_U) { \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(4); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)LOAD_U32(maddr); \
STORE_U32(maddr, (uint32)(readv op sval)); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
else { \
uint64 op_result; \
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); \
CHECK_ATOMIC_MEMORY_ACCESS(8); \
\
- os_mutex_lock(&node->shared_mem_lock); \
+ shared_memory_lock(memory); \
readv = (uint64)LOAD_I64(maddr); \
op_result = readv op sval; \
STORE_I64(maddr, op_result); \
- os_mutex_unlock(&node->shared_mem_lock); \
+ shared_memory_unlock(memory); \
} \
PUSH_I64(readv); \
break; \
@@ -937,8 +938,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
if (!func_import->call_conv_wasm_c_api) {
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
}
- else if (module_inst->e->c_api_func_imports) {
- c_api_func_import = module_inst->e->c_api_func_imports + cur_func_index;
+ else if (module_inst->e->common.c_api_func_imports) {
+ c_api_func_import =
+ module_inst->e->common.c_api_func_imports + cur_func_index;
native_func_pointer = c_api_func_import->func_ptr_linked;
}
@@ -1029,7 +1031,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
}
/* - module_inst */
- exec_env->module_inst = (WASMModuleInstanceCommon *)sub_module_inst;
+ wasm_exec_env_set_module_inst(exec_env,
+ (WASMModuleInstanceCommon *)sub_module_inst);
/* - aux_stack_boundary */
aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary;
exec_env->aux_stack_boundary.boundary =
@@ -1051,31 +1054,23 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
prev_frame->ip = ip;
exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
-
- /* transfer exception if it is thrown */
- if (wasm_copy_exception(sub_module_inst, NULL)) {
- bh_memcpy_s(module_inst->cur_exception,
- sizeof(module_inst->cur_exception),
- sub_module_inst->cur_exception,
- sizeof(sub_module_inst->cur_exception));
- }
+ wasm_exec_env_restore_module_inst(exec_env,
+ (WASMModuleInstanceCommon *)module_inst);
}
#endif
#if WASM_ENABLE_THREAD_MGR != 0
-#define CHECK_SUSPEND_FLAGS() \
- do { \
- os_mutex_lock(&exec_env->wait_lock); \
- if (exec_env->suspend_flags.flags != 0) { \
- if (exec_env->suspend_flags.flags & 0x01) { \
- /* terminate current thread */ \
- os_mutex_unlock(&exec_env->wait_lock); \
- return; \
- } \
- /* TODO: support suspend and breakpoint */ \
- } \
- os_mutex_unlock(&exec_env->wait_lock); \
+#define CHECK_SUSPEND_FLAGS() \
+ do { \
+ WASM_SUSPEND_FLAGS_LOCK(exec_env->wait_lock); \
+ if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \
+ & WASM_SUSPEND_FLAG_TERMINATE) { \
+ /* terminate current thread */ \
+ WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \
+ return; \
+ } \
+ /* TODO: support suspend and breakpoint */ \
+ WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \
} while (0)
#endif
@@ -1127,12 +1122,27 @@ wasm_interp_dump_op_count()
goto *p_label_addr; \
} while (0)
#else
-#define FETCH_OPCODE_AND_DISPATCH() \
- do { \
- const void *p_label_addr = label_base + *(int16 *)frame_ip; \
- frame_ip += sizeof(int16); \
- goto *p_label_addr; \
+#if UINTPTR_MAX == UINT64_MAX
+#define FETCH_OPCODE_AND_DISPATCH() \
+ do { \
+ const void *p_label_addr; \
+ bh_assert(((uintptr_t)frame_ip & 1) == 0); \
+ /* int32 relative offset was emitted in 64-bit target */ \
+ p_label_addr = label_base + (int32)LOAD_U32_WITH_2U16S(frame_ip); \
+ frame_ip += sizeof(int32); \
+ goto *p_label_addr; \
} while (0)
+#else
+#define FETCH_OPCODE_AND_DISPATCH() \
+ do { \
+ const void *p_label_addr; \
+ bh_assert(((uintptr_t)frame_ip & 1) == 0); \
+ /* uint32 label address was emitted in 32-bit target */ \
+ p_label_addr = (void *)(uintptr_t)LOAD_U32_WITH_2U16S(frame_ip); \
+ frame_ip += sizeof(int32); \
+ goto *p_label_addr; \
+ } while (0)
+#endif
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
#define HANDLE_OP_END() FETCH_OPCODE_AND_DISPATCH()
@@ -1166,15 +1176,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
WASMFunctionInstance *cur_func,
WASMInterpFrame *prev_frame)
{
-#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *node =
- wasm_module_get_shared_memory((WASMModuleCommon *)module->module);
-#endif
WASMMemoryInstance *memory = wasm_get_default_memory(module);
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
- uint32 linear_mem_size = memory ? memory->memory_data_size : 0;
+ uint32 linear_mem_size = 0;
+ if (memory)
+#if WASM_ENABLE_THREAD_MGR == 0
+ linear_mem_size = memory->memory_data_size;
+#else
+ linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
+#endif
#endif
WASMGlobalInstance *globals = module->e ? module->e->globals : NULL;
WASMGlobalInstance *global;
@@ -1186,7 +1198,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
register uint8 *frame_ip = &opcode_IMPDEP; /* cache of frame->ip */
register uint32 *frame_lp = NULL; /* cache of frame->lp */
#if WASM_ENABLE_LABELS_AS_VALUES != 0
-#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
+#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 && UINTPTR_MAX == UINT64_MAX
/* cache of label base addr */
register uint8 *label_base = &&HANDLE_WASM_OP_UNREACHABLE;
#endif
@@ -1199,6 +1211,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint8 *maddr = NULL;
uint32 local_idx, local_offset, global_idx;
uint8 opcode, local_type, *global_addr;
+#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
+ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
+#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
+ bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled(
+ (WASMModuleInstanceCommon *)module);
+#else
+ bool disable_bounds_checks = false;
+#endif
+#endif
#if WASM_ENABLE_LABELS_AS_VALUES != 0
#define HANDLE_OPCODE(op) &&HANDLE_##op
@@ -1896,7 +1917,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
}
@@ -2974,12 +2995,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
segment = read_uint32(frame_ip);
- bytes = (uint64)POP_I32();
- offset = (uint64)POP_I32();
+ bytes = (uint64)(uint32)POP_I32();
+ offset = (uint64)(uint32)POP_I32();
addr = POP_I32();
#if WASM_ENABLE_THREAD_MGR
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -2990,10 +3011,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
goto out_of_bounds;
maddr = memory->memory_data + (uint32)addr;
#endif
+ if (bh_bitmap_get_bit(module->e->common.data_dropped,
+ segment)) {
+ seg_len = 0;
+ data = NULL;
+ }
+ else {
- seg_len = (uint64)module->module->data_segments[segment]
- ->data_length;
- data = module->module->data_segments[segment]->data;
+ seg_len =
+ (uint64)module->module->data_segments[segment]
+ ->data_length;
+ data = module->module->data_segments[segment]->data;
+ }
if (offset + bytes > seg_len)
goto out_of_bounds;
@@ -3006,8 +3035,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint32 segment;
segment = read_uint32(frame_ip);
-
- module->module->data_segments[segment]->data_length = 0;
+ bh_bitmap_set_bit(module->e->common.data_dropped,
+ segment);
break;
}
case WASM_OP_MEMORY_COPY:
@@ -3020,7 +3049,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
dst = POP_I32();
#if WASM_ENABLE_THREAD_MGR
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -3050,7 +3079,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
dst = POP_I32();
#if WASM_ENABLE_THREAD_MGR
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
#ifndef OS_ENABLE_HW_BOUND_CHECK
@@ -3069,7 +3098,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
case WASM_OP_TABLE_INIT:
{
uint32 tbl_idx, elem_idx;
- uint64 n, s, d;
+ uint32 n, s, d;
WASMTableInstance *tbl_inst;
elem_idx = read_uint32(frame_ip);
@@ -3084,20 +3113,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
s = (uint32)POP_I32();
d = (uint32)POP_I32();
- if (!n) {
- break;
- }
-
- if (n + s > module->module->table_segments[elem_idx]
- .function_count
- || d + n > tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(
+ s, n,
+ module->module->table_segments[elem_idx]
+ .function_count)
+ || offset_len_out_of_bounds(d, n,
+ tbl_inst->cur_size)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
}
- if (module->module->table_segments[elem_idx]
- .is_dropped) {
+ if (!n) {
+ 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;
@@ -3126,15 +3158,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
{
uint32 elem_idx = read_uint32(frame_ip);
bh_assert(elem_idx < module->module->table_seg_count);
-
- module->module->table_segments[elem_idx].is_dropped =
- true;
+ bh_bitmap_set_bit(module->e->common.elem_dropped,
+ elem_idx);
break;
}
case WASM_OP_TABLE_COPY:
{
uint32 src_tbl_idx, dst_tbl_idx;
- uint64 n, s, d;
+ uint32 n, s, d;
WASMTableInstance *src_tbl_inst, *dst_tbl_inst;
dst_tbl_idx = read_uint32(frame_ip);
@@ -3151,8 +3182,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
s = (uint32)POP_I32();
d = (uint32)POP_I32();
- if (d + n > dst_tbl_inst->cur_size
- || s + n > src_tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(d, n,
+ dst_tbl_inst->cur_size)
+ || offset_len_out_of_bounds(
+ s, n, src_tbl_inst->cur_size)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
@@ -3223,7 +3256,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
fill_val = POP_I32();
i = POP_I32();
- if (i + n > tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(i, n,
+ tbl_inst->cur_size)) {
wasm_set_exception(module,
"out of bounds table access");
goto got_exception;
@@ -3338,23 +3372,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I32_LOAD8_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(1);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)(*(uint8 *)maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I32_LOAD16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)LOAD_U16(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = LOAD_I32(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I32(readv);
@@ -3373,30 +3407,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I64_LOAD8_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(1);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)(*(uint8 *)maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_LOAD16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U16(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_LOAD32_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U32(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(8);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = LOAD_I64(maddr);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I64(readv);
@@ -3414,23 +3448,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I32_STORE8) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(1);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
*(uint8 *)maddr = (uint8)sval;
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I32_STORE16) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U16(maddr, (uint16)sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U32(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
break;
}
@@ -3448,30 +3482,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (opcode == WASM_OP_ATOMIC_I64_STORE8) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(1);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
*(uint8 *)maddr = (uint8)sval;
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_STORE16) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U16(maddr, (uint16)sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_I64_STORE32) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_U32(maddr, (uint32)sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(8);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
STORE_I64(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
break;
}
@@ -3491,32 +3525,32 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_ATOMIC_MEMORY_ACCESS(1);
expect = (uint8)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)(*(uint8 *)maddr);
if (readv == expect)
*(uint8 *)maddr = (uint8)(sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_RMW_I32_CMPXCHG16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);
expect = (uint16)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint32)LOAD_U16(maddr);
if (readv == expect)
STORE_U16(maddr, (uint16)(sval));
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = LOAD_I32(maddr);
if (readv == expect)
STORE_U32(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I32(readv);
break;
@@ -3537,43 +3571,43 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_ATOMIC_MEMORY_ACCESS(1);
expect = (uint8)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)(*(uint8 *)maddr);
if (readv == expect)
*(uint8 *)maddr = (uint8)(sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG16_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);
expect = (uint16)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U16(maddr);
if (readv == expect)
STORE_U16(maddr, (uint16)(sval));
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG32_U) {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);
expect = (uint32)expect;
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_U32(maddr);
if (readv == expect)
STORE_U32(maddr, (uint32)(sval));
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
else {
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(8);
- os_mutex_lock(&node->shared_mem_lock);
+ shared_memory_lock(memory);
readv = (uint64)LOAD_I64(maddr);
if (readv == expect)
STORE_I64(maddr, sval);
- os_mutex_unlock(&node->shared_mem_lock);
+ shared_memory_unlock(memory);
}
PUSH_I64(readv);
break;
@@ -3820,7 +3854,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
if (memory)
- linear_mem_size = memory->memory_data_size;
+ linear_mem_size = get_linear_mem_size();
#endif
if (wasm_copy_exception(module, NULL))
goto got_exception;
@@ -3933,7 +3967,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
/* This frame won't be used by JITed code, so only allocate interp
frame here. */
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
- char exception[EXCEPTION_BUF_LEN];
if (argc < function->param_cell_num) {
char buf[128];
@@ -3979,6 +4012,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
wasm_exec_env_set_cur_frame(exec_env, frame);
+#if defined(os_writegsbase)
+ {
+ WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst);
+ if (memory_inst)
+ /* write base addr of linear memory to GS segment register */
+ os_writegsbase(memory_inst->memory_data);
+ }
+#endif
+
if (function->is_import_func) {
#if WASM_ENABLE_MULTI_MODULE != 0
if (function->import_module_inst) {
@@ -4009,8 +4051,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
}
#endif
- wasm_copy_exception(module_inst, exception);
- LOG_DEBUG("meet an exception %s", exception);
}
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.c
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.c
index a3c4f422490..2a06f42e36e 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.c
@@ -173,7 +173,6 @@ read_leb(uint8 **p_buf, const uint8 *buf_end, uint32 maxbits, bool sign,
#define read_uint8(p) TEMPLATE_READ_VALUE(uint8, p)
#define read_uint32(p) TEMPLATE_READ_VALUE(uint32, p)
-#define read_bool(p) TEMPLATE_READ_VALUE(bool, p)
#define read_leb_int64(p, p_end, res) \
do { \
@@ -302,7 +301,13 @@ check_utf8_str(const uint8 *str, uint32 len)
while (p < p_end) {
chr = *p;
- if (chr < 0x80) {
+
+ if (chr == 0) {
+ LOG_WARNING(
+ "LIMITATION: a string which contains '\\00' is unsupported");
+ return false;
+ }
+ else if (chr < 0x80) {
p++;
}
else if (chr >= 0xC2 && chr <= 0xDF && p + 1 < p_end) {
@@ -490,6 +495,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end,
if (type != VALUE_TYPE_V128)
goto fail_type_mismatch;
+ CHECK_BUF(p, p_end, 1);
flag = read_uint8(p);
(void)flag;
@@ -694,34 +700,10 @@ wasm_loader_find_export(const WASMModule *module, const char *module_name,
const char *field_name, uint8 export_kind,
char *error_buf, uint32 error_buf_size)
{
- WASMExport *export;
- uint32 i;
-
- for (i = 0, export = module->exports; i < module->export_count;
- ++i, ++export) {
- /**
- * need to consider a scenario that different kinds of exports
- * may have the same name, like
- * (table (export "m1" "exported") 10 funcref)
- * (memory (export "m1" "exported") 10)
- **/
- if (export->kind == export_kind && !strcmp(field_name, export->name)) {
- break;
- }
- }
-
- if (i == module->export_count) {
- LOG_DEBUG("can not find an export %d named %s in the module %s",
- export_kind, field_name, module_name);
- set_error_buf(error_buf, error_buf_size,
- "unknown import or incompatible import type");
- return NULL;
- }
-
- (void)module_name;
-
- /* since there is a validation in load_export_section(), it is for sure
- * export->index is valid*/
+ WASMExport *export =
+ loader_find_export((WASMModuleCommon *)module, module_name, field_name,
+ export_kind, error_buf, error_buf_size);
+ ;
return export;
}
#endif
@@ -912,152 +894,6 @@ wasm_loader_resolve_global(const char *module_name, const char *global_name,
return global;
}
-static WASMModule *
-search_sub_module(const WASMModule *parent_module, const char *sub_module_name)
-{
- WASMRegisteredModule *node =
- bh_list_first_elem(parent_module->import_module_list);
- while (node && strcmp(sub_module_name, node->module_name)) {
- node = bh_list_elem_next(node);
- }
- return node ? (WASMModule *)node->module : NULL;
-}
-
-static bool
-register_sub_module(const WASMModule *parent_module,
- const char *sub_module_name, WASMModule *sub_module)
-{
- /* register sub_module into its parent sub module list */
- WASMRegisteredModule *node = NULL;
- bh_list_status ret;
-
- if (search_sub_module(parent_module, sub_module_name)) {
- LOG_DEBUG("%s has been registered in its parent", sub_module_name);
- return true;
- }
-
- node = loader_malloc(sizeof(WASMRegisteredModule), NULL, 0);
- if (!node) {
- return false;
- }
-
- node->module_name = sub_module_name;
- node->module = (WASMModuleCommon *)sub_module;
- ret = bh_list_insert(parent_module->import_module_list, node);
- bh_assert(BH_LIST_SUCCESS == ret);
- (void)ret;
- return true;
-}
-
-static WASMModule *
-load_depended_module(const WASMModule *parent_module,
- const char *sub_module_name, char *error_buf,
- uint32 error_buf_size)
-{
- WASMModule *sub_module = NULL;
- bool ret = false;
- uint8 *buffer = NULL;
- uint32 buffer_size = 0;
- const module_reader reader = wasm_runtime_get_module_reader();
- const module_destroyer destroyer = wasm_runtime_get_module_destroyer();
-
- /* check the registered module list of the parent */
- sub_module = search_sub_module(parent_module, sub_module_name);
- if (sub_module) {
- LOG_DEBUG("%s has been loaded before", sub_module_name);
- return sub_module;
- }
-
- /* check the global registered module list */
- sub_module =
- (WASMModule *)wasm_runtime_find_module_registered(sub_module_name);
- if (sub_module) {
- LOG_DEBUG("%s has been loaded", sub_module_name);
- goto register_sub_module;
- }
-
- LOG_VERBOSE("loading %s", sub_module_name);
-
- if (!reader) {
- set_error_buf_v(error_buf, error_buf_size,
- "no sub module reader to load %s", sub_module_name);
- return NULL;
- }
-
- /* start to maintain a loading module list */
- ret = wasm_runtime_is_loading_module(sub_module_name);
- if (ret) {
- set_error_buf_v(error_buf, error_buf_size,
- "found circular dependency on %s", sub_module_name);
- return NULL;
- }
-
- ret = wasm_runtime_add_loading_module(sub_module_name, error_buf,
- error_buf_size);
- if (!ret) {
- LOG_DEBUG("can not add %s into loading module list\n", sub_module_name);
- return NULL;
- }
-
- ret = reader(sub_module_name, &buffer, &buffer_size);
- if (!ret) {
- LOG_DEBUG("read the file of %s failed", sub_module_name);
- set_error_buf_v(error_buf, error_buf_size, "unknown import",
- sub_module_name);
- goto delete_loading_module;
- }
-
- sub_module =
- wasm_loader_load(buffer, buffer_size, false, error_buf, error_buf_size);
- if (!sub_module) {
- LOG_DEBUG("error: can not load the sub_module %s", sub_module_name);
- /* others will be destroyed in runtime_destroy() */
- goto destroy_file_buffer;
- }
-
- wasm_runtime_delete_loading_module(sub_module_name);
-
- /* register on a global list */
- ret = wasm_runtime_register_module_internal(
- sub_module_name, (WASMModuleCommon *)sub_module, buffer, buffer_size,
- error_buf, error_buf_size);
- if (!ret) {
- LOG_DEBUG("error: can not register module %s globally\n",
- sub_module_name);
- /* others will be unloaded in runtime_destroy() */
- goto unload_module;
- }
-
- /* register into its parent list */
-register_sub_module:
- ret = register_sub_module(parent_module, sub_module_name, sub_module);
- if (!ret) {
- set_error_buf_v(error_buf, error_buf_size,
- "failed to register sub module %s", sub_module_name);
- /* since it is in the global module list, no need to
- * unload the module. the runtime_destroy() will do it
- */
- return NULL;
- }
-
- return sub_module;
-
-unload_module:
- wasm_loader_unload(sub_module);
-
-destroy_file_buffer:
- if (destroyer) {
- destroyer(buffer, buffer_size);
- }
- else {
- LOG_WARNING("need to release the reading buffer of %s manually",
- sub_module_name);
- }
-
-delete_loading_module:
- wasm_runtime_delete_loading_module(sub_module_name);
- return NULL;
-}
#endif /* end of WASM_ENABLE_MULTI_MODULE */
static bool
@@ -1104,8 +940,9 @@ load_function_import(const uint8 **p_buf, const uint8 *buf_end,
#if WASM_ENABLE_MULTI_MODULE != 0
else {
if (!wasm_runtime_is_built_in_module(sub_module_name)) {
- sub_module = load_depended_module(parent_module, sub_module_name,
- error_buf, error_buf_size);
+ sub_module = (WASMModule *)wasm_runtime_load_depended_module(
+ (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
+ error_buf_size);
if (!sub_module) {
return false;
}
@@ -1193,8 +1030,9 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
#if WASM_ENABLE_MULTI_MODULE != 0
if (!wasm_runtime_is_built_in_module(sub_module_name)) {
- sub_module = load_depended_module(parent_module, sub_module_name,
- error_buf, error_buf_size);
+ sub_module = (WASMModule *)wasm_runtime_load_depended_module(
+ (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
+ error_buf_size);
if (!sub_module) {
return false;
}
@@ -1327,8 +1165,9 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
#if WASM_ENABLE_MULTI_MODULE != 0
if (!wasm_runtime_is_built_in_module(sub_module_name)) {
- sub_module = load_depended_module(parent_module, sub_module_name,
- error_buf, error_buf_size);
+ sub_module = (WASMModule *)wasm_runtime_load_depended_module(
+ (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
+ error_buf_size);
if (!sub_module) {
return false;
}
@@ -1427,8 +1266,9 @@ load_global_import(const uint8 **p_buf, const uint8 *buf_end,
#if WASM_ENABLE_MULTI_MODULE != 0
if (!global->is_linked
&& !wasm_runtime_is_built_in_module(sub_module_name)) {
- sub_module = load_depended_module(parent_module, sub_module_name,
- error_buf, error_buf_size);
+ sub_module = (WASMModule *)wasm_runtime_load_depended_module(
+ (WASMModuleCommon *)parent_module, sub_module_name, error_buf,
+ error_buf_size);
if (!sub_module) {
return false;
}
@@ -1541,7 +1381,15 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
return false;
}
if (memory->flags > 1) {
- set_error_buf(error_buf, error_buf_size, "integer too large");
+ if (memory->flags & 2) {
+ set_error_buf(error_buf, error_buf_size,
+ "shared memory flag was found, "
+ "please enable shared memory, lib-pthread "
+ "or lib-wasi-threads");
+ }
+ else {
+ set_error_buf(error_buf, error_buf_size, "invalid memory flags");
+ }
return false;
}
#else
@@ -2860,7 +2708,7 @@ load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
read_leb_uint32(p, p_end, name_len);
- if (name_len == 0 || p + name_len > p_end) {
+ if (p + name_len > p_end) {
set_error_buf(error_buf, error_buf_size, "unexpected end");
return false;
}
@@ -3000,7 +2848,7 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf,
if (module->function_count == 0)
return true;
-#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LLVM_JIT != 0
+#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
if (os_mutex_init(&module->tierup_wait_lock) != 0) {
set_error_buf(error_buf, error_buf_size, "init jit tierup lock failed");
return false;
@@ -3035,6 +2883,8 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf,
llvm_jit_options = wasm_runtime_get_llvm_jit_options();
option.opt_level = llvm_jit_options.opt_level;
option.size_level = llvm_jit_options.size_level;
+ option.segue_flags = llvm_jit_options.segue_flags;
+ option.linux_perf_support = llvm_jit_options.linux_perf_support;
#if WASM_ENABLE_BULK_MEMORY != 0
option.enable_bulk_memory = true;
@@ -5475,6 +5325,7 @@ wasm_loader_pop_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf,
return true;
}
+#if WASM_ENABLE_FAST_INTERP == 0
static bool
wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt,
uint8 type_push, uint8 type_pop, char *error_buf,
@@ -5489,6 +5340,7 @@ wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt,
return false;
return true;
}
+#endif
static bool
wasm_loader_push_frame_csp(WASMLoaderContext *ctx, uint8 label_type,
@@ -5552,21 +5404,27 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx, char *error_buf,
LOG_OP("\ndelete last op\n"); \
} while (0)
#else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
+#if UINTPTR_MAX == UINT64_MAX
#define emit_label(opcode) \
do { \
int32 offset = \
(int32)((uint8 *)handle_table[opcode] - (uint8 *)handle_table[0]); \
- if (!(offset >= INT16_MIN && offset < INT16_MAX)) { \
- set_error_buf(error_buf, error_buf_size, \
- "pre-compiled label offset out of range"); \
- goto fail; \
- } \
- wasm_loader_emit_int16(loader_ctx, offset); \
+ /* emit int32 relative offset in 64-bit target */ \
+ wasm_loader_emit_uint32(loader_ctx, offset); \
LOG_OP("\nemit_op [%02x]\t", opcode); \
} while (0)
+#else
+#define emit_label(opcode) \
+ do { \
+ uint32 label_addr = (uint32)(uintptr_t)handle_table[opcode]; \
+ /* emit uint32 label address in 32-bit target */ \
+ wasm_loader_emit_uint32(loader_ctx, label_addr); \
+ LOG_OP("\nemit_op [%02x]\t", opcode); \
+ } while (0)
+#endif
#define skip_label() \
do { \
- wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
+ wasm_loader_emit_backspace(loader_ctx, sizeof(int32)); \
LOG_OP("\ndelete last op\n"); \
} while (0)
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
@@ -5896,12 +5754,6 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
(void)error_buf;
(void)error_buf_size;
return true;
-#if WASM_ENABLE_LABELS_AS_VALUES != 0
-#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
-fail:
- return false;
-#endif
-#endif
}
static bool
@@ -6165,27 +6017,6 @@ wasm_loader_pop_frame_offset(WASMLoaderContext *ctx, uint8 type,
return true;
}
-static bool
-wasm_loader_push_pop_frame_offset(WASMLoaderContext *ctx, uint8 pop_cnt,
- uint8 type_push, uint8 type_pop,
- bool disable_emit, int16 operand_offset,
- char *error_buf, uint32 error_buf_size)
-{
- uint8 i;
-
- for (i = 0; i < pop_cnt; i++) {
- if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf,
- error_buf_size))
- return false;
- }
- if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit,
- operand_offset, error_buf,
- error_buf_size))
- return false;
-
- return true;
-}
-
static bool
wasm_loader_push_frame_ref_offset(WASMLoaderContext *ctx, uint8 type,
bool disable_emit, int16 operand_offset,
@@ -6219,12 +6050,24 @@ wasm_loader_push_pop_frame_ref_offset(WASMLoaderContext *ctx, uint8 pop_cnt,
bool disable_emit, int16 operand_offset,
char *error_buf, uint32 error_buf_size)
{
- if (!wasm_loader_push_pop_frame_offset(ctx, pop_cnt, type_push, type_pop,
- disable_emit, operand_offset,
- error_buf, error_buf_size))
+ uint8 i;
+
+ for (i = 0; i < pop_cnt; i++) {
+ if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf,
+ error_buf_size))
+ return false;
+
+ if (!wasm_loader_pop_frame_ref(ctx, type_pop, error_buf,
+ error_buf_size))
+ return false;
+ }
+
+ if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit,
+ operand_offset, error_buf,
+ error_buf_size))
return false;
- if (!wasm_loader_push_pop_frame_ref(ctx, pop_cnt, type_push, type_pop,
- error_buf, error_buf_size))
+
+ if (!wasm_loader_push_frame_ref(ctx, type_push, error_buf, error_buf_size))
return false;
return true;
@@ -7013,6 +6856,7 @@ static bool
copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block,
char *error_buf, uint32 error_buf_size)
{
+ bool ret = false;
int16 *frame_offset = NULL;
uint8 *cells = NULL, cell;
int16 *src_offsets = NULL;
@@ -7083,13 +6927,13 @@ copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block,
if (is_if_block)
PUSH_OFFSET_TYPE(VALUE_TYPE_I32);
+ ret = true;
+
+fail:
/* Free the emit data */
wasm_runtime_free(emit_data);
- return true;
-
-fail:
- return false;
+ return ret;
}
#endif
@@ -7189,7 +7033,7 @@ wasm_loader_get_custom_section(WASMModule *module, const char *name,
section = section->next;
}
- return false;
+ return NULL;
}
#endif
@@ -7301,6 +7145,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
BlockType block_type;
p_org = p - 1;
+ CHECK_BUF(p, p_end, 1);
value_type = read_uint8(p);
if (is_byte_a_type(value_type)) {
/* If the first byte is one of these special values:
@@ -7354,10 +7199,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
}
#if WASM_ENABLE_FAST_INTERP != 0
- if (opcode == WASM_OP_BLOCK) {
- skip_label();
- }
- else if (opcode == WASM_OP_LOOP) {
+ if (opcode == WASM_OP_BLOCK || opcode == WASM_OP_LOOP) {
skip_label();
if (BLOCK_HAS_PARAM(block_type)) {
/* Make sure params are in dynamic space */
@@ -7365,8 +7207,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
loader_ctx, false, error_buf, error_buf_size))
goto fail;
}
- (loader_ctx->frame_csp - 1)->code_compiled =
- loader_ctx->p_code_compiled;
+ if (opcode == WASM_OP_LOOP) {
+ (loader_ctx->frame_csp - 1)->code_compiled =
+ loader_ctx->p_code_compiled;
+ }
}
else if (opcode == WASM_OP_IF) {
/* If block has parameters, we should make sure they are in
@@ -7606,6 +7450,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
if (frame_csp_tmp->label_type != LABEL_TYPE_LOOP)
ret_count = block_type_get_result_types(
&frame_csp_tmp->block_type, &ret_types);
+ else
+ ret_count = block_type_get_param_types(
+ &frame_csp_tmp->block_type, &ret_types);
}
else {
uint8 *tmp_ret_types = NULL;
@@ -7616,6 +7463,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
if (frame_csp_tmp->label_type != LABEL_TYPE_LOOP)
tmp_ret_count = block_type_get_result_types(
&frame_csp_tmp->block_type, &tmp_ret_types);
+ else
+ tmp_ret_count = block_type_get_param_types(
+ &frame_csp_tmp->block_type, &tmp_ret_types);
if (ret_count != tmp_ret_count
|| (ret_count
@@ -7908,7 +7758,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
}
if (available_stack_cell > 0) {
- if (is_32bit_type(*(loader_ctx->frame_ref - 1))) {
+ if (is_32bit_type(*(loader_ctx->frame_ref - 1))
+ || *(loader_ctx->frame_ref - 1) == VALUE_TYPE_ANY) {
loader_ctx->frame_ref--;
loader_ctx->stack_cell_num--;
#if WASM_ENABLE_FAST_INTERP != 0
@@ -7964,6 +7815,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
uint8 ref_type;
BranchBlock *cur_block = loader_ctx->frame_csp - 1;
int32 available_stack_cell;
+#if WASM_ENABLE_FAST_INTERP != 0
+ uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled;
+#endif
POP_I32();
@@ -7992,26 +7846,26 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
if (loader_ctx->p_code_compiled) {
uint8 opcode_tmp = WASM_OP_SELECT_64;
- uint8 *p_code_compiled_tmp =
- loader_ctx->p_code_compiled - 2;
#if WASM_ENABLE_LABELS_AS_VALUES != 0
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
*(void **)(p_code_compiled_tmp
- sizeof(void *)) =
handle_table[opcode_tmp];
#else
+#if UINTPTR_MAX == UINT64_MAX
+ /* emit int32 relative offset in 64-bit target
+ */
int32 offset =
(int32)((uint8 *)handle_table[opcode_tmp]
- (uint8 *)handle_table[0]);
- if (!(offset >= INT16_MIN
- && offset < INT16_MAX)) {
- set_error_buf(error_buf, error_buf_size,
- "pre-compiled label offset "
- "out of range");
- goto fail;
- }
- *(int16 *)(p_code_compiled_tmp
- - sizeof(int16)) = (int16)offset;
+ *(int32 *)(p_code_compiled_tmp
+ - sizeof(int32)) = offset;
+#else
+ /* emit uint32 label address in 32-bit target */
+ *(uint32 *)(p_code_compiled_tmp
+ - sizeof(uint32)) =
+ (uint32)(uintptr_t)handle_table[opcode_tmp];
+#endif
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
@@ -8062,9 +7916,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
case WASM_OP_SELECT_T:
{
uint8 vec_len, ref_type;
+#if WASM_ENABLE_FAST_INTERP != 0
+ uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled;
+#endif
read_leb_uint32(p, p_end, vec_len);
- if (!vec_len) {
+ if (vec_len != 1) {
+ /* typed select must have exactly one result */
set_error_buf(error_buf, error_buf_size,
"invalid result arity");
goto fail;
@@ -8083,8 +7941,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
if (loader_ctx->p_code_compiled) {
uint8 opcode_tmp = WASM_OP_SELECT;
- uint8 *p_code_compiled_tmp =
- loader_ctx->p_code_compiled - 2;
if (ref_type == VALUE_TYPE_V128) {
#if (WASM_ENABLE_SIMD == 0) \
@@ -8103,16 +7959,17 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
*(void **)(p_code_compiled_tmp - sizeof(void *)) =
handle_table[opcode_tmp];
#else
+#if UINTPTR_MAX == UINT64_MAX
+ /* emit int32 relative offset in 64-bit target */
int32 offset = (int32)((uint8 *)handle_table[opcode_tmp]
- (uint8 *)handle_table[0]);
- if (!(offset >= INT16_MIN && offset < INT16_MAX)) {
- set_error_buf(
- error_buf, error_buf_size,
- "pre-compiled label offset out of range");
- goto fail;
- }
- *(int16 *)(p_code_compiled_tmp - sizeof(int16)) =
- (int16)offset;
+ *(int32 *)(p_code_compiled_tmp - sizeof(int32)) =
+ offset;
+#else
+ /* emit uint32 label address in 32-bit target */
+ *(uint32 *)(p_code_compiled_tmp - sizeof(uint32)) =
+ (uint32)(uintptr_t)handle_table[opcode_tmp];
+#endif
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
@@ -9254,10 +9111,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0)
case WASM_OP_SIMD_PREFIX:
{
- opcode = read_uint8(p);
+ uint32 opcode1;
+
+ CHECK_BUF(p, p_end, 1);
+ opcode1 = read_uint8(p);
/* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h
*/
- switch (opcode) {
+ switch (opcode1) {
/* memory instruction */
case SIMD_v128_load:
case SIMD_v128_load8x8_s:
@@ -9275,7 +9135,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
read_leb_uint32(p, p_end, align); /* align */
if (!check_simd_memory_access_align(
- opcode, align, error_buf, error_buf_size)) {
+ opcode1, align, error_buf, error_buf_size)) {
goto fail;
}
@@ -9294,7 +9154,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
read_leb_uint32(p, p_end, align); /* align */
if (!check_simd_memory_access_align(
- opcode, align, error_buf, error_buf_size)) {
+ opcode1, align, error_buf, error_buf_size)) {
goto fail;
}
@@ -9350,7 +9210,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
uint8 pop_type[] = { VALUE_TYPE_I32, VALUE_TYPE_I32,
VALUE_TYPE_I32, VALUE_TYPE_I64,
VALUE_TYPE_F32, VALUE_TYPE_F64 };
- POP_AND_PUSH(pop_type[opcode - SIMD_i8x16_splat],
+ POP_AND_PUSH(pop_type[opcode1 - SIMD_i8x16_splat],
VALUE_TYPE_V128);
break;
}
@@ -9395,22 +9255,23 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
CHECK_BUF(p, p_end, 1);
lane = read_uint8(p);
- if (!check_simd_access_lane(opcode, lane, error_buf,
+ if (!check_simd_access_lane(opcode1, lane, error_buf,
error_buf_size)) {
goto fail;
}
- if (replace[opcode - SIMD_i8x16_extract_lane_s]) {
+ if (replace[opcode1 - SIMD_i8x16_extract_lane_s]) {
if (!(wasm_loader_pop_frame_ref(
loader_ctx,
- replace[opcode - SIMD_i8x16_extract_lane_s],
+ replace[opcode1
+ - SIMD_i8x16_extract_lane_s],
error_buf, error_buf_size)))
goto fail;
}
POP_AND_PUSH(
VALUE_TYPE_V128,
- push_type[opcode - SIMD_i8x16_extract_lane_s]);
+ push_type[opcode1 - SIMD_i8x16_extract_lane_s]);
break;
}
@@ -9511,7 +9372,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
read_leb_uint32(p, p_end, align); /* align */
if (!check_simd_memory_access_align(
- opcode, align, error_buf, error_buf_size)) {
+ opcode1, align, error_buf, error_buf_size)) {
goto fail;
}
@@ -9519,14 +9380,14 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
CHECK_BUF(p, p_end, 1);
lane = read_uint8(p);
- if (!check_simd_access_lane(opcode, lane, error_buf,
+ if (!check_simd_access_lane(opcode1, lane, error_buf,
error_buf_size)) {
goto fail;
}
POP_V128();
POP_I32();
- if (opcode < SIMD_v128_store8_lane) {
+ if (opcode1 < SIMD_v128_store8_lane) {
PUSH_V128();
}
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
@@ -9542,7 +9403,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
read_leb_uint32(p, p_end, align); /* align */
if (!check_simd_memory_access_align(
- opcode, align, error_buf, error_buf_size)) {
+ opcode1, align, error_buf, error_buf_size)) {
goto fail;
}
@@ -9899,7 +9760,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
snprintf(error_buf, error_buf_size,
"WASM module load failed: "
"invalid opcode 0xfd %02x.",
- opcode);
+ opcode1);
}
goto fail;
}
@@ -9912,15 +9773,18 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_SHARED_MEMORY != 0
case WASM_OP_ATOMIC_PREFIX:
{
- opcode = read_uint8(p);
+ uint32 opcode1;
+
+ CHECK_BUF(p, p_end, 1);
+ opcode1 = read_uint8(p);
#if WASM_ENABLE_FAST_INTERP != 0
- emit_byte(loader_ctx, opcode);
+ emit_byte(loader_ctx, opcode1);
#endif
- if (opcode != WASM_OP_ATOMIC_FENCE) {
+ if (opcode1 != WASM_OP_ATOMIC_FENCE) {
CHECK_MEMORY();
read_leb_uint32(p, p_end, align); /* align */
read_leb_uint32(p, p_end, mem_offset); /* offset */
- if (!check_memory_align_equal(opcode, align, error_buf,
+ if (!check_memory_align_equal(opcode1, align, error_buf,
error_buf_size)) {
goto fail;
}
@@ -9931,7 +9795,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
func->has_memory_operations = true;
#endif
- switch (opcode) {
+ switch (opcode1) {
case WASM_OP_ATOMIC_NOTIFY:
POP2_AND_PUSH(VALUE_TYPE_I32, VALUE_TYPE_I32);
break;
@@ -10047,7 +9911,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
default:
set_error_buf_v(error_buf, error_buf_size,
"%s %02x %02x", "unsupported opcode",
- 0xfe, opcode);
+ 0xfe, opcode1);
goto fail;
}
break;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_mini_loader.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_mini_loader.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_mini_loader.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_mini_loader.c
index aa5e18f6a8f..47ec549eedb 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_mini_loader.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_mini_loader.c
@@ -1843,7 +1843,7 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf,
if (module->function_count == 0)
return true;
-#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LLVM_JIT != 0
+#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
if (os_mutex_init(&module->tierup_wait_lock) != 0) {
set_error_buf(error_buf, error_buf_size, "init jit tierup lock failed");
return false;
@@ -1876,6 +1876,8 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf,
option.is_jit_mode = true;
option.opt_level = llvm_jit_options.opt_level;
option.size_level = llvm_jit_options.size_level;
+ option.segue_flags = llvm_jit_options.segue_flags;
+ option.linux_perf_support = llvm_jit_options.linux_perf_support;
#if WASM_ENABLE_BULK_MEMORY != 0
option.enable_bulk_memory = true;
@@ -3936,6 +3938,7 @@ wasm_loader_pop_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf,
return true;
}
+#if WASM_ENABLE_FAST_INTERP == 0
static bool
wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt,
uint8 type_push, uint8 type_pop, char *error_buf,
@@ -3950,6 +3953,7 @@ wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt,
return false;
return true;
}
+#endif
static bool
wasm_loader_push_frame_csp(WASMLoaderContext *ctx, uint8 label_type,
@@ -4006,21 +4010,27 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx, char *error_buf,
LOG_OP("\ndelete last op\n"); \
} while (0)
#else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
+#if UINTPTR_MAX == UINT64_MAX
#define emit_label(opcode) \
do { \
int32 offset = \
(int32)((uint8 *)handle_table[opcode] - (uint8 *)handle_table[0]); \
- if (!(offset >= INT16_MIN && offset < INT16_MAX)) { \
- set_error_buf(error_buf, error_buf_size, \
- "pre-compiled label offset out of range"); \
- goto fail; \
- } \
- wasm_loader_emit_int16(loader_ctx, offset); \
+ /* emit int32 relative offset in 64-bit target */ \
+ wasm_loader_emit_uint32(loader_ctx, offset); \
LOG_OP("\nemit_op [%02x]\t", opcode); \
} while (0)
+#else
+#define emit_label(opcode) \
+ do { \
+ uint32 label_addr = (uint32)(uintptr_t)handle_table[opcode]; \
+ /* emit uint32 label address in 32-bit target */ \
+ wasm_loader_emit_uint32(loader_ctx, label_addr); \
+ LOG_OP("\nemit_op [%02x]\t", opcode); \
+ } while (0)
+#endif
#define skip_label() \
do { \
- wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
+ wasm_loader_emit_backspace(loader_ctx, sizeof(int32)); \
LOG_OP("\ndelete last op\n"); \
} while (0)
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
@@ -4348,13 +4358,6 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
}
return true;
-
-#if WASM_ENABLE_LABELS_AS_VALUES != 0
-#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
-fail:
- return false;
-#endif
-#endif
}
static bool
@@ -4607,25 +4610,6 @@ wasm_loader_pop_frame_offset(WASMLoaderContext *ctx, uint8 type,
return true;
}
-static bool
-wasm_loader_push_pop_frame_offset(WASMLoaderContext *ctx, uint8 pop_cnt,
- uint8 type_push, uint8 type_pop,
- bool disable_emit, int16 operand_offset,
- char *error_buf, uint32 error_buf_size)
-{
- for (int i = 0; i < pop_cnt; i++) {
- if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf,
- error_buf_size))
- return false;
- }
- if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit,
- operand_offset, error_buf,
- error_buf_size))
- return false;
-
- return true;
-}
-
static bool
wasm_loader_push_frame_ref_offset(WASMLoaderContext *ctx, uint8 type,
bool disable_emit, int16 operand_offset,
@@ -4659,12 +4643,24 @@ wasm_loader_push_pop_frame_ref_offset(WASMLoaderContext *ctx, uint8 pop_cnt,
bool disable_emit, int16 operand_offset,
char *error_buf, uint32 error_buf_size)
{
- if (!wasm_loader_push_pop_frame_offset(ctx, pop_cnt, type_push, type_pop,
- disable_emit, operand_offset,
- error_buf, error_buf_size))
+ uint8 i;
+
+ for (i = 0; i < pop_cnt; i++) {
+ if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf,
+ error_buf_size))
+ return false;
+
+ if (!wasm_loader_pop_frame_ref(ctx, type_pop, error_buf,
+ error_buf_size))
+ return false;
+ }
+
+ if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit,
+ operand_offset, error_buf,
+ error_buf_size))
return false;
- if (!wasm_loader_push_pop_frame_ref(ctx, pop_cnt, type_push, type_pop,
- error_buf, error_buf_size))
+
+ if (!wasm_loader_push_frame_ref(ctx, type_push, error_buf, error_buf_size))
return false;
return true;
@@ -5631,10 +5627,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
}
#if WASM_ENABLE_FAST_INTERP != 0
- if (opcode == WASM_OP_BLOCK) {
- skip_label();
- }
- else if (opcode == WASM_OP_LOOP) {
+ if (opcode == WASM_OP_BLOCK || opcode == WASM_OP_LOOP) {
skip_label();
if (BLOCK_HAS_PARAM(block_type)) {
/* Make sure params are in dynamic space */
@@ -5642,8 +5635,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
loader_ctx, false, error_buf, error_buf_size))
goto fail;
}
- (loader_ctx->frame_csp - 1)->code_compiled =
- loader_ctx->p_code_compiled;
+ if (opcode == WASM_OP_LOOP) {
+ (loader_ctx->frame_csp - 1)->code_compiled =
+ loader_ctx->p_code_compiled;
+ }
}
else if (opcode == WASM_OP_IF) {
/* If block has parameters, we should make sure they are in
@@ -6104,7 +6099,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
&& !cur_block->is_stack_polymorphic));
if (available_stack_cell > 0) {
- if (is_32bit_type(*(loader_ctx->frame_ref - 1))) {
+ if (is_32bit_type(*(loader_ctx->frame_ref - 1))
+ || *(loader_ctx->frame_ref - 1) == VALUE_TYPE_ANY) {
loader_ctx->frame_ref--;
loader_ctx->stack_cell_num--;
#if WASM_ENABLE_FAST_INTERP != 0
@@ -6150,6 +6146,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
uint8 ref_type;
BranchBlock *cur_block = loader_ctx->frame_csp - 1;
int32 available_stack_cell;
+#if WASM_ENABLE_FAST_INTERP != 0
+ uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled;
+#endif
POP_I32();
@@ -6172,26 +6171,26 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
if (loader_ctx->p_code_compiled) {
uint8 opcode_tmp = WASM_OP_SELECT_64;
- uint8 *p_code_compiled_tmp =
- loader_ctx->p_code_compiled - 2;
#if WASM_ENABLE_LABELS_AS_VALUES != 0
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
*(void **)(p_code_compiled_tmp
- sizeof(void *)) =
handle_table[opcode_tmp];
#else
+#if UINTPTR_MAX == UINT64_MAX
+ /* emit int32 relative offset in 64-bit target
+ */
int32 offset =
(int32)((uint8 *)handle_table[opcode_tmp]
- (uint8 *)handle_table[0]);
- if (!(offset >= INT16_MIN
- && offset < INT16_MAX)) {
- set_error_buf(error_buf, error_buf_size,
- "pre-compiled label offset "
- "out of range");
- goto fail;
- }
- *(int16 *)(p_code_compiled_tmp
- - sizeof(int16)) = (int16)offset;
+ *(int32 *)(p_code_compiled_tmp
+ - sizeof(int32)) = offset;
+#else
+ /* emit uint32 label address in 32-bit target */
+ *(uint32 *)(p_code_compiled_tmp
+ - sizeof(uint32)) =
+ (uint32)(uintptr_t)handle_table[opcode_tmp];
+#endif
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
@@ -6232,9 +6231,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
case WASM_OP_SELECT_T:
{
uint8 vec_len, ref_type;
+#if WASM_ENABLE_FAST_INTERP != 0
+ uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled;
+#endif
read_leb_uint32(p, p_end, vec_len);
- if (!vec_len) {
+ if (vec_len != 1) {
+ /* typed select must have exactly one result */
set_error_buf(error_buf, error_buf_size,
"invalid result arity");
goto fail;
@@ -6253,8 +6256,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
if (loader_ctx->p_code_compiled) {
uint8 opcode_tmp = WASM_OP_SELECT;
- uint8 *p_code_compiled_tmp =
- loader_ctx->p_code_compiled - 2;
if (ref_type == VALUE_TYPE_F64
|| ref_type == VALUE_TYPE_I64)
@@ -6265,15 +6266,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
*(void **)(p_code_compiled_tmp - sizeof(void *)) =
handle_table[opcode_tmp];
#else
+#if UINTPTR_MAX == UINT64_MAX
+ /* emit int32 relative offset in 64-bit target */
int32 offset = (int32)((uint8 *)handle_table[opcode_tmp]
- (uint8 *)handle_table[0]);
- if (!(offset >= INT16_MIN && offset < INT16_MAX)) {
- set_error_buf(error_buf, error_buf_size,
- "pre-compiled label offset out of range");
- goto fail;
- }
- *(int16 *)(p_code_compiled_tmp - sizeof(int16)) =
- (int16)offset;
+ *(int32 *)(p_code_compiled_tmp - sizeof(int32)) = offset;
+#else
+ /* emit uint32 label address in 32-bit target */
+ *(uint32 *)(p_code_compiled_tmp - sizeof(uint32)) =
+ (uint32)(uintptr_t)handle_table[opcode_tmp];
+#endif
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_opcode.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_opcode.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_opcode.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_opcode.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.c
similarity index 90%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.c
index 29365024d9d..205c6d4b6fb 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.c
@@ -10,6 +10,7 @@
#include "bh_log.h"
#include "mem_alloc.h"
#include "../common/wasm_runtime_common.h"
+#include "../common/wasm_memory.h"
#if WASM_ENABLE_SHARED_MEMORY != 0
#include "../common/wasm_shared_memory.h"
#endif
@@ -51,11 +52,15 @@ set_error_buf_v(char *error_buf, uint32 error_buf_size, const char *format, ...)
}
WASMModule *
-wasm_load(uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size)
+wasm_load(uint8 *buf, uint32 size,
+#if WASM_ENABLE_MULTI_MODULE != 0
+ bool main_module,
+#endif
+ char *error_buf, uint32 error_buf_size)
{
return wasm_loader_load(buf, size,
#if WASM_ENABLE_MULTI_MODULE != 0
- true,
+ main_module,
#endif
error_buf, error_buf_size);
}
@@ -122,11 +127,8 @@ memories_deinstantiate(WASMModuleInstance *module_inst,
}
#endif
#if WASM_ENABLE_SHARED_MEMORY != 0
- if (memories[i]->is_shared) {
- int32 ref_count = shared_memory_dec_reference(
- (WASMModuleCommon *)module_inst->module);
- bh_assert(ref_count >= 0);
-
+ if (shared_memory_is_shared(memories[i])) {
+ uint32 ref_count = shared_memory_dec_reference(memories[i]);
/* if the reference count is not zero,
don't free the memory */
if (ref_count > 0)
@@ -159,13 +161,14 @@ memories_deinstantiate(WASMModuleInstance *module_inst,
}
static WASMMemoryInstance *
-memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
+memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
+ WASMMemoryInstance *memory, uint32 memory_idx,
uint32 num_bytes_per_page, uint32 init_page_count,
uint32 max_page_count, uint32 heap_size, uint32 flags,
char *error_buf, uint32 error_buf_size)
{
WASMModule *module = module_inst->module;
- uint64 memory_data_size;
+ uint64 memory_data_size, max_memory_data_size;
uint32 heap_offset = num_bytes_per_page * init_page_count;
uint32 inc_page_count, aux_heap_base, global_idx;
uint32 bytes_of_last_page, bytes_to_page_end;
@@ -180,22 +183,11 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
bool is_shared_memory = flags & 0x02 ? true : false;
/* shared memory */
- if (is_shared_memory) {
- WASMSharedMemNode *node = wasm_module_get_shared_memory(
- (WASMModuleCommon *)module_inst->module);
- /* If the memory of this module has been instantiated,
- return the memory instance directly */
- if (node) {
- uint32 ref_count;
- ref_count = shared_memory_inc_reference(
- (WASMModuleCommon *)module_inst->module);
- bh_assert(ref_count > 0);
- memory = (WASMMemoryInstance *)shared_memory_get_memory_inst(node);
- bh_assert(memory);
-
- (void)ref_count;
- return memory;
- }
+ if (is_shared_memory && parent != NULL) {
+ bh_assert(parent->memory_count > memory_idx);
+ memory = parent->memories[memory_idx];
+ shared_memory_inc_reference(memory);
+ return memory;
}
#endif /* end of WASM_ENABLE_SHARED_MEMORY */
@@ -215,7 +207,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
if (num_bytes_per_page < heap_size) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
- "try using `--heap_size=0` option");
+ "try using `--heap-size=0` option");
return NULL;
}
}
@@ -274,7 +266,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
if (init_page_count > DEFAULT_MAX_PAGES) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
- "try using `--heap_size=0` option");
+ "try using `--heap-size=0` option");
return NULL;
}
else if (init_page_count == DEFAULT_MAX_PAGES) {
@@ -284,6 +276,12 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
if (max_page_count > DEFAULT_MAX_PAGES)
max_page_count = DEFAULT_MAX_PAGES;
}
+ else { /* heap_size == 0 */
+ if (init_page_count == DEFAULT_MAX_PAGES) {
+ num_bytes_per_page = UINT32_MAX;
+ init_page_count = max_page_count = 1;
+ }
+ }
LOG_VERBOSE("Memory instantiate:");
LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u",
@@ -291,22 +289,33 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size);
memory_data_size = (uint64)num_bytes_per_page * init_page_count;
+ max_memory_data_size = (uint64)num_bytes_per_page * max_page_count;
+ bh_assert(memory_data_size <= UINT32_MAX);
+ bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB);
+ (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 max page for shared memory */
- memory_data_size = (uint64)num_bytes_per_page * max_page_count;
+ /* Allocate maximum memory size when memory is shared */
+ if (max_memory_data_size > 0
+ && !(memory->memory_data = runtime_malloc(
+ max_memory_data_size, error_buf, error_buf_size))) {
+ goto fail1;
+ }
}
+ else
#endif
- bh_assert(memory_data_size <= 4 * (uint64)BH_GB);
-
- bh_assert(memory != NULL);
-#ifndef OS_ENABLE_HW_BOUND_CHECK
- if (memory_data_size > 0
- && !(memory->memory_data =
- runtime_malloc(memory_data_size, error_buf, error_buf_size))) {
- goto fail1;
+ {
+ /* Allocate initial memory size when memory is not shared */
+ if (memory_data_size > 0
+ && !(memory->memory_data = runtime_malloc(
+ memory_data_size, error_buf, error_buf_size))) {
+ goto fail1;
+ }
}
-#else
+#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:
@@ -315,14 +324,16 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
* 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_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 (!os_mem_commit(mapped_mem, memory_data_size,
- MMAP_PROT_READ | MMAP_PROT_WRITE)) {
+ 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;
@@ -335,12 +346,13 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
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 */
-#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
if (memory_data_size > UINT32_MAX)
- memory_data_size = (uint32)memory_data_size;
+ memory_data_size = UINT32_MAX;
+#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
memory->module_type = Wasm_Module_Bytecode;
memory->num_bytes_per_page = num_bytes_per_page;
@@ -368,44 +380,20 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
}
}
-#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0
if (memory_data_size > 0) {
-#if UINTPTR_MAX == UINT64_MAX
- memory->mem_bound_check_1byte.u64 = memory_data_size - 1;
- memory->mem_bound_check_2bytes.u64 = memory_data_size - 2;
- memory->mem_bound_check_4bytes.u64 = memory_data_size - 4;
- memory->mem_bound_check_8bytes.u64 = memory_data_size - 8;
- memory->mem_bound_check_16bytes.u64 = memory_data_size - 16;
-#else
- memory->mem_bound_check_1byte.u32[0] = (uint32)memory_data_size - 1;
- memory->mem_bound_check_2bytes.u32[0] = (uint32)memory_data_size - 2;
- memory->mem_bound_check_4bytes.u32[0] = (uint32)memory_data_size - 4;
- memory->mem_bound_check_8bytes.u32[0] = (uint32)memory_data_size - 8;
- memory->mem_bound_check_16bytes.u32[0] = (uint32)memory_data_size - 16;
-#endif
+ wasm_runtime_set_mem_bound_check_bytes(memory, memory_data_size);
}
-#endif
#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
- memory->is_shared = true;
- if (!shared_memory_set_memory_inst(
- (WASMModuleCommon *)module_inst->module,
- (WASMMemoryInstanceCommon *)memory)) {
- set_error_buf(error_buf, error_buf_size, "allocate memory failed");
- goto fail4;
- }
+ memory->is_shared_memory = 1;
+ memory->ref_count = 1;
}
#endif
LOG_VERBOSE("Memory instantiate success.");
return memory;
-#if WASM_ENABLE_SHARED_MEMORY != 0
-fail4:
- if (heap_size > 0)
- mem_allocator_destroy(memory->heap_handle);
-#endif
fail3:
if (heap_size > 0)
wasm_runtime_free(memory->heap_handle);
@@ -428,7 +416,8 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory,
*/
static WASMMemoryInstance **
memories_instantiate(const WASMModule *module, WASMModuleInstance *module_inst,
- uint32 heap_size, char *error_buf, uint32 error_buf_size)
+ WASMModuleInstance *parent, uint32 heap_size,
+ char *error_buf, uint32 error_buf_size)
{
WASMImport *import;
uint32 mem_index = 0, i,
@@ -474,26 +463,29 @@ memories_instantiate(const WASMModule *module, WASMModuleInstance *module_inst,
else
#endif
{
- if (!(memories[mem_index++] = memory_instantiate(
- module_inst, memory, num_bytes_per_page, init_page_count,
- max_page_count, actual_heap_size, flags, error_buf,
- error_buf_size))) {
+ if (!(memories[mem_index] = memory_instantiate(
+ module_inst, parent, memory, mem_index,
+ num_bytes_per_page, init_page_count, max_page_count,
+ actual_heap_size, flags, error_buf, error_buf_size))) {
memories_deinstantiate(module_inst, memories, memory_count);
return NULL;
}
+ mem_index++;
}
}
/* instantiate memories from memory section */
for (i = 0; i < module->memory_count; i++, memory++) {
- if (!(memories[mem_index++] = memory_instantiate(
- module_inst, memory, module->memories[i].num_bytes_per_page,
+ if (!(memories[mem_index] = memory_instantiate(
+ module_inst, parent, memory, mem_index,
+ module->memories[i].num_bytes_per_page,
module->memories[i].init_page_count,
module->memories[i].max_page_count, heap_size,
module->memories[i].flags, error_buf, error_buf_size))) {
memories_deinstantiate(module_inst, memories, memory_count);
return NULL;
}
+ mem_index++;
}
bh_assert(mem_index == memory_count);
@@ -1070,7 +1062,8 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst,
wasm functions, and ensure that the exec_env's module inst
is the correct one. */
module_inst_main = exec_env_main->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(exec_env,
+ (WASMModuleInstanceCommon *)module_inst);
}
else {
/* Try using the existing exec_env */
@@ -1095,7 +1088,8 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst,
module inst to ensure that the exec_env's module inst
is the correct one. */
module_inst_main = exec_env->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(
+ exec_env, (WASMModuleInstanceCommon *)module_inst);
}
}
@@ -1104,10 +1098,14 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst,
goto fail;
}
+#if WASM_ENABLE_LIBC_WASI != 0
if (initialize_func
&& !wasm_call_function(exec_env, initialize_func, 0, NULL)) {
goto fail;
}
+#else
+ (void)initialize_func;
+#endif
if (post_inst_func
&& !wasm_call_function(exec_env, post_inst_func, 0, NULL)) {
@@ -1124,12 +1122,12 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst,
fail:
if (is_sub_inst) {
/* Restore the parent exec_env's module inst */
- exec_env_main->module_inst = module_inst_main;
+ wasm_exec_env_restore_module_inst(exec_env_main, module_inst_main);
}
else {
if (module_inst_main)
/* Restore the existing exec_env's module inst */
- exec_env->module_inst = module_inst_main;
+ wasm_exec_env_restore_module_inst(exec_env, module_inst_main);
if (exec_env_created)
wasm_exec_env_destroy(exec_env_created);
}
@@ -1198,7 +1196,8 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
module inst to ensure that the exec_env's module inst
is the correct one. */
module_inst_old = exec_env->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(
+ exec_env, (WASMModuleInstanceCommon *)module_inst);
}
}
@@ -1209,7 +1208,7 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
if (module_inst_old)
/* Restore the existing exec_env's module inst */
- exec_env->module_inst = module_inst_old;
+ wasm_exec_env_restore_module_inst(exec_env, module_inst_old);
if (exec_env_created)
wasm_exec_env_destroy(exec_env_created);
@@ -1265,7 +1264,8 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
module inst to ensure that the exec_env's module inst
is the correct one. */
module_inst_old = exec_env->module_inst;
- exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
+ wasm_exec_env_set_module_inst(
+ exec_env, (WASMModuleInstanceCommon *)module_inst);
}
}
@@ -1273,7 +1273,7 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
if (module_inst_old)
/* Restore the existing exec_env's module inst */
- exec_env->module_inst = module_inst_old;
+ wasm_exec_env_restore_module_inst(exec_env, module_inst_old);
if (exec_env_created)
wasm_exec_env_destroy(exec_env_created);
@@ -1281,78 +1281,6 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
return ret;
}
-#if WASM_ENABLE_MULTI_MODULE != 0
-static bool
-sub_module_instantiate(WASMModule *module, WASMModuleInstance *module_inst,
- uint32 stack_size, uint32 heap_size, char *error_buf,
- uint32 error_buf_size)
-{
- bh_list *sub_module_inst_list = module_inst->e->sub_module_inst_list;
- WASMRegisteredModule *sub_module_list_node =
- bh_list_first_elem(module->import_module_list);
-
- while (sub_module_list_node) {
- WASMSubModInstNode *sub_module_inst_list_node = NULL;
- WASMModule *sub_module = (WASMModule *)sub_module_list_node->module;
- WASMModuleInstance *sub_module_inst = NULL;
-
- sub_module_inst =
- wasm_instantiate(sub_module, false, NULL, stack_size, heap_size,
- error_buf, error_buf_size);
- if (!sub_module_inst) {
- LOG_DEBUG("instantiate %s failed",
- sub_module_list_node->module_name);
- goto failed;
- }
-
- sub_module_inst_list_node = runtime_malloc(sizeof(WASMSubModInstNode),
- error_buf, error_buf_size);
- if (!sub_module_inst_list_node) {
- LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d",
- sizeof(WASMSubModInstNode));
- goto failed;
- }
-
- sub_module_inst_list_node->module_inst = sub_module_inst;
- sub_module_inst_list_node->module_name =
- sub_module_list_node->module_name;
- bh_list_status ret =
- bh_list_insert(sub_module_inst_list, sub_module_inst_list_node);
- bh_assert(BH_LIST_SUCCESS == ret);
- (void)ret;
-
- sub_module_list_node = bh_list_elem_next(sub_module_list_node);
-
- continue;
- failed:
- if (sub_module_inst_list_node) {
- bh_list_remove(sub_module_inst_list, sub_module_inst_list_node);
- wasm_runtime_free(sub_module_inst_list_node);
- }
-
- if (sub_module_inst)
- wasm_deinstantiate(sub_module_inst, false);
- return false;
- }
-
- return true;
-}
-
-static void
-sub_module_deinstantiate(WASMModuleInstance *module_inst)
-{
- bh_list *list = module_inst->e->sub_module_inst_list;
- WASMSubModInstNode *node = bh_list_first_elem(list);
- while (node) {
- WASMSubModInstNode *next_node = bh_list_elem_next(node);
- bh_list_remove(list, node);
- wasm_deinstantiate(node->module_inst, false);
- wasm_runtime_free(node);
- node = next_node;
- }
-}
-#endif
-
static bool
check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
uint32 error_buf_size)
@@ -1642,7 +1570,7 @@ wasm_set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode)
* Instantiate module
*/
WASMModuleInstance *
-wasm_instantiate(WASMModule *module, bool is_sub_inst,
+wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, char *error_buf, uint32 error_buf_size)
{
@@ -1659,6 +1587,7 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
#if WASM_ENABLE_MULTI_MODULE != 0
bool ret = false;
#endif
+ const bool is_sub_inst = parent != NULL;
if (!module)
return NULL;
@@ -1728,14 +1657,40 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
#if WASM_ENABLE_MULTI_MODULE != 0
module_inst->e->sub_module_inst_list =
&module_inst->e->sub_module_inst_list_head;
- ret = sub_module_instantiate(module, module_inst, stack_size, heap_size,
- error_buf, error_buf_size);
+ ret = wasm_runtime_sub_module_instantiate(
+ (WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst,
+ stack_size, heap_size, error_buf, error_buf_size);
if (!ret) {
LOG_DEBUG("build a sub module list failed");
goto fail;
}
#endif
+#if WASM_ENABLE_BULK_MEMORY != 0
+ if (module->data_seg_count > 0) {
+ module_inst->e->common.data_dropped =
+ bh_bitmap_new(0, module->data_seg_count);
+ if (module_inst->e->common.data_dropped == NULL) {
+ LOG_DEBUG("failed to allocate bitmaps");
+ set_error_buf(error_buf, error_buf_size,
+ "failed to allocate bitmaps");
+ goto fail;
+ }
+ }
+#endif
+#if WASM_ENABLE_REF_TYPES != 0
+ if (module->table_seg_count > 0) {
+ module_inst->e->common.elem_dropped =
+ bh_bitmap_new(0, module->table_seg_count);
+ if (module_inst->e->common.elem_dropped == NULL) {
+ LOG_DEBUG("failed to allocate bitmaps");
+ set_error_buf(error_buf, error_buf_size,
+ "failed to allocate bitmaps");
+ goto fail;
+ }
+ }
+#endif
+
#if WASM_ENABLE_DUMP_CALL_STACK != 0
if (!(module_inst->frames = runtime_malloc((uint64)sizeof(Vector),
error_buf, error_buf_size))) {
@@ -1777,8 +1732,9 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
/* Instantiate memories/tables/functions */
if ((module_inst->memory_count > 0
- && !(module_inst->memories = memories_instantiate(
- module, module_inst, heap_size, error_buf, error_buf_size)))
+ && !(module_inst->memories =
+ memories_instantiate(module, module_inst, parent, heap_size,
+ error_buf, error_buf_size)))
|| (module_inst->table_count > 0
&& !(module_inst->tables =
tables_instantiate(module, module_inst, first_table,
@@ -1853,20 +1809,25 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
for (i = 0; i < module->data_seg_count; i++) {
WASMMemoryInstance *memory = NULL;
uint8 *memory_data = NULL;
- uint32 memory_size = 0;
+ uint64 memory_size = 0;
WASMDataSeg *data_seg = module->data_segments[i];
#if WASM_ENABLE_BULK_MEMORY != 0
if (data_seg->is_passive)
continue;
#endif
+ if (is_sub_inst)
+ /* Ignore setting memory init data if the memory has been
+ initialized */
+ continue;
/* has check it in loader */
memory = module_inst->memories[data_seg->memory_index];
bh_assert(memory);
memory_data = memory->memory_data;
- memory_size = memory->num_bytes_per_page * memory->cur_page_count;
+ memory_size =
+ (uint64)memory->num_bytes_per_page * memory->cur_page_count;
bh_assert(memory_data || memory_size == 0);
bh_assert(data_seg->base_offset.init_expr_type
@@ -1912,7 +1873,7 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
/* check offset + length(could be zero) */
length = data_seg->data_length;
- if (base_offset + length > memory_size) {
+ if ((uint64)base_offset + length > memory_size) {
LOG_DEBUG("base_offset(%d) + length(%d) > memory_size(%d)",
base_offset, length, memory_size);
#if WASM_ENABLE_REF_TYPES != 0
@@ -1926,8 +1887,9 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
}
if (memory_data) {
- bh_memcpy_s(memory_data + base_offset, memory_size - base_offset,
- data_seg->data, length);
+ bh_memcpy_s(memory_data + base_offset,
+ (uint32)memory_size - base_offset, data_seg->data,
+ length);
}
}
@@ -2097,16 +2059,6 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst,
}
#endif
-#if WASM_ENABLE_WASI_NN != 0
- if (!is_sub_inst) {
- if (!(module_inst->e->wasi_nn_ctx = wasi_nn_initialize())) {
- set_error_buf(error_buf, error_buf_size,
- "wasi nn initialization failed");
- goto fail;
- }
- }
-#endif
-
#if WASM_ENABLE_DEBUG_INTERP != 0
if (!is_sub_inst) {
/* Add module instance into module's instance list */
@@ -2219,17 +2171,8 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
#endif
#if WASM_ENABLE_MULTI_MODULE != 0
- sub_module_deinstantiate(module_inst);
-#endif
-
-#if WASM_ENABLE_LIBC_WASI != 0
- /* Destroy wasi resource before freeing app heap, since some fields of
- wasi contex are allocated from app heap, and if app heap is freed,
- these fields will be set to NULL, we cannot free their internal data
- which may allocated from global heap. */
- /* Only destroy wasi ctx in the main module instance */
- if (!is_sub_inst)
- wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst);
+ wasm_runtime_sub_module_deinstantiate(
+ (WASMModuleInstanceCommon *)module_inst);
#endif
if (module_inst->memory_count > 0)
@@ -2261,15 +2204,21 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
}
#endif
- if (module_inst->e->c_api_func_imports)
- wasm_runtime_free(module_inst->e->c_api_func_imports);
+ if (module_inst->e->common.c_api_func_imports)
+ wasm_runtime_free(module_inst->e->common.c_api_func_imports);
-#if WASM_ENABLE_WASI_NN != 0
if (!is_sub_inst) {
- WASINNContext *wasi_nn_ctx = module_inst->e->wasi_nn_ctx;
- if (wasi_nn_ctx)
- wasi_nn_destroy(wasi_nn_ctx);
+#if WASM_ENABLE_WASI_NN != 0
+ wasi_nn_destroy(module_inst);
+#endif
+ wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst);
}
+
+#if WASM_ENABLE_BULK_MEMORY != 0
+ bh_bitmap_delete(module_inst->e->common.data_dropped);
+#endif
+#if WASM_ENABLE_REF_TYPES != 0
+ bh_bitmap_delete(module_inst->e->common.elem_dropped);
#endif
wasm_runtime_free(module_inst);
@@ -2431,6 +2380,9 @@ wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
/* set thread handle and stack boundary */
wasm_exec_env_set_thread_info(exec_env);
+ /* set exec env so it can be later retrieved from instance */
+ module_inst->e->common.cur_exec_env = exec_env;
+
interp_call_wasm(module_inst, exec_env, function, argc, argv);
return !wasm_copy_exception(module_inst, NULL);
}
@@ -2467,14 +2419,16 @@ wasm_dump_perf_profiling(const WASMModuleInstance *module_inst)
}
if (func_name)
- os_printf(" func %s, execution time: %.3f ms, execution count: %d "
- "times\n",
- func_name,
- module_inst->e->functions[i].total_exec_time / 1000.0f,
- module_inst->e->functions[i].total_exec_cnt);
+ 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);
else
- os_printf(" func %d, execution time: %.3f ms, execution count: %d "
- "times\n",
+ 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);
}
@@ -2568,15 +2522,20 @@ void
wasm_module_free_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 ptr)
{
- if (ptr) {
- WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
- uint8 *addr;
+ WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
- if (!memory) {
- return;
- }
+ if (!memory) {
+ return;
+ }
+
+ if (ptr) {
+ uint8 *addr = memory->memory_data + ptr;
+ uint8 *memory_data_end;
- addr = memory->memory_data + ptr;
+ /* memory->memory_data_end may be changed in memory grow */
+ SHARED_MEMORY_LOCK(memory);
+ memory_data_end = memory->memory_data_end;
+ SHARED_MEMORY_UNLOCK(memory);
if (memory->heap_handle && memory->heap_data <= addr
&& addr < memory->heap_data_end) {
@@ -2584,7 +2543,7 @@ wasm_module_free_internal(WASMModuleInstance *module_inst,
}
else if (module_inst->e->malloc_function
&& module_inst->e->free_function && memory->memory_data <= addr
- && addr < memory->memory_data_end) {
+ && addr < memory_data_end) {
execute_free_function(module_inst, exec_env,
module_inst->e->free_function, ptr);
}
@@ -3011,6 +2970,7 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
total_len += \
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
if ((!print) && buf && (len == 0)) { \
+ exception_unlock(module_inst); \
return total_len; \
} \
} while (0)
@@ -3035,6 +2995,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
return 0;
}
+ exception_lock(module_inst);
snprintf(line_buf, sizeof(line_buf), "\n");
PRINT_OR_DUMP();
@@ -3043,17 +3004,20 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
uint32 line_length, i;
if (!bh_vector_get(module_inst->frames, n, &frame)) {
+ exception_unlock(module_inst);
return 0;
}
/* function name not exported, print number instead */
if (frame.func_name_wp == NULL) {
- line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n",
- n, frame.func_index);
+ line_length =
+ snprintf(line_buf, sizeof(line_buf),
+ "#%02" PRIu32 " $f%" PRIu32 "\n", n, frame.func_index);
}
else {
- line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
- frame.func_name_wp);
+ line_length =
+ snprintf(line_buf, sizeof(line_buf), "#%02" PRIu32 " %s\n", n,
+ frame.func_name_wp);
}
if (line_length >= sizeof(line_buf)) {
@@ -3071,6 +3035,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
}
snprintf(line_buf, sizeof(line_buf), "\n");
PRINT_OR_DUMP();
+ exception_unlock(module_inst);
return total_len + 1;
}
@@ -3124,11 +3089,7 @@ llvm_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
{
bool ret;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
- return aot_call_indirect(exec_env, tbl_idx, elem_idx, argc, argv);
- }
-#endif
+ bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
ret = call_indirect(exec_env, tbl_idx, elem_idx, argc, argv, false, 0);
#ifdef OS_ENABLE_HW_BOUND_CHECK
@@ -3155,11 +3116,7 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
char buf[96];
bool ret = false;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
- return aot_invoke_native(exec_env, func_idx, argc, argv);
- }
-#endif
+ bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
module_inst = (WASMModuleInstance *)wasm_runtime_get_module_inst(exec_env);
module = module_inst->module;
@@ -3172,8 +3129,9 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
import_func = &module->import_functions[func_idx].u.function;
if (import_func->call_conv_wasm_c_api) {
- if (module_inst->e->c_api_func_imports) {
- c_api_func_import = module_inst->e->c_api_func_imports + func_idx;
+ if (module_inst->e->common.c_api_func_imports) {
+ c_api_func_import =
+ module_inst->e->common.c_api_func_imports + func_idx;
func_ptr = c_api_func_import->func_ptr_linked;
}
else {
@@ -3224,20 +3182,23 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
{
WASMMemoryInstance *memory_inst;
WASMModule *module;
- uint8 *data = NULL;
+ uint8 *data;
uint8 *maddr;
- uint64 seg_len = 0;
+ uint64 seg_len;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- return aot_memory_init(module_inst, seg_index, offset, len, dst);
- }
-#endif
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
memory_inst = wasm_get_default_memory(module_inst);
- module = module_inst->module;
- seg_len = module->data_segments[seg_index]->data_length;
- data = module->data_segments[seg_index]->data;
+
+ if (bh_bitmap_get_bit(module_inst->e->common.data_dropped, seg_index)) {
+ seg_len = 0;
+ data = NULL;
+ }
+ else {
+ module = module_inst->module;
+ seg_len = module->data_segments[seg_index]->data_length;
+ data = module->data_segments[seg_index]->data;
+ }
if (!wasm_runtime_validate_app_addr((WASMModuleInstanceCommon *)module_inst,
dst, len))
@@ -3251,20 +3212,18 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
maddr = wasm_runtime_addr_app_to_native(
(WASMModuleInstanceCommon *)module_inst, dst);
+ SHARED_MEMORY_LOCK(memory_inst);
bh_memcpy_s(maddr, memory_inst->memory_data_size - dst, data + offset, len);
+ SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}
bool
llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index)
{
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- return aot_data_drop(module_inst, seg_index);
- }
-#endif
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
- module_inst->module->data_segments[seg_index]->data_length = 0;
+ bh_bitmap_set_bit(module_inst->e->common.data_dropped, seg_index);
/* Currently we can't free the dropped data segment
as they are stored in wasm bytecode */
return true;
@@ -3275,16 +3234,8 @@ llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index)
void
llvm_jit_drop_table_seg(WASMModuleInstance *module_inst, uint32 tbl_seg_idx)
{
- WASMTableSeg *tbl_segs;
-
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- return aot_drop_table_seg(module_inst, tbl_seg_idx);
- }
-#endif
-
- tbl_segs = module_inst->module->table_segments;
- tbl_segs[tbl_seg_idx].is_dropped = true;
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
+ bh_bitmap_set_bit(module_inst->e->common.elem_dropped, tbl_seg_idx);
}
void
@@ -3295,12 +3246,7 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
WASMTableInstance *tbl_inst;
WASMTableSeg *tbl_seg;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- return aot_table_init(module_inst, tbl_idx, tbl_seg_idx, length,
- src_offset, dst_offset);
- }
-#endif
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_inst = wasm_get_table_inst(module_inst, tbl_idx);
tbl_seg = module_inst->module->table_segments + tbl_seg_idx;
@@ -3308,17 +3254,17 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
bh_assert(tbl_inst);
bh_assert(tbl_seg);
- if (!length) {
+ if (offset_len_out_of_bounds(src_offset, length, tbl_seg->function_count)
+ || 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;
}
- if (length + src_offset > tbl_seg->function_count
- || dst_offset + length > tbl_inst->cur_size) {
- jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
+ if (!length) {
return;
}
- if (tbl_seg->is_dropped) {
+ 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;
}
@@ -3343,21 +3289,16 @@ llvm_jit_table_copy(WASMModuleInstance *module_inst, uint32 src_tbl_idx,
WASMTableInstance *src_tbl_inst;
WASMTableInstance *dst_tbl_inst;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- aot_table_copy(module_inst, src_tbl_idx, dst_tbl_idx, length,
- src_offset, dst_offset);
- return;
- }
-#endif
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
src_tbl_inst = wasm_get_table_inst(module_inst, src_tbl_idx);
dst_tbl_inst = wasm_get_table_inst(module_inst, dst_tbl_idx);
bh_assert(src_tbl_inst);
bh_assert(dst_tbl_inst);
- if ((uint64)dst_offset + length > dst_tbl_inst->cur_size
- || (uint64)src_offset + length > src_tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(dst_offset, length, dst_tbl_inst->cur_size)
+ || offset_len_out_of_bounds(src_offset, length,
+ src_tbl_inst->cur_size)) {
jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
@@ -3379,17 +3320,12 @@ llvm_jit_table_fill(WASMModuleInstance *module_inst, uint32 tbl_idx,
{
WASMTableInstance *tbl_inst;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- aot_table_fill(module_inst, tbl_idx, length, val, data_offset);
- return;
- }
-#endif
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_inst = wasm_get_table_inst(module_inst, tbl_idx);
bh_assert(tbl_inst);
- if (data_offset + length > tbl_inst->cur_size) {
+ if (offset_len_out_of_bounds(data_offset, length, tbl_inst->cur_size)) {
jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS);
return;
}
@@ -3406,11 +3342,7 @@ llvm_jit_table_grow(WASMModuleInstance *module_inst, uint32 tbl_idx,
WASMTableInstance *tbl_inst;
uint32 i, orig_size, total_size;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == module_inst->module_type) {
- return aot_table_grow(module_inst, tbl_idx, inc_size, init_val);
- }
-#endif
+ bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_inst = wasm_get_table_inst(module_inst, tbl_idx);
if (!tbl_inst) {
@@ -3450,11 +3382,7 @@ llvm_jit_alloc_frame(WASMExecEnv *exec_env, uint32 func_index)
WASMInterpFrame *frame;
uint32 size;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
- return aot_alloc_frame(exec_env, func_index);
- }
-#endif
+ bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
module_inst = (WASMModuleInstance *)exec_env->module_inst;
size = wasm_interp_interp_frame_size(0);
@@ -3483,12 +3411,7 @@ llvm_jit_free_frame(WASMExecEnv *exec_env)
WASMInterpFrame *frame;
WASMInterpFrame *prev_frame;
-#if WASM_ENABLE_JIT != 0
- if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
- aot_free_frame(exec_env);
- return;
- }
-#endif
+ bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
frame = wasm_exec_env_get_cur_frame(exec_env);
prev_frame = frame->prev_frame;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.h
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.h
index 15169433ed8..bb5fdc80bbe 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.h
@@ -7,6 +7,8 @@
#define _WASM_RUNTIME_H
#include "wasm.h"
+#include "bh_atomic.h"
+#include "bh_bitmap.h"
#include "bh_hashmap.h"
#include "../common/wasm_runtime_common.h"
#include "../common/wasm_exec_env.h"
@@ -78,8 +80,16 @@ typedef union {
struct WASMMemoryInstance {
/* Module type */
uint32 module_type;
- /* Shared memory flag */
- bool is_shared;
+
+ /* Whether the memory is shared */
+ uint8 is_shared_memory;
+
+ /* One byte padding */
+ uint8 __padding__;
+
+ /* Reference count of the memory instance:
+ 0: non-shared memory, > 0: shared memory */
+ bh_atomic_16_t ref_count;
/* Number bytes per page */
uint32 num_bytes_per_page;
@@ -209,8 +219,28 @@ typedef struct CApiFuncImport {
void *env_arg;
} CApiFuncImport;
+/* The common part of WASMModuleInstanceExtra and AOTModuleInstanceExtra */
+typedef struct WASMModuleInstanceExtraCommon {
+ void *contexts[WASM_MAX_INSTANCE_CONTEXTS];
+ CApiFuncImport *c_api_func_imports;
+ /* pointer to the exec env currently used */
+ WASMExecEnv *cur_exec_env;
+#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
+ /* Disable bounds checks or not */
+ bool disable_bounds_checks;
+#endif
+#if WASM_ENABLE_BULK_MEMORY != 0
+ bh_bitmap *data_dropped;
+#endif
+#if WASM_ENABLE_REF_TYPES != 0
+ bh_bitmap *elem_dropped;
+#endif
+} WASMModuleInstanceExtraCommon;
+
/* Extra info of WASM module instance for interpreter/jit mode */
typedef struct WASMModuleInstanceExtra {
+ WASMModuleInstanceExtraCommon common;
+
WASMGlobalInstance *globals;
WASMFunctionInstance *functions;
@@ -222,7 +252,6 @@ typedef struct WASMModuleInstanceExtra {
WASMFunctionInstance *free_function;
WASMFunctionInstance *retain_function;
- CApiFuncImport *c_api_func_imports;
RunningMode running_mode;
#if WASM_ENABLE_MULTI_MODULE != 0
@@ -241,10 +270,6 @@ typedef struct WASMModuleInstanceExtra {
&& WASM_ENABLE_LAZY_JIT != 0)
WASMModuleInstance *next;
#endif
-
-#if WASM_ENABLE_WASI_NN != 0
- WASINNContext *wasi_nn_ctx;
-#endif
} WASMModuleInstanceExtra;
struct AOTFuncPerfProfInfo;
@@ -290,12 +315,8 @@ struct WASMModuleInstance {
it denotes `AOTModule *` */
DefPointer(WASMModule *, module);
-#if WASM_ENABLE_LIBC_WASI
- /* WASI context */
- DefPointer(WASIContext *, wasi_ctx);
-#else
- DefPointer(void *, wasi_ctx);
-#endif
+ DefPointer(void *, used_to_be_wasi_ctx); /* unused */
+
DefPointer(WASMExecEnv *, exec_env_singleton);
/* Array of function pointers to import functions,
not available in AOTModuleInstance */
@@ -390,7 +411,11 @@ wasm_get_func_code_end(WASMFunctionInstance *func)
}
WASMModule *
-wasm_load(uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size);
+wasm_load(uint8 *buf, uint32 size,
+#if WASM_ENABLE_MULTI_MODULE != 0
+ bool main_module,
+#endif
+ char *error_buf, uint32 error_buf_size);
WASMModule *
wasm_load_from_sections(WASMSection *section_list, char *error_buf,
@@ -400,7 +425,7 @@ void
wasm_unload(WASMModule *module);
WASMModuleInstance *
-wasm_instantiate(WASMModule *module, bool is_sub_inst,
+wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, char *error_buf, uint32 error_buf_size);
@@ -661,6 +686,16 @@ void
wasm_propagate_wasi_args(WASMModule *module);
#endif
+#if WASM_ENABLE_THREAD_MGR != 0
+void
+exception_lock(WASMModuleInstance *module_inst);
+void
+exception_unlock(WASMModuleInstance *module_inst);
+#else
+#define exception_lock(module_inst) (void)(module_inst)
+#define exception_unlock(module_inst) (void)(module_inst)
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
index 206479c2a24..56deaff32f1 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
@@ -531,7 +531,8 @@ pthread_start_routine(void *arg)
else {
info_node->u.ret = (void *)(uintptr_t)argv[0];
#ifdef OS_ENABLE_HW_BOUND_CHECK
- if (exec_env->suspend_flags.flags & 0x08)
+ if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags)
+ & WASM_SUSPEND_FLAG_EXIT)
/* argv[0] isn't set after longjmp(1) to
invoke_native_with_hw_bound_check */
info_node->u.ret = exec_env->thread_ret_value;
@@ -558,9 +559,6 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
uint32 thread_handle;
uint32 stack_size = 8192;
int32 ret = -1;
-#if WASM_ENABLE_LIBC_WASI != 0
- WASIContext *wasi_ctx;
-#endif
bh_assert(module);
bh_assert(module_inst);
@@ -580,18 +578,14 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
#endif
if (!(new_module_inst = wasm_runtime_instantiate_internal(
- module, true, exec_env, stack_size, 0, NULL, 0)))
+ module, module_inst, exec_env, stack_size, 0, NULL, 0)))
return -1;
/* Set custom_data to new module instance */
wasm_runtime_set_custom_data_internal(
new_module_inst, wasm_runtime_get_custom_data(module_inst));
-#if WASM_ENABLE_LIBC_WASI != 0
- wasi_ctx = get_wasi_ctx(module_inst);
- if (wasi_ctx)
- wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
-#endif
+ wasm_native_inherit_contexts(new_module_inst, module_inst);
if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst)))
goto fail;
@@ -690,6 +684,14 @@ pthread_join_wrapper(wasm_exec_env_t exec_env, uint32 thread,
bh_assert(node->joinable);
join_ret = 0;
ret = node->u.ret;
+
+ /* The target thread changes the node's status before calling
+ wasm_cluster_exit_thread to exit, so here its resources may
+ haven't been destroyed yet, we wait enough time to ensure that
+ they are actually destroyed to avoid unexpected behavior. */
+ os_mutex_lock(&exec_env->wait_lock);
+ os_cond_reltimedwait(&exec_env->wait_cond, &exec_env->wait_lock, 1000);
+ os_mutex_unlock(&exec_env->wait_lock);
}
if (retval_offset != 0)
@@ -757,7 +759,6 @@ __pthread_self_wrapper(wasm_exec_env_t exec_env)
static void
pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset)
{
- wasm_module_inst_t module_inst = get_module_inst(exec_env);
ThreadRoutineArgs *args = get_thread_arg(exec_env);
/* Currently exit main thread is not allowed */
if (!args)
@@ -775,9 +776,6 @@ pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset)
/* destroy pthread key values */
call_key_destructor(exec_env);
- /* routine exit, destroy instance */
- wasm_runtime_deinstantiate_internal(module_inst, true);
-
if (!args->info_node->joinable) {
delete_thread_info_node(args->info_node);
}
@@ -789,6 +787,8 @@ pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset)
wasm_runtime_free(args);
+ /* Don't destroy exec_env->module_inst in this functuntion since
+ it will be destroyed in wasm_cluster_exit_thread */
wasm_cluster_exit_thread(exec_env, (void *)(uintptr_t)retval_offset);
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats.cmake
similarity index 76%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats.cmake
index b773c837e38..e17a6b25afa 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats.cmake
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats.cmake
@@ -23,6 +23,7 @@ include(FetchContent)
set(RATS_BUILD_MODE "sgx"
CACHE INTERNAL "Select build mode for librats(host|occlum|sgx|wasm)")
set(RATS_INSTALL_PATH "${CMAKE_BINARY_DIR}/librats" CACHE INTERNAL "")
+set(BUILD_SAMPLES OFF CACHE BOOL "Disable de compilation of the librats samples" FORCE)
FetchContent_Declare(
librats
@@ -34,8 +35,17 @@ if (NOT librats_POPULATED)
message("-- Fetching librats ..")
FetchContent_Populate(librats)
include_directories("${librats_SOURCE_DIR}/include")
+
+ # Prevent the propagation of the CMAKE_C_FLAGS of WAMR into librats
+ set(SAVED_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
+ set(CMAKE_C_FLAGS "")
+
+ # Import the building scripts of librats
add_subdirectory(${librats_SOURCE_DIR} ${librats_BINARY_DIR} EXCLUDE_FROM_ALL)
+ # Restore the CMAKE_C_FLAGS of WAMR
+ set(CMAKE_C_FLAGS ${SAVED_CMAKE_C_FLAGS})
+
endif()
file (GLOB source_all ${LIB_RATS_DIR}/*.c)
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_common.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_common.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_common.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c
similarity index 88%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c
index 59d61f4c828..bdacc259ce2 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c
@@ -17,7 +17,7 @@
#include "lib_rats_common.h"
static int
-librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
+librats_collect_wrapper(wasm_exec_env_t exec_env, uint32_t *evidence_json,
const char *buffer, uint32_t buffer_size)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@@ -47,7 +47,7 @@ librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
return (int)RATS_ATTESTER_ERR_NO_MEM;
}
bh_memcpy_s(str_ret, json_size, json, json_size);
- *((int *)evidence_json) = str_ret_offset;
+ *evidence_json = str_ret_offset;
free(json);
return 0;
@@ -96,6 +96,15 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env,
return 0;
}
+static void
+librats_dispose_evidence_json_wrapper(wasm_exec_env_t exec_env,
+ uint32_t evidence_json)
+{
+ wasm_module_inst_t module_inst = get_module_inst(exec_env);
+
+ module_free(evidence_json);
+}
+
/* clang-format off */
#define REG_NATIVE_FUNC(func_name, signature) \
{ #func_name, func_name##_wrapper, signature, NULL }
@@ -104,7 +113,8 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env,
static NativeSymbol native_symbols_lib_rats[] = {
REG_NATIVE_FUNC(librats_collect, "(**~)i"),
REG_NATIVE_FUNC(librats_verify, "(*~*~)i"),
- REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i")
+ REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i"),
+ REG_NATIVE_FUNC(librats_dispose_evidence_json, "(i)")
};
uint32_t
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h
index e334983e9aa..9286451080e 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h
@@ -41,6 +41,9 @@ librats_parse_evidence(const char *evidence_json, uint32_t json_size,
evidence_json ? strlen(evidence_json) + 1 : 0, \
evidence, sizeof(rats_sgx_evidence_t))
+void
+librats_dispose_evidence_json(char *evidence_json);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h
index c9a07eb72bd..98429bbb0a4 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h
@@ -17,6 +17,8 @@ extern "C" {
#endif
typedef enum {
+ /* Used only for sock_addr_resolve hints */
+ SOCKET_ANY = -1,
SOCKET_DGRAM = 0,
SOCKET_STREAM,
} __wasi_sock_type_t;
@@ -84,7 +86,7 @@ typedef struct __wasi_addr_t {
} addr;
} __wasi_addr_t;
-typedef enum { INET4 = 0, INET6 } __wasi_address_family_t;
+typedef enum { INET4 = 0, INET6, INET_UNSPEC } __wasi_address_family_t;
typedef struct __wasi_addr_info_t {
__wasi_addr_t addr;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c
index defbc6efeb6..1172d0a7738 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c
@@ -430,6 +430,9 @@ addrinfo_hints_to_wasi_hints(const struct addrinfo *hints,
case AF_INET6:
wasi_hints->family = INET6;
break;
+ case AF_UNSPEC:
+ wasi_hints->family = INET_UNSPEC;
+ break;
default:
return __WASI_ERRNO_AFNOSUPPORT;
}
@@ -440,6 +443,8 @@ addrinfo_hints_to_wasi_hints(const struct addrinfo *hints,
case SOCK_DGRAM:
wasi_hints->type = SOCKET_DGRAM;
break;
+ case 0:
+ wasi_hints->type = SOCKET_ANY;
default:
return __WASI_ERRNO_NOTSUP;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/build.sh
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/build.sh
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/build.sh
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json
new file mode 100644
index 00000000000..b0afd1d6b6a
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json
@@ -0,0 +1,3 @@
+{
+ "name": "WAMR lib-socket tests"
+}
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/nslookup.c
similarity index 64%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/nslookup.c
index 37150f1eb7f..8e64d06be30 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/nslookup.c
@@ -5,6 +5,8 @@
#include
#include
+#include
+#include
#ifdef __wasi__
#include
#include
@@ -39,11 +41,28 @@ test_nslookup(int af)
freeaddrinfo(res);
}
+void *
+test_nslookup_mt(void *params)
+{
+ int *af = (int *)params;
+ test_nslookup(*af);
+ return NULL;
+}
+
int
main()
{
- test_nslookup(AF_INET); /* for ipv4 */
- test_nslookup(AF_INET6); /* for ipv6 */
+ int afs[] = { AF_INET, AF_INET6 };
+
+ for (int i = 0; i < sizeof(afs) / sizeof(afs[0]); i++) {
+ pthread_t th;
+
+ printf("Testing %d in main thread...\n", afs[i]);
+ test_nslookup(afs[i]);
+ printf("Testing %d in a new thread...\n", afs[i]);
+ pthread_create(&th, NULL, test_nslookup_mt, &afs[i]);
+ pthread_join(th, NULL);
+ }
return 0;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c
new file mode 100644
index 00000000000..0ed03125074
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+#include
+#include
+#include
+#include
+#include
+#ifdef __wasi__
+#include
+#include
+#include
+#endif
+#include
+#include
+#include
+
+#define SERVER_MSG "Message from server."
+#define PORT 8989
+
+pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+
+int server_init_complete = 0;
+
+typedef struct {
+ struct sockaddr_storage addr;
+ socklen_t addr_len;
+ int sock;
+ int protocol;
+} socket_info_t;
+
+void
+wait_for_server(int wait_time_seconds)
+{
+ int res = 0;
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += wait_time_seconds;
+
+ pthread_mutex_lock(&mut);
+ while (server_init_complete == 0) {
+ res = pthread_cond_timedwait(&cond, &mut, &ts);
+ if (res == ETIMEDOUT)
+ break;
+ }
+ pthread_mutex_unlock(&mut);
+
+ assert(res == 0);
+}
+
+void
+notify_server_started()
+{
+ pthread_mutex_lock(&mut);
+ server_init_complete = 1;
+ pthread_cond_signal(&cond);
+ pthread_mutex_unlock(&mut);
+}
+
+socket_info_t
+init_socket_addr(int family, int protocol)
+{
+ socket_info_t info;
+
+ info.sock = socket(family, protocol, 0);
+ assert(info.sock != -1);
+ info.protocol = protocol;
+
+ memset(&info.addr, 0, sizeof(info.addr));
+
+ if (family == AF_INET) {
+ struct sockaddr_in *addr = (struct sockaddr_in *)&info.addr;
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons(PORT);
+ addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ info.addr_len = sizeof(struct sockaddr_in);
+ }
+ else if (family == AF_INET6) {
+ struct sockaddr_in6 *addr = (struct sockaddr_in6 *)&info.addr;
+ addr->sin6_family = AF_INET6;
+ addr->sin6_port = htons(PORT);
+ addr->sin6_addr = in6addr_loopback;
+ info.addr_len = sizeof(struct sockaddr_in6);
+ }
+
+ return info;
+}
+
+void *
+server(void *arg)
+{
+ char buffer[sizeof(SERVER_MSG) + 1] = { 0 };
+ struct sockaddr_storage client_addr;
+ socket_info_t *info = (socket_info_t *)arg;
+ struct sockaddr *server_addr = (struct sockaddr *)&info->addr;
+ int server_sock = info->sock;
+
+ int optval = 1;
+ assert(setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &optval,
+ sizeof(optval))
+ == 0);
+
+ assert(bind(server_sock, server_addr, info->addr_len) == 0);
+
+ if (info->protocol == SOCK_STREAM)
+ listen(server_sock, 1);
+ notify_server_started();
+
+ socklen_t addr_size = info->addr_len;
+ if (info->protocol == SOCK_STREAM) {
+ int client_sock =
+ accept(server_sock, (struct sockaddr *)&client_addr, &addr_size);
+ assert(client_sock >= 0);
+ assert(recv(client_sock, buffer, sizeof(buffer), 0) > 0);
+ strcpy(buffer, SERVER_MSG);
+ assert(send(client_sock, buffer, sizeof(buffer), 0) > 0);
+ assert(recv(client_sock, buffer, sizeof(buffer), 0) > 0);
+ }
+ else {
+ assert(recvfrom(server_sock, buffer, sizeof(buffer), 0,
+ (struct sockaddr *)&client_addr, &addr_size)
+ > 0);
+ strcpy(buffer, SERVER_MSG);
+ assert(sendto(server_sock, buffer, strlen(buffer), 0,
+ (struct sockaddr *)&client_addr, addr_size)
+ > 0);
+ assert(recvfrom(server_sock, buffer, sizeof(buffer), 0,
+ (struct sockaddr *)&client_addr, &addr_size)
+ > 0);
+ }
+ assert(close(server_sock) == 0);
+
+ return NULL;
+}
+
+void *
+client(void *arg)
+{
+ char buffer[sizeof(SERVER_MSG) + 1];
+ socket_info_t *info = (socket_info_t *)arg;
+ int sock = info->sock;
+ struct sockaddr *addr = (struct sockaddr *)&info->addr;
+
+ wait_for_server(1);
+
+ if (info->protocol == SOCK_STREAM) {
+ assert(connect(sock, addr, info->addr_len) != -1);
+ }
+
+ assert(sendto(sock, "open", strlen("open"), 0, addr, info->addr_len) > 0);
+ assert(recv(sock, buffer, sizeof(buffer), 0) > 0);
+ assert(strncmp(buffer, SERVER_MSG, strlen(SERVER_MSG)) == 0);
+ assert(sendto(sock, "close", sizeof("close"), 0, addr, info->addr_len) > 0);
+ assert(close(sock) == 0);
+
+ return NULL;
+}
+
+void
+test_protocol(int family, int protocol)
+{
+ pthread_t server_thread, client_thread;
+ socket_info_t server_info = init_socket_addr(family, protocol);
+ socket_info_t client_info = init_socket_addr(family, protocol);
+
+ printf("Testing address family: %d protocol: %d\n", family, protocol);
+
+ server_init_complete = 0;
+
+ assert(pthread_create(&server_thread, NULL, server, (void *)&server_info)
+ == 0);
+ assert(pthread_create(&client_thread, NULL, client, (void *)&client_info)
+ == 0);
+ assert(pthread_join(server_thread, NULL) == 0);
+ assert(pthread_join(client_thread, NULL) == 0);
+}
+
+int
+main(int argc, char **argv)
+{
+ /* test tcp with ipv4 and ipv6 */
+ test_protocol(AF_INET, SOCK_STREAM);
+ test_protocol(AF_INET6, SOCK_STREAM);
+
+ /* test udp with ipv4 and ipv6 */
+ test_protocol(AF_INET, SOCK_DGRAM);
+ test_protocol(AF_INET6, SOCK_DGRAM);
+
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c
index 6b36c9073fb..7e557be9009 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c
@@ -80,9 +80,6 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
int32 thread_id;
uint32 stack_size = 8192;
int32 ret = -1;
-#if WASM_ENABLE_LIBC_WASI != 0
- WASIContext *wasi_ctx;
-#endif
bh_assert(module);
bh_assert(module_inst);
@@ -90,7 +87,7 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
stack_size = ((WASMModuleInstance *)module_inst)->default_wasm_stack_size;
if (!(new_module_inst = wasm_runtime_instantiate_internal(
- module, true, exec_env, stack_size, 0, NULL, 0)))
+ module, module_inst, exec_env, stack_size, 0, NULL, 0)))
return -1;
wasm_runtime_set_custom_data_internal(
@@ -99,11 +96,7 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst)))
goto thread_preparation_fail;
-#if WASM_ENABLE_LIBC_WASI != 0
- wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst);
- if (wasi_ctx)
- wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
-#endif
+ wasm_native_inherit_contexts(new_module_inst, module_inst);
start_func = wasm_runtime_lookup_function(new_module_inst,
THREAD_START_FUNCTION, NULL);
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh
new file mode 100755
index 00000000000..1ea95cb97c4
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+
+set -eo pipefail
+CC=${CC:=/opt/wasi-sdk/bin/clang}
+WAMR_DIR=../../../../..
+
+show_usage() {
+ echo "Usage: $0 [--sysroot PATH_TO_SYSROOT]"
+ echo "--sysroot PATH_TO_SYSROOT specify to build with custom sysroot for wasi-libc"
+}
+
+while [[ $# -gt 0 ]]; do
+ key="$1"
+ case $key in
+ --sysroot)
+ sysroot_path="$2"
+ shift
+ shift
+ ;;
+ --help)
+ show_usage
+ exit
+ ;;
+ *)
+ echo "Unknown option: $1"
+ exit 1
+ ;;
+ esac
+done
+
+rm -rf *.wasm
+rm -rf *.aot
+
+for test_c in *.c; do
+ test_wasm="$(basename $test_c .c).wasm"
+
+ if [[ -n "$sysroot_path" ]]; then
+ if [ ! -d "$sysroot_path" ]; then
+ echo "Directory $sysroot_path doesn't exist. Aborting"
+ exit 1
+ fi
+ sysroot_command="--sysroot $sysroot_path"
+ fi
+
+ echo "Compiling $test_c to $test_wasm"
+ $CC \
+ -target wasm32-wasi-threads \
+ -O2 \
+ -Wall \
+ -pthread \
+ -z stack-size=32768 \
+ -Wl,--export=__heap_base \
+ -Wl,--export=__data_end \
+ -Wl,--shared-memory,--max-memory=1966080 \
+ -Wl,--export=wasi_thread_start \
+ -Wl,--export=malloc \
+ -Wl,--export=free \
+ -Wl,--export=test \
+ $sysroot_command \
+ $test_c -o $test_wasm
+done
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c
new file mode 100644
index 00000000000..946e8bd6347
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+#include
+#include "mutex_common.h"
+
+void
+test()
+{
+ pthread_mutex_t mutex;
+
+ // Set mutex type to errorcheck. This type provides some additional checks
+ // (for example returns EDEADLK instead of deadlocking in some cases)
+ pthread_mutexattr_t mutex_attr;
+ pthread_mutexattr_init(&mutex_attr);
+ pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
+
+ pthread_mutex_init(&mutex, &mutex_attr);
+ pthread_mutexattr_destroy(&mutex_attr);
+
+ run_common_tests(&mutex);
+ fprintf(stderr, "Errorcheck mutex test is completed\n");
+ pthread_mutex_destroy(&mutex);
+}
+
+int
+main()
+{
+ test();
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json
new file mode 100644
index 00000000000..bb91ad083e8
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json
@@ -0,0 +1,3 @@
+{
+ "name": "lib-wasi-threads stress tests"
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h
new file mode 100644
index 00000000000..d57ff7d50eb
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef MUTEX_COMMON_H
+#define MUTEX_COMMON_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+enum Constants {
+ NUM_ITER = 250000,
+ NUM_THREADS = 12,
+ NUM_RETRY = 8,
+ RETRY_SLEEP_TIME_US = 1000,
+};
+
+// We're counting how many times each thread was called using this array
+// Main thread is also counted here so we need to make arrays bigger
+typedef struct {
+ int tids[NUM_THREADS + 1];
+ int calls[NUM_THREADS + 1];
+} StatCollector;
+
+typedef struct {
+ pthread_mutex_t *mutex;
+ StatCollector stat;
+ int counter;
+ bool is_sleeping;
+} MutexCounter;
+
+// This enum defines whether thread should sleep to increase contention
+enum SleepState {
+ NON_SLEEP = 0,
+ SLEEP = 1,
+};
+
+void
+mutex_counter_init(MutexCounter *mutex_counter, pthread_mutex_t *mutex,
+ enum SleepState is_sleeping)
+{
+ memset(mutex_counter, 0, sizeof(*mutex_counter));
+ mutex_counter->mutex = mutex;
+ mutex_counter->is_sleeping = is_sleeping;
+}
+
+// This function spawns the thread using exponential retries if it receives
+// EAGAIN
+static inline void
+spawn_thread(pthread_t *tid, void *func, void *arg)
+{
+ int status_code = -1;
+ int timeout_us = RETRY_SLEEP_TIME_US;
+ for (int tries = 0; status_code != 0 && tries < NUM_RETRY; ++tries) {
+ status_code = pthread_create(tid, NULL, (void *(*)(void *))func, arg);
+ assert(status_code == 0 || status_code == EAGAIN);
+ if (status_code == EAGAIN) {
+ usleep(timeout_us);
+ timeout_us *= 2;
+ }
+ }
+
+ assert(status_code == 0 && "Thread creation should succeed");
+}
+
+// This function adds tid to our stat
+static inline void
+add_to_stat(StatCollector *stat, int tid)
+{
+ int tid_num = 0;
+ for (; tid_num < NUM_THREADS + 1 && stat->tids[tid_num] != 0; ++tid_num) {
+ if (stat->tids[tid_num] == tid) {
+ stat->calls[tid_num]++;
+ return;
+ }
+ }
+
+ assert(tid_num < NUM_THREADS + 1);
+ stat->tids[tid_num] = tid;
+ stat->calls[tid_num] = 1;
+}
+
+// This function prints number of calls by TID
+static inline void
+print_stat(StatCollector *stat)
+{
+ fprintf(stderr, "Thread calls count by TID\n");
+ for (int i = 0; i < NUM_THREADS + 1; ++i) {
+ if (stat->tids[i] != 0) {
+ fprintf(stderr, "TID: %d; Calls: %d\n", stat->tids[i],
+ stat->calls[i]);
+ }
+ }
+}
+
+// This function is run by the threads, it increases counter in a loop and then
+// sleeps after unlocking the mutex to provide better contention
+static inline void *
+inc_shared_variable(void *arg)
+{
+ MutexCounter *mutex_counter = (MutexCounter *)(arg);
+ int sleep_us = 0;
+ while (!pthread_mutex_lock(mutex_counter->mutex)
+ && mutex_counter->counter < NUM_ITER) {
+ mutex_counter->counter++;
+ add_to_stat(&mutex_counter->stat, (int)(pthread_self()));
+ if (mutex_counter->is_sleeping) {
+ sleep_us = rand() % 1000;
+ }
+
+ assert(pthread_mutex_unlock(mutex_counter->mutex) == 0
+ && "Should be able to unlock a mutex");
+ if (mutex_counter->is_sleeping) {
+ usleep(sleep_us);
+ }
+ }
+
+ assert(mutex_counter->counter == NUM_ITER);
+ assert(pthread_mutex_unlock(mutex_counter->mutex) == 0
+ && "Should be able to unlock the mutex after test execution");
+
+ return NULL;
+}
+
+// Locking and unlocking a mutex in a single thread.
+static inline void *
+same_thread_lock_unlock_test(void *mutex)
+{
+ for (int i = 0; i < NUM_ITER; ++i) {
+ assert(pthread_mutex_lock(mutex) == 0
+ && "Main thread should be able to lock a mutex");
+ assert(pthread_mutex_unlock(mutex) == 0
+ && "Main thread should be able to unlock a mutex");
+ }
+
+ return NULL;
+}
+
+// This function spawns a thread that locks and unlocks a mutex `NUM_ITER` times
+// in a row
+static inline void
+same_non_main_thread_lock_unlock_test(pthread_mutex_t *mutex)
+{
+ pthread_t tid = 0;
+ spawn_thread(&tid, same_thread_lock_unlock_test, mutex);
+
+ assert(tid != 0 && "TID can't be 0 after successful thread creation");
+ assert(pthread_join(tid, NULL) == 0
+ && "Thread should be joined successfully");
+}
+
+// This function checks basic contention between main and non-main thread
+// increasing the shared variable
+static inline void
+two_threads_inc_test(pthread_mutex_t *mutex)
+{
+ MutexCounter mutex_counter;
+ mutex_counter_init(&mutex_counter, mutex, false);
+
+ pthread_t tid = 0;
+ spawn_thread(&tid, inc_shared_variable, &mutex_counter);
+
+ assert(tid != 0 && "TID can't be 0 after successful thread creation");
+ inc_shared_variable(&mutex_counter);
+ assert(pthread_join(tid, NULL) == 0
+ && "Thread should be joined without errors");
+ assert(mutex_counter.counter == NUM_ITER);
+}
+
+// This function creates number of threads specified by NUM_THREADS and run
+// concurrent increasing of shared variable
+static inline void
+max_threads_inc_test(pthread_mutex_t *mutex, int threads_num,
+ enum SleepState is_sleeping)
+{
+ MutexCounter mutex_counter;
+ mutex_counter_init(&mutex_counter, mutex, is_sleeping);
+
+ pthread_t tids[threads_num];
+ for (int i = 0; i < threads_num; ++i) {
+ spawn_thread(&tids[i], inc_shared_variable, &mutex_counter);
+ }
+
+ inc_shared_variable(&mutex_counter);
+
+ for (int i = 0; i < threads_num; ++i) {
+ assert(pthread_join(tids[i], NULL) == 0
+ && "Thread should be joined without errors");
+ }
+
+ print_stat(&mutex_counter.stat);
+}
+
+// This function just runs all the tests described above
+static inline void
+run_common_tests(pthread_mutex_t *mutex)
+{
+ srand(time(NULL));
+
+ fprintf(stderr, "Starting same_thread_lock_unlock_test test\n");
+ same_thread_lock_unlock_test(mutex);
+ fprintf(stderr, "Finished same_thread_lock_unlock_test test\n");
+
+ fprintf(stderr, "Starting same_non_main_thread_lock_unlock_test test\n");
+ same_non_main_thread_lock_unlock_test(mutex);
+ fprintf(stderr, "Finished same_non_main_thread_lock_unlock_test test\n");
+
+ fprintf(stderr, "Starting two_threads_inc_test test\n");
+ two_threads_inc_test(mutex);
+ fprintf(stderr, "Finished two_threads_inc_test test\n");
+
+ fprintf(stderr, "Starting max_threads_inc_test_sleep test\n");
+ max_threads_inc_test(mutex, NUM_THREADS, SLEEP);
+ fprintf(stderr, "Finished concurrent_inc sleep test\n");
+
+ fprintf(stderr, "Starting max_threads_inc_test_non_sleep test\n");
+ max_threads_inc_test(mutex, NUM_THREADS, NON_SLEEP);
+ fprintf(stderr, "Finished max_threads_inc_test test\n");
+}
+
+#endif // MUTEX_COMMON_H
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c
new file mode 100644
index 00000000000..c7ffae279a0
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+#include
+#include "mutex_common.h"
+
+void
+test()
+{
+ pthread_mutex_t mutex;
+ pthread_mutex_init(&mutex, NULL);
+
+ run_common_tests(&mutex);
+
+ fprintf(stderr, "Normal mutex test is completed\n");
+ pthread_mutex_destroy(&mutex);
+}
+
+int
+main()
+{
+ test();
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c
new file mode 100644
index 00000000000..5874372cb35
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+#include
+#include "mutex_common.h"
+
+void
+multiple_same_thread_lock(void *mutex)
+{
+ for (int i = 0; i < 100; ++i) {
+ assert(pthread_mutex_lock(mutex) == 0
+ && "Recursive mutex should allow multiple locking");
+ }
+
+ for (int i = 0; i < 100; ++i) {
+ assert(pthread_mutex_unlock(mutex) == 0
+ && "Recursive mutex should allow multiple unlocking");
+ }
+}
+
+void *
+same_thread_multiple_rec_mutex_lock(void *mutex)
+{
+ for (int i = 0; i < NUM_ITER; ++i) {
+ multiple_same_thread_lock(mutex);
+ }
+
+ return NULL;
+}
+
+void
+test()
+{
+ pthread_mutex_t mutex;
+
+ // Set mutex type to recursive. This type allows multiple locking and
+ // unlocking within the same thread
+ pthread_mutexattr_t mutex_attr;
+ pthread_mutexattr_init(&mutex_attr);
+ pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
+
+ pthread_mutex_init(&mutex, &mutex_attr);
+ pthread_mutexattr_destroy(&mutex_attr);
+
+ run_common_tests(&mutex);
+
+ fprintf(stderr, "Starting same_thread_multiple_rec_mutex_lock test\n");
+ same_thread_multiple_rec_mutex_lock(&mutex);
+ fprintf(stderr, "Finished same_thread_multiple_rec_mutex_lock test\n");
+
+ fprintf(stderr, "Starting same_thread_multiple_rec_mutex_lock test in "
+ "non-main thread\n");
+ pthread_t tid;
+ spawn_thread(&tid, same_thread_multiple_rec_mutex_lock, &mutex);
+ assert(pthread_join(tid, NULL) == 0
+ && "Non-main thread should be joined successfully");
+ fprintf(stderr, "Finished same_thread_multiple_rec_mutex_lock test in "
+ "non-main thread\n");
+
+ fprintf(stderr, "Recursive mutex test is completed\n");
+ pthread_mutex_destroy(&mutex);
+}
+
+int
+main()
+{
+ test();
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c
new file mode 100644
index 00000000000..8cb61a2a694
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef __wasi__
+#error This example only compiles to WASM/WASI target
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+unsigned prime_numbers_count = 0;
+
+bool
+is_prime(unsigned int num)
+{
+ for (unsigned int i = 2; i <= (unsigned int)(sqrt(num)); ++i) {
+ if (num % i == 0) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void *
+check_if_prime(void *value)
+{
+ unsigned int *num = (unsigned int *)(value);
+ usleep(10000);
+ if (is_prime(*num)) {
+ __atomic_fetch_add(&prime_numbers_count, 1, __ATOMIC_SEQ_CST);
+ }
+ return NULL;
+}
+
+unsigned int
+validate(int iter_num)
+{
+ unsigned int counter = 0;
+ for (unsigned int i = 2; i <= iter_num; ++i) {
+ counter += is_prime(i);
+ }
+
+ return counter;
+}
+
+void
+spawn_thread(pthread_t *thread, int retry_time_us, int retry_num,
+ unsigned int *arg)
+{
+ int status_code = -1;
+ int timeout_us = retry_time_us;
+ for (int tries = 0; status_code != 0 && tries < retry_num; ++tries) {
+ status_code = pthread_create(thread, NULL, &check_if_prime, arg);
+ assert(status_code == 0 || status_code == EAGAIN);
+ if (status_code == EAGAIN) {
+ usleep(timeout_us);
+ timeout_us *= 2;
+ }
+ }
+
+ assert(status_code == 0 && "Thread creation should succeed");
+}
+
+void
+test(int iter_num, int retry_num, int max_threads_num, int retry_time_us)
+{
+ pthread_t threads[max_threads_num];
+ unsigned int args[max_threads_num];
+ double percentage = 0.1;
+
+ for (unsigned int factorised_number = 2; factorised_number < iter_num;
+ ++factorised_number) {
+ if (factorised_number > iter_num * percentage) {
+ fprintf(stderr, "Stress test is %d%% finished\n",
+ (unsigned int)(percentage * 100));
+ percentage += 0.1;
+ }
+
+ unsigned int thread_num = factorised_number % max_threads_num;
+ if (threads[thread_num] != 0) {
+ assert(pthread_join(threads[thread_num], NULL) == 0);
+ }
+
+ args[thread_num] = factorised_number;
+
+ usleep(retry_time_us);
+ spawn_thread(&threads[thread_num], retry_time_us, retry_num,
+ &args[thread_num]);
+ assert(threads[thread_num] != 0);
+ }
+
+ for (int i = 0; i < max_threads_num; ++i) {
+ assert(threads[i] == 0 || pthread_join(threads[i], NULL) == 0);
+ }
+
+ // Check the test results
+ assert(
+ prime_numbers_count == validate(iter_num)
+ && "Answer mismatch between tested code and reference implementation");
+
+ fprintf(stderr, "Stress test finished successfully\n");
+}
+
+enum DEFAULT_PARAMETERS {
+ ITER_NUM = 20000,
+ RETRY_NUM = 8,
+ MAX_THREADS_NUM = 12,
+ RETRY_SLEEP_TIME_US = 2000,
+};
+
+int
+main(int argc, char **argv)
+{
+ test(ITER_NUM, RETRY_NUM, MAX_THREADS_NUM, RETRY_SLEEP_TIME_US);
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c
new file mode 100644
index 00000000000..c4c2d2857e0
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+int threads_executed = 0;
+unsigned int threads_creation_tried = 0;
+unsigned int threads_in_use = 0;
+
+void *
+thread_func(void *arg)
+{
+ (void)(arg);
+ __atomic_fetch_add(&threads_executed, 1, __ATOMIC_RELAXED);
+ __atomic_fetch_sub(&threads_in_use, 1, __ATOMIC_SEQ_CST);
+ return NULL;
+}
+
+void
+spawn_thread(pthread_t *thread, int retry_time, int iter_num)
+{
+ int status_code = -1;
+ int timeout_us = retry_time;
+ for (int tries = 0; status_code != 0 && tries < iter_num; ++tries) {
+ status_code = pthread_create(thread, NULL, &thread_func, NULL);
+ __atomic_fetch_add(&threads_creation_tried, 1, __ATOMIC_RELAXED);
+
+ assert(status_code == 0 || status_code == EAGAIN);
+ if (status_code == EAGAIN) {
+ usleep(timeout_us);
+ timeout_us *= 2;
+ }
+ }
+
+ assert(status_code == 0 && "Thread creation should succeed");
+}
+
+void
+test(int iter_num, int max_threads_num, int retry_num, int retry_time_us)
+{
+ double percentage = 0.1;
+ int second_us = 1000 * 1000 * 1000; // 1 second in us
+
+ for (int iter = 0; iter < iter_num; ++iter) {
+ if (iter > iter_num * percentage) {
+ fprintf(stderr, "Spawning stress test is %d%% finished\n",
+ (unsigned int)(percentage * 100));
+ percentage += 0.1;
+ }
+ while (__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST)
+ == max_threads_num) {
+ usleep(100);
+ }
+
+ __atomic_fetch_add(&threads_in_use, 1, __ATOMIC_SEQ_CST);
+ pthread_t tmp;
+ spawn_thread(&tmp, retry_time_us, iter_num);
+ pthread_detach(tmp);
+ }
+
+ while ((__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) != 0)) {
+ // Casting to int* to supress compiler warning
+ __builtin_wasm_memory_atomic_wait32((int *)(&threads_in_use), 0,
+ second_us);
+ }
+
+ assert(__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) == 0);
+
+ // Validation
+ assert(threads_creation_tried >= threads_executed
+ && "Test executed more threads than were created");
+ assert((1. * threads_creation_tried) / threads_executed < 2.5
+ && "Ensuring that we're retrying thread creation less than 2.5 "
+ "times on average ");
+
+ fprintf(stderr,
+ "Spawning stress test finished successfully executed %d threads "
+ "with retry ratio %f\n",
+ threads_creation_tried,
+ (1. * threads_creation_tried) / threads_executed);
+}
+
+enum DEFAULT_PARAMETERS {
+ ITER_NUM = 50000,
+ RETRY_NUM = 8,
+ MAX_NUM_THREADS = 12,
+ RETRY_SLEEP_TIME_US = 4000,
+};
+
+int
+main(int argc, char **argv)
+{
+ test(ITER_NUM, MAX_NUM_THREADS, RETRY_NUM, RETRY_SLEEP_TIME_US);
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh
new file mode 100755
index 00000000000..608dd226082
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+
+set -eo pipefail
+CC=${CC:=/opt/wasi-sdk/bin/clang}
+WAMR_DIR=../../../../..
+
+show_usage() {
+ echo "Usage: $0 [--sysroot PATH_TO_SYSROOT]"
+ echo "--sysroot PATH_TO_SYSROOT specify to build with custom sysroot for wasi-libc"
+}
+
+while [[ $# -gt 0 ]]; do
+ key="$1"
+ case $key in
+ --sysroot)
+ sysroot_path="$2"
+ shift
+ shift
+ ;;
+ --help)
+ show_usage
+ exit
+ ;;
+ *)
+ echo "Unknown option: $1"
+ exit 1
+ ;;
+ esac
+done
+
+# Stress tests names
+thread_start_file_exclusions=("linear_memory_size_update.wasm")
+
+rm -rf *.wasm
+rm -rf *.aot
+
+for test_c in *.c; do
+ test_wasm="$(basename $test_c .c).wasm"
+
+ if [[ " ${thread_start_file_exclusions[@]} " =~ " ${test_wasm} " ]] ; then
+ thread_start_file=""
+ else
+ thread_start_file=$WAMR_DIR/samples/wasi-threads/wasm-apps/wasi_thread_start.S
+ fi
+
+ if [[ -n "$sysroot_path" ]]; then
+ if [ ! -d "$sysroot_path" ]; then
+ echo "Directory $sysroot_path doesn't exist. Aborting"
+ exit 1
+ fi
+ sysroot_command="--sysroot $sysroot_path"
+ fi
+
+ echo "Compiling $test_c to $test_wasm"
+ $CC \
+ -target wasm32-wasi-threads \
+ -O2 \
+ -pthread -ftls-model=local-exec \
+ -z stack-size=32768 \
+ -Wl,--export=__heap_base \
+ -Wl,--export=__data_end \
+ -Wl,--shared-memory,--max-memory=1966080 \
+ -Wl,--export=wasi_thread_start \
+ -Wl,--export=malloc \
+ -Wl,--export=free \
+ -I $WAMR_DIR/samples/wasi-threads/wasm-apps \
+ $sysroot_command \
+ $thread_start_file \
+ $test_c -o $test_wasm
+done
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/common.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/common.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/common.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c
index 23ba5f62777..94ffa0f67e9 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c
@@ -65,7 +65,7 @@ main(int argc, char **argv)
assert(start_args_init(&data[i].base));
thread_ids[i] = __wasi_thread_spawn(&data[i]);
printf("Thread created with id=%d\n", thread_ids[i]);
- assert(thread_ids[i] > 0 && "Thread creation failed");
+ ASSERT_VALID_TID(thread_ids[i]);
for (int j = 0; j < i; j++) {
assert(thread_ids[i] != thread_ids[j] && "Duplicated TIDs");
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c
index a38e753640f..7e1e8e08128 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c
@@ -49,7 +49,7 @@ main(int argc, char **argv)
for (int i = 0; i < NUM_THREADS; i++) {
assert(start_args_init(&data[i].base));
thread_ids[i] = __wasi_thread_spawn(&data[i]);
- assert(thread_ids[i] > 0 && "Thread creation failed");
+ ASSERT_VALID_TID(thread_ids[i]);
}
printf("Wait for threads to finish\n");
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c
index f81fca49b90..fb33802fce9 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c
@@ -61,7 +61,7 @@ main(int argc, char **argv)
for (int i = 0; i < NUM_THREADS; i++) {
assert(start_args_init(&data[i].base));
thread_ids[i] = __wasi_thread_spawn(&data[i]);
- assert(thread_ids[i] > 0 && "Thread creation failed");
+ ASSERT_VALID_TID(thread_ids[i]);
}
printf("Wait for threads to finish\n");
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json
new file mode 100644
index 00000000000..cd2cc7636ca
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json
@@ -0,0 +1,3 @@
+{
+ "name": "lib-wasi-threads tests"
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
index 69e125d407d..5cf61338f0b 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
@@ -38,7 +38,7 @@ main(int argc, char **argv)
assert(start_args_init(&data.base));
int thread_id = __wasi_thread_spawn(&data);
- assert(thread_id > 0 && "Thread creation failed");
+ ASSERT_VALID_TID(thread_id);
return EXIT_SUCCESS;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c
index b7fb9afba6b..d6e34539be1 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c
@@ -69,7 +69,7 @@ main(int argc, char **argv)
data[i].iteration = i;
thread_ids[i] = __wasi_thread_spawn(&data[i]);
- assert(thread_ids[i] > 0 && "Thread creation failed");
+ ASSERT_VALID_TID(thread_ids[i]);
}
printf("Wait for threads to finish\n");
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c
similarity index 88%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c
index 4d53da0c94f..dc2d4f1bca7 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c
@@ -21,7 +21,8 @@ tid_allocator_init(TidAllocator *tid_allocator)
return false;
for (int64 i = tid_allocator->pos - 1; i >= 0; i--)
- tid_allocator->ids[i] = TID_MIN + (tid_allocator->pos - 1 - i);
+ tid_allocator->ids[i] =
+ (uint32)(TID_MIN + (tid_allocator->pos - 1 - i));
return true;
}
@@ -54,7 +55,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator)
LOG_ERROR("Overflow detected during realloc");
return -1;
}
- int32 *tmp = wasm_runtime_realloc(tid_allocator->ids, realloc_size);
+ int32 *tmp =
+ wasm_runtime_realloc(tid_allocator->ids, (uint32)realloc_size);
if (tmp == NULL) {
LOG_ERROR("Thread ID allocator realloc failed");
return -1;
@@ -64,7 +66,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator)
tid_allocator->pos = new_size - old_size;
tid_allocator->ids = tmp;
for (int64 i = tid_allocator->pos - 1; i >= 0; i--)
- tid_allocator->ids[i] = TID_MIN + (tid_allocator->size - 1 - i);
+ tid_allocator->ids[i] =
+ (uint32)(TID_MIN + (tid_allocator->size - 1 - i));
}
// Pop available thread identifier from the stack
@@ -77,4 +80,4 @@ tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id)
// Release thread identifier by pushing it into the stack
bh_assert(tid_allocator->pos < tid_allocator->size);
tid_allocator->ids[tid_allocator->pos++] = thread_id;
-}
\ No newline at end of file
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h
similarity index 83%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h
index 53af1719ff3..6e25f7749da 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h
@@ -8,8 +8,14 @@
#include "platform_common.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define TID_ALLOCATOR_INIT_SIZE CLUSTER_MAX_THREAD_NUM
enum {
+ /* Keep it in sync with
+ https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
TID_MIN = 1,
TID_MAX = 0x1FFFFFFF
}; // Reserved TIDs (WASI specification)
@@ -33,4 +39,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator);
void
tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _TID_ALLOCATOR_H */
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake
new file mode 100644
index 00000000000..75d8f4e0e64
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake
@@ -0,0 +1,6 @@
+# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+create_wamr_unit_test(wasi_threads
+ ${CMAKE_CURRENT_LIST_DIR}/test_tid_allocator.cpp
+)
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp
new file mode 100644
index 00000000000..6fa7300f6c4
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+
+#include "tid_allocator.h"
+
+#include
+
+class TidAllocatorTest : public ::testing::Test
+{
+ protected:
+ void SetUp() override { ASSERT_TRUE(tid_allocator_init(&_allocator)); }
+
+ void TearDown() override { tid_allocator_deinit(&_allocator); }
+
+ TidAllocator _allocator;
+};
+
+static bool
+is_tid_valid(int32 tid)
+{
+ /* See: https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids
+ */
+ return tid >= TID_MIN && tid <= TID_MAX;
+}
+
+TEST_F(TidAllocatorTest, BasicTest)
+{
+ int32 tid = tid_allocator_get_tid(&_allocator);
+
+ ASSERT_TRUE(is_tid_valid(tid));
+}
+
+TEST_F(TidAllocatorTest, ShouldFailOnAllocatingMoreThanAllowedThreadIDs)
+{
+ int32 last_tid = 0;
+ for (int32 i = 0; i < TID_MAX + 1; i++) {
+ last_tid = tid_allocator_get_tid(&_allocator);
+ if (last_tid < 0) {
+ break;
+ }
+ ASSERT_TRUE(is_tid_valid(last_tid));
+ }
+
+ ASSERT_LT(last_tid, 0);
+}
+
+TEST_F(TidAllocatorTest, ShouldAllocateMoreThanAllowedTIDsIfOldTIDsAreReleased)
+{
+ int32 last_tid = 0;
+ for (int32 i = 0; i < TID_MAX + 1; i++) {
+ if (last_tid != 0) {
+ tid_allocator_release_tid(&_allocator, last_tid);
+ }
+
+ last_tid = tid_allocator_get_tid(&_allocator);
+ ASSERT_TRUE(is_tid_valid(last_tid));
+ }
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake
new file mode 100644
index 00000000000..7949f06f38c
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake
@@ -0,0 +1,28 @@
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Find libuv library
+# This module defines
+# LIBUV_FOUND, if false, do not try to link to libuv
+# LIBUV_LIBRARIES
+# LIBUV_INCLUDE_DIR, where to find uv.h
+
+find_path(LIBUV_INCLUDE_DIR NAMES uv.h)
+find_library(LIBUV_LIBRARIES NAMES uv libuv)
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(
+ LIBUV
+ FOUND_VAR LIBUV_FOUND
+ REQUIRED_VARS
+ LIBUV_LIBRARIES
+ LIBUV_INCLUDE_DIR
+)
+
+if(WIN32)
+ list(APPEND LIBUV_LIBRARIES iphlpapi)
+ list(APPEND LIBUV_LIBRARIES psapi)
+ list(APPEND LIBUV_LIBRARIES userenv)
+ list(APPEND LIBUV_LIBRARIES ws2_32)
+endif()
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake
new file mode 100644
index 00000000000..88499eaa645
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake
@@ -0,0 +1,25 @@
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Find libuvwasi library
+# This module defines
+# UVWASI_FOUND, if false, do not try to link to libuvwasi
+# UVWASI_LIBRARIES
+# UVWASI_INCLUDE_DIR, where to find headers
+
+find_path(UVWASI_INCLUDE_DIR NAMES uvwasi.h wasi_serdes.h wasi_types.h PATH_SUFFIXES uvwasi)
+find_library(UVWASI_LIBRARIES NAMES uvwasi_a)
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(
+ UVWASI
+ FOUND_VAR UVWASI_FOUND
+ REQUIRED_VARS
+ UVWASI_LIBRARIES
+ UVWASI_INCLUDE_DIR
+)
+
+if(UVWASI_FOUND)
+ set(UVWASI_INCLUDE_DIR ${UVWASI_INCLUDE_DIR}/uvwasi)
+endif()
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
new file mode 100644
index 00000000000..7a3bfbdce7d
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
@@ -0,0 +1,61 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set (LIBC_WASI_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+set (LIBUV_VERSION v1.46.0)
+
+add_definitions (-DWASM_ENABLE_LIBC_WASI=1 -DWASM_ENABLE_UVWASI=1)
+
+include(FetchContent)
+
+# Point CMake at the custom modules to find libuv and uvwasi
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
+
+## libuv
+find_package(LIBUV QUIET)
+if (LIBUV_FOUND)
+ include_directories(${LIBUV_INCLUDE_DIR})
+else()
+ FetchContent_Declare(
+ libuv
+ GIT_REPOSITORY https://github.com/libuv/libuv.git
+ GIT_TAG ${LIBUV_VERSION}
+ )
+ FetchContent_GetProperties(libuv)
+ if (NOT libuv_POPULATED)
+ message("-- Fetching libuv ..")
+ FetchContent_Populate(libuv)
+ include_directories("${libuv_SOURCE_DIR}/include")
+ add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
+ set (LIBUV_LIBRARIES uv_a)
+ set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1)
+ endif()
+endif()
+
+## uvwasi
+find_package(UVWASI QUIET)
+if (UVWASI_FOUND)
+ include_directories(${UVWASI_INCLUDE_DIR})
+else()
+ FetchContent_Declare(
+ uvwasi
+ GIT_REPOSITORY https://github.com/nodejs/uvwasi.git
+ GIT_TAG main
+ )
+ FetchContent_GetProperties(uvwasi)
+ if (NOT uvwasi_POPULATED)
+ message("-- Fetching uvwasi ..")
+ FetchContent_Populate(uvwasi)
+ include_directories("${uvwasi_SOURCE_DIR}/include")
+ add_subdirectory(${uvwasi_SOURCE_DIR} ${uvwasi_BINARY_DIR} EXCLUDE_FROM_ALL)
+ set (UVWASI_LIBRARIES uvwasi_a)
+ set_target_properties(uvwasi_a PROPERTIES POSITION_INDEPENDENT_CODE 1)
+ endif()
+endif()
+
+set (UV_A_LIBS ${LIBUV_LIBRARIES} ${UVWASI_LIBRARIES})
+
+file (GLOB_RECURSE source_all ${LIBC_WASI_DIR}/*.c)
+
+set (LIBC_WASI_SOURCE ${source_all})
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c
index 504ff7f93e4..6ead654066d 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c
@@ -30,7 +30,16 @@
wasm_runtime_module_free(module_inst, offset)
/* clang-format on */
-#define wasi_errno_t uvwasi_errno_t
+// uvwasi_errno_t is typedef'd to uint16 which is correct according to the ABI
+// specification. However, in WASM, the smallest integer type is int32. If we
+// return uint16, we would rely on language SDKs to implement the correct
+// behaviour of casting to uint16 before checking the value or using it any way.
+// Failure to do so can cause tricky bugs as the upper 16 bits of the error
+// result are not guaranteed to be zero'ed by us so the result essentially
+// contains garbage from the WASM app perspective. To prevent this, we return
+// uint32 directly instead so as not to be reliant on the correct behaviour of
+// any current/future SDK implementations.
+#define wasi_errno_t uint32_t
#define wasi_fd_t uvwasi_fd_t
#define wasi_clockid_t uvwasi_clockid_t
#define wasi_timestamp_t uvwasi_timestamp_t
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
similarity index 88%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
index afb11925ab3..9f35b81a7f8 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
@@ -7,6 +7,7 @@
#include "bh_platform.h"
#include "wasm_export.h"
#include "wasm_runtime_common.h"
+#include "wasmtime_ssp.h"
#if WASM_ENABLE_THREAD_MGR != 0
#include "../../../thread-mgr/thread_manager.h"
@@ -56,11 +57,13 @@ typedef struct WASIContext *wasi_ctx_t;
wasi_ctx_t
wasm_runtime_get_wasi_ctx(wasm_module_inst_t module_inst);
+#if WASM_ENABLE_THREAD_MGR != 0
static inline uint64_t
min_uint64(uint64_t a, uint64_t b)
{
return a > b ? b : a;
}
+#endif
static inline uint32_t
min_uint32(uint32_t a, uint32_t b)
@@ -190,7 +193,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t)))
return (wasi_errno_t)-1;
- return wasmtime_ssp_clock_res_get(clock_id, resolution);
+ return os_clock_res_get(clock_id, resolution);
}
static wasi_errno_t
@@ -204,7 +207,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
if (!validate_native_addr(time, sizeof(wasi_timestamp_t)))
return (wasi_errno_t)-1;
- return wasmtime_ssp_clock_time_get(clock_id, precision, time);
+ return os_clock_time_get(clock_id, precision, time);
}
static wasi_errno_t
@@ -333,7 +336,7 @@ wasi_fd_close(wasm_exec_env_t exec_env, wasi_fd_t fd)
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_close(curfds, prestats, fd);
+ return wasmtime_ssp_fd_close(exec_env, curfds, prestats, fd);
}
static wasi_errno_t
@@ -346,7 +349,7 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_datasync(curfds, fd);
+ return wasmtime_ssp_fd_datasync(exec_env, curfds, fd);
}
static wasi_errno_t
@@ -387,8 +390,8 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
iovec->buf_len = iovec_app->buf_len;
}
- err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin, iovs_len, offset,
- &nread);
+ err = wasmtime_ssp_fd_pread(exec_env, curfds, fd, iovec_begin, iovs_len,
+ offset, &nread);
if (err)
goto fail;
@@ -441,8 +444,8 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec->buf_len = iovec_app->buf_len;
}
- err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset,
- &nwritten);
+ err = wasmtime_ssp_fd_pwrite(exec_env, curfds, fd, ciovec_begin, iovs_len,
+ offset, &nwritten);
if (err)
goto fail;
@@ -494,7 +497,8 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
iovec->buf_len = iovec_app->buf_len;
}
- err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread);
+ err = wasmtime_ssp_fd_read(exec_env, curfds, fd, iovec_begin, iovs_len,
+ &nread);
if (err)
goto fail;
@@ -519,7 +523,7 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_renumber(curfds, prestats, from, to);
+ return wasmtime_ssp_fd_renumber(exec_env, curfds, prestats, from, to);
}
static wasi_errno_t
@@ -536,7 +540,8 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_seek(curfds, fd, offset, whence, newoffset);
+ return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence,
+ newoffset);
}
static wasi_errno_t
@@ -552,7 +557,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t)))
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_tell(curfds, fd, newoffset);
+ return wasmtime_ssp_fd_tell(exec_env, curfds, fd, newoffset);
}
static wasi_errno_t
@@ -571,7 +576,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t)))
return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_fdstat_get(curfds, fd, &fdstat);
+ err = wasmtime_ssp_fd_fdstat_get(exec_env, curfds, fd, &fdstat);
if (err)
return err;
@@ -590,7 +595,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_fdstat_set_flags(curfds, fd, flags);
+ return wasmtime_ssp_fd_fdstat_set_flags(exec_env, curfds, fd, flags);
}
static wasi_errno_t
@@ -605,8 +610,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base,
- fs_rights_inheriting);
+ return wasmtime_ssp_fd_fdstat_set_rights(
+ exec_env, curfds, fd, fs_rights_base, fs_rights_inheriting);
}
static wasi_errno_t
@@ -619,7 +624,7 @@ wasi_fd_sync(wasm_exec_env_t exec_env, wasi_fd_t fd)
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_sync(curfds, fd);
+ return wasmtime_ssp_fd_sync(exec_env, curfds, fd);
}
static wasi_errno_t
@@ -661,7 +666,8 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
ciovec->buf_len = iovec_app->buf_len;
}
- err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten);
+ err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len,
+ &nwritten);
if (err)
goto fail;
@@ -686,7 +692,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_advise(curfds, fd, offset, len, advice);
+ return wasmtime_ssp_fd_advise(exec_env, curfds, fd, offset, len, advice);
}
static wasi_errno_t
@@ -700,7 +706,7 @@ wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_allocate(curfds, fd, offset, len);
+ return wasmtime_ssp_fd_allocate(exec_env, curfds, fd, offset, len);
}
static wasi_errno_t
@@ -714,7 +720,8 @@ wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_create_directory(curfds, fd, path, path_len);
+ return wasmtime_ssp_path_create_directory(exec_env, curfds, fd, path,
+ path_len);
}
static wasi_errno_t
@@ -731,8 +738,9 @@ wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path,
- old_path_len, new_fd, new_path, new_path_len);
+ return wasmtime_ssp_path_link(exec_env, curfds, prestats, old_fd, old_flags,
+ old_path, old_path_len, new_fd, new_path,
+ new_path_len);
}
static wasi_errno_t
@@ -754,9 +762,9 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
return (wasi_errno_t)-1;
- err = wasmtime_ssp_path_open(curfds, dirfd, dirflags, path, path_len,
- oflags, fs_rights_base, fs_rights_inheriting,
- fs_flags, &fd);
+ err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path,
+ path_len, oflags, fs_rights_base,
+ fs_rights_inheriting, fs_flags, &fd);
*fd_app = fd;
return err;
@@ -778,7 +786,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
if (!validate_native_addr(bufused_app, sizeof(uint32)))
return (wasi_errno_t)-1;
- err = wasmtime_ssp_fd_readdir(curfds, fd, buf, buf_len, cookie, &bufused);
+ err = wasmtime_ssp_fd_readdir(exec_env, curfds, fd, buf, buf_len, cookie,
+ &bufused);
if (err)
return err;
@@ -803,8 +812,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
if (!validate_native_addr(bufused_app, sizeof(uint32)))
return (wasi_errno_t)-1;
- err = wasmtime_ssp_path_readlink(curfds, fd, path, path_len, buf, buf_len,
- &bufused);
+ err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf,
+ buf_len, &bufused);
if (err)
return err;
@@ -824,8 +833,9 @@ wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_rename(curfds, old_fd, old_path, old_path_len,
- new_fd, new_path, new_path_len);
+ return wasmtime_ssp_path_rename(exec_env, curfds, old_fd, old_path,
+ old_path_len, new_fd, new_path,
+ new_path_len);
}
static wasi_errno_t
@@ -842,7 +852,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_get(curfds, fd, filestat);
+ return wasmtime_ssp_fd_filestat_get(exec_env, curfds, fd, filestat);
}
static wasi_errno_t
@@ -857,8 +867,8 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim,
- fstflags);
+ return wasmtime_ssp_fd_filestat_set_times(exec_env, curfds, fd, st_atim,
+ st_mtim, fstflags);
}
static wasi_errno_t
@@ -872,7 +882,7 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_fd_filestat_set_size(curfds, fd, st_size);
+ return wasmtime_ssp_fd_filestat_set_size(exec_env, curfds, fd, st_size);
}
static wasi_errno_t
@@ -890,8 +900,8 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_filestat_get(curfds, fd, flags, path, path_len,
- filestat);
+ return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path,
+ path_len, filestat);
}
static wasi_errno_t
@@ -907,8 +917,9 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_filestat_set_times(
- curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags);
+ return wasmtime_ssp_path_filestat_set_times(exec_env, curfds, fd, flags,
+ path, path_len, st_atim,
+ st_mtim, fstflags);
}
static wasi_errno_t
@@ -924,8 +935,8 @@ wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len,
- fd, new_path, new_path_len);
+ return wasmtime_ssp_path_symlink(exec_env, curfds, prestats, old_path,
+ old_path_len, fd, new_path, new_path_len);
}
static wasi_errno_t
@@ -939,7 +950,7 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_unlink_file(curfds, fd, path, path_len);
+ return wasmtime_ssp_path_unlink_file(exec_env, curfds, fd, path, path_len);
}
static wasi_errno_t
@@ -953,7 +964,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
if (!wasi_ctx)
return (wasi_errno_t)-1;
- return wasmtime_ssp_path_remove_directory(curfds, fd, path, path_len);
+ return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path,
+ path_len);
}
#if WASM_ENABLE_THREAD_MGR != 0
@@ -1024,8 +1036,8 @@ execute_interruptible_poll_oneoff(
/* update timeout for clock subscription events */
update_clock_subscription_data(
in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed));
- err = wasmtime_ssp_poll_oneoff(curfds, in_copy, out, nsubscriptions,
- nevents);
+ err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out,
+ nsubscriptions, nevents);
elapsed += time_quant;
if (err) {
@@ -1077,7 +1089,8 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
return (wasi_errno_t)-1;
#if WASM_ENABLE_THREAD_MGR == 0
- err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents);
+ err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions,
+ &nevents);
#else
err = execute_interruptible_poll_oneoff(curfds, in, out, nsubscriptions,
&nevents, exec_env);
@@ -1131,7 +1144,7 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasi_ssp_sock_accept(curfds, fd, flags, fd_new);
+ return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new);
}
static wasi_errno_t
@@ -1150,7 +1163,7 @@ wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasi_ssp_sock_addr_local(curfds, fd, addr);
+ return wasi_ssp_sock_addr_local(exec_env, curfds, fd, addr);
}
static wasi_errno_t
@@ -1169,7 +1182,7 @@ wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasi_ssp_sock_addr_remote(curfds, fd, addr);
+ return wasi_ssp_sock_addr_remote(exec_env, curfds, fd, addr);
}
static wasi_errno_t
@@ -1190,8 +1203,8 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx);
- return wasi_ssp_sock_addr_resolve(curfds, ns_lookup_list, host, service,
- hints, addr_info, addr_info_size,
+ return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host,
+ service, hints, addr_info, addr_info_size,
max_info_size);
}
@@ -1209,7 +1222,7 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
- return wasi_ssp_sock_bind(curfds, addr_pool, fd, addr);
+ return wasi_ssp_sock_bind(exec_env, curfds, addr_pool, fd, addr);
}
static wasi_errno_t
@@ -1232,7 +1245,7 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx);
- return wasi_ssp_sock_connect(curfds, addr_pool, fd, addr);
+ return wasi_ssp_sock_connect(exec_env, curfds, addr_pool, fd, addr);
}
static wasi_errno_t
@@ -1251,7 +1264,7 @@ wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_broadcast(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_broadcast(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1270,7 +1283,7 @@ wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_keep_alive(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_keep_alive(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1290,7 +1303,8 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_linger(curfds, fd, is_enabled, linger_s);
+ return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled,
+ linger_s);
}
static wasi_errno_t
@@ -1309,7 +1323,7 @@ wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_recv_buf_size(curfds, fd, size);
+ return wasmtime_ssp_sock_get_recv_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@@ -1328,7 +1342,7 @@ wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_recv_timeout(curfds, fd, timeout_us);
+ return wasmtime_ssp_sock_get_recv_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@@ -1347,7 +1361,7 @@ wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_reuse_addr(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_reuse_addr(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1366,7 +1380,7 @@ wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_reuse_port(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_reuse_port(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1385,7 +1399,7 @@ wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_send_buf_size(curfds, fd, size);
+ return wasmtime_ssp_sock_get_send_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@@ -1404,7 +1418,7 @@ wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_send_timeout(curfds, fd, timeout_us);
+ return wasmtime_ssp_sock_get_send_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@@ -1423,7 +1437,8 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_fastopen_connect(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd,
+ is_enabled);
}
static wasi_errno_t
@@ -1442,7 +1457,7 @@ wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_no_delay(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_tcp_no_delay(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1461,7 +1476,8 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_quick_ack(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd,
+ is_enabled);
}
static wasi_errno_t
@@ -1480,7 +1496,7 @@ wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_keep_idle(curfds, fd, time_s);
+ return wasmtime_ssp_sock_get_tcp_keep_idle(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@@ -1499,7 +1515,7 @@ wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_tcp_keep_intvl(curfds, fd, time_s);
+ return wasmtime_ssp_sock_get_tcp_keep_intvl(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@@ -1518,7 +1534,7 @@ wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_ip_multicast_loop(curfds, fd, ipv6,
+ return wasmtime_ssp_sock_get_ip_multicast_loop(exec_env, curfds, fd, ipv6,
is_enabled);
}
@@ -1537,7 +1553,7 @@ wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_ip_ttl(curfds, fd, ttl_s);
+ return wasmtime_ssp_sock_get_ip_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@@ -1556,7 +1572,7 @@ wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_ip_multicast_ttl(curfds, fd, ttl_s);
+ return wasmtime_ssp_sock_get_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@@ -1575,7 +1591,7 @@ wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_get_ipv6_only(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_get_ipv6_only(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1590,7 +1606,7 @@ wasi_sock_listen(wasm_exec_env_t exec_env, wasi_fd_t fd, uint32 backlog)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasi_ssp_sock_listen(curfds, fd, backlog);
+ return wasi_ssp_sock_listen(exec_env, curfds, fd, backlog);
}
static wasi_errno_t
@@ -1607,7 +1623,7 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasi_ssp_sock_open(curfds, poolfd, af, socktype, sockfd);
+ return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd);
}
static wasi_errno_t
@@ -1622,7 +1638,7 @@ wasi_sock_set_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_broadcast(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_broadcast(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1638,7 +1654,7 @@ wasi_sock_set_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_keep_alive(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_keep_alive(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1654,7 +1670,8 @@ wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_linger(curfds, fd, is_enabled, linger_s);
+ return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled,
+ linger_s);
}
static wasi_errno_t
@@ -1669,7 +1686,7 @@ wasi_sock_set_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_recv_buf_size(curfds, fd, size);
+ return wasmtime_ssp_sock_set_recv_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@@ -1685,7 +1702,7 @@ wasi_sock_set_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_recv_timeout(curfds, fd, timeout_us);
+ return wasmtime_ssp_sock_set_recv_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@@ -1701,7 +1718,7 @@ wasi_sock_set_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_reuse_addr(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_reuse_addr(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1717,7 +1734,7 @@ wasi_sock_set_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_reuse_port(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_reuse_port(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1732,7 +1749,7 @@ wasi_sock_set_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_send_buf_size(curfds, fd, size);
+ return wasmtime_ssp_sock_set_send_buf_size(exec_env, curfds, fd, size);
}
static wasi_errno_t
@@ -1748,7 +1765,7 @@ wasi_sock_set_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_send_timeout(curfds, fd, timeout_us);
+ return wasmtime_ssp_sock_set_send_timeout(exec_env, curfds, fd, timeout_us);
}
static wasi_errno_t
@@ -1764,7 +1781,8 @@ wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_fastopen_connect(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd,
+ is_enabled);
}
static wasi_errno_t
@@ -1780,7 +1798,7 @@ wasi_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_no_delay(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_tcp_no_delay(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -1796,7 +1814,8 @@ wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_quick_ack(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd,
+ is_enabled);
}
static wasi_errno_t
@@ -1812,7 +1831,7 @@ wasi_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_keep_idle(curfds, fd, time_s);
+ return wasmtime_ssp_sock_set_tcp_keep_idle(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@@ -1828,7 +1847,7 @@ wasi_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_tcp_keep_intvl(curfds, fd, time_s);
+ return wasmtime_ssp_sock_set_tcp_keep_intvl(exec_env, curfds, fd, time_s);
}
static wasi_errno_t
@@ -1844,7 +1863,7 @@ wasi_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_ip_multicast_loop(curfds, fd, ipv6,
+ return wasmtime_ssp_sock_set_ip_multicast_loop(exec_env, curfds, fd, ipv6,
is_enabled);
}
@@ -1865,8 +1884,8 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_ip_add_membership(curfds, fd, imr_multiaddr,
- imr_interface);
+ return wasmtime_ssp_sock_set_ip_add_membership(
+ exec_env, curfds, fd, imr_multiaddr, imr_interface);
}
static wasi_errno_t
@@ -1886,8 +1905,8 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_ip_drop_membership(curfds, fd, imr_multiaddr,
- imr_interface);
+ return wasmtime_ssp_sock_set_ip_drop_membership(
+ exec_env, curfds, fd, imr_multiaddr, imr_interface);
}
static wasi_errno_t
@@ -1902,7 +1921,7 @@ wasi_sock_set_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t ttl_s)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_ip_ttl(curfds, fd, ttl_s);
+ return wasmtime_ssp_sock_set_ip_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@@ -1918,7 +1937,7 @@ wasi_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd,
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_ip_multicast_ttl(curfds, fd, ttl_s);
+ return wasmtime_ssp_sock_set_ip_multicast_ttl(exec_env, curfds, fd, ttl_s);
}
static wasi_errno_t
@@ -1933,7 +1952,7 @@ wasi_sock_set_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled)
curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx);
- return wasmtime_ssp_sock_set_ipv6_only(curfds, fd, is_enabled);
+ return wasmtime_ssp_sock_set_ipv6_only(exec_env, curfds, fd, is_enabled);
}
static wasi_errno_t
@@ -2051,8 +2070,9 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock,
memset(buf_begin, 0, total_size);
*ro_data_len = 0;
- err = wasmtime_ssp_sock_recv_from(curfds, sock, buf_begin, total_size,
- ri_flags, src_addr, &recv_bytes);
+ err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin,
+ total_size, ri_flags, src_addr,
+ &recv_bytes);
if (err != __WASI_ESUCCESS) {
goto fail;
}
@@ -2151,7 +2171,8 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
return err;
*so_data_len = 0;
- err = wasmtime_ssp_sock_send(curfds, sock, buf, buf_size, &send_bytes);
+ err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size,
+ &send_bytes);
*so_data_len = (uint32)send_bytes;
wasm_runtime_free(buf);
@@ -2191,8 +2212,8 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock,
return err;
*so_data_len = 0;
- err = wasmtime_ssp_sock_send_to(curfds, addr_pool, sock, buf, buf_size,
- si_flags, dest_addr, &send_bytes);
+ err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf,
+ buf_size, si_flags, dest_addr, &send_bytes);
*so_data_len = (uint32)send_bytes;
wasm_runtime_free(buf);
@@ -2210,7 +2231,7 @@ wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
if (!wasi_ctx)
return __WASI_EINVAL;
- return wasmtime_ssp_sock_shutdown(curfds, sock);
+ return wasmtime_ssp_sock_shutdown(exec_env, curfds, sock);
}
static wasi_errno_t
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h
similarity index 70%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h
index be509576b06..d958fa39cb0 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h
@@ -6,7 +6,6 @@
#ifndef _LIBC_WASI_WRAPPER_H
#define _LIBC_WASI_WRAPPER_H
-#include "wasmtime_ssp.h"
#include "posix.h"
#ifdef __cplusplus
@@ -19,7 +18,16 @@ typedef __wasi_advice_t wasi_advice_t;
typedef __wasi_ciovec_t wasi_ciovec_t;
typedef __wasi_clockid_t wasi_clockid_t;
typedef __wasi_dircookie_t wasi_dircookie_t;
-typedef __wasi_errno_t wasi_errno_t;
+// __wasi_errno_t is typedef'd to uint16 which is correct according to the ABI
+// specification. However, in WASM, the smallest integer type is int32. If we
+// return uint16, we would rely on language SDKs to implement the correct
+// behaviour of casting to uint16 before checking the value or using it any way.
+// Failure to do so can cause tricky bugs as the upper 16 bits of the error
+// result are not guaranteed to be zero'ed by us so the result essentially
+// contains garbage from the WASM app perspective. To prevent this, we return
+// uint32 directly instead so as not to be reliant on the correct behaviour of
+// any current/future WASI SDK implemenations.
+typedef uint32_t wasi_errno_t;
typedef __wasi_event_t wasi_event_t;
typedef __wasi_exitcode_t wasi_exitcode_t;
typedef __wasi_fdflags_t wasi_fdflags_t;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h
new file mode 100644
index 00000000000..ed8463866f5
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h
@@ -0,0 +1,606 @@
+/*
+ * Part of the Wasmtime Project, under the Apache License v2.0 with
+ * LLVM Exceptions. See
+ * https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE
+ * for license information.
+ */
+
+/**
+ * The defitions of type, macro and structure in this file should be
+ * consistent with those in wasi-libc:
+ * https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h
+ */
+
+#ifndef WASMTIME_SSP_H
+#define WASMTIME_SSP_H
+
+#include
+#include
+#include
+
+#include "bh_platform.h"
+#include "wasm_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(WASMTIME_SSP_WASI_API)
+#define WASMTIME_SSP_SYSCALL_NAME(name) asm("__wasi_" #name)
+#else
+#define WASMTIME_SSP_SYSCALL_NAME(name)
+#endif
+
+__wasi_errno_t
+wasmtime_ssp_args_get(struct argv_environ_values *arg_environ, char **argv,
+ char *argv_buf)
+ WASMTIME_SSP_SYSCALL_NAME(args_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_args_sizes_get(struct argv_environ_values *arg_environ,
+ size_t *argc, size_t *argv_buf_size)
+ WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_environ_get(struct argv_environ_values *arg_environ,
+ char **environs, char *environ_buf)
+ WASMTIME_SSP_SYSCALL_NAME(environ_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_environ_sizes_get(struct argv_environ_values *arg_environ,
+ size_t *environ_count, size_t *environ_buf_size)
+ WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_prestat_get(struct fd_prestats *prestats, __wasi_fd_t fd,
+ __wasi_prestat_t *buf)
+ WASMTIME_SSP_SYSCALL_NAME(fd_prestat_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd,
+ char *path, size_t path_len)
+ WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, __wasi_fd_t fd)
+ WASMTIME_SSP_SYSCALL_NAME(fd_close) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd)
+ WASMTIME_SSP_SYSCALL_NAME(fd_datasync) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_iovec_t *iovs,
+ size_t iovs_len, __wasi_filesize_t offset, size_t *nread)
+ WASMTIME_SSP_SYSCALL_NAME(fd_pread) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_ciovec_t *iovs,
+ size_t iovs_len, __wasi_filesize_t offset,
+ size_t *nwritten)
+ WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_iovec_t *iovs,
+ size_t iovs_len, size_t *nread)
+ WASMTIME_SSP_SYSCALL_NAME(fd_read) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, __wasi_fd_t from,
+ __wasi_fd_t to)
+ WASMTIME_SSP_SYSCALL_NAME(fd_renumber) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filedelta_t offset,
+ __wasi_whence_t whence, __wasi_filesize_t *newoffset)
+ WASMTIME_SSP_SYSCALL_NAME(fd_seek) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filesize_t *newoffset)
+ WASMTIME_SSP_SYSCALL_NAME(fd_tell) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_fdstat_t *buf)
+ WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_fdflags_t flags)
+ WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_rights_t fs_rights_base,
+ __wasi_rights_t fs_rights_inheriting)
+ WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd)
+ WASMTIME_SSP_SYSCALL_NAME(fd_sync) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_ciovec_t *iovs,
+ size_t iovs_len, size_t *nwritten)
+ WASMTIME_SSP_SYSCALL_NAME(fd_write) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filesize_t offset,
+ __wasi_filesize_t len, __wasi_advice_t advice)
+ WASMTIME_SSP_SYSCALL_NAME(fd_advise) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filesize_t offset,
+ __wasi_filesize_t len)
+ WASMTIME_SSP_SYSCALL_NAME(fd_allocate) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ const char *path, size_t path_len)
+ WASMTIME_SSP_SYSCALL_NAME(path_create_directory) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, __wasi_fd_t old_fd,
+ __wasi_lookupflags_t old_flags, const char *old_path,
+ size_t old_path_len, __wasi_fd_t new_fd,
+ const char *new_path, size_t new_path_len)
+ WASMTIME_SSP_SYSCALL_NAME(path_link) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags,
+ const char *path, size_t path_len,
+ __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base,
+ __wasi_rights_t fs_rights_inheriting,
+ __wasi_fdflags_t fs_flags, __wasi_fd_t *fd)
+ WASMTIME_SSP_SYSCALL_NAME(path_open) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, void *buf, size_t buf_len,
+ __wasi_dircookie_t cookie, size_t *bufused)
+ WASMTIME_SSP_SYSCALL_NAME(fd_readdir) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const char *path, size_t path_len,
+ char *buf, size_t buf_len, size_t *bufused)
+ WASMTIME_SSP_SYSCALL_NAME(path_readlink) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t old_fd, const char *old_path,
+ size_t old_path_len, __wasi_fd_t new_fd,
+ const char *new_path, size_t new_path_len)
+ WASMTIME_SSP_SYSCALL_NAME(path_rename) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filestat_t *buf)
+ WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_timestamp_t st_atim,
+ __wasi_timestamp_t st_mtim,
+ __wasi_fstflags_t fstflags)
+ WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_filesize_t st_size)
+ WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_lookupflags_t flags, const char *path,
+ size_t path_len, __wasi_filestat_t *buf)
+ WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_lookupflags_t flags,
+ const char *path, size_t path_len,
+ __wasi_timestamp_t st_atim,
+ __wasi_timestamp_t st_mtim,
+ __wasi_fstflags_t fstflags)
+ WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, const char *old_path,
+ size_t old_path_len, __wasi_fd_t fd,
+ const char *new_path, size_t new_path_len)
+ WASMTIME_SSP_SYSCALL_NAME(path_symlink) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const char *path, size_t path_len)
+ WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ const char *path, size_t path_len)
+ WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ const __wasi_subscription_t *in, __wasi_event_t *out,
+ size_t nsubscriptions, size_t *nevents)
+ WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_random_get(void *buf, size_t buf_len)
+ WASMTIME_SSP_SYSCALL_NAME(random_get) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_fdflags_t flags,
+ __wasi_fd_t *fd_new) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_addr_t *addr) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_addr_t *addr) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t poolfd, __wasi_address_family_t af,
+ __wasi_sock_type_t socktype,
+ __wasi_fd_t *sockfd) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct addr_pool *addr_pool, __wasi_fd_t fd,
+ __wasi_addr_t *addr) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ char **ns_lookup_list, const char *host,
+ const char *service, __wasi_addr_info_hints_t *hints,
+ __wasi_addr_info_t *addr_info,
+ __wasi_size_t addr_info_size,
+ __wasi_size_t *max_info_size) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct addr_pool *addr_pool, __wasi_fd_t fd,
+ __wasi_addr_t *addr) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t *size) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t *reuse) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t *reuse) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t *size) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t size) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t reuse) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t reuse) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t size) WARN_UNUSED;
+
+__wasi_errno_t
+wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_size_t backlog) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, void *buf, size_t buf_len,
+ size_t *recv_len)
+ WASMTIME_SSP_SYSCALL_NAME(sock_recv) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, void *buf, size_t buf_len,
+ __wasi_riflags_t ri_flags, __wasi_addr_t *src_addr,
+ size_t *recv_len)
+ WASMTIME_SSP_SYSCALL_NAME(sock_recv_from) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, const void *buf, size_t buf_len,
+ size_t *sent_len)
+ WASMTIME_SSP_SYSCALL_NAME(sock_send) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct addr_pool *addr_pool, __wasi_fd_t sock,
+ const void *buf, size_t buf_len,
+ __wasi_siflags_t si_flags,
+ const __wasi_addr_t *dest_addr, size_t *sent_len)
+ WASMTIME_SSP_SYSCALL_NAME(sock_send_to) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock)
+ WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_recv_timeout(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint64_t timeout_us)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_timeout) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_recv_timeout(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint64_t *timeout_us)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_timeout) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_send_timeout(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint64_t timeout_us)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_send_timeout) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_send_timeout(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint64_t *timeout_us)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_send_timeout) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ size_t bufsiz)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_send_buf_size) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ size_t *bufsiz)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_send_buf_size) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ size_t bufsiz)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_buf_size) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ size_t *bufsiz)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_buf_size) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_keep_alive(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_keep_alive) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_keep_alive(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_keep_alive) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_addr) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_addr) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_port) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_port) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, bool is_enabled, int linger_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_linger) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, bool *is_enabled, int *linger_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_linger) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_broadcast(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_broadcast) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_broadcast(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_broadcast) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_tcp_no_delay(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_no_delay) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_tcp_no_delay(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_no_delay) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_quick_ack) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_quick_ack) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint32_t time_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_idle) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint32_t *time_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_idle) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint32_t time_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_intvl) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ uint32_t *time_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_intvl) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_fastopen_connect) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_fastopen_connect) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, bool ipv6,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_loop) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, bool ipv6,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_loop) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock,
+ __wasi_addr_ip_t *imr_multiaddr,
+ uint32_t imr_interface)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_add_membership) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock,
+ __wasi_addr_ip_t *imr_multiaddr,
+ uint32_t imr_interface)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_drop_membership) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_ip_ttl(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, uint8_t ttl_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_ttl) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_ip_ttl(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, uint8_t *ttl_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_ttl) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, uint8_t ttl_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_ttl) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, uint8_t *ttl_s)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_ttl) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_set_ipv6_only(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_set_ipv6_only) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sock_get_ipv6_only(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t sock,
+ bool *is_enabled)
+ WASMTIME_SSP_SYSCALL_NAME(sock_get_ipv6_only) WARN_UNUSED;
+
+__wasi_errno_t
+wasmtime_ssp_sched_yield(void)
+ WASMTIME_SSP_SYSCALL_NAME(sched_yield) WARN_UNUSED;
+
+#ifdef __cplusplus
+}
+#endif
+
+#undef WASMTIME_SSP_SYSCALL_NAME
+
+#endif /* end of WASMTIME_SSP_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c
new file mode 100644
index 00000000000..ec1481c2ef0
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+
+#include "ssp_config.h"
+#include "blocking_op.h"
+
+__wasi_errno_t
+blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle,
+ bool is_stdio)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ return __WASI_EINTR;
+ }
+ __wasi_errno_t error = os_close(handle, is_stdio);
+ wasm_runtime_end_blocking_op(exec_env);
+ return error;
+}
+
+__wasi_errno_t
+blocking_op_readv(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_iovec_t *iov, int iovcnt, size_t *nread)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ return __WASI_EINTR;
+ }
+ __wasi_errno_t error = os_readv(handle, iov, iovcnt, nread);
+ wasm_runtime_end_blocking_op(exec_env);
+ return error;
+}
+
+__wasi_errno_t
+blocking_op_preadv(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_iovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nread)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ return __WASI_EINTR;
+ }
+ __wasi_errno_t ret = os_preadv(handle, iov, iovcnt, offset, nread);
+ wasm_runtime_end_blocking_op(exec_env);
+ return ret;
+}
+
+__wasi_errno_t
+blocking_op_writev(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_ciovec_t *iov, int iovcnt,
+ size_t *nwritten)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ return __WASI_EINTR;
+ }
+ __wasi_errno_t error = os_writev(handle, iov, iovcnt, nwritten);
+ wasm_runtime_end_blocking_op(exec_env);
+ return error;
+}
+
+__wasi_errno_t
+blocking_op_pwritev(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_ciovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nwritten)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ return __WASI_EINTR;
+ }
+ __wasi_errno_t error = os_pwritev(handle, iov, iovcnt, offset, nwritten);
+ wasm_runtime_end_blocking_op(exec_env);
+ return error;
+}
+
+int
+blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock,
+ bh_socket_t *sockp, void *addr,
+ unsigned int *addrlenp)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ errno = EINTR;
+ return -1;
+ }
+ int ret = os_socket_accept(server_sock, sockp, addr, addrlenp);
+ wasm_runtime_end_blocking_op(exec_env);
+ return ret;
+}
+
+int
+blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock,
+ const char *addr, int port)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ errno = EINTR;
+ return -1;
+ }
+ int ret = os_socket_connect(sock, addr, port);
+ wasm_runtime_end_blocking_op(exec_env);
+ return ret;
+}
+
+int
+blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock,
+ void *buf, unsigned int len, int flags,
+ bh_sockaddr_t *src_addr)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ errno = EINTR;
+ return -1;
+ }
+ int ret = os_socket_recv_from(sock, buf, len, flags, src_addr);
+ wasm_runtime_end_blocking_op(exec_env);
+ return ret;
+}
+
+int
+blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock,
+ const void *buf, unsigned int len, int flags,
+ const bh_sockaddr_t *dest_addr)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ errno = EINTR;
+ return -1;
+ }
+ int ret = os_socket_send_to(sock, buf, len, flags, dest_addr);
+ wasm_runtime_end_blocking_op(exec_env);
+ return ret;
+}
+
+int
+blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host,
+ const char *service, uint8_t *hint_is_tcp,
+ uint8_t *hint_is_ipv4,
+ bh_addr_info_t *addr_info,
+ size_t addr_info_size, size_t *max_info_size)
+{
+ /*
+ * Note: Unlike others, os_socket_addr_resolve() is not a simple system
+ * call. It's likely backed by a complex libc function, getaddrinfo().
+ * Depending on the implementation of getaddrinfo() and underlying
+ * DNS resolver, it might or might not be possible to make it return
+ * with os_wakeup_blocking_op().
+ *
+ * Unfortunately, many of ISC/bind based resolvers just keep going on
+ * interrupted system calls. It includes macOS and glibc.
+ *
+ * On the other hand, NuttX as of writing this returns EAI_AGAIN
+ * on EINTR.
+ */
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ errno = EINTR;
+ return -1;
+ }
+ int ret = os_socket_addr_resolve(host, service, hint_is_tcp, hint_is_ipv4,
+ addr_info, addr_info_size, max_info_size);
+ wasm_runtime_end_blocking_op(exec_env);
+ return ret;
+}
+
+__wasi_errno_t
+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)
+{
+ if (!wasm_runtime_begin_blocking_op(exec_env)) {
+ return __WASI_EINTR;
+ }
+ __wasi_errno_t error = os_openat(handle, path, oflags, fd_flags,
+ lookup_flags, access_mode, out);
+ wasm_runtime_end_blocking_op(exec_env);
+ return error;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h
new file mode 100644
index 00000000000..afaa4a4f0cb
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "bh_platform.h"
+#include "wasm_export.h"
+
+__wasi_errno_t
+blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle,
+ bool is_stdio);
+__wasi_errno_t
+blocking_op_readv(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_iovec_t *iov, int iovcnt, size_t *nread);
+__wasi_errno_t
+blocking_op_preadv(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_iovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nread);
+__wasi_errno_t
+blocking_op_writev(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_ciovec_t *iov, int iovcnt,
+ size_t *nwritten);
+__wasi_errno_t
+blocking_op_pwritev(wasm_exec_env_t exec_env, os_file_handle handle,
+ const struct __wasi_ciovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nwritten);
+int
+blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock,
+ bh_socket_t *sockp, void *addr,
+ unsigned int *addrlenp);
+int
+blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock,
+ const char *addr, int port);
+int
+blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock,
+ void *buf, unsigned int len, int flags,
+ bh_sockaddr_t *src_addr);
+int
+blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock,
+ const void *buf, unsigned int len, int flags,
+ const bh_sockaddr_t *dest_addr);
+int
+blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host,
+ const char *service, uint8_t *hint_is_tcp,
+ uint8_t *hint_is_ipv4,
+ bh_addr_info_t *addr_info,
+ size_t addr_info_size, size_t *max_info_size);
+
+__wasi_errno_t
+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);
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h
similarity index 84%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h
index 40b064b8136..5e0778c3f22 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h
@@ -49,7 +49,7 @@
/* Mutex that uses the lock annotations. */
struct LOCKABLE mutex {
- pthread_mutex_t object;
+ korp_mutex object;
};
/* clang-format off */
@@ -60,69 +60,71 @@ struct LOCKABLE mutex {
static inline bool
mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock)
{
- return pthread_mutex_init(&lock->object, NULL) == 0 ? true : false;
+ return os_mutex_init(&lock->object) == BHT_OK ? true : false;
}
static inline void
mutex_destroy(struct mutex *lock) REQUIRES_UNLOCKED(*lock)
{
- pthread_mutex_destroy(&lock->object);
+ os_mutex_destroy(&lock->object);
}
static inline void
mutex_lock(struct mutex *lock) LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
{
- pthread_mutex_lock(&lock->object);
+ os_mutex_lock(&lock->object);
}
static inline void
mutex_unlock(struct mutex *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
{
- pthread_mutex_unlock(&lock->object);
+ os_mutex_unlock(&lock->object);
}
/* Read-write lock that uses the lock annotations. */
struct LOCKABLE rwlock {
- pthread_rwlock_t object;
+ korp_rwlock object;
};
static inline bool
rwlock_init(struct rwlock *lock) REQUIRES_UNLOCKED(*lock)
{
- return pthread_rwlock_init(&lock->object, NULL) == 0 ? true : false;
+ return os_rwlock_init(&lock->object) == 0 ? true : false;
}
static inline void
rwlock_rdlock(struct rwlock *lock) LOCKS_SHARED(*lock) NO_LOCK_ANALYSIS
{
- pthread_rwlock_rdlock(&lock->object);
+ os_rwlock_rdlock(&lock->object);
}
static inline void
rwlock_wrlock(struct rwlock *lock) LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
{
- pthread_rwlock_wrlock(&lock->object);
+ os_rwlock_wrlock(&lock->object);
}
static inline void
rwlock_unlock(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
{
- pthread_rwlock_unlock(&lock->object);
+ os_rwlock_unlock(&lock->object);
}
static inline void
rwlock_destroy(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
{
- pthread_rwlock_destroy(&lock->object);
+ os_rwlock_destroy(&lock->object);
}
/* Condition variable that uses the lock annotations. */
struct LOCKABLE cond {
- pthread_cond_t object;
-#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
- || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
+ korp_cond object;
+
+#if !CONFIG_HAS_CLOCK_NANOSLEEP \
+ && (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
+ || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
clockid_t clock;
#endif
};
@@ -147,43 +149,49 @@ cond_init_monotonic(struct cond *cond)
fail:
pthread_condattr_destroy(&attr);
#else
- if (pthread_cond_init(&cond->object, NULL) != 0)
+ if (os_cond_init(&cond->object) != 0)
return false;
ret = true;
#endif
-#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
- || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
+#if !CONFIG_HAS_CLOCK_NANOSLEEP \
+ && (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
+ || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
cond->clock = CLOCK_MONOTONIC;
#endif
+
return ret;
}
static inline bool
cond_init_realtime(struct cond *cond)
{
- if (pthread_cond_init(&cond->object, NULL) != 0)
+ if (os_cond_init(&cond->object) != 0)
return false;
-#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
- || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
+
+#if !CONFIG_HAS_CLOCK_NANOSLEEP \
+ && (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
+ || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
cond->clock = CLOCK_REALTIME;
#endif
+
return true;
}
static inline void
cond_destroy(struct cond *cond)
{
- pthread_cond_destroy(&cond->object);
+ os_cond_destroy(&cond->object);
}
static inline void
cond_signal(struct cond *cond)
{
- pthread_cond_signal(&cond->object);
+ os_cond_signal(&cond->object);
}
#if !CONFIG_HAS_CLOCK_NANOSLEEP
+
static inline bool
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
@@ -259,7 +267,7 @@ static inline void
cond_wait(struct cond *cond, struct mutex *lock)
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
{
- pthread_cond_wait(&cond->object, &lock->object);
+ os_cond_wait(&cond->object, &lock->object);
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
similarity index 58%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
index 61e84183695..b59035f349e 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
@@ -13,7 +13,9 @@
#include "ssp_config.h"
#include "bh_platform.h"
+#include "blocking_op.h"
#include "wasmtime_ssp.h"
+#include "libc_errno.h"
#include "locking.h"
#include "posix.h"
#include "random.h"
@@ -21,6 +23,18 @@
#include "rights.h"
#include "str.h"
+/* Some platforms (e.g. Windows) already define `min()` macro.
+ We're undefing it here to make sure the `min` call does exactly
+ what we want it to do. */
+#ifdef min
+#undef min
+#endif
+static inline size_t
+min(size_t a, size_t b)
+{
+ return a > b ? b : a;
+}
+
#if 0 /* TODO: -std=gnu99 causes compile error, comment them first */
// struct iovec must have the same layout as __wasi_iovec_t.
static_assert(offsetof(struct iovec, iov_base) ==
@@ -55,111 +69,6 @@ static_assert(sizeof(struct iovec) == sizeof(__wasi_ciovec_t),
"Size mismatch");
#endif
-#if defined(WASMTIME_SSP_STATIC_CURFDS)
-static __thread struct fd_table *curfds;
-static __thread struct fd_prestats *prestats;
-static __thread struct argv_environ_values *argv_environ;
-static __thread struct addr_pool *addr_pool;
-#endif
-
-// Converts a POSIX error code to a CloudABI error code.
-static __wasi_errno_t
-convert_errno(int error)
-{
- static const __wasi_errno_t errors[] = {
-#define X(v) [v] = __WASI_##v
- X(E2BIG),
- X(EACCES),
- X(EADDRINUSE),
- X(EADDRNOTAVAIL),
- X(EAFNOSUPPORT),
- X(EAGAIN),
- X(EALREADY),
- X(EBADF),
- X(EBADMSG),
- X(EBUSY),
- X(ECANCELED),
- X(ECHILD),
- X(ECONNABORTED),
- X(ECONNREFUSED),
- X(ECONNRESET),
- X(EDEADLK),
- X(EDESTADDRREQ),
- X(EDOM),
- X(EDQUOT),
- X(EEXIST),
- X(EFAULT),
- X(EFBIG),
- X(EHOSTUNREACH),
- X(EIDRM),
- X(EILSEQ),
- X(EINPROGRESS),
- X(EINTR),
- X(EINVAL),
- X(EIO),
- X(EISCONN),
- X(EISDIR),
- X(ELOOP),
- X(EMFILE),
- X(EMLINK),
- X(EMSGSIZE),
- X(EMULTIHOP),
- X(ENAMETOOLONG),
- X(ENETDOWN),
- X(ENETRESET),
- X(ENETUNREACH),
- X(ENFILE),
- X(ENOBUFS),
- X(ENODEV),
- X(ENOENT),
- X(ENOEXEC),
- X(ENOLCK),
- X(ENOLINK),
- X(ENOMEM),
- X(ENOMSG),
- X(ENOPROTOOPT),
- X(ENOSPC),
- X(ENOSYS),
-#ifdef ENOTCAPABLE
- X(ENOTCAPABLE),
-#endif
- X(ENOTCONN),
- X(ENOTDIR),
- X(ENOTEMPTY),
- X(ENOTRECOVERABLE),
- X(ENOTSOCK),
- X(ENOTSUP),
- X(ENOTTY),
- X(ENXIO),
- X(EOVERFLOW),
- X(EOWNERDEAD),
- X(EPERM),
- X(EPIPE),
- X(EPROTO),
- X(EPROTONOSUPPORT),
- X(EPROTOTYPE),
- X(ERANGE),
- X(EROFS),
- X(ESPIPE),
- X(ESRCH),
- X(ESTALE),
- X(ETIMEDOUT),
- X(ETXTBSY),
- X(EXDEV),
-#undef X
-#if EOPNOTSUPP != ENOTSUP
- [EOPNOTSUPP] = __WASI_ENOTSUP,
-#endif
-#if EWOULDBLOCK != EAGAIN
- [EWOULDBLOCK] = __WASI_EAGAIN,
-#endif
- };
- if (error < 0 || (size_t)error >= sizeof(errors) / sizeof(errors[0])
- || errors[error] == 0)
- return __WASI_ENOSYS;
- return errors[error];
-}
-
static bool
ns_lookup_list_search(char **list, const char *host)
{
@@ -185,21 +94,9 @@ ns_lookup_list_search(char **list, const char *host)
return false;
}
-// Converts a POSIX timespec to a CloudABI timestamp.
-static __wasi_timestamp_t
-convert_timespec(const struct timespec *ts)
-{
- if (ts->tv_sec < 0)
- return 0;
- if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / 1000000000)
- return UINT64_MAX;
- return (__wasi_timestamp_t)ts->tv_sec * 1000000000
- + (__wasi_timestamp_t)ts->tv_nsec;
-}
-
-// Converts a CloudABI clock identifier to a POSIX clock identifier.
+#if !defined(BH_PLATFORM_WINDOWS) && CONFIG_HAS_CLOCK_NANOSLEEP
static bool
-convert_clockid(__wasi_clockid_t in, clockid_t *out)
+wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out)
{
switch (in) {
case __WASI_CLOCK_MONOTONIC:
@@ -222,28 +119,29 @@ convert_clockid(__wasi_clockid_t in, clockid_t *out)
return false;
}
}
+#endif
static void
wasi_addr_to_bh_sockaddr(const __wasi_addr_t *wasi_addr,
bh_sockaddr_t *sockaddr)
{
if (wasi_addr->kind == IPv4) {
- sockaddr->addr_bufer.ipv4 = (wasi_addr->addr.ip4.addr.n0 << 24)
- | (wasi_addr->addr.ip4.addr.n1 << 16)
- | (wasi_addr->addr.ip4.addr.n2 << 8)
- | wasi_addr->addr.ip4.addr.n3;
+ sockaddr->addr_buffer.ipv4 = (wasi_addr->addr.ip4.addr.n0 << 24)
+ | (wasi_addr->addr.ip4.addr.n1 << 16)
+ | (wasi_addr->addr.ip4.addr.n2 << 8)
+ | wasi_addr->addr.ip4.addr.n3;
sockaddr->is_ipv4 = true;
sockaddr->port = wasi_addr->addr.ip4.port;
}
else {
- sockaddr->addr_bufer.ipv6[0] = wasi_addr->addr.ip6.addr.n0;
- sockaddr->addr_bufer.ipv6[1] = wasi_addr->addr.ip6.addr.n1;
- sockaddr->addr_bufer.ipv6[2] = wasi_addr->addr.ip6.addr.n2;
- sockaddr->addr_bufer.ipv6[3] = wasi_addr->addr.ip6.addr.n3;
- sockaddr->addr_bufer.ipv6[4] = wasi_addr->addr.ip6.addr.h0;
- sockaddr->addr_bufer.ipv6[5] = wasi_addr->addr.ip6.addr.h1;
- sockaddr->addr_bufer.ipv6[6] = wasi_addr->addr.ip6.addr.h2;
- sockaddr->addr_bufer.ipv6[7] = wasi_addr->addr.ip6.addr.h3;
+ sockaddr->addr_buffer.ipv6[0] = wasi_addr->addr.ip6.addr.n0;
+ sockaddr->addr_buffer.ipv6[1] = wasi_addr->addr.ip6.addr.n1;
+ sockaddr->addr_buffer.ipv6[2] = wasi_addr->addr.ip6.addr.n2;
+ sockaddr->addr_buffer.ipv6[3] = wasi_addr->addr.ip6.addr.n3;
+ sockaddr->addr_buffer.ipv6[4] = wasi_addr->addr.ip6.addr.h0;
+ sockaddr->addr_buffer.ipv6[5] = wasi_addr->addr.ip6.addr.h1;
+ sockaddr->addr_buffer.ipv6[6] = wasi_addr->addr.ip6.addr.h2;
+ sockaddr->addr_buffer.ipv6[7] = wasi_addr->addr.ip6.addr.h3;
sockaddr->is_ipv4 = false;
sockaddr->port = wasi_addr->addr.ip6.port;
}
@@ -258,24 +156,24 @@ bh_sockaddr_to_wasi_addr(const bh_sockaddr_t *sockaddr,
wasi_addr->kind = IPv4;
wasi_addr->addr.ip4.port = sockaddr->port;
wasi_addr->addr.ip4.addr.n0 =
- (sockaddr->addr_bufer.ipv4 & 0xFF000000) >> 24;
+ (sockaddr->addr_buffer.ipv4 & 0xFF000000) >> 24;
wasi_addr->addr.ip4.addr.n1 =
- (sockaddr->addr_bufer.ipv4 & 0x00FF0000) >> 16;
+ (sockaddr->addr_buffer.ipv4 & 0x00FF0000) >> 16;
wasi_addr->addr.ip4.addr.n2 =
- (sockaddr->addr_bufer.ipv4 & 0x0000FF00) >> 8;
- wasi_addr->addr.ip4.addr.n3 = (sockaddr->addr_bufer.ipv4 & 0x000000FF);
+ (sockaddr->addr_buffer.ipv4 & 0x0000FF00) >> 8;
+ wasi_addr->addr.ip4.addr.n3 = (sockaddr->addr_buffer.ipv4 & 0x000000FF);
}
else {
wasi_addr->kind = IPv6;
wasi_addr->addr.ip6.port = sockaddr->port;
- wasi_addr->addr.ip6.addr.n0 = sockaddr->addr_bufer.ipv6[0];
- wasi_addr->addr.ip6.addr.n1 = sockaddr->addr_bufer.ipv6[1];
- wasi_addr->addr.ip6.addr.n2 = sockaddr->addr_bufer.ipv6[2];
- wasi_addr->addr.ip6.addr.n3 = sockaddr->addr_bufer.ipv6[3];
- wasi_addr->addr.ip6.addr.h0 = sockaddr->addr_bufer.ipv6[4];
- wasi_addr->addr.ip6.addr.h1 = sockaddr->addr_bufer.ipv6[5];
- wasi_addr->addr.ip6.addr.h2 = sockaddr->addr_bufer.ipv6[6];
- wasi_addr->addr.ip6.addr.h3 = sockaddr->addr_bufer.ipv6[7];
+ wasi_addr->addr.ip6.addr.n0 = sockaddr->addr_buffer.ipv6[0];
+ wasi_addr->addr.ip6.addr.n1 = sockaddr->addr_buffer.ipv6[1];
+ wasi_addr->addr.ip6.addr.n2 = sockaddr->addr_buffer.ipv6[2];
+ wasi_addr->addr.ip6.addr.n3 = sockaddr->addr_buffer.ipv6[3];
+ wasi_addr->addr.ip6.addr.h0 = sockaddr->addr_buffer.ipv6[4];
+ wasi_addr->addr.ip6.addr.h1 = sockaddr->addr_buffer.ipv6[5];
+ wasi_addr->addr.ip6.addr.h2 = sockaddr->addr_buffer.ipv6[6];
+ wasi_addr->addr.ip6.addr.h3 = sockaddr->addr_buffer.ipv6[7];
}
}
@@ -299,35 +197,6 @@ wasi_addr_ip_to_bh_ip_addr_buffer(__wasi_addr_ip_t *addr,
}
}
-__wasi_errno_t
-wasmtime_ssp_clock_res_get(__wasi_clockid_t clock_id,
- __wasi_timestamp_t *resolution)
-{
- clockid_t nclock_id;
- if (!convert_clockid(clock_id, &nclock_id))
- return __WASI_EINVAL;
- struct timespec ts;
- if (clock_getres(nclock_id, &ts) < 0)
- return convert_errno(errno);
- *resolution = convert_timespec(&ts);
- return 0;
-}
-
-__wasi_errno_t
-wasmtime_ssp_clock_time_get(__wasi_clockid_t clock_id,
- __wasi_timestamp_t precision,
- __wasi_timestamp_t *time)
-{
- clockid_t nclock_id;
- if (!convert_clockid(clock_id, &nclock_id))
- return __WASI_EINVAL;
- struct timespec ts;
- if (clock_gettime(nclock_id, &ts) < 0)
- return convert_errno(errno);
- *time = convert_timespec(&ts);
- return 0;
-}
-
struct fd_prestat {
const char *dir;
};
@@ -340,15 +209,12 @@ fd_prestats_init(struct fd_prestats *pt)
pt->prestats = NULL;
pt->size = 0;
pt->used = 0;
-#if defined(WASMTIME_SSP_STATIC_CURFDS)
- prestats = pt;
-#endif
return true;
}
// Grows the preopened resource table to a required lower bound and a
// minimum number of free preopened resource table entries.
-static bool
+static __wasi_errno_t
fd_prestats_grow(struct fd_prestats *pt, size_t min, size_t incr)
REQUIRES_EXCLUSIVE(pt->lock)
{
@@ -362,7 +228,7 @@ fd_prestats_grow(struct fd_prestats *pt, size_t min, size_t incr)
struct fd_prestat *prestats =
wasm_runtime_malloc((uint32)(sizeof(*prestats) * size));
if (prestats == NULL)
- return false;
+ return __WASI_ENOMEM;
if (pt->prestats && pt->size > 0) {
bh_memcpy_s(prestats, (uint32)(sizeof(*prestats) * size),
@@ -378,27 +244,39 @@ fd_prestats_grow(struct fd_prestats *pt, size_t min, size_t incr)
pt->prestats = prestats;
pt->size = size;
}
- return true;
+ return __WASI_ESUCCESS;
}
-// Inserts a preopened resource record into the preopened resource table.
-bool
-fd_prestats_insert(struct fd_prestats *pt, const char *dir, __wasi_fd_t fd)
+static __wasi_errno_t
+fd_prestats_insert_locked(struct fd_prestats *pt, const char *dir,
+ __wasi_fd_t fd)
{
// Grow the preopened resource table if needed.
- rwlock_wrlock(&pt->lock);
- if (!fd_prestats_grow(pt, fd, 1)) {
- rwlock_unlock(&pt->lock);
- return false;
+ __wasi_errno_t error = fd_prestats_grow(pt, fd, 1);
+
+ if (error != __WASI_ESUCCESS) {
+ return error;
}
pt->prestats[fd].dir = bh_strdup(dir);
- rwlock_unlock(&pt->lock);
if (pt->prestats[fd].dir == NULL)
- return false;
+ return __WASI_ENOMEM;
- return true;
+ return __WASI_ESUCCESS;
+}
+
+// Inserts a preopened resource record into the preopened resource table.
+bool
+fd_prestats_insert(struct fd_prestats *pt, const char *dir, __wasi_fd_t fd)
+{
+ rwlock_wrlock(&pt->lock);
+
+ __wasi_errno_t error = fd_prestats_insert_locked(pt, dir, fd);
+
+ rwlock_unlock(&pt->lock);
+
+ return error == __WASI_ESUCCESS;
}
// Looks up a preopened resource table entry by number.
@@ -417,16 +295,37 @@ fd_prestats_get_entry(struct fd_prestats *pt, __wasi_fd_t fd,
return 0;
}
+// Remove a preopened resource record from the preopened resource table by
+// number
+static __wasi_errno_t
+fd_prestats_remove_entry(struct fd_prestats *pt, __wasi_fd_t fd)
+{
+ // Test for file descriptor existence.
+ if (fd >= pt->size)
+ return __WASI_EBADF;
+ struct fd_prestat *prestat = &pt->prestats[fd];
+
+ if (prestat->dir != NULL) {
+ wasm_runtime_free((void *)prestat->dir);
+ prestat->dir = NULL;
+ }
+
+ return __WASI_ESUCCESS;
+}
+
struct fd_object {
struct refcount refcount;
__wasi_filetype_t type;
- int number;
+ os_file_handle file_handle;
+ // Keep track of whether this fd object refers to a stdio stream so we know
+ // whether to close the underlying file handle when releasing the object.
+ bool is_stdio;
union {
// Data associated with directory file descriptors.
struct {
struct mutex lock; // Lock to protect members below.
- DIR *handle; // Directory handle.
+ os_dir_stream handle; // Directory handle.
__wasi_dircookie_t offset; // Offset of the directory.
} directory;
};
@@ -446,9 +345,6 @@ fd_table_init(struct fd_table *ft)
ft->entries = NULL;
ft->size = 0;
ft->used = 0;
-#if defined(WASMTIME_SSP_STATIC_CURFDS)
- curfds = ft;
-#endif
return true;
}
@@ -511,7 +407,7 @@ fd_table_grow(struct fd_table *ft, size_t min, size_t incr)
// Allocates a new file descriptor object.
static __wasi_errno_t
-fd_object_new(__wasi_filetype_t type, struct fd_object **fo)
+fd_object_new(__wasi_filetype_t type, bool is_stdio, struct fd_object **fo)
TRYLOCKS_SHARED(0, (*fo)->refcount)
{
*fo = wasm_runtime_malloc(sizeof(**fo));
@@ -519,7 +415,8 @@ fd_object_new(__wasi_filetype_t type, struct fd_object **fo)
return __WASI_ENOMEM;
refcount_init(&(*fo)->refcount, 1);
(*fo)->type = type;
- (*fo)->number = -1;
+ (*fo)->file_handle = os_get_invalid_handle();
+ (*fo)->is_stdio = is_stdio;
return 0;
}
@@ -557,131 +454,122 @@ fd_table_detach(struct fd_table *ft, __wasi_fd_t fd, struct fd_object **fo)
// Determines the type of a file descriptor and its maximum set of
// rights that should be attached to it.
static __wasi_errno_t
-fd_determine_type_rights(int fd, __wasi_filetype_t *type,
+fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type,
__wasi_rights_t *rights_base,
__wasi_rights_t *rights_inheriting)
{
- struct stat sb;
- if (fstat(fd, &sb) < 0)
- return convert_errno(errno);
- if (S_ISBLK(sb.st_mode)) {
- *type = __WASI_FILETYPE_BLOCK_DEVICE;
- *rights_base = RIGHTS_BLOCK_DEVICE_BASE;
- *rights_inheriting = RIGHTS_BLOCK_DEVICE_INHERITING;
- }
- else if (S_ISCHR(sb.st_mode)) {
- *type = __WASI_FILETYPE_CHARACTER_DEVICE;
-#if CONFIG_HAS_ISATTY
- if (isatty(fd)) {
- *rights_base = RIGHTS_TTY_BASE;
- *rights_inheriting = RIGHTS_TTY_INHERITING;
- }
- else
-#endif
- {
- *rights_base = RIGHTS_CHARACTER_DEVICE_BASE;
- *rights_inheriting = RIGHTS_CHARACTER_DEVICE_INHERITING;
- }
- }
- else if (S_ISDIR(sb.st_mode)) {
- *type = __WASI_FILETYPE_DIRECTORY;
- *rights_base = RIGHTS_DIRECTORY_BASE;
- *rights_inheriting = RIGHTS_DIRECTORY_INHERITING;
- }
- else if (S_ISREG(sb.st_mode)) {
- *type = __WASI_FILETYPE_REGULAR_FILE;
- *rights_base = RIGHTS_REGULAR_FILE_BASE;
- *rights_inheriting = RIGHTS_REGULAR_FILE_INHERITING;
- }
- else if (S_ISSOCK(sb.st_mode)) {
- int socktype;
- socklen_t socktypelen = sizeof(socktype);
- if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &socktype, &socktypelen) < 0)
- return convert_errno(errno);
- switch (socktype) {
- case SOCK_DGRAM:
- *type = __WASI_FILETYPE_SOCKET_DGRAM;
- break;
- case SOCK_STREAM:
- *type = __WASI_FILETYPE_SOCKET_STREAM;
- break;
- default:
- return __WASI_EINVAL;
- }
- *rights_base = RIGHTS_SOCKET_BASE;
- *rights_inheriting = RIGHTS_SOCKET_INHERITING;
- }
- else if (S_ISFIFO(sb.st_mode)) {
- *type = __WASI_FILETYPE_SOCKET_STREAM;
- *rights_base = RIGHTS_SOCKET_BASE;
- *rights_inheriting = RIGHTS_SOCKET_INHERITING;
- }
- else {
- return __WASI_EINVAL;
+ struct __wasi_filestat_t buf;
+ __wasi_errno_t error = os_fstat(fd, &buf);
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
+ *type = buf.st_filetype;
+
+ switch (buf.st_filetype) {
+ case __WASI_FILETYPE_BLOCK_DEVICE:
+ *rights_base = RIGHTS_BLOCK_DEVICE_BASE;
+ *rights_inheriting = RIGHTS_BLOCK_DEVICE_INHERITING;
+ break;
+ case __WASI_FILETYPE_CHARACTER_DEVICE:
+ error = os_isatty(fd);
+
+ if (error == __WASI_ESUCCESS) {
+ *rights_base = RIGHTS_TTY_BASE;
+ *rights_inheriting = RIGHTS_TTY_INHERITING;
+ }
+ else {
+ *rights_base = RIGHTS_CHARACTER_DEVICE_BASE;
+ *rights_inheriting = RIGHTS_CHARACTER_DEVICE_INHERITING;
+ }
+ break;
+ case __WASI_FILETYPE_DIRECTORY:
+ *rights_base = RIGHTS_DIRECTORY_BASE;
+ *rights_inheriting = RIGHTS_DIRECTORY_INHERITING;
+ break;
+ case __WASI_FILETYPE_REGULAR_FILE:
+ *rights_base = RIGHTS_REGULAR_FILE_BASE;
+ *rights_inheriting = RIGHTS_REGULAR_FILE_INHERITING;
+ break;
+ case __WASI_FILETYPE_SOCKET_DGRAM:
+ case __WASI_FILETYPE_SOCKET_STREAM:
+ *rights_base = RIGHTS_SOCKET_BASE;
+ *rights_inheriting = RIGHTS_SOCKET_INHERITING;
+ break;
+ case __WASI_FILETYPE_SYMBOLIC_LINK:
+ case __WASI_FILETYPE_UNKNOWN:
+ // If we don't know the type, allow for the maximum set of
+ // rights
+ *rights_base = RIGHTS_ALL;
+ *rights_inheriting = RIGHTS_ALL;
+ break;
+ default:
+ return __WASI_EINVAL;
}
+ wasi_libc_file_access_mode access_mode;
+ error = os_file_get_access_mode(fd, &access_mode);
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
// Strip off read/write bits based on the access mode.
- switch (fcntl(fd, F_GETFL) & O_ACCMODE) {
- case O_RDONLY:
+ switch (access_mode) {
+ case WASI_LIBC_ACCESS_MODE_READ_ONLY:
*rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_WRITE;
break;
- case O_WRONLY:
+ case WASI_LIBC_ACCESS_MODE_WRITE_ONLY:
*rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_READ;
break;
}
- return 0;
-}
-// Returns the underlying file descriptor number of a file descriptor
-// object. This function can only be applied to objects that have an
-// underlying file descriptor number.
-static int
-fd_number(const struct fd_object *fo)
-{
- int number = fo->number;
- assert(number >= 0 && "fd_number() called on virtual file descriptor");
- return number;
+ return error;
}
-#define CLOSE_NON_STD_FD(fd) \
- do { \
- if (fd > 2) \
- close(fd); \
- } while (0)
-
// Lowers the reference count on a file descriptor object. When the
// reference count reaches zero, its resources are cleaned up.
-static void
-fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount)
+static __wasi_errno_t
+fd_object_release(wasm_exec_env_t env, struct fd_object *fo)
+ UNLOCKS(fo->refcount)
{
+ __wasi_errno_t error = __WASI_ESUCCESS;
+
if (refcount_release(&fo->refcount)) {
+ int saved_errno = errno;
switch (fo->type) {
case __WASI_FILETYPE_DIRECTORY:
- // For directories we may keep track of a DIR object. Calling
- // closedir() on it also closes the underlying file descriptor.
+ // For directories we may keep track of a DIR object.
+ // Calling os_closedir() on it also closes the underlying file
+ // descriptor.
mutex_destroy(&fo->directory.lock);
- if (fo->directory.handle == NULL) {
- CLOSE_NON_STD_FD(fd_number(fo));
- }
- else {
- closedir(fo->directory.handle);
+ if (os_is_dir_stream_valid(&fo->directory.handle)) {
+ error = os_closedir(fo->directory.handle);
+ break;
}
- break;
+ // Fallthrough.
default:
- CLOSE_NON_STD_FD(fd_number(fo));
+ // The env == NULL case is for
+ // fd_table_destroy, path_get, path_put,
+ // fd_table_insert_existing
+ error = (env == NULL) ? os_close(fo->file_handle, fo->is_stdio)
+ : blocking_op_close(env, fo->file_handle,
+ fo->is_stdio);
break;
}
wasm_runtime_free(fo);
+ errno = saved_errno;
}
+ return error;
}
// Inserts an already existing file descriptor into the file descriptor
// table.
bool
-fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out)
+fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in,
+ os_file_handle out, bool is_stdio)
{
- __wasi_filetype_t type;
- __wasi_rights_t rights_base, rights_inheriting;
+ __wasi_filetype_t type = __WASI_FILETYPE_UNKNOWN;
+ __wasi_rights_t rights_base = 0, rights_inheriting = 0;
struct fd_object *fo;
__wasi_errno_t error;
@@ -690,8 +578,8 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out)
if (error != 0) {
#ifdef BH_PLATFORM_EGO
/**
- * since it is an already opened file and we can assume the opened file
- * has all necessary rights no matter how to get
+ * since it is an already opened file and we can assume the opened
+ * file has all necessary rights no matter how to get
*/
if (error != __WASI_ENOTSUP)
return false;
@@ -700,23 +588,23 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out)
#endif
}
- error = fd_object_new(type, &fo);
+ error = fd_object_new(type, is_stdio, &fo);
if (error != 0)
return false;
- fo->number = out;
+ fo->file_handle = out;
if (type == __WASI_FILETYPE_DIRECTORY) {
if (!mutex_init(&fo->directory.lock)) {
- fd_object_release(fo);
+ fd_object_release(NULL, fo);
return false;
}
- fo->directory.handle = NULL;
+ fo->directory.handle = os_get_invalid_dir_stream();
}
// Grow the file descriptor table if needed.
rwlock_wrlock(&ft->lock);
if (!fd_table_grow(ft, in, 1)) {
rwlock_unlock(&ft->lock);
- fd_object_release(fo);
+ fd_object_release(NULL, fo);
return false;
}
@@ -726,71 +614,81 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out)
}
// Picks an unused slot from the file descriptor table.
-static __wasi_fd_t
-fd_table_unused(struct fd_table *ft) REQUIRES_SHARED(ft->lock)
+static __wasi_errno_t
+fd_table_unused(struct fd_table *ft, __wasi_fd_t *out) REQUIRES_SHARED(ft->lock)
{
assert(ft->size > ft->used && "File descriptor table has no free slots");
for (;;) {
- __wasi_fd_t fd = (__wasi_fd_t)random_uniform(ft->size);
- if (ft->entries[fd].object == NULL)
- return fd;
+ uintmax_t random_fd = 0;
+ __wasi_errno_t error = random_uniform(ft->size, &random_fd);
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
+ if (ft->entries[(__wasi_fd_t)random_fd].object == NULL) {
+ *out = (__wasi_fd_t)random_fd;
+ return error;
+ }
}
}
// Inserts a file descriptor object into an unused slot of the file
// descriptor table.
static __wasi_errno_t
-fd_table_insert(struct fd_table *ft, struct fd_object *fo,
- __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting,
- __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock)
- UNLOCKS(fo->refcount)
+fd_table_insert(wasm_exec_env_t exec_env, struct fd_table *ft,
+ struct fd_object *fo, __wasi_rights_t rights_base,
+ __wasi_rights_t rights_inheriting, __wasi_fd_t *out)
+ REQUIRES_UNLOCKED(ft->lock) UNLOCKS(fo->refcount)
{
// Grow the file descriptor table if needed.
rwlock_wrlock(&ft->lock);
if (!fd_table_grow(ft, 0, 1)) {
rwlock_unlock(&ft->lock);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
return convert_errno(errno);
}
- *out = fd_table_unused(ft);
+ __wasi_errno_t error = fd_table_unused(ft, out);
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
fd_table_attach(ft, *out, fo, rights_base, rights_inheriting);
rwlock_unlock(&ft->lock);
- return 0;
+ return error;
}
// Inserts a numerical file descriptor into the file descriptor table.
static __wasi_errno_t
-fd_table_insert_fd(struct fd_table *ft, int in, __wasi_filetype_t type,
+fd_table_insert_fd(wasm_exec_env_t exec_env, struct fd_table *ft,
+ os_file_handle in, __wasi_filetype_t type,
__wasi_rights_t rights_base,
__wasi_rights_t rights_inheriting, __wasi_fd_t *out)
REQUIRES_UNLOCKED(ft->lock)
{
struct fd_object *fo;
- __wasi_errno_t error = fd_object_new(type, &fo);
+ __wasi_errno_t error = fd_object_new(type, false, &fo);
if (error != 0) {
- close(in);
+ os_close(in, false);
return error;
}
- fo->number = in;
+ fo->file_handle = in;
if (type == __WASI_FILETYPE_DIRECTORY) {
if (!mutex_init(&fo->directory.lock)) {
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
return (__wasi_errno_t)-1;
}
- fo->directory.handle = NULL;
+ fo->directory.handle = os_get_invalid_dir_stream();
}
- return fd_table_insert(ft, fo, rights_base, rights_inheriting, out);
+ return fd_table_insert(exec_env, ft, fo, rights_base, rights_inheriting,
+ out);
}
__wasi_errno_t
-wasmtime_ssp_fd_prestat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t fd, __wasi_prestat_t *buf)
+wasmtime_ssp_fd_prestat_get(struct fd_prestats *prestats, __wasi_fd_t fd,
+ __wasi_prestat_t *buf)
{
rwlock_rdlock(&prestats->lock);
struct fd_prestat *prestat;
@@ -812,11 +710,8 @@ wasmtime_ssp_fd_prestat_get(
}
__wasi_errno_t
-wasmtime_ssp_fd_prestat_dir_name(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_prestats *prestats,
-#endif
- __wasi_fd_t fd, char *path, size_t path_len)
+wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd,
+ char *path, size_t path_len)
{
rwlock_rdlock(&prestats->lock);
struct fd_prestat *prestat;
@@ -825,12 +720,14 @@ wasmtime_ssp_fd_prestat_dir_name(
rwlock_unlock(&prestats->lock);
return error;
}
- if (path_len != strlen(prestat->dir)) {
+
+ const size_t prestat_dir_len = strlen(prestat->dir);
+ if (path_len < prestat_dir_len) {
rwlock_unlock(&prestats->lock);
- return EINVAL;
+ return __WASI_EINVAL;
}
- bh_memcpy_s(path, (uint32)path_len, prestat->dir, (uint32)path_len);
+ bh_memcpy_s(path, (uint32)path_len, prestat->dir, (uint32)prestat_dir_len);
rwlock_unlock(&prestats->lock);
@@ -838,31 +735,18 @@ wasmtime_ssp_fd_prestat_dir_name(
}
__wasi_errno_t
-wasmtime_ssp_fd_close(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct fd_prestats *prestats,
-#endif
- __wasi_fd_t fd)
-{
- // Don't allow closing a pre-opened resource.
- // TODO: Eventually, we do want to permit this, once libpreopen in
- // userspace is capable of removing entries from its tables as well.
- {
- rwlock_rdlock(&prestats->lock);
- struct fd_prestat *prestat;
- __wasi_errno_t error = fd_prestats_get_entry(prestats, fd, &prestat);
- rwlock_unlock(&prestats->lock);
- if (error == 0) {
- return __WASI_ENOTSUP;
- }
- }
-
+wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, __wasi_fd_t fd)
+{
// Validate the file descriptor.
struct fd_table *ft = curfds;
rwlock_wrlock(&ft->lock);
+ rwlock_wrlock(&prestats->lock);
+
struct fd_entry *fe;
__wasi_errno_t error = fd_table_get_entry(ft, fd, 0, 0, &fe);
if (error != 0) {
+ rwlock_unlock(&prestats->lock);
rwlock_unlock(&ft->lock);
return error;
}
@@ -870,9 +754,20 @@ wasmtime_ssp_fd_close(
// Remove it from the file descriptor table.
struct fd_object *fo;
fd_table_detach(ft, fd, &fo);
+
+ // Remove it from the preopened resource table if it exists
+ error = fd_prestats_remove_entry(prestats, fd);
+
+ rwlock_unlock(&prestats->lock);
rwlock_unlock(&ft->lock);
- fd_object_release(fo);
- return 0;
+ fd_object_release(exec_env, fo);
+
+ // Ignore the error if there is no preopen associated with this fd
+ if (error == __WASI_EBADF) {
+ return __WASI_ESUCCESS;
+ }
+
+ return error;
}
// Look up a file descriptor object in a locked file descriptor table
@@ -914,11 +809,8 @@ fd_object_get(struct fd_table *curfds, struct fd_object **fo, __wasi_fd_t fd,
}
__wasi_errno_t
-wasmtime_ssp_fd_datasync(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd)
+wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd)
{
struct fd_object *fo;
__wasi_errno_t error =
@@ -926,24 +818,17 @@ wasmtime_ssp_fd_datasync(
if (error != 0)
return error;
-#if CONFIG_HAS_FDATASYNC
- int ret = fdatasync(fd_number(fo));
-#else
- int ret = fsync(fd_number(fo));
-#endif
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ error = os_fdatasync(fo->file_handle);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_pread(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt,
- __wasi_filesize_t offset, size_t *nread)
+wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt,
+ __wasi_filesize_t offset, size_t *nread)
{
if (iovcnt == 0)
return __WASI_EINVAL;
@@ -951,175 +836,78 @@ wasmtime_ssp_fd_pread(
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_READ, 0);
+
if (error != 0)
return error;
-#if CONFIG_HAS_PREADV
- ssize_t len = preadv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt,
- (off_t)offset);
- fd_object_release(fo);
- if (len < 0)
- return convert_errno(errno);
- *nread = (size_t)len;
- return 0;
-#else
- if (iovcnt == 1) {
- ssize_t len = pread(fd_number(fo), iov->buf, iov->buf_len, offset);
- fd_object_release(fo);
- if (len < 0)
- return convert_errno(errno);
- *nread = len;
- return 0;
- }
- else {
- // Allocate a single buffer to fit all data.
- size_t totalsize = 0;
- for (size_t i = 0; i < iovcnt; ++i)
- totalsize += iov[i].buf_len;
- char *buf = wasm_runtime_malloc(totalsize);
- if (buf == NULL) {
- fd_object_release(fo);
- return __WASI_ENOMEM;
- }
+ error = blocking_op_preadv(exec_env, fo->file_handle, iov, (int)iovcnt,
+ offset, nread);
- // Perform a single read operation.
- ssize_t len = pread(fd_number(fo), buf, totalsize, offset);
- fd_object_release(fo);
- if (len < 0) {
- wasm_runtime_free(buf);
- return convert_errno(errno);
- }
+ fd_object_release(exec_env, fo);
- // Copy data back to vectors.
- size_t bufoff = 0;
- for (size_t i = 0; i < iovcnt; ++i) {
- if (bufoff + iov[i].buf_len < (size_t)len) {
- bh_memcpy_s(iov[i].buf, iov[i].buf_len, buf + bufoff,
- iov[i].buf_len);
- bufoff += iov[i].buf_len;
- }
- else {
- bh_memcpy_s(iov[i].buf, iov[i].buf_len, buf + bufoff,
- len - bufoff);
- break;
- }
- }
- wasm_runtime_free(buf);
- *nread = len;
- return 0;
- }
-#endif
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_pwrite(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt,
- __wasi_filesize_t offset, size_t *nwritten)
+wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_ciovec_t *iov,
+ size_t iovcnt, __wasi_filesize_t offset,
+ size_t *nwritten)
{
- if (iovcnt == 0)
- return __WASI_EINVAL;
-
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_WRITE, 0);
+
if (error != 0)
return error;
- ssize_t len;
-#if CONFIG_HAS_PWRITEV
- len = pwritev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt,
- (off_t)offset);
-#else
- if (iovcnt == 1) {
- len = pwrite(fd_number(fo), iov->buf, iov->buf_len, offset);
- }
- else {
- // Allocate a single buffer to fit all data.
- size_t totalsize = 0;
- for (size_t i = 0; i < iovcnt; ++i)
- totalsize += iov[i].buf_len;
- char *buf = wasm_runtime_malloc(totalsize);
- if (buf == NULL) {
- fd_object_release(fo);
- return __WASI_ENOMEM;
- }
- size_t bufoff = 0;
- for (size_t i = 0; i < iovcnt; ++i) {
- bh_memcpy_s(buf + bufoff, totalsize - bufoff, iov[i].buf,
- iov[i].buf_len);
- bufoff += iov[i].buf_len;
- }
+ error = blocking_op_pwritev(exec_env, fo->file_handle, iov, (int)iovcnt,
+ offset, nwritten);
+ fd_object_release(exec_env, fo);
- // Perform a single write operation.
- len = pwrite(fd_number(fo), buf, totalsize, offset);
- wasm_runtime_free(buf);
- }
-#endif
- fd_object_release(fo);
- if (len < 0)
- return convert_errno(errno);
- *nwritten = (size_t)len;
- return 0;
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_read(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, size_t *nread)
+wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt,
+ size_t *nread)
{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_READ, 0);
+
if (error != 0)
return error;
- ssize_t len = readv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt);
- fd_object_release(fo);
- if (len < 0)
- return convert_errno(errno);
- *nread = (size_t)len;
- return 0;
+ error =
+ blocking_op_readv(exec_env, fo->file_handle, iov, (int)iovcnt, nread);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_renumber(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct fd_prestats *prestats,
-#endif
- __wasi_fd_t from, __wasi_fd_t to)
-{
- // Don't allow renumbering over a pre-opened resource.
- // TODO: Eventually, we do want to permit this, once libpreopen in
- // userspace is capable of removing entries from its tables as well.
- {
- rwlock_rdlock(&prestats->lock);
- struct fd_prestat *prestat;
- __wasi_errno_t error = fd_prestats_get_entry(prestats, to, &prestat);
- if (error != 0) {
- error = fd_prestats_get_entry(prestats, from, &prestat);
- }
- rwlock_unlock(&prestats->lock);
- if (error == 0) {
- return __WASI_ENOTSUP;
- }
- }
-
+wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, __wasi_fd_t from,
+ __wasi_fd_t to)
+{
struct fd_table *ft = curfds;
rwlock_wrlock(&ft->lock);
+ rwlock_wrlock(&prestats->lock);
+
struct fd_entry *fe_from;
__wasi_errno_t error = fd_table_get_entry(ft, from, 0, 0, &fe_from);
if (error != 0) {
+ rwlock_unlock(&prestats->lock);
rwlock_unlock(&ft->lock);
return error;
}
struct fd_entry *fe_to;
error = fd_table_get_entry(ft, to, 0, 0, &fe_to);
if (error != 0) {
+ rwlock_unlock(&prestats->lock);
rwlock_unlock(&ft->lock);
return error;
}
@@ -1129,40 +917,67 @@ wasmtime_ssp_fd_renumber(
refcount_acquire(&fe_from->object->refcount);
fd_table_attach(ft, to, fe_from->object, fe_from->rights_base,
fe_from->rights_inheriting);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
// Remove the old fd from the file descriptor table.
fd_table_detach(ft, from, &fo);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
--ft->used;
+ // Handle renumbering of any preopened resources
+ struct fd_prestat *prestat_from;
+ __wasi_errno_t prestat_from_error =
+ fd_prestats_get_entry(prestats, from, &prestat_from);
+
+ struct fd_prestat *prestat_to;
+ __wasi_errno_t prestat_to_error =
+ fd_prestats_get_entry(prestats, to, &prestat_to);
+
+ // Renumbering over two preopened resources.
+ if (prestat_from_error == __WASI_ESUCCESS
+ && prestat_to_error == __WASI_ESUCCESS) {
+ (void)fd_prestats_remove_entry(prestats, to);
+
+ error = fd_prestats_insert_locked(prestats, prestat_from->dir, to);
+
+ if (error == __WASI_ESUCCESS) {
+ (void)fd_prestats_remove_entry(prestats, from);
+ }
+ else {
+ (void)fd_prestats_remove_entry(prestats, to);
+ }
+ }
+ // Renumbering from a non-preopened fd to a preopened fd. In this case,
+ // we can't a keep the destination fd entry in the preopened table so
+ // remove it entirely.
+ else if (prestat_from_error != __WASI_ESUCCESS
+ && prestat_to_error == __WASI_ESUCCESS) {
+ (void)fd_prestats_remove_entry(prestats, to);
+ }
+ // Renumbering from a preopened fd to a non-preopened fd
+ else if (prestat_from_error == __WASI_ESUCCESS
+ && prestat_to_error != __WASI_ESUCCESS) {
+ error = fd_prestats_insert_locked(prestats, prestat_from->dir, to);
+
+ if (error == __WASI_ESUCCESS) {
+ (void)fd_prestats_remove_entry(prestats, from);
+ }
+ else {
+ (void)fd_prestats_remove_entry(prestats, to);
+ }
+ }
+
+ rwlock_unlock(&prestats->lock);
rwlock_unlock(&ft->lock);
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_seek(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_filedelta_t offset, __wasi_whence_t whence,
- __wasi_filesize_t *newoffset)
+wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filedelta_t offset,
+ __wasi_whence_t whence, __wasi_filesize_t *newoffset)
{
- int nwhence;
- switch (whence) {
- case __WASI_WHENCE_CUR:
- nwhence = SEEK_CUR;
- break;
- case __WASI_WHENCE_END:
- nwhence = SEEK_END;
- break;
- case __WASI_WHENCE_SET:
- nwhence = SEEK_SET;
- break;
- default:
- return __WASI_EINVAL;
- }
-
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd,
@@ -1173,20 +988,16 @@ wasmtime_ssp_fd_seek(
if (error != 0)
return error;
- off_t ret = lseek(fd_number(fo), offset, nwhence);
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- *newoffset = (__wasi_filesize_t)ret;
- return 0;
+ error = os_lseek(fo->file_handle, offset, whence, newoffset);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_tell(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_filesize_t *newoffset)
+wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filesize_t *newoffset)
{
struct fd_object *fo;
__wasi_errno_t error =
@@ -1194,113 +1005,70 @@ wasmtime_ssp_fd_tell(
if (error != 0)
return error;
- off_t ret = lseek(fd_number(fo), 0, SEEK_CUR);
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- *newoffset = (__wasi_filesize_t)ret;
- return 0;
+ error = os_lseek(fo->file_handle, 0, __WASI_WHENCE_CUR, newoffset);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_fdstat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_fdstat_t *buf)
+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);
- if (error != 0) {
+ if (error != __WASI_ESUCCESS) {
rwlock_unlock(&ft->lock);
return error;
}
// Extract file descriptor type and rights.
struct fd_object *fo = fe->object;
- *buf = (__wasi_fdstat_t){
- .fs_filetype = fo->type,
- .fs_rights_base = fe->rights_base,
- .fs_rights_inheriting = fe->rights_inheriting,
- };
- // Fetch file descriptor flags.
- int ret;
- switch (fo->type) {
- default:
- ret = fcntl(fd_number(fo), F_GETFL);
- break;
+ __wasi_fdflags_t flags;
+ error = os_file_get_fdflags(fo->file_handle, &flags);
+
+ if (error != __WASI_ESUCCESS) {
+ rwlock_unlock(&ft->lock);
+ return error;
}
- rwlock_unlock(&ft->lock);
- if (ret < 0)
- return convert_errno(errno);
- if ((ret & O_APPEND) != 0)
- buf->fs_flags |= __WASI_FDFLAG_APPEND;
-#ifdef O_DSYNC
- if ((ret & O_DSYNC) != 0)
- buf->fs_flags |= __WASI_FDFLAG_DSYNC;
-#endif
- if ((ret & O_NONBLOCK) != 0)
- buf->fs_flags |= __WASI_FDFLAG_NONBLOCK;
-#ifdef O_RSYNC
- if ((ret & O_RSYNC) != 0)
- buf->fs_flags |= __WASI_FDFLAG_RSYNC;
-#endif
- if ((ret & O_SYNC) != 0)
- buf->fs_flags |= __WASI_FDFLAG_SYNC;
- return 0;
+ *buf = (__wasi_fdstat_t){ .fs_filetype = fo->type,
+ .fs_rights_base = fe->rights_base,
+ .fs_rights_inheriting = fe->rights_inheriting,
+ .fs_flags = flags };
+
+ rwlock_unlock(&ft->lock);
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_fdstat_set_flags(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_fdflags_t fs_flags)
-{
- int noflags = 0;
- if ((fs_flags & __WASI_FDFLAG_APPEND) != 0)
- noflags |= O_APPEND;
- if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0)
-#ifdef O_DSYNC
- noflags |= O_DSYNC;
-#else
- noflags |= O_SYNC;
-#endif
- if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0)
- noflags |= O_NONBLOCK;
- if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0)
-#ifdef O_RSYNC
- noflags |= O_RSYNC;
-#else
- noflags |= O_SYNC;
-#endif
- if ((fs_flags & __WASI_FDFLAG_SYNC) != 0)
- noflags |= O_SYNC;
-
+wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_fdflags_t fs_flags)
+{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS, 0);
+
if (error != 0)
return error;
- int ret = fcntl(fd_number(fo), F_SETFL, noflags);
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ error = os_file_set_fdflags(fo->file_handle, fs_flags);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_fdstat_set_rights(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_rights_t fs_rights_base,
- __wasi_rights_t fs_rights_inheriting)
+wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_rights_t fs_rights_base,
+ __wasi_rights_t fs_rights_inheriting)
{
struct fd_table *ft = curfds;
rwlock_wrlock(&ft->lock);
@@ -1320,31 +1088,27 @@ wasmtime_ssp_fd_fdstat_set_rights(
}
__wasi_errno_t
-wasmtime_ssp_fd_sync(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd)
+wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd)
{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_SYNC, 0);
+
if (error != 0)
return error;
- int ret = fsync(fd_number(fo));
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ error = os_fsync(fo->file_handle);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_write(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, size_t *nwritten)
+wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt,
+ size_t *nwritten)
{
struct fd_object *fo;
__wasi_errno_t error =
@@ -1353,142 +1117,81 @@ wasmtime_ssp_fd_write(
return error;
#ifndef BH_VPRINTF
- ssize_t len = writev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt);
+ error = blocking_op_writev(exec_env, fo->file_handle, iov, (int)iovcnt,
+ nwritten);
#else
- ssize_t len = 0;
/* redirect stdout/stderr output to BH_VPRINTF function */
- if (fd_number(fo) == 1 || fd_number(fo) == 2) {
+ if (fo->is_stdio) {
int i;
- const struct iovec *iov1 = (const struct iovec *)iov;
-
- for (i = 0; i < (int)iovcnt; i++, iov1++) {
- if (iov1->iov_len > 0 && iov1->iov_base) {
+ *nwritten = 0;
+ for (i = 0; i < (int)iovcnt; i++) {
+ if (iov[i].buf_len > 0 && iov[i].buf != NULL) {
char format[16];
/* make up format string "%.ns" */
- snprintf(format, sizeof(format), "%%.%ds", (int)iov1->iov_len);
- len += (ssize_t)os_printf(format, iov1->iov_base);
+ snprintf(format, sizeof(format), "%%.%ds", (int)iov[i].buf_len);
+ *nwritten += (size_t)os_printf(format, iov[i].buf);
}
}
}
else {
- len = writev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt);
+ error = blocking_op_writev(exec_env, fo->file_handle, iov, (int)iovcnt,
+ nwritten);
}
#endif /* end of BH_VPRINTF */
- fd_object_release(fo);
- if (len < 0)
- return convert_errno(errno);
- *nwritten = (size_t)len;
- return 0;
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_advise(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len,
- __wasi_advice_t advice)
-{
-#ifdef POSIX_FADV_NORMAL
- int nadvice;
- switch (advice) {
- case __WASI_ADVICE_DONTNEED:
- nadvice = POSIX_FADV_DONTNEED;
- break;
- case __WASI_ADVICE_NOREUSE:
- nadvice = POSIX_FADV_NOREUSE;
- break;
- case __WASI_ADVICE_NORMAL:
- nadvice = POSIX_FADV_NORMAL;
- break;
- case __WASI_ADVICE_RANDOM:
- nadvice = POSIX_FADV_RANDOM;
- break;
- case __WASI_ADVICE_SEQUENTIAL:
- nadvice = POSIX_FADV_SEQUENTIAL;
- break;
- case __WASI_ADVICE_WILLNEED:
- nadvice = POSIX_FADV_WILLNEED;
- break;
- default:
- return __WASI_EINVAL;
- }
-
+wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filesize_t offset,
+ __wasi_filesize_t len, __wasi_advice_t advice)
+{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_ADVISE, 0);
if (error != 0)
return error;
- int ret = posix_fadvise(fd_number(fo), (off_t)offset, (off_t)len, nadvice);
- fd_object_release(fo);
- if (ret != 0)
- return convert_errno(ret);
- return 0;
-#else
- // Advisory information can safely be ignored if unsupported.
- switch (advice) {
- case __WASI_ADVICE_DONTNEED:
- case __WASI_ADVICE_NOREUSE:
- case __WASI_ADVICE_NORMAL:
- case __WASI_ADVICE_RANDOM:
- case __WASI_ADVICE_SEQUENTIAL:
- case __WASI_ADVICE_WILLNEED:
- break;
- default:
- return __WASI_EINVAL;
+ if (fo->type == __WASI_FILETYPE_DIRECTORY) {
+ fd_object_release(exec_env, fo);
+ return __WASI_EBADF;
}
- // At least check for file descriptor existence.
- struct fd_table *ft = curfds;
- rwlock_rdlock(&ft->lock);
- struct fd_entry *fe;
- __wasi_errno_t error =
- fd_table_get_entry(ft, fd, __WASI_RIGHT_FD_ADVISE, 0, &fe);
- rwlock_unlock(&ft->lock);
+ error = os_fadvise(fo->file_handle, offset, len, advice);
+
+ fd_object_release(exec_env, fo);
+
return error;
-#endif
}
__wasi_errno_t
-wasmtime_ssp_fd_allocate(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len)
+wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filesize_t offset,
+ __wasi_filesize_t len)
{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_ALLOCATE, 0);
- if (error != 0)
+ if (error != __WASI_ESUCCESS)
return error;
-#if CONFIG_HAS_POSIX_FALLOCATE
- int ret = posix_fallocate(fd_number(fo), (off_t)offset, (off_t)len);
-#else
- // At least ensure that the file is grown to the right size.
- // TODO(ed): See if this can somehow be implemented without any race
- // conditions. We may end up shrinking the file right now.
- struct stat sb;
- int ret = fstat(fd_number(fo), &sb);
- off_t newsize = (off_t)(offset + len);
- if (ret == 0 && sb.st_size < newsize)
- ret = ftruncate(fd_number(fo), newsize);
-#endif
+ error = os_fallocate(fo->file_handle, offset, len);
- fd_object_release(fo);
- if (ret != 0)
- return convert_errno(ret);
- return 0;
+ fd_object_release(exec_env, fo);
+
+ return error;
}
// Reads the entire contents of a symbolic link, returning the contents
// in an allocated buffer. The allocated buffer is large enough to fit
// at least one extra byte, so the caller may append a trailing slash to
// it. This is needed by path_get().
-static char *
-readlinkat_dup(int fd, const char *path, size_t *p_len)
+__wasi_errno_t
+readlinkat_dup(os_file_handle handle, const char *path, size_t *p_len,
+ char **out_buf)
{
char *buf = NULL;
size_t len = 32;
@@ -1500,7 +1203,8 @@ readlinkat_dup(int fd, const char *path, size_t *p_len)
if (newbuf == NULL) {
if (buf)
wasm_runtime_free(buf);
- return NULL;
+ *out_buf = NULL;
+ return __WASI_ENOMEM;
}
if (buf != NULL) {
@@ -1509,15 +1213,20 @@ readlinkat_dup(int fd, const char *path, size_t *p_len)
}
buf = newbuf;
- ssize_t ret = readlinkat(fd, path, buf, len);
- if (ret < 0) {
+ size_t bytes_read = 0;
+ __wasi_errno_t error =
+ os_readlinkat(handle, path, buf, len, &bytes_read);
+ if (error != __WASI_ESUCCESS) {
wasm_runtime_free(buf);
- return NULL;
+ *out_buf = NULL;
+ return error;
}
- if ((size_t)ret + 1 < len) {
- buf[ret] = '\0';
+ if ((size_t)bytes_read + 1 < len) {
+ buf[bytes_read] = '\0';
*p_len = len;
- return buf;
+ *out_buf = buf;
+
+ return __WASI_ESUCCESS;
}
len_org = len;
len *= 2;
@@ -1531,7 +1240,7 @@ readlinkat_dup(int fd, const char *path, size_t *p_len)
// descriptor representing the directory where the lookup needs to start
// and the actual pathname string.
struct path_access {
- int fd; // Directory file descriptor.
+ os_file_handle fd; // Directory file descriptor.
const char *path; // Pathname.
bool follow; // Whether symbolic links should be followed.
char *path_start; // Internal: pathname to free.
@@ -1543,10 +1252,10 @@ struct path_access {
// pathname to ensure the target path is placed underneath the
// directory.
static __wasi_errno_t
-path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
- __wasi_lookupflags_t flags, const char *upath, size_t upathlen,
- __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting,
- bool needs_final_component)
+path_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct path_access *pa, __wasi_fd_t fd, __wasi_lookupflags_t flags,
+ const char *upath, size_t upathlen, __wasi_rights_t rights_base,
+ __wasi_rights_t rights_inheriting, bool needs_final_component)
TRYLOCKS_EXCLUSIVE(0, pa->fd_object->refcount)
{
char *path = str_nullterminate(upath, upathlen);
@@ -1565,7 +1274,7 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
#if CONFIG_HAS_CAP_ENTER
// Rely on the kernel to constrain access to automatically constrain
// access to files stored underneath this directory.
- pa->fd = fd_number(fo);
+ pa->fd = fo->file_handle;
pa->path = pa->path_start = path;
pa->follow = (flags & __WASI_LOOKUP_SYMLINK_FOLLOW) != 0;
pa->fd_object = fo;
@@ -1580,8 +1289,8 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
// causes a file descriptor to be pushed, while handling ".." entries
// causes an entry to be popped. Index 0 cannot be popped, as this
// would imply escaping the base directory.
- int fds[128];
- fds[0] = fd_number(fo);
+ os_file_handle fds[128];
+ fds[0] = fo->file_handle;
size_t curfd = 0;
// Stack of pathname strings used for symlink expansion. By using a
@@ -1592,8 +1301,13 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
paths[0] = paths_start[0] = path;
size_t curpath = 0;
size_t expansions = 0;
- char *symlink;
+ char *symlink = NULL;
size_t symlink_len;
+#ifdef BH_PLATFORM_WINDOWS
+#define PATH_SEPARATORS "/\\"
+#else
+#define PATH_SEPARATORS "/"
+#endif
for (;;) {
// Extract the next pathname component from 'paths[curpath]', null
@@ -1601,9 +1315,10 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
// whether the pathname component is followed by one or more
// trailing slashes, as this requires it to be a directory.
char *file = paths[curpath];
- char *file_end = file + strcspn(file, "/");
- paths[curpath] = file_end + strspn(file_end, "/");
- bool ends_with_slashes = *file_end == '/';
+ char *file_end = file + strcspn(file, PATH_SEPARATORS);
+ paths[curpath] = file_end + strspn(file_end, PATH_SEPARATORS);
+ bool ends_with_slashes =
+ (*file_end != '\0' && strchr(PATH_SEPARATORS, *file_end));
*file_end = '\0';
// Test for empty pathname strings and absolute paths.
@@ -1623,7 +1338,10 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
error = __WASI_ENOTCAPABLE;
goto fail;
}
- close(fds[curfd--]);
+ error = os_close(fds[curfd--], false);
+
+ if (error != __WASI_ESUCCESS)
+ goto fail;
}
else if (curpath > 0 || *paths[curpath] != '\0'
|| (ends_with_slashes && !needs_final_component)) {
@@ -1632,16 +1350,14 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
// components. In other words, a pathname component that must be a
// directory. First attempt to obtain a directory file descriptor
// for it.
- int newdir =
-#ifdef O_SEARCH
- openat(fds[curfd], file, O_SEARCH | O_DIRECTORY | O_NOFOLLOW);
-#else
- openat(fds[curfd], file, O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
-#endif
- if (newdir != -1) {
+ os_file_handle newdir;
+ error = blocking_op_openat(
+ exec_env, fds[curfd], file, __WASI_O_DIRECTORY, 0, 0,
+ WASI_LIBC_ACCESS_MODE_READ_ONLY, &newdir);
+ if (error == __WASI_ESUCCESS) {
// Success. Push it onto the directory stack.
if (curfd + 1 == sizeof(fds) / sizeof(fds[0])) {
- close(newdir);
+ os_close(newdir, false);
error = __WASI_ENAMETOOLONG;
goto fail;
}
@@ -1649,20 +1365,23 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
}
else {
// Failed to open it. Attempt symlink expansion.
- if (errno != ELOOP && errno != EMLINK && errno != ENOTDIR) {
- error = convert_errno(errno);
+ if (error != __WASI_ELOOP && error != __WASI_EMLINK
+ && error != __WASI_ENOTDIR) {
goto fail;
}
- symlink = readlinkat_dup(fds[curfd], file, &symlink_len);
- if (symlink != NULL)
+ error =
+ readlinkat_dup(fds[curfd], file, &symlink_len, &symlink);
+
+ if (error == __WASI_ESUCCESS) {
+ bh_assert(symlink != NULL);
goto push_symlink;
+ }
// readlink returns EINVAL if the path isn't a symlink. In that
// case, it's more informative to return ENOTDIR.
- if (errno == EINVAL)
- errno = ENOTDIR;
+ if (error == __WASI_EINVAL)
+ error = __WASI_ENOTDIR;
- error = convert_errno(errno);
goto fail;
}
}
@@ -1672,11 +1391,13 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
// expansion.
if (ends_with_slashes
|| (flags & __WASI_LOOKUP_SYMLINK_FOLLOW) != 0) {
- symlink = readlinkat_dup(fds[curfd], file, &symlink_len);
- if (symlink != NULL)
+ error =
+ readlinkat_dup(fds[curfd], file, &symlink_len, &symlink);
+ if (error == __WASI_ESUCCESS) {
+ bh_assert(symlink != NULL);
goto push_symlink;
- if (errno != EINVAL && errno != ENOENT) {
- error = convert_errno(errno);
+ }
+ if (error != __WASI_EINVAL && error != __WASI_ENOENT) {
goto fail;
}
}
@@ -1753,7 +1474,7 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
// Return the lease. Close all directories, except the one the caller
// needs to use.
for (size_t i = 1; i < curfd; ++i)
- close(fds[i]);
+ os_close(fds[i], false);
pa->fd = fds[curfd];
pa->follow = false;
pa->fd_object = fo;
@@ -1762,23 +1483,23 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd,
fail:
// Failure. Free all resources.
for (size_t i = 1; i <= curfd; ++i)
- close(fds[i]);
+ os_close(fds[i], false);
for (size_t i = 0; i <= curpath; ++i)
wasm_runtime_free(paths_start[i]);
- fd_object_release(fo);
+ fd_object_release(NULL, fo);
return error;
#endif
}
static __wasi_errno_t
-path_get_nofollow(struct fd_table *curfds, struct path_access *pa,
- __wasi_fd_t fd, const char *path, size_t pathlen,
- __wasi_rights_t rights_base,
+path_get_nofollow(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct path_access *pa, __wasi_fd_t fd, const char *path,
+ size_t pathlen, __wasi_rights_t rights_base,
__wasi_rights_t rights_inheriting, bool needs_final_component)
TRYLOCKS_EXCLUSIVE(0, pa->fd_object->refcount)
{
__wasi_lookupflags_t flags = 0;
- return path_get(curfds, pa, fd, flags, path, pathlen, rights_base,
+ return path_get(exec_env, curfds, pa, fd, flags, path, pathlen, rights_base,
rights_inheriting, needs_final_component);
}
@@ -1787,30 +1508,27 @@ path_put(struct path_access *pa) UNLOCKS(pa->fd_object->refcount)
{
if (pa->path_start)
wasm_runtime_free(pa->path_start);
- if (fd_number(pa->fd_object) != pa->fd)
- close(pa->fd);
- fd_object_release(pa->fd_object);
+ if (pa->fd_object->file_handle != pa->fd)
+ os_close(pa->fd, false);
+ fd_object_release(NULL, pa->fd_object);
}
__wasi_errno_t
-wasmtime_ssp_path_create_directory(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const char *path, size_t pathlen)
+wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ const char *path, size_t pathlen)
{
struct path_access pa;
__wasi_errno_t error =
- path_get_nofollow(curfds, &pa, fd, path, pathlen,
+ path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen,
__WASI_RIGHT_PATH_CREATE_DIRECTORY, 0, true);
if (error != 0)
return error;
- int ret = mkdirat(pa.fd, pa.path, 0777);
+ error = os_mkdirat(pa.fd, pa.path);
path_put(&pa);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+
+ return error;
}
static bool
@@ -1820,7 +1538,7 @@ validate_path(const char *path, struct fd_prestats *pt)
char path_resolved[PATH_MAX], prestat_dir_resolved[PATH_MAX];
char *path_real, *prestat_dir_real;
- if (!(path_real = realpath(path, path_resolved)))
+ if (!(path_real = os_realpath(path, path_resolved)))
/* path doesn't exist, creating a link to this file
is allowed: if this file is to be created in
the future, WASI will strictly check whether it
@@ -1830,7 +1548,7 @@ validate_path(const char *path, struct fd_prestats *pt)
for (i = 0; i < pt->size; i++) {
if (pt->prestats[i].dir) {
if (!(prestat_dir_real =
- realpath(pt->prestats[i].dir, prestat_dir_resolved)))
+ os_realpath(pt->prestats[i].dir, prestat_dir_resolved)))
return false;
if (!strncmp(path_real, prestat_dir_real, strlen(prestat_dir_real)))
return true;
@@ -1841,24 +1559,23 @@ validate_path(const char *path, struct fd_prestats *pt)
}
__wasi_errno_t
-wasmtime_ssp_path_link(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct fd_prestats *prestats,
-#endif
- __wasi_fd_t old_fd, __wasi_lookupflags_t old_flags, const char *old_path,
- size_t old_path_len, __wasi_fd_t new_fd, const char *new_path,
- size_t new_path_len)
+wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, __wasi_fd_t old_fd,
+ __wasi_lookupflags_t old_flags, const char *old_path,
+ size_t old_path_len, __wasi_fd_t new_fd,
+ const char *new_path, size_t new_path_len)
{
struct path_access old_pa;
__wasi_errno_t error =
- path_get(curfds, &old_pa, old_fd, old_flags, old_path, old_path_len,
- __WASI_RIGHT_PATH_LINK_SOURCE, 0, false);
+ path_get(exec_env, curfds, &old_pa, old_fd, old_flags, old_path,
+ old_path_len, __WASI_RIGHT_PATH_LINK_SOURCE, 0, false);
if (error != 0)
return error;
struct path_access new_pa;
- error = path_get_nofollow(curfds, &new_pa, new_fd, new_path, new_path_len,
- __WASI_RIGHT_PATH_LINK_TARGET, 0, true);
+ error =
+ path_get_nofollow(exec_env, curfds, &new_pa, new_fd, new_path,
+ new_path_len, __WASI_RIGHT_PATH_LINK_TARGET, 0, true);
if (error != 0) {
path_put(&old_pa);
return error;
@@ -1872,14 +1589,18 @@ wasmtime_ssp_path_link(
}
rwlock_unlock(&prestats->lock);
- int ret = linkat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path,
- old_pa.follow ? AT_SYMLINK_FOLLOW : 0);
- if (ret < 0 && errno == ENOTSUP && !old_pa.follow) {
+ error = os_linkat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path,
+ old_pa.follow ? __WASI_LOOKUP_SYMLINK_FOLLOW : 0);
+
+#if defined(__APPLE__)
+ if (error == __WASI_ENOTSUP && !old_pa.follow) {
// OS X doesn't allow creating hardlinks to symbolic links.
// Duplicate the symbolic link instead.
size_t target_len;
- char *target = readlinkat_dup(old_pa.fd, old_pa.path, &target_len);
- if (target != NULL) {
+ char *target = NULL;
+ error = readlinkat_dup(old_pa.fd, old_pa.path, &target_len, &target);
+ if (error == __WASI_ESUCCESS) {
+ bh_assert(target != NULL);
bh_assert(target[target_len] == '\0');
rwlock_rdlock(&prestats->lock);
if (!validate_path(target, prestats)) {
@@ -1888,26 +1609,25 @@ wasmtime_ssp_path_link(
return __WASI_EBADF;
}
rwlock_unlock(&prestats->lock);
- ret = symlinkat(target, new_pa.fd, new_pa.path);
+ error = os_symlinkat(target, new_pa.fd, new_pa.path);
wasm_runtime_free(target);
}
}
+#endif
+
path_put(&old_pa);
path_put(&new_pa);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_open(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, const char *path,
- size_t pathlen, __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base,
- __wasi_rights_t fs_rights_inheriting, __wasi_fdflags_t fs_flags,
- __wasi_fd_t *fd)
+wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags,
+ const char *path, size_t pathlen, __wasi_oflags_t oflags,
+ __wasi_rights_t fs_rights_base,
+ __wasi_rights_t fs_rights_inheriting,
+ __wasi_fdflags_t fs_flags, __wasi_fd_t *fd)
{
// Rights that should be installed on the new file descriptor.
__wasi_rights_t rights_base = fs_rights_base;
@@ -1921,7 +1641,11 @@ wasmtime_ssp_path_open(
& (__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE
| __WASI_RIGHT_FD_ALLOCATE | __WASI_RIGHT_FD_FILESTAT_SET_SIZE))
!= 0;
- int noflags = write ? read ? O_RDWR : O_WRONLY : O_RDONLY;
+
+ wasi_libc_file_access_mode access_mode =
+ write ? read ? WASI_LIBC_ACCESS_MODE_READ_WRITE
+ : WASI_LIBC_ACCESS_MODE_WRITE_ONLY
+ : WASI_LIBC_ACCESS_MODE_READ_ONLY;
// Which rights are needed on the directory file descriptor.
__wasi_rights_t needed_base = __WASI_RIGHT_PATH_OPEN;
@@ -1929,113 +1653,58 @@ wasmtime_ssp_path_open(
// Convert open flags.
if ((oflags & __WASI_O_CREAT) != 0) {
- noflags |= O_CREAT;
needed_base |= __WASI_RIGHT_PATH_CREATE_FILE;
}
- if ((oflags & __WASI_O_DIRECTORY) != 0)
- noflags |= O_DIRECTORY;
- if ((oflags & __WASI_O_EXCL) != 0)
- noflags |= O_EXCL;
if ((oflags & __WASI_O_TRUNC) != 0) {
- noflags |= O_TRUNC;
needed_base |= __WASI_RIGHT_PATH_FILESTAT_SET_SIZE;
}
// Convert file descriptor flags.
- if ((fs_flags & __WASI_FDFLAG_APPEND) != 0)
- noflags |= O_APPEND;
- if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) {
-#ifdef O_DSYNC
- noflags |= O_DSYNC;
-#else
- noflags |= O_SYNC;
-#endif
- needed_inheriting |= __WASI_RIGHT_FD_DATASYNC;
+ if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) {
+ needed_inheriting |= __WASI_RIGHT_FD_SYNC;
}
- if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0)
- noflags |= O_NONBLOCK;
if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0) {
-#ifdef O_RSYNC
- noflags |= O_RSYNC;
-#else
- noflags |= O_SYNC;
-#endif
needed_inheriting |= __WASI_RIGHT_FD_SYNC;
}
- if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) {
- noflags |= O_SYNC;
- needed_inheriting |= __WASI_RIGHT_FD_SYNC;
+ if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) {
+ needed_inheriting |= __WASI_RIGHT_FD_DATASYNC;
}
- if (write && (noflags & (O_APPEND | O_TRUNC)) == 0)
+
+ if (write
+ && !((fs_flags & __WASI_FDFLAG_APPEND) || (__WASI_O_TRUNC & oflags)))
needed_inheriting |= __WASI_RIGHT_FD_SEEK;
struct path_access pa;
- __wasi_errno_t error =
- path_get(curfds, &pa, dirfd, dirflags, path, pathlen, needed_base,
- needed_inheriting, (oflags & __WASI_O_CREAT) != 0);
+ __wasi_errno_t error = path_get(
+ exec_env, curfds, &pa, dirfd, dirflags, path, pathlen, needed_base,
+ needed_inheriting, (oflags & __WASI_O_CREAT) != 0);
+
if (error != 0)
return error;
- if (!pa.follow)
- noflags |= O_NOFOLLOW;
-
- int nfd = openat(pa.fd, pa.path, noflags, 0666);
- if (nfd < 0) {
- int openat_errno = errno;
- // Linux returns ENXIO instead of EOPNOTSUPP when opening a socket.
- if (openat_errno == ENXIO) {
- struct stat sb;
- int ret = fstatat(pa.fd, pa.path, &sb,
- pa.follow ? 0 : AT_SYMLINK_NOFOLLOW);
- path_put(&pa);
- return ret == 0 && S_ISSOCK(sb.st_mode) ? __WASI_ENOTSUP
- : __WASI_ENXIO;
- }
- // Linux returns ENOTDIR instead of ELOOP when using
- // O_NOFOLLOW|O_DIRECTORY on a symlink.
- if (openat_errno == ENOTDIR
- && (noflags & (O_NOFOLLOW | O_DIRECTORY)) != 0) {
- struct stat sb;
- int ret = fstatat(pa.fd, pa.path, &sb, AT_SYMLINK_NOFOLLOW);
- if (S_ISLNK(sb.st_mode)) {
- path_put(&pa);
- return __WASI_ELOOP;
- }
- (void)ret;
- }
- path_put(&pa);
- // FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on
- // a symlink.
- if (!pa.follow && openat_errno == EMLINK)
- return __WASI_ELOOP;
- return convert_errno(openat_errno);
- }
+
+ os_file_handle handle;
+ error = blocking_op_openat(exec_env, pa.fd, pa.path, oflags, fs_flags,
+ dirflags, access_mode, &handle);
+
path_put(&pa);
+ if (error != __WASI_ESUCCESS)
+ return error;
+
// Determine the type of the new file descriptor and which rights
// contradict with this type.
__wasi_filetype_t type;
__wasi_rights_t max_base, max_inheriting;
- error = fd_determine_type_rights(nfd, &type, &max_base, &max_inheriting);
- if (error != 0) {
- close(nfd);
- return error;
- }
-
- {
- struct stat sb;
- if (fstat(nfd, &sb) < 0) {
- close(nfd);
- return convert_errno(errno);
- }
+ error = fd_determine_type_rights(handle, &type, &max_base, &max_inheriting);
- if (S_ISDIR(sb.st_mode))
- rights_base |= (__wasi_rights_t)RIGHTS_DIRECTORY_BASE;
- else if (S_ISREG(sb.st_mode))
- rights_base |= (__wasi_rights_t)RIGHTS_REGULAR_FILE_BASE;
+ if (error != __WASI_ESUCCESS) {
+ os_close(handle, false);
+ return error;
}
- return fd_table_insert_fd(curfds, nfd, type, rights_base & max_base,
+ return fd_table_insert_fd(exec_env, curfds, handle, type,
+ rights_base & max_base,
rights_inheriting & max_inheriting, fd);
}
@@ -2054,12 +1723,9 @@ fd_readdir_put(void *buf, size_t bufsize, size_t *bufused, const void *elem,
}
__wasi_errno_t
-wasmtime_ssp_fd_readdir(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, void *buf, size_t nbyte, __wasi_dircookie_t cookie,
- size_t *bufused)
+wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, void *buf, size_t nbyte,
+ __wasi_dircookie_t cookie, size_t *bufused)
{
struct fd_object *fo;
__wasi_errno_t error =
@@ -2070,15 +1736,13 @@ wasmtime_ssp_fd_readdir(
// Create a directory handle if none has been opened yet.
mutex_lock(&fo->directory.lock);
- DIR *dp = fo->directory.handle;
- if (dp == NULL) {
- dp = fdopendir(fd_number(fo));
- if (dp == NULL) {
+ if (!os_is_dir_stream_valid(&fo->directory.handle)) {
+ error = os_fdopendir(fo->file_handle, &fo->directory.handle);
+ if (error != __WASI_ESUCCESS) {
mutex_unlock(&fo->directory.lock);
- fd_object_release(fo);
- return convert_errno(errno);
+ fd_object_release(exec_env, fo);
+ return error;
}
- fo->directory.handle = dp;
fo->directory.offset = __WASI_DIRCOOKIE_START;
}
@@ -2086,173 +1750,102 @@ wasmtime_ssp_fd_readdir(
// the current offset.
if (fo->directory.offset != cookie) {
if (cookie == __WASI_DIRCOOKIE_START)
- rewinddir(dp);
+ os_rewinddir(fo->directory.handle);
else
- seekdir(dp, (long)cookie);
+ os_seekdir(fo->directory.handle, cookie);
fo->directory.offset = cookie;
}
*bufused = 0;
while (*bufused < nbyte) {
// Read the next directory entry.
- errno = 0;
- struct dirent *de = readdir(dp);
- if (de == NULL) {
+ __wasi_dirent_t cde;
+ const char *d_name = NULL;
+
+ error = os_readdir(fo->directory.handle, &cde, &d_name);
+ if (d_name == NULL) {
mutex_unlock(&fo->directory.lock);
- fd_object_release(fo);
- return errno == 0 || *bufused > 0 ? 0 : convert_errno(errno);
- }
- fo->directory.offset = (__wasi_dircookie_t)telldir(dp);
-
- // Craft a directory entry and copy that back.
- size_t namlen = strlen(de->d_name);
- __wasi_dirent_t cde = {
- .d_next = fo->directory.offset,
-#if CONFIG_HAS_D_INO
- .d_ino = de->d_ino,
-#else
- .d_ino = 0,
-#endif
- .d_namlen = (uint32)namlen,
- };
- switch (de->d_type) {
- case DT_BLK:
- cde.d_type = __WASI_FILETYPE_BLOCK_DEVICE;
- break;
- case DT_CHR:
- cde.d_type = __WASI_FILETYPE_CHARACTER_DEVICE;
- break;
- case DT_DIR:
- cde.d_type = __WASI_FILETYPE_DIRECTORY;
- break;
- case DT_FIFO:
- cde.d_type = __WASI_FILETYPE_SOCKET_STREAM;
- break;
- case DT_LNK:
- cde.d_type = __WASI_FILETYPE_SYMBOLIC_LINK;
- break;
- case DT_REG:
- cde.d_type = __WASI_FILETYPE_REGULAR_FILE;
- break;
-#ifdef DT_SOCK
- case DT_SOCK:
- // Technically not correct, but good enough.
- cde.d_type = __WASI_FILETYPE_SOCKET_STREAM;
- break;
-#endif
- default:
- cde.d_type = __WASI_FILETYPE_UNKNOWN;
- break;
+ fd_object_release(exec_env, fo);
+
+ return *bufused > 0 ? __WASI_ESUCCESS : error;
}
+
+ fo->directory.offset = cde.d_next;
+
fd_readdir_put(buf, nbyte, bufused, &cde, sizeof(cde));
- fd_readdir_put(buf, nbyte, bufused, de->d_name, namlen);
+ fd_readdir_put(buf, nbyte, bufused, d_name, cde.d_namlen);
}
mutex_unlock(&fo->directory.lock);
- fd_object_release(fo);
- return 0;
+ fd_object_release(exec_env, fo);
+ return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasmtime_ssp_path_readlink(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const char *path, size_t pathlen, char *buf, size_t bufsize,
- size_t *bufused)
+wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const char *path, size_t pathlen,
+ char *buf, size_t bufsize, size_t *bufused)
{
struct path_access pa;
- __wasi_errno_t error = path_get_nofollow(
- curfds, &pa, fd, path, pathlen, __WASI_RIGHT_PATH_READLINK, 0, false);
+ __wasi_errno_t error =
+ path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen,
+ __WASI_RIGHT_PATH_READLINK, 0, false);
+
if (error != 0)
return error;
- // Linux requires that the buffer size is positive. whereas POSIX does
- // not. Use a fake buffer to store the results if the size is zero.
- char fakebuf[1];
- ssize_t len = readlinkat(pa.fd, pa.path, bufsize == 0 ? fakebuf : buf,
- bufsize == 0 ? sizeof(fakebuf) : bufsize);
+ error = os_readlinkat(pa.fd, pa.path, buf, bufsize, bufused);
+
path_put(&pa);
- if (len < 0)
- return convert_errno(errno);
- *bufused = (size_t)len < bufsize ? (size_t)len : bufsize;
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_rename(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t old_fd, const char *old_path, size_t old_path_len,
- __wasi_fd_t new_fd, const char *new_path, size_t new_path_len)
+wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t old_fd, const char *old_path,
+ size_t old_path_len, __wasi_fd_t new_fd,
+ const char *new_path, size_t new_path_len)
{
struct path_access old_pa;
- __wasi_errno_t error =
- path_get_nofollow(curfds, &old_pa, old_fd, old_path, old_path_len,
- __WASI_RIGHT_PATH_RENAME_SOURCE, 0, true);
+ __wasi_errno_t error = path_get_nofollow(
+ exec_env, curfds, &old_pa, old_fd, old_path, old_path_len,
+ __WASI_RIGHT_PATH_RENAME_SOURCE, 0, true);
if (error != 0)
return error;
struct path_access new_pa;
- error = path_get_nofollow(curfds, &new_pa, new_fd, new_path, new_path_len,
- __WASI_RIGHT_PATH_RENAME_TARGET, 0, true);
+ error = path_get_nofollow(exec_env, curfds, &new_pa, new_fd, new_path,
+ new_path_len, __WASI_RIGHT_PATH_RENAME_TARGET, 0,
+ true);
if (error != 0) {
path_put(&old_pa);
return error;
}
- int ret = renameat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path);
+ error = os_renameat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path);
+
path_put(&old_pa);
path_put(&new_pa);
- if (ret < 0) {
- return convert_errno(errno);
- }
- return 0;
-}
-// Converts a POSIX stat structure to a CloudABI filestat structure.
-static void
-convert_stat(const struct stat *in, __wasi_filestat_t *out)
-{
- *out = (__wasi_filestat_t){
- .st_dev = in->st_dev,
- .st_ino = in->st_ino,
- .st_nlink = (__wasi_linkcount_t)in->st_nlink,
- .st_size = (__wasi_filesize_t)in->st_size,
- .st_atim = convert_timespec(&in->st_atim),
- .st_mtim = convert_timespec(&in->st_mtim),
- .st_ctim = convert_timespec(&in->st_ctim),
- };
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_filestat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_filestat_t *buf)
+wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_filestat_t *buf)
{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_FILESTAT_GET, 0);
+
if (error != 0)
return error;
- int ret;
- switch (fo->type) {
- default:
- {
- struct stat sb;
- ret = fstat(fd_number(fo), &sb);
- convert_stat(&sb, buf);
- break;
- }
- }
- buf->st_filetype = fo->type;
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ error = os_fstat(fo->file_handle, buf);
+
+ fd_object_release(exec_env, fo);
+
+ return error;
}
static void
@@ -2270,61 +1863,30 @@ convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
}
-// Converts the provided timestamps and flags to a set of arguments for
-// futimens() and utimensat().
-static void
-convert_utimens_arguments(__wasi_timestamp_t st_atim,
- __wasi_timestamp_t st_mtim,
- __wasi_fstflags_t fstflags, struct timespec *ts)
-{
- if ((fstflags & __WASI_FILESTAT_SET_ATIM_NOW) != 0) {
- ts[0].tv_nsec = UTIME_NOW;
- }
- else if ((fstflags & __WASI_FILESTAT_SET_ATIM) != 0) {
- convert_timestamp(st_atim, &ts[0]);
- }
- else {
- ts[0].tv_nsec = UTIME_OMIT;
- }
-
- if ((fstflags & __WASI_FILESTAT_SET_MTIM_NOW) != 0) {
- ts[1].tv_nsec = UTIME_NOW;
- }
- else if ((fstflags & __WASI_FILESTAT_SET_MTIM) != 0) {
- convert_timestamp(st_mtim, &ts[1]);
- }
- else {
- ts[1].tv_nsec = UTIME_OMIT;
- }
-}
-
__wasi_errno_t
-wasmtime_ssp_fd_filestat_set_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_filesize_t st_size)
+wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_filesize_t st_size)
{
struct fd_object *fo;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_FILESTAT_SET_SIZE, 0);
+
if (error != 0)
return error;
- int ret = ftruncate(fd_number(fo), (off_t)st_size);
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ error = os_ftruncate(fo->file_handle, st_size);
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_fd_filestat_set_times(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_timestamp_t st_atim, __wasi_timestamp_t st_mtim,
- __wasi_fstflags_t fstflags)
+wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_timestamp_t st_atim,
+ __wasi_timestamp_t st_mtim,
+ __wasi_fstflags_t fstflags)
{
if ((fstflags
& ~(__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW
@@ -2338,64 +1900,42 @@ wasmtime_ssp_fd_filestat_set_times(
if (error != 0)
return error;
- struct timespec ts[2];
- convert_utimens_arguments(st_atim, st_mtim, fstflags, ts);
- int ret = futimens(fd_number(fo), ts);
+ error = os_futimens(fo->file_handle, st_atim, st_mtim, fstflags);
- fd_object_release(fo);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ fd_object_release(exec_env, fo);
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_filestat_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path,
- size_t pathlen, __wasi_filestat_t *buf)
+wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_lookupflags_t flags, const char *path,
+ size_t pathlen, __wasi_filestat_t *buf)
{
struct path_access pa;
- __wasi_errno_t error = path_get(curfds, &pa, fd, flags, path, pathlen,
- __WASI_RIGHT_PATH_FILESTAT_GET, 0, false);
+ __wasi_errno_t error =
+ path_get(exec_env, curfds, &pa, fd, flags, path, pathlen,
+ __WASI_RIGHT_PATH_FILESTAT_GET, 0, false);
if (error != 0)
return error;
- struct stat sb;
- int ret = fstatat(pa.fd, pa.path, &sb, pa.follow ? 0 : AT_SYMLINK_NOFOLLOW);
+ error = os_fstatat(pa.fd, pa.path, buf,
+ pa.follow ? __WASI_LOOKUP_SYMLINK_FOLLOW : 0);
+
path_put(&pa);
- if (ret < 0)
- return convert_errno(errno);
- convert_stat(&sb, buf);
-
- // Convert the file type. In the case of sockets there is no way we
- // can easily determine the exact socket type.
- if (S_ISBLK(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_BLOCK_DEVICE;
- else if (S_ISCHR(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_CHARACTER_DEVICE;
- else if (S_ISDIR(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_DIRECTORY;
- else if (S_ISFIFO(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_SOCKET_STREAM;
- else if (S_ISLNK(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_SYMBOLIC_LINK;
- else if (S_ISREG(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_REGULAR_FILE;
- else if (S_ISSOCK(sb.st_mode))
- buf->st_filetype = __WASI_FILETYPE_SOCKET_STREAM;
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_filestat_set_times(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path,
- size_t pathlen, __wasi_timestamp_t st_atim, __wasi_timestamp_t st_mtim,
- __wasi_fstflags_t fstflags)
+wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_lookupflags_t flags,
+ const char *path, size_t pathlen,
+ __wasi_timestamp_t st_atim,
+ __wasi_timestamp_t st_mtim,
+ __wasi_fstflags_t fstflags)
{
if (((fstflags
& ~(__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW
@@ -2411,29 +1951,23 @@ wasmtime_ssp_path_filestat_set_times(
struct path_access pa;
__wasi_errno_t error =
- path_get(curfds, &pa, fd, flags, path, pathlen,
+ path_get(exec_env, curfds, &pa, fd, flags, path, pathlen,
__WASI_RIGHT_PATH_FILESTAT_SET_TIMES, 0, false);
if (error != 0)
return error;
- struct timespec ts[2];
- convert_utimens_arguments(st_atim, st_mtim, fstflags, ts);
- int ret =
- utimensat(pa.fd, pa.path, ts, pa.follow ? 0 : AT_SYMLINK_NOFOLLOW);
+ error = os_utimensat(pa.fd, pa.path, st_atim, st_mtim, fstflags,
+ pa.follow ? __WASI_LOOKUP_SYMLINK_FOLLOW : 0);
path_put(&pa);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_symlink(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct fd_prestats *prestats,
-#endif
- const char *old_path, size_t old_path_len, __wasi_fd_t fd,
- const char *new_path, size_t new_path_len)
+wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct fd_prestats *prestats, const char *old_path,
+ size_t old_path_len, __wasi_fd_t fd,
+ const char *new_path, size_t new_path_len)
{
char *target = str_nullterminate(old_path, old_path_len);
if (target == NULL)
@@ -2441,7 +1975,7 @@ wasmtime_ssp_path_symlink(
struct path_access pa;
__wasi_errno_t error =
- path_get_nofollow(curfds, &pa, fd, new_path, new_path_len,
+ path_get_nofollow(exec_env, curfds, &pa, fd, new_path, new_path_len,
__WASI_RIGHT_PATH_SYMLINK, 0, true);
if (error != 0) {
wasm_runtime_free(target);
@@ -2456,88 +1990,60 @@ wasmtime_ssp_path_symlink(
}
rwlock_unlock(&prestats->lock);
- int ret = symlinkat(target, pa.fd, pa.path);
+ error = os_symlinkat(target, pa.fd, pa.path);
+
path_put(&pa);
wasm_runtime_free(target);
- if (ret < 0)
- return convert_errno(errno);
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_unlink_file(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const char *path, size_t pathlen)
+wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, const char *path, size_t pathlen)
{
struct path_access pa;
- __wasi_errno_t error = path_get_nofollow(
- curfds, &pa, fd, path, pathlen, __WASI_RIGHT_PATH_UNLINK_FILE, 0, true);
- if (error != 0)
+ __wasi_errno_t error =
+ path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen,
+ __WASI_RIGHT_PATH_UNLINK_FILE, 0, true);
+ if (error != __WASI_ESUCCESS)
return error;
- int ret = unlinkat(pa.fd, pa.path, 0);
-#ifndef __linux__
- // Non-Linux implementations may return EPERM when attempting to remove a
- // directory without REMOVEDIR. While that's what POSIX specifies, it's
- // less useful. Adjust this to EISDIR. It doesn't matter that this is not
- // atomic with the unlinkat, because if the file is removed and a directory
- // is created before fstatat sees it, we're racing with that change anyway
- // and unlinkat could have legitimately seen the directory if the race had
- // turned out differently.
- if (ret < 0 && errno == EPERM) {
- struct stat statbuf;
- if (fstatat(pa.fd, pa.path, &statbuf, AT_SYMLINK_NOFOLLOW) == 0
- && S_ISDIR(statbuf.st_mode)) {
- errno = EISDIR;
- }
- }
-#endif
+ error = os_unlinkat(pa.fd, pa.path, false);
+
path_put(&pa);
- if (ret < 0) {
- return convert_errno(errno);
- }
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_path_remove_directory(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, const char *path, size_t pathlen)
+wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ const char *path, size_t pathlen)
{
struct path_access pa;
__wasi_errno_t error =
- path_get_nofollow(curfds, &pa, fd, path, pathlen,
+ path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen,
__WASI_RIGHT_PATH_REMOVE_DIRECTORY, 0, true);
if (error != 0)
return error;
- int ret = unlinkat(pa.fd, pa.path, AT_REMOVEDIR);
-#ifndef __linux__
- // POSIX permits either EEXIST or ENOTEMPTY when the directory is not empty.
- // Map it to ENOTEMPTY.
- if (ret < 0 && errno == EEXIST) {
- errno = ENOTEMPTY;
- }
-#endif
+ error = os_unlinkat(pa.fd, pa.path, true);
+
path_put(&pa);
- if (ret < 0) {
- return convert_errno(errno);
- }
- return 0;
+
+ return error;
}
__wasi_errno_t
-wasmtime_ssp_poll_oneoff(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions,
- size_t *nevents) NO_LOCK_ANALYSIS
+wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ const __wasi_subscription_t *in, __wasi_event_t *out,
+ size_t nsubscriptions,
+ size_t *nevents) NO_LOCK_ANALYSIS
{
+#ifdef BH_PLATFORM_WINDOWS
+ return __WASI_ENOSYS;
+#else
// Sleeping.
if (nsubscriptions == 1 && in[0].u.type == __WASI_EVENTTYPE_CLOCK) {
out[0] = (__wasi_event_t){
@@ -2546,7 +2052,7 @@ wasmtime_ssp_poll_oneoff(
};
#if CONFIG_HAS_CLOCK_NANOSLEEP
clockid_t clock_id;
- if (convert_clockid(in[0].u.u.clock.clock_id, &clock_id)) {
+ if (wasi_clockid_to_clockid(in[0].u.u.clock.clock_id, &clock_id)) {
struct timespec ts;
convert_timestamp(in[0].u.u.clock.timeout, &ts);
int ret = clock_nanosleep(
@@ -2653,7 +2159,7 @@ wasmtime_ssp_poll_oneoff(
if (error == 0) {
// Proper file descriptor on which we can poll().
pfds[i] = (struct pollfd){
- .fd = fd_number(fos[i]),
+ .fd = fos[i]->file_handle,
.events = s->u.type == __WASI_EVENTTYPE_FD_READ
? POLLIN
: POLLOUT,
@@ -2709,6 +2215,7 @@ wasmtime_ssp_poll_oneoff(
else {
timeout = -1;
}
+
int ret = poll(pfds, nsubscriptions, timeout);
__wasi_errno_t error = 0;
@@ -2729,7 +2236,7 @@ wasmtime_ssp_poll_oneoff(
__wasi_filesize_t nbytes = 0;
if (in[i].u.type == __WASI_EVENTTYPE_FD_READ) {
int l;
- if (ioctl(fd_number(fos[i]), FIONREAD, &l) == 0)
+ if (ioctl(fos[i]->file_handle, FIONREAD, &l) == 0)
nbytes = (__wasi_filesize_t)l;
}
if ((pfds[i].revents & POLLNVAL) != 0) {
@@ -2781,147 +2288,28 @@ wasmtime_ssp_poll_oneoff(
for (size_t i = 0; i < nsubscriptions; ++i)
if (fos[i] != NULL)
- fd_object_release(fos[i]);
+ fd_object_release(exec_env, fos[i]);
wasm_runtime_free(fos);
wasm_runtime_free(pfds);
return error;
-}
-
-#if 0
-/**
- * We throw exception in libc-wasi wrapper function wasi_proc_exit()
- * but not call this function.
- */
-void wasmtime_ssp_proc_exit(
- __wasi_exitcode_t rval
-) {
- _Exit((int32)rval);
-}
-#endif
-
-__wasi_errno_t
-wasmtime_ssp_proc_raise(__wasi_signal_t sig)
-{
- static const int signals[] = {
-#define X(v) [__WASI_##v] = v
-#if defined(SIGABRT)
- X(SIGABRT),
-#endif
-#if defined(SIGALRM)
- X(SIGALRM),
-#endif
-#if defined(SIGBUS)
- X(SIGBUS),
#endif
-#if defined(SIGCHLD)
- X(SIGCHLD),
-#endif
-#if defined(SIGCONT)
- X(SIGCONT),
-#endif
-#if defined(SIGFPE)
- X(SIGFPE),
-#endif
-#if defined(SIGHUP)
- X(SIGHUP),
-#endif
-#if defined(SIGILL)
- X(SIGILL),
-#endif
-#if defined(SIGINT)
- X(SIGINT),
-#endif
-#if defined(SIGKILL)
- X(SIGKILL),
-#endif
-#if defined(SIGPIPE)
- X(SIGPIPE),
-#endif
-#if defined(SIGQUIT)
- X(SIGQUIT),
-#endif
-#if defined(SIGSYS)
- X(SIGSEGV),
-#endif
-#if defined(SIGSTOP)
- X(SIGSTOP),
-#endif
-#if defined(SIGSYS)
- X(SIGSYS),
-#endif
-#if defined(SIGTERM)
- X(SIGTERM),
-#endif
-#if defined(SIGTRAP)
- X(SIGTRAP),
-#endif
-#if defined(SIGTSTP)
- X(SIGTSTP),
-#endif
-#if defined(SIGTTIN)
- X(SIGTTIN),
-#endif
-#if defined(SIGTTOU)
- X(SIGTTOU),
-#endif
-#if defined(SIGURG)
- X(SIGURG),
-#endif
-#if defined(SIGUSR1)
- X(SIGUSR1),
-#endif
-#if defined(SIGUSR2)
- X(SIGUSR2),
-#endif
-#if defined(SIGVTALRM)
- X(SIGVTALRM),
-#endif
-#if defined(SIGXCPU)
- X(SIGXCPU),
-#endif
-#if defined(SIGXFSZ)
- X(SIGXFSZ),
-#endif
-#undef X
- };
- if (sig >= sizeof(signals) / sizeof(signals[0]) || signals[sig] == 0)
- return __WASI_EINVAL;
-
-#if CONFIG_TLS_USE_GSBASE
- // TLS on OS X depends on installing a SIGSEGV handler. Reset SIGSEGV
- // to the default action before raising.
- if (sig == __WASI_SIGSEGV) {
- struct sigaction sa = {
- .sa_handler = SIG_DFL,
- };
- sigemptyset(&sa.sa_mask);
- sigaction(SIGSEGV, &sa, NULL);
- }
-#endif
-
- if (raise(signals[sig]) < 0)
- return convert_errno(errno);
- return 0;
}
__wasi_errno_t
wasmtime_ssp_random_get(void *buf, size_t nbyte)
{
- random_buf(buf, nbyte);
- return 0;
+ return random_buf(buf, nbyte);
}
__wasi_errno_t
-wasi_ssp_sock_accept(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new)
+wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_fdflags_t flags,
+ __wasi_fd_t *fd_new)
{
__wasi_filetype_t wasi_type;
__wasi_rights_t max_base, max_inheriting;
struct fd_object *fo;
- bh_socket_t new_sock = -1;
+ bh_socket_t new_sock = os_get_invalid_handle();
int ret;
__wasi_errno_t error =
fd_object_get(curfds, &fo, fd, __WASI_RIGHT_SOCK_ACCEPT, 0);
@@ -2929,8 +2317,9 @@ wasi_ssp_sock_accept(
goto fail;
}
- ret = os_socket_accept(fd_number(fo), &new_sock, NULL, NULL);
- fd_object_release(fo);
+ ret = blocking_op_socket_accept(exec_env, fo->file_handle, &new_sock, NULL,
+ NULL);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
error = convert_errno(errno);
goto fail;
@@ -2942,29 +2331,26 @@ wasi_ssp_sock_accept(
goto fail;
}
- error = fd_table_insert_fd(curfds, new_sock, wasi_type, max_base,
+ error = fd_table_insert_fd(exec_env, curfds, new_sock, wasi_type, max_base,
max_inheriting, fd_new);
if (error != __WASI_ESUCCESS) {
/* released in fd_table_insert_fd() */
- new_sock = -1;
+ new_sock = os_get_invalid_handle();
goto fail;
}
return __WASI_ESUCCESS;
fail:
- if (-1 != new_sock) {
+ if (os_is_handle_valid(&new_sock)) {
os_socket_close(new_sock);
}
return error;
}
__wasi_errno_t
-wasi_ssp_sock_addr_local(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr)
+wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_addr_t *addr)
{
struct fd_object *fo;
bh_sockaddr_t bh_addr;
@@ -2975,8 +2361,8 @@ wasi_ssp_sock_addr_local(
if (error != __WASI_ESUCCESS)
return error;
- ret = os_socket_addr_local(fd_number(fo), &bh_addr);
- fd_object_release(fo);
+ ret = os_socket_addr_local(fo->file_handle, &bh_addr);
+ fd_object_release(exec_env, fo);
if (ret != BHT_OK) {
return convert_errno(errno);
}
@@ -2987,11 +2373,8 @@ wasi_ssp_sock_addr_local(
}
__wasi_errno_t
-wasi_ssp_sock_addr_remote(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr)
+wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_addr_t *addr)
{
struct fd_object *fo;
bh_sockaddr_t bh_addr;
@@ -3002,8 +2385,8 @@ wasi_ssp_sock_addr_remote(
if (error != __WASI_ESUCCESS)
return error;
- ret = os_socket_addr_remote(fd_number(fo), &bh_addr);
- fd_object_release(fo);
+ ret = os_socket_addr_remote(fo->file_handle, &bh_addr);
+ fd_object_release(exec_env, fo);
if (ret != BHT_OK) {
return convert_errno(errno);
}
@@ -3043,11 +2426,9 @@ wasi_addr_to_string(const __wasi_addr_t *addr, char *buf, size_t buflen)
}
__wasi_errno_t
-wasi_ssp_sock_bind(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct addr_pool *addr_pool,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr)
+wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct addr_pool *addr_pool, __wasi_fd_t fd,
+ __wasi_addr_t *addr)
{
char buf[48] = { 0 };
struct fd_object *fo;
@@ -3067,8 +2448,8 @@ wasi_ssp_sock_bind(
if (error != __WASI_ESUCCESS)
return error;
- ret = os_socket_bind(fd_number(fo), buf, &port);
- fd_object_release(fo);
+ ret = os_socket_bind(fo->file_handle, buf, &port);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3077,13 +2458,12 @@ wasi_ssp_sock_bind(
}
__wasi_errno_t
-wasi_ssp_sock_addr_resolve(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, char **ns_lookup_list,
-#endif
- const char *host, const char *service, __wasi_addr_info_hints_t *hints,
- __wasi_addr_info_t *addr_info, __wasi_size_t addr_info_size,
- __wasi_size_t *max_info_size)
+wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ char **ns_lookup_list, const char *host,
+ const char *service, __wasi_addr_info_hints_t *hints,
+ __wasi_addr_info_t *addr_info,
+ __wasi_size_t addr_info_size,
+ __wasi_size_t *max_info_size)
{
bh_addr_info_t *wamr_addr_info =
wasm_runtime_malloc(addr_info_size * sizeof(bh_addr_info_t));
@@ -3101,10 +2481,13 @@ wasi_ssp_sock_addr_resolve(
return __WASI_EACCES;
}
- int ret = os_socket_addr_resolve(
- host, service, hints->hints_enabled ? &hints_is_tcp : NULL,
- hints->hints_enabled ? &hints_is_ipv4 : NULL, wamr_addr_info,
- addr_info_size, &_max_info_size);
+ int ret = blocking_op_socket_addr_resolve(
+ exec_env, host, service,
+ hints->hints_enabled && hints->type != SOCKET_ANY ? &hints_is_tcp
+ : NULL,
+ hints->hints_enabled && hints->family != INET_UNSPEC ? &hints_is_ipv4
+ : NULL,
+ wamr_addr_info, addr_info_size, &_max_info_size);
if (ret != BHT_OK) {
wasm_runtime_free(wamr_addr_info);
@@ -3127,11 +2510,9 @@ wasi_ssp_sock_addr_resolve(
}
__wasi_errno_t
-wasi_ssp_sock_connect(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct addr_pool *addr_pool,
-#endif
- __wasi_fd_t fd, __wasi_addr_t *addr)
+wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct addr_pool *addr_pool, __wasi_fd_t fd,
+ __wasi_addr_t *addr)
{
char buf[48] = { 0 };
struct fd_object *fo;
@@ -3150,10 +2531,10 @@ wasi_ssp_sock_connect(
if (error != __WASI_ESUCCESS)
return error;
- ret = os_socket_connect(fd_number(fo), buf,
- addr->kind == IPv4 ? addr->addr.ip4.port
- : addr->addr.ip6.port);
- fd_object_release(fo);
+ ret = blocking_op_socket_connect(exec_env, fo->file_handle, buf,
+ addr->kind == IPv4 ? addr->addr.ip4.port
+ : addr->addr.ip6.port);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3162,127 +2543,97 @@ wasi_ssp_sock_connect(
}
__wasi_errno_t
-wasi_ssp_sock_get_recv_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t *size)
+wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t *size)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval;
- socklen_t optlen = sizeof(optval);
-
- ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_RCVBUF, &optval, &optlen);
- fd_object_release(fo);
+ size_t bufsize = 0;
+ int ret = os_socket_get_recv_buf_size(fo->file_handle, &bufsize);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
- *size = optval;
+ *size = (__wasi_size_t)bufsize;
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasi_ssp_sock_get_reuse_addr(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t *reuse)
+wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t *reuse)
{
-
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval;
- socklen_t optlen = sizeof(optval);
+ bool enabled = false;
- ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEADDR, &optval, &optlen);
- fd_object_release(fo);
+ int ret = os_socket_get_reuse_addr(fo->file_handle, &enabled);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
- *reuse = optval;
+ *reuse = (uint8_t)enabled;
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasi_ssp_sock_get_reuse_port(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t *reuse)
+wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t *reuse)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval;
- socklen_t optlen = sizeof(optval);
-
-#if defined(SO_REUSEPORT) /* NuttX doesn't have SO_REUSEPORT */
- ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEPORT, &optval, &optlen);
-#else
- errno = ENOTSUP;
- ret = BHT_ERROR;
- optval = 0;
-#endif /* defined(SO_REUSEPORT) */
+ bool enabled = false;
+ int ret = os_socket_get_reuse_port(fo->file_handle, &enabled);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
- *reuse = optval;
+ *reuse = (uint8_t)enabled;
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasi_ssp_sock_get_send_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t *size)
+wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t *size)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval;
- socklen_t optlen = sizeof(optval);
+ size_t bufsize = 0;
+ int ret = os_socket_get_send_buf_size(fo->file_handle, &bufsize);
- ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_SNDBUF, &optval, &optlen);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
- *size = optval;
+ *size = (__wasi_size_t)bufsize;
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasi_ssp_sock_listen(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t backlog)
+wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, __wasi_size_t backlog)
{
struct fd_object *fo;
int ret;
@@ -3291,8 +2642,8 @@ wasi_ssp_sock_listen(
if (error != __WASI_ESUCCESS)
return error;
- ret = os_socket_listen(fd_number(fo), backlog);
- fd_object_release(fo);
+ ret = os_socket_listen(fo->file_handle, backlog);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3301,19 +2652,16 @@ wasi_ssp_sock_listen(
}
__wasi_errno_t
-wasi_ssp_sock_open(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype,
- __wasi_fd_t *sockfd)
+wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t poolfd, __wasi_address_family_t af,
+ __wasi_sock_type_t socktype, __wasi_fd_t *sockfd)
{
bh_socket_t sock;
bool is_tcp = SOCKET_DGRAM == socktype ? false : true;
bool is_ipv4 = INET6 == af ? false : true;
int ret;
- __wasi_filetype_t wasi_type;
- __wasi_rights_t max_base, max_inheriting;
+ __wasi_filetype_t wasi_type = __WASI_FILETYPE_UNKNOWN;
+ __wasi_rights_t max_base = 0, max_inheriting = 0;
__wasi_errno_t error;
(void)poolfd;
@@ -3338,7 +2686,7 @@ wasi_ssp_sock_open(
}
// TODO: base rights and inheriting rights ?
- error = fd_table_insert_fd(curfds, sock, wasi_type, max_base,
+ error = fd_table_insert_fd(exec_env, curfds, sock, wasi_type, max_base,
max_inheriting, sockfd);
if (error != __WASI_ESUCCESS) {
return error;
@@ -3348,23 +2696,18 @@ wasi_ssp_sock_open(
}
__wasi_errno_t
-wasi_ssp_sock_set_recv_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t size)
+wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t size)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval = size;
+ int ret = os_socket_set_recv_buf_size(fo->file_handle, size);
- ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_RCVBUF, &optval,
- sizeof(optval));
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3373,23 +2716,17 @@ wasi_ssp_sock_set_recv_buf_size(
}
__wasi_errno_t
-wasi_ssp_sock_set_reuse_addr(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t reuse)
+wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t reuse)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval = reuse;
+ int ret = os_socket_set_reuse_addr(fo->file_handle, (bool)reuse);
- ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEADDR, &optval,
- sizeof(optval));
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3398,29 +2735,17 @@ wasi_ssp_sock_set_reuse_addr(
}
__wasi_errno_t
-wasi_ssp_sock_set_reuse_port(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, uint8_t reuse)
+wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t fd, uint8_t reuse)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval = reuse;
-
-#if defined(SO_REUSEPORT) /* NuttX doesn't have SO_REUSEPORT */
- ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEPORT, &optval,
- sizeof(optval));
-#else
- errno = ENOTSUP;
- ret = BHT_ERROR;
-#endif /* defined(SO_REUSEPORT) */
+ int ret = os_socket_set_reuse_port(fo->file_handle, (bool)reuse);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3429,24 +2754,18 @@ wasi_ssp_sock_set_reuse_port(
}
__wasi_errno_t
-wasi_ssp_sock_set_send_buf_size(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t fd, __wasi_size_t size)
+wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env,
+ struct fd_table *curfds, __wasi_fd_t fd,
+ __wasi_size_t size)
{
struct fd_object *fo;
- int ret;
__wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0);
if (error != __WASI_ESUCCESS)
return error;
- int optval = size;
-
- ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_SNDBUF, &optval,
- sizeof(optval));
+ int ret = os_socket_set_send_buf_size(fo->file_handle, size);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret) {
return convert_errno(errno);
}
@@ -3455,25 +2774,21 @@ wasi_ssp_sock_set_send_buf_size(
}
__wasi_errno_t
-wasmtime_ssp_sock_recv(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, void *buf, size_t buf_len, size_t *recv_len)
+wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, void *buf, size_t buf_len,
+ size_t *recv_len)
{
__wasi_addr_t src_addr;
- return wasmtime_ssp_sock_recv_from(curfds, sock, buf, buf_len, 0, &src_addr,
- recv_len);
+ return wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf, buf_len, 0,
+ &src_addr, recv_len);
}
__wasi_errno_t
-wasmtime_ssp_sock_recv_from(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, void *buf, size_t buf_len, __wasi_riflags_t ri_flags,
- __wasi_addr_t *src_addr, size_t *recv_len)
+wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, void *buf, size_t buf_len,
+ __wasi_riflags_t ri_flags, __wasi_addr_t *src_addr,
+ size_t *recv_len)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -3485,8 +2800,9 @@ wasmtime_ssp_sock_recv_from(
return error;
}
- ret = os_socket_recv_from(fd_number(fo), buf, buf_len, 0, &sockaddr);
- fd_object_release(fo);
+ ret = blocking_op_socket_recv_from(exec_env, fo->file_handle, buf, buf_len,
+ 0, &sockaddr);
+ fd_object_release(exec_env, fo);
if (-1 == ret) {
return convert_errno(errno);
}
@@ -3498,11 +2814,9 @@ wasmtime_ssp_sock_recv_from(
}
__wasi_errno_t
-wasmtime_ssp_sock_send(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, const void *buf, size_t buf_len, size_t *sent_len)
+wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, const void *buf, size_t buf_len,
+ size_t *sent_len)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -3513,8 +2827,8 @@ wasmtime_ssp_sock_send(
return error;
}
- ret = os_socket_send(fd_number(fo), buf, buf_len);
- fd_object_release(fo);
+ ret = os_socket_send(fo->file_handle, buf, buf_len);
+ fd_object_release(exec_env, fo);
if (-1 == ret) {
return convert_errno(errno);
}
@@ -3524,12 +2838,11 @@ wasmtime_ssp_sock_send(
}
__wasi_errno_t
-wasmtime_ssp_sock_send_to(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds, struct addr_pool *addr_pool,
-#endif
- __wasi_fd_t sock, const void *buf, size_t buf_len,
- __wasi_siflags_t si_flags, const __wasi_addr_t *dest_addr, size_t *sent_len)
+wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ struct addr_pool *addr_pool, __wasi_fd_t sock,
+ const void *buf, size_t buf_len,
+ __wasi_siflags_t si_flags,
+ const __wasi_addr_t *dest_addr, size_t *sent_len)
{
char addr_buf[48] = { 0 };
struct fd_object *fo;
@@ -3552,8 +2865,9 @@ wasmtime_ssp_sock_send_to(
wasi_addr_to_bh_sockaddr(dest_addr, &sockaddr);
- ret = os_socket_send_to(fd_number(fo), buf, buf_len, 0, &sockaddr);
- fd_object_release(fo);
+ ret = blocking_op_socket_send_to(exec_env, fo->file_handle, buf, buf_len, 0,
+ &sockaddr);
+ fd_object_release(exec_env, fo);
if (-1 == ret) {
return convert_errno(errno);
}
@@ -3563,42 +2877,37 @@ wasmtime_ssp_sock_send_to(
}
__wasi_errno_t
-wasmtime_ssp_sock_shutdown(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock)
+wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock)
{
struct fd_object *fo;
__wasi_errno_t error;
- int ret;
error = fd_object_get(curfds, &fo, sock, 0, 0);
if (error != 0)
return error;
- ret = os_socket_shutdown(fd_number(fo));
- fd_object_release(fo);
- if (BHT_OK != ret)
- return convert_errno(errno);
+ error = os_socket_shutdown(fo->file_handle);
+ fd_object_release(exec_env, fo);
- return __WASI_ESUCCESS;
+ return error;
}
__wasi_errno_t
wasmtime_ssp_sched_yield(void)
{
+#ifdef BH_PLATFORM_WINDOWS
+ SwitchToThread();
+#else
if (sched_yield() < 0)
return convert_errno(errno);
+#endif
return 0;
}
__wasi_errno_t
-wasmtime_ssp_args_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *argv_environ,
-#endif
- char **argv, char *argv_buf)
+wasmtime_ssp_args_get(struct argv_environ_values *argv_environ, char **argv,
+ char *argv_buf)
{
for (size_t i = 0; i < argv_environ->argc; ++i) {
argv[i] =
@@ -3611,11 +2920,8 @@ wasmtime_ssp_args_get(
}
__wasi_errno_t
-wasmtime_ssp_args_sizes_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *argv_environ,
-#endif
- size_t *argc, size_t *argv_buf_size)
+wasmtime_ssp_args_sizes_get(struct argv_environ_values *argv_environ,
+ size_t *argc, size_t *argv_buf_size)
{
*argc = argv_environ->argc;
*argv_buf_size = argv_environ->argv_buf_size;
@@ -3623,18 +2929,15 @@ wasmtime_ssp_args_sizes_get(
}
__wasi_errno_t
-wasmtime_ssp_environ_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *argv_environ,
-#endif
- char **environ, char *environ_buf)
+wasmtime_ssp_environ_get(struct argv_environ_values *argv_environ,
+ char **environs, char *environ_buf)
{
for (size_t i = 0; i < argv_environ->environ_count; ++i) {
- environ[i] =
+ environs[i] =
environ_buf
+ (argv_environ->environ_list[i] - argv_environ->environ_buf);
}
- environ[argv_environ->environ_count] = NULL;
+ environs[argv_environ->environ_count] = NULL;
bh_memcpy_s(environ_buf, (uint32)argv_environ->environ_buf_size,
argv_environ->environ_buf,
(uint32)argv_environ->environ_buf_size);
@@ -3642,11 +2945,8 @@ wasmtime_ssp_environ_get(
}
__wasi_errno_t
-wasmtime_ssp_environ_sizes_get(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct argv_environ_values *argv_environ,
-#endif
- size_t *environ_count, size_t *environ_buf_size)
+wasmtime_ssp_environ_sizes_get(struct argv_environ_values *argv_environ,
+ size_t *environ_count, size_t *environ_buf_size)
{
*environ_count = argv_environ->environ_count;
*environ_buf_size = argv_environ->environ_buf_size;
@@ -3682,7 +2982,7 @@ fd_table_destroy(struct fd_table *ft)
if (ft->entries) {
for (uint32 i = 0; i < ft->size; i++) {
if (ft->entries[i].object != NULL) {
- fd_object_release(ft->entries[i].object);
+ fd_object_release(NULL, ft->entries[i].object);
}
}
rwlock_destroy(&ft->lock);
@@ -3753,12 +3053,6 @@ addr_pool_insert(struct addr_pool *addr_pool, const char *addr, uint8 mask)
return true;
}
-static inline size_t
-min(size_t a, size_t b)
-{
- return a > b ? b : a;
-}
-
static void
init_address_mask(uint8_t *buf, size_t buflen, size_t mask)
{
@@ -3871,16 +3165,13 @@ addr_pool_destroy(struct addr_pool *addr_pool)
}
}
-#ifndef WASMTIME_SSP_STATIC_CURFDS
#define WASMTIME_SSP_PASSTHROUGH_FD_TABLE struct fd_table *curfds,
-#else
-#define WASMTIME_SSP_PASSTHROUGH_FD_TABLE
-#endif
// Defines a function that passes through the socket option to the OS
// implementation
#define WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(FUNC_NAME, OPTION_TYPE) \
__wasi_errno_t wasmtime_ssp_sock_##FUNC_NAME( \
+ wasm_exec_env_t exec_env, \
WASMTIME_SSP_PASSTHROUGH_FD_TABLE __wasi_fd_t sock, \
OPTION_TYPE option) \
{ \
@@ -3890,8 +3181,8 @@ addr_pool_destroy(struct addr_pool *addr_pool)
error = fd_object_get(curfds, &fo, sock, 0, 0); \
if (error != 0) \
return error; \
- ret = os_socket_##FUNC_NAME(fd_number(fo), option); \
- fd_object_release(fo); \
+ ret = os_socket_##FUNC_NAME(fo->file_handle, option); \
+ fd_object_release(exec_env, fo); \
if (BHT_OK != ret) \
return convert_errno(errno); \
return __WASI_ESUCCESS; \
@@ -3934,11 +3225,8 @@ WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(get_ipv6_only, bool *)
#undef WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION
__wasi_errno_t
-wasmtime_ssp_sock_set_linger(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, bool is_enabled, int linger_s)
+wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, bool is_enabled, int linger_s)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -3947,19 +3235,16 @@ wasmtime_ssp_sock_set_linger(
if (error != 0)
return error;
- ret = os_socket_set_linger(fd_number(fo), is_enabled, linger_s);
- fd_object_release(fo);
+ ret = os_socket_set_linger(fo->file_handle, is_enabled, linger_s);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret)
return convert_errno(errno);
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasmtime_ssp_sock_get_linger(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, bool *is_enabled, int *linger_s)
+wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds,
+ __wasi_fd_t sock, bool *is_enabled, int *linger_s)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -3968,8 +3253,8 @@ wasmtime_ssp_sock_get_linger(
if (error != 0)
return error;
- ret = os_socket_get_linger(fd_number(fo), is_enabled, linger_s);
- fd_object_release(fo);
+ ret = os_socket_get_linger(fo->file_handle, is_enabled, linger_s);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret)
return convert_errno(errno);
@@ -3977,11 +3262,11 @@ wasmtime_ssp_sock_get_linger(
}
__wasi_errno_t
-wasmtime_ssp_sock_set_ip_add_membership(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface)
+wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock,
+ __wasi_addr_ip_t *imr_multiaddr,
+ uint32_t imr_interface)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -3994,20 +3279,20 @@ wasmtime_ssp_sock_set_ip_add_membership(
wasi_addr_ip_to_bh_ip_addr_buffer(imr_multiaddr, &addr_info);
is_ipv6 = imr_multiaddr->kind == IPv6;
- ret = os_socket_set_ip_add_membership(fd_number(fo), &addr_info,
+ ret = os_socket_set_ip_add_membership(fo->file_handle, &addr_info,
imr_interface, is_ipv6);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret)
return convert_errno(errno);
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasmtime_ssp_sock_set_ip_drop_membership(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface)
+wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock,
+ __wasi_addr_ip_t *imr_multiaddr,
+ uint32_t imr_interface)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -4020,20 +3305,19 @@ wasmtime_ssp_sock_set_ip_drop_membership(
wasi_addr_ip_to_bh_ip_addr_buffer(imr_multiaddr, &addr_info);
is_ipv6 = imr_multiaddr->kind == IPv6;
- ret = os_socket_set_ip_drop_membership(fd_number(fo), &addr_info,
+ ret = os_socket_set_ip_drop_membership(fo->file_handle, &addr_info,
imr_interface, is_ipv6);
- fd_object_release(fo);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret)
return convert_errno(errno);
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasmtime_ssp_sock_set_ip_multicast_loop(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, bool ipv6, bool is_enabled)
+wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, bool ipv6,
+ bool is_enabled)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -4042,19 +3326,18 @@ wasmtime_ssp_sock_set_ip_multicast_loop(
if (error != 0)
return error;
- ret = os_socket_set_ip_multicast_loop(fd_number(fo), ipv6, is_enabled);
- fd_object_release(fo);
+ ret = os_socket_set_ip_multicast_loop(fo->file_handle, ipv6, is_enabled);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret)
return convert_errno(errno);
return __WASI_ESUCCESS;
}
__wasi_errno_t
-wasmtime_ssp_sock_get_ip_multicast_loop(
-#if !defined(WASMTIME_SSP_STATIC_CURFDS)
- struct fd_table *curfds,
-#endif
- __wasi_fd_t sock, bool ipv6, bool *is_enabled)
+wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env,
+ struct fd_table *curfds,
+ __wasi_fd_t sock, bool ipv6,
+ bool *is_enabled)
{
struct fd_object *fo;
__wasi_errno_t error;
@@ -4063,8 +3346,8 @@ wasmtime_ssp_sock_get_ip_multicast_loop(
if (error != 0)
return error;
- ret = os_socket_get_ip_multicast_loop(fd_number(fo), ipv6, is_enabled);
- fd_object_release(fo);
+ ret = os_socket_get_ip_multicast_loop(fo->file_handle, ipv6, is_enabled);
+ fd_object_release(exec_env, fo);
if (BHT_OK != ret)
return convert_errno(errno);
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h
index 7a593390a30..75ed5978462 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h
@@ -60,7 +60,8 @@ struct addr_pool {
bool
fd_table_init(struct fd_table *);
bool
-fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
+fd_table_insert_existing(struct fd_table *, __wasi_fd_t, os_file_handle,
+ bool is_stdio);
bool
fd_prestats_init(struct fd_prestats *);
bool
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c
similarity index 52%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c
index 01a1dab3a6a..29c50dd870d 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c
@@ -13,14 +13,16 @@
#include "ssp_config.h"
#include "bh_platform.h"
+#include "libc_errno.h"
#include "random.h"
#if CONFIG_HAS_ARC4RANDOM_BUF
-void
+__wasi_errno_t
random_buf(void *buf, size_t len)
{
arc4random_buf(buf, len);
+ return __WASI_ESUCCESS;
}
#elif CONFIG_HAS_GETRANDOM
@@ -29,7 +31,7 @@ random_buf(void *buf, size_t len)
#include
#endif
-void
+__wasi_errno_t
random_buf(void *buf, size_t len)
{
for (;;) {
@@ -37,40 +39,71 @@ random_buf(void *buf, size_t len)
if (x < 0) {
if (errno == EINTR)
continue;
- os_printf("getrandom failed: %s", strerror(errno));
- abort();
+ return convert_errno(errno);
}
if ((size_t)x == len)
- return;
+ break;
buf = (void *)((unsigned char *)buf + x);
len -= (size_t)x;
}
+ return __WASI_ESUCCESS;
+}
+
+#elif defined(BH_PLATFORM_WINDOWS)
+
+#include
+#pragma comment(lib, "Bcrypt.lib")
+
+__wasi_errno_t
+random_buf(void *buf, size_t len)
+{
+ NTSTATUS ret =
+ BCryptGenRandom(NULL, buf, (ULONG)len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
+
+ // Since we pass NULL for the algorithm handle, the only way BCryptGenRandom
+ // can fail is if one of the parameters is invalid
+ // (STATUS_INVALID_PARAMETER).
+ return ret ? __WASI_EINVAL : __WASI_ESUCCESS;
}
#else
-static int urandom;
+static int urandom = -1;
+static __wasi_errno_t urandom_error = __WASI_ESUCCESS;
static void
open_urandom(void)
{
urandom = open("/dev/urandom", O_RDONLY);
- if (urandom < 0) {
- os_printf("Failed to open /dev/urandom\n");
- abort();
- }
+ if (urandom < 0)
+ urandom_error = convert_errno(errno);
}
-void
+__wasi_errno_t
random_buf(void *buf, size_t len)
{
static pthread_once_t open_once = PTHREAD_ONCE_INIT;
- pthread_once(&open_once, open_urandom);
+ int pthread_ret = pthread_once(&open_once, open_urandom);
+
+ if (pthread_ret != 0)
+ return convert_errno(pthread_ret);
- if ((size_t)read(urandom, buf, len) != len) {
- os_printf("Short read on /dev/urandom\n");
- abort();
+ if (urandom < 0)
+ return urandom_error;
+
+ size_t bytes_read = 0;
+
+ while (bytes_read < len) {
+ ssize_t bytes_read_now =
+ read(urandom, buf + bytes_read, len - bytes_read);
+
+ if (bytes_read_now < 0)
+ return convert_errno(errno);
+
+ bytes_read += (size_t)bytes_read_now;
}
+
+ return __WASI_ESUCCESS;
}
#endif
@@ -82,8 +115,8 @@ random_buf(void *buf, size_t len)
// arc4random() until it lies within the range [2^k % upper, 2^k). As
// this range has length k * upper, we can safely obtain a number
// without any modulo bias.
-uintmax_t
-random_uniform(uintmax_t upper)
+__wasi_errno_t
+random_uniform(uintmax_t upper, uintmax_t *out)
{
// Compute 2^k % upper
// == (2^k - upper) % upper
@@ -91,8 +124,14 @@ random_uniform(uintmax_t upper)
uintmax_t lower = -upper % upper;
for (;;) {
uintmax_t value;
- random_buf(&value, sizeof(value));
- if (value >= lower)
- return value % upper;
+ __wasi_errno_t error = random_buf(&value, sizeof(value));
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
+ if (value >= lower) {
+ *out = value % upper;
+ return error;
+ }
}
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h
similarity index 84%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h
index 23c2da4dbd6..7cd94d74dbd 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h
@@ -14,8 +14,12 @@
#ifndef RANDOM_H
#define RANDOM_H
-void
+#include "bh_platform.h"
+
+__wasi_errno_t
random_buf(void *, size_t);
-uintmax_t random_uniform(uintmax_t);
+
+__wasi_errno_t
+random_uniform(uintmax_t upper, uintmax_t *out);
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h
similarity index 68%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h
index 7f6e9b94192..bcc750c2621 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h
@@ -14,8 +14,8 @@
#ifndef SSP_CONFIG_H
#define SSP_CONFIG_H
+#include "bh_platform.h"
#include "gnuc.h"
-#include
#if defined(__FreeBSD__) || defined(__APPLE__) \
|| (defined(ANDROID) && __ANDROID_API__ < 28)
@@ -26,8 +26,8 @@
// On Linux, prefer to use getrandom, though it isn't available in
// GLIBC before 2.25.
-#if (defined(__linux__) || defined(ESP_PLATFORM)) \
- && (!defined(__GLIBC__) || __GLIBC__ > 2 \
+#if (defined(__linux__) || defined(ESP_PLATFORM) || defined(__COSMOPOLITAN__)) \
+ && (!defined(__GLIBC__) || __GLIBC__ > 2 \
|| (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
#define CONFIG_HAS_GETRANDOM 1
#else
@@ -47,66 +47,19 @@
#define CONFIG_HAS_CLOCK_NANOSLEEP 0
#endif
-#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(ESP_PLATFORM)
-#define CONFIG_HAS_FDATASYNC 1
-#else
-#define CONFIG_HAS_FDATASYNC 0
-#endif
-
-/*
- * For NuttX, CONFIG_HAS_ISATTY is provided by its platform header.
- * (platform_internal.h)
- */
-#ifndef __NuttX__
-#ifndef __CloudABI__
-#define CONFIG_HAS_ISATTY 1
-#else
-#define CONFIG_HAS_ISATTY 0
-#endif
-#endif
-
-#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
-#define CONFIG_HAS_POSIX_FALLOCATE 1
-#else
-#define CONFIG_HAS_POSIX_FALLOCATE 0
-#endif
-
-#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
-#define CONFIG_HAS_PREADV 1
-#else
-#define CONFIG_HAS_PREADV 0
-#endif
-
#if defined(__APPLE__) || defined(__CloudABI__)
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1
#else
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0
#endif
-#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX)
+#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) && !defined(_WIN32) \
+ && !defined(__COSMOPOLITAN__)
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
#else
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0
#endif
-#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
-#define CONFIG_HAS_PWRITEV 1
-#else
-#define CONFIG_HAS_PWRITEV 0
-#endif
-
-#ifdef __APPLE__
-#define st_atim st_atimespec
-#define st_ctim st_ctimespec
-#define st_mtim st_mtimespec
-#endif
-
-#ifdef __APPLE__
-#define CONFIG_TLS_USE_GSBASE 1
-#else
-#define CONFIG_TLS_USE_GSBASE 0
-#endif
-
#if !defined(BH_PLATFORM_LINUX_SGX)
/* Clang's __GNUC_PREREQ macro has a different meaning than GCC one,
so we have to handle this case specially */
@@ -134,10 +87,4 @@ not implemented until 4.9. See
#define CONFIG_HAS_STD_ATOMIC 0
#endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */
-#if !defined(__NuttX__)
-#define CONFIG_HAS_D_INO 1
-#else
-#define CONFIG_HAS_D_INO 0
-#endif
-
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.c
similarity index 87%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.c
index 9303eb3f5e2..dbf002468ba 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.c
@@ -16,10 +16,6 @@
#include "debug_engine.h"
#endif
-#if WASM_ENABLE_SHARED_MEMORY != 0
-#include "wasm_shared_memory.h"
-#endif
-
typedef struct {
bh_list_link l;
void (*destroy_cb)(WASMCluster *);
@@ -32,6 +28,8 @@ static bh_list cluster_list_head;
static bh_list *const cluster_list = &cluster_list_head;
static korp_mutex cluster_list_lock;
+static korp_mutex _exception_lock;
+
typedef void (*list_visitor)(void *, void *);
static uint32 cluster_max_thread_num = CLUSTER_MAX_THREAD_NUM;
@@ -52,6 +50,10 @@ thread_manager_init()
return false;
if (os_mutex_init(&cluster_list_lock) != 0)
return false;
+ if (os_mutex_init(&_exception_lock) != 0) {
+ os_mutex_destroy(&cluster_list_lock);
+ return false;
+ }
return true;
}
@@ -66,6 +68,7 @@ thread_manager_destroy()
cluster = next;
}
wasm_cluster_cancel_all_callbacks();
+ os_mutex_destroy(&_exception_lock);
os_mutex_destroy(&cluster_list_lock);
}
@@ -477,9 +480,6 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasm_module_t module;
wasm_module_inst_t new_module_inst;
-#if WASM_ENABLE_LIBC_WASI != 0
- WASIContext *wasi_ctx;
-#endif
WASMExecEnv *new_exec_env;
uint32 aux_stack_start, aux_stack_size;
uint32 stack_size = 8192;
@@ -509,7 +509,7 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
#endif
if (!(new_module_inst = wasm_runtime_instantiate_internal(
- module, true, exec_env, stack_size, 0, NULL, 0))) {
+ module, module_inst, exec_env, stack_size, 0, NULL, 0))) {
goto fail1;
}
@@ -517,10 +517,7 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_runtime_set_custom_data_internal(
new_module_inst, wasm_runtime_get_custom_data(module_inst));
-#if WASM_ENABLE_LIBC_WASI != 0
- wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst);
- wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
-#endif
+ wasm_native_inherit_contexts(new_module_inst, module_inst);
new_exec_env = wasm_exec_env_create_internal(new_module_inst,
exec_env->wasm_stack_size);
@@ -606,7 +603,8 @@ thread_manager_start_routine(void *arg)
#ifdef OS_ENABLE_HW_BOUND_CHECK
os_mutex_lock(&exec_env->wait_lock);
- if (exec_env->suspend_flags.flags & 0x08)
+ if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags)
+ & WASM_SUSPEND_FLAG_EXIT)
ret = exec_env->thread_ret_value;
os_mutex_unlock(&exec_env->wait_lock);
#endif
@@ -745,10 +743,10 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
#if WASM_ENABLE_INTERP != 0
if (module_inst_src->module_type == Wasm_Module_Bytecode) {
- new_c_api_func_imports =
- &(((WASMModuleInstance *)module_inst_dst)->e->c_api_func_imports);
+ new_c_api_func_imports = &(((WASMModuleInstance *)module_inst_dst)
+ ->e->common.c_api_func_imports);
c_api_func_imports = ((const WASMModuleInstance *)module_inst_src)
- ->e->c_api_func_imports;
+ ->e->common.c_api_func_imports;
import_func_count =
((WASMModule *)(((const WASMModuleInstance *)module_inst_src)
->module))
@@ -759,10 +757,10 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
if (module_inst_src->module_type == Wasm_Module_AoT) {
AOTModuleInstanceExtra *e =
(AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_dst)->e;
- new_c_api_func_imports = &(e->c_api_func_imports);
+ new_c_api_func_imports = &(e->common.c_api_func_imports);
e = (AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_src)->e;
- c_api_func_imports = e->c_api_func_imports;
+ c_api_func_imports = e->common.c_api_func_imports;
import_func_count =
((AOTModule *)(((AOTModuleInstance *)module_inst_src)->module))
@@ -993,7 +991,9 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval)
if (exec_env->jmpbuf_stack_top) {
/* Store the return value in exec_env */
exec_env->thread_ret_value = retval;
- exec_env->suspend_flags.flags |= 0x08;
+
+ WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags,
+ WASM_SUSPEND_FLAG_EXIT);
#ifndef BH_PLATFORM_WINDOWS
/* Pop all jmpbuf_node except the last one */
@@ -1055,8 +1055,22 @@ set_thread_cancel_flags(WASMExecEnv *exec_env)
#if WASM_ENABLE_DEBUG_INTERP != 0
wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TERM);
#endif
- exec_env->suspend_flags.flags |= 0x01;
+ WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags,
+ WASM_SUSPEND_FLAG_TERMINATE);
+
+ os_mutex_unlock(&exec_env->wait_lock);
+
+#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP
+ wasm_runtime_interrupt_blocking_op(exec_env);
+#endif
+}
+static void
+clear_thread_cancel_flags(WASMExecEnv *exec_env)
+{
+ os_mutex_lock(&exec_env->wait_lock);
+ WASM_SUSPEND_FLAGS_FETCH_AND(exec_env->suspend_flags,
+ ~WASM_SUSPEND_FLAG_TERMINATE);
os_mutex_unlock(&exec_env->wait_lock);
}
@@ -1178,7 +1192,8 @@ void
wasm_cluster_suspend_thread(WASMExecEnv *exec_env)
{
/* Set the suspend flag */
- exec_env->suspend_flags.flags |= 0x02;
+ WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags,
+ WASM_SUSPEND_FLAG_SUSPEND);
}
static void
@@ -1214,7 +1229,8 @@ wasm_cluster_suspend_all_except_self(WASMCluster *cluster,
void
wasm_cluster_resume_thread(WASMExecEnv *exec_env)
{
- exec_env->suspend_flags.flags &= ~0x02;
+ WASM_SUSPEND_FLAGS_FETCH_AND(exec_env->suspend_flags,
+ ~WASM_SUSPEND_FLAG_SUSPEND);
os_cond_signal(&exec_env->wait_cond);
}
@@ -1234,76 +1250,55 @@ wasm_cluster_resume_all(WASMCluster *cluster)
os_mutex_unlock(&cluster->lock);
}
+struct spread_exception_data {
+ WASMExecEnv *skip;
+ const char *exception;
+};
+
static void
set_exception_visitor(void *node, void *user_data)
{
- WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
- WASMExecEnv *exec_env = (WASMExecEnv *)user_data;
- WASMModuleInstanceCommon *module_inst = get_module_inst(exec_env);
- WASMModuleInstance *wasm_inst = (WASMModuleInstance *)module_inst;
-
- if (curr_exec_env != exec_env) {
- WASMModuleInstance *curr_wasm_inst =
- (WASMModuleInstance *)get_module_inst(curr_exec_env);
-
- /* Only spread non "wasi proc exit" exception */
-#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *shared_mem_node = wasm_module_get_shared_memory(
- (WASMModuleCommon *)curr_wasm_inst->module);
- if (shared_mem_node)
- os_mutex_lock(&shared_mem_node->shared_mem_lock);
-#endif
- if (!strstr(wasm_inst->cur_exception, "wasi proc exit")) {
- bh_memcpy_s(curr_wasm_inst->cur_exception,
- sizeof(curr_wasm_inst->cur_exception),
- wasm_inst->cur_exception,
- sizeof(wasm_inst->cur_exception));
- }
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (shared_mem_node)
- os_mutex_unlock(&shared_mem_node->shared_mem_lock);
-#endif
+ const struct spread_exception_data *data = user_data;
+ WASMExecEnv *exec_env = (WASMExecEnv *)node;
- /* Terminate the thread so it can exit from dead loops */
- set_thread_cancel_flags(curr_exec_env);
- }
-}
+ if (exec_env != data->skip) {
+ WASMModuleInstance *wasm_inst =
+ (WASMModuleInstance *)get_module_inst(exec_env);
-static void
-clear_exception_visitor(void *node, void *user_data)
-{
- WASMExecEnv *exec_env = (WASMExecEnv *)user_data;
- WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
-
- if (curr_exec_env != exec_env) {
- WASMModuleInstance *curr_wasm_inst =
- (WASMModuleInstance *)get_module_inst(curr_exec_env);
+ exception_lock(wasm_inst);
+ if (data->exception != NULL) {
+ snprintf(wasm_inst->cur_exception, sizeof(wasm_inst->cur_exception),
+ "Exception: %s", data->exception);
+ }
+ else {
+ wasm_inst->cur_exception[0] = '\0';
+ }
+ exception_unlock(wasm_inst);
-#if WASM_ENABLE_SHARED_MEMORY != 0
- WASMSharedMemNode *shared_mem_node = wasm_module_get_shared_memory(
- (WASMModuleCommon *)curr_wasm_inst->module);
- if (shared_mem_node)
- os_mutex_lock(&shared_mem_node->shared_mem_lock);
-#endif
- curr_wasm_inst->cur_exception[0] = '\0';
-#if WASM_ENABLE_SHARED_MEMORY != 0
- if (shared_mem_node)
- os_mutex_unlock(&shared_mem_node->shared_mem_lock);
-#endif
+ /* Terminate the thread so it can exit from dead loops */
+ if (data->exception != NULL) {
+ set_thread_cancel_flags(exec_env);
+ }
+ else {
+ clear_thread_cancel_flags(exec_env);
+ }
}
}
void
-wasm_cluster_spread_exception(WASMExecEnv *exec_env, bool clear)
+wasm_cluster_set_exception(WASMExecEnv *exec_env, const char *exception)
{
+ const bool has_exception = exception != NULL;
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
bh_assert(cluster);
+ struct spread_exception_data data;
+ data.skip = NULL;
+ data.exception = exception;
+
os_mutex_lock(&cluster->lock);
- cluster->has_exception = !clear;
- traverse_list(&cluster->exec_env_list,
- clear ? clear_exception_visitor : set_exception_visitor,
- exec_env);
+ cluster->has_exception = has_exception;
+ traverse_list(&cluster->exec_env_list, set_exception_visitor, &data);
os_mutex_unlock(&cluster->lock);
}
@@ -1339,13 +1334,91 @@ wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
}
}
+#if WASM_ENABLE_MODULE_INST_CONTEXT != 0
+struct inst_set_context_data {
+ void *key;
+ void *ctx;
+};
+
+static void
+set_context_visitor(void *node, void *user_data)
+{
+ WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
+ WASMModuleInstanceCommon *module_inst = get_module_inst(curr_exec_env);
+ const struct inst_set_context_data *data = user_data;
+
+ wasm_runtime_set_context(module_inst, data->key, data->ctx);
+}
+
+void
+wasm_cluster_set_context(WASMModuleInstanceCommon *module_inst, void *key,
+ void *ctx)
+{
+ WASMExecEnv *exec_env = wasm_clusters_search_exec_env(module_inst);
+
+ if (exec_env == NULL) {
+ /* Maybe threads have not been started yet. */
+ wasm_runtime_set_context(module_inst, key, ctx);
+ }
+ else {
+ WASMCluster *cluster;
+ struct inst_set_context_data data;
+ data.key = key;
+ data.ctx = ctx;
+
+ cluster = wasm_exec_env_get_cluster(exec_env);
+ bh_assert(cluster);
+
+ os_mutex_lock(&cluster->lock);
+ traverse_list(&cluster->exec_env_list, set_context_visitor, &data);
+ os_mutex_unlock(&cluster->lock);
+ }
+}
+#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
+
bool
wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env)
{
os_mutex_lock(&exec_env->wait_lock);
- bool is_thread_terminated =
- (exec_env->suspend_flags.flags & 0x01) ? true : false;
+ bool is_thread_terminated = (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags)
+ & WASM_SUSPEND_FLAG_TERMINATE)
+ ? true
+ : false;
os_mutex_unlock(&exec_env->wait_lock);
return is_thread_terminated;
}
+
+void
+exception_lock(WASMModuleInstance *module_inst)
+{
+ /*
+ * Note: this lock could be per module instance if desirable.
+ * We can revisit on AOT version bump.
+ * It probably doesn't matter though because the exception handling
+ * logic should not be executed too frequently anyway.
+ */
+ os_mutex_lock(&_exception_lock);
+}
+
+void
+exception_unlock(WASMModuleInstance *module_inst)
+{
+ os_mutex_unlock(&_exception_lock);
+}
+
+void
+wasm_cluster_traverse_lock(WASMExecEnv *exec_env)
+{
+ WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
+ bh_assert(cluster);
+ os_mutex_lock(&cluster->lock);
+}
+
+void
+wasm_cluster_traverse_unlock(WASMExecEnv *exec_env)
+{
+ WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
+ bh_assert(cluster);
+ os_mutex_unlock(&cluster->lock);
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.h
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.h
index 2060869c280..b95f434ae0d 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.h
@@ -139,7 +139,7 @@ WASMExecEnv *
wasm_clusters_search_exec_env(WASMModuleInstanceCommon *module_inst);
void
-wasm_cluster_spread_exception(WASMExecEnv *exec_env, bool clear);
+wasm_cluster_set_exception(WASMExecEnv *exec_env, const char *exception);
WASMExecEnv *
wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env);
@@ -151,6 +151,10 @@ void
wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
void *custom_data);
+void
+wasm_cluster_set_context(WASMModuleInstanceCommon *module_inst, void *key,
+ void *ctx);
+
bool
wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env);
@@ -211,6 +215,12 @@ wasm_cluster_set_debug_inst(WASMCluster *cluster, WASMDebugInstance *inst);
#endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */
+void
+wasm_cluster_traverse_lock(WASMExecEnv *exec_env);
+
+void
+wasm_cluster_traverse_unlock(WASMExecEnv *exec_env);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_mgr.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_mgr.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_mgr.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore
new file mode 100644
index 00000000000..81c0ff6aaa1
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore
@@ -0,0 +1,2 @@
+**/*.wasm
+**/*.tflite
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/README.md
similarity index 59%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/README.md
index ac737c28115..fbc99ccbb27 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/README.md
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/README.md
@@ -25,6 +25,7 @@ Build the runtime image for your execution target type.
* `cpu`
* `nvidia-gpu`
* `vx-delegate`
+* `tpu`
```
EXECUTION_TYPE=cpu
@@ -55,42 +56,59 @@ Tests: passed!
```
docker run \
- -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets wasi-nn-cpu \
- --dir=/assets \
+ -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
+ -v $PWD/core/iwasm/libraries/wasi-nn/test/models:/models \
+ wasi-nn-cpu \
+ --dir=/ \
--env="TARGET=cpu" \
/assets/test_tensorflow.wasm
```
* (NVIDIA) GPU
+ * Requirements:
+ * [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker).
```
docker run \
--runtime=nvidia \
- -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets wasi-nn-nvidia-gpu \
- --dir=/assets \
+ -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
+ -v $PWD/core/iwasm/libraries/wasi-nn/test/models:/models \
+ wasi-nn-nvidia-gpu \
+ --dir=/ \
--env="TARGET=gpu" \
/assets/test_tensorflow.wasm
```
-* vx-delegate for NPU (x86 simulater)
+* vx-delegate for NPU (x86 simulator)
```
docker run \
- -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets wasi-nn-vx-delegate \
- --dir=/assets \
+ -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
+ wasi-nn-vx-delegate \
+ --dir=/ \
--env="TARGET=gpu" \
- /assets/test_tensorflow.wasm
+ /assets/test_tensorflow_quantized.wasm
```
+* (Coral) TPU
+ * Requirements:
+ * [Coral USB](https://coral.ai/products/accelerator/).
-
-Requirements:
-* [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker).
+```
+docker run \
+ --privileged \
+ --device=/dev/bus/usb:/dev/bus/usb \
+ -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \
+ wasi-nn-tpu \
+ --dir=/ \
+ --env="TARGET=tpu" \
+ /assets/test_tensorflow_quantized.wasm
+```
## What is missing
Supported:
* Graph encoding: `tensorflowlite`.
-* Execution target: `cpu` and `gpu`.
+* Execution target: `cpu`, `gpu` and `tpu`.
* Tensor type: `fp32`.
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake
new file mode 100644
index 00000000000..59fdaf758bf
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake
@@ -0,0 +1,42 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+
+find_library(TENSORFLOW_LITE
+ NAMES tensorflow-lite
+)
+
+if(NOT EXISTS ${TENSORFLOW_LITE})
+ if(NOT EXISTS "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
+ execute_process(
+ COMMAND "${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh"
+ RESULT_VARIABLE TENSORFLOW_RESULT
+ )
+ else()
+ message("Tensorflow is already downloaded.")
+ endif()
+
+ set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
+
+ if(WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1)
+ # Tensorflow specific:
+ # * https://www.tensorflow.org/lite/guide/build_cmake#available_options_to_build_tensorflow_lite
+ set (TFLITE_ENABLE_GPU ON)
+ endif()
+
+ if (CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set (TFLITE_ENABLE_XNNPACK OFF)
+ endif()
+
+ add_subdirectory(
+ "${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
+ "${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite"
+ EXCLUDE_FROM_ALL
+ )
+
+ set(TENSORFLOW_LITE_INCLUDE_DIR "${TENSORFLOW_SOURCE_DIR}")
+ set(FLATBUFFER_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include")
+
+ include_directories(${TENSORFLOW_LITE_INCLUDE_DIR})
+ include_directories(${FLATBUFFER_INCLUDE_DIR})
+endif()
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake
new file mode 100644
index 00000000000..670988e1d8d
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake
@@ -0,0 +1,46 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+if (NOT DEFINED WAMR_BUILD_PLATFORM)
+ string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
+endif ()
+
+set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
+set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
+
+set (CMAKE_C_STANDARD 99)
+
+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)
+ set (WAMR_BUILD_TARGET "X86_64")
+ elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set (WAMR_BUILD_TARGET "X86_32")
+ else ()
+ message(SEND_ERROR "Unsupported build target platform!")
+ endif ()
+endif ()
+
+set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter")
+
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
+
+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 ()
+
+set (WAMR_BUILD_INTERP 1)
+set (WAMR_BUILD_AOT 1)
+set (WAMR_BUILD_JIT 0)
+set (WAMR_BUILD_LIBC_WASI 1)
+set (WAMR_BUILD_FAST_INTERP 1)
+
+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")
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake
new file mode 100644
index 00000000000..48af9babf72
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake
@@ -0,0 +1,22 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
+
+# Find tensorflow-lite
+find_package(tensorflow_lite REQUIRED)
+
+set(WASI_NN_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
+
+include_directories (${WASI_NN_ROOT_DIR}/include)
+include_directories (${WASI_NN_ROOT_DIR}/src)
+include_directories (${WASI_NN_ROOT_DIR}/src/utils)
+
+set (
+ WASI_NN_SOURCES
+ ${WASI_NN_ROOT_DIR}/src/wasi_nn.c
+ ${WASI_NN_ROOT_DIR}/src/wasi_nn_tensorflowlite.cpp
+ ${WASI_NN_ROOT_DIR}/src/utils/wasi_nn_app_native.c
+)
+
+set (WASI_NN_LIBS tensorflow-lite)
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt
new file mode 100644
index 00000000000..4157e194c84
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt
@@ -0,0 +1,58 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+cmake_minimum_required(VERSION 3.16)
+project(wasi-nn C CXX)
+
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../..)
+set(WASI_NN_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
+
+if(NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE Debug)
+endif()
+
+#### libvmlib ####
+# NOTE: we build vmlib as a shared library here so that it can be
+# shared between iwasm and native libraries.
+include(${WASI_NN_ROOT_DIR}/cmake/iwasm_helper.cmake)
+include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
+
+add_library(vmlib SHARED ${WAMR_RUNTIME_LIB_SOURCE})
+
+# iwasm
+include(${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
+set(RUNTIME_SOURCE_ALL
+ ${WAMR_ROOT_DIR}/product-mini/platforms/${WAMR_BUILD_PLATFORM}/main.c
+ ${UNCOMMON_SHARED_SOURCE}
+)
+
+add_executable(iwasm ${RUNTIME_SOURCE_ALL})
+target_link_libraries(iwasm vmlib -lpthread -lm -ldl)
+
+#### TensorFlow ####
+
+include(${WASI_NN_ROOT_DIR}/cmake/wasi_nn.cmake)
+
+#### WASI-NN ####
+
+include_directories(
+ ${WAMR_ROOT_DIR}/core/iwasm/include
+ ${WAMR_ROOT_DIR}/core/shared/utils
+ ${WAMR_ROOT_DIR}/core/shared/platform/linux
+)
+
+add_library(wasi-nn SHARED
+ ${WASI_NN_SOURCES}
+)
+
+# Add `get_native_lib` symbol
+target_compile_definitions(wasi-nn PUBLIC
+ WASI_NN_SHARED
+)
+
+target_link_libraries(wasi-nn
+ ${WASI_NN_LIBS}
+ vmlib
+)
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md
new file mode 100644
index 00000000000..b255185ed7e
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md
@@ -0,0 +1,13 @@
+# wasi-nn as shared library
+
+Example on how to create libwasi-nn (external library) instead of embedding wasi-nn inside iwasm
+
+From folder `core/iwasm/libraries/wasi-nn/test`, build the test and run
+
+```sh
+../external/build/iwasm \
+ --dir=. \
+ --env="TARGET=cpu" \
+ --native-lib=../external/build/libwasi-nn.so \
+ test_tensorflow.wasm
+```
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn_types.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn_types.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h
index a2cebe49ecb..7cfc70f341e 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn_types.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h
@@ -6,6 +6,9 @@
#ifndef WASI_NN_TYPES_H
#define WASI_NN_TYPES_H
+#include
+#include
+
/**
* ERRORS
*
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/logger.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/logger.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/logger.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/logger.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn.c
similarity index 76%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn.c
index 466630f99f1..c234e450a15 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn.c
@@ -9,16 +9,18 @@
#include
#include
#include
+#include
#include "wasi_nn.h"
+#include "wasi_nn_private.h"
#include "wasi_nn_app_native.h"
-#include "logger.h"
#include "wasi_nn_tensorflowlite.hpp"
+#include "logger.h"
#include "bh_platform.h"
#include "wasm_export.h"
-#include "wasm_runtime.h"
-#include "aot_runtime.h"
+
+#define HASHMAP_INITIAL_SIZE 20
/* Definition of 'wasi_nn.h' structs in WASM app format (using offset) */
@@ -51,6 +53,120 @@ static api_function lookup[] = {
tensorflowlite_get_output }
};
+static HashMap *hashmap;
+
+static void
+wasi_nn_ctx_destroy(WASINNContext *wasi_nn_ctx);
+
+/* Get wasi-nn context from module instance */
+
+static uint32
+hash_func(const void *key)
+{
+ // fnv1a_hash
+ const uint32 FNV_PRIME = 16777619;
+ const uint32 FNV_OFFSET_BASIS = 2166136261U;
+
+ uint32 hash = FNV_OFFSET_BASIS;
+ const unsigned char *bytes = (const unsigned char *)key;
+
+ for (size_t i = 0; i < sizeof(uintptr_t); ++i) {
+ hash ^= bytes[i];
+ hash *= FNV_PRIME;
+ }
+
+ return hash;
+}
+
+static bool
+key_equal_func(void *key1, void *key2)
+{
+ return key1 == key2;
+}
+
+static void
+key_destroy_func(void *key1)
+{}
+
+static void
+value_destroy_func(void *value)
+{
+ wasi_nn_ctx_destroy((WASINNContext *)value);
+}
+
+static WASINNContext *
+wasi_nn_initialize_context()
+{
+ NN_DBG_PRINTF("Initializing wasi-nn context");
+ WASINNContext *wasi_nn_ctx =
+ (WASINNContext *)wasm_runtime_malloc(sizeof(WASINNContext));
+ if (wasi_nn_ctx == NULL) {
+ NN_ERR_PRINTF("Error when allocating memory for WASI-NN context");
+ return NULL;
+ }
+ wasi_nn_ctx->is_model_loaded = false;
+ tensorflowlite_initialize(&wasi_nn_ctx->tflite_ctx);
+ return wasi_nn_ctx;
+}
+
+static bool
+wasi_nn_initialize()
+{
+ NN_DBG_PRINTF("Initializing wasi-nn");
+ hashmap = bh_hash_map_create(HASHMAP_INITIAL_SIZE, true, hash_func,
+ key_equal_func, key_destroy_func,
+ value_destroy_func);
+ if (hashmap == NULL) {
+ NN_ERR_PRINTF("Error while initializing hashmap");
+ return false;
+ }
+ return true;
+}
+
+static WASINNContext *
+wasm_runtime_get_wasi_nn_ctx(wasm_module_inst_t instance)
+{
+ WASINNContext *wasi_nn_ctx =
+ (WASINNContext *)bh_hash_map_find(hashmap, (void *)instance);
+ if (wasi_nn_ctx == NULL) {
+ wasi_nn_ctx = wasi_nn_initialize_context();
+ if (wasi_nn_ctx == NULL)
+ return NULL;
+ bool ok =
+ bh_hash_map_insert(hashmap, (void *)instance, (void *)wasi_nn_ctx);
+ if (!ok) {
+ NN_ERR_PRINTF("Error while storing context");
+ wasi_nn_ctx_destroy(wasi_nn_ctx);
+ return NULL;
+ }
+ }
+ NN_DBG_PRINTF("Returning ctx");
+ return wasi_nn_ctx;
+}
+
+static void
+wasi_nn_ctx_destroy(WASINNContext *wasi_nn_ctx)
+{
+ if (wasi_nn_ctx == NULL) {
+ NN_ERR_PRINTF(
+ "Error when deallocating memory. WASI-NN context is NULL");
+ return;
+ }
+ NN_DBG_PRINTF("Freeing wasi-nn");
+ NN_DBG_PRINTF("-> is_model_loaded: %d", wasi_nn_ctx->is_model_loaded);
+ NN_DBG_PRINTF("-> current_encoding: %d", wasi_nn_ctx->current_encoding);
+ tensorflowlite_destroy(wasi_nn_ctx->tflite_ctx);
+ wasm_runtime_free(wasi_nn_ctx);
+}
+
+void
+wasi_nn_destroy(wasm_module_inst_t instance)
+{
+ WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
+ bh_hash_map_remove(hashmap, (void *)instance, NULL, NULL);
+ wasi_nn_ctx_destroy(wasi_nn_ctx);
+}
+
/* Utils */
static bool
@@ -64,36 +180,13 @@ is_encoding_implemented(graph_encoding encoding)
static error
is_model_initialized(WASINNContext *wasi_nn_ctx)
{
- if (!wasi_nn_ctx->is_initialized) {
+ if (!wasi_nn_ctx->is_model_loaded) {
NN_ERR_PRINTF("Model not initialized.");
return runtime_error;
}
return success;
}
-WASINNContext *
-wasm_runtime_get_wasi_nn_ctx(wasm_module_inst_t instance)
-{
- WASINNContext *wasi_nn_ctx = NULL;
-#if WASM_ENABLE_INTERP != 0
- if (instance->module_type == Wasm_Module_Bytecode) {
- NN_DBG_PRINTF("Getting ctx from WASM");
- WASMModuleInstance *module_inst = (WASMModuleInstance *)instance;
- wasi_nn_ctx = ((WASMModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx;
- }
-#endif
-#if WASM_ENABLE_AOT != 0
- if (instance->module_type == Wasm_Module_AoT) {
- NN_DBG_PRINTF("Getting ctx from AOT");
- AOTModuleInstance *module_inst = (AOTModuleInstance *)instance;
- wasi_nn_ctx = ((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx;
- }
-#endif
- bh_assert(wasi_nn_ctx != NULL);
- NN_DBG_PRINTF("Returning ctx");
- return wasi_nn_ctx;
-}
-
/* WASI-NN implementation */
error
@@ -131,7 +224,7 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
NN_DBG_PRINTF("wasi_nn_load finished with status %d [graph=%d]", res, *g);
wasi_nn_ctx->current_encoding = encoding;
- wasi_nn_ctx->is_initialized = true;
+ wasi_nn_ctx->is_model_loaded = true;
fail:
// XXX: Free intermediate structure pointers
@@ -250,39 +343,6 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx,
return res;
}
-/* Non-exposed public functions */
-
-WASINNContext *
-wasi_nn_initialize()
-{
- NN_DBG_PRINTF("Initializing wasi-nn");
- WASINNContext *wasi_nn_ctx =
- (WASINNContext *)wasm_runtime_malloc(sizeof(WASINNContext));
- if (wasi_nn_ctx == NULL) {
- NN_ERR_PRINTF("Error when allocating memory for WASI-NN context");
- return NULL;
- }
- wasi_nn_ctx->is_initialized = true;
- wasi_nn_ctx->current_encoding = 3;
- tensorflowlite_initialize(&wasi_nn_ctx->tflite_ctx);
- return wasi_nn_ctx;
-}
-
-void
-wasi_nn_destroy(WASINNContext *wasi_nn_ctx)
-{
- if (wasi_nn_ctx == NULL) {
- NN_ERR_PRINTF(
- "Error when deallocating memory. WASI-NN context is NULL");
- return;
- }
- NN_DBG_PRINTF("Freeing wasi-nn");
- NN_DBG_PRINTF("-> is_initialized: %d", wasi_nn_ctx->is_initialized);
- NN_DBG_PRINTF("-> current_encoding: %d", wasi_nn_ctx->current_encoding);
- tensorflowlite_destroy(wasi_nn_ctx->tflite_ctx);
- wasm_runtime_free(wasi_nn_ctx);
-}
-
/* Register WASI-NN in WAMR */
/* clang-format off */
@@ -299,8 +359,19 @@ static NativeSymbol native_symbols_wasi_nn[] = {
};
uint32_t
-get_wasi_nn_export_apis(NativeSymbol **p_libc_wasi_apis)
+get_wasi_nn_export_apis(NativeSymbol **p_native_symbols)
{
- *p_libc_wasi_apis = native_symbols_wasi_nn;
+ if (!wasi_nn_initialize())
+ return 0;
+ *p_native_symbols = native_symbols_wasi_nn;
return sizeof(native_symbols_wasi_nn) / sizeof(NativeSymbol);
}
+
+#if defined(WASI_NN_SHARED)
+uint32_t
+get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols)
+{
+ *p_module_name = "wasi_nn";
+ return get_wasi_nn_export_apis(p_native_symbols);
+}
+#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h
similarity index 71%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h
index 52d16bd1da0..e66c274a093 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h
@@ -7,25 +7,20 @@
#define WASI_NN_PRIVATE_H
#include "wasi_nn_types.h"
+#include "wasm_export.h"
typedef struct {
- bool is_initialized;
+ bool is_model_loaded;
graph_encoding current_encoding;
void *tflite_ctx;
} WASINNContext;
-/**
- * @brief Initialize wasi-nn
- *
- */
-WASINNContext *
-wasi_nn_initialize();
/**
* @brief Destroy wasi-nn on app exists
*
*/
void
-wasi_nn_destroy(WASINNContext *wasi_nn_ctx);
+wasi_nn_destroy(wasm_module_inst_t instance);
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp
similarity index 74%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp
index dfd21787cd8..65e38f867c0 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp
@@ -7,9 +7,8 @@
#include "wasi_nn_tensorflowlite.hpp"
#include "logger.h"
-#include "bh_common.h"
#include "bh_platform.h"
-#include "platform_common.h"
+#include "wasm_export.h"
#include
#include
@@ -17,11 +16,11 @@
#include
#include
-#if defined(WASI_NN_ENABLE_GPU)
+#if WASM_ENABLE_WASI_NN_GPU != 0
#include
#endif
-#if defined(WASI_NN_ENABLE_EXTERNAL_DELEGATE)
+#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0
#include
#endif
@@ -131,8 +130,8 @@ tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder,
return invalid_argument;
}
- if (target != cpu && target != gpu) {
- NN_ERR_PRINTF("Only CPU and GPU target is supported.");
+ if (target != cpu && target != gpu && target != tpu) {
+ NN_ERR_PRINTF("Only CPU, GPU and TPU target is supported.");
return invalid_argument;
}
@@ -196,7 +195,7 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
switch (tfl_ctx->models[g].target) {
case gpu:
{
-#if defined(WASI_NN_ENABLE_GPU)
+#if WASM_ENABLE_WASI_NN_GPU != 0
NN_WARN_PRINTF("GPU enabled.");
// https://www.tensorflow.org/lite/performance/gpu
TfLiteGpuDelegateOptionsV2 options =
@@ -217,10 +216,19 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
NN_ERR_PRINTF("Error when enabling GPU delegate.");
use_default = true;
}
-#elif defined(WASI_NN_ENABLE_EXTERNAL_DELEGATE)
+#else
+ NN_WARN_PRINTF("GPU not enabled.");
+ use_default = true;
+#endif
+ break;
+ }
+ case tpu:
+ {
+#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0
NN_WARN_PRINTF("external delegation enabled.");
TfLiteExternalDelegateOptions options =
- TfLiteExternalDelegateOptionsDefault(WASI_NN_EXT_DELEGATE_PATH);
+ TfLiteExternalDelegateOptionsDefault(
+ WASM_WASI_NN_EXTERNAL_DELEGATE_PATH);
tfl_ctx->delegate = TfLiteExternalDelegateCreate(&options);
if (tfl_ctx->delegate == NULL) {
NN_ERR_PRINTF("Error when generating External delegate.");
@@ -234,7 +242,7 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g,
use_default = true;
}
#else
- NN_WARN_PRINTF("GPU not enabled.");
+ NN_WARN_PRINTF("External delegate not enabled.");
use_default = true;
#endif
break;
@@ -286,14 +294,37 @@ tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx,
return invalid_argument;
}
- auto *input =
- tfl_ctx->interpreters[ctx].interpreter->typed_input_tensor(
- index);
- if (input == NULL)
- return missing_memory;
+ if (tensor->quantization.type == kTfLiteNoQuantization) {
+ NN_DBG_PRINTF("No quantization information. Using float as default");
+ float *it =
+ tfl_ctx->interpreters[ctx].interpreter->typed_input_tensor(
+ index);
+
+ int size = model_tensor_size * sizeof(float);
+ bh_memcpy_s(it, size, input_tensor->data, size);
+ }
+ else { // TODO: Assumming uint8 quantized networks.
+ TfLiteAffineQuantization *quant_info =
+ (TfLiteAffineQuantization *)tensor->quantization.params;
+ if (quant_info->scale->size != 1 || quant_info->zero_point->size != 1) {
+ NN_ERR_PRINTF("Quantization per channel is not supported");
+ return runtime_error;
+ }
+ uint8_t *it =
+ tfl_ctx->interpreters[ctx].interpreter->typed_input_tensor(
+ index);
+
+ float scale = quant_info->scale->data[0];
+ float zero_point = (float)quant_info->zero_point->data[0];
+ NN_DBG_PRINTF("input tensor: (scale, offset) = (%f, %f)", scale,
+ zero_point);
+
+ float *input_tensor_f = (float *)input_tensor->data;
+ for (uint32_t i = 0; i < model_tensor_size; ++i) {
+ it[i] = (uint8_t)(input_tensor_f[i] / scale + zero_point);
+ }
+ }
- bh_memcpy_s(input, model_tensor_size * sizeof(float), input_tensor->data,
- model_tensor_size * sizeof(float));
return success;
}
@@ -326,6 +357,7 @@ tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx,
NN_DBG_PRINTF("Number of tensors (%d)", num_output_tensors);
if (index + 1 > num_output_tensors) {
+ NN_ERR_PRINTF("Index %d is invalid.", index);
return runtime_error;
}
@@ -344,15 +376,37 @@ tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx,
return missing_memory;
}
- float *tensor_f =
- tfl_ctx->interpreters[ctx].interpreter->typed_output_tensor(
- index);
- for (uint32_t i = 0; i < model_tensor_size; ++i)
- NN_DBG_PRINTF("output: %f", tensor_f[i]);
+ if (tensor->quantization.type == kTfLiteNoQuantization) {
+ NN_DBG_PRINTF("No quantization information");
+ float *ot =
+ tfl_ctx->interpreters[ctx].interpreter->typed_output_tensor(
+ index);
+
+ int size = model_tensor_size * sizeof(float);
+ bh_memcpy_s(output_tensor, size, ot, size);
+ }
+ else { // TODO: Assumming uint8 quantized networks.
+ TfLiteAffineQuantization *quant_info =
+ (TfLiteAffineQuantization *)tensor->quantization.params;
+ if (quant_info->scale->size != 1 || quant_info->zero_point->size != 1) {
+ NN_ERR_PRINTF("Quantization per channel is not supported");
+ return runtime_error;
+ }
+ uint8_t *ot = tfl_ctx->interpreters[ctx]
+ .interpreter->typed_output_tensor(index);
+
+ float scale = quant_info->scale->data[0];
+ float zero_point = (float)quant_info->zero_point->data[0];
+ NN_DBG_PRINTF("output tensor: (scale, offset) = (%f, %f)", scale,
+ zero_point);
+
+ float *output_tensor_f = (float *)output_tensor;
+ for (uint32_t i = 0; i < model_tensor_size; ++i) {
+ output_tensor_f[i] = (ot[i] - zero_point) * scale;
+ }
+ }
*output_tensor_size = model_tensor_size;
- bh_memcpy_s(output_tensor, model_tensor_size * sizeof(float), tensor_f,
- model_tensor_size * sizeof(float));
return success;
}
@@ -393,19 +447,35 @@ tensorflowlite_destroy(void *tflite_ctx)
*/
TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx;
- if (tfl_ctx->delegate != NULL) {
-#if defined(WASI_NN_ENABLE_GPU)
- TfLiteGpuDelegateV2Delete(tfl_ctx->delegate);
-#elif defined(WASI_NN_ENABLE_EXTERNAL_DELEGATE)
- TfLiteExternalDelegateDelete(tfl_ctx->delegate);
-#endif
- }
-
NN_DBG_PRINTF("Freeing memory.");
for (int i = 0; i < MAX_GRAPHS_PER_INST; ++i) {
tfl_ctx->models[i].model.reset();
- if (tfl_ctx->models[i].model_pointer)
+ if (tfl_ctx->models[i].model_pointer) {
+ if (tfl_ctx->delegate) {
+ switch (tfl_ctx->models[i].target) {
+ case gpu:
+ {
+#if WASM_ENABLE_WASI_NN_GPU != 0
+ TfLiteGpuDelegateV2Delete(tfl_ctx->delegate);
+#else
+ NN_ERR_PRINTF("GPU delegate delete but not enabled.");
+#endif
+ break;
+ }
+ case tpu:
+ {
+#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0
+ TfLiteExternalDelegateDelete(tfl_ctx->delegate);
+#else
+ NN_ERR_PRINTF(
+ "External delegate delete but not enabled.");
+#endif
+ break;
+ }
+ }
+ }
wasm_runtime_free(tfl_ctx->models[i].model_pointer);
+ }
tfl_ctx->models[i].model_pointer = NULL;
}
for (int i = 0; i < MAX_GRAPH_EXEC_CONTEXTS_PER_INST; ++i) {
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile
new file mode 100644
index 00000000000..b20d0111afa
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile
@@ -0,0 +1,26 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM ubuntu:20.04
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y \
+ cmake build-essential git wget python3.10 python3-pip --no-install-recommends \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/*
+
+ARG WASI_SDK_VER=19
+RUN wget -c --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VER}/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -P /opt \
+ && tar xf /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -C /opt \
+ && ln -fs /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk \
+ && rm /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz
+
+WORKDIR /wasi-nn/test
+
+COPY core/iwasm/libraries/wasi-nn/test/requirements.txt .
+
+RUN pip3 install --no-cache-dir -r requirements.txt && rm requirements.txt
+
+ENTRYPOINT [ "bash", "./build.sh" ]
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu
new file mode 100644
index 00000000000..6fe56567e7c
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu
@@ -0,0 +1,35 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM ubuntu:20.04 AS base
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y \
+ cmake build-essential git --no-install-recommends
+
+WORKDIR /home/wamr
+
+COPY . .
+
+WORKDIR /home/wamr/product-mini/platforms/linux/build
+
+# hadolint ignore=DL3008
+RUN apt-get install -y wget ca-certificates --no-install-recommends \
+ && mkdir /usr/local/share/ca-certificates/cacert.org \
+ && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
+ && update-ca-certificates \
+ && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
+
+RUN cmake \
+ -DWAMR_BUILD_WASI_NN=1 \
+ ..
+
+RUN make -j "$(grep -c ^processor /proc/cpuinfo)"
+
+FROM ubuntu:22.04
+
+COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm
+
+ENTRYPOINT [ "/iwasm" ]
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu
new file mode 100644
index 00000000000..737b2d3f043
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu
@@ -0,0 +1,49 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM ubuntu:20.04 AS base
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y \
+ cmake build-essential git --no-install-recommends
+
+WORKDIR /home/wamr
+
+COPY . .
+
+WORKDIR /home/wamr/product-mini/platforms/linux/build
+
+# hadolint ignore=DL3008
+RUN apt-get install -y wget ca-certificates --no-install-recommends \
+ && mkdir /usr/local/share/ca-certificates/cacert.org \
+ && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
+ && update-ca-certificates \
+ && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
+
+RUN cmake \
+ -DWAMR_BUILD_WASI_NN=1 \
+ -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
+ ..
+
+RUN make -j "$(grep -c ^processor /proc/cpuinfo)"
+
+FROM nvidia/cuda:11.3.0-runtime-ubuntu20.04
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ ocl-icd-libopencl1 \
+ ocl-icd-opencl-dev \
+ clinfo && \
+ rm -rf /var/lib/apt/lists/*
+
+RUN mkdir -p /etc/OpenCL/vendors && \
+ echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd
+
+ENV NVIDIA_VISIBLE_DEVICES=all
+ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
+
+COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm
+
+ENTRYPOINT [ "/iwasm" ]
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu
new file mode 100644
index 00000000000..742645b06ae
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu
@@ -0,0 +1,37 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM ubuntu:20.04 AS base
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y \
+ cmake build-essential git curl gnupg --no-install-recommends && \
+ rm -rf /var/lib/apt/lists/*
+
+# hadolint ignore=DL3008,DL4006
+RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list && \
+ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
+ apt-get update && apt-get install -y libedgetpu1-std --no-install-recommends && \
+ rm -rf /var/lib/apt/lists/*
+
+WORKDIR /home/wamr
+
+COPY . .
+
+WORKDIR /home/wamr/product-mini/platforms/linux/build
+
+RUN cmake \
+ -DWAMR_BUILD_WASI_NN=1 \
+ -DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \
+ -DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \
+ -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
+ ..
+
+RUN make -j "$(grep -c ^processor /proc/cpuinfo)" && \
+ cp /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm
+
+WORKDIR /assets
+
+ENTRYPOINT [ "/iwasm" ]
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate
new file mode 100644
index 00000000000..f078045b946
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate
@@ -0,0 +1,113 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM ubuntu:20.04 AS base
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y \
+ cmake build-essential git curl libssl-dev python3 --no-install-recommends \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/*
+
+# hadolint ignore=DL3008
+RUN apt-get update && apt-get install -y wget ca-certificates --no-install-recommends \
+ && apt-get clean -y \
+ && rm -rf /var/lib/apt/lists/* \
+ && mkdir /usr/local/share/ca-certificates/cacert.org \
+ && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
+ && update-ca-certificates \
+ && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
+
+# Build TensorFlow Lite VX delegate default built for x86-64 simulator
+WORKDIR /tmp
+RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \
+ && git clone https://github.com/VeriSilicon/tflite-vx-delegate.git \
+ && git clone https://github.com/tensorflow/tensorflow.git
+
+
+# Build TIM-VX
+WORKDIR /tmp/tim-vx/host_build
+RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local ../ \
+ && make -j "$(grep -c ^processor /proc/cpuinfo)" \
+ && make install
+
+WORKDIR /tmp/tim-vx
+#RUN mkdir -p prebuilt-sdk/x86_64_linux/lib/include
+#RUN cp prebuilt-sdk/x86_64_linux/include/CL prebuilt-sdk/x86_64_linux/lib/include -fr
+
+
+# Build TensorFlow Lite
+WORKDIR /tmp/tensorflow/build
+RUN cmake \
+ -DBUILD_SHARED_LIBS=ON=on \
+ -DTFLITE_ENABLE_RUY=on \
+ -DTFLITE_ENABLE_NNAPI=off \
+ -DTFLITE_ENABLE_XNNPACK=on \
+ -DTFLITE_ENABLE_EXTERNAL_DELEGATE=on \
+ ../tensorflow/lite/
+RUN make -j "$(grep -c ^processor /proc/cpuinfo)" \
+ && make install \
+ && cp --no-preserve=ownership -d lib*.so* /usr/local/lib \
+ && cp -r --no-preserve=ownership -d flatbuffers/include/flatbuffers /usr/local/include
+# install header files
+RUN install -d /usr/local/include/tensorflow/lite
+WORKDIR /tmp/tensorflow/tensorflow/lite
+# hadolint ignore=SC2046
+RUN cp --parents \
+ $(find . -name "*.h*") \
+ /usr/local/include/tensorflow/lite
+# install version.h from core
+RUN install -d /usr/local/include/tensorflow/core/public && \
+ cp /tmp/tensorflow/tensorflow/core/public/version.h /usr/local/include/tensorflow/core/public
+
+
+# Build Vx Delegate default built for x86-64 simulator
+WORKDIR /tmp/tflite-vx-delegate/build
+RUN cmake \
+ -DBUILD_SHARED_LIBS=ON \
+ -DFETCHCONTENT_SOURCE_DIR_TENSORFLOW=/tmp/tensorflow \
+ -DTFLITE_LIB_LOC=/usr/local/lib/libtensorflow-lite.so \
+ -DTIM_VX_INSTALL=/usr/local \
+ -DCMAKE_INSTALL_PREFIX=/usr/ \
+ ../
+RUN make vx_delegate -j "$(grep -c ^processor /proc/cpuinfo)" \
+ && make install \
+ && cp --no-preserve=ownership -d lib*.so* /usr/lib
+# install header files
+RUN install -d /usr/local/include/tensorflow-lite-vx-delegate
+WORKDIR /tmp/tflite-vx-delegate/
+# hadolint ignore=SC2046
+RUN cp --parents \
+ $(find . -name "*.h*") \
+ /usr/local/include/tensorflow-lite-vx-delegate
+
+ENV VIVANTE_SDK_DIR=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/
+ENV VSIMULATOR_CONFIG=czl
+
+ENV LD_LIBRARY_PATH=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/lib:/usr/local/lib:/lib/x86_64-linux-gnu/:/lib64/:/usr/lib:$LD_LIBRARY_PATH
+
+
+# Build WASI-NN
+WORKDIR /home/wamr
+
+COPY . .
+
+WORKDIR /home/wamr/core/iwasm/libraries/wasi-nn/test/build
+
+# hadolint ignore=SC2086
+RUN cmake \
+ -DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}:/usr/local/lib/ \
+ -DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}:/usr/local/include/ \
+ -DWAMR_BUILD_WASI_NN=1 \
+ -DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \
+ -DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \
+ ..
+
+RUN make -j "$(grep -c ^processor /proc/cpuinfo)"
+
+RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm
+
+ENTRYPOINT [ "/run/iwasm" ]
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/build.sh
similarity index 51%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/build.sh
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/build.sh
index 33879eaf7ce..da6cfa5f8e0 100755
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/build.sh
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/build.sh
@@ -1,21 +1,41 @@
+#!/bin/sh
+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+CURR_PATH=$(cd $(dirname $0) && pwd -P)
+
# WASM application that uses WASI-NN
/opt/wasi-sdk/bin/clang \
-Wl,--allow-undefined \
-Wl,--strip-all,--no-entry \
--sysroot=/opt/wasi-sdk/share/wasi-sysroot \
- -I.. -I../src/utils \
+ -I../include -I../src/utils \
-o test_tensorflow.wasm \
test_tensorflow.c utils.c
# TFLite models to use in the tests
-cd models
+cd ${CURR_PATH}/models
python3 average.py
python3 max.py
python3 mult_dimension.py
python3 mult_outputs.py
python3 sum.py
+
+# Specific tests for TPU
+
+cd ${CURR_PATH}
+/opt/wasi-sdk/bin/clang \
+ -Wl,--allow-undefined \
+ -Wl,--strip-all,--no-entry \
+ --sysroot=/opt/wasi-sdk/share/wasi-sysroot \
+ -I../include -I../src/utils \
+ -o test_tensorflow_quantized.wasm \
+ test_tensorflow_quantized.c utils.c
+
+cd ${CURR_PATH}/models
+python3 quantized.py
+
+cd ${CURR_PATH}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/average.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/average.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/average.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/average.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/max.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/max.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/max.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/max.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py
new file mode 100644
index 00000000000..b195b319f5d
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py
@@ -0,0 +1,30 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+import tensorflow as tf
+import numpy as np
+import pathlib
+
+model = tf.keras.Sequential([
+ tf.keras.layers.InputLayer(input_shape=[5, 5, 1]),
+ tf.keras.layers.AveragePooling2D(
+ pool_size=(5, 5), strides=None, padding="valid", data_format=None)
+
+])
+
+def representative_dataset():
+ for _ in range(1000):
+ data = np.random.randint(0, 25, (1, 5, 5, 1))
+ yield [data.astype(np.float32)]
+
+converter = tf.lite.TFLiteConverter.from_keras_model(model)
+converter.optimizations = [tf.lite.Optimize.DEFAULT]
+converter.representative_dataset = representative_dataset
+converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
+converter.inference_input_type = tf.uint8 # or tf.int8
+converter.inference_output_type = tf.uint8 # or tf.int8
+tflite_model = converter.convert()
+
+tflite_models_dir = pathlib.Path("./")
+tflite_model_file = tflite_models_dir / "quantized_model.tflite"
+tflite_model_file.write_bytes(tflite_model)
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/sum.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/sum.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/sum.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/sum.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/utils.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/utils.py
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/utils.py
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/utils.py
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/requirements.txt
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/requirements.txt
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/requirements.txt
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c
similarity index 83%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c
index 2fa5165384c..6a9e20702f4 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c
@@ -20,7 +20,7 @@ test_sum(execution_target target)
uint32_t output_size = 0;
float *output = run_inference(target, input.input_tensor, input.dim,
- &output_size, "/assets/models/sum.tflite", 1);
+ &output_size, "./models/sum.tflite", 1);
assert(output_size == 1);
assert(fabs(output[0] - 300.0) < EPSILON);
@@ -38,7 +38,7 @@ test_max(execution_target target)
uint32_t output_size = 0;
float *output = run_inference(target, input.input_tensor, input.dim,
- &output_size, "/assets/models/max.tflite", 1);
+ &output_size, "./models/max.tflite", 1);
assert(output_size == 1);
assert(fabs(output[0] - 24.0) < EPSILON);
@@ -56,9 +56,8 @@ test_average(execution_target target)
input_info input = create_input(dims);
uint32_t output_size = 0;
- float *output =
- run_inference(target, input.input_tensor, input.dim, &output_size,
- "/assets/models/average.tflite", 1);
+ float *output = run_inference(target, input.input_tensor, input.dim,
+ &output_size, "./models/average.tflite", 1);
assert(output_size == 1);
assert(fabs(output[0] - 12.0) < EPSILON);
@@ -76,9 +75,8 @@ test_mult_dimensions(execution_target target)
input_info input = create_input(dims);
uint32_t output_size = 0;
- float *output =
- run_inference(target, input.input_tensor, input.dim, &output_size,
- "/assets/models/mult_dim.tflite", 1);
+ float *output = run_inference(target, input.input_tensor, input.dim,
+ &output_size, "./models/mult_dim.tflite", 1);
assert(output_size == 9);
for (int i = 0; i < 9; i++)
@@ -96,9 +94,8 @@ test_mult_outputs(execution_target target)
input_info input = create_input(dims);
uint32_t output_size = 0;
- float *output =
- run_inference(target, input.input_tensor, input.dim, &output_size,
- "/assets/models/mult_out.tflite", 2);
+ float *output = run_inference(target, input.input_tensor, input.dim,
+ &output_size, "./models/mult_out.tflite", 2);
assert(output_size == 8);
// first tensor check
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c
new file mode 100644
index 00000000000..3ed7c751e3b
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "utils.h"
+#include "logger.h"
+
+#undef EPSILON
+#define EPSILON 1e-2
+
+void
+test_average_quantized(execution_target target)
+{
+ int dims[] = { 1, 5, 5, 1 };
+ input_info input = create_input(dims);
+
+ uint32_t output_size = 0;
+ float *output =
+ run_inference(target, input.input_tensor, input.dim, &output_size,
+ "./models/quantized_model.tflite", 1);
+
+ NN_INFO_PRINTF("Output size: %d", output_size);
+ NN_INFO_PRINTF("Result: average is %f", output[0]);
+ // NOTE: 11.95 instead of 12 because of errors due quantization
+ assert(fabs(output[0] - 11.95) < EPSILON);
+
+ free(input.dim);
+ free(input.input_tensor);
+ free(output);
+}
+
+int
+main()
+{
+ char *env = getenv("TARGET");
+ if (env == NULL) {
+ NN_INFO_PRINTF("Usage:\n--env=\"TARGET=[cpu|gpu|tpu]\"");
+ return 1;
+ }
+ execution_target target;
+ if (strcmp(env, "cpu") == 0)
+ target = cpu;
+ else if (strcmp(env, "gpu") == 0)
+ target = gpu;
+ else if (strcmp(env, "tpu") == 0)
+ target = tpu;
+ else {
+ NN_ERR_PRINTF("Wrong target!");
+ return 1;
+ }
+ NN_INFO_PRINTF("################### Testing quantized model...");
+ test_average_quantized(target);
+
+ NN_INFO_PRINTF("Tests: passed!");
+ return 0;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.c
index e0704cab421..7b4f65d16b8 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.c
@@ -132,8 +132,8 @@ run_inference(execution_target target, float *input, uint32_t *input_size,
*output_size = MAX_OUTPUT_TENSOR_SIZE - *output_size;
if (wasm_get_output(ctx, i, &out_tensor[offset], output_size)
!= success) {
- NN_ERR_PRINTF("Error when getting output.");
- exit(1);
+ NN_ERR_PRINTF("Error when getting index %d.", i);
+ break;
}
offset += *output_size;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.h
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.h
index 6373be54214..0b2328406ea 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.h
@@ -11,7 +11,7 @@
#include "wasi_nn.h"
#define MAX_MODEL_SIZE 85000000
-#define MAX_OUTPUT_TENSOR_SIZE 200
+#define MAX_OUTPUT_TENSOR_SIZE 1000000
#define INPUT_TENSOR_DIMS 4
#define EPSILON 1e-8
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/LICENSE.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/LICENSE.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/LICENSE.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/LICENSE.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/coap-constants.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/coap-constants.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/coap-constants.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/coap-constants.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/extension/coap_ext.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/extension/coap_ext.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/extension/coap_ext.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/extension/coap_ext.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/lib_coap.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/lib_coap.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/lib_coap.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/lib_coap.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/SConscript
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/SConscript
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/SConscript
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_alloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_alloc.c
similarity index 94%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_alloc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_alloc.c
index 5c2a628a261..0e2c4da7cae 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_alloc.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_alloc.c
@@ -24,19 +24,23 @@ hmu_is_in_heap(void *hmu, gc_uint8 *heap_base_addr, gc_uint8 *heap_end_addr)
static bool
remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
{
- hmu_tree_node_t *q = NULL, **slot = NULL, *parent;
- hmu_tree_node_t *root = heap->kfc_tree_root;
+ hmu_tree_node_t *q = NULL, **slot = NULL;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
+ hmu_tree_node_t *root = heap->kfc_tree_root, *parent;
gc_uint8 *base_addr = heap->base_addr;
gc_uint8 *end_addr = base_addr + heap->current_size;
+#endif
bh_assert(p);
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
parent = p->parent;
if (!parent || p == root /* p can not be the ROOT node */
|| !hmu_is_in_heap(p, base_addr, end_addr)
|| (parent != root && !hmu_is_in_heap(parent, base_addr, end_addr))) {
goto fail;
}
+#endif
/* get the slot which holds pointer to node p */
if (p == p->parent->right) {
@@ -67,9 +71,11 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
/* move right child up*/
*slot = p->right;
if (p->right) {
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(p->right, base_addr, end_addr)) {
goto fail;
}
+#endif
p->right->parent = p->parent;
}
@@ -80,9 +86,11 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
if (!p->right) {
/* move left child up*/
*slot = p->left;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(p->left, base_addr, end_addr)) {
goto fail;
}
+#endif
/* p->left can never be NULL unless it is corrupted. */
p->left->parent = p->parent;
@@ -92,14 +100,18 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
/* both left & right exist, find p's predecessor at first*/
q = p->left;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(q, base_addr, end_addr)) {
goto fail;
}
+#endif
while (q->right) {
q = q->right;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(q, base_addr, end_addr)) {
goto fail;
}
+#endif
}
/* remove from the tree*/
@@ -111,15 +123,19 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
q->left = p->left;
q->right = p->right;
if (q->left) {
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(q->left, base_addr, end_addr)) {
goto fail;
}
+#endif
q->left->parent = q;
}
if (q->right) {
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(q->right, base_addr, end_addr)) {
goto fail;
}
+#endif
q->right->parent = q;
}
@@ -127,27 +143,35 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p)
return true;
fail:
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
heap->is_heap_corrupted = true;
+#endif
return false;
}
static bool
unlink_hmu(gc_heap_t *heap, hmu_t *hmu)
{
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
gc_uint8 *base_addr, *end_addr;
+#endif
gc_size_t size;
bh_assert(gci_is_heap_valid(heap));
bh_assert(hmu && (gc_uint8 *)hmu >= heap->base_addr
&& (gc_uint8 *)hmu < heap->base_addr + heap->current_size);
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (hmu_get_ut(hmu) != HMU_FC) {
heap->is_heap_corrupted = true;
return false;
}
+#endif
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
base_addr = heap->base_addr;
end_addr = base_addr + heap->current_size;
+#endif
size = hmu_get_size(hmu);
if (HMU_IS_FC_NORMAL(size)) {
@@ -156,10 +180,12 @@ unlink_hmu(gc_heap_t *heap, hmu_t *hmu)
hmu_normal_node_t *node = heap->kfc_normal_list[node_idx].next;
while (node) {
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(node, base_addr, end_addr)) {
heap->is_heap_corrupted = true;
return false;
}
+#endif
node_next = get_hmu_normal_node_next(node);
if ((hmu_t *)node == hmu) {
if (!node_prev) /* list head */
@@ -205,7 +231,9 @@ hmu_set_free_size(hmu_t *hmu)
bool
gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
{
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
gc_uint8 *base_addr, *end_addr;
+#endif
hmu_normal_node_t *np = NULL;
hmu_tree_node_t *root = NULL, *tp = NULL, *node = NULL;
uint32 node_idx;
@@ -219,8 +247,10 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
<= heap->base_addr + heap->current_size);
bh_assert(!(size & 7));
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
base_addr = heap->base_addr;
end_addr = base_addr + heap->current_size;
+#endif
hmu_set_ut(hmu, HMU_FC);
hmu_set_size(hmu, size);
@@ -228,10 +258,12 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
if (HMU_IS_FC_NORMAL(size)) {
np = (hmu_normal_node_t *)hmu;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(np, base_addr, end_addr)) {
heap->is_heap_corrupted = true;
return false;
}
+#endif
node_idx = size >> 3;
set_hmu_normal_node_next(np, heap->kfc_normal_list[node_idx].next);
@@ -265,10 +297,12 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size)
}
tp = tp->left;
}
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(tp, base_addr, end_addr)) {
heap->is_heap_corrupted = true;
return false;
}
+#endif
}
return true;
}
@@ -321,15 +355,19 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
bh_assert(node_idx >= init_node_idx);
p = normal_head->next;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(p, base_addr, end_addr)) {
heap->is_heap_corrupted = true;
return NULL;
}
+#endif
normal_head->next = get_hmu_normal_node_next(p);
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (((gc_int32)(uintptr_t)hmu_to_obj(p) & 7) != 0) {
heap->is_heap_corrupted = true;
return NULL;
}
+#endif
if ((gc_size_t)node_idx != (uint32)init_node_idx
/* with bigger size*/
@@ -365,10 +403,12 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size)
bh_assert(root);
tp = root->right;
while (tp) {
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (!hmu_is_in_heap(tp, base_addr, end_addr)) {
heap->is_heap_corrupted = true;
return NULL;
}
+#endif
if (tp->size < size) {
tp = tp->right;
@@ -462,10 +502,12 @@ gc_alloc_vo_internal(void *vheap, gc_size_t size, const char *file, int line)
/* integer overflow */
return NULL;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, allocate memory failed.\n");
return NULL;
}
+#endif
os_mutex_lock(&heap->lock);
@@ -522,10 +564,12 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file,
/* integer overflow */
return NULL;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, allocate memory failed.\n");
return NULL;
}
+#endif
if (obj_old) {
hmu_old = obj_to_hmu(obj_old);
@@ -564,6 +608,7 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file,
os_mutex_unlock(&heap->lock);
return NULL;
}
+ hmu_mark_pinuse(hmu_next);
}
os_mutex_unlock(&heap->lock);
return obj_old;
@@ -646,10 +691,12 @@ gc_free_vo_internal(void *vheap, gc_object_t obj, const char *file, int line)
return GC_SUCCESS;
}
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, free memory failed.\n");
return GC_ERROR;
}
+#endif
hmu = obj_to_hmu(obj);
@@ -766,11 +813,13 @@ gci_dump(gc_heap_t *heap)
else if (ut == HMU_FC)
inuse = 'F';
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (size == 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) {
os_printf("[GC_ERROR]Heap is corrupted, heap dump failed.\n");
heap->is_heap_corrupted = true;
return;
}
+#endif
os_printf("#%d %08" PRIx32 " %" PRIx32 " %d %d"
" %c %" PRId32 "\n",
@@ -787,8 +836,12 @@ gci_dump(gc_heap_t *heap)
i++;
}
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (cur != end) {
os_printf("[GC_ERROR]Heap is corrupted, heap dump failed.\n");
heap->is_heap_corrupted = true;
}
+#else
+ bh_assert(cur == end);
+#endif
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc_internal.h
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc_internal.h
index e1ff9d61d85..6abe2b12a50 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc_internal.h
@@ -214,13 +214,16 @@ set_hmu_normal_node_next(hmu_normal_node_t *node, hmu_normal_node_t *next)
#if defined(_MSC_VER)
__pragma(pack(push, 1));
#define __attr_packed
+#define __attr_aligned(a)
#elif defined(__GNUC__) || defined(__clang__)
#define __attr_packed __attribute__((packed))
+#define __attr_aligned(a) __attribute__((aligned(a)))
#else
#error "packed attribute isn't used to define struct hmu_tree_node"
#endif
#else /* else of UINTPTR_MAX == UINT64_MAX */
#define __attr_packed
+#define __attr_aligned(a)
#endif
typedef struct hmu_tree_node {
@@ -229,7 +232,7 @@ typedef struct hmu_tree_node {
struct hmu_tree_node *right;
struct hmu_tree_node *parent;
gc_size_t size;
-} __attr_packed hmu_tree_node_t;
+} __attr_packed __attr_aligned(4) hmu_tree_node_t;
#if UINTPTR_MAX == UINT64_MAX
#if defined(_MSC_VER)
@@ -268,9 +271,11 @@ typedef struct gc_heap_struct {
size[left] <= size[cur] < size[right] */
hmu_tree_node_t *kfc_tree_root;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
/* whether heap is corrupted, e.g. the hmu nodes are modified
by user */
bool is_heap_corrupted;
+#endif
gc_size_t init_size;
gc_size_t highmark_size;
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_hmu.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_hmu.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_hmu.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_hmu.c
index 41745e161ed..f9d7c0f4a79 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_hmu.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_hmu.c
@@ -83,7 +83,9 @@ hmu_verify(void *vheap, hmu_t *hmu)
os_printf("Invalid padding for object created at %s:%d\n",
(prefix->file_name ? prefix->file_name : ""),
prefix->line_no);
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
heap->is_heap_corrupted = true;
+#endif
}
}
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_kfc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_kfc.c
similarity index 95%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_kfc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_kfc.c
index 80d20267943..1dda3ae031a 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_kfc.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_kfc.c
@@ -133,8 +133,11 @@ gc_destroy_with_pool(gc_handle_t handle)
hmu_t *cur = (hmu_t *)heap->base_addr;
hmu_t *end = (hmu_t *)((char *)heap->base_addr + heap->current_size);
- if (!heap->is_heap_corrupted
- && (hmu_t *)((char *)cur + hmu_get_size(cur)) != end) {
+ if (
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
+ !heap->is_heap_corrupted &&
+#endif
+ (hmu_t *)((char *)cur + hmu_get_size(cur)) != end) {
os_printf("Memory leak detected:\n");
gci_dump(heap);
ret = GC_ERROR;
@@ -186,10 +189,12 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
if (offset == 0)
return 0;
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (heap->is_heap_corrupted) {
os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
return GC_ERROR;
}
+#endif
heap->base_addr = (uint8 *)base_addr_new;
@@ -211,11 +216,13 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
while (cur < end) {
size = hmu_get_size(cur);
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (size <= 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) {
os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
heap->is_heap_corrupted = true;
return GC_ERROR;
}
+#endif
if (hmu_get_ut(cur) == HMU_FC && !HMU_IS_FC_NORMAL(size)) {
tree_node = (hmu_tree_node_t *)cur;
@@ -238,11 +245,15 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
cur = (hmu_t *)((char *)cur + size);
}
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
if (cur != end) {
os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
heap->is_heap_corrupted = true;
return GC_ERROR;
}
+#else
+ bh_assert(cur == end);
+#endif
return 0;
}
@@ -250,9 +261,13 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
bool
gc_is_heap_corrupted(gc_handle_t handle)
{
+#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
gc_heap_t *heap = (gc_heap_t *)handle;
return heap->is_heap_corrupted ? true : false;
+#else
+ return false;
+#endif
}
#if BH_ENABLE_GC_VERIFY != 0
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.cmake
similarity index 69%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.cmake
index c0b4157f43e..1754a1acaa0 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.cmake
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.cmake
@@ -10,6 +10,14 @@ if (WAMR_BUILD_GC_VERIFY EQUAL 1)
add_definitions (-DBH_ENABLE_GC_VERIFY=1)
endif ()
+if (NOT DEFINED WAMR_BUILD_GC_CORRUPTION_CHECK)
+ set (WAMR_BUILD_GC_CORRUPTION_CHECK 1)
+endif ()
+
+if (WAMR_BUILD_GC_CORRUPTION_CHECK EQUAL 0)
+ add_definitions (-DBH_ENABLE_GC_CORRUPTION_CHECK=0)
+endif ()
+
file (GLOB_RECURSE source_all
${MEM_ALLOC_DIR}/ems/*.c
${MEM_ALLOC_DIR}/tlsf/*.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/README.md
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/README.md
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/README.md
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_platform.c
similarity index 87%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_platform.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_platform.c
index c9f5f17e641..24bf9c7ffb5 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_platform.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_platform.c
@@ -47,7 +47,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
}
void *
-os_mmap(void *hint, size_t size, int prot, int flags)
+os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
{
if ((uint64)size >= UINT32_MAX)
return NULL;
@@ -69,3 +69,7 @@ os_mprotect(void *addr, size_t size, int prot)
void
os_dcache_flush()
{}
+
+void
+os_icache_flush(void *start, size_t len)
+{}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_thread.c
similarity index 99%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_thread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_thread.c
index 0efd2f39448..9fe927db0e7 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_thread.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_thread.c
@@ -359,3 +359,7 @@ os_thread_get_stack_boundary()
/* TODO: get alios stack boundary */
return NULL;
}
+
+void
+os_thread_jit_write_protect_np(bool enabled)
+{}
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_time.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_time.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_time.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/platform_internal.h
similarity index 78%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/platform_internal.h
index f6a4ba11e83..d2897a6b599 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/platform_internal.h
@@ -32,6 +32,12 @@ typedef aos_task_t *aos_tid_t;
typedef aos_mutex_t korp_mutex;
typedef aos_sem_t korp_sem;
+/* korp_rwlock is used in platform_api_extension.h,
+ we just define the type to make the compiler happy */
+typedef struct {
+ int dummy;
+} korp_rwlock;
+
struct os_thread_wait_node;
typedef struct os_thread_wait_node *os_thread_wait_list;
typedef struct korp_cond {
@@ -64,4 +70,16 @@ int signbit(double x);
int isnan(double x);
/* clang-format on */
+/* The below types are used in platform_api_extension.h,
+ we just define them to make the compiler happy */
+typedef int os_file_handle;
+typedef void *os_dir_stream;
+typedef int os_raw_file_handle;
+
+static inline os_file_handle
+os_get_invalid_handle()
+{
+ return -1;
+}
+
#endif /* end of _BH_PLATFORM_H */
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/shared_platform.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/shared_platform.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_init.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_init.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_init.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_internal.h
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_internal.h
index 521fa0c555b..42e4e726c40 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_internal.h
@@ -27,6 +27,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -55,6 +56,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
@@ -138,15 +140,21 @@ seekdir(DIR *__dir, long __location);
#endif
-#if __ANDROID_API__ < 24
-
ssize_t
preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset);
ssize_t
pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset);
-#endif
+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;
+}
#ifdef __cplusplus
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/shared_platform.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/shared_platform.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_malloc.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_malloc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_malloc.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_thread.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_thread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_thread.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_time.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_time.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_time.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/platform_api_freertos.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/platform_api_freertos.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/platform_api_freertos.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/platform_api_freertos.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c
new file mode 100644
index 00000000000..e6c26c839a5
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2023 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "errno.h"
+#include "libc_errno.h"
+
+__wasi_errno_t
+convert_errno(int error)
+{
+ // The C standard library only requires EDOM, EILSEQ and ERANGE to be
+ // defined. Other error codes are POSIX-specific and hence may or may
+ // not be available on non-POSIX platforms.
+ __wasi_errno_t code = __WASI_ENOSYS;
+#define X(v) \
+ case v: \
+ code = __WASI_##v; \
+ break;
+ switch (error) {
+ X(EDOM)
+ X(EILSEQ)
+ X(ERANGE)
+#ifdef E2BIG
+ X(E2BIG)
+#endif
+#ifdef EACCES
+ X(EACCES)
+#endif
+#ifdef EADDRINUSE
+ X(EADDRINUSE)
+#endif
+#ifdef EADDRNOTAVAIL
+ X(EADDRNOTAVAIL)
+#endif
+#ifdef EAFNOSUPPORT
+ X(EAFNOSUPPORT)
+#endif
+#ifdef EAGAIN
+ X(EAGAIN)
+#endif
+#ifdef EALREADY
+ X(EALREADY)
+#endif
+#ifdef EBADF
+ X(EBADF)
+#endif
+#ifdef EBADMSG
+ X(EBADMSG)
+#endif
+#ifdef EBUSY
+ X(EBUSY)
+#endif
+#ifdef ECANCELED
+ X(ECANCELED)
+#endif
+#ifdef ECHILD
+ X(ECHILD)
+#endif
+#ifdef ECONNABORTED
+ X(ECONNABORTED)
+#endif
+#ifdef ECONNREFUSED
+ X(ECONNREFUSED)
+#endif
+#ifdef ECONNRESET
+ X(ECONNRESET)
+#endif
+#ifdef EDEADLK
+ X(EDEADLK)
+#endif
+#ifdef EDESTADDRREQ
+ X(EDESTADDRREQ)
+#endif
+#ifdef EDQUOT
+ X(EDQUOT)
+#endif
+#ifdef EEXIST
+ X(EEXIST)
+#endif
+#ifdef EFAULT
+ X(EFAULT)
+#endif
+#ifdef EFBIG
+ X(EFBIG)
+#endif
+#ifdef EHOSTUNREACH
+ X(EHOSTUNREACH)
+#endif
+#ifdef EIDRM
+ X(EIDRM)
+#endif
+#ifdef EINPROGRESS
+ X(EINPROGRESS)
+#endif
+#ifdef EINTR
+ X(EINTR)
+#endif
+#ifdef EINVAL
+ X(EINVAL)
+#endif
+#ifdef EIO
+ X(EIO)
+#endif
+#ifdef EISCONN
+ X(EISCONN)
+#endif
+#ifdef EISDIR
+ X(EISDIR)
+#endif
+#ifdef ELOOP
+ X(ELOOP)
+#endif
+#ifdef EMFILE
+ X(EMFILE)
+#endif
+#ifdef EMLINK
+ X(EMLINK)
+#endif
+#ifdef EMSGSIZE
+ X(EMSGSIZE)
+#endif
+#ifdef EMULTIHOP
+ X(EMULTIHOP)
+#endif
+#ifdef ENAMETOOLONG
+ X(ENAMETOOLONG)
+#endif
+#ifdef ENETDOWN
+ X(ENETDOWN)
+#endif
+#ifdef ENETRESET
+ X(ENETRESET)
+#endif
+#ifdef ENETUNREACH
+ X(ENETUNREACH)
+#endif
+#ifdef ENFILE
+ X(ENFILE)
+#endif
+#ifdef ENOBUFS
+ X(ENOBUFS)
+#endif
+#ifdef ENODEV
+ X(ENODEV)
+#endif
+#ifdef ENOENT
+ X(ENOENT)
+#endif
+#ifdef ENOEXEC
+ X(ENOEXEC)
+#endif
+#ifdef ENOLCK
+ X(ENOLCK)
+#endif
+#ifdef ENOLINK
+ X(ENOLINK)
+#endif
+#ifdef ENOMEM
+ X(ENOMEM)
+#endif
+#ifdef ENOMSG
+ X(ENOMSG)
+#endif
+#ifdef ENOPROTOOPT
+ X(ENOPROTOOPT)
+#endif
+#ifdef ENOSPC
+ X(ENOSPC)
+#endif
+#ifdef ENOSYS
+ X(ENOSYS)
+#endif
+#ifdef ENOTCAPABLE
+ X(ENOTCAPABLE)
+#endif
+#ifdef ENOTCONN
+ X(ENOTCONN)
+#endif
+#ifdef ENOTDIR
+ X(ENOTDIR)
+#endif
+#ifdef ENOTEMPTY
+ X(ENOTEMPTY)
+#endif
+#ifdef ENOTRECOVERABLE
+ X(ENOTRECOVERABLE)
+#endif
+#ifdef ENOTSOCK
+ X(ENOTSOCK)
+#endif
+#ifdef ENOTSUP
+ X(ENOTSUP)
+#endif
+#ifdef ENOTTY
+ X(ENOTTY)
+#endif
+#ifdef ENXIO
+ X(ENXIO)
+#endif
+#ifdef EOVERFLOW
+ X(EOVERFLOW)
+#endif
+#ifdef EOWNERDEAD
+ X(EOWNERDEAD)
+#endif
+#ifdef EPERM
+ X(EPERM)
+#endif
+#ifdef EPIPE
+ X(EPIPE)
+#endif
+#ifdef EPROTO
+ X(EPROTO)
+#endif
+#ifdef EPROTONOSUPPORT
+ X(EPROTONOSUPPORT)
+#endif
+#ifdef EPROTOTYPE
+ X(EPROTOTYPE)
+#endif
+#ifdef EROFS
+ X(EROFS)
+#endif
+#ifdef ESPIPE
+ X(ESPIPE)
+#endif
+#ifdef ESRCH
+ X(ESRCH)
+#endif
+#ifdef ESTALE
+ X(ESTALE)
+#endif
+#ifdef ETIMEDOUT
+ X(ETIMEDOUT)
+#endif
+#ifdef ETXTBSY
+ X(ETXTBSY)
+#endif
+#ifdef EXDEV
+ X(EXDEV)
+#endif
+ default:
+#ifdef EOPNOTSUPP
+ if (error == EOPNOTSUPP)
+ code = __WASI_ENOTSUP;
+#endif
+#ifdef EWOULDBLOCK
+ if (error == EWOULDBLOCK)
+ code = __WASI_EAGAIN;
+#endif
+ break;
+ }
+#undef X
+ return code;
+}
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h
new file mode 100644
index 00000000000..b0a8b78c6af
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2023 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef WASI_ERRNO_H
+#define WASI_ERRNO_H
+
+#include "platform_wasi_types.h"
+
+// Converts an errno error code to a WASI error code.
+__wasi_errno_t
+convert_errno(int error);
+
+#endif /* end of WASI_ERRNO_H */
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake
new file mode 100644
index 00000000000..a7c7645ce3d
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake
@@ -0,0 +1,8 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set (PLATFORM_COMMON_LIBC_UTIL_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+include_directories(${PLATFORM_COMMON_LIBC_UTIL_DIR})
+
+file (GLOB_RECURSE PLATFORM_COMMON_LIBC_UTIL_SOURCE ${PLATFORM_COMMON_LIBC_UTIL_DIR}/*.c)
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/COPYRIGHT b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/COPYRIGHT
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/COPYRIGHT
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/COPYRIGHT
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/math.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/math.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/math.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/math.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/platform_api_math.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/platform_api_math.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/platform_api_math.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/platform_api_math.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake
new file mode 100644
index 00000000000..2bf9fab4afa
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake
@@ -0,0 +1,19 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set (PLATFORM_COMMON_POSIX_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+file (GLOB_RECURSE source_all ${PLATFORM_COMMON_POSIX_DIR}/*.c)
+
+if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
+ list(REMOVE_ITEM source_all
+ ${PLATFORM_COMMON_POSIX_DIR}/posix_file.c
+ ${PLATFORM_COMMON_POSIX_DIR}/posix_clock.c
+ ${PLATFORM_COMMON_POSIX_DIR}/posix_socket.c
+ )
+else()
+ include (${CMAKE_CURRENT_LIST_DIR}/../libc-util/platform_common_libc_util.cmake)
+ set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE})
+endif()
+
+set (PLATFORM_COMMON_POSIX_SOURCE ${source_all} )
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c
new file mode 100644
index 00000000000..560828a06eb
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "platform_api_extension.h"
+
+#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP
+
+static bool g_blocking_op_inited = false;
+static int g_blocking_op_signo = SIGUSR1;
+static sigset_t g_blocking_op_sigmask;
+
+static void
+blocking_op_sighandler(int signo)
+{
+ /* nothing */
+}
+
+void
+os_set_signal_number_for_blocking_op(int signo)
+{
+ g_blocking_op_signo = signo;
+}
+
+int
+os_blocking_op_init()
+{
+ if (g_blocking_op_inited) {
+ return BHT_OK;
+ }
+
+ sigemptyset(&g_blocking_op_sigmask);
+ sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo);
+
+ struct sigaction sa;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = blocking_op_sighandler;
+ if (sigaction(g_blocking_op_signo, &sa, NULL)) {
+ return BHT_ERROR;
+ }
+ g_blocking_op_inited = true;
+ return BHT_OK;
+}
+
+void
+os_begin_blocking_op()
+{
+ pthread_sigmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL);
+}
+
+void
+os_end_blocking_op()
+{
+ pthread_sigmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL);
+}
+
+int
+os_wakeup_blocking_op(korp_tid tid)
+{
+ int ret = pthread_kill(tid, g_blocking_op_signo);
+ if (ret != 0) {
+ return BHT_ERROR;
+ }
+ return BHT_OK;
+}
+
+#endif /* OS_ENABLE_WAKEUP_BLOCKING_OP */
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c
new file mode 100644
index 00000000000..280306c422c
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2023 Amazon Inc. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "libc_errno.h"
+#include "platform_api_extension.h"
+
+#define NANOSECONDS_PER_SECOND 1000000000ULL
+
+static __wasi_errno_t
+wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out)
+{
+ switch (in) {
+ case __WASI_CLOCK_MONOTONIC:
+ *out = CLOCK_MONOTONIC;
+ return __WASI_ESUCCESS;
+ case __WASI_CLOCK_REALTIME:
+ *out = CLOCK_REALTIME;
+ return __WASI_ESUCCESS;
+ case __WASI_CLOCK_PROCESS_CPUTIME_ID:
+#if defined(CLOCK_PROCESS_CPUTIME_ID)
+ *out = CLOCK_PROCESS_CPUTIME_ID;
+ return __WASI_ESUCCESS;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ case __WASI_CLOCK_THREAD_CPUTIME_ID:
+#if defined(CLOCK_THREAD_CPUTIME_ID)
+ *out = CLOCK_THREAD_CPUTIME_ID;
+ return __WASI_ESUCCESS;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ default:
+ return __WASI_EINVAL;
+ }
+}
+
+static __wasi_timestamp_t
+timespec_to_nanoseconds(const struct timespec *ts)
+{
+ if (ts->tv_sec < 0)
+ return 0;
+ if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / NANOSECONDS_PER_SECOND)
+ return UINT64_MAX;
+ return (__wasi_timestamp_t)ts->tv_sec * NANOSECONDS_PER_SECOND
+ + (__wasi_timestamp_t)ts->tv_nsec;
+}
+
+__wasi_errno_t
+os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution)
+{
+ clockid_t nclock_id;
+ __wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id);
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
+ struct timespec ts;
+ if (clock_getres(nclock_id, &ts) < 0)
+ return convert_errno(errno);
+
+ *resolution = timespec_to_nanoseconds(&ts);
+
+ return error;
+}
+
+__wasi_errno_t
+os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
+ __wasi_timestamp_t *time)
+{
+ clockid_t nclock_id;
+ __wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id);
+
+ if (error != __WASI_ESUCCESS)
+ return error;
+
+ struct timespec ts;
+ if (clock_gettime(nclock_id, &ts) < 0)
+ return convert_errno(errno);
+
+ *time = timespec_to_nanoseconds(&ts);
+
+ return error;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c
new file mode 100644
index 00000000000..8c4f7aa9d24
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c
@@ -0,0 +1,1007 @@
+/*
+ * Copyright (C) 2023 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "platform_api_extension.h"
+#include "libc_errno.h"
+#include
+
+#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
+#define CONFIG_HAS_PWRITEV 1
+#define CONFIG_HAS_PREADV 1
+#else
+#define CONFIG_HAS_PWRITEV 0
+#define CONFIG_HAS_PREADV 0
+#endif
+
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(ESP_PLATFORM)
+#define CONFIG_HAS_FDATASYNC 1
+#else
+#define CONFIG_HAS_FDATASYNC 0
+#endif
+
+/*
+ * For NuttX, CONFIG_HAS_ISATTY is provided by its platform header.
+ * (platform_internal.h)
+ */
+#if !defined(__NuttX__)
+#define CONFIG_HAS_D_INO 1
+#define CONFIG_HAS_ISATTY 1
+#else
+#define CONFIG_HAS_D_INO 0
+#endif
+
+#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(__COSMOPOLITAN__)
+#define CONFIG_HAS_POSIX_FALLOCATE 1
+#else
+#define CONFIG_HAS_POSIX_FALLOCATE 0
+#endif
+
+#if defined(O_DSYNC)
+#define CONFIG_HAS_O_DSYNC
+#endif
+
+// POSIX requires O_RSYNC to be defined, but Linux explicitly doesn't support
+// it.
+#if defined(O_RSYNC) && !defined(__linux__)
+#define CONFIG_HAS_O_RSYNC
+#endif
+
+#if defined(O_SYNC)
+#define CONFIG_HAS_O_SYNC
+#endif
+
+// Converts a POSIX timespec to a WASI timestamp.
+static __wasi_timestamp_t
+convert_timespec(const struct timespec *ts)
+{
+ if (ts->tv_sec < 0)
+ return 0;
+ if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / 1000000000)
+ return UINT64_MAX;
+ return (__wasi_timestamp_t)ts->tv_sec * 1000000000
+ + (__wasi_timestamp_t)ts->tv_nsec;
+}
+
+// Converts a POSIX stat structure to a WASI filestat structure
+static void
+convert_stat(os_file_handle handle, const struct stat *in,
+ __wasi_filestat_t *out)
+{
+ out->st_dev = in->st_dev;
+ out->st_ino = in->st_ino;
+ out->st_nlink = (__wasi_linkcount_t)in->st_nlink;
+ out->st_size = (__wasi_filesize_t)in->st_size;
+#ifdef __APPLE__
+ out->st_atim = convert_timespec(&in->st_atimespec);
+ out->st_mtim = convert_timespec(&in->st_mtimespec);
+ out->st_ctim = convert_timespec(&in->st_ctimespec);
+#else
+ out->st_atim = convert_timespec(&in->st_atim);
+ out->st_mtim = convert_timespec(&in->st_mtim);
+ out->st_ctim = convert_timespec(&in->st_ctim);
+#endif
+
+ // Convert the file type. In the case of sockets there is no way we
+ // can easily determine the exact socket type.
+ if (S_ISBLK(in->st_mode)) {
+ out->st_filetype = __WASI_FILETYPE_BLOCK_DEVICE;
+ }
+ else if (S_ISCHR(in->st_mode)) {
+ out->st_filetype = __WASI_FILETYPE_CHARACTER_DEVICE;
+ }
+ else if (S_ISDIR(in->st_mode)) {
+ out->st_filetype = __WASI_FILETYPE_DIRECTORY;
+ }
+ else if (S_ISFIFO(in->st_mode)) {
+ out->st_filetype = __WASI_FILETYPE_SOCKET_STREAM;
+ }
+ else if (S_ISLNK(in->st_mode)) {
+ out->st_filetype = __WASI_FILETYPE_SYMBOLIC_LINK;
+ }
+ else if (S_ISREG(in->st_mode)) {
+ out->st_filetype = __WASI_FILETYPE_REGULAR_FILE;
+ }
+ else if (S_ISSOCK(in->st_mode)) {
+ int socktype;
+ socklen_t socktypelen = sizeof(socktype);
+
+ if (getsockopt(handle, SOL_SOCKET, SO_TYPE, &socktype, &socktypelen)
+ < 0) {
+ out->st_filetype = __WASI_FILETYPE_UNKNOWN;
+ return;
+ }
+
+ switch (socktype) {
+ case SOCK_DGRAM:
+ out->st_filetype = __WASI_FILETYPE_SOCKET_DGRAM;
+ break;
+ case SOCK_STREAM:
+ out->st_filetype = __WASI_FILETYPE_SOCKET_STREAM;
+ break;
+ default:
+ out->st_filetype = __WASI_FILETYPE_UNKNOWN;
+ return;
+ }
+ }
+ else {
+ out->st_filetype = __WASI_FILETYPE_UNKNOWN;
+ }
+}
+
+static void
+convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
+{
+ // Store sub-second remainder.
+#if defined(__SYSCALL_SLONG_TYPE)
+ out->tv_nsec = (__SYSCALL_SLONG_TYPE)(in % 1000000000);
+#else
+ out->tv_nsec = (long)(in % 1000000000);
+#endif
+ in /= 1000000000;
+
+ // Clamp to the maximum in case it would overflow our system's time_t.
+ out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
+}
+
+// Converts the provided timestamps and flags to a set of arguments for
+// futimens() and utimensat().
+static void
+convert_utimens_arguments(__wasi_timestamp_t st_atim,
+ __wasi_timestamp_t st_mtim,
+ __wasi_fstflags_t fstflags, struct timespec *ts)
+{
+ if ((fstflags & __WASI_FILESTAT_SET_ATIM_NOW) != 0) {
+ ts[0].tv_nsec = UTIME_NOW;
+ }
+ else if ((fstflags & __WASI_FILESTAT_SET_ATIM) != 0) {
+ convert_timestamp(st_atim, &ts[0]);
+ }
+ else {
+ ts[0].tv_nsec = UTIME_OMIT;
+ }
+
+ if ((fstflags & __WASI_FILESTAT_SET_MTIM_NOW) != 0) {
+ ts[1].tv_nsec = UTIME_NOW;
+ }
+ else if ((fstflags & __WASI_FILESTAT_SET_MTIM) != 0) {
+ convert_timestamp(st_mtim, &ts[1]);
+ }
+ else {
+ ts[1].tv_nsec = UTIME_OMIT;
+ }
+}
+
+__wasi_errno_t
+os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf)
+{
+ struct stat stat_buf;
+ int ret = fstat(handle, &stat_buf);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ convert_stat(handle, &stat_buf, buf);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_fstatat(os_file_handle handle, const char *path,
+ struct __wasi_filestat_t *buf, __wasi_lookupflags_t lookup_flags)
+{
+ struct stat stat_buf;
+ int ret = fstatat(handle, path, &stat_buf,
+ (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW)
+ ? AT_SYMLINK_FOLLOW
+ : AT_SYMLINK_NOFOLLOW);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ convert_stat(handle, &stat_buf, buf);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_file_get_fdflags(os_file_handle handle, __wasi_fdflags_t *flags)
+{
+ int ret = fcntl(handle, F_GETFL);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ *flags = 0;
+
+ if ((ret & O_APPEND) != 0)
+ *flags |= __WASI_FDFLAG_APPEND;
+#ifdef CONFIG_HAS_O_DSYNC
+ if ((ret & O_DSYNC) != 0)
+ *flags |= __WASI_FDFLAG_DSYNC;
+#endif
+ if ((ret & O_NONBLOCK) != 0)
+ *flags |= __WASI_FDFLAG_NONBLOCK;
+#ifdef CONFIG_HAS_O_RSYNC
+ if ((ret & O_RSYNC) != 0)
+ *flags |= __WASI_FDFLAG_RSYNC;
+#endif
+#ifdef CONFIG_HAS_O_SYNC
+ if ((ret & O_SYNC) != 0)
+ *flags |= __WASI_FDFLAG_SYNC;
+#endif
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_file_set_fdflags(os_file_handle handle, __wasi_fdflags_t flags)
+{
+ int fcntl_flags = 0;
+
+ if ((flags & __WASI_FDFLAG_APPEND) != 0)
+ fcntl_flags |= O_APPEND;
+ if ((flags & __WASI_FDFLAG_DSYNC) != 0)
+#ifdef CONFIG_HAS_O_DSYNC
+ fcntl_flags |= O_DSYNC;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ if ((flags & __WASI_FDFLAG_NONBLOCK) != 0)
+ fcntl_flags |= O_NONBLOCK;
+ if ((flags & __WASI_FDFLAG_RSYNC) != 0)
+#ifdef CONFIG_HAS_O_RSYNC
+ fcntl_flags |= O_RSYNC;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ if ((flags & __WASI_FDFLAG_SYNC) != 0)
+#ifdef CONFIG_HAS_O_SYNC
+ fcntl_flags |= O_SYNC;
+#else
+ return __WASI_ENOTSUP;
+#endif
+
+ int ret = fcntl(handle, F_SETFL, fcntl_flags);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_fdatasync(os_file_handle handle)
+{
+#if CONFIG_HAS_FDATASYNC
+ int ret = fdatasync(handle);
+#else
+ int ret = fsync(handle);
+#endif
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_fsync(os_file_handle handle)
+{
+ int ret = fsync(handle);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_open_preopendir(const char *path, os_file_handle *out)
+{
+
+ int fd = open(path, O_RDONLY | O_DIRECTORY, 0);
+
+ if (fd < 0)
+ return convert_errno(errno);
+
+ *out = fd;
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags,
+ __wasi_fdflags_t fs_flags, __wasi_lookupflags_t lookup_flags,
+ wasi_libc_file_access_mode read_write_mode, os_file_handle *out)
+{
+ int open_flags = 0;
+
+ // Convert open flags.
+ if ((oflags & __WASI_O_CREAT) != 0) {
+ open_flags |= O_CREAT;
+ }
+ if ((oflags & __WASI_O_DIRECTORY) != 0)
+ open_flags |= O_DIRECTORY;
+ if ((oflags & __WASI_O_EXCL) != 0)
+ open_flags |= O_EXCL;
+ if ((oflags & __WASI_O_TRUNC) != 0) {
+ open_flags |= O_TRUNC;
+ }
+
+ // Convert file descriptor flags.
+ if ((fs_flags & __WASI_FDFLAG_APPEND) != 0)
+ open_flags |= O_APPEND;
+ if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) {
+#ifdef CONFIG_HAS_O_DSYNC
+ open_flags |= O_DSYNC;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ }
+ if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0)
+ open_flags |= O_NONBLOCK;
+ if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0) {
+#ifdef CONFIG_HAS_O_RSYNC
+ open_flags |= O_RSYNC;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ }
+ if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) {
+#ifdef CONFIG_HAS_O_SYNC
+ open_flags |= O_SYNC;
+#else
+ return __WASI_ENOTSUP;
+#endif
+ }
+
+ if ((lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) == 0) {
+ open_flags |= O_NOFOLLOW;
+ }
+
+ switch (read_write_mode) {
+ case WASI_LIBC_ACCESS_MODE_READ_WRITE:
+ open_flags |= O_RDWR;
+ break;
+ case WASI_LIBC_ACCESS_MODE_READ_ONLY:
+ open_flags |= O_RDONLY;
+ break;
+ case WASI_LIBC_ACCESS_MODE_WRITE_ONLY:
+ open_flags |= O_WRONLY;
+ break;
+ default:
+ return __WASI_EINVAL;
+ }
+
+ int fd = openat(handle, path, open_flags, 0666);
+
+ if (fd < 0) {
+ int openat_errno = errno;
+ // Linux returns ENXIO instead of EOPNOTSUPP when opening a socket.
+ if (openat_errno == ENXIO) {
+ struct stat sb;
+ int ret = fstatat(fd, path, &sb,
+ (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW)
+ ? 0
+ : AT_SYMLINK_NOFOLLOW);
+ return ret == 0 && S_ISSOCK(sb.st_mode) ? __WASI_ENOTSUP
+ : __WASI_ENXIO;
+ }
+ // Linux returns ENOTDIR instead of ELOOP when using
+ // O_NOFOLLOW|O_DIRECTORY on a symlink.
+ if (openat_errno == ENOTDIR
+ && (open_flags & (O_NOFOLLOW | O_DIRECTORY)) != 0) {
+ struct stat sb;
+ int ret = fstatat(fd, path, &sb, AT_SYMLINK_NOFOLLOW);
+ if (S_ISLNK(sb.st_mode)) {
+ return __WASI_ELOOP;
+ }
+ (void)ret;
+ }
+ // FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on
+ // a symlink.
+ if ((lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) == 0
+ && openat_errno == EMLINK)
+ return __WASI_ELOOP;
+
+ return convert_errno(openat_errno);
+ }
+
+ *out = fd;
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_file_get_access_mode(os_file_handle handle,
+ wasi_libc_file_access_mode *access_mode)
+{
+ int ret = fcntl(handle, F_GETFL, 0);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ switch (ret & O_ACCMODE) {
+ case O_RDONLY:
+ *access_mode = WASI_LIBC_ACCESS_MODE_READ_ONLY;
+ break;
+ case O_WRONLY:
+ *access_mode = WASI_LIBC_ACCESS_MODE_WRITE_ONLY;
+ break;
+ case O_RDWR:
+ *access_mode = WASI_LIBC_ACCESS_MODE_READ_WRITE;
+ break;
+ default:
+ return __WASI_EINVAL;
+ }
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_close(os_file_handle handle, bool is_stdio)
+{
+ if (is_stdio)
+ return __WASI_ESUCCESS;
+
+ int ret = close(handle);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nread)
+{
+#if CONFIG_HAS_PREADV
+ ssize_t len =
+ preadv(handle, (const struct iovec *)iov, (int)iovcnt, (off_t)offset);
+ if (len < 0)
+ return convert_errno(errno);
+
+ *nread = (size_t)len;
+ return __WASI_ESUCCESS;
+#else
+ if (iovcnt == 1) {
+ ssize_t len = pread(handle, iov->buf, iov->buf_len, offset);
+
+ if (len < 0)
+ return convert_errno(errno);
+
+ *nread = len;
+ return __WASI_ESUCCESS;
+ }
+
+ // Allocate a single buffer to fit all data.
+ size_t totalsize = 0;
+ for (int i = 0; i < iovcnt; ++i)
+ totalsize += iov[i].buf_len;
+
+ char *buf = BH_MALLOC(totalsize);
+
+ if (buf == NULL) {
+ return __WASI_ENOMEM;
+ }
+
+ // Perform a single read operation.
+ ssize_t len = pread(handle, buf, totalsize, offset);
+
+ if (len < 0) {
+ BH_FREE(buf);
+ return convert_errno(errno);
+ }
+
+ // Copy data back to vectors.
+ size_t bufoff = 0;
+ for (int i = 0; i < iovcnt; ++i) {
+ if (bufoff + iov[i].buf_len < (size_t)len) {
+ memcpy(iov[i].buf, buf + bufoff, iov[i].buf_len);
+ bufoff += iov[i].buf_len;
+ }
+ else {
+ memcpy(iov[i].buf, buf + bufoff, len - bufoff);
+ break;
+ }
+ }
+ BH_FREE(buf);
+ *nread = len;
+
+ return __WASI_ESUCCESS;
+#endif
+}
+
+__wasi_errno_t
+os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nwritten)
+{
+ if (iovcnt == 0)
+ return __WASI_EINVAL;
+
+ ssize_t len = 0;
+#if CONFIG_HAS_PWRITEV
+ len =
+ pwritev(handle, (const struct iovec *)iov, (int)iovcnt, (off_t)offset);
+#else
+ if (iovcnt == 1) {
+ len = pwrite(handle, iov->buf, iov->buf_len, offset);
+ }
+ else {
+ // Allocate a single buffer to fit all data.
+ size_t totalsize = 0;
+ for (int i = 0; i < iovcnt; ++i)
+ totalsize += iov[i].buf_len;
+ char *buf = BH_MALLOC(totalsize);
+ if (buf == NULL) {
+ return __WASI_ENOMEM;
+ }
+ size_t bufoff = 0;
+ for (int i = 0; i < iovcnt; ++i) {
+ memcpy(buf + bufoff, iov[i].buf, iov[i].buf_len);
+ bufoff += iov[i].buf_len;
+ }
+
+ // Perform a single write operation.
+ len = pwrite(handle, buf, totalsize, offset);
+ BH_FREE(buf);
+ }
+#endif
+ if (len < 0)
+ return convert_errno(errno);
+
+ *nwritten = (size_t)len;
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
+ size_t *nread)
+{
+ ssize_t len = readv(handle, (const struct iovec *)iov, (int)iovcnt);
+
+ if (len < 0)
+ return convert_errno(errno);
+
+ *nread = (size_t)len;
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
+ size_t *nwritten)
+{
+ ssize_t len = writev(handle, (const struct iovec *)iov, (int)iovcnt);
+
+ if (len < 0)
+ return convert_errno(errno);
+
+ *nwritten = (size_t)len;
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_fallocate(os_file_handle handle, __wasi_filesize_t offset,
+ __wasi_filesize_t length)
+{
+#if CONFIG_HAS_POSIX_FALLOCATE
+ int ret = posix_fallocate(handle, (off_t)offset, (off_t)length);
+#else
+ // At least ensure that the file is grown to the right size.
+ // TODO(ed): See if this can somehow be implemented without any race
+ // conditions. We may end up shrinking the file right now.
+ struct stat sb;
+ int ret = fstat(handle, &sb);
+ off_t newsize = (off_t)(offset + length);
+
+ if (ret == 0 && sb.st_size < newsize)
+ ret = ftruncate(handle, newsize);
+#endif
+
+ if (ret != 0)
+ return convert_errno(ret);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_ftruncate(os_file_handle handle, __wasi_filesize_t size)
+{
+ int ret = ftruncate(handle, (off_t)size);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_futimens(os_file_handle handle, __wasi_timestamp_t access_time,
+ __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags)
+{
+ struct timespec ts[2];
+ convert_utimens_arguments(access_time, modification_time, fstflags, ts);
+
+ int ret = futimens(handle, ts);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_utimensat(os_file_handle handle, const char *path,
+ __wasi_timestamp_t access_time,
+ __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags,
+ __wasi_lookupflags_t lookup_flags)
+{
+ struct timespec ts[2];
+ convert_utimens_arguments(access_time, modification_time, fstflags, ts);
+
+ int ret = utimensat(handle, path, ts,
+ (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW)
+ ? 0
+ : AT_SYMLINK_NOFOLLOW);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_readlinkat(os_file_handle handle, const char *path, char *buf,
+ size_t bufsize, size_t *nread)
+{
+ // Linux requires that the buffer size is positive. whereas POSIX does
+ // not. Use a fake buffer to store the results if the size is zero.
+ char fakebuf[1];
+ ssize_t len = readlinkat(handle, path, bufsize == 0 ? fakebuf : buf,
+ bufsize == 0 ? sizeof(fakebuf) : bufsize);
+
+ if (len < 0)
+ return convert_errno(errno);
+
+ *nread = (size_t)len < bufsize ? (size_t)len : bufsize;
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_linkat(os_file_handle from_handle, const char *from_path,
+ os_file_handle to_handle, const char *to_path,
+ __wasi_lookupflags_t lookup_flags)
+{
+ int ret = linkat(
+ from_handle, from_path, to_handle, to_path,
+ (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) ? AT_SYMLINK_FOLLOW : 0);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_symlinkat(const char *old_path, os_file_handle handle, const char *new_path)
+{
+ int ret = symlinkat(old_path, handle, new_path);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_mkdirat(os_file_handle handle, const char *path)
+{
+ int ret = mkdirat(handle, path, 0777);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_renameat(os_file_handle old_handle, const char *old_path,
+ os_file_handle new_handle, const char *new_path)
+{
+
+ int ret = renameat(old_handle, old_path, new_handle, new_path);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_unlinkat(os_file_handle handle, const char *path, bool is_dir)
+{
+ int ret = unlinkat(handle, path, is_dir ? AT_REMOVEDIR : 0);
+
+#ifndef __linux__
+ if (ret < 0) {
+ // Non-Linux implementations may return EPERM when attempting to remove
+ // a directory without REMOVEDIR. While that's what POSIX specifies,
+ // it's less useful. Adjust this to EISDIR. It doesn't matter that this
+ // is not atomic with the unlinkat, because if the file is removed and a
+ // directory is created before fstatat sees it, we're racing with that
+ // change anyway and unlinkat could have legitimately seen the directory
+ // if the race had turned out differently.
+ if (errno == EPERM) {
+ struct stat statbuf;
+ if (fstatat(handle, path, &statbuf, AT_SYMLINK_NOFOLLOW) == 0
+ && S_ISDIR(statbuf.st_mode)) {
+ errno = EISDIR;
+ }
+ }
+ // POSIX permits either EEXIST or ENOTEMPTY when the directory is not
+ // empty. Map it to ENOTEMPTY.
+ else if (errno == EEXIST) {
+ errno = ENOTEMPTY;
+ }
+
+ return convert_errno(errno);
+ }
+#endif
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_lseek(os_file_handle handle, __wasi_filedelta_t offset,
+ __wasi_whence_t whence, __wasi_filesize_t *new_offset)
+{
+ int nwhence;
+
+ switch (whence) {
+ case __WASI_WHENCE_CUR:
+ nwhence = SEEK_CUR;
+ break;
+ case __WASI_WHENCE_END:
+ nwhence = SEEK_END;
+ break;
+ case __WASI_WHENCE_SET:
+ nwhence = SEEK_SET;
+ break;
+ default:
+ return __WASI_EINVAL;
+ }
+
+ off_t ret = lseek(handle, offset, nwhence);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ *new_offset = (__wasi_filesize_t)ret;
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_fadvise(os_file_handle handle, __wasi_filesize_t offset,
+ __wasi_filesize_t length, __wasi_advice_t advice)
+{
+#ifdef POSIX_FADV_NORMAL
+ int nadvice;
+ switch (advice) {
+ case __WASI_ADVICE_DONTNEED:
+ nadvice = POSIX_FADV_DONTNEED;
+ break;
+ case __WASI_ADVICE_NOREUSE:
+ nadvice = POSIX_FADV_NOREUSE;
+ break;
+ case __WASI_ADVICE_NORMAL:
+ nadvice = POSIX_FADV_NORMAL;
+ break;
+ case __WASI_ADVICE_RANDOM:
+ nadvice = POSIX_FADV_RANDOM;
+ break;
+ case __WASI_ADVICE_SEQUENTIAL:
+ nadvice = POSIX_FADV_SEQUENTIAL;
+ break;
+ case __WASI_ADVICE_WILLNEED:
+ nadvice = POSIX_FADV_WILLNEED;
+ break;
+ default:
+ return __WASI_EINVAL;
+ }
+
+ int ret = posix_fadvise(handle, (off_t)offset, (off_t)length, nadvice);
+
+ if (ret < 0)
+ return convert_errno(ret);
+
+ return __WASI_ESUCCESS;
+#else
+ // Advisory information can be safely ignored if not supported
+ switch (advice) {
+ case __WASI_ADVICE_DONTNEED:
+ case __WASI_ADVICE_NOREUSE:
+ case __WASI_ADVICE_NORMAL:
+ case __WASI_ADVICE_RANDOM:
+ case __WASI_ADVICE_SEQUENTIAL:
+ case __WASI_ADVICE_WILLNEED:
+ return __WASI_ESUCCESS;
+ default:
+ return __WASI_EINVAL;
+ }
+#endif
+}
+
+__wasi_errno_t
+os_isatty(os_file_handle handle)
+{
+#if CONFIG_HAS_ISATTY
+ int ret = isatty(handle);
+
+ if (ret == 1)
+ return __WASI_ESUCCESS;
+
+ return __WASI_ENOTTY;
+#else
+ return __WASI_ENOTSUP;
+#endif
+}
+
+os_file_handle
+os_convert_stdin_handle(os_raw_file_handle raw_stdin)
+{
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+ return raw_stdin >= 0 ? raw_stdin : STDIN_FILENO;
+}
+
+os_file_handle
+os_convert_stdout_handle(os_raw_file_handle raw_stdout)
+{
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+ return raw_stdout >= 0 ? raw_stdout : STDOUT_FILENO;
+}
+
+os_file_handle
+os_convert_stderr_handle(os_raw_file_handle raw_stderr)
+{
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+ return raw_stderr >= 0 ? raw_stderr : STDERR_FILENO;
+}
+
+__wasi_errno_t
+os_fdopendir(os_file_handle handle, os_dir_stream *dir_stream)
+{
+ *dir_stream = fdopendir(handle);
+
+ if (*dir_stream == NULL)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_rewinddir(os_dir_stream dir_stream)
+{
+ rewinddir(dir_stream);
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_seekdir(os_dir_stream dir_stream, __wasi_dircookie_t position)
+{
+ seekdir(dir_stream, (long)position);
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry,
+ const char **d_name)
+{
+ errno = 0;
+
+ struct dirent *dent = readdir(dir_stream);
+
+ if (dent == NULL) {
+ *d_name = NULL;
+ return convert_errno(errno);
+ }
+
+ long offset = (__wasi_dircookie_t)telldir(dir_stream);
+
+ size_t namlen = strlen(dent->d_name);
+
+ *d_name = dent->d_name;
+ entry->d_next = offset;
+ entry->d_namlen = (__wasi_dirnamlen_t)namlen;
+#if CONFIG_HAS_D_INO
+ entry->d_ino = dent->d_ino;
+#else
+ entry->d_ino = 0;
+#endif
+
+ switch (dent->d_type) {
+ case DT_BLK:
+ entry->d_type = __WASI_FILETYPE_BLOCK_DEVICE;
+ break;
+ case DT_CHR:
+ entry->d_type = __WASI_FILETYPE_CHARACTER_DEVICE;
+ break;
+ case DT_DIR:
+ entry->d_type = __WASI_FILETYPE_DIRECTORY;
+ break;
+ case DT_FIFO:
+ entry->d_type = __WASI_FILETYPE_SOCKET_STREAM;
+ break;
+ case DT_LNK:
+ entry->d_type = __WASI_FILETYPE_SYMBOLIC_LINK;
+ break;
+ case DT_REG:
+ entry->d_type = __WASI_FILETYPE_REGULAR_FILE;
+ break;
+#ifdef DT_SOCK
+ case DT_SOCK:
+ // Technically not correct, but good enough.
+ entry->d_type = __WASI_FILETYPE_SOCKET_STREAM;
+ break;
+#endif
+ default:
+ entry->d_type = __WASI_FILETYPE_UNKNOWN;
+ break;
+ }
+
+ return __WASI_ESUCCESS;
+}
+
+__wasi_errno_t
+os_closedir(os_dir_stream dir_stream)
+{
+ int ret = closedir(dir_stream);
+
+ if (ret < 0)
+ return convert_errno(errno);
+
+ return __WASI_ESUCCESS;
+}
+
+os_dir_stream
+os_get_invalid_dir_stream()
+{
+ return NULL;
+}
+
+bool
+os_is_dir_stream_valid(os_dir_stream *dir_stream)
+{
+ assert(dir_stream != NULL);
+
+ return *dir_stream != NULL;
+}
+
+bool
+os_is_handle_valid(os_file_handle *handle)
+{
+ assert(handle != NULL);
+
+ return *handle > -1;
+}
+
+char *
+os_realpath(const char *path, char *resolved_path)
+{
+ return realpath(path, resolved_path);
+}
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_malloc.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_malloc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_malloc.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_memmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_memmap.c
similarity index 93%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_memmap.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_memmap.c
index 2dfbee453f7..583557bb855 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_memmap.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_memmap.c
@@ -5,6 +5,10 @@
#include "platform_api_vmcore.h"
+#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__)
+#include
+#endif
+
#ifndef BH_ENABLE_TRACE_MMAP
#define BH_ENABLE_TRACE_MMAP 0
#endif
@@ -33,10 +37,14 @@ round_down(uintptr_t v, uintptr_t b)
#endif
void *
-os_mmap(void *hint, size_t size, int prot, int flags)
+os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
{
int map_prot = PROT_NONE;
+#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__)
+ int map_flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_JIT;
+#else
int map_flags = MAP_ANONYMOUS | MAP_PRIVATE;
+#endif
uint64 request_size, page_size;
uint8 *addr = MAP_FAILED;
uint32 i;
@@ -106,7 +114,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
/* try 10 times, step with 1MB each time */
for (i = 0; i < 10 && hint_addr < (uint8 *)(uintptr_t)(2ULL * BH_GB);
i++) {
- addr = mmap(hint_addr, request_size, map_prot, map_flags, -1, 0);
+ addr = mmap(hint_addr, request_size, map_prot, map_flags, file, 0);
if (addr != MAP_FAILED) {
if (addr > (uint8 *)(uintptr_t)(2ULL * BH_GB)) {
/* unmap and try again if the mapped address doesn't
@@ -128,7 +136,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
if (addr == MAP_FAILED) {
/* try 5 times */
for (i = 0; i < 5; i++) {
- addr = mmap(hint, request_size, map_prot, map_flags, -1, 0);
+ addr = mmap(hint, request_size, map_prot, map_flags, file, 0);
if (addr != MAP_FAILED)
break;
}
@@ -251,3 +259,11 @@ os_mprotect(void *addr, size_t size, int prot)
void
os_dcache_flush(void)
{}
+
+void
+os_icache_flush(void *start, size_t len)
+{
+#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__)
+ sys_icache_invalidate(start, len);
+#endif
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c
new file mode 100644
index 00000000000..fa0645037a8
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include
+
+#include "platform_api_extension.h"
+
+int
+os_usleep(uint32 usec)
+{
+ struct timespec ts;
+ int ret;
+
+ ts.tv_sec = usec / 1000000;
+ ts.tv_nsec = (usec % 1000000) * 1000;
+ ret = nanosleep(&ts, NULL);
+ return ret == 0 ? 0 : -1;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_socket.c
similarity index 96%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_socket.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_socket.c
index e33781d7d2e..7bdcb529e61 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_socket.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_socket.c
@@ -5,6 +5,7 @@
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
+#include "libc_errno.h"
#include
#include
@@ -53,7 +54,7 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr,
struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr;
bh_sockaddr->port = ntohs(addr->sin_port);
- bh_sockaddr->addr_bufer.ipv4 = ntohl(addr->sin_addr.s_addr);
+ bh_sockaddr->addr_buffer.ipv4 = ntohl(addr->sin_addr.s_addr);
bh_sockaddr->is_ipv4 = true;
return BHT_OK;
}
@@ -65,12 +66,12 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr,
bh_sockaddr->port = ntohs(addr->sin6_port);
- for (i = 0; i < sizeof(bh_sockaddr->addr_bufer.ipv6)
- / sizeof(bh_sockaddr->addr_bufer.ipv6[0]);
+ for (i = 0; i < sizeof(bh_sockaddr->addr_buffer.ipv6)
+ / sizeof(bh_sockaddr->addr_buffer.ipv6[0]);
i++) {
uint16 part_addr = addr->sin6_addr.s6_addr[i * 2]
| (addr->sin6_addr.s6_addr[i * 2 + 1] << 8);
- bh_sockaddr->addr_bufer.ipv6[i] = ntohs(part_addr);
+ bh_sockaddr->addr_buffer.ipv6[i] = ntohs(part_addr);
}
bh_sockaddr->is_ipv4 = false;
@@ -91,7 +92,7 @@ bh_sockaddr_to_sockaddr(const bh_sockaddr_t *bh_sockaddr,
struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr;
addr->sin_port = htons(bh_sockaddr->port);
addr->sin_family = AF_INET;
- addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_bufer.ipv4);
+ addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_buffer.ipv4);
*socklen = sizeof(*addr);
}
#ifdef IPPROTO_IPV6
@@ -101,10 +102,10 @@ bh_sockaddr_to_sockaddr(const bh_sockaddr_t *bh_sockaddr,
addr->sin6_port = htons(bh_sockaddr->port);
addr->sin6_family = AF_INET6;
- for (i = 0; i < sizeof(bh_sockaddr->addr_bufer.ipv6)
- / sizeof(bh_sockaddr->addr_bufer.ipv6[0]);
+ for (i = 0; i < sizeof(bh_sockaddr->addr_buffer.ipv6)
+ / sizeof(bh_sockaddr->addr_buffer.ipv6[0]);
i++) {
- uint16 part_addr = htons(bh_sockaddr->addr_bufer.ipv6[i]);
+ uint16 part_addr = htons(bh_sockaddr->addr_buffer.ipv6[i]);
addr->sin6_addr.s6_addr[i * 2] = 0xff & part_addr;
addr->sin6_addr.s6_addr[i * 2 + 1] = (0xff00 & part_addr) >> 8;
}
@@ -275,6 +276,9 @@ os_socket_recv_from(bh_socket_t socket, void *buf, unsigned int len, int flags,
return -1;
}
}
+ else if (src_addr) {
+ memset(src_addr, 0, sizeof(*src_addr));
+ }
return ret;
}
@@ -305,11 +309,13 @@ os_socket_close(bh_socket_t socket)
return BHT_OK;
}
-int
+__wasi_errno_t
os_socket_shutdown(bh_socket_t socket)
{
- shutdown(socket, O_RDWR);
- return BHT_OK;
+ if (shutdown(socket, O_RDWR) != 0) {
+ return convert_errno(errno);
+ }
+ return __WASI_ESUCCESS;
}
int
@@ -796,7 +802,7 @@ os_socket_set_ip_add_membership(bh_socket_t socket,
{
assert(imr_multiaddr);
if (is_ipv6) {
-#ifdef IPPROTO_IPV6
+#if defined(IPPROTO_IPV6) && !defined(BH_PLATFORM_COSMOPOLITAN)
struct ipv6_mreq mreq;
for (int i = 0; i < 8; i++) {
((uint16_t *)mreq.ipv6mr_multiaddr.s6_addr)[i] =
@@ -834,7 +840,7 @@ os_socket_set_ip_drop_membership(bh_socket_t socket,
{
assert(imr_multiaddr);
if (is_ipv6) {
-#ifdef IPPROTO_IPV6
+#if defined(IPPROTO_IPV6) && !defined(BH_PLATFORM_COSMOPOLITAN)
struct ipv6_mreq mreq;
for (int i = 0; i < 8; i++) {
((uint16_t *)mreq.ipv6mr_multiaddr.s6_addr)[i] =
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_thread.c
similarity index 86%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_thread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_thread.c
index 5e814c41824..616420c948c 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_thread.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_thread.c
@@ -39,6 +39,9 @@ os_thread_wrapper(void *arg)
#ifdef OS_ENABLE_HW_BOUND_CHECK
if (os_thread_signal_init(handler) != 0)
return NULL;
+#endif
+#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP
+ os_end_blocking_op();
#endif
start_func(thread_arg);
#ifdef OS_ENABLE_HW_BOUND_CHECK
@@ -326,6 +329,61 @@ os_cond_broadcast(korp_cond *cond)
return BHT_OK;
}
+int
+os_rwlock_init(korp_rwlock *lock)
+{
+ assert(lock);
+
+ if (pthread_rwlock_init(lock, NULL) != BHT_OK)
+ return BHT_ERROR;
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_rdlock(korp_rwlock *lock)
+{
+ assert(lock);
+
+ if (pthread_rwlock_rdlock(lock) != BHT_OK)
+ return BHT_ERROR;
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_wrlock(korp_rwlock *lock)
+{
+ assert(lock);
+
+ if (pthread_rwlock_wrlock(lock) != BHT_OK)
+ return BHT_ERROR;
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_unlock(korp_rwlock *lock)
+{
+ assert(lock);
+
+ if (pthread_rwlock_unlock(lock) != BHT_OK)
+ return BHT_ERROR;
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_destroy(korp_rwlock *lock)
+{
+ assert(lock);
+
+ if (pthread_rwlock_destroy(lock) != BHT_OK)
+ return BHT_ERROR;
+
+ return BHT_OK;
+}
+
int
os_thread_join(korp_tid thread, void **value_ptr)
{
@@ -415,6 +473,14 @@ os_thread_get_stack_boundary()
return addr;
}
+void
+os_thread_jit_write_protect_np(bool enabled)
+{
+#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__)
+ pthread_jit_write_protect_np(enabled);
+#endif
+}
+
#ifdef OS_ENABLE_HW_BOUND_CHECK
#define SIG_ALT_STACK_SIZE (32 * 1024)
@@ -430,8 +496,14 @@ static os_thread_local_attribute bool thread_signal_inited = false;
/* The signal alternate stack base addr */
static os_thread_local_attribute uint8 *sigalt_stack_base_addr;
+/*
+ * ASAN is not designed to work with custom stack unwind or other low-level
+ * things. Ignore a function that does some low-level magic. (e.g. walking
+ * through the thread's stack bypassing the frame boundaries)
+ */
#if defined(__clang__)
#pragma clang optimize off
+__attribute__((no_sanitize_address))
#elif defined(__GNUC__)
#pragma GCC push_options
#pragma GCC optimize("O0")
@@ -492,6 +564,14 @@ destroy_stack_guard_pages()
}
#endif /* end of WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 */
+/*
+ * ASAN is not designed to work with custom stack unwind or other low-level
+ * things. Ignore a function that does some low-level magic. (e.g. walking
+ * through the thread's stack bypassing the frame boundaries)
+ */
+#if defined(__GNUC__) || defined(__clang__)
+__attribute__((no_sanitize_address))
+#endif
static void
mask_signals(int how)
{
@@ -503,9 +583,17 @@ mask_signals(int how)
pthread_sigmask(how, &set, NULL);
}
-static os_thread_local_attribute struct sigaction prev_sig_act_SIGSEGV;
-static os_thread_local_attribute struct sigaction prev_sig_act_SIGBUS;
+static struct sigaction prev_sig_act_SIGSEGV;
+static struct sigaction prev_sig_act_SIGBUS;
+/*
+ * ASAN is not designed to work with custom stack unwind or other low-level
+ * things. Ignore a function that does some low-level magic. (e.g. walking
+ * through the thread's stack bypassing the frame boundaries)
+ */
+#if defined(__GNUC__) || defined(__clang__)
+__attribute__((no_sanitize_address))
+#endif
static void
signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext)
{
@@ -529,9 +617,12 @@ signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext)
prev_sig_act->sa_sigaction(sig_num, sig_info, sig_ucontext);
}
else if (prev_sig_act
- && ((void *)prev_sig_act->sa_sigaction == SIG_DFL
- || (void *)prev_sig_act->sa_sigaction == SIG_IGN)) {
- sigaction(sig_num, prev_sig_act, NULL);
+ && prev_sig_act->sa_handler
+ /* Filter out SIG_DFL and SIG_IGN here, they will
+ run into the else branch below */
+ && (void *)prev_sig_act->sa_handler != SIG_DFL
+ && (void *)prev_sig_act->sa_handler != SIG_IGN) {
+ prev_sig_act->sa_handler(sig_num);
}
/* Output signal info and then crash if signal is unhandled */
else {
@@ -573,7 +664,7 @@ os_thread_signal_init(os_signal_handler handler)
/* Initialize memory for signal alternate stack of current thread */
if (!(map_addr = os_mmap(NULL, map_size, MMAP_PROT_READ | MMAP_PROT_WRITE,
- MMAP_MAP_NONE))) {
+ MMAP_MAP_NONE, os_get_invalid_handle()))) {
os_printf("Failed to mmap memory for alternate stack\n");
goto fail1;
}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_time.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_time.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_time.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_init.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_init.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_init.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_internal.h
similarity index 72%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_internal.h
index 0ac63cf5e75..02cd78be496 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_internal.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * Copyright (C) 2023 Dylibso. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
@@ -31,7 +32,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -41,8 +41,8 @@
extern "C" {
#endif
-#ifndef BH_PLATFORM_LINUX
-#define BH_PLATFORM_LINUX
+#ifndef BH_PLATFORM_COSMOPOLITAN
+#define BH_PLATFORM_COSMOPOLITAN
#endif
/* Stack size of applet threads's native part. */
@@ -63,6 +63,26 @@ typedef sem_t korp_sem;
#define bh_socket_t int
+typedef int os_file_handle;
+typedef DIR *os_dir_stream;
+typedef int os_raw_file_handle;
+
+#if WASM_DISABLE_WRITE_GS_BASE == 0
+#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
+#define os_writegsbase(base_addr) \
+ do { \
+ uint64 __gs_value = (uint64)(uintptr_t)base_addr; \
+ asm volatile("wrgsbase %0" ::"r"(__gs_value) : "memory"); \
+ } while (0)
+#if 0
+/* _writegsbase_u64 also works, but need to add -mfsgsbase flag for gcc */
+#include
+#define os_writegsbase(base_addr) \
+ _writegsbase_u64(((uint64)(uintptr_t)base_addr))
+#endif
+#endif
+#endif
+
#if WASM_DISABLE_HW_BOUND_CHECK == 0
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake
new file mode 100644
index 00000000000..929ecb9e4a3
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake
@@ -0,0 +1,19 @@
+# Copyright (C) 2019 Intel Corporation. All rights reserved.
+# Copyright (C) 2023 Dylibso. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+add_definitions(-DBH_PLATFORM_COSMOPOLITAN)
+
+include_directories(${PLATFORM_SHARED_DIR})
+include_directories(${PLATFORM_SHARED_DIR}/../include)
+
+include (${CMAKE_CURRENT_LIST_DIR}/../common/posix/platform_api_posix.cmake)
+
+file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
+
+set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_POSIX_SOURCE})
+
+file (GLOB header ${PLATFORM_SHARED_DIR}/../include/*.h)
+LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_init.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_init.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_init.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_internal.h
similarity index 86%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_internal.h
index 3fd1c258e25..30b89624e99 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_internal.h
@@ -58,6 +58,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
@@ -102,6 +103,22 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
+#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0
+#define OS_ENABLE_WAKEUP_BLOCKING_OP
+#endif
+void
+os_set_signal_number_for_blocking_op(int signo);
+
+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;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/shared_platform.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/shared_platform.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_init.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_init.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_init.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_internal.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_internal.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/shared_platform.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/shared_platform.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_malloc.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_malloc.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_malloc.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c
new file mode 100644
index 00000000000..9f3ec47a6a3
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include "platform_api_vmcore.h"
+#include "platform_api_extension.h"
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+#include "soc/mmu.h"
+#include "rom/cache.h"
+
+#define MEM_DUAL_BUS_OFFSET (IRAM0_CACHE_ADDRESS_LOW - DRAM0_CACHE_ADDRESS_LOW)
+
+#define in_ibus_ext(addr) \
+ (((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \
+ && ((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH))
+
+static portMUX_TYPE s_spinlock = portMUX_INITIALIZER_UNLOCKED;
+#endif
+
+void *
+os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
+{
+ if (prot & MMAP_PROT_EXEC) {
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ uint32_t mem_caps = MALLOC_CAP_SPIRAM;
+#else
+ uint32_t mem_caps = MALLOC_CAP_EXEC;
+#endif
+
+ // Memory allocation with MALLOC_CAP_EXEC will return 4-byte aligned
+ // Reserve extra 4 byte to fixup alignment and size for the pointer to
+ // the originally allocated address
+ void *buf_origin =
+ heap_caps_malloc(size + 4 + sizeof(uintptr_t), mem_caps);
+ if (!buf_origin) {
+ return NULL;
+ }
+ void *buf_fixed = buf_origin + sizeof(void *);
+ if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
+ buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7));
+ }
+
+ uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
+ *addr_field = (uintptr_t)buf_origin;
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ return buf_fixed + MEM_DUAL_BUS_OFFSET;
+#else
+ return buf_fixed;
+#endif
+ }
+ else {
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ uint32_t mem_caps = MALLOC_CAP_SPIRAM;
+#else
+ uint32_t mem_caps = MALLOC_CAP_8BIT;
+#endif
+ return heap_caps_malloc(size, mem_caps);
+ }
+}
+
+void
+os_munmap(void *addr, size_t size)
+{
+ char *ptr = (char *)addr;
+
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ if (in_ibus_ext(ptr)) {
+ ptr -= MEM_DUAL_BUS_OFFSET;
+ }
+#endif
+ // We don't need special handling of the executable allocations
+ // here, free() of esp-idf handles it properly
+ return os_free(ptr);
+}
+
+int
+os_mprotect(void *addr, size_t size, int prot)
+{
+ return 0;
+}
+
+void
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ IRAM_ATTR
+#endif
+ os_dcache_flush()
+{
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+ uint32_t preload;
+ extern void Cache_WriteBack_All(void);
+
+ portENTER_CRITICAL(&s_spinlock);
+
+ Cache_WriteBack_All();
+ preload = Cache_Disable_ICache();
+ Cache_Enable_ICache(preload);
+
+ portEXIT_CRITICAL(&s_spinlock);
+#endif
+}
+
+void
+os_icache_flush(void *start, size_t len)
+{}
+
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+void *
+os_get_dbus_mirror(void *ibus)
+{
+ if (in_ibus_ext(ibus)) {
+ return (void *)((char *)ibus - MEM_DUAL_BUS_OFFSET);
+ }
+ else {
+ return ibus;
+ }
+}
+#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_platform.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_platform.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_platform.c
index 35b893d814f..bbc18f69bf6 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_platform.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_platform.c
@@ -53,6 +53,10 @@ os_thread_get_stack_boundary(void)
#endif
}
+void
+os_thread_jit_write_protect_np(bool enabled)
+{}
+
int
os_usleep(uint32 usec)
{
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_socket.c
similarity index 95%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_socket.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_socket.c
index 9f441b71218..a75d82975d0 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_socket.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_socket.c
@@ -5,6 +5,7 @@
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
+#include "libc_errno.h"
#include
@@ -30,7 +31,7 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr, socklen_t socklen,
assert(socklen >= sizeof(struct sockaddr_in));
bh_sockaddr->port = ntohs(addr->sin_port);
- bh_sockaddr->addr_bufer.ipv4 = ntohl(addr->sin_addr.s_addr);
+ bh_sockaddr->addr_buffer.ipv4 = ntohl(addr->sin_addr.s_addr);
bh_sockaddr->is_ipv4 = true;
return BHT_OK;
}
@@ -167,11 +168,13 @@ os_socket_close(bh_socket_t socket)
return BHT_OK;
}
-int
+__wasi_errno_t
os_socket_shutdown(bh_socket_t socket)
{
- shutdown(socket, O_RDWR);
- return BHT_OK;
+ if (shutdown(socket, O_RDWR) != 0) {
+ return convert_errno(errno);
+ }
+ return __WASI_ESUCCESS;
}
int
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_thread.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_thread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_thread.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/platform_internal.h
similarity index 92%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/platform_internal.h
index 81304ea80c6..70c4fe7b1d5 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/platform_internal.h
@@ -39,6 +39,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 unsigned int korp_sem;
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -108,6 +109,16 @@ typedef unsigned int korp_sem;
#define DT_LNK DTYPE_LINK
#define DT_SOCK DTYPE_SOCK
+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;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/shared_platform.cmake
similarity index 66%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/shared_platform.cmake
index 13bc45dcb1f..8d7fe5d808a 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/shared_platform.cmake
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/shared_platform.cmake
@@ -11,3 +11,9 @@ include_directories(${PLATFORM_SHARED_DIR}/../include)
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE})
+
+# If enable PSRAM of ESP32-S3, it had better to put AOT into PSRAM, so that
+# users can use SRAM to for Wi-Fi/BLE and peripheral driver.
+if(CONFIG_ESP32S3_SPIRAM_SUPPORT)
+ add_definitions(-DWASM_MEM_DUAL_BUS_MIRROR=1)
+endif()
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_init.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_init.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_init.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_internal.h
similarity index 85%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_internal.h
index 7b4789c9922..5241c64569c 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_internal.h
@@ -57,6 +57,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
@@ -65,6 +66,10 @@ typedef sem_t korp_sem;
#define bh_socket_t int
+typedef int os_file_handle;
+typedef DIR *os_dir_stream;
+typedef int os_raw_file_handle;
+
#if WASM_DISABLE_HW_BOUND_CHECK == 0
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
@@ -101,6 +106,20 @@ os_sigreturn();
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
+#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0
+#define OS_ENABLE_WAKEUP_BLOCKING_OP
+#endif
+void
+os_set_signal_number_for_blocking_op(int signo);
+
+typedef int os_file_handle;
+
+static inline os_file_handle
+os_get_invalid_handle()
+{
+ return -1;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/shared_platform.cmake
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/shared_platform.cmake
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_extension.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_extension.h
similarity index 58%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_extension.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_extension.h
index 94fe16ea3a8..7c6120ba206 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_extension.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_extension.h
@@ -7,6 +7,7 @@
#define PLATFORM_API_EXTENSION_H
#include "platform_common.h"
+#include "platform_wasi_types.h"
/**
* The related data structures should be defined
* in platform_internal.h
@@ -130,6 +131,7 @@ os_thread_exit(void *retval);
#define os_memory_order_release memory_order_release
#define os_memory_order_seq_cst memory_order_seq_cst
#define os_atomic_thread_fence atomic_thread_fence
+#define os_atomic_cmpxchg atomic_compare_exchange_strong
#endif
#endif /* end of os_atomic_thread_fence */
@@ -237,6 +239,56 @@ os_cond_signal(korp_cond *cond);
int
os_cond_broadcast(korp_cond *cond);
+/**
+ * Initialize readwrite lock object
+ *
+ * @param cond [OUTPUT] pointer to a lock object variable
+ *
+ * @return 0 if success
+ */
+int
+os_rwlock_init(korp_rwlock *lock);
+
+/**
+ * Acquire the read lock
+ *
+ * @param lock lock variable
+ *
+ * @return 0 if success
+ */
+int
+os_rwlock_rdlock(korp_rwlock *lock);
+
+/**
+ * Acquire the write lock
+ *
+ * @param lock lock variable
+ *
+ * @return 0 if success
+ */
+int
+os_rwlock_wrlock(korp_rwlock *lock);
+
+/**
+ * Unlocks the lock object
+ *
+ * @param lock lock variable
+ *
+ * @return 0 if success
+ */
+int
+os_rwlock_unlock(korp_rwlock *lock);
+
+/**
+ * Destroy a lock object
+ *
+ * @param lock lock variable
+ *
+ * @return 0 if success
+ */
+int
+os_rwlock_destroy(korp_rwlock *lock);
+
/**
* Creates a new POSIX-like semaphore or opens an existing
* semaphore. The semaphore is identified by name. For details of
@@ -322,6 +374,34 @@ os_sem_getvalue(korp_sem *sem, int *sval);
int
os_sem_unlink(const char *name);
+/**
+ * Initialize process-global state for os_wakeup_blocking_op.
+ */
+int
+os_blocking_op_init();
+
+/**
+ * Start accepting os_wakeup_blocking_op requests for the calling thread.
+ */
+void
+os_begin_blocking_op();
+
+/**
+ * Stop accepting os_wakeup_blocking_op requests for the calling thread.
+ */
+void
+os_end_blocking_op();
+
+/**
+ * Wake up the specified thread.
+ *
+ * For example, on posix-like platforms, this can be implemented by
+ * sending a signal (w/o SA_RESTART) which interrupts a blocking
+ * system call.
+ */
+int
+os_wakeup_blocking_op(korp_tid tid);
+
/****************************************************
* Section 2 *
* Socket support *
@@ -341,7 +421,7 @@ typedef union {
} bh_ip_addr_buffer_t;
typedef struct {
- bh_ip_addr_buffer_t addr_bufer;
+ bh_ip_addr_buffer_t addr_buffer;
uint16 port;
bool is_ipv4;
} bh_sockaddr_t;
@@ -493,9 +573,9 @@ os_socket_close(bh_socket_t socket);
*
* @param socket the socket to be shutdown
*
- * @return always return 0
+ * @return returns corresponding error code
*/
-int
+__wasi_errno_t
os_socket_shutdown(bh_socket_t socket);
/**
@@ -1032,6 +1112,526 @@ os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled);
int
os_dumps_proc_mem_info(char *out, unsigned int size);
+/****************************************************
+ * Section 3 *
+ * Filesystem support *
+ ****************************************************/
+
+/**
+ * NOTES:
+ * Fileystem APIs are required for WASI libc support. If you don't need to
+ * support WASI libc, there is no need to implement these APIs. With a
+ * few exceptions, each filesystem function has been named after the equivalent
+ * POSIX filesystem function with an os_ prefix.
+ *
+ * Filesystem types
+ *
+ * os_raw_file_handle: the underlying OS file handle type e.g. int on POSIX
+ * systems and HANDLE on Windows. This type exists to allow embedders to provide
+ * custom file handles for stdout/stdin/stderr.
+ *
+ * os_file_handle: the file handle type used in the WASI libc fd
+ * table. Filesystem implementations can use it as a means to store any
+ * necessary platform-specific information which may not be directly available
+ * through the raw OS file handle. Similiar to POSIX file descriptors, file
+ * handles may also refer to sockets, directories, symbolic links or character
+ * devices and any of the filesystem operations which make sense for these
+ * resource types should be supported as far as possible.
+ *
+ * os_dir_stream: a directory stream type in which fileystem implementations
+ * can store any necessary state to iterate over the entries in a directory.
+ */
+
+/**
+ * Obtain information about an open file associated with the given handle.
+ *
+ * @param handle the handle for which to obtain file information
+ * @param buf a buffer in which to store the information
+ */
+__wasi_errno_t
+os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf);
+
+/**
+ * Obtain information about an open file or directory.
+ * @param handle the directory handle from which to resolve the file/directory
+ * path
+ * @param path the relative path of the file or directory for which to obtain
+ * information
+ * @param buf a buffer in which to store the information
+ * @param follow_symlink whether to follow symlinks when resolving the path
+ */
+__wasi_errno_t
+os_fstatat(os_file_handle handle, const char *path,
+ struct __wasi_filestat_t *buf, __wasi_lookupflags_t lookup_flags);
+
+/**
+ * Obtain the file status flags for the provided handle. This is similiar to the
+ * POSIX function fcntl called with the F_GETFL command.
+ *
+ * @param handle the handle for which to obtain the file status flags
+ * @param flags a pointer in which to store the output
+ */
+__wasi_errno_t
+os_file_get_fdflags(os_file_handle handle, __wasi_fdflags_t *flags);
+
+/**
+ * Set the file status flags for the provided handle. This is similiar to the
+ * POSIX function fcntl called with the F_SETFL command.
+ *
+ * @param handle the handle for which to set the file status flags
+ * @param flags the flags to set
+ */
+__wasi_errno_t
+os_file_set_fdflags(os_file_handle handle, __wasi_fdflags_t flags);
+
+/**
+ * Synchronize the data of a file to disk.
+ *
+ * @param handle
+ */
+__wasi_errno_t
+os_fdatasync(os_file_handle handle);
+
+/**
+ * Synchronize the data and metadata of a file to disk.
+ *
+ * @param handle
+ */
+__wasi_errno_t
+os_fsync(os_file_handle handle);
+
+/**
+ * Open a preopen directory. The path provided must refer to a directory and the
+ * returned handle will allow only readonly operations.
+ *
+ * @param path the path of the preopen directory to open
+ * @param out a pointer in which to store the newly opened handle
+ */
+__wasi_errno_t
+os_open_preopendir(const char *path, os_file_handle *out);
+
+typedef uint8 wasi_libc_file_access_mode;
+#define WASI_LIBC_ACCESS_MODE_READ_ONLY 0
+#define WASI_LIBC_ACCESS_MODE_WRITE_ONLY 1
+#define WASI_LIBC_ACCESS_MODE_READ_WRITE 2
+
+/**
+ * Open a file or directory at the given path.
+ *
+ * @param handle a handle to the directory in which to open the new file or
+ * directory
+ * @param path the relative path of the file or directory to open
+ * @param oflags the flags to determine how the file or directory is opened
+ * @param fd_flags the flags to set on the returned handle
+ * @param lookup_flags whether to follow symlinks when resolving the path
+ * @param access_mode whether the file is opened as read only, write only or
+ * both
+ * @param out a pointer in which to store the newly opened handle
+ */
+__wasi_errno_t
+os_openat(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);
+
+/**
+ * Obtain the file access mode for the provided handle. This is similiar to the
+ * POSIX function fcntl called with the F_GETFL command combined with the
+ * O_ACCMODE mask.
+ *
+ * @param handle the handle for which to obtain the access mode
+ * @param access_mode a pointer in which to store the access mode
+ */
+__wasi_errno_t
+os_file_get_access_mode(os_file_handle handle,
+ wasi_libc_file_access_mode *access_mode);
+
+/**
+ * Close the provided handle. If is_stdio is true, the raw file handle
+ * associated with the given file handle will not be closed.
+ *
+ * @param handle the handle to close
+ * @param is_stdio whether the provided handle refers to a stdio device
+ */
+__wasi_errno_t
+os_close(os_file_handle handle, bool is_stdio);
+
+/**
+ * Read data from the provided handle at the given offset into multiple buffers.
+ *
+ * @param handle the handle to read from
+ * @param iov the buffers to read into
+ * @param iovcnt the number of buffers to read into
+ * @param offset the offset to read from
+ * @param nread a pointer in which to store the number of bytes read
+ */
+__wasi_errno_t
+os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nread);
+
+/**
+ * Write data from multiple buffers at the given offset to the provided handle.
+ *
+ * @param handle the handle to write to
+ * @param iov the buffers to write from
+ * @param iovcnt the number of buffers to write from
+ * @param offset the offset to write from
+ * @param nwritten a pointer in which to store the number of bytes written
+ */
+__wasi_errno_t
+os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
+ __wasi_filesize_t offset, size_t *nwritten);
+
+/**
+ * Read data from the provided handle into multiple buffers.
+ *
+ * @param handle the handle to read from
+ * @param iov the buffers to read into
+ * @param iovcnt the number of buffers to read into
+ * @param nread a pointer in which to store the number of bytes read
+ */
+__wasi_errno_t
+os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
+ size_t *nread);
+
+/**
+ * Write data from multiple buffers to the provided handle.
+ *
+ * @param handle the handle to write to
+ * @param iov the buffers to write from
+ * @param iovcnt the number of buffers to write from
+ * @param nwritten a pointer in which to store the number of bytes written
+ */
+__wasi_errno_t
+os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
+ size_t *nwritten);
+
+/**
+ * Allocate storage space for the file associated with the provided handle. This
+ * is similar to the POSIX function posix_fallocate.
+ *
+ * @param handle the handle to allocate space for
+ * @param offset the offset to allocate space at
+ * @param length the amount of space to allocate
+ */
+__wasi_errno_t
+os_fallocate(os_file_handle handle, __wasi_filesize_t offset,
+ __wasi_filesize_t length);
+
+/**
+ * Adjust the size of an open file.
+ *
+ * @param handle the associated file handle for which to adjust the size
+ * @param size the new size of the file
+ */
+__wasi_errno_t
+os_ftruncate(os_file_handle handle, __wasi_filesize_t size);
+
+/**
+ * Set file access and modification times on an open file or directory.
+ *
+ * @param handle the associated file handle for which to adjust the
+ * access/modification times
+ * @param access_time the timestamp for the new access time
+ * @param modification_time the timestamp for the new modification time
+ * @param fstflags a bitmask to indicate which timestamps to adjust
+ */
+__wasi_errno_t
+os_futimens(os_file_handle handle, __wasi_timestamp_t access_time,
+ __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags);
+
+/**
+ * Set file access and modification times on an open file or directory.
+ *
+ * @param handle the directory handle from which to resolve the path
+ * @param path the relative path of the file or directory for which to adjust
+ * the access/modification times
+ * @param access_time the timestamp for the new access time
+ * @param modification_time the timestamp for the new modification time
+ * @param fstflags a bitmask to indicate which timestamps to adjust
+ * @param lookup_flags whether to follow symlinks when resolving the path
+ */
+__wasi_errno_t
+os_utimensat(os_file_handle handle, const char *path,
+ __wasi_timestamp_t access_time,
+ __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags,
+ __wasi_lookupflags_t lookup_flags);
+
+/**
+ * Read the contents of a symbolic link relative to the provided directory
+ * handle.
+ *
+ * @param handle the directory handle
+ * @param path the relative path of the symbolic link from which to read
+ * @param buf the buffer to read the link contents into
+ * @param bufsize the size of the provided buffer
+ * @param nread a pointer in which to store the number of bytes read into the
+ * buffer
+ */
+__wasi_errno_t
+os_readlinkat(os_file_handle handle, const char *path, char *buf,
+ size_t bufsize, size_t *nread);
+
+/**
+ * Create a link from one path to another path.
+ *
+ * @param from_handle the directory handle from which to resolve the origin path
+ * @param from_path the origin path to link from
+ * @param to_handle the directory handle from which to resolve the destination
+ * path
+ * @param to_path the destination path at which to create the link
+ * @param lookup_flags whether to follow symlinks when resolving the origin path
+ */
+__wasi_errno_t
+os_linkat(os_file_handle from_handle, const char *from_path,
+ os_file_handle to_handle, const char *to_path,
+ __wasi_lookupflags_t lookup_flags);
+
+/**
+ * Create a symbolic link from one path to another path.
+ *
+ * @param old_path the symbolic link contents
+ * @param handle the directory handle from which to resolve the destination path
+ * @param new_path the destination path at which to create the symbolic link
+ */
+__wasi_errno_t
+os_symlinkat(const char *old_path, os_file_handle handle, const char *new_path);
+
+/**
+ * Create a directory relative to the provided directory handle.
+ *
+ * @param handle the directory handle
+ * @param path the relative path of the directory to create
+ */
+__wasi_errno_t
+os_mkdirat(os_file_handle handle, const char *path);
+
+/**
+ * Rename a file or directory.
+ *
+ * @param old_handle the directory handle from which to resolve the old path
+ * @param old_path the source path to rename
+ * @param new_handle the directory handle from which to resolve the destination
+ * path
+ * @param new_path the destination path to which to rename the file or directory
+ */
+__wasi_errno_t
+os_renameat(os_file_handle old_handle, const char *old_path,
+ os_file_handle new_handle, const char *new_path);
+
+/**
+ * Unlink a file or directory.
+ *
+ * @param handle the directory handle from which to resolve the path
+ * @param path the relative path of the file or directory to unlink
+ * @param is_dir whether the provided handle refers to a directory or file
+ */
+__wasi_errno_t
+os_unlinkat(os_file_handle handle, const char *path, bool is_dir);
+
+/**
+ * Move the read/write offset of an open file.
+ *
+ * @param handle the associated file handle for which to adjust the offset
+ * @param offset the number of bytes to adjust the offset by
+ * @param whence the position whence to adjust the offset
+ * @param new_offset a pointer in which to store the new offset
+ */
+__wasi_errno_t
+os_lseek(os_file_handle handle, __wasi_filedelta_t offset,
+ __wasi_whence_t whence, __wasi_filesize_t *new_offset);
+
+/**
+ * Provide file advisory information for the given handle. This is similar to
+ * the POSIX function posix_fadvise.
+ *
+ * @param handle the associated file handle for which to provide advisory
+ * information
+ * @param offset the offset within the file to which the advisory
+ * information applies
+ * @param length the length of the region for which the advisory information
+ * applies
+ * @param advice the advice to provide
+ */
+__wasi_errno_t
+os_fadvise(os_file_handle handle, __wasi_filesize_t offset,
+ __wasi_filesize_t length, __wasi_advice_t advice);
+
+/**
+ * Determine if the given handle refers to a terminal device. __WASI_ESUCCESS
+ * will be returned if the handle is associated with a terminal device,
+ * otherwise an appropriate error code will be returned.
+ *
+ * @param handle
+ */
+__wasi_errno_t
+os_isatty(os_file_handle handle);
+
+/**
+ * Converts a raw file handle to STDIN to a corresponding file handle to STDIN.
+ * If the provided raw file handle is invalid, the platform-default raw handle
+ * for STDIN will be used.
+ *
+ * @param raw_stdin a raw file handle to STDIN
+ *
+ * @return a handle to STDIN
+ */
+os_file_handle
+os_convert_stdin_handle(os_raw_file_handle raw_stdin);
+
+/**
+ * Converts a raw file handle to STDOUT to a correponding file handle to STDOUT.
+ * If the provided raw file handle is invalid, the platform-default raw handle
+ * for STDOUT will be used.
+ *
+ * @param raw_stdout a raw file handle to STDOUT
+ *
+ * @return a handle to STDOUT
+ */
+os_file_handle
+os_convert_stdout_handle(os_raw_file_handle raw_stdout);
+
+/**
+ * Converts a raw file handle to STDERR to a correponding file handle to STDERR.
+ * If the provided raw file handle is invalid, the platform-default raw handle
+ * for STDERR will be used.
+ *
+ * @param raw_stderr a raw file handle to STDERR
+ *
+ * @return a handle to STDERR
+ */
+os_file_handle
+os_convert_stderr_handle(os_raw_file_handle raw_stderr);
+
+/**
+ * Open a directory stream for the provided directory handle. The returned
+ * directory stream will be positioned at the first entry in the directory.
+ *
+ * @param handle the directory handle
+ * @param dir_stream a pointer in which to store the new directory stream
+ */
+__wasi_errno_t
+os_fdopendir(os_file_handle handle, os_dir_stream *dir_stream);
+
+/**
+ * Reset the position of a directory stream to the beginning of the directory.
+ *
+ * @param dir_stream the directory stream for which to reset the position
+ */
+__wasi_errno_t
+os_rewinddir(os_dir_stream dir_stream);
+
+/**
+ * Set the position of the given directory stream.
+ *
+ * @param dir_stream the directory stream for which to set the position
+ * @param position the position to set
+ */
+__wasi_errno_t
+os_seekdir(os_dir_stream dir_stream, __wasi_dircookie_t position);
+
+/**
+ * Read a directory entry from the given directory stream. The directory name
+ * will be NULL if the end of the directory is reached or an error is
+ * encountered.
+ *
+ * @param dir_stream the directory stream from which to read the entry
+ * @param entry a pointer in which to store the directory entry
+ * @param d_name a pointer in which to store the directory entry name
+ */
+__wasi_errno_t
+os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry,
+ const char **d_name);
+
+/**
+ * Close the given directory stream. The handle associated with the directory
+ * stream will also be closed.
+ *
+ * @param dir_stream the directory stream to close
+ */
+__wasi_errno_t
+os_closedir(os_dir_stream dir_stream);
+
+/**
+ * Returns an invalid directory stream that is guaranteed to cause failure when
+ * called with any directory filesystem operation.
+ *
+ * @return the invalid directory stream
+ */
+os_dir_stream
+os_get_invalid_dir_stream();
+
+/**
+ * Checks whether the given directory stream is valid. An invalid directory
+ * stream is guaranteed to cause failure when called with any directory
+ * filesystem operation.
+ *
+ * @param dir_stream a pointer to a directory stream
+ */
+bool
+os_is_dir_stream_valid(os_dir_stream *dir_stream);
+
+/**
+ * Returns an invalid handle that is guaranteed to cause failure when
+ * called with any filesystem operation.
+ *
+ * @return the invalid handle
+ */
+os_file_handle
+os_get_invalid_handle();
+
+/**
+ * Checks whether the given file handle is valid. An invalid handle is
+ * guaranteed to cause failure when called with any filesystem operation.
+ *
+ * @param handle a pointer to a file handle
+ */
+bool
+os_is_handle_valid(os_file_handle *handle);
+
+/**
+ * Resolve a pathname. The generated pathname will be stored as a
+ * null-terminated string, with a maximum length of PATH_MAX bytes.
+ *
+ * @param path the path to resolve
+ * @param resolved_path the buffer to store the resolved path in
+ *
+ * @return the resolved path if success, NULL otherwise
+ */
+char *
+os_realpath(const char *path, char *resolved_path);
+
+/****************************************************
+ * Section 4 *
+ * Clock functions *
+ ****************************************************/
+
+/**
+ * NOTES:
+ * Clock functions are required for WASI libc support. If you don't need to
+ * support WASI libc, there is no need to implement these APIs.
+ */
+
+/**
+ * Get the resolution of the specified clock.
+ *
+ * @param clock_id clock identifier
+ * @param resolution output variable to store the clock resolution
+ */
+__wasi_errno_t
+os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution);
+
+/**
+ * Get the current time of the specified clock.
+ *
+ * @param clock_id clock identifier
+ * @param precision the maximum lag that the returned time value may have,
+ * compared to its actual value.
+ * @param time output variable to store the clock time
+ */
+__wasi_errno_t
+os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
+ __wasi_timestamp_t *time);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_vmcore.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_vmcore.h
similarity index 87%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_vmcore.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_vmcore.h
index c2f03c9e502..559141f75f3 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_vmcore.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_vmcore.h
@@ -81,6 +81,13 @@ os_self_thread(void);
uint8 *
os_thread_get_stack_boundary(void);
+/**
+ * Set whether the MAP_JIT region write protection is enabled for this thread.
+ * Pass true to make the region executable, false to make it writable.
+ */
+void
+os_thread_jit_write_protect_np(bool enabled);
+
/**
************** mutext APIs ***********
* vmcore: Not required until pthread is supported by runtime
@@ -123,12 +130,17 @@ enum {
};
void *
-os_mmap(void *hint, size_t size, int prot, int flags);
+os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file);
void
os_munmap(void *addr, size_t size);
int
os_mprotect(void *addr, size_t size, int prot);
+#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
+void *
+os_get_dbus_mirror(void *ibus);
+#endif
+
/**
* Flush cpu data cache, in some CPUs, after applying relocation to the
* AOT code, the code may haven't been written back to the cpu data cache,
@@ -138,6 +150,12 @@ os_mprotect(void *addr, size_t size, int prot);
void
os_dcache_flush(void);
+/**
+ * Flush instruction cache.
+ */
+void
+os_icache_flush(void *start, size_t len);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_common.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_common.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_common.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h
new file mode 100644
index 00000000000..ac1a95ea1eb
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h
@@ -0,0 +1,610 @@
+/*
+ * Copyright (C) 2023 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+/*
+ * This file declares the WASI interface. The definitions of types, macros and
+ * structures in this file should be consistent with those in wasi-libc:
+ * https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h
+ */
+
+#ifndef _PLATFORM_WASI_TYPES_H
+#define _PLATFORM_WASI_TYPES_H
+
+#include "../../../config.h"
+
+#include
+#include
+
+/* clang-format off */
+
+#ifdef __cplusplus
+#ifndef _Static_assert
+#define _Static_assert static_assert
+#endif /* _Static_assert */
+
+#ifndef _Alignof
+#define _Alignof alignof
+#endif /* _Alignof */
+
+extern "C" {
+#endif
+
+/* There is no need to check the WASI layout if we're using uvwasi or libc-wasi
+ * is not enabled at all. */
+#if WASM_ENABLE_UVWASI != 0 || WASM_ENABLE_LIBC_WASI == 0
+#define assert_wasi_layout(expr, message) /* nothing */
+#else
+#define assert_wasi_layout(expr, message) _Static_assert(expr, message)
+#endif
+
+assert_wasi_layout(_Alignof(int8_t) == 1, "non-wasi data layout");
+assert_wasi_layout(_Alignof(uint8_t) == 1, "non-wasi data layout");
+assert_wasi_layout(_Alignof(int16_t) == 2, "non-wasi data layout");
+assert_wasi_layout(_Alignof(uint16_t) == 2, "non-wasi data layout");
+assert_wasi_layout(_Alignof(int32_t) == 4, "non-wasi data layout");
+assert_wasi_layout(_Alignof(uint32_t) == 4, "non-wasi data layout");
+#if 0
+assert_wasi_layout(_Alignof(int64_t) == 8, "non-wasi data layout");
+assert_wasi_layout(_Alignof(uint64_t) == 8, "non-wasi data layout");
+#endif
+
+typedef uint32_t __wasi_size_t;
+assert_wasi_layout(_Alignof(__wasi_size_t) == 4, "non-wasi data layout");
+
+typedef uint8_t __wasi_advice_t;
+#define __WASI_ADVICE_NORMAL (0)
+#define __WASI_ADVICE_SEQUENTIAL (1)
+#define __WASI_ADVICE_RANDOM (2)
+#define __WASI_ADVICE_WILLNEED (3)
+#define __WASI_ADVICE_DONTNEED (4)
+#define __WASI_ADVICE_NOREUSE (5)
+
+typedef uint32_t __wasi_clockid_t;
+#define __WASI_CLOCK_REALTIME (0)
+#define __WASI_CLOCK_MONOTONIC (1)
+#define __WASI_CLOCK_PROCESS_CPUTIME_ID (2)
+#define __WASI_CLOCK_THREAD_CPUTIME_ID (3)
+
+typedef uint64_t __wasi_device_t;
+
+typedef uint64_t __wasi_dircookie_t;
+#define __WASI_DIRCOOKIE_START (0)
+
+typedef uint32_t __wasi_dirnamlen_t;
+
+typedef uint16_t __wasi_errno_t;
+#define __WASI_ESUCCESS (0)
+#define __WASI_E2BIG (1)
+#define __WASI_EACCES (2)
+#define __WASI_EADDRINUSE (3)
+#define __WASI_EADDRNOTAVAIL (4)
+#define __WASI_EAFNOSUPPORT (5)
+#define __WASI_EAGAIN (6)
+#define __WASI_EALREADY (7)
+#define __WASI_EBADF (8)
+#define __WASI_EBADMSG (9)
+#define __WASI_EBUSY (10)
+#define __WASI_ECANCELED (11)
+#define __WASI_ECHILD (12)
+#define __WASI_ECONNABORTED (13)
+#define __WASI_ECONNREFUSED (14)
+#define __WASI_ECONNRESET (15)
+#define __WASI_EDEADLK (16)
+#define __WASI_EDESTADDRREQ (17)
+#define __WASI_EDOM (18)
+#define __WASI_EDQUOT (19)
+#define __WASI_EEXIST (20)
+#define __WASI_EFAULT (21)
+#define __WASI_EFBIG (22)
+#define __WASI_EHOSTUNREACH (23)
+#define __WASI_EIDRM (24)
+#define __WASI_EILSEQ (25)
+#define __WASI_EINPROGRESS (26)
+#define __WASI_EINTR (27)
+#define __WASI_EINVAL (28)
+#define __WASI_EIO (29)
+#define __WASI_EISCONN (30)
+#define __WASI_EISDIR (31)
+#define __WASI_ELOOP (32)
+#define __WASI_EMFILE (33)
+#define __WASI_EMLINK (34)
+#define __WASI_EMSGSIZE (35)
+#define __WASI_EMULTIHOP (36)
+#define __WASI_ENAMETOOLONG (37)
+#define __WASI_ENETDOWN (38)
+#define __WASI_ENETRESET (39)
+#define __WASI_ENETUNREACH (40)
+#define __WASI_ENFILE (41)
+#define __WASI_ENOBUFS (42)
+#define __WASI_ENODEV (43)
+#define __WASI_ENOENT (44)
+#define __WASI_ENOEXEC (45)
+#define __WASI_ENOLCK (46)
+#define __WASI_ENOLINK (47)
+#define __WASI_ENOMEM (48)
+#define __WASI_ENOMSG (49)
+#define __WASI_ENOPROTOOPT (50)
+#define __WASI_ENOSPC (51)
+#define __WASI_ENOSYS (52)
+#define __WASI_ENOTCONN (53)
+#define __WASI_ENOTDIR (54)
+#define __WASI_ENOTEMPTY (55)
+#define __WASI_ENOTRECOVERABLE (56)
+#define __WASI_ENOTSOCK (57)
+#define __WASI_ENOTSUP (58)
+#define __WASI_ENOTTY (59)
+#define __WASI_ENXIO (60)
+#define __WASI_EOVERFLOW (61)
+#define __WASI_EOWNERDEAD (62)
+#define __WASI_EPERM (63)
+#define __WASI_EPIPE (64)
+#define __WASI_EPROTO (65)
+#define __WASI_EPROTONOSUPPORT (66)
+#define __WASI_EPROTOTYPE (67)
+#define __WASI_ERANGE (68)
+#define __WASI_EROFS (69)
+#define __WASI_ESPIPE (70)
+#define __WASI_ESRCH (71)
+#define __WASI_ESTALE (72)
+#define __WASI_ETIMEDOUT (73)
+#define __WASI_ETXTBSY (74)
+#define __WASI_EXDEV (75)
+#define __WASI_ENOTCAPABLE (76)
+
+#if defined(_MSC_VER)
+#define ALIGNED_(x) __declspec(align(x))
+#define WARN_UNUSED _Check_return_
+#elif defined(__GNUC__)
+#define ALIGNED_(x) __attribute__ ((aligned(x)))
+#define WARN_UNUSED __attribute__((__warn_unused_result__))
+#endif
+
+#define ALIGNED_TYPE(t,x) typedef t ALIGNED_(x)
+
+typedef uint16_t __wasi_eventrwflags_t;
+#define __WASI_EVENT_FD_READWRITE_HANGUP (0x0001)
+
+typedef uint8_t __wasi_eventtype_t;
+#define __WASI_EVENTTYPE_CLOCK (0)
+#define __WASI_EVENTTYPE_FD_READ (1)
+#define __WASI_EVENTTYPE_FD_WRITE (2)
+
+typedef uint32_t __wasi_exitcode_t;
+
+typedef uint32_t __wasi_fd_t;
+
+typedef uint16_t __wasi_fdflags_t;
+#define __WASI_FDFLAG_APPEND (0x0001)
+#define __WASI_FDFLAG_DSYNC (0x0002)
+#define __WASI_FDFLAG_NONBLOCK (0x0004)
+#define __WASI_FDFLAG_RSYNC (0x0008)
+#define __WASI_FDFLAG_SYNC (0x0010)
+
+typedef int64_t __wasi_filedelta_t;
+
+typedef uint64_t __wasi_filesize_t;
+
+typedef uint8_t __wasi_filetype_t;
+#define __WASI_FILETYPE_UNKNOWN (0)
+#define __WASI_FILETYPE_BLOCK_DEVICE (1)
+#define __WASI_FILETYPE_CHARACTER_DEVICE (2)
+#define __WASI_FILETYPE_DIRECTORY (3)
+#define __WASI_FILETYPE_REGULAR_FILE (4)
+#define __WASI_FILETYPE_SOCKET_DGRAM (5)
+#define __WASI_FILETYPE_SOCKET_STREAM (6)
+#define __WASI_FILETYPE_SYMBOLIC_LINK (7)
+
+typedef uint16_t __wasi_fstflags_t;
+#define __WASI_FILESTAT_SET_ATIM (0x0001)
+#define __WASI_FILESTAT_SET_ATIM_NOW (0x0002)
+#define __WASI_FILESTAT_SET_MTIM (0x0004)
+#define __WASI_FILESTAT_SET_MTIM_NOW (0x0008)
+
+typedef uint64_t __wasi_inode_t;
+
+ALIGNED_TYPE(uint64_t, 8) __wasi_linkcount_t;
+
+typedef uint32_t __wasi_lookupflags_t;
+#define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001)
+
+typedef uint16_t __wasi_oflags_t;
+#define __WASI_O_CREAT (0x0001)
+#define __WASI_O_DIRECTORY (0x0002)
+#define __WASI_O_EXCL (0x0004)
+#define __WASI_O_TRUNC (0x0008)
+
+typedef uint16_t __wasi_riflags_t;
+#define __WASI_SOCK_RECV_PEEK (0x0001)
+#define __WASI_SOCK_RECV_WAITALL (0x0002)
+
+typedef uint64_t __wasi_rights_t;
+
+/**
+ * Observe that WASI defines rights in the plural form
+ * TODO: refactor to use RIGHTS instead of RIGHT
+ */
+#define __WASI_RIGHT_FD_DATASYNC ((__wasi_rights_t)(UINT64_C(1) << 0))
+#define __WASI_RIGHT_FD_READ ((__wasi_rights_t)(UINT64_C(1) << 1))
+#define __WASI_RIGHT_FD_SEEK ((__wasi_rights_t)(UINT64_C(1) << 2))
+#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(UINT64_C(1) << 3))
+#define __WASI_RIGHT_FD_SYNC ((__wasi_rights_t)(UINT64_C(1) << 4))
+#define __WASI_RIGHT_FD_TELL ((__wasi_rights_t)(UINT64_C(1) << 5))
+#define __WASI_RIGHT_FD_WRITE ((__wasi_rights_t)(UINT64_C(1) << 6))
+#define __WASI_RIGHT_FD_ADVISE ((__wasi_rights_t)(UINT64_C(1) << 7))
+#define __WASI_RIGHT_FD_ALLOCATE ((__wasi_rights_t)(UINT64_C(1) << 8))
+#define __WASI_RIGHT_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 9))
+#define __WASI_RIGHT_PATH_CREATE_FILE ((__wasi_rights_t)(UINT64_C(1) << 10))
+#define __WASI_RIGHT_PATH_LINK_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 11))
+#define __WASI_RIGHT_PATH_LINK_TARGET ((__wasi_rights_t)(UINT64_C(1) << 12))
+#define __WASI_RIGHT_PATH_OPEN ((__wasi_rights_t)(UINT64_C(1) << 13))
+#define __WASI_RIGHT_FD_READDIR ((__wasi_rights_t)(UINT64_C(1) << 14))
+#define __WASI_RIGHT_PATH_READLINK ((__wasi_rights_t)(UINT64_C(1) << 15))
+#define __WASI_RIGHT_PATH_RENAME_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 16))
+#define __WASI_RIGHT_PATH_RENAME_TARGET ((__wasi_rights_t)(UINT64_C(1) << 17))
+#define __WASI_RIGHT_PATH_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 18))
+#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 19))
+#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 20))
+#define __WASI_RIGHT_FD_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 21))
+#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 22))
+#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 23))
+#define __WASI_RIGHT_PATH_SYMLINK ((__wasi_rights_t)(UINT64_C(1) << 24))
+#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 25))
+#define __WASI_RIGHT_PATH_UNLINK_FILE ((__wasi_rights_t)(UINT64_C(1) << 26))
+#define __WASI_RIGHT_POLL_FD_READWRITE ((__wasi_rights_t)(UINT64_C(1) << 27))
+#define __WASI_RIGHT_SOCK_CONNECT ((__wasi_rights_t)(UINT64_C(1) << 28))
+#define __WASI_RIGHT_SOCK_LISTEN ((__wasi_rights_t)(UINT64_C(1) << 29))
+#define __WASI_RIGHT_SOCK_BIND ((__wasi_rights_t)(UINT64_C(1) << 30))
+#define __WASI_RIGHT_SOCK_ACCEPT ((__wasi_rights_t)(UINT64_C(1) << 31))
+#define __WASI_RIGHT_SOCK_RECV ((__wasi_rights_t)(UINT64_C(1) << 32))
+#define __WASI_RIGHT_SOCK_SEND ((__wasi_rights_t)(UINT64_C(1) << 33))
+#define __WASI_RIGHT_SOCK_ADDR_LOCAL ((__wasi_rights_t)(UINT64_C(1) << 34))
+#define __WASI_RIGHT_SOCK_ADDR_REMOTE ((__wasi_rights_t)(UINT64_C(1) << 35))
+#define __WASI_RIGHT_SOCK_RECV_FROM ((__wasi_rights_t)(UINT64_C(1) << 36))
+#define __WASI_RIGHT_SOCK_SEND_TO ((__wasi_rights_t)(UINT64_C(1) << 37))
+
+typedef uint16_t __wasi_roflags_t;
+#define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001)
+
+typedef uint8_t __wasi_sdflags_t;
+#define __WASI_SHUT_RD (0x01)
+#define __WASI_SHUT_WR (0x02)
+
+typedef uint16_t __wasi_siflags_t;
+
+typedef uint8_t __wasi_signal_t;
+
+typedef uint16_t __wasi_subclockflags_t;
+#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001)
+
+typedef uint64_t __wasi_timestamp_t;
+
+typedef uint64_t __wasi_userdata_t;
+
+typedef uint8_t __wasi_whence_t;
+#define __WASI_WHENCE_SET (0)
+#define __WASI_WHENCE_CUR (1)
+#define __WASI_WHENCE_END (2)
+
+typedef uint8_t __wasi_preopentype_t;
+#define __WASI_PREOPENTYPE_DIR (0)
+
+struct fd_table;
+struct fd_prestats;
+struct argv_environ_values;
+struct addr_pool;
+
+typedef struct ALIGNED_(8) __wasi_dirent_t {
+ __wasi_dircookie_t d_next;
+ __wasi_inode_t d_ino;
+ __wasi_dirnamlen_t d_namlen;
+ __wasi_filetype_t d_type;
+} __wasi_dirent_t;
+assert_wasi_layout(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout");
+assert_wasi_layout(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout");
+assert_wasi_layout(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout");
+
+typedef struct ALIGNED_(8) __wasi_event_t {
+ __wasi_userdata_t userdata;
+ __wasi_errno_t error;
+ __wasi_eventtype_t type;
+ uint8_t __paddings[5];
+ union __wasi_event_u {
+ struct __wasi_event_u_fd_readwrite_t {
+ __wasi_filesize_t nbytes;
+ __wasi_eventrwflags_t flags;
+ uint8_t __paddings[6];
+ } fd_readwrite;
+ } u;
+} __wasi_event_t;
+assert_wasi_layout(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout");
+assert_wasi_layout(sizeof(__wasi_event_t) == 32, "non-wasi data layout");
+assert_wasi_layout(_Alignof(__wasi_event_t) == 8, "non-wasi data layout");
+
+typedef struct __wasi_prestat_t {
+ __wasi_preopentype_t pr_type;
+ union __wasi_prestat_u {
+ struct __wasi_prestat_u_dir_t {
+ size_t pr_name_len;
+ } dir;
+ } u;
+} __wasi_prestat_t;
+assert_wasi_layout(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ sizeof(__wasi_prestat_t) == 8, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ sizeof(__wasi_prestat_t) == 16, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ _Alignof(__wasi_prestat_t) == 4, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ _Alignof(__wasi_prestat_t) == 8, "non-wasi data layout");
+
+typedef struct ALIGNED_(8) __wasi_fdstat_t {
+ __wasi_filetype_t fs_filetype;
+ __wasi_fdflags_t fs_flags;
+ uint8_t __paddings[4];
+ __wasi_rights_t fs_rights_base;
+ __wasi_rights_t fs_rights_inheriting;
+} __wasi_fdstat_t;
+assert_wasi_layout(
+ offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16,
+ "non-wasi data layout");
+assert_wasi_layout(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout");
+assert_wasi_layout(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout");
+
+typedef struct ALIGNED_(8) __wasi_filestat_t {
+ __wasi_device_t st_dev;
+ __wasi_inode_t st_ino;
+ __wasi_filetype_t st_filetype;
+ __wasi_linkcount_t st_nlink;
+ __wasi_filesize_t st_size;
+ __wasi_timestamp_t st_atim;
+ __wasi_timestamp_t st_mtim;
+ __wasi_timestamp_t st_ctim;
+} __wasi_filestat_t;
+assert_wasi_layout(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout");
+assert_wasi_layout(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_filestat_t, st_nlink) == 24, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_filestat_t, st_size) == 32, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_filestat_t, st_atim) == 40, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_filestat_t, st_mtim) == 48, "non-wasi data layout");
+assert_wasi_layout(
+ offsetof(__wasi_filestat_t, st_ctim) == 56, "non-wasi data layout");
+assert_wasi_layout(sizeof(__wasi_filestat_t) == 64, "non-wasi data layout");
+assert_wasi_layout(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout");
+
+typedef struct __wasi_ciovec_t {
+ const void *buf;
+ size_t buf_len;
+} __wasi_ciovec_t;
+assert_wasi_layout(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ _Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ _Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout");
+
+typedef struct __wasi_iovec_t {
+ void *buf;
+ size_t buf_len;
+} __wasi_iovec_t;
+assert_wasi_layout(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ sizeof(__wasi_iovec_t) == 8, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ sizeof(__wasi_iovec_t) == 16, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 4 ||
+ _Alignof(__wasi_iovec_t) == 4, "non-wasi data layout");
+assert_wasi_layout(sizeof(void *) != 8 ||
+ _Alignof(__wasi_iovec_t) == 8, "non-wasi data layout");
+
+/**
+ * The contents of a `subscription` when type is `eventtype::clock`.
+ */
+typedef struct ALIGNED_(8) __wasi_subscription_clock_t {
+ /**
+ * The clock against which to compare the timestamp.
+ */
+ __wasi_clockid_t clock_id;
+
+ uint8_t __paddings1[4];
+
+ /**
+ * The absolute or relative timestamp.
+ */
+ __wasi_timestamp_t timeout;
+
+ /**
+ * The amount of time that the implementation may wait additionally
+ * to coalesce with other events.
+ */
+ __wasi_timestamp_t precision;
+
+ /**
+ * Flags specifying whether the timeout is absolute or relative
+ */
+ __wasi_subclockflags_t flags;
+
+ uint8_t __paddings2[4];
+
+} __wasi_subscription_clock_t;
+
+assert_wasi_layout(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size");
+assert_wasi_layout(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align");
+assert_wasi_layout(offsetof(__wasi_subscription_clock_t, clock_id) == 0, "witx calculated offset");
+assert_wasi_layout(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset");
+assert_wasi_layout(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset");
+assert_wasi_layout(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset");
+
+/**
+ * The contents of a `subscription` when type is type is
+ * `eventtype::fd_read` or `eventtype::fd_write`.
+ */
+typedef struct __wasi_subscription_fd_readwrite_t {
+ /**
+ * The file descriptor on which to wait for it to become ready for reading or writing.
+ */
+ __wasi_fd_t fd;
+
+} __wasi_subscription_fd_readwrite_t;
+
+assert_wasi_layout(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size");
+assert_wasi_layout(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align");
+assert_wasi_layout(offsetof(__wasi_subscription_fd_readwrite_t, fd) == 0, "witx calculated offset");
+
+/**
+ * The contents of a `subscription`.
+ */
+typedef union __wasi_subscription_u_u_t {
+ __wasi_subscription_clock_t clock;
+ __wasi_subscription_fd_readwrite_t fd_readwrite;
+} __wasi_subscription_u_u_t ;
+
+typedef struct ALIGNED_(8) __wasi_subscription_u_t {
+ __wasi_eventtype_t type;
+ __wasi_subscription_u_u_t u;
+} __wasi_subscription_u_t;
+
+assert_wasi_layout(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size");
+assert_wasi_layout(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align");
+assert_wasi_layout(offsetof(__wasi_subscription_u_t, u) == 8, "witx calculated union offset");
+assert_wasi_layout(sizeof(__wasi_subscription_u_u_t) == 32, "witx calculated union size");
+assert_wasi_layout(_Alignof(__wasi_subscription_u_u_t) == 8, "witx calculated union align");
+
+/**
+ * Subscription to an event.
+ */
+typedef struct __wasi_subscription_t {
+ /**
+ * User-provided value that is attached to the subscription in the
+ * implementation and returned through `event::userdata`.
+ */
+ __wasi_userdata_t userdata;
+
+ /**
+ * The type of the event to which to subscribe, and its contents
+ */
+ __wasi_subscription_u_t u;
+
+} __wasi_subscription_t;
+
+assert_wasi_layout(sizeof(__wasi_subscription_t) == 48, "witx calculated size");
+assert_wasi_layout(_Alignof(__wasi_subscription_t) == 8, "witx calculated align");
+assert_wasi_layout(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset");
+assert_wasi_layout(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset");
+
+/* keep syncing with wasi_socket_ext.h */
+typedef enum {
+ /* Used only for sock_addr_resolve hints */
+ SOCKET_ANY = -1,
+ SOCKET_DGRAM = 0,
+ SOCKET_STREAM,
+} __wasi_sock_type_t;
+
+typedef uint16_t __wasi_ip_port_t;
+
+typedef enum { IPv4 = 0, IPv6 } __wasi_addr_type_t;
+
+/* n0.n1.n2.n3 */
+typedef struct __wasi_addr_ip4_t {
+ uint8_t n0;
+ uint8_t n1;
+ uint8_t n2;
+ uint8_t n3;
+} __wasi_addr_ip4_t;
+
+typedef struct __wasi_addr_ip4_port_t {
+ __wasi_addr_ip4_t addr;
+ __wasi_ip_port_t port;
+} __wasi_addr_ip4_port_t;
+
+typedef struct __wasi_addr_ip6_t {
+ uint16_t n0;
+ uint16_t n1;
+ uint16_t n2;
+ uint16_t n3;
+ uint16_t h0;
+ uint16_t h1;
+ uint16_t h2;
+ uint16_t h3;
+} __wasi_addr_ip6_t;
+
+typedef struct __wasi_addr_ip6_port_t {
+ __wasi_addr_ip6_t addr;
+ __wasi_ip_port_t port;
+} __wasi_addr_ip6_port_t;
+
+typedef struct __wasi_addr_ip_t {
+ __wasi_addr_type_t kind;
+ union {
+ __wasi_addr_ip4_t ip4;
+ __wasi_addr_ip6_t ip6;
+ } addr;
+} __wasi_addr_ip_t;
+
+typedef struct __wasi_addr_t {
+ __wasi_addr_type_t kind;
+ union {
+ __wasi_addr_ip4_port_t ip4;
+ __wasi_addr_ip6_port_t ip6;
+ } addr;
+} __wasi_addr_t;
+
+typedef enum { INET4 = 0, INET6, INET_UNSPEC } __wasi_address_family_t;
+
+typedef struct __wasi_addr_info_t {
+ __wasi_addr_t addr;
+ __wasi_sock_type_t type;
+} __wasi_addr_info_t;
+
+typedef struct __wasi_addr_info_hints_t {
+ __wasi_sock_type_t type;
+ __wasi_address_family_t family;
+ // this is to workaround lack of optional parameters
+ uint8_t hints_enabled;
+} __wasi_addr_info_hints_t;
+
+#undef assert_wasi_layout
+
+/* clang-format on */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* end of _PLATFORM_WASI_TYPES_H */
\ No newline at end of file
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/platform_internal.h
similarity index 89%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/platform_internal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/platform_internal.h
index d18f015ee1f..c96768e321d 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/platform_internal.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/platform_internal.h
@@ -50,6 +50,7 @@ typedef pthread_t korp_thread;
typedef pthread_t korp_tid;
typedef pthread_mutex_t korp_mutex;
typedef pthread_cond_t korp_cond;
+typedef pthread_rwlock_t korp_rwlock;
typedef unsigned int korp_sem;
#ifndef SGX_DISABLE_PTHREAD
@@ -68,6 +69,16 @@ strcpy(char *dest, const char *src);
#define os_memory_order_seq_cst __ATOMIC_SEQ_CST
#define os_atomic_thread_fence __atomic_thread_fence
+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;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.h
similarity index 97%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.h
index e4de90274f4..3a911d2b6ed 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.h
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.h
@@ -7,7 +7,6 @@
#define _LIBC_WASI_SGX_PFS_H
#include "bh_hashmap.h"
-#include "wasmtime_ssp.h"
#ifdef __cplusplus
extern "C" {
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_platform.c
similarity index 91%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_platform.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_platform.c
index b40eaf79c43..32b95682670 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_platform.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_platform.c
@@ -120,13 +120,20 @@ strcpy(char *dest, const char *src)
}
void *
-os_mmap(void *hint, size_t size, int prot, int flags)
+os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
{
int mprot = 0;
uint64 aligned_size, page_size;
void *ret = NULL;
sgx_status_t st = 0;
+ if (os_is_handle_valid(&file)) {
+ os_printf("os_mmap(size=%u, prot=0x%x, file=%x) failed: file is not "
+ "supported.\n",
+ size, prot, file);
+ return NULL;
+ }
+
page_size = getpagesize();
aligned_size = (size + page_size - 1) & ~(page_size - 1);
@@ -195,3 +202,7 @@ os_mprotect(void *addr, size_t size, int prot)
void
os_dcache_flush(void)
{}
+
+void
+os_icache_flush(void *start, size_t len)
+{}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.c
similarity index 98%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.c
index afb6d6014bf..cd1a6ceade8 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.c
@@ -5,6 +5,7 @@
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
+#include "libc_errno.h"
#ifndef SGX_DISABLE_WASI
@@ -261,7 +262,7 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr, socklen_t socklen,
assert(socklen >= sizeof(struct sockaddr_in));
bh_sockaddr->port = ntohs(addr->sin_port);
- bh_sockaddr->addr_bufer.ipv4 = ntohl(addr->sin_addr.s_addr);
+ bh_sockaddr->addr_buffer.ipv4 = ntohl(addr->sin_addr.s_addr);
bh_sockaddr->is_ipv4 = true;
return BHT_OK;
}
@@ -279,7 +280,7 @@ bh_sockaddr_to_sockaddr(const bh_sockaddr_t *bh_sockaddr,
struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr;
addr->sin_port = htons(bh_sockaddr->port);
addr->sin_family = AF_INET;
- addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_bufer.ipv4);
+ addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_buffer.ipv4);
*socklen = sizeof(*addr);
return BHT_OK;
}
@@ -855,10 +856,13 @@ os_socket_send_to(bh_socket_t socket, const void *buf, unsigned int len,
return ret;
}
-int
+__wasi_errno_t
os_socket_shutdown(bh_socket_t socket)
{
- return shutdown(socket, O_RDWR);
+ if (shutdown(socket, O_RDWR) != 0) {
+ return convert_errno(errno);
+ }
+ return __WASI_ESUCCESS;
}
int
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_thread.c
similarity index 78%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_thread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_thread.c
index 1cb2f5d09a3..73f3005fab2 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_thread.c
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_thread.c
@@ -210,3 +210,72 @@ os_thread_get_stack_boundary()
/* TODO: get sgx stack boundary */
return NULL;
}
+
+void
+os_thread_jit_write_protect_np(bool enabled)
+{}
+
+int
+os_rwlock_init(korp_rwlock *lock)
+{
+#ifndef SGX_DISABLE_PTHREAD
+ assert(lock);
+
+ if (pthread_rwlock_init(lock, NULL) != BHT_OK)
+ return BHT_ERROR;
+#endif
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_rdlock(korp_rwlock *lock)
+{
+#ifndef SGX_DISABLE_PTHREAD
+ assert(lock);
+
+ if (pthread_rwlock_rdlock(lock) != BHT_OK)
+ return BHT_ERROR;
+#endif
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_wrlock(korp_rwlock *lock)
+{
+#ifndef SGX_DISABLE_PTHREAD
+ assert(lock);
+
+ if (pthread_rwlock_wrlock(lock) != BHT_OK)
+ return BHT_ERROR;
+#endif
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_unlock(korp_rwlock *lock)
+{
+#ifndef SGX_DISABLE_PTHREAD
+ assert(lock);
+
+ if (pthread_rwlock_unlock(lock) != BHT_OK)
+ return BHT_ERROR;
+#endif
+
+ return BHT_OK;
+}
+
+int
+os_rwlock_destroy(korp_rwlock *lock)
+{
+#ifndef SGX_DISABLE_PTHREAD
+ assert(lock);
+
+ if (pthread_rwlock_destroy(lock) != BHT_OK)
+ return BHT_ERROR;
+#endif
+
+ return BHT_OK;
+}
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.h
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.h
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.h
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_wamr.edl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_wamr.edl
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_wamr.edl
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_wamr.edl
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/shared_platform.cmake
similarity index 76%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/shared_platform.cmake
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/shared_platform.cmake
index b2de1ab06a6..e8e1670058f 100644
--- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/shared_platform.cmake
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/shared_platform.cmake
@@ -20,16 +20,23 @@ if (NOT BUILD_UNTRUST_PART EQUAL 1)
${SGX_SDK_DIR}/include/libcxx)
endif ()
-if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
- add_definitions(-DSGX_DISABLE_WASI)
-endif ()
-
if (NOT WAMR_BUILD_THREAD_MGR EQUAL 1)
add_definitions(-DSGX_DISABLE_PTHREAD)
endif ()
file (GLOB source_all ${PLATFORM_SHARED_DIR}/*.c)
+if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
+ add_definitions(-DSGX_DISABLE_WASI)
+else()
+ list(APPEND source_all
+ ${PLATFORM_SHARED_DIR}/../common/posix/posix_file.c
+ ${PLATFORM_SHARED_DIR}/../common/posix/posix_clock.c
+ )
+ include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake)
+ set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE})
+endif()
+
file (GLOB source_all_untrusted ${PLATFORM_SHARED_DIR}/untrusted/*.c)
set (PLATFORM_SHARED_SOURCE ${source_all})
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/file.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/file.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/file.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/pthread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/pthread.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/pthread.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/pthread.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/signal.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/signal.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/signal.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/signal.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/socket.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/socket.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/socket.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/time.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/time.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/time.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_init.c
similarity index 100%
rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_init.c
rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_init.c
diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h
new file mode 100644
index 00000000000..335070bf80f
--- /dev/null
+++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#ifndef _PLATFORM_INTERNAL_H
+#define _PLATFORM_INTERNAL_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include