feature (page maps): implemented a function to check if a page is mapped or not

This commit is contained in:
antifallobst 2023-04-20 18:29:21 +02:00
parent 18be33952f
commit 1b7be49c34
2 changed files with 22 additions and 0 deletions

View File

@ -31,6 +31,7 @@ extern page_map_T* page_map_fetch_current ();
extern void page_map_load (page_map_T* page_map);
void page_map_map_memory (page_map_T* page_map, void* virtual_address, void* physical_address, uint64_t flags);
void page_map_unmap_memory (page_map_T* page_map, void* virtual_address);
bool page_map_check_memory (page_map_T* page_map, void* virtual_address);
void* page_map_get_physical_address (page_map_T* page_map, void* virtual_address);
void page_map_destruct (page_map_T* page_map);
void page_map_dump_info (page_map_T* page_map);

View File

@ -89,6 +89,27 @@ void page_map_unmap_memory(page_map_T* page_map, void* virtual_address) {
page_table->entries[page_index] = 0;
}
bool page_map_check_memory(page_map_T* page_map, void* virtual_address) {
virtual_address = (void*)FLOOR_TO((uint64_t)virtual_address, PFRAME_SIZE);
// Intel's Developer Manual has a nice graph, that explains how these indexes are calculated
uint16_t page_index = ((uint64_t)virtual_address >> 12) & 0x1FF;
uint16_t page_table_index = ((uint64_t)virtual_address >> 21) & 0x1FF;
uint16_t page_directory_index = ((uint64_t)virtual_address >> 30) & 0x1FF;
uint16_t page_directory_page_index = ((uint64_t)virtual_address >> 39) & 0x1FF;
if (!page_map_entry_get_flag(&page_map->entries[page_directory_page_index], PM_FLAG_PRESENT)) return false;
page_map_T* page_directory_page = page_map_entry_get_address(&page_map->entries[page_directory_page_index]);
if (!page_map_entry_get_flag(&page_directory_page->entries[page_directory_index], PM_FLAG_PRESENT)) return false;
page_map_T* page_directory = page_map_entry_get_address(&page_directory_page->entries[page_directory_index]);
if (!page_map_entry_get_flag(&page_directory->entries[page_table_index], PM_FLAG_PRESENT)) return false;
page_map_T* page_table = page_map_entry_get_address(&page_directory->entries[page_table_index]);
return page_map_entry_get_flag(&page_table->entries[page_index], PM_FLAG_PRESENT);
}
void* page_map_get_physical_address(page_map_T* page_map, void* virtual_address) {
virtual_address = (void*)FLOOR_TO((uint64_t)virtual_address, PFRAME_SIZE);