You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by rd...@apache.org on 2022/12/05 11:16:11 UTC

[incubator-teaclave-sgx-sdk] branch v2.0.0-preview updated: Fix capi incompatibility with intel sgx sdk

This is an automated email from the ASF dual-hosted git repository.

rduan pushed a commit to branch v2.0.0-preview
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git


The following commit(s) were added to refs/heads/v2.0.0-preview by this push:
     new 804f7295 Fix capi incompatibility with intel sgx sdk
804f7295 is described below

commit 804f7295a026bbcfb28a39d80f0a834f5eb67023
Author: volcano <vo...@163.com>
AuthorDate: Mon Dec 5 19:15:38 2022 +0800

    Fix capi incompatibility with intel sgx sdk
---
 rustlib/std/Cargo.toml                     |  3 ++-
 sgx_crypto/sgx_crypto_sys/tcrypto/Makefile |  2 ++
 sgx_libc/sgx_tlibc_sys/tlibc/Makefile      |  2 ++
 sgx_libc/sgx_tlibc_sys/tsafecrt/Makefile   |  2 ++
 sgx_libc/src/linux/mod.rs                  |  7 +------
 sgx_oc/src/linux/x86_64/mod.rs             | 24 ++++++++++++------------
 sgx_sync/src/capi.rs                       | 26 ++++++++------------------
 sgx_trts/src/capi.rs                       |  8 +++++++-
 sgx_tse/src/capi.rs                        | 11 +++++++++--
 9 files changed, 45 insertions(+), 40 deletions(-)

diff --git a/rustlib/std/Cargo.toml b/rustlib/std/Cargo.toml
index 6e3c63b4..6ede65f1 100644
--- a/rustlib/std/Cargo.toml
+++ b/rustlib/std/Cargo.toml
@@ -43,13 +43,14 @@ untrusted_time = []
 unsupported_process = []
 panic-unwind = ["panic_unwind"]
 profiler = ["profiler_builtins"]
+capi = ["sgx_sync/capi", "sgx_rsrvmm/capi"]
 
 [dependencies]
 sgx_alloc = { path = "../../sgx_alloc" }
 sgx_backtrace_sys = { path = "../../sgx_backtrace/sgx_backtrace_sys", optional = true }
 sgx_demangle = { path = "../../sgx_demangle", optional = true }
 sgx_ffi = { path = "../../sgx_ffi" }
-sgx_oc = { path = "../../sgx_oc", default-features = false, features = ["align"] }
+sgx_oc = { path = "../../sgx_oc", default-features = false, features = ["align", "extra_traits"] }
 sgx_sync = { path = "../../sgx_sync" }
 sgx_trts = { path = "../../sgx_trts" }
 sgx_types = { path = "../../sgx_types" }
diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile b/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile
index 35e3f30b..f99e2e98 100644
--- a/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile
+++ b/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile
@@ -124,6 +124,8 @@ ifeq ("$(wildcard $(IPPCP_DIR)/lib/linux/intel64)", "")
 CHECK_OPT := opt_check_failed
 endif
 
+.NOTPARALLEL:
+
 .PHONY: all
 all: $(CHECK_OPT) $(BUILD_DIR) $(TARGET) $(DISP_LIB_NAME)
 
diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/Makefile b/sgx_libc/sgx_tlibc_sys/tlibc/Makefile
index dc2855e3..4f5a93f9 100644
--- a/sgx_libc/sgx_tlibc_sys/tlibc/Makefile
+++ b/sgx_libc/sgx_tlibc_sys/tlibc/Makefile
@@ -89,6 +89,8 @@ CHECK_OPT := opt_check_failed
 endif
 endif
 
+.NOTPARALLEL:
+
 .PHONY: all
 all: $(CHECK_OPT) $(BUILD_DIR) $(LIBC_NAME)
 
diff --git a/sgx_libc/sgx_tlibc_sys/tsafecrt/Makefile b/sgx_libc/sgx_tlibc_sys/tsafecrt/Makefile
index d2eecece..7aa6d4bc 100644
--- a/sgx_libc/sgx_tlibc_sys/tsafecrt/Makefile
+++ b/sgx_libc/sgx_tlibc_sys/tsafecrt/Makefile
@@ -58,6 +58,8 @@ LIB_OBJS := $(addprefix $(OUT_DIR)/, $(LIB_OBJS))
 LIB_NAME := $(OUT_DIR)/libtsafecrt.a
 BUILD_DIR := build_dir
 
