Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(801)

Side by Side Diff: runtime/vm/dart_api_message.cc

Issue 10829444: Avoid trusting the length encoded in the Snapshot if there is an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/dart_api_message.h" 5 #include "vm/dart_api_message.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/snapshot_ids.h" 7 #include "vm/snapshot_ids.h"
8 #include "vm/symbols.h" 8 #include "vm/symbols.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 static const int kNumInitialReferences = 4; 12 static const int kNumInitialReferences = 4;
13 13
14 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, 14 ApiMessageReader::ApiMessageReader(const Snapshot* snapshot, ReAlloc alloc)
15 intptr_t length, 15 : BaseReader(snapshot->content(), snapshot->length()),
16 ReAlloc alloc)
17 : BaseReader(buffer, length),
18 alloc_(alloc), 16 alloc_(alloc),
19 backward_references_(kNumInitialReferences) { 17 backward_references_(kNumInitialReferences) {
20 Init(); 18 Init();
21 } 19 }
22 20
23 21
24 void ApiMessageReader::Init() { 22 void ApiMessageReader::Init() {
25 // Initialize marker objects used to handle Lists. 23 // Initialize marker objects used to handle Lists.
26 // TODO(sjesse): Remove this when message serialization format is 24 // TODO(sjesse): Remove this when message serialization format is
27 // updated. 25 // updated.
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 Dart_CObject* ApiMessageReader::GetBackRef(intptr_t id) { 451 Dart_CObject* ApiMessageReader::GetBackRef(intptr_t id) {
454 ASSERT(id >= kMaxPredefinedObjectIds); 452 ASSERT(id >= kMaxPredefinedObjectIds);
455 intptr_t index = (id - kMaxPredefinedObjectIds); 453 intptr_t index = (id - kMaxPredefinedObjectIds);
456 if (index < backward_references_.length()) { 454 if (index < backward_references_.length()) {
457 return backward_references_[index]->reference(); 455 return backward_references_[index]->reference();
458 } 456 }
459 return NULL; 457 return NULL;
460 } 458 }
461 459
462 460
463 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { 461 intptr_t ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) {
464 // Write out the serialization header value for this object. 462 // Write out the serialization header value for this object.
465 WriteInlinedObjectHeader(kMaxPredefinedObjectIds); 463 WriteInlinedObjectHeader(kMaxPredefinedObjectIds);
466 464
467 // Write out the class and tags information. 465 // Write out the class and tags information.
468 WriteIndexedObject(kArrayCid); 466 WriteIndexedObject(kArrayCid);
469 WriteIntptrValue(0); 467 WriteIntptrValue(0);
470 468
471 // Write out the length field. 469 // Write out the length field.
472 Write<RawObject*>(Smi::New(field_count)); 470 Write<RawObject*>(Smi::New(field_count));
473 471
474 // Write out the type arguments. 472 // Write out the type arguments.
475 WriteNullObject(); 473 WriteNullObject();
476 474
477 // Write out the individual Smis. 475 // Write out the individual Smis.
478 for (int i = 0; i < field_count; i++) { 476 for (int i = 0; i < field_count; i++) {
479 Write<RawObject*>(Integer::New(data[i])); 477 Write<RawObject*>(Integer::New(data[i]));
480 } 478 }
481 479
482 FinalizeBuffer(); 480 return FinalizeBuffer();
483 } 481 }
484 482
485 483
486 void ApiMessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) { 484 void ApiMessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) {
487 // Mark the object as serialized by adding the object id to the 485 // Mark the object as serialized by adding the object id to the
488 // upper bits of the type field in the Dart_CObject structure. Add 486 // upper bits of the type field in the Dart_CObject structure. Add
489 // an offset for making marking of object id 0 possible. 487 // an offset for making marking of object id 0 possible.
490 ASSERT(!IsCObjectMarked(object)); 488 ASSERT(!IsCObjectMarked(object));
491 intptr_t mark_value = object_id + kDartCObjectMarkOffset; 489 intptr_t mark_value = object_id + kDartCObjectMarkOffset;
492 object->type = static_cast<Dart_CObject::Type>( 490 object->type = static_cast<Dart_CObject::Type>(
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 WriteIntptrValue(reinterpret_cast<intptr_t>(peer)); 764 WriteIntptrValue(reinterpret_cast<intptr_t>(peer));
767 WriteIntptrValue(reinterpret_cast<intptr_t>(callback)); 765 WriteIntptrValue(reinterpret_cast<intptr_t>(callback));
768 break; 766 break;
769 } 767 }
770 default: 768 default:
771 UNREACHABLE(); 769 UNREACHABLE();
772 } 770 }
773 } 771 }
774 772
775 773
776 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { 774 intptr_t ApiMessageWriter::WriteCMessage(Dart_CObject* object) {
777 WriteCObject(object); 775 WriteCObject(object);
778 // Write out all objects that were added to the forward list and have 776 // Write out all objects that were added to the forward list and have
779 // not been serialized yet. These would typically be fields of arrays. 777 // not been serialized yet. These would typically be fields of arrays.
780 // NOTE: The forward list might grow as we process the list. 778 // NOTE: The forward list might grow as we process the list.
781 for (intptr_t i = 0; i < forward_id_; i++) { 779 for (intptr_t i = 0; i < forward_id_; i++) {
782 WriteForwardedCObject(forward_list_[i]); 780 WriteForwardedCObject(forward_list_[i]);
783 } 781 }
784 UnmarkAllCObjects(object); 782 UnmarkAllCObjects(object);
785 FinalizeBuffer(); 783 return FinalizeBuffer();
786 } 784 }
787 785
788 } // namespace dart 786 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698