- Timestamp:
- Jul 4, 2023 7:09:24 AM (18 months ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxGuest/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInit.cpp
r100267 r100360 117 117 g_vbgldata.pMmioReq = PortInfo.u.Out.pMmioReq; 118 118 119 rc = VbglR0PhysHeapInit(g_vbgldata.pMmioReq == NULL /*fAlloc32BitAddr*/); 119 /* 120 * Initialize the physical heap, only allocate memory below 4GiB if the new 121 * MMIO interface isn't available and we are using a 32-bit OUT instruction to pass a block 122 * physical address to the host. 123 */ 124 rc = VbglR0PhysHeapInit(g_vbgldata.pMmioReq == NULL ? _4G - 1 : NIL_RTHCPHYS /*HCPhysMax*/); 120 125 if (RT_SUCCESS(rc)) 121 126 { … … 208 213 g_vbgldata.pMmioReq = pMmioReq; 209 214 210 rc = VbglR0PhysHeapInit(pMmioReq == NULL /*fAlloc32BitAddr*/); 215 /* 216 * Initialize the physical heap, only allocate memory below 4GiB if the new 217 * MMIO interface isn't available and we are using a 32-bit OUT instruction to pass a block 218 * physical address to the host. 219 */ 220 rc = VbglR0PhysHeapInit(g_vbgldata.pMmioReq == NULL ? _4G - 1 : NIL_RTHCPHYS /*HCPhysMax*/); 211 221 if (RT_SUCCESS(rc)) 212 222 { -
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInternal.h
r100267 r100360 152 152 /** Head of the chunk list. */ 153 153 VBGLPHYSHEAPCHUNK *pChunkHead; 154 /** Flag whether all allocations should be below 4GiB to fit into 155 * a 32-bit address. */ 156 bool fAlloc32BitAddr; 154 /** Maximum physical address allowed for allocations, inclusive. */ 155 RTHCPHYS HCPhysMax; 157 156 /** @} */ 158 157 -
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp
r100267 r100360 157 157 * linker cannot eliminiate functions within objects. Only drawback is that 158 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 # endif159 * 160 * Update: Just enable it everywhere so we can more easily use memory above 4G. 161 */ 162 #define VBGL_PH_USE_MEMOBJ 163 163 164 164 … … 233 233 /** The allocation handle. */ 234 234 RTR0MEMOBJ hMemObj; 235 #elif ARCH_BITS == 64 235 #endif 236 #if ARCH_BITS == 64 236 237 /** Pad the size up to 64 bytes. */ 237 238 # ifdef VBGL_PH_USE_MEMOBJ … … 532 533 cbChunk = RT_ALIGN_32(cbChunk, VBGL_PH_CHUNKSIZE); 533 534 534 if (g_vbgldata.fAlloc32BitAddr)535 {536 /*537 * This function allocates physical contiguous memory below 4 GB. This 4GB538 * limitation stems from using a 32-bit OUT instruction to pass a block539 * physical address to the host.540 */541 535 #ifdef VBGL_PH_USE_MEMOBJ 542 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/); 543 pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL); 536 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, g_vbgldata.HCPhysMax, false /*fExecutable*/); 537 pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL); 538 PhysAddr = RT_SUCCESS(rc) ? (RTCCPHYS)RTR0MemObjGetPagePhysAddr(hMemObj, 0 /*iPage*/) : NIL_RTCCPHYS; 544 539 #else 545 pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk); 546 #endif 547 } 548 else 549 { 550 /** @todo Provide appropriate memory API. */ 551 #ifdef VBGL_PH_USE_MEMOBJ 552 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/); 553 pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL); 554 #else 555 pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk); 556 #endif 557 } 540 pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk); 541 #endif 558 542 if (!pChunk) 559 543 { … … 567 551 cbChunk = RT_ALIGN_32(cbChunk, PAGE_SIZE); 568 552 #ifdef VBGL_PH_USE_MEMOBJ 569 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/);553 rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, g_vbgldata.HCPhysMax, false /*fExecutable*/); 570 554 pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL); 555 PhysAddr = RT_SUCCESS(rc) ? (RTCCPHYS)RTR0MemObjGetPagePhysAddr(hMemObj, 0 /*iPage*/) : NIL_RTCCPHYS; 571 556 #else 572 557 pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk); … … 578 563 VBGLPHYSHEAPCHUNK *pOldHeadChunk; 579 564 VBGLPHYSHEAPFREEBLOCK *pBlock; 580 AssertRelease( !g_vbgldata.fAlloc32BitAddr565 AssertRelease( g_vbgldata.HCPhysMax == NIL_RTHCPHYS 581 566 || (PhysAddr < _4G && PhysAddr + cbChunk <= _4G)); 582 567 … … 1183 1168 #endif /* IN_TESTCASE */ 1184 1169 1185 DECLR0VBGL(int) VbglR0PhysHeapInit( bool fAlloc32BitAddr)1186 { 1187 g_vbgldata. fAlloc32BitAddr = fAlloc32BitAddr;1188 g_vbgldata.hMtxHeap 1170 DECLR0VBGL(int) VbglR0PhysHeapInit(RTHCPHYS HCPhysMax) 1171 { 1172 g_vbgldata.HCPhysMax = HCPhysMax; 1173 g_vbgldata.hMtxHeap = NIL_RTSEMFASTMUTEX; 1189 1174 1190 1175 /* Allocate the first chunk of the heap. */ -
trunk/src/VBox/Additions/common/VBoxGuest/lib/testcase/tstVbglR0PhysHeap-1.cpp
r100270 r100360 53 53 #define IN_TESTCASE 54 54 #define IN_RING0 /* pretend we're in ring-0 so we get access to the functions */ 55 #include <iprt/memobj.h> 55 56 #include "../VBoxGuestR0LibInternal.h" 56 57 … … 66 67 67 68 69 typedef struct TSTMEMOBJ 70 { 71 size_t cb; 72 } TSTMEMOBJ; 73 typedef TSTMEMOBJ *PTSTMEMOBJ; 74 75 68 76 /********************************************************************************************************************************* 69 77 * Global Variables * … … 75 83 76 84 /** Drop-in replacement for RTMemContAlloc */ 77 static void *tstMemContAlloc(PRTCCPHYS pPhys, size_t cb) 78 { 85 static int tstMemObjContAllocTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, bool fExecutable, const char *pszTag) 86 { 87 RT_NOREF(pszTag, PhysHighest, fExecutable); 88 79 89 RTTESTI_CHECK(cb > 0); 80 90 … … 82 92 if (g_cChunks < TST_MAX_CHUNKS) 83 93 { 84 void *pvRet = RTMemAlloc(cb); 85 if (pvRet) 86 { 94 PTSTMEMOBJ pMem = (PTSTMEMOBJ)RTMemAlloc(sizeof(TSTMEMOBJ) + cb); 95 if (pMem) 96 { 97 pMem->cb = cb; 98 87 99 g_cChunks++; 88 100 g_cbChunks += cb; 89 *pPhys = (uint32_t)(uintptr_t)pvRet ^ (UINT32_C(0xf0f0f0f0) & ~(uint32_t)PAGE_OFFSET_MASK); 90 91 /* Avoid problematic values that won't happen in real life: */ 92 if (!*pPhys) 93 *pPhys = 4U << PAGE_SHIFT; 94 if (UINT32_MAX - *pPhys < cb) 95 *pPhys -= RT_ALIGN_32(cb, PAGE_SIZE); 96 97 return pvRet; 98 } 99 } 100 101 *pPhys = NIL_RTCCPHYS; 102 return NULL; 103 } 104 105 106 /** Drop-in replacement for RTMemContFree */ 107 static void tstMemContFree(void *pv, size_t cb) 108 { 109 RTTESTI_CHECK(RT_VALID_PTR(pv)); 110 RTTESTI_CHECK(cb > 0); 101 *pMemObj = (RTR0MEMOBJ)pMem; 102 return VINF_SUCCESS; 103 } 104 } 105 106 return VERR_NO_MEMORY; 107 } 108 109 110 /** Drop-in replacement for RTR0MemObjAddress */ 111 static void *tstMemObjAddress(RTR0MEMOBJ hMemObj) 112 { 113 return (void *)((PTSTMEMOBJ)hMemObj + 1); 114 } 115 116 117 /** Drop-in replacement for RTR0MemObjGetPagePhysAddr */ 118 static RTHCPHYS tstMemObjGetPagePhysAddr(RTR0MEMOBJ hMemObj, uint32_t iPage) 119 { 120 RTTESTI_CHECK(iPage == 0); 121 122 PTSTMEMOBJ pMemObj = (PTSTMEMOBJ)hMemObj; 123 uintptr_t PtrMem = (uintptr_t)(pMemObj + 1); 124 RTHCPHYS Phys = (uint32_t)(uintptr_t)PtrMem ^ (UINT32_C(0xf0f0f0f0) & ~(uint32_t)PAGE_OFFSET_MASK); 125 126 /* Avoid problematic values that won't happen in real life: */ 127 if (!Phys) 128 Phys = 4U << PAGE_SHIFT; 129 if (UINT32_MAX - Phys < pMemObj->cb) 130 Phys -= RT_ALIGN_32(pMemObj->cb, PAGE_SIZE); 131 132 return Phys; 133 } 134 135 136 /** Drop-in replacement for RTR0MemObjFree */ 137 static void tstMemObjFree(RTR0MEMOBJ hMemObj, bool fFreeMappings) 138 { 139 RT_NOREF(fFreeMappings); 140 141 PTSTMEMOBJ pMemObj = (PTSTMEMOBJ)hMemObj; 142 RTTESTI_CHECK(RT_VALID_PTR(pMemObj)); 143 RTTESTI_CHECK(pMemObj->cb > 0); 111 144 RTTESTI_CHECK(g_cChunks > 0); 112 RTMemFree(pv);113 145 g_cChunks--; 114 g_cbChunks -= cb; 115 } 116 117 118 #define RTMemContAlloc tstMemContAlloc 119 #define RTMemContFree tstMemContFree 146 g_cbChunks -= pMemObj->cb; 147 RTMemFree(pMemObj); 148 } 149 150 151 #define RTR0MemObjAllocContTag tstMemObjContAllocTag 152 #define RTR0MemObjAddress tstMemObjAddress 153 #define RTR0MemObjGetPagePhysAddr tstMemObjGetPagePhysAddr 154 #define RTR0MemObjFree tstMemObjFree 120 155 #include "../VBoxGuestR0LibPhysHeap.cpp" 121 156 … … 178 213 */ 179 214 RTTestSub(hTest, "Basics"); 180 RTTESTI_CHECK_RC(rc = VbglR0PhysHeapInit( true /*fAlloc32BitAddr*/), VINF_SUCCESS);215 RTTESTI_CHECK_RC(rc = VbglR0PhysHeapInit(NIL_RTHCPHYS), VINF_SUCCESS); 181 216 if (RT_FAILURE(rc)) 182 217 return RTTestSummaryAndDestroy(hTest); … … 288 323 */ 289 324 RTTestSub(hTest, "Random Test"); 290 RTTESTI_CHECK_RC(rc = VbglR0PhysHeapInit( true /*fAlloc32BitAddr*/), VINF_SUCCESS);325 RTTESTI_CHECK_RC(rc = VbglR0PhysHeapInit(NIL_RTHCPHYS), VINF_SUCCESS); 291 326 if (RT_FAILURE(rc)) 292 327 return RTTestSummaryAndDestroy(hTest);
Note:
See TracChangeset
for help on using the changeset viewer.