Skip to content

Commit

Permalink
Fix deny(unused) of an unused import with SGX + Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Jan 5, 2024
1 parent 7b7c103 commit 07cecfa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
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
60 changes: 33 additions & 27 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,39 +125,45 @@ 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(feature = "std")]
mod imp {
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", not(feature = "std")))]
pub use self::sgx_no_std_image_base::set_image_base;

#[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;

#[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;

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

0 comments on commit 07cecfa

Please sign in to comment.