]> git.lizzy.rs Git - rust.git/commitdiff
Exposing enclave image-base to the enclave application
authorVardhan Thigle <vardhan.thigle@fortanix.com>
Wed, 9 Jan 2019 11:50:37 +0000 (17:20 +0530)
committerVardhan Thigle <vardhan.thigle@fortanix.com>
Wed, 9 Jan 2019 12:37:59 +0000 (18:07 +0530)
image-base could be used by crates like backtrace to providing to make
symbol resolution easier.

src/libstd/sys/sgx/abi/mem.rs
src/libstd/sys/sgx/backtrace.rs

index 09552d5b4af295b1d6c29ca2570980f4c8d3ee27..808f1ce3ff2c73a4265f9d60319357505de2a425 100644 (file)
@@ -17,8 +17,10 @@ pub(crate) unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
 // 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
index 7e792300f434cc44bc345f5a62b10a9e175fd30b..2b8e1da05791dee62231a0c0c1aeeb02ee26cadf 100644 (file)
@@ -3,6 +3,7 @@
 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,