Changeset 55342 in vbox
- Timestamp:
- Apr 20, 2015 2:19:53 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/HGSMI/HGSMI.h
r50542 r55342 6 6 7 7 /* 8 * Copyright (C) 2006-201 4Oracle Corporation8 * Copyright (C) 2006-2015 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 128 128 RT_C_DECLS_BEGIN 129 129 130 DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromPtr(void *pvBuffer) 131 { 132 return (HGSMIBUFFERHEADER *)pvBuffer; 133 } 134 135 DECLINLINE(uint8_t *) HGSMIBufferDataFromPtr(void *pvBuffer) 136 { 137 return (uint8_t *)pvBuffer + sizeof(HGSMIBUFFERHEADER); 138 } 139 140 DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTailFromPtr(void *pvBuffer, uint32_t u32DataSize) 141 { 142 return (HGSMIBUFFERTAIL *)(HGSMIBufferDataFromPtr(pvBuffer) + u32DataSize); 143 } 144 130 145 DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize (void) 131 146 { … … 185 200 return NULL; 186 201 } 187 188 HGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);189 202 190 203 uint32_t HGSMIChecksum (HGSMIOFFSET offBuffer, … … 291 304 } 292 305 293 int HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo, 294 uint8_t u8Channel, 295 const char *pszName, 296 PFNHGSMICHANNELHANDLER pfnChannelHandler, 297 void *pvChannelHandler, 298 HGSMICHANNELHANDLER *pOldHandler); 299 300 int HGSMIBufferProcess (HGSMIAREA *pArea, 301 HGSMICHANNELINFO * pChannelInfo, 302 HGSMIOFFSET offBuffer); 306 HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo, 307 uint8_t u8Channel); 308 309 int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo, 310 uint8_t u8Channel, 311 const char *pszName, 312 PFNHGSMICHANNELHANDLER pfnChannelHandler, 313 void *pvChannelHandler); 314 315 int HGSMIBufferProcess(HGSMIAREA *pArea, 316 HGSMICHANNELINFO *pChannelInfo, 317 HGSMIOFFSET offBuffer); 303 318 RT_C_DECLS_END 304 319 -
trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/xpdm/VBoxMPInternal.cpp
r53008 r55342 6 6 7 7 /* 8 * Copyright (C) 2011 Oracle Corporation8 * Copyright (C) 2011-2015 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 581 581 int VBoxVbvaChannelDisplayEnable(PVBOXMP_COMMON pCommon, int iDisplay, uint8_t u8Channel) 582 582 { 583 static HGSMICHANNELHANDLER s_OldHandler;584 585 583 LOGF_ENTER(); 586 584 … … 626 624 rc = HGSMIChannelRegister(&pCommon->hostCtx.channels, u8Channel, 627 625 "VGA Miniport HGSMI channel", VBoxVbvaChannelGenericHandlerCB, 628 pContexts , &s_OldHandler);626 pContexts); 629 627 } 630 628 -
trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp
r54594 r55342 5 5 6 6 /* 7 * Copyright (C) 2006-201 3Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 2691 2691 } 2692 2692 2693 static HGSMICHANNELHANDLER sOldChannelHandler;2694 2695 2693 int VBVAInit (PVGASTATE pVGAState) 2696 2694 { … … 2714 2712 HGSMI_CH_VBVA, 2715 2713 vbvaChannelHandler, 2716 pVGAState, 2717 &sOldChannelHandler); 2714 pVGAState); 2718 2715 if (RT_SUCCESS (rc)) 2719 2716 { -
trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
r53513 r55342 9 9 10 10 /* 11 * Copyright (C) 2006-201 2Oracle Corporation11 * Copyright (C) 2006-2015 Oracle Corporation 12 12 * 13 13 * This file is part of VirtualBox Open Source Edition (OSE), as … … 261 261 } 262 262 263 //static HGSMICHANNEL *hgsmiChannelFindById (PHGSMIINSTANCE pIns,264 // uint8_t u8Channel)265 //{266 // HGSMICHANNEL *pChannel = &pIns->Channels[u8Channel];267 //268 // if (pChannel->u8Flags & HGSMI_CH_F_REGISTERED)269 // {270 // return pChannel;271 // }272 //273 // return NULL;274 //}275 276 #if 0277 /* Verify that the given offBuffer points to a valid buffer, which is within the area.278 */279 static const HGSMIBUFFERHEADER *hgsmiVerifyBuffer (const HGSMIAREA *pArea,280 HGSMIOFFSET offBuffer)281 {282 AssertPtr(pArea);283 284 LogFlowFunc(("buffer 0x%x, area %p %x [0x%x;0x%x]\n", offBuffer, pArea->pu8Base, pArea->cbArea, pArea->offBase, pArea->offLast));285 286 if ( offBuffer < pArea->offBase287 || offBuffer > pArea->offLast)288 {289 LogFunc(("offset 0x%x is outside the area [0x%x;0x%x]!!!\n", offBuffer, pArea->offBase, pArea->offLast));290 HGSMI_STRICT_ASSERT_FAILED();291 return NULL;292 }293 294 const HGSMIBUFFERHEADER *pHeader = HGSMIOffsetToPointer (pArea, offBuffer);295 296 /* Quick check of the data size, it should be less than the maximum297 * data size for the buffer at this offset.298 */299 LogFlowFunc(("datasize check: pHeader->u32DataSize = 0x%x pArea->offLast - offBuffer = 0x%x\n", pHeader->u32DataSize, pArea->offLast - offBuffer));300 if (pHeader->u32DataSize <= pArea->offLast - offBuffer)301 {302 HGSMIBUFFERTAIL *pTail = HGSMIBufferTail (pHeader);303 304 /* At least both pHeader and pTail structures are in the area. Check the checksum. */305 uint32_t u32Checksum = HGSMIChecksum (offBuffer, pHeader, pTail);306 307 LogFlowFunc(("checksum check: u32Checksum = 0x%x pTail->u32Checksum = 0x%x\n", u32Checksum, pTail->u32Checksum));308 if (u32Checksum == pTail->u32Checksum)309 {310 LogFlowFunc(("returning %p\n", pHeader));311 return pHeader;312 }313 else314 {315 LogFunc(("invalid checksum 0x%x, expected 0x%x!!!\n", u32Checksum, pTail->u32Checksum));316 }317 }318 else319 {320 LogFunc(("invalid data size 0x%x, maximum is 0x%x!!!\n", pHeader->u32DataSize, pArea->offLast - offBuffer));321 }322 323 LogFlowFunc(("returning NULL\n"));324 HGSMI_STRICT_ASSERT_FAILED();325 return NULL;326 }327 328 /*329 * Process a guest buffer.330 * @thread EMT331 */332 static int hgsmiGuestBufferProcess (HGSMIINSTANCE *pIns,333 const HGSMICHANNEL *pChannel,334 const HGSMIBUFFERHEADER *pHeader)335 {336 LogFlowFunc(("pIns %p, pChannel %p, pHeader %p\n", pIns, pChannel, pHeader));337 338 int rc = HGSMIChannelHandlerCall (pIns,339 &pChannel->handler,340 pHeader);341 342 return rc;343 }344 #endif345 263 /* 346 264 * Virtual hardware IO handlers. … … 572 490 #endif 573 491 574 #if 0575 DECLINLINE(HGSMIOFFSET) hgsmiMemoryOffset (const HGSMIINSTANCE *pIns, const void *pv)576 {577 Assert((uint8_t *)pv >= pIns->area.pu8Base);578 Assert((uint8_t *)pv < pIns->area.pu8Base + pIns->area.cbArea);579 return (HGSMIOFFSET)((uint8_t *)pv - pIns->area.pu8Base);580 }581 #endif582 492 /* 583 493 * The host heap. … … 598 508 AssertRC (rc); 599 509 } 600 601 #if 0602 static int hgsmiHostHeapAlloc (HGSMIINSTANCE *pIns, void **ppvMem, uint32_t cb)603 {604 int rc = hgsmiHostHeapLock (pIns);605 606 if (RT_SUCCESS (rc))607 {608 if (pIns->hostHeap == NIL_RTHEAPSIMPLE)609 {610 rc = VERR_NOT_SUPPORTED;611 }612 else613 {614 /* A block structure: [header][data][tail].615 * 'header' and 'tail' is used to verify memory blocks.616 */617 uint32_t cbAlloc = HGSMIBufferRequiredSize (cb);618 619 void *pv = RTHeapSimpleAlloc (pIns->hostHeap, cbAlloc, 0);620 621 if (pv)622 {623 HGSMIBUFFERHEADER *pHdr = (HGSMIBUFFERHEADER *)pv;624 625 /* Store some information which will help to verify memory pointers. */626 pHdr->u32Signature = HGSMI_MEM_SIGNATURE;627 pHdr->cb = cb;628 pHdr->off = hgsmiMemoryOffset (pIns, pv);629 pHdr->u32HdrVerifyer = HGSMI_MEM_VERIFYER_HDR (pHdr);630 631 /* Setup the tail. */632 HGSMIBUFFERTAIL *pTail = HGSMIBufferTail (pHdr);633 634 pTail->u32TailVerifyer = HGSMI_MEM_VERIFYER_TAIL (pHdr);635 636 *ppvMem = pv;637 }638 else639 {640 rc = VERR_NO_MEMORY;641 }642 }643 644 hgsmiHostHeapUnlock (pIns);645 }646 647 return rc;648 }649 650 651 static int hgsmiHostHeapCheckBlock (HGSMIINSTANCE *pIns, void *pvMem)652 {653 int rc = hgsmiHostHeapLock (pIns);654 655 if (RT_SUCCESS (rc))656 {657 rc = hgsmiVerifyBuffer (pIns, pvMem);658 659 hgsmiHostHeapUnlock (pIns);660 }661 662 return rc;663 }664 665 static int hgsmiHostHeapFree (HGSMIINSTANCE *pIns, void *pvMem)666 {667 int rc = hgsmiHostHeapLock (pIns);668 669 if (RT_SUCCESS (rc))670 {671 RTHeapSimpleFree (pIns->hostHeap, pvMem);672 673 hgsmiHostHeapUnlock (pIns);674 }675 676 return rc;677 }678 679 static int hgsmiCheckMemPtr (HGSMIINSTANCE *pIns, void *pvMem, HGSMIOFFSET *poffMem)680 {681 int rc = hgsmiHostHeapCheckBlock (pIns, pvMem);682 683 if (RT_SUCCESS (rc))684 {685 *poffMem = hgsmiMemoryOffset (pIns, pvMem);686 }687 688 return rc;689 }690 #endif691 510 692 511 static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry) … … 1545 1364 /* Register a new HGSMI channel by a predefined index. 1546 1365 */ 1547 int HGSMIHostChannelRegister (PHGSMIINSTANCE pIns, 1548 uint8_t u8Channel, 1549 PFNHGSMICHANNELHANDLER pfnChannelHandler, 1550 void *pvChannelHandler, 1551 HGSMICHANNELHANDLER *pOldHandler) 1552 { 1553 LogFlowFunc(("pIns %p, u8Channel %x, pfnChannelHandler %p, pvChannelHandler %p, pOldHandler %p\n", 1554 pIns, u8Channel, pfnChannelHandler, pvChannelHandler, pOldHandler)); 1366 int HGSMIHostChannelRegister(PHGSMIINSTANCE pIns, 1367 uint8_t u8Channel, 1368 PFNHGSMICHANNELHANDLER pfnChannelHandler, 1369 void *pvChannelHandler) 1370 { 1371 LogFlowFunc(("pIns %p, u8Channel %x, pfnChannelHandler %p, pvChannelHandler %p\n", 1372 pIns, u8Channel, pfnChannelHandler, pvChannelHandler)); 1555 1373 1556 1374 AssertReturn(!HGSMI_IS_DYNAMIC_CHANNEL(u8Channel), VERR_INVALID_PARAMETER); … … 1562 1380 if (RT_SUCCESS (rc)) 1563 1381 { 1564 rc = HGSMIChannelRegister (&pIns->channelInfo, u8Channel, NULL, pfnChannelHandler, pvChannelHandler , pOldHandler);1382 rc = HGSMIChannelRegister (&pIns->channelInfo, u8Channel, NULL, pfnChannelHandler, pvChannelHandler); 1565 1383 1566 1384 hgsmiUnlock (pIns); … … 1578 1396 PFNHGSMICHANNELHANDLER pfnChannelHandler, 1579 1397 void *pvChannelHandler, 1580 uint8_t *pu8Channel, 1581 HGSMICHANNELHANDLER *pOldHandler) 1582 { 1583 LogFlowFunc(("pIns %p, pszChannel %s, pfnChannelHandler %p, pvChannelHandler %p, pu8Channel %p, pOldHandler %p\n", 1584 pIns, pszChannel, pfnChannelHandler, pvChannelHandler, pu8Channel, pOldHandler)); 1398 uint8_t *pu8Channel) 1399 { 1400 LogFlowFunc(("pIns %p, pszChannel %s, pfnChannelHandler %p, pvChannelHandler %p, pu8Channel %p\n", 1401 pIns, pszChannel, pfnChannelHandler, pvChannelHandler, pu8Channel)); 1585 1402 1586 1403 AssertPtrReturn(pIns, VERR_INVALID_PARAMETER); … … 1604 1421 if (RT_SUCCESS (rc)) 1605 1422 { 1606 rc = HGSMIChannelRegister (&pIns->channelInfo, *pu8Channel, pszName, pfnChannelHandler, pvChannelHandler , pOldHandler);1423 rc = HGSMIChannelRegister (&pIns->channelInfo, *pu8Channel, pszName, pfnChannelHandler, pvChannelHandler); 1607 1424 } 1608 1425 … … 1624 1441 return rc; 1625 1442 } 1626 1627 #if 01628 /* A wrapper to safely call the handler.1629 */1630 int HGSMIChannelHandlerCall (PHGSMIINSTANCE pIns,1631 const HGSMICHANNELHANDLER *pHandler,1632 const HGSMIBUFFERHEADER *pHeader)1633 {1634 LogFlowFunc(("pHandler %p, pIns %p, pHeader %p\n", pHandler, pIns, pHeader));1635 1636 int rc;1637 1638 if ( pHandler1639 && pHandler->pfnHandler)1640 {1641 void *pvBuffer = HGSMIBufferData (pHeader);1642 HGSMISIZE cbBuffer = pHeader->u32DataSize;1643 1644 rc = pHandler->pfnHandler (pIns, pHandler->pvHandler, pHeader->u16ChannelInfo, pvBuffer, cbBuffer);1645 }1646 else1647 {1648 /* It is a NOOP case here. */1649 rc = VINF_SUCCESS;1650 }1651 1652 LogFlowFunc(("leave rc = %Rrc\n", rc));1653 1654 return rc;1655 }1656 1657 #endif1658 1443 1659 1444 void *HGSMIOffsetToPointerHost (PHGSMIINSTANCE pIns, … … 1737 1522 return rc; 1738 1523 } 1739 1740 static HGSMICHANNELHANDLER sOldChannelHandler;1741 1524 1742 1525 int HGSMICreate (PHGSMIINSTANCE *ppIns, … … 1816 1599 HGSMI_CH_HGSMI, 1817 1600 hgsmiChannelHandler, 1818 pIns, 1819 &sOldChannelHandler); 1601 pIns); 1820 1602 1821 1603 if (RT_SUCCESS (rc)) -
trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h
r50550 r55342 6 6 7 7 /* 8 * Copyright (C) 2006-201 0Oracle Corporation8 * Copyright (C) 2006-2015 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 60 60 uint8_t u8Channel, 61 61 PFNHGSMICHANNELHANDLER pfnChannelHandler, 62 void *pvChannelHandler, 63 HGSMICHANNELHANDLER *pOldHandler); 62 void *pvChannelHandler); 64 63 65 64 int HGSMIChannelRegisterName (PHGSMIINSTANCE pIns, … … 67 66 PFNHGSMICHANNELHANDLER pfnChannelHandler, 68 67 void *pvChannelHandler, 69 uint8_t *pu8Channel, 70 HGSMICHANNELHANDLER *pOldHandler); 71 72 int HGSMIChannelHandlerCall (PHGSMIINSTANCE pIns, 73 const HGSMICHANNELHANDLER *pHandler, 74 const HGSMIBUFFERHEADER *pHeader); 75 68 uint8_t *pu8Channel); 76 69 77 70 int HGSMISetupHostHeap (PHGSMIINSTANCE pIns, -
trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp
r50518 r55342 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 413 413 } 414 414 415 typedef struct HGSMIBUFFERCONTEXT 416 { 417 const HGSMIBUFFERHEADER *pHeader; /* The original buffer header. */ 418 void *pvData; /* Payload data in the buffer./ */ 419 uint32_t cbData; /* Size of data */ 420 } HGSMIBUFFERCONTEXT; 421 415 422 /* Verify that the given offBuffer points to a valid buffer, which is within the area. 416 423 */ 417 static const HGSMIBUFFERHEADER *hgsmiVerifyBuffer (const HGSMIAREA *pArea, 418 HGSMIOFFSET offBuffer) 419 { 420 AssertPtr(pArea); 421 422 LogFlowFunc(("buffer 0x%x, area %p %x [0x%x;0x%x]\n", offBuffer, pArea->pu8Base, pArea->cbArea, pArea->offBase, pArea->offLast)); 424 static int hgsmiVerifyBuffer(const HGSMIAREA *pArea, 425 HGSMIOFFSET offBuffer, 426 HGSMIBUFFERCONTEXT *pBufferContext) 427 { 428 LogFlowFunc(("buffer 0x%x, area %p %x [0x%x;0x%x]\n", 429 offBuffer, pArea->pu8Base, pArea->cbArea, pArea->offBase, pArea->offLast)); 430 431 int rc = VINF_SUCCESS; 423 432 424 433 if ( offBuffer < pArea->offBase 425 434 || offBuffer > pArea->offLast) 426 435 { 427 LogFunc(("offset 0x%x is outside the area [0x%x;0x%x]!!!\n", offBuffer, pArea->offBase, pArea->offLast)); 436 LogFunc(("offset 0x%x is outside the area [0x%x;0x%x]!!!\n", 437 offBuffer, pArea->offBase, pArea->offLast)); 438 rc = VERR_INVALID_PARAMETER; 428 439 HGSMI_STRICT_ASSERT_FAILED(); 429 return NULL; 430 } 431 432 const HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer (pArea, offBuffer); 433 434 /* Quick check of the data size, it should be less than the maximum 435 * data size for the buffer at this offset. 436 */ 437 LogFlowFunc(("datasize check: pHeader->u32DataSize = 0x%x pArea->offLast - offBuffer = 0x%x\n", pHeader->u32DataSize, pArea->offLast - offBuffer)); 438 if (pHeader->u32DataSize <= pArea->offLast - offBuffer) 439 { 440 HGSMIBUFFERTAIL *pTail = HGSMIBufferTail (pHeader); 441 442 /* At least both pHeader and pTail structures are in the area. Check the checksum. */ 443 uint32_t u32Checksum = HGSMIChecksum (offBuffer, pHeader, pTail); 444 445 LogFlowFunc(("checksum check: u32Checksum = 0x%x pTail->u32Checksum = 0x%x\n", u32Checksum, pTail->u32Checksum)); 446 if (u32Checksum == pTail->u32Checksum) 447 { 448 LogFlowFunc(("returning %p\n", pHeader)); 449 return pHeader; 440 } 441 else 442 { 443 void *pvBuffer = HGSMIOffsetToPointer(pArea, offBuffer); 444 HGSMIBUFFERHEADER header = *HGSMIBufferHeaderFromPtr(pvBuffer); 445 446 /* Quick check of the data size, it should be less than the maximum 447 * data size for the buffer at this offset. 448 */ 449 LogFlowFunc(("datasize check: header.u32DataSize = 0x%x pArea->offLast - offBuffer = 0x%x\n", 450 header.u32DataSize, pArea->offLast - offBuffer)); 451 452 if (header.u32DataSize <= pArea->offLast - offBuffer) 453 { 454 HGSMIBUFFERTAIL tail = *HGSMIBufferTailFromPtr(pvBuffer, header.u32DataSize); 455 456 /* At least both header and tail structures are in the area. Check the checksum. */ 457 uint32_t u32Checksum = HGSMIChecksum(offBuffer, &header, &tail); 458 LogFlowFunc(("checksum check: u32Checksum = 0x%x pTail->u32Checksum = 0x%x\n", 459 u32Checksum, pTail->u32Checksum)); 460 if (u32Checksum == tail.u32Checksum) 461 { 462 /* Success. */ 463 pBufferContext->pHeader = HGSMIBufferHeaderFromPtr(pvBuffer); 464 pBufferContext->pvData = HGSMIBufferDataFromPtr(pvBuffer); 465 pBufferContext->cbData = header.u32DataSize; 466 } 467 else 468 { 469 LogFunc(("invalid checksum 0x%x, expected 0x%x!!!\n", 470 u32Checksum, pTail->u32Checksum)); 471 rc = VERR_INVALID_STATE; 472 HGSMI_STRICT_ASSERT_FAILED(); 473 } 450 474 } 451 475 else 452 476 { 453 LogFunc(("invalid checksum 0x%x, expected 0x%x!!!\n", u32Checksum, pTail->u32Checksum)); 477 LogFunc(("invalid data size 0x%x, maximum is 0x%x!!!\n", 478 header.u32DataSize, pArea->offLast - offBuffer)); 479 rc = VERR_TOO_MUCH_DATA; 454 480 HGSMI_STRICT_ASSERT_FAILED(); 455 481 } 456 482 } 457 else 458 { 459 LogFunc(("invalid data size 0x%x, maximum is 0x%x!!!\n", pHeader->u32DataSize, pArea->offLast - offBuffer)); 460 HGSMI_STRICT_ASSERT_FAILED(); 461 } 462 463 LogFlowFunc(("returning NULL\n")); 464 return NULL; 483 484 return rc; 465 485 } 466 486 467 487 /* A wrapper to safely call the handler. 468 488 */ 469 int HGSMIChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,470 const HGSMIBUFFERHEADER *pHeader)471 { 472 LogFlowFunc(("pHandler %p , pHeader %p\n", pHandler, pHeader));489 static int hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler, 490 const HGSMIBUFFERCONTEXT *pBufferContext) 491 { 492 LogFlowFunc(("pHandler %p\n", pHandler)); 473 493 474 494 int rc; 475 476 Assert(pHandler && pHandler->pfnHandler);477 495 478 496 if ( pHandler 479 497 && pHandler->pfnHandler) 480 498 { 481 void *pvBuffer = HGSMIBufferData (pHeader); 482 HGSMISIZE cbBuffer = pHeader->u32DataSize; 483 484 rc = pHandler->pfnHandler (pHandler->pvHandler, pHeader->u16ChannelInfo, pvBuffer, cbBuffer); 499 rc = pHandler->pfnHandler(pHandler->pvHandler, pBufferContext->pHeader->u16ChannelInfo, 500 pBufferContext->pvData, pBufferContext->cbData); 485 501 } 486 502 else … … 491 507 492 508 LogFlowFunc(("leave rc = %Rrc\n", rc)); 493 494 509 return rc; 495 510 } 496 511 497 /* 498 * Process a guest buffer. 499 * @thread EMT 500 */ 501 static int hgsmiBufferProcess (const HGSMICHANNEL *pChannel, 502 const HGSMIBUFFERHEADER *pHeader) 503 { 504 LogFlowFunc(("pChannel %p, pHeader %p\n", pChannel, pHeader)); 505 506 int rc = HGSMIChannelHandlerCall (&pChannel->handler, 507 pHeader); 508 509 return rc; 510 } 511 512 HGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, 513 uint8_t u8Channel) 514 { 512 /** Helper to convert HGSMI channel index to the channel structure pointer. 513 * 514 * @returns Pointer to the channel data. 515 * @param pChannelInfo The channel pool. 516 * @param u8Channel The channel index. 517 */ 518 HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo, 519 uint8_t u8Channel) 520 { 521 AssertCompile(RT_ELEMENTS(pChannelInfo->Channels) >= 0x100); 515 522 HGSMICHANNEL *pChannel = &pChannelInfo->Channels[u8Channel]; 516 523 … … 523 530 } 524 531 525 int HGSMIBufferProcess (HGSMIAREA *pArea, 526 HGSMICHANNELINFO * pChannelInfo, 527 HGSMIOFFSET offBuffer) 532 /** Process a guest buffer. 533 * 534 * @returns VBox status. 535 * @param pArea Area which supposed to contain the buffer. 536 * @param pChannelInfo The channel pool. 537 * @param offBuffer The buffer location in the area. 538 */ 539 int HGSMIBufferProcess(HGSMIAREA *pArea, 540 HGSMICHANNELINFO *pChannelInfo, 541 HGSMIOFFSET offBuffer) 528 542 { 529 543 LogFlowFunc(("pArea %p, offBuffer 0x%x\n", pArea, offBuffer)); 530 544 531 AssertPtr(pArea); 532 AssertPtr(pChannelInfo); 533 534 int rc = VERR_GENERAL_FAILURE; 535 536 // VM_ASSERT_EMT(pIns->pVM); 545 AssertPtrReturn(pArea, VERR_INVALID_PARAMETER); 546 AssertPtrReturn(pChannelInfo, VERR_INVALID_PARAMETER); 537 547 538 548 /* Guest has prepared a command description at 'offBuffer'. */ 539 const HGSMIBUFFERHEADER *pHeader = hgsmiVerifyBuffer (pArea, offBuffer);540 Assert(pHeader);541 if ( pHeader)549 HGSMIBUFFERCONTEXT bufferContext; 550 int rc = hgsmiVerifyBuffer(pArea, offBuffer, &bufferContext); 551 if (RT_SUCCESS(rc)) 542 552 { 543 553 /* Pass the command to the appropriate handler registered with this instance. 544 554 * Start with the handler list head, which is the preallocated HGSMI setup channel. 545 555 */ 546 HGSMICHANNEL *pChannel = HGSMIChannelFindById (pChannelInfo, pHeader->u8Channel); 547 Assert(pChannel); 556 HGSMICHANNEL *pChannel = HGSMIChannelFindById(pChannelInfo, bufferContext.pHeader->u8Channel); 548 557 if (pChannel) 549 558 { 550 hgsmiBufferProcess (pChannel, pHeader); 551 HGSMI_STRICT_ASSERT(hgsmiVerifyBuffer (pArea, offBuffer) != NULL); 552 rc = VINF_SUCCESS; 559 rc = hgsmiChannelHandlerCall(&pChannel->handler, &bufferContext); 560 HGSMI_STRICT_ASSERT(RT_SUCCESS(hgsmiVerifyBuffer(pArea, offBuffer, &bufferContext))); 553 561 } 554 562 else 555 563 { 556 564 rc = VERR_INVALID_FUNCTION; 557 } 558 } 559 else 560 { 561 rc = VERR_INVALID_HANDLE; 562 // LogRel(("HGSMI[%s]: ignored invalid guest buffer 0x%08X!!!\n", pIns->pszName, offBuffer)); 563 } 565 HGSMI_STRICT_ASSERT_FAILED(); 566 } 567 } 568 564 569 return rc; 565 570 } 566 571 567 /* Register a new VBVAchannel by index.572 /** Register a new HGSMI channel by index. 568 573 * 569 */ 570 int HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo, 571 uint8_t u8Channel, 572 const char *pszName, 573 PFNHGSMICHANNELHANDLER pfnChannelHandler, 574 void *pvChannelHandler, 575 HGSMICHANNELHANDLER *pOldHandler) 576 { 577 AssertPtrReturn(pOldHandler, VERR_INVALID_PARAMETER); 578 574 * @returns VBox status. 575 * @param pChannelInfo The channel pool managed by the caller. 576 * @param u8Channel Index of the channel. 577 * @param pszName Name of the channel (optional, allocated by the caller). 578 * @param pfnChannelHandler The channel callback. 579 * @param pvChannelHandler The callback pointer. 580 */ 581 int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo, 582 uint8_t u8Channel, 583 const char *pszName, 584 PFNHGSMICHANNELHANDLER pfnChannelHandler, 585 void *pvChannelHandler) 586 { 579 587 /* Check whether the channel is already registered. */ 580 HGSMICHANNEL *pChannel = HGSMIChannelFindById (pChannelInfo, u8Channel); 581 582 if (!pChannel) 583 { 584 /* Channel is not yet registered. */ 585 pChannel = &pChannelInfo->Channels[u8Channel]; 586 587 pChannel->u8Flags = HGSMI_CH_F_REGISTERED; 588 pChannel->u8Channel = u8Channel; 589 590 pChannel->handler.pfnHandler = NULL; 591 pChannel->handler.pvHandler = NULL; 592 593 pChannel->pszName = pszName; 594 } 595 596 *pOldHandler = pChannel->handler; 588 HGSMICHANNEL *pChannel = HGSMIChannelFindById(pChannelInfo, u8Channel); 589 if (pChannel) 590 { 591 HGSMI_STRICT_ASSERT_FAILED(); 592 return VERR_ALREADY_EXISTS; 593 } 594 595 /* Channel is not yet registered. */ 596 pChannel = &pChannelInfo->Channels[u8Channel]; 597 598 pChannel->u8Flags = HGSMI_CH_F_REGISTERED; 599 pChannel->u8Channel = u8Channel; 597 600 598 601 pChannel->handler.pfnHandler = pfnChannelHandler; 599 602 pChannel->handler.pvHandler = pvChannelHandler; 600 603 604 pChannel->pszName = pszName; 605 601 606 return VINF_SUCCESS; 602 607 } 603
Note:
See TracChangeset
for help on using the changeset viewer.