Skip to content

Commit 3e2ee76

Browse files
mem: map_to dont take the frame allocator as an argument anymore :^)
your welcome @czapek1337 Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 2f64856 commit 3e2ee76

File tree

5 files changed

+47
-105
lines changed

5 files changed

+47
-105
lines changed

src/aero_kernel/src/drivers/block/ahci.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ impl HbaPort {
582582
| PageTableFlags::WRITABLE
583583
| PageTableFlags::WRITE_THROUGH
584584
| PageTableFlags::NO_CACHE,
585-
&mut FRAME_ALLOCATOR,
586585
)?
587586
.flush();
588587
}
@@ -923,7 +922,6 @@ impl AhciProtected {
923922
| PageTableFlags::NO_CACHE
924923
| PageTableFlags::WRITABLE
925924
| PageTableFlags::WRITE_THROUGH,
926-
&mut FRAME_ALLOCATOR,
927925
)
928926
}?
929927
.flush();

src/aero_kernel/src/mem/alloc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ impl Allocator {
204204
page,
205205
frame,
206206
PageTableFlags::PRESENT | PageTableFlags::WRITABLE,
207-
&mut FRAME_ALLOCATOR,
208207
)
209208
}
210209
.expect("Failed to map frame to extend the heap")
@@ -410,7 +409,6 @@ pub fn init_heap() {
410409
Page::containing_address(VirtAddr::new(HEAP_START as _)),
411410
frame,
412411
PageTableFlags::PRESENT | PageTableFlags::WRITABLE,
413-
&mut FRAME_ALLOCATOR,
414412
)
415413
.expect("init_heap: failed to initialize the heap")
416414
.flush();

src/aero_kernel/src/mem/paging/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ mod tests {
594594
.is_free(frame.start_address(), 0));
595595
}
596596

597-
unsafe { offset_table.map_to(page, frame, PageTableFlags::PRESENT, &mut FRAME_ALLOCATOR) }
597+
unsafe { offset_table.map_to(page, frame, PageTableFlags::PRESENT) }
598598
.unwrap()
599599
.flush();
600600

src/aero_kernel/src/mem/paging/mapper.rs

