diff --git a/service/ptos/arch/amd64/cpu/mmu.c b/service/ptos/arch/amd64/cpu/mmu.c index 1e3d692..ad6845b 100644 --- a/service/ptos/arch/amd64/cpu/mmu.c +++ b/service/ptos/arch/amd64/cpu/mmu.c @@ -231,3 +231,30 @@ HalMmuMapPage( MdTlbFlushSingle(VirtualBase); return STATUS_SUCCESS; } + +PT_STATUS +HalMmuUnmapPage(MMU_VAS *Vas, UPTR VirtualBase, MMU_PAGESIZE PageSize) +{ + UPTR *PageTable; + USIZE PageTableIndex; + + if (Vas == NULL) { + return STATUS_INVALID_PARAM; + } + + if (!MmuPageSizeValid(PageSize)) { + return STATUS_INVALID_PARAM; + } + + PageTable = MmuPageMapExtract(Vas, VirtualBase, PAGEMAP_PML1, false); + if (PageTable == NULL) { + return STATUS_NOT_FOUND; + } + + PageTableIndex = MmuPageMapIndex(VirtualBase, PAGEMAP_PML1); + + /* Unmap and flush the TLB */ + PageTable[PageTableIndex] = 0; + MdTlbFlushSingle(VirtualBase); + return STATUS_SUCCESS; +} diff --git a/service/ptos/head/hal/mmu.h b/service/ptos/head/hal/mmu.h index 7fea973..7879dfc 100644 --- a/service/ptos/head/hal/mmu.h +++ b/service/ptos/head/hal/mmu.h @@ -52,4 +52,16 @@ PT_STATUS HalMmuMapPage( MMU_PAGESIZE PageSize ); +/* + * Unmap a single page of memory + * + * @Vas: Virtual address space to unmap within + * @VirtualBase: Virtual address to unmap + * @PageSize: Page size to unmap + */ +PT_STATUS HalMmuUnmapPage( + MMU_VAS *Vas, UPTR VirtualBase, + MMU_PAGESIZE PageSize +); + #endif /* !_HAL_MMU_H_ */