Lines Matching defs:pHeapInt

189  * @param   pHeapInt        Pointer to the heap anchor block.
194 # define RTHEAPOFF_TO_PTR_N(pHeapInt, off, type) ( (type)rtHeapOffCheckedOffToPtr(pHeapInt, off, true /*fNull*/) )
196 # define RTHEAPOFF_TO_PTR_N(pHeapInt, off, type) ( (type)((off) ? (uint8_t *)(pHeapInt) + (off) : NULL) )
205 * @param pHeapInt Pointer to the heap anchor block.
210 # define RTHEAPOFF_TO_PTR(pHeapInt, off, type) ( (type)rtHeapOffCheckedOffToPtr(pHeapInt, off, false /*fNull*/) )
212 # define RTHEAPOFF_TO_PTR(pHeapInt, off, type) ( (type)((uint8_t *)(pHeapInt) + (off)) )
221 * @param pHeapInt Pointer to the heap anchor block.
225 # define RTHEAPOFF_TO_OFF(pHeapInt, ptr) rtHeapOffCheckedPtrToOff(pHeapInt, ptr)
227 # define RTHEAPOFF_TO_OFF(pHeapInt, ptr) ( (uint32_t)((ptr) ? (uintptr_t)(ptr) - (uintptr_t)(pHeapInt) : UINT32_C(0)) )
236 #define ASSERT_PREV(pHeapInt, pBlock) \
240 ASSERT_L((pBlock)->offPrev, RTHEAPOFF_TO_OFF(pHeapInt, pBlock)); \
244 Assert((pBlock) == (PRTHEAPOFFSETBLOCK)((pHeapInt) + 1)); \
251 ASSERT_L((pBlock)->offNext, (pHeapInt)->cbHeap); \
252 ASSERT_G((pBlock)->offNext, RTHEAPOFF_TO_OFF(pHeapInt, pBlock)); \
256 #define ASSERT_BLOCK(pHeapInt, pBlock) \
258 AssertMsg(RTHEAPOFF_GET_ANCHOR(pBlock) == (pHeapInt), ("%p != %p\n", RTHEAPOFF_GET_ANCHOR(pBlock), (pHeapInt))); \
259 ASSERT_GE(RTHEAPOFF_TO_OFF(pHeapInt, pBlock), sizeof(RTHEAPOFFSETINTERNAL)); \
260 ASSERT_L( RTHEAPOFF_TO_OFF(pHeapInt, pBlock), (pHeapInt)->cbHeap); \
261 ASSERT_NEXT(pHeapInt, pBlock); \
262 ASSERT_PREV(pHeapInt, pBlock); \
265 #define ASSERT_BLOCK_USED(pHeapInt, pBlock) \
267 AssertMsg(RTHEAPOFF_GET_ANCHOR(pBlock) == (pHeapInt), ("%p != %p\n", RTHEAPOFF_GET_ANCHOR(pBlock), (pHeapInt))); \
268 ASSERT_GE(RTHEAPOFF_TO_OFF(pHeapInt, pBlock), sizeof(RTHEAPOFFSETINTERNAL)); \
269 ASSERT_L( RTHEAPOFF_TO_OFF(pHeapInt, pBlock), (pHeapInt)->cbHeap); \
270 ASSERT_NEXT(pHeapInt, pBlock); \
271 ASSERT_PREV(pHeapInt, pBlock); \
274 #define ASSERT_FREE_PREV(pHeapInt, pBlock) \
278 ASSERT_GE((pBlock)->offPrev, (pHeapInt)->offFreeHead); \
279 ASSERT_L((pBlock)->offPrev, RTHEAPOFF_TO_OFF(pHeapInt, pBlock)); \
283 Assert((pBlock) == RTHEAPOFF_TO_PTR(pHeapInt, (pHeapInt)->offFreeHead, PRTHEAPOFFSETFREE) ); \
286 #define ASSERT_FREE_NEXT(pHeapInt, pBlock) \
290 ASSERT_LE((pBlock)->offNext, (pHeapInt)->offFreeTail); \
291 ASSERT_G((pBlock)->offNext, RTHEAPOFF_TO_OFF(pHeapInt, pBlock)); \
295 Assert((pBlock) == RTHEAPOFF_TO_PTR(pHeapInt, (pHeapInt)->offFreeTail, PRTHEAPOFFSETFREE)); \
299 # define ASSERT_FREE_CB(pHeapInt, pBlock) \
300 do { size_t cbCalc = ((pBlock)->Core.offNext ? (pBlock)->Core.offNext : (pHeapInt)->cbHeap) \
301 - RTHEAPOFF_TO_OFF((pHeapInt), (pBlock)) - sizeof(RTHEAPOFFSETBLOCK); \
305 # define ASSERT_FREE_CB(pHeapInt, pBlock) do {} while (0)
309 #define ASSERT_BLOCK_FREE(pHeapInt, pBlock) \
310 do { ASSERT_BLOCK(pHeapInt, &(pBlock)->Core); \
312 ASSERT_GE(RTHEAPOFF_TO_OFF(pHeapInt, pBlock), (pHeapInt)->offFreeHead); \
313 ASSERT_LE(RTHEAPOFF_TO_OFF(pHeapInt, pBlock), (pHeapInt)->offFreeTail); \
314 ASSERT_FREE_NEXT(pHeapInt, pBlock); \
315 ASSERT_FREE_PREV(pHeapInt, pBlock); \
316 ASSERT_FREE_CB(pHeapInt, pBlock); \
320 #define ASSERT_ANCHOR(pHeapInt) \
321 do { AssertPtr(pHeapInt);\
322 Assert((pHeapInt)->u32Magic == RTHEAPOFFSET_MAGIC); \
330 static void rtHeapOffsetAssertAll(PRTHEAPOFFSETINTERNAL pHeapInt);
332 static PRTHEAPOFFSETBLOCK rtHeapOffsetAllocBlock(PRTHEAPOFFSETINTERNAL pHeapInt, size_t cb, size_t uAlignment);
333 static void rtHeapOffsetFreeBlock(PRTHEAPOFFSETINTERNAL pHeapInt, PRTHEAPOFFSETBLOCK pBlock);
338 DECLINLINE(void *) rtHeapOffCheckedOffToPtr(PRTHEAPOFFSETINTERNAL pHeapInt, uint32_t off, bool fNull)
343 AssertMsg(off < pHeapInt->cbHeap, ("%#x %#x\n", off, pHeapInt->cbHeap));
344 AssertMsg(off >= sizeof(*pHeapInt), ("%#x %#x\n", off, sizeof(*pHeapInt)));
345 return (uint8_t *)pHeapInt + off;
349 DECLINLINE(uint32_t) rtHeapOffCheckedPtrToOff(PRTHEAPOFFSETINTERNAL pHeapInt, void *pv)
353 uintptr_t off = (uintptr_t)pv - (uintptr_t)pHeapInt;
354 AssertMsg(off < pHeapInt->cbHeap, ("%#x %#x\n", off, pHeapInt->cbHeap));
355 AssertMsg(off >= sizeof(*pHeapInt), ("%#x %#x\n", off, sizeof(*pHeapInt)));
365 PRTHEAPOFFSETINTERNAL pHeapInt;
381 pHeapInt = (PRTHEAPOFFSETINTERNAL)pvMemory;
386 pHeapInt = (PRTHEAPOFFSETINTERNAL)((uintptr_t)pvMemory + off);
392 pHeapInt->u32Magic = RTHEAPOFFSET_MAGIC;
393 pHeapInt->cbHeap = (uint32_t)cbMemory;
394 pHeapInt->cbFree = (uint32_t)cbMemory
397 pHeapInt->offFreeTail = pHeapInt->offFreeHead = sizeof(*pHeapInt);
398 for (i = 0; i < RT_ELEMENTS(pHeapInt->au32Alignment); i++)
399 pHeapInt->au32Alignment[i] = UINT32_MAX;
402 pFree = RTHEAPOFF_TO_PTR(pHeapInt, pHeapInt->offFreeHead, PRTHEAPOFFSETFREE);
405 pFree->Core.offSelf = pHeapInt->offFreeHead;
409 pFree->cb = pHeapInt->cbFree;
411 *phHeap = pHeapInt;
414 rtHeapOffsetAssertAll(pHeapInt);
423 PRTHEAPOFFSETINTERNAL pHeapInt = hHeap;
429 AssertPtrReturn(pHeapInt, NULL);
447 pBlock = rtHeapOffsetAllocBlock(pHeapInt, cb, cbAlignment);
460 PRTHEAPOFFSETINTERNAL pHeapInt = hHeap;
466 AssertPtrReturn(pHeapInt, NULL);
484 pBlock = rtHeapOffsetAllocBlock(pHeapInt, cb, cbAlignment);
504 * @param pHeapInt The heap.
508 static PRTHEAPOFFSETBLOCK rtHeapOffsetAllocBlock(PRTHEAPOFFSETINTERNAL pHeapInt, size_t cb, size_t uAlignment)
513 AssertReturn((pHeapInt)->u32Magic == RTHEAPOFFSET_MAGIC, NULL);
515 rtHeapOffsetAssertAll(pHeapInt);
521 for (pFree = RTHEAPOFF_TO_PTR_N(pHeapInt, pHeapInt->offFreeHead, PRTHEAPOFFSETFREE);
523 pFree = RTHEAPOFF_TO_PTR_N(pHeapInt, pFree->offNext, PRTHEAPOFFSETFREE))
526 ASSERT_BLOCK_FREE(pHeapInt, pFree);
551 pFree->Core.offSelf = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
555 pFree->cb = (pFree->Core.offNext ? pFree->Core.offNext : pHeapInt->cbHeap)
563 RTHEAPOFF_TO_PTR(pHeapInt, pFree->Core.offNext, PRTHEAPOFFSETBLOCK)->offPrev = pFree->Core.offSelf;
565 RTHEAPOFF_TO_PTR(pHeapInt, pFree->Core.offNext, PRTHEAPOFFSETFREE)->offPrev = pFree->Core.offSelf;
567 pHeapInt->offFreeTail = pFree->Core.offSelf;
569 pHeapInt->cbFree -= sizeof(RTHEAPOFFSETBLOCK);
570 ASSERT_BLOCK_FREE(pHeapInt, pPrev);
571 ASSERT_BLOCK_FREE(pHeapInt, pFree);
584 pNew->Core.offSelf = RTHEAPOFF_TO_OFF(pHeapInt, pNew);
587 RTHEAPOFF_TO_PTR(pHeapInt, pFree->Core.offNext, PRTHEAPOFFSETBLOCK)->offPrev = pNew->Core.offSelf;
588 pNew->Core.offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
593 RTHEAPOFF_TO_PTR(pHeapInt, pNew->offNext, PRTHEAPOFFSETFREE)->offPrev = pNew->Core.offSelf;
595 pHeapInt->offFreeTail = pNew->Core.offSelf;
598 RTHEAPOFF_TO_PTR(pHeapInt, pNew->offPrev, PRTHEAPOFFSETFREE)->offNext = pNew->Core.offSelf;
600 pHeapInt->offFreeHead = pNew->Core.offSelf;
601 pNew->cb = (pNew->Core.offNext ? pNew->Core.offNext : pHeapInt->cbHeap) \
603 ASSERT_BLOCK_FREE(pHeapInt, pNew);
610 pHeapInt->cbFree -= pFree->cb;
611 pHeapInt->cbFree += pNew->cb;
613 ASSERT_BLOCK_USED(pHeapInt, pRet);
621 RTHEAPOFF_TO_PTR(pHeapInt, pFree->offNext, PRTHEAPOFFSETFREE)->offPrev = pFree->offPrev;
623 pHeapInt->offFreeTail = pFree->offPrev;
625 RTHEAPOFF_TO_PTR(pHeapInt, pFree->offPrev, PRTHEAPOFFSETFREE)->offNext = pFree->offNext;
627 pHeapInt->offFreeHead = pFree->offNext;
632 pHeapInt->cbFree -= pFree->cb;
635 ASSERT_BLOCK_USED(pHeapInt, pRet);
641 rtHeapOffsetAssertAll(pHeapInt);
649 PRTHEAPOFFSETINTERNAL pHeapInt;
664 pHeapInt = RTHEAPOFF_GET_ANCHOR(pBlock);
665 ASSERT_BLOCK_USED(pHeapInt, pBlock);
666 ASSERT_ANCHOR(pHeapInt);
667 Assert(pHeapInt == (PRTHEAPOFFSETINTERNAL)hHeap || !hHeap);
673 const size_t cbBlock = (pBlock->pNext ? (uintptr_t)pBlock->pNext : (uintptr_t)pHeapInt->pvEnd)
681 rtHeapOffsetFreeBlock(pHeapInt, pBlock);
689 * @param pHeapInt The heap.
692 static void rtHeapOffsetFreeBlock(PRTHEAPOFFSETINTERNAL pHeapInt, PRTHEAPOFFSETBLOCK pBlock)
699 rtHeapOffsetAssertAll(pHeapInt);
708 if (pHeapInt->offFreeTail)
710 pRight = RTHEAPOFF_TO_PTR_N(pHeapInt, pFree->Core.offNext, PRTHEAPOFFSETFREE);
713 ASSERT_BLOCK(pHeapInt, &pRight->Core);
714 pRight = RTHEAPOFF_TO_PTR_N(pHeapInt, pRight->Core.offNext, PRTHEAPOFFSETFREE);
717 pLeft = RTHEAPOFF_TO_PTR_N(pHeapInt, pHeapInt->offFreeTail, PRTHEAPOFFSETFREE);
720 ASSERT_BLOCK_FREE(pHeapInt, pRight);
721 pLeft = RTHEAPOFF_TO_PTR_N(pHeapInt, pRight->offPrev, PRTHEAPOFFSETFREE);
724 ASSERT_BLOCK_FREE(pHeapInt, pLeft);
727 ASSERT_L(RTHEAPOFF_TO_OFF(pHeapInt, pLeft), RTHEAPOFF_TO_OFF(pHeapInt, pFree));
729 Assert(!pLeft || RTHEAPOFF_TO_PTR_N(pHeapInt, pLeft->offNext, PRTHEAPOFFSETFREE) == pRight);
736 Assert(pRight == RTHEAPOFF_TO_PTR_N(pHeapInt, pHeapInt->offFreeHead, PRTHEAPOFFSETFREE));
739 pFree->offNext = RTHEAPOFF_TO_OFF(pHeapInt, pRight);
741 pRight->offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
743 pHeapInt->offFreeTail = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
744 pHeapInt->offFreeHead = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
751 if (pLeft->Core.offNext == RTHEAPOFF_TO_OFF(pHeapInt, pFree))
755 RTHEAPOFF_TO_PTR(pHeapInt, pFree->Core.offNext, PRTHEAPOFFSETBLOCK)->offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pLeft);
756 pHeapInt->cbFree -= pLeft->cb;
765 pFree->offNext = RTHEAPOFF_TO_OFF(pHeapInt, pRight);
766 pFree->offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pLeft);
767 pLeft->offNext = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
769 pRight->offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
771 pHeapInt->offFreeTail = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
779 && pRight->Core.offPrev == RTHEAPOFF_TO_OFF(pHeapInt, pFree))
784 RTHEAPOFF_TO_PTR(pHeapInt, pRight->Core.offNext, PRTHEAPOFFSETBLOCK)->offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
789 RTHEAPOFF_TO_PTR(pHeapInt, pRight->offNext, PRTHEAPOFFSETFREE)->offPrev = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
791 pHeapInt->offFreeTail = RTHEAPOFF_TO_OFF(pHeapInt, pFree);
792 pHeapInt->cbFree -= pRight->cb;
798 pFree->cb = (pFree->Core.offNext ? pFree->Core.offNext : pHeapInt->cbHeap)
799 - RTHEAPOFF_TO_OFF(pHeapInt, pFree) - sizeof(RTHEAPOFFSETBLOCK);
800 pHeapInt->cbFree += pFree->cb;
801 ASSERT_BLOCK_FREE(pHeapInt, pFree);
804 rtHeapOffsetAssertAll(pHeapInt);
812 * @param pHeapInt
814 static void rtHeapOffsetAssertAll(PRTHEAPOFFSETINTERNAL pHeapInt)
819 for (pBlock = (PRTHEAPOFFSETFREE)(pHeapInt + 1);
821 pBlock = RTHEAPOFF_TO_PTR_N(pHeapInt, pBlock->Core.offNext, PRTHEAPOFFSETFREE))
825 ASSERT_BLOCK_FREE(pHeapInt, pBlock);
826 Assert(pBlock->offPrev == RTHEAPOFF_TO_OFF(pHeapInt, pPrevFree));
827 Assert(pPrevFree || pHeapInt->offFreeHead == RTHEAPOFF_TO_OFF(pHeapInt, pBlock));
831 ASSERT_BLOCK_USED(pHeapInt, &pBlock->Core);
832 Assert(!pPrev || RTHEAPOFF_TO_OFF(pHeapInt, pPrev) == pBlock->Core.offPrev);
835 Assert(pHeapInt->offFreeTail == RTHEAPOFF_TO_OFF(pHeapInt, pPrevFree));
842 PRTHEAPOFFSETINTERNAL pHeapInt;
858 pHeapInt = RTHEAPOFF_GET_ANCHOR(pBlock);
859 ASSERT_BLOCK_USED(pHeapInt, pBlock);
860 ASSERT_ANCHOR(pHeapInt);
861 Assert(pHeapInt == (PRTHEAPOFFSETINTERNAL)hHeap || !hHeap);
866 cbBlock = (pBlock->offNext ? pBlock->offNext : pHeapInt->cbHeap)
867 - RTHEAPOFF_TO_OFF(pHeapInt, pBlock) - sizeof(RTHEAPOFFSETBLOCK);
875 PRTHEAPOFFSETINTERNAL pHeapInt;
880 pHeapInt = hHeap;
881 AssertPtrReturn(pHeapInt, 0);
882 ASSERT_ANCHOR(pHeapInt);
883 return pHeapInt->cbHeap;
890 PRTHEAPOFFSETINTERNAL pHeapInt;
895 pHeapInt = hHeap;
896 AssertPtrReturn(pHeapInt, 0);
897 ASSERT_ANCHOR(pHeapInt);
898 return pHeapInt->cbFree;
905 PRTHEAPOFFSETINTERNAL pHeapInt = (PRTHEAPOFFSETINTERNAL)hHeap;
909 hHeap, pHeapInt->cbHeap, pHeapInt->cbFree);
911 for (pBlock = (PRTHEAPOFFSETFREE)(pHeapInt + 1);
913 pBlock = RTHEAPOFF_TO_PTR_N(pHeapInt, pBlock->Core.offNext, PRTHEAPOFFSETFREE))
915 size_t cb = (pBlock->offNext ? pBlock->Core.offNext : pHeapInt->cbHeap)
916 - RTHEAPOFF_TO_OFF(pHeapInt, pBlock) - sizeof(RTHEAPOFFSETBLOCK);