From 43d785942c40e8fd4f8a190e1cc75208ead0857c Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Fri, 6 Oct 2023 11:42:35 -0700 Subject: [PATCH] Use pointer types for SGX image base address --- src/backtrace/mod.rs | 17 +++++++++-------- tests/sgx-image-base.rs | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/backtrace/mod.rs b/src/backtrace/mod.rs index c098755a..b6cfb166 100644 --- a/src/backtrace/mod.rs +++ b/src/backtrace/mod.rs @@ -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 _ } } @@ -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! { diff --git a/tests/sgx-image-base.rs b/tests/sgx-image-base.rs index d8bacf3d..c29a8b67 100644 --- a/tests/sgx-image-base.rs +++ b/tests/sgx-image-base.rs @@ -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 {