From 13f2079b4850052bad79890d04e81cc6365b4479 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sat, 7 Nov 2020 12:41:48 +0100 Subject: [PATCH 1/2] Relaxe `Sized` requirement for `Mapper::map_to` This makes it possible to use the method with trait objects. Resolves https://github.com/rust-osdev/acpi/issues/78 --- .../paging/mapper/mapped_page_table.rs | 14 +++++++------- src/structures/paging/mapper/mod.rs | 6 +++--- .../paging/mapper/offset_page_table.rs | 6 +++--- .../paging/mapper/recursive_page_table.rs | 16 ++++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/structures/paging/mapper/mapped_page_table.rs b/src/structures/paging/mapper/mapped_page_table.rs index 55b884bbd..433cf0cf3 100644 --- a/src/structures/paging/mapper/mapped_page_table.rs +++ b/src/structures/paging/mapper/mapped_page_table.rs @@ -53,7 +53,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { let p4 = &mut self.level_4_table; let p3 = self.page_table_walker.create_next_table( @@ -81,7 +81,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { let p4 = &mut self.level_4_table; let p3 = self.page_table_walker.create_next_table( @@ -114,7 +114,7 @@ impl<'a, P: PhysToVirt> MappedPageTable<'a, P> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { let p4 = &mut self.level_4_table; let p3 = self.page_table_walker.create_next_table( @@ -153,7 +153,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.map_to_1gib(page, frame, flags, parent_table_flags, allocator) } @@ -261,7 +261,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.map_to_2mib(page, frame, flags, parent_table_flags, allocator) } @@ -389,7 +389,7 @@ impl<'a, P: PhysToVirt> Mapper for MappedPageTable<'a, P> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.map_to_4kib(page, frame, flags, parent_table_flags, allocator) } @@ -643,7 +643,7 @@ impl PageTableWalker

{ allocator: &mut A, ) -> Result<&'b mut PageTable, PageTableCreateError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { let created; diff --git a/src/structures/paging/mapper/mod.rs b/src/structures/paging/mapper/mod.rs index 5253d121d..11af57d3c 100644 --- a/src/structures/paging/mapper/mod.rs +++ b/src/structures/paging/mapper/mod.rs @@ -170,7 +170,7 @@ pub trait Mapper { ) -> Result, MapToError> where Self: Sized, - A: FrameAllocator, + A: FrameAllocator + ?Sized, { let parent_table_flags = flags & (PageTableFlags::PRESENT @@ -260,7 +260,7 @@ pub trait Mapper { ) -> Result, MapToError> where Self: Sized, - A: FrameAllocator; + A: FrameAllocator + ?Sized; /// Removes a mapping from the page table and returns the frame that used to be mapped. /// @@ -348,7 +348,7 @@ pub trait Mapper { ) -> Result, MapToError> where Self: Sized, - A: FrameAllocator, + A: FrameAllocator + ?Sized, S: PageSize, Self: Mapper, { diff --git a/src/structures/paging/mapper/offset_page_table.rs b/src/structures/paging/mapper/offset_page_table.rs index 3274fea19..022b7646d 100644 --- a/src/structures/paging/mapper/offset_page_table.rs +++ b/src/structures/paging/mapper/offset_page_table.rs @@ -70,7 +70,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.inner .map_to_with_table_flags(page, frame, flags, parent_table_flags, allocator) @@ -137,7 +137,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.inner .map_to_with_table_flags(page, frame, flags, parent_table_flags, allocator) @@ -204,7 +204,7 @@ impl<'a> Mapper for OffsetPageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.inner .map_to_with_table_flags(page, frame, flags, parent_table_flags, allocator) diff --git a/src/structures/paging/mapper/recursive_page_table.rs b/src/structures/paging/mapper/recursive_page_table.rs index 9c99afb62..267b87c2a 100644 --- a/src/structures/paging/mapper/recursive_page_table.rs +++ b/src/structures/paging/mapper/recursive_page_table.rs @@ -108,7 +108,7 @@ impl<'a> RecursivePageTable<'a> { allocator: &mut A, ) -> Result<&'b mut PageTable, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { /// This inner function is used to limit the scope of `unsafe`. /// @@ -120,7 +120,7 @@ impl<'a> RecursivePageTable<'a> { allocator: &mut A, ) -> Result<&'b mut PageTable, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { use crate::structures::paging::PageTableFlags as Flags; @@ -165,7 +165,7 @@ impl<'a> RecursivePageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { use crate::structures::paging::PageTableFlags as Flags; let p4 = &mut self.p4; @@ -199,7 +199,7 @@ impl<'a> RecursivePageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { use crate::structures::paging::PageTableFlags as Flags; let p4 = &mut self.p4; @@ -243,7 +243,7 @@ impl<'a> RecursivePageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { let p4 = &mut self.p4; @@ -297,7 +297,7 @@ impl<'a> Mapper for RecursivePageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.map_to_1gib(page, frame, flags, parent_table_flags, allocator) } @@ -419,7 +419,7 @@ impl<'a> Mapper for RecursivePageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.map_to_2mib(page, frame, flags, parent_table_flags, allocator) } @@ -576,7 +576,7 @@ impl<'a> Mapper for RecursivePageTable<'a> { allocator: &mut A, ) -> Result, MapToError> where - A: FrameAllocator, + A: FrameAllocator + ?Sized, { self.map_to_4kib(page, frame, flags, parent_table_flags, allocator) } From 9a8d1dcfb72a924a2b56a8558d4a19b4554d948f Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 28 Dec 2020 10:56:29 +0100 Subject: [PATCH 2/2] Update changelog for #204 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index e561fce0e..0e110d82f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ # Unreleased - **Breaking:** Also return flags for `MapperAllSizes::translate()` ([#207](https://github.com/rust-osdev/x86_64/pull/207)) +- Relaxe `Sized` requirement for `FrameAllocator` in `Mapper::map_to` ([204](https://github.com/rust-osdev/x86_64/pull/204)) # 0.12.3 – 2020-10-31