diff --git a/src/structures/paging/mapper/mapped_page_table.rs b/src/structures/paging/mapper/mapped_page_table.rs index d40968db3..341c8b5d1 100644 --- a/src/structures/paging/mapper/mapped_page_table.rs +++ b/src/structures/paging/mapper/mapped_page_table.rs @@ -42,7 +42,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -52,7 +52,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { .create_next_table(&mut p4[page.p4_index()], allocator)?; if !p3[page.p3_index()].is_unused() { - return Err(MapToError::PageAlreadyMapped); + return Err(MapToError::PageAlreadyMapped(frame)); } p3[page.p3_index()].set_addr(frame.start_address(), flags | PageTableFlags::HUGE_PAGE); @@ -67,7 +67,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -80,7 +80,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { .create_next_table(&mut p3[page.p3_index()], allocator)?; if !p2[page.p2_index()].is_unused() { - return Err(MapToError::PageAlreadyMapped); + return Err(MapToError::PageAlreadyMapped(frame)); } p2[page.p2_index()].set_addr(frame.start_address(), flags | PageTableFlags::HUGE_PAGE); @@ -95,7 +95,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -111,7 +111,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { .create_next_table(&mut p2[page.p2_index()], allocator)?; if !p1[page.p1_index()].is_unused() { - return Err(MapToError::PageAlreadyMapped); + return Err(MapToError::PageAlreadyMapped(frame)); } p1[page.p1_index()].set_frame(frame.frame(), flags); @@ -126,7 +126,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -199,7 +199,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -280,7 +280,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -499,7 +499,25 @@ enum PageTableCreateError { FrameAllocationFailed, } -impl From for MapToError { +impl From for MapToError { + fn from(err: PageTableCreateError) -> Self { + match err { + PageTableCreateError::MappedToHugePage => MapToError::ParentEntryHugePage, + PageTableCreateError::FrameAllocationFailed => MapToError::FrameAllocationFailed, + } + } +} + +impl From for MapToError { + fn from(err: PageTableCreateError) -> Self { + match err { + PageTableCreateError::MappedToHugePage => MapToError::ParentEntryHugePage, + PageTableCreateError::FrameAllocationFailed => MapToError::FrameAllocationFailed, + } + } +} + +impl From for MapToError { fn from(err: PageTableCreateError) -> Self { match err { PageTableCreateError::MappedToHugePage => MapToError::ParentEntryHugePage, diff --git a/src/structures/paging/mapper/mod.rs b/src/structures/paging/mapper/mod.rs index 0fb1359f3..45fb6a395 100644 --- a/src/structures/paging/mapper/mod.rs +++ b/src/structures/paging/mapper/mod.rs @@ -88,7 +88,7 @@ pub trait Mapper { frame: UnusedPhysFrame, flags: PageTableFlags, frame_allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where Self: Sized, A: FrameAllocator; @@ -117,7 +117,7 @@ pub trait Mapper { frame: UnusedPhysFrame, flags: PageTableFlags, frame_allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where Self: Sized, A: FrameAllocator, @@ -156,7 +156,7 @@ impl MapperFlush { /// This error is returned from `map_to` and similar methods. #[derive(Debug)] -pub enum MapToError { +pub enum MapToError { /// An additional frame was needed for the mapping process, but the frame allocator /// returned `None`. FrameAllocationFailed, @@ -164,7 +164,7 @@ pub enum MapToError { /// given page is part of an already mapped huge page. ParentEntryHugePage, /// The given page is already mapped to a physical frame. - PageAlreadyMapped, + PageAlreadyMapped(UnusedPhysFrame), } /// An error indicating that an `unmap` call failed. diff --git a/src/structures/paging/mapper/offset_page_table.rs b/src/structures/paging/mapper/offset_page_table.rs index 397a98523..4d6a64cfc 100644 --- a/src/structures/paging/mapper/offset_page_table.rs +++ b/src/structures/paging/mapper/offset_page_table.rs @@ -55,7 +55,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -89,7 +89,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -123,7 +123,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { diff --git a/src/structures/paging/mapper/recursive_page_table.rs b/src/structures/paging/mapper/recursive_page_table.rs index 01e41bba1..9e3b0fc23 100644 --- a/src/structures/paging/mapper/recursive_page_table.rs +++ b/src/structures/paging/mapper/recursive_page_table.rs @@ -85,22 +85,22 @@ impl<'a> RecursivePageTable<'a> { /// Returns `MapToError::FrameAllocationFailed` if the entry is unused and the allocator /// returned `None`. Returns `MapToError::ParentEntryHugePage` if the `HUGE_PAGE` flag is set /// in the passed entry. - unsafe fn create_next_table<'b, A>( + unsafe fn create_next_table<'b, A, S: PageSize>( entry: &'b mut PageTableEntry, next_table_page: Page, allocator: &mut A, - ) -> Result<&'b mut PageTable, MapToError> + ) -> Result<&'b mut PageTable, MapToError> where A: FrameAllocator, { /// This inner function is used to limit the scope of `unsafe`. /// /// This is a safe function, so we need to use `unsafe` blocks when we do something unsafe. - fn inner<'b, A>( + fn inner<'b, A, S: PageSize>( entry: &'b mut PageTableEntry, next_table_page: Page, allocator: &mut A, - ) -> Result<&'b mut PageTable, MapToError> + ) -> Result<&'b mut PageTable, MapToError> where A: FrameAllocator, { @@ -141,7 +141,7 @@ impl<'a> RecursivePageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -152,7 +152,7 @@ impl<'a> RecursivePageTable<'a> { let p3 = unsafe { Self::create_next_table(&mut p4[page.p4_index()], p3_page, allocator)? }; if !p3[page.p3_index()].is_unused() { - return Err(MapToError::PageAlreadyMapped); + return Err(MapToError::PageAlreadyMapped(frame)); } p3[page.p3_index()].set_addr(frame.start_address(), flags | Flags::HUGE_PAGE); @@ -167,7 +167,7 @@ impl<'a> RecursivePageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -181,7 +181,7 @@ impl<'a> RecursivePageTable<'a> { let p2 = unsafe { Self::create_next_table(&mut p3[page.p3_index()], p2_page, allocator)? }; if !p2[page.p2_index()].is_unused() { - return Err(MapToError::PageAlreadyMapped); + return Err(MapToError::PageAlreadyMapped(frame)); } p2[page.p2_index()].set_addr(frame.start_address(), flags | Flags::HUGE_PAGE); @@ -196,7 +196,7 @@ impl<'a> RecursivePageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -212,7 +212,7 @@ impl<'a> RecursivePageTable<'a> { let p1 = unsafe { Self::create_next_table(&mut p2[page.p2_index()], p1_page, allocator)? }; if !p1[page.p1_index()].is_unused() { - return Err(MapToError::PageAlreadyMapped); + return Err(MapToError::PageAlreadyMapped(frame)); } p1[page.p1_index()].set_frame(frame.frame(), flags); @@ -227,7 +227,7 @@ impl<'a> Mapper for RecursivePageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -312,7 +312,7 @@ impl<'a> Mapper for RecursivePageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, { @@ -417,7 +417,7 @@ impl<'a> Mapper for RecursivePageTable<'a> { frame: UnusedPhysFrame, flags: PageTableFlags, allocator: &mut A, - ) -> Result, MapToError> + ) -> Result, MapToError> where A: FrameAllocator, {