Changeset 21858 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Jul 28, 2009 7:27:08 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50494
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/SSM-new.cpp
r21856 r21858 231 231 /** @name SSMRECTERM::fFlags 232 232 * @{ */ 233 /** There is CRC-32 for the data. */233 /** There is a CRC-32 value for the stream. */ 234 234 #define SSMRECTERM_FLAGS_CRC32 UINT16_C(0x0001) 235 235 /** @} */ … … 294 294 /** The current uncompressed offset into the data unit. */ 295 295 uint64_t offUnit; 296 /** Whether we're checksumming the unit or not. */297 bool fUnitChecksummed;298 /** The unit CRC. */299 uint32_t u32UnitCRC;300 296 301 297 /** Pointer to the progress callback function. */ … … 526 522 * This is mainly intended for sanity checking. */ 527 523 uint64_t offStream; 524 /** The CRC-in-progress value this unit starts at. */ 525 uint32_t u32CurStreamCRC; 528 526 /** The checksum of this structure, including the whole name. 529 527 * Calculated with this field set to zero. */ … … 542 540 char szName[SSM_MAX_NAME_SIZE]; 543 541 } SSMFILEUNITHDR; 544 AssertCompileMemberOffset(SSMFILEUNITHDR, szName, 4 0);542 AssertCompileMemberOffset(SSMFILEUNITHDR, szName, 44); 545 543 AssertCompileMemberSize(SSMFILEUNITHDR, szMagic, sizeof(SSMFILEUNITHDR_MAGIC)); 546 544 AssertCompileMemberSize(SSMFILEUNITHDR, szMagic, sizeof(SSMFILEUNITHDR_END)); … … 583 581 /** Flags, see SSMRECTERM_FLAGS_CRC32. */ 584 582 uint16_t fFlags; 585 /** The checksum of the dataup to the start of this record. */586 uint32_t u32 CRC;583 /** The checksum of the stream up to the start of this record. */ 584 uint32_t u32StreamCRC; 587 585 /** The length of this data unit in bytes (including this record). */ 588 586 uint64_t cbUnit; … … 1528 1526 Handle.cbUnitLeftV1 = 0; 1529 1527 Handle.offUnit = UINT64_MAX; 1530 Handle.fUnitChecksummed = false;1531 Handle.u32UnitCRC = 0;1532 1528 Handle.pfnProgress = pfnProgress; 1533 1529 Handle.pvUser = pvUser; … … 1657 1653 */ 1658 1654 memcpy(&u.UnitHdr.szMagic[0], SSMFILEUNITHDR_MAGIC, sizeof(u.UnitHdr.szMagic)); 1659 u.UnitHdr.offStream = pUnit->offStream; 1660 u.UnitHdr.u32CRC = 0; 1661 u.UnitHdr.u32Version = pUnit->u32Version; 1662 u.UnitHdr.u32Instance = pUnit->u32Instance; 1663 u.UnitHdr.u32Phase = SSM_PHASE_FINAL; 1664 u.UnitHdr.fFlags = 0; 1665 u.UnitHdr.cbName = (uint32_t)pUnit->cchName + 1; 1655 u.UnitHdr.offStream = pUnit->offStream; 1656 if (Handle.fChecksummed) 1657 ssmR3StrmFlush(&Handle); 1658 u.UnitHdr.u32CurStreamCRC = Handle.u32StreamCRC; 1659 u.UnitHdr.u32CRC = 0; 1660 u.UnitHdr.u32Version = pUnit->u32Version; 1661 u.UnitHdr.u32Instance = pUnit->u32Instance; 1662 u.UnitHdr.u32Phase = SSM_PHASE_FINAL; 1663 u.UnitHdr.fFlags = 0; 1664 u.UnitHdr.cbName = (uint32_t)pUnit->cchName + 1; 1666 1665 memcpy(&u.UnitHdr.szName[0], &pUnit->szName[0], u.UnitHdr.cbName); 1667 u.UnitHdr.u32CRC = RTCrc32(&u.UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName[u.UnitHdr.cbName]));1666 u.UnitHdr.u32CRC = RTCrc32(&u.UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName[u.UnitHdr.cbName])); 1668 1667 Log(("SSM: Unit at %#9llx: '%s', instance %u, phase %#x, version %u\n", 1669 1668 u.UnitHdr.offStream, u.UnitHdr.szName, u.UnitHdr.u32Instance, u.UnitHdr.u32Phase, u.UnitHdr.u32Version)); … … 1702 1701 TermRec.u8TypeAndFlags = SSM_REC_FLAGS_FIXED | SSM_REC_FLAGS_IMPORTANT | SSM_REC_TYPE_TERM; 1703 1702 TermRec.cbRec = sizeof(TermRec) - 2; 1704 if (Handle.f UnitChecksummed)1703 if (Handle.fChecksummed) 1705 1704 { 1706 TermRec.fFlags = SSMRECTERM_FLAGS_CRC32;1707 TermRec.u32 CRC = RTCrc32Finish(Handle.u32UnitCRC);1705 TermRec.fFlags = SSMRECTERM_FLAGS_CRC32; 1706 TermRec.u32StreamCRC = RTCrc32Finish(Handle.u32StreamCRC); 1708 1707 } 1709 1708 else 1710 1709 { 1711 TermRec.fFlags = 0;1712 TermRec.u32 CRC= 0;1710 TermRec.fFlags = 0; 1711 TermRec.u32StreamCRC = 0; 1713 1712 } 1714 1713 TermRec.cbUnit = Handle.offUnit + sizeof(TermRec); … … 1717 1716 rc = ssmR3DataWriteFinish(&Handle); 1718 1717 if (RT_SUCCESS(rc)) 1719 {1720 1718 Handle.offUnit = UINT64_MAX; 1721 Handle.u32UnitCRC = 0;1722 }1723 1719 else 1724 1720 { … … 1790 1786 /* Write the end unit. */ 1791 1787 memcpy(&u.UnitHdr.szMagic[0], SSMFILEUNITHDR_END, sizeof(u.UnitHdr.szMagic)); 1792 u.UnitHdr.offStream = ssmR3StrmTell(&Handle); 1793 u.UnitHdr.u32Version = 0; 1794 u.UnitHdr.u32Instance = 0; 1795 u.UnitHdr.u32Phase = SSM_PHASE_FINAL; 1796 u.UnitHdr.fFlags = 0; 1797 u.UnitHdr.cbName = 0; 1798 u.UnitHdr.u32CRC = 0; 1799 u.UnitHdr.u32CRC = RTCrc32(&u.UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName[0])); 1788 u.UnitHdr.offStream = ssmR3StrmTell(&Handle); 1789 u.UnitHdr.u32CurStreamCRC = Handle.u32StreamCRC; 1790 u.UnitHdr.u32CRC = 0; 1791 u.UnitHdr.u32Version = 0; 1792 u.UnitHdr.u32Instance = 0; 1793 u.UnitHdr.u32Phase = SSM_PHASE_FINAL; 1794 u.UnitHdr.fFlags = 0; 1795 u.UnitHdr.cbName = 0; 1796 u.UnitHdr.u32CRC = RTCrc32(&u.UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName[0])); 1800 1797 Log(("SSM: Unit at %#9llx: END UNIT\n", u.UnitHdr.offStream)); 1801 1798 rc = ssmR3StrmWrite(&Handle, &u.UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName[0])); … … 1910 1907 1911 1908 /** 1912 * Validates the integrity of a saved state file. 1909 * Validates the integrity of a saved state file, it also initializes 1910 * u32StreamCRC for v2.0+. 1913 1911 * 1914 1912 * @returns VBox status. … … 1995 1993 } 1996 1994 1995 if (fChecksummed && fChecksumOnRead) 1996 pSSM->u32StreamCRC = RTCrc32Process(RTCrc32Start(), &uHdr, pSSM->u.Read.cbFileHdr); 1997 1997 1998 /* 1998 1999 * Read and validate the footer. … … 2041 2042 */ 2042 2043 if ( fChecksummed 2043 && fChecksumIt) 2044 && fChecksumIt 2045 && !fChecksumOnRead) 2044 2046 { 2045 2047 rc = RTFileSeek(pSSM->hFile, 0, RTFILE_SEEK_BEGIN, NULL); … … 2193 2195 pSSM->cbUnitLeftV1 = 0; 2194 2196 pSSM->offUnit = UINT64_MAX; 2195 pSSM->fUnitChecksummed = 0;2196 pSSM->u32UnitCRC = 0;2197 2197 pSSM->pfnProgress = NULL; 2198 2198 pSSM->pvUser = NULL; … … 2460 2460 * Read the unit header and check its integrity. 2461 2461 */ 2462 uint64_t offUnit = ssmR3StrmTell(pSSM); 2462 uint64_t offUnit = ssmR3StrmTell(pSSM); 2463 uint32_t u32CurStreamCRC = pSSM->u32StreamCRC; 2463 2464 SSMFILEUNITHDR UnitHdr; 2464 2465 int rc = ssmR3StrmRead(pSSM, &UnitHdr, RT_OFFSETOF(SSMFILEUNITHDR, szName)); … … 2497 2498 return VERR_SSM_INTEGRITY; 2498 2499 } 2500 AssertLogRelMsgReturn(UnitHdr.u32CurStreamCRC == u32CurStreamCRC || !pSSM->fChecksummed, 2501 ("Unit at %#llx (%lld): Stream CRC mismatch: %08x, correct is %08x\n", offUnit, offUnit, UnitHdr.u32CurStreamCRC, u32CurStreamCRC), VERR_SSM_INTEGRITY); 2499 2502 AssertLogRelMsgReturn(!UnitHdr.fFlags, ("Unit at %#llx (%lld): fFlags=%08x\n", offUnit, offUnit, UnitHdr.fFlags), VERR_SSM_INTEGRITY); 2500 2503 if (!memcmp(&UnitHdr.szMagic[0], SSMFILEUNITHDR_END, sizeof(UnitHdr.szMagic))) … … 2811 2814 * Try open the file and validate it. 2812 2815 */ 2813 int rc = ssmR3OpenFile(NULL, pszFilename, true /*fChecksumIt*/, false /*fChecksumOnRead*/, pSSM);2816 int rc = ssmR3OpenFile(NULL, pszFilename, false /*fChecksumIt*/, true /*fChecksumOnRead*/, pSSM); 2814 2817 if (RT_SUCCESS(rc)) 2815 2818 { … … 3008 3011 AssertLogRelRCReturn(rc, rc); 3009 3012 3013 if (pSSM->fChecksummed) 3014 pSSM->u32StreamCRC = RTCrc32Process(UnitHdr.u32CurStreamCRC, &UnitHdr, cbUnitHdr); 3015 3010 3016 ssmR3DataReadBeginV2(pSSM); 3011 3017 return VINF_SUCCESS; … … 3133 3139 static void ssmR3DataWriteBegin(PSSMHANDLE pSSM) 3134 3140 { 3135 pSSM->offUnit = 0; 3136 if (pSSM->fUnitChecksummed) 3137 pSSM->u32UnitCRC = RTCrc32Start(); 3141 pSSM->offUnit = 0; 3138 3142 } 3139 3143 … … 3157 3161 if (RT_FAILURE(pSSM->rc)) 3158 3162 return pSSM->rc; 3159 3160 /*3161 * Do the stream checksumming before we write the data.3162 */3163 if (pSSM->fUnitChecksummed)3164 pSSM->u32UnitCRC = RTCrc32Process(pSSM->u32UnitCRC, pvBuf, cbBuf);3165 3163 3166 3164 /* … … 4043 4041 4044 4042 /** 4045 * Read reader that does the decompression and keeps the offset and CRC members 4046 * up to date. 4043 * Read reader that keep works the progress indicator and unit offset. 4047 4044 * 4048 4045 * Does not set SSM::rc. … … 4060 4057 { 4061 4058 pSSM->offUnit += cbToRead; 4062 if (pSSM->fUnitChecksummed)4063 pSSM->u32UnitCRC = RTCrc32Process(pSSM->u32UnitCRC, pvBuf, cbToRead);4064 4065 4059 ssmR3Progress(pSSM, cbToRead); 4066 4060 return VINF_SUCCESS; … … 4158 4152 * Read the two mandatory bytes. 4159 4153 */ 4160 uint32_t u32 UnitCRC = pSSM->u32UnitCRC;4154 uint32_t u32StreamCRC = pSSM->u32StreamCRC; 4161 4155 uint8_t abHdr[8]; 4162 4156 int rc = ssmR3DataReadV2Raw(pSSM, abHdr, 2); … … 4188 4182 AssertLogRelMsgReturn(!(TermRec.fFlags & ~SSMRECTERM_FLAGS_CRC32), ("%#x\n", TermRec.fFlags), VERR_SSM_INTEGRITY); 4189 4183 if (!(TermRec.fFlags & SSMRECTERM_FLAGS_CRC32)) 4190 AssertLogRelMsgReturn(TermRec.u32 CRC == 0, ("%#x\n", TermRec.u32CRC), VERR_SSM_INTEGRITY);4191 else if (pSSM->f UnitChecksummed)4192 { 4193 u32 UnitCRC = RTCrc32Finish(u32UnitCRC);4194 AssertLogRelMsgReturn(TermRec.u32 CRC == u32UnitCRC, ("%#x, %#x\n", TermRec.u32CRC, u32UnitCRC), VERR_SSM_INTEGRITY_CRC);4184 AssertLogRelMsgReturn(TermRec.u32StreamCRC == 0, ("%#x\n", TermRec.u32StreamCRC), VERR_SSM_INTEGRITY); 4185 else if (pSSM->fChecksummed) 4186 { 4187 u32StreamCRC = RTCrc32Finish(u32StreamCRC); 4188 AssertLogRelMsgReturn(TermRec.u32StreamCRC == u32StreamCRC, ("%#x, %#x\n", TermRec.u32StreamCRC, u32StreamCRC), VERR_SSM_INTEGRITY_CRC); 4195 4189 } 4196 4190
Note:
See TracChangeset
for help on using the changeset viewer.