Ignore:
Timestamp:
Aug 27, 2007, 9:54:05 PM (18 years ago)
Author:
bird
Message:

Use the new type system.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/kLdr/kLdrHlpHeap.c

    r3537 r3567  
    5858    struct KLDRHEAPBLOCK   *pPrev;
    5959    /** The size of this block including this header. */
    60     size_t                  cb;
     60    KSIZE                   cb;
    6161    /** The flags. */
    62     size_t                  fFlags;
     62    KSIZE                   fFlags;
    6363} KLDRHEAPBLOCK, *PKLDRHEAPBLOCK;
    6464
    6565/** 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)
    6767/** Valid flag mask. */
    68 #define KLDRHEAPBLOCK_FLAG_MASK     ((size_t)1)
     68#define KLDRHEAPBLOCK_FLAG_MASK     ((KSIZE)1)
    6969
    7070/** Checks if the block is freed. */
     
    7575 * Assumes pB1 < pB2. */
    7676#define KLDRHEAPBLOCK_IS_ADJACENT(pB1, pB2) \
    77     ( ((uintptr_t)(pB1) + (pB1)->cb) == (uintptr_t)(pB2) )
     77    ( ((KUPTR)(pB1) + (pB1)->cb) == (KUPTR)(pB2) )
    7878
    7979/** The block alignment. */
     
    9393        KLDRHEAP_ASSERT(!((pBlock)->fFlags & ~KLDRHEAPBLOCK_FLAG_MASK)); \
    9494        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); \
    9797    } while (0)
    9898
     
    100100    do { \
    101101        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); \
    104104    } while (0)
    105105
     
    133133    void   *pvBase;
    134134    /** The length of the segment (in bytes). */
    135     size_t  cb;
     135    KSIZE   cb;
    136136} KLDRHEAPSEG, *PKLDRHEAPSEG;
    137137
     
    144144    struct KLDRHEAPSEGS    *pNext;
    145145    /** The number of segments used. */
    146     uint32_t                cSegs;
     146    KU32                    cSegs;
    147147    /** Array of chunks. */
    148148    KLDRHEAPSEG             aSegs[64];
     
    181181static int      kLdrHeapInit(PKLDRHEAPANCHOR pHeap);
    182182static void     kLdrHeapDelete(PKLDRHEAPANCHOR pHeap);
    183 static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, size_t cb);
     183static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb);
    184184static void     kLdrHeapFree(PKLDRHEAPANCHOR pHeap, void *pv);
    185 static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, size_t cb);
    186 static int      kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, size_t cb);
     185static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb);
     186static int      kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cb);
    187187static void     kLdrHeapSegFree(PKLDRHEAPSEG pSeg);
    188188
     
    214214 * @param   cb      The requested heap block size.
    215215 */
    216 void *kldrHlpAlloc(size_t cb)
     216void *kldrHlpAlloc(KSIZE cb)
    217217{
    218218    return kLdrHeapAlloc(&g_Heap, cb);
     
    226226 * @param   cb      The requested heap block size.
    227227 */
    228 void *kldrHlpAllocZ(size_t cb)
     228void *kldrHlpAllocZ(KSIZE cb)
    229229{
    230230    void *pv = kLdrHeapAlloc(&g_Heap, cb);
     
    252252 * @param   cb      The amount of memory.
    253253 */
    254 void kldrHlpHeapDonate(void *pv, size_t cb)
     254void kldrHlpHeapDonate(void *pv, KSIZE cb)
    255255{
    256256    kLdrHeapDonate(&g_Heap, pv, cb);
     
    293293    {
    294294        /* find the tail. */
    295         uint32_t        iSeg;
     295        KU32            iSeg;
    296296        PKLDRHEAPSEGS   pSegs = pHeap->SegsHead.pNext;
    297297        if (!pSegs)
     
    322322 * Internal heap block allocator.
    323323 */
    324 static void *   kldrHeapAllocSub(PKLDRHEAPANCHOR pHeap, size_t cb)
     324static void *   kldrHeapAllocSub(PKLDRHEAPANCHOR pHeap, KSIZE cb)
    325325{
    326326    /*
    327327     * Find a fitting free block.
    328328     */
    329     const size_t    cbReq = KLDR_ALIGN_Z(cb + sizeof(KLDRHEAPBLOCK), KLDRHEAPBLOCK_ALIGNMENT);
     329    const KSIZE     cbReq = KLDR_ALIGN_Z(cb + sizeof(KLDRHEAPBLOCK), KLDRHEAPBLOCK_ALIGNMENT);
    330330    PKLDRHEAPFREE   pCur = pHeap->pFreeHead;
    331331    while (pCur)
     
    376376        pCur->Core.cb -= cbReq;
    377377
    378         pNew = (PKLDRHEAPBLOCK)((uintptr_t)pCur + pCur->Core.cb);
     378        pNew = (PKLDRHEAPBLOCK)((KUPTR)pCur + pCur->Core.cb);
    379379        pNew->fFlags = 0;
    380380        pNew->cb = cbReq;
     
    415415 * @param   cb      The requested heap block size.
    416416 */
    417 static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, size_t cb)
     417static void *   kLdrHeapAlloc(PKLDRHEAPANCHOR pHeap, KSIZE cb)
    418418{
    419419    void *pv;
     
    563563 * @param cb    Size of the donated memory.
    564564 */
    565 static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, size_t cb)
     565static void     kLdrHeapDonate(PKLDRHEAPANCHOR pHeap, void *pv, KSIZE cb)
    566566{
    567567    PKLDRHEAPBLOCK pBlock;
     
    576576     * Align the donation on a heap block boundrary.
    577577     */
    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;
    581581        pv = KLDR_ALIGN_P(pv, KLDRHEAPBLOCK_ALIGNMENT);
    582582    }
    583     cb &= ~(size_t)(KLDRHEAPBLOCK_ALIGNMENT - 1);
     583    cb &= ~(KSIZE)(KLDRHEAPBLOCK_ALIGNMENT - 1);
    584584
    585585    /*
     
    593593
    594594    /* insert */
    595     if ((uintptr_t)pBlock < (uintptr_t)pHeap->pHead)
     595    if ((KUPTR)pBlock < (KUPTR)pHeap->pHead)
    596596    {
    597597        /* head */
     
    600600        pHeap->pHead = pBlock;
    601601    }
    602     else if ((uintptr_t)pBlock > (uintptr_t)pHeap->pTail)
     602    else if ((KUPTR)pBlock > (KUPTR)pHeap->pTail)
    603603    {
    604604        if (pHeap->pTail)
     
    624624        {
    625625            KLDRHEAP_ASSERT_BLOCK(pHeap, pCur);
    626             if ((uintptr_t)pCur > (uintptr_t)pBlock)
     626            if ((KUPTR)pCur > (KUPTR)pBlock)
    627627                break;
    628628            pPrev = pCur;
     
    650650 * @param   cbMin   The minimum segment size.
    651651 */
    652 static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, size_t cbMin)
     652static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cbMin)
    653653{
    654654#ifdef __OS2__
    655655    APIRET rc;
    656656
    657     pSeg->cb = (cbMin + 0xffff) & ~(size_t)0xffff;
     657    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
    658658    pSeg->pvBase = NULL;
    659659    rc = DosAllocMem(&pSeg->pvBase, pSeg->cb, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_ANY);
     
    668668
    669669#elif defined(__WIN__)
    670     pSeg->cb = (cbMin + 0xffff) & ~(size_t)0xffff;
     670    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
    671671    pSeg->pvBase = VirtualAlloc(NULL, pSeg->cb, MEM_COMMIT, PAGE_READWRITE);
    672672    if (!pSeg->pvBase)
Note: See TracChangeset for help on using the changeset viewer.