2 use core
::sync
::atomic
::{AtomicBool, Ordering, ATOMIC_BOOL_INIT}
;
4 // Do not remove inline: will result in relocation failure
6 unsafe fn rel_ptr_mut
<T
>(offset
: u64) -> *mut T
{
7 (image_base() + offset
) as *mut T
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
14 fn image_base() -> u64 {
16 unsafe { llvm_asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) }
;
20 pub unsafe fn alloc(_size
: usize) -> (*mut u8, usize, u32) {
22 static HEAP_BASE
: u64;
23 static HEAP_SIZE
: usize;
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)
30 (ptr
::null_mut(), 0, 0)
34 pub unsafe fn remap(_ptr
: *mut u8, _oldsize
: usize, _newsize
: usize, _can_move
: bool
) -> *mut u8 {
38 pub unsafe fn free_part(_ptr
: *mut u8, _oldsize
: usize, _newsize
: usize) -> bool
{
42 pub unsafe fn free(_ptr
: *mut u8, _size
: usize) -> bool
{
46 pub fn can_release_part(_flags
: u32) -> bool
{
50 #[cfg(feature = "global")]
51 pub fn acquire_global_lock() {
52 compile_error
!("The `global` feature is not implemented for the SGX platform")
55 #[cfg(feature = "global")]
56 pub fn release_global_lock() {
57 compile_error
!("The `global` feature is not implemented for the SGX platform")
60 pub fn allocates_zeros() -> bool
{
64 pub fn page_size() -> usize {