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/counters.h" | 10 #include "src/counters.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 SetMagicNumber(cs->isolate()); | 380 SetMagicNumber(cs->isolate()); |
381 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 381 SetHeaderValue(kVersionHashOffset, Version::Hash()); |
382 SetHeaderValue(kSourceHashOffset, cs->source_hash()); | 382 SetHeaderValue(kSourceHashOffset, cs->source_hash()); |
383 SetHeaderValue(kCpuFeaturesOffset, | 383 SetHeaderValue(kCpuFeaturesOffset, |
384 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); | 384 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); |
385 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); | 385 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); |
386 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 386 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
387 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); | 387 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); |
388 SetHeaderValue(kPayloadLengthOffset, payload->length()); | 388 SetHeaderValue(kPayloadLengthOffset, payload->length()); |
389 | 389 |
| 390 // Zero out any padding in the header. |
| 391 memset(data_ + kUnalignedHeaderSize, 0, kHeaderSize - kUnalignedHeaderSize); |
| 392 |
390 // Copy reservation chunk sizes. | 393 // Copy reservation chunk sizes. |
391 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 394 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
392 reservation_size); | 395 reservation_size); |
393 | 396 |
394 // Copy code stub keys. | 397 // Copy code stub keys. |
395 CopyBytes(data_ + kHeaderSize + reservation_size, | 398 CopyBytes(data_ + kHeaderSize + reservation_size, |
396 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); | 399 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); |
397 | 400 |
| 401 // Zero out any padding before the payload. |
398 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); | 402 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); |
399 | 403 |
400 // Copy serialized data. | 404 // Copy serialized data. |
401 CopyBytes(data_ + padded_payload_offset, payload->begin(), | 405 CopyBytes(data_ + padded_payload_offset, payload->begin(), |
402 static_cast<size_t>(payload->length())); | 406 static_cast<size_t>(payload->length())); |
403 | 407 |
404 Checksum checksum(DataWithoutHeader()); | 408 Checksum checksum(DataWithoutHeader()); |
405 SetHeaderValue(kChecksum1Offset, checksum.a()); | 409 SetHeaderValue(kChecksum1Offset, checksum.a()); |
406 SetHeaderValue(kChecksum2Offset, checksum.b()); | 410 SetHeaderValue(kChecksum2Offset, checksum.b()); |
407 } | 411 } |
408 | 412 |
409 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( | 413 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( |
410 Isolate* isolate, uint32_t expected_source_hash) const { | 414 Isolate* isolate, uint32_t expected_source_hash) const { |
411 if (this->size_ < kHeaderSize) return INVALID_HEADER; | 415 if (this->size_ < kHeaderSize) return INVALID_HEADER; |
412 uint32_t magic_number = GetMagicNumber(); | 416 uint32_t magic_number = GetMagicNumber(); |
413 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; | 417 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; |
| 418 if (GetExtraReferences() > GetExtraReferences(isolate)) { |
| 419 return MAGIC_NUMBER_MISMATCH; |
| 420 } |
414 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); | 421 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); |
415 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); | 422 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); |
416 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); | 423 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); |
417 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); | 424 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); |
| 425 uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset); |
418 uint32_t c1 = GetHeaderValue(kChecksum1Offset); | 426 uint32_t c1 = GetHeaderValue(kChecksum1Offset); |
419 uint32_t c2 = GetHeaderValue(kChecksum2Offset); | 427 uint32_t c2 = GetHeaderValue(kChecksum2Offset); |
420 if (version_hash != Version::Hash()) return VERSION_MISMATCH; | 428 if (version_hash != Version::Hash()) return VERSION_MISMATCH; |
421 if (source_hash != expected_source_hash) return SOURCE_MISMATCH; | 429 if (source_hash != expected_source_hash) return SOURCE_MISMATCH; |
422 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { | 430 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { |
423 return CPU_FEATURES_MISMATCH; | 431 return CPU_FEATURES_MISMATCH; |
424 } | 432 } |
425 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; | 433 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; |
| 434 uint32_t max_payload_length = |
| 435 this->size_ - |
| 436 POINTER_SIZE_ALIGN(kHeaderSize + |
| 437 GetHeaderValue(kNumReservationsOffset) * kInt32Size + |
| 438 GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size); |
| 439 if (payload_length > max_payload_length) return LENGTH_MISMATCH; |
426 if (!Checksum(DataWithoutHeader()).Check(c1, c2)) return CHECKSUM_MISMATCH; | 440 if (!Checksum(DataWithoutHeader()).Check(c1, c2)) return CHECKSUM_MISMATCH; |
427 return CHECK_SUCCESS; | 441 return CHECK_SUCCESS; |
428 } | 442 } |
429 | 443 |
430 uint32_t SerializedCodeData::SourceHash(Handle<String> source) { | 444 uint32_t SerializedCodeData::SourceHash(Handle<String> source) { |
431 return source->length(); | 445 return source->length(); |
432 } | 446 } |
433 | 447 |
434 // Return ScriptData object and relinquish ownership over it to the caller. | 448 // Return ScriptData object and relinquish ownership over it to the caller. |
435 ScriptData* SerializedCodeData::GetScriptData() { | 449 ScriptData* SerializedCodeData::GetScriptData() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); | 492 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); |
479 if (*rejection_result != CHECK_SUCCESS) { | 493 if (*rejection_result != CHECK_SUCCESS) { |
480 cached_data->Reject(); | 494 cached_data->Reject(); |
481 return SerializedCodeData(nullptr, 0); | 495 return SerializedCodeData(nullptr, 0); |
482 } | 496 } |
483 return scd; | 497 return scd; |
484 } | 498 } |
485 | 499 |
486 } // namespace internal | 500 } // namespace internal |
487 } // namespace v8 | 501 } // namespace v8 |
OLD | NEW |