mm: make get_physaddr return NULL if PD or PT is not present

This commit is contained in:
2025-12-09 23:34:15 +03:00
parent 24caf9c8aa
commit 2a7f62e275
+10 -2
View File
@@ -22,10 +22,18 @@ void *get_physaddr(void *virtualaddr) {
unsigned long ptindex = (unsigned long)virtualaddr >> 12 & 0x03FF; unsigned long ptindex = (unsigned long)virtualaddr >> 12 & 0x03FF;
unsigned long *pd = (unsigned long *)0xFFFFF000; unsigned long *pd = (unsigned long *)0xFFFFF000;
// Here you need to check whether the PD entry is present. if(!(pd[pdindex] & PAGE_PRESENT))
{
debug_log("get_physaddr: no PD (virt address is %X)\n", virtualaddr);
return NULL;
}
uint32_t *pt = (uint32_t*)(0xFFC00000 + (pdindex << 12)); uint32_t *pt = (uint32_t*)(0xFFC00000 + (pdindex << 12));
// Here you need to check whether the PT entry is present. if(!(pt[ptindex] & PAGE_PRESENT))
{
debug_log("get_physaddr: no PT (virt address is %X)\n", virtualaddr);
return NULL;
}
return (void *)((pt[ptindex] & ~0xFFF) + ((unsigned long)virtualaddr & 0xFFF)); return (void *)((pt[ptindex] & ~0xFFF) + ((unsigned long)virtualaddr & 0xFFF));
} }