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

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, 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 "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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 if (size == NULL) { 815 if (size == NULL) {
816 RETURN_NULL_ERROR(size); 816 RETURN_NULL_ERROR(size);
817 } 817 }
818 const char* msg = CheckIsolateState(isolate, 818 const char* msg = CheckIsolateState(isolate,
819 ClassFinalizer::kGeneratingSnapshot); 819 ClassFinalizer::kGeneratingSnapshot);
820 if (msg != NULL) { 820 if (msg != NULL) {
821 return Api::NewError(msg); 821 return Api::NewError(msg);
822 } 822 }
823 // Since this is only a snapshot the root library should not be set. 823 // Since this is only a snapshot the root library should not be set.
824 isolate->object_store()->set_root_library(Library::Handle(isolate)); 824 isolate->object_store()->set_root_library(Library::Handle(isolate));
825 SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate); 825 FullSnapshotWriter writer(buffer, ApiReallocate);
826 writer.WriteFullSnapshot(); 826 writer.WriteFullSnapshot();
827 *size = writer.BytesWritten(); 827 *size = writer.BytesWritten();
828 return Api::Success(isolate); 828 return Api::Success(isolate);
829 } 829 }
830 830
831 831
832 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, 832 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
833 intptr_t* size) { 833 intptr_t* size) {
834 Isolate* isolate = Isolate::Current(); 834 Isolate* isolate = Isolate::Current();
835 DARTSCOPE(isolate); 835 DARTSCOPE(isolate);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 946 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
947 return reinterpret_cast<uint8_t*>(new_ptr); 947 return reinterpret_cast<uint8_t*>(new_ptr);
948 } 948 }
949 949
950 950
951 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, 951 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id,
952 intptr_t len, 952 intptr_t len,
953 intptr_t* data) { 953 intptr_t* data) {
954 uint8_t* buffer = NULL; 954 uint8_t* buffer = NULL;
955 ApiMessageWriter writer(&buffer, &allocator); 955 ApiMessageWriter writer(&buffer, &allocator);
956
957 writer.WriteMessage(len, data); 956 writer.WriteMessage(len, data);
958 957
959 // Post the message at the given port. 958 // Post the message at the given port.
960 return PortMap::PostMessage(new Message( 959 return PortMap::PostMessage(new Message(
961 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); 960 port_id, Message::kIllegalPort, buffer, writer.BytesWritten(),
961 Message::kNormalPriority));
962 } 962 }
963 963
964 964
965 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { 965 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) {
966 uint8_t* buffer = NULL; 966 uint8_t* buffer = NULL;
967 ApiMessageWriter writer(&buffer, allocator); 967 ApiMessageWriter writer(&buffer, allocator);
968
969 writer.WriteCMessage(message); 968 writer.WriteCMessage(message);
970 969
971 // Post the message at the given port. 970 // Post the message at the given port.
972 return PortMap::PostMessage(new Message( 971 return PortMap::PostMessage(new Message(
973 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); 972 port_id, Message::kIllegalPort, buffer, writer.BytesWritten(),
973 Message::kNormalPriority));
974 } 974 }
975 975
976 976
977 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { 977 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
978 Isolate* isolate = Isolate::Current(); 978 Isolate* isolate = Isolate::Current();
979 CHECK_ISOLATE(isolate); 979 CHECK_ISOLATE(isolate);
980 DARTSCOPE_NOCHECKS(isolate); 980 DARTSCOPE_NOCHECKS(isolate);
981 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); 981 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle));
982 uint8_t* data = NULL; 982 uint8_t* data = NULL;
983 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); 983 MessageWriter writer(&data, &allocator);
984 writer.WriteObject(object.raw()); 984 writer.WriteMessage(object);
985 writer.FinalizeBuffer(); 985 intptr_t len = writer.BytesWritten();
986 return PortMap::PostMessage(new Message( 986 return PortMap::PostMessage(new Message(
987 port_id, Message::kIllegalPort, data, Message::kNormalPriority)); 987 port_id, Message::kIllegalPort, data, len, Message::kNormalPriority));
988 } 988 }
989 989
990 990
991 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, 991 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
992 Dart_NativeMessageHandler handler, 992 Dart_NativeMessageHandler handler,
993 bool handle_concurrently) { 993 bool handle_concurrently) {
994 if (name == NULL) { 994 if (name == NULL) {
995 name = "<UnnamedNativePort>"; 995 name = "<UnnamedNativePort>";
996 } 996 }
997 if (handler == NULL) { 997 if (handler == NULL) {
(...skipping 2781 matching lines...) Expand 10 before | Expand all | Expand 10 after
3779 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { 3779 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) {
3780 Isolate* isolate = Isolate::Current(); 3780 Isolate* isolate = Isolate::Current();
3781 DARTSCOPE(isolate); 3781 DARTSCOPE(isolate);
3782 TIMERSCOPE(time_script_loading); 3782 TIMERSCOPE(time_script_loading);
3783 if (buffer == NULL) { 3783 if (buffer == NULL) {
3784 RETURN_NULL_ERROR(buffer); 3784 RETURN_NULL_ERROR(buffer);
3785 } 3785 }
3786 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 3786 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
3787 if (!snapshot->IsScriptSnapshot()) { 3787 if (!snapshot->IsScriptSnapshot()) {
3788 return Api::NewError("%s expects parameter 'buffer' to be a script type" 3788 return Api::NewError("%s expects parameter 'buffer' to be a script type"
3789 " snapshot", CURRENT_FUNC); 3789 " snapshot.", CURRENT_FUNC);
3790 } 3790 }
3791 Library& library = 3791 Library& library =
3792 Library::Handle(isolate, isolate->object_store()->root_library()); 3792 Library::Handle(isolate, isolate->object_store()->root_library());
3793 if (!library.IsNull()) { 3793 if (!library.IsNull()) {
3794 const String& library_url = String::Handle(isolate, library.url()); 3794 const String& library_url = String::Handle(isolate, library.url());
3795 return Api::NewError("%s: A script has already been loaded from '%s'.", 3795 return Api::NewError("%s: A script has already been loaded from '%s'.",
3796 CURRENT_FUNC, library_url.ToCString()); 3796 CURRENT_FUNC, library_url.ToCString());
3797 } 3797 }
3798 SnapshotReader reader(snapshot, isolate); 3798 SnapshotReader reader(snapshot->content(),
3799 snapshot->length(),
3800 snapshot->kind(),
3801 isolate);
3799 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); 3802 const Object& tmp = Object::Handle(isolate, reader.ReadObject());
3800 if (!tmp.IsLibrary()) { 3803 if (!tmp.IsLibrary()) {
3801 return Api::NewError("%s: Unable to deserialize snapshot correctly.", 3804 return Api::NewError("%s: Unable to deserialize snapshot correctly.",
3802 CURRENT_FUNC); 3805 CURRENT_FUNC);
3803 } 3806 }
3804 library ^= tmp.raw(); 3807 library ^= tmp.raw();
3805 library.set_debuggable(true); 3808 library.set_debuggable(true);
3806 isolate->object_store()->set_root_library(library); 3809 isolate->object_store()->set_root_library(library);
3807 return Api::NewHandle(isolate, library.raw()); 3810 return Api::NewHandle(isolate, library.raw());
3808 } 3811 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
4081 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4084 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4082 Dart::set_perf_events_writer(function); 4085 Dart::set_perf_events_writer(function);
4083 } 4086 }
4084 4087
4085 4088
4086 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4089 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4087 Dart::set_flow_graph_writer(function); 4090 Dart::set_flow_graph_writer(function);
4088 } 4091 }
4089 4092
4090 } // namespace dart 4093 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_message.h » ('j') | runtime/vm/snapshot_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698