Changeset 26574 in vbox for trunk/include
- Timestamp:
- Feb 16, 2010 12:44:10 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 57756
- Location:
- trunk/include
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Makefile.kmk
r26304 r26574 24 24 include $(KBUILD_PATH)/header.kmk 25 25 26 LIBRARIES = SyntaxVBoxIncludeR3 SyntaxVBoxIncludeR0 SyntaxVBoxInclude GC26 LIBRARIES = SyntaxVBoxIncludeR3 SyntaxVBoxIncludeR0 SyntaxVBoxIncludeRC 27 27 28 28 cpp_hdrs := \ … … 79 79 $(addprefix $(PATH_TARGET)/,$(subst .h,-cpp.cpp, $(subst /,_,$(hdrs.r0)))) 80 80 81 SyntaxVBoxInclude GC_TEMPLATE = VBoxRc82 SyntaxVBoxInclude GC_DEFS = VBOX_WITH_HGCM83 SyntaxVBoxInclude GC_SOURCES := \81 SyntaxVBoxIncludeRC_TEMPLATE = VBoxRc 82 SyntaxVBoxIncludeRC_DEFS = VBOX_WITH_HGCM 83 SyntaxVBoxIncludeRC_SOURCES := \ 84 84 $(addprefix $(PATH_TARGET)/,$(subst .h,-c.c, $(subst /,_,$(hdrs.gc)))) \ 85 85 $(addprefix $(PATH_TARGET)/,$(subst .h,-cpp.cpp, $(subst /,_,$(hdrs.gc)))) … … 98 98 99 99 $$(PATH_TARGET)/$(flatname)-c.c: $(VBOX_ROOT_INCLUDE_MAKEFILE) | $$(PATH_TARGET)/ 100 ifn1of ($(hdr), $(cpp_hdrs))100 ifn1of ($(hdr), $(cpp_hdrs) VBox/intnetinline.h) 101 101 $(QUIET)$$(APPEND) -t -n $$@ '#include <$(hdr)>' 'int main(int argc, char **argv) {(void)argc; (void)argv; return 0;}' 102 102 else -
trunk/include/VBox/intnet.h
r23209 r26574 1 1 /** @file 2 * IN ETNET - Internal Networking. (DEV,++)2 * INTNET - Internal Networking. (DEV,++) 3 3 */ 4 4 … … 52 52 typedef struct INTNETRINGBUF 53 53 { 54 /** The start of the buffer offset relative to the. (inclusive)*/54 /** The offset from this structure to the start of the buffer. */ 55 55 uint32_t offStart; 56 /** The offset to the end of the buffer. (exclusive)*/56 /** The offset from this structure to the end of the buffer. (exclusive). */ 57 57 uint32_t offEnd; 58 58 /** The current read offset. */ 59 uint32_t volatile offRead; 60 /** The current write offset. */ 61 uint32_t volatile offWrite; 59 uint32_t volatile offReadX; 60 /** Alignment. */ 61 uint32_t u32Align0; 62 63 /** The committed write offset. */ 64 uint32_t volatile offWriteCom; 65 /** Writer internal current write offset. 66 * This is ahead of offWriteCom when buffer space is handed to a third party for 67 * data gathering. offWriteCom will be assigned this value by the writer then 68 * the frame is ready. */ 69 uint32_t volatile offWriteInt; 70 /** The number of bytes written (not counting overflows). */ 71 STAMCOUNTER cbStatWritten; 72 /** The number of frames written (not counting overflows). */ 73 STAMCOUNTER cStatFrames; 74 /** The number of overflows. */ 75 STAMCOUNTER cOverflows; 62 76 } INTNETRINGBUF; 77 AssertCompileSize(INTNETRINGBUF, 48); 63 78 /** Pointer to a ring buffer. */ 64 79 typedef INTNETRINGBUF *PINTNETRINGBUF; 65 80 66 /** 67 * Get the amount of space available for writing. 68 * 69 * @returns Number of available bytes. 70 * @param pRingBuf The ring buffer. 71 */ 72 DECLINLINE(uint32_t) INTNETRingGetWritable(PINTNETRINGBUF pRingBuf) 73 { 74 return pRingBuf->offRead <= pRingBuf->offWrite 75 ? pRingBuf->offEnd - pRingBuf->offWrite + pRingBuf->offRead - pRingBuf->offStart - 1 76 : pRingBuf->offRead - pRingBuf->offWrite - 1; 77 } 78 79 80 /** 81 * Get the amount of data ready for reading. 82 * 83 * @returns Number of ready bytes. 84 * @param pRingBuf The ring buffer. 85 */ 86 DECLINLINE(uint32_t) INTNETRingGetReadable(PINTNETRINGBUF pRingBuf) 87 { 88 return pRingBuf->offRead <= pRingBuf->offWrite 89 ? pRingBuf->offWrite - pRingBuf->offRead 90 : pRingBuf->offEnd - pRingBuf->offRead + pRingBuf->offWrite - pRingBuf->offStart; 91 } 81 /** The alignment of a ring buffer. */ 82 #define INTNETRINGBUF_ALIGNMENT sizeof(INTNETHDR) 83 84 /** 85 * Asserts the sanity of the specified INTNETRINGBUF structure. 86 */ 87 #define INTNETRINGBUF_ASSERT_SANITY(pRingBuf) \ 88 do \ 89 { \ 90 AssertPtr(pRingBuf); \ 91 { \ 92 uint32_t const offWriteCom = (pRingBuf)->offWriteCom; \ 93 uint32_t const offRead = (pRingBuf)->offReadX; \ 94 uint32_t const offWriteInt = (pRingBuf)->offWriteInt; \ 95 \ 96 AssertMsg(offWriteCom == RT_ALIGN_32(offWriteCom, INTNETHDR_ALIGNMENT), ("%#x\n", offWriteCom)); \ 97 AssertMsg(offWriteCom >= (pRingBuf)->offStart, ("%#x %#x\n", offWriteCom, (pRingBuf)->offStart)); \ 98 AssertMsg(offWriteCom < (pRingBuf)->offEnd, ("%#x %#x\n", offWriteCom, (pRingBuf)->offEnd)); \ 99 \ 100 AssertMsg(offRead == RT_ALIGN_32(offRead, INTNETHDR_ALIGNMENT), ("%#x\n", offRead)); \ 101 AssertMsg(offRead >= (pRingBuf)->offStart, ("%#x %#x\n", offRead, (pRingBuf)->offStart)); \ 102 AssertMsg(offRead < (pRingBuf)->offEnd, ("%#x %#x\n", offRead, (pRingBuf)->offEnd)); \ 103 \ 104 AssertMsg(offWriteInt == RT_ALIGN_32(offWriteInt, INTNETHDR_ALIGNMENT), ("%#x\n", offWriteInt)); \ 105 AssertMsg(offWriteInt >= (pRingBuf)->offStart, ("%#x %#x\n", offWriteInt, (pRingBuf)->offStart)); \ 106 AssertMsg(offWriteInt < (pRingBuf)->offEnd, ("%#x %#x\n", offWriteInt, (pRingBuf)->offEnd)); \ 107 AssertMsg( offRead <= offWriteCom \ 108 ? offWriteCom <= offWriteInt || offWriteInt < offRead \ 109 : offWriteCom <= offWriteInt, \ 110 ("W=%#x W'=%#x R=%#x\n", offWriteCom, offWriteInt, offRead)); \ 111 } \ 112 } while (0) 113 92 114 93 115 … … 97 119 typedef struct INTNETBUF 98 120 { 121 /** Magic number (INTNETBUF_MAGIC). */ 122 uint32_t u32Magic; 99 123 /** The size of the entire buffer. */ 100 124 uint32_t cbBuf; … … 103 127 /** The size of the receive area. */ 104 128 uint32_t cbRecv; 105 /** Alignment. */106 uint32_t u32Align;107 129 /** The receive buffer. */ 108 130 INTNETRINGBUF Recv; … … 115 137 /** Number of lost packets due to overflows. */ 116 138 STAMCOUNTER cStatLost; 117 /** Number of packets received (not counting lost ones). */ 118 STAMCOUNTER cStatRecvs; 119 /** Number of frame bytes received (not couting lost frames). */ 120 STAMCOUNTER cbStatRecv; 121 /** Number of packets received. */ 122 STAMCOUNTER cStatSends; 123 /** Number of frame bytes sent. */ 124 STAMCOUNTER cbStatSend; 139 /** Number of bad frames (both rings). */ 140 STAMCOUNTER cStatBadFrames; 141 /** Reserved for future use. */ 142 STAMCOUNTER aStatReserved[2]; 125 143 } INTNETBUF; 144 AssertCompileSize(INTNETBUF, 160); 145 AssertCompileMemberOffset(INTNETBUF, Recv, 16); 146 AssertCompileMemberOffset(INTNETBUF, Send, 64); 147 126 148 /** Pointer to an interface buffer. */ 127 149 typedef INTNETBUF *PINTNETBUF; 128 150 /** Pointer to a const interface buffer. */ 129 151 typedef INTNETBUF const *PCINTNETBUF; 152 153 /** Magic number for INTNETBUF::u32Magic (Sir William Gerald Golding). */ 154 #define INTNETBUF_MAGIC UINT32_C(0x19110919) 155 156 /** 157 * Asserts the sanity of the specified INTNETBUF structure. 158 */ 159 #define INTNETBUF_ASSERT_SANITY(pBuf) \ 160 do \ 161 { \ 162 AssertPtr(pBuf); \ 163 Assert((pBuf)->u32Magic == INTNETBUF_MAGIC); \ 164 { \ 165 uint32_t const offRecvStart = (pBuf)->Recv.offStart + RT_OFFSETOF(INTNETBUF, Recv); \ 166 uint32_t const offRecvEnd = (pBuf)->Recv.offStart + RT_OFFSETOF(INTNETBUF, Recv); \ 167 uint32_t const offSendStart = (pBuf)->Send.offStart + RT_OFFSETOF(INTNETBUF, Send); \ 168 uint32_t const offSendEnd = (pBuf)->Send.offStart + RT_OFFSETOF(INTNETBUF, Send); \ 169 \ 170 Assert(offRecvEnd > offRecvStart); \ 171 Assert(offRecvEnd - offRecvStart == (pBuf)->cbRecv); \ 172 Assert(offRecvStart == sizeof(INTNETBUF)); \ 173 \ 174 Assert(offSendEnd > offSendStart); \ 175 Assert(offSendEnd - offSendStart == (pBuf)->cbSend); \ 176 Assert(pffSendEnd <= (pBuf)->cbBuf); \ 177 \ 178 Assert(offSendStart == offRecvEnd); \ 179 } \ 180 } while (0) 181 130 182 131 183 /** Internal networking interface handle. */ … … 153 205 * memory. 154 206 */ 155 #pragma pack(1)156 207 typedef struct INTNETHDR 157 208 { … … 163 214 /** The offset from the start of this header to where the actual frame starts. 164 215 * This is used to keep the frame it self continguous in virtual memory and 165 * thereby both simplify reading and*/216 * thereby both simplify access as well as the descriptor. */ 166 217 int32_t offFrame; 167 218 } INTNETHDR; 168 #pragma pack() 219 AssertCompileSize(INTNETHDR, 8); 220 AssertCompileSizeAlignment(INTNETBUF, sizeof(INTNETHDR)); 169 221 /** Pointer to a packet header.*/ 170 222 typedef INTNETHDR *PINTNETHDR; … … 172 224 typedef INTNETHDR const *PCINTNETHDR; 173 225 226 /** The alignment of a packet header. */ 227 #define INTNETHDR_ALIGNMENT sizeof(INTNETHDR) 228 AssertCompile(sizeof(INTNETHDR) == INTNETHDR_ALIGNMENT); 229 AssertCompile(INTNETHDR_ALIGNMENT <= INTNETRINGBUF_ALIGNMENT); 230 174 231 /** INTNETHDR::u16Type value for normal frames. */ 175 #define INTNETHDR_TYPE_FRAME 0x2442 176 177 178 /** 179 * Calculates the pointer to the frame. 180 * 181 * @returns Pointer to the start of the frame. 182 * @param pHdr Pointer to the packet header 183 * @param pBuf The buffer the header is within. Only used in strict builds. 184 */ 185 DECLINLINE(void *) INTNETHdrGetFramePtr(PCINTNETHDR pHdr, PCINTNETBUF pBuf) 186 { 187 uint8_t *pu8 = (uint8_t *)pHdr + pHdr->offFrame; 188 #ifdef VBOX_STRICT 189 const uintptr_t off = (uintptr_t)pu8 - (uintptr_t)pBuf; 190 Assert(pHdr->u16Type == INTNETHDR_TYPE_FRAME); 191 Assert(off < pBuf->cbBuf); 192 Assert(off + pHdr->cbFrame <= pBuf->cbBuf); 193 #endif 194 NOREF(pBuf); 195 return pu8; 196 } 197 198 199 /** 200 * Skips to the next (read) frame in the buffer. 201 * 202 * @param pBuf The buffer. 203 * @param pRingBuf The ring buffer in question. 204 */ 205 DECLINLINE(void) INTNETRingSkipFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf) 206 { 207 uint32_t offRead = pRingBuf->offRead; 208 PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offRead); 209 Assert(pRingBuf->offRead < pBuf->cbBuf); 210 Assert(pRingBuf->offRead >= pRingBuf->offStart); 211 Assert(pRingBuf->offRead < pRingBuf->offEnd); 212 213 /* skip the frame */ 214 offRead += pHdr->offFrame + pHdr->cbFrame; 215 offRead = RT_ALIGN_32(offRead, sizeof(INTNETHDR)); 216 Assert(offRead <= pRingBuf->offEnd && offRead >= pRingBuf->offStart); 217 if (offRead >= pRingBuf->offEnd) 218 offRead = pRingBuf->offStart; 219 ASMAtomicXchgU32(&pRingBuf->offRead, offRead); 220 } 232 #define INTNETHDR_TYPE_FRAME 0x2442 233 234 /** 235 * Asserts the sanity of the specified INTNETHDR. 236 */ 237 #define INTNETHDR_ASSERT_SANITY(pHdr, pRingBuf) \ 238 do \ 239 { \ 240 AssertPtr(pHdr); \ 241 Assert(RT_ALIGN_PT(pHdr, INTNETHDR_ALIGNMENT, INTNETHDR *) == pHdr); \ 242 Assert((pHdr)->u16Type == INTNETHDR_TYPE_FRAME); \ 243 { \ 244 uintptr_t const offHdr = (uintptr_t)pHdr - (uintptr_t)pRingBuf; \ 245 uintptr_t const offFrame = offHdr + (pHdr)->offFrame; \ 246 \ 247 Assert(offHdr >= (pRingBuf)->offStart); \ 248 Assert(offHdr < (pRingBuf)->offEnd); \ 249 \ 250 /* could do more thorough work here... later, perhaps. */ \ 251 Assert(offFrame >= (pRingBuf)->offStart); \ 252 Assert(offFrame < (pRingBuf)->offEnd); \ 253 } \ 254 } while (0) 221 255 222 256 -
trunk/include/VBox/pdmnetifs.h
r26305 r26574 190 190 * when this is a buffer of the required size available. 191 191 * @retval VERR_NO_MEMORY if really out of buffer space. 192 * @retval VERR_NET_DOWN if we cannot send anything to the network at this 193 * point in time. Drop the frame with a xmit error. This is typically 194 * only seen when pausing the VM since the device keeps the link state, 195 * but there could of course be races. 192 196 * 193 197 * @param pInterface Pointer to the interface structure containing the called function pointer. … … 222 226 * 223 227 * @retval VINF_SUCCESS on success. 224 * @retval VERR_NET_NO_NETWORK if the NIC is not connected to a network. 225 * 226 * @param pInterface Pointer to the interface structure containing the called function pointer. 228 * @retval VERR_NET_DOWN if the NIC is not connected to a network. pSgBuf will 229 * be freed. 230 * @retval VERR_NET_NO_BUFFER_SPACE if we're out of resources. pSgBuf will be 231 * freed. 232 * 233 * @param pInterface Pointer to the interface structure containing the 234 * called function pointer. 227 235 * @param pSgBuf The buffer containing the data to send. The buffer 228 * ownership shall be 1. Upon sucessfull return the 229 * buffer will be owned by the downstream driver and 230 * have ownership set to 2. The caller must not ever 231 * touch it again. On failure the buffer remains in 232 * the callers ownership and it should be handed over 233 * to PDMINETWORKUP::pfnFreeBuf. 236 * ownership shall be 1. The buffer will always be 237 * consumed, regardless of the status code. 238 * 234 239 * @param fOnWorkerThread Set if we're being called on a work thread. Clear 235 240 * if an EMT.
Note:
See TracChangeset
for help on using the changeset viewer.