From 5d5fc992da49cb1d8ea438d3692899f27d9611d0 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Mon, 28 Mar 2022 19:46:52 +0200 Subject: [PATCH] Fixed wrong type for MmGlobalData kernel export --- src/core/kernel/common/mm.h | 97 +++++++- src/core/kernel/exports/EmuKrnlMm.cpp | 2 +- .../kernel/memory-manager/PhysicalMemory.cpp | 68 ++--- .../kernel/memory-manager/PhysicalMemory.h | 101 ++------ .../kernel/memory-manager/PoolManager.cpp | 8 +- src/core/kernel/memory-manager/VMManager.cpp | 232 +++++++++--------- src/core/kernel/memory-manager/VMManager.h | 12 +- 7 files changed, 284 insertions(+), 236 deletions(-) diff --git a/src/core/kernel/common/mm.h b/src/core/kernel/common/mm.h index 3be1e3e4e..dee2a19e6 100644 --- a/src/core/kernel/common/mm.h +++ b/src/core/kernel/common/mm.h @@ -17,7 +17,102 @@ namespace xbox { -XBSYSAPI EXPORTNUM(102) PVOID MmGlobalData[8]; +typedef ulong_xt PFN; +typedef ulong_xt PFN_COUNT; +typedef ulong_xt PFN_NUMBER, *PPFN_NUMBER; + + typedef struct _MMPFNFREE + { + ushort_xt PackedPfnFlink; + ushort_xt PackedPfnBlink; + } MMPFNFREE, *PMMPFNFREE; + + typedef struct _MMPFNREGION + { + MMPFNFREE FreePagesByColor[32]; + PFN_COUNT AvailablePages; + } MMPFNREGION, *PMMPFNREGION; + + /* enum describing the usage type of the memory pages */ + typedef enum _PageType + { + UnknownType, // Used by the PFN database + StackType, // Used by MmCreateKernelStack + VirtualPageTableType, // Used by the pages holding the PTs that map the user memory (lower 2 GiB) + SystemPageTableType, // Used by the pages holding the PTs that map the system memory + PoolType, // Used by ExAllocatePoolWithTag + VirtualMemoryType, // Used by NtAllocateVirtualMemory + SystemMemoryType, // Used by MmAllocateSystemMemory + ImageType, // Used to mark executable memory + CacheType, // Used by the file cache related functions + ContiguousType, // Used by MmAllocateContiguousMemoryEx and others + DebuggerType, // xbdm-related + COUNTtype // The size of the array containing the page usage per type + } PageType; + + /* The Xbox PTE, modelled around the Intel 386 PTE specification */ + typedef struct _XBOX_PTE + { + ulong_xt Valid : 1; + ulong_xt Write : 1; + ulong_xt Owner : 1; + ulong_xt WriteThrough : 1; + ulong_xt CacheDisable : 1; + ulong_xt Accessed : 1; + ulong_xt Dirty : 1; + ulong_xt LargePage : 1; + ulong_xt Global : 1; + ulong_xt GuardOrEnd : 1; // software field used for our own purposes + ulong_xt Persist : 1; // software field used for our own purposes + ulong_xt Unused : 1; // software field used for our own purposes + ulong_xt PFN : 20; + } XBOX_PTE, *PXBOX_PTE; + + + /* PTE as used by the memory manager */ + typedef union _MMPTE + { + ulong_xt Default; + XBOX_PTE Hardware; + } MMPTE, *PMMPTE; + + typedef PFN_NUMBER (FASTCALL *PMMREMOVE_PAGE_ROUTINE) ( + IN PageType BusyType, + IN PMMPTE TargetPte + ); + + typedef struct _MMPTERANGE + { + MMPTE HeadPte; + PMMPTE FirstCommittedPte; + PMMPTE LastCommittedPte; + PMMPTE LastReservedPte; + PFN_COUNT *AvailablePages; + PMMREMOVE_PAGE_ROUTINE RemovePageRoutine; + } MMPTERANGE, *PMMPTERANGE; + + typedef struct _MMADDRESS_NODE + { + ulong_ptr_xt StartingVpn; + ulong_ptr_xt EndingVpn; + struct _MMADDRESS_NODE *Parent; + struct _MMADDRESS_NODE *LeftChild; + struct _MMADDRESS_NODE *RightChild; + } MMADDRESS_NODE, *PMMADDRESS_NODE; + +typedef struct _MMGLOBALDATA +{ + PMMPFNREGION RetailPfnRegion; + PMMPTERANGE SystemPteRange; + PULONG AvailablePages; + PFN_COUNT *AllocatedPagesByUsage; + PRTL_CRITICAL_SECTION AddressSpaceLock; + PMMADDRESS_NODE *VadRoot; + PMMADDRESS_NODE *VadHint; + PMMADDRESS_NODE *VadFreeHint; +} MMGLOBALDATA, *PMMGLOBALDATA; + +XBSYSAPI EXPORTNUM(102) MMGLOBALDATA MmGlobalData; // ****************************************************************** // * MmAllocateContiguousMemory diff --git a/src/core/kernel/exports/EmuKrnlMm.cpp b/src/core/kernel/exports/EmuKrnlMm.cpp index 49f749fff..844e1ca2a 100644 --- a/src/core/kernel/exports/EmuKrnlMm.cpp +++ b/src/core/kernel/exports/EmuKrnlMm.cpp @@ -49,7 +49,7 @@ namespace NtDll // ****************************************************************** // * 0x0066 - MmGlobalData // ****************************************************************** -XBSYSAPI EXPORTNUM(102) xbox::PVOID xbox::MmGlobalData[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; +XBSYSAPI EXPORTNUM(102) xbox::MMGLOBALDATA xbox::MmGlobalData = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; // ****************************************************************** // * 0x00A4 - LaunchDataPage diff --git a/src/core/kernel/memory-manager/PhysicalMemory.cpp b/src/core/kernel/memory-manager/PhysicalMemory.cpp index a65f8d2c3..ca1df81d6 100644 --- a/src/core/kernel/memory-manager/PhysicalMemory.cpp +++ b/src/core/kernel/memory-manager/PhysicalMemory.cpp @@ -45,9 +45,9 @@ inline FreeBlock* ListEntryToFreeBlock(xbox::PLIST_ENTRY pListEntry) void PhysicalMemory::InitializePageDirectory() { - PMMPTE pPde; - PMMPTE pPde_end; - MMPTE TempPte; + xbox::PMMPTE pPde; + xbox::PMMPTE pPde_end; + xbox::MMPTE TempPte; // Write the pde's of the WC (tiled) memory - no page tables @@ -76,7 +76,7 @@ void PhysicalMemory::InitializePageDirectory() // TODO: map memory for the file system cache? } -void PhysicalMemory::WritePfn(PFN pfn_start, PFN pfn_end, PMMPTE pPte, PageType BusyType, bool bZero) +void PhysicalMemory::WritePfn(xbox::PFN pfn_start, xbox::PFN pfn_end, xbox::PMMPTE pPte, xbox::PageType BusyType, bool bZero) { XBOX_PFN TempPF; @@ -101,7 +101,7 @@ void PhysicalMemory::WritePfn(PFN pfn_start, PFN pfn_end, PMMPTE pPte, PageType TempPF.Default = 0; TempPF.Busy.Busy = 1; TempPF.Busy.BusyType = BusyType; - if (BusyType != VirtualPageTableType && BusyType != SystemPageTableType) { + if (BusyType != xbox::VirtualPageTableType && BusyType != xbox::SystemPageTableType) { TempPF.Busy.PteIndex = GetPteOffset(GetVAddrMappedByPte(pPte)); } else { TempPF.PTPageFrame.PtesUsed = 0; } // we are writing a pfn of a PT @@ -118,13 +118,13 @@ void PhysicalMemory::WritePfn(PFN pfn_start, PFN pfn_end, PMMPTE pPte, PageType } } -void PhysicalMemory::WritePte(PMMPTE pPteStart, PMMPTE pPteEnd, MMPTE Pte, PFN pfn, bool bZero) +void PhysicalMemory::WritePte(xbox::PMMPTE pPteStart, xbox::PMMPTE pPteEnd, xbox::MMPTE Pte, xbox::PFN pfn, bool bZero) { // This function is intended to write pte's, not pde's. To write those, use (De)AllocatePT which will perform // all the necessary housekeeping. Also, the pde's mapping these pte's should have already being commited or else // GetPfnOfPT will assert - PMMPTE PointerPte = pPteStart; + xbox::PMMPTE PointerPte = pPteStart; PXBOX_PFN PTpfn; if (bZero) @@ -163,16 +163,16 @@ void PhysicalMemory::WritePte(PMMPTE pPteStart, PMMPTE pPteEnd, MMPTE Pte, PFN p } } -bool PhysicalMemory::RemoveFree(PFN_COUNT NumberOfPages, PFN* result, PFN_COUNT PfnAlignment, PFN start, PFN end) +bool PhysicalMemory::RemoveFree(xbox::PFN_COUNT NumberOfPages, xbox::PFN* result, xbox::PFN_COUNT PfnAlignment, xbox::PFN start, xbox::PFN end) { xbox::PLIST_ENTRY ListEntry; - PFN PfnStart; - PFN PfnEnd; - PFN IntersectionStart; - PFN IntersectionEnd; - PFN_COUNT PfnCount; - PFN_COUNT PfnAlignmentMask; - PFN_COUNT PfnAlignmentSubtraction; + xbox::PFN PfnStart; + xbox::PFN PfnEnd; + xbox::PFN IntersectionStart; + xbox::PFN IntersectionEnd; + xbox::PFN_COUNT PfnCount; + xbox::PFN_COUNT PfnAlignmentMask; + xbox::PFN_COUNT PfnAlignmentSubtraction; // The caller should already guarantee that there are enough free pages available if (NumberOfPages == 0) { result = nullptr; return false; } @@ -307,10 +307,10 @@ bool PhysicalMemory::RemoveFree(PFN_COUNT NumberOfPages, PFN* result, PFN_COUNT return false; } -void PhysicalMemory::InsertFree(PFN start, PFN end) +void PhysicalMemory::InsertFree(xbox::PFN start, xbox::PFN end) { xbox::PLIST_ENTRY ListEntry; - PFN_COUNT size = end - start + 1; + xbox::PFN_COUNT size = end - start + 1; ListEntry = FreeList.Blink; // search from the top @@ -374,7 +374,7 @@ void PhysicalMemory::InsertFree(PFN start, PFN end) } } -bool PhysicalMemory::ConvertXboxToSystemPtePermissions(DWORD perms, PMMPTE pPte) +bool PhysicalMemory::ConvertXboxToSystemPtePermissions(DWORD perms, xbox::PMMPTE pPte) { ULONG Mask = 0; @@ -431,7 +431,7 @@ bool PhysicalMemory::ConvertXboxToSystemPtePermissions(DWORD perms, PMMPTE pPte) return false; } -bool PhysicalMemory::ConvertXboxToPtePermissions(DWORD perms, PMMPTE pPte) +bool PhysicalMemory::ConvertXboxToPtePermissions(DWORD perms, xbox::PMMPTE pPte) { ULONG Mask = 0; ULONG LowNibble; @@ -644,12 +644,12 @@ DWORD PhysicalMemory::ConvertXboxToWinPermissions(DWORD Perms) bool PhysicalMemory::AllocatePT(size_t Size, VAddr addr) { - PFN pfn; - PMMPTE pPde; - MMPTE TempPte; - PFN_COUNT PdeNumber = PAGES_SPANNED_LARGE(addr, Size); - PFN_COUNT PTtoCommit = 0; - PageType BusyType = SystemPageTableType; + xbox::PFN pfn; + xbox::PMMPTE pPde; + xbox::MMPTE TempPte; + xbox::PFN_COUNT PdeNumber = PAGES_SPANNED_LARGE(addr, Size); + xbox::PFN_COUNT PTtoCommit = 0; + xbox::PageType BusyType = xbox::SystemPageTableType; VAddr StartingAddr = addr; assert(Size); @@ -677,7 +677,7 @@ bool PhysicalMemory::AllocatePT(size_t Size, VAddr addr) return false; } - if (addr <= HIGHEST_USER_ADDRESS) { BusyType = VirtualPageTableType; } + if (addr <= HIGHEST_USER_ADDRESS) { BusyType = xbox::VirtualPageTableType; } StartingAddr = addr; // Now actually commit the PT's. Note that we won't construct the vma's for the PTs since they are outside of all @@ -705,9 +705,9 @@ bool PhysicalMemory::AllocatePT(size_t Size, VAddr addr) void PhysicalMemory::DeallocatePT(size_t Size, VAddr addr) { - PMMPTE pPde; + xbox::PMMPTE pPde; PXBOX_PFN PTpfn; - PFN_COUNT PdeNumber = PAGES_SPANNED_LARGE(addr, Size); + xbox::PFN_COUNT PdeNumber = PAGES_SPANNED_LARGE(addr, Size); VAddr StartingAddr = addr; assert(Size); @@ -721,14 +721,14 @@ void PhysicalMemory::DeallocatePT(size_t Size, VAddr addr) if (PTpfn->PTPageFrame.PtesUsed == 0) { InsertFree(pPde->Hardware.PFN, pPde->Hardware.PFN); - WritePfn(pPde->Hardware.PFN, pPde->Hardware.PFN, pPde, (PageType)PTpfn->PTPageFrame.BusyType, true); + WritePfn(pPde->Hardware.PFN, pPde->Hardware.PFN, pPde, (xbox::PageType)PTpfn->PTPageFrame.BusyType, true); WRITE_ZERO_PTE(pPde); } StartingAddr += LARGE_PAGE_SIZE; } } -bool PhysicalMemory::IsMappable(PFN_COUNT PagesRequested, bool bRetailRegion, bool bDebugRegion) +bool PhysicalMemory::IsMappable(xbox::PFN_COUNT PagesRequested, bool bRetailRegion, bool bDebugRegion) { bool ret = false; if (bRetailRegion && m_PhysicalPagesAvailable >= PagesRequested) { ret = true; } @@ -738,12 +738,12 @@ bool PhysicalMemory::IsMappable(PFN_COUNT PagesRequested, bool bRetailRegion, bo return ret; } -PXBOX_PFN PhysicalMemory::GetPfnOfPT(PMMPTE pPte) +PXBOX_PFN PhysicalMemory::GetPfnOfPT(xbox::PMMPTE pPte) { PXBOX_PFN PTpfn; // GetPteAddress on a pte address will yield the corresponding pde which maps the supplied pte - PMMPTE PointerPde = GetPteAddress(pPte); + xbox::PMMPTE PointerPde = GetPteAddress(pPte); // PointerPde should have already been written to by AllocatePT assert(PointerPde->Hardware.Valid != 0); if (m_MmLayoutRetail || m_MmLayoutDebug) { @@ -751,8 +751,8 @@ PXBOX_PFN PhysicalMemory::GetPfnOfPT(PMMPTE pPte) } else { PTpfn = CHIHIRO_PFN_ELEMENT(PointerPde->Hardware.PFN); } assert(PTpfn->PTPageFrame.Busy == 1); - assert(PTpfn->PTPageFrame.BusyType == SystemPageTableType || - PTpfn->PTPageFrame.BusyType == VirtualPageTableType); + assert(PTpfn->PTPageFrame.BusyType == xbox::SystemPageTableType || + PTpfn->PTPageFrame.BusyType == xbox::VirtualPageTableType); return PTpfn; } diff --git a/src/core/kernel/memory-manager/PhysicalMemory.h b/src/core/kernel/memory-manager/PhysicalMemory.h index e952f293f..b0a40f95b 100644 --- a/src/core/kernel/memory-manager/PhysicalMemory.h +++ b/src/core/kernel/memory-manager/PhysicalMemory.h @@ -40,84 +40,37 @@ typedef uintptr_t VAddr; typedef uintptr_t PAddr; typedef uint32_t u32; -typedef unsigned int PFN; -typedef unsigned int PFN_COUNT; /* An entry of the list tracking the free pages on the system */ typedef struct _FreeBlock { - PFN start; // starting page of the block - PFN_COUNT size; // number of pages in the block + xbox::PFN start; // starting page of the block + xbox::PFN_COUNT size; // number of pages in the block xbox::LIST_ENTRY ListEntry; }FreeBlock, *PFreeBlock; -/* The Xbox PTE, modelled around the Intel 386 PTE specification */ -typedef struct _XBOX_PTE -{ - ULONG Valid : 1; - ULONG Write : 1; - ULONG Owner : 1; - ULONG WriteThrough : 1; - ULONG CacheDisable : 1; - ULONG Accessed : 1; - ULONG Dirty : 1; - ULONG LargePage : 1; - ULONG Global : 1; - ULONG GuardOrEnd : 1; // software field used for our own purposes - ULONG Persist : 1; // software field used for our own purposes - ULONG Unused : 1; // software field used for our own purposes - ULONG PFN : 20; -} XBOX_PTE, *PXBOX_PTE; - - -/* PTE as used by the memory manager */ -typedef union _MMPTE -{ - ULONG Default; - XBOX_PTE Hardware; -}MMPTE, *PMMPTE; - - /* PFN entry used by the memory manager */ typedef union _XBOX_PFN { - ULONG Default; + xbox::ulong_xt Default; struct { - ULONG LockCount : 16; // Set to prevent page relocation. Used by MmLockUnlockPhysicalPage and others - ULONG Busy : 1; // If set, PFN is in use - ULONG Unused : 1; - ULONG PteIndex : 10; // Offset in the PT that maps the pte (it seems to be needed only for page relocations) - ULONG BusyType : 4; // What the page is used for + xbox::ulong_xt LockCount : 16; // Set to prevent page relocation. Used by MmLockUnlockPhysicalPage and others + xbox::ulong_xt Busy : 1; // If set, PFN is in use + xbox::ulong_xt Unused : 1; + xbox::ulong_xt PteIndex : 10; // Offset in the PT that maps the pte (it seems to be needed only for page relocations) + xbox::ulong_xt BusyType : 4; // What the page is used for } Busy; struct { - ULONG LockCount : 16; // Set to prevent page relocation. Used by MmLockUnlockPhysicalPage and others - ULONG Busy : 1; // If set, PFN is in use - ULONG PtesUsed : 11; // Number of used pte's in the PT pointed by the pde - ULONG BusyType : 4; // What the page is used for (must be VirtualPageTableType or SystemPageTableType) + xbox::ulong_xt LockCount : 16; // Set to prevent page relocation. Used by MmLockUnlockPhysicalPage and others + xbox::ulong_xt Busy : 1; // If set, PFN is in use + xbox::ulong_xt PtesUsed : 11; // Number of used pte's in the PT pointed by the pde + xbox::ulong_xt BusyType : 4; // What the page is used for (must be VirtualPageTableType or SystemPageTableType) } PTPageFrame; }XBOX_PFN, *PXBOX_PFN; -/* enum describing the usage type of the memory pages */ -typedef enum _PageType -{ - UnknownType, // Used by the PFN database - StackType, // Used by MmCreateKernelStack - VirtualPageTableType, // Used by the pages holding the PTs that map the user memory (lower 2 GiB) - SystemPageTableType, // Used by the pages holding the PTs that map the system memory - PoolType, // Used by ExAllocatePoolWithTag - VirtualMemoryType, // Used by NtAllocateVirtualMemory - SystemMemoryType, // Used by MmAllocateSystemMemory - ImageType, // Used to mark executable memory - CacheType, // Used by the file cache related functions - ContiguousType, // Used by MmAllocateContiguousMemoryEx and others - DebuggerType, // xbdm-related - COUNTtype // The size of the array containing the page usage per type -}PageType; - - /* enum describing the memory layouts the memory manager can use */ typedef enum _MmLayout { @@ -155,8 +108,8 @@ typedef enum _MmLayout /* Various macros to manipulate PDE/PTE/PFN */ -#define GetPdeAddress(Va) ((PMMPTE)(((((ULONG)(Va)) >> 22) << 2) + PAGE_DIRECTORY_BASE)) // (Va/4M) * 4 + PDE_BASE -#define GetPteAddress(Va) ((PMMPTE)(((((ULONG)(Va)) >> 12) << 2) + PAGE_TABLES_BASE)) // (Va/4K) * 4 + PTE_BASE +#define GetPdeAddress(Va) ((xbox::PMMPTE)(((((ULONG)(Va)) >> 22) << 2) + PAGE_DIRECTORY_BASE)) // (Va/4M) * 4 + PDE_BASE +#define GetPteAddress(Va) ((xbox::PMMPTE)(((((ULONG)(Va)) >> 12) << 2) + PAGE_TABLES_BASE)) // (Va/4K) * 4 + PTE_BASE #define GetVAddrMappedByPte(Pte) ((VAddr)((ULONG_PTR)(Pte) << 10)) #define GetPteOffset(Va) ((((ULONG)(Va)) << 10) >> 22) #define IsPteOnPdeBoundary(Pte) (((ULONG_PTR)(Pte) & (PAGE_SIZE - 1)) == 0) @@ -201,15 +154,15 @@ class PhysicalMemory // highest pfn available for contiguous allocations PAddr m_MaxContiguousPfn = XBOX_CONTIGUOUS_MEMORY_LIMIT; // amount of free physical pages available for non-debugger usage - PFN_COUNT m_PhysicalPagesAvailable = X64M_PHYSICAL_PAGE; + xbox::PFN_COUNT m_PhysicalPagesAvailable = X64M_PHYSICAL_PAGE; // amount of free physical pages available for usage by the debugger (devkit only) - PFN_COUNT m_DebuggerPagesAvailable = 0; + xbox::PFN_COUNT m_DebuggerPagesAvailable = 0; // array containing the number of pages in use per type - PFN_COUNT m_PagesByUsage[COUNTtype] = { 0 }; + xbox::PFN_COUNT m_PagesByUsage[xbox::COUNTtype] = { 0 }; // highest page on the system - PFN m_HighestPage = XBOX_HIGHEST_PHYSICAL_PAGE; + xbox::PFN m_HighestPage = XBOX_HIGHEST_PHYSICAL_PAGE; // first page of the nv2a instance memory - PFN m_NV2AInstancePage = XBOX_INSTANCE_PHYSICAL_PAGE; + xbox::PFN m_NV2AInstancePage = XBOX_INSTANCE_PHYSICAL_PAGE; // number of allocated bytes for the nv2a instance memory size_t m_NV2AInstanceMemoryBytes = NV2A_INSTANCE_PAGE_COUNT << PAGE_SHIFT; // boolean that indicates that the extra 64 MiB on a devkit can be used for heap/Nt allocations @@ -227,19 +180,19 @@ class PhysicalMemory // set up the page directory void InitializePageDirectory(); // write a contiguous range of pfn's - void WritePfn(PFN pfn_start, PFN pfn_end, PMMPTE pPte, PageType BusyType, bool bZero = false); + void WritePfn(xbox::PFN pfn_start, xbox::PFN pfn_end, xbox::PMMPTE pPte, xbox::PageType BusyType, bool bZero = false); // write a contiguous range of pte's - void WritePte(PMMPTE pPteStart, PMMPTE pPteEnd, MMPTE Pte, PFN pfn, bool bZero = false); + void WritePte(xbox::PMMPTE pPteStart, xbox::PMMPTE pPteEnd, xbox::MMPTE Pte, xbox::PFN pfn, bool bZero = false); // retrieves the pfn entry which maps a PT - PXBOX_PFN GetPfnOfPT(PMMPTE pPte); + PXBOX_PFN GetPfnOfPT(xbox::PMMPTE pPte); // commit a contiguous number of pages - bool RemoveFree(PFN_COUNT NumberOfPages, PFN* result, PFN_COUNT PfnAlignment, PFN start, PFN end); + bool RemoveFree(xbox::PFN_COUNT NumberOfPages, xbox::PFN* result, xbox::PFN_COUNT PfnAlignment, xbox::PFN start, xbox::PFN end); // release a contiguous number of pages - void InsertFree(PFN start, PFN end); + void InsertFree(xbox::PFN start, xbox::PFN end); // convert from Xbox to the desired system pte protection (if possible) and return it - bool ConvertXboxToSystemPtePermissions(DWORD perms, PMMPTE pPte); + bool ConvertXboxToSystemPtePermissions(DWORD perms, xbox::PMMPTE pPte); // convert from Xbox to non-system pte protection (if possible) and return it - bool ConvertXboxToPtePermissions(DWORD perms, PMMPTE pPte); + bool ConvertXboxToPtePermissions(DWORD perms, xbox::PMMPTE pPte); // convert from pte permissions to the corresponding Xbox protection code DWORD ConvertPteToXboxPermissions(ULONG PteMask); // convert from Xbox to Windows permissions @@ -251,7 +204,7 @@ class PhysicalMemory // deallocate page tables (if possible) void DeallocatePT(size_t Size, VAddr addr); // checks if enough free pages are available for the allocation (doesn't account for fragmentation) - bool IsMappable(PFN_COUNT PagesRequested, bool bRetailRegion, bool bDebugRegion); + bool IsMappable(xbox::PFN_COUNT PagesRequested, bool bRetailRegion, bool bDebugRegion); }; #endif diff --git a/src/core/kernel/memory-manager/PoolManager.cpp b/src/core/kernel/memory-manager/PoolManager.cpp index b64eb6fee..e0c727843 100644 --- a/src/core/kernel/memory-manager/PoolManager.cpp +++ b/src/core/kernel/memory-manager/PoolManager.cpp @@ -95,7 +95,7 @@ VAddr PoolManager::AllocatePool(size_t Size, uint32_t Tag) Lock(); PoolDesc->RunningAllocs += 1; - Entry = reinterpret_cast(g_VMManager.AllocateSystemMemory(PoolType, XBOX_PAGE_READWRITE, Size, false)); + Entry = reinterpret_cast(g_VMManager.AllocateSystemMemory(xbox::PoolType, XBOX_PAGE_READWRITE, Size, false)); if (Entry != nullptr) { NumberOfPages = ROUND_UP_4K(Size) >> PAGE_SHIFT; @@ -202,7 +202,7 @@ VAddr PoolManager::AllocatePool(size_t Size, uint32_t Tag) // The current pool descriptor is exhausted, so we ask the VMManager to allocate a page to create a new one - Entry = reinterpret_cast(g_VMManager.AllocateSystemMemory(PoolType, XBOX_PAGE_READWRITE, PAGE_SIZE, false)); + Entry = reinterpret_cast(g_VMManager.AllocateSystemMemory(xbox::PoolType, XBOX_PAGE_READWRITE, PAGE_SIZE, false)); if (Entry == nullptr) { EmuLog(LOG_LEVEL::WARNING, "AllocatePool returns nullptr"); @@ -245,7 +245,7 @@ void PoolManager::DeallocatePool(VAddr addr) PoolDesc->RunningDeAllocs += 1; - BigPages = g_VMManager.DeallocateSystemMemory(PoolType, addr, 0); + BigPages = g_VMManager.DeallocateSystemMemory(xbox::PoolType, addr, 0); PoolDesc->TotalBigPages -= BigPages; @@ -306,7 +306,7 @@ void PoolManager::DeallocatePool(VAddr addr) if (CHECK_ALIGNMENT(reinterpret_cast(Entry), PAGE_SIZE) && (PAGE_END(reinterpret_cast(Entry) + Entry->BlockSize) != false)) { - g_VMManager.DeallocateSystemMemory(PoolType, reinterpret_cast(Entry), 0); + g_VMManager.DeallocateSystemMemory(xbox::PoolType, reinterpret_cast(Entry), 0); PoolDesc->TotalPages -= 1; } diff --git a/src/core/kernel/memory-manager/VMManager.cpp b/src/core/kernel/memory-manager/VMManager.cpp index 308d33db0..cf5979666 100644 --- a/src/core/kernel/memory-manager/VMManager.cpp +++ b/src/core/kernel/memory-manager/VMManager.cpp @@ -207,10 +207,10 @@ void VMManager::DestroyMemoryRegions() void VMManager::InitializeSystemAllocations() { - PFN pfn; - PFN pfn_end; - PMMPTE PointerPte; - PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN pfn_end; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; VAddr addr; @@ -248,7 +248,7 @@ void VMManager::InitializeSystemAllocations() } addr = (VAddr)CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(pfn); - AllocateContiguousMemoryInternal(pfn_end - pfn + 1, pfn, pfn_end, 1, XBOX_PAGE_READWRITE, UnknownType); + AllocateContiguousMemoryInternal(pfn_end - pfn + 1, pfn, pfn_end, 1, XBOX_PAGE_READWRITE, xbox::UnknownType); PersistMemory(addr, (pfn_end - pfn + 1) << PAGE_SHIFT, true); if (m_MmLayoutDebug) { m_PhysicalPagesAvailable += 16; m_DebuggerPagesAvailable -= 16; } @@ -328,8 +328,8 @@ void VMManager::RestorePersistentMemory() EmuLog(LOG_LEVEL::INFO, "Restored Framebuffer\n"); } - MMPTE pte; - PFN pfn; + xbox::MMPTE pte; + xbox::PFN pfn; size_t pfn_num_pages; uint32_t *pfn_addr; if (m_MmLayoutRetail) { @@ -348,7 +348,7 @@ void VMManager::RestorePersistentMemory() for (unsigned int i = 0; i < persisted_mem->NumOfPtes; i++) { pte.Default = persisted_mem->Data[persisted_mem->NumOfPtes + i]; assert(pte.Hardware.Valid != 0 && pte.Hardware.Persist != 0); - memcpy(GetPteAddress(persisted_mem->Data[i]), &pte.Default, sizeof(MMPTE)); + memcpy(GetPteAddress(persisted_mem->Data[i]), &pte.Default, sizeof(xbox::MMPTE)); RemoveFree(1, &pfn, 0, pte.Hardware.PFN, pte.Hardware.PFN); PXBOX_PFN temp_pfn = &((PXBOX_PFN)&persisted_mem->Data[(persisted_mem->NumOfPtes * 2) + (persisted_mem->NumOfPtes - pfn_num_pages) * KiB(1)])[pte.Hardware.PFN]; m_PagesByUsage[temp_pfn->Busy.BusyType]++; @@ -365,7 +365,7 @@ void VMManager::RestorePersistentMemory() } } - PFN_COUNT pages_num = 1; + xbox::PFN_COUNT pages_num = 1; for (unsigned int i = 0; i < persisted_mem->NumOfPtes; i++) { pte.Default = persisted_mem->Data[persisted_mem->NumOfPtes + i]; if (pte.Hardware.GuardOrEnd == 0) { @@ -382,7 +382,7 @@ void VMManager::RestorePersistentMemory() if (m_MmLayoutDebug) { m_PhysicalPagesAvailable += 16; m_DebuggerPagesAvailable -= 16; } - PFN pfn_end; + xbox::PFN pfn_end; if (m_MmLayoutRetail || m_MmLayoutDebug) { pfn = XBOX_INSTANCE_PHYSICAL_PAGE; pfn_end = XBOX_INSTANCE_PHYSICAL_PAGE + NV2A_INSTANCE_PAGE_COUNT - 1; @@ -392,8 +392,8 @@ void VMManager::RestorePersistentMemory() pfn_end = CHIHIRO_INSTANCE_PHYSICAL_PAGE + NV2A_INSTANCE_PAGE_COUNT - 1; } VAddr addr = (VAddr)CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(pfn); - PMMPTE PointerPte = GetPteAddress(addr); - PMMPTE EndingPte = GetPteAddress(CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(pfn_end)); + xbox::PMMPTE PointerPte = GetPteAddress(addr); + xbox::PMMPTE EndingPte = GetPteAddress(CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(pfn_end)); AllocateContiguousMemoryInternal(pfn_end - pfn + 1, pfn, pfn_end, 1, XBOX_PAGE_READWRITE); while (PointerPte <= EndingPte) { @@ -427,10 +427,10 @@ void VMManager::SavePersistentMemory() { PersistedMemory* persisted_mem; size_t num_persisted_ptes; - std::vector cached_persisted_ptes; + std::vector cached_persisted_ptes; LPVOID addr; - PMMPTE PointerPte; - PMMPTE EndingPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; int i; Lock(); @@ -493,7 +493,7 @@ void VMManager::SavePersistentMemory() Unlock(); } -VAddr VMManager::DbgTestPte(VAddr addr, PMMPTE Pte, bool bWriteCheck) +VAddr VMManager::DbgTestPte(VAddr addr, xbox::PMMPTE Pte, bool bWriteCheck) { LOG_FUNC_BEGIN LOG_FUNC_ARG(addr) @@ -501,7 +501,7 @@ VAddr VMManager::DbgTestPte(VAddr addr, PMMPTE Pte, bool bWriteCheck) LOG_FUNC_ARG(bWriteCheck) LOG_FUNC_END; - PMMPTE PointerPte; + xbox::PMMPTE PointerPte; VAddr ret = 0; Lock(); @@ -516,7 +516,7 @@ VAddr VMManager::DbgTestPte(VAddr addr, PMMPTE Pte, bool bWriteCheck) if (PointerPte->Hardware.Write == 0) { - MMPTE TempPte = *PointerPte; + xbox::MMPTE TempPte = *PointerPte; *Pte = TempPte; TempPte.Hardware.Write = 1; WRITE_PTE(PointerPte, TempPte); @@ -538,7 +538,7 @@ VAddr VMManager::DbgTestPte(VAddr addr, PMMPTE Pte, bool bWriteCheck) RETURN(ret); } -PFN_COUNT VMManager::QueryNumberOfFreeDebuggerPages() +xbox::PFN_COUNT VMManager::QueryNumberOfFreeDebuggerPages() { return m_DebuggerPagesAvailable; } @@ -550,13 +550,13 @@ void VMManager::MemoryStatistics(xbox::PMM_STATISTICS memory_statistics) memory_statistics->TotalPhysicalPages = g_SystemMaxMemory >> PAGE_SHIFT; memory_statistics->AvailablePages = m_MmLayoutDebug && m_bAllowNonDebuggerOnTop64MiB ? m_PhysicalPagesAvailable + m_DebuggerPagesAvailable : m_PhysicalPagesAvailable; - memory_statistics->VirtualMemoryBytesCommitted = (m_PagesByUsage[VirtualMemoryType] + - m_PagesByUsage[ImageType]) << PAGE_SHIFT; + memory_statistics->VirtualMemoryBytesCommitted = (m_PagesByUsage[xbox::VirtualMemoryType] + + m_PagesByUsage[xbox::ImageType]) << PAGE_SHIFT; memory_statistics->VirtualMemoryBytesReserved = m_VirtualMemoryBytesReserved; - memory_statistics->CachePagesCommitted = m_PagesByUsage[CacheType]; - memory_statistics->PoolPagesCommitted = m_PagesByUsage[PoolType]; - memory_statistics->StackPagesCommitted = m_PagesByUsage[StackType]; - memory_statistics->ImagePagesCommitted = m_PagesByUsage[ImageType]; + memory_statistics->CachePagesCommitted = m_PagesByUsage[xbox::CacheType]; + memory_statistics->PoolPagesCommitted = m_PagesByUsage[xbox::PoolType]; + memory_statistics->StackPagesCommitted = m_PagesByUsage[xbox::StackType]; + memory_statistics->ImagePagesCommitted = m_PagesByUsage[xbox::ImageType]; Unlock(); } @@ -579,10 +579,10 @@ VAddr VMManager::ClaimGpuMemory(size_t Size, size_t* BytesToSkip) if (Size != MAXULONG_PTR) { - PFN pfn; - PFN EndingPfn; - PMMPTE PointerPte; - PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN EndingPfn; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; // Actually deallocate the requested number of instance pages. Note that we can't just call DeallocateContiguous // since that function will always deallocate the entire original allocation @@ -601,7 +601,7 @@ VAddr VMManager::ClaimGpuMemory(size_t Size, size_t* BytesToSkip) EndingPte = GetPteAddress(CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(EndingPfn)); WritePte(PointerPte, EndingPte, *PointerPte, 0, true); - WritePfn(pfn, EndingPfn, PointerPte, ContiguousType, true); + WritePfn(pfn, EndingPfn, PointerPte, xbox::ContiguousType, true); InsertFree(pfn, EndingPfn); DestructVMA((VAddr)CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(pfn), ContiguousRegion, m_NV2AInstanceMemoryBytes - Size); @@ -616,7 +616,7 @@ VAddr VMManager::ClaimGpuMemory(size_t Size, size_t* BytesToSkip) EndingPte = GetPteAddress(CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(EndingPfn)); WritePte(PointerPte, EndingPte, *PointerPte, 0, true); - WritePfn(pfn, EndingPfn, PointerPte, ContiguousType, true); + WritePfn(pfn, EndingPfn, PointerPte, xbox::ContiguousType, true); InsertFree(pfn, EndingPfn); DestructVMA((VAddr)CONVERT_PFN_TO_CONTIGUOUS_PHYSICAL(pfn), ContiguousRegion, m_NV2AInstanceMemoryBytes - Size); } @@ -639,8 +639,8 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist) LOG_FUNC_ARG(bPersist) LOG_FUNC_END; - PMMPTE PointerPte; - PMMPTE EndingPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; assert(IS_PHYSICAL_ADDRESS(addr)); // only contiguous memory can be made persistent @@ -667,7 +667,7 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist) Unlock(); } -VAddr VMManager::AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Size, bool bAddGuardPage) +VAddr VMManager::AllocateSystemMemory(xbox::PageType BusyType, DWORD Perms, size_t Size, bool bAddGuardPage) { LOG_FUNC_BEGIN LOG_FUNC_ARG(BusyType) @@ -676,14 +676,14 @@ VAddr VMManager::AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Siz LOG_FUNC_ARG(bAddGuardPage) LOG_FUNC_END; - MMPTE TempPte; - PMMPTE PointerPte; - PMMPTE EndingPte; - PFN pfn; - PFN LowestAcceptablePfn; - PFN HighestAcceptablePfn; - PFN_COUNT PteNumber; - PFN_COUNT PagesNumber; + xbox::MMPTE TempPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN LowestAcceptablePfn; + xbox::PFN HighestAcceptablePfn; + xbox::PFN_COUNT PteNumber; + xbox::PFN_COUNT PagesNumber; VAddr addr; MemoryRegionType MemoryType; @@ -702,7 +702,7 @@ VAddr VMManager::AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Siz PagesNumber = PteNumber; if (bAddGuardPage) { PteNumber++; } - if (BusyType == DebuggerType) + if (BusyType == xbox::DebuggerType) { // Debugger pages are only allocated from the extra 64 MiB available on devkits and are mapped in the // devkit system region @@ -770,10 +770,10 @@ VAddr VMManager::AllocateContiguousMemory(size_t Size, PAddr LowestAddress, PAdd LOG_FUNC_ARG(Perms) LOG_FUNC_END; - PFN PfnAlignment; - PFN LowestPfn; - PFN HighestPfn; - PFN_COUNT PteNumber; + xbox::PFN PfnAlignment; + xbox::PFN LowestPfn; + xbox::PFN HighestPfn; + xbox::PFN_COUNT PteNumber; VAddr Addr; if (!Size) { RETURN(NULL); } @@ -801,13 +801,13 @@ VAddr VMManager::AllocateContiguousMemory(size_t Size, PAddr LowestAddress, PAdd RETURN(Addr); } -VAddr VMManager::AllocateContiguousMemoryInternal(PFN_COUNT NumberOfPages, PFN LowestPfn, PFN HighestPfn, PFN PfnAlignment, DWORD Perms, PageType BusyType) +VAddr VMManager::AllocateContiguousMemoryInternal(xbox::PFN_COUNT NumberOfPages, xbox::PFN LowestPfn, xbox::PFN HighestPfn, xbox::PFN PfnAlignment, DWORD Perms, xbox::PageType BusyType) { - MMPTE TempPte; - PMMPTE PointerPte; - PMMPTE EndingPte; - PFN pfn; - PFN EndingPfn; + xbox::MMPTE TempPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN EndingPfn; VAddr addr; if (!ConvertXboxToSystemPtePermissions(Perms, &TempPte)) { goto Fail; } @@ -850,11 +850,11 @@ VAddr VMManager::MapDeviceMemory(PAddr Paddr, size_t Size, DWORD Perms) LOG_FUNC_ARG(Perms) LOG_FUNC_END; - MMPTE TempPte; - PMMPTE PointerPte; - PMMPTE EndingPte; - PFN pfn; - PFN_COUNT PteNumber; + xbox::MMPTE TempPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN_COUNT PteNumber; VAddr addr; if (!Size || !ConvertXboxToSystemPtePermissions(Perms, &TempPte)) { RETURN(NULL); } @@ -908,10 +908,10 @@ void VMManager::DeallocateContiguousMemory(VAddr addr) LOG_FUNC_ARG(addr) LOG_FUNC_END; - PMMPTE StartingPte; - PMMPTE EndingPte; - PFN pfn; - PFN EndingPfn; + xbox::PMMPTE StartingPte; + xbox::PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN EndingPfn; VMAIter it; bool bOverflow; @@ -935,7 +935,7 @@ void VMManager::DeallocateContiguousMemory(VAddr addr) EndingPfn = pfn + (EndingPte - StartingPte); InsertFree(pfn, EndingPfn); - WritePfn(pfn, EndingPfn, StartingPte, ContiguousType, true); + WritePfn(pfn, EndingPfn, StartingPte, xbox::ContiguousType, true); WritePte(StartingPte, EndingPte, *StartingPte, 0, true); DestructVMA(it->first, ContiguousRegion, it->second.size); DeallocatePT((EndingPte - StartingPte + 1) << PAGE_SHIFT, addr); @@ -943,18 +943,18 @@ void VMManager::DeallocateContiguousMemory(VAddr addr) Unlock(); } -PFN_COUNT VMManager::DeallocateSystemMemory(PageType BusyType, VAddr addr, size_t Size) +xbox::PFN_COUNT VMManager::DeallocateSystemMemory(xbox::PageType BusyType, VAddr addr, size_t Size) { LOG_FUNC_BEGIN LOG_FUNC_ARG(addr) LOG_FUNC_ARG(Size) LOG_FUNC_END; - PMMPTE PointerPte; - PMMPTE StartingPte; - PMMPTE EndingPte; - PFN pfn; - PFN_COUNT PteNumber; + xbox::PMMPTE PointerPte; + xbox::PMMPTE StartingPte; + xbox::PMMPTE EndingPte; + xbox::PFN pfn; + xbox::PFN_COUNT PteNumber; VMAIter it; MemoryRegionType MemoryType = SystemRegion; bool bGuardPageAdded = false; @@ -964,7 +964,7 @@ PFN_COUNT VMManager::DeallocateSystemMemory(PageType BusyType, VAddr addr, size_ Lock(); - if (BusyType == DebuggerType) + if (BusyType == xbox::DebuggerType) { assert(IS_DEVKIT_ADDRESS(addr)); MemoryType = DevkitRegion; @@ -1005,7 +1005,7 @@ PFN_COUNT VMManager::DeallocateSystemMemory(PageType BusyType, VAddr addr, size_ } WritePte(StartingPte, EndingPte, *StartingPte, 0, true); - DestructVMA(BusyType == DebuggerType ? addr : it->first, MemoryType, bGuardPageAdded ? Size + PAGE_SIZE : Size); + DestructVMA(BusyType == xbox::DebuggerType ? addr : it->first, MemoryType, bGuardPageAdded ? Size + PAGE_SIZE : Size); DeallocatePT(bGuardPageAdded ? Size + PAGE_SIZE : Size, addr); Unlock(); @@ -1023,9 +1023,9 @@ void VMManager::UnmapDeviceMemory(VAddr addr, size_t Size) { // The allocation is inside the system region, so it must have been mapped by us. Unmap it - PMMPTE StartingPte; - PMMPTE EndingPte; - PFN_COUNT PteNumber; + xbox::PMMPTE StartingPte; + xbox::PMMPTE EndingPte; + xbox::PFN_COUNT PteNumber; VMAIter it; bool bOverflow; @@ -1065,10 +1065,10 @@ void VMManager::Protect(VAddr addr, size_t Size, DWORD NewPerms) LOG_FUNC_ARG(NewPerms) LOG_FUNC_END; - MMPTE TempPte; - MMPTE NewPermsPte; - PMMPTE PointerPte; - PMMPTE EndingPte; + xbox::MMPTE TempPte; + xbox::MMPTE NewPermsPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; assert(IS_PHYSICAL_ADDRESS(addr) || IS_SYSTEM_ADDRESS(addr)); @@ -1102,8 +1102,8 @@ DWORD VMManager::QueryProtection(VAddr addr) { LOG_FUNC_ONE_ARG(addr); - PMMPTE PointerPte; - MMPTE TempPte; + xbox::PMMPTE PointerPte; + xbox::MMPTE TempPte; DWORD Protect; // This function can query any virtual address, even invalid ones, so we won't do any vma checks here @@ -1148,8 +1148,8 @@ size_t VMManager::QuerySize(VAddr addr, bool bCxbxCaller) { LOG_FUNC_ONE_ARG(addr); - PMMPTE PointerPte; - PFN_COUNT PagesNumber; + xbox::PMMPTE PointerPte; + xbox::PFN_COUNT PagesNumber; size_t Size = 0; Lock(); @@ -1211,9 +1211,9 @@ void VMManager::LockBufferOrSinglePage(PAddr paddr, VAddr addr, size_t Size, boo LOG_FUNC_ARG(bUnLock) LOG_FUNC_END; - PMMPTE PointerPte; - PMMPTE EndingPte; - PFN pfn; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PFN pfn; PXBOX_PFN PfnEntry; ULONG LockUnit; @@ -1257,7 +1257,7 @@ void VMManager::LockBufferOrSinglePage(PAddr paddr, VAddr addr, size_t Size, boo } else { PfnEntry = CHIHIRO_PFN_ELEMENT(pfn); } - if (PfnEntry->Busy.BusyType != ContiguousType && pfn <= m_HighestPage) + if (PfnEntry->Busy.BusyType != xbox::ContiguousType && pfn <= m_HighestPage) { LockUnit = bUnLock ? -LOCK_COUNT_UNIT : LOCK_COUNT_UNIT; @@ -1280,13 +1280,13 @@ xbox::ntstatus_xt VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBits LOG_FUNC_ARG(Protect) LOG_FUNC_END; - MMPTE TempPte; - PMMPTE PointerPte; - PMMPTE EndingPte; - PMMPTE StartingPte; - PFN_COUNT PteNumber = 0; - PFN TempPfn; - PageType BusyType; + xbox::MMPTE TempPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PMMPTE StartingPte; + xbox::PFN_COUNT PteNumber = 0; + xbox::PFN TempPfn; + xbox::PageType BusyType; xbox::ntstatus_xt status; VAddr CapturedBase = *addr; size_t CapturedSize = *Size; @@ -1484,7 +1484,7 @@ xbox::ntstatus_xt VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBits // With VirtualAlloc we grab one page at a time to avoid fragmentation issues BusyType = (Protect & (XBOX_PAGE_EXECUTE | XBOX_PAGE_EXECUTE_READ | XBOX_PAGE_EXECUTE_READWRITE - | XBOX_PAGE_EXECUTE_WRITECOPY)) ? ImageType : VirtualMemoryType; + | XBOX_PAGE_EXECUTE_WRITECOPY)) ? xbox::ImageType : xbox::VirtualMemoryType; PointerPte = StartingPte; while (PointerPte <= EndingPte) { @@ -1542,11 +1542,11 @@ xbox::ntstatus_xt VMManager::XbFreeVirtualMemory(VAddr* addr, size_t* Size, DWOR VAddr AlignedCapturedBase; size_t AlignedCapturedSize; xbox::ntstatus_xt status; - PMMPTE PointerPte; - PMMPTE EndingPte; - PMMPTE StartingPte; - PFN TempPfn; - PageType BusyType; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PMMPTE StartingPte; + xbox::PFN TempPfn; + xbox::PageType BusyType; VMAIter it; bool bOverflow; @@ -1653,9 +1653,9 @@ xbox::ntstatus_xt VMManager::XbFreeVirtualMemory(VAddr* addr, size_t* Size, DWOR TempPfn = PointerPte->Hardware.PFN; InsertFree(TempPfn, TempPfn); if (m_MmLayoutRetail || m_MmLayoutDebug) { - BusyType = (PageType)(XBOX_PFN_ELEMENT(TempPfn)->Busy.BusyType); + BusyType = (xbox::PageType)(XBOX_PFN_ELEMENT(TempPfn)->Busy.BusyType); } - else { BusyType = (PageType)(CHIHIRO_PFN_ELEMENT(TempPfn)->Busy.BusyType); } + else { BusyType = (xbox::PageType)(CHIHIRO_PFN_ELEMENT(TempPfn)->Busy.BusyType); } WritePfn(TempPfn, TempPfn, PointerPte, BusyType, true); } @@ -1701,13 +1701,13 @@ xbox::ntstatus_xt VMManager::XbVirtualProtect(VAddr* addr, size_t* Size, DWORD* VAddr AlignedCapturedBase; size_t AlignedCapturedSize; xbox::ntstatus_xt status; - PMMPTE PointerPte; - PMMPTE EndingPte; - PMMPTE StartingPte; - PMMPTE PointerPde; - MMPTE TempPte; - MMPTE NewPermsPte; - MMPTE OldPermsPte; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PMMPTE StartingPte; + xbox::PMMPTE PointerPde; + xbox::MMPTE TempPte; + xbox::MMPTE NewPermsPte; + xbox::MMPTE OldPermsPte; VMAIter it; bool bOverflow; @@ -1808,10 +1808,10 @@ xbox::ntstatus_xt VMManager::XbVirtualProtect(VAddr* addr, size_t* Size, DWORD* xbox::ntstatus_xt VMManager::XbVirtualMemoryStatistics(VAddr addr, xbox::PMEMORY_BASIC_INFORMATION memory_statistics) { VMAIter it; - PMMPTE PointerPte; - PMMPTE EndingPte; - PMMPTE StartingPte; - PMMPTE PointerPde; + xbox::PMMPTE PointerPte; + xbox::PMMPTE EndingPte; + xbox::PMMPTE StartingPte; + xbox::PMMPTE PointerPde; DWORD CurrentProtect; DWORD InitialProtect; DWORD CurrentState; @@ -1904,7 +1904,7 @@ xbox::ntstatus_xt VMManager::XbVirtualMemoryStatistics(VAddr addr, xbox::PMEMORY if (CurrentState == XBOX_MEM_COMMIT) { break; } // Pde is invalid and we are looking for reserved memory, so skip this pde and keep searching if we are not at EndingPte yet - PointerPte = (PMMPTE)GetVAddrMappedByPte(PointerPde + 1); + PointerPte = (xbox::PMMPTE)GetVAddrMappedByPte(PointerPde + 1); continue; } } @@ -1945,7 +1945,7 @@ xbox::ntstatus_xt VMManager::XbVirtualMemoryStatistics(VAddr addr, xbox::PMEMORY return X_STATUS_SUCCESS; } -VAddr VMManager::MapMemoryBlock(MemoryRegionType Type, PFN_COUNT PteNumber, DWORD Permissions, bool b64Blocks, VAddr HighestAddress) +VAddr VMManager::MapMemoryBlock(MemoryRegionType Type, xbox::PFN_COUNT PteNumber, DWORD Permissions, bool b64Blocks, VAddr HighestAddress) { VAddr addr; VMAIter it = m_MemoryRegionArray[Type].LastFree; @@ -2101,7 +2101,7 @@ bool VMManager::IsValidVirtualAddress(const VAddr addr) { LOG_FUNC_ONE_ARG(addr); - PMMPTE PointerPte; + xbox::PMMPTE PointerPte; Lock(); @@ -2135,7 +2135,7 @@ PAddr VMManager::TranslateVAddrToPAddr(const VAddr addr) LOG_FUNC_ONE_ARG(addr); PAddr PAddr; - PMMPTE PointerPte; + xbox::PMMPTE PointerPte; // ergo720: horrendous hack, this identity maps all allocations done by the VMManager to keep the LLE USB working. // The problem is that if the user buffer pointed to by the TD is allocated by the VMManager with VirtualAlloc, then diff --git a/src/core/kernel/memory-manager/VMManager.h b/src/core/kernel/memory-manager/VMManager.h index d2206e1bb..94243f6b7 100644 --- a/src/core/kernel/memory-manager/VMManager.h +++ b/src/core/kernel/memory-manager/VMManager.h @@ -103,13 +103,13 @@ class VMManager : public PhysicalMemory // retrieves memory statistics void MemoryStatistics(xbox::PMM_STATISTICS memory_statistics); // allocates memory in the system region - VAddr AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Size, bool bAddGuardPage); + VAddr AllocateSystemMemory(xbox::PageType BusyType, DWORD Perms, size_t Size, bool bAddGuardPage); // allocates memory in the contiguous region VAddr AllocateContiguousMemory(size_t Size, PAddr LowestAddress, PAddr HighestAddress, ULONG Alignment, DWORD Perms); // maps device memory in the system region VAddr MapDeviceMemory(PAddr Paddr, size_t Size, DWORD Perms); // deallocates memory in the system region - PFN_COUNT DeallocateSystemMemory(PageType BusyType, VAddr addr, size_t Size); + xbox::PFN_COUNT DeallocateSystemMemory(xbox::PageType BusyType, VAddr addr, size_t Size); // deallocates memory in the contiguous region void DeallocateContiguousMemory(VAddr addr); // unmaps device memory in the system region @@ -131,9 +131,9 @@ class VMManager : public PhysicalMemory // make contiguous memory persist across a quick reboot void PersistMemory(VAddr addr, size_t Size, bool bPersist); // debug function to reset a pte or check if it is writable - VAddr DbgTestPte(VAddr addr, PMMPTE Pte, bool bWriteCheck); + VAddr DbgTestPte(VAddr addr, xbox::PMMPTE Pte, bool bWriteCheck); // retrieves the number of free debugger pages - PFN_COUNT QueryNumberOfFreeDebuggerPages(); + xbox::PFN_COUNT QueryNumberOfFreeDebuggerPages(); // xbox implementation of NtAllocateVirtualMemory xbox::ntstatus_xt XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBits, size_t* Size, DWORD AllocationType, DWORD Protect); // xbox implementation of NtFreeVirtualMemory @@ -161,7 +161,7 @@ class VMManager : public PhysicalMemory void* m_PersistentMemoryHandle = nullptr; // same as AllocateContiguousMemory, but it allows to allocate beyond m_MaxContiguousPfn - VAddr AllocateContiguousMemoryInternal(PFN_COUNT NumberOfPages, PFN LowestPfn, PFN HighestPfn, PFN PfnAlignment, DWORD Perms, PageType BusyType = ContiguousType); + VAddr AllocateContiguousMemoryInternal(xbox::PFN_COUNT NumberOfPages, xbox::PFN LowestPfn, xbox::PFN HighestPfn, xbox::PFN PfnAlignment, DWORD Perms, xbox::PageType BusyType = xbox::ContiguousType); // set up the system allocations void InitializeSystemAllocations(); // initializes a memory region struct @@ -169,7 +169,7 @@ class VMManager : public PhysicalMemory // clears all memory region structs void DestroyMemoryRegions(); // map a memory block with the supplied allocation routine - VAddr MapMemoryBlock(MemoryRegionType Type, PFN_COUNT PteNumber, DWORD Permissions, bool b64Blocks, VAddr HighestAddress = 0); + VAddr MapMemoryBlock(MemoryRegionType Type, xbox::PFN_COUNT PteNumber, DWORD Permissions, bool b64Blocks, VAddr HighestAddress = 0); // helper function which allocates user memory with VirtualAlloc VAddr MapHostMemory(VAddr StartingAddr, size_t Size, size_t VmaEnd, DWORD Permissions); // constructs a vma