MCPcopy Create free account
hub / github.com/Ruddle/Fomos / active_level_4_table

Function active_level_4_table

bootloader/kernel/src/memory.rs:23–35  ·  view source on GitHub ↗

Returns a mutable reference to the active level 4 table. This function is unsafe because the caller must guarantee that the complete physical memory is mapped to virtual memory at the passed `physical_memory_offset`. Also, this function must be only called once to avoid aliasing `&mut` references (which is undefined behavior).

(physical_memory_offset: VirtAddr)

Source from the content-addressed store, hash-verified

21/// `physical_memory_offset`. Also, this function must be only called once
22/// to avoid aliasing `&mut` references (which is undefined behavior).
23unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
24 use x86_64::registers::control::Cr3;
25
26 let (level_4_table_frame, _) = Cr3::read();
27
28 let phys = level_4_table_frame.start_address();
29
30 log::info!("level_4_table_frame.start_address {:?}", phys);
31 let virt = physical_memory_offset + phys.as_u64();
32 let page_table_ptr: *mut PageTable = virt.as_mut_ptr();
33
34 &mut *page_table_ptr // unsafe
35}
36
37pub unsafe fn kern_phy_to_virt(physical_memory_offset: VirtAddr, target_phy: PhysAddr) -> VirtAddr {
38 let virt = VirtAddr::new(physical_memory_offset.as_u64() + target_phy.as_u64());

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected