Changeset 97919 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Dec 30, 2022 4:57:42 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp
r97918 r97919 105 105 * Structures and Typedefs * 106 106 *********************************************************************************************************************************/ 107 /** 108 * A heap block (within a chunk). 109 * 110 * This is used to track a part of a heap chunk that's either free or 111 * allocated. The VBGLPHYSHEAPBLOCK::fAllocated member indicates which it is. 112 */ 107 113 struct VBGLPHYSHEAPBLOCK 108 114 { … … 111 117 112 118 /** Size of user data in the block. Does not include this block header. */ 113 uint32_t cbDataSize; 114 115 uint32_t fu32Flags; 116 119 uint32_t cbDataSize : 31; 120 /** The top bit indicates whether it's allocated or free. */ 121 uint32_t fAllocated : 1; 122 123 /** Pointer to the next block on the list. */ 117 124 VBGLPHYSHEAPBLOCK *pNext; 125 /** Pointer to the previous block on the list. */ 118 126 VBGLPHYSHEAPBLOCK *pPrev; 119 127 /** Pointer back to the chunk. */ 120 128 VBGLPHYSHEAPCHUNK *pChunk; 121 129 }; 122 130 131 /** 132 * A chunk of memory used by the heap for sub-allocations. 133 * 134 * There is a list of these. 135 */ 123 136 struct VBGLPHYSHEAPCHUNK 124 137 { … … 135 148 int32_t cAllocatedBlocks; 136 149 150 /** Pointer to the next chunk. */ 137 151 VBGLPHYSHEAPCHUNK *pNext; 152 /** Pointer to the previous chunk. */ 138 153 VBGLPHYSHEAPCHUNK *pPrev; 139 154 }; … … 165 180 while (pBlock) 166 181 { 167 VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, flags = %08X, pChunk = %p\n", 168 pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize, pBlock->fu32Flags, pBlock->pChunk)); 182 VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, %s, pChunk = %p\n", 183 pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize, 184 pBlock->fAllocated ? "allocated" : "free", pBlock->pChunk)); 169 185 170 186 pBlock = pBlock->pNext; … … 177 193 while (pBlock) 178 194 { 179 VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, flags = %08X, pChunk = %p\n", 180 pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize, pBlock->fu32Flags, pBlock->pChunk)); 195 VBGL_PH_dprintf(("%p: pNext = %p, pPrev = %p, sign = %08X, size = %8d, %s, pChunk = %p\n", 196 pBlock, pBlock->pNext, pBlock->pPrev, pBlock->u32Signature, pBlock->cbDataSize, 197 pBlock->fAllocated ? "allocated" : "free", pBlock->pChunk)); 181 198 182 199 pBlock = pBlock->pNext; … … 233 250 pBlock->u32Signature = VBGL_PH_BLOCKSIGNATURE; 234 251 pBlock->cbDataSize = cbDataSize; 235 pBlock->f u32Flags = 0;252 pBlock->fAllocated = false; 236 253 pBlock->pNext = NULL; 237 254 pBlock->pPrev = NULL; … … 260 277 pBlock->pPrev = NULL; 261 278 262 if (pBlock->f u32Flags & VBGL_PH_BF_ALLOCATED)279 if (pBlock->fAllocated) 263 280 { 264 281 pBlock->pNext = g_vbgldata.pAllocBlocksHead; … … 293 310 if (pBlock->pPrev) 294 311 pBlock->pPrev->pNext = pBlock->pNext; 295 else if (pBlock->f u32Flags & VBGL_PH_BF_ALLOCATED)312 else if (pBlock->fAllocated) 296 313 { 297 314 Assert(g_vbgldata.pAllocBlocksHead == pBlock); … … 487 504 VBGL_PH_ASSERT_MSG(pBlock->u32Signature == VBGL_PH_BLOCKSIGNATURE, 488 505 ("pBlock = %p, pBlock->u32Signature = %08X\n", pBlock, pBlock->u32Signature)); 489 VBGL_PH_ASSERT_MSG((pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) == 0, 490 ("pBlock = %p, pBlock->fu32Flags = %08X\n", pBlock, pBlock->fu32Flags)); 506 VBGL_PH_ASSERT_MSG(!pBlock->fAllocated, ("pBlock = %p\n", pBlock)); 491 507 492 508 /* We have a free block, either found or allocated. */ … … 512 528 513 529 /* Mark as allocated */ 514 pBlock->f u32Flags |= VBGL_PH_BF_ALLOCATED;530 pBlock->fAllocated = true; 515 531 516 532 /* Insert to allocated list */ … … 536 552 if (pBlock) 537 553 { 538 VBGL_PH_ASSERT_MSG((pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) != 0, 539 ("pBlock = %p, pBlock->fu32Flags = %08X\n", pBlock, pBlock->fu32Flags)); 540 541 if (pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) 554 VBGL_PH_ASSERT_MSG(pBlock->fAllocated, ("pBlock = %p\n", pBlock)); 555 556 if (pBlock->fAllocated) 542 557 physAddr = pBlock->pChunk->physAddr + (uint32_t)((uintptr_t)pv - (uintptr_t)pBlock->pChunk); 543 558 } … … 566 581 } 567 582 568 VBGL_PH_ASSERT_MSG((pBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) != 0, 569 ("pBlock = %p, pBlock->fu32Flags = %08X\n", pBlock, pBlock->fu32Flags)); 583 VBGL_PH_ASSERT_MSG(pBlock->fAllocated, ("pBlock = %p\n", pBlock)); 570 584 571 585 /* Exclude from allocated list */ … … 577 591 578 592 /* Mark as free */ 579 pBlock->f u32Flags &= ~VBGL_PH_BF_ALLOCATED;593 pBlock->fAllocated = false; 580 594 581 595 /* Insert to free list */ … … 603 617 604 618 if ( (uintptr_t)pNeighbour < (uintptr_t)pChunk + pChunk->cbSize 605 && (pNeighbour->fu32Flags & VBGL_PH_BF_ALLOCATED) == 0)619 && !pNeighbour->fAllocated) 606 620 { 607 621 /* The next block is free as well. */ … … 701 715 RTErrInfoSetF(pErrInfo, VERR_INTERNAL_ERROR_3, 702 716 "pCurBlock=%p: cbDataSize=%#x\n", pCurBlock, pCurBlock->cbDataSize)); 703 AssertReturn( pCurBlock->fu32Flags <= VBGL_PH_BF_ALLOCATED, 704 RTErrInfoSetF(pErrInfo, VERR_INTERNAL_ERROR_3, 705 "pCurBlock=%p: fu32Flags=%#x\n", pCurBlock, pCurBlock->fu32Flags)); 706 if (pCurBlock->fu32Flags & VBGL_PH_BF_ALLOCATED) 717 if (pCurBlock->fAllocated) 707 718 cUsedBlocks += 1; 708 719 else
Note:
See TracChangeset
for help on using the changeset viewer.