Changeset 97943 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- Jan 2, 2023 4:50:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp
r97940 r97943 62 62 #include <iprt/err.h> 63 63 #include <iprt/mem.h> 64 #include <iprt/memobj.h> 64 65 #include <iprt/semaphore.h> 65 66 … … 146 147 - VBGL_PH_ALLOC_ALIGN, \ 147 148 VBGL_PH_ALLOC_ALIGN) 149 150 /** 151 * Whether to use the RTR0MemObjAllocCont API or RTMemContAlloc for 152 * allocating chunks. 153 * 154 * This can be enabled on hosts where RTMemContAlloc is more complicated than 155 * RTR0MemObjAllocCont. This can also be done if we wish to save code space, as 156 * the latter is typically always dragged into the link on guests where the 157 * linker cannot eliminiate functions within objects. Only drawback is that 158 * RTR0MemObjAllocCont requires another heap allocation for the handle. 159 */ 160 #if defined(DOXYGEN_RUNNING) || (!defined(IN_TESTCASE) && 0) 161 # define VBGL_PH_USE_MEMOBJ 162 #endif 148 163 149 164 … … 207 222 uint32_t physAddr; 208 223 224 #if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32 209 225 uint32_t uPadding1; 226 #endif 210 227 211 228 /** Number of block of any kind. */ … … 218 235 /** Pointer to the previous chunk. */ 219 236 VBGLPHYSHEAPCHUNK *pPrev; 237 238 #if defined(VBGL_PH_USE_MEMOBJ) 239 /** The allocation handle. */ 240 RTR0MEMOBJ hMemObj; 241 #endif 242 220 243 #if ARCH_BITS == 64 221 244 /** Pad the size up to 64 bytes. */ 245 # ifdef VBGL_PH_USE_MEMOBJ 246 uintptr_t auPadding2[2]; 247 # else 222 248 uintptr_t auPadding2[3]; 249 # endif 223 250 #endif 224 251 }; … … 486 513 static VBGLPHYSHEAPFREEBLOCK *vbglPhysHeapChunkAlloc(uint32_t cbMinBlock) 487 514 { 488 RTCCPHYS PhysAddr = NIL_RTHCPHYS; 489 VBGLPHYSHEAPCHUNK *pChunk; 490 uint32_t cbChunk; 515 RTCCPHYS PhysAddr = NIL_RTHCPHYS; 516 VBGLPHYSHEAPCHUNK *pChunk; 517 uint32_t cbChunk; 518 #ifdef VBGL_PH_USE_MEMOBJ 519 RTR0MEMOBJ hMemObj = NIL_RTR0MEMOBJ; 520 int rc; 521 #endif 522 491 523 VBGL_PH_DPRINTF(("Allocating new chunk for %#x byte allocation\n", cbMinBlock)); 492 524 AssertReturn(cbMinBlock <= VBGL_PH_LARGEST_ALLOC_SIZE, NULL); /* paranoia */ … … 509 541 * physical address to the host. 510 542 */ 543 #ifdef VBGL_PH_USE_MEMOBJ 544 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/); 545 pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL); 546 #else 511 547 pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk); 548 #endif 512 549 if (!pChunk) 513 550 { … … 520 557 cbChunk >>= 2; 521 558 cbChunk = RT_ALIGN_32(cbChunk, PAGE_SIZE); 559 #ifdef VBGL_PH_USE_MEMOBJ 560 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/); 561 pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL); 562 #else 522 563 pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk); 564 #endif 523 565 } while (!pChunk && cbChunk > cbMinChunk); 524 566 } … … 539 581 pChunk->pNext = NULL; 540 582 pChunk->pPrev = NULL; 583 #ifdef VBGL_PH_USE_MEMOBJ 584 pChunk->hMemObj = hMemObj; 585 #endif 586 587 /* Initialize the padding too: */ 588 #if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32 541 589 pChunk->uPadding1 = UINT32_C(0xADDCAAA1); 590 #endif 542 591 #if ARCH_BITS == 64 543 592 pChunk->auPadding2[0] = UINT64_C(0xADDCAAA3ADDCAAA2); 544 593 pChunk->auPadding2[1] = UINT64_C(0xADDCAAA5ADDCAAA4); 594 # ifndef VBGL_PH_USE_MEMOBJ 545 595 pChunk->auPadding2[2] = UINT64_C(0xADDCAAA7ADDCAAA6); 596 # endif 546 597 #endif 547 598 … … 627 678 * Finally, free the chunk memory. 628 679 */ 680 #ifdef VBGL_PH_USE_MEMOBJ 681 RTR0MemObjFree(pChunk->hMemObj, true /*fFreeMappings*/); 682 #else 629 683 RTMemContFree(pChunk, pChunk->cbChunk); 684 #endif 630 685 } 631 686
Note:
See TracChangeset
for help on using the changeset viewer.