diff --git a/rmm/src/main.rs b/rmm/src/main.rs index 00fee6a997..10ec7a8bc0 100644 --- a/rmm/src/main.rs +++ b/rmm/src/main.rs @@ -235,8 +235,12 @@ unsafe fn new_tables(areas: &'static [MemoryArea]) { let mut flush_all = PageFlushAll::new(); for i in 0..16 { let virt = VirtualAddress::new(MEGABYTE + i * A::PAGE_SIZE); + let phys = mapper + .allocator_mut() + .allocate_one() + .expect("failed to map page"); let flush = mapper - .map(virt, PageFlags::::new().user(true).write(true)) + .map_phys(virt, phys, PageFlags::::new().user(true).write(true)) .expect("failed to map page"); flush_all.consume(flush); } @@ -245,7 +249,8 @@ unsafe fn new_tables(areas: &'static [MemoryArea]) { let mut flush_all = PageFlushAll::new(); for i in 0..16 { let virt = VirtualAddress::new(MEGABYTE + i * A::PAGE_SIZE); - let flush = mapper.unmap(virt).expect("failed to unmap page"); + let (old, _, flush) = mapper.unmap_phys(virt).expect("failed to unmap page"); + mapper.allocator_mut().free_one(old); flush_all.consume(flush); } flush_all.flush(); diff --git a/rmm/src/page/mapper.rs b/rmm/src/page/mapper.rs index 7af3bfd6ca..102ea3c0a8 100644 --- a/rmm/src/page/mapper.rs +++ b/rmm/src/page/mapper.rs @@ -157,17 +157,6 @@ impl PageMapper { } } - pub unsafe fn map( - &mut self, - virt: VirtualAddress, - flags: PageFlags, - ) -> Option> { - unsafe { - let phys = self.allocator.allocate_one()?; - self.map_phys(virt, phys, flags) - } - } - pub unsafe fn map_phys( &mut self, virt: VirtualAddress, @@ -218,17 +207,6 @@ impl PageMapper { } } - pub unsafe fn unmap(&mut self, virt: VirtualAddress) -> Option> - where - F: FrameAllocator, - { - unsafe { - let (old, _, flush) = self.unmap_phys(virt)?; - self.allocator.free_one(old); - Some(flush) - } - } - pub unsafe fn unmap_phys( &mut self, virt: VirtualAddress, diff --git a/src/allocator/mod.rs b/src/allocator/mod.rs index f3fd0b2fd4..53b1f5f9d6 100644 --- a/src/allocator/mod.rs +++ b/src/allocator/mod.rs @@ -2,31 +2,36 @@ use crate::{ memory::KernelMapper, paging::{mapper::PageFlushAll, Page, PageFlags, VirtualAddress}, }; -use rmm::Flusher; +use rmm::{Flusher, FrameAllocator}; pub use self::linked_list::Allocator; mod linked_list; unsafe fn map_heap(mapper: &mut KernelMapper, offset: usize, size: usize) { - unsafe { - let mut flush_all = PageFlushAll::new(); + let mut flush_all = PageFlushAll::new(); - let heap_start_page = Page::containing_address(VirtualAddress::new(offset)); - let heap_end_page = Page::containing_address(VirtualAddress::new(offset + size - 1)); - for page in Page::range_inclusive(heap_start_page, heap_end_page) { - let result = mapper - .map( + let heap_start_page = Page::containing_address(VirtualAddress::new(offset)); + let heap_end_page = Page::containing_address(VirtualAddress::new(offset + size - 1)); + for page in Page::range_inclusive(heap_start_page, heap_end_page) { + unsafe { + let phys = mapper + .allocator_mut() + .allocate_one() + .expect("failed to allocate kernel heap"); + let flush = mapper + .map_phys( page.start_address(), + phys, PageFlags::new() .write(true) .global(cfg!(not(feature = "pti"))), ) .expect("failed to map kernel heap"); - flush_all.consume(result); + flush_all.consume(flush); } - - flush_all.flush(); } + + flush_all.flush(); } pub unsafe fn init() {