// ****************************************************************** // * 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; }
void MemorySynchronizer::RemoveMemoryBlock(VAddr mapping, VAddr original) { memory_blocks.erase(FindMemoryBlock(mapping, original)); }
void MemorySynchronizer::ResizeMemoryBlock(VAddr mapping, VAddr original, u32 size) { FindMemoryBlock(mapping, original)->size = size; }
// ****************************************************************** // * CxbxRtlReallocDebug - Debug track RTL realloc // ****************************************************************** void *CxbxRtlReallocDebug(HANDLE Heap, DWORD Flags, PVOID pMem, SIZE_T Bytes, char *pFile, int Line) { void *pRetMem = NULL; g_MemoryMutex.Lock(); CXBX_MEMORY_BLOCK *pRealloc = FindMemoryBlock(pMem); if(pRealloc == NULL) { printf("CxbxRtlRealloc: realloc on non-existent block: 0x%.08X! " " File: %s\n" " Line: %d\n", pMem, pFile, Line); } else { if(!CheckIntegrity(pRealloc)) { printf("CxbxRtlReallocDebug: Realloc on damaged block\n" " Block : 0x.%08X\n" " Allocation\n" " Size: %d\n" " File: %s\n" " Line: %d\n" " Reallocation\n" " Size: %d\n" " File: %s\n" " Line: %d\n", pRealloc->pMem, pRealloc->pFile, pRealloc->Size, pRealloc->Line, Bytes, pFile, Line); } void *pNewMem = NtDll::RtlReAllocateHeap(Heap, Flags, GetMemStart(pRealloc), Bytes + 2 * sizeof(MEMORY_GUARD)); free(pRealloc->pFile); free(pRealloc); if(!pNewMem) { printf("CxbxRtlReallocDebug: Reallocation failed\n" " Heap : 0x%.08X\n" " Flags : 0x%.08X\n" " pMem : 0x%.08X\n" " Bytes : %d\n" " File : %s\n" " Line : %d\n", Heap, Flags, pMem, Bytes, pFile, Line); } else { CXBX_MEMORY_BLOCK *pBlock = InsertMemoryBlock(pNewMem, Bytes, pFile, Line, CXBX_ALLOC_RTL); pRetMem = pBlock->pMem; } } g_MemoryMutex.Unlock(); return pRetMem; }