#[inline(always)]
pub unsafe fn rel_ptr<T>(offset: u64) -> *const T {
(image_base()+offset) as *const T
}
#[inline(always)]
pub unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
(image_base()+offset) as *mut T
}
extern {
static ENCLAVE_SIZE: usize;
}
#[inline(always)]
fn image_base() -> u64 {
let base;
unsafe{asm!("lea IMAGE_BASE(%rip),$0":"=r"(base))};
base
}
#[allow(dead_code)]
pub fn is_enclave_range<T>(p: *const T, len: usize) -> bool {
let start=p as u64;
let end=start+(len as u64);
start >= image_base() && end <= image_base()+(ENCLAVE_SIZE as u64)
}
pub fn is_user_range<T>(p: *const T, len: usize) -> bool {
let start=p as u64;
let end=start+(len as u64);
end <= image_base() || start >= image_base()+(ENCLAVE_SIZE as u64)
}