Changeset 69971 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Dec 7, 2017 11:16:53 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/alloc/memtracker.cpp
r69111 r69971 505 505 * @param cbUser The size requested by the user. 506 506 * @param pszTag The tag string. 507 * @param pvCaller The return address. 507 508 * @param enmMethod The allocation method. 508 509 */ 509 510 static void *rtMemTrackerHdrAllocEx(PRTMEMTRACKERINT pTracker, void *pv, size_t cbUser, 510 const char *pszTag, RTMEMTRACKERMETHOD enmMethod)511 const char *pszTag, void *pvCaller, RTMEMTRACKERMETHOD enmMethod) 511 512 { 512 513 /* … … 528 529 pHdr->pszTag = pszTag; 529 530 pHdr->pTag = NULL; 531 pHdr->pvCaller = pvCaller; 530 532 pHdr->pvUser = pHdr + 1; 533 pHdr->uReserved = 0; 531 534 532 535 /* … … 579 582 * @param cbUser The size of the user memory or 0. 580 583 * @param pszTag The tag to associate the free with. 584 * @param pvCaller The return address. 581 585 * @param enmMethod The free method. 582 586 * @param uDeadMagic The dead magic value to use. 583 587 */ 584 588 static void *rtMemTrackerHdrFreeCommon(PRTMEMTRACKERINT pTracker, void *pvUser, size_t cbUser, 585 const char *pszTag, RTMEMTRACKERMETHOD enmMethod,589 const char *pszTag, void *pvCaller, RTMEMTRACKERMETHOD enmMethod, 586 590 size_t uDeadMagic) 587 591 { … … 633 637 634 638 /** @todo we're currently ignoring pszTag, consider how to correctly 635 * attribute the free operation if the tags differ - i t639 * attribute the free operation if the tags differ - if it 636 640 * makes sense at all... */ 637 641 NOREF(pszTag); … … 656 660 } 657 661 662 NOREF(pvCaller); /* Intended for We may later do some use-after-free tracking. */ 658 663 return pHdr; 659 664 } … … 669 674 * @param cbOldUser The size of the user memory, 0 if unknown. 670 675 * @param pszTag The tag string. 671 */ 672 static void *rtMemTrackerHdrReallocPrepEx(PRTMEMTRACKERINT pTracker, void *pvOldUser, size_t cbOldUser, const char *pszTag) 676 * @param pvCaller The return address. 677 */ 678 static void *rtMemTrackerHdrReallocPrepEx(PRTMEMTRACKERINT pTracker, void *pvOldUser, size_t cbOldUser, 679 const char *pszTag, void *pvCaller) 673 680 { 674 681 if (!pvOldUser) 675 682 return NULL; 676 return rtMemTrackerHdrFreeCommon(pTracker, pvOldUser, cbOldUser, pszTag, 683 return rtMemTrackerHdrFreeCommon(pTracker, pvOldUser, cbOldUser, pszTag, pvCaller, 677 684 RTMEMTRACKERMETHOD_REALLOC_PREP, RTMEMTRACKERHDR_MAGIC_REALLOC); 678 685 } … … 689 696 * @param pvOldUser Pointer to the old user memory. 690 697 * @param pszTag The tag string. 698 * @param pvCaller The return address. 691 699 */ 692 700 static void *rtMemTrackerHdrReallocDoneEx(PRTMEMTRACKERINT pTracker, void *pvNew, size_t cbNewUser, 693 void *pvOldUser, const char *pszTag )701 void *pvOldUser, const char *pszTag, void *pvCaller) 694 702 { 695 703 /* Succeeded? */ 696 704 if (pvNew) 697 return rtMemTrackerHdrAllocEx(pTracker, pvNew, cbNewUser, pszTag, RTMEMTRACKERMETHOD_REALLOC_DONE);705 return rtMemTrackerHdrAllocEx(pTracker, pvNew, cbNewUser, pszTag, pvCaller, RTMEMTRACKERMETHOD_REALLOC_DONE); 698 706 699 707 /* Failed or just realloc to zero? */ … … 703 711 AssertReturn(pHdr->uMagic == RTMEMTRACKERHDR_MAGIC_REALLOC, NULL); 704 712 705 return rtMemTrackerHdrAllocEx(pTracker, pHdr, pHdr->cbUser, pszTag, RTMEMTRACKERMETHOD_REALLOC_FAILED);713 return rtMemTrackerHdrAllocEx(pTracker, pHdr, pHdr->cbUser, pszTag, pvCaller, RTMEMTRACKERMETHOD_REALLOC_FAILED); 706 714 } 707 715 … … 719 727 * @param cbUser The size of the user memory, 0 if unknown. 720 728 * @param pszTag The tag string. 729 * @param pvCaller The return address. 721 730 * @param enmMethod The free method. 722 731 */ 723 732 static void *rtMemTrackerHdrFreeEx(PRTMEMTRACKERINT pTracker, void *pvUser, size_t cbUser, 724 const char *pszTag, RTMEMTRACKERMETHOD enmMethod)733 const char *pszTag, void *pvCaller, RTMEMTRACKERMETHOD enmMethod) 725 734 { 726 735 if (!pvUser) 727 736 return NULL; 728 return rtMemTrackerHdrFreeCommon(pTracker, pvUser, cbUser, pszTag, enmMethod, RTMEMTRACKERHDR_MAGIC_FREE);737 return rtMemTrackerHdrFreeCommon(pTracker, pvUser, cbUser, pszTag, pvCaller, enmMethod, RTMEMTRACKERHDR_MAGIC_FREE); 729 738 } 730 739 … … 825 834 if (pCurHdr->pTag) 826 835 pOutput->pfnPrintf(pOutput, 827 " %zu bytes at %p with tag %s\n"828 " 836 " %zu bytes at %p by %p with tag %s\n" 837 "%.*Rhxd\n" 829 838 "\n", 830 pCurHdr->cbUser, pCurHdr->pvUser, pCurHdr->p Tag->szTag,839 pCurHdr->cbUser, pCurHdr->pvUser, pCurHdr->pvCaller, pCurHdr->pTag->szTag, 831 840 RT_MIN(pCurHdr->cbUser, 16*3), pCurHdr->pvUser); 832 841 else 833 842 pOutput->pfnPrintf(pOutput, 834 " %zu bytes at %p without a tag\n"835 " 843 " %zu bytes at %p by %p without a tag\n" 844 "%.*Rhxd\n" 836 845 "\n", 837 pCurHdr->cbUser, pCurHdr->pvUser, 846 pCurHdr->cbUser, pCurHdr->pvUser, pCurHdr->pvCaller, 838 847 RT_MIN(pCurHdr->cbUser, 16*3), pCurHdr->pvUser); 839 848 } … … 1214 1223 1215 1224 1216 RTDECL(void *) RTMemTrackerHdrAlloc(void *pv, size_t cb, const char *pszTag, RTMEMTRACKERMETHOD enmMethod)1225 RTDECL(void *) RTMemTrackerHdrAlloc(void *pv, size_t cb, const char *pszTag, void *pvCaller, RTMEMTRACKERMETHOD enmMethod) 1217 1226 { 1218 1227 PRTMEMTRACKERINT pTracker = g_pDefaultTracker; 1219 1228 if (RT_UNLIKELY(!pTracker)) 1220 1229 pTracker = rtMemTrackerLazyInitDefaultTracker(); 1221 return rtMemTrackerHdrAllocEx(pTracker, pv, cb, pszTag, enmMethod);1222 } 1223 1224 1225 RTDECL(void *) RTMemTrackerHdrReallocPrep(void *pvOldUser, size_t cbOldUser, const char *pszTag )1230 return rtMemTrackerHdrAllocEx(pTracker, pv, cb, pszTag, pvCaller, enmMethod); 1231 } 1232 1233 1234 RTDECL(void *) RTMemTrackerHdrReallocPrep(void *pvOldUser, size_t cbOldUser, const char *pszTag, void *pvCaller) 1226 1235 { 1227 1236 PRTMEMTRACKERINT pTracker = g_pDefaultTracker; 1228 1237 if (RT_UNLIKELY(!pTracker)) 1229 1238 pTracker = rtMemTrackerLazyInitDefaultTracker(); 1230 return rtMemTrackerHdrReallocPrepEx(pTracker, pvOldUser, cbOldUser, pszTag );1231 } 1232 1233 1234 RTDECL(void *) RTMemTrackerHdrReallocDone(void *pvNew, size_t cbNewUser, void *pvOld, const char *pszTag )1239 return rtMemTrackerHdrReallocPrepEx(pTracker, pvOldUser, cbOldUser, pszTag, pvCaller); 1240 } 1241 1242 1243 RTDECL(void *) RTMemTrackerHdrReallocDone(void *pvNew, size_t cbNewUser, void *pvOld, const char *pszTag, void *pvCaller) 1235 1244 { 1236 1245 PRTMEMTRACKERINT pTracker = g_pDefaultTracker; 1237 1246 if (RT_UNLIKELY(!pTracker)) 1238 1247 pTracker = rtMemTrackerLazyInitDefaultTracker(); 1239 return rtMemTrackerHdrReallocDoneEx(pTracker, pvNew, cbNewUser, pvOld, pszTag );1240 } 1241 1242 1243 RTDECL(void *) RTMemTrackerHdrFree(void *pvUser, size_t cbUser, const char *pszTag, RTMEMTRACKERMETHOD enmMethod)1248 return rtMemTrackerHdrReallocDoneEx(pTracker, pvNew, cbNewUser, pvOld, pszTag, pvCaller); 1249 } 1250 1251 1252 RTDECL(void *) RTMemTrackerHdrFree(void *pvUser, size_t cbUser, const char *pszTag, void *pvCaller, RTMEMTRACKERMETHOD enmMethod) 1244 1253 { 1245 1254 PRTMEMTRACKERINT pTracker = g_pDefaultTracker; 1246 1255 if (RT_UNLIKELY(!pTracker)) 1247 1256 pTracker = rtMemTrackerLazyInitDefaultTracker(); 1248 return rtMemTrackerHdrFreeEx(pTracker, pvUser, cbUser, pszTag, enmMethod);1257 return rtMemTrackerHdrFreeEx(pTracker, pvUser, cbUser, pszTag, pvCaller, enmMethod); 1249 1258 } 1250 1259
Note:
See TracChangeset
for help on using the changeset viewer.