|
1 | 1 | use core::ffi::c_void;
|
| 2 | +#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(miri)))] |
| 3 | +use core::ffi::c_void; |
2 | 4 | use core::fmt;
|
3 | 5 |
|
4 | 6 | /// Inspects the current call-stack, passing all active frames into the closure
|
@@ -125,39 +127,46 @@ impl fmt::Debug for Frame {
|
125 | 127 | }
|
126 | 128 | }
|
127 | 129 |
|
128 |
| -#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))] |
129 |
| -mod sgx_no_std_image_base { |
130 |
| - use core::ffi::c_void; |
131 |
| - use core::sync::atomic::{AtomicUsize, Ordering::SeqCst}; |
| 130 | +#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(miri)))] |
| 131 | +mod sgx_image_base { |
132 | 132 |
|
133 |
| - static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0); |
| 133 | + #[cfg(not(feature = "std"))] |
| 134 | + pub(crate) mod imp { |
| 135 | + use core::sync::atomic::{AtomicUsize, Ordering::SeqCst}; |
134 | 136 |
|
135 |
| - /// Set the image base address. This is only available for Fortanix SGX |
136 |
| - /// target when the `std` feature is not enabled. This can be used in the |
137 |
| - /// standard library to set the correct base address. |
138 |
| - #[doc(hidden)] |
139 |
| - pub fn set_image_base(base_addr: *mut c_void) { |
140 |
| - IMAGE_BASE.store(base_addr as _, SeqCst); |
141 |
| - } |
| 137 | + static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0); |
142 | 138 |
|
143 |
| - pub(crate) fn get_image_base() -> *mut c_void { |
144 |
| - IMAGE_BASE.load(SeqCst) as _ |
145 |
| - } |
146 |
| -} |
| 139 | + /// Set the image base address. This is only available for Fortanix SGX |
| 140 | + /// target when the `std` feature is not enabled. This can be used in the |
| 141 | + /// standard library to set the correct base address. |
| 142 | + #[doc(hidden)] |
| 143 | + pub fn set_image_base(base_addr: *mut c_void) { |
| 144 | + IMAGE_BASE.store(base_addr as _, SeqCst); |
| 145 | + } |
147 | 146 |
|
148 |
| -#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))] |
149 |
| -pub use self::sgx_no_std_image_base::set_image_base; |
| 147 | + pub(crate) fn get_image_base() -> *mut c_void { |
| 148 | + IMAGE_BASE.load(SeqCst) as _ |
| 149 | + } |
| 150 | + } |
150 | 151 |
|
151 |
| -#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))] |
152 |
| -#[deny(unused)] |
153 |
| -pub(crate) use self::sgx_no_std_image_base::get_image_base; |
| 152 | + #[cfg(feature = "std")] |
| 153 | + mod imp { |
| 154 | + pub(crate) fn get_image_base() -> *mut c_void { |
| 155 | + std::os::fortanix_sgx::mem::image_base() as _ |
| 156 | + } |
| 157 | + } |
154 | 158 |
|
155 |
| -#[cfg(all(target_env = "sgx", target_vendor = "fortanix", feature = "std"))] |
156 |
| -#[deny(unused)] |
157 |
| -pub(crate) fn get_image_base() -> *mut c_void { |
158 |
| - std::os::fortanix_sgx::mem::image_base() as _ |
| 159 | + pub(crate) use imp::get_image_base; |
159 | 160 | }
|
160 | 161 |
|
| 162 | +#[cfg(all( |
| 163 | + target_env = "sgx", |
| 164 | + target_vendor = "fortanix", |
| 165 | + not(feature = "std"), |
| 166 | + not(miri) |
| 167 | +))] |
| 168 | +pub use sgx_image_base::imp::set_image_base; |
| 169 | + |
161 | 170 | cfg_if::cfg_if! {
|
162 | 171 | // This needs to come first, to ensure that
|
163 | 172 | // Miri takes priority over the host platform
|
|
0 commit comments