#[cfg(any(target_arch = "mips64", target_arch = "riscv64"))]
pub mod global_allocator {
use linked_list_allocator::LockedHeap;
#[global_allocator]
static ALLOCATOR: LockedHeap = LockedHeap::empty();
pub unsafe fn init_allocator(heap_start_addr: *mut u8, heap_size: usize) {
unsafe { ALLOCATOR.lock().init(heap_start_addr, heap_size) }
}
}
#[cfg_attr(
any(target_arch = "mips64", target_arch = "riscv64"),
doc = "See [global_allocator::init_allocator] safety comment."
)]
#[cfg_attr(
not(any(target_arch = "mips64", target_arch = "riscv64")),
doc = "This macro is entirely safe to invoke in non-MIPS and non-RISC-V64 profiles, and functions as a no-op."
)]
#[macro_export]
macro_rules! alloc_heap {
($size:expr) => {{
#[cfg(any(target_arch = "mips64", target_arch = "riscv64"))]
{
use $crate::malloc::global_allocator::init_allocator;
static mut HEAP: [u8; $size] = [0u8; $size];
unsafe { init_allocator(HEAP.as_mut_ptr(), $size) }
}
}};
}