VirtualBox

Changeset 55474 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 28, 2015 8:53:39 AM (10 years ago)
Author:
vboxsync
Message:

HGSMI: removed obsolete functions from common code, cleanup, comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp

    r55421 r55474  
    5858 */
    5959
    60 static uint32_t hgsmiHashBegin (void)
     60static uint32_t hgsmiHashBegin(void)
    6161{
    6262    return 0;
    6363}
    6464
    65 static uint32_t hgsmiHashProcess (uint32_t hash,
    66                                   const void *pvData,
    67                                   size_t cbData)
     65static uint32_t hgsmiHashProcess(uint32_t hash,
     66                                 const void *pvData,
     67                                 size_t cbData)
    6868{
    6969    const uint8_t *pu8Data = (const uint8_t *)pvData;
     
    7979}
    8080
    81 static uint32_t hgsmiHashEnd (uint32_t hash)
     81static uint32_t hgsmiHashEnd(uint32_t hash)
    8282{
    8383    hash += (hash << 3);
     
    8888}
    8989
    90 uint32_t HGSMIChecksum (HGSMIOFFSET offBuffer,
    91                         const HGSMIBUFFERHEADER *pHeader,
    92                         const HGSMIBUFFERTAIL *pTail)
    93 {
    94     uint32_t u32Checksum = hgsmiHashBegin ();
    95 
    96     u32Checksum = hgsmiHashProcess (u32Checksum, &offBuffer, sizeof (offBuffer));
    97     u32Checksum = hgsmiHashProcess (u32Checksum, pHeader, sizeof (HGSMIBUFFERHEADER));
    98     u32Checksum = hgsmiHashProcess (u32Checksum, pTail, RT_OFFSETOF(HGSMIBUFFERTAIL, u32Checksum));
    99 
    100     return hgsmiHashEnd (u32Checksum);
    101 }
    102 
    103 int HGSMIAreaInitialize (HGSMIAREA *pArea, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase)
     90uint32_t HGSMIChecksum(HGSMIOFFSET offBuffer,
     91                       const HGSMIBUFFERHEADER *pHeader,
     92                       const HGSMIBUFFERTAIL *pTail)
     93{
     94    uint32_t u32Checksum = hgsmiHashBegin();
     95
     96    u32Checksum = hgsmiHashProcess(u32Checksum, &offBuffer, sizeof(offBuffer));
     97    u32Checksum = hgsmiHashProcess(u32Checksum, pHeader, sizeof(HGSMIBUFFERHEADER));
     98    u32Checksum = hgsmiHashProcess(u32Checksum, pTail, RT_OFFSETOF(HGSMIBUFFERTAIL, u32Checksum));
     99
     100    return hgsmiHashEnd(u32Checksum);
     101}
     102
     103int HGSMIAreaInitialize(HGSMIAREA *pArea,
     104                        void *pvBase,
     105                        HGSMISIZE cbArea,
     106                        HGSMIOFFSET offBase)
    104107{
    105108    uint8_t *pu8Base = (uint8_t *)pvBase;
    106109
    107110    if (  !pArea                                   /* Check that the area: */
    108         || cbArea < HGSMIBufferMinimumSize ()      /* Large enough. */
    109         || pu8Base + cbArea < pu8Base              /* No address space wrap. */
    110         || offBase > UINT32_C(0xFFFFFFFF) - cbArea /* Area within the 32 bit space: offBase + cbMem <= 0xFFFFFFFF */
     111        || cbArea < HGSMIBufferMinimumSize()       /* large enough; */
     112        || pu8Base + cbArea < pu8Base              /* no address space wrap; */
     113        || offBase > UINT32_C(0xFFFFFFFF) - cbArea /* area within the 32 bit space: offBase + cbMem <= 0xFFFFFFFF. */
    111114       )
    112115    {
     
    116119    pArea->pu8Base = pu8Base;
    117120    pArea->offBase = offBase;
    118     pArea->offLast = cbArea - HGSMIBufferMinimumSize () + offBase;
     121    pArea->offLast = cbArea - HGSMIBufferMinimumSize() + offBase;
    119122    pArea->cbArea = cbArea;
    120123
     
    122125}
    123126
    124 void HGSMIAreaClear (HGSMIAREA *pArea)
     127void HGSMIAreaClear(HGSMIAREA *pArea)
    125128{
    126129    if (pArea)
    127130    {
    128         memset (pArea, 0, sizeof (HGSMIAREA));
     131        RT_ZERO(*pArea);
    129132    }
    130133}
     
    161164    }
    162165
    163     HGSMIOFFSET offBuffer = HGSMIPointerToOffset (pArea, pHeader);
     166    HGSMIOFFSET offBuffer = HGSMIPointerToOffset(pArea, pHeader);
    164167
    165168    pHeader->u8Flags        = HGSMI_BUFFER_HEADER_F_SEQ_SINGLE;
     
    167170    pHeader->u8Channel      = u8Channel;
    168171    pHeader->u16ChannelInfo = u16ChannelInfo;
    169     memset (pHeader->u.au8Union, 0, sizeof (pHeader->u.au8Union));
    170 
    171     HGSMIBUFFERTAIL *pTail = HGSMIBufferTail (pHeader);
    172 
     172    RT_ZERO(pHeader->u.au8Union);
     173
     174    HGSMIBUFFERTAIL *pTail = HGSMIBufferTailFromPtr(pHeader, u32DataSize);
    173175    pTail->u32Reserved = 0;
    174     pTail->u32Checksum = HGSMIChecksum (offBuffer, pHeader, pTail);
     176    pTail->u32Checksum = HGSMIChecksum(offBuffer, pHeader, pTail);
    175177
    176178    return offBuffer;
    177179}
    178180
    179 int HGSMIHeapSetup (HGSMIHEAP *pHeap,
    180                     void *pvBase,
    181                     HGSMISIZE cbArea,
    182                     HGSMIOFFSET offBase,
    183                     const HGSMIENV *pEnv)
    184 {
    185     if (   !pHeap
    186         || !pvBase)
    187     {
    188         return VERR_INVALID_PARAMETER;
    189     }
    190 
    191     int rc = HGSMIAreaInitialize (&pHeap->area, pvBase, cbArea, offBase);
    192 
    193     if (RT_SUCCESS (rc))
     181int HGSMIHeapSetup(HGSMIHEAP *pHeap,
     182                   void *pvBase,
     183                   HGSMISIZE cbArea,
     184                   HGSMIOFFSET offBase,
     185                   const HGSMIENV *pEnv)
     186{
     187    AssertPtrReturn(pHeap, VERR_INVALID_PARAMETER);
     188    AssertPtrReturn(pvBase, VERR_INVALID_PARAMETER);
     189
     190    int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
     191    if (RT_SUCCESS(rc))
    194192    {
    195193        rc = HGSMIMAInit(&pHeap->ma, &pHeap->area, NULL, 0, 0, pEnv);
    196194        if (RT_FAILURE(rc))
    197195        {
    198             HGSMIAreaClear (&pHeap->area);
     196            HGSMIAreaClear(&pHeap->area);
    199197        }
    200198    }
     
    203201}
    204202
    205 void HGSMIHeapDestroy (HGSMIHEAP *pHeap)
     203void HGSMIHeapDestroy(HGSMIHEAP *pHeap)
    206204{
    207205    if (pHeap)
    208206    {
    209207        HGSMIMAUninit(&pHeap->ma);
    210     }
    211 }
    212 
    213 void *HGSMIHeapAlloc (HGSMIHEAP *pHeap,
    214                       HGSMISIZE cbData,
    215                       uint8_t u8Channel,
    216                       uint16_t u16ChannelInfo)
    217 {
    218     HGSMISIZE cbAlloc = HGSMIBufferRequiredSize (cbData);
    219 
    220     HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIHeapBufferAlloc (pHeap, cbAlloc);
    221     if (!pHeader)
    222         return NULL;
    223 
    224     HGSMIOFFSET offBuffer = HGSMIBufferInitializeSingle(HGSMIHeapArea(pHeap), pHeader,
    225                                                         cbAlloc, u8Channel, u16ChannelInfo);
    226     if (offBuffer == HGSMIOFFSET_VOID)
    227     {
     208        RT_ZERO(*pHeap);
     209    }
     210}
     211
     212void *HGSMIHeapAlloc(HGSMIHEAP *pHeap,
     213                     HGSMISIZE cbData,
     214                     uint8_t u8Channel,
     215                     uint16_t u16ChannelInfo)
     216{
     217    HGSMISIZE cbAlloc = HGSMIBufferRequiredSize(cbData);
     218    HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIHeapBufferAlloc(pHeap, cbAlloc);
     219    if (pHeader)
     220    {
     221        HGSMIOFFSET offBuffer = HGSMIBufferInitializeSingle(HGSMIHeapArea(pHeap), pHeader,
     222                                                            cbAlloc, u8Channel, u16ChannelInfo);
     223        if (offBuffer == HGSMIOFFSET_VOID)
     224        {
     225            HGSMIHeapBufferFree(pHeap, pHeader);
     226            pHeader = NULL;
     227        }
     228    }
     229
     230    return pHeader? HGSMIBufferDataFromPtr(pHeader): NULL;
     231}
     232
     233void HGSMIHeapFree(HGSMIHEAP *pHeap,
     234                   void *pvData)
     235{
     236    if (pvData)
     237    {
     238        HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
    228239        HGSMIHeapBufferFree(pHeap, pHeader);
    229         return NULL;
    230     }
    231 
    232     return HGSMIBufferData (pHeader);
    233 }
    234 
    235 void HGSMIHeapFree (HGSMIHEAP *pHeap,
    236                     void *pvData)
    237 {
    238     if (pvData)
    239     {
    240         HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData (pvData);
    241 
    242         HGSMIHeapBufferFree (pHeap, pHeader);
    243     }
    244 }
    245 
    246 void* HGSMIHeapBufferAlloc (HGSMIHEAP *pHeap, HGSMISIZE cbBuffer)
     240    }
     241}
     242
     243void *HGSMIHeapBufferAlloc(HGSMIHEAP *pHeap,
     244                           HGSMISIZE cbBuffer)
    247245{
    248246    void *pvBuf = HGSMIMAAlloc(&pHeap->ma, cbBuffer);
     
    263261} HGSMIBUFFERCONTEXT;
    264262
    265 /* Verify that the given offBuffer points to a valid buffer, which is within the area.
     263/** Verify that the given offBuffer points to a valid buffer, which is within the area.
     264 *
     265 * @returns VBox status and the buffer information in pBufferContext.
     266 * @param pArea          Area which supposed to contain the buffer.
     267 * @param offBuffer      The buffer location in the area.
     268 * @param pBufferContext Where to write information about the buffer.
    266269 */
    267270static int hgsmiVerifyBuffer(const HGSMIAREA *pArea,
     
    328331}
    329332
    330 /* A wrapper to safely call the handler.
    331  */
    332 static void hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,
    333                                     const HGSMIBUFFERCONTEXT *pBufferContext)
    334 {
    335     LogFlowFunc(("pHandler %p\n", pHandler));
    336 
    337     if (   pHandler
    338         && pHandler->pfnHandler)
    339     {
    340         pHandler->pfnHandler(pHandler->pvHandler, pBufferContext->pHeader->u16ChannelInfo,
    341                              pBufferContext->pvData, pBufferContext->cbData);
    342     }
    343 }
    344 
    345333/** Helper to convert HGSMI channel index to the channel structure pointer.
    346334 *
     
    370358 * @param offBuffer    The buffer location in the area.
    371359 */
    372 int HGSMIBufferProcess(HGSMIAREA *pArea,
     360int HGSMIBufferProcess(const HGSMIAREA *pArea,
    373361                       HGSMICHANNELINFO *pChannelInfo,
    374362                       HGSMIOFFSET offBuffer)
     
    387375         * Start with the handler list head, which is the preallocated HGSMI setup channel.
    388376         */
    389         HGSMICHANNEL *pChannel = HGSMIChannelFindById(pChannelInfo, bufferContext.pHeader->u8Channel);
     377        const HGSMICHANNEL *pChannel = HGSMIChannelFindById(pChannelInfo, bufferContext.pHeader->u8Channel);
    390378        if (pChannel)
    391379        {
    392             hgsmiChannelHandlerCall(&pChannel->handler, &bufferContext);
     380            const HGSMICHANNELHANDLER *pHandler = &pChannel->handler;
     381            if (pHandler->pfnHandler)
     382            {
     383                pHandler->pfnHandler(pHandler->pvHandler, bufferContext.pHeader->u16ChannelInfo,
     384                                     bufferContext.pvData, bufferContext.cbData);
     385            }
    393386            HGSMI_STRICT_ASSERT(RT_SUCCESS(hgsmiVerifyBuffer(pArea, offBuffer, &bufferContext)));
    394387        }
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