1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Do not remove inline: will result in relocation failure
13 pub unsafe fn rel_ptr<T>(offset: u64) -> *const T {
14 (image_base() + offset) as *const T
17 // Do not remove inline: will result in relocation failure
19 pub unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
20 (image_base() + offset) as *mut T
24 static ENCLAVE_SIZE: usize;
27 // Do not remove inline: will result in relocation failure
28 // For the same reason we use inline ASM here instead of an extern static to
31 fn image_base() -> u64 {
33 unsafe { asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) };
37 pub fn is_user_range(p: *const u8, len: usize) -> bool {
39 let end=start + (len as u64);
40 end <= image_base() ||
41 start >= image_base() + (unsafe { ENCLAVE_SIZE } as u64) // unsafe ok: link-time constant