Skip to content

Commit

Permalink
updated allocator.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Blindspot22 committed Aug 7, 2024
1 parent 5f45ce4 commit f7273cf
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
pub mod bump;
use x86_64::{
structures::paging::{
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
},
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<BumpAllocator> = Locked::new(BumpAllocator::new());
/// A wrapper around spin::Mutex to permit trait implementations.
pub struct Locked<A> {
inner: spin::Mutex<A>,
}

impl<A> Locked<A> {
pub const fn new(inner: A) -> Self {
Locked {
inner: spin::Mutex::new(inner),
}
}

pub fn lock(&self) -> spin::MutexGuard<A> {
self.inner.lock()
}
}

fn align_up(addr: usize, align: usize) -> usize {
(addr + align - 1) & !(align - 1)
}

pub struct Dummy;

unsafe impl GlobalAlloc for Dummy {
Expand Down

0 comments on commit f7273cf

Please sign in to comment.