Initial MemoryManager Implementation
This commit is contained in:
parent
db7da95d9e
commit
f46f77c3ad
|
@ -275,6 +275,7 @@ $(SOLUTIONDIR)Export.bat</Command>
|
|||
<ClInclude Include="..\..\src\CxbxKrnl\HLEDataBase\XOnline.1.0.5849.h" />
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\HLEIntercept.h" />
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\LibRc4.h" />
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\MemoryManager.h" />
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\nv2a_int.h" />
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\OOVPA.h" />
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\ReservedMemory.h" />
|
||||
|
@ -525,6 +526,7 @@ $(SOLUTIONDIR)Export.bat</Command>
|
|||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\CxbxKrnl\LibRc4.cpp" />
|
||||
<ClCompile Include="..\..\src\CxbxKrnl\MemoryManager.cpp" />
|
||||
<ClCompile Include="..\..\src\CxbxKrnl\ResourceTracker.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
|
|
|
@ -196,6 +196,9 @@
|
|||
<ClCompile Include="..\..\src\Common\EmuEEPROM.cpp">
|
||||
<Filter>Shared</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\CxbxKrnl\MemoryManager.cpp">
|
||||
<Filter>Emulator</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\Cxbx\DlgControllerConfig.h">
|
||||
|
@ -525,6 +528,9 @@
|
|||
<ClInclude Include="..\..\src\Common\EmuEEPROM.h">
|
||||
<Filter>Shared</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\CxbxKrnl\MemoryManager.h">
|
||||
<Filter>Emulator</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\resource\About.jpg">
|
||||
|
|
|
@ -224,18 +224,6 @@ typedef long NTSTATUS;
|
|||
// * memory
|
||||
// ******************************************************************
|
||||
|
||||
// Define virtual base and alternate virtual base of kernel.
|
||||
#define KSEG0_BASE 0x80000000
|
||||
|
||||
// Define virtual base addresses for physical memory windows.
|
||||
#define MM_SYSTEM_PHYSICAL_MAP KSEG0_BASE
|
||||
|
||||
#define MM_HIGHEST_PHYSICAL_PAGE 0x07FFF
|
||||
#define MM_64M_PHYSICAL_PAGE 0x04000
|
||||
#define MM_INSTANCE_PHYSICAL_PAGE 0x03FE0 // Chihiro arcade should use 0x07FF0
|
||||
|
||||
#define MM_INSTANCE_PAGE_COUNT 16
|
||||
|
||||
#define PAGE_SHIFT 12
|
||||
|
||||
// Xbox pages are (1 << 12) = 0x00001000 = 4096 bytes in size.
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace xboxkrnl
|
|||
#include "EmuNV2A.h" // For InitOpenGLContext
|
||||
#include "HLEIntercept.h"
|
||||
#include "ReservedMemory.h" // For virtual_memory_placeholder
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
#include <clocale>
|
||||
|
@ -225,8 +226,6 @@ void RestoreExeImageHeader()
|
|||
ExeOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] = NewOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS];
|
||||
}
|
||||
|
||||
#define CONTIGUOUS_MEMORY_SIZE (64 * ONE_MB)
|
||||
|
||||
void *CxbxRestoreContiguousMemory(char *szFilePath_memory_bin)
|
||||
{
|
||||
// First, try to open an existing memory.bin file :
|
||||
|
@ -660,7 +659,7 @@ void CxbxKrnlInit
|
|||
|
||||
// Assign the running Xbe path, so it can be accessed via the kernel thunk 'XeImageFileName' :
|
||||
xboxkrnl::XeImageFileName.MaximumLength = MAX_PATH;
|
||||
xboxkrnl::XeImageFileName.Buffer = (PCHAR)malloc(MAX_PATH);
|
||||
xboxkrnl::XeImageFileName.Buffer = (PCHAR)g_MemoryManager.Allocate(MAX_PATH);
|
||||
sprintf(xboxkrnl::XeImageFileName.Buffer, "%c:\\%s", CxbxDefaultXbeDriveLetter, fileName.c_str());
|
||||
xboxkrnl::XeImageFileName.Length = (USHORT)strlen(xboxkrnl::XeImageFileName.Buffer);
|
||||
DbgPrintf("EmuMain : XeImageFileName = %s\n", xboxkrnl::XeImageFileName.Buffer);
|
||||
|
|
|
@ -234,31 +234,6 @@ extern int EmuException(LPEXCEPTION_POINTERS e)
|
|||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
// check how many bytes were allocated for a structure
|
||||
extern int EmuCheckAllocationSize(LPVOID pBase, bool largeBound)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION MemoryBasicInfo;
|
||||
|
||||
DWORD dwRet;
|
||||
#ifdef _DEBUG_ALLOC
|
||||
dwRet = CxbxVirtualQueryDebug(pBase, &MemoryBasicInfo, sizeof(MemoryBasicInfo));
|
||||
if (dwRet == -1)
|
||||
#endif
|
||||
dwRet = VirtualQuery(pBase, &MemoryBasicInfo, sizeof(MemoryBasicInfo));
|
||||
|
||||
if(dwRet == 0)
|
||||
return 0;
|
||||
|
||||
if(MemoryBasicInfo.State != MEM_COMMIT)
|
||||
return 0;
|
||||
|
||||
// this is a hack in order to determine when pointers come from a large write-combined database
|
||||
if(largeBound && MemoryBasicInfo.RegionSize > 5*1024*1024)
|
||||
return -1;
|
||||
|
||||
return MemoryBasicInfo.RegionSize - ((DWORD)pBase - (DWORD)MemoryBasicInfo.BaseAddress);
|
||||
}
|
||||
|
||||
// exception handle for that tough final exit :)
|
||||
int ExitException(LPEXCEPTION_POINTERS e)
|
||||
{
|
||||
|
|
|
@ -50,9 +50,6 @@ inline void NTAPI EmuWarning(const char *szWarningMessage, ...) { }
|
|||
// exception handler
|
||||
extern int EmuException(LPEXCEPTION_POINTERS e);
|
||||
|
||||
// check the allocation size of a given virtual address
|
||||
extern int EmuCheckAllocationSize(LPVOID pBase, bool largeBound);
|
||||
|
||||
// print call stack trace
|
||||
#ifdef _DEBUG
|
||||
void EmuPrintStackTrace(PCONTEXT ContextRecord);
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#ifdef _DEBUG_ALLOC
|
||||
#define CxbxMalloc(Size) CxbxMallocDebug(Size, __FILE__, __LINE__)
|
||||
#define CxbxCalloc(Num, Size) CxbxCallocDebug(Num, Size, __FILE__, __LINE__)
|
||||
#define CxbxFree(Addr) CxbxFreeDebug(Addr, __FILE__, __LINE__)
|
||||
#define CxbxFree(Addr) CxbxFreeDebug(Addr, __FILE__, __LINE__)
|
||||
#define CxbxRtlAlloc(Heap, Flags, Bytes) CxbxRtlAllocDebug(Heap, Flags, Bytes, __FILE__, __LINE__)
|
||||
#define CxbxRtlFree(Heap, Flags, pMem) CxbxRtlFreeDebug(Heap, Flags, pMem, __FILE__, __LINE__)
|
||||
#define CxbxRtlRealloc(Heap, Flags, pMem, Bytes) CxbxRtlReallocDebug(Heap, Flags, pMem, Bytes, __FILE__, __LINE__)
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace xboxkrnl
|
|||
#include "DbgConsole.h"
|
||||
#include "ResourceTracker.h"
|
||||
#include "EmuAlloc.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "EmuXTL.h"
|
||||
|
||||
#include <process.h>
|
||||
|
@ -271,49 +272,49 @@ int GetD3DResourceRefCount(XTL::IDirect3DResource8 *EmuResource)
|
|||
|
||||
XTL::X_D3DSurface *EmuNewD3DSurface()
|
||||
{
|
||||
XTL::X_D3DSurface *result = (XTL::X_D3DSurface *)calloc(1, sizeof(XTL::X_D3DSurface));
|
||||
XTL::X_D3DSurface *result = (XTL::X_D3DSurface *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DSurface));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_SURFACE | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
||||
XTL::X_D3DTexture *EmuNewD3DTexture()
|
||||
{
|
||||
XTL::X_D3DTexture *result = (XTL::X_D3DTexture *)calloc(1, sizeof(XTL::X_D3DTexture));
|
||||
XTL::X_D3DTexture *result = (XTL::X_D3DTexture *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DTexture));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
||||
XTL::X_D3DVolumeTexture *EmuNewD3DVolumeTexture()
|
||||
{
|
||||
XTL::X_D3DVolumeTexture *result = (XTL::X_D3DVolumeTexture *)calloc(1, sizeof(XTL::X_D3DVolumeTexture));
|
||||
XTL::X_D3DVolumeTexture *result = (XTL::X_D3DVolumeTexture *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DVolumeTexture));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
||||
XTL::X_D3DCubeTexture *EmuNewD3DCubeTexture()
|
||||
{
|
||||
XTL::X_D3DCubeTexture *result = (XTL::X_D3DCubeTexture *)calloc(1, sizeof(XTL::X_D3DCubeTexture));
|
||||
XTL::X_D3DCubeTexture *result = (XTL::X_D3DCubeTexture *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DCubeTexture));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
||||
XTL::X_D3DIndexBuffer *EmuNewD3DIndexBuffer()
|
||||
{
|
||||
XTL::X_D3DIndexBuffer *result = (XTL::X_D3DIndexBuffer *)calloc(1, sizeof(XTL::X_D3DIndexBuffer));
|
||||
XTL::X_D3DIndexBuffer *result = (XTL::X_D3DIndexBuffer *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DIndexBuffer));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_INDEXBUFFER | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
||||
XTL::X_D3DVertexBuffer *EmuNewD3DVertexBuffer()
|
||||
{
|
||||
XTL::X_D3DVertexBuffer *result = (XTL::X_D3DVertexBuffer *)calloc(1, sizeof(XTL::X_D3DVertexBuffer));
|
||||
XTL::X_D3DVertexBuffer *result = (XTL::X_D3DVertexBuffer *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DVertexBuffer));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_VERTEXBUFFER | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
||||
XTL::X_D3DPalette *EmuNewD3DPalette()
|
||||
{
|
||||
XTL::X_D3DPalette *result = (XTL::X_D3DPalette *)calloc(1, sizeof(XTL::X_D3DPalette));
|
||||
XTL::X_D3DPalette *result = (XTL::X_D3DPalette *)g_MemoryManager.AllocateZeroed(1, sizeof(XTL::X_D3DPalette));
|
||||
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_PALETTE | 1; // Set refcount to 1
|
||||
return result;
|
||||
}
|
||||
|
@ -1055,7 +1056,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
|
|||
DWORD *lpCodes = 0;
|
||||
|
||||
g_pDD7->GetFourCCCodes(&dwCodes, lpCodes);
|
||||
lpCodes = (DWORD*)CxbxMalloc(dwCodes*sizeof(DWORD));
|
||||
lpCodes = (DWORD*)g_MemoryManager.Allocate(dwCodes*sizeof(DWORD));
|
||||
g_pDD7->GetFourCCCodes(&dwCodes, lpCodes);
|
||||
g_bSupportsYUY2 = false;
|
||||
for(DWORD v=0;v<dwCodes;v++)
|
||||
|
@ -1067,7 +1068,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
|
|||
}
|
||||
}
|
||||
|
||||
CxbxFree(lpCodes);
|
||||
g_MemoryManager.Free(lpCodes);
|
||||
if(!g_bSupportsYUY2)
|
||||
EmuWarning("YUY2 overlays are not supported in hardware, could be slow!");
|
||||
else
|
||||
|
@ -1337,7 +1338,7 @@ static void EmuUnswizzleTextureStages()
|
|||
RECT iRect = {0,0,0,0};
|
||||
POINT iPoint = {0,0};
|
||||
|
||||
void *pTemp = malloc(dwHeight*dwPitch);
|
||||
void *pTemp = g_MemoryManager.Allocate(dwHeight*dwPitch);
|
||||
|
||||
XTL::EmuUnswizzleRect
|
||||
(
|
||||
|
@ -1349,7 +1350,7 @@ static void EmuUnswizzleTextureStages()
|
|||
|
||||
pTexture->UnlockRect(0);
|
||||
|
||||
free(pTemp);
|
||||
g_MemoryManager.Free(pTemp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2058,7 +2059,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_GetGammaRamp)
|
|||
");\n",
|
||||
pRamp);
|
||||
|
||||
D3DGAMMARAMP *pGammaRamp = (D3DGAMMARAMP *)malloc(sizeof(D3DGAMMARAMP));
|
||||
D3DGAMMARAMP *pGammaRamp = (D3DGAMMARAMP *)g_MemoryManager.Allocate(sizeof(D3DGAMMARAMP));
|
||||
|
||||
g_pD3DDevice8->GetGammaRamp(pGammaRamp);
|
||||
|
||||
|
@ -2069,7 +2070,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_GetGammaRamp)
|
|||
pRamp->blue[v] = (BYTE)pGammaRamp->blue[v];
|
||||
}
|
||||
|
||||
free(pGammaRamp);
|
||||
g_MemoryManager.Free(pGammaRamp);
|
||||
|
||||
|
||||
|
||||
|
@ -2500,8 +2501,8 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
|
|||
pDeclaration, pFunction, pHandle, Usage);
|
||||
|
||||
// create emulated shader struct
|
||||
X_D3DVertexShader *pD3DVertexShader = (X_D3DVertexShader*)CxbxCalloc(1, sizeof(X_D3DVertexShader));
|
||||
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER*)CxbxCalloc(1, sizeof(VERTEX_SHADER));
|
||||
X_D3DVertexShader *pD3DVertexShader = (X_D3DVertexShader*)g_MemoryManager.AllocateZeroed(1, sizeof(X_D3DVertexShader));
|
||||
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER*)g_MemoryManager.AllocateZeroed(1, sizeof(VERTEX_SHADER));
|
||||
|
||||
// TODO: Intelligently fill out these fields as necessary
|
||||
|
||||
|
@ -2597,9 +2598,9 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
|
|||
// Save the status, to remove things later
|
||||
pVertexShader->Status = hRet;
|
||||
|
||||
CxbxFree(pRecompiledDeclaration);
|
||||
g_MemoryManager.Free(pRecompiledDeclaration);
|
||||
|
||||
pVertexShader->pDeclaration = (DWORD*)CxbxMalloc(DeclarationSize);
|
||||
pVertexShader->pDeclaration = (DWORD*)g_MemoryManager.Allocate(DeclarationSize);
|
||||
memcpy(pVertexShader->pDeclaration, pDeclaration, DeclarationSize);
|
||||
|
||||
pVertexShader->FunctionSize = 0;
|
||||
|
@ -2612,7 +2613,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
|
|||
{
|
||||
if(pFunction != NULL)
|
||||
{
|
||||
pVertexShader->pFunction = (DWORD*)CxbxMalloc(VertexShaderSize);
|
||||
pVertexShader->pFunction = (DWORD*)g_MemoryManager.Allocate(VertexShaderSize);
|
||||
memcpy(pVertexShader->pFunction, pFunction, VertexShaderSize);
|
||||
pVertexShader->FunctionSize = VertexShaderSize;
|
||||
}
|
||||
|
@ -2859,7 +2860,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DeletePixelShader)
|
|||
{
|
||||
g_pD3DDevice8->DeletePixelShader(pPixelShader->Handle);
|
||||
}
|
||||
CxbxFree(pPixelShader);
|
||||
g_MemoryManager.Free(pPixelShader);
|
||||
}*/
|
||||
|
||||
|
||||
|
@ -2914,7 +2915,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreatePixelShader)
|
|||
// CreatePixelShader() is expected to return a pHandle directly to a shader interface.
|
||||
|
||||
/*
|
||||
PIXEL_SHADER *pPixelShader = (PIXEL_SHADER*)CxbxCalloc(1, sizeof(PIXEL_SHADER)); // Clear, to prevent side-effects on random contents
|
||||
PIXEL_SHADER *pPixelShader = (PIXEL_SHADER*)g_MemoryManager.AllocateZeroed(1, sizeof(PIXEL_SHADER)); // Clear, to prevent side-effects on random contents
|
||||
|
||||
memcpy(&pPixelShader->PSDef, pPSDef, sizeof(X_D3DPIXELSHADERDEF));
|
||||
|
||||
|
@ -3145,7 +3146,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateTexture)
|
|||
{
|
||||
// If YUY2 is not supported in hardware, we'll actually mark this as a special fake texture
|
||||
Texture_Data = X_D3DRESOURCE_DATA_YUV_SURFACE;
|
||||
pTexture->Lock = (DWORD)CxbxMalloc(g_dwOverlayP * g_dwOverlayH);
|
||||
pTexture->Lock = (DWORD)g_MemoryManager.Allocate(g_dwOverlayP * g_dwOverlayH);
|
||||
|
||||
g_pCachedYuvSurface = (X_D3DSurface*)pTexture;
|
||||
|
||||
|
@ -3282,7 +3283,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVolumeTexture)
|
|||
{
|
||||
// If YUY2 is not supported in hardware, we'll actually mark this as a special fake texture
|
||||
(*ppVolumeTexture)->Data = X_D3DRESOURCE_DATA_YUV_SURFACE;
|
||||
(*ppVolumeTexture)->Lock = (DWORD)CxbxMalloc(g_dwOverlayP * g_dwOverlayH);
|
||||
(*ppVolumeTexture)->Lock = (DWORD)g_MemoryManager.Allocate(g_dwOverlayP * g_dwOverlayH);
|
||||
(*ppVolumeTexture)->Format = Format << X_D3DFORMAT_FORMAT_SHIFT;
|
||||
|
||||
(*ppVolumeTexture)->Size = (g_dwOverlayW & X_D3DSIZE_WIDTH_MASK)
|
||||
|
@ -3783,7 +3784,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Begin)
|
|||
|
||||
if(g_IVBTable == 0)
|
||||
{
|
||||
g_IVBTable = (struct XTL::_D3DIVB*)CxbxMalloc(sizeof(XTL::_D3DIVB)*1024);
|
||||
g_IVBTable = (struct XTL::_D3DIVB*)g_MemoryManager.Allocate(sizeof(XTL::_D3DIVB)*1024);
|
||||
}
|
||||
|
||||
g_IVBTblOffs = 0;
|
||||
|
@ -3794,7 +3795,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Begin)
|
|||
|
||||
if(g_pIVBVertexBuffer == 0)
|
||||
{
|
||||
g_pIVBVertexBuffer = (DWORD*)CxbxMalloc(sizeof(XTL::_D3DIVB)*1024);
|
||||
g_pIVBVertexBuffer = (DWORD*)g_MemoryManager.Allocate(sizeof(XTL::_D3DIVB)*1024);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4136,8 +4137,8 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_End)()
|
|||
EmuFlushIVB();
|
||||
|
||||
// TODO: Should technically clean this up at some point..but on XP doesnt matter much
|
||||
// CxbxFree(g_pIVBVertexBuffer);
|
||||
// CxbxFree(g_IVBTable);
|
||||
// g_MemoryManager.Free(g_pIVBVertexBuffer);
|
||||
// g_MemoryManager.Free(g_IVBTable);
|
||||
|
||||
|
||||
|
||||
|
@ -4423,7 +4424,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
|
||||
// create vertex buffer
|
||||
{
|
||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
||||
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||
|
||||
if(dwSize == -1)
|
||||
{
|
||||
|
@ -4482,7 +4483,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
|
||||
// create index buffer
|
||||
{
|
||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
||||
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||
|
||||
if(dwSize == -1 || dwSize == 0)
|
||||
{
|
||||
|
@ -4534,7 +4535,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
|
||||
// create push buffer
|
||||
{
|
||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
||||
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||
|
||||
if(dwSize == -1)
|
||||
{
|
||||
|
@ -4684,7 +4685,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
// TODO : Do we actually need to set these?
|
||||
pPixelContainer->Common = X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||
pPixelContainer->Data = X_D3DRESOURCE_DATA_YUV_SURFACE;
|
||||
pPixelContainer->Lock = (DWORD)CxbxMalloc(g_dwOverlayP * g_dwOverlayH);
|
||||
pPixelContainer->Lock = (DWORD)g_MemoryManager.Allocate(g_dwOverlayP * g_dwOverlayH);
|
||||
pPixelContainer->Format = (X_D3DFMT_YUY2 << X_D3DFORMAT_FORMAT_SHIFT);
|
||||
|
||||
pPixelContainer->Size = (g_dwOverlayW & X_D3DSIZE_WIDTH_MASK);
|
||||
|
@ -4882,7 +4883,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
|
||||
BYTE *pPixelData = (BYTE*)LockedRect.pBits;
|
||||
DWORD dwDataSize = dwMipWidth*dwMipHeight;
|
||||
DWORD* pExpandedTexture = (DWORD*)CxbxMalloc(dwDataSize * sizeof(DWORD));
|
||||
DWORD* pExpandedTexture = (DWORD*)g_MemoryManager.Allocate(dwDataSize * sizeof(DWORD));
|
||||
DWORD* pTexturePalette = (DWORD*)pCurrentPalette;
|
||||
|
||||
//__asm int 3;
|
||||
|
@ -4916,7 +4917,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
memcpy(pPixelData, pExpandedTexture, dwDataSize * sizeof(DWORD));
|
||||
|
||||
// Flush unused data buffers
|
||||
CxbxFree(pExpandedTexture);
|
||||
g_MemoryManager.Free(pExpandedTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5025,7 +5026,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
|||
|
||||
// create palette
|
||||
{
|
||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
||||
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||
|
||||
if(dwSize == -1)
|
||||
{
|
||||
|
@ -5139,7 +5140,7 @@ ULONG WINAPI XTL::EMUPATCH(D3DResource_Release)
|
|||
g_pCachedYuvSurface = NULL;
|
||||
|
||||
// free memory associated with this special resource handle
|
||||
CxbxFree((PVOID)pThis->Lock);
|
||||
g_MemoryManager.Free((PVOID)pThis->Lock);
|
||||
}
|
||||
|
||||
EMUPATCH(D3DDevice_EnableOverlay)(FALSE);
|
||||
|
@ -8266,7 +8267,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_SetPalette)
|
|||
if( pPalette->Data )
|
||||
{
|
||||
pCurrentPalette = (LPVOID) pPalette->Data;
|
||||
dwCurrentPaletteSize = EmuCheckAllocationSize( (LPVOID) pPalette->Data, false );
|
||||
dwCurrentPaletteSize = g_MemoryManager.QueryAllocationSize((LPVOID)pPalette->Data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8433,17 +8434,17 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DeleteVertexShader)
|
|||
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER *)pD3DVertexShader->Handle;
|
||||
|
||||
RealHandle = pVertexShader->Handle;
|
||||
CxbxFree(pVertexShader->pDeclaration);
|
||||
g_MemoryManager.Free(pVertexShader->pDeclaration);
|
||||
|
||||
if(pVertexShader->pFunction)
|
||||
{
|
||||
CxbxFree(pVertexShader->pFunction);
|
||||
g_MemoryManager.Free(pVertexShader->pFunction);
|
||||
}
|
||||
|
||||
FreeVertexDynamicPatch(pVertexShader);
|
||||
|
||||
CxbxFree(pVertexShader);
|
||||
CxbxFree(pD3DVertexShader);
|
||||
g_MemoryManager.Free(pVertexShader);
|
||||
g_MemoryManager.Free(pD3DVertexShader);
|
||||
}
|
||||
|
||||
HRESULT hRet = g_pD3DDevice8->DeleteVertexShader(RealHandle);
|
||||
|
@ -8897,7 +8898,7 @@ PVOID WINAPI XTL::EMUPATCH(D3D_AllocContiguousMemory)
|
|||
// so that we can return a valid page aligned pointer
|
||||
//
|
||||
|
||||
PVOID pRet = CxbxMalloc(dwSize + PAGE_SIZE);
|
||||
PVOID pRet = g_MemoryManager.Allocate(dwSize + PAGE_SIZE);
|
||||
|
||||
// align to page boundary
|
||||
{
|
||||
|
@ -9607,7 +9608,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_PersistDisplay)()
|
|||
FILE* fp = fopen( "PersistedSurface.bin", "wb" );
|
||||
if(fp)
|
||||
{
|
||||
void* ptr = malloc( BackBufferDesc.Width * BackBufferDesc.Height * dwBytesPerPixel );
|
||||
void* ptr = g_MemoryManager.Allocate( BackBufferDesc.Width * BackBufferDesc.Height * dwBytesPerPixel );
|
||||
|
||||
if( SUCCEEDED( pBackBuffer->LockRect( &LockedRect, NULL, 0 ) ) )
|
||||
{
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
#include "CxbxKrnl/EmuFS.h"
|
||||
#include "CxbxKrnl/EmuAlloc.h"
|
||||
#include "CxbxKrnl/EmuXTL.h"
|
||||
#include <CxbxKrnl/MemoryManager.h>
|
||||
|
||||
#include <process.h>
|
||||
#include <locale.h>
|
||||
|
@ -734,13 +735,13 @@ HRESULT XTL::CreatePixelShaderFunction(X_D3DPIXELSHADERDEF *pPSD, LPD3DXBUFFER*
|
|||
// The Xbox sets r0 to the alpha channel of texture 0, so it can be read before written!
|
||||
if(bR0WAccess)
|
||||
{
|
||||
char *szNewCodeBuffer = (char *)CxbxMalloc((strlen(szCode)+20)*sizeof(char));
|
||||
char *szNewCodeBuffer = (char *)g_MemoryManager.Allocate((strlen(szCode)+20)*sizeof(char));
|
||||
strncpy(szNewCodeBuffer, szCode, iPreRunLen);
|
||||
strcat(szNewCodeBuffer, "mov r0, t0.a\n");
|
||||
strcat(szNewCodeBuffer, &szCode[iPreRunLen]);
|
||||
strcpy(szCode, szNewCodeBuffer);
|
||||
|
||||
CxbxFree(szNewCodeBuffer);
|
||||
g_MemoryManager.Free(szNewCodeBuffer);
|
||||
}
|
||||
/*DbgPrintf("r1 case! ... ");
|
||||
if(bR1WAccess || bR1AWAccess || bR1RGBWAccess)
|
||||
|
@ -753,12 +754,12 @@ HRESULT XTL::CreatePixelShaderFunction(X_D3DPIXELSHADERDEF *pPSD, LPD3DXBUFFER*
|
|||
|
||||
sprintf(szCat, "mov r1%s, t1%s\n", szChannel, szChannel);
|
||||
|
||||
char *szNewCodeBuffer = (char *)malloc((strlen(szCode)+50)*sizeof(char));
|
||||
char *szNewCodeBuffer = (char *)g_MemoryManager.Allocate((strlen(szCode)+50)*sizeof(char));
|
||||
strncpy(szNewCodeBuffer, szCode, iPreRunLen);
|
||||
strcat(szNewCodeBuffer, szCat);
|
||||
strcat(szNewCodeBuffer, &szCode[iPreRunLen]);
|
||||
strcpy(szCode, szNewCodeBuffer);
|
||||
free(szNewCodeBuffer);
|
||||
g_MemoryManager.Free(szNewCodeBuffer);
|
||||
}
|
||||
DbgPrintf("end\n");*/
|
||||
|
||||
|
@ -2616,7 +2617,7 @@ inline void CorrectConstToReg(char *szConst, int *pPSC0, int *pPSC1)
|
|||
|
||||
// Add this const to the beginning of the psh
|
||||
char str[100];
|
||||
char *szNewCodeBuffer = (char *)malloc((strlen(pCodeBuffer)+70)*sizeof(char));
|
||||
char *szNewCodeBuffer = (char *)g_MemoryManager.Allocate((strlen(pCodeBuffer)+70)*sizeof(char));
|
||||
strncpy(szNewCodeBuffer, pCodeBuffer, 7);
|
||||
szNewCodeBuffer[7]=0x00;
|
||||
sprintf(str, "def c%d, %ff, %ff, %ff, %ff\n", i,
|
||||
|
@ -2626,7 +2627,7 @@ inline void CorrectConstToReg(char *szConst, int *pPSC0, int *pPSC1)
|
|||
strcat(szNewCodeBuffer, &pCodeBuffer[7]);
|
||||
strcpy(pCodeBuffer, szNewCodeBuffer);
|
||||
|
||||
free(szNewCodeBuffer);
|
||||
g_MemoryManager.Free(szNewCodeBuffer);
|
||||
|
||||
iConstCount++;
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "CxbxKrnl/EmuXTL.h"
|
||||
#include "CxbxKrnl/EmuD3D8Types.h" // For X_D3DFORMAT
|
||||
#include "CxbxKrnl/ResourceTracker.h"
|
||||
#include "CxbxKrnl/MemoryManager.h"
|
||||
|
||||
uint32 XTL::g_dwPrimaryPBCount = 0;
|
||||
uint32 *XTL::g_pPrimaryPB = 0;
|
||||
|
@ -131,7 +132,7 @@ static void EmuUnswizzleActiveTexture()
|
|||
RECT iRect = {0,0,0,0};
|
||||
POINT iPoint = {0,0};
|
||||
|
||||
void *pTemp = malloc(dwHeight*dwPitch);
|
||||
void *pTemp = g_MemoryManager.Allocate(dwHeight*dwPitch);
|
||||
|
||||
XTL::EmuUnswizzleRect
|
||||
(
|
||||
|
@ -143,7 +144,7 @@ static void EmuUnswizzleActiveTexture()
|
|||
|
||||
pTexture->UnlockRect(0);
|
||||
|
||||
free(pTemp);
|
||||
g_MemoryManager.Free(pTemp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "CxbxKrnl/EmuAlloc.h"
|
||||
#include "CxbxKrnl/EmuXTL.h"
|
||||
#include "CxbxKrnl/ResourceTracker.h"
|
||||
#include "CxbxKrnl/MemoryManager.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
|
@ -104,7 +105,7 @@ void XTL::VertexPatcher::CacheStream(VertexPatchDesc *pPatchDesc,
|
|||
void *pCalculateData = NULL;
|
||||
uint32 uiKey;
|
||||
UINT uiLength;
|
||||
CACHEDSTREAM *pCachedStream = (CACHEDSTREAM *)CxbxCalloc(1, sizeof(CACHEDSTREAM));
|
||||
CACHEDSTREAM *pCachedStream = (CACHEDSTREAM *)g_MemoryManager.AllocateZeroed(1, sizeof(CACHEDSTREAM));
|
||||
|
||||
// Check if the cache is full, if so, throw away the least used stream
|
||||
if(g_PatchedStreamsCache.get_count() > VERTEX_BUFFER_CACHE_SIZE)
|
||||
|
@ -200,7 +201,7 @@ void XTL::VertexPatcher::FreeCachedStream(void *pStream)
|
|||
{
|
||||
if(pCachedStream->bIsUP && pCachedStream->pStreamUP)
|
||||
{
|
||||
CxbxFree(pCachedStream->pStreamUP);
|
||||
g_MemoryManager.Free(pCachedStream->pStreamUP);
|
||||
}
|
||||
if(pCachedStream->Stream.pOriginalStream)
|
||||
{
|
||||
|
@ -210,7 +211,7 @@ void XTL::VertexPatcher::FreeCachedStream(void *pStream)
|
|||
{
|
||||
pCachedStream->Stream.pPatchedStream->Release();
|
||||
}
|
||||
CxbxFree(pCachedStream);
|
||||
g_MemoryManager.Free(pCachedStream);
|
||||
}
|
||||
g_PatchedStreamsCache.Unlock();
|
||||
g_PatchedStreamsCache.remove(pStream);
|
||||
|
@ -227,7 +228,7 @@ bool XTL::VertexPatcher::ApplyCachedStream(VertexPatchDesc *pPatchDesc,
|
|||
UINT uiLength;
|
||||
bool bApplied = false;
|
||||
uint32 uiKey;
|
||||
//CACHEDSTREAM *pCachedStream = (CACHEDSTREAM *)CxbxMalloc(sizeof(CACHEDSTREAM));
|
||||
//CACHEDSTREAM *pCachedStream = (CACHEDSTREAM *)g_MemoryManager.Allocate(sizeof(CACHEDSTREAM));
|
||||
|
||||
if(!pPatchDesc->pVertexStreamZeroData)
|
||||
{
|
||||
|
@ -448,7 +449,7 @@ bool XTL::VertexPatcher::PatchStream(VertexPatchDesc *pPatchDesc,
|
|||
// TODO: This is sometimes the number of indices, which isn't too good
|
||||
dwNewSize = pPatchDesc->dwVertexCount * pStreamPatch->ConvertedStride;
|
||||
pNewVertexBuffer = NULL;
|
||||
pNewData = (uint08*)CxbxMalloc(dwNewSize);
|
||||
pNewData = (uint08*)g_MemoryManager.Allocate(dwNewSize);
|
||||
if(!pNewData)
|
||||
{
|
||||
CxbxKrnlCleanup("Couldn't allocate the new stream zero buffer");
|
||||
|
@ -897,7 +898,7 @@ bool XTL::VertexPatcher::PatchPrimitive(VertexPatchDesc *pPatchDesc,
|
|||
dwOriginalSizeWR = dwOriginalSize;
|
||||
dwNewSizeWR = dwNewSize;
|
||||
|
||||
m_pNewVertexStreamZeroData = (uint08*)CxbxMalloc(dwNewSizeWR);
|
||||
m_pNewVertexStreamZeroData = (uint08*)g_MemoryManager.Allocate(dwNewSizeWR);
|
||||
m_bAllocatedStreamZeroData = true;
|
||||
|
||||
pPatchedVertexData = (uint08*)m_pNewVertexStreamZeroData;
|
||||
|
@ -1037,7 +1038,7 @@ bool XTL::VertexPatcher::Restore()
|
|||
|
||||
if(this->m_bAllocatedStreamZeroData)
|
||||
{
|
||||
CxbxFree(m_pNewVertexStreamZeroData);
|
||||
g_MemoryManager.Free(m_pNewVertexStreamZeroData);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "CxbxKrnl/EmuFS.h"
|
||||
#include "CxbxKrnl/EmuAlloc.h"
|
||||
#include "CxbxKrnl/EmuXTL.h"
|
||||
#include "CxbxKrnl/MemoryManager.h"
|
||||
|
||||
// ****************************************************************************
|
||||
// * Vertex shader function recompiler
|
||||
|
@ -1675,10 +1676,10 @@ static boolean VshAddStreamPatch(VSH_PATCH_DATA *pPatchData)
|
|||
pStreamPatch->NbrTypes = pPatchData->TypePatchData.NbrTypes;
|
||||
pStreamPatch->NeedPatch = pPatchData->NeedPatching;
|
||||
// 2010/01/12 - revel8n - fixed allocated data size and type
|
||||
pStreamPatch->pTypes = (UINT *)CxbxMalloc(pPatchData->TypePatchData.NbrTypes * sizeof(UINT)); //VSH_TYPE_PATCH_DATA));
|
||||
pStreamPatch->pTypes = (UINT *)g_MemoryManager.Allocate(pPatchData->TypePatchData.NbrTypes * sizeof(UINT)); //VSH_TYPE_PATCH_DATA));
|
||||
memcpy(pStreamPatch->pTypes, pPatchData->TypePatchData.Types, pPatchData->TypePatchData.NbrTypes * sizeof(UINT)); //VSH_TYPE_PATCH_DATA));
|
||||
// 2010/12/06 - PatrickvL - do the same for new sizes :
|
||||
pStreamPatch->pSizes = (UINT *)CxbxMalloc(pPatchData->TypePatchData.NbrTypes * sizeof(UINT));
|
||||
pStreamPatch->pSizes = (UINT *)g_MemoryManager.Allocate(pPatchData->TypePatchData.NbrTypes * sizeof(UINT));
|
||||
memcpy(pStreamPatch->pSizes, pPatchData->TypePatchData.NewSizes, pPatchData->TypePatchData.NbrTypes * sizeof(UINT));
|
||||
|
||||
return TRUE;
|
||||
|
@ -1977,7 +1978,7 @@ DWORD XTL::EmuRecompileVshDeclaration
|
|||
|
||||
// Calculate size of declaration
|
||||
DWORD DeclarationSize = VshGetDeclarationSize(pDeclaration);
|
||||
*ppRecompiledDeclaration = (DWORD *)CxbxMalloc(DeclarationSize);
|
||||
*ppRecompiledDeclaration = (DWORD *)g_MemoryManager.Allocate(DeclarationSize);
|
||||
DWORD *pRecompiled = *ppRecompiledDeclaration;
|
||||
memcpy(pRecompiled, pDeclaration, DeclarationSize);
|
||||
*pDeclarationSize = DeclarationSize;
|
||||
|
@ -2001,7 +2002,7 @@ DWORD XTL::EmuRecompileVshDeclaration
|
|||
// Copy the patches to the vertex shader struct
|
||||
DWORD StreamsSize = PatchData.StreamPatchData.NbrStreams * sizeof(STREAM_DYNAMIC_PATCH);
|
||||
pVertexDynamicPatch->NbrStreams = PatchData.StreamPatchData.NbrStreams;
|
||||
pVertexDynamicPatch->pStreamPatches = (STREAM_DYNAMIC_PATCH *)CxbxMalloc(StreamsSize);
|
||||
pVertexDynamicPatch->pStreamPatches = (STREAM_DYNAMIC_PATCH *)g_MemoryManager.Allocate(StreamsSize);
|
||||
memcpy(pVertexDynamicPatch->pStreamPatches,
|
||||
PatchData.StreamPatchData.pStreamPatches,
|
||||
StreamsSize);
|
||||
|
@ -2022,7 +2023,7 @@ extern HRESULT XTL::EmuRecompileVshFunction
|
|||
VSH_SHADER_HEADER *pShaderHeader = (VSH_SHADER_HEADER*)pFunction;
|
||||
DWORD *pToken;
|
||||
boolean EOI = false;
|
||||
VSH_XBOX_SHADER *pShader = (VSH_XBOX_SHADER*)CxbxCalloc(1, sizeof(VSH_XBOX_SHADER));
|
||||
VSH_XBOX_SHADER *pShader = (VSH_XBOX_SHADER*)g_MemoryManager.AllocateZeroed(1, sizeof(VSH_XBOX_SHADER));
|
||||
LPD3DXBUFFER pErrors = NULL;
|
||||
HRESULT hRet = 0;
|
||||
|
||||
|
@ -2073,7 +2074,7 @@ extern HRESULT XTL::EmuRecompileVshFunction
|
|||
// The size of the shader is
|
||||
*pOriginalSize = (DWORD)pToken - (DWORD)pFunction;
|
||||
|
||||
char* pShaderDisassembly = (char*)CxbxMalloc(pShader->IntermediateCount * 100); // Should be plenty
|
||||
char* pShaderDisassembly = (char*)g_MemoryManager.Allocate(pShader->IntermediateCount * 100); // Should be plenty
|
||||
DbgVshPrintf("-- Before conversion --\n");
|
||||
VshWriteShader(pShader, pShaderDisassembly, FALSE);
|
||||
DbgVshPrintf("%s", pShaderDisassembly);
|
||||
|
@ -2118,9 +2119,9 @@ extern HRESULT XTL::EmuRecompileVshFunction
|
|||
if( pErrors )
|
||||
pErrors->Release();
|
||||
|
||||
CxbxFree(pShaderDisassembly);
|
||||
g_MemoryManager.Free(pShaderDisassembly);
|
||||
}
|
||||
CxbxFree(pShader);
|
||||
g_MemoryManager.Free(pShader);
|
||||
|
||||
return hRet;
|
||||
}
|
||||
|
@ -2129,12 +2130,12 @@ extern void XTL::FreeVertexDynamicPatch(VERTEX_SHADER *pVertexShader)
|
|||
{
|
||||
for (DWORD i = 0; i < pVertexShader->VertexDynamicPatch.NbrStreams; i++)
|
||||
{
|
||||
CxbxFree(pVertexShader->VertexDynamicPatch.pStreamPatches[i].pTypes);
|
||||
g_MemoryManager.Free(pVertexShader->VertexDynamicPatch.pStreamPatches[i].pTypes);
|
||||
pVertexShader->VertexDynamicPatch.pStreamPatches[i].pTypes = nullptr;
|
||||
CxbxFree(pVertexShader->VertexDynamicPatch.pStreamPatches[i].pSizes);
|
||||
g_MemoryManager.Free(pVertexShader->VertexDynamicPatch.pStreamPatches[i].pSizes);
|
||||
pVertexShader->VertexDynamicPatch.pStreamPatches[i].pSizes = nullptr;
|
||||
}
|
||||
CxbxFree(pVertexShader->VertexDynamicPatch.pStreamPatches);
|
||||
g_MemoryManager.Free(pVertexShader->VertexDynamicPatch.pStreamPatches);
|
||||
pVertexShader->VertexDynamicPatch.pStreamPatches = NULL;
|
||||
pVertexShader->VertexDynamicPatch.NbrStreams = 0;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ namespace xboxkrnl
|
|||
#include "EmuShared.h"
|
||||
#include "EmuAlloc.h"
|
||||
#include "EmuXTL.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#include <mmreg.h>
|
||||
#include <msacm.h>
|
||||
|
@ -803,7 +804,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
|||
|
||||
DWORD dwEmuFlags = 0;
|
||||
|
||||
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)CxbxMalloc(sizeof(DSBUFFERDESC));
|
||||
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)g_MemoryManager.Allocate(sizeof(DSBUFFERDESC));
|
||||
DSBUFFERDESC *pDSBufferDescSpecial = NULL;
|
||||
bool bIsSpecial = false;
|
||||
|
||||
|
@ -828,7 +829,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
|||
|
||||
if(pdsbd->lpwfxFormat != NULL)
|
||||
{
|
||||
pDSBufferDesc->lpwfxFormat = (WAVEFORMATEX*)CxbxMalloc(sizeof(WAVEFORMATEX)+pdsbd->lpwfxFormat->cbSize);
|
||||
pDSBufferDesc->lpwfxFormat = (WAVEFORMATEX*)g_MemoryManager.Allocate(sizeof(WAVEFORMATEX)+pdsbd->lpwfxFormat->cbSize);
|
||||
memcpy(pDSBufferDesc->lpwfxFormat, pdsbd->lpwfxFormat, sizeof(WAVEFORMATEX));
|
||||
|
||||
if(pDSBufferDesc->lpwfxFormat->wFormatTag == WAVE_FORMAT_XBOX_ADPCM)
|
||||
|
@ -868,8 +869,8 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
|||
|
||||
// TODO: A better response to this scenario if possible.
|
||||
|
||||
pDSBufferDescSpecial = (DSBUFFERDESC*)CxbxMalloc(sizeof(DSBUFFERDESC));
|
||||
pDSBufferDescSpecial->lpwfxFormat = (WAVEFORMATEX*)CxbxMalloc(sizeof(WAVEFORMATEX));
|
||||
pDSBufferDescSpecial = (DSBUFFERDESC*)g_MemoryManager.Allocate(sizeof(DSBUFFERDESC));
|
||||
pDSBufferDescSpecial->lpwfxFormat = (WAVEFORMATEX*)g_MemoryManager.Allocate(sizeof(WAVEFORMATEX));
|
||||
|
||||
//memset(pDSBufferDescSpecial->lpwfxFormat, 0, sizeof(WAVEFORMATEX));
|
||||
//memset(pDSBufferDescSpecial, 0, sizeof(DSBUFFERDESC));
|
||||
|
@ -886,7 +887,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
|||
pDSBufferDescSpecial->dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
|
||||
pDSBufferDescSpecial->dwBufferBytes = 3 * pDSBufferDescSpecial->lpwfxFormat->nAvgBytesPerSec;
|
||||
|
||||
// pDSBufferDesc->lpwfxFormat = (WAVEFORMATEX*)CxbxMalloc(sizeof(WAVEFORMATEX)/*+pdsbd->lpwfxFormat->cbSize*/);
|
||||
// pDSBufferDesc->lpwfxFormat = (WAVEFORMATEX*)g_MemoryManager.Allocate(sizeof(WAVEFORMATEX)/*+pdsbd->lpwfxFormat->cbSize*/);
|
||||
|
||||
//// pDSBufferDesc->lpwfxFormat->cbSize = sizeof( WAVEFORMATEX );
|
||||
// pDSBufferDesc->lpwfxFormat->nChannels = 1;
|
||||
|
@ -1216,9 +1217,9 @@ ULONG WINAPI XTL::EMUPATCH(IDirectSoundBuffer_Release)
|
|||
}
|
||||
|
||||
if(pThis->EmuBufferDesc->lpwfxFormat != NULL)
|
||||
CxbxFree(pThis->EmuBufferDesc->lpwfxFormat);
|
||||
g_MemoryManager.Free(pThis->EmuBufferDesc->lpwfxFormat);
|
||||
|
||||
CxbxFree(pThis->EmuBufferDesc);
|
||||
g_MemoryManager.Free(pThis->EmuBufferDesc);
|
||||
|
||||
delete pThis;
|
||||
}
|
||||
|
@ -1562,7 +1563,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream)
|
|||
// TODO: Garbage Collection
|
||||
*ppStream = new X_CDirectSoundStream();
|
||||
|
||||
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)CxbxMalloc(sizeof(DSBUFFERDESC));
|
||||
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)g_MemoryManager.Allocate(sizeof(DSBUFFERDESC));
|
||||
|
||||
// convert from Xbox to PC DSound
|
||||
{
|
||||
|
@ -1580,7 +1581,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream)
|
|||
|
||||
if(pdssd->lpwfxFormat != NULL)
|
||||
{
|
||||
pDSBufferDesc->lpwfxFormat = (WAVEFORMATEX*)CxbxMalloc(sizeof(WAVEFORMATEX));
|
||||
pDSBufferDesc->lpwfxFormat = (WAVEFORMATEX*)g_MemoryManager.Allocate(sizeof(WAVEFORMATEX));
|
||||
memcpy(pDSBufferDesc->lpwfxFormat, pdssd->lpwfxFormat, sizeof(WAVEFORMATEX));
|
||||
}
|
||||
|
||||
|
@ -1830,9 +1831,9 @@ ULONG WINAPI XTL::EMUPATCH(DirectSound_CDirectSoundStream_Release)
|
|||
}
|
||||
|
||||
if(pThis->EmuBufferDesc->lpwfxFormat != NULL)
|
||||
CxbxFree(pThis->EmuBufferDesc->lpwfxFormat);
|
||||
g_MemoryManager.Free(pThis->EmuBufferDesc->lpwfxFormat);
|
||||
|
||||
CxbxFree(pThis->EmuBufferDesc);
|
||||
g_MemoryManager.Free(pThis->EmuBufferDesc);
|
||||
|
||||
delete pThis;
|
||||
}
|
||||
|
@ -3652,7 +3653,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSound_GetEffectData)
|
|||
|
||||
// TODO: Implement
|
||||
if( !pvData )
|
||||
pvData = CxbxMalloc( dwDataSize );
|
||||
pvData = g_MemoryManager.Allocate( dwDataSize );
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace xboxkrnl
|
|||
#include "EmuFS.h"
|
||||
#include "EmuAlloc.h" // For CxbxCalloc()
|
||||
#include "CxbxKrnl.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#undef FIELD_OFFSET // prevent macro redefinition warnings
|
||||
#include <windows.h>
|
||||
|
@ -397,7 +398,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
uint32 dwCopySize = pTLS->dwDataEndAddr - pTLS->dwDataStartAddr;
|
||||
uint32 dwZeroSize = pTLS->dwSizeofZeroFill;
|
||||
|
||||
pNewTLS = CxbxCalloc(1, dwCopySize + dwZeroSize + 0x100 /* + HACK: extra safety padding 0x100*/);
|
||||
pNewTLS = g_MemoryManager.AllocateZeroed(1, dwCopySize + dwZeroSize + 0x100 /* + HACK: extra safety padding 0x100*/);
|
||||
|
||||
memcpy(pNewTLS, pTLSData, dwCopySize);
|
||||
|
||||
|
@ -438,7 +439,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
}
|
||||
|
||||
// Allocate the xbox KPCR structure
|
||||
xboxkrnl::KPCR *NewPcr = (xboxkrnl::KPCR*)CxbxCalloc(1, sizeof(xboxkrnl::KPCR));
|
||||
xboxkrnl::KPCR *NewPcr = (xboxkrnl::KPCR*)g_MemoryManager.AllocateZeroed(1, sizeof(xboxkrnl::KPCR));
|
||||
xboxkrnl::NT_TIB *XbTib = &(NewPcr->NtTib);
|
||||
xboxkrnl::PKPRCB Prcb = &(NewPcr->PrcbData);
|
||||
// Note : As explained above (at EmuKeSetPcr), Cxbx cannot allocate one NT_TIB and KPRCB
|
||||
|
@ -480,7 +481,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
|||
|
||||
// Initialize a fake PrcbData.CurrentThread
|
||||
{
|
||||
xboxkrnl::ETHREAD *EThread = (xboxkrnl::ETHREAD*)CxbxCalloc(1, sizeof(xboxkrnl::ETHREAD)); // Clear, to prevent side-effects on random contents
|
||||
xboxkrnl::ETHREAD *EThread = (xboxkrnl::ETHREAD*)g_MemoryManager.AllocateZeroed(1, sizeof(xboxkrnl::ETHREAD)); // Clear, to prevent side-effects on random contents
|
||||
|
||||
EThread->Tcb.TlsData = pNewTLS;
|
||||
EThread->UniqueThread = GetCurrentThreadId();
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#pragma warning(default:4005)
|
||||
#include "CxbxKrnl.h"
|
||||
#include "EmuAlloc.h"
|
||||
#include "MemoryManager.h"
|
||||
//#include "Logging.h" // For hex4()
|
||||
|
||||
|
||||
|
@ -570,7 +571,7 @@ EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(const HANDLE Handl
|
|||
void _CxbxPVOIDDeleter(PVOID *ptr)
|
||||
{
|
||||
if (*ptr)
|
||||
CxbxFree(*ptr);
|
||||
g_MemoryManager.Free(*ptr);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -588,7 +589,7 @@ NtDll::FILE_LINK_INFORMATION * _XboxToNTLinkInfo(xboxkrnl::FILE_LINK_INFORMATION
|
|||
|
||||
// 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 *) CxbxCalloc(1, *Length);
|
||||
NtDll::FILE_LINK_INFORMATION *ntLinkInfo = (NtDll::FILE_LINK_INFORMATION *) g_MemoryManager.AllocateZeroed(1, *Length);
|
||||
ntLinkInfo->ReplaceIfExists = xboxLinkInfo->ReplaceIfExists;
|
||||
ntLinkInfo->RootDirectory = RootDirectory;
|
||||
ntLinkInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);
|
||||
|
@ -608,7 +609,7 @@ NtDll::FILE_RENAME_INFORMATION * _XboxToNTRenameInfo(xboxkrnl::FILE_RENAME_INFOR
|
|||
|
||||
// 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 *) CxbxCalloc(1, *Length);
|
||||
NtDll::FILE_RENAME_INFORMATION *ntRenameInfo = (NtDll::FILE_RENAME_INFORMATION *) g_MemoryManager.AllocateZeroed(1, *Length);
|
||||
ntRenameInfo->ReplaceIfExists = xboxRenameInfo->ReplaceIfExists;
|
||||
ntRenameInfo->RootDirectory = RootDirectory;
|
||||
ntRenameInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace xboxkrnl
|
|||
|
||||
#include "Logging.h" // For LOG_FUNC()
|
||||
#include "EmuKrnlLogging.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
// prevent name collisions
|
||||
namespace NtDll
|
||||
|
@ -53,7 +54,7 @@ namespace NtDll
|
|||
};
|
||||
|
||||
#include "Emu.h" // For EmuWarning()
|
||||
#include "EmuAlloc.h" // For CxbxFree(), CxbxMalloc(), etc.
|
||||
#include "EmuAlloc.h" // For CxbxFree(), g_MemoryManager.Allocate(), etc.
|
||||
|
||||
// Global Variable(s)
|
||||
PVOID g_pPersistedData = NULL;
|
||||
|
@ -88,11 +89,11 @@ XBSYSAPI EXPORTNUM(1) xboxkrnl::PVOID NTAPI xboxkrnl::AvGetSavedDataAddress(void
|
|||
|
||||
if (g_pPersistedData)
|
||||
{
|
||||
CxbxFree(g_pPersistedData);
|
||||
g_MemoryManager.Free(g_pPersistedData);
|
||||
g_pPersistedData = NULL;
|
||||
}
|
||||
|
||||
g_pPersistedData = CxbxMalloc(640 * 480 * 4);
|
||||
g_pPersistedData = g_MemoryManager.Allocate(640 * 480 * 4);
|
||||
|
||||
#if 0
|
||||
// Get a copy of the front buffer
|
||||
|
@ -115,7 +116,7 @@ XBSYSAPI EXPORTNUM(1) xboxkrnl::PVOID NTAPI xboxkrnl::AvGetSavedDataAddress(void
|
|||
FILE* fp = fopen( "PersistedSurface.bin", "rb" );
|
||||
fseek( fp, 0, SEEK_END );
|
||||
long size = ftell( fp );
|
||||
g_pPersistedData = malloc( size );
|
||||
g_pPersistedData = g_MemoryManager.Allocate( size );
|
||||
fread( g_pPersistedData, size, 1, fp );
|
||||
fclose(fp);
|
||||
}*/
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace xboxkrnl
|
|||
#include "Logging.h" // For LOG_FUNC()
|
||||
#include "EmuEEPROM.h" // For EmuFindEEPROMInfo, EEPROM, XboxFactoryGameRegion
|
||||
#include "EmuKrnlLogging.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
// prevent name collisions
|
||||
namespace NtDll
|
||||
|
@ -126,7 +127,7 @@ XBSYSAPI EXPORTNUM(15) xboxkrnl::PVOID NTAPI xboxkrnl::ExAllocatePoolWithTag
|
|||
LOG_FUNC_ARG(Tag)
|
||||
LOG_FUNC_END;
|
||||
|
||||
PVOID pRet = CxbxCalloc(1, NumberOfBytes); // Clear, to prevent side-effects on random contents
|
||||
PVOID pRet = g_MemoryManager.AllocateZeroed(1, NumberOfBytes); // Clear, to prevent side-effects on random contents
|
||||
|
||||
LOG_INCOMPLETE(); // TODO : Actually implement ExAllocatePoolWithTag
|
||||
|
||||
|
@ -157,7 +158,7 @@ XBSYSAPI EXPORTNUM(17) xboxkrnl::VOID NTAPI xboxkrnl::ExFreePool
|
|||
{
|
||||
LOG_FUNC_ONE_ARG(P);
|
||||
|
||||
CxbxFree(P);
|
||||
g_MemoryManager.Free(P);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
|
|
@ -48,8 +48,9 @@ namespace xboxkrnl
|
|||
#include "EmuKrnlLogging.h"
|
||||
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
||||
#include "Emu.h" // For EmuWarning()
|
||||
#include "EmuAlloc.h" // For CxbxFree(), CxbxMalloc(), etc.
|
||||
#include "EmuAlloc.h" // For CxbxFree(), g_MemoryManager.Allocate(), etc.
|
||||
#include "ResourceTracker.h" // For g_AlignCache
|
||||
#include "MemoryManager.h"
|
||||
|
||||
// prevent name collisions
|
||||
namespace NtDll
|
||||
|
@ -131,22 +132,8 @@ XBSYSAPI EXPORTNUM(166) xboxkrnl::PVOID NTAPI xboxkrnl::MmAllocateContiguousMemo
|
|||
// Allocate when input arguments are valid
|
||||
if (pRet != NULL)
|
||||
{
|
||||
//
|
||||
// NOTE: Kludgey (but necessary) solution:
|
||||
//
|
||||
// Since this memory must be aligned on a page boundary, we must allocate an extra page
|
||||
// so that we can return a valid page aligned pointer
|
||||
//
|
||||
|
||||
// TODO : Allocate differently if(ProtectionType & PAGE_WRITECOMBINE)
|
||||
pRet = CxbxMalloc(NumberOfBytes + Alignment);
|
||||
|
||||
// align to page boundary
|
||||
DWORD dwRet = (DWORD)pRet;
|
||||
|
||||
dwRet += Alignment - dwRet % Alignment;
|
||||
g_AlignCache.insert(dwRet, pRet);
|
||||
pRet = (PVOID)dwRet;
|
||||
pRet = g_MemoryManager.AllocateContiguous(NumberOfBytes, Alignment);
|
||||
}
|
||||
|
||||
RETURN(pRet);
|
||||
|
@ -167,7 +154,7 @@ XBSYSAPI EXPORTNUM(167) xboxkrnl::PVOID NTAPI xboxkrnl::MmAllocateSystemMemory
|
|||
LOG_FUNC_END;
|
||||
|
||||
// TODO: should this be aligned?
|
||||
PVOID pRet = CxbxMalloc(NumberOfBytes);
|
||||
PVOID pRet = g_MemoryManager.Allocate(NumberOfBytes);
|
||||
|
||||
RETURN(pRet);
|
||||
}
|
||||
|
@ -296,27 +283,7 @@ XBSYSAPI EXPORTNUM(171) xboxkrnl::VOID NTAPI xboxkrnl::MmFreeContiguousMemory
|
|||
{
|
||||
LOG_FUNC_ONE_ARG(BaseAddress);
|
||||
|
||||
PVOID OrigBaseAddress = BaseAddress;
|
||||
|
||||
if (g_AlignCache.exists(BaseAddress))
|
||||
{
|
||||
OrigBaseAddress = g_AlignCache.get(BaseAddress);
|
||||
g_AlignCache.remove(BaseAddress);
|
||||
}
|
||||
|
||||
if (OrigBaseAddress == &DefaultLaunchDataPage)
|
||||
{
|
||||
DbgPrintf("Ignored MmFreeContiguousMemory(&DefaultLaunchDataPage)\n");
|
||||
LOG_IGNORED();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO : Free PAGE_WRITECOMBINE differently
|
||||
if (OrigBaseAddress == LaunchDataPage)
|
||||
DbgPrintf("MmFreeContiguousMemory detected a free of LaunchDataPage\n");
|
||||
|
||||
CxbxFree(OrigBaseAddress);
|
||||
}
|
||||
g_MemoryManager.Free(BaseAddress);
|
||||
|
||||
// TODO -oDxbx: Sokoban crashes after this, at reset time (press Black + White to hit this).
|
||||
// Tracing in assembly shows the crash takes place quite a while further, so it's probably
|
||||
|
@ -338,7 +305,7 @@ XBSYSAPI EXPORTNUM(172) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmFreeSystemMemory
|
|||
LOG_FUNC_ARG(NumberOfBytes)
|
||||
LOG_FUNC_END;
|
||||
|
||||
CxbxFree(BaseAddress);
|
||||
g_MemoryManager.Free(BaseAddress);
|
||||
|
||||
RETURN(STATUS_SUCCESS);
|
||||
}
|
||||
|
@ -440,7 +407,7 @@ XBSYSAPI EXPORTNUM(177) xboxkrnl::PVOID NTAPI xboxkrnl::MmMapIoSpace
|
|||
LOG_FUNC_END;
|
||||
|
||||
// TODO: should this be aligned?
|
||||
PVOID pRet = CxbxMalloc(NumberOfBytes);
|
||||
PVOID pRet = g_MemoryManager.Allocate(NumberOfBytes);
|
||||
LOG_INCOMPLETE();
|
||||
|
||||
RETURN(pRet);
|
||||
|
@ -512,8 +479,10 @@ XBSYSAPI EXPORTNUM(179) xboxkrnl::ULONG NTAPI xboxkrnl::MmQueryAddressProtect
|
|||
|
||||
// Assume read/write when page is allocated :
|
||||
ULONG Result = PAGE_NOACCESS;
|
||||
if (EmuCheckAllocationSize(VirtualAddress, false))
|
||||
|
||||
if (g_MemoryManager.IsAllocated(VirtualAddress)) {
|
||||
Result = PAGE_READWRITE;
|
||||
}
|
||||
|
||||
LOG_INCOMPLETE(); // TODO : Improve the MmQueryAddressProtect implementation
|
||||
|
||||
|
@ -532,7 +501,7 @@ XBSYSAPI EXPORTNUM(180) xboxkrnl::ULONG NTAPI xboxkrnl::MmQueryAllocationSize
|
|||
|
||||
LOG_INCOMPLETE(); // TODO : Free PAGE_WRITECOMBINE differently
|
||||
|
||||
ULONG uiSize = EmuCheckAllocationSize(BaseAddress, false);
|
||||
ULONG uiSize = g_MemoryManager.QueryAllocationSize(BaseAddress);
|
||||
|
||||
RETURN(uiSize);
|
||||
}
|
||||
|
@ -634,7 +603,7 @@ XBSYSAPI EXPORTNUM(183) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmUnmapIoSpace
|
|||
LOG_FUNC_ARG(NumberOfBytes)
|
||||
LOG_FUNC_END;
|
||||
|
||||
CxbxFree(BaseAddress);
|
||||
g_MemoryManager.Free(BaseAddress);
|
||||
LOG_INCOMPLETE();
|
||||
|
||||
RETURN(STATUS_SUCCESS);
|
||||
|
|
|
@ -55,7 +55,8 @@ namespace NtDll
|
|||
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
||||
#include "Emu.h" // For EmuWarning()
|
||||
#include "EmuFile.h" // For EmuNtSymbolicLinkObject, NtStatusToString(), etc.
|
||||
#include "EmuAlloc.h" // For CxbxFree(), CxbxMalloc(), etc.
|
||||
#include "EmuAlloc.h" // For CxbxFree(), g_MemoryManager.Allocate(), etc.
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#pragma warning(disable:4005) // Ignore redefined status values
|
||||
#include <ntstatus.h>
|
||||
|
@ -985,7 +986,7 @@ XBSYSAPI EXPORTNUM(207) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryDirectoryFile
|
|||
}
|
||||
|
||||
NtDll::FILE_DIRECTORY_INFORMATION *NtFileDirInfo =
|
||||
(NtDll::FILE_DIRECTORY_INFORMATION *) CxbxMalloc(NtFileDirectoryInformationSize + NtPathBufferSize);
|
||||
(NtDll::FILE_DIRECTORY_INFORMATION *) g_MemoryManager.Allocate(NtFileDirectoryInformationSize + NtPathBufferSize);
|
||||
|
||||
// Short-hand pointer to Nt filename :
|
||||
wchar_t *wcstr = NtFileDirInfo->FileName;
|
||||
|
@ -1024,7 +1025,7 @@ XBSYSAPI EXPORTNUM(207) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryDirectoryFile
|
|||
}
|
||||
|
||||
// TODO: Cache the last search result for quicker access with CreateFile (xbox does this internally!)
|
||||
CxbxFree(NtFileDirInfo);
|
||||
g_MemoryManager.Free(NtFileDirInfo);
|
||||
|
||||
RETURN(ret);
|
||||
}
|
||||
|
@ -1122,7 +1123,7 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil
|
|||
// We need to retry the operation in case the buffer is too small to fit the data
|
||||
do
|
||||
{
|
||||
ntFileInfo = CxbxMalloc(bufferSize);
|
||||
ntFileInfo = g_MemoryManager.Allocate(bufferSize);
|
||||
|
||||
ret = NtDll::NtQueryInformationFile(
|
||||
FileHandle,
|
||||
|
@ -1134,14 +1135,14 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil
|
|||
// Buffer is too small; make a larger one
|
||||
if (ret == STATUS_BUFFER_OVERFLOW)
|
||||
{
|
||||
CxbxFree(ntFileInfo);
|
||||
g_MemoryManager.Free(ntFileInfo);
|
||||
|
||||
bufferSize *= 2;
|
||||
// Bail out if the buffer gets too big
|
||||
if (bufferSize > 65536)
|
||||
return STATUS_INVALID_PARAMETER; // TODO: what's the appropriate error code to return here?
|
||||
|
||||
ntFileInfo = CxbxMalloc(bufferSize);
|
||||
ntFileInfo = g_MemoryManager.Allocate(bufferSize);
|
||||
}
|
||||
} while (ret == STATUS_BUFFER_OVERFLOW);
|
||||
|
||||
|
@ -1149,7 +1150,7 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil
|
|||
NTSTATUS convRet = NTToXboxFileInformation(ntFileInfo, FileInformation, FileInformationClass, Length);
|
||||
|
||||
// Make sure to free the memory first
|
||||
CxbxFree(ntFileInfo);
|
||||
g_MemoryManager.Free(ntFileInfo);
|
||||
|
||||
if (FAILED(ret))
|
||||
EmuWarning("NtQueryInformationFile failed! (0x%.08X)", ret);
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace xboxkrnl
|
|||
#include "EmuShared.h"
|
||||
#include "EmuAlloc.h"
|
||||
#include "EmuXTL.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#include <mmreg.h>
|
||||
#include <msacm.h>
|
||||
|
@ -78,7 +79,7 @@ HRESULT WINAPI XTL::EMUPATCH(XACTEngineCreate)
|
|||
|
||||
// TODO: Any other form of initialization?
|
||||
|
||||
*ppEngine = (X_XACTEngine*) CxbxCalloc(1, sizeof( X_XACTEngine ) );
|
||||
*ppEngine = (X_XACTEngine*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTEngine ) );
|
||||
|
||||
|
||||
|
||||
|
@ -122,7 +123,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_RegisterWaveBank)
|
|||
|
||||
// TODO: Implement
|
||||
|
||||
*ppWaveBank = (X_XACTWaveBank*) CxbxCalloc(1, sizeof( X_XACTWaveBank ) );
|
||||
*ppWaveBank = (X_XACTWaveBank*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTWaveBank ) );
|
||||
|
||||
RETURN(S_OK);
|
||||
}
|
||||
|
@ -145,7 +146,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_RegisterStreamedWaveBank)
|
|||
|
||||
// TODO: Implement
|
||||
|
||||
*ppWaveBank = (X_XACTWaveBank*) CxbxCalloc(1, sizeof( X_XACTWaveBank ) );
|
||||
*ppWaveBank = (X_XACTWaveBank*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTWaveBank ) );
|
||||
|
||||
RETURN(S_OK);
|
||||
}
|
||||
|
@ -170,7 +171,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_CreateSoundBank)
|
|||
|
||||
// TODO: Implement
|
||||
|
||||
*ppSoundBank = (X_XACTSoundBank*) CxbxCalloc(1, sizeof( X_XACTSoundBank ) );
|
||||
*ppSoundBank = (X_XACTSoundBank*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTSoundBank ) );
|
||||
|
||||
RETURN(S_OK);
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_CreateSoundSource)
|
|||
LOG_FUNC_ARG(ppSoundSource)
|
||||
LOG_FUNC_END;
|
||||
|
||||
*ppSoundSource = (X_XACTSoundSource*) CxbxCalloc(1, sizeof( X_XACTSoundSource ) );
|
||||
*ppSoundSource = (X_XACTSoundSource*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTSoundSource ) );
|
||||
|
||||
RETURN(S_OK);
|
||||
}
|
||||
|
@ -513,7 +514,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_UnRegisterWaveBank)
|
|||
// to IXACTWaveBank is released.
|
||||
|
||||
// if(pWaveBank)
|
||||
// free(pWaveBank);
|
||||
// g_MemoryManager.Free(pWaveBank);
|
||||
|
||||
RETURN(S_OK);
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->MemoryManager.cpp
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
|
||||
#include "CxbxKrnl.h"
|
||||
#include "Emu.h"
|
||||
#include "Logging.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
MemoryManager g_MemoryManager;
|
||||
|
||||
MemoryManager::MemoryManager()
|
||||
{
|
||||
InitializeCriticalSectionAndSpinCount(&m_CriticalSection, 0x400);
|
||||
}
|
||||
|
||||
MemoryManager::~MemoryManager()
|
||||
{
|
||||
DeleteCriticalSection(&m_CriticalSection);
|
||||
}
|
||||
|
||||
void* MemoryManager::Allocate(size_t size)
|
||||
{
|
||||
LOG_FUNC_ONE_ARG(size);
|
||||
|
||||
EnterCriticalSection(&m_CriticalSection);
|
||||
|
||||
void* ptr = malloc(size);
|
||||
MemoryBlockInfo info;
|
||||
info.offset = (uint32_t)ptr;
|
||||
info.size = size;
|
||||
info.type = MemoryType::STANDARD;
|
||||
|
||||
m_MemoryBlockInfo[info.offset] = info;
|
||||
|
||||
LeaveCriticalSection(&m_CriticalSection);
|
||||
|
||||
RETURN(ptr);
|
||||
}
|
||||
|
||||
void* MemoryManager::AllocateAligned(size_t size, size_t alignment)
|
||||
{
|
||||
LOG_FUNC_BEGIN
|
||||
LOG_FUNC_ARG(size);
|
||||
LOG_FUNC_ARG(alignment);
|
||||
LOG_FUNC_END;
|
||||
|
||||
EnterCriticalSection(&m_CriticalSection);
|
||||
|
||||
void* ptr = _aligned_malloc(size, alignment);
|
||||
MemoryBlockInfo info;
|
||||
info.offset = (uint32_t)ptr;
|
||||
info.size = size;
|
||||
info.type = MemoryType::ALIGNED;
|
||||
|
||||
m_MemoryBlockInfo[info.offset] = info;
|
||||
|
||||
LeaveCriticalSection(&m_CriticalSection);
|
||||
|
||||
|
||||
RETURN(ptr);
|
||||
}
|
||||
|
||||
void* MemoryManager::AllocateContiguous(size_t size, size_t alignment)
|
||||
{
|
||||
LOG_FUNC_BEGIN
|
||||
LOG_FUNC_ARG(size);
|
||||
LOG_FUNC_ARG(alignment);
|
||||
LOG_FUNC_END;
|
||||
|
||||
|
||||
EnterCriticalSection(&m_CriticalSection);
|
||||
|
||||
size = (size + alignment) + (size % alignment);
|
||||
uint32_t addr = NULL;
|
||||
|
||||
// If the allocation table is empty, we can allocate wherever we please
|
||||
if (m_ContiguousMemoryRegions.size() == 0) {
|
||||
addr = MM_SYSTEM_PHYSICAL_MAP;
|
||||
} else {
|
||||
for (auto it = m_ContiguousMemoryRegions.begin(); it != m_ContiguousMemoryRegions.end(); ++it) {
|
||||
ContiguousMemoryRegion current = it->second;
|
||||
|
||||
if (std::next(it) == m_ContiguousMemoryRegions.end()) {
|
||||
addr = current.offset + current.size;
|
||||
break;
|
||||
}
|
||||
|
||||
ContiguousMemoryRegion next = std::next(it)->second;
|
||||
if (((current.offset + current.size + size) < next.offset)) {
|
||||
addr = current.offset + current.size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addr + size > MM_SYSTEM_PHYSICAL_MAP + CONTIGUOUS_MEMORY_SIZE) {
|
||||
EmuWarning("MemoryManager::AllocateContiguous exausted it's allowed memory buffer");
|
||||
addr = NULL;
|
||||
}
|
||||
|
||||
if (addr != NULL) {
|
||||
ContiguousMemoryRegion region;
|
||||
region.offset = addr;
|
||||
region.size = size;
|
||||
m_ContiguousMemoryRegions[addr] = region;
|
||||
|
||||
MemoryBlockInfo info;
|
||||
info.type = MemoryType::CONTIGUOUS;
|
||||
info.offset = region.offset;
|
||||
info.size = region.size;
|
||||
m_MemoryBlockInfo[addr] = info;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&m_CriticalSection);
|
||||
RETURN((void*)addr);
|
||||
}
|
||||
|
||||
void* MemoryManager::AllocateZeroed(size_t num, size_t size)
|
||||
{
|
||||
void* buffer = Allocate(num * size);
|
||||
memset(buffer, 0, num * size);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool MemoryManager::IsAllocated(void* block)
|
||||
{
|
||||
return m_MemoryBlockInfo.find((uint32_t)block) != m_MemoryBlockInfo.end();
|
||||
}
|
||||
|
||||
void MemoryManager::Free(void* block)
|
||||
{
|
||||
LOG_FUNC_ONE_ARG(block);
|
||||
|
||||
if (IsAllocated(block)) {
|
||||
EnterCriticalSection(&m_CriticalSection);
|
||||
MemoryBlockInfo info = m_MemoryBlockInfo[info.offset];
|
||||
switch (info.type) {
|
||||
case MemoryType::ALIGNED:
|
||||
_aligned_free((void*)info.offset);
|
||||
m_MemoryBlockInfo.erase(info.offset);
|
||||
break;
|
||||
case MemoryType::STANDARD:
|
||||
free((void*)info.offset);
|
||||
m_MemoryBlockInfo.erase(info.offset);
|
||||
break;
|
||||
case MemoryType::CONTIGUOUS:
|
||||
m_ContiguousMemoryRegions.erase(info.offset);
|
||||
m_MemoryBlockInfo.erase(info.offset);
|
||||
break;
|
||||
default:
|
||||
CxbxKrnlCleanup("Fatal: MemoryManager attempted to free memory of an unknown type");
|
||||
break;
|
||||
}
|
||||
LeaveCriticalSection(&m_CriticalSection);
|
||||
return;
|
||||
}
|
||||
|
||||
CxbxKrnlCleanup("Fatal: Attempted to free memory that was not allocated via MemoryManager");
|
||||
}
|
||||
|
||||
size_t MemoryManager::QueryAllocationSize(void* block)
|
||||
{
|
||||
LOG_FUNC_ONE_ARG(block);
|
||||
|
||||
if (IsAllocated(block)) {
|
||||
MemoryBlockInfo info = m_MemoryBlockInfo[info.offset];
|
||||
RETURN(info.size);
|
||||
}
|
||||
|
||||
CxbxKrnlCleanup("Fatal: Attempted to query memory that was not allocated via MemoryManager");
|
||||
|
||||
// Never reached
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->MemoryManager.h
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
|
||||
#ifndef MEMORY_MANAGER_H
|
||||
#define MEMORY_MANAGER_H
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
// Define virtual base and alternate virtual base of kernel.
|
||||
#define KSEG0_BASE 0x80000000
|
||||
// Define virtual base addresses for physical memory windows.
|
||||
#define MM_SYSTEM_PHYSICAL_MAP KSEG0_BASE
|
||||
#define MM_HIGHEST_PHYSICAL_PAGE 0x07FFF
|
||||
#define MM_64M_PHYSICAL_PAGE 0x04000
|
||||
#define MM_INSTANCE_PHYSICAL_PAGE 0x03FE0 // Chihiro arcade should use 0x07FF0
|
||||
#define MM_INSTANCE_PAGE_COUNT 16
|
||||
#define CONTIGUOUS_MEMORY_SIZE (64 * ONE_MB)
|
||||
|
||||
enum struct MemoryType {
|
||||
STANDARD = 0,
|
||||
ALIGNED,
|
||||
CONTIGUOUS
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
MemoryType type;
|
||||
uint32_t offset;
|
||||
size_t size;
|
||||
} MemoryBlockInfo;
|
||||
|
||||
typedef struct {
|
||||
uint32_t offset;
|
||||
size_t size;
|
||||
} ContiguousMemoryRegion;
|
||||
|
||||
class MemoryManager
|
||||
{
|
||||
public:
|
||||
MemoryManager();
|
||||
~MemoryManager();
|
||||
void* Allocate(size_t size);
|
||||
void* AllocateAligned(size_t size, size_t alignment);
|
||||
void* AllocateContiguous(size_t size, size_t alignment);
|
||||
void* AllocateZeroed(size_t num, size_t size);
|
||||
bool IsAllocated(void* block);
|
||||
void Free(void* block);
|
||||
size_t QueryAllocationSize(void* block);
|
||||
private:
|
||||
std::unordered_map<uint32_t, MemoryBlockInfo> m_MemoryBlockInfo;
|
||||
std::map<uint32_t, ContiguousMemoryRegion> m_ContiguousMemoryRegions;
|
||||
CRITICAL_SECTION m_CriticalSection;
|
||||
};
|
||||
|
||||
extern MemoryManager g_MemoryManager;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue