Skip to content

Commit

Permalink
fix(x86_64/mm): remove FrameAlloc ZST
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed May 8, 2024
1 parent 6c89db4 commit 3dd321d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ features = [
]

[target.'cfg(target_arch = "x86_64")'.dependencies]
free-list = { version = "0.3", features = ["x86_64"] }
multiboot = "0.8"
uart_16550 = "0.3"
x86 = { version = "0.52", default-features = false }
Expand Down
7 changes: 5 additions & 2 deletions src/arch/x86_64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub fn map<S>(
#[cfg(feature = "smp")]
let mut ipi_tlb_flush = false;

let mut frame_allocator = physicalmem::PHYSICAL_FREE_LIST.lock();
for (page, frame) in pages.zip(frames) {
unsafe {
// TODO: Require explicit unmaps
Expand All @@ -170,11 +171,12 @@ pub fn map<S>(
debug!("Had to unmap page {page:?} before mapping.");
}
recursive_page_table()
.map_to(page, frame, flags, &mut physicalmem::FrameAlloc)
.map_to(page, frame, flags, &mut *frame_allocator)
.unwrap()
.flush();
}
}
drop(frame_allocator);

#[cfg(feature = "smp")]
if ipi_tlb_flush {
Expand Down Expand Up @@ -218,12 +220,13 @@ where
frame.start_address()
);

let mut frame_allocator = physicalmem::PHYSICAL_FREE_LIST.lock();
unsafe {
recursive_page_table()
.identity_map(
frame,
PageTableEntryFlags::PRESENT | PageTableEntryFlags::NO_EXECUTE,
&mut physicalmem::FrameAlloc,
&mut *frame_allocator,
)
.unwrap()
.flush();
Expand Down
13 changes: 1 addition & 12 deletions src/arch/x86_64/mm/physicalmem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::sync::atomic::{AtomicUsize, Ordering};

use ::x86_64::structures::paging::{FrameAllocator, PhysFrame};
use free_list::{AllocError, FreeList, PageLayout, PageRange};
use hermit_sync::InterruptTicketMutex;
use multiboot::information::{MemoryType, Multiboot};
Expand All @@ -10,7 +9,7 @@ use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize};
use crate::arch::x86_64::mm::{MultibootMemory, PhysAddr, VirtAddr};
use crate::mm;

static PHYSICAL_FREE_LIST: InterruptTicketMutex<FreeList<16>> =
pub static PHYSICAL_FREE_LIST: InterruptTicketMutex<FreeList<16>> =
InterruptTicketMutex::new(FreeList::new());
static TOTAL_MEMORY: AtomicUsize = AtomicUsize::new(0);

Expand Down Expand Up @@ -173,16 +172,6 @@ pub fn allocate(size: usize) -> Result<PhysAddr, AllocError> {
))
}

pub struct FrameAlloc;

unsafe impl<S: x86_64::structures::paging::PageSize> FrameAllocator<S> for FrameAlloc {
fn allocate_frame(&mut self) -> Option<PhysFrame<S>> {
let layout = PageLayout::from_size_align(S::SIZE as usize, S::SIZE as usize).unwrap();
let addr = PHYSICAL_FREE_LIST.lock().allocate(layout).ok()?.start() as u64;
Some(PhysFrame::from_start_address(x86_64::PhysAddr::new(addr)).unwrap())
}
}

pub fn allocate_aligned(size: usize, align: usize) -> Result<PhysAddr, AllocError> {
assert!(size > 0);
assert!(align > 0);
Expand Down

0 comments on commit 3dd321d

Please sign in to comment.