intnetinline.h revision e64031e20c39650a7bc902a3e1aba613b9415dee
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * INTNET - Internal Networking, Inlined Code. (DEV,++)
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * This is all inlined because it's too tedious to create 2-3 libraries to
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * contain it all. Large parts of this header is only accessible from C++
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * sources because of mixed code and variables.
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * Copyright (C) 2006-2010 Oracle Corporation
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * This file is part of VirtualBox Open Source Edition (OSE), as
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * available from http://www.virtualbox.org. This file is free software;
590e03a0114f53c994d970cfb356dadaaa57e39dJaco Jooste * you can redistribute it and/or modify it under the terms of the GNU
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * General Public License (GPL) as published by the Free Software
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * Foundation, in version 2 as it comes in the "COPYING" file of the
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * The contents of this file may alternatively be used under the terms
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * of the Common Development and Distribution License Version 1.0
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * VirtualBox OSE distribution, in which case the provisions of the
297d50ecdec790c7b0d75d204c8695b406e274c1Peter Major * CDDL are applicable instead of those of the GPL.
b22c2a29f35c5c8bf679b6904dca1d502328d86aPhill Cunnington * You may elect to license modified versions of this file under the
4701cb94cccc5ef52c5333593fe9dd5a2376a9d9Jaco Jooste * terms and conditions of either the GPL or the CDDL or both.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * Valid internal networking frame type.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @returns true / false.
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna * @param u16Type The frame type to check.
582e60f5478cf04cad2b208c3e8013fef3617942Jaco JoosteDECLINLINE(bool) IntNetIsValidFrameType(uint16_t u16Type)
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste return true;
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste return false;
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna * Partly initializes a scatter / gather buffer, leaving the segments to the
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * @returns Pointer to the start of the frame.
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna * @param pSG Pointer to the scatter / gather structure.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param cbTotal The total size.
4701cb94cccc5ef52c5333593fe9dd5a2376a9d9Jaco Jooste * @param cSegs The number of segments.
48a3f9d4300dcee393075c632655deb42f43bce6Jaco Jooste * @param cSegsUsed The number of used segments.
4701cb94cccc5ef52c5333593fe9dd5a2376a9d9Jaco JoosteDECLINLINE(void) IntNetSgInitTempSegs(PINTNETSG pSG, uint32_t cbTotal, unsigned cSegs, unsigned cSegsUsed)
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste pSG->GsoCtx.u8Type = (uint8_t)PDMNETWORKGSOTYPE_INVALID;
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * Partly initializes a scatter / gather buffer w/ GSO, leaving the segments to
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * the caller.
b22c2a29f35c5c8bf679b6904dca1d502328d86aPhill Cunnington * @returns Pointer to the start of the frame.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param pSG Pointer to the scatter / gather structure.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param cbTotal The total size.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param cSegs The number of segments.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param cSegsUsed The number of used segments.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param pGso The GSO context.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert WapshottDECLINLINE(void) IntNetSgInitTempSegsGso(PINTNETSG pSG, uint32_t cbTotal, unsigned cSegs,
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * Initializes a scatter / gather buffer describing a simple linear buffer.
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * @returns Pointer to the start of the frame.
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * @param pSG Pointer to the scatter / gather structure.
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * @param pvFrame Pointer to the frame
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste * @param cbFrame The size of the frame.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert WapshottDECLINLINE(void) IntNetSgInitTemp(PINTNETSG pSG, void *pvFrame, uint32_t cbFrame)
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * Initializes a scatter / gather buffer describing a simple linear buffer.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @returns Pointer to the start of the frame.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param pSG Pointer to the scatter / gather structure.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param pvFrame Pointer to the frame
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param cbFrame The size of the frame.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott * @param pGso The GSO context.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert WapshottDECLINLINE(void) IntNetSgInitTempGso(PINTNETSG pSG, void *pvFrame, uint32_t cbFrame, PCPDMNETWORKGSO pGso)
unsigned iSeg = 0;
while (offSrc)
iSeg++;
iSeg++;
#ifdef __cplusplus
return NULL;
#ifdef VBOX_STRICT
return pu8;
#ifdef VBOX_STRICT
return pGso;
#ifdef INTNET_POISON_READ_FRAMES
DECLINLINE(int) intnetRingAllocateFrameInternal(PINTNETRINGBUF pRingBuf, uint32_t cbFrame, uint16_t u16Type,
Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (1) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u16Type, cbFrame));
return VINF_SUCCESS;
AssertMsg(pRingBuf->offEnd - offWriteInt >= sizeof(INTNETHDR), ("offEnd=%x offWriteInt=%x\n", pRingBuf->offEnd, offWriteInt));
Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (2) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u16Type, cbFrame));
return VINF_SUCCESS;
Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (3) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u16Type, cbFrame));
return VINF_SUCCESS;
return VERR_BUFFER_OVERFLOW;
DECLINLINE(int) IntNetRingAllocateFrame(PINTNETRINGBUF pRingBuf, uint32_t cbFrame, PINTNETHDR *ppHdr, void **ppvFrame)
DECLINLINE(int) IntNetRingAllocateGsoFrame(PINTNETRINGBUF pRingBuf, uint32_t cbFrame, PCPDMNETWORKGSO pGso,
int rc = intnetRingAllocateFrameInternal(pRingBuf, cbFrame + sizeof(*pGso), INTNETHDR_TYPE_GSO, ppHdr, &pvFrame);
return rc;
+ cb;
Log2(("IntNetRingCommitFrame: offWriteCom: %#x -> %#x (R=%#x T=%#x S=%#x)\n", pRingBuf->offWriteCom, offWriteCom, pRingBuf->offReadX, pHdr->u16Type, cbFrame));
Log2(("IntNetRingCommitFrameEx: offWriteCom: %#x -> %#x (R=%#x T=%#x S=%#x P=%#x)\n", pRingBuf->offWriteCom, offWriteCom, pRingBuf->offReadX, pHdr->u16Type, pHdr->cbFrame, cbAlignedFrame - cbAlignedUsed));
return VINF_SUCCESS;
AssertMsg(pRingBuf->offEnd - offWriteInt >= sizeof(INTNETHDR), ("offEnd=%x offWriteInt=%x\n", pRingBuf->offEnd, offWriteInt));
return VINF_SUCCESS;
return VINF_SUCCESS;
return VERR_BUFFER_OVERFLOW;
#ifdef INTNET_POISON_READ_FRAMES
return cbFrame;
DECLINLINE(void) IntNetBufInit(PINTNETBUF pIntBuf, uint32_t cbBuf, uint32_t cbRecv, uint32_t cbSend)
uint32_t offBuf = RT_ALIGN_32(sizeof(INTNETBUF), INTNETRINGBUF_ALIGNMENT) - RT_OFFSETOF(INTNETBUF, Recv);