From 7e868309a7fcac995eacdd5a4acc4e967f6b49d8 Mon Sep 17 00:00:00 2001 From: ergo720 Date: Sat, 3 Mar 2018 12:46:36 +0100 Subject: [PATCH] Oops... (small update to DestructVMA) --- src/CxbxKrnl/VMManager.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/CxbxKrnl/VMManager.cpp b/src/CxbxKrnl/VMManager.cpp index 115627ae6..9f76f17ec 100644 --- a/src/CxbxKrnl/VMManager.cpp +++ b/src/CxbxKrnl/VMManager.cpp @@ -1068,7 +1068,7 @@ VAddr VMManager::MapBlockWithVirtualAlloc(VAddr StartingAddr, size_t Size, size_ { for (; StartingAddr + Size - 1 < VmaEnd; StartingAddr += m_AllocationGranularity) { - if ((VAddr)VirtualAlloc((void*)StartingAddr, Size, MEM_RESERVE | MEM_COMMIT, Perms) == StartingAddr) + if ((VAddr)VirtualAlloc((void*)StartingAddr, Size, XBOX_MEM_RESERVE | XBOX_MEM_COMMIT, Perms) == StartingAddr) { return StartingAddr; } @@ -1081,7 +1081,7 @@ VAddr VMManager::ReserveBlockWithVirtualAlloc(VAddr StartingAddr, size_t Size, s { for (; StartingAddr + Size - 1 < VmaEnd; StartingAddr += m_AllocationGranularity) { - if ((VAddr)VirtualAlloc((void*)StartingAddr, Size, MEM_RESERVE, XBOX_PAGE_NOACCESS) == StartingAddr) + if ((VAddr)VirtualAlloc((void*)StartingAddr, Size, XBOX_MEM_RESERVE, XBOX_PAGE_NOACCESS) == StartingAddr) { return StartingAddr; } @@ -1309,7 +1309,23 @@ VMAIter VMManager::CheckExistenceVMA(VAddr addr, MemoryRegionType Type, size_t S void VMManager::DestructVMA(VMAIter it, MemoryRegionType Type) { - VMAIter CarvedVmaIt = CarveVMARange(it->first, it->second.size); + BOOL ret; + + if (it->second.bFragmented) + { + ret = VirtualFree((void*)it->first, 0, XBOX_MEM_RELEASE); + } + else + { + ret = UnmapViewOfFile((void*)(ROUND_DOWN(it->first, m_AllocationGranularity))); + } + + if (!ret) + { + DbgPrintf("Deallocation routine failed with error %d\n", GetLastError()); + } + + VMAIter CarvedVmaIt = CarveVMARange(it->first, it->second.size, Type); VAddr target_end = it->first + it->second.size; VMAIter it_end = m_MemoryRegionArray[Type].RegionMap.end(); @@ -1319,7 +1335,7 @@ void VMManager::DestructVMA(VMAIter it, MemoryRegionType Type) // merged during this process, causing invalidation of the iterators while (CarvedVmaIt != it_end && CarvedVmaIt->second.base < target_end) { - CarvedVmaIt = std::next(Unmap(CarvedVmaIt)); + CarvedVmaIt = std::next(Unmap(CarvedVmaIt, Type)); } // If we free an entire vma (which should always be the case), prev(CarvedVmaIt) will be the freed vma. If it is not,