increasing_heap_allocator/
lib.rs

1#![no_std]
2
3pub use allocator::HeapAllocator;
4
5mod allocator;
6
7// helper functions
8const fn align_up(addr: usize, alignment: usize) -> usize {
9    (addr + alignment - 1) & !(alignment - 1)
10}
11
12const fn is_aligned(addr: usize, alignment: usize) -> bool {
13    (addr & (alignment - 1)) == 0
14}
15
16#[derive(Debug, Clone, Copy)]
17pub struct HeapStats {
18    pub allocated: usize,
19    pub free_size: usize,
20    pub heap_size: usize,
21}
22
23pub trait PageAllocatorProvider<const PAGE_SIZE: usize> {
24    /// Return the start address of the new allocated heap
25    fn allocate_pages(&mut self, pages: usize) -> Option<*mut u8>;
26    /// Deallocate pages from the end of the heap
27    /// Return true if the deallocation was successful
28    fn deallocate_pages(&mut self, pages: usize) -> bool;
29}