curiOS/crates/foundation/src/alloc/mod.rs
2026-08-05 19:00:32 +02:00

24 lines
595 B
Rust

use core::ptr::NonNull;
use liballoc::alloc::Allocator;
pub mod bump;
pub mod slab;
#[derive(Debug, Default)]
pub struct PanicingAllocator;
unsafe impl Allocator for PanicingAllocator {
fn allocate(
&self,
layout: core::alloc::Layout,
) -> Result<NonNull<[u8]>, core::alloc::AllocError> {
match layout.size() {
0 => Ok(NonNull::slice_from_raw_parts(NonNull::dangling(), 0)),
_ => panic!("PanicingAllocator cannot allocate memory"),
}
}
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: core::alloc::Layout) {}
}