[Bug] Problem with mapping

This commit is contained in:
Adrien Bourmault 2020-01-20 19:09:42 +01:00
parent 8d839cd586
commit a8035052a9
2 changed files with 24 additions and 7 deletions

View File

@ -230,34 +230,51 @@ ulong *MmGetPageDescriptorFromVirtual(void *virtualAddr)
DebugLog("PML4[%d], PDP[%d], PD[%d], PT[%d]\n", pml4Index, pdpIndex, pdIndex, ptIndex); DebugLog("PML4[%d], PDP[%d], PD[%d], PT[%d]\n", pml4Index, pdpIndex, pdIndex, ptIndex);
if (!((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51 if (!((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51
// Alloc space
KalAllocMemoryEx((void**)&MmPageMapLevel4[pml4Index], 512*sizeof(pdpe_t), M_ZEROED, KPAGESIZE); KalAllocMemoryEx((void**)&MmPageMapLevel4[pml4Index], 512*sizeof(pdpe_t), M_ZEROED, KPAGESIZE);
// Set present
MmPageMapLevel4[pml4Index] = (pml4_t)((ulong)MmPageMapLevel4[pml4Index] | PRESENT | READWRITE);
pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000); pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000);
DebugLog("Create PDP\n"); DebugLog("\tCreate PDP at %p\n", MmPageMapLevel4[pml4Index]);
} else { } else {
pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000); pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000);
} }
DebugLog("PDP at %p = %p\n", &pdp[0], pdp[pdpIndex]); DebugLog("\tPDP[%d] = %p\n", pdpIndex, pdp[pdpIndex]);
if (!((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51 if (!((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51
KalAllocMemoryEx((void**)&pdp[pdpIndex], 512*sizeof(pde_t), M_ZEROED, KPAGESIZE); KalAllocMemoryEx((void**)&pdp[pdpIndex], 512*sizeof(pde_t), M_ZEROED, KPAGESIZE);
pdp[pdpIndex] = (pdpe_t)((ulong)pdp[pdpIndex] | PRESENT | READWRITE);
pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000); pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000);
DebugLog("Create PD\n"); DebugLog("\tCreate PD at %p\n", (ulong)pdp[pdpIndex]);
} else { } else {
pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000); pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000);
} }
DebugLog("PD at %p = %p\n", &pd[0], pd[pdIndex]); DebugLog("\tPD[%d] = %p\n", pdIndex, pd[pdIndex]);
if (!((ulong)pd[pdIndex] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51 if (!((ulong)pd[pdIndex] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51
//
KalAllocMemoryEx((void**)&pd[pdIndex], 512*sizeof(pte_t), M_ZEROED, KPAGESIZE); KalAllocMemoryEx((void**)&pd[pdIndex], 512*sizeof(pte_t), M_ZEROED, KPAGESIZE);
pd[pdIndex] = (pde_t)((ulong)pd[pdIndex] | PRESENT | READWRITE);
pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000); pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000);
DebugLog("Create PT\n"); DebugLog("\tCreate PT at %p\n", (ulong)pd[pdIndex]);
} else { } else {
pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000); pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000);
} }
DebugLog("PT at %p = %p\n", &pt[0], pt[ptIndex]); DebugLog("\tPT[%d] = %p\n", ptIndex, pt[ptIndex]);
MmLoadPML4((void *)MmPageMapLevel4); MmLoadPML4((void *)MmPageMapLevel4);

View File

@ -297,7 +297,7 @@ error_t MmTestBusyPage(void)
ulong a = KeGetTicks(); ulong a = KeGetTicks();
DebugLog("Start alloc 30 MB: %lu s\n", a/1000); DebugLog("Start alloc 30 MB: %lu s\n", a/1000);
tab[j++] = MmAllocPageFrame(5*MB, NORMAL); tab[j++] = MmAllocPageFrame(5*MB, NORMAL);
tab[j++] = MmAllocPageFrame(8*KB, NORMAL); tab[j++] = MmAllocPageFrame(513*4*KB, NORMAL);
ulong b = KeGetTicks(); ulong b = KeGetTicks();
DebugLog("End alloc : %lu s\n", b/1000); DebugLog("End alloc : %lu s\n", b/1000);
DebugLog("Alloc time : %lu s\n", (b-a)/1000); DebugLog("Alloc time : %lu s\n", (b-a)/1000);