ptos/amd64+hal: Add virtual address space forking
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -260,3 +260,37 @@ HalMmuUnmapPage(MMU_VAS *Vas, UPTR VirtualBase, MMU_PAGESIZE PageSize)
|
|||||||
MdTlbFlushSingle(VirtualBase);
|
MdTlbFlushSingle(VirtualBase);
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PT_STATUS
|
||||||
|
HalMmuForkVas(const MMU_VAS *Source, MMU_VAS *Result)
|
||||||
|
{
|
||||||
|
const UPTR *Src;
|
||||||
|
UPTR *Dest;
|
||||||
|
UPTR DestPhysBase;
|
||||||
|
MM_PFN DestPfn;
|
||||||
|
|
||||||
|
if (Source == NULL || Result == NULL) {
|
||||||
|
return STATUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
DestPfn = MmRequestFrame();
|
||||||
|
if (DestPfn == PFN_ERROR) {
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
DestPhysBase = PFN_TO_ADDRESS(DestPfn);
|
||||||
|
Src = PMA_TO_VMA((Source->Cr3 & PTE_ADDR_MASK));
|
||||||
|
Dest = PMA_TO_VMA(DestPhysBase);
|
||||||
|
|
||||||
|
/* Begin copy */
|
||||||
|
for (USIZE Idx = 0; Idx < 512; ++Idx) {
|
||||||
|
if (Idx < 256) {
|
||||||
|
Dest[Idx] = 0;
|
||||||
|
} else {
|
||||||
|
Dest[Idx] = Src[Idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result->Cr3 = DestPhysBase;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ VOID HalMmuReadVas(MMU_VAS *Result);
|
|||||||
*/
|
*/
|
||||||
VOID HalMmuWriteVas(const MMU_VAS *Vas);
|
VOID HalMmuWriteVas(const MMU_VAS *Vas);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fork a virtual address space with the user-portion zeroed
|
||||||
|
* out.
|
||||||
|
*
|
||||||
|
* @Source: Source VAS to fork from
|
||||||
|
* @Result: Result is written here
|
||||||
|
*/
|
||||||
|
PT_STATUS HalMmuForkVas(const MMU_VAS *Source, MMU_VAS *Result);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Map a single page of memory
|
* Map a single page of memory
|
||||||
*
|
*
|
||||||
|
|||||||
+12
-1
@@ -35,6 +35,9 @@ static USIZE PageSizeTable[] = {
|
|||||||
[PAGESIZE_4K] = 0x1000
|
[PAGESIZE_4K] = 0x1000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Kernel VAS */
|
||||||
|
static MMU_VAS KVas;
|
||||||
|
|
||||||
/* Bump pointer and vad tree */
|
/* Bump pointer and vad tree */
|
||||||
static UPTR VallocBump = VALLOC_BASE;
|
static UPTR VallocBump = VALLOC_BASE;
|
||||||
static MM_VAD_TREE VadTree;
|
static MM_VAD_TREE VadTree;
|
||||||
@@ -138,7 +141,15 @@ MmVmInit(VOID)
|
|||||||
|
|
||||||
HalMmuReadVas(&VasCurrent);
|
HalMmuReadVas(&VasCurrent);
|
||||||
MmVadTreeInit(&VadTree);
|
MmVadTreeInit(&VadTree);
|
||||||
|
Status = HalMmuForkVas(&VasCurrent, &KVas);
|
||||||
|
if (PT_ERROR(Status)) {
|
||||||
|
KeBugCheck(
|
||||||
|
BUGCHECK_OOM,
|
||||||
|
"failed to allocate kernel vas\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
HalMmuWriteVas(&KVas);
|
||||||
VirtualStart = VallocBump;
|
VirtualStart = VallocBump;
|
||||||
VallocBump += INITIAL_VALLOC_PAGES * PAGESIZE;
|
VallocBump += INITIAL_VALLOC_PAGES * PAGESIZE;
|
||||||
VirtualEnd = VallocBump;
|
VirtualEnd = VallocBump;
|
||||||
@@ -152,7 +163,7 @@ MmVmInit(VOID)
|
|||||||
|
|
||||||
PhysicalBase = PFN_TO_ADDRESS(Pfn);
|
PhysicalBase = PFN_TO_ADDRESS(Pfn);
|
||||||
Status = HalMmuMapPage(
|
Status = HalMmuMapPage(
|
||||||
&VasCurrent,
|
&KVas,
|
||||||
VirtualStart + Off,
|
VirtualStart + Off,
|
||||||
PhysicalBase,
|
PhysicalBase,
|
||||||
PAGE_READ| PAGE_WRITE,
|
PAGE_READ| PAGE_WRITE,
|
||||||
|
|||||||
Reference in New Issue
Block a user