Removed redundant allocate functions

This commit is contained in:
ergo720 2021-02-17 14:34:45 +01:00
parent 86788a558e
commit 1b2308f3e1
8 changed files with 25 additions and 140 deletions

View File

@ -1269,7 +1269,7 @@ int GetD3DResourceRefCount(IDirect3DResource *EmuResource)
/*
xbox::X_D3DSurface *EmuNewD3DSurface()
{
xbox::X_D3DSurface *result = (xbox::X_D3DSurface *)g_VMManager.AllocateZeroed(sizeof(xbox::X_D3DSurface));
xbox::X_D3DSurface *result = (xbox::X_D3DSurface *)xbox::ExAllocatePool(sizeof(xbox::X_D3DSurface));
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_SURFACE | 1; // Set refcount to 1
return result;
}

View File

@ -863,8 +863,8 @@ void CxbxImpl_End()
g_InlineVertexBuffer_DeclarationOverride = false;
// TODO: Should technically clean this up at some point..but on XP doesnt matter much
// g_VMManager.Deallocate((VAddr)g_InlineVertexBuffer_pData);
// g_VMManager.Deallocate((VAddr)g_InlineVertexBuffer_Table);
// ExFreePool(g_InlineVertexBuffer_pData);
// ExFreePool(g_InlineVertexBuffer_Table);
}
void CxbxImpl_SetVertexData4f(int Register, FLOAT a, FLOAT b, FLOAT c, FLOAT d)

View File

@ -34,7 +34,6 @@
#include "core\kernel\support\Emu.h"
#include "EmuShared.h"
#include "core\hle\XACTENG\XactEng.h"
#include "core\kernel\memory-manager\VMManager.h"
#include <mmreg.h>
#include <msacm.h>
@ -65,7 +64,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(XACTEngineCreate)
// TODO: Any other form of initialization?
*ppEngine = (X_XACTEngine*)g_VMManager.AllocateZeroed(sizeof( X_XACTEngine ));
*ppEngine = (X_XACTEngine*)ExAllocatePool(sizeof( X_XACTEngine ));
@ -109,7 +108,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IXACTEngine_RegisterWaveBank)
// TODO: Implement
*ppWaveBank = (X_XACTWaveBank*)g_VMManager.AllocateZeroed(sizeof( X_XACTWaveBank ));
*ppWaveBank = (X_XACTWaveBank*)ExAllocatePool(sizeof( X_XACTWaveBank ));
RETURN(S_OK);
}
@ -132,7 +131,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IXACTEngine_RegisterStreamedWaveBank)
// TODO: Implement
*ppWaveBank = (X_XACTWaveBank*)g_VMManager.AllocateZeroed(sizeof( X_XACTWaveBank ));
*ppWaveBank = (X_XACTWaveBank*)ExAllocatePool(sizeof( X_XACTWaveBank ));
RETURN(S_OK);
}
@ -157,7 +156,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IXACTEngine_CreateSoundBank)
// TODO: Implement
*ppSoundBank = (X_XACTSoundBank*)g_VMManager.AllocateZeroed(sizeof( X_XACTSoundBank ));
*ppSoundBank = (X_XACTSoundBank*)ExAllocatePool(sizeof( X_XACTSoundBank ));
RETURN(S_OK);
}
@ -203,7 +202,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IXACTEngine_CreateSoundSource)
LOG_FUNC_ARG(ppSoundSource)
LOG_FUNC_END;
*ppSoundSource = (X_XACTSoundSource*)g_VMManager.AllocateZeroed(sizeof( X_XACTSoundSource ));
*ppSoundSource = (X_XACTSoundSource*)ExAllocatePool(sizeof( X_XACTSoundSource ));
RETURN(S_OK);
}
@ -500,7 +499,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IXACTEngine_UnRegisterWaveBank)
// to IXACTWaveBank is released.
// if(pWaveBank)
// g_VMManager.Deallocate((VAddr)pWaveBank);
// ExFreePool(pWaveBank);
RETURN(S_OK);
}

View File

@ -1398,7 +1398,7 @@ __declspec(noreturn) void CxbxKrnlInit
// Assign the running Xbe path, so it can be accessed via the kernel thunk 'XeImageFileName' :
xbox::XeImageFileName.MaximumLength = MAX_PATH;
xbox::XeImageFileName.Buffer = (PCHAR)g_VMManager.Allocate(MAX_PATH);
xbox::XeImageFileName.Buffer = (PCHAR)xbox::ExAllocatePool(MAX_PATH);
sprintf(xbox::XeImageFileName.Buffer, "%c:\\%s", CxbxDefaultXbeDriveLetter, fileName.c_str());
xbox::XeImageFileName.Length = (USHORT)strlen(xbox::XeImageFileName.Buffer);
EmuLogInit(LOG_LEVEL::INFO, "XeImageFileName = %s", xbox::XeImageFileName.Buffer);

View File

@ -667,72 +667,6 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist)
Unlock();
}
VAddr VMManager::Allocate(size_t Size)
{
LOG_FUNC_ONE_ARG(Size);
MMPTE TempPte;
PMMPTE PointerPte;
PMMPTE EndingPte;
PFN pfn;
PFN_COUNT PteNumber;
VAddr addr;
if (!Size) { RETURN(NULL); }
Lock();
PteNumber = ROUND_UP_4K(Size) >> PAGE_SHIFT;
if (!IsMappable(PteNumber, true, m_MmLayoutDebug && m_bAllowNonDebuggerOnTop64MiB ? true : false)) { goto Fail; }
ConvertXboxToPtePermissions(XBOX_PAGE_EXECUTE_READWRITE, &TempPte);
addr = MapMemoryBlock(UserRegion, PteNumber, MEM_RESERVE | MEM_COMMIT, false);
if (!addr) { goto Fail; }
// Check if we have to construct the PT's for this allocation
if (!AllocatePT(PteNumber << PAGE_SHIFT, addr))
{
VirtualFree((void*)addr, 0, MEM_RELEASE);
goto Fail;
}
// Finally, write the pte's and the pfn's
PointerPte = GetPteAddress(addr);
EndingPte = PointerPte + PteNumber - 1;
while (PointerPte <= EndingPte)
{
RemoveFree(1, &pfn, 0, 0, m_MmLayoutDebug && !m_bAllowNonDebuggerOnTop64MiB ? XBOX_HIGHEST_PHYSICAL_PAGE
: m_HighestPage);
WritePfn(pfn, pfn, PointerPte, ImageType);
WritePte(PointerPte, PointerPte, TempPte, pfn);
PointerPte++;
}
ConstructVMA(addr, PteNumber << PAGE_SHIFT, UserRegion, AllocatedVma);
UpdateMemoryPermissions(addr, PteNumber << PAGE_SHIFT, XBOX_PAGE_EXECUTE_READWRITE);
Unlock();
RETURN(addr);
Fail:
Unlock();
RETURN(NULL);
}
VAddr VMManager::AllocateZeroed(size_t Size)
{
LOG_FORWARD("g_VMManager.Allocate");
VAddr addr = Allocate(Size);
if (addr) { xbox::RtlFillMemoryUlong((void*)addr, ROUND_UP_4K(Size), 0); }
RETURN(addr);
}
VAddr VMManager::AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Size, bool bAddGuardPage)
{
LOG_FUNC_BEGIN
@ -968,54 +902,6 @@ VAddr VMManager::MapDeviceMemory(PAddr Paddr, size_t Size, DWORD Perms)
RETURN(NULL);
}
void VMManager::Deallocate(VAddr addr)
{
LOG_FUNC_BEGIN
LOG_FUNC_ARG(addr)
LOG_FUNC_END;
PMMPTE PointerPte;
PMMPTE StartingPte;
PMMPTE EndingPte;
PFN pfn;
PFN_COUNT PteNumber;
VMAIter it;
bool bOverflow;
assert(CHECK_ALIGNMENT(addr, PAGE_SIZE)); // all starting addresses in the user region are page aligned
assert(IS_USER_ADDRESS(addr));
Lock();
it = CheckConflictingVMA(addr, 0, UserRegion, &bOverflow);
if (it == m_MemoryRegionArray[UserRegion].RegionMap.end() || bOverflow)
{
Unlock();
return;
}
PointerPte = GetPteAddress(addr);
EndingPte = PointerPte + (it->second.size >> PAGE_SHIFT) - 1;
StartingPte = PointerPte;
PteNumber = EndingPte - StartingPte + 1;
while (PointerPte <= EndingPte)
{
pfn = PointerPte->Hardware.PFN;
InsertFree(pfn, pfn);
WritePfn(pfn, pfn, PointerPte, ImageType, true);
PointerPte++;
}
WritePte(StartingPte, EndingPte, *StartingPte, 0, true);
DestructVMA(it->first, UserRegion, it->second.size);
DeallocatePT(PteNumber << PAGE_SHIFT, addr);
Unlock();
}
void VMManager::DeallocateContiguousMemory(VAddr addr)
{
LOG_FUNC_BEGIN

View File

@ -102,10 +102,6 @@ class VMManager : public PhysicalMemory
void Initialize(unsigned int SystemType, int BootFlags, blocks_reserved_t blocks_reserved);
// retrieves memory statistics
void MemoryStatistics(xbox::PMM_STATISTICS memory_statistics);
// allocates memory in the user region
VAddr Allocate(size_t Size);
// allocates memory in the user region and zeros it
VAddr AllocateZeroed(size_t size);
// allocates memory in the system region
VAddr AllocateSystemMemory(PageType BusyType, DWORD Perms, size_t Size, bool bAddGuardPage);
// allocates memory in the contiguous region
@ -118,8 +114,6 @@ class VMManager : public PhysicalMemory
void DeallocateContiguousMemory(VAddr addr);
// unmaps device memory in the system region
void UnmapDeviceMemory(VAddr addr, size_t Size);
// deallocates memory in the user region
void Deallocate(VAddr addr);
// changes the protections of a memory region
void Protect(VAddr addr, size_t Size, DWORD NewPerms);
// checks if a VAddr is valid

View File

@ -33,13 +33,16 @@
#include "core\kernel\exports\EmuKrnlKe.h"
#include "core\kernel\support\EmuFS.h" // For fs_instruction_t
#include "core\kernel\init\CxbxKrnl.h"
#include "core\kernel\memory-manager\VMManager.h"
#include "Logging.h"
#include <windows.h>
#include <cstdio>
#include <vector>
#ifdef RtlZeroMemory
#undef RtlZeroMemory
#endif
// NT_TIB (Thread Information Block) offsets - see https://www.microsoft.com/msj/archive/S2CE.aspx
#define TIB_ExceptionList offsetof(NT_TIB, ExceptionList) // = 0x00/0
#define TIB_StackBase offsetof(NT_TIB, StackBase) // = 0x04/4
@ -533,7 +536,8 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
}
/* + HACK: extra safety padding 0x100 */
pNewTLS = (void*)g_VMManager.AllocateZeroed(dwCopySize + dwZeroSize + 0x100 + 0xC);
pNewTLS = (void*)xbox::ExAllocatePool(dwCopySize + dwZeroSize + 0x100 + 0xC);
xbox::RtlZeroMemory(pNewTLS, dwCopySize + dwZeroSize + 0x100 + 0xC);
/* Skip the first 12 bytes so that TLSData will be 16 byte aligned (addr returned by AllocateZeroed is 4K aligned) */
pNewTLS = (uint8_t*)pNewTLS + 12;
@ -579,7 +583,8 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
}
// Allocate the xbox KPCR structure
xbox::KPCR *NewPcr = (xbox::KPCR*)g_VMManager.AllocateZeroed(sizeof(xbox::KPCR));
xbox::KPCR *NewPcr = (xbox::KPCR*)xbox::ExAllocatePool(sizeof(xbox::KPCR));
xbox::RtlZeroMemory(NewPcr, sizeof(xbox::KPCR));
xbox::NT_TIB *XbTib = &(NewPcr->NtTib);
xbox::PKPRCB Prcb = &(NewPcr->PrcbData);
// Note : As explained above (at EmuKeSetPcr), Cxbx cannot allocate one NT_TIB and KPRCB
@ -625,7 +630,8 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
// Initialize a fake PrcbData.CurrentThread
{
xbox::ETHREAD *EThread = (xbox::ETHREAD*)g_VMManager.AllocateZeroed(sizeof(xbox::ETHREAD)); // Clear, to prevent side-effects on random contents
xbox::ETHREAD *EThread = (xbox::ETHREAD*)xbox::ExAllocatePool(sizeof(xbox::ETHREAD)); // Clear, to prevent side-effects on random contents
xbox::RtlZeroMemory(EThread, sizeof(xbox::ETHREAD));
EThread->Tcb.TlsData = pNewTLS;
EThread->UniqueThread = GetCurrentThreadId();

View File

@ -38,7 +38,6 @@
#include <ntstatus.h>
#pragma warning(default:4005)
#include "core\kernel\init\CxbxKrnl.h"
#include "core\kernel\memory-manager\VMManager.h"
#include "Logging.h"
#include <filesystem>
@ -752,8 +751,9 @@ EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(const HANDLE Handl
void _CxbxPVOIDDeleter(PVOID *ptr)
{
if (*ptr)
g_VMManager.Deallocate((VAddr)*ptr);
if (*ptr) {
xbox::ExFreePool(*ptr);
}
}
// ----------------------------------------------------------------------------
@ -771,7 +771,7 @@ NtDll::FILE_LINK_INFORMATION * _XboxToNTLinkInfo(xbox::FILE_LINK_INFORMATION *xb
// Build the native FILE_LINK_INFORMATION struct
*Length = sizeof(NtDll::FILE_LINK_INFORMATION) + convertedFileName.size() * sizeof(wchar_t);
NtDll::FILE_LINK_INFORMATION *ntLinkInfo = (NtDll::FILE_LINK_INFORMATION *) g_VMManager.AllocateZeroed(*Length);
NtDll::FILE_LINK_INFORMATION *ntLinkInfo = (NtDll::FILE_LINK_INFORMATION *)xbox::ExAllocatePool(*Length);
ntLinkInfo->ReplaceIfExists = xboxLinkInfo->ReplaceIfExists;
ntLinkInfo->RootDirectory = RootDirectory;
ntLinkInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);
@ -791,7 +791,7 @@ NtDll::FILE_RENAME_INFORMATION * _XboxToNTRenameInfo(xbox::FILE_RENAME_INFORMATI
// Build the native FILE_RENAME_INFORMATION struct
*Length = sizeof(NtDll::FILE_RENAME_INFORMATION) + convertedFileName.size() * sizeof(wchar_t);
NtDll::FILE_RENAME_INFORMATION *ntRenameInfo = (NtDll::FILE_RENAME_INFORMATION *) g_VMManager.AllocateZeroed(*Length);
NtDll::FILE_RENAME_INFORMATION *ntRenameInfo = (NtDll::FILE_RENAME_INFORMATION *)xbox::ExAllocatePool(*Length);
ntRenameInfo->ReplaceIfExists = xboxRenameInfo->ReplaceIfExists;
ntRenameInfo->RootDirectory = RootDirectory;
ntRenameInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);