|
| 1 | +use core::ptr; |
| 2 | +use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering}; |
| 3 | + |
| 4 | +// Do not remove inline: will result in relocation failure |
| 5 | +#[inline(always)] |
| 6 | +unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T { |
| 7 | + (image_base()+offset) as *mut T |
| 8 | +} |
| 9 | + |
| 10 | +// Do not remove inline: will result in relocation failure |
| 11 | +// For the same reason we use inline ASM here instead of an extern static to |
| 12 | +// locate the base |
| 13 | +#[inline(always)] |
| 14 | +fn image_base() -> u64 { |
| 15 | + let base; |
| 16 | + unsafe{asm!("lea IMAGE_BASE(%rip),$0":"=r"(base))}; |
| 17 | + base |
| 18 | +} |
| 19 | + |
| 20 | +pub unsafe fn alloc(_size: usize) -> (*mut u8, usize, u32) { |
| 21 | + extern { |
| 22 | + static HEAP_BASE: u64; |
| 23 | + static HEAP_SIZE: usize; |
| 24 | + } |
| 25 | + static INIT: AtomicBool = ATOMIC_BOOL_INIT; |
| 26 | + // No ordering requirement since this function is protected by the global lock. |
| 27 | + if !INIT.swap(true, Ordering::Relaxed) { |
| 28 | + (rel_ptr_mut(HEAP_BASE), HEAP_SIZE, 0) |
| 29 | + } else { |
| 30 | + (ptr::null_mut(), 0, 0) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +pub unsafe fn remap(_ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) |
| 35 | + -> *mut u8 |
| 36 | +{ |
| 37 | + ptr::null_mut() |
| 38 | +} |
| 39 | + |
| 40 | +pub unsafe fn free_part(_ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool { |
| 41 | + false |
| 42 | +} |
| 43 | + |
| 44 | +pub unsafe fn free(_ptr: *mut u8, _size: usize) -> bool { |
| 45 | + false |
| 46 | +} |
| 47 | + |
| 48 | +pub fn can_release_part(_flags: u32) -> bool { |
| 49 | + false |
| 50 | +} |
| 51 | + |
| 52 | +#[cfg(feature = "global")] |
| 53 | +pub fn acquire_global_lock() { |
| 54 | + compile_error!("The `global` feature is not implemented for the SGX platform") |
| 55 | +} |
| 56 | + |
| 57 | +#[cfg(feature = "global")] |
| 58 | +pub fn release_global_lock() { |
| 59 | + compile_error!("The `global` feature is not implemented for the SGX platform") |
| 60 | +} |
| 61 | + |
| 62 | +pub fn allocates_zeros() -> bool { |
| 63 | + false |
| 64 | +} |
| 65 | + |
| 66 | +pub fn page_size() -> usize { |
| 67 | + 0x1000 |
| 68 | +} |
0 commit comments