Skip to content

Commit

Permalink
Exposing enclave image-base to the enclave application
Browse files Browse the repository at this point in the history
image-base could be used by crates like backtrace to providing to make
symbol resolution easier.
  • Loading branch information
Vardhan Thigle committed Jan 9, 2019
1 parent 4166a4e commit 2e4766c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/libstd/sys/sgx/abi/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/libstd/sys/sgx/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 2e4766c

Please sign in to comment.