VirtualBox

Changeset 28071 in vbox


Ignore:
Timestamp:
Apr 7, 2010 11:20:54 PM (15 years ago)
Author:
vboxsync
Message:

VBoxNetFlt: Deal with multi segment SG buffers. TODO: One weird windows code path.

Location:
trunk/include/VBox
Files:
2 edited

Legend:

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

    r28025 r28071  
    583583     * @param   pIfPort     Pointer to this structure.
    584584     *
    585      * @remarks Called while owning the network and the out-bound trunk port semaphores.
     585     * @remarks Usuaully called while owning the network and the out-bound trunk
     586     *          port semaphores.
    586587     */
    587588    DECLR0CALLBACKMEMBER(bool, pfnIsPromiscuous,(PINTNETTRUNKIFPORT pIfPort));
  • trunk/include/VBox/intnetinline.h

    r28037 r28071  
    168168}
    169169
     170
     171/**
     172 * Reads an entire SG into a fittingly size buffer.
     173 *
     174 * @param   pSG         The SG list to read.
     175 * @param   pvBuf       The buffer to read into (at least pSG->cbTotal in size).
     176 */
     177DECLINLINE(void) INTNETSgRead(PCINTNETSG pSG, void *pvBuf)
     178{
     179    memcpy(pvBuf, pSG->aSegs[0].pv, pSG->aSegs[0].cb);
     180    if (pSG->cSegsUsed == 1)
     181        Assert(pSG->cbTotal == pSG->aSegs[0].cb);
     182    else
     183    {
     184        uint8_t        *pbDst = (uint8_t *)pvBuf + pSG->aSegs[0].cb;
     185        unsigned        iSeg  = 0;
     186        unsigned const  cSegs = pSG->cSegsUsed;
     187        while (++iSeg < cSegs)
     188        {
     189            uint32_t    cbSeg = pSG->aSegs[iSeg].cb;
     190            Assert((uintptr_t)pbDst - (uintptr_t)pvBuf + cbSeg <= pSG->cbTotal);
     191            memcpy(pbDst, pSG->aSegs[iSeg].pv, cbSeg);
     192            pbDst += cbSeg;
     193        }
     194    }
     195}
     196
     197
     198/**
     199 * Reads a portion of an SG into a buffer.
     200 *
     201 * @param   pSG         The SG list to read.
     202 * @param   offSrc      The offset to start start copying from.
     203 * @param   cbToRead    The number of bytes to copy.
     204 * @param   pvBuf       The buffer to read into, cb or more in size.
     205 */
     206DECLINLINE(void) INTNETSgReadEx(PCINTNETSG pSG, uint32_t offSrc, uint32_t cbToRead, void *pvBuf)
     207{
     208    uint8_t    *pbDst = (uint8_t *)pvBuf;
     209    uint32_t    iSeg  = 0;
     210
     211    /* validate assumptions */
     212    Assert(cbToRead          <  pSG->cbTotal);
     213    Assert(offSrc            <= pSG->cbTotal);
     214    Assert(offSrc + cbToRead <= pSG->cbTotal);
     215
     216    /* Find the right segment and copy any bits from within the segment. */
     217    while (offSrc)
     218    {
     219        uint32_t cbSeg = pSG->aSegs[iSeg].cb;
     220        if (offSrc < cbSeg)
     221        {
     222            uint32_t cbChunk = cbSeg - offSrc;
     223            if (cbChunk >= cbToRead)
     224            {
     225                memcpy(pbDst, (uint8_t const *)pSG->aSegs[iSeg].pv + offSrc, cbToRead);
     226                return;
     227            }
     228
     229            memcpy(pbDst, (uint8_t const *)pSG->aSegs[iSeg].pv + offSrc, cbChunk);
     230            pbDst    += cbChunk;
     231            cbToRead -= cbChunk;
     232            break;
     233        }
     234
     235        /* advance */
     236        offSrc -= cbSeg;
     237        iSeg++;
     238    }
     239
     240    /* We're not at the start of a segment, copy until we're done. */
     241    for (;;)
     242    {
     243        uint32_t cbSeg = pSG->aSegs[iSeg].cb;
     244        if (cbSeg >= cbToRead)
     245        {
     246            memcpy(pbDst, pSG->aSegs[iSeg].pv, cbToRead);
     247            return;
     248        }
     249
     250        memcpy(pbDst, pSG->aSegs[iSeg].pv, cbSeg);
     251        pbDst    += cbSeg;
     252        cbToRead -= cbSeg;
     253        iSeg++;
     254        Assert(iSeg < pSG->cSegsUsed);
     255    }
     256}
     257
    170258#ifdef __cplusplus
    171259
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