diff --git a/paw/stos/arch/amd64/cpu/mmu.c b/paw/stos/arch/amd64/cpu/mmu.c index 3abb2e9..898a756 100644 --- a/paw/stos/arch/amd64/cpu/mmu.c +++ b/paw/stos/arch/amd64/cpu/mmu.c @@ -187,6 +187,39 @@ MmuExtractLevel(MMU_VAS *Vas, UPTR Vma, PAGE_LEVEL Level, BOOLEAN Alloc) return PageMap; } +ST_STATUS +HalMmuForkVas(MMU_VAS *Old, MMU_VAS *NewResult) +{ + UPTR *OldVma, *NewVma; + UPTR NewPma; + MM_PFN NewPfn; + + if (Old == NULL || NewResult == NULL) { + return STATUS_INVALID_PARAM; + } + + NewPfn = MmRequestFrame(); + if (NewPfn == 0) { + return STATUS_NO_MEMORY; + } + + NewPma = NewPfn << LOG2_PAGESIZE; + NewVma = PMA_TO_VMA(NewPma); + OldVma = PMA_TO_VMA((Old->Cr3 & PTE_ADDR_MASK)); + + /* Start breeding the new VAS~ Fill it deep~ */ + for (USHORT Off = 0; Off < 512; ++Off) { + if (Off < 256) { + NewVma[Off] = 0; + } else { + NewVma[Off] = OldVma[Off]; + } + } + + NewResult->Cr3 = NewPma; + return STATUS_SUCCESS; +} + VOID HalMmuReadVas(MMU_VAS *Result) { diff --git a/paw/stos/head/hal/mmu.h b/paw/stos/head/hal/mmu.h index 3ed797b..f61be37 100644 --- a/paw/stos/head/hal/mmu.h +++ b/paw/stos/head/hal/mmu.h @@ -36,6 +36,19 @@ VOID HalMmuReadVas(MMU_VAS *Result); */ VOID HalMmuWriteVas(MMU_VAS *Vas); +/* + * When starting other cute slut critter processes, we need a fresh + * VAS with the lower half gone so that it can be re-populated properly + * for user processes. + * + * This function does not breed the CR3 register and you'll manually + * need to do so with HalMmuWriteVas() + * + * @Old: Old VAS to fork + * @NewResult: New result is written here + */ +ST_STATUS HalMmuForkVas(MMU_VAS *Old, MMU_VAS *NewResult); + /* * Map a single page of memory *