From 397efc08fc4b4cc8179d13019e7d654fa25cea4c Mon Sep 17 00:00:00 2001 From: ergo720 Date: Thu, 16 Aug 2018 20:57:00 +0200 Subject: [PATCH] Bug fixes --- src/CxbxKrnl/VMManager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CxbxKrnl/VMManager.cpp b/src/CxbxKrnl/VMManager.cpp index 0204683b1..6ae88e1dc 100644 --- a/src/CxbxKrnl/VMManager.cpp +++ b/src/CxbxKrnl/VMManager.cpp @@ -77,12 +77,13 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF ConstructMemoryRegion(CONTIGUOUS_MEMORY_BASE, CONTIGUOUS_MEMORY_XBOX_SIZE, ContiguousRegion); ConstructMemoryRegion(SYSTEM_MEMORY_BASE, SYSTEM_MEMORY_SIZE, SystemRegion); ConstructMemoryRegion(DEVKIT_MEMORY_BASE, DEVKIT_MEMORY_SIZE, DevkitRegion); - + + unsigned char PreviousLayout; if ((BootFlags & BOOT_QUICK_REBOOT) != 0) { // Restore the memory layout we were emulating in the previous session - unsigned char PreviousLayout = *(unsigned char*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 9); + PreviousLayout = *(unsigned char*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 9); m_MmLayoutChihiro = (PreviousLayout == MmChihiro); m_MmLayoutDebug = (PreviousLayout == MmDebug); m_MmLayoutRetail = (PreviousLayout == MmRetail); @@ -95,8 +96,8 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF m_MmLayoutChihiro = (g_XbeType == xtChihiro); m_MmLayoutDebug = (g_XbeType == xtDebug); m_MmLayoutRetail = (g_XbeType == xtRetail); - - *(unsigned char*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 9) = m_MmLayoutChihiro ? MmChihiro : (m_MmLayoutDebug ? MmDebug : MmRetail); + + PreviousLayout = m_MmLayoutChihiro ? MmChihiro : (m_MmLayoutDebug ? MmDebug : MmRetail); } // Set up general memory variables according to the xbe type @@ -137,7 +138,8 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF // The memory manager needs updating to only persist areas of memory marked with MmPersistContiguousMemory and discard the rest. // But right now it persists the whole block". So we also clear the entire mapped memory.bin since we are not quick rebooting xboxkrnl::RtlFillMemoryUlong((void*)CONTIGUOUS_MEMORY_BASE, g_SystemMaxMemory, 0); - xboxkrnl::RtlFillMemoryUlong((void*)PAGE_TABLES_BASE, PAGE_TABLES_SIZE, 0); + xboxkrnl::RtlFillMemoryUlong((void*)PAGE_TABLES_BASE, PAGE_TABLES_SIZE, 0); + *(unsigned char*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 9) = PreviousLayout; InitializePfnDatabase(); } else { @@ -2134,7 +2136,7 @@ xboxkrnl::NTSTATUS VMManager::XbVirtualMemoryStatistics(VAddr addr, xboxkrnl::PM // ergo720: hack. Always report as reserved the region after the memory placeholder and below 0x8000000 if we are emulating // a 128 MiB system regardless of what VirtualQuery says. Once LLE CPU and MMU are implemented, this can be removed - if (g_bIsRetail != true && addr >= XBE_IMAGE_BASE + XBE_MAX_VA && addr < CHIHIRO_MEMORY_SIZE) { + if (m_MmLayoutRetail != true && addr >= XBE_IMAGE_BASE + XBE_MAX_VA && addr < CHIHIRO_MEMORY_SIZE) { memory_statistics->AllocationBase = (void*)(XBE_IMAGE_BASE + XBE_MAX_VA); memory_statistics->AllocationProtect = XBOX_PAGE_NOACCESS; memory_statistics->BaseAddress = (void*)ROUND_DOWN_4K(addr);