1 use crate::alloc::{GlobalAlloc, Layout, System};
3 use super::waitqueue::SpinMutex;
5 // Using a SpinMutex because we never want to exit the enclave waiting for the
7 #[cfg_attr(test, linkage = "available_externally")]
8 #[export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE"]
9 static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc> = SpinMutex::new(dlmalloc::DLMALLOC_INIT);
11 #[stable(feature = "alloc_system_type", since = "1.28.0")]
12 unsafe impl GlobalAlloc for System {
14 unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
15 DLMALLOC.lock().malloc(layout.size(), layout.align())
19 unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
20 DLMALLOC.lock().calloc(layout.size(), layout.align())
24 unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
25 DLMALLOC.lock().free(ptr, layout.size(), layout.align())
29 unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
30 DLMALLOC.lock().realloc(ptr, layout.size(), layout.align(), new_size)