Commit afb49bae authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[flags] Improve flag to verify and create snapshot checksums

- Rename --skip-snapshot-checksum to --verify-snapshot-checksum to
  avoid double negations in most of the code
- Conditionally create and verify checksums in SerializedCodeData
- Remove unused Deserializer::GetChecksum

Bug: chromium:1270752
Change-Id: I8360e0dd5f25dac68bf68909155771b302184a4b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3284883
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77925}
parent 6ffcdddb
......@@ -1754,8 +1754,9 @@ DEFINE_BOOL(rcs_cpu_time, false,
DEFINE_IMPLICATION(rcs_cpu_time, rcs)
// snapshot-common.cc
DEFINE_BOOL(skip_snapshot_checksum, false,
"Skip snapshot checksum calculation when deserializing an Isolate.")
DEFINE_BOOL(verify_snapshot_checksum, true,
"Verify snapshot checksums when deserializing snapshots. Enable "
"checksum creation and verification for code caches.")
DEFINE_BOOL(profile_deserialization, false,
"Print the time it takes to deserialize the snapshot.")
DEFINE_BOOL(serialization_statistics, false,
......
......@@ -557,8 +557,9 @@ SerializedCodeData::SerializedCodeData(const std::vector<byte>* payload,
// Copy serialized data.
CopyBytes(data_ + kHeaderSize, payload->data(),
static_cast<size_t>(payload->size()));
SetHeaderValue(kChecksumOffset, Checksum(ChecksummedContent()));
uint32_t checksum =
FLAG_verify_snapshot_checksum ? Checksum(ChecksummedContent()) : 0;
SetHeaderValue(kChecksumOffset, checksum);
}
SerializedCodeSanityCheckResult SerializedCodeData::SanityCheck(
......@@ -587,21 +588,23 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckWithoutSource()
return SerializedCodeSanityCheckResult::kMagicNumberMismatch;
}
uint32_t version_hash = GetHeaderValue(kVersionHashOffset);
uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
uint32_t c = GetHeaderValue(kChecksumOffset);
if (version_hash != Version::Hash()) {
return SerializedCodeSanityCheckResult::kVersionMismatch;
}
uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
if (flags_hash != FlagList::Hash()) {
return SerializedCodeSanityCheckResult::kFlagsMismatch;
}
uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
uint32_t max_payload_length = this->size_ - kHeaderSize;
if (payload_length > max_payload_length) {
return SerializedCodeSanityCheckResult::kLengthMismatch;
}
if (Checksum(ChecksummedContent()) != c) {
return SerializedCodeSanityCheckResult::kChecksumMismatch;
if (FLAG_verify_snapshot_checksum) {
uint32_t checksum = GetHeaderValue(kChecksumOffset);
if (Checksum(ChecksummedContent()) != checksum) {
return SerializedCodeSanityCheckResult::kChecksumMismatch;
}
}
return SerializedCodeSanityCheckResult::kSuccess;
}
......
......@@ -49,8 +49,6 @@ class Deserializer : public SerializerDeserializer {
Deserializer(const Deserializer&) = delete;
Deserializer& operator=(const Deserializer&) = delete;
uint32_t GetChecksum() const { return source_.GetChecksum(); }
protected:
// Create a deserializer from a snapshot byte source.
Deserializer(IsolateT* isolate, base::Vector<const byte> payload,
......
......@@ -103,10 +103,6 @@ class SnapshotByteSource final {
int position() { return position_; }
void set_position(int position) { position_ = position; }
uint32_t GetChecksum() const {
return Checksum(base::Vector<const byte>(data_, length_));
}
private:
const byte* data_;
int length_;
......
......@@ -168,9 +168,7 @@ bool Snapshot::Initialize(Isolate* isolate) {
const v8::StartupData* blob = isolate->snapshot_blob();
SnapshotImpl::CheckVersion(blob);
if (!FLAG_skip_snapshot_checksum) {
CHECK(VerifyChecksum(blob));
}
if (FLAG_verify_snapshot_checksum) CHECK(VerifyChecksum(blob));
base::Vector<const byte> startup_data =
SnapshotImpl::ExtractStartupData(blob);
base::Vector<const byte> read_only_data =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment