]> git.proxmox.com Git - rustc.git/blob - vendor/dlmalloc/src/sgx.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / vendor / dlmalloc / src / sgx.rs
1 use core::ptr;
2 use core::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
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 { llvm_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 "C" {
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) -> *mut u8 {
35 ptr::null_mut()
36 }
37
38 pub unsafe fn free_part(_ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
39 false
40 }
41
42 pub unsafe fn free(_ptr: *mut u8, _size: usize) -> bool {
43 false
44 }
45
46 pub fn can_release_part(_flags: u32) -> bool {
47 false
48 }
49
50 #[cfg(feature = "global")]
51 pub fn acquire_global_lock() {
52 compile_error!("The `global` feature is not implemented for the SGX platform")
53 }
54
55 #[cfg(feature = "global")]
56 pub fn release_global_lock() {
57 compile_error!("The `global` feature is not implemented for the SGX platform")
58 }
59
60 pub fn allocates_zeros() -> bool {
61 false
62 }
63
64 pub fn page_size() -> usize {
65 0x1000
66 }