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(crate) 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(crate) 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 /// Returns `true` if the specified memory range is in the enclave.
38 #[unstable(feature = "sgx_platform", issue = "56975")]
39 pub fn is_enclave_range(p: *const u8, len: usize) -> bool {
41 let end=start + (len as u64);
42 start >= image_base() &&
43 end <= image_base() + (unsafe { ENCLAVE_SIZE } as u64) // unsafe ok: link-time constant
46 /// Returns `true` if the specified memory range is in userspace.
47 #[unstable(feature = "sgx_platform", issue = "56975")]
48 pub fn is_user_range(p: *const u8, len: usize) -> bool {
50 let end=start + (len as u64);
51 end <= image_base() ||
52 start >= image_base() + (unsafe { ENCLAVE_SIZE } as u64) // unsafe ok: link-time constant