Merge main into dev/socket

This commit is contained in:
Wenyong Huang
2022-09-10 22:12:43 +08:00
74 changed files with 1478 additions and 646 deletions

View File

@ -135,11 +135,11 @@ ExternalProject_Add(WASM_MODULE
-S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps
BUILD_COMMAND ${CMAKE_COMMAND} --build .
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy
./mA.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/
./mB.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/
./mC.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/
./mD.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/
./mE.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/
./mA.wasm ${CMAKE_BINARY_DIR}
./mB.wasm ${CMAKE_BINARY_DIR}
./mC.wasm ${CMAKE_BINARY_DIR}
./mD.wasm ${CMAKE_BINARY_DIR}
./mE.wasm ${CMAKE_BINARY_DIR}
)
################ NATIVE

View File

@ -122,22 +122,6 @@ main()
"call \"C5\", it will be failed since it is a export function, ===> ");
wasm_application_execute_func(module_inst, "C5", 0, args);
/* call functions of mB */
printf("call \"mB.B1\", it will return 0x15:i32, ===> ");
wasm_application_execute_func(module_inst, "$mB$B1", 0, args);
printf("call \"mB.B2\", it will call A1() of mA and return 0xb:i32, ===> ");
wasm_application_execute_func(module_inst, "$mB$B2", 0, args);
printf("call \"mB.B3\", it will be failed since it is a export function, "
"===> ");
wasm_application_execute_func(module_inst, "$mB$B3", 0, args);
/* call functions of mA */
printf("call \"mA.A1\", it will return 0xb:i32, ===>");
wasm_application_execute_func(module_inst, "$mA$A1", 0, args);
printf("call \"mA.A2\", it will be failed since it is a export function, "
"===> ");
wasm_application_execute_func(module_inst, "$mA$A2", 0, args);
printf("----------------------------------------\n\n");
ret = true;
printf("- wasm_runtime_deinstantiate\n");

View File

@ -45,6 +45,7 @@ set(WAMR_BUILD_JIT 0)
set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_FAST_INTERP 1)
set(WAMR_BUILD_LIB_PTHREAD 1)
set(WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1)
# compiling and linking flags
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")

View File

@ -0,0 +1,81 @@
# Copyright (c) 2022 Intel Corporation
# Copyright (c) 2020-2021 Alibaba Cloud
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.1.4)
project(sgx-ra)
################ runtime settings ##############
set (WAMR_BUILD_PLATFORM "linux-sgx")
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# Set WAMR_BUILD_TARGET
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif ()
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_LIB_PTHREAD 1)
set (WAMR_BUILD_FAST_INTERP 1)
set (WAMR_BUILD_LIB_RATS 1)
# compiling and linking flags
if (COLLECT_CODE_COVERAGE EQUAL 1)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif ()
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -ffunction-sections -fdata-sections \
-Wall -Wno-unused-parameter -Wno-pedantic \
-nostdinc -fvisibility=hidden -fpie" )
# build out vmlib
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
set (SGX_PLATFORM_DIR ${WAMR_ROOT_DIR}/product-mini/platforms/linux-sgx)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
add_custom_command (
OUTPUT libvmlib_untrusted.a
COMMAND mkdir -p untrusted && cd untrusted &&
${CMAKE_C_COMPILER} -c ${PLATFORM_SHARED_SOURCE_UNTRUSTED}
COMMAND ${CMAKE_AR} rc libvmlib_untrusted.a untrusted/*.o)
add_custom_target (vmlib_untrusted ALL DEPENDS libvmlib_untrusted.a)
execute_process (
COMMAND bash -c "sed -i -E 's/^#define LIB_RATS 0/#define LIB_RATS 1/g' ${SGX_PLATFORM_DIR}/enclave-sample/Enclave/Enclave.edl"
OUTPUT_VARIABLE cmdOutput
)
################ wamr runtime ###################
add_custom_target (
iwasm ALL
DEPENDS vmlib_untrusted vmlib_untrusted
COMMAND make -C ${SGX_PLATFORM_DIR}/enclave-sample SGX_MODE=HW SGX_DEBUG=1 VMLIB_BUILD_DIR=${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${SGX_PLATFORM_DIR}/enclave-sample/enclave.signed.so ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${SGX_PLATFORM_DIR}/enclave-sample/iwasm ${CMAKE_BINARY_DIR}
COMMAND make -C ${SGX_PLATFORM_DIR}/enclave-sample clean)
################ wasm application ###############
add_subdirectory(wasm-app)

42
samples/sgx-ra/README.md Normal file
View File

@ -0,0 +1,42 @@
"sgx-ra" sample introduction
==============
This sample demonstrates how to execute Remote Attestation on SGX with [librats](https://github.com/inclavare-containers/librats) and run it with iwasm. It can only build on [SGX supported processors](https://www.intel.com/content/www/us/en/support/articles/000028173/processors.html), please check it.
## Preparation
Before staring, we need to download and intall [SGX SDK](https://download.01.org/intel-sgx/latest/linux-latest/distro) and [SGX DCAP Library](https://download.01.org/intel-sgx/latest/dcap-latest) referring to this [guide](https://download.01.org/intel-sgx/sgx-dcap/1.8/linux/docs/Intel_SGX_DCAP_Linux_SW_Installation_Guide.pdf).
The following command is the example of the SGX environment installation on ubuntu18.04.
``` shell
$ cd $HOME
$ # Set your platform, you can get the platforms list on
$ # https://download.01.org/intel-sgx/latest/linux-latest/distro
$ SGX_PALTFORM=ubuntu18.04-server
$ SGX_SDK_VERSION=2.17.100.3
$ SGX_DRIVER_VERSION=1.41
$ # install SGX Driver
$ wget https://download.01.org/intel-sgx/latest/linux-latest/distro/$SGX_PALTFORM/sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin
$ chmod +x sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin
$ sudo ./sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin
$ # install SGX SDK
$ wget https://download.01.org/intel-sgx/latest/linux-latest/distro/$SGX_PALTFORM/sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin
$ chmod +x sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin
$ sudo ./sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin
$ # install SGX DCAP Library
$ echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu bionic main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list > /dev/null
$ wget -O - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
$ sudo apt update
$ sudo apt install libsgx-uae-service libsgx-dcap-default-qpl-dev libsgx-dcap-ql-dev libsgx-dcap-quote-verify-dev
```
## Build
``` shell
$ mkdir build && cd build
$ cmake ..
$ make
$ # run the sample
$ ./iwasm wasm-app/test.wasm
```
The sample will print the evidence in json and "Evidence is trusted." by default.

View File

@ -0,0 +1,38 @@
# Copyright (c) 2022 Intel Corporation
# Copyright (c) 2020-2021 Alibaba Cloud
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.0)
project(wasm-app)
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
set (LIB_RATS_DIR ${WAMR_ROOT_DIR}/core/iwasm/libraries/lib-rats)
set (CMAKE_C_LINK_FLAGS "")
set (CMAKE_CXX_LINK_FLAGS "")
if (APPLE)
set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
endif ()
set (CMAKE_SYSTEM_PROCESSOR wasm32)
set (CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot)
if (NOT DEFINED WASI_SDK_DIR)
set (WASI_SDK_DIR "/opt/wasi-sdk")
endif ()
set (CMAKE_C_FLAGS "-nostdlib")
set (CMAKE_C_COMPILER_TARGET "wasm32")
set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
set (CMAKE_EXE_LINKER_FLAGS
"-Wl,--max-memory=131072 -z stack-size=8192 \
-Wl,--no-entry,--strip-all \
-Wl,--export=__main_argc_argv \
-Wl,--export=__heap_base,--export=__data_end \
-Wl,--allow-undefined"
)
add_executable(test.wasm main.c)
set_target_properties(test.wasm PROPERTIES INCLUDE_DIRECTORIES ${LIB_RATS_DIR})
target_link_libraries(test.wasm)

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 Intel Corporation
* Copyright (c) 2020-2021 Alibaba Cloud
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <stdlib.h>
#include "lib_rats_wrapper.h"
int
main(int argc, char **argv)
{
char *evidence_json = NULL;
const char *hash = "12345678123456781234567812345678";
evidence_json = librats_collect((const uint8_t *)hash);
if (evidence_json == NULL) {
printf("Librats collect evidence failed.\n");
return -1;
}
printf("evidence json:\n%s\n", evidence_json);
if (librats_verify(evidence_json, (const uint8_t *)hash) != 0) {
printf("Evidence is not trusted.\n");
}
else {
printf("Evidence is trusted.\n");
}
if (evidence_json) {
free(evidence_json);
}
return 0;
}

View File

@ -87,10 +87,10 @@ ExternalProject_Add(wasm-app
${CMAKE_CURRENT_SOURCE_DIR}/wasm-src
BUILD_COMMAND ${CMAKE_COMMAND} --build .
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy
tcp_client.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build
tcp_server.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build
send_recv.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build
socket_opts.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build
tcp_client.wasm ${CMAKE_BINARY_DIR}
tcp_server.wasm ${CMAKE_BINARY_DIR}
send_recv.wasm ${CMAKE_BINARY_DIR}
socket_opts.wasm ${CMAKE_BINARY_DIR}
)
add_executable(tcp_server ${CMAKE_CURRENT_SOURCE_DIR}/wasm-src/tcp_server.c)

View File

@ -90,5 +90,5 @@ ExternalProject_Add(xnnpack
//:f32_sqrt_ulp_eval.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/bazel-out/wasm-opt/bin/
${CMAKE_CURRENT_SOURCE_DIR}/build/wasm-opt
${CMAKE_BINARY_DIR}/wasm-opt
)

View File

@ -42,5 +42,5 @@ ExternalProject_Add(bwa
-DCMAKE_SYSROOT=${WASI_SDK_HOME}/share/wasi-sysroot
${CMAKE_CURRENT_SOURCE_DIR}/bwa
BUILD_COMMAND make bwa_wasm_opt
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./bwa.opt.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/bwa.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./bwa.opt.wasm ${CMAKE_BINARY_DIR}/bwa.wasm
)

View File

@ -26,5 +26,5 @@ ExternalProject_Add(codecbench
-DCMAKE_SYSROOT=${WASI_SDK_HOME}/share/wasi-sysroot
${CMAKE_CURRENT_SOURCE_DIR}/meshoptimizer
BUILD_COMMAND make codecbench
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./codecbench.wasm ${CMAKE_CURRENT_SOURCE_DIR}/build/codecbench.wasm
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ./codecbench.wasm ${CMAKE_BINARY_DIR}/codecbench.wasm
)

View File

@ -1,10 +1,10 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f4378ce..9bc104b 100644
index b13d946..4254003 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,3 +129,43 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/meshoptimizerConfig.cmake
@@ -149,3 +149,43 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/meshoptimizerConfigVersion.cmake
COMPONENT meshoptimizer
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshoptimizer)
+
+##################################################
@ -47,10 +47,10 @@ index f4378ce..9bc104b 100644
+
+add_dependencies(codecbench.opt codecbench)
diff --git a/src/vertexcodec.cpp b/src/vertexcodec.cpp
index 5f3ec20..b79bfad 100644
index 821c467..b7d30b1 100644
--- a/src/vertexcodec.cpp
+++ b/src/vertexcodec.cpp
@@ -81,13 +81,13 @@
@@ -83,13 +83,13 @@
#endif
#ifdef SIMD_WASM
@ -71,7 +71,7 @@ index 5f3ec20..b79bfad 100644
#endif
namespace meshopt
@@ -700,7 +700,7 @@ static v128_t decodeShuffleMask(unsigned char mask0, unsigned char mask1)
@@ -691,7 +691,7 @@ static v128_t decodeShuffleMask(unsigned char mask0, unsigned char mask1)
v128_t sm1 = wasm_v128_load(&kDecodeBytesGroupShuffle[mask1]);
v128_t sm1off = wasm_v128_load(&kDecodeBytesGroupCount[mask0]);
@ -80,7 +80,7 @@ index 5f3ec20..b79bfad 100644
v128_t sm1r = wasm_i8x16_add(sm1, sm1off);
@@ -751,7 +751,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
@@ -741,7 +741,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
v128_t shuf = decodeShuffleMask(mask0, mask1);
@ -89,7 +89,7 @@ index 5f3ec20..b79bfad 100644
wasm_v128_store(buffer, result);
@@ -773,7 +773,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
@@ -763,7 +763,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
v128_t shuf = decodeShuffleMask(mask0, mask1);
@ -99,10 +99,10 @@ index 5f3ec20..b79bfad 100644
wasm_v128_store(buffer, result);
diff --git a/src/vertexfilter.cpp b/src/vertexfilter.cpp
index 023452c..2374cf7 100644
index 14a73b1..8f4b3c1 100644
--- a/src/vertexfilter.cpp
+++ b/src/vertexfilter.cpp
@@ -56,10 +56,10 @@
@@ -57,10 +57,10 @@
#endif
#ifdef SIMD_WASM