Adjust frame IP in backtraces relative to image base for SGX target

This commit is contained in:
Mohsen Zohrevandi 2023-11-13 16:43:38 -08:00
parent 4bd2fd5c83
commit 6e7ea03c26
2 changed files with 10 additions and 0 deletions

View File

@ -327,6 +327,11 @@ impl Backtrace {
let _lock = lock();
let mut frames = Vec::new();
let mut actual_start = None;
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
{
let image_base = crate::os::fortanix_sgx::mem::image_base();
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
}
unsafe {
backtrace_rs::trace_unsynchronized(|frame| {
frames.push(BacktraceFrame {

View File

@ -64,6 +64,11 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
let mut first_omit = true;
// Start immediately if we're not using a short backtrace.
let mut start = print_fmt != PrintFmt::Short;
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
{
let image_base = crate::os::fortanix_sgx::mem::image_base();
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
}
backtrace_rs::trace_unsynchronized(|frame| {
if print_fmt == PrintFmt::Short && idx > MAX_NB_FRAMES {
return false;