MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / map_consecutive_pages

Function map_consecutive_pages

kernel/src/memory.rs:388–426  ·  view source on GitHub ↗

Map a consecutive set of pages to a consecutive set of frames level_4_physaddr The physical address of the L4 pagetable start_page First page in the sequence start_frame First frame in the sequence num_frames Number of consecutive frames

(
    level_4_physaddr: u64,
    start_page: Page,
    start_frame: PhysFrame,
    num_frames: u64)

Source from the content-addressed store, hash-verified

386/// start_frame First frame in the sequence
387/// num_frames Number of consecutive frames
388fn map_consecutive_pages(
389 level_4_physaddr: u64,
390 start_page: Page,
391 start_frame: PhysFrame,
392 num_frames: u64)
393 -> Result<PhysAddr, MapToError<Size4KiB>> {
394
395 let frame_range = PhysFrame::range(start_frame, start_frame + num_frames);
396 let page_range = Page::range(start_page, start_page + num_frames);
397
398 let memory_info = unsafe {MEMORY_INFO.as_mut().unwrap()};
399
400 let l4_table: &mut PageTable = unsafe {
401 &mut *(memory_info.physical_memory_offset
402 + level_4_physaddr).as_mut_ptr()};
403
404 let frame_allocator = &mut memory_info.frame_allocator;
405
406 let mut mapper = unsafe {
407 OffsetPageTable::new(l4_table,
408 memory_info.physical_memory_offset)};
409
410 for (page, frame) in page_range.zip(frame_range) {
411 unsafe {
412 mapper.map_to_with_table_flags(page,
413 frame,
414 // Writeable by user
415 PageTableFlags::PRESENT |
416 PageTableFlags::WRITABLE |
417 PageTableFlags::USER_ACCESSIBLE,
418 // Parent table flags include writable
419 PageTableFlags::PRESENT |
420 PageTableFlags::WRITABLE |
421 PageTableFlags::USER_ACCESSIBLE,
422 frame_allocator)?.flush()
423 };
424 }
425 Ok(start_frame.start_address())
426}
427
428/// Allocates a consecutive set of frames
429///

Callers 2

create_consecutive_pagesFunction · 0.85

Calls 1

as_mut_ptrMethod · 0.80

Tested by

no test coverage detected