Move SGX-specific image base logic to sys_common

This commit is contained in:
Mohsen Zohrevandi 2023-11-14 13:27:57 -08:00
parent 6e7ea03c26
commit ec8c3d9992
2 changed files with 14 additions and 11 deletions

View File

@ -95,7 +95,7 @@ use crate::fmt;
use crate::panic::UnwindSafe;
use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use crate::sync::LazyLock;
use crate::sys_common::backtrace::{lock, output_filename};
use crate::sys_common::backtrace::{lock, output_filename, set_image_base};
use crate::vec::Vec;
/// A captured OS thread stack backtrace.
@ -327,11 +327,7 @@ 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 _));
}
set_image_base();
unsafe {
backtrace_rs::trace_unsynchronized(|frame| {
frames.push(BacktraceFrame {

View File

@ -64,11 +64,7 @@ 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 _));
}
set_image_base();
backtrace_rs::trace_unsynchronized(|frame| {
if print_fmt == PrintFmt::Short && idx > MAX_NB_FRAMES {
return false;
@ -218,3 +214,14 @@ pub fn output_filename(
}
fmt::Display::fmt(&file.display(), fmt)
}
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
pub fn set_image_base() {
let image_base = crate::os::fortanix_sgx::mem::image_base();
backtrace_rs::set_image_base(crate::ptr::from_exposed_addr_mut(image_base as _));
}
#[cfg(not(all(target_vendor = "fortanix", target_env = "sgx")))]
pub fn set_image_base() {
// nothing to do for platforms other than SGX
}