From 8790b48c0600df780aa6d504ffac047b1246ed67 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Thu, 29 Nov 2018 20:14:32 +0100 Subject: [PATCH] Fix a bug in AllocateSystemMemory --- src/CxbxKrnl/VMManager.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/CxbxKrnl/VMManager.cpp b/src/CxbxKrnl/VMManager.cpp index c7517d84c..167ddcdd1 100644 --- a/src/CxbxKrnl/VMManager.cpp +++ b/src/CxbxKrnl/VMManager.cpp @@ -852,19 +852,24 @@ VAddr VMManager::AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Siz PMMPTE EndingPte; PFN pfn; PFN EndingPfn; - PFN LowestAcceptablePfn = 0; - PFN HighestAcceptablePfn = XBOX_HIGHEST_PHYSICAL_PAGE; + PFN LowestAcceptablePfn; + PFN HighestAcceptablePfn; PFN_COUNT PteNumber; PFN_COUNT PagesNumber; VAddr addr; MappingFn MappingRoutine; - bool bVAlloc = false; - MemoryRegionType MemoryType = SystemRegion; + bool bVAlloc; + MemoryRegionType MemoryType; // NOTE: AllocateSystemMemory won't allocate a physical page for the guard page (if requested) and just adds an extra // unallocated virtual page in front of the mapped allocation. For this reason we will decommmit later the extra guard page allocated - if (!Size || !ConvertXboxToSystemPteProtection(Perms, &TempPte)) { RETURN(NULL); } + if (!Size || !ConvertXboxToSystemPteProtection(Perms, &TempPte)) { RETURN(NULL); } + + LowestAcceptablePfn = 0; + HighestAcceptablePfn = m_MmLayoutDebug ? XBOX_HIGHEST_PHYSICAL_PAGE : m_HighestPage; + bVAlloc = false; + MemoryType = SystemRegion; Lock();