Skip to content

Commit 6e7ea03

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

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

library/std/src/backtrace.rs

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ 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+
{
332+
let image_base = crate::os::fortanix_sgx::mem::image_base();
333+
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
334+
}
330335
unsafe {
331336
backtrace_rs::trace_unsynchronized(|frame| {
332337
frames.push(BacktraceFrame {

library/std/src/sys_common/backtrace.rs

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ 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+
{
69+
let image_base = crate::os::fortanix_sgx::mem::image_base();
70+
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
71+
}
6772
backtrace_rs::trace_unsynchronized(|frame| {
6873
if print_fmt == PrintFmt::Short && idx > MAX_NB_FRAMES {
6974
return false;

0 commit comments

Comments
 (0)