From ac64b124dad390eabc5eb7546eba54543c6e9f96 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 15 Nov 2018 22:53:27 +0100 Subject: [PATCH] paging: fix free unused pte --- core/paging.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/paging.c b/core/paging.c index 2b19d45..8f44ae9 100644 --- a/core/paging.c +++ b/core/paging.c @@ -103,8 +103,8 @@ int pagingSetup(paddr_t upperKernelAddr) } pt[ptEntry].present = 1; - pt[ptEntry].write = 1; // TODO set Kernel code as RO - pt[ptEntry].paddr = i >> PAGE_SHIFT; + pt[ptEntry].write = 1; // TODO set Kernel code as RO + pt[ptEntry].paddr = i >> PAGE_SHIFT; } // Setup mirroring @@ -150,14 +150,15 @@ int pageMap(vaddr_t vaddr, paddr_t paddr, int flags) __native_flush_tlb_single((vaddr_t)pt); memset((void *)pt, 0, PAGE_SIZE); - } + } else { - // Already mapped ? Remove old mapping - if (pt[ptEntry].present) { - unrefPhyPage(pt[ptEntry].paddr << PAGE_SHIFT); - } // PTE not already used ? We will use it ! So increase the PT ref count - else { - refPhyPage(pd[pdEntry].pt_addr << PAGE_SHIFT); + // Already mapped ? Remove old mapping + if (pt[ptEntry].present) { + unrefPhyPage(pt[ptEntry].paddr << PAGE_SHIFT); + } // PTE not already used ? We will use it ! So increase the PT ref count + else { + refPhyPage(pd[pdEntry].pt_addr << PAGE_SHIFT); + } } pt[ptEntry].user = (flags & PAGING_MEM_USER) ? 1 : 0;