Upgrade Rust SGX SDK to v1.0.6

... and Intel SGX SDK to v2.4, Rust to nightly-2019-01-28
This commit is contained in:
Tate, Hongliang Tian 2019-02-23 16:21:35 +08:00 committed by Tate Tian
parent c2cf0c65b2
commit 7fcf195359
10 changed files with 65 additions and 38 deletions

@ -38,11 +38,11 @@ Occlum LibOS has several *explicit* and *implicit* dependencies: the former ones
Explicit dependencies are listed below: Explicit dependencies are listed below:
1. [Occlum's fork of Intel SGX SDK](https://github.com/occlum/linux-sgx/tree/for_occlum). See [README.md](https://github.com/occlum/linux-sgx/blob/for_occlum/README.md) for how to compile and install. 1. [enable_rdfsbase kernel module](https://github.com/occlum/enable_rdfsbase), which enables rdfsbase instruction and its friends. See [README.md](https://github.com/occlum/enable_rdfsbase/blob/master/README.md) for how to compile and install.
1. [Occlum's fork of Intel SGX SDK](https://github.com/occlum/linux-sgx/tree/sgx_2.4_for_occlum). See [README.md](https://github.com/occlum/linux-sgx/blob/sgx_2.4_for_occlum/README.md) for how to compile and install.
1. [Occlum's fork of LLVM toolchain](https://github.com/occlum/llvm/tree/for_occlum). See [README.occlum.md](https://github.com/occlum/llvm/blob/for_occlum/README.occlum.md) for how to compile and install. 1. [Occlum's fork of LLVM toolchain](https://github.com/occlum/llvm/tree/for_occlum). See [README.occlum.md](https://github.com/occlum/llvm/blob/for_occlum/README.occlum.md) for how to compile and install.
1. [Occlum's fork of musl libc](https://github.com/occlum/musl/tree/for_occlum). See [INSTALL](https://github.com/occlum/musl/blob/for_occlum/INSTALL) for how to compile and install. 1. [Occlum's fork of musl libc](https://github.com/occlum/musl/tree/for_occlum). See [INSTALL](https://github.com/occlum/musl/blob/for_occlum/INSTALL) for how to compile and install.
1. [enable_rdfsbase kernel module](https://github.com/occlum/enable_rdfsbase), which enables rdfsbase instruction and its friends. See [README.md](https://github.com/occlum/enable_rdfsbase/blob/master/README.md) for how to compile and install. 1. [Rust programming language](https://www.rust-lang.org/). We have tested with Rust nightly-2019-01-28. Other versions of Rust may or may not work.
1. [Rust programming language](https://www.rust-lang.org/). We have tested with Rust nightly-2018-10-01. Other versions of Rust may or may not work.
Implicit dependencies are managed by Git with [.gitmodules](https://github.com/occlum/libos/blob/master/.gitmodules) and compiled with Makefile. The most important implicit dependency is [Rust SGX SDK](https://github.com/baidu/rust-sgx-sdk). After downloading Occlum LibOS project, run the following command to set up the implicit dependecies: Implicit dependencies are managed by Git with [.gitmodules](https://github.com/occlum/libos/blob/master/.gitmodules) and compiled with Makefile. The most important implicit dependency is [Rust SGX SDK](https://github.com/baidu/rust-sgx-sdk). After downloading Occlum LibOS project, run the following command to set up the implicit dependecies:

2
deps/rust-sgx-sdk vendored

@ -1 +1 @@
Subproject commit 4d999470c8c12a6e6f70d302c09114957114bb05 Subproject commit a824416aba3840a2d76753b6da94130526b60893

@ -1 +1 @@
Subproject commit 3c9a9f063dacf5ef98971e64338d315e107a9083 Subproject commit 5f2e64efd27714e90b4a22f4a3ce46ef6598d32a

47
src/libos/Cargo.lock generated

@ -1,11 +1,13 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]] [[package]]
name = "Occlum" name = "Occlum"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sgx_trts 1.0.4", "sgx_trts 1.0.6",
"sgx_tstd 1.0.4", "sgx_tstd 1.0.6",
"sgx_types 1.0.4", "sgx_types 1.0.6",
"xmas-elf 0.6.2", "xmas-elf 0.6.2",
] ]
@ -20,9 +22,9 @@ dependencies = [
[[package]] [[package]]
name = "sgx_alloc" name = "sgx_alloc"
version = "1.0.4" version = "1.0.6"
dependencies = [ dependencies = [
"sgx_trts 1.0.4", "sgx_trts 1.0.6",
] ]
[[package]] [[package]]
@ -30,41 +32,50 @@ name = "sgx_build_helper"
version = "0.1.0" version = "0.1.0"
[[package]] [[package]]
name = "sgx_tprotected_fs" name = "sgx_libc"
version = "1.0.4" version = "1.0.6"
dependencies = [ dependencies = [
"sgx_trts 1.0.4", "sgx_types 1.0.6",
"sgx_types 1.0.4", ]
[[package]]
name = "sgx_tprotected_fs"
version = "1.0.6"
dependencies = [
"sgx_trts 1.0.6",
"sgx_types 1.0.6",
] ]
[[package]] [[package]]
name = "sgx_trts" name = "sgx_trts"
version = "1.0.4" version = "1.0.6"
dependencies = [ dependencies = [
"sgx_types 1.0.4", "sgx_libc 1.0.6",
"sgx_types 1.0.6",
] ]
[[package]] [[package]]
name = "sgx_tstd" name = "sgx_tstd"
version = "1.0.4" version = "1.0.6"
dependencies = [ dependencies = [
"sgx_alloc 1.0.4", "sgx_alloc 1.0.6",
"sgx_build_helper 0.1.0", "sgx_build_helper 0.1.0",
"sgx_tprotected_fs 1.0.4", "sgx_libc 1.0.6",
"sgx_trts 1.0.4", "sgx_tprotected_fs 1.0.6",
"sgx_types 1.0.4", "sgx_trts 1.0.6",
"sgx_types 1.0.6",
"sgx_unwind 0.0.1", "sgx_unwind 0.0.1",
] ]
[[package]] [[package]]
name = "sgx_types" name = "sgx_types"
version = "1.0.4" version = "1.0.6"
[[package]] [[package]]
name = "sgx_unwind" name = "sgx_unwind"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"sgx_trts 1.0.4", "sgx_trts 1.0.6",
] ]
[[package]] [[package]]

@ -17,7 +17,7 @@ ENCLAVE_CONFIG := Enclave_config.xml
ENCLAVE_KEY := Enclave_private.pem ENCLAVE_KEY := Enclave_private.pem
C_FLAGS := $(SGX_CFLAGS_T) -fno-stack-protector -I./include/ C_FLAGS := $(SGX_CFLAGS_T) -fno-stack-protector -I./include/
_Other_Link_Flags := -L../../deps/rust-sgx-sdk/compiler-rt/ -L. _Other_Link_Flags := -L$(RUST_SGX_SDK_DIR)/compiler-rt/ -L.
_Other_Enclave_Libs := -lcompiler-rt-patch -locclum_rs -lsgx_tprotected_fs _Other_Enclave_Libs := -lcompiler-rt-patch -locclum_rs -lsgx_tprotected_fs
LINK_FLAGS := $(SGX_LFLAGS_T) LINK_FLAGS := $(SGX_LFLAGS_T)
@ -42,11 +42,11 @@ $(S_OBJS): %.o: %.S
@echo "CC <= $@" @echo "CC <= $@"
$(EDL_C_SRCS): $(SGX_EDGER8R) ../Enclave.edl $(EDL_C_SRCS): $(SGX_EDGER8R) ../Enclave.edl
@cd src/ && $(SGX_EDGER8R) --trusted ../../Enclave.edl --search-path $(SGX_SDK)/include --search-path ../../../deps/rust-sgx-sdk/edl/ @cd src/ && $(SGX_EDGER8R) --trusted ../../Enclave.edl --search-path $(SGX_SDK)/include --search-path $(RUST_SGX_SDK_DIR)/edl/
@echo "GEN <= $(EDL_C_SRCS)" @echo "GEN <= $(EDL_C_SRCS)"
compiler-rt: compiler-rt:
@$(MAKE) --no-print-directory -C ../../deps/rust-sgx-sdk/compiler-rt/ > /dev/null @$(MAKE) --no-print-directory -C $(RUST_SGX_SDK_DIR)/compiler-rt/ > /dev/null
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
$(LIBOS_A): $(RUST_SRCS) $(LIBOS_A): $(RUST_SRCS)

@ -3,10 +3,12 @@
#![crate_type = "staticlib"] #![crate_type = "staticlib"]
#![cfg_attr(not(target_env = "sgx"), no_std)] #![cfg_attr(not(target_env = "sgx"), no_std)]
#![cfg_attr(target_env = "sgx", feature(rustc_private))] #![cfg_attr(target_env = "sgx", feature(rustc_private))]
#![feature(alloc)]
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(integer_atomics)]
#![feature(range_contains)] #![feature(range_contains)]
#[macro_use]
extern crate alloc;
extern crate sgx_types; extern crate sgx_types;
#[cfg(not(target_env = "sgx"))] #[cfg(not(target_env = "sgx"))]
#[macro_use] #[macro_use]

@ -14,12 +14,12 @@ pub struct Task {
} }
lazy_static! { lazy_static! {
static ref new_process_queue: SgxMutex<VecDeque<ProcessRef>> = static ref NEW_PROCESS_QUEUE: SgxMutex<VecDeque<ProcessRef>> =
{ SgxMutex::new(VecDeque::new()) }; { SgxMutex::new(VecDeque::new()) };
} }
pub fn enqueue_task(new_process: ProcessRef) { pub fn enqueue_task(new_process: ProcessRef) {
new_process_queue.lock().unwrap().push_back(new_process); NEW_PROCESS_QUEUE.lock().unwrap().push_back(new_process);
let mut ret = 0; let mut ret = 0;
let ocall_status = unsafe { ocall_run_new_task(&mut ret) }; let ocall_status = unsafe { ocall_run_new_task(&mut ret) };
@ -29,7 +29,7 @@ pub fn enqueue_task(new_process: ProcessRef) {
} }
fn dequeue_task() -> Option<ProcessRef> { fn dequeue_task() -> Option<ProcessRef> {
new_process_queue.lock().unwrap().pop_front() NEW_PROCESS_QUEUE.lock().unwrap().pop_front()
} }
pub fn run_task() -> Result<i32, Error> { pub fn run_task() -> Result<i32, Error> {

@ -3,6 +3,7 @@ use std::cmp::{max, min};
use std::ptr; use std::ptr;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use alloc::alloc::{Layout, alloc, dealloc};
#[derive(Debug)] #[derive(Debug)]
pub struct RingBuf { pub struct RingBuf {
@ -43,15 +44,17 @@ struct RingBufInner {
closed: AtomicBool, // if reader has been dropped closed: AtomicBool, // if reader has been dropped
} }
const RING_BUF_ALIGN : usize = 16;
impl RingBufInner { impl RingBufInner {
fn new(capacity: usize) -> RingBufInner { fn new(capacity: usize) -> RingBufInner {
let capacity = max(capacity, 16).next_power_of_two(); let capacity = max(capacity, RING_BUF_ALIGN).next_power_of_two();
RingBufInner { RingBufInner {
buf: unsafe { buf: unsafe {
let mut buf_ptr = ptr::null_mut(); let buf_layout = Layout::from_size_align_unchecked(capacity, RING_BUF_ALIGN);
libc::posix_memalign(&mut buf_ptr, 16, capacity); let buf_ptr = alloc(buf_layout);
assert!(buf_ptr != ptr::null_mut()); assert!(buf_ptr != ptr::null_mut());
buf_ptr as *mut u8 buf_ptr
}, },
capacity: capacity, capacity: capacity,
head: AtomicUsize::new(0), head: AtomicUsize::new(0),
@ -109,7 +112,10 @@ impl RingBufInner {
impl Drop for RingBufInner { impl Drop for RingBufInner {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { libc::free(self.buf as *mut c_void) } unsafe {
let buf_layout = Layout::from_size_align_unchecked(self.capacity, RING_BUF_ALIGN);
dealloc(self.buf, buf_layout);
}
} }
} }

@ -8,7 +8,7 @@ Bin := pal
C_Flags := $(SGX_CFLAGS_U) C_Flags := $(SGX_CFLAGS_U)
Link_Flags := $(SGX_LFLAGS_U) Link_Flags := $(SGX_LFLAGS_U)
Link_Flags += -L../../deps/rust-sgx-sdk/sgx_ustdc/ -lsgx_ustdc -lsgx_uprotected_fs Link_Flags += -L$(RUST_SGX_SDK_DIR)/sgx_ustdc/ -lsgx_ustdc -lsgx_uprotected_fs
.PHONY: all .PHONY: all
@ -19,7 +19,7 @@ $(Bin): $(EDL_Gen_Files) $(Objs) sgx_ustdc
@echo "LINK => $@" @echo "LINK => $@"
$(EDL_Gen_Files): $(SGX_EDGER8R) ../Enclave.edl $(EDL_Gen_Files): $(SGX_EDGER8R) ../Enclave.edl
@$(SGX_EDGER8R) --untrusted ../Enclave.edl --search-path $(SGX_SDK)/include --search-path ../../deps/rust-sgx-sdk/edl/ @$(SGX_EDGER8R) --untrusted ../Enclave.edl --search-path $(SGX_SDK)/include --search-path $(RUST_SGX_SDK_DIR)/edl/
@echo "GEN => $(EDL_Gen_Files)" @echo "GEN => $(EDL_Gen_Files)"
$(Objs): %.o: %.c $(Objs): %.o: %.c
@ -31,7 +31,7 @@ $(Objs): %.o: %.c
# #
.PHONY: sgx_ustdc .PHONY: sgx_ustdc
sgx_ustdc: sgx_ustdc:
@$(MAKE) --no-print-directory -C ../../deps/rust-sgx-sdk/sgx_ustdc/ > /dev/null @$(MAKE) --no-print-directory -C $(RUST_SGX_SDK_DIR)/sgx_ustdc/ > /dev/null
.PHONY: clean .PHONY: clean
clean: clean:

@ -1,3 +1,8 @@
MAIN_MAKEFILE := $(firstword $(MAKEFILE_LIST))
INCLUDE_MAKEFILE := $(lastword $(MAKEFILE_LIST))
CUR_DIR := $(shell dirname $(realpath $(MAIN_MAKEFILE)))
PROJECT_DIR := $(realpath $(CUR_DIR)/../../)
SGX_SDK ?= /opt/intel/sgxsdk SGX_SDK ?= /opt/intel/sgxsdk
SGX_MODE ?= HW SGX_MODE ?= HW
SGX_ARCH ?= x64 SGX_ARCH ?= x64
@ -32,6 +37,9 @@ else
SGX_COMMON_CFLAGS += -O2 SGX_COMMON_CFLAGS += -O2
endif endif
RUST_SGX_SDK_DIR := $(PROJECT_DIR)/deps/rust-sgx-sdk
SGX_COMMON_CFLAGS += -I$(RUST_SGX_SDK_DIR)/common/ -I$(RUST_SGX_SDK_DIR)/edl/
ifneq ($(SGX_MODE), HW) ifneq ($(SGX_MODE), HW)
Urts_Library_Name := sgx_urts_sim Urts_Library_Name := sgx_urts_sim
else else