| 139 | } |
| 140 | |
| 141 | auto VirtualMemory::GetMapping(void* page_dir, void* virtual_addr) |
| 142 | -> Expected<void*> { |
| 143 | assert(page_dir != nullptr && "GetMapping: page_dir is null"); |
| 144 | |
| 145 | auto pte_result = FindPageTableEntry(page_dir, virtual_addr, false); |
| 146 | if (!pte_result.has_value()) { |
| 147 | return std::unexpected(Error(ErrorCode::kVmPageNotMapped)); |
| 148 | } |
| 149 | |
| 150 | auto pte = pte_result.value(); |
| 151 | |
| 152 | if (!cpu_io::virtual_memory::IsPageTableEntryValid(*pte)) { |
| 153 | return std::unexpected(Error(ErrorCode::kVmPageNotMapped)); |
| 154 | } |
| 155 | |
| 156 | return reinterpret_cast<void*>( |
| 157 | cpu_io::virtual_memory::PageTableEntryToPhysical(*pte)); |
| 158 | } |
| 159 | |
| 160 | auto VirtualMemory::DestroyPageDirectory(void* page_dir, bool free_pages) |
| 161 | -> void { |