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

Side by Side Diff: runtime/vm/snapshot.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, 3 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
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ASSERT((value & kSmiTagMask) == 0); 138 ASSERT((value & kSmiTagMask) == 0);
139 return reinterpret_cast<RawSmi*>(value); 139 return reinterpret_cast<RawSmi*>(value);
140 } 140 }
141 141
142 142
143 intptr_t BaseReader::ReadSmiValue() { 143 intptr_t BaseReader::ReadSmiValue() {
144 return Smi::Value(ReadAsSmi()); 144 return Smi::Value(ReadAsSmi());
145 } 145 }
146 146
147 147
148 SnapshotReader::SnapshotReader(const Snapshot* snapshot, Isolate* isolate) 148 SnapshotReader::SnapshotReader(const uint8_t* buffer,
149 : BaseReader(snapshot->content(), snapshot->length()), 149 intptr_t size,
150 kind_(snapshot->kind()), 150 Snapshot::Kind kind,
151 Isolate* isolate)
152 : BaseReader(buffer, size),
153 kind_(kind),
151 isolate_(isolate), 154 isolate_(isolate),
152 cls_(Class::Handle()), 155 cls_(Class::Handle()),
153 obj_(Object::Handle()), 156 obj_(Object::Handle()),
154 str_(String::Handle()), 157 str_(String::Handle()),
155 library_(Library::Handle()), 158 library_(Library::Handle()),
156 type_(AbstractType::Handle()), 159 type_(AbstractType::Handle()),
157 type_arguments_(AbstractTypeArguments::Handle()), 160 type_arguments_(AbstractTypeArguments::Handle()),
158 tokens_(Array::Handle()), 161 tokens_(Array::Handle()),
159 backward_references_((snapshot->kind() == Snapshot::kFull) ? 162 backward_references_((kind == Snapshot::kFull) ?
160 kNumInitialReferencesInFullSnapshot : 163 kNumInitialReferencesInFullSnapshot :
161 kNumInitialReferences) { 164 kNumInitialReferences) {
162 } 165 }
163 166
164 167
165 RawObject* SnapshotReader::ReadObject() { 168 RawObject* SnapshotReader::ReadObject() {
166 Object& obj = Object::Handle(ReadObjectImpl()); 169 Object& obj = Object::Handle(ReadObjectImpl());
167 for (intptr_t i = 0; i < backward_references_.length(); i++) { 170 for (intptr_t i = 0; i < backward_references_.length(); i++) {
168 if (!backward_references_[i]->is_deserialized()) { 171 if (!backward_references_[i]->is_deserialized()) {
169 ReadObjectImpl(); 172 ReadObjectImpl();
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 } \ 853 } \
851 854
852 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) 855 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE)
853 #undef SNAPSHOT_WRITE 856 #undef SNAPSHOT_WRITE
854 default: break; 857 default: break;
855 } 858 }
856 UNREACHABLE(); 859 UNREACHABLE();
857 } 860 }
858 861
859 862
860 void SnapshotWriter::WriteFullSnapshot() { 863 void FullSnapshotWriter::WriteFullSnapshot() {
861 ASSERT(kind_ == Snapshot::kFull);
862 Isolate* isolate = Isolate::Current(); 864 Isolate* isolate = Isolate::Current();
863 ASSERT(isolate != NULL); 865 ASSERT(isolate != NULL);
864 ObjectStore* object_store = isolate->object_store(); 866 ObjectStore* object_store = isolate->object_store();
865 ASSERT(object_store != NULL); 867 ASSERT(object_store != NULL);
866 868
869 // Reserve space in the output buffer for a snapshot header.
870 ReserveHeader();
871
867 // Write out all the objects in the object store of the isolate which 872 // Write out all the objects in the object store of the isolate which
868 // is the root set for all dart allocated objects at this point. 873 // is the root set for all dart allocated objects at this point.
869 SnapshotWriterVisitor visitor(this, false); 874 SnapshotWriterVisitor visitor(this, false);
870 object_store->VisitObjectPointers(&visitor); 875 object_store->VisitObjectPointers(&visitor);
871 876
872 // Write out all forwarded objects. 877 // Write out all forwarded objects.
873 WriteForwardedObjects(); 878 WriteForwardedObjects();
874 879
875 // Finalize the snapshot buffer. 880 FillHeader(kind());
876 FinalizeBuffer(); 881 UnmarkAll();
877 } 882 }
878 883
879 884
880 uword SnapshotWriter::GetObjectTags(RawObject* raw) { 885 uword SnapshotWriter::GetObjectTags(RawObject* raw) {
881 uword tags = raw->ptr()->tags_; 886 uword tags = raw->ptr()->tags_;
882 if (SerializedHeaderTag::decode(tags) == kObjectId) { 887 if (SerializedHeaderTag::decode(tags) == kObjectId) {
883 intptr_t id = SerializedHeaderData::decode(tags); 888 intptr_t id = SerializedHeaderData::decode(tags);
884 return forward_list_[id - kMaxPredefinedObjectIds]->tags(); 889 return forward_list_[id - kMaxPredefinedObjectIds]->tags();
885 } else { 890 } else {
886 return tags; 891 return tags;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 for (intptr_t i = 0; i < len; i++) { 1126 for (intptr_t i = 0; i < len; i++) {
1122 WriteObjectRef(data[i]); 1127 WriteObjectRef(data[i]);
1123 } 1128 }
1124 } 1129 }
1125 1130
1126 1131
1127 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { 1132 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) {
1128 ASSERT(kind() == Snapshot::kScript); 1133 ASSERT(kind() == Snapshot::kScript);
1129 1134
1130 // Write out the library object. 1135 // Write out the library object.
1136 ReserveHeader();
1131 WriteObject(lib.raw()); 1137 WriteObject(lib.raw());
1132 1138 FillHeader(kind());
1133 // Finalize the snapshot buffer. 1139 UnmarkAll();
1134 FinalizeBuffer();
1135 } 1140 }
1136 1141
1137 1142
1138 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { 1143 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
1139 for (RawObject** current = first; current <= last; current++) { 1144 for (RawObject** current = first; current <= last; current++) {
1140 RawObject* raw_obj = *current; 1145 RawObject* raw_obj = *current;
1141 if (as_references_) { 1146 if (as_references_) {
1142 writer_->WriteObjectRef(raw_obj); 1147 writer_->WriteObjectRef(raw_obj);
1143 } else { 1148 } else {
1144 writer_->WriteObjectImpl(raw_obj); 1149 writer_->WriteObjectImpl(raw_obj);
1145 } 1150 }
1146 } 1151 }
1147 } 1152 }
1148 1153
1154
1155 void MessageWriter::WriteMessage(const Object& obj) {
1156 ASSERT(kind() == Snapshot::kMessage);
1157 WriteObject(obj.raw());
1158 UnmarkAll();
1159 }
1160
1161
1149 } // namespace dart 1162 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698