diff --git a/src/allocator.rs b/src/allocator.rs index 02bfc0a..6a319dd 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,3 +1,4 @@ +pub mod bump; use x86_64::{ structures::paging::{ mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, @@ -5,14 +6,35 @@ use x86_64::{ VirtAddr, }; use alloc::alloc::{GlobalAlloc, Layout}; +use bump::BumpAllocator; use core::ptr::null_mut; -use linked_list_allocator::LockedHeap; 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(BumpAllocator::new()); +/// 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() + } +} + +fn align_up(addr: usize, align: usize) -> usize { + (addr + align - 1) & !(align - 1) +} + pub struct Dummy; unsafe impl GlobalAlloc for Dummy {