OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/snapshot/code-serializer.h" | 5 #include "src/snapshot/code-serializer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/log.h" | 10 #include "src/log.h" |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 SetMagicNumber(cs->isolate()); | 308 SetMagicNumber(cs->isolate()); |
309 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 309 SetHeaderValue(kVersionHashOffset, Version::Hash()); |
310 SetHeaderValue(kSourceHashOffset, cs->source_hash()); | 310 SetHeaderValue(kSourceHashOffset, cs->source_hash()); |
311 SetHeaderValue(kCpuFeaturesOffset, | 311 SetHeaderValue(kCpuFeaturesOffset, |
312 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); | 312 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); |
313 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); | 313 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); |
314 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 314 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
315 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); | 315 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); |
316 SetHeaderValue(kPayloadLengthOffset, payload->length()); | 316 SetHeaderValue(kPayloadLengthOffset, payload->length()); |
317 | 317 |
318 Checksum checksum(payload->ToConstVector()); | |
319 SetHeaderValue(kChecksum1Offset, checksum.a()); | |
320 SetHeaderValue(kChecksum2Offset, checksum.b()); | |
321 | |
322 // Copy reservation chunk sizes. | 318 // Copy reservation chunk sizes. |
323 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 319 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
324 reservation_size); | 320 reservation_size); |
325 | 321 |
326 // Copy code stub keys. | 322 // Copy code stub keys. |
327 CopyBytes(data_ + kHeaderSize + reservation_size, | 323 CopyBytes(data_ + kHeaderSize + reservation_size, |
328 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); | 324 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); |
329 | 325 |
330 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); | 326 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); |
331 | 327 |
332 // Copy serialized data. | 328 // Copy serialized data. |
333 CopyBytes(data_ + padded_payload_offset, payload->begin(), | 329 CopyBytes(data_ + padded_payload_offset, payload->begin(), |
334 static_cast<size_t>(payload->length())); | 330 static_cast<size_t>(payload->length())); |
| 331 |
| 332 Checksum checksum(DataWithoutHeader()); |
| 333 SetHeaderValue(kChecksum1Offset, checksum.a()); |
| 334 SetHeaderValue(kChecksum2Offset, checksum.b()); |
335 } | 335 } |
336 | 336 |
337 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( | 337 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( |
338 Isolate* isolate, uint32_t expected_source_hash) const { | 338 Isolate* isolate, uint32_t expected_source_hash) const { |
339 uint32_t magic_number = GetMagicNumber(); | 339 uint32_t magic_number = GetMagicNumber(); |
340 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; | 340 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; |
341 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); | 341 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); |
342 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); | 342 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); |
343 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); | 343 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); |
344 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); | 344 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); |
345 uint32_t c1 = GetHeaderValue(kChecksum1Offset); | 345 uint32_t c1 = GetHeaderValue(kChecksum1Offset); |
346 uint32_t c2 = GetHeaderValue(kChecksum2Offset); | 346 uint32_t c2 = GetHeaderValue(kChecksum2Offset); |
347 if (version_hash != Version::Hash()) return VERSION_MISMATCH; | 347 if (version_hash != Version::Hash()) return VERSION_MISMATCH; |
348 if (source_hash != expected_source_hash) return SOURCE_MISMATCH; | 348 if (source_hash != expected_source_hash) return SOURCE_MISMATCH; |
349 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { | 349 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { |
350 return CPU_FEATURES_MISMATCH; | 350 return CPU_FEATURES_MISMATCH; |
351 } | 351 } |
352 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; | 352 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; |
353 if (!Checksum(Payload()).Check(c1, c2)) return CHECKSUM_MISMATCH; | 353 if (!Checksum(DataWithoutHeader()).Check(c1, c2)) return CHECKSUM_MISMATCH; |
354 return CHECK_SUCCESS; | 354 return CHECK_SUCCESS; |
355 } | 355 } |
356 | 356 |
357 uint32_t SerializedCodeData::SourceHash(Handle<String> source) { | 357 uint32_t SerializedCodeData::SourceHash(Handle<String> source) { |
358 return source->length(); | 358 return source->length(); |
359 } | 359 } |
360 | 360 |
361 // Return ScriptData object and relinquish ownership over it to the caller. | 361 // Return ScriptData object and relinquish ownership over it to the caller. |
362 ScriptData* SerializedCodeData::GetScriptData() { | 362 ScriptData* SerializedCodeData::GetScriptData() { |
363 DCHECK(owns_data_); | 363 DCHECK(owns_data_); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); | 405 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); |
406 if (*rejection_result != CHECK_SUCCESS) { | 406 if (*rejection_result != CHECK_SUCCESS) { |
407 cached_data->Reject(); | 407 cached_data->Reject(); |
408 return SerializedCodeData(nullptr, 0); | 408 return SerializedCodeData(nullptr, 0); |
409 } | 409 } |
410 return scd; | 410 return scd; |
411 } | 411 } |
412 | 412 |
413 } // namespace internal | 413 } // namespace internal |
414 } // namespace v8 | 414 } // namespace v8 |
OLD | NEW |