示例#1
0
/////////////////////////////////////////////////////////////////////////////
// HRESULT CMallocSpy::DumpLeaks
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CMallocSpy::DumpLeaks()
{
	ULONG	cTotalLeaks	= 0;
	SIZE_T	cTotalBytes	= 0;
	DWORD	dwSelection	= IDOK;

	//Display Leaks to the Output Window
	while(!CAllocList.IsEmpty())
	{	
		//Obtain the pointer to the leaked memory
		void* pRequest = CAllocList.RemoveHead();
		ASSERT(pRequest);
		
		void* pActual = HEADER_OFFSET(pRequest);
		ASSERT(pActual);

		//Make sure that the head/tail signitures are intact
		if(HEAD_SIGNITURE(pActual) != HEADSIGN)
			InternalTraceFmt(L"TRACE - IMallocSpy HeadSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", pRequest, BUFFER_ID(pActual), BUFFER_LENGTH(pActual));

		if(TAIL_SIGNITURE(pActual) != TAILSIGN)
			InternalTraceFmt(L"TRACE - IMallocSpy TailSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", pRequest, BUFFER_ID(pActual), BUFFER_LENGTH(pActual));

		SIZE_T	ulSize		= BUFFER_LENGTH(pActual);
		ULONG	ulID		= BUFFER_ID(pActual);
		WCHAR*	pwszFileName= BUFFER_FILENAME(pActual);
		ULONG	ulLine		= BUFFER_LINENUMBER(pActual);
		
		//Display a message box for all leaks (until the user is tired of it...)
		if(dwSelection == IDOK)
		{
			dwSelection = wMessageBox(GetFocus(), MB_TASKMODAL | MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1, 
				L"IMallocSpy Leak", 
					L"IMallocSpy Leak:\n"
					L"0x%p, ID=%08lu, %Iu byte(s), File: %s, Line %d\n\n",
					pRequest, ulID, ulSize, pwszFileName, ulLine);
		}

		//Include FileName and Line Number of the leak...
		InternalTraceFmt(L"-- IMallocSpy Leak! - 0x%p,\tID=%08lu,\t%Iu byte(s),\tFile: %s,\tLine %d" wWndEOL, pRequest, ulID, ulSize, pwszFileName, ulLine);
		
		cTotalLeaks++;
		cTotalBytes += ulSize;

		//Free the Leak
		//You really cant free the leak since the app could be potentially still
		//using it.  Or the DLL may still be in use or have attached threads...
		//SAFE_FREE(pActual);
	}

	if(cTotalLeaks)
		InternalTraceFmt(L"-- IMallocSpy Total Leaks: %lu = %Iu byte(s)" wWndEOL, cTotalLeaks, cTotalBytes);
	return S_OK;
}
示例#2
0
/////////////////////////////////////////////////////////////////////////////
// void* CMallocSpy::PostAlloc
//
/////////////////////////////////////////////////////////////////////////////
void* CMallocSpy::PostAlloc(void* pActual)
{
	//E_OUTOFMEMORY condition
	if(!pActual)
		return NULL;
	
	//pActual is the pointer to the head of the buffer, including the header
	//Add the users pointer to the list
	AddToList(USERS_OFFSET(pActual));

	//Place the HeadSigniture in the HEADER
	HEAD_SIGNITURE(pActual) = HEADSIGN;
	
	//Place the Size in the HEADER
	BUFFER_LENGTH(pActual) = m_cbRequest;

	//Place the ID in the HEADER
	ULONG ulID = ++m_cAllocations;
	BUFFER_ID(pActual) = ulID;

	//Place the FILENAME in the HEADER
	BUFFER_FILENAME(pActual) = NULL;

	//Place the LINE NUMBER in the HEADER
	BUFFER_LINENUMBER(pActual) = 0;

	//Set the UsersBuffer to a known char
    memset(USERS_OFFSET(pActual), ALLOCSIGN, m_cbRequest);

	//Place the TailSigniture in the HEADER
	TAIL_SIGNITURE(pActual) = TAILSIGN;

	//Show Allocation
	if(GetErrorPosting(EP_IMALLOC_ALLOCS))
		InternalTraceFmt(L"TRACE - IMallocSpy Alloc - 0x%p,\tID=%08lu,\t%Iu byte(s)\n", USERS_OFFSET(pActual), ulID, m_cbRequest);

	//Break at indicated Allocation
	if(g_dwBreakID == ulID)
		BREAKINTO();

	// Return the actual users buffer
    return USERS_OFFSET(pActual);
}
示例#3
0
/////////////////////////////////////////////////////////////////////////////
// void* CMallocSpy::PreFree
//
/////////////////////////////////////////////////////////////////////////////
void* CMallocSpy::PreFree(void* pRequest, BOOL fSpyed)
{
	//pRequest is the users pointer to thier buffer, not the header

	//E_OUTOFMEMORY condition
	if(!pRequest)
		return NULL;

    //If this memory was alloced under IMallocSpy, need to remove it
    if(fSpyed)
	{
		//Remove this pointer from the list
		RemoveFromList(pRequest);
	
		void* pActual	= HEADER_OFFSET(pRequest);
		ULONG ulID		= BUFFER_ID(pActual);
		
		//Make sure that the head/tail signitures are intact
		if(HEAD_SIGNITURE(pActual) != HEADSIGN)
			InternalTraceFmt(L"TRACE - IMallocSpy HeadSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", pRequest, ulID, BUFFER_LENGTH(pActual));

		if(TAIL_SIGNITURE(pActual) != TAILSIGN)
			InternalTraceFmt(L"TRACE - IMallocSpy TailSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", pRequest, ulID, BUFFER_LENGTH(pActual));

		//Break at indicated Allocation
		if(g_dwBreakID == ulID)
			BREAKINTO();

		//Set the UsersBuffer to a known char
		memset(pRequest, FREESIGN, BUFFER_LENGTH(pActual));

		//Need to return the actual header pointer to
		//free the entire buffer including the heading
		return pActual;
	}

	//else
	return pRequest;
}
示例#4
0
/////////////////////////////////////////////////////////////////////////////
// void* CMallocSpy::PostRealloc
//
/////////////////////////////////////////////////////////////////////////////
void* CMallocSpy::PostRealloc(void* pActual, BOOL fSpyed)
{
	//E_OUTOFMEMORY condition
	if(!pActual)
		return NULL;

    //If this buffer was alloced under IMallocSpy
    if(fSpyed)
    {
		//pActual is the pointer to header
		//Add the new pointer to the list
		AddToList(USERS_OFFSET(pActual));

		//HeadSigniture should still be intact
		if(HEAD_SIGNITURE(pActual) != HEADSIGN)
			InternalTraceFmt(L"TRACE - IMallocSpy HeadSigniture Corrupted! - 0x%p, ID=%08lu, %Iu byte(s)\n", USERS_OFFSET(pActual), BUFFER_ID(pActual), BUFFER_LENGTH(pActual));
		
		//ID should still be intact

		//Place the new Size in the HEADER
		BUFFER_LENGTH(pActual) = m_cbRequest;

		//Place the new FileName in the HEADER
		BUFFER_FILENAME(pActual) = NULL;

		//Place the new Line Number in the HEADER
		BUFFER_LINENUMBER(pActual) = 0;
		
        //Need to place the tail signiture again, 
		//since it will be over written by the realloc
		TAIL_SIGNITURE(pActual) = TAILSIGN;

		//Show ReAllocations
		if(GetErrorPosting(EP_IMALLOC_ALLOCS))
			InternalTraceFmt(L"TRACE - IMallocSpy Realloc - 0x%p,\tID=%08lu,\t%Iu byte(s)\n", USERS_OFFSET(pActual), BUFFER_ID(pActual), m_cbRequest);

		//Return the actual "user" buffer
		return USERS_OFFSET(pActual);
    }
    
	//else
    return pActual;
}
示例#5
0
   SRC_SEL_W(SQ_SEL_1),
   R6xx_ELEM_LOOP(0),
   BURST_COUNT(0),
   END_OF_PROGRAM(1),
   VALID_PIXEL_MODE(0),
   CF_INST(SQ_CF_INST_EXPORT_DONE),
   WHOLE_QUAD_MODE(0),
   BARRIER(0)),
 /* 3 */
 0x00000000,
 0x00000000,
 /* 4/5 */
 VTX_DWORD0(VTX_INST(SQ_VTX_INST_FETCH),
   FETCH_TYPE(SQ_VTX_FETCH_VERTEX_DATA),
   FETCH_WHOLE_QUAD(0),
   BUFFER_ID(0),
   SRC_GPR(0),
   SRC_REL(ABSOLUTE),
   SRC_SEL_X(SQ_SEL_X),
   MEGA_FETCH_COUNT(16)),
 VTX_DWORD1_GPR(DST_GPR(0),
   DST_REL(0),
   DST_SEL_X(SQ_SEL_X),
   DST_SEL_Y(SQ_SEL_Y),
   DST_SEL_Z(SQ_SEL_Z),
   DST_SEL_W(SQ_SEL_W),
   USE_CONST_FIELDS(0),
   DATA_FORMAT(FMT_32_32_32_32_FLOAT),
   NUM_FORMAT_ALL(SQ_NUM_FORMAT_SCALED),
   FORMAT_COMP_ALL(SQ_FORMAT_COMP_SIGNED),
   SRF_MODE_ALL(SRF_MODE_ZERO_CLAMP_MINUS_ONE)),