Changeset 100309 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Jun 28, 2023 10:25:37 AM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/alloc/memcache.cpp
r98103 r100309 47 47 #include <iprt/err.h> 48 48 #include <iprt/mem.h> 49 #include <iprt/ param.h>49 #include <iprt/system.h> 50 50 51 51 #include "internal/magics.h" … … 175 175 AssertReturn(!pfnDtor || pfnCtor, VERR_INVALID_PARAMETER); 176 176 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); 178 180 AssertReturn(!fFlags, VERR_INVALID_PARAMETER); 179 181 … … 215 217 pThis->cbObject = (uint32_t)RT_ALIGN_Z(cbObject, cbAlignment); 216 218 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); 218 220 while ( RT_ALIGN_Z(sizeof(RTMEMCACHEPAGE), 8) 219 221 + pThis->cPerPage * pThis->cbObject 220 222 + RT_ALIGN(pThis->cPerPage, 64) / 8 * 2 221 > PAGE_SIZE)223 > cbPage) 222 224 pThis->cPerPage--; 223 225 pThis->cBits = RT_ALIGN(pThis->cPerPage, 64); … … 276 278 } 277 279 278 RTMemPageFree(pPage, PAGE_SIZE);280 RTMemPageFree(pPage, RTSystemGetPageSize()); 279 281 } 280 282 … … 310 312 * on the cache. 311 313 */ 312 PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)RTMemPageAlloc(PAGE_SIZE); 314 size_t const cbPage = RTSystemGetPageSize(); 315 PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)RTMemPageAlloc(cbPage); 313 316 if (pPage) 314 317 { … … 323 326 pb = RT_ALIGN_PT(pb, 8, uint8_t *); 324 327 pPage->pbmCtor = pb; 325 pb = (uint8_t *)pPage + PAGE_SIZE- pThis->cbObject * cObjects;328 pb = (uint8_t *)pPage + cbPage - pThis->cbObject * cObjects; 326 329 pPage->pbObjects = pb; Assert(RT_ALIGN_P(pb, pThis->cbAlignment) == pb); 327 330 pb -= pThis->cBits / 8; … … 471 474 } 472 475 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()); 474 477 475 478 /* … … 517 520 * Find the cache page. The page structure is at the start of the page. 518 521 */ 519 PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~ (uintptr_t)PAGE_OFFSET_MASK);522 PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~RTSystemGetPageOffsetMask()); 520 523 Assert(pPage->pCache == pThis); 521 524 Assert(ASMAtomicUoReadS32(&pPage->cFree) < (int32_t)pThis->cPerPage); … … 573 576 # ifdef RT_STRICT 574 577 /* 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()); 576 579 Assert(pPage->pCache == pThis); 577 580 Assert(ASMAtomicUoReadS32(&pPage->cFree) < (int32_t)pThis->cPerPage);
Note:
See TracChangeset
for help on using the changeset viewer.