Debug heap allocation tracker
This commit is contained in:
parent
758e4b52a9
commit
6633af7ba2
|
@ -35,12 +35,13 @@
|
|||
#include <malloc.h>
|
||||
|
||||
#ifdef _DEBUG_ALLOC
|
||||
#define CxbxMalloc(x) CxbxMallocDebug(x, __FILE__, __LINE__)
|
||||
#define CxbxCalloc(x, y) CxbxCallocDebug(x, y, __FILE__, __LINE__)
|
||||
#define CxbxFree(x) CxbxFreeDebug(x, __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 CxbxMalloc(x) CxbxMallocDebug(x, __FILE__, __LINE__)
|
||||
#define CxbxCalloc(x, y) CxbxCallocDebug(x, y, __FILE__, __LINE__)
|
||||
#define CxbxFree(x) CxbxFreeDebug(x, __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__)
|
||||
#define CxbxRtlSizeHeap(Heap, Flags, pMem) CxbxRtlSizeHeapDebug(Heap, Flags, pMem, __FILE__, __LINE__)
|
||||
|
||||
// ******************************************************************
|
||||
// * CxbxMallocDebug - Debug track malloc
|
||||
|
@ -79,8 +80,8 @@ void *CxbxRtlAllocDebug(HANDLE Heap,
|
|||
BOOL CxbxRtlFreeDebug(HANDLE Heap,
|
||||
DWORD Flags,
|
||||
PVOID pMem,
|
||||
char *pFile,
|
||||
int Line);
|
||||
char *pFile,
|
||||
int Line);
|
||||
|
||||
// ******************************************************************
|
||||
// * CxbxRtlReallocDebug - Debug track RTL realloc
|
||||
|
@ -89,8 +90,17 @@ void *CxbxRtlReallocDebug(HANDLE Heap,
|
|||
DWORD Flags,
|
||||
PVOID pMem,
|
||||
SIZE_T Bytes,
|
||||
char *pFile,
|
||||
int Line);
|
||||
char *pFile,
|
||||
int Line);
|
||||
|
||||
// ******************************************************************
|
||||
// * CxbxRtlHeapSizeDebug - Debug track RTL heap size
|
||||
// ******************************************************************
|
||||
SIZE_T CxbxRtlSizeHeapDebug(HANDLE Heap,
|
||||
DWORD Flags,
|
||||
PVOID pMem,
|
||||
char *pFile,
|
||||
int Line);
|
||||
|
||||
// ******************************************************************
|
||||
// * CxbxAllocDump - Dump the memory allocations
|
||||
|
@ -98,12 +108,13 @@ void *CxbxRtlReallocDebug(HANDLE Heap,
|
|||
void CxbxAllocDump(bool DumpData);
|
||||
|
||||
#else // _DEBUG_ALLOC
|
||||
#define CxbxMalloc(x) malloc(x)
|
||||
#define CxbxCalloc(x, y) calloc(x, y)
|
||||
#define CxbxFree(x) free(x)
|
||||
#define CxbxRtlAlloc(Heap, Flags, Bytes) NtDll::RtlAllocateHeap(Heap, Flags, Bytes)
|
||||
#define CxbxRtlFree(Heap, Flags, pMem) NtDll::RtlFreeHeap(Heap, Flags, pMem)
|
||||
#define CxbxMalloc(x) malloc(x)
|
||||
#define CxbxCalloc(x, y) calloc(x, y)
|
||||
#define CxbxFree(x) free(x)
|
||||
#define CxbxRtlAlloc(Heap, Flags, Bytes) NtDll::RtlAllocateHeap(Heap, Flags, Bytes)
|
||||
#define CxbxRtlFree(Heap, Flags, pMem) NtDll::RtlFreeHeap(Heap, Flags, pMem)
|
||||
#define CxbxRtlRealloc(Heap, Flags, pMem, Bytes) NtDll::RtlReAllocateHeap(Heap, Flags, pMem, Bytes)
|
||||
#define CxbxRtlSizeHeap(Heap, Flags, pMem) NtDll::RtlSizeHeap(Heap, Flags, pMem)
|
||||
#endif
|
||||
|
||||
#endif // EMUALLOC_H
|
||||
|
|
|
@ -400,8 +400,8 @@ void *CxbxRtlAllocDebug(HANDLE Heap,
|
|||
BOOL CxbxRtlFreeDebug(HANDLE Heap,
|
||||
DWORD Flags,
|
||||
PVOID pMem,
|
||||
char *pFile,
|
||||
int Line)
|
||||
char *pFile,
|
||||
int Line)
|
||||
{
|
||||
BOOL Ret = FALSE;
|
||||
if (pMem == NULL)
|
||||
|
@ -443,14 +443,14 @@ BOOL CxbxRtlFreeDebug(HANDLE Heap,
|
|||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * CxbxRtlReallocDEbug - Debug track RTL realloc
|
||||
// * CxbxRtlReallocDebug - Debug track RTL realloc
|
||||
// ******************************************************************
|
||||
void *CxbxRtlReallocDebug(HANDLE Heap,
|
||||
DWORD Flags,
|
||||
PVOID pMem,
|
||||
SIZE_T Bytes,
|
||||
char *pFile,
|
||||
int Line)
|
||||
char *pFile,
|
||||
int Line)
|
||||
{
|
||||
void *pRetMem = NULL;
|
||||
g_MemoryMutex.Lock();
|
||||
|
@ -481,7 +481,7 @@ void *CxbxRtlReallocDebug(HANDLE Heap,
|
|||
pRealloc->pFile, pRealloc->Size, pRealloc->Line,
|
||||
Bytes, pFile, Line);
|
||||
}
|
||||
void *pNewMem = NtDll::RtlReAllocateHeap(Heap, Flags, pMem, Bytes + 2 * sizeof(MEMORY_GUARD));
|
||||
void *pNewMem = NtDll::RtlReAllocateHeap(Heap, Flags, GetMemStart(pRealloc), Bytes + 2 * sizeof(MEMORY_GUARD));
|
||||
free(pRealloc->pFile);
|
||||
free(pRealloc);
|
||||
if(!pNewMem)
|
||||
|
@ -510,4 +510,44 @@ void *CxbxRtlReallocDebug(HANDLE Heap,
|
|||
return pRetMem;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * CxbxRtlSizeHeapDebug - Debug track RTL heap size
|
||||
// ******************************************************************
|
||||
SIZE_T CxbxRtlSizeHeapDebug(HANDLE Heap,
|
||||
DWORD Flags,
|
||||
PVOID pMem,
|
||||
char *pFile,
|
||||
int Line)
|
||||
{
|
||||
SIZE_T Size = 0;
|
||||
g_MemoryMutex.Lock();
|
||||
|
||||
CXBX_MEMORY_BLOCK *pBlock = FindMemoryBlock(pMem);
|
||||
if(pBlock == NULL)
|
||||
{
|
||||
printf("CxbxRtlSizeHeap: size heap on non-existent block: 0x%.08X! "
|
||||
" File: %s\n"
|
||||
" Line: %d\n",
|
||||
pMem, pFile, Line);
|
||||
}
|
||||
else
|
||||
{
|
||||
SIZE_T ActualSize = NtDll::RtlSizeHeap(Heap, Flags, GetMemStart(pBlock))
|
||||
- 2 * sizeof(MEMORY_GUARD);
|
||||
if(ActualSize != pBlock->Size)
|
||||
{
|
||||
printf("CxbxRtlSizeHeap: heap size mismatch, RtlSizeHeap: %d Tracker: %d\n"
|
||||
" File : %s\n"
|
||||
" Line : %d\n",
|
||||
ActualSize,
|
||||
pBlock->Size,
|
||||
pFile,
|
||||
Line);
|
||||
}
|
||||
Size = ActualSize;
|
||||
}
|
||||
|
||||
g_MemoryMutex.Unlock();
|
||||
return Size;
|
||||
}
|
||||
#endif // _DEBUG_ALLOC
|
|
@ -214,7 +214,7 @@ SIZE_T WINAPI XTL::EmuRtlSizeHeap
|
|||
GetCurrentThreadId(), hHeap, dwFlags, lpMem);
|
||||
//*/
|
||||
|
||||
SIZE_T ret = NtDll::RtlSizeHeap(hHeap, dwFlags, lpMem);
|
||||
SIZE_T ret = CxbxRtlSizeHeap(hHeap, dwFlags, lpMem);
|
||||
|
||||
EmuSwapFS(); // XBox FS
|
||||
|
||||
|
|
Loading…
Reference in New Issue