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:18:29 UTC

[incubator-teaclave-sgx-sdk] branch v2.0.0-preview updated: Fix dead loop issue when sgx_trts is initialized

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 75332f64 Fix dead loop issue when sgx_trts is initialized
75332f64 is described below

commit 75332f645d76b7c6bfb8e64c7978660f5fab5901
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/mem.rs | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs
index d1120326..b8778de0 100644
--- a/sgx_trts/src/enclave/mem.rs
+++ b/sgx_trts/src/enclave/mem.rs
@@ -41,11 +41,6 @@ impl MmLayout {
         arch::Global::get().enclave_size
     }
 
-    #[inline]
-    pub fn entry_address() -> usize {
-        Image::get_or_init().entry_addr
-    }
-
     #[inline]
     pub fn elrange_base() -> usize {
         Image::get_or_init().elrange_base
@@ -56,6 +51,11 @@ impl MmLayout {
         Image::get_or_init().elrange_size
     }
 
+    #[inline]
+    pub fn entry_address() -> usize {
+        Image::get_or_init().entry_address
+    }
+
     #[inline]
     pub fn heap_base() -> usize {
         Heap::get_or_init().base
@@ -96,9 +96,9 @@ 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"]
@@ -113,15 +113,20 @@ impl Image {
                 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(),
+                    entry_address: Self::entry_address(),
                 });
                 IMAGE.as_ref().unwrap()
             }
         }
     }
 
+    #[inline]
+    pub fn try_get() -> Option<&'static Image> {
+        unsafe { IMAGE.as_ref() }
+    }
+
     #[inline]
     fn image_base() -> usize {
         unsafe { &__ImageBase as *const _ as usize }
@@ -358,9 +363,11 @@ pub fn is_within_enclave(p: *const u8, len: usize) -> bool {
     } else {
         start
     };
-    let base = MmLayout::elrange_base();
+    let base = Image::try_get()
+        .map(|image| image.elrange_base)
+        .unwrap_or_else(Image::elrange_base);
 
-    (start <= end) && (start >= base) && (end < base + MmLayout::elrange_size())
+    (start <= end) && (start >= base) && (end < base + Image::elrange_size())
 }
 
 pub fn is_within_host(p: *const u8, len: usize) -> bool {
@@ -374,9 +381,11 @@ pub fn is_within_host(p: *const u8, len: usize) -> bool {
     } else {
         start
     };
-    let base = MmLayout::elrange_base();
+    let base = Image::try_get()
+        .map(|image| image.elrange_base)
+        .unwrap_or_else(Image::elrange_base);
 
-    (start <= end) && ((end < base) || (start > base + MmLayout::elrange_size() - 1))
+    (start <= end) && ((end < base) || (start > base + Image::elrange_size() - 1))
 }
 
 pub trait EnclaveRange {


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