1 // Do not remove inline: will result in relocation failure
3 pub(crate) unsafe fn rel_ptr<T>(offset: u64) -> *const T {
4 (image_base() + offset) as *const T
7 // Do not remove inline: will result in relocation failure
9 pub(crate) unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
10 (image_base() + offset) as *mut T
14 static ENCLAVE_SIZE: usize;
17 // Do not remove inline: will result in relocation failure
18 // For the same reason we use inline ASM here instead of an extern static to
20 /// Returns address at which current enclave is loaded.
22 #[unstable(feature = "sgx_platform", issue = "56975")]
23 pub fn image_base() -> u64 {
25 unsafe { asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) };
29 /// Returns `true` if the specified memory range is in the enclave.
30 #[unstable(feature = "sgx_platform", issue = "56975")]
31 pub fn is_enclave_range(p: *const u8, len: usize) -> bool {
33 let end=start + (len as u64);
34 start >= image_base() &&
35 end <= image_base() + (unsafe { ENCLAVE_SIZE } as u64) // unsafe ok: link-time constant
38 /// Returns `true` if the specified memory range is in userspace.
39 #[unstable(feature = "sgx_platform", issue = "56975")]
40 pub fn is_user_range(p: *const u8, len: usize) -> bool {
42 let end=start + (len as u64);
43 end <= image_base() ||
44 start >= image_base() + (unsafe { ENCLAVE_SIZE } as u64) // unsafe ok: link-time constant