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/09/06 12:58:43 UTC

[incubator-teaclave-sgx-sdk] branch v2.0.0-preview updated: Fix pthread_self for untrusted threads

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 cdae0480 Fix pthread_self for untrusted threads
cdae0480 is described below

commit cdae048017aee0d657a0f90e67b2fbeff5aa33ad
Author: volcano <vo...@163.com>
AuthorDate: Tue Sep 6 20:58:26 2022 +0800

    Fix pthread_self for untrusted threads
---
 sgx_libc/src/linux/pthread/mod.rs | 16 +++++-----------
 sgx_trts/src/capi.rs              |  2 +-
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/sgx_libc/src/linux/pthread/mod.rs b/sgx_libc/src/linux/pthread/mod.rs
index a3ab4e5f..00f1abe2 100644
--- a/sgx_libc/src/linux/pthread/mod.rs
+++ b/sgx_libc/src/linux/pthread/mod.rs
@@ -17,15 +17,15 @@
 
 use crate::linux::*;
 use core::mem;
-use core::mem::ManuallyDrop;
 use core::ptr;
 use sgx_sync::capi::*;
+use sgx_trts::capi::*;
 use sgx_trts::thread::tls::{Key, Tls};
 use sgx_trts::thread::{self, Native, Thread};
 use sgx_trts::trts::is_within_enclave;
 use sgx_types::error::SgxStatus;
 
-pub type pthread_t = *mut c_void;
+pub type pthread_t = *const c_void;
 pub type pthread_key_t = size_t;
 
 pub type pthread_mutex_t = sgx_thread_mutex_t;
@@ -83,7 +83,7 @@ pub unsafe extern "C" fn pthread_create(
     let f = move |arg| start_routine(arg);
     match Thread::new(f, arg) {
         Ok(t) => {
-            *thread = Thread::into_raw(t) as *mut c_void;
+            *thread = Thread::into_raw(t) as pthread_t;
             0
         }
         Err(e) => match e {
@@ -115,20 +115,14 @@ pub unsafe extern "C" fn pthread_join(thread: pthread_t, retval: *mut *mut c_voi
 #[no_mangle]
 pub unsafe extern "C" fn pthread_self() -> pthread_t {
     if let Some(t) = thread::current() {
-        Thread::into_raw(t) as *mut c_void
+        Thread::into_raw(t) as pthread_t
     } else {
-        ptr::null_mut()
+        sgx_thread_self()
     }
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn pthread_equal(t1: pthread_t, t2: pthread_t) -> c_int {
-    if t1.is_null() || t2.is_null() {
-        return 0;
-    }
-
-    let t1 = ManuallyDrop::new(Thread::from_raw(t1 as *mut Native));
-    let t2 = ManuallyDrop::new(Thread::from_raw(t2 as *mut Native));
     if t1 == t2 {
         1
     } else {
diff --git a/sgx_trts/src/capi.rs b/sgx_trts/src/capi.rs
index 58a8ba06..babc4e99 100644
--- a/sgx_trts/src/capi.rs
+++ b/sgx_trts/src/capi.rs
@@ -298,7 +298,7 @@ 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 *const c_void
+    current().tds() as *const _ as sgx_thread_t
 }
 
 #[inline]


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