Changeset 71629 in vbox for trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
- Timestamp:
- Apr 3, 2018 2:23:01 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
r71626 r71629 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * VBox Host Guest Shared Memory Interface (HGSMI).3 * VBox Host Guest Shared Memory Interface (HGSMI), host part. 4 * 5 5 * Host part: 6 6 * - virtual hardware IO handlers; … … 86 86 87 87 #ifdef VBOXHGSMI_STATE_DEBUG 88 # define VBOXHGSMI_STATE_START_MAGIC 0x1234567889 # define VBOXHGSMI_STATE_STOP_MAGIC 0x8765432190 # define VBOXHGSMI_STATE_FIFOSTART_MAGIC 0x9abcdef191 # define VBOXHGSMI_STATE_FIFOSTOP_MAGIC 0x1fedcba992 93 # define VBOXHGSMI_SAVE_START(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_START_MAGIC); AssertRC(rc2); }while(0)94 # define VBOXHGSMI_SAVE_STOP(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC); AssertRC(rc2); }while(0)95 # define VBOXHGSMI_SAVE_FIFOSTART(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC); AssertRC(rc2); }while(0)96 # define VBOXHGSMI_SAVE_FIFOSTOP(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC); AssertRC(rc2); }while(0)97 98 # define VBOXHGSMI_LOAD_CHECK(_pSSM, _v) \99 do { \88 # define VBOXHGSMI_STATE_START_MAGIC UINT32_C(0x12345678) 89 # define VBOXHGSMI_STATE_STOP_MAGIC UINT32_C(0x87654321) 90 # define VBOXHGSMI_STATE_FIFOSTART_MAGIC UINT32_C(0x9abcdef1) 91 # define VBOXHGSMI_STATE_FIFOSTOP_MAGIC UINT32_C(0x1fedcba9) 92 93 # define VBOXHGSMI_SAVE_START(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_START_MAGIC); AssertRC(rc2); }while(0) 94 # define VBOXHGSMI_SAVE_STOP(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC); AssertRC(rc2); }while(0) 95 # define VBOXHGSMI_SAVE_FIFOSTART(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC); AssertRC(rc2); }while(0) 96 # define VBOXHGSMI_SAVE_FIFOSTOP(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC); AssertRC(rc2); }while(0) 97 98 # define VBOXHGSMI_LOAD_CHECK(_pSSM, _v) \ 99 do { \ 100 100 uint32_t u32; \ 101 101 int rc2 = SSMR3GetU32(_pSSM, &u32); AssertRC(rc2); \ 102 102 Assert(u32 == (_v)); \ 103 }while(0) 104 105 #define VBOXHGSMI_LOAD_START(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_START_MAGIC) 106 #define VBOXHGSMI_LOAD_FIFOSTART(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC) 107 #define VBOXHGSMI_LOAD_FIFOSTOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC) 108 #define VBOXHGSMI_LOAD_STOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC) 109 #else 110 #define VBOXHGSMI_SAVE_START(_pSSM) do{ }while(0) 111 #define VBOXHGSMI_SAVE_STOP(_pSSM) do{ }while(0) 112 #define VBOXHGSMI_SAVE_FIFOSTART(_pSSM) do{ }while(0) 113 #define VBOXHGSMI_SAVE_FIFOSTOP(_pSSM) do{ }while(0) 114 115 116 #define VBOXHGSMI_LOAD_START(_pSSM) do{ }while(0) 117 #define VBOXHGSMI_LOAD_FIFOSTART(_pSSM) do{ }while(0) 118 #define VBOXHGSMI_LOAD_FIFOSTOP(_pSSM) do{ }while(0) 119 #define VBOXHGSMI_LOAD_STOP(_pSSM) do{ }while(0) 120 103 } while(0) 104 105 # define VBOXHGSMI_LOAD_START(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_START_MAGIC) 106 # define VBOXHGSMI_LOAD_FIFOSTART(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC) 107 # define VBOXHGSMI_LOAD_FIFOSTOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC) 108 # define VBOXHGSMI_LOAD_STOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC) 109 #else /* !VBOXHGSMI_STATE_DEBUG */ 110 # define VBOXHGSMI_SAVE_START(a_pSSM) do { } while(0) 111 # define VBOXHGSMI_SAVE_STOP(a_pSSM) do { } while(0) 112 # define VBOXHGSMI_SAVE_FIFOSTART(a_pSSM) do { } while(0) 113 # define VBOXHGSMI_SAVE_FIFOSTOP(a_pSSM) do { } while(0) 114 115 # define VBOXHGSMI_LOAD_START(a_pSSM) do { } while(0) 116 # define VBOXHGSMI_LOAD_FIFOSTART(a_pSSM) do { } while(0) 117 # define VBOXHGSMI_LOAD_FIFOSTOP(a_pSSM) do { } while(0) 118 # define VBOXHGSMI_LOAD_STOP(a_pSSM) do { } while(0) 121 119 #endif 122 120 … … 125 123 */ 126 124 #ifdef HGSMI_STRICT 127 # define HGSMI_STRICT_ASSERT_FAILED()AssertFailed()128 # define HGSMI_STRICT_ASSERT(expr)Assert(expr)125 # define HGSMI_STRICT_ASSERT_FAILED() AssertFailed() 126 # define HGSMI_STRICT_ASSERT(expr) Assert(expr) 129 127 #else 130 #define HGSMI_STRICT_ASSERT_FAILED() do {} while (0) 131 #define HGSMI_STRICT_ASSERT(expr) do {} while (0) 132 #endif /* !HGSMI_STRICT */ 133 134 135 /* Host heap types. */ 136 #define HGSMI_HEAP_TYPE_NULL 0 /* Heap not initialized. */ 137 #define HGSMI_HEAP_TYPE_POINTER 1 /* Deprecated, used only for old saved states. RTHEAPSIMPLE. */ 138 #define HGSMI_HEAP_TYPE_OFFSET 2 /* Deprecated, used only for old saved states. RTHEAPOFFSET. */ 139 #define HGSMI_HEAP_TYPE_MA 3 /* Memory allocator. */ 128 # define HGSMI_STRICT_ASSERT_FAILED() do {} while (0) 129 # define HGSMI_STRICT_ASSERT(expr) do {} while (0) 130 #endif 131 132 133 /** @name Host heap types. 134 * @{ */ 135 #define HGSMI_HEAP_TYPE_NULL 0 /**< Heap not initialized. */ 136 #define HGSMI_HEAP_TYPE_POINTER 1 /**< Deprecated, used only for old saved states. RTHEAPSIMPLE. */ 137 #define HGSMI_HEAP_TYPE_OFFSET 2 /**< Deprecated, used only for old saved states. RTHEAPOFFSET. */ 138 #define HGSMI_HEAP_TYPE_MA 3 /**< Memory allocator. */ 139 /** @} */ 140 140 141 141 typedef struct HGSMIHOSTHEAP 142 142 { 143 uint32_t u32HeapType; /* HGSMI_HEAP_TYPE_* */144 int32_t volatile cRefs; /* How many blocks allocated. */145 HGSMIAREA area; /* Host heap location. */143 uint32_t u32HeapType; /**< HGSMI_HEAP_TYPE_* */ 144 int32_t volatile cRefs; /**< How many blocks allocated. */ 145 HGSMIAREA area; /**< Host heap location. */ 146 146 union 147 147 { 148 HGSMIMADATA ma; /* Memory allocator for the default host heap implementation. */149 struct /* Legacy heap implementations. For old saved states. */148 HGSMIMADATA ma; /**< Memory allocator for the default host heap implementation. */ 149 struct /**< Legacy heap implementations. For old saved states. */ 150 150 { 151 151 union 152 152 { 153 RTHEAPSIMPLE hPtr; /* Pointer based heap. */154 RTHEAPOFFSET hOff; /* Offset based heap. */153 RTHEAPSIMPLE hPtr; /**< Pointer based heap. */ 154 RTHEAPOFFSET hOff; /**< Offset based heap. */ 155 155 } u; 156 156 } legacy; … … 160 160 typedef struct HGSMIINSTANCE 161 161 { 162 PVM pVM; /* The VM. */163 164 const char *pszName; /* A name for the instance. Mostyl used in the log. */165 166 RTCRITSECT instanceCritSect; /* For updating the instance data: FIFO's, channels. */167 168 HGSMIAREA area; /*The shared memory description. */169 HGSMIHOSTHEAP hostHeap; /* Host heap instance. */170 RTCRITSECT hostHeapCritSect; /* Heap serialization lock. */171 172 RTLISTANCHOR hostFIFO; /* Pending host buffers. */173 RTLISTANCHOR hostFIFORead; /* Host buffers read by the guest. */174 RTLISTANCHOR hostFIFOProcessed; /* Processed by the guest. */175 RTLISTANCHOR hostFIFOFree; /* Buffers for reuse. */162 PVM pVM; /**< The VM. */ 163 164 const char *pszName; /**< A name for the instance. Mostyl used in the log. */ 165 166 RTCRITSECT instanceCritSect; /**< For updating the instance data: FIFO's, channels. */ 167 168 HGSMIAREA area; /**< The shared memory description. */ 169 HGSMIHOSTHEAP hostHeap; /**< Host heap instance. */ 170 RTCRITSECT hostHeapCritSect; /**< Heap serialization lock. */ 171 172 RTLISTANCHOR hostFIFO; /**< Pending host buffers. */ 173 RTLISTANCHOR hostFIFORead; /**< Host buffers read by the guest. */ 174 RTLISTANCHOR hostFIFOProcessed; /**< Processed by the guest. */ 175 RTLISTANCHOR hostFIFOFree; /**< Buffers for reuse. */ 176 176 #ifdef VBOX_WITH_WDDM 177 RTLISTANCHOR guestCmdCompleted; /* list of completed guest commands to be returned to the guest*/177 RTLISTANCHOR guestCmdCompleted; /**< list of completed guest commands to be returned to the guest*/ 178 178 #endif 179 RTCRITSECT hostFIFOCritSect; /* FIFO serialization lock. */180 181 PFNHGSMINOTIFYGUEST pfnNotifyGuest; /* Guest notification callback. */182 void *pvNotifyGuest; /* Guest notification callback context. */179 RTCRITSECT hostFIFOCritSect; /**< FIFO serialization lock. */ 180 181 PFNHGSMINOTIFYGUEST pfnNotifyGuest; /**< Guest notification callback. */ 182 void *pvNotifyGuest; /**< Guest notification callback context. */ 183 183 184 184 volatile HGSMIHOSTFLAGS *pHGFlags; 185 185 186 HGSMICHANNELINFO channelInfo; /* Channel handlers indexed by the channel id.186 HGSMICHANNELINFO channelInfo; /**< Channel handlers indexed by the channel id. 187 187 * The array is accessed under the instance lock. 188 188 */ … … 197 197 RTLISTNODE nodeEntry; 198 198 199 HGSMIINSTANCE *pIns; /* Backlink to the HGSMI instance. */200 201 volatile uint32_t fl; /* Status flags of the entry. */202 203 HGSMIOFFSET offBuffer; /* Offset of the HGSMI buffer header in the HGSMI host heap:199 HGSMIINSTANCE *pIns; /**< Backlink to the HGSMI instance. */ 200 201 volatile uint32_t fl; /**< Status flags of the entry. */ 202 203 HGSMIOFFSET offBuffer; /**< Offset of the HGSMI buffer header in the HGSMI host heap: 204 204 * [pIns->hostHeap.area.offBase .. offLast]. */ 205 205 } HGSMIHOSTFIFOENTRY; … … 213 213 #define HGSMI_F_HOST_FIFO_CANCELED 0x0020 214 214 215 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback 215 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback(void *pvCallback); 216 216 217 217 #ifdef VBOX_WITH_WDDM … … 220 220 { 221 221 RTLISTNODE nodeEntry; 222 HGSMIOFFSET offBuffer; /* Offset of the guest command buffer. */222 HGSMIOFFSET offBuffer; /**< Offset of the guest command buffer. */ 223 223 } HGSMIGUESTCOMPLENTRY; 224 224 225 225 226 static void hgsmiGuestCompletionFIFOFree 226 static void hgsmiGuestCompletionFIFOFree(HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY *pEntry) 227 227 { 228 228 NOREF (pIns); … … 230 230 } 231 231 232 static int hgsmiGuestCompletionFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY **ppEntry) 233 { 234 int rc = VINF_SUCCESS; 235 236 NOREF (pIns); 237 238 HGSMIGUESTCOMPLENTRY *pEntry = (HGSMIGUESTCOMPLENTRY *)RTMemAllocZ (sizeof (HGSMIGUESTCOMPLENTRY)); 239 232 static int hgsmiGuestCompletionFIFOAlloc(HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY **ppEntry) 233 { 234 HGSMIGUESTCOMPLENTRY *pEntry = (HGSMIGUESTCOMPLENTRY *)RTMemAllocZ(sizeof(HGSMIGUESTCOMPLENTRY)); 240 235 if (pEntry) 236 { 241 237 *ppEntry = pEntry; 242 else243 rc = VERR_NO_MEMORY;244 245 return rc;246 } 247 248 #endif 249 250 static int hgsmiLock 251 { 252 int rc = RTCritSectEnter 253 AssertRC 254 return rc; 255 } 256 257 static void hgsmiUnlock 258 { 259 int rc = RTCritSectLeave 260 AssertRC 261 } 262 263 static int hgsmiFIFOLock 264 { 265 int rc = RTCritSectEnter 266 AssertRC 267 return rc; 268 } 269 270 static void hgsmiFIFOUnlock 271 { 272 int rc = RTCritSectLeave 273 AssertRC 238 return VINF_SUCCESS; 239 } 240 NOREF(pIns); 241 return VERR_NO_MEMORY; 242 } 243 244 #endif /* VBOX_WITH_WDDM */ 245 246 static int hgsmiLock(HGSMIINSTANCE *pIns) 247 { 248 int rc = RTCritSectEnter(&pIns->instanceCritSect); 249 AssertRC(rc); 250 return rc; 251 } 252 253 static void hgsmiUnlock(HGSMIINSTANCE *pIns) 254 { 255 int rc = RTCritSectLeave(&pIns->instanceCritSect); 256 AssertRC(rc); 257 } 258 259 static int hgsmiFIFOLock(HGSMIINSTANCE *pIns) 260 { 261 int rc = RTCritSectEnter(&pIns->hostFIFOCritSect); 262 AssertRC(rc); 263 return rc; 264 } 265 266 static void hgsmiFIFOUnlock(HGSMIINSTANCE *pIns) 267 { 268 int rc = RTCritSectLeave(&pIns->hostFIFOCritSect); 269 AssertRC(rc); 274 270 } 275 271 … … 282 278 * @thread EMT 283 279 */ 284 void HGSMIGuestWrite (PHGSMIINSTANCE pIns, 285 HGSMIOFFSET offBuffer) 286 { 287 HGSMIBufferProcess (&pIns->area, &pIns->channelInfo, offBuffer); 280 void HGSMIGuestWrite(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer) 281 { 282 HGSMIBufferProcess(&pIns->area, &pIns->channelInfo, offBuffer); 288 283 } 289 284 … … 325 320 326 321 /* Called from HGSMI_IO_GUEST read handler. */ 327 HGSMIOFFSET HGSMIGuestRead 322 HGSMIOFFSET HGSMIGuestRead(PHGSMIINSTANCE pIns) 328 323 { 329 324 LogFlowFunc(("pIns %p\n", pIns)); … … 346 341 } 347 342 348 static bool hgsmiProcessHostCmdCompletion(HGSMIINSTANCE *pIns, 349 HGSMIOFFSET offBuffer, 350 bool bCompleteFirst) 343 static bool hgsmiProcessHostCmdCompletion(HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer, bool fCompleteFirst) 351 344 { 352 345 VM_ASSERT_EMT(pIns->pVM); … … 362 355 { 363 356 Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_READ)); 364 if ( bCompleteFirst || pIter->offBuffer == offBuffer)357 if (fCompleteFirst || pIter->offBuffer == offBuffer) 365 358 { 366 359 pEntry = pIter; … … 371 364 LogFlowFunc(("read list entry: %p.\n", pEntry)); 372 365 373 Assert(pEntry || bCompleteFirst);366 Assert(pEntry || fCompleteFirst); 374 367 375 368 if (pEntry) … … 385 378 386 379 hgsmiHostCommandFreeCallback(pEntry); 387 388 380 return true; 389 381 } 390 382 391 383 hgsmiFIFOUnlock(pIns); 392 if (! bCompleteFirst)384 if (!fCompleteFirst) 393 385 LogRel(("HGSMI[%s]: ignored invalid write to the host FIFO: 0x%08X!!!\n", pIns->pszName, offBuffer)); 394 386 } … … 396 388 } 397 389 398 /* The guest has finished processing of a buffer previously submitted by the host. 390 /** 391 * The guest has finished processing of a buffer previously submitted by the 392 * host. 393 * 399 394 * Called from HGSMI_IO_HOST write handler. 400 395 * @thread EMT 401 396 */ 402 void HGSMIHostWrite (HGSMIINSTANCE *pIns, 403 HGSMIOFFSET offBuffer) 397 void HGSMIHostWrite(HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer) 404 398 { 405 399 LogFlowFunc(("pIns %p offBuffer 0x%x\n", pIns, offBuffer)); 406 400 407 hgsmiProcessHostCmdCompletion (pIns, offBuffer, false); 408 } 409 410 /* The guest reads a new host buffer to be processed. 401 hgsmiProcessHostCmdCompletion(pIns, offBuffer, false); 402 } 403 404 /** 405 * The guest reads a new host buffer to be processed. 406 * 411 407 * Called from the HGSMI_IO_HOST read handler. 408 * 412 409 * @thread EMT 413 410 */ 414 HGSMIOFFSET HGSMIHostRead 411 HGSMIOFFSET HGSMIHostRead(HGSMIINSTANCE *pIns) 415 412 { 416 413 LogFlowFunc(("pIns %p\n", pIns)); … … 460 457 461 458 462 /* Tells the guest that a new buffer to be processed is available from the host. */463 static void hgsmiNotifyGuest 459 /** Tells the guest that a new buffer to be processed is available from the host. */ 460 static void hgsmiNotifyGuest(HGSMIINSTANCE *pIns) 464 461 { 465 462 if (pIns->pfnNotifyGuest) 466 { 467 pIns->pfnNotifyGuest (pIns->pvNotifyGuest); 468 } 463 pIns->pfnNotifyGuest(pIns->pvNotifyGuest); 469 464 } 470 465 … … 477 472 uint32_t HGSMIGetHostGuestFlags(HGSMIINSTANCE *pIns) 478 473 { 479 return pIns->pHGFlags ? ASMAtomicReadU32(&pIns->pHGFlags->u32HostFlags) : 0;474 return pIns->pHGFlags ? ASMAtomicReadU32(&pIns->pHGFlags->u32HostFlags) : 0; 480 475 } 481 476 … … 483 478 { 484 479 AssertPtrReturnVoid(pIns->pHGFlags); 485 ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, (~flags)); 486 } 480 ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, ~flags); 481 } 482 487 483 488 484 /* … … 492 488 * 493 489 */ 490 494 491 static int hgsmiHostHeapLock(HGSMIINSTANCE *pIns) 495 492 { 496 493 int rc = RTCritSectEnter(&pIns->hostHeapCritSect); 497 AssertRC 494 AssertRC(rc); 498 495 return rc; 499 496 } … … 502 499 { 503 500 int rc = RTCritSectLeave(&pIns->hostHeapCritSect); 504 AssertRC 501 AssertRC(rc); 505 502 } 506 503 … … 570 567 HGSMIOFFSET offHeapHandle; 571 568 if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER) 572 {573 569 offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hPtr - (uintptr_t)pHeap->area.pu8Base); 574 }575 570 else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET) 576 {577 571 offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hOff - (uintptr_t)pHeap->area.pu8Base); 578 }579 572 else 580 {581 573 offHeapHandle = HGSMIOFFSET_VOID; 582 }583 574 return offHeapHandle; 584 575 } … … 596 587 { 597 588 if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET) 598 {599 589 pHeap->u.legacy.u.hOff = (RTHEAPOFFSET)((uint8_t *)pvBase + offHeapHandle); 600 }601 590 else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER) 602 591 { … … 611 600 612 601 if (RT_SUCCESS(rc)) 613 {614 602 pHeap->u32HeapType = u32HeapType; 615 }616 603 else 617 {618 604 HGSMIAreaClear(&pHeap->area); 619 }620 605 } 621 606 … … 636 621 { 637 622 rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, paDescriptors, cBlocks, cbMaxBlock, pEnv); 638 639 623 if (RT_SUCCESS(rc)) 640 {641 624 pHeap->u32HeapType = HGSMI_HEAP_TYPE_MA; 642 }643 625 else 644 {645 626 HGSMIAreaClear(&pHeap->area); 646 }647 627 } 648 628 … … 659 639 { 660 640 if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA) 661 {662 641 HGSMIMAUninit(&pHeap->u.ma); 663 }664 642 hgsmiHostHeapSetupUninitialized(pHeap); 665 643 } 666 644 667 static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry) 668 { 669 int rc = VINF_SUCCESS; 670 671 NOREF (pIns); 672 673 HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)RTMemAllocZ (sizeof (HGSMIHOSTFIFOENTRY)); 674 645 static int hgsmiHostFIFOAlloc(HGSMIHOSTFIFOENTRY **ppEntry) 646 { 647 HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)RTMemAllocZ(sizeof(HGSMIHOSTFIFOENTRY)); 675 648 if (pEntry) 676 649 { 677 650 pEntry->fl = HGSMI_F_HOST_FIFO_ALLOCATED; 678 }679 else680 {681 rc = VERR_NO_MEMORY;682 }683 684 if (RT_SUCCESS (rc))685 {686 651 *ppEntry = pEntry; 687 } 688 689 return rc; 690 } 691 692 static void hgsmiHostFIFOFree (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY *pEntry) 693 { 694 NOREF (pIns); 695 RTMemFree (pEntry); 652 return VINF_SUCCESS; 653 } 654 return VERR_NO_MEMORY; 655 } 656 657 static void hgsmiHostFIFOFree(HGSMIHOSTFIFOENTRY *pEntry) 658 { 659 RTMemFree(pEntry); 696 660 } 697 661 … … 701 665 702 666 HGSMIINSTANCE *pIns = pEntry->pIns; 703 int rc = hgsmiFIFOLock 667 int rc = hgsmiFIFOLock(pIns); 704 668 if (RT_SUCCESS(rc)) 705 669 { 706 670 RTListNodeRemove(&pEntry->nodeEntry); 707 hgsmiFIFOUnlock 671 hgsmiFIFOUnlock(pIns); 708 672 709 673 void RT_UNTRUSTED_VOLATILE_GUEST *pvData = HGSMIBufferDataFromOffset(&pIns->hostHeap.area, pEntry->offBuffer); 710 674 711 rc = hgsmiHostHeapLock 675 rc = hgsmiHostHeapLock(pIns); 712 676 if (RT_SUCCESS(rc)) 713 677 { … … 718 682 } 719 683 720 hgsmiHostFIFOFree (pIns,pEntry);684 hgsmiHostFIFOFree(pEntry); 721 685 } 722 686 … … 747 711 748 712 if (pEntry) 749 {750 713 RTListNodeRemove(&pEntry->nodeEntry); 751 }752 714 else 753 {754 715 AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n", 755 716 pIns->pszName, offBuffer)); 756 } 757 758 hgsmiFIFOUnlock (pIns); 759 760 rc = hgsmiHostHeapLock (pIns); 717 718 hgsmiFIFOUnlock(pIns); 719 720 rc = hgsmiHostHeapLock(pIns); 761 721 if (RT_SUCCESS(rc)) 762 722 { … … 770 730 { 771 731 /* Deallocate the entry. */ 772 hgsmiHostFIFOFree(p Ins, pEntry);773 } 774 } 775 776 return rc; 777 } 778 779 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback 732 hgsmiHostFIFOFree(pEntry); 733 } 734 } 735 736 return rc; 737 } 738 739 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback(void *pvCallback) 780 740 { 781 741 /* Guest has processed the command. */ … … 785 745 786 746 /* This is a simple callback, just signal the event. */ 787 hgsmiHostCommandFreeByEntry (pEntry); 788 } 789 790 static int hgsmiHostCommandWrite(HGSMIINSTANCE *pIns, 791 HGSMIOFFSET offBuffer) 747 hgsmiHostCommandFreeByEntry(pEntry); 748 } 749 750 static int hgsmiHostCommandWrite(HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer) 792 751 { 793 752 AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER); 794 753 795 754 HGSMIHOSTFIFOENTRY *pEntry; 796 int rc = hgsmiHostFIFOAlloc(pIns, &pEntry); 797 755 int rc = hgsmiHostFIFOAlloc(&pEntry); 798 756 if (RT_SUCCESS(rc)) 799 757 { … … 813 771 } 814 772 else 815 { 816 hgsmiHostFIFOFree(pIns, pEntry); 817 } 773 hgsmiHostFIFOFree(pEntry); 818 774 } 819 775 … … 874 830 875 831 if (pvData) 876 {877 832 *ppvData = pvData; 878 }879 833 else 880 834 { … … 978 932 RT_UNTRUSTED_VALIDATED_FENCE(); 979 933 980 981 934 /* 982 935 * Lock the heap and do the job. … … 1026 979 rc = SSMR3PutU32(pSSM, pIter->offBuffer); 1027 980 if (RT_FAILURE(rc)) 1028 {1029 981 break; 1030 }1031 982 } 1032 983 } … … 1055 1006 rc = SSMR3PutU32(pSSM, pIter->offBuffer); 1056 1007 if (RT_FAILURE(rc)) 1057 {1058 1008 break; 1059 }1060 1009 } 1061 1010 } … … 1066 1015 } 1067 1016 1068 static int hgsmiHostLoadFifoEntryLocked 1017 static int hgsmiHostLoadFifoEntryLocked(PHGSMIINSTANCE pIns, HGSMIHOSTFIFOENTRY **ppEntry, PSSMHANDLE pSSM) 1069 1018 { 1070 1019 HGSMIHOSTFIFOENTRY *pEntry; 1071 int rc = hgsmiHostFIFOAlloc (pIns,&pEntry); AssertRC(rc);1072 if (RT_SUCCESS 1020 int rc = hgsmiHostFIFOAlloc(&pEntry); AssertRC(rc); 1021 if (RT_SUCCESS(rc)) 1073 1022 { 1074 1023 uint32_t u32; 1075 1024 pEntry->pIns = pIns; 1076 rc = SSMR3GetU32 1025 rc = SSMR3GetU32(pSSM, &u32); AssertRC(rc); 1077 1026 pEntry->fl = u32; 1078 rc = SSMR3GetU32 1079 if (RT_SUCCESS 1027 rc = SSMR3GetU32(pSSM, &pEntry->offBuffer); AssertRC(rc); 1028 if (RT_SUCCESS(rc)) 1080 1029 *ppEntry = pEntry; 1081 1030 else 1082 hgsmiHostFIFOFree (pIns,pEntry);1031 hgsmiHostFIFOFree(pEntry); 1083 1032 } 1084 1033 … … 1113 1062 { 1114 1063 HGSMIGUESTCOMPLENTRY *pEntry; 1115 int rc = hgsmiGuestCompletionFIFOAlloc 1064 int rc = hgsmiGuestCompletionFIFOAlloc(pIns, &pEntry); AssertRC(rc); 1116 1065 if (RT_SUCCESS (rc)) 1117 1066 { 1118 rc = SSMR3GetU32 1119 if (RT_SUCCESS 1067 rc = SSMR3GetU32(pSSM, &pEntry->offBuffer); AssertRC(rc); 1068 if (RT_SUCCESS(rc)) 1120 1069 *ppEntry = pEntry; 1121 1070 else 1122 hgsmiGuestCompletionFIFOFree 1071 hgsmiGuestCompletionFIFOFree(pIns, pEntry); 1123 1072 } 1124 1073 return rc; … … 1158 1107 AssertRCBreak(rc); 1159 1108 1160 hgsmiHostFIFOFree(p Ins, pEntry);1109 hgsmiHostFIFOFree(pEntry); 1161 1110 } 1162 1111 } … … 1198 1147 uint32_t i; 1199 1148 for (i = 0; i < *pcBlocks; ++i) 1200 {1201 1149 SSMR3GetU32(pSSM, &paDescriptors[i]); 1202 }1203 1150 } 1204 1151 else 1205 {1206 1152 rc = VERR_NO_MEMORY; 1207 }1208 1153 } 1209 1154 1210 1155 if (RT_SUCCESS(rc)) 1211 {1212 1156 rc = SSMR3GetU32(pSSM, pcbMaxBlock); 1213 }1214 1215 1157 if (RT_SUCCESS(rc)) 1216 {1217 1158 *ppaDescriptors = paDescriptors; 1218 }1219 1159 else 1220 {1221 1160 RTMemFree(paDescriptors); 1222 } 1223 } 1224 1225 return rc; 1226 } 1227 1228 int HGSMIHostSaveStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM) 1161 } 1162 1163 return rc; 1164 } 1165 1166 int HGSMIHostSaveStateExec(PHGSMIINSTANCE pIns, PSSMHANDLE pSSM) 1229 1167 { 1230 1168 VBOXHGSMI_SAVE_START(pSSM); … … 1234 1172 SSMR3PutU32(pSSM, pIns->hostHeap.u32HeapType); 1235 1173 1236 HGSMIOFFSET off = pIns->pHGFlags ? HGSMIPointerToOffset(&pIns->area, (const HGSMIBUFFERHEADER *)pIns->pHGFlags) : HGSMIOFFSET_VOID; 1237 SSMR3PutU32 (pSSM, off); 1238 1239 off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA? 1240 0: 1241 hgsmiHostHeapHandleLocationOffset(&pIns->hostHeap); 1174 HGSMIOFFSET off = pIns->pHGFlags ? HGSMIPointerToOffset(&pIns->area, (const HGSMIBUFFERHEADER *)pIns->pHGFlags) 1175 : HGSMIOFFSET_VOID; 1176 SSMR3PutU32(pSSM, off); 1177 1178 off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA ? 0 : hgsmiHostHeapHandleLocationOffset(&pIns->hostHeap); 1242 1179 rc = SSMR3PutU32 (pSSM, off); 1243 1180 if (off != HGSMIOFFSET_VOID) 1244 1181 { 1245 SSMR3PutU32 1246 SSMR3PutU32 1182 SSMR3PutU32(pSSM, hgsmiHostHeapOffset(&pIns->hostHeap)); 1183 SSMR3PutU32(pSSM, hgsmiHostHeapSize(&pIns->hostHeap)); 1247 1184 /* need save mem pointer to calculate offset on restore */ 1248 SSMR3PutU64 1185 SSMR3PutU64(pSSM, (uint64_t)(uintptr_t)pIns->area.pu8Base); 1249 1186 rc = hgsmiFIFOLock (pIns); 1250 1187 if (RT_SUCCESS(rc)) 1251 1188 { 1252 rc = hgsmiHostSaveFifoLocked 1253 rc = hgsmiHostSaveFifoLocked 1254 rc = hgsmiHostSaveFifoLocked 1189 rc = hgsmiHostSaveFifoLocked(&pIns->hostFIFO, pSSM); AssertRC(rc); 1190 rc = hgsmiHostSaveFifoLocked(&pIns->hostFIFORead, pSSM); AssertRC(rc); 1191 rc = hgsmiHostSaveFifoLocked(&pIns->hostFIFOProcessed, pSSM); AssertRC(rc); 1255 1192 #ifdef VBOX_WITH_WDDM 1256 rc = hgsmiHostSaveGuestCmdCompletedFifoLocked 1193 rc = hgsmiHostSaveGuestCmdCompletedFifoLocked(&pIns->guestCmdCompleted, pSSM); AssertRC(rc); 1257 1194 #endif 1258 1195 1259 hgsmiFIFOUnlock 1196 hgsmiFIFOUnlock(pIns); 1260 1197 } 1261 1198 1262 1199 if (RT_SUCCESS(rc)) 1263 {1264 1200 if (pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA) 1265 {1266 1201 rc = hgsmiHostSaveMA(pSSM, &pIns->hostHeap.u.ma); 1267 }1268 }1269 1202 } 1270 1203 … … 1274 1207 } 1275 1208 1276 int HGSMIHostLoadStateExec 1209 int HGSMIHostLoadStateExec(PHGSMIINSTANCE pIns, PSSMHANDLE pSSM, uint32_t u32Version) 1277 1210 { 1278 1211 if (u32Version < VGA_SAVEDSTATE_VERSION_HGSMI) … … 1282 1215 1283 1216 int rc; 1284 HGSMIOFFSET off;1285 1217 uint32_t u32HeapType = HGSMI_HEAP_TYPE_NULL; 1286 1287 1218 if (u32Version >= VGA_SAVEDSTATE_VERSION_HGSMIMA) 1288 1219 { … … 1291 1222 } 1292 1223 1224 HGSMIOFFSET off; 1293 1225 rc = SSMR3GetU32(pSSM, &off); 1294 1226 AssertLogRelRCReturn(rc, rc); 1295 pIns->pHGFlags = (off != HGSMIOFFSET_VOID) ? (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer(&pIns->area, off) : NULL;1227 pIns->pHGFlags = off != HGSMIOFFSET_VOID ? (HGSMIHOSTFLAGS *)HGSMIOffsetToPointer(&pIns->area, off) : NULL; 1296 1228 1297 1229 rc = SSMR3GetU32(pSSM, &off); … … 1301 1233 /* There is a saved heap. */ 1302 1234 if (u32HeapType == HGSMI_HEAP_TYPE_NULL) 1303 { 1304 u32HeapType = u32Version > VGA_SAVEDSTATE_VERSION_HOST_HEAP? 1305 HGSMI_HEAP_TYPE_OFFSET: 1306 HGSMI_HEAP_TYPE_POINTER; 1307 } 1235 u32HeapType = u32Version > VGA_SAVEDSTATE_VERSION_HOST_HEAP 1236 ? HGSMI_HEAP_TYPE_OFFSET : HGSMI_HEAP_TYPE_POINTER; 1308 1237 1309 1238 HGSMIOFFSET offHeap; … … 1317 1246 if (RT_SUCCESS(rc)) 1318 1247 { 1319 rc = hgsmiFIFOLock 1248 rc = hgsmiFIFOLock(pIns); 1320 1249 if (RT_SUCCESS(rc)) 1321 1250 { 1322 rc = hgsmiHostLoadFifoLocked 1251 rc = hgsmiHostLoadFifoLocked(pIns, &pIns->hostFIFO, pSSM); 1323 1252 if (RT_SUCCESS(rc)) 1324 rc = hgsmiHostLoadFifoLocked 1253 rc = hgsmiHostLoadFifoLocked(pIns, &pIns->hostFIFORead, pSSM); 1325 1254 if (RT_SUCCESS(rc)) 1326 rc = hgsmiHostLoadFifoLocked 1255 rc = hgsmiHostLoadFifoLocked(pIns, &pIns->hostFIFOProcessed, pSSM); 1327 1256 #ifdef VBOX_WITH_WDDM 1328 1257 if (RT_SUCCESS(rc) && u32Version > VGA_SAVEDSTATE_VERSION_PRE_WDDM) 1329 rc = hgsmiHostLoadGuestCmdCompletedFifoLocked 1258 rc = hgsmiHostLoadGuestCmdCompletedFifoLocked(pIns, &pIns->guestCmdCompleted, pSSM, u32Version); 1330 1259 #endif 1331 1260 1332 hgsmiFIFOUnlock 1261 hgsmiFIFOUnlock(pIns); 1333 1262 } 1334 1263 } … … 1359 1288 || u32HeapType == HGSMI_HEAP_TYPE_POINTER) 1360 1289 { 1361 rc = hgsmiHostHeapLock 1362 if (RT_SUCCESS 1290 rc = hgsmiHostHeapLock(pIns); 1291 if (RT_SUCCESS(rc)) 1363 1292 { 1364 1293 Assert(!pIns->hostHeap.cRefs); … … 1373 1302 offHeap); 1374 1303 1375 hgsmiHostHeapUnlock 1304 hgsmiHostHeapUnlock(pIns); 1376 1305 } 1377 1306 } … … 1390 1319 /* Register a new HGSMI channel by a predefined index. 1391 1320 */ 1392 int HGSMIHostChannelRegister(PHGSMIINSTANCE pIns, 1393 uint8_t u8Channel, 1394 PFNHGSMICHANNELHANDLER pfnChannelHandler, 1395 void *pvChannelHandler) 1321 int HGSMIHostChannelRegister(PHGSMIINSTANCE pIns, uint8_t u8Channel, 1322 PFNHGSMICHANNELHANDLER pfnChannelHandler, void *pvChannelHandler) 1396 1323 { 1397 1324 LogFlowFunc(("pIns %p, u8Channel %x, pfnChannelHandler %p, pvChannelHandler %p\n", … … 1412 1339 1413 1340 LogFlowFunc(("leave rc = %Rrc\n", rc)); 1414 1415 1341 return rc; 1416 1342 } … … 1483 1409 void RT_UNTRUSTED_VOLATILE_GUEST *HGSMIOffsetToPointerHost(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer) 1484 1410 { 1485 const HGSMIAREA *pArea = &pIns->area; 1486 1487 if ( offBuffer < pArea->offBase 1488 || offBuffer > pArea->offLast) 1489 { 1490 LogFunc(("offset 0x%x is outside the area [0x%x;0x%x]!!!\n", offBuffer, pArea->offBase, pArea->offLast)); 1491 return NULL; 1492 } 1493 1494 return HGSMIOffsetToPointer(pArea, offBuffer); 1411 const HGSMIAREA *pArea = &pIns->area; 1412 HGSMIOFFSET const offArea = offBuffer - pArea->offBase; 1413 ASSERT_GUEST_MSG_RETURN(offArea < pArea->cbArea, 1414 ("offBuffer=%#x; area %#x LB %#x\n", offBuffer, pArea->offBase, pArea->cbArea), 1415 NULL); 1416 return &pArea->pu8Base[offArea]; 1495 1417 } 1496 1418 … … 1498 1420 HGSMIOFFSET HGSMIPointerToOffsetHost(PHGSMIINSTANCE pIns, const void RT_UNTRUSTED_VOLATILE_GUEST *pv) 1499 1421 { 1500 const HGSMIAREA *pArea = &pIns->area; 1501 uintptr_t off = (uintptr_t)pv - (uintptr_t)pArea->pu8Base; 1502 if (off < pArea->cbArea) 1503 return pArea->offBase + (HGSMIOFFSET)off; 1504 1505 LogFunc(("pointer %p is outside the area %p LB %#x!!!\n", pv, pArea->pu8Base, pArea->cbArea)); 1506 return HGSMIOFFSET_VOID; 1422 const HGSMIAREA *pArea = &pIns->area; 1423 uintptr_t const offArea = (uintptr_t)pv - (uintptr_t)pArea->pu8Base; 1424 ASSERT_GUEST_MSG_RETURN(offArea < pArea->cbArea, 1425 ("pv=%p; area %#x LB %#x\n", pv, pArea->offBase, pArea->cbArea), 1426 HGSMIOFFSET_VOID); 1427 return pArea->offBase + (HGSMIOFFSET)offArea; 1507 1428 } 1508 1429 … … 1542 1463 1543 1464 1544 void *HGSMIContext 1465 void *HGSMIContext(PHGSMIINSTANCE pIns) 1545 1466 { 1546 1467 uint8_t *p = (uint8_t *)pIns; 1547 return p + sizeof 1468 return p + sizeof(HGSMIINSTANCE); 1548 1469 } 1549 1470 1550 1471 /* The guest submitted a buffer. */ 1551 static DECLCALLBACK(int) hgsmiChannelHandler 1552 1472 static DECLCALLBACK(int) hgsmiChannelHandler(void *pvHandler, uint16_t u16ChannelInfo, 1473 RT_UNTRUSTED_VOLATILE_GUEST void *pvBuffer, HGSMISIZE cbBuffer) 1553 1474 { 1554 1475 int rc = VINF_SUCCESS; … … 1563 1484 case HGSMI_CC_HOST_FLAGS_LOCATION: 1564 1485 { 1565 if (cbBuffer < sizeof (HGSMIBUFFERLOCATION)) 1566 { 1567 rc = VERR_INVALID_PARAMETER; 1568 break; 1569 } 1570 1571 HGSMIBUFFERLOCATION *pLoc = (HGSMIBUFFERLOCATION *)pvBuffer; 1572 if (pLoc->cbLocation != sizeof(HGSMIHOSTFLAGS)) 1573 { 1574 rc = VERR_INVALID_PARAMETER; 1575 break; 1576 } 1577 1578 pIns->pHGFlags = (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, pLoc->offLocation); 1579 } break; 1486 ASSERT_GUEST_RETURN(cbBuffer >= sizeof(HGSMIBUFFERLOCATION), VERR_INVALID_PARAMETER); 1487 HGSMIBUFFERLOCATION RT_UNTRUSTED_VOLATILE_GUEST *pLoc = (HGSMIBUFFERLOCATION RT_UNTRUSTED_VOLATILE_GUEST *)pvBuffer; 1488 HGSMIBUFFERLOCATION LocSafe; 1489 LocSafe.cbLocation = pLoc->cbLocation; 1490 LocSafe.offLocation = pLoc->offLocation; 1491 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE(); 1492 1493 ASSERT_GUEST_RETURN(LocSafe.cbLocation == sizeof(HGSMIHOSTFLAGS), VERR_INVALID_PARAMETER); 1494 RT_UNTRUSTED_VALIDATED_FENCE(); 1495 1496 pIns->pHGFlags = (HGSMIHOSTFLAGS RT_UNTRUSTED_VOLATILE_GUEST *)HGSMIOffsetToPointer(&pIns->area, pLoc->offLocation); 1497 break; 1498 } 1580 1499 1581 1500 default: … … 1588 1507 } 1589 1508 1590 int HGSMICreate 1591 1592 1593 1594 1595 1596 1597 1598 size_tcbContext)1509 int HGSMICreate(PHGSMIINSTANCE *ppIns, 1510 PVM pVM, 1511 const char *pszName, 1512 HGSMIOFFSET offBase, 1513 uint8_t *pu8MemBase, 1514 HGSMISIZE cbMem, 1515 PFNHGSMINOTIFYGUEST pfnNotifyGuest, 1516 void *pvNotifyGuest, 1517 size_t cbContext) 1599 1518 { 1600 1519 LogFlowFunc(("ppIns = %p, pVM = %p, pszName = [%s], offBase = 0x%08X, pu8MemBase = %p, cbMem = 0x%08X, " … … 1615 1534 AssertPtrReturn(pu8MemBase, VERR_INVALID_PARAMETER); 1616 1535 1617 int rc = VINF_SUCCESS; 1618 1619 PHGSMIINSTANCE pIns = (PHGSMIINSTANCE)RTMemAllocZ (sizeof (HGSMIINSTANCE) + cbContext); 1620 1621 if (!pIns) 1622 { 1536 int rc; 1537 PHGSMIINSTANCE pIns = (PHGSMIINSTANCE)RTMemAllocZ(sizeof (HGSMIINSTANCE) + cbContext); 1538 if (pIns) 1539 { 1540 rc = HGSMIAreaInitialize (&pIns->area, pu8MemBase, cbMem, offBase); 1541 if (RT_SUCCESS (rc)) 1542 rc = RTCritSectInit (&pIns->instanceCritSect); 1543 if (RT_SUCCESS (rc)) 1544 rc = RTCritSectInit (&pIns->hostHeapCritSect); 1545 if (RT_SUCCESS (rc)) 1546 rc = RTCritSectInit (&pIns->hostFIFOCritSect); 1547 if (RT_SUCCESS (rc)) 1548 { 1549 pIns->pVM = pVM; 1550 pIns->pszName = VALID_PTR(pszName) ? pszName : ""; 1551 1552 hgsmiHostHeapSetupUninitialized(&pIns->hostHeap); 1553 1554 pIns->pfnNotifyGuest = pfnNotifyGuest; 1555 pIns->pvNotifyGuest = pvNotifyGuest; 1556 1557 RTListInit(&pIns->hostFIFO); 1558 RTListInit(&pIns->hostFIFORead); 1559 RTListInit(&pIns->hostFIFOProcessed); 1560 RTListInit(&pIns->hostFIFOFree); 1561 RTListInit(&pIns->guestCmdCompleted); 1562 1563 rc = HGSMIHostChannelRegister(pIns, HGSMI_CH_HGSMI, hgsmiChannelHandler, pIns); 1564 } 1565 if (RT_SUCCESS (rc)) 1566 *ppIns = pIns; 1567 else 1568 HGSMIDestroy(pIns); 1569 } 1570 else 1623 1571 rc = VERR_NO_MEMORY; 1624 }1625 1626 if (RT_SUCCESS (rc))1627 {1628 rc = HGSMIAreaInitialize (&pIns->area, pu8MemBase, cbMem, offBase);1629 }1630 1631 if (RT_SUCCESS (rc))1632 {1633 rc = RTCritSectInit (&pIns->instanceCritSect);1634 }1635 1636 if (RT_SUCCESS (rc))1637 {1638 rc = RTCritSectInit (&pIns->hostHeapCritSect);1639 }1640 1641 if (RT_SUCCESS (rc))1642 {1643 rc = RTCritSectInit (&pIns->hostFIFOCritSect);1644 }1645 1646 if (RT_SUCCESS (rc))1647 {1648 pIns->pVM = pVM;1649 1650 pIns->pszName = VALID_PTR(pszName)? pszName: "";1651 1652 hgsmiHostHeapSetupUninitialized(&pIns->hostHeap);1653 1654 pIns->pfnNotifyGuest = pfnNotifyGuest;1655 pIns->pvNotifyGuest = pvNotifyGuest;1656 1657 RTListInit(&pIns->hostFIFO);1658 RTListInit(&pIns->hostFIFORead);1659 RTListInit(&pIns->hostFIFOProcessed);1660 RTListInit(&pIns->hostFIFOFree);1661 RTListInit(&pIns->guestCmdCompleted);1662 }1663 1664 rc = HGSMIHostChannelRegister (pIns,1665 HGSMI_CH_HGSMI,1666 hgsmiChannelHandler,1667 pIns);1668 1669 if (RT_SUCCESS (rc))1670 {1671 *ppIns = pIns;1672 }1673 else1674 {1675 HGSMIDestroy (pIns);1676 }1677 1572 1678 1573 LogFlowFunc(("leave rc = %Rrc, pIns = %p\n", rc, pIns)); 1679 1680 1574 return rc; 1681 1575 } … … 1707 1601 } 1708 1602 1709 void HGSMIDestroy 1603 void HGSMIDestroy(PHGSMIINSTANCE pIns) 1710 1604 { 1711 1605 LogFlowFunc(("pIns = %p\n", pIns)); … … 1714 1608 { 1715 1609 hgsmiHostHeapDestroy(&pIns->hostHeap); 1716 1717 if (RTCritSectIsInitialized (&pIns->hostHeapCritSect)) 1718 { 1719 RTCritSectDelete (&pIns->hostHeapCritSect); 1720 } 1721 1722 if (RTCritSectIsInitialized (&pIns->instanceCritSect)) 1723 { 1724 RTCritSectDelete (&pIns->instanceCritSect); 1725 } 1726 1727 if (RTCritSectIsInitialized (&pIns->hostFIFOCritSect)) 1728 { 1729 RTCritSectDelete (&pIns->hostFIFOCritSect); 1730 } 1731 1732 memset (pIns, 0, sizeof (HGSMIINSTANCE)); 1733 1734 RTMemFree (pIns); 1610 if (RTCritSectIsInitialized(&pIns->hostHeapCritSect)) 1611 RTCritSectDelete(&pIns->hostHeapCritSect); 1612 if (RTCritSectIsInitialized(&pIns->instanceCritSect)) 1613 RTCritSectDelete(&pIns->instanceCritSect); 1614 if (RTCritSectIsInitialized(&pIns->hostFIFOCritSect)) 1615 RTCritSectDelete(&pIns->hostFIFOCritSect); 1616 1617 memset(pIns, 0, sizeof (HGSMIINSTANCE)); 1618 RTMemFree(pIns); 1735 1619 } 1736 1620 … … 1740 1624 #ifdef VBOX_WITH_WDDM 1741 1625 1742 static int hgsmiGuestCommandComplete 1626 static int hgsmiGuestCommandComplete(HGSMIINSTANCE *pIns, HGSMIOFFSET offMem) 1743 1627 { 1744 1628 HGSMIGUESTCOMPLENTRY *pEntry = NULL; 1745 1629 1746 1630 AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER); 1747 int rc = hgsmiGuestCompletionFIFOAlloc 1631 int rc = hgsmiGuestCompletionFIFOAlloc(pIns, &pEntry); 1748 1632 AssertRC(rc); 1749 if (RT_SUCCESS 1633 if (RT_SUCCESS(rc)) 1750 1634 { 1751 1635 pEntry->offBuffer = offMem; … … 1753 1637 rc = hgsmiFIFOLock(pIns); 1754 1638 AssertRC(rc); 1755 if (RT_SUCCESS 1639 if (RT_SUCCESS(rc)) 1756 1640 { 1757 1641 RTListAppend(&pIns->guestCmdCompleted, &pEntry->nodeEntry); … … 1761 1645 } 1762 1646 else 1763 {1764 1647 hgsmiGuestCompletionFIFOFree(pIns, pEntry); 1765 }1766 1648 } 1767 1649 … … 1771 1653 int hgsmiCompleteGuestCommand(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer, bool fDoIrq) 1772 1654 { 1773 int rc = hgsmiGuestCommandComplete 1655 int rc = hgsmiGuestCommandComplete(pIns, offBuffer); 1774 1656 if (RT_SUCCESS (rc)) 1775 1657 { 1658 #ifdef DEBUG_misha 1659 Assert(fDoIrq); 1660 #endif 1776 1661 if (fDoIrq) 1777 1662 { … … 1779 1664 hgsmiNotifyGuest (pIns); 1780 1665 } 1781 #ifdef DEBUG_misha1782 else1783 {1784 Assert(0);1785 }1786 #endif1787 1666 } 1788 1667 return rc; … … 1792 1671 { 1793 1672 LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem)); 1794 1795 int rc = VINF_SUCCESS;1796 1673 1797 1674 HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_GUEST *pHeader = HGSMIBufferHeaderFromData(pvMem); 1798 1675 HGSMIOFFSET offBuffer = HGSMIPointerToOffset(&pIns->area, pHeader); 1799 1800 Assert(offBuffer != HGSMIOFFSET_VOID); 1801 if (offBuffer != HGSMIOFFSET_VOID) 1802 { 1803 rc = hgsmiCompleteGuestCommand(pIns, offBuffer, fDoIrq); 1804 AssertRC (rc); 1805 } 1806 else 1807 { 1808 LogRel(("invalid cmd offset \n")); 1809 rc = VERR_INVALID_PARAMETER; 1810 } 1676 ASSERT_GUEST_RETURN(offBuffer != HGSMIOFFSET_VOID, VERR_INVALID_PARAMETER); 1677 1678 int rc = hgsmiCompleteGuestCommand(pIns, offBuffer, fDoIrq); 1679 AssertRC(rc); 1811 1680 1812 1681 LogFlowFunc(("rc = %Rrc\n", rc)); 1813 1814 return rc; 1815 } 1816 #endif 1682 return rc; 1683 } 1684 1685 #endif /* VBOX_WITH_WDDM */ 1686
Note:
See TracChangeset
for help on using the changeset viewer.