Changeset 3567 for trunk/kStuff/kLdr/kLdrHlpHeap.c
- Timestamp:
- Aug 27, 2007, 9:54:05 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/kLdr/kLdrHlpHeap.c
r3537 r3567 58 58 struct KLDRHEAPBLOCK *pPrev; 59 59 /** The size of this block including this header. */ 60 size_tcb;60 KSIZE cb; 61 61 /** The flags. */ 62 size_tfFlags;62 KSIZE fFlags; 63 63 } KLDRHEAPBLOCK, *PKLDRHEAPBLOCK; 64 64 65 65 /** Indicates whether the block is free (set) or allocated (clear). */ 66 #define KLDRHEAPBLOCK_FLAG_FREE (( size_t)1)66 #define KLDRHEAPBLOCK_FLAG_FREE ((KSIZE)1) 67 67 /** Valid flag mask. */ 68 #define KLDRHEAPBLOCK_FLAG_MASK (( size_t)1)68 #define KLDRHEAPBLOCK_FLAG_MASK ((KSIZE)1) 69 69 70 70 /** Checks if the block is freed. */ … … 75 75 * Assumes pB1 < pB2. */ 76 76 #define KLDRHEAPBLOCK_IS_ADJACENT(pB1, pB2) \ 77 ( (( uintptr_t)(pB1) + (pB1)->cb) == (uintptr_t)(pB2) )77 ( ((KUPTR)(pB1) + (pB1)->cb) == (KUPTR)(pB2) ) 78 78 79 79 /** The block alignment. */ … … 93 93 KLDRHEAP_ASSERT(!((pBlock)->fFlags & ~KLDRHEAPBLOCK_FLAG_MASK)); \ 94 94 KLDRHEAP_ASSERT(!((pBlock)->cb & (KLDRHEAPBLOCK_ALIGNMENT - 1))); \ 95 KLDRHEAP_ASSERT(( uintptr_t)(pBlock)->pPrev < (uintptr_t)(pBlock)); \96 KLDRHEAP_ASSERT(( uintptr_t)(pBlock)->pNext > (uintptr_t)(pBlock) || !(pBlock)->pNext); \95 KLDRHEAP_ASSERT((KUPTR)(pBlock)->pPrev < (KUPTR)(pBlock)); \ 96 KLDRHEAP_ASSERT((KUPTR)(pBlock)->pNext > (KUPTR)(pBlock) || !(pBlock)->pNext); \ 97 97 } while (0) 98 98 … … 100 100 do { \ 101 101 KLDRHEAP_ASSERT_BLOCK(pHeap, &(pFree)->Core); \ 102 KLDRHEAP_ASSERT(( uintptr_t)(pFree)->pPrev < (uintptr_t)(pFree)); \103 KLDRHEAP_ASSERT(( uintptr_t)(pFree)->pNext > (uintptr_t)(pFree) || !(pFree)->pNext); \102 KLDRHEAP_ASSERT((KUPTR)(pFree)->pPrev < (KUPTR)(pFree)); \ 103 KLDRHEAP_ASSERT((KUPTR)(pFree)->pNext > (KUPTR)(pFree) || !(pFree)->pNext); \ 104 104 } while (0) 105 105 … … 133 133 void *pvBase; 134 134 /** The length of the segment (in bytes). */ 135 size_tcb;135 KSIZE cb; 136 136 } KLDRHEAPSEG, *PKLDRHEAPSEG; 137 137 … … 144 144 struct KLDRHEAPSEGS *pNext; 145 145 /** The number of segments used. */ 146 uint32_tcSegs;146 KU32 cSegs; 147 147 /** Array of chunks. */ 148 148 KLDRHEAPSEG aSegs[64]; … … 181 181 static int kLdrHeapInit(PKLDRHEAPANCHOR pHeap); 182 182 static void kLdrHeapDelete(PKLDRHEAPANCHOR pHeap); 183 static void * kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, size_tcb);183 static void * kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb); 184 184 static void kLdrHeapFree(PKLDRHEAPANCHOR pHeap, void *pv); 185 static void kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, size_tcb);186 static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, size_tcb);185 static void kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb); 186 static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cb); 187 187 static void kLdrHeapSegFree(PKLDRHEAPSEG pSeg); 188 188 … … 214 214 * @param cb The requested heap block size. 215 215 */ 216 void *kldrHlpAlloc( size_tcb)216 void *kldrHlpAlloc(KSIZE cb) 217 217 { 218 218 return kLdrHeapAlloc(&g_Heap, cb); … … 226 226 * @param cb The requested heap block size. 227 227 */ 228 void *kldrHlpAllocZ( size_tcb)228 void *kldrHlpAllocZ(KSIZE cb) 229 229 { 230 230 void *pv = kLdrHeapAlloc(&g_Heap, cb); … … 252 252 * @param cb The amount of memory. 253 253 */ 254 void kldrHlpHeapDonate(void *pv, size_tcb)254 void kldrHlpHeapDonate(void *pv, KSIZE cb) 255 255 { 256 256 kLdrHeapDonate(&g_Heap, pv, cb); … … 293 293 { 294 294 /* find the tail. */ 295 uint32_tiSeg;295 KU32 iSeg; 296 296 PKLDRHEAPSEGS pSegs = pHeap->SegsHead.pNext; 297 297 if (!pSegs) … … 322 322 * Internal heap block allocator. 323 323 */ 324 static void * kldrHeapAllocSub(PKLDRHEAPANCHOR pHeap, size_tcb)324 static void * kldrHeapAllocSub(PKLDRHEAPANCHOR pHeap, KSIZE cb) 325 325 { 326 326 /* 327 327 * Find a fitting free block. 328 328 */ 329 const size_tcbReq = KLDR_ALIGN_Z(cb + sizeof(KLDRHEAPBLOCK), KLDRHEAPBLOCK_ALIGNMENT);329 const KSIZE cbReq = KLDR_ALIGN_Z(cb + sizeof(KLDRHEAPBLOCK), KLDRHEAPBLOCK_ALIGNMENT); 330 330 PKLDRHEAPFREE pCur = pHeap->pFreeHead; 331 331 while (pCur) … … 376 376 pCur->Core.cb -= cbReq; 377 377 378 pNew = (PKLDRHEAPBLOCK)(( uintptr_t)pCur + pCur->Core.cb);378 pNew = (PKLDRHEAPBLOCK)((KUPTR)pCur + pCur->Core.cb); 379 379 pNew->fFlags = 0; 380 380 pNew->cb = cbReq; … … 415 415 * @param cb The requested heap block size. 416 416 */ 417 static void * kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, size_tcb)417 static void * kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb) 418 418 { 419 419 void *pv; … … 563 563 * @param cb Size of the donated memory. 564 564 */ 565 static void kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, size_tcb)565 static void kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb) 566 566 { 567 567 PKLDRHEAPBLOCK pBlock; … … 576 576 * Align the donation on a heap block boundrary. 577 577 */ 578 if (( uintptr_t)pv & (KLDRHEAPBLOCK_ALIGNMENT - 1))579 { 580 cb -= ( uintptr_t)pv & 31;578 if ((KUPTR)pv & (KLDRHEAPBLOCK_ALIGNMENT - 1)) 579 { 580 cb -= (KUPTR)pv & 31; 581 581 pv = KLDR_ALIGN_P(pv, KLDRHEAPBLOCK_ALIGNMENT); 582 582 } 583 cb &= ~( size_t)(KLDRHEAPBLOCK_ALIGNMENT - 1);583 cb &= ~(KSIZE)(KLDRHEAPBLOCK_ALIGNMENT - 1); 584 584 585 585 /* … … 593 593 594 594 /* insert */ 595 if (( uintptr_t)pBlock < (uintptr_t)pHeap->pHead)595 if ((KUPTR)pBlock < (KUPTR)pHeap->pHead) 596 596 { 597 597 /* head */ … … 600 600 pHeap->pHead = pBlock; 601 601 } 602 else if (( uintptr_t)pBlock > (uintptr_t)pHeap->pTail)602 else if ((KUPTR)pBlock > (KUPTR)pHeap->pTail) 603 603 { 604 604 if (pHeap->pTail) … … 624 624 { 625 625 KLDRHEAP_ASSERT_BLOCK(pHeap, pCur); 626 if (( uintptr_t)pCur > (uintptr_t)pBlock)626 if ((KUPTR)pCur > (KUPTR)pBlock) 627 627 break; 628 628 pPrev = pCur; … … 650 650 * @param cbMin The minimum segment size. 651 651 */ 652 static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, size_tcbMin)652 static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cbMin) 653 653 { 654 654 #ifdef __OS2__ 655 655 APIRET rc; 656 656 657 pSeg->cb = (cbMin + 0xffff) & ~( size_t)0xffff;657 pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff; 658 658 pSeg->pvBase = NULL; 659 659 rc = DosAllocMem(&pSeg->pvBase, pSeg->cb, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_ANY); … … 668 668 669 669 #elif defined(__WIN__) 670 pSeg->cb = (cbMin + 0xffff) & ~( size_t)0xffff;670 pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff; 671 671 pSeg->pvBase = VirtualAlloc(NULL, pSeg->cb, MEM_COMMIT, PAGE_READWRITE); 672 672 if (!pSeg->pvBase)
Note:
See TracChangeset
for help on using the changeset viewer.