Skip to content

Commit 43d7859

Browse files
committed
Use pointer types for SGX image base address
1 parent f09114a commit 43d7859

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/backtrace/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,21 @@ impl fmt::Debug for Frame {
127127

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

132-
static IMAGE_BASE: AtomicU64 = AtomicU64::new(0);
133+
static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0);
133134

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

142-
pub(crate) fn get_image_base() -> u64 {
143-
IMAGE_BASE.load(SeqCst)
143+
pub(crate) fn get_image_base() -> *mut c_void {
144+
IMAGE_BASE.load(SeqCst) as _
144145
}
145146
}
146147

@@ -153,8 +154,8 @@ pub(crate) use self::sgx_no_std_image_base::get_image_base;
153154

154155
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", feature = "std"))]
155156
#[deny(unused)]
156-
pub(crate) fn get_image_base() -> u64 {
157-
std::os::fortanix_sgx::mem::image_base()
157+
pub(crate) fn get_image_base() -> *mut c_void {
158+
std::os::fortanix_sgx::mem::image_base() as _
158159
}
159160

160161
cfg_if::cfg_if! {

tests/sgx-image-base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn sgx_image_base_no_std() {
3838
}
3939

4040
let image_base = guess_image_base();
41-
backtrace::set_image_base(image_base);
41+
backtrace::set_image_base(image_base as _);
4242

4343
let mut frame_ips = Vec::new();
4444
unsafe {

0 commit comments

Comments
 (0)