Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backtrace/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Frame {
// the address here, which could be later mapped to correct function.
#[cfg(all(target_env = "sgx", target_vendor = "fortanix"))]
{
let image_base = super::get_image_base();
let image_base = super::sgx_image_base::get_image_base();
ip = usize::wrapping_sub(ip as usize, image_base as _) as _;
}
ip
Expand Down
64 changes: 37 additions & 27 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,39 +125,49 @@ impl fmt::Debug for Frame {
}
}

#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
mod sgx_no_std_image_base {
use core::ffi::c_void;
use core::sync::atomic::{AtomicUsize, Ordering::SeqCst};

static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0);

/// Set the image base address. This is only available for Fortanix SGX
/// target when the `std` feature is not enabled. This can be used in the
/// standard library to set the correct base address.
#[doc(hidden)]
pub fn set_image_base(base_addr: *mut c_void) {
IMAGE_BASE.store(base_addr as _, SeqCst);
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(miri)))]
mod sgx_image_base {

#[cfg(not(feature = "std"))]
pub(crate) mod imp {
use core::ffi::c_void;
use core::sync::atomic::{AtomicUsize, Ordering::SeqCst};

static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0);

/// Set the image base address. This is only available for Fortanix SGX
/// target when the `std` feature is not enabled. This can be used in the
/// standard library to set the correct base address.
#[doc(hidden)]
pub fn set_image_base(base_addr: *mut c_void) {
IMAGE_BASE.store(base_addr as _, SeqCst);
}

pub(crate) fn get_image_base() -> *mut c_void {
IMAGE_BASE.load(SeqCst) as _
}
}

pub(crate) fn get_image_base() -> *mut c_void {
IMAGE_BASE.load(SeqCst) as _
}
}

#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
pub use self::sgx_no_std_image_base::set_image_base;
#[cfg(feature = "std")]
mod imp {
use core::ffi::c_void;

#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
#[deny(unused)]
pub(crate) use self::sgx_no_std_image_base::get_image_base;
pub(crate) fn get_image_base() -> *mut c_void {
std::os::fortanix_sgx::mem::image_base() as _
}
}

#[cfg(all(target_env = "sgx", target_vendor = "fortanix", feature = "std"))]
#[deny(unused)]
pub(crate) fn get_image_base() -> *mut c_void {
std::os::fortanix_sgx::mem::image_base() as _
pub(crate) use imp::get_image_base;
}

#[cfg(all(
target_env = "sgx",
target_vendor = "fortanix",
not(feature = "std"),
not(miri)
))]
pub use sgx_image_base::imp::set_image_base;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes part of the public API of this library here. I don't think it should be disabled in Miri.


cfg_if::cfg_if! {
// This needs to come first, to ensure that
// Miri takes priority over the host platform
Expand Down