354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * IPRT - S/G buffer handling.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2010-2013 Oracle Corporation
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * available from http://www.virtualbox.org. This file is free software;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * you can redistribute it and/or modify it under the terms of the GNU
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * General Public License (GPL) as published by the Free Software
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * The contents of this file may alternatively be used under the terms
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * of the Common Development and Distribution License Version 1.0
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * VirtualBox OSE distribution, in which case the provisions of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * CDDL are applicable instead of those of the GPL.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * You may elect to license modified versions of this file under the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * terms and conditions of either the GPL or the CDDL or both.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/*******************************************************************************
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync* Header Files *
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync*******************************************************************************/
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncstatic void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData)
89c28c87cc69edce638703dbfa181d6d67daf17bvboxsync /* Check that the S/G buffer has memory left. */
44a56c2ffd522c0ef282907c9b07641d06dc143avboxsync && (uintptr_t)pSgBuf->pvSegCur >= (uintptr_t)pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg
44a56c2ffd522c0ef282907c9b07641d06dc143avboxsync && (uintptr_t)pSgBuf->pvSegCur + pSgBuf->cbSegLeft <= (uintptr_t)pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg + pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg,
44a56c2ffd522c0ef282907c9b07641d06dc143avboxsync ("pSgBuf->idxSeg=%d pSgBuf->cSegs=%d pSgBuf->pvSegCur=%p pSgBuf->cbSegLeft=%zd pSgBuf->paSegs[%d].pvSeg=%p pSgBuf->paSegs[%d].cbSeg=%zd\n",
44a56c2ffd522c0ef282907c9b07641d06dc143avboxsync pSgBuf->idxSeg, pSgBuf->cSegs, pSgBuf->pvSegCur, pSgBuf->cbSegLeft,
44a56c2ffd522c0ef282907c9b07641d06dc143avboxsync pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg, pSgBuf->idxSeg, pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg));
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync /* Advance to the next segment if required. */
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync pSgBuf->pvSegCur = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync pSgBuf->cbSegLeft = pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync pSgBuf->pvSegCur = (uint8_t *)pSgBuf->pvSegCur + cbData;
cb6fa623dea342f8cdb056585d3237e0bffd970avboxsyncRTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, size_t cSegs)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(void) RTSgBufClone(PRTSGBUF pSgBufTo, PCRTSGBUF pSgBufFrom)
6337fd8860ce7d3ae9835f9bee38c15ecbabc86avboxsyncRTDECL(void *) RTSgBufGetNextSegment(PRTSGBUF pSgBuf, size_t *pcbSeg)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufCopy(PRTSGBUF pSgBufDst, PRTSGBUF pSgBufSrc, size_t cbCopy)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync size_t cbThisCopy = RT_MIN(RT_MIN(pSgBufDst->cbSegLeft, cbLeft), pSgBufSrc->cbSegLeft);
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(int) RTSgBufCmp(PCRTSGBUF pSgBuf1, PCRTSGBUF pSgBuf2, size_t cbCmp)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync /* Set up the temporary buffers */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync size_t cbThisCmp = RT_MIN(RT_MIN(SgBuf1.cbSegLeft, cbLeft), SgBuf2.cbSegLeft);
018872730d2bb228577f818371b9b3d513168a74vboxsyncRTDECL(int) RTSgBufCmpEx(PRTSGBUF pSgBuf1, PRTSGBUF pSgBuf2, size_t cbCmp,
018872730d2bb228577f818371b9b3d513168a74vboxsync /* Set up the temporary buffers */
018872730d2bb228577f818371b9b3d513168a74vboxsync size_t cbThisCmp = RT_MIN(RT_MIN(pSgBuf1Tmp->cbSegLeft, cbLeft), pSgBuf2Tmp->cbSegLeft);
018872730d2bb228577f818371b9b3d513168a74vboxsync /* Search for the correct offset */
018872730d2bb228577f818371b9b3d513168a74vboxsync while ( cbThisCmp-- > 0
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufSet(PRTSGBUF pSgBuf, uint8_t ubFill, size_t cbSet)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufCopyToBuf(PRTSGBUF pSgBuf, void *pvBuf, size_t cbCopy)
f5307deb2af02309e5320206881885148c6f48e4vboxsyncRTDECL(size_t) RTSgBufCopyFromBuf(PRTSGBUF pSgBuf, const void *pvBuf, size_t cbCopy)
f5307deb2af02309e5320206881885148c6f48e4vboxsync pvBuf = (const void *)((uintptr_t)pvBuf + cbThisCopy);
c1e15b3c98815ead93f67b8eb8b116189497cfb4vboxsyncRTDECL(size_t) RTSgBufAdvance(PRTSGBUF pSgBuf, size_t cbAdvance)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncRTDECL(size_t) RTSgBufSegArrayCreate(PRTSGBUF pSgBuf, PRTSGSEG paSeg, unsigned *pcSeg, size_t cbData)
83a8011f7acdb5bbbd1fe141846dfeeb0a53d94avboxsync cbData -= RT_MIN(pSgBuf->paSegs[idx].cbSeg, cbData);
c4e7058a3ae47876c97ed660d5377a6346950678vboxsyncRTDECL(bool) RTSgBufIsZero(PRTSGBUF pSgBuf, size_t cbCheck)
c4e7058a3ae47876c97ed660d5377a6346950678vboxsync /* Use optimized inline assembler if possible. */
0cd76e2baf48b7043ebbd62634ef3eee2b70cb9evboxsync if (ASMBitFirstSet((volatile void *)pvBuf, (uint32_t)cbThisCheck * 8) != -1)
c4e7058a3ae47876c97ed660d5377a6346950678vboxsync for (unsigned i = 0; i < cbThisCheck; i++)