VirtualBox

Changeset 100309 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Jun 28, 2023 10:25:37 AM (19 months ago)
Author:
vboxsync
Message:

Runtime/common/alloc/memcache.cpp: Replace occurences of PAGE_SIZE/PAGE_OFFSET_MASK with RTSystemGetPageSize()/RTSystemGetPageOffsetMask(), bugref:10476

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/alloc/memcache.cpp

    r98103 r100309  
    4747#include <iprt/err.h>
    4848#include <iprt/mem.h>
    49 #include <iprt/param.h>
     49#include <iprt/system.h>
    5050
    5151#include "internal/magics.h"
     
    175175    AssertReturn(!pfnDtor || pfnCtor, VERR_INVALID_PARAMETER);
    176176    AssertReturn(cbObject > 0, VERR_INVALID_PARAMETER);
    177     AssertReturn(cbObject <= PAGE_SIZE / 8, VERR_INVALID_PARAMETER);
     177
     178    size_t const cbPage = RTSystemGetPageSize();
     179    AssertReturn(cbObject <= cbPage / 8, VERR_INVALID_PARAMETER);
    178180    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
    179181
     
    215217    pThis->cbObject         = (uint32_t)RT_ALIGN_Z(cbObject, cbAlignment);
    216218    pThis->cbAlignment      = (uint32_t)cbAlignment;
    217     pThis->cPerPage         = (uint32_t)((PAGE_SIZE - RT_ALIGN_Z(sizeof(RTMEMCACHEPAGE), cbAlignment)) / pThis->cbObject);
     219    pThis->cPerPage         = (uint32_t)((cbPage - RT_ALIGN_Z(sizeof(RTMEMCACHEPAGE), cbAlignment)) / pThis->cbObject);
    218220    while (  RT_ALIGN_Z(sizeof(RTMEMCACHEPAGE), 8)
    219221           + pThis->cPerPage * pThis->cbObject
    220222           + RT_ALIGN(pThis->cPerPage, 64) / 8 * 2
    221            > PAGE_SIZE)
     223           > cbPage)
    222224        pThis->cPerPage--;
    223225    pThis->cBits            = RT_ALIGN(pThis->cPerPage, 64);
     
    276278        }
    277279
    278         RTMemPageFree(pPage, PAGE_SIZE);
     280        RTMemPageFree(pPage, RTSystemGetPageSize());
    279281    }
    280282
     
    310312         * on the cache.
    311313         */
    312         PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)RTMemPageAlloc(PAGE_SIZE);
     314        size_t const cbPage = RTSystemGetPageSize();
     315        PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)RTMemPageAlloc(cbPage);
    313316        if (pPage)
    314317        {
     
    323326            pb = RT_ALIGN_PT(pb, 8, uint8_t *);
    324327            pPage->pbmCtor      = pb;
    325             pb = (uint8_t *)pPage + PAGE_SIZE - pThis->cbObject * cObjects;
     328            pb = (uint8_t *)pPage + cbPage - pThis->cbObject * cObjects;
    326329            pPage->pbObjects    = pb;   Assert(RT_ALIGN_P(pb, pThis->cbAlignment) == pb);
    327330            pb -= pThis->cBits / 8;
     
    471474    }
    472475    void *pvObj = &pPage->pbObjects[iObj * pThis->cbObject];
    473     Assert((uintptr_t)pvObj - (uintptr_t)pPage < PAGE_SIZE);
     476    Assert((uintptr_t)pvObj - (uintptr_t)pPage < RTSystemGetPageSize());
    474477
    475478    /*
     
    517520     * Find the cache page.  The page structure is at the start of the page.
    518521     */
    519     PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~(uintptr_t)PAGE_OFFSET_MASK);
     522    PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~RTSystemGetPageOffsetMask());
    520523    Assert(pPage->pCache == pThis);
    521524    Assert(ASMAtomicUoReadS32(&pPage->cFree) < (int32_t)pThis->cPerPage);
     
    573576# ifdef RT_STRICT
    574577        /* This is the same as the other branch, except it's not actually freed. */
    575         PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~(uintptr_t)PAGE_OFFSET_MASK);
     578        PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~RTSystemGetPageOffsetMask());
    576579        Assert(pPage->pCache == pThis);
    577580        Assert(ASMAtomicUoReadS32(&pPage->cFree) < (int32_t)pThis->cPerPage);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette