diff options
author | Felix Geyer <debfx-pkg@fobos.de> | 2010-08-06 21:27:11 +0200 |
---|---|---|
committer | Felix Geyer <debfx-pkg@fobos.de> | 2010-08-06 21:27:11 +0200 |
commit | adf97a4e6386ea334ce8d77f0cde3b92454b9fa5 (patch) | |
tree | 62a6d6e6a4743f2aa3e55fa0cdc850fb1d6a2eb9 /src/VBox/Runtime | |
parent | 3cc524b669caddac0b3c8c8fd0b57eaff7f490eb (diff) | |
download | virtualbox-adf97a4e6386ea334ce8d77f0cde3b92454b9fa5.tar.gz |
Imported Upstream version 3.2.8-dfsgupstream/3.2.8-dfsg
Diffstat (limited to 'src/VBox/Runtime')
-rw-r--r-- | src/VBox/Runtime/common/misc/sg.cpp | 43 | ||||
-rw-r--r-- | src/VBox/Runtime/common/string/utf-8.cpp | 23 | ||||
-rw-r--r-- | src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp | 8 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/socket.cpp | 102 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/tcp.cpp | 16 | ||||
-rw-r--r-- | src/VBox/Runtime/testcase/tstRTStrAlloc.cpp | 2 | ||||
-rw-r--r-- | src/VBox/Runtime/testcase/tstUtf8.cpp | 58 |
7 files changed, 196 insertions, 56 deletions
diff --git a/src/VBox/Runtime/common/misc/sg.cpp b/src/VBox/Runtime/common/misc/sg.cpp index f5f1ad8f7..d49c947ae 100644 --- a/src/VBox/Runtime/common/misc/sg.cpp +++ b/src/VBox/Runtime/common/misc/sg.cpp @@ -36,7 +36,7 @@ static void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData) { size_t cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft); - void *pvBuf = pSgBuf->pvSegCurr; + void *pvBuf = pSgBuf->pvSegCur; pSgBuf->cbSegLeft -= cbData; @@ -45,37 +45,38 @@ static void *sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData) { pSgBuf->idxSeg++; - if (RT_UNLIKELY(pSgBuf->idxSeg == pSgBuf->cSeg)) + if (RT_UNLIKELY(pSgBuf->idxSeg == pSgBuf->cSegs)) { pSgBuf->cbSegLeft = 0; - pSgBuf->pvSegCurr = NULL; + pSgBuf->pvSegCur = NULL; } else { - pSgBuf->pvSegCurr = pSgBuf->pcaSeg[pSgBuf->idxSeg].pvSeg; - pSgBuf->cbSegLeft = pSgBuf->pcaSeg[pSgBuf->idxSeg].cbSeg; + pSgBuf->pvSegCur = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg; + pSgBuf->cbSegLeft = pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg; } *pcbData = cbData; } else - pSgBuf->pvSegCurr = (void *)((uintptr_t)pSgBuf->pvSegCurr + cbData); + pSgBuf->pvSegCur = (uint8_t *)pSgBuf->pvSegCur + cbData; return pvBuf; } -RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG pcaSeg, unsigned cSeg) +RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, size_t cSegs) { - AssertPtrReturnVoid(pSgBuf); - AssertPtrReturnVoid(pcaSeg); - AssertReturnVoid(cSeg > 0); + AssertPtr(pSgBuf); + AssertPtr(paSegs); + Assert(cSegs > 0); + Assert(cSegs < (~(unsigned)0 >> 1)); - pSgBuf->pcaSeg = pcaSeg; - pSgBuf->cSeg = cSeg; + pSgBuf->paSegs = paSegs; + pSgBuf->cSegs = (unsigned)cSegs; pSgBuf->idxSeg = 0; - pSgBuf->pvSegCurr = pcaSeg[0].pvSeg; - pSgBuf->cbSegLeft = pcaSeg[0].cbSeg; + pSgBuf->pvSegCur = paSegs[0].pvSeg; + pSgBuf->cbSegLeft = paSegs[0].cbSeg; } @@ -84,20 +85,20 @@ RTDECL(void) RTSgBufReset(PRTSGBUF pSgBuf) AssertPtrReturnVoid(pSgBuf); pSgBuf->idxSeg = 0; - pSgBuf->pvSegCurr = pSgBuf->pcaSeg[0].pvSeg; - pSgBuf->cbSegLeft = pSgBuf->pcaSeg[0].cbSeg; + pSgBuf->pvSegCur = pSgBuf->paSegs[0].pvSeg; + pSgBuf->cbSegLeft = pSgBuf->paSegs[0].cbSeg; } RTDECL(void) RTSgBufClone(PRTSGBUF pSgBufTo, PCRTSGBUF pSgBufFrom) { - AssertPtrReturnVoid(pSgBufTo); - AssertPtrReturnVoid(pSgBufFrom); + AssertPtr(pSgBufTo); + AssertPtr(pSgBufFrom); - pSgBufTo->pcaSeg = pSgBufFrom->pcaSeg; - pSgBufTo->cSeg = pSgBufFrom->cSeg; + pSgBufTo->paSegs = pSgBufFrom->paSegs; + pSgBufTo->cSegs = pSgBufFrom->cSegs; pSgBufTo->idxSeg = pSgBufFrom->idxSeg; - pSgBufTo->pvSegCurr = pSgBufFrom->pvSegCurr; + pSgBufTo->pvSegCur = pSgBufFrom->pvSegCur; pSgBufTo->cbSegLeft = pSgBufFrom->cbSegLeft; } diff --git a/src/VBox/Runtime/common/string/utf-8.cpp b/src/VBox/Runtime/common/string/utf-8.cpp index d6cbb28ba..cfc39e2dc 100644 --- a/src/VBox/Runtime/common/string/utf-8.cpp +++ b/src/VBox/Runtime/common/string/utf-8.cpp @@ -327,6 +327,29 @@ RTDECL(bool) RTStrIsValidEncoding(const char *psz) RT_EXPORT_SYMBOL(RTStrIsValidEncoding); +RTDECL(size_t) RTStrPurgeEncoding(char *psz) +{ + size_t cErrors = 0; + for (;;) + { + RTUNICP Cp; + int rc = RTStrGetCpEx((const char **)&psz, &Cp); + if (RT_SUCCESS(rc)) + { + if (!Cp) + break; + } + else + { + psz[-1] = '?'; + cErrors++; + } + } + return cErrors; +} +RT_EXPORT_SYMBOL(RTStrPurgeEncoding); + + RTDECL(int) RTStrToUni(const char *pszString, PRTUNICP *ppaCps) { /* diff --git a/src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp b/src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp index e9dd1e913..875780ed3 100644 --- a/src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp +++ b/src/VBox/Runtime/r0drv/nt/initterm-r0drv-nt.cpp @@ -224,6 +224,14 @@ int rtR0InitNative(void) g_cbrtNtPbQuantumEnd = 1; g_offrtNtPbDpcQueueDepth = 0x3400 + 0x18; } + /* Windows7.7600.16539.amd64fre.win7_gdr.100226-1909 */ + else if ( BuildNumber == 7600 + && !memcmp(&pbPrcb[0x4bb8], &u.szVendor[0], 4*3)) + { + g_offrtNtPbQuantumEnd = 0x21d9; + g_cbrtNtPbQuantumEnd = 1; + g_offrtNtPbDpcQueueDepth = 0x2180 + 0x18; + } #else # error "port me" diff --git a/src/VBox/Runtime/r3/socket.cpp b/src/VBox/Runtime/r3/socket.cpp index 9f3caa48e..4e7fbba89 100644 --- a/src/VBox/Runtime/r3/socket.cpp +++ b/src/VBox/Runtime/r3/socket.cpp @@ -51,6 +51,7 @@ #include "internal/iprt.h" #include <iprt/socket.h> +#include <iprt/alloca.h> #include <iprt/asm.h> #include <iprt/assert.h> #include <iprt/err.h> @@ -585,70 +586,103 @@ RTDECL(int) RTSocketSgWrite(RTSOCKET hSocket, PCRTSGBUF pSgBuf) AssertPtrReturn(pThis, VERR_INVALID_HANDLE); AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); AssertPtrReturn(pSgBuf, VERR_INVALID_PARAMETER); - AssertReturn(pSgBuf->cSeg > 0, VERR_INVALID_PARAMETER); + AssertReturn(pSgBuf->cSegs > 0, VERR_INVALID_PARAMETER); AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); /* * Construct message descriptor (translate pSgBuf) and send it. */ - int rc = VINF_SUCCESS; - do - { + int rc = VERR_NO_TMP_MEMORY; #ifdef RT_OS_WINDOWS - AssertCompileSize(WSABUF, sizeof(RTSGSEG)); - AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); + AssertCompileSize(WSABUF, sizeof(RTSGSEG)); + AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); - LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSeg * sizeof(WSABUF)); - AssertPtrBreakStmt(paMsg, rc = VERR_NO_MEMORY); - for (unsigned i = 0; i < pSgBuf->cSeg; i++) + LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(WSABUF)); + if (paMsg) + { + for (unsigned i = 0; i < pSgBuf->cSegs; i++) { - paMsg[i].buf = (char *)pSgBuf->pcaSeg[i].pvSeg; - paMsg[i].len = (u_long)pSgBuf->pcaSeg[i].cbSeg; + paMsg[i].buf = (char *)pSgBuf->paSegs[i].pvSeg; + paMsg[i].len = (u_long)pSgBuf->paSegs[i].cbSeg; } DWORD dwSent; - int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSeg, &dwSent, + int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSegs, &dwSent, MSG_NOSIGNAL, NULL, NULL); - ssize_t cbWritten; if (!hrc) - { - /* avoid overflowing ssize_t, the exact value isn't important */ - cbWritten = RT_MIN(dwSent, INT_MAX); - } + rc = VINF_SUCCESS; +/** @todo check for incomplete writes */ else - cbWritten = -1; -#else - AssertCompileSize(struct iovec, sizeof(RTSGSEG)); - AssertCompileMemberSize(struct iovec, iov_base, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); - AssertCompileMemberSize(struct iovec, iov_len, RT_SIZEOFMEMB(RTSGSEG, cbSeg)); + rc = rtSocketError(); - struct iovec *paMsg = (struct iovec *)RTMemTmpAllocZ(pSgBuf->cSeg * sizeof(struct iovec)); - AssertPtrBreakStmt(paMsg, rc = VERR_NO_MEMORY); - for (unsigned i = 0; i < pSgBuf->cSeg; i++) + RTMemTmpFree(paMsg); + } + +#else /* !RT_OS_WINDOWS */ + AssertCompileSize(struct iovec, sizeof(RTSGSEG)); + AssertCompileMemberSize(struct iovec, iov_base, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); + AssertCompileMemberSize(struct iovec, iov_len, RT_SIZEOFMEMB(RTSGSEG, cbSeg)); + + struct iovec *paMsg = (struct iovec *)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(struct iovec)); + if (paMsg) + { + for (unsigned i = 0; i < pSgBuf->cSegs; i++) { - paMsg[i].iov_base = pSgBuf->pcaSeg[i].pvSeg; - paMsg[i].iov_len = pSgBuf->pcaSeg[i].cbSeg; + paMsg[i].iov_base = pSgBuf->paSegs[i].pvSeg; + paMsg[i].iov_len = pSgBuf->paSegs[i].cbSeg; } struct msghdr msgHdr; - memset(&msgHdr, '\0', sizeof(msgHdr)); - msgHdr.msg_iov = paMsg; - msgHdr.msg_iovlen = pSgBuf->cSeg; + RT_ZERO(msgHdr); + msgHdr.msg_iov = paMsg; + msgHdr.msg_iovlen = pSgBuf->cSegs; ssize_t cbWritten = sendmsg(pThis->hNative, &msgHdr, MSG_NOSIGNAL); -#endif - - RTMemTmpFree(paMsg); if (RT_LIKELY(cbWritten >= 0)) rc = VINF_SUCCESS; +/** @todo check for incomplete writes */ else rc = rtSocketError(); - } while (0); + + RTMemTmpFree(paMsg); + } +#endif /* !RT_OS_WINDOWS */ rtSocketUnlock(pThis); return rc; } +RTDECL(int) RTSocketSgWriteL(RTSOCKET hSocket, size_t cSegs, ...) +{ + va_list va; + va_start(va, cSegs); + int rc = RTSocketSgWriteLV(hSocket, cSegs, va); + va_end(va); + return rc; +} + + +RTDECL(int) RTSocketSgWriteLV(RTSOCKET hSocket, size_t cSegs, va_list va) +{ + /* + * Set up a S/G segment array + buffer on the stack and pass it + * on to RTSocketSgWrite. + */ + Assert(cSegs <= 16); + PRTSGSEG paSegs = (PRTSGSEG)alloca(cSegs * sizeof(RTSGSEG)); + AssertReturn(paSegs, VERR_NO_TMP_MEMORY); + for (size_t i = 0; i < cSegs; i++) + { + paSegs[i].pvSeg = va_arg(va, void *); + paSegs[i].cbSeg = va_arg(va, size_t); + } + + RTSGBUF SgBuf; + RTSgBufInit(&SgBuf, paSegs, cSegs); + return RTSocketSgWrite(hSocket, &SgBuf); +} + + RTDECL(int) RTSocketSelectOne(RTSOCKET hSocket, RTMSINTERVAL cMillies) { /* diff --git a/src/VBox/Runtime/r3/tcp.cpp b/src/VBox/Runtime/r3/tcp.cpp index 05b6dc7b8..e333e71d3 100644 --- a/src/VBox/Runtime/r3/tcp.cpp +++ b/src/VBox/Runtime/r3/tcp.cpp @@ -1019,3 +1019,19 @@ RTR3DECL(int) RTTcpSgWrite(RTSOCKET Sock, PCRTSGBUF pSgBuf) return RTSocketSgWrite(Sock, pSgBuf); } + +RTR3DECL(int) RTTcpSgWriteL(RTSOCKET hSocket, size_t cSegs, ...) +{ + va_list va; + va_start(va, cSegs); + int rc = RTSocketSgWriteLV(hSocket, cSegs, va); + va_end(va); + return rc; +} + + +RTR3DECL(int) RTTcpSgWriteLV(RTSOCKET hSocket, size_t cSegs, va_list va) +{ + return RTSocketSgWriteLV(hSocket, cSegs, va); +} + diff --git a/src/VBox/Runtime/testcase/tstRTStrAlloc.cpp b/src/VBox/Runtime/testcase/tstRTStrAlloc.cpp index b1d92a710..daf872458 100644 --- a/src/VBox/Runtime/testcase/tstRTStrAlloc.cpp +++ b/src/VBox/Runtime/testcase/tstRTStrAlloc.cpp @@ -42,7 +42,7 @@ static void tst1(void) { RTTestISub("Basics"); char *psz; - int rc; + int rc = VINF_SUCCESS; /* RTStrAlloc */ RTTESTI_CHECK(psz = RTStrAlloc(0)); diff --git a/src/VBox/Runtime/testcase/tstUtf8.cpp b/src/VBox/Runtime/testcase/tstUtf8.cpp index 6dcf55afb..cb55786e8 100644 --- a/src/VBox/Runtime/testcase/tstUtf8.cpp +++ b/src/VBox/Runtime/testcase/tstUtf8.cpp @@ -790,6 +790,63 @@ void TstRTStrXCmp(RTTEST hTest) /** + * Check case insensitivity. + */ +void TstRTStrPurgeEncoding(RTTEST hTest) +{ + RTTestSub(hTest, "RTStrPurgeEncoding"); + + /* + * Test some good strings. + */ + char sz1[] = "1234567890wertyuiopsdfghjklzxcvbnm"; + char sz1Copy[sizeof(sz1)]; + memcpy(sz1Copy, sz1, sizeof(sz1)); + + RTTESTI_CHECK_RETV(RTStrPurgeEncoding(sz1) == 0); + RTTESTI_CHECK_RETV(!memcmp(sz1, sz1Copy, sizeof(sz1))); + + char *pszAll = RTStrDup(g_szAll); + if (pszAll) + { + RTTESTI_CHECK(RTStrPurgeEncoding(pszAll) == 0); + RTTESTI_CHECK(!memcmp(pszAll, g_szAll, sizeof(g_szAll))); + RTStrFree(pszAll); + } + + /* + * Test some bad stuff. + */ + struct + { + size_t cErrors; + unsigned char szIn[5]; + const char *pszExpect; + } aTests[] = + { + { 0, { '1', '2', '3', '4', '\0' }, "1234" }, + { 1, { 0x80, '2', '3', '4', '\0' }, "?234" }, + { 1, { '1', 0x80, '3', '4', '\0' }, "1?34" }, + { 1, { '1', '2', 0x80, '4', '\0' }, "12?4" }, + { 1, { '1', '2', '3', 0x80, '\0' }, "123?" }, + { 2, { 0x80, 0x81, '3', '4', '\0' }, "??34" }, + { 2, { '1', 0x80, 0x81, '4', '\0' }, "1??4" }, + { 2, { '1', '2', 0x80, 0x81, '\0' }, "12??" }, + }; + for (size_t i = 0; i < RT_ELEMENTS(aTests); i++) + { + size_t cErrors = RTStrPurgeEncoding((char *)aTests[i].szIn); + if (cErrors != aTests[i].cErrors) + RTTestFailed(hTest, "#%u: cErrors=%u expected %u\n", i, cErrors, aTests[i].cErrors); + else if (strcmp((char *)aTests[i].szIn, aTests[i].pszExpect)) + RTTestFailed(hTest, "#%u: %.5Rhxs expected %.5Rhxs (%s)\n", i, aTests[i].szIn, aTests[i].pszExpect, aTests[i].pszExpect); + } + + RTTestSubDone(hTest); +} + + +/** * Benchmark stuff. */ void Benchmarks(RTTEST hTest) @@ -1234,6 +1291,7 @@ int main() test2(hTest); test3(hTest); TstRTStrXCmp(hTest); + TstRTStrPurgeEncoding(hTest); testStrEnd(hTest); testStrStr(hTest); testMinistring(hTest); |