#![doc(html_root_url = "https://docs.rs/ruspiro-allocator/0.5.0")]
#![cfg_attr(not(any(test, doctest)), no_std)]
#![feature(alloc_error_handler)]
#[cfg_attr(not(any(test, doctest)), global_allocator)]
static ALLOCATOR: RusPiRoAllocator = RusPiRoAllocator;
use core::alloc::{GlobalAlloc, Layout};
mod memory;
struct RusPiRoAllocator;
unsafe impl GlobalAlloc for RusPiRoAllocator {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
memory::alloc(layout.size(), layout.align())
}
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
memory::free(ptr)
}
#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let ptr = memory::alloc(layout.size(), layout.align());
memset(ptr, 0x0, layout.size());
ptr
}
}
#[cfg(not(any(test, doctest)))]
#[alloc_error_handler]
#[allow(clippy::empty_loop)]
fn alloc_error_handler(_: Layout) -> ! {
loop {}
}
extern "C" {
fn memset(ptr: *mut u8, value: i32, size: usize) -> *mut u8;
}