arch_mmu_unmap()

This commit is contained in:
Matheus
2022-07-27 20:50:42 -03:00
parent ed866b05a9
commit 605c87e85f
2 changed files with 11 additions and 3 deletions
+10 -3
View File
@@ -57,12 +57,11 @@ static bool setpage(arch_mmu_tableptr context, void* vaddr, uint64_t entry){
context = (void*)context + (size_t)limine_hhdm_offset; context = (void*)context + (size_t)limine_hhdm_offset;
uint64_t* pdptaddr = context[pdpt] & ~0xFFF; uint64_t* pdptaddr = context[pdpt] & ~0xFFF;
// TODO unallocate in case of failure
if(!pdptaddr){ if(!pdptaddr){
pdptaddr = pmm_alloc(1); pdptaddr = pmm_alloc(1);
if(!pdptaddr) return false;
changeentry(&context[pdpt], pdptaddr, PTR_FLAGS); changeentry(&context[pdpt], pdptaddr, PTR_FLAGS);
memset((void*)pdptaddr + (size_t)limine_hhdm_offset, 0, PAGE_SIZE); memset((void*)pdptaddr + (size_t)limine_hhdm_offset, 0, PAGE_SIZE);
} }
@@ -73,6 +72,7 @@ static bool setpage(arch_mmu_tableptr context, void* vaddr, uint64_t entry){
if(!pdaddr){ if(!pdaddr){
pdaddr = pmm_alloc(1); pdaddr = pmm_alloc(1);
if(!pdaddr) return false;
changeentry(&pdptaddr[pd], pdaddr, PTR_FLAGS); changeentry(&pdptaddr[pd], pdaddr, PTR_FLAGS);
memset((void*)pdaddr + (size_t)limine_hhdm_offset, 0, PAGE_SIZE); memset((void*)pdaddr + (size_t)limine_hhdm_offset, 0, PAGE_SIZE);
} }
@@ -83,6 +83,7 @@ static bool setpage(arch_mmu_tableptr context, void* vaddr, uint64_t entry){
if(!ptaddr){ if(!ptaddr){
ptaddr = pmm_alloc(1); ptaddr = pmm_alloc(1);
if(!ptaddr) return false;
changeentry(&pdaddr[pt], ptaddr, PTR_FLAGS); changeentry(&pdaddr[pt], ptaddr, PTR_FLAGS);
memset((void*)ptaddr + (size_t)limine_hhdm_offset, 0, PAGE_SIZE); memset((void*)ptaddr + (size_t)limine_hhdm_offset, 0, PAGE_SIZE);
} }
@@ -144,7 +145,13 @@ int arch_mmu_map(arch_mmu_tableptr context, void* paddr, void* vaddr, size_t fla
} }
// TODO unmap void arch_mmu_unmap(arch_mmu_tableptr context, void* vaddr){
if(!getmapping(context, vaddr)) return;
arch_mmu_map(context, 0, vaddr, 0);
}
void arch_mmu_init(){ void arch_mmu_init(){
+1
View File
@@ -316,6 +316,7 @@ static bool unmap(vmm_mapping** mapstart, void* addr, size_t pagec){
if(arch_mmu_isaccessed(context, addr)){ if(arch_mmu_isaccessed(context, addr)){
void* paddr = arch_mmu_getphysicaladdr(context, addr); void* paddr = arch_mmu_getphysicaladdr(context, addr);
pmm_free(paddr, 1); pmm_free(paddr, 1);
arch_mmu_unmap(context, addr);
} }
break; break;