sg.cpp revision 89c28c87cc69edce638703dbfa181d6d67daf17b
ea7d33962ceb90ea90e67e427d60b5788f34268avboxsync * IPRT - S/G buffer handling.
ea7d33962ceb90ea90e67e427d60b5788f34268avboxsync * Copyright (C) 2010 Oracle Corporation
65b0f0cd3c38007138720b7eaa43c963a9ee1244vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
65b0f0cd3c38007138720b7eaa43c963a9ee1244vboxsync * available from http://www.virtualbox.org. This file is free software;
65b0f0cd3c38007138720b7eaa43c963a9ee1244vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The contents of this file may alternatively be used under the terms
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * of the Common Development and Distribution License Version 1.0
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * CDDL are applicable instead of those of the GPL.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You may elect to license modified versions of this file under the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * terms and conditions of either the GPL or the CDDL or both.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync/*******************************************************************************
65b0f0cd3c38007138720b7eaa43c963a9ee1244vboxsync* Header Files *
65b0f0cd3c38007138720b7eaa43c963a9ee1244vboxsync*******************************************************************************/
65b0f0cd3c38007138720b7eaa43c963a9ee1244vboxsyncstatic void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync /* Check that the S/G buffer has memory left. */
c320aee99660824809e157bbad368db3542a9e90vboxsync && (uintptr_t)pSgBuf->pvSegCur >= (uintptr_t)pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg
c320aee99660824809e157bbad368db3542a9e90vboxsync && (uintptr_t)pSgBuf->pvSegCur + pSgBuf->cbSegLeft <= (uintptr_t)pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg + pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg,
c320aee99660824809e157bbad368db3542a9e90vboxsync ("pSgBuf->idxSeg=%d pSgBuf->cSegs=%d pSgBuf->pvSegCur=%p pSgBuf->cbSegLeft=%zd pSgBuf->paSegs[%d].pvSeg=%p pSgBuf->paSegs[%d].cbSeg=%zd\n",
c320aee99660824809e157bbad368db3542a9e90vboxsync pSgBuf->idxSeg, pSgBuf->cSegs, pSgBuf->pvSegCur, pSgBuf->cbSegLeft,
c320aee99660824809e157bbad368db3542a9e90vboxsync pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg, pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg));
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsync /* Advance to the next segment if required. */
b6dc9545438e63d05fff621e85ddb7dc39cf14e7vboxsync pSgBuf->pvSegCur = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg;
b6dc9545438e63d05fff621e85ddb7dc39cf14e7vboxsync pSgBuf->cbSegLeft = pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg;
20593760b116c90f3e439552763eef632a3bbb17vboxsync pSgBuf->pvSegCur = (uint8_t *)pSgBuf->pvSegCur + cbData;
6fea4abcc6ee0f2797ac01ef79c374d506aedc02vboxsyncRTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, size_t cSegs)
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsyncRTDECL(void) RTSgBufClone(PRTSGBUF pSgBufTo, PCRTSGBUF pSgBufFrom)
2cf084f1df635fcf1e1e40547a96c33f723471cbvboxsyncRTDECL(void *) RTSgBufGetNextSegment(PRTSGBUF pSgBuf, size_t *pcbSeg)
while (cbLeft)
void *pvBufDst;
void *pvBufSrc;
if (!cbThisCopy)
while (cbLeft)
void *pvBuf1;
void *pvBuf2;
if (!cbCmp)
if (rc)
return rc;
if (!fAdvance)
while (cbLeft)
if (!cbCmp)
if (rc)
if (pcbOff)
while ( cbThisCmp-- > 0
pbBuf1++;
pbBuf2++;
cbOff++;
return rc;
while (cbLeft)
if (!cbThisSet)
while (cbLeft)
if (!cbThisCopy)
while (cbLeft)
if (!cbThisCopy)
while (cbLeft)
if (!cbThisAdvance)
RTDECL(size_t) RTSgBufSegArrayCreate(PRTSGBUF pSgBuf, PRTSGSEG paSeg, unsigned *pcSeg, size_t cbData)
unsigned cSeg = 0;
if (!paSeg)
while ( cbData
idx++;
cSeg++;
while ( cbData
if (!cbThisSeg)
cSeg++;
return cb;