@@ -125,6 +125,37 @@ impl fmt::Debug for Frame {
125125 }
126126}
127127
128+ #[ cfg( all( target_env = "sgx" , target_vendor = "fortanix" , not( feature = "std" ) ) ) ]
129+ mod sgx_no_std_image_base {
130+ use core:: sync:: atomic:: { AtomicU64 , Ordering :: SeqCst } ;
131+
132+ static IMAGE_BASE : AtomicU64 = AtomicU64 :: new ( 0 ) ;
133+
134+ /// Set the image base address. This is only available for Fortanix SGX
135+ /// target when the `std` feature is not enabled. This can be used in the
136+ /// standard library to set the correct base address.
137+ pub fn set_image_base ( base_addr : u64 ) {
138+ IMAGE_BASE . store ( base_addr, SeqCst ) ;
139+ }
140+
141+ pub ( crate ) fn get_image_base ( ) -> u64 {
142+ IMAGE_BASE . load ( SeqCst )
143+ }
144+ }
145+
146+ #[ cfg( all( target_env = "sgx" , target_vendor = "fortanix" , not( feature = "std" ) ) ) ]
147+ pub use self :: sgx_no_std_image_base:: set_image_base;
148+
149+ #[ cfg( all( target_env = "sgx" , target_vendor = "fortanix" , not( feature = "std" ) ) ) ]
150+ #[ deny( unused) ]
151+ pub ( crate ) use self :: sgx_no_std_image_base:: get_image_base;
152+
153+ #[ cfg( all( target_env = "sgx" , target_vendor = "fortanix" , feature = "std" ) ) ]
154+ #[ deny( unused) ]
155+ pub ( crate ) fn get_image_base ( ) -> u64 {
156+ std:: os:: fortanix_sgx:: mem:: image_base ( )
157+ }
158+
128159cfg_if:: cfg_if! {
129160 // This needs to come first, to ensure that
130161 // Miri takes priority over the host platform
0 commit comments