Skip to content

Commit 2e4766c

Browse files
author
Vardhan Thigle
committed
Exposing enclave image-base to the enclave application
image-base could be used by crates like backtrace to providing to make symbol resolution easier.
1 parent 4166a4e commit 2e4766c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ extern {
1717
// Do not remove inline: will result in relocation failure
1818
// For the same reason we use inline ASM here instead of an extern static to
1919
// locate the base
20+
/// Returns address at which current enclave is loaded.
2021
#[inline(always)]
21-
fn image_base() -> u64 {
22+
#[unstable(feature = "sgx_platform", issue = "56975")]
23+
pub fn image_base() -> u64 {
2224
let base;
2325
unsafe { asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) };
2426
base

src/libstd/sys/sgx/backtrace.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use error::Error;
33
use libc;
44
use sys_common::backtrace::Frame;
55
use unwind as uw;
6+
use sys::sgx::abi::mem::image_base;
67

78
pub struct BacktraceContext;
89

@@ -75,11 +76,6 @@ extern "C" fn trace_fn(
7576
uw::_URC_NO_REASON
7677
}
7778

78-
extern {
79-
static IMAGE_BASE: u8;
80-
}
81-
82-
8379
// To reduce TCB size in Sgx enclave, we do not want to implement resolve_symname functionality.
8480
// Rather, we print the offset of the address here, which could be later mapped to correct function.
8581
pub fn resolve_symname<F>(frame: Frame,
@@ -88,7 +84,7 @@ pub fn resolve_symname<F>(frame: Frame,
8884
where F: FnOnce(Option<&str>) -> io::Result<()>
8985
{
9086
callback(Some(&format!("0x{:x}",
91-
(unsafe {frame.symbol_addr.wrapping_offset_from(&IMAGE_BASE)}))))
87+
(frame.symbol_addr.wrapping_offset_from(image_base() as _)))))
9288
}
9389

9490
pub fn foreach_symbol_fileline<F>(_: Frame,

0 commit comments

Comments
 (0)