Merge pull request #264 from LukeUsher/memory-manager
Initial Memory Manager implementation
This commit is contained in:
commit
54be6c85a5
|
@ -281,6 +281,7 @@ $(SOLUTIONDIR)Export.bat</Command>
|
||||||
<ClInclude Include="..\..\src\CxbxKrnl\HLEDataBase\XOnline.1.0.5849.h" />
|
<ClInclude Include="..\..\src\CxbxKrnl\HLEDataBase\XOnline.1.0.5849.h" />
|
||||||
<ClInclude Include="..\..\src\CxbxKrnl\HLEIntercept.h" />
|
<ClInclude Include="..\..\src\CxbxKrnl\HLEIntercept.h" />
|
||||||
<ClInclude Include="..\..\src\CxbxKrnl\LibRc4.h" />
|
<ClInclude Include="..\..\src\CxbxKrnl\LibRc4.h" />
|
||||||
|
<ClInclude Include="..\..\src\CxbxKrnl\MemoryManager.h" />
|
||||||
<ClInclude Include="..\..\src\CxbxKrnl\nv2a_int.h" />
|
<ClInclude Include="..\..\src\CxbxKrnl\nv2a_int.h" />
|
||||||
<ClInclude Include="..\..\src\CxbxKrnl\OOVPA.h" />
|
<ClInclude Include="..\..\src\CxbxKrnl\OOVPA.h" />
|
||||||
<ClInclude Include="..\..\src\CxbxKrnl\ReservedMemory.h" />
|
<ClInclude Include="..\..\src\CxbxKrnl\ReservedMemory.h" />
|
||||||
|
@ -537,6 +538,7 @@ $(SOLUTIONDIR)Export.bat</Command>
|
||||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\CxbxKrnl\LibRc4.cpp" />
|
<ClCompile Include="..\..\src\CxbxKrnl\LibRc4.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\CxbxKrnl\MemoryManager.cpp" />
|
||||||
<ClCompile Include="..\..\src\CxbxKrnl\ResourceTracker.cpp">
|
<ClCompile Include="..\..\src\CxbxKrnl\ResourceTracker.cpp">
|
||||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
|
|
@ -196,6 +196,9 @@
|
||||||
<ClCompile Include="..\..\src\Common\EmuEEPROM.cpp">
|
<ClCompile Include="..\..\src\Common\EmuEEPROM.cpp">
|
||||||
<Filter>Shared</Filter>
|
<Filter>Shared</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\CxbxKrnl\MemoryManager.cpp">
|
||||||
|
<Filter>Emulator</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\Cxbx\DlgControllerConfig.h">
|
<ClInclude Include="..\..\src\Cxbx\DlgControllerConfig.h">
|
||||||
|
@ -543,6 +546,9 @@
|
||||||
<ClInclude Include="..\..\src\CxbxVersion.h">
|
<ClInclude Include="..\..\src\CxbxVersion.h">
|
||||||
<Filter>Shared</Filter>
|
<Filter>Shared</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\CxbxKrnl\MemoryManager.h">
|
||||||
|
<Filter>Emulator</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\resource\About.jpg">
|
<None Include="..\..\resource\About.jpg">
|
||||||
|
|
|
@ -224,18 +224,6 @@ typedef long NTSTATUS;
|
||||||
// * memory
|
// * 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
|
#define PAGE_SHIFT 12
|
||||||
|
|
||||||
// Xbox pages are (1 << 12) = 0x00001000 = 4096 bytes in size.
|
// Xbox pages are (1 << 12) = 0x00001000 = 4096 bytes in size.
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace xboxkrnl
|
||||||
#include "EmuNV2A.h" // For InitOpenGLContext
|
#include "EmuNV2A.h" // For InitOpenGLContext
|
||||||
#include "HLEIntercept.h"
|
#include "HLEIntercept.h"
|
||||||
#include "ReservedMemory.h" // For virtual_memory_placeholder
|
#include "ReservedMemory.h" // For virtual_memory_placeholder
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
|
@ -226,8 +227,6 @@ void RestoreExeImageHeader()
|
||||||
ExeOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] = NewOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS];
|
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)
|
void *CxbxRestoreContiguousMemory(char *szFilePath_memory_bin)
|
||||||
{
|
{
|
||||||
// First, try to open an existing memory.bin file :
|
// First, try to open an existing memory.bin file :
|
||||||
|
@ -570,14 +569,6 @@ void CxbxKrnlInit
|
||||||
{
|
{
|
||||||
// Create a fake kernel header for XapiRestrictCodeSelectorLimit
|
// Create a fake kernel header for XapiRestrictCodeSelectorLimit
|
||||||
// Thanks advancingdragon / DirtBox
|
// Thanks advancingdragon / DirtBox
|
||||||
typedef struct DUMMY_KERNEL
|
|
||||||
{
|
|
||||||
IMAGE_DOS_HEADER DosHeader;
|
|
||||||
DWORD Signature;
|
|
||||||
IMAGE_FILE_HEADER FileHeader;
|
|
||||||
IMAGE_SECTION_HEADER SectionHeader;
|
|
||||||
} *PDUMMY_KERNEL;
|
|
||||||
|
|
||||||
PDUMMY_KERNEL DummyKernel = (PDUMMY_KERNEL)XBOX_KERNEL_BASE;
|
PDUMMY_KERNEL DummyKernel = (PDUMMY_KERNEL)XBOX_KERNEL_BASE;
|
||||||
memset(DummyKernel, 0, sizeof(DUMMY_KERNEL));
|
memset(DummyKernel, 0, sizeof(DUMMY_KERNEL));
|
||||||
|
|
||||||
|
@ -661,7 +652,7 @@ void CxbxKrnlInit
|
||||||
|
|
||||||
// Assign the running Xbe path, so it can be accessed via the kernel thunk 'XeImageFileName' :
|
// Assign the running Xbe path, so it can be accessed via the kernel thunk 'XeImageFileName' :
|
||||||
xboxkrnl::XeImageFileName.MaximumLength = MAX_PATH;
|
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());
|
sprintf(xboxkrnl::XeImageFileName.Buffer, "%c:\\%s", CxbxDefaultXbeDriveLetter, fileName.c_str());
|
||||||
xboxkrnl::XeImageFileName.Length = (USHORT)strlen(xboxkrnl::XeImageFileName.Buffer);
|
xboxkrnl::XeImageFileName.Length = (USHORT)strlen(xboxkrnl::XeImageFileName.Buffer);
|
||||||
DbgPrintf("EmuMain : XeImageFileName = %s\n", 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;
|
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 :)
|
// exception handle for that tough final exit :)
|
||||||
int ExitException(LPEXCEPTION_POINTERS e)
|
int ExitException(LPEXCEPTION_POINTERS e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,9 +50,6 @@ inline void NTAPI EmuWarning(const char *szWarningMessage, ...) { }
|
||||||
// exception handler
|
// exception handler
|
||||||
extern int EmuException(LPEXCEPTION_POINTERS e);
|
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
|
// print call stack trace
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
void EmuPrintStackTrace(PCONTEXT ContextRecord);
|
void EmuPrintStackTrace(PCONTEXT ContextRecord);
|
||||||
|
@ -102,4 +99,12 @@ extern HANDLE g_hInputHandle[XINPUT_HANDLE_SLOTS];
|
||||||
|
|
||||||
extern void InitializeSectionStructures(void);
|
extern void InitializeSectionStructures(void);
|
||||||
|
|
||||||
|
typedef struct DUMMY_KERNEL
|
||||||
|
{
|
||||||
|
IMAGE_DOS_HEADER DosHeader;
|
||||||
|
DWORD Signature;
|
||||||
|
IMAGE_FILE_HEADER FileHeader;
|
||||||
|
IMAGE_SECTION_HEADER SectionHeader;
|
||||||
|
} *PDUMMY_KERNEL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#ifdef _DEBUG_ALLOC
|
#ifdef _DEBUG_ALLOC
|
||||||
#define CxbxMalloc(Size) CxbxMallocDebug(Size, __FILE__, __LINE__)
|
#define CxbxMalloc(Size) CxbxMallocDebug(Size, __FILE__, __LINE__)
|
||||||
#define CxbxCalloc(Num, Size) CxbxCallocDebug(Num, 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 CxbxRtlAlloc(Heap, Flags, Bytes) CxbxRtlAllocDebug(Heap, Flags, Bytes, __FILE__, __LINE__)
|
||||||
#define CxbxRtlFree(Heap, Flags, pMem) CxbxRtlFreeDebug(Heap, Flags, pMem, __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__)
|
#define CxbxRtlRealloc(Heap, Flags, pMem, Bytes) CxbxRtlReallocDebug(Heap, Flags, pMem, Bytes, __FILE__, __LINE__)
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace xboxkrnl
|
||||||
#include "DbgConsole.h"
|
#include "DbgConsole.h"
|
||||||
#include "ResourceTracker.h"
|
#include "ResourceTracker.h"
|
||||||
#include "EmuAlloc.h"
|
#include "EmuAlloc.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
#include "EmuXTL.h"
|
#include "EmuXTL.h"
|
||||||
|
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
|
@ -272,49 +273,49 @@ int GetD3DResourceRefCount(XTL::IDirect3DResource8 *EmuResource)
|
||||||
|
|
||||||
XTL::X_D3DSurface *EmuNewD3DSurface()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_SURFACE | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::X_D3DTexture *EmuNewD3DTexture()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::X_D3DVolumeTexture *EmuNewD3DVolumeTexture()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::X_D3DCubeTexture *EmuNewD3DCubeTexture()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::X_D3DIndexBuffer *EmuNewD3DIndexBuffer()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_INDEXBUFFER | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::X_D3DVertexBuffer *EmuNewD3DVertexBuffer()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_VERTEXBUFFER | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
XTL::X_D3DPalette *EmuNewD3DPalette()
|
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
|
result->Common = X_D3DCOMMON_D3DCREATED | X_D3DCOMMON_TYPE_PALETTE | 1; // Set refcount to 1
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1056,7 +1057,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
|
||||||
DWORD *lpCodes = 0;
|
DWORD *lpCodes = 0;
|
||||||
|
|
||||||
g_pDD7->GetFourCCCodes(&dwCodes, lpCodes);
|
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_pDD7->GetFourCCCodes(&dwCodes, lpCodes);
|
||||||
g_bSupportsYUY2 = false;
|
g_bSupportsYUY2 = false;
|
||||||
for(DWORD v=0;v<dwCodes;v++)
|
for(DWORD v=0;v<dwCodes;v++)
|
||||||
|
@ -1068,7 +1069,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CxbxFree(lpCodes);
|
g_MemoryManager.Free(lpCodes);
|
||||||
if(!g_bSupportsYUY2)
|
if(!g_bSupportsYUY2)
|
||||||
EmuWarning("YUY2 overlays are not supported in hardware, could be slow!");
|
EmuWarning("YUY2 overlays are not supported in hardware, could be slow!");
|
||||||
else
|
else
|
||||||
|
@ -1338,7 +1339,7 @@ static void EmuUnswizzleTextureStages()
|
||||||
RECT iRect = {0,0,0,0};
|
RECT iRect = {0,0,0,0};
|
||||||
POINT iPoint = {0,0};
|
POINT iPoint = {0,0};
|
||||||
|
|
||||||
void *pTemp = malloc(dwHeight*dwPitch);
|
void *pTemp = g_MemoryManager.Allocate(dwHeight*dwPitch);
|
||||||
|
|
||||||
XTL::EmuUnswizzleRect
|
XTL::EmuUnswizzleRect
|
||||||
(
|
(
|
||||||
|
@ -1350,7 +1351,7 @@ static void EmuUnswizzleTextureStages()
|
||||||
|
|
||||||
pTexture->UnlockRect(0);
|
pTexture->UnlockRect(0);
|
||||||
|
|
||||||
free(pTemp);
|
g_MemoryManager.Free(pTemp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2059,7 +2060,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_GetGammaRamp)
|
||||||
");\n",
|
");\n",
|
||||||
pRamp);
|
pRamp);
|
||||||
|
|
||||||
D3DGAMMARAMP *pGammaRamp = (D3DGAMMARAMP *)malloc(sizeof(D3DGAMMARAMP));
|
D3DGAMMARAMP *pGammaRamp = (D3DGAMMARAMP *)g_MemoryManager.Allocate(sizeof(D3DGAMMARAMP));
|
||||||
|
|
||||||
g_pD3DDevice8->GetGammaRamp(pGammaRamp);
|
g_pD3DDevice8->GetGammaRamp(pGammaRamp);
|
||||||
|
|
||||||
|
@ -2070,7 +2071,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_GetGammaRamp)
|
||||||
pRamp->blue[v] = (BYTE)pGammaRamp->blue[v];
|
pRamp->blue[v] = (BYTE)pGammaRamp->blue[v];
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pGammaRamp);
|
g_MemoryManager.Free(pGammaRamp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2501,8 +2502,8 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
|
||||||
pDeclaration, pFunction, pHandle, Usage);
|
pDeclaration, pFunction, pHandle, Usage);
|
||||||
|
|
||||||
// create emulated shader struct
|
// create emulated shader struct
|
||||||
X_D3DVertexShader *pD3DVertexShader = (X_D3DVertexShader*)CxbxCalloc(1, sizeof(X_D3DVertexShader));
|
X_D3DVertexShader *pD3DVertexShader = (X_D3DVertexShader*)g_MemoryManager.AllocateZeroed(1, sizeof(X_D3DVertexShader));
|
||||||
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER*)CxbxCalloc(1, sizeof(VERTEX_SHADER));
|
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER*)g_MemoryManager.AllocateZeroed(1, sizeof(VERTEX_SHADER));
|
||||||
|
|
||||||
// TODO: Intelligently fill out these fields as necessary
|
// TODO: Intelligently fill out these fields as necessary
|
||||||
|
|
||||||
|
@ -2598,9 +2599,9 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
|
||||||
// Save the status, to remove things later
|
// Save the status, to remove things later
|
||||||
pVertexShader->Status = hRet;
|
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);
|
memcpy(pVertexShader->pDeclaration, pDeclaration, DeclarationSize);
|
||||||
|
|
||||||
pVertexShader->FunctionSize = 0;
|
pVertexShader->FunctionSize = 0;
|
||||||
|
@ -2613,7 +2614,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
|
||||||
{
|
{
|
||||||
if(pFunction != NULL)
|
if(pFunction != NULL)
|
||||||
{
|
{
|
||||||
pVertexShader->pFunction = (DWORD*)CxbxMalloc(VertexShaderSize);
|
pVertexShader->pFunction = (DWORD*)g_MemoryManager.Allocate(VertexShaderSize);
|
||||||
memcpy(pVertexShader->pFunction, pFunction, VertexShaderSize);
|
memcpy(pVertexShader->pFunction, pFunction, VertexShaderSize);
|
||||||
pVertexShader->FunctionSize = VertexShaderSize;
|
pVertexShader->FunctionSize = VertexShaderSize;
|
||||||
}
|
}
|
||||||
|
@ -2860,7 +2861,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DeletePixelShader)
|
||||||
{
|
{
|
||||||
g_pD3DDevice8->DeletePixelShader(pPixelShader->Handle);
|
g_pD3DDevice8->DeletePixelShader(pPixelShader->Handle);
|
||||||
}
|
}
|
||||||
CxbxFree(pPixelShader);
|
g_MemoryManager.Free(pPixelShader);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -2915,7 +2916,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreatePixelShader)
|
||||||
// CreatePixelShader() is expected to return a pHandle directly to a shader interface.
|
// 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));
|
memcpy(&pPixelShader->PSDef, pPSDef, sizeof(X_D3DPIXELSHADERDEF));
|
||||||
|
|
||||||
|
@ -3146,7 +3147,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateTexture)
|
||||||
{
|
{
|
||||||
// If YUY2 is not supported in hardware, we'll actually mark this as a special fake texture
|
// If YUY2 is not supported in hardware, we'll actually mark this as a special fake texture
|
||||||
Texture_Data = X_D3DRESOURCE_DATA_YUV_SURFACE;
|
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;
|
g_pCachedYuvSurface = (X_D3DSurface*)pTexture;
|
||||||
|
|
||||||
|
@ -3283,7 +3284,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVolumeTexture)
|
||||||
{
|
{
|
||||||
// If YUY2 is not supported in hardware, we'll actually mark this as a special fake texture
|
// 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)->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)->Format = Format << X_D3DFORMAT_FORMAT_SHIFT;
|
||||||
|
|
||||||
(*ppVolumeTexture)->Size = (g_dwOverlayW & X_D3DSIZE_WIDTH_MASK)
|
(*ppVolumeTexture)->Size = (g_dwOverlayW & X_D3DSIZE_WIDTH_MASK)
|
||||||
|
@ -3784,7 +3785,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Begin)
|
||||||
|
|
||||||
if(g_IVBTable == 0)
|
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;
|
g_IVBTblOffs = 0;
|
||||||
|
@ -3795,7 +3796,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Begin)
|
||||||
|
|
||||||
if(g_pIVBVertexBuffer == 0)
|
if(g_pIVBVertexBuffer == 0)
|
||||||
{
|
{
|
||||||
g_pIVBVertexBuffer = (DWORD*)CxbxMalloc(sizeof(XTL::_D3DIVB)*1024);
|
g_pIVBVertexBuffer = (DWORD*)g_MemoryManager.Allocate(sizeof(XTL::_D3DIVB)*1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4137,8 +4138,8 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_End)()
|
||||||
EmuFlushIVB();
|
EmuFlushIVB();
|
||||||
|
|
||||||
// TODO: Should technically clean this up at some point..but on XP doesnt matter much
|
// TODO: Should technically clean this up at some point..but on XP doesnt matter much
|
||||||
// CxbxFree(g_pIVBVertexBuffer);
|
// g_MemoryManager.Free(g_pIVBVertexBuffer);
|
||||||
// CxbxFree(g_IVBTable);
|
// g_MemoryManager.Free(g_IVBTable);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -4424,7 +4425,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
|
|
||||||
// create vertex buffer
|
// create vertex buffer
|
||||||
{
|
{
|
||||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||||
|
|
||||||
if(dwSize == -1)
|
if(dwSize == -1)
|
||||||
{
|
{
|
||||||
|
@ -4483,7 +4484,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
|
|
||||||
// create index buffer
|
// create index buffer
|
||||||
{
|
{
|
||||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||||
|
|
||||||
if(dwSize == -1 || dwSize == 0)
|
if(dwSize == -1 || dwSize == 0)
|
||||||
{
|
{
|
||||||
|
@ -4535,7 +4536,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
|
|
||||||
// create push buffer
|
// create push buffer
|
||||||
{
|
{
|
||||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||||
|
|
||||||
if(dwSize == -1)
|
if(dwSize == -1)
|
||||||
{
|
{
|
||||||
|
@ -4685,7 +4686,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
// TODO : Do we actually need to set these?
|
// TODO : Do we actually need to set these?
|
||||||
pPixelContainer->Common = X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
pPixelContainer->Common = X_D3DCOMMON_TYPE_TEXTURE | 1; // Set refcount to 1
|
||||||
pPixelContainer->Data = X_D3DRESOURCE_DATA_YUV_SURFACE;
|
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->Format = (X_D3DFMT_YUY2 << X_D3DFORMAT_FORMAT_SHIFT);
|
||||||
|
|
||||||
pPixelContainer->Size = (g_dwOverlayW & X_D3DSIZE_WIDTH_MASK);
|
pPixelContainer->Size = (g_dwOverlayW & X_D3DSIZE_WIDTH_MASK);
|
||||||
|
@ -4883,7 +4884,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
|
|
||||||
BYTE *pPixelData = (BYTE*)LockedRect.pBits;
|
BYTE *pPixelData = (BYTE*)LockedRect.pBits;
|
||||||
DWORD dwDataSize = dwMipWidth*dwMipHeight;
|
DWORD dwDataSize = dwMipWidth*dwMipHeight;
|
||||||
DWORD* pExpandedTexture = (DWORD*)CxbxMalloc(dwDataSize * sizeof(DWORD));
|
DWORD* pExpandedTexture = (DWORD*)g_MemoryManager.Allocate(dwDataSize * sizeof(DWORD));
|
||||||
DWORD* pTexturePalette = (DWORD*)pCurrentPalette;
|
DWORD* pTexturePalette = (DWORD*)pCurrentPalette;
|
||||||
|
|
||||||
//__asm int 3;
|
//__asm int 3;
|
||||||
|
@ -4917,7 +4918,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
memcpy(pPixelData, pExpandedTexture, dwDataSize * sizeof(DWORD));
|
memcpy(pPixelData, pExpandedTexture, dwDataSize * sizeof(DWORD));
|
||||||
|
|
||||||
// Flush unused data buffers
|
// Flush unused data buffers
|
||||||
CxbxFree(pExpandedTexture);
|
g_MemoryManager.Free(pExpandedTexture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5026,7 +5027,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DResource_Register)
|
||||||
|
|
||||||
// create palette
|
// create palette
|
||||||
{
|
{
|
||||||
DWORD dwSize = EmuCheckAllocationSize(pBase, true);
|
DWORD dwSize = g_MemoryManager.QueryAllocationSize(pBase);
|
||||||
|
|
||||||
if(dwSize == -1)
|
if(dwSize == -1)
|
||||||
{
|
{
|
||||||
|
@ -5140,7 +5141,7 @@ ULONG WINAPI XTL::EMUPATCH(D3DResource_Release)
|
||||||
g_pCachedYuvSurface = NULL;
|
g_pCachedYuvSurface = NULL;
|
||||||
|
|
||||||
// free memory associated with this special resource handle
|
// free memory associated with this special resource handle
|
||||||
CxbxFree((PVOID)pThis->Lock);
|
g_MemoryManager.Free((PVOID)pThis->Lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
EMUPATCH(D3DDevice_EnableOverlay)(FALSE);
|
EMUPATCH(D3DDevice_EnableOverlay)(FALSE);
|
||||||
|
@ -8267,7 +8268,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_SetPalette)
|
||||||
if( pPalette->Data )
|
if( pPalette->Data )
|
||||||
{
|
{
|
||||||
pCurrentPalette = (LPVOID) pPalette->Data;
|
pCurrentPalette = (LPVOID) pPalette->Data;
|
||||||
dwCurrentPaletteSize = EmuCheckAllocationSize( (LPVOID) pPalette->Data, false );
|
dwCurrentPaletteSize = g_MemoryManager.QueryAllocationSize((LPVOID)pPalette->Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8434,17 +8435,17 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DeleteVertexShader)
|
||||||
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER *)pD3DVertexShader->Handle;
|
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER *)pD3DVertexShader->Handle;
|
||||||
|
|
||||||
RealHandle = pVertexShader->Handle;
|
RealHandle = pVertexShader->Handle;
|
||||||
CxbxFree(pVertexShader->pDeclaration);
|
g_MemoryManager.Free(pVertexShader->pDeclaration);
|
||||||
|
|
||||||
if(pVertexShader->pFunction)
|
if(pVertexShader->pFunction)
|
||||||
{
|
{
|
||||||
CxbxFree(pVertexShader->pFunction);
|
g_MemoryManager.Free(pVertexShader->pFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeVertexDynamicPatch(pVertexShader);
|
FreeVertexDynamicPatch(pVertexShader);
|
||||||
|
|
||||||
CxbxFree(pVertexShader);
|
g_MemoryManager.Free(pVertexShader);
|
||||||
CxbxFree(pD3DVertexShader);
|
g_MemoryManager.Free(pD3DVertexShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hRet = g_pD3DDevice8->DeleteVertexShader(RealHandle);
|
HRESULT hRet = g_pD3DDevice8->DeleteVertexShader(RealHandle);
|
||||||
|
@ -8898,7 +8899,7 @@ PVOID WINAPI XTL::EMUPATCH(D3D_AllocContiguousMemory)
|
||||||
// so that we can return a valid page aligned pointer
|
// 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
|
// align to page boundary
|
||||||
{
|
{
|
||||||
|
@ -9608,7 +9609,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_PersistDisplay)()
|
||||||
FILE* fp = fopen( "PersistedSurface.bin", "wb" );
|
FILE* fp = fopen( "PersistedSurface.bin", "wb" );
|
||||||
if(fp)
|
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 ) ) )
|
if( SUCCEEDED( pBackBuffer->LockRect( &LockedRect, NULL, 0 ) ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
#include "CxbxKrnl/EmuFS.h"
|
#include "CxbxKrnl/EmuFS.h"
|
||||||
#include "CxbxKrnl/EmuAlloc.h"
|
#include "CxbxKrnl/EmuAlloc.h"
|
||||||
#include "CxbxKrnl/EmuXTL.h"
|
#include "CxbxKrnl/EmuXTL.h"
|
||||||
|
#include <CxbxKrnl/MemoryManager.h>
|
||||||
|
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <locale.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!
|
// The Xbox sets r0 to the alpha channel of texture 0, so it can be read before written!
|
||||||
if(bR0WAccess)
|
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);
|
strncpy(szNewCodeBuffer, szCode, iPreRunLen);
|
||||||
strcat(szNewCodeBuffer, "mov r0, t0.a\n");
|
strcat(szNewCodeBuffer, "mov r0, t0.a\n");
|
||||||
strcat(szNewCodeBuffer, &szCode[iPreRunLen]);
|
strcat(szNewCodeBuffer, &szCode[iPreRunLen]);
|
||||||
strcpy(szCode, szNewCodeBuffer);
|
strcpy(szCode, szNewCodeBuffer);
|
||||||
|
|
||||||
CxbxFree(szNewCodeBuffer);
|
g_MemoryManager.Free(szNewCodeBuffer);
|
||||||
}
|
}
|
||||||
/*DbgPrintf("r1 case! ... ");
|
/*DbgPrintf("r1 case! ... ");
|
||||||
if(bR1WAccess || bR1AWAccess || bR1RGBWAccess)
|
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);
|
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);
|
strncpy(szNewCodeBuffer, szCode, iPreRunLen);
|
||||||
strcat(szNewCodeBuffer, szCat);
|
strcat(szNewCodeBuffer, szCat);
|
||||||
strcat(szNewCodeBuffer, &szCode[iPreRunLen]);
|
strcat(szNewCodeBuffer, &szCode[iPreRunLen]);
|
||||||
strcpy(szCode, szNewCodeBuffer);
|
strcpy(szCode, szNewCodeBuffer);
|
||||||
free(szNewCodeBuffer);
|
g_MemoryManager.Free(szNewCodeBuffer);
|
||||||
}
|
}
|
||||||
DbgPrintf("end\n");*/
|
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
|
// Add this const to the beginning of the psh
|
||||||
char str[100];
|
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);
|
strncpy(szNewCodeBuffer, pCodeBuffer, 7);
|
||||||
szNewCodeBuffer[7]=0x00;
|
szNewCodeBuffer[7]=0x00;
|
||||||
sprintf(str, "def c%d, %ff, %ff, %ff, %ff\n", i,
|
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]);
|
strcat(szNewCodeBuffer, &pCodeBuffer[7]);
|
||||||
strcpy(pCodeBuffer, szNewCodeBuffer);
|
strcpy(pCodeBuffer, szNewCodeBuffer);
|
||||||
|
|
||||||
free(szNewCodeBuffer);
|
g_MemoryManager.Free(szNewCodeBuffer);
|
||||||
|
|
||||||
iConstCount++;
|
iConstCount++;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "CxbxKrnl/EmuXTL.h"
|
#include "CxbxKrnl/EmuXTL.h"
|
||||||
#include "CxbxKrnl/EmuD3D8Types.h" // For X_D3DFORMAT
|
#include "CxbxKrnl/EmuD3D8Types.h" // For X_D3DFORMAT
|
||||||
#include "CxbxKrnl/ResourceTracker.h"
|
#include "CxbxKrnl/ResourceTracker.h"
|
||||||
|
#include "CxbxKrnl/MemoryManager.h"
|
||||||
|
|
||||||
uint32 XTL::g_dwPrimaryPBCount = 0;
|
uint32 XTL::g_dwPrimaryPBCount = 0;
|
||||||
uint32 *XTL::g_pPrimaryPB = 0;
|
uint32 *XTL::g_pPrimaryPB = 0;
|
||||||
|
@ -131,7 +132,7 @@ static void EmuUnswizzleActiveTexture()
|
||||||
RECT iRect = {0,0,0,0};
|
RECT iRect = {0,0,0,0};
|
||||||
POINT iPoint = {0,0};
|
POINT iPoint = {0,0};
|
||||||
|
|
||||||
void *pTemp = malloc(dwHeight*dwPitch);
|
void *pTemp = g_MemoryManager.Allocate(dwHeight*dwPitch);
|
||||||
|
|
||||||
XTL::EmuUnswizzleRect
|
XTL::EmuUnswizzleRect
|
||||||
(
|
(
|
||||||
|
@ -143,7 +144,7 @@ static void EmuUnswizzleActiveTexture()
|
||||||
|
|
||||||
pTexture->UnlockRect(0);
|
pTexture->UnlockRect(0);
|
||||||
|
|
||||||
free(pTemp);
|
g_MemoryManager.Free(pTemp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "CxbxKrnl/EmuAlloc.h"
|
#include "CxbxKrnl/EmuAlloc.h"
|
||||||
#include "CxbxKrnl/EmuXTL.h"
|
#include "CxbxKrnl/EmuXTL.h"
|
||||||
#include "CxbxKrnl/ResourceTracker.h"
|
#include "CxbxKrnl/ResourceTracker.h"
|
||||||
|
#include "CxbxKrnl/MemoryManager.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ void XTL::VertexPatcher::CacheStream(VertexPatchDesc *pPatchDesc,
|
||||||
void *pCalculateData = NULL;
|
void *pCalculateData = NULL;
|
||||||
uint32 uiKey;
|
uint32 uiKey;
|
||||||
UINT uiLength;
|
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
|
// Check if the cache is full, if so, throw away the least used stream
|
||||||
if(g_PatchedStreamsCache.get_count() > VERTEX_BUFFER_CACHE_SIZE)
|
if(g_PatchedStreamsCache.get_count() > VERTEX_BUFFER_CACHE_SIZE)
|
||||||
|
@ -200,7 +201,7 @@ void XTL::VertexPatcher::FreeCachedStream(void *pStream)
|
||||||
{
|
{
|
||||||
if(pCachedStream->bIsUP && pCachedStream->pStreamUP)
|
if(pCachedStream->bIsUP && pCachedStream->pStreamUP)
|
||||||
{
|
{
|
||||||
CxbxFree(pCachedStream->pStreamUP);
|
g_MemoryManager.Free(pCachedStream->pStreamUP);
|
||||||
}
|
}
|
||||||
if(pCachedStream->Stream.pOriginalStream)
|
if(pCachedStream->Stream.pOriginalStream)
|
||||||
{
|
{
|
||||||
|
@ -210,7 +211,7 @@ void XTL::VertexPatcher::FreeCachedStream(void *pStream)
|
||||||
{
|
{
|
||||||
pCachedStream->Stream.pPatchedStream->Release();
|
pCachedStream->Stream.pPatchedStream->Release();
|
||||||
}
|
}
|
||||||
CxbxFree(pCachedStream);
|
g_MemoryManager.Free(pCachedStream);
|
||||||
}
|
}
|
||||||
g_PatchedStreamsCache.Unlock();
|
g_PatchedStreamsCache.Unlock();
|
||||||
g_PatchedStreamsCache.remove(pStream);
|
g_PatchedStreamsCache.remove(pStream);
|
||||||
|
@ -227,7 +228,7 @@ bool XTL::VertexPatcher::ApplyCachedStream(VertexPatchDesc *pPatchDesc,
|
||||||
UINT uiLength;
|
UINT uiLength;
|
||||||
bool bApplied = false;
|
bool bApplied = false;
|
||||||
uint32 uiKey;
|
uint32 uiKey;
|
||||||
//CACHEDSTREAM *pCachedStream = (CACHEDSTREAM *)CxbxMalloc(sizeof(CACHEDSTREAM));
|
//CACHEDSTREAM *pCachedStream = (CACHEDSTREAM *)g_MemoryManager.Allocate(sizeof(CACHEDSTREAM));
|
||||||
|
|
||||||
if(!pPatchDesc->pVertexStreamZeroData)
|
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
|
// TODO: This is sometimes the number of indices, which isn't too good
|
||||||
dwNewSize = pPatchDesc->dwVertexCount * pStreamPatch->ConvertedStride;
|
dwNewSize = pPatchDesc->dwVertexCount * pStreamPatch->ConvertedStride;
|
||||||
pNewVertexBuffer = NULL;
|
pNewVertexBuffer = NULL;
|
||||||
pNewData = (uint08*)CxbxMalloc(dwNewSize);
|
pNewData = (uint08*)g_MemoryManager.Allocate(dwNewSize);
|
||||||
if(!pNewData)
|
if(!pNewData)
|
||||||
{
|
{
|
||||||
CxbxKrnlCleanup("Couldn't allocate the new stream zero buffer");
|
CxbxKrnlCleanup("Couldn't allocate the new stream zero buffer");
|
||||||
|
@ -897,7 +898,7 @@ bool XTL::VertexPatcher::PatchPrimitive(VertexPatchDesc *pPatchDesc,
|
||||||
dwOriginalSizeWR = dwOriginalSize;
|
dwOriginalSizeWR = dwOriginalSize;
|
||||||
dwNewSizeWR = dwNewSize;
|
dwNewSizeWR = dwNewSize;
|
||||||
|
|
||||||
m_pNewVertexStreamZeroData = (uint08*)CxbxMalloc(dwNewSizeWR);
|
m_pNewVertexStreamZeroData = (uint08*)g_MemoryManager.Allocate(dwNewSizeWR);
|
||||||
m_bAllocatedStreamZeroData = true;
|
m_bAllocatedStreamZeroData = true;
|
||||||
|
|
||||||
pPatchedVertexData = (uint08*)m_pNewVertexStreamZeroData;
|
pPatchedVertexData = (uint08*)m_pNewVertexStreamZeroData;
|
||||||
|
@ -1037,7 +1038,7 @@ bool XTL::VertexPatcher::Restore()
|
||||||
|
|
||||||
if(this->m_bAllocatedStreamZeroData)
|
if(this->m_bAllocatedStreamZeroData)
|
||||||
{
|
{
|
||||||
CxbxFree(m_pNewVertexStreamZeroData);
|
g_MemoryManager.Free(m_pNewVertexStreamZeroData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "CxbxKrnl/EmuFS.h"
|
#include "CxbxKrnl/EmuFS.h"
|
||||||
#include "CxbxKrnl/EmuAlloc.h"
|
#include "CxbxKrnl/EmuAlloc.h"
|
||||||
#include "CxbxKrnl/EmuXTL.h"
|
#include "CxbxKrnl/EmuXTL.h"
|
||||||
|
#include "CxbxKrnl/MemoryManager.h"
|
||||||
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
// * Vertex shader function recompiler
|
// * Vertex shader function recompiler
|
||||||
|
@ -1675,10 +1676,10 @@ static boolean VshAddStreamPatch(VSH_PATCH_DATA *pPatchData)
|
||||||
pStreamPatch->NbrTypes = pPatchData->TypePatchData.NbrTypes;
|
pStreamPatch->NbrTypes = pPatchData->TypePatchData.NbrTypes;
|
||||||
pStreamPatch->NeedPatch = pPatchData->NeedPatching;
|
pStreamPatch->NeedPatch = pPatchData->NeedPatching;
|
||||||
// 2010/01/12 - revel8n - fixed allocated data size and type
|
// 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));
|
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 :
|
// 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));
|
memcpy(pStreamPatch->pSizes, pPatchData->TypePatchData.NewSizes, pPatchData->TypePatchData.NbrTypes * sizeof(UINT));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -1977,7 +1978,7 @@ DWORD XTL::EmuRecompileVshDeclaration
|
||||||
|
|
||||||
// Calculate size of declaration
|
// Calculate size of declaration
|
||||||
DWORD DeclarationSize = VshGetDeclarationSize(pDeclaration);
|
DWORD DeclarationSize = VshGetDeclarationSize(pDeclaration);
|
||||||
*ppRecompiledDeclaration = (DWORD *)CxbxMalloc(DeclarationSize);
|
*ppRecompiledDeclaration = (DWORD *)g_MemoryManager.Allocate(DeclarationSize);
|
||||||
DWORD *pRecompiled = *ppRecompiledDeclaration;
|
DWORD *pRecompiled = *ppRecompiledDeclaration;
|
||||||
memcpy(pRecompiled, pDeclaration, DeclarationSize);
|
memcpy(pRecompiled, pDeclaration, DeclarationSize);
|
||||||
*pDeclarationSize = DeclarationSize;
|
*pDeclarationSize = DeclarationSize;
|
||||||
|
@ -2001,7 +2002,7 @@ DWORD XTL::EmuRecompileVshDeclaration
|
||||||
// Copy the patches to the vertex shader struct
|
// Copy the patches to the vertex shader struct
|
||||||
DWORD StreamsSize = PatchData.StreamPatchData.NbrStreams * sizeof(STREAM_DYNAMIC_PATCH);
|
DWORD StreamsSize = PatchData.StreamPatchData.NbrStreams * sizeof(STREAM_DYNAMIC_PATCH);
|
||||||
pVertexDynamicPatch->NbrStreams = PatchData.StreamPatchData.NbrStreams;
|
pVertexDynamicPatch->NbrStreams = PatchData.StreamPatchData.NbrStreams;
|
||||||
pVertexDynamicPatch->pStreamPatches = (STREAM_DYNAMIC_PATCH *)CxbxMalloc(StreamsSize);
|
pVertexDynamicPatch->pStreamPatches = (STREAM_DYNAMIC_PATCH *)g_MemoryManager.Allocate(StreamsSize);
|
||||||
memcpy(pVertexDynamicPatch->pStreamPatches,
|
memcpy(pVertexDynamicPatch->pStreamPatches,
|
||||||
PatchData.StreamPatchData.pStreamPatches,
|
PatchData.StreamPatchData.pStreamPatches,
|
||||||
StreamsSize);
|
StreamsSize);
|
||||||
|
@ -2022,7 +2023,7 @@ extern HRESULT XTL::EmuRecompileVshFunction
|
||||||
VSH_SHADER_HEADER *pShaderHeader = (VSH_SHADER_HEADER*)pFunction;
|
VSH_SHADER_HEADER *pShaderHeader = (VSH_SHADER_HEADER*)pFunction;
|
||||||
DWORD *pToken;
|
DWORD *pToken;
|
||||||
boolean EOI = false;
|
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;
|
LPD3DXBUFFER pErrors = NULL;
|
||||||
HRESULT hRet = 0;
|
HRESULT hRet = 0;
|
||||||
|
|
||||||
|
@ -2073,7 +2074,7 @@ extern HRESULT XTL::EmuRecompileVshFunction
|
||||||
// The size of the shader is
|
// The size of the shader is
|
||||||
*pOriginalSize = (DWORD)pToken - (DWORD)pFunction;
|
*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");
|
DbgVshPrintf("-- Before conversion --\n");
|
||||||
VshWriteShader(pShader, pShaderDisassembly, FALSE);
|
VshWriteShader(pShader, pShaderDisassembly, FALSE);
|
||||||
DbgVshPrintf("%s", pShaderDisassembly);
|
DbgVshPrintf("%s", pShaderDisassembly);
|
||||||
|
@ -2118,9 +2119,9 @@ extern HRESULT XTL::EmuRecompileVshFunction
|
||||||
if( pErrors )
|
if( pErrors )
|
||||||
pErrors->Release();
|
pErrors->Release();
|
||||||
|
|
||||||
CxbxFree(pShaderDisassembly);
|
g_MemoryManager.Free(pShaderDisassembly);
|
||||||
}
|
}
|
||||||
CxbxFree(pShader);
|
g_MemoryManager.Free(pShader);
|
||||||
|
|
||||||
return hRet;
|
return hRet;
|
||||||
}
|
}
|
||||||
|
@ -2129,12 +2130,12 @@ extern void XTL::FreeVertexDynamicPatch(VERTEX_SHADER *pVertexShader)
|
||||||
{
|
{
|
||||||
for (DWORD i = 0; i < pVertexShader->VertexDynamicPatch.NbrStreams; i++)
|
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;
|
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;
|
pVertexShader->VertexDynamicPatch.pStreamPatches[i].pSizes = nullptr;
|
||||||
}
|
}
|
||||||
CxbxFree(pVertexShader->VertexDynamicPatch.pStreamPatches);
|
g_MemoryManager.Free(pVertexShader->VertexDynamicPatch.pStreamPatches);
|
||||||
pVertexShader->VertexDynamicPatch.pStreamPatches = NULL;
|
pVertexShader->VertexDynamicPatch.pStreamPatches = NULL;
|
||||||
pVertexShader->VertexDynamicPatch.NbrStreams = 0;
|
pVertexShader->VertexDynamicPatch.NbrStreams = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace xboxkrnl
|
||||||
#include "EmuShared.h"
|
#include "EmuShared.h"
|
||||||
#include "EmuAlloc.h"
|
#include "EmuAlloc.h"
|
||||||
#include "EmuXTL.h"
|
#include "EmuXTL.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
#include <mmreg.h>
|
#include <mmreg.h>
|
||||||
#include <msacm.h>
|
#include <msacm.h>
|
||||||
|
@ -803,7 +804,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
||||||
|
|
||||||
DWORD dwEmuFlags = 0;
|
DWORD dwEmuFlags = 0;
|
||||||
|
|
||||||
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)CxbxMalloc(sizeof(DSBUFFERDESC));
|
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)g_MemoryManager.Allocate(sizeof(DSBUFFERDESC));
|
||||||
DSBUFFERDESC *pDSBufferDescSpecial = NULL;
|
DSBUFFERDESC *pDSBufferDescSpecial = NULL;
|
||||||
bool bIsSpecial = false;
|
bool bIsSpecial = false;
|
||||||
|
|
||||||
|
@ -828,7 +829,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
||||||
|
|
||||||
if(pdsbd->lpwfxFormat != NULL)
|
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));
|
memcpy(pDSBufferDesc->lpwfxFormat, pdsbd->lpwfxFormat, sizeof(WAVEFORMATEX));
|
||||||
|
|
||||||
if(pDSBufferDesc->lpwfxFormat->wFormatTag == WAVE_FORMAT_XBOX_ADPCM)
|
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.
|
// TODO: A better response to this scenario if possible.
|
||||||
|
|
||||||
pDSBufferDescSpecial = (DSBUFFERDESC*)CxbxMalloc(sizeof(DSBUFFERDESC));
|
pDSBufferDescSpecial = (DSBUFFERDESC*)g_MemoryManager.Allocate(sizeof(DSBUFFERDESC));
|
||||||
pDSBufferDescSpecial->lpwfxFormat = (WAVEFORMATEX*)CxbxMalloc(sizeof(WAVEFORMATEX));
|
pDSBufferDescSpecial->lpwfxFormat = (WAVEFORMATEX*)g_MemoryManager.Allocate(sizeof(WAVEFORMATEX));
|
||||||
|
|
||||||
//memset(pDSBufferDescSpecial->lpwfxFormat, 0, sizeof(WAVEFORMATEX));
|
//memset(pDSBufferDescSpecial->lpwfxFormat, 0, sizeof(WAVEFORMATEX));
|
||||||
//memset(pDSBufferDescSpecial, 0, sizeof(DSBUFFERDESC));
|
//memset(pDSBufferDescSpecial, 0, sizeof(DSBUFFERDESC));
|
||||||
|
@ -886,7 +887,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
||||||
pDSBufferDescSpecial->dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
|
pDSBufferDescSpecial->dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
|
||||||
pDSBufferDescSpecial->dwBufferBytes = 3 * pDSBufferDescSpecial->lpwfxFormat->nAvgBytesPerSec;
|
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->cbSize = sizeof( WAVEFORMATEX );
|
||||||
// pDSBufferDesc->lpwfxFormat->nChannels = 1;
|
// pDSBufferDesc->lpwfxFormat->nChannels = 1;
|
||||||
|
@ -1216,9 +1217,9 @@ ULONG WINAPI XTL::EMUPATCH(IDirectSoundBuffer_Release)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pThis->EmuBufferDesc->lpwfxFormat != NULL)
|
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;
|
delete pThis;
|
||||||
}
|
}
|
||||||
|
@ -1562,7 +1563,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream)
|
||||||
// TODO: Garbage Collection
|
// TODO: Garbage Collection
|
||||||
*ppStream = new X_CDirectSoundStream();
|
*ppStream = new X_CDirectSoundStream();
|
||||||
|
|
||||||
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)CxbxMalloc(sizeof(DSBUFFERDESC));
|
DSBUFFERDESC *pDSBufferDesc = (DSBUFFERDESC*)g_MemoryManager.Allocate(sizeof(DSBUFFERDESC));
|
||||||
|
|
||||||
// convert from Xbox to PC DSound
|
// convert from Xbox to PC DSound
|
||||||
{
|
{
|
||||||
|
@ -1580,7 +1581,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream)
|
||||||
|
|
||||||
if(pdssd->lpwfxFormat != NULL)
|
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));
|
memcpy(pDSBufferDesc->lpwfxFormat, pdssd->lpwfxFormat, sizeof(WAVEFORMATEX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1830,9 +1831,9 @@ ULONG WINAPI XTL::EMUPATCH(DirectSound_CDirectSoundStream_Release)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pThis->EmuBufferDesc->lpwfxFormat != NULL)
|
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;
|
delete pThis;
|
||||||
}
|
}
|
||||||
|
@ -3652,7 +3653,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSound_GetEffectData)
|
||||||
|
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
if( !pvData )
|
if( !pvData )
|
||||||
pvData = CxbxMalloc( dwDataSize );
|
pvData = g_MemoryManager.Allocate( dwDataSize );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ namespace xboxkrnl
|
||||||
#include "EmuFS.h"
|
#include "EmuFS.h"
|
||||||
#include "EmuAlloc.h" // For CxbxCalloc()
|
#include "EmuAlloc.h" // For CxbxCalloc()
|
||||||
#include "CxbxKrnl.h"
|
#include "CxbxKrnl.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
#undef FIELD_OFFSET // prevent macro redefinition warnings
|
#undef FIELD_OFFSET // prevent macro redefinition warnings
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
@ -397,7 +398,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
||||||
uint32 dwCopySize = pTLS->dwDataEndAddr - pTLS->dwDataStartAddr;
|
uint32 dwCopySize = pTLS->dwDataEndAddr - pTLS->dwDataStartAddr;
|
||||||
uint32 dwZeroSize = pTLS->dwSizeofZeroFill;
|
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);
|
memcpy(pNewTLS, pTLSData, dwCopySize);
|
||||||
|
|
||||||
|
@ -438,7 +439,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate the xbox KPCR structure
|
// 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::NT_TIB *XbTib = &(NewPcr->NtTib);
|
||||||
xboxkrnl::PKPRCB Prcb = &(NewPcr->PrcbData);
|
xboxkrnl::PKPRCB Prcb = &(NewPcr->PrcbData);
|
||||||
// Note : As explained above (at EmuKeSetPcr), Cxbx cannot allocate one NT_TIB and KPRCB
|
// 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
|
// 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->Tcb.TlsData = pNewTLS;
|
||||||
EThread->UniqueThread = GetCurrentThreadId();
|
EThread->UniqueThread = GetCurrentThreadId();
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#pragma warning(default:4005)
|
#pragma warning(default:4005)
|
||||||
#include "CxbxKrnl.h"
|
#include "CxbxKrnl.h"
|
||||||
#include "EmuAlloc.h"
|
#include "EmuAlloc.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
//#include "Logging.h" // For hex4()
|
//#include "Logging.h" // For hex4()
|
||||||
|
|
||||||
|
|
||||||
|
@ -570,7 +571,7 @@ EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(const HANDLE Handl
|
||||||
void _CxbxPVOIDDeleter(PVOID *ptr)
|
void _CxbxPVOIDDeleter(PVOID *ptr)
|
||||||
{
|
{
|
||||||
if (*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
|
// Build the native FILE_LINK_INFORMATION struct
|
||||||
*Length = sizeof(NtDll::FILE_LINK_INFORMATION) + convertedFileName.size() * sizeof(wchar_t);
|
*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->ReplaceIfExists = xboxLinkInfo->ReplaceIfExists;
|
||||||
ntLinkInfo->RootDirectory = RootDirectory;
|
ntLinkInfo->RootDirectory = RootDirectory;
|
||||||
ntLinkInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);
|
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
|
// Build the native FILE_RENAME_INFORMATION struct
|
||||||
*Length = sizeof(NtDll::FILE_RENAME_INFORMATION) + convertedFileName.size() * sizeof(wchar_t);
|
*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->ReplaceIfExists = xboxRenameInfo->ReplaceIfExists;
|
||||||
ntRenameInfo->RootDirectory = RootDirectory;
|
ntRenameInfo->RootDirectory = RootDirectory;
|
||||||
ntRenameInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);
|
ntRenameInfo->FileNameLength = convertedFileName.size() * sizeof(wchar_t);
|
||||||
|
|
|
@ -45,6 +45,7 @@ namespace xboxkrnl
|
||||||
|
|
||||||
#include "Logging.h" // For LOG_FUNC()
|
#include "Logging.h" // For LOG_FUNC()
|
||||||
#include "EmuKrnlLogging.h"
|
#include "EmuKrnlLogging.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
// prevent name collisions
|
// prevent name collisions
|
||||||
namespace NtDll
|
namespace NtDll
|
||||||
|
@ -53,7 +54,7 @@ namespace NtDll
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "Emu.h" // For EmuWarning()
|
#include "Emu.h" // For EmuWarning()
|
||||||
#include "EmuAlloc.h" // For CxbxFree(), CxbxMalloc(), etc.
|
#include "EmuAlloc.h" // For CxbxFree(), g_MemoryManager.Allocate(), etc.
|
||||||
|
|
||||||
// Global Variable(s)
|
// Global Variable(s)
|
||||||
PVOID g_pPersistedData = NULL;
|
PVOID g_pPersistedData = NULL;
|
||||||
|
@ -88,11 +89,11 @@ XBSYSAPI EXPORTNUM(1) xboxkrnl::PVOID NTAPI xboxkrnl::AvGetSavedDataAddress(void
|
||||||
|
|
||||||
if (g_pPersistedData)
|
if (g_pPersistedData)
|
||||||
{
|
{
|
||||||
CxbxFree(g_pPersistedData);
|
g_MemoryManager.Free(g_pPersistedData);
|
||||||
g_pPersistedData = NULL;
|
g_pPersistedData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pPersistedData = CxbxMalloc(640 * 480 * 4);
|
g_pPersistedData = g_MemoryManager.Allocate(640 * 480 * 4);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Get a copy of the front buffer
|
// 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" );
|
FILE* fp = fopen( "PersistedSurface.bin", "rb" );
|
||||||
fseek( fp, 0, SEEK_END );
|
fseek( fp, 0, SEEK_END );
|
||||||
long size = ftell( fp );
|
long size = ftell( fp );
|
||||||
g_pPersistedData = malloc( size );
|
g_pPersistedData = g_MemoryManager.Allocate( size );
|
||||||
fread( g_pPersistedData, size, 1, fp );
|
fread( g_pPersistedData, size, 1, fp );
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}*/
|
}*/
|
||||||
|
|
|
@ -46,6 +46,7 @@ namespace xboxkrnl
|
||||||
#include "Logging.h" // For LOG_FUNC()
|
#include "Logging.h" // For LOG_FUNC()
|
||||||
#include "EmuEEPROM.h" // For EmuFindEEPROMInfo, EEPROM, XboxFactoryGameRegion
|
#include "EmuEEPROM.h" // For EmuFindEEPROMInfo, EEPROM, XboxFactoryGameRegion
|
||||||
#include "EmuKrnlLogging.h"
|
#include "EmuKrnlLogging.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
// prevent name collisions
|
// prevent name collisions
|
||||||
namespace NtDll
|
namespace NtDll
|
||||||
|
@ -126,7 +127,7 @@ XBSYSAPI EXPORTNUM(15) xboxkrnl::PVOID NTAPI xboxkrnl::ExAllocatePoolWithTag
|
||||||
LOG_FUNC_ARG(Tag)
|
LOG_FUNC_ARG(Tag)
|
||||||
LOG_FUNC_END;
|
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
|
LOG_INCOMPLETE(); // TODO : Actually implement ExAllocatePoolWithTag
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ XBSYSAPI EXPORTNUM(17) xboxkrnl::VOID NTAPI xboxkrnl::ExFreePool
|
||||||
{
|
{
|
||||||
LOG_FUNC_ONE_ARG(P);
|
LOG_FUNC_ONE_ARG(P);
|
||||||
|
|
||||||
CxbxFree(P);
|
g_MemoryManager.Free(P);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ******************************************************************
|
// ******************************************************************
|
||||||
|
|
|
@ -48,8 +48,9 @@ namespace xboxkrnl
|
||||||
#include "EmuKrnlLogging.h"
|
#include "EmuKrnlLogging.h"
|
||||||
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
||||||
#include "Emu.h" // For EmuWarning()
|
#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 "ResourceTracker.h" // For g_AlignCache
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
// prevent name collisions
|
// prevent name collisions
|
||||||
namespace NtDll
|
namespace NtDll
|
||||||
|
@ -131,22 +132,8 @@ XBSYSAPI EXPORTNUM(166) xboxkrnl::PVOID NTAPI xboxkrnl::MmAllocateContiguousMemo
|
||||||
// Allocate when input arguments are valid
|
// Allocate when input arguments are valid
|
||||||
if (pRet != NULL)
|
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)
|
// TODO : Allocate differently if(ProtectionType & PAGE_WRITECOMBINE)
|
||||||
pRet = CxbxMalloc(NumberOfBytes + Alignment);
|
pRet = g_MemoryManager.AllocateContiguous(NumberOfBytes, Alignment);
|
||||||
|
|
||||||
// align to page boundary
|
|
||||||
DWORD dwRet = (DWORD)pRet;
|
|
||||||
|
|
||||||
dwRet += Alignment - dwRet % Alignment;
|
|
||||||
g_AlignCache.insert(dwRet, pRet);
|
|
||||||
pRet = (PVOID)dwRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN(pRet);
|
RETURN(pRet);
|
||||||
|
@ -167,7 +154,7 @@ XBSYSAPI EXPORTNUM(167) xboxkrnl::PVOID NTAPI xboxkrnl::MmAllocateSystemMemory
|
||||||
LOG_FUNC_END;
|
LOG_FUNC_END;
|
||||||
|
|
||||||
// TODO: should this be aligned?
|
// TODO: should this be aligned?
|
||||||
PVOID pRet = CxbxMalloc(NumberOfBytes);
|
PVOID pRet = g_MemoryManager.Allocate(NumberOfBytes);
|
||||||
|
|
||||||
RETURN(pRet);
|
RETURN(pRet);
|
||||||
}
|
}
|
||||||
|
@ -296,32 +283,18 @@ XBSYSAPI EXPORTNUM(171) xboxkrnl::VOID NTAPI xboxkrnl::MmFreeContiguousMemory
|
||||||
{
|
{
|
||||||
LOG_FUNC_ONE_ARG(BaseAddress);
|
LOG_FUNC_ONE_ARG(BaseAddress);
|
||||||
|
|
||||||
PVOID OrigBaseAddress = BaseAddress;
|
if (BaseAddress == &DefaultLaunchDataPage) {
|
||||||
|
|
||||||
if (g_AlignCache.exists(BaseAddress))
|
|
||||||
{
|
|
||||||
OrigBaseAddress = g_AlignCache.get(BaseAddress);
|
|
||||||
g_AlignCache.remove(BaseAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OrigBaseAddress == &DefaultLaunchDataPage)
|
|
||||||
{
|
|
||||||
DbgPrintf("Ignored MmFreeContiguousMemory(&DefaultLaunchDataPage)\n");
|
DbgPrintf("Ignored MmFreeContiguousMemory(&DefaultLaunchDataPage)\n");
|
||||||
LOG_IGNORED();
|
LOG_IGNORED();
|
||||||
}
|
return;
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO : Free PAGE_WRITECOMBINE differently
|
|
||||||
if (OrigBaseAddress == LaunchDataPage)
|
|
||||||
DbgPrintf("MmFreeContiguousMemory detected a free of LaunchDataPage\n");
|
|
||||||
|
|
||||||
CxbxFree(OrigBaseAddress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO -oDxbx: Sokoban crashes after this, at reset time (press Black + White to hit this).
|
g_MemoryManager.Free(BaseAddress);
|
||||||
// Tracing in assembly shows the crash takes place quite a while further, so it's probably
|
|
||||||
// not related to this call per-se. The strangest thing is, that if we let the debugger step
|
// TODO -oDxbx: Sokoban crashes after this, at reset time (press Black + White to hit this).
|
||||||
// all the way through, the crash doesn't occur. Adding a Sleep(100) here doesn't help though.
|
// Tracing in assembly shows the crash takes place quite a while further, so it's probably
|
||||||
|
// not related to this call per-se. The strangest thing is, that if we let the debugger step
|
||||||
|
// all the way through, the crash doesn't occur. Adding a Sleep(100) here doesn't help though.
|
||||||
}
|
}
|
||||||
|
|
||||||
// ******************************************************************
|
// ******************************************************************
|
||||||
|
@ -338,7 +311,7 @@ XBSYSAPI EXPORTNUM(172) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmFreeSystemMemory
|
||||||
LOG_FUNC_ARG(NumberOfBytes)
|
LOG_FUNC_ARG(NumberOfBytes)
|
||||||
LOG_FUNC_END;
|
LOG_FUNC_END;
|
||||||
|
|
||||||
CxbxFree(BaseAddress);
|
g_MemoryManager.Free(BaseAddress);
|
||||||
|
|
||||||
RETURN(STATUS_SUCCESS);
|
RETURN(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -440,7 +413,7 @@ XBSYSAPI EXPORTNUM(177) xboxkrnl::PVOID NTAPI xboxkrnl::MmMapIoSpace
|
||||||
LOG_FUNC_END;
|
LOG_FUNC_END;
|
||||||
|
|
||||||
// TODO: should this be aligned?
|
// TODO: should this be aligned?
|
||||||
PVOID pRet = CxbxMalloc(NumberOfBytes);
|
PVOID pRet = g_MemoryManager.Allocate(NumberOfBytes);
|
||||||
LOG_INCOMPLETE();
|
LOG_INCOMPLETE();
|
||||||
|
|
||||||
RETURN(pRet);
|
RETURN(pRet);
|
||||||
|
@ -512,8 +485,10 @@ XBSYSAPI EXPORTNUM(179) xboxkrnl::ULONG NTAPI xboxkrnl::MmQueryAddressProtect
|
||||||
|
|
||||||
// Assume read/write when page is allocated :
|
// Assume read/write when page is allocated :
|
||||||
ULONG Result = PAGE_NOACCESS;
|
ULONG Result = PAGE_NOACCESS;
|
||||||
if (EmuCheckAllocationSize(VirtualAddress, false))
|
|
||||||
|
if (g_MemoryManager.IsAllocated(VirtualAddress)) {
|
||||||
Result = PAGE_READWRITE;
|
Result = PAGE_READWRITE;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_INCOMPLETE(); // TODO : Improve the MmQueryAddressProtect implementation
|
LOG_INCOMPLETE(); // TODO : Improve the MmQueryAddressProtect implementation
|
||||||
|
|
||||||
|
@ -532,7 +507,7 @@ XBSYSAPI EXPORTNUM(180) xboxkrnl::ULONG NTAPI xboxkrnl::MmQueryAllocationSize
|
||||||
|
|
||||||
LOG_INCOMPLETE(); // TODO : Free PAGE_WRITECOMBINE differently
|
LOG_INCOMPLETE(); // TODO : Free PAGE_WRITECOMBINE differently
|
||||||
|
|
||||||
ULONG uiSize = EmuCheckAllocationSize(BaseAddress, false);
|
ULONG uiSize = g_MemoryManager.QueryAllocationSize(BaseAddress);
|
||||||
|
|
||||||
RETURN(uiSize);
|
RETURN(uiSize);
|
||||||
}
|
}
|
||||||
|
@ -634,7 +609,7 @@ XBSYSAPI EXPORTNUM(183) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmUnmapIoSpace
|
||||||
LOG_FUNC_ARG(NumberOfBytes)
|
LOG_FUNC_ARG(NumberOfBytes)
|
||||||
LOG_FUNC_END;
|
LOG_FUNC_END;
|
||||||
|
|
||||||
CxbxFree(BaseAddress);
|
g_MemoryManager.Free(BaseAddress);
|
||||||
LOG_INCOMPLETE();
|
LOG_INCOMPLETE();
|
||||||
|
|
||||||
RETURN(STATUS_SUCCESS);
|
RETURN(STATUS_SUCCESS);
|
||||||
|
|
|
@ -55,7 +55,8 @@ namespace NtDll
|
||||||
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
||||||
#include "Emu.h" // For EmuWarning()
|
#include "Emu.h" // For EmuWarning()
|
||||||
#include "EmuFile.h" // For EmuNtSymbolicLinkObject, NtStatusToString(), etc.
|
#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
|
#pragma warning(disable:4005) // Ignore redefined status values
|
||||||
#include <ntstatus.h>
|
#include <ntstatus.h>
|
||||||
|
@ -985,7 +986,7 @@ XBSYSAPI EXPORTNUM(207) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryDirectoryFile
|
||||||
}
|
}
|
||||||
|
|
||||||
NtDll::FILE_DIRECTORY_INFORMATION *NtFileDirInfo =
|
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 :
|
// Short-hand pointer to Nt filename :
|
||||||
wchar_t *wcstr = NtFileDirInfo->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!)
|
// TODO: Cache the last search result for quicker access with CreateFile (xbox does this internally!)
|
||||||
CxbxFree(NtFileDirInfo);
|
g_MemoryManager.Free(NtFileDirInfo);
|
||||||
|
|
||||||
RETURN(ret);
|
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
|
// We need to retry the operation in case the buffer is too small to fit the data
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ntFileInfo = CxbxMalloc(bufferSize);
|
ntFileInfo = g_MemoryManager.Allocate(bufferSize);
|
||||||
|
|
||||||
ret = NtDll::NtQueryInformationFile(
|
ret = NtDll::NtQueryInformationFile(
|
||||||
FileHandle,
|
FileHandle,
|
||||||
|
@ -1134,14 +1135,14 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil
|
||||||
// Buffer is too small; make a larger one
|
// Buffer is too small; make a larger one
|
||||||
if (ret == STATUS_BUFFER_OVERFLOW)
|
if (ret == STATUS_BUFFER_OVERFLOW)
|
||||||
{
|
{
|
||||||
CxbxFree(ntFileInfo);
|
g_MemoryManager.Free(ntFileInfo);
|
||||||
|
|
||||||
bufferSize *= 2;
|
bufferSize *= 2;
|
||||||
// Bail out if the buffer gets too big
|
// Bail out if the buffer gets too big
|
||||||
if (bufferSize > 65536)
|
if (bufferSize > 65536)
|
||||||
return STATUS_INVALID_PARAMETER; // TODO: what's the appropriate error code to return here?
|
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);
|
} while (ret == STATUS_BUFFER_OVERFLOW);
|
||||||
|
|
||||||
|
@ -1149,7 +1150,7 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil
|
||||||
NTSTATUS convRet = NTToXboxFileInformation(ntFileInfo, FileInformation, FileInformationClass, Length);
|
NTSTATUS convRet = NTToXboxFileInformation(ntFileInfo, FileInformation, FileInformationClass, Length);
|
||||||
|
|
||||||
// Make sure to free the memory first
|
// Make sure to free the memory first
|
||||||
CxbxFree(ntFileInfo);
|
g_MemoryManager.Free(ntFileInfo);
|
||||||
|
|
||||||
if (FAILED(ret))
|
if (FAILED(ret))
|
||||||
EmuWarning("NtQueryInformationFile failed! (0x%.08X)", ret);
|
EmuWarning("NtQueryInformationFile failed! (0x%.08X)", ret);
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace xboxkrnl
|
||||||
#include "EmuShared.h"
|
#include "EmuShared.h"
|
||||||
#include "EmuAlloc.h"
|
#include "EmuAlloc.h"
|
||||||
#include "EmuXTL.h"
|
#include "EmuXTL.h"
|
||||||
|
#include "MemoryManager.h"
|
||||||
|
|
||||||
#include <mmreg.h>
|
#include <mmreg.h>
|
||||||
#include <msacm.h>
|
#include <msacm.h>
|
||||||
|
@ -78,7 +79,7 @@ HRESULT WINAPI XTL::EMUPATCH(XACTEngineCreate)
|
||||||
|
|
||||||
// TODO: Any other form of initialization?
|
// 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
|
// TODO: Implement
|
||||||
|
|
||||||
*ppWaveBank = (X_XACTWaveBank*) CxbxCalloc(1, sizeof( X_XACTWaveBank ) );
|
*ppWaveBank = (X_XACTWaveBank*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTWaveBank ) );
|
||||||
|
|
||||||
RETURN(S_OK);
|
RETURN(S_OK);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +146,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_RegisterStreamedWaveBank)
|
||||||
|
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
|
|
||||||
*ppWaveBank = (X_XACTWaveBank*) CxbxCalloc(1, sizeof( X_XACTWaveBank ) );
|
*ppWaveBank = (X_XACTWaveBank*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTWaveBank ) );
|
||||||
|
|
||||||
RETURN(S_OK);
|
RETURN(S_OK);
|
||||||
}
|
}
|
||||||
|
@ -170,7 +171,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_CreateSoundBank)
|
||||||
|
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
|
|
||||||
*ppSoundBank = (X_XACTSoundBank*) CxbxCalloc(1, sizeof( X_XACTSoundBank ) );
|
*ppSoundBank = (X_XACTSoundBank*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTSoundBank ) );
|
||||||
|
|
||||||
RETURN(S_OK);
|
RETURN(S_OK);
|
||||||
}
|
}
|
||||||
|
@ -216,7 +217,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_CreateSoundSource)
|
||||||
LOG_FUNC_ARG(ppSoundSource)
|
LOG_FUNC_ARG(ppSoundSource)
|
||||||
LOG_FUNC_END;
|
LOG_FUNC_END;
|
||||||
|
|
||||||
*ppSoundSource = (X_XACTSoundSource*) CxbxCalloc(1, sizeof( X_XACTSoundSource ) );
|
*ppSoundSource = (X_XACTSoundSource*)g_MemoryManager.AllocateZeroed(1, sizeof( X_XACTSoundSource ) );
|
||||||
|
|
||||||
RETURN(S_OK);
|
RETURN(S_OK);
|
||||||
}
|
}
|
||||||
|
@ -513,7 +514,7 @@ HRESULT WINAPI XTL::EMUPATCH(IXACTEngine_UnRegisterWaveBank)
|
||||||
// to IXACTWaveBank is released.
|
// to IXACTWaveBank is released.
|
||||||
|
|
||||||
// if(pWaveBank)
|
// if(pWaveBank)
|
||||||
// free(pWaveBank);
|
// g_MemoryManager.Free(pWaveBank);
|
||||||
|
|
||||||
RETURN(S_OK);
|
RETURN(S_OK);
|
||||||
}
|
}
|
|
@ -0,0 +1,232 @@
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
if (ptr != nullptr) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (ptr != nullptr) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
// If the end address of the block won't meet the alignment, adjust the size
|
||||||
|
if (size % alignment > 0) {
|
||||||
|
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) {
|
||||||
|
// Start allocating Contiguous Memory after the Kernel image header to prevent overwriting our dummy Kernel
|
||||||
|
addr = XBOX_KERNEL_BASE + sizeof(DUMMY_KERNEL);
|
||||||
|
} else {
|
||||||
|
// Locate the first available Memory Region with enough space for the requested buffer
|
||||||
|
// This could be improved later on by always locating the smallest block with enough space
|
||||||
|
// in order to reduce memory fragmentation.
|
||||||
|
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 exhausted 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)
|
||||||
|
{
|
||||||
|
LOG_FUNC_ONE_ARG(block);
|
||||||
|
|
||||||
|
EnterCriticalSection(&m_CriticalSection);
|
||||||
|
bool result = m_MemoryBlockInfo.find((uint32_t)block) != m_MemoryBlockInfo.end();
|
||||||
|
LeaveCriticalSection(&m_CriticalSection);
|
||||||
|
|
||||||
|
RETURN(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryManager::Free(void* block)
|
||||||
|
{
|
||||||
|
LOG_FUNC_ONE_ARG(block);
|
||||||
|
|
||||||
|
EnterCriticalSection(&m_CriticalSection);
|
||||||
|
|
||||||
|
if (IsAllocated(block)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
__debugbreak();
|
||||||
|
CxbxKrnlCleanup("Fatal: Attempted to free memory that was not allocated via MemoryManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
LeaveCriticalSection(&m_CriticalSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MemoryManager::QueryAllocationSize(void* block)
|
||||||
|
{
|
||||||
|
LOG_FUNC_ONE_ARG(block);
|
||||||
|
|
||||||
|
EnterCriticalSection(&m_CriticalSection);
|
||||||
|
|
||||||
|
size_t ret = 0;
|
||||||
|
|
||||||
|
if (IsAllocated(block)) {
|
||||||
|
MemoryBlockInfo info = m_MemoryBlockInfo[(uint32_t)block];
|
||||||
|
ret = info.size;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EmuWarning("MemoryManager: Attempted to query memory that was not allocated via MemoryManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
LeaveCriticalSection(&m_CriticalSection);
|
||||||
|
RETURN(ret);
|
||||||
|
}
|
|
@ -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