Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor SGX directory structure #588

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ target_include_directories(faasm_common_deps INTERFACE

# Faasm SGX support
if (SGX_FOUND)
add_subdirectory(src/sgx)
add_subdirectory(src/enclave)
else ()
add_library(faasm_sgx_dummy INTERFACE)
add_library(faasm::sgx ALIAS faasm_sgx_dummy)
add_library(faasm_enclave_dummy INTERFACE)
add_library(faasm::enclave ALIAS faasm_enclave_dummy)
endif ()

# Faasm runtime
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <sgx/crypto/types.h>
#include <sgx/error.h>
#include <enclave/error.h>
#include <enclave/inside/crypto/types.h>

#include <sgx_tcrypto.h>
#include <sgx_trts.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <sgx/crypto/types.h>
#include <enclave/inside/crypto/types.h>

#include <sgx_tcrypto.h>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions include/sgx/native.h → include/enclave/inside/native.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <sgx/error.h>
#include <sgx/ocalls.h>
#include <enclave/error.h>
#include <enclave/inside/ocalls.h>

#include <iwasm/aot/aot_runtime.h>
#include <iwasm/common/wasm_exec_env.h>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <sgx/attestation.h>
#include <sgx/error.h>
#include <enclave/error.h>

#include <storage/FileLoader.h>
#include <storage/FileSystem.h>
Expand Down Expand Up @@ -74,9 +73,6 @@ class SGXWAMRWasmModule final : public WasmModule

uint8_t* getMemoryBase() override;

// TODO: Move in gs/fs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class member was defined in attestation.h and was not used.

faaslet_sgx_msg_buffer_t sgxWamrMsgResponse;

private:
uint32_t threadId = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion include/sgx/system.h → include/enclave/outside/system.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <sgx/error.h>
#include <enclave/error.h>

#include <sgx_eid.h>
#include <sgx_error.h>
Expand Down
83 changes: 0 additions & 83 deletions include/sgx/attestation.h

This file was deleted.

109 changes: 109 additions & 0 deletions src/enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# --------------------------------------------------------
# SGX Config and Checks Shared Between Trusted/Untrusted Builds
# --------------------------------------------------------

# SGX configuration
set(SGX_SDK_LIB_PATH ${SGX_SDK_PATH}/lib64)
set(SGX_SDK_ENCLAVE_SIGNER ${SGX_SDK_PATH}/bin/x64/sgx_sign)
set(SGX_SDK_ENCLAVE_EDGER8R ${SGX_SDK_PATH}/bin/x64/sgx_edger8r)
set(ENCLAVE_PATH "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/enclave_trusted.sign.so")
set(ENCLAVE_EDL_FILENAME "enclave")
add_definitions(-DFAASM_ENCLAVE_PATH="${ENCLAVE_PATH}")

# Check for SGX SDK
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(EXISTS ${SGX_SDK_PATH})
message(STATUS "Found SGX-SDK: TRUE")
else()
message(STATUS "Found SGX-SDK: FALSE")
message(FATAL_ERROR "SGX-SDK not installed in ${SGX_SDK_PATH}")
endif()

# NASM configuration
enable_language(ASM_NASM)
set(CMAKE_ASM_NASM_FLAGS -felf64)
set(CMAKE_ASM_NASM_COMPILE_OBJECT
"<CMAKE_ASM_NASM_COMPILER> <INCLUDES> ${CMAKE_ASM_NASM_FLAGS} -o <OBJECT> <SOURCE>"
)

# --------------------------------------------------------
# Global SGX Compilation Flags
# --------------------------------------------------------

set(SGX_C_GLOBAL_FLAGS -m64)

if(CMAKE_BUILD_TYPE EQUAL "Debug")
set(SGX_C_GLOBAL_FLAGS ${SGX_C_GLOBAL_FLAGS} -O0 -g)

add_definitions(-DFAASM_SGX_DEBUG)
else()
set(SGX_C_GLOBAL_FLAGS ${SGX_C_GLOBAL_FLAGS} -O2)
endif()


# --------------------------------------------------------
# WAMR Build Common For Trusted and Untrusted
#
# 28/06/2021 - To build WAMR inside SGX, we follow the provided example:
# https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/product-mini/platforms/linux-sgx/CMakeLists.txt
# --------------------------------------------------------

# Set target platform details
set(WAMR_BUILD_PLATFORM "linux-sgx")
set(WAMR_BUILD_TARGET X86_64)
set(WAMR_BUILD_SPEC_TEST)

# Set AOT mode, disable JIT
set(WAMR_BUILD_AOT 1)
set(WAMR_BUILD_JIT 0)
set(WAMR_BUILD_LAZY_JIT 0)

# Set libraries
set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_LIBC_WASI 0)
set(WAMR_BUILD_LIB_PTHREAD 0)

# Let WAMR do the including and importing of the sources
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)

# WAMR Trusted lib
faasm_private_lib(wamrlib_trusted "${WAMR_RUNTIME_LIB_SOURCE}")

target_include_directories(wamrlib_trusted PRIVATE
${SGX_SDK_PATH}/include
${SGX_SDK_PATH}/include/tlibc
${SGX_SDK_PATH}/include/libcxx
)

target_compile_options(wamrlib_trusted PRIVATE
-std=gnu99
-fPIC
-ffunction-sections
-fdata-sections
-Wall
-Wno-unused-parameter
-Wno-pedantic
-nostdinc
-fvisibility=hidden
)

# WAMR untrusted lib
add_library(wamrlib_untrusted STATIC ${PLATFORM_SHARED_SOURCE_UNTRUSTED})

target_compile_options(wamrlib_untrusted PRIVATE
-fPIC
-ffunction-sections
-fdata-sections
)

# --------------------------------------------------------
# Trusted Enclave Library
# --------------------------------------------------------
add_subdirectory(inside)

# --------------------------------------------------------
# Untrusted Enclave Library
# --------------------------------------------------------
add_subdirectory(outside)

Loading