1
1
use fixedvec:: FixedVec ;
2
2
use frame_allocator:: FrameAllocator ;
3
3
use os_bootinfo:: MemoryRegionType ;
4
- use x86_64:: structures:: paging:: { MapToError , RecursivePageTable , UnmapError } ;
5
- use x86_64:: structures:: paging:: { Mapper , MapperFlush , Page , PageSize , PageTableFlags , PhysFrame , Size4KB } ;
4
+ use x86_64:: structures:: paging:: { self , MapToError , RecursivePageTable , UnmapError } ;
5
+ use x86_64:: structures:: paging:: { Mapper , MapperFlush , Page , PageSize , PageTableFlags , PhysFrame , Size4KiB } ;
6
6
use x86_64:: { align_up, PhysAddr , VirtAddr } ;
7
7
use xmas_elf:: program:: { self , ProgramHeader64 } ;
8
8
@@ -91,7 +91,7 @@ pub(crate) fn map_segment(
91
91
frame_allocator,
92
92
) ?. flush ( ) ;
93
93
94
- type PageArray = [ u64 ; Size4KB :: SIZE as usize / 8 ] ;
94
+ type PageArray = [ u64 ; Size4KiB :: SIZE as usize / 8 ] ;
95
95
96
96
let last_page = Page :: containing_address ( virt_start_addr + file_size - 1u64 ) ;
97
97
let last_page_ptr = last_page. start_address ( ) . as_ptr :: < PageArray > ( ) ;
@@ -103,13 +103,13 @@ pub(crate) fn map_segment(
103
103
}
104
104
105
105
// remap last page
106
- if let Err ( e) = page_table. unmap ( last_page. clone ( ) , & mut |_| { } ) {
106
+ if let Err ( e) = page_table. unmap ( last_page. clone ( ) ) {
107
107
return Err ( match e {
108
- UnmapError :: EntryWithInvalidFlagsPresent ( _ ) => {
109
- MapToError :: EntryWithInvalidFlagsPresent
108
+ UnmapError :: ParentEntryHugePage => {
109
+ MapToError :: ParentEntryHugePage
110
110
}
111
111
UnmapError :: PageNotMapped => unreachable ! ( ) ,
112
- UnmapError :: InvalidFrameAddressInPageTable => unreachable ! ( ) ,
112
+ UnmapError :: InvalidFrameAddress ( _ ) => unreachable ! ( ) ,
113
113
} ) ;
114
114
}
115
115
@@ -125,7 +125,7 @@ pub(crate) fn map_segment(
125
125
// Map additional frames.
126
126
let start_page: Page = Page :: containing_address ( VirtAddr :: new ( align_up (
127
127
zero_start. as_u64 ( ) ,
128
- Size4KB :: SIZE ,
128
+ Size4KiB :: SIZE ,
129
129
) ) ) ;
130
130
let end_page = Page :: containing_address ( zero_end) ;
131
131
for page in Page :: range_inclusive ( start_page, end_page) {
@@ -158,7 +158,13 @@ where
158
158
S : PageSize ,
159
159
RecursivePageTable < ' a > : Mapper < S > ,
160
160
{
161
- page_table. map_to ( page, phys_frame, flags, & mut || {
162
- frame_allocator. allocate_frame ( MemoryRegionType :: PageTable )
163
- } )
161
+ struct PageTableAllocator < ' a , ' b : ' a > ( & ' a mut FrameAllocator < ' b > ) ;
162
+
163
+ impl < ' a , ' b > paging:: FrameAllocator < Size4KiB > for PageTableAllocator < ' a , ' b > {
164
+ fn alloc ( & mut self ) -> Option < PhysFrame < Size4KiB > > {
165
+ self . 0 . allocate_frame ( MemoryRegionType :: PageTable )
166
+ }
167
+ }
168
+
169
+ page_table. map_to ( page, phys_frame, flags, & mut PageTableAllocator ( frame_allocator) )
164
170
}
0 commit comments