- Timestamp:
- Mar 28, 2008 5:05:00 PM (17 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/MMInternal.h
r6796 r7632 145 145 #if defined(VBOX_STRICT) || defined(__DOXYGEN__) 146 146 # define MMHYPER_HEAP_FREE_POISON 0xCB 147 #endif 148 149 /** @def MMHYPER_HEAP_STRICT 150 * Enables a bunch of assertions in the heap code. */ 151 #if defined(VBOX_STRICT) || defined(__DOXYGEN__) 152 # define MMHYPER_HEAP_STRICT 1 153 # if 0 || defined(__DOXYGEN__) 154 /** @def MMHYPER_HEAP_STRICT_FENCE 155 * Enables tail fence. */ 156 # define MMHYPER_HEAP_STRICT_FENCE 157 /** @def MMHYPER_HEAP_STRICT_FENCE_SIZE 158 * The fence size in bytes. */ 159 # define MMHYPER_HEAP_STRICT_FENCE_SIZE 256 160 /** @def MMHYPER_HEAP_STRICT_FENCE_U32 161 * The fence filler. */ 162 # define MMHYPER_HEAP_STRICT_FENCE_U32 0xdeadbeef 163 # endif 147 164 #endif 148 165 -
trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp
r6529 r7632 37 37 * Defined Constants And Macros * 38 38 *******************************************************************************/ 39 #ifdef DEBUG40 # define MMHYPER_HEAP_STRICT 141 #endif42 43 39 #define ASSERT_L(u1, u2) AssertMsg((u1) < (u2), ("u1=%#x u2=%#x\n", u1, u2)) 44 40 #define ASSERT_LE(u1, u2) AssertMsg((u1) <= (u2), ("u1=%#x u2=%#x\n", u1, u2)) … … 149 145 static int mmHyperFree(PMMHYPERHEAP pHeap, PMMHYPERCHUNK pChunk); 150 146 #ifdef MMHYPER_HEAP_STRICT 151 static void mm R3HyperHeapCheck(PMMHYPERHEAP pHeap);147 static void mmHyperHeapCheck(PMMHYPERHEAP pHeap); 152 148 #endif 153 149 … … 299 295 Log3(("mmHyperAllocChunk: Enter cb=%#x uAlignment=%#x\n", cb, uAlignment)); 300 296 #ifdef MMHYPER_HEAP_STRICT 301 mmR3HyperHeapCheck(pHeap); 297 mmHyperHeapCheck(pHeap); 298 #endif 299 #ifdef MMHYPER_HEAP_STRICT_FENCE 300 uint32_t cbFence = RT_MAX(MMHYPER_HEAP_STRICT_FENCE_SIZE, uAlignment); 301 cb += cbFence; 302 302 #endif 303 303 … … 509 509 } 510 510 511 #ifdef MMHYPER_HEAP_STRICT_FENCE 512 uint32_t *pu32End = (uint32_t *)((uint8_t *)(pRet + 1) + cb); 513 uint32_t *pu32EndReal = pRet->offNext 514 ? (uint32_t *)((uint8_t *)pRet + pRet->offNext) 515 : (uint32_t *)(pHeap->CTXSUFF(pbHeap) + pHeap->cbHeap); 516 cbFence += (uintptr_t)pu32EndReal - (uintptr_t)pu32End; Assert(!(cbFence & 0x3)); 517 ASMMemFill32((uint8_t *)pu32EndReal - cbFence, cbFence, MMHYPER_HEAP_STRICT_FENCE_U32); 518 pu32EndReal[-1] = cbFence; 519 #endif 511 520 #ifdef MMHYPER_HEAP_STRICT 512 mm R3HyperHeapCheck(pHeap);521 mmHyperHeapCheck(pHeap); 513 522 #endif 514 523 return pRet; … … 531 540 532 541 #ifdef MMHYPER_HEAP_STRICT 533 mm R3HyperHeapCheck(pHeap);542 mmHyperHeapCheck(pHeap); 534 543 #endif 535 544 … … 615 624 616 625 #ifdef MMHYPER_HEAP_STRICT 617 mm R3HyperHeapCheck(pHeap);626 mmHyperHeapCheck(pHeap); 618 627 #endif 619 628 return pvRet; … … 776 785 VERR_INVALID_POINTER); 777 786 787 #ifdef MMHYPER_HEAP_STRICT 788 mmHyperHeapCheck(pHeap); 789 #endif 790 778 791 #if defined(VBOX_WITH_STATISTICS) || defined(MMHYPER_HEAP_FREE_POISON) 779 792 /* calc block size. */ … … 857 870 Log3(("mmHyperFree: Enter pHeap=%p pChunk=%p\n", pHeap, pChunk)); 858 871 PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)pChunk; 859 860 #ifdef MMHYPER_HEAP_STRICT861 mmR3HyperHeapCheck(pHeap);862 #endif863 872 864 873 /* … … 1009 1018 1010 1019 #ifdef MMHYPER_HEAP_STRICT 1011 mm R3HyperHeapCheck(pHeap);1020 mmHyperHeapCheck(pHeap); 1012 1021 #endif 1013 1022 return VINF_SUCCESS; … … 1015 1024 1016 1025 1026 #if defined(DEBUG) || defined(MMHYPER_HEAP_STRICT) 1027 /** 1028 * Dumps a heap chunk to the log. 1029 * 1030 * @param pHeap Pointer to the heap. 1031 * @param pCur Pointer to the chunk. 1032 */ 1033 static void mmHyperHeapDumpOne(PMMHYPERHEAP pHeap, PMMHYPERCHUNKFREE pCur) 1034 { 1035 if (MMHYPERCHUNK_ISUSED(&pCur->core)) 1036 { 1037 if (pCur->core.offStat) 1038 { 1039 PMMHYPERSTAT pStat = (PMMHYPERSTAT)((uintptr_t)pCur + pCur->core.offStat); 1040 const char *pszSelf = pCur->core.offStat == sizeof(MMHYPERCHUNK) ? " stat record" : ""; 1041 #ifdef IN_RING3 1042 Log(("%p %06x USED offNext=%06x offPrev=-%06x %s%s\n", 1043 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1044 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), 1045 mmR3GetTagName((MMTAG)pStat->Core.Key), pszSelf)); 1046 #else 1047 Log(("%p %06x USED offNext=%06x offPrev=-%06x %d%s\n", 1048 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1049 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), 1050 (MMTAG)pStat->Core.Key, pszSelf)); 1051 #endif 1052 } 1053 else 1054 Log(("%p %06x USED offNext=%06x offPrev=-%06x\n", 1055 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1056 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core))); 1057 } 1058 else 1059 Log(("%p %06x FREE offNext=%06x offPrev=-%06x : cb=%06x offNext=%06x offPrev=-%06x\n", 1060 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1061 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), pCur->cb, pCur->offNext, pCur->offPrev)); 1062 } 1063 #endif /* DEBUG || MMHYPER_HEAP_STRICT */ 1064 1065 1017 1066 #ifdef MMHYPER_HEAP_STRICT 1018 1067 /** 1019 1068 * Internal consitency check. 1020 1069 */ 1021 static void mm R3HyperHeapCheck(PMMHYPERHEAP pHeap)1070 static void mmHyperHeapCheck(PMMHYPERHEAP pHeap) 1022 1071 { 1023 1072 PMMHYPERCHUNKFREE pPrev = NULL; … … 1033 1082 ("pPrev->core.offNext=%d offPrev=%d\n", pPrev->core.offNext, MMHYPERCHUNK_GET_OFFPREV(&pCur->core))); 1034 1083 1084 # ifdef MMHYPER_HEAP_STRICT_FENCE 1085 uint32_t off = (uint8_t *)pCur - CTXSUFF(pHeap->pbHeap); 1086 if ( MMHYPERCHUNK_ISUSED(&pCur->core) 1087 && off < pHeap->offPageAligned) 1088 { 1089 uint32_t cbCur = pCur->core.offNext 1090 ? pCur->core.offNext 1091 : pHeap->cbHeap - off; 1092 uint32_t *pu32End = ((uint32_t *)((uint8_t *)pCur + cbCur)); 1093 uint32_t cbFence = pu32End[-1]; 1094 if (RT_UNLIKELY( cbFence >= cbCur - sizeof(*pCur) 1095 || cbFence < MMHYPER_HEAP_STRICT_FENCE_SIZE)) 1096 { 1097 mmHyperHeapDumpOne(pHeap, pCur); 1098 Assert(cbFence < cbCur - sizeof(*pCur)); 1099 Assert(cbFence >= MMHYPER_HEAP_STRICT_FENCE_SIZE); 1100 } 1101 1102 uint32_t *pu32Bad = ASMMemIsAllU32((uint8_t *)pu32End - cbFence, cbFence - sizeof(uint32_t), MMHYPER_HEAP_STRICT_FENCE_U32); 1103 if (RT_UNLIKELY(pu32Bad)) 1104 { 1105 mmHyperHeapDumpOne(pHeap, pCur); 1106 Assert(!pu32Bad); 1107 } 1108 } 1109 # endif 1110 1035 1111 /* next */ 1036 1112 if (!pCur->core.offNext) … … 1043 1119 1044 1120 1121 /** 1122 * Performs consistency checks on the heap if MMHYPER_HEAP_STRICT was 1123 * defined at build time. 1124 * 1125 * @param pVM Pointer to the shared VM structure. 1126 */ 1127 MMDECL(void) MMHyperHeapCheck(PVM pVM) 1128 { 1129 #ifdef MMHYPER_HEAP_STRICT 1130 mmHyperHeapCheck(CTXSUFF(pVM->mm.s.pHyperHeap)); 1131 #endif 1132 } 1133 1134 1045 1135 #ifdef DEBUG 1046 1136 /** … … 1055 1145 for (;;) 1056 1146 { 1057 if (MMHYPERCHUNK_ISUSED(&pCur->core)) 1058 { 1059 if (pCur->core.offStat) 1060 { 1061 PMMHYPERSTAT pStat = (PMMHYPERSTAT)((uintptr_t)pCur + pCur->core.offStat); 1062 const char *pszSelf = pCur->core.offStat == sizeof(MMHYPERCHUNK) ? " stat record" : ""; 1063 #ifdef IN_RING3 1064 Log(("%p %06x USED offNext=%06x offPrev=-%06x %s%s\n", 1065 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1066 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), 1067 mmR3GetTagName((MMTAG)pStat->Core.Key), pszSelf)); 1068 #else 1069 Log(("%p %06x USED offNext=%06x offPrev=-%06x %d%s\n", 1070 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1071 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), 1072 (MMTAG)pStat->Core.Key, pszSelf)); 1073 #endif 1074 } 1075 else 1076 Log(("%p %06x USED offNext=%06x offPrev=-%06x\n", 1077 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1078 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core))); 1079 } 1080 else 1081 Log(("%p %06x FREE offNext=%06x offPrev=-%06x : cb=%06x offNext=%06x offPrev=-%06x\n", 1082 pCur, (uintptr_t)pCur - (uintptr_t)CTXSUFF(pHeap->pbHeap), 1083 pCur->core.offNext, -MMHYPERCHUNK_GET_OFFPREV(&pCur->core), pCur->cb, pCur->offNext, pCur->offPrev)); 1147 mmHyperHeapDumpOne(pHeap, pCur); 1084 1148 1085 1149 /* next */
Note:
See TracChangeset
for help on using the changeset viewer.