Skip to content

Commit 6763480

Browse files
committed
Adjust frame IP in backtraces relative to image base for SGX target
1 parent 4bd2fd5 commit 6763480

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

library/std/src/backtrace.rs

+4
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ impl Backtrace {
327327
let _lock = lock();
328328
let mut frames = Vec::new();
329329
let mut actual_start = None;
330+
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
331+
let image_base = crate::os::fortanix_sgx::mem::image_base();
332+
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
333+
}
330334
unsafe {
331335
backtrace_rs::trace_unsynchronized(|frame| {
332336
frames.push(BacktraceFrame {

library/std/src/sys_common/backtrace.rs

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
6464
let mut first_omit = true;
6565
// Start immediately if we're not using a short backtrace.
6666
let mut start = print_fmt != PrintFmt::Short;
67+
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
68+
let image_base = crate::os::fortanix_sgx::mem::image_base();
69+
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
70+
}
6771
backtrace_rs::trace_unsynchronized(|frame| {
6872
if print_fmt == PrintFmt::Short && idx > MAX_NB_FRAMES {
6973
return false;

0 commit comments

Comments
 (0)