Use RtlFillMemoryUlong in the VMManager instead of a standalone function
This commit is contained in:
parent
6cc5c565fb
commit
5734b0ec10
|
@ -494,7 +494,7 @@ XBSYSAPI EXPORTNUM(374) xboxkrnl::PVOID NTAPI xboxkrnl::MmDbgAllocateMemory
|
|||
assert(g_bIsDebug);
|
||||
|
||||
PVOID addr = (PVOID)g_VMManager.AllocateSystemMemory(DebuggerType, Protect, NumberOfBytes, false);
|
||||
if (addr) { FillMemoryUlong((void*)addr, ROUND_UP_4K(NumberOfBytes), 0); } // debugger pages are zeroed
|
||||
if (addr) { RtlFillMemoryUlong((void*)addr, ROUND_UP_4K(NumberOfBytes), 0); } // debugger pages are zeroed
|
||||
|
||||
RETURN(addr);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#define _XBOXKRNL_DEFEXTRN_
|
||||
|
||||
#define LOG_PREFIX "KRNL"
|
||||
#define CHECK_ALIGNMENT(size, alignment) (((size) % (alignment)) == 0) // For RtlFillMemoryUlong
|
||||
|
||||
// prevent name collisions
|
||||
namespace xboxkrnl
|
||||
|
@ -55,6 +56,7 @@ namespace NtDll
|
|||
|
||||
#include "CxbxKrnl.h" // For CxbxKrnlCleanup()
|
||||
#include "Emu.h" // For EmuWarning()
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
|
@ -969,14 +971,21 @@ XBSYSAPI EXPORTNUM(285) xboxkrnl::VOID NTAPI xboxkrnl::RtlFillMemoryUlong
|
|||
LOG_FUNC_ARG(Destination)
|
||||
LOG_FUNC_ARG(Length)
|
||||
LOG_FUNC_ARG(Pattern)
|
||||
LOG_FUNC_END;
|
||||
LOG_FUNC_END;
|
||||
|
||||
// Fill 32 bits at a time
|
||||
// Any extra bytes are ignored
|
||||
uint32_t numDwords = Length / sizeof(ULONG);
|
||||
uint32_t *lastAddr = (uint32_t *)Destination + numDwords;
|
||||
for (uint32_t *p = (uint32_t *)Destination; p < lastAddr; p++) {
|
||||
*p = Pattern;
|
||||
|
||||
assert(Length != 0);
|
||||
assert(CHECK_ALIGNMENT(Length, sizeof(ULONG))); // Length must be a multiple of ULONG
|
||||
assert(CHECK_ALIGNMENT((uintptr_t)Destination, sizeof(ULONG))); // Destination must be 4-byte aligned
|
||||
|
||||
int NumOfRepeats = Length / sizeof(ULONG);
|
||||
ULONG* d = (ULONG*)Destination;
|
||||
|
||||
for (int i = 0; i < NumOfRepeats; ++i)
|
||||
{
|
||||
d[i] = Pattern; // copy an ULONG at a time
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,21 +41,6 @@
|
|||
#include <assert.h>
|
||||
|
||||
|
||||
void FillMemoryUlong(void* Destination, size_t Length, ULONG Long)
|
||||
{
|
||||
assert(Length != 0);
|
||||
assert(CHECK_ALIGNMENT(Length, sizeof(ULONG))); // Length must be a multiple of ULONG
|
||||
assert(CHECK_ALIGNMENT((uintptr_t)Destination, sizeof(ULONG))); // Destination must be 4-byte aligned
|
||||
|
||||
int NumOfRepeats = Length / sizeof(ULONG);
|
||||
ULONG* d = (ULONG*)Destination;
|
||||
|
||||
for (int i = 0; i < NumOfRepeats; ++i)
|
||||
{
|
||||
d[i] = Long; // copy an ULONG at a time
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicalMemory::InitializePageDirectory()
|
||||
{
|
||||
PMMPTE pPde;
|
||||
|
|
|
@ -208,10 +208,6 @@ typedef enum _PageType
|
|||
#define IS_USER_ADDRESS(Va) (((VAddr)(Va) - LOWEST_USER_ADDRESS) <= (HIGHEST_USER_ADDRESS - LOWEST_USER_ADDRESS))
|
||||
|
||||
|
||||
/* Global helper function used to copy an ULONG block of memory to another buffer. It mimics RtlFillMemoryUlong */
|
||||
void FillMemoryUlong(void* Destination, size_t Length, ULONG Long);
|
||||
|
||||
|
||||
/* PhysicalMemory class */
|
||||
class PhysicalMemory
|
||||
{
|
||||
|
|
|
@ -136,7 +136,7 @@ dashboard from non-retail xbe?");
|
|||
|
||||
// Set up the pfn database
|
||||
if ((QuickReboot & BOOT_QUICK_REBOOT) == 0) {
|
||||
FillMemoryUlong((void*)PAGE_TABLES_BASE, PAGE_TABLES_SIZE, 0);
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)PAGE_TABLES_BASE, PAGE_TABLES_SIZE, 0);
|
||||
InitializePfnDatabase();
|
||||
}
|
||||
else {
|
||||
|
@ -213,13 +213,13 @@ void VMManager::InitializePfnDatabase()
|
|||
|
||||
// Zero all the entries of the PFN database
|
||||
if (g_bIsRetail) {
|
||||
FillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB, 0); // Xbox: 64 KiB
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB, 0); // Xbox: 64 KiB
|
||||
}
|
||||
else if (g_bIsChihiro) {
|
||||
FillMemoryUlong((void*)CHIHIRO_PFN_ADDRESS, X64KB * 2, 0); // Chihiro: 128 KiB
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)CHIHIRO_PFN_ADDRESS, X64KB * 2, 0); // Chihiro: 128 KiB
|
||||
}
|
||||
else {
|
||||
FillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB * 2, 0); // Debug: 128 KiB
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB * 2, 0); // Debug: 128 KiB
|
||||
}
|
||||
|
||||
|
||||
|
@ -692,18 +692,18 @@ void VMManager::RestorePersistentMemory()
|
|||
|
||||
// Zero all the remaining pte's
|
||||
EndingPte += 1;
|
||||
FillMemoryUlong((void*)PAGE_TABLES_BASE, (VAddr)GetPteAddress(CONTIGUOUS_MEMORY_BASE) - PAGE_TABLES_BASE, 0);
|
||||
FillMemoryUlong((void*)EndingPte, PAGE_TABLES_END + 1 - (VAddr)EndingPte, 0);
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)PAGE_TABLES_BASE, (VAddr)GetPteAddress(CONTIGUOUS_MEMORY_BASE) - PAGE_TABLES_BASE, 0);
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)EndingPte, PAGE_TABLES_END + 1 - (VAddr)EndingPte, 0);
|
||||
|
||||
// Zero all the entries of the PFN database
|
||||
if (g_bIsRetail) {
|
||||
FillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB, 0); // Xbox: 64 KiB
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB, 0); // Xbox: 64 KiB
|
||||
}
|
||||
else if (g_bIsChihiro) {
|
||||
FillMemoryUlong((void*)CHIHIRO_PFN_ADDRESS, X64KB * 2, 0); // Chihiro: 128 KiB
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)CHIHIRO_PFN_ADDRESS, X64KB * 2, 0); // Chihiro: 128 KiB
|
||||
}
|
||||
else {
|
||||
FillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB * 2, 0); // Debug: 128 KiB
|
||||
xboxkrnl::RtlFillMemoryUlong((void*)XBOX_PFN_ADDRESS, X64KB * 2, 0); // Debug: 128 KiB
|
||||
}
|
||||
|
||||
// Now we need to restore the launch data page and the frame buffer pointers to their correct values
|
||||
|
@ -844,7 +844,7 @@ VAddr VMManager::AllocateZeroed(size_t Size)
|
|||
LOG_FORWARD("g_VMManager.Allocate");
|
||||
|
||||
VAddr addr = Allocate(Size);
|
||||
if (addr) { FillMemoryUlong((void*)addr, ROUND_UP_4K(Size), 0); }
|
||||
if (addr) { xboxkrnl::RtlFillMemoryUlong((void*)addr, ROUND_UP_4K(Size), 0); }
|
||||
|
||||
RETURN(addr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue