summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/cpu/mmu.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-11-18 00:43:20 -0500
committerIan Moffett <ian@osmora.org>2025-11-18 00:43:20 -0500
commitf3fe5e8d39fc9bbcffb346d0b7329445140a1e93 (patch)
tree8b6e26b015fc1e60964c1f1db1da8a910a7606fc /sys/arch/amd64/cpu/mmu.c
parent7dd5178ddd0078d2e1ef38722bff1172f79f0f05 (diff)
kern/amd64: mmu: Add mu_pmap_forkvas() helper
The mu_pmap_forkvas() function copies the current virtual address with the user porition zeroed. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/arch/amd64/cpu/mmu.c')
-rw-r--r--sys/arch/amd64/cpu/mmu.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/arch/amd64/cpu/mmu.c b/sys/arch/amd64/cpu/mmu.c
index 65c4e46..15ba19a 100644
--- a/sys/arch/amd64/cpu/mmu.c
+++ b/sys/arch/amd64/cpu/mmu.c
@@ -28,10 +28,12 @@
*/
#include <sys/types.h>
+#include <sys/errno.h>
#include <sys/cdefs.h>
#include <kern/panic.h>
#include <mu/mmu.h>
#include <vm/vm.h>
+#include <vm/phys.h>
#include <md/vas.h>
/*
@@ -76,6 +78,32 @@ mu_pmap_writevas(struct mmu_vas *vas)
return 0;
}
+int
+mu_pmap_forkvas(struct mmu_vas *result)
+{
+ struct mmu_vas vas;
+ uintptr_t paddr, *pml4_dest;
+ uintptr_t *pml4_src;
+
+ mu_pmap_readvas(&vas);
+ paddr = vm_phys_alloc(1);
+ if (paddr == 0) {
+ return -ENOMEM;
+ }
+
+ pml4_dest = PHYS_TO_VIRT(paddr);
+ pml4_src = PHYS_TO_VIRT(vas.cr3);
+ for (uint16_t i = 0; i < 512; ++i) {
+ if (i < 256) {
+ pml4_dest[i] = 0;
+ } else {
+ pml4_dest[i] = pml4_src[i];
+ }
+ }
+
+ return 0;
+}
+
void
mu_pmap_init(void)
{