+.NOTPARALLEL:
+
 .PHONY: all
 all: $(BUILD_DIR) $(LIB_NAME)
 
diff --git a/sgx_libc/src/linux/mod.rs b/sgx_libc/src/linux/mod.rs
index 6cee33df..1b8074bb 100644
--- a/sgx_libc/src/linux/mod.rs
+++ b/sgx_libc/src/linux/mod.rs
@@ -18,6 +18,7 @@
 use core::mem;
 use core::ptr;
 use core::slice;
+use sgx_oc::ocall::set_errno;
 use sgx_trts::rand::rand;
 
 cfg_if! {
@@ -54,12 +55,6 @@ pub extern "C" fn errno() -> c_int {
     unsafe { *errno_location() }
 }
 
-/// Set the last error number.
-#[no_mangle]
-pub extern "C" fn set_errno(e: c_int) {
-    unsafe { *errno_location() = e }
-}
-
 #[no_mangle]
 pub extern "C" fn gai_strerror(errcode: c_int) -> *const c_char {
     use sgx_oc::linux::ocall::gai_error_cstr;
diff --git a/sgx_oc/src/linux/x86_64/mod.rs b/sgx_oc/src/linux/x86_64/mod.rs
index c7f357c9..3d88e8ec 100644
--- a/sgx_oc/src/linux/x86_64/mod.rs
+++ b/sgx_oc/src/linux/x86_64/mod.rs
@@ -377,8 +377,8 @@ cfg_if! {
             }
         }
         impl Eq for epoll_event {}
-        impl ::fmt::Debug for epoll_event {
-            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
+        impl core::fmt::Debug for epoll_event {
+            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 let events = self.events;
                 let u64 = self.u64;
                 f.debug_struct("epoll_event")
@@ -387,8 +387,8 @@ cfg_if! {
                     .finish()
             }
         }
-        impl ::hash::Hash for epoll_event {
-            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
+        impl core::hash::Hash for epoll_event {
+            fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
                 let events = self.events;
                 let u64 = self.u64;
                 events.hash(state);
@@ -407,16 +407,16 @@ cfg_if! {
             }
         }
         impl Eq for sockaddr_un {}
-        impl ::fmt::Debug for sockaddr_un {
-            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
+        impl core::fmt::Debug for sockaddr_un {
+            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 f.debug_struct("sockaddr_un")
                     .field("sun_family", &self.sun_family)
                 // FIXME: .field("sun_path", &self.sun_path)
                     .finish()
             }
         }
-        impl ::hash::Hash for sockaddr_un {
-            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
+        impl core::hash::Hash for sockaddr_un {
+            fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
                 self.sun_family.hash(state);
                 self.sun_path.hash(state);
             }
@@ -435,8 +435,8 @@ cfg_if! {
 
         impl Eq for sockaddr_storage {}
 
-        impl ::fmt::Debug for sockaddr_storage {
-            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
+        impl core::fmt::Debug for sockaddr_storage {
+            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 f.debug_struct("sockaddr_storage")
                     .field("ss_family", &self.ss_family)
                     .field("__ss_align", &self.__ss_align)
@@ -445,8 +445,8 @@ cfg_if! {
             }
         }
 
-        impl ::hash::Hash for sockaddr_storage {
-            fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
+        impl core::hash::Hash for sockaddr_storage {
+            fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
                 self.ss_family.hash(state);
                 self.__ss_pad2.hash(state);
             }
diff --git a/sgx_sync/src/capi.rs b/sgx_sync/src/capi.rs
index 85405794..82b70051 100644
--- a/sgx_sync/src/capi.rs
+++ b/sgx_sync/src/capi.rs
@@ -16,9 +16,9 @@
 // under the License..
 
 use crate::spin::SpinMutex;
-use crate::sys::locks::generic::condvar::{Condvar, MovableCondvar};
-use crate::sys::locks::generic::mutex::{MovableMutex, MovableReentrantMutex, Mutex, MutexControl};
-use crate::sys::locks::generic::rwlock::{MovableRwLock, RwLock};
+use crate::sys::locks::generic::condvar::Condvar;
+use crate::sys::locks::generic::mutex::{Mutex, MutexControl};
+use crate::sys::locks::generic::rwlock::RwLock;
 use alloc::boxed::Box;
 use core::mem;
 use core::mem::ManuallyDrop;
@@ -123,21 +123,11 @@ pub unsafe extern "C" fn sgx_thread_mutex_init(
     } else if mutex.control == SGX_THREAD_MUTEX_RECURSIVE {
         MutexControl::Recursive
     } else {
-        return EINVAL;
-    };
-
-    let mutex_ptr = match control {
-        MutexControl::NonRecursive => {
-            let m = ManuallyDrop::new(MovableMutex::new());
-            &**m as *const _ as *mut c_void
-        }
-        MutexControl::Recursive => {
-            let m = ManuallyDrop::new(MovableReentrantMutex::new());
-            &**m as *const _ as *mut c_void
-        }
+        MutexControl::NonRecursive
     };
 
-    mutex.mutex = mutex_ptr;
+    let m = ManuallyDrop::new(Box::new(Mutex::new_with_control(control)));
+    mutex.mutex = &**m as *const _ as *mut c_void;
     0
 }
 
@@ -217,7 +207,7 @@ pub unsafe extern "C" fn sgx_thread_cond_init(
 ) -> c_int {
     check_param!(cond, sgx_thread_cond_t);
 
-    let c = ManuallyDrop::new(MovableCondvar::new());
+    let c = ManuallyDrop::new(Box::new(Condvar::new()));
     (*cond).cond = &**c as *const _ as *mut c_void;
     0
 }
@@ -343,7 +333,7 @@ pub unsafe extern "C" fn sgx_thread_rwlock_init(
 ) -> c_int {
     check_param!(rwlock, sgx_thread_rwlock_t);
 
-    let rw = ManuallyDrop::new(MovableRwLock::new());
+    let rw = ManuallyDrop::new(Box::new(RwLock::new()));
     (*rwlock).rwlock = &**rw as *const _ as *mut c_void;
     0
 }
diff --git a/sgx_trts/src/capi.rs b/sgx_trts/src/capi.rs
index 12f23921..9cf01743 100644
--- a/sgx_trts/src/capi.rs
+++ b/sgx_trts/src/capi.rs
@@ -276,13 +276,19 @@ pub unsafe extern "C" fn sgx_read_rand(p: *mut u8, len: usize) -> u32 {
     }
 }
 
+#[inline]
+#[no_mangle]
+pub unsafe extern "C" fn get_thread_data() -> *const c_void {
+    current().tds() as *const _ as *const c_void
+}
+
 pub type sgx_thread_t = *const c_void;
 pub const SGX_THREAD_T_NULL: *const c_void = ptr::null();
 
 #[inline]
 #[no_mangle]
 pub unsafe extern "C" fn sgx_thread_self() -> sgx_thread_t {
-    current().tds() as *const _ as sgx_thread_t
+    get_thread_data()
 }
 
 #[inline]
diff --git a/sgx_tse/src/capi.rs b/sgx_tse/src/capi.rs
index 617a731f..ea581a0f 100644
--- a/sgx_tse/src/capi.rs
+++ b/sgx_tse/src/capi.rs
@@ -26,11 +26,18 @@ pub unsafe extern "C" fn sgx_create_report(
     report_data: *const ReportData,
     report: *mut Report,
 ) -> SgxStatus {
-    if target_info.is_null() || report_data.is_null() || report.is_null() {
+    if report.is_null() {
         return SgxStatus::InvalidParameter;
     }
 
-    match Report::for_target(&*target_info, &*report_data) {
+    let result = match (target_info.is_null(), report_data.is_null()) {
+        (true, true) => Report::for_self(),
+        (false, false) => Report::for_target(&*target_info, &*report_data),
+        (true, false) => Report::for_target(&TargetInfo::default(), &*report_data),
+        (false, true) => Report::for_target(&*target_info, &ReportData::default()),
+    };
+
+    match result {
         Ok(r) => {
             *report = r;
             SgxStatus::Success


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org