about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVardhan Thigle <vardhan.thigle@fortanix.com>2019-01-09 17:20:37 +0530
committerVardhan Thigle <vardhan.thigle@fortanix.com>2019-01-09 18:07:59 +0530
commit2e4766c3afcdac9f45edbd73723384b360ee4b68 (patch)
treed7057bf0b7f19b7ccd870a9310dad0c13fb95cee
parent4166a4e5d0ef32ceb0d67d1f5dba334caf439a0d (diff)
downloadrust-2e4766c3afcdac9f45edbd73723384b360ee4b68.tar.gz
rust-2e4766c3afcdac9f45edbd73723384b360ee4b68.zip
Exposing enclave image-base to the enclave application
image-base could be used by crates like backtrace to providing to make
symbol resolution easier.
-rw-r--r--src/libstd/sys/sgx/abi/mem.rs4
-rw-r--r--src/libstd/sys/sgx/backtrace.rs8
2 files changed, 5 insertions, 7 deletions
diff --git a/src/libstd/sys/sgx/abi/mem.rs b/src/libstd/sys/sgx/abi/mem.rs
index 09552d5b4af..808f1ce3ff2 100644
--- a/src/libstd/sys/sgx/abi/mem.rs
+++ b/src/libstd/sys/sgx/abi/mem.rs
@@ -17,8 +17,10 @@ extern {
 // Do not remove inline: will result in relocation failure
 // For the same reason we use inline ASM here instead of an extern static to
 // locate the base
+/// Returns address at which current enclave is loaded.
 #[inline(always)]
-fn image_base() -> u64 {
+#[unstable(feature = "sgx_platform", issue = "56975")]
+pub fn image_base() -> u64 {
     let base;
     unsafe { asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) };
     base
diff --git a/src/libstd/sys/sgx/backtrace.rs b/src/libstd/sys/sgx/backtrace.rs
index 7e792300f43..2b8e1da0579 100644
--- a/src/libstd/sys/sgx/backtrace.rs
+++ b/src/libstd/sys/sgx/backtrace.rs
@@ -3,6 +3,7 @@ use error::Error;
 use libc;
 use sys_common::backtrace::Frame;
 use unwind as uw;
+use sys::sgx::abi::mem::image_base;
 
 pub struct BacktraceContext;
 
@@ -75,11 +76,6 @@ extern "C" fn trace_fn(
     uw::_URC_NO_REASON
 }
 
-extern {
-   static IMAGE_BASE: u8;
-}
-
-
 // To reduce TCB size in Sgx enclave, we do not want to implement resolve_symname functionality.
 // Rather, we print the offset of the address here, which could be later mapped to correct function.
 pub fn resolve_symname<F>(frame: Frame,
@@ -88,7 +84,7 @@ pub fn resolve_symname<F>(frame: Frame,
     where F: FnOnce(Option<&str>) -> io::Result<()>
 {
     callback(Some(&format!("0x{:x}",
-            (unsafe {frame.symbol_addr.wrapping_offset_from(&IMAGE_BASE)}))))
+            (frame.symbol_addr.wrapping_offset_from(image_base() as _)))))
 }
 
 pub fn foreach_symbol_fileline<F>(_: Frame,