Lines changed: 46 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -173,30 +173,25 @@ pub trait Mapper<S: PageSize> {
173173
/// because of TLB races. It's worth noting that all the above requirements
174174
/// also apply to shared mappings, including the aliasing requirements.
175175
#[inline]
176-
unsafe fn map_to<A>(
176+
unsafe fn map_to(
177177
&mut self,
178178
page: Page<S>,
179179
frame: PhysFrame<S>,
180180
flags: PageTableFlags,
181-
frame_allocator: &mut A,
182181
) -> Result<MapperFlush<S>, MapToError<S>>
183182
where
184183
Self: Sized,
185-
A: FrameAllocator<Size4KiB> + ?Sized,
186184
{
187185
let parent_table_flags = flags
188186
& (PageTableFlags::PRESENT
189187
| PageTableFlags::WRITABLE
190188
| PageTableFlags::USER_ACCESSIBLE);
191189

192-
self.map_to_with_table_flags(page, frame, flags, parent_table_flags, frame_allocator)
190+
self.map_to_with_table_flags(page, frame, flags, parent_table_flags)
193191
}
194192

195193
/// Creates a new mapping in the page table.
196194
///
197-
/// This function might need additional physical frames to create new page tables. These
198-
/// frames are allocated from the `allocator` argument. At most three frames are required.
199-
///
200195
/// The flags of the parent table(s) can be explicitly specified. Those flags are used for
201196
/// newly created table entries, and for existing entries the flags are added.
202197
///
@@ -231,17 +226,15 @@ pub trait Mapper<S: PageSize> {
231226
/// the same in all address spaces, otherwise undefined behavior can occur
232227
/// because of TLB races. It's worth noting that all the above requirements
233228
/// also apply to shared mappings, including the aliasing requirements.
234-
unsafe fn map_to_with_table_flags<A>(
229+
unsafe fn map_to_with_table_flags(
235230
&mut self,
236231
page: Page<S>,
237232
frame: PhysFrame<S>,
238233
flags: PageTableFlags,
239234
parent_table_flags: PageTableFlags,
240-
frame_allocator: &mut A,
241235
) -> Result<MapperFlush<S>, MapToError<S>>
242236
where
243-
Self: Sized,
244-
A: FrameAllocator<Size4KiB> + ?Sized;
237+
Self: Sized;
245238

246239
/// Removes a mapping from the page table and returns the frame that used to be mapped.
247240
///
@@ -276,20 +269,18 @@ pub trait Mapper<S: PageSize> {
276269
/// This is a convencience function that invokes [`Mapper::map_to`] internally, so
277270
/// all safety requirements of it also apply for this function.
278271
#[inline]
279-
unsafe fn identity_map<A>(
272+
unsafe fn identity_map(
280273
&mut self,
281274
frame: PhysFrame<S>,
282275
flags: PageTableFlags,
283-
frame_allocator: &mut A,
284276
) -> Result<MapperFlush<S>, MapToError<S>>
285277
where
286278
Self: Sized,
287-
A: FrameAllocator<Size4KiB> + ?Sized,
288279
S: PageSize,
289280
Self: Mapper<S>,
290281
{
291282
let page = Page::containing_address(VirtAddr::new(frame.start_address().as_u64()));
292-
self.map_to(page, frame, flags, frame_allocator)
283+
self.map_to(page, frame, flags)
293284
}
294285
}
295286

@@ -412,46 +403,36 @@ impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> {
412403
}
413404
}
414405

415-
fn map_to_2mib<A>(
406+
fn map_to_2mib(
416407
&mut self,
417408
page: Page<Size2MiB>,
418409
frame: PhysFrame<Size2MiB>,
419410
flags: PageTableFlags,
420411
parent_table_flags: PageTableFlags,
421-
allocator: &mut A,
422-
) -> Result<MapperFlush<Size2MiB>, MapToError<Size2MiB>>
423-
where
424-
A: FrameAllocator<Size4KiB> + ?Sized,
425-
{
412+
) -> Result<MapperFlush<Size2MiB>, MapToError<Size2MiB>> {
426413
let mut is_alloc_4 = false;
427414

428415
let p4;
429416

430417
if self.level_5_paging_enabled {
431418
let p5 = &mut self.page_table;
432-
let (alloc, yes) = self.page_table_walker.create_next_table(
433-
&mut p5[page.p5_index()],
434-
parent_table_flags,
435-
allocator,
436-
)?;
419+
let (alloc, yes) = self
420+
.page_table_walker
421+
.create_next_table(&mut p5[page.p5_index()], parent_table_flags)?;
437422

438423
p4 = yes;
439424
is_alloc_4 = alloc;
440425
} else {
441426
p4 = &mut self.page_table;
442427
}
443428

444-
let (is_alloc_3, p3) = self.page_table_walker.create_next_table(
445-
&mut p4[page.p4_index()],
446-
parent_table_flags,
447-
allocator,
448-
)?;
429+
let (is_alloc_3, p3) = self
430+
.page_table_walker
431+
.create_next_table(&mut p4[page.p4_index()], parent_table_flags)?;
449432

450-
let (is_alloc_2, p2) = self.page_table_walker.create_next_table(
451-
&mut p3[page.p3_index()],
452-
parent_table_flags,
453-
allocator,
454-
)?;
433+
let (is_alloc_2, p2) = self
434+
.page_table_walker
435+
.create_next_table(&mut p3[page.p3_index()], parent_table_flags)?;
455436

456437
if !p2[page.p2_index()].is_unused() {
457438
return Err(MapToError::PageAlreadyMapped(frame));
@@ -475,52 +456,40 @@ impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> {
475456
Ok(MapperFlush::new(page))
476457
}
477458

478-
fn map_to_4kib<A>(
459+
fn map_to_4kib(
479460
&mut self,
480461
page: Page<Size4KiB>,
481462
frame: PhysFrame<Size4KiB>,
482463
flags: PageTableFlags,
483464
parent_table_flags: PageTableFlags,
484-
allocator: &mut A,
485-
) -> Result<MapperFlush<Size4KiB>, MapToError<Size4KiB>>
486-
where
487-
A: FrameAllocator<Size4KiB> + ?Sized,
488-
{
465+
) -> Result<MapperFlush<Size4KiB>, MapToError<Size4KiB>> {
489466
let p4;
490467

491468
let mut is_alloc_4 = false;
492469

493470
if self.level_5_paging_enabled {
494471
let p5 = &mut self.page_table;
495-
let (alloc, yes) = self.page_table_walker.create_next_table(
496-
&mut p5[page.p5_index()],
497-
parent_table_flags,
498-
allocator,
499-
)?;
472+
let (alloc, yes) = self
473+
.page_table_walker
474+
.create_next_table(&mut p5[page.p5_index()], parent_table_flags)?;
500475

501476
p4 = yes;
502477
is_alloc_4 = alloc;
503478
} else {
504479
p4 = &mut self.page_table;
505480
}
506481

507-
let (is_alloc_3, p3) = self.page_table_walker.create_next_table(
508-
&mut p4[page.p4_index()],
509-
parent_table_flags,
510-
allocator,
511-
)?;
482+
let (is_alloc_3, p3) = self
483+
.page_table_walker
484+
.create_next_table(&mut p4[page.p4_index()], parent_table_flags)?;
512485

513-
let (is_alloc_2, p2) = self.page_table_walker.create_next_table(
514-
&mut p3[page.p3_index()],
515-
parent_table_flags,
516-
allocator,
517-
)?;
486+
let (is_alloc_2, p2) = self
487+
.page_table_walker
488+
.create_next_table(&mut p3[page.p3_index()], parent_table_flags)?;
518489

519-
let (is_alloc_1, p1) = self.page_table_walker.create_next_table(
520-
&mut p2[page.p2_index()],
521-
parent_table_flags,
522-
allocator,
523-
)?;
490+
let (is_alloc_1, p1) = self
491+
.page_table_walker
492+
.create_next_table(&mut p2[page.p2_index()], parent_table_flags)?;
524493

525494
if !p1[page.p1_index()].is_unused() {
526495
return Err(MapToError::PageAlreadyMapped(frame));
@@ -551,18 +520,14 @@ impl<'a, P: PageTableFrameMapping> MappedPageTable<'a, P> {
551520

552521
impl<'a, P: PageTableFrameMapping> Mapper<Size2MiB> for MappedPageTable<'a, P> {
553522
#[inline]
554-
unsafe fn map_to_with_table_flags<A>(
523+
unsafe fn map_to_with_table_flags(
555524
&mut self,
556525
page: Page<Size2MiB>,
557526
frame: PhysFrame<Size2MiB>,
558527
flags: PageTableFlags,
559528
parent_table_flags: PageTableFlags,
560-
allocator: &mut A,
561-
) -> Result<MapperFlush<Size2MiB>, MapToError<Size2MiB>>
562-
where
563-
A: FrameAllocator<Size4KiB> + ?Sized,
564-
{
565-
self.map_to_2mib(page, frame, flags, parent_table_flags, allocator)
529+
) -> Result<MapperFlush<Size2MiB>, MapToError<Size2MiB>> {
530+
self.map_to_2mib(page, frame, flags, parent_table_flags)
566531
}
567532

568533
fn unmap(
@@ -675,18 +640,14 @@ impl<'a, P: PageTableFrameMapping> Mapper<Size2MiB> for MappedPageTable<'a, P> {
675640

676641
impl<'a, P: PageTableFrameMapping> Mapper<Size4KiB> for MappedPageTable<'a, P> {
677642
#[inline]
678-
unsafe fn map_to_with_table_flags<A>(
643+
unsafe fn map_to_with_table_flags(
679644
&mut self,
680645
page: Page<Size4KiB>,
681646
frame: PhysFrame<Size4KiB>,
682647
flags: PageTableFlags,
683648
parent_table_flags: PageTableFlags,
684-
allocator: &mut A,
685-
) -> Result<MapperFlush<Size4KiB>, MapToError<Size4KiB>>
686-
where
687-
A: FrameAllocator<Size4KiB> + ?Sized,
688-
{
689-
self.map_to_4kib(page, frame, flags, parent_table_flags, allocator)
649+
) -> Result<MapperFlush<Size4KiB>, MapToError<Size4KiB>> {
650+
self.map_to_4kib(page, frame, flags, parent_table_flags)
690651
}
691652

692653
fn unmap(
@@ -933,19 +894,15 @@ impl<P: PageTableFrameMapping> PageTableWalker<P> {
933894
/// Returns `MapToError::FrameAllocationFailed` if the entry is unused and the allocator
934895
/// returned `None`. Returns `MapToError::ParentEntryHugePage` if the `HUGE_PAGE` flag is set
935896
/// in the passed entry.
936-
fn create_next_table<'b, A>(
897+
fn create_next_table<'b>(
937898
&self,
938899
entry: &'b mut PageTableEntry,
939900
insert_flags: PageTableFlags,
940-
allocator: &mut A,
941-
) -> Result<(bool, &'b mut PageTable), PageTableCreateError>
942-
where
943-
A: FrameAllocator<Size4KiB> + ?Sized,
944-
{
901+
) -> Result<(bool, &'b mut PageTable), PageTableCreateError> {
945902
let created;
946903

947904
if entry.is_unused() {
948-
if let Some(frame) = allocator.allocate_frame() {
905+
if let Some(frame) = unsafe { FRAME_ALLOCATOR.allocate_frame() } {
949906
entry.set_frame(frame, insert_flags);
950907
created = true;
951908
} else {
@@ -1120,19 +1077,15 @@ unsafe impl PageTableFrameMapping for PhysOffset {
11201077

11211078
impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
11221079
#[inline]
1123-
unsafe fn map_to_with_table_flags<A>(
1080+
unsafe fn map_to_with_table_flags(
11241081
&mut self,
11251082
page: Page<Size2MiB>,
11261083
frame: PhysFrame<Size2MiB>,
11271084
flags: PageTableFlags,
11281085
parent_table_flags: PageTableFlags,
1129-
allocator: &mut A,
1130-
) -> Result<MapperFlush<Size2MiB>, MapToError<Size2MiB>>
1131-
where
1132-
A: FrameAllocator<Size4KiB> + ?Sized,
1133-
{
1086+
) -> Result<MapperFlush<Size2MiB>, MapToError<Size2MiB>> {
11341087
self.inner
1135-
.map_to_with_table_flags(page, frame, flags, parent_table_flags, allocator)
1088+
.map_to_with_table_flags(page, frame, flags, parent_table_flags)
11361089
}
11371090

11381091
#[inline]
@@ -1160,19 +1113,15 @@ impl<'a> Mapper<Size2MiB> for OffsetPageTable<'a> {
11601113

11611114
impl<'a> Mapper<Size4KiB> for OffsetPageTable<'a> {
11621115
#[inline]
1163-
unsafe fn map_to_with_table_flags<A>(
1116+
unsafe fn map_to_with_table_flags(
11641117
&mut self,
11651118
page: Page<Size4KiB>,
11661119
frame: PhysFrame<Size4KiB>,
11671120
flags: PageTableFlags,
11681121
parent_table_flags: PageTableFlags,
1169-
allocator: &mut A,
1170-
) -> Result<MapperFlush<Size4KiB>, MapToError<Size4KiB>>
1171-
where
1172-
A: FrameAllocator<Size4KiB> + ?Sized,
1173-
{
1122+
) -> Result<MapperFlush<Size4KiB>, MapToError<Size4KiB>> {
11741123
self.inner
1175-
.map_to_with_table_flags(page, frame, flags, parent_table_flags, allocator)
1124+
.map_to_with_table_flags(page, frame, flags, parent_table_flags)
11761125
}
11771126

11781127
#[inline]

src/aero_kernel/src/userland/vm.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ impl Mapping {
286286
PageTableFlags::USER_ACCESSIBLE
287287
| PageTableFlags::PRESENT
288288
| self.protection.into(),
289-
&mut FRAME_ALLOCATOR,
290289
)
291290
}
292291
.expect("Failed to identity map userspace private mapping")
@@ -350,7 +349,6 @@ impl Mapping {
350349
PageTableFlags::PRESENT
351350
| PageTableFlags::USER_ACCESSIBLE
352351
| self.protection.into(),
353-
&mut FRAME_ALLOCATOR,
354352
)
355353
}
356354
.expect("failed to map allocated frame for private file read")
@@ -406,7 +404,6 @@ impl Mapping {
406404
page,
407405
new_frame,
408406
PageTableFlags::PRESENT | PageTableFlags::USER_ACCESSIBLE | protection.into(),
409-
&mut FRAME_ALLOCATOR,
410407
)?
411408
.flush();
412409
}

0 commit comments

Comments
 (0)