mmu: destroy ctx

This commit is contained in:
Matheus
2022-10-11 23:26:20 -03:00
parent 3958f6b51a
commit defed64456
2 changed files with 32 additions and 2 deletions
+1
View File
@@ -21,6 +21,7 @@
typedef uint64_t* arch_mmu_tableptr;
void arch_mmu_destroy(arch_mmu_tableptr context);
int arch_mmu_map(arch_mmu_tableptr, void*, void*, size_t);
bool arch_mmu_isaccessed(arch_mmu_tableptr, void*);
void* arch_mmu_getphysicaladdr(arch_mmu_tableptr, void*);
+31 -2
View File
@@ -108,8 +108,6 @@ static bool setpage(arch_mmu_tableptr context, void* vaddr, uint64_t entry){
}
static uint64_t getmapping(arch_mmu_tableptr context, void* vaddr){
uint64_t addr = (uint64_t)vaddr;
size_t pdpt = (addr >> 39) & 0b111111111;
@@ -150,6 +148,37 @@ void* arch_mmu_getphysicaladdr(arch_mmu_tableptr context, void* addr){
return paddr;
}
static void destroy(uint64_t* table, int depth){
for(size_t i = 0; i < 512; ++i){
if(depth == 0 && i == 256)
break;
uint64_t paddr = table[i];
if(!paddr)
continue;
paddr &= ~((uint64_t)0xFFF);
paddr &= ~(uint64_t)ARCH_MMU_MAP_NOEXEC;
if(depth < 3)
destroy(paddr+limine_hhdm_offset, depth+1);
pmm_free(paddr, 1);
}
}
void arch_mmu_destroy(arch_mmu_tableptr context){
if(context < limine_hhdm_offset)
context = (uint8_t*)context + (uintptr_t)limine_hhdm_offset;
destroy(context, 0);
}
bool arch_mmu_isaccessed(arch_mmu_tableptr context, void* addr){
return (getmapping(context, addr) & ARCH_MMU_MAP_ACCESSED) != 0;
}