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

Side by Side Diff: runtime/vm/dart_api_impl.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/dart.cc ('k') | runtime/vm/dart_api_message.h » ('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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 } 808 }
809 if (size == NULL) { 809 if (size == NULL) {
810 RETURN_NULL_ERROR(size); 810 RETURN_NULL_ERROR(size);
811 } 811 }
812 const char* msg = CheckIsolateState(isolate); 812 const char* msg = CheckIsolateState(isolate);
813 if (msg != NULL) { 813 if (msg != NULL) {
814 return Api::NewError(msg); 814 return Api::NewError(msg);
815 } 815 }
816 // Since this is only a snapshot the root library should not be set. 816 // Since this is only a snapshot the root library should not be set.
817 isolate->object_store()->set_root_library(Library::Handle(isolate)); 817 isolate->object_store()->set_root_library(Library::Handle(isolate));
818 SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate); 818 FullSnapshotWriter writer(buffer, ApiReallocate);
819 writer.WriteFullSnapshot(); 819 writer.WriteFullSnapshot();
820 *size = writer.BytesWritten(); 820 *size = writer.BytesWritten();
821 return Api::Success(isolate); 821 return Api::Success(isolate);
822 } 822 }
823 823
824 824
825 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, 825 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
826 intptr_t* size) { 826 intptr_t* size) {
827 Isolate* isolate = Isolate::Current(); 827 Isolate* isolate = Isolate::Current();
828 DARTSCOPE(isolate); 828 DARTSCOPE(isolate);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 939 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
940 return reinterpret_cast<uint8_t*>(new_ptr); 940 return reinterpret_cast<uint8_t*>(new_ptr);
941 } 941 }
942 942
943 943
944 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, 944 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id,
945 intptr_t len, 945 intptr_t len,
946 intptr_t* data) { 946 intptr_t* data) {
947 uint8_t* buffer = NULL; 947 uint8_t* buffer = NULL;
948 ApiMessageWriter writer(&buffer, &allocator); 948 ApiMessageWriter writer(&buffer, &allocator);
949
950 writer.WriteMessage(len, data); 949 writer.WriteMessage(len, data);
951 950
952 // Post the message at the given port. 951 // Post the message at the given port.
953 return PortMap::PostMessage(new Message( 952 return PortMap::PostMessage(new Message(
954 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); 953 port_id, Message::kIllegalPort, buffer, writer.BytesWritten(),
954 Message::kNormalPriority));
955 } 955 }
956 956
957 957
958 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { 958 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) {
959 uint8_t* buffer = NULL; 959 uint8_t* buffer = NULL;
960 ApiMessageWriter writer(&buffer, allocator); 960 ApiMessageWriter writer(&buffer, allocator);
961
962 writer.WriteCMessage(message); 961 writer.WriteCMessage(message);
963 962
964 // Post the message at the given port. 963 // Post the message at the given port.
965 return PortMap::PostMessage(new Message( 964 return PortMap::PostMessage(new Message(
966 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); 965 port_id, Message::kIllegalPort, buffer, writer.BytesWritten(),
966 Message::kNormalPriority));
967 } 967 }
968 968
969 969
970 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { 970 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
971 Isolate* isolate = Isolate::Current(); 971 Isolate* isolate = Isolate::Current();
972 CHECK_ISOLATE(isolate); 972 CHECK_ISOLATE(isolate);
973 DARTSCOPE_NOCHECKS(isolate); 973 DARTSCOPE_NOCHECKS(isolate);
974 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); 974 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle));
975 uint8_t* data = NULL; 975 uint8_t* data = NULL;
976 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); 976 MessageWriter writer(&data, &allocator);
977 writer.WriteObject(object.raw()); 977 writer.WriteMessage(object);
978 writer.FinalizeBuffer(); 978 intptr_t len = writer.BytesWritten();
979 return PortMap::PostMessage(new Message( 979 return PortMap::PostMessage(new Message(
980 port_id, Message::kIllegalPort, data, Message::kNormalPriority)); 980 port_id, Message::kIllegalPort, data, len, Message::kNormalPriority));
981 } 981 }
982 982
983 983
984 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, 984 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
985 Dart_NativeMessageHandler handler, 985 Dart_NativeMessageHandler handler,
986 bool handle_concurrently) { 986 bool handle_concurrently) {
987 if (name == NULL) { 987 if (name == NULL) {
988 name = "<UnnamedNativePort>"; 988 name = "<UnnamedNativePort>";
989 } 989 }
990 if (handler == NULL) { 990 if (handler == NULL) {
(...skipping 2829 matching lines...) Expand 10 before | Expand all | Expand 10 after
3820 TIMERSCOPE(time_script_loading); 3820 TIMERSCOPE(time_script_loading);
3821 if (buffer == NULL) { 3821 if (buffer == NULL) {
3822 RETURN_NULL_ERROR(buffer); 3822 RETURN_NULL_ERROR(buffer);
3823 } 3823 }
3824 if (FLAG_use_cha) { 3824 if (FLAG_use_cha) {
3825 RemoveOptimizedCode(); 3825 RemoveOptimizedCode();
3826 } 3826 }
3827 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 3827 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
3828 if (!snapshot->IsScriptSnapshot()) { 3828 if (!snapshot->IsScriptSnapshot()) {
3829 return Api::NewError("%s expects parameter 'buffer' to be a script type" 3829 return Api::NewError("%s expects parameter 'buffer' to be a script type"
3830 " snapshot", CURRENT_FUNC); 3830 " snapshot.", CURRENT_FUNC);
3831 } 3831 }
3832 Library& library = 3832 Library& library =
3833 Library::Handle(isolate, isolate->object_store()->root_library()); 3833 Library::Handle(isolate, isolate->object_store()->root_library());
3834 if (!library.IsNull()) { 3834 if (!library.IsNull()) {
3835 const String& library_url = String::Handle(isolate, library.url()); 3835 const String& library_url = String::Handle(isolate, library.url());
3836 return Api::NewError("%s: A script has already been loaded from '%s'.", 3836 return Api::NewError("%s: A script has already been loaded from '%s'.",
3837 CURRENT_FUNC, library_url.ToCString()); 3837 CURRENT_FUNC, library_url.ToCString());
3838 } 3838 }
3839 SnapshotReader reader(snapshot, isolate); 3839 SnapshotReader reader(snapshot->content(),
3840 snapshot->length(),
3841 snapshot->kind(),
3842 isolate);
3840 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); 3843 const Object& tmp = Object::Handle(isolate, reader.ReadObject());
3841 if (!tmp.IsLibrary()) { 3844 if (!tmp.IsLibrary()) {
3842 return Api::NewError("%s: Unable to deserialize snapshot correctly.", 3845 return Api::NewError("%s: Unable to deserialize snapshot correctly.",
3843 CURRENT_FUNC); 3846 CURRENT_FUNC);
3844 } 3847 }
3845 library ^= tmp.raw(); 3848 library ^= tmp.raw();
3846 library.set_debuggable(true); 3849 library.set_debuggable(true);
3847 isolate->object_store()->set_root_library(library); 3850 isolate->object_store()->set_root_library(library);
3848 return Api::NewHandle(isolate, library.raw()); 3851 return Api::NewHandle(isolate, library.raw());
3849 } 3852 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4131 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4129 Dart::set_perf_events_writer(function); 4132 Dart::set_perf_events_writer(function);
4130 } 4133 }
4131 4134
4132 4135
4133 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4136 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4134 Dart::set_flow_graph_writer(function); 4137 Dart::set_flow_graph_writer(function);
4135 } 4138 }
4136 4139
4137 } // namespace dart 4140 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698