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/08 10:47:01 UTC

[incubator-teaclave-sgx-sdk] branch v2.0.0-preview updated (75332f64 -> 0b52204a)

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

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


 discard 75332f64 Fix dead loop issue when sgx_trts is initialized
     new 0b52204a Fix dead loop issue when sgx_trts is initialized

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (75332f64)
            \
             N -- N -- N   refs/heads/v2.0.0-preview (0b52204a)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 sgx_trts/src/enclave/init.rs |  2 +-
 sgx_trts/src/enclave/mem.rs  | 48 +++++++++++++++++---------------------------
 2 files changed, 19 insertions(+), 31 deletions(-)


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


[incubator-teaclave-sgx-sdk] 01/01: Fix dead loop issue when sgx_trts is initialized

Posted by rd...@apache.org.
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

commit 0b52204aae9c28b9479982fcf824b3283a69bdd0
Author: volcano <vo...@163.com>
AuthorDate: Thu Sep 8 18:18:11 2022 +0800

    Fix dead loop issue when sgx_trts is initialized
---
 sgx_trts/src/enclave/init.rs |  2 +-
 sgx_trts/src/enclave/mem.rs  | 45 +++++++++++++++++++++-----------------------
 2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/sgx_trts/src/enclave/init.rs b/sgx_trts/src/enclave/init.rs
index 4742c2ea..1e61526d 100644
--- a/sgx_trts/src/enclave/init.rs
+++ b/sgx_trts/src/enclave/init.rs
@@ -42,7 +42,7 @@ pub fn rtinit(tcs: &mut Tcs, ms: *mut SystemFeatures, tidx: usize) -> SgxResult
     // TODO: pcl_entry
     parse::relocate()?;
 
-    mem::Image::get_or_init();
+    mem::Image::init();
     let features = SysFeatures::init(NonNull::new(ms).ok_or(SgxStatus::Unexpected)?)?;
 
     let heap = mem::Heap::get_or_init();
diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs
index d1120326..db578f84 100644
--- a/sgx_trts/src/enclave/mem.rs
+++ b/sgx_trts/src/enclave/mem.rs
@@ -19,7 +19,7 @@ use crate::arch;
 use crate::enclave::parse;
 use crate::error;
 use crate::feature::SysFeatures;
-use core::mem;
+use core::mem::{self, MaybeUninit};
 use core::ptr;
 use sgx_types::marker::ContiguousMemory;
 use sgx_types::types::ProtectPerm;
@@ -42,18 +42,18 @@ impl MmLayout {
     }
 
     #[inline]
-    pub fn entry_address() -> usize {
-        Image::get_or_init().entry_addr
+    pub fn elrange_base() -> usize {
+        Image::get().elrange_base
     }
 
     #[inline]
-    pub fn elrange_base() -> usize {
-        Image::get_or_init().elrange_base
+    pub fn elrange_size() -> usize {
+        Image::get().elrange_size
     }
 
     #[inline]
-    pub fn elrange_size() -> usize {
-        Image::get_or_init().elrange_size
+    pub fn entry_address() -> usize {
+        Image::get().entry_address
     }
 
     #[inline]
@@ -96,30 +96,27 @@ impl MmLayout {
 pub struct Image {
     pub image_base: usize,
     pub image_size: usize,
-    pub entry_addr: usize,
     pub elrange_base: usize,
     pub elrange_size: usize,
+    pub entry_address: usize,
 }
 
 #[link_section = ".data.rel.ro"]
-static mut IMAGE: Option<Image> = None;
+static mut IMAGE: MaybeUninit<Image> = MaybeUninit::uninit();
 
 impl Image {
-    pub fn get_or_init() -> &'static Image {
-        unsafe {
-            if let Some(ref enclave) = IMAGE {
-                enclave
-            } else {
-                IMAGE = Some(Image {
-                    image_base: Self::image_base(),
-                    image_size: Self::image_size(),
-                    entry_addr: Self::entry_address(),
-                    elrange_base: Self::elrange_base(),
-                    elrange_size: Self::elrange_size(),
-                });
-                IMAGE.as_ref().unwrap()
-            }
-        }
+    pub fn init() {
+        let mut image = unsafe { IMAGE.assume_init_mut() };
+        image.image_base = Self::image_base();
+        image.image_size = Self::image_size();
+        image.elrange_base = Self::elrange_base();
+        image.elrange_size = Self::elrange_size();
+        image.entry_address = Self::entry_address();
+    }
+
+    #[inline]
+    pub fn get() -> &'static Image {
+        unsafe { IMAGE.assume_init_ref() }
     }
 
     #[inline]


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