Changeset 22273 in vbox for trunk/src/VBox/Runtime/common/alloc
- Timestamp:
- Aug 14, 2009 11:00:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/alloc/heapsimple.cpp
r21337 r22273 144 144 /** The typical magic (RTHEAPSIMPLE_MAGIC). */ 145 145 size_t uMagic; 146 /** The heap size. (This structure is notincluded!) */146 /** The heap size. (This structure is included!) */ 147 147 size_t cbHeap; 148 148 /** Pointer to the end of the heap. */ … … 285 285 * Initializes the heap. 286 286 * 287 * @returns IPRT status code on success.287 * @returns IPRT status code. 288 288 * @param pHeap Where to store the heap anchor block on success. 289 289 * @param pvMemory Pointer to the heap memory. … … 346 346 } 347 347 RT_EXPORT_SYMBOL(RTHeapSimpleInit); 348 349 350 /** 351 * Relocater the heap internal structures after copying it to a new location. 352 * 353 * This can be used when loading a saved heap. 354 * 355 * @returns IPRT status code. 356 * @param hHeap Heap handle that has already been adjusted by to the new 357 * location. That is to say, when calling 358 * RTHeapSimpleInit, the caller must note the offset of the 359 * returned heap handle into the heap memory. This offset 360 * must be used when calcuating the handle value for the 361 * new location. The offset may in some cases not be zero! 362 * @param offDelta The delta between the new and old location, i.e. what 363 * should be added to the internal pointers. 364 */ 365 RTDECL(int) RTHeapSimpleRelocate(RTHEAPSIMPLE hHeap, uintptr_t offDelta) 366 { 367 PRTHEAPSIMPLEINTERNAL pHeapInt = hHeap; 368 PRTHEAPSIMPLEFREE pCur; 369 370 /* 371 * Validate input. 372 */ 373 AssertPtrReturn(pHeapInt, VERR_INVALID_HANDLE); 374 AssertReturn(pHeapInt->uMagic == RTHEAPSIMPLE_MAGIC, VERR_INVALID_HANDLE); 375 AssertMsgReturn((uintptr_t)pHeapInt - (uintptr_t)pHeapInt->pvEnd + pHeapInt->cbHeap == offDelta, 376 ("offDelta=%p, expected=%p\n", offDelta, (uintptr_t)pHeapInt->pvEnd - pHeapInt->cbHeap - (uintptr_t)pHeapInt), 377 VERR_INVALID_PARAMETER); 378 379 /* 380 * Relocate the heap anchor block. 381 */ 382 #define RELOCATE_IT(var, type, offDelta) do { if (RT_UNLIKELY((var) != NULL)) { (var) = (type)((uintptr_t)(var) + offDelta); } } while (0) 383 RELOCATE_IT(pHeapInt->pvEnd, void *, offDelta); 384 RELOCATE_IT(pHeapInt->pFreeHead, PRTHEAPSIMPLEFREE, offDelta); 385 RELOCATE_IT(pHeapInt->pFreeTail, PRTHEAPSIMPLEFREE, offDelta); 386 387 /* 388 * Walk the heap blocks. 389 */ 390 for (pCur = PRTHEAPSIMPLEFREE(pHeapInt + 1); 391 pCur && (uintptr_t)pCur < (uintptr_t)pHeapInt->pvEnd; 392 pCur = (PRTHEAPSIMPLEFREE)pCur->Core.pNext) 393 { 394 RELOCATE_IT(pCur->Core.pNext, PRTHEAPSIMPLEBLOCK, offDelta); 395 RELOCATE_IT(pCur->Core.pPrev, PRTHEAPSIMPLEBLOCK, offDelta); 396 RELOCATE_IT(pCur->Core.pHeap, PRTHEAPSIMPLEINTERNAL, offDelta); 397 if (RTHEAPSIMPLEBLOCK_IS_FREE(&pCur->Core)) 398 { 399 RELOCATE_IT(pCur->pNext, PRTHEAPSIMPLEFREE, offDelta); 400 RELOCATE_IT(pCur->pPrev, PRTHEAPSIMPLEFREE, offDelta); 401 } 402 } 403 #undef RELOCATE_IT 404 405 #ifdef RTHEAPSIMPLE_STRICT 406 /* 407 * Give it a once over before we return. 408 */ 409 rtHeapSimpleAssertAll(pHeapInt); 410 #endif 411 return VINF_SUCCESS; 412 } 413 RT_EXPORT_SYMBOL(RTHeapSimpleRelocate); 348 414 349 415
Note:
See TracChangeset
for help on using the changeset viewer.