From 5654c02f365ee3f1548e316cee0d312559ea4e8f Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 30 Apr 2026 18:59:46 +0100 Subject: [PATCH] x86_64: pmap: implement pmap_flush and pmap_remove_range --- arch/x86_64/pmap.c | 12 ++++++++++++ arch/x86_64/pmap_ctrl.S | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86_64/pmap.c b/arch/x86_64/pmap.c index 8eba547..d347336 100644 --- a/arch/x86_64/pmap.c +++ b/arch/x86_64/pmap.c @@ -321,6 +321,10 @@ static kern_status_t do_pmap_remove( virt_addr_t pv, enum page_size size) { + if (pmap == PMAP_INVALID) { + return KERN_OK; + } + unsigned int pml4t_index = BAD_INDEX, pdpt_index = BAD_INDEX, pd_index = BAD_INDEX, pt_index = BAD_INDEX; @@ -622,5 +626,13 @@ kern_status_t pmap_remove(pmap_t pmap, virt_addr_t p) kern_status_t pmap_remove_range(pmap_t pmap, virt_addr_t p, size_t len) { + if (pmap == PMAP_INVALID) { + return KERN_OK; + } + + for (size_t i = p; i < p + len; i += VM_PAGE_SIZE) { + pmap_remove(pmap, i); + } + return KERN_OK; } diff --git a/arch/x86_64/pmap_ctrl.S b/arch/x86_64/pmap_ctrl.S index 77f1b0e..9c3ac54 100644 --- a/arch/x86_64/pmap_ctrl.S +++ b/arch/x86_64/pmap_ctrl.S @@ -1,3 +1,11 @@ + .global pmap_flush + .type pmap_flush, @function + +pmap_flush: + mov %cr3, %rax + mov %rax, %cr3 + ret + .global pmap_switch .type pmap_switch, @function @@ -6,6 +14,7 @@ pmap_switch: mov %rdi, %cr3 ret + .global gigabyte_pages .type gigabyte_pages, @function