Skip to content

Commit

Permalink
Use pointer types for SGX image base address
Browse files Browse the repository at this point in the history
  • Loading branch information
mzohreva committed Oct 6, 2023
1 parent f09114a commit 43d7859
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,21 @@ impl fmt::Debug for Frame {

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

static IMAGE_BASE: AtomicU64 = AtomicU64::new(0);
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: u64) {
IMAGE_BASE.store(base_addr, SeqCst);
pub fn set_image_base(base_addr: *mut c_void) {
IMAGE_BASE.store(base_addr as _, SeqCst);
}

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

Expand All @@ -153,8 +154,8 @@ 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() -> u64 {
std::os::fortanix_sgx::mem::image_base()
pub(crate) fn get_image_base() -> *mut c_void {
std::os::fortanix_sgx::mem::image_base() as _
}

cfg_if::cfg_if! {
Expand Down
2 changes: 1 addition & 1 deletion tests/sgx-image-base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn sgx_image_base_no_std() {
}

let image_base = guess_image_base();
backtrace::set_image_base(image_base);
backtrace::set_image_base(image_base as _);

let mut frame_ips = Vec::new();
unsafe {
Expand Down

0 comments on commit 43d7859

Please sign in to comment.