📄 memtrk.c
字号:
if (!pTOC->ulTrackingLen || !pTOC->ulTrackingStart) { goto errret; } if (!uiTablesize && !PerformCallBack4(&cbi,0)){ ERRORMSG(1, (L"MEMTR: Out of resource tracking memory!\r\n")); SetLastError(ERROR_NOT_ENOUGH_SERVER_MEMORY); goto errret; } DEBUGCHK(table); // Check for any installed filters if (dwType>=MAX_REGTYPES || (rgRegTypes[dwType].dwFlags®TYPE_MASKED) || ((lpFilterInfo->dwFlags&FILTER_PROCIDON)&&(lpFilterInfo->dwProcID!=dwProcID))) { goto errret; } uiRealHash=uiHashVal=MEMTR_hash(dwType,handle); do { if (!table[uiHashVal].Frames[0]) break; if (++uiHashVal == uiTablesize) uiHashVal=0; } while (uiRealHash!=uiHashVal); if (table[uiHashVal].Frames[0]) { ERRORMSG(1, (L"MEMTR: Out of resource tracking memory!\r\n")); SetLastError(ERROR_NOT_ENOUGH_SERVER_MEMORY); goto errret; } DEBUGMSG(ZONE_MEMTRACKER, (L"Adding handle %8.8lx at spot %8.8lx\r\n", (DWORD)handle, (DWORD)uiHashVal)); table[uiHashVal].handle = handle; table[uiHashVal].cb=cb; table[uiHashVal].dw1=dw1; table[uiHashVal].dw2=dw2; table[uiHashVal].dwProcID = (DWORD)HandleToPointer((HANDLE)dwProcID); table[uiHashVal].dwType = dwType; table[uiHashVal].dwSize = dwSize; table[uiHashVal].dwTime=GetTickCount(); table[uiHashVal].hProc = hCurProc; { CALLBACKINFO cbstack = {ProcArray[0].hProc,(FARPROC)MEMTR_GetStackFrames,table[uiHashVal].Frames}; PerformCallBack4(&cbstack); } table[uiHashVal].pnNext=NULL; table[uiHashVal].pnPrev = pnLast; DEBUGCHK((pnFirst || !pnLast) && (!pnFirst || pnLast)); if (pnLast) { pnLast->pnNext = &table[uiHashVal]; } else { pnFirst=&table[uiHashVal]; } pnLast = &table[uiHashVal]; LeaveCriticalSection(&Trackcs); return TRUE;errret: LeaveCriticalSection(&Trackcs);#endif return FALSE;}/*@func BOOL | DeleteTrackedItem | Deregisters a resource item@rdesc TRUE if the item was found and removed, FALSE otherwise.@parm DWORD | dwType | TypeID this resource was registered with.@parm HANDLE | handle | Handle this resource was registered with@xref <f RegisterTrackedItem> <f AddTrackedItem> <f PrintTrackedItem> <f FilterTrackedItem> <f TrackerCallBack>*/BOOL SC_DeleteTrackedItem(DWORD dwType, HANDLE handle){#ifdef MEMTRACKING UINT uiHashVal, uiRealHash; BOOL fFound = FALSE; EnterCriticalSection(&Trackcs); if (!pTOC->ulTrackingLen || !pTOC->ulTrackingStart) { goto errret; } if (!uiTablesize && !PerformCallBack4(&cbi,0)){ ERRORMSG(1, (L"MEMTR: Out of resource tracking memory!\r\n")); SetLastError(ERROR_NOT_ENOUGH_SERVER_MEMORY); goto errret; } DEBUGCHK(table); // check for type filters - cant check for process filters if (dwType>=MAX_REGTYPES || (rgRegTypes[dwType].dwFlags®TYPE_MASKED)) { goto errret; } uiRealHash=uiHashVal=MEMTR_hash(dwType,handle); do { if ((table[uiHashVal].handle==handle) && (table[uiHashVal].dwType==dwType) && !(table[uiHashVal].dwFlags&ITEM_DELETED)) { fFound = TRUE; break; } if (++uiHashVal == uiTablesize) uiHashVal=0; } while (uiRealHash!=uiHashVal); if (!fFound) { DEBUGMSG(ZONE_MEMTRACKER, (L"MEMTR: Delete - invalid handle!\r\n")); SetLastError(ERROR_INVALID_TARGET_HANDLE); goto errret; } // check if it has been shown if (table[uiHashVal].dwFlags&ITEM_SHOWN) { // pend the delete table[uiHashVal].dwFlags |= ITEM_DELETED; DEBUGMSG(ZONE_MEMTRACKER, (L"Pending Delete handle %8.8lx at spot %8.8lx\r\n", (DWORD)handle, (DWORD)uiHashVal)); } else { // really delete it DEBUGMSG(ZONE_MEMTRACKER, (L"Deleting handle %8.8lx at spot %8.8lx\r\n", (DWORD)handle, (DWORD)uiHashVal)); MEMTR_deletenode(table+uiHashVal); } LeaveCriticalSection(&Trackcs); return TRUE;errret: LeaveCriticalSection(&Trackcs);#endif return FALSE; }#ifdef MEMTRACKINGvoid MEMTR_deletenode(pTrack_Node pn){ if (pn->pnPrev) { pn->pnPrev->pnNext = pn->pnNext; } if (pn->pnNext) { pn->pnNext->pnPrev = pn->pnPrev; } if (pnFirst == pn) pnFirst = pn->pnNext; if (pnLast == pn) pnLast = pn->pnPrev; memset(pn, 0, sizeof(Track_Node));}// placeholderint MEMTR_hash(DWORD dwType, HANDLE handle){ return 0;// return ((DWORD)handle)%uiTablesize;}#ifdef WINCEPROFILE//---------------------------------------------------------------------------// GetEXEProfEntry - returns the PROFentry for the specified process//---------------------------------------------------------------------------PROFentry *GetEXEProfEntry(ULONG Index) { // EXE PPROCESS pProc = (PPROCESS)&ProcArray[Index]; PROFentry *pEntry; UINT i, j; LPTOCentry pTOCEntry = (LPTOCentry)((LPBYTE)pTOC + sizeof(ROMHDR)); for(i=0; i < pTOC->nummods; i++, pTOCEntry++) { if(pProc->oe.tocptr == pTOCEntry) { break; } } if(i >= pTOC->nummods) { return NULL; } pEntry = (PROFentry *)pTOC->ulProfileOffset; for(j=0; j < pTOC->nummods; j++, pEntry++) { if(pEntry->ulModNum == i) { return pEntry; } } return NULL;}//---------------------------------------------------------------------------// GetFixedProfEntry - returns the PROFentry for the DLL in which the // address was found.//---------------------------------------------------------------------------PROFentry *GetFixedProfEntry(ULONG p) { // DLL or Kernel UINT i; PROFentry *pEntry; pEntry = (PROFentry *)pTOC->ulProfileOffset; for(i=0; i < pTOC->nummods; i++, pEntry++) { if(p > pEntry->ulStartAddr && p < pEntry->ulEndAddr) { return pEntry; } } return NULL;}//---------------------------------------------------------------------------// GetSymbolText - searches symbol table for passed symbol number//---------------------------------------------------------------------------static LPBYTE GetSymbolText(LPBYTE lpSym, DWORD dwSymNum){ while (dwSymNum > 0) { while (*lpSym++); dwSymNum--; } return lpSym;}//---------------------------------------------------------------------------// GetSymbol - searches symbol table for the specified address in the// specified module. (Returns symbol text + function base addr)//---------------------------------------------------------------------------LPSTR GetSymbol(PROFentry *pProfEntry, ULONG p, ULONG *pulFuncAddr) { UINT i; if(pProfEntry->ulNumSym) { SYMentry *pSym = (SYMentry *)pProfEntry->ulHitAddress; for(i=0; i < pProfEntry->ulNumSym; i++, pSym++) { if(p < pSym->ulFuncAddress) { break; } } if(i) { pSym--; *pulFuncAddr = pSym->ulFuncAddress; return GetSymbolText((LPBYTE)pProfEntry->ulSymAddress, i-1); } } *pulFuncAddr = 0; return NULL;}#endif // WINCEPROFILE#pragma optimize ("", off)void MEMTR_printnode(DWORD dwFlags, pTrack_Node pn){ CALLBACKINFO cbiPrint; DWORD Cnt; ACCESSKEY ulOldKey; SWITCHKEY(ulOldKey,0xffffffff); if (dwFlags&PRINT_DETAILS) { if (pn->cb) { RETAILMSG(1,(L" 0x%08x:0x%08x(%8.8u):%6.6ld::", pn->dwProcID, pn->handle, pn->dwTime, pn->dwSize)); cbiPrint.hProc = pn->hProc; cbiPrint.pfn = (FARPROC)(pn->cb); cbiPrint.pvArg0 = (PVOID)dwFlags; PerformCallBack (&cbiPrint, pn->dwType, pn->handle, pn->dwProcID, pn->dwFlags&ITEM_DELETED, pn->dwSize, pn->dw1, pn->dw2); } else { RETAILMSG(1,(L" 0x%08x:0x%08x(%8.8u):%6.6ld", pn->dwProcID, pn->handle, pn->dwTime, pn->dwSize)); if (pn->dw1 || pn->dw2) { RETAILMSG(1,(L"::%08lx:%08lx:", pn->dw1, pn->dw2)); } if (pn->dwType == 0 && (pn->dwFlags & ITEM_DELETED) == 0) { // Look for special type 0 pTrack_Node pnTest; for (pnTest = pnFirst; pnTest; pnTest = pnTest->pnNext) { if ((!(pnTest->dwFlags & ITEM_DELETED)) && (ULONG)pnTest->handle >= (ULONG)pn->handle && ((ULONG)pnTest->handle) < ((ULONG)pn->handle) + pn->dwSize && pnTest != pn) { RETAILMSG(1,(L" %s", rgRegTypes[pnTest->dwType].szName)); break; } } } RETAILMSG(1,(L"\r\n")); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -