VirtualBox

Changeset 55342 in vbox


Ignore:
Timestamp:
Apr 20, 2015 2:19:53 PM (10 years ago)
Author:
vboxsync
Message:

HGSMI: cleanup, comments.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HGSMI/HGSMI.h

    r50542 r55342  
    66
    77/*
    8  * Copyright (C) 2006-2014 Oracle Corporation
     8 * Copyright (C) 2006-2015 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    128128RT_C_DECLS_BEGIN
    129129
     130DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromPtr(void *pvBuffer)
     131{
     132    return (HGSMIBUFFERHEADER *)pvBuffer;
     133}
     134
     135DECLINLINE(uint8_t *) HGSMIBufferDataFromPtr(void *pvBuffer)
     136{
     137    return (uint8_t *)pvBuffer + sizeof(HGSMIBUFFERHEADER);
     138}
     139
     140DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTailFromPtr(void *pvBuffer, uint32_t u32DataSize)
     141{
     142    return (HGSMIBUFFERTAIL *)(HGSMIBufferDataFromPtr(pvBuffer) + u32DataSize);
     143}
     144
    130145DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize (void)
    131146{
     
    185200    return NULL;
    186201}
    187 
    188 HGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);
    189202
    190203uint32_t HGSMIChecksum (HGSMIOFFSET offBuffer,
     
    291304}
    292305
    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);
     306HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo,
     307                                   uint8_t u8Channel);
     308
     309int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo,
     310                         uint8_t u8Channel,
     311                         const char *pszName,
     312                         PFNHGSMICHANNELHANDLER pfnChannelHandler,
     313                         void *pvChannelHandler);
     314
     315int HGSMIBufferProcess(HGSMIAREA *pArea,
     316                       HGSMICHANNELINFO *pChannelInfo,
     317                       HGSMIOFFSET offBuffer);
    303318RT_C_DECLS_END
    304319
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/xpdm/VBoxMPInternal.cpp

    r53008 r55342  
    66
    77/*
    8  * Copyright (C) 2011 Oracle Corporation
     8 * Copyright (C) 2011-2015 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    581581int VBoxVbvaChannelDisplayEnable(PVBOXMP_COMMON pCommon, int iDisplay, uint8_t u8Channel)
    582582{
    583     static HGSMICHANNELHANDLER s_OldHandler;
    584 
    585583    LOGF_ENTER();
    586584
     
    626624            rc = HGSMIChannelRegister(&pCommon->hostCtx.channels, u8Channel,
    627625                                       "VGA Miniport HGSMI channel", VBoxVbvaChannelGenericHandlerCB,
    628                                        pContexts, &s_OldHandler);
     626                                       pContexts);
    629627        }
    630628
  • trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp

    r54594 r55342  
    55
    66/*
    7  * Copyright (C) 2006-2013 Oracle Corporation
     7 * Copyright (C) 2006-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    26912691}
    26922692
    2693 static HGSMICHANNELHANDLER sOldChannelHandler;
    2694 
    26952693int VBVAInit (PVGASTATE pVGAState)
    26962694{
     
    27142712                                    HGSMI_CH_VBVA,
    27152713                                    vbvaChannelHandler,
    2716                                     pVGAState,
    2717                                     &sOldChannelHandler);
     2714                                    pVGAState);
    27182715         if (RT_SUCCESS (rc))
    27192716         {
  • trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp

    r53513 r55342  
    99
    1010/*
    11  * Copyright (C) 2006-2012 Oracle Corporation
     11 * Copyright (C) 2006-2015 Oracle Corporation
    1212 *
    1313 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    261261}
    262262
    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 0
    277 /* 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->offBase
    287         || 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 maximum
    297      * 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         else
    314         {
    315             LogFunc(("invalid checksum 0x%x, expected 0x%x!!!\n", u32Checksum, pTail->u32Checksum));
    316         }
    317     }
    318     else
    319     {
    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 EMT
    331  */
    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 #endif
    345263/*
    346264 * Virtual hardware IO handlers.
     
    572490#endif
    573491
    574 #if 0
    575 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 #endif
    582492/*
    583493 * The host heap.
     
    598508    AssertRC (rc);
    599509}
    600 
    601 #if 0
    602 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         else
    613         {
    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             else
    639             {
    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 #endif
    691510
    692511static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry)
     
    15451364/* Register a new HGSMI channel by a predefined index.
    15461365 */
    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));
     1366int 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));
    15551373
    15561374    AssertReturn(!HGSMI_IS_DYNAMIC_CHANNEL(u8Channel), VERR_INVALID_PARAMETER);
     
    15621380    if (RT_SUCCESS (rc))
    15631381    {
    1564         rc = HGSMIChannelRegister (&pIns->channelInfo, u8Channel, NULL, pfnChannelHandler, pvChannelHandler, pOldHandler);
     1382        rc = HGSMIChannelRegister (&pIns->channelInfo, u8Channel, NULL, pfnChannelHandler, pvChannelHandler);
    15651383
    15661384        hgsmiUnlock (pIns);
     
    15781396                              PFNHGSMICHANNELHANDLER pfnChannelHandler,
    15791397                              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));
    15851402
    15861403    AssertPtrReturn(pIns, VERR_INVALID_PARAMETER);
     
    16041421            if (RT_SUCCESS (rc))
    16051422            {
    1606                 rc = HGSMIChannelRegister (&pIns->channelInfo, *pu8Channel, pszName, pfnChannelHandler, pvChannelHandler, pOldHandler);
     1423                rc = HGSMIChannelRegister (&pIns->channelInfo, *pu8Channel, pszName, pfnChannelHandler, pvChannelHandler);
    16071424            }
    16081425
     
    16241441    return rc;
    16251442}
    1626 
    1627 #if 0
    1628 /* 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 (   pHandler
    1639         && 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     else
    1647     {
    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 #endif
    16581443
    16591444void *HGSMIOffsetToPointerHost (PHGSMIINSTANCE pIns,
     
    17371522    return rc;
    17381523}
    1739 
    1740 static HGSMICHANNELHANDLER sOldChannelHandler;
    17411524
    17421525int HGSMICreate (PHGSMIINSTANCE *ppIns,
     
    18161599                                   HGSMI_CH_HGSMI,
    18171600                                   hgsmiChannelHandler,
    1818                                    pIns,
    1819                                    &sOldChannelHandler);
     1601                                   pIns);
    18201602
    18211603    if (RT_SUCCESS (rc))
  • trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h

    r50550 r55342  
    66
    77/*
    8  * Copyright (C) 2006-2010 Oracle Corporation
     8 * Copyright (C) 2006-2015 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6060                          uint8_t u8Channel,
    6161                          PFNHGSMICHANNELHANDLER pfnChannelHandler,
    62                           void *pvChannelHandler,
    63                           HGSMICHANNELHANDLER *pOldHandler);
     62                          void *pvChannelHandler);
    6463
    6564int HGSMIChannelRegisterName (PHGSMIINSTANCE pIns,
     
    6766                              PFNHGSMICHANNELHANDLER pfnChannelHandler,
    6867                              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);
    7669
    7770int HGSMISetupHostHeap (PHGSMIINSTANCE pIns,
  • trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp

    r50518 r55342  
    55
    66/*
    7  * Copyright (C) 2006-2014 Oracle Corporation
     7 * Copyright (C) 2006-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    413413}
    414414
     415typedef 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
    415422/* Verify that the given offBuffer points to a valid buffer, which is within the area.
    416423 */
    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));
     424static 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;
    423432
    424433    if (   offBuffer < pArea->offBase
    425434        || offBuffer > pArea->offLast)
    426435    {
    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;
    428439        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            }
    450474        }
    451475        else
    452476        {
    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;
    454480            HGSMI_STRICT_ASSERT_FAILED();
    455481        }
    456482    }
    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;
    465485}
    466486
    467487/* A wrapper to safely call the handler.
    468488 */
    469 int HGSMIChannelHandlerCall (const HGSMICHANNELHANDLER *pHandler,
    470                              const HGSMIBUFFERHEADER *pHeader)
    471 {
    472     LogFlowFunc(("pHandler %p, pHeader %p\n", pHandler, pHeader));
     489static int hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,
     490                                   const HGSMIBUFFERCONTEXT *pBufferContext)
     491{
     492    LogFlowFunc(("pHandler %p\n", pHandler));
    473493
    474494    int rc;
    475 
    476     Assert(pHandler && pHandler->pfnHandler);
    477495
    478496    if (   pHandler
    479497        && pHandler->pfnHandler)
    480498    {
    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);
    485501    }
    486502    else
     
    491507
    492508    LogFlowFunc(("leave rc = %Rrc\n", rc));
    493 
    494509    return rc;
    495510}
    496511
    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 */
     518HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo,
     519                                   uint8_t u8Channel)
     520{
     521    AssertCompile(RT_ELEMENTS(pChannelInfo->Channels) >= 0x100);
    515522    HGSMICHANNEL *pChannel = &pChannelInfo->Channels[u8Channel];
    516523
     
    523530}
    524531
    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 */
     539int HGSMIBufferProcess(HGSMIAREA *pArea,
     540                       HGSMICHANNELINFO *pChannelInfo,
     541                       HGSMIOFFSET offBuffer)
    528542{
    529543    LogFlowFunc(("pArea %p, offBuffer 0x%x\n", pArea, offBuffer));
    530544
    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);
    537547
    538548    /* 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))
    542552    {
    543553        /* Pass the command to the appropriate handler registered with this instance.
    544554         * Start with the handler list head, which is the preallocated HGSMI setup channel.
    545555         */
    546         HGSMICHANNEL *pChannel = HGSMIChannelFindById (pChannelInfo, pHeader->u8Channel);
    547         Assert(pChannel);
     556        HGSMICHANNEL *pChannel = HGSMIChannelFindById(pChannelInfo, bufferContext.pHeader->u8Channel);
    548557        if (pChannel)
    549558        {
    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)));
    553561        }
    554562        else
    555563        {
    556564            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
    564569    return rc;
    565570}
    566571
    567 /* Register a new VBVA channel by index.
     572/** Register a new HGSMI channel by index.
    568573 *
    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 */
     581int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo,
     582                         uint8_t u8Channel,
     583                         const char *pszName,
     584                         PFNHGSMICHANNELHANDLER pfnChannelHandler,
     585                         void *pvChannelHandler)
     586{
    579587    /* 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;
    597600
    598601    pChannel->handler.pfnHandler = pfnChannelHandler;
    599602    pChannel->handler.pvHandler = pvChannelHandler;
    600603
     604    pChannel->pszName = pszName;
     605
    601606    return VINF_SUCCESS;
    602607}
    603 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette