Changeset 21871 in vbox
- Timestamp:
- Jul 30, 2009 9:30:27 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/SSM-new.cpp
r21866 r21871 295 295 uint64_t offStream; 296 296 /** The amount of buffered data. */ 297 size_tcb;297 uint32_t cb; 298 298 /** End of stream indicator (for read streams only). */ 299 299 bool fEndOfStream; … … 317 317 /** Termination indicator. */ 318 318 bool volatile fTerminating; 319 /** Indicates whether it is necessary to seek before the next buffer is 320 * read from the stream. This is used to avoid a seek in ssmR3StrmPeekAt. */ 321 bool fNeedSeek; 319 322 /** Stream error status. */ 320 323 int32_t volatile rc; 324 /** The handle of the I/O thread. This is set to nil when not active. */ 325 RTTHREAD hIoThread; 321 326 322 327 /** The head of the consumer queue. … … 1361 1366 */ 1362 1367 pStrm->fTerminating = false; 1368 pStrm->fNeedSeek = false; 1363 1369 pStrm->rc = VINF_SUCCESS; 1370 pStrm->hIoThread = NIL_RTTHREAD; 1364 1371 1365 1372 pStrm->pHead = NULL; … … 1542 1549 for (;;) 1543 1550 { 1544 PSSMSTRMBUF pMine = (PSSMSTRMBUF)ASMAtomicUoReadPtr((void * volatile *) pStrm->pFree);1551 PSSMSTRMBUF pMine = (PSSMSTRMBUF)ASMAtomicUoReadPtr((void * volatile *)&pStrm->pFree); 1545 1552 if (!pMine) 1546 1553 { … … 1632 1639 } 1633 1640 1634 pMine = (PSSMSTRMBUF)ASMAtomicXchgPtr((void * volatile *) pStrm->pHead, NULL);1641 pMine = (PSSMSTRMBUF)ASMAtomicXchgPtr((void * volatile *)&pStrm->pHead, NULL); 1635 1642 if (pMine) 1636 1643 pStrm->pPending = ssmR3StrmReverseList(pMine); … … 1659 1666 if (pStrm->pCur) 1660 1667 { 1661 PSSMSTRMBUF p Cur= pStrm->pCur;1668 PSSMSTRMBUF pBuf = pStrm->pCur; 1662 1669 pStrm->pCur = NULL; 1663 1670 … … 1665 1672 { 1666 1673 uint32_t cb = pStrm->off; 1667 p Cur->cb = cb;1668 p Cur->offStream = pStrm->offCurStream;1674 pBuf->cb = cb; 1675 pBuf->offStream = pStrm->offCurStream; 1669 1676 if ( pStrm->fChecksummed 1670 1677 && pStrm->offStreamCRC < cb) 1671 1678 pStrm->u32StreamCRC = RTCrc32Process(pStrm->u32StreamCRC, 1672 &p Cur->abData[pStrm->offStreamCRC],1679 &pBuf->abData[pStrm->offStreamCRC], 1673 1680 cb - pStrm->offStreamCRC); 1674 1681 pStrm->offCurStream += cb; … … 1676 1683 pStrm->offStreamCRC = 0; 1677 1684 1678 ssmR3StrmPutBuf(pStrm, p Cur);1685 ssmR3StrmPutBuf(pStrm, pBuf); 1679 1686 } 1680 1687 else 1681 1688 { 1682 uint32_t cb = p Cur->cb;1689 uint32_t cb = pBuf->cb; 1683 1690 if ( pStrm->fChecksummed 1684 1691 && pStrm->offStreamCRC < cb) 1685 1692 pStrm->u32StreamCRC = RTCrc32Process(pStrm->u32StreamCRC, 1686 &p Cur->abData[pStrm->offStreamCRC],1693 &pBuf->abData[pStrm->offStreamCRC], 1687 1694 cb - pStrm->offStreamCRC); 1688 1695 pStrm->offCurStream += cb; … … 1690 1697 pStrm->offStreamCRC = 0; 1691 1698 1692 ssmR3StrmPutFreeBuf(pStrm, p Cur);1699 ssmR3StrmPutFreeBuf(pStrm, pBuf); 1693 1700 } 1694 1701 } … … 1795 1802 if (RT_LIKELY(pBuf)) 1796 1803 { 1797 uint32_t cbLeft = pStrm->off - RT_SIZEOFMEMB(SSMSTRMBUF, abData);1804 uint32_t cbLeft = RT_SIZEOFMEMB(SSMSTRMBUF, abData) - pStrm->off; 1798 1805 if (RT_LIKELY(cbLeft >= cbToWrite)) 1799 1806 { 1800 1807 memcpy(&pBuf->abData[pStrm->off], pvBuf, cbToWrite); 1801 pStrm->off += cbToWrite;1808 pStrm->off += (uint32_t)cbToWrite; 1802 1809 return VINF_SUCCESS; 1803 1810 } … … 1810 1817 pvBuf = (uint8_t const *)pvBuf + cbLeft; 1811 1818 } 1819 Assert(pStrm->off == RT_SIZEOFMEMB(SSMSTRMBUF, abData)); 1812 1820 } 1813 1821 … … 1832 1840 * Copy data to the buffer. 1833 1841 */ 1834 uint32_t cbCopy = pStrm->off -RT_SIZEOFMEMB(SSMSTRMBUF, abData);1842 uint32_t cbCopy = RT_SIZEOFMEMB(SSMSTRMBUF, abData); 1835 1843 if (cbCopy > cbToWrite) 1836 cbCopy = cbToWrite;1837 memcpy(&pBuf->abData[ pStrm->off], pvBuf, cbCopy);1838 pStrm->off += cbCopy;1844 cbCopy = (uint32_t)cbToWrite; 1845 memcpy(&pBuf->abData[0], pvBuf, cbCopy); 1846 pStrm->off = cbCopy; 1839 1847 cbToWrite -= cbCopy; 1840 1848 pvBuf = (uint8_t const *)pvBuf + cbCopy; … … 1856 1864 static int ssmR3StrmReadMore(PSSMSTRM pStrm) 1857 1865 { 1866 int rc; 1867 1868 /* 1869 * Undo seek done by ssmR3StrmPeekAt. 1870 */ 1871 if (pStrm->fNeedSeek) 1872 { 1873 rc = RTFileSeek(pStrm->hFile, pStrm->offCurStream + pStrm->off, RTFILE_SEEK_BEGIN, NULL); 1874 if (RT_FAILURE(rc)) 1875 { 1876 if (ssmR3StrmSetError(pStrm, rc)) 1877 LogRel(("ssmR3StrmReadMore: RTFileSeek(,%#llx,) failed with rc=%Rrc\n", pStrm->offCurStream + pStrm->off, rc)); 1878 return rc; 1879 } 1880 1881 } 1882 1883 /* 1884 * Get a free buffer and try fill it up. 1885 */ 1858 1886 PSSMSTRMBUF pBuf = ssmR3StrmGetFreeBuf(pStrm); 1859 1887 if (!pBuf) 1860 1888 return pStrm->rc; 1861 1889 1862 pBuf->offStream = RTFileTell(pStrm->hFile); 1890 pBuf->offStream = pStrm->offCurStream + pStrm->off; 1891 Assert(pBuf->offStream == RTFileTell(pStrm->hFile)); 1863 1892 size_t cbRead = sizeof(pBuf->abData); 1864 intrc = RTFileRead(pStrm->hFile, &pBuf->abData[0], cbRead, &cbRead);1893 rc = RTFileRead(pStrm->hFile, &pBuf->abData[0], cbRead, &cbRead); 1865 1894 if (RT_SUCCESS(rc)) 1866 1895 { 1867 pBuf->cb = cbRead;1868 pBuf->fEndOfStream = cbRead == 0; 1896 pBuf->cb = (uint32_t)cbRead; 1897 pBuf->fEndOfStream = cbRead == 0; /** @todo Check out this EOF mess... */ 1869 1898 ssmR3StrmPutBuf(pStrm, pBuf); 1870 1899 } … … 1906 1935 { 1907 1936 Assert(pStrm->off <= pBuf->cb); 1908 uint32_t cbLeft = p Strm->off - pBuf->cb;1937 uint32_t cbLeft = pBuf->cb - pStrm->off; 1909 1938 if (cbLeft >= cbToRead) 1910 1939 { 1911 1940 memcpy(pvBuf, &pBuf->abData[pStrm->off], cbToRead); 1912 pStrm->off += cbToRead; 1941 pStrm->off += (uint32_t)cbToRead; 1942 Assert(pStrm->off <= pBuf->cb); 1913 1943 return VINF_SUCCESS; 1914 1944 } … … 1922 1952 else if (pBuf->fEndOfStream) 1923 1953 return VERR_EOF; 1954 Assert(pStrm->off == pBuf->cb); 1924 1955 } 1925 1956 … … 1962 1993 * Read data from the buffer. 1963 1994 */ 1964 uint32_t cbCopy = p Strm->off - pBuf->cb;1995 uint32_t cbCopy = pBuf->cb; 1965 1996 if (cbCopy > cbToRead) 1966 cbCopy = cbToRead;1967 memcpy(pvBuf, &pBuf->abData[ pStrm->off], cbCopy);1968 pStrm->off += cbCopy;1997 cbCopy = (uint32_t)cbToRead; 1998 memcpy(pvBuf, &pBuf->abData[0], cbCopy); 1999 pStrm->off = cbCopy; 1969 2000 cbToRead -= cbCopy; 1970 2001 pvBuf = (uint8_t *)pvBuf + cbCopy; 2002 Assert(!pStrm->pCur || pStrm->off <= pStrm->pCur->cb); 1971 2003 } while (cbToRead > 0); 1972 2004 … … 2000 2032 { 2001 2033 PSSMSTRMBUF pBuf = pStrm->pCur; Assert(pBuf); 2002 pStrm->u32StreamCRC = RTCrc32Process(pStrm->u32StreamCRC, &pBuf->abData[pStrm->off], pStrm->off - pStrm->offStreamCRC); 2034 pStrm->u32StreamCRC = RTCrc32Process(pStrm->u32StreamCRC, &pBuf->abData[pStrm->offStreamCRC], pStrm->off - pStrm->offStreamCRC); 2035 //if (pStrm->offStreamCRC == 0 && pStrm->off == 0x40) 2036 // LogAlways(("ssmR3StrmCurCRC: %08x\n%.64Rhxd\n", pStrm->u32StreamCRC, pBuf->abData)); 2037 pStrm->offStreamCRC = pStrm->off; 2003 2038 } 2004 2039 else … … 2030 2065 { 2031 2066 pStrm->fChecksummed = false; 2067 } 2068 2069 2070 /** 2071 * 2072 * @returns VBox stutus code. 2073 * @param pStrm The strem handle. 2074 * @param off The seek offset. 2075 * @param uMethod The seek method. 2076 * @param poff Where to optionally store the new file offset. 2077 */ 2078 static int ssmR3StrmSeek(PSSMSTRM pStrm, int64_t off, uint32_t uMethod, uint64_t *poff) 2079 { 2080 AssertReturn(!pStrm->fWrite, VERR_NOT_SUPPORTED); 2081 AssertReturn(pStrm->hIoThread == NIL_RTTHREAD, VERR_WRONG_ORDER); 2082 2083 uint64_t offStream; 2084 int rc = RTFileSeek(pStrm->hFile, off, uMethod, &offStream); 2085 if (RT_SUCCESS(rc)) 2086 { 2087 pStrm->offCurStream = offStream; 2088 pStrm->off = 0; 2089 pStrm->offStreamCRC = 0; 2090 pStrm->u32StreamCRC = 0; 2091 if (pStrm->pCur) 2092 { 2093 ssmR3StrmPutFreeBuf(pStrm, pStrm->pCur); 2094 pStrm->pCur = NULL; 2095 } 2096 if (poff) 2097 *poff = offStream; 2098 } 2099 return rc; 2032 2100 } 2033 2101 … … 2079 2147 2080 2148 2149 /*** 2150 * Tests if the stream is a file stream or not. 2151 * 2152 * @returns true / false. 2153 * @param pStrm The stream handle. 2154 */ 2155 static bool ssmR3StrmIsFile(PSSMSTRM pStrm) 2156 { 2157 return pStrm->hFile != NIL_RTFILE; 2158 } 2159 2160 2161 /** 2162 * Peeks at data in a file stream without buffering anything (or upsetting 2163 * the buffering for that matter). 2164 * 2165 * @returns VBox status code. 2166 * @param pStrm The stream handle 2167 * @param off The offset to start peeking at. Use a negative offset to 2168 * peek at something relative to the end of the file. 2169 * @param pvBuf Output buffer. 2170 * @param cbToRead How much to read. 2171 * @param poff Where to optionally store the position. Useful when 2172 * using a negative off. 2173 * 2174 * @remarks Failures occuring while peeking will not be raised on the stream. 2175 */ 2176 static int ssmR3StrmPeekAt(PSSMSTRM pStrm, RTFOFF off, void *pvBuf, size_t cbToRead, uint64_t *poff) 2177 { 2178 AssertReturn(!pStrm->fWrite && pStrm->hFile != NIL_RTFILE, VERR_NOT_SUPPORTED); 2179 AssertReturn(pStrm->hIoThread == NIL_RTTHREAD, VERR_WRONG_ORDER); 2180 2181 pStrm->fNeedSeek = true; 2182 int rc = RTFileSeek(pStrm->hFile, off, off >= 0 ? RTFILE_SEEK_BEGIN : RTFILE_SEEK_END, poff); 2183 if (RT_SUCCESS(rc)) 2184 rc = RTFileRead(pStrm->hFile, pvBuf, cbToRead, NULL); 2185 2186 return rc; 2187 } 2188 2189 2081 2190 2082 2191 /** … … 2084 2193 * 2085 2194 * @returns VBox status. 2086 * @param File Handle to the file. Positioned where to start2087 * 2088 * @param cb File The portion of the fileto checksum.2195 * @param pStrm The stream handle 2196 * @param off Where to start checksumming. 2197 * @param cb How much to checksum. 2089 2198 * @param pu32CRC Where to store the calculated checksum. 2090 2199 */ 2091 static int ssmR3CalcChecksum( RTFILE File, uint64_t cbFile, uint32_t *pu32CRC)2200 static int ssmR3CalcChecksum(PSSMSTRM pStrm, uint64_t off, uint64_t cb, uint32_t *pu32CRC) 2092 2201 { 2093 2202 /* 2094 2203 * Allocate a buffer. 2095 2204 */ 2096 void *pvBuf = RTMemTmpAlloc(32*1024); 2205 const size_t cbBuf = _32K; 2206 void *pvBuf = RTMemTmpAlloc(cbBuf); 2097 2207 if (!pvBuf) 2098 2208 return VERR_NO_TMP_MEMORY; … … 2101 2211 * Loop reading and calculating CRC32. 2102 2212 */ 2103 int rc = VINF_SUCCESS;2213 int rc = VINF_SUCCESS; 2104 2214 uint32_t u32CRC = RTCrc32Start(); 2105 while (cb File)2215 while (cb > 0) 2106 2216 { 2107 2217 /* read chunk */ 2108 register unsigned cbToRead = 32*1024;2109 if (cb File < 32*1024)2110 cbToRead = (unsigned)cbFile;2111 rc = RTFileRead(File, pvBuf, cbToRead, NULL);2218 size_t cbToRead = cbBuf; 2219 if (cb < cbBuf) 2220 cbToRead = cb; 2221 rc = ssmR3StrmPeekAt(pStrm, off, pvBuf, cbToRead, NULL); 2112 2222 if (RT_FAILURE(rc)) 2113 2223 { … … 2118 2228 2119 2229 /* update total */ 2120 cb File-= cbToRead;2230 cb -= cbToRead; 2121 2231 2122 2232 /* calc crc32. */ 2123 u32CRC = RTCrc32Process(u32CRC, pvBuf, 2233 u32CRC = RTCrc32Process(u32CRC, pvBuf, cbToRead); 2124 2234 } 2125 2235 RTMemTmpFree(pvBuf); … … 2747 2857 2748 2858 /* 2749 * Read and validate the footer .2859 * Read and validate the footer if it's a file. 2750 2860 */ 2751 /** @todo this needs to be fixed when starting to buffer input using a separate thread. */ 2752 uint64_t offRestore = RTFileTell(pSSM->Strm.hFile); 2753 SSMFILEFTR Footer; 2754 uint64_t offFooter; 2755 rc = RTFileSeek(pSSM->Strm.hFile, -(RTFOFF)sizeof(Footer), RTFILE_SEEK_END, &offFooter); 2756 AssertLogRelRCReturn(rc, rc); 2757 rc = RTFileRead(pSSM->Strm.hFile, &Footer, sizeof(Footer), NULL); 2758 AssertLogRelRCReturn(rc, rc); 2759 if (memcmp(Footer.szMagic, SSMFILEFTR_MAGIC, sizeof(Footer.szMagic))) 2760 { 2761 LogRel(("SSM: Bad footer magic: %.*Rhxs\n", sizeof(Footer.szMagic), &Footer.szMagic[0])); 2762 return VERR_SSM_INTEGRITY; 2763 } 2764 SSM_CHECK_CRC32_RET(&Footer, sizeof(Footer), ("Footer CRC mismatch: %08x, correct is %08x\n", u32CRC, u32ActualCRC)); 2765 if (Footer.offStream != offFooter) 2766 { 2767 LogRel(("SSM: SSMFILEFTR::offStream is wrong: %llx, expected %llx\n", Footer.offStream, offFooter)); 2768 return VERR_SSM_INTEGRITY; 2769 } 2770 if (Footer.u32Reserved) 2771 { 2772 LogRel(("SSM: Reserved footer field isn't zero: %08x\n", Footer.u32Reserved)); 2773 return VERR_SSM_INTEGRITY; 2774 } 2775 if ( !fChecksummed 2776 && Footer.u32StreamCRC) 2777 { 2778 LogRel(("SSM: u32StreamCRC field isn't zero, but header says stream checksumming is disabled.\n")); 2779 return VERR_SSM_INTEGRITY; 2780 } 2781 2782 pSSM->u.Read.cbLoadFile = offFooter + sizeof(Footer); 2783 pSSM->u.Read.u32LoadCRC = Footer.u32StreamCRC; 2861 if (ssmR3StrmIsFile(&pSSM->Strm)) 2862 { 2863 SSMFILEFTR Footer; 2864 uint64_t offFooter; 2865 rc = ssmR3StrmPeekAt(&pSSM->Strm, -(RTFOFF)sizeof(SSMFILEFTR), &Footer, sizeof(Footer), &offFooter); 2866 AssertLogRelRCReturn(rc, rc); 2867 if (memcmp(Footer.szMagic, SSMFILEFTR_MAGIC, sizeof(Footer.szMagic))) 2868 { 2869 LogRel(("SSM: Bad footer magic: %.*Rhxs\n", sizeof(Footer.szMagic), &Footer.szMagic[0])); 2870 return VERR_SSM_INTEGRITY; 2871 } 2872 SSM_CHECK_CRC32_RET(&Footer, sizeof(Footer), ("Footer CRC mismatch: %08x, correct is %08x\n", u32CRC, u32ActualCRC)); 2873 if (Footer.offStream != offFooter) 2874 { 2875 LogRel(("SSM: SSMFILEFTR::offStream is wrong: %llx, expected %llx\n", Footer.offStream, offFooter)); 2876 return VERR_SSM_INTEGRITY; 2877 } 2878 if (Footer.u32Reserved) 2879 { 2880 LogRel(("SSM: Reserved footer field isn't zero: %08x\n", Footer.u32Reserved)); 2881 return VERR_SSM_INTEGRITY; 2882 } 2883 if ( !fChecksummed 2884 && Footer.u32StreamCRC) 2885 { 2886 LogRel(("SSM: u32StreamCRC field isn't zero, but header says stream checksumming is disabled.\n")); 2887 return VERR_SSM_INTEGRITY; 2888 } 2889 2890 pSSM->u.Read.cbLoadFile = offFooter + sizeof(Footer); 2891 pSSM->u.Read.u32LoadCRC = Footer.u32StreamCRC; 2892 } 2893 else 2894 { 2895 pSSM->u.Read.cbLoadFile = UINT64_MAX; 2896 pSSM->u.Read.u32LoadCRC = 0; 2897 } 2784 2898 2785 2899 /* … … 2795 2909 if ( fChecksummed 2796 2910 && fChecksumIt 2797 && !fChecksumOnRead) 2798 { 2799 rc = RTFileSeek(pSSM->Strm.hFile, 0, RTFILE_SEEK_BEGIN, NULL); 2800 AssertLogRelRCReturn(rc, rc); 2911 && !fChecksumOnRead 2912 && ssmR3StrmIsFile(&pSSM->Strm)) 2913 { 2801 2914 uint32_t u32CRC; 2802 rc = ssmR3CalcChecksum( pSSM->Strm.hFile, offFooter, &u32CRC);2915 rc = ssmR3CalcChecksum(&pSSM->Strm, 0, pSSM->u.Read.cbLoadFile - sizeof(SSMFILEFTR), &u32CRC); 2803 2916 if (RT_FAILURE(rc)) 2804 2917 return rc; … … 2809 2922 } 2810 2923 } 2811 2812 rc = RTFileSeek(pSSM->Strm.hFile, RTFILE_SEEK_BEGIN, offRestore, NULL);2813 AssertRCReturn(rc, rc);2814 2924 } 2815 2925 else … … 2894 3004 || fChecksumOnRead) 2895 3005 { 2896 /** @todo this needs to be fixed when starting to buffer input using a separate thread. */2897 uint64_t offRestore = RTFileTell(pSSM->Strm.hFile);2898 rc = RTFileSeek(pSSM->Strm.hFile, RT_OFFSETOF(SSMFILEHDRV11, u32CRC) + sizeof(uHdr.v1_1.u32CRC), RTFILE_SEEK_BEGIN, NULL);2899 AssertLogRelRCReturn(rc, rc);2900 3006 uint32_t u32CRC; 2901 rc = ssmR3CalcChecksum(pSSM->Strm.hFile, cbFile - pSSM->u.Read.cbFileHdr, &u32CRC); 3007 rc = ssmR3CalcChecksum(&pSSM->Strm, 3008 RT_OFFSETOF(SSMFILEHDRV11, u32CRC) + sizeof(uHdr.v1_1.u32CRC), 3009 cbFile - pSSM->u.Read.cbFileHdr, 3010 &u32CRC); 2902 3011 if (RT_FAILURE(rc)) 2903 3012 return rc; … … 2907 3016 return VERR_SSM_INTEGRITY_CRC; 2908 3017 } 2909 rc = RTFileSeek(pSSM->Strm.hFile, RTFILE_SEEK_BEGIN, offRestore, NULL);2910 AssertRCReturn(rc, rc);2911 3018 } 2912 3019 } … … 3203 3310 */ 3204 3311 uint64_t offUnit = ssmR3StrmTell(&pSSM->Strm); 3205 uint32_t u32CurStreamCRC = pSSM->u32StreamCRC;3312 uint32_t u32CurStreamCRC = ssmR3StrmCurCRC(&pSSM->Strm); 3206 3313 SSMFILEUNITHDR UnitHdr; 3207 3314 int rc = ssmR3StrmRead(&pSSM->Strm, &UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName)); … … 3240 3347 return VERR_SSM_INTEGRITY; 3241 3348 } 3242 AssertLogRelMsgReturn(UnitHdr.u32CurStreamCRC == u32CurStreamCRC || !pSSM-> fChecksummed,3349 AssertLogRelMsgReturn(UnitHdr.u32CurStreamCRC == u32CurStreamCRC || !pSSM->Strm.fChecksummed, 3243 3350 ("Unit at %#llx (%lld): Stream CRC mismatch: %08x, correct is %08x\n", offUnit, offUnit, UnitHdr.u32CurStreamCRC, u32CurStreamCRC), VERR_SSM_INTEGRITY); 3244 3351 AssertLogRelMsgReturn(!UnitHdr.fFlags, ("Unit at %#llx (%lld): fFlags=%08x\n", offUnit, offUnit, UnitHdr.fFlags), VERR_SSM_INTEGRITY); … … 3476 3583 if (pfnProgress) 3477 3584 pfnProgress(pVM, 99, pvUser); 3585 3586 ssmR3StrmClose(&Handle.Strm); 3478 3587 } 3479 3588 … … 3481 3590 * Done 3482 3591 */ 3483 ssmR3StrmClose(&Handle.Strm);3484 3592 if (RT_SUCCESS(rc)) 3485 3593 { … … 3595 3703 * Close the stream and free the handle. 3596 3704 */ 3597 ssmR3StrmClose(&Handle.Strm);3705 int rc = ssmR3StrmClose(&pSSM->Strm); 3598 3706 if (pSSM->u.Read.pZipDecompV1) 3599 3707 { … … 3629 3737 * Read the unit header and verify it. 3630 3738 */ 3631 int rc = RTFileReadAt(pSSM->hFile, off, &UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName), NULL); 3739 /** @todo this doesn't work when we get an I/O thread... */ 3740 int rc = RTFileReadAt(pSSM->Strm.hFile, off, &UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName), NULL); 3632 3741 AssertRCReturn(rc, rc); 3633 3742 if (!memcmp(&UnitHdr.achMagic[0], SSMFILEUNITHDR_MAGIC, sizeof(SSMFILEUNITHDR_MAGIC))) … … 3639 3748 && UnitHdr.cchName == cbUnit) 3640 3749 { 3641 rc = RTFileRead(pSSM-> hFile, szName, cbUnit, NULL);3750 rc = RTFileRead(pSSM->Strm.hFile, szName, cbUnit, NULL); 3642 3751 AssertRCReturn(rc, rc); 3643 3752 AssertLogRelMsgReturn(!szName[UnitHdr.cchName - 1], … … 3685 3794 */ 3686 3795 uint64_t const offDir = pSSM->u.Read.cbLoadFile - sizeof(SSMFILEFTR) - cbDir; 3687 int rc = RTFileReadAt(pSSM->hFile, offDir, pDir, cbDir, NULL); 3796 /** @todo this doesn't work when we get an I/O thread... */ 3797 int rc = RTFileReadAt(pSSM->Strm.hFile, offDir, pDir, cbDir, NULL); 3688 3798 AssertLogRelRCReturn(rc, rc); 3689 3799 AssertLogRelReturn(!memcmp(pDir->szMagic, SSMFILEDIR_MAGIC, sizeof(pDir->szMagic)), VERR_SSM_INTEGRITY); … … 3717 3827 RT_ZERO(UnitHdr); 3718 3828 } 3719 rc = RTFileReadAt(pSSM->hFile, pDir->aEntries[i].off, &UnitHdr, cbToRead, NULL); 3829 /** @todo this doesn't work when we get an I/O thread... */ 3830 rc = RTFileReadAt(pSSM->Strm.hFile, pDir->aEntries[i].off, &UnitHdr, cbToRead, NULL); 3720 3831 AssertLogRelRCReturn(rc, rc); 3721 3832 … … 3748 3859 if (piVersion) 3749 3860 *piVersion = UnitHdr.u32Version; 3750 rc = RTFileSeek(pSSM->hFile, pDir->aEntries[i].off + cbUnitHdr, RTFILE_SEEK_BEGIN, NULL); 3861 /** @todo this doesn't work when we get an I/O thread... */ 3862 rc = RTFileSeek(pSSM->Strm.hFile, pDir->aEntries[i].off + cbUnitHdr, RTFILE_SEEK_BEGIN, NULL); 3751 3863 AssertLogRelRCReturn(rc, rc); 3752 3864 3753 if (pSSM-> fChecksummed)3754 pSSM-> u32StreamCRC = RTCrc32Process(UnitHdr.u32CurStreamCRC, &UnitHdr, cbUnitHdr);3865 if (pSSM->Strm.fChecksummed) 3866 pSSM->Strm.u32StreamCRC = RTCrc32Process(UnitHdr.u32CurStreamCRC, &UnitHdr, cbUnitHdr); 3755 3867 3756 3868 ssmR3DataReadBeginV2(pSSM); … … 3780 3892 */ 3781 3893 SSMFILEFTR Footer; 3782 int rc = RTFileReadAt(pSSM->hFile, pSSM->u.Read.cbLoadFile - sizeof(Footer), &Footer, sizeof(Footer), NULL); 3894 /** @todo this doesn't work when we get an I/O thread... */ 3895 int rc = RTFileReadAt(pSSM->Strm.hFile, pSSM->u.Read.cbLoadFile - sizeof(Footer), &Footer, sizeof(Footer), NULL); 3783 3896 AssertLogRelRCReturn(rc, rc); 3784 3897 AssertLogRelReturn(!memcmp(Footer.szMagic, SSMFILEFTR_MAGIC, sizeof(Footer.szMagic)), VERR_SSM_INTEGRITY); … … 3937 4050 { 3938 4051 cbHdr = 2; 3939 abHdr[1] = cb;4052 abHdr[1] = (uint8_t)cb; 3940 4053 } 3941 4054 else if (cb < 0x00000800) 3942 4055 { 3943 4056 cbHdr = 3; 3944 abHdr[1] = 0xc0 | (cb >> 6);3945 abHdr[2] = 0x80 | (cb & 0x3f);4057 abHdr[1] = (uint8_t)(0xc0 | (cb >> 6)); 4058 abHdr[2] = (uint8_t)(0x80 | (cb & 0x3f)); 3946 4059 } 3947 4060 else if (cb < 0x00010000) 3948 4061 { 3949 4062 cbHdr = 4; 3950 abHdr[1] = 0xe0 | (cb >> 12);3951 abHdr[2] = 0x80 | ((cb >> 6) & 0x3f);3952 abHdr[3] = 0x80 | (cb & 0x3f);4063 abHdr[1] = (uint8_t)(0xe0 | (cb >> 12)); 4064 abHdr[2] = (uint8_t)(0x80 | ((cb >> 6) & 0x3f)); 4065 abHdr[3] = (uint8_t)(0x80 | (cb & 0x3f)); 3953 4066 } 3954 4067 else if (cb < 0x00200000) 3955 4068 { 3956 4069 cbHdr = 5; 3957 abHdr[1] = 0xf0 | (cb >> 18);3958 abHdr[2] = 0x80 | ((cb >> 12) & 0x3f);3959 abHdr[3] = 0x80 | ((cb >> 6) & 0x3f);3960 abHdr[4] = 0x80 | (cb & 0x3f);4070 abHdr[1] = (uint8_t)(0xf0 | (cb >> 18)); 4071 abHdr[2] = (uint8_t)(0x80 | ((cb >> 12) & 0x3f)); 4072 abHdr[3] = (uint8_t)(0x80 | ((cb >> 6) & 0x3f)); 4073 abHdr[4] = (uint8_t)(0x80 | (cb & 0x3f)); 3961 4074 } 3962 4075 else if (cb < 0x04000000) 3963 4076 { 3964 4077 cbHdr = 6; 3965 abHdr[1] = 0xf8 | (cb >> 24);3966 abHdr[2] = 0x80 | ((cb >> 18) & 0x3f);3967 abHdr[3] = 0x80 | ((cb >> 12) & 0x3f);3968 abHdr[4] = 0x80 | ((cb >> 6) & 0x3f);3969 abHdr[5] = 0x80 | (cb & 0x3f);4078 abHdr[1] = (uint8_t)(0xf8 | (cb >> 24)); 4079 abHdr[2] = (uint8_t)(0x80 | ((cb >> 18) & 0x3f)); 4080 abHdr[3] = (uint8_t)(0x80 | ((cb >> 12) & 0x3f)); 4081 abHdr[4] = (uint8_t)(0x80 | ((cb >> 6) & 0x3f)); 4082 abHdr[5] = (uint8_t)(0x80 | (cb & 0x3f)); 3970 4083 } 3971 4084 else if (cb <= 0x7fffffff) 3972 4085 { 3973 4086 cbHdr = 7; 3974 abHdr[1] = 0xfc | (cb >> 30);3975 abHdr[2] = 0x80 | ((cb >> 24) & 0x3f);3976 abHdr[3] = 0x80 | ((cb >> 18) & 0x3f);3977 abHdr[4] = 0x80 | ((cb >> 12) & 0x3f);3978 abHdr[5] = 0x80 | ((cb >> 6) & 0x3f);3979 abHdr[6] = 0x80 | (cb & 0x3f);4087 abHdr[1] = (uint8_t)(0xfc | (cb >> 30)); 4088 abHdr[2] = (uint8_t)(0x80 | ((cb >> 24) & 0x3f)); 4089 abHdr[3] = (uint8_t)(0x80 | ((cb >> 18) & 0x3f)); 4090 abHdr[4] = (uint8_t)(0x80 | ((cb >> 12) & 0x3f)); 4091 abHdr[5] = (uint8_t)(0x80 | ((cb >> 6) & 0x3f)); 4092 abHdr[6] = (uint8_t)(0x80 | (cb & 0x3f)); 3980 4093 } 3981 4094 else … … 4161 4274 { 4162 4275 memcpy(&pSSM->u.Write.abDataBuffer[0], pvBuf, cbBuf); 4163 pSSM->u.Write.offDataBuffer = cbBuf;4276 pSSM->u.Write.offDataBuffer = (uint32_t)cbBuf; 4164 4277 } 4165 4278 return rc; … … 4190 4303 4191 4304 memcpy(&pSSM->u.Write.abDataBuffer[off], pvBuf, cbBuf); 4192 pSSM->u.Write.offDataBuffer = off + cbBuf;4305 pSSM->u.Write.offDataBuffer = off + (uint32_t)cbBuf; 4193 4306 return VINF_SUCCESS; 4194 4307 } … … 4815 4928 * @param pcbDecompr Where to store the size of the decompressed data. 4816 4929 */ 4817 DECLINLINE(int) ssmR3DataReadV2RawLzfHdr(PSSMHANDLE pSSM, size_t *pcbDecompr)4930 DECLINLINE(int) ssmR3DataReadV2RawLzfHdr(PSSMHANDLE pSSM, uint32_t *pcbDecompr) 4818 4931 { 4819 4932 *pcbDecompr = 0; /* shuts up gcc. */ … … 4831 4944 pSSM->u.Read.cbRecLeft -= sizeof(cKB); 4832 4945 4833 size_t cbDecompr = (size_t)cKB * _1K;4946 uint32_t cbDecompr = (uint32_t)cKB * _1K; 4834 4947 AssertLogRelMsgReturn( cbDecompr >= pSSM->u.Read.cbRecLeft 4835 4948 && cbDecompr <= RT_SIZEOFMEMB(SSMHANDLE, u.Read.abDataBuffer), … … 4892 5005 * Read the two mandatory bytes. 4893 5006 */ 4894 uint32_t u32StreamCRC = ssmR3StrmCurCRC( pSSM); /** @todo NOT good. */5007 uint32_t u32StreamCRC = ssmR3StrmCurCRC(&pSSM->Strm); /** @todo NOT good. */ 4895 5008 uint8_t abHdr[8]; 4896 5009 int rc = ssmR3DataReadV2Raw(pSSM, abHdr, 2); … … 5068 5181 Assert(cbBuf > cbToCopy); 5069 5182 memcpy(pvBuf, &pSSM->u.Read.abDataBuffer[off], cbToCopy); 5070 pvBuf = (uint8_t *)pvBuf + cbToCopy;5183 pvBuf = (uint8_t *)pvBuf + cbToCopy; 5071 5184 cbBuf -= cbToCopy; 5072 pSSM->u.Read.cbDataBuffer = 0;5185 pSSM->u.Read.cbDataBuffer = 0; 5073 5186 pSSM->u.Read.offDataBuffer = 0; 5074 5187 } … … 5093 5206 * Read data from the current record. 5094 5207 */ 5095 size_t cbToRead;5208 uint32_t cbToRead; 5096 5209 switch (pSSM->u.Read.u8TypeAndFlags & SSM_REC_TYPE_MASK) 5097 5210 { 5098 5211 case SSM_REC_TYPE_RAW: 5099 5212 { 5100 cbToRead = RT_MIN(cbBuf, pSSM->u.Read.cbRecLeft);5213 cbToRead = (uint32_t)RT_MIN(cbBuf, pSSM->u.Read.cbRecLeft); 5101 5214 int rc = ssmR3DataReadV2Raw(pSSM, pvBuf, cbToRead); 5102 5215 if (RT_FAILURE(rc)) … … 5108 5221 case SSM_REC_TYPE_RAW_LZF: 5109 5222 { 5110 size_t cbDecompr;5223 uint32_t cbDecompr; 5111 5224 int rc = ssmR3DataReadV2RawLzfHdr(pSSM, &cbDecompr); 5112 5225 if (RT_FAILURE(rc)) … … 5125 5238 if (RT_FAILURE(rc)) 5126 5239 return rc; 5127 memcpy(pvBuf, &pSSM->u.Read.abDataBuffer[0], cbBuf);5128 pSSM->u.Read.cbDataBuffer = cbDecompr;5129 pSSM->u.Read. offDataBuffer = cbBuf;5130 cbToRead = cbBuf;5240 cbToRead = (uint32_t)cbBuf; 5241 memcpy(pvBuf, &pSSM->u.Read.abDataBuffer[0], cbToRead); 5242 pSSM->u.Read.cbDataBuffer = cbDecompr; 5243 pSSM->u.Read.offDataBuffer = cbToRead; 5131 5244 } 5132 5245 break; … … 5170 5283 Assert(cbBuf > cbToCopy); 5171 5284 memcpy(pvBuf, &pSSM->u.Read.abDataBuffer[off], cbToCopy); 5172 pvBuf = (uint8_t *)pvBuf + cbToCopy;5285 pvBuf = (uint8_t *)pvBuf + cbToCopy; 5173 5286 cbBuf -= cbToCopy; 5174 pSSM->u.Read.cbDataBuffer = 0;5287 pSSM->u.Read.cbDataBuffer = 0; 5175 5288 pSSM->u.Read.offDataBuffer = 0; 5176 5289 } … … 5196 5309 * LATER: optimize by reading directly into the output buffer for some cases. 5197 5310 */ 5198 size_t cbToRead;5311 uint32_t cbToRead; 5199 5312 switch (pSSM->u.Read.u8TypeAndFlags & SSM_REC_TYPE_MASK) 5200 5313 { … … 5205 5318 if (RT_FAILURE(rc)) 5206 5319 return pSSM->rc = rc; 5207 pSSM->u.Read.cbRecLeft -= cbToRead;5320 pSSM->u.Read.cbRecLeft -= cbToRead; 5208 5321 pSSM->u.Read.cbDataBuffer = cbToRead; 5209 5322 break; … … 5212 5325 case SSM_REC_TYPE_RAW_LZF: 5213 5326 { 5214 size_t cbDecompr;5327 uint32_t cbDecompr; 5215 5328 int rc = ssmR3DataReadV2RawLzfHdr(pSSM, &cbDecompr); 5216 5329 if (RT_FAILURE(rc)) … … 5232 5345 * Copy data from the buffer. 5233 5346 */ 5234 size_t cbToCopy =RT_MIN(cbBuf, cbToRead);5347 uint32_t cbToCopy = (uint32_t)RT_MIN(cbBuf, cbToRead); 5235 5348 memcpy(pvBuf, &pSSM->u.Read.abDataBuffer[0], cbToCopy); 5236 5349 cbBuf -= cbToCopy; … … 5276 5389 5277 5390 memcpy(pvBuf, &pSSM->u.Read.abDataBuffer[off], cbBuf); 5278 pSSM->u.Read.offDataBuffer = off + cbBuf;5391 pSSM->u.Read.offDataBuffer = off + (uint32_t)cbBuf; 5279 5392 Log4((cbBuf 5280 5393 ? "ssmR3DataRead: %08llx|%08llx/%08x/%08x: cbBuf=%#x %.*Rhxs%s\n"
Note:
See TracChangeset
for help on using the changeset viewer.