Changeset 25055 in vbox for trunk/src/VBox/Runtime/common/alloc
- Timestamp:
- Nov 27, 2009 3:45:49 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 55393
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/alloc/heapsimple.cpp
r22281 r25055 282 282 283 283 284 /** 285 * Initializes the heap. 286 * 287 * @returns IPRT status code. 288 * @param pHeap Where to store the heap anchor block on success. 289 * @param pvMemory Pointer to the heap memory. 290 * @param cbMemory The size of the heap memory. 291 */ 292 RTDECL(int) RTHeapSimpleInit(PRTHEAPSIMPLE pHeap, void *pvMemory, size_t cbMemory) 284 RTDECL(int) RTHeapSimpleInit(PRTHEAPSIMPLE phHeap, void *pvMemory, size_t cbMemory) 293 285 { 294 286 PRTHEAPSIMPLEINTERNAL pHeapInt; … … 338 330 pFree->cb = pHeapInt->cbFree; 339 331 340 *p Heap = pHeapInt;332 *phHeap = pHeapInt; 341 333 342 334 #ifdef RTHEAPSIMPLE_STRICT … … 348 340 349 341 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 new357 * location. That is to say, when calling358 * RTHeapSimpleInit, the caller must note the offset of the359 * returned heap handle into the heap memory. This offset360 * must be used when calcuating the handle value for the361 * new location. The offset may in some cases not be zero!362 * @param offDelta The delta between the new and old location, i.e. what363 * should be added to the internal pointers.364 */365 342 RTDECL(int) RTHeapSimpleRelocate(RTHEAPSIMPLE hHeap, uintptr_t offDelta) 366 343 { … … 373 350 AssertPtrReturn(pHeapInt, VERR_INVALID_HANDLE); 374 351 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), 352 AssertMsgReturn((uintptr_t)pHeapInt - (uintptr_t)pHeapInt->pvEnd + pHeapInt->cbHeap == offDelta, 353 ("offDelta=%p, expected=%p\n", offDelta, (uintptr_t)pHeapInt->pvEnd - pHeapInt->cbHeap - (uintptr_t)pHeapInt), 377 354 VERR_INVALID_PARAMETER); 378 355 … … 388 365 * Walk the heap blocks. 389 366 */ 390 for (pCur = (PRTHEAPSIMPLEFREE)(pHeapInt + 1); 391 pCur && (uintptr_t)pCur < (uintptr_t)pHeapInt->pvEnd; 367 for (pCur = (PRTHEAPSIMPLEFREE)(pHeapInt + 1); 368 pCur && (uintptr_t)pCur < (uintptr_t)pHeapInt->pvEnd; 392 369 pCur = (PRTHEAPSIMPLEFREE)pCur->Core.pNext) 393 370 { … … 409 386 rtHeapSimpleAssertAll(pHeapInt); 410 387 #endif 411 return VINF_SUCCESS; 388 return VINF_SUCCESS; 412 389 } 413 390 RT_EXPORT_SYMBOL(RTHeapSimpleRelocate); 414 391 415 392 416 417 /** 418 * Allocates memory from the specified simple heap. 419 * 420 * @returns Pointer to the allocated memory block on success. 421 * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.) 422 * 423 * @param Heap The heap to allocate the memory on. 424 * @param cb The requested heap block size. 425 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment. 426 * Must be a power of 2. 427 */ 428 RTDECL(void *) RTHeapSimpleAlloc(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment) 429 { 430 PRTHEAPSIMPLEINTERNAL pHeapInt = Heap; 393 RTDECL(void *) RTHeapSimpleAlloc(RTHEAPSIMPLE hHeap, size_t cb, size_t cbAlignment) 394 { 395 PRTHEAPSIMPLEINTERNAL pHeapInt = hHeap; 431 396 PRTHEAPSIMPLEBLOCK pBlock; 432 397 … … 463 428 464 429 465 /** 466 * Allocates zeroed memory from the specified simple heap. 467 * 468 * @returns Pointer to the allocated memory block on success. 469 * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.) 470 * 471 * @param Heap The heap to allocate the memory on. 472 * @param cb The requested heap block size. 473 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment. 474 * Must be a power of 2. 475 */ 476 RTDECL(void *) RTHeapSimpleAllocZ(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment) 477 { 478 PRTHEAPSIMPLEINTERNAL pHeapInt = Heap; 430 RTDECL(void *) RTHeapSimpleAllocZ(RTHEAPSIMPLE hHeap, size_t cb, size_t cbAlignment) 431 { 432 PRTHEAPSIMPLEINTERNAL pHeapInt = hHeap; 479 433 PRTHEAPSIMPLEBLOCK pBlock; 480 434 … … 519 473 * @returns Pointer to the allocated block. 520 474 * @returns NULL on failure. 475 * 521 476 * @param pHeapInt The heap. 522 477 * @param cb Size of the memory block to allocate. … … 686 641 687 642 688 689 690 /** 691 * Frees memory allocated from a simple heap. 692 * 693 * @param Heap The heap. This is optional and will only be used for strict assertions. 694 * @param pv The heap block returned by RTHeapSimple 695 */ 696 RTDECL(void) RTHeapSimpleFree(RTHEAPSIMPLE Heap, void *pv) 643 RTDECL(void) RTHeapSimpleFree(RTHEAPSIMPLE hHeap, void *pv) 697 644 { 698 645 PRTHEAPSIMPLEINTERNAL pHeapInt; … … 714 661 ASSERT_BLOCK_USED(pHeapInt, pBlock); 715 662 ASSERT_ANCHOR(pHeapInt); 716 Assert(pHeapInt == (PRTHEAPSIMPLEINTERNAL) Heap || !Heap);663 Assert(pHeapInt == (PRTHEAPSIMPLEINTERNAL)hHeap || !hHeap); 717 664 718 665 #ifdef RTHEAPSIMPLE_FREE_POISON … … 887 834 888 835 889 /** 890 * Gets the size of the specified heap block. 891 * 892 * @returns The actual size of the heap block. 893 * @returns 0 if \a pv is NULL or it doesn't point to a valid heap block. An invalid \a pv 894 * can also cause traps or trigger assertions. 895 * @param Heap The heap. This is optional and will only be used for strict assertions. 896 * @param pv The heap block returned by RTHeapSimple 897 */ 898 RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE Heap, void *pv) 836 RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE hHeap, void *pv) 899 837 { 900 838 PRTHEAPSIMPLEINTERNAL pHeapInt; … … 917 855 ASSERT_BLOCK_USED(pHeapInt, pBlock); 918 856 ASSERT_ANCHOR(pHeapInt); 919 Assert(pHeapInt == (PRTHEAPSIMPLEINTERNAL) Heap || !Heap);857 Assert(pHeapInt == (PRTHEAPSIMPLEINTERNAL)hHeap || !hHeap); 920 858 921 859 /* … … 929 867 930 868 931 /** 932 * Gets the size of the heap. 933 * 934 * This size includes all the internal heap structures. So, even if the heap is 935 * empty the RTHeapSimpleGetFreeSize() will never reach the heap size returned 936 * by this function. 937 * 938 * @returns The heap size. 939 * @returns 0 if heap was safely detected as being bad. 940 * @param Heap The heap. 941 */ 942 RTDECL(size_t) RTHeapSimpleGetHeapSize(RTHEAPSIMPLE Heap) 869 RTDECL(size_t) RTHeapSimpleGetHeapSize(RTHEAPSIMPLE hHeap) 943 870 { 944 871 PRTHEAPSIMPLEINTERNAL pHeapInt; 945 872 946 if ( Heap == NIL_RTHEAPSIMPLE)873 if (hHeap == NIL_RTHEAPSIMPLE) 947 874 return 0; 948 875 949 pHeapInt = Heap;876 pHeapInt = hHeap; 950 877 AssertPtrReturn(pHeapInt, 0); 951 878 ASSERT_ANCHOR(pHeapInt); … … 955 882 956 883 957 /** 958 * Returns the sum of all free heap blocks. 959 * 960 * This is the amount of memory you can theoretically allocate 961 * if you do allocations exactly matching the free blocks. 962 * 963 * @returns The size of the free blocks. 964 * @returns 0 if heap was safely detected as being bad. 965 * @param Heap The heap. 966 */ 967 RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE Heap) 884 RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE hHeap) 968 885 { 969 886 PRTHEAPSIMPLEINTERNAL pHeapInt; 970 887 971 if ( Heap == NIL_RTHEAPSIMPLE)888 if (hHeap == NIL_RTHEAPSIMPLE) 972 889 return 0; 973 890 974 pHeapInt = Heap;891 pHeapInt = hHeap; 975 892 AssertPtrReturn(pHeapInt, 0); 976 893 ASSERT_ANCHOR(pHeapInt); … … 980 897 981 898 982 /** 983 * Dumps the hypervisor heap. 984 * 985 * @param Heap The heap handle. 986 * @param pfnPrintf Printf like function that groks IPRT formatting. 987 */ 988 RTDECL(void) RTHeapSimpleDump(RTHEAPSIMPLE Heap, PFNRTHEAPSIMPLEPRINTF pfnPrintf) 989 { 990 PRTHEAPSIMPLEINTERNAL pHeapInt = (PRTHEAPSIMPLEINTERNAL)Heap; 899 RTDECL(void) RTHeapSimpleDump(RTHEAPSIMPLE hHeap, PFNRTHEAPSIMPLEPRINTF pfnPrintf) 900 { 901 PRTHEAPSIMPLEINTERNAL pHeapInt = (PRTHEAPSIMPLEINTERNAL)hHeap; 991 902 PRTHEAPSIMPLEFREE pBlock; 992 903 993 904 pfnPrintf("**** Dumping Heap %p - cbHeap=%zx cbFree=%zx ****\n", 994 Heap, pHeapInt->cbHeap, pHeapInt->cbFree);905 hHeap, pHeapInt->cbHeap, pHeapInt->cbFree); 995 906 996 907 for (pBlock = (PRTHEAPSIMPLEFREE)(pHeapInt + 1); … … 1008 919 pBlock, (uintptr_t)pBlock - (uintptr_t)(pHeapInt + 1), pBlock->Core.pNext, pBlock->Core.pPrev, pBlock->Core.fFlags, cb); 1009 920 } 1010 pfnPrintf("**** Done dumping Heap %p ****\n", Heap);921 pfnPrintf("**** Done dumping Heap %p ****\n", hHeap); 1011 922 } 1012 923 RT_EXPORT_SYMBOL(RTHeapSimpleDump);
Note:
See TracChangeset
for help on using the changeset viewer.