Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Use pointer types for SGX image base address
  • Loading branch information
mzohreva committed Oct 6, 2023
commit 43d785942c40e8fd4f8a190e1cc75208ead0857c
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