From bd87767255c784156deb19ea166826ab78a023fb Mon Sep 17 00:00:00 2001 From: Natasha Moongrave Date: Wed, 1 Apr 2026 20:04:09 +0200 Subject: Added all new implemented allocators to allocator.rs --- StrixKernel/src/allocator.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/StrixKernel/src/allocator.rs b/StrixKernel/src/allocator.rs index 7792666..4bae6bd 100644 --- a/StrixKernel/src/allocator.rs +++ b/StrixKernel/src/allocator.rs @@ -1,6 +1,6 @@ use alloc::alloc::{GlobalAlloc, Layout}; use core::ptr::null_mut; -use linked_list_allocator::LockedHeap; +use fixed_size_block::FixedSizeBlockAllocator; use x86_64::{ VirtAddr, structures::paging::{ @@ -8,11 +8,15 @@ use x86_64::{ }, }; +pub mod bump; +pub mod fixed_size_block; +pub mod linked_list; + pub const HEAP_START: usize = 0x_4444_4444_0000; pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB #[global_allocator] -static ALLOCATOR: LockedHeap = LockedHeap::empty(); +static ALLOCATOR: Locked = Locked::new(FixedSizeBlockAllocator::new()); pub fn init_heap( mapper: &mut impl Mapper, @@ -51,4 +55,28 @@ unsafe impl GlobalAlloc for Dummy { unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { panic!("dealloc should be never called") } +} + +/// A wrapper around spin::Mutex to permit trait implementations. +pub struct Locked { + inner: spin::Mutex, +} + +impl Locked { + pub const fn new(inner: A) -> Self { + Locked { + inner: spin::Mutex::new(inner), + } + } + + pub fn lock(&self) -> spin::MutexGuard { + self.inner.lock() + } +} + +/// Align the given address `addr` upwards to alignment `align`. +/// +/// Requires that `align` is a power of two. +fn align_up(addr: usize, align: usize) -> usize { + (addr + align - 1) & !(align - 1) } \ No newline at end of file -- cgit v1.2.3