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)
| 21 | /// `physical_memory_offset`. Also, this function must be only called once |
| 22 | /// to avoid aliasing `&mut` references (which is undefined behavior). |
| 23 | unsafe 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 | |
| 37 | pub 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()); |