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

Side by Side Diff: runtime/lib/isolate.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 | « no previous file | runtime/vm/dart.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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart.h" 8 #include "vm/dart.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 24 matching lines...) Expand all
35 intptr_t port_id_; 35 intptr_t port_id_;
36 }; 36 };
37 37
38 38
39 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 39 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
40 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 40 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
41 return reinterpret_cast<uint8_t*>(new_ptr); 41 return reinterpret_cast<uint8_t*>(new_ptr);
42 } 42 }
43 43
44 44
45 static uint8_t* SerializeObject(const Instance& obj) {
46 uint8_t* result = NULL;
47 SnapshotWriter writer(Snapshot::kMessage, &result, &allocator);
48 writer.WriteObject(obj.raw());
49 writer.FinalizeBuffer();
50 return result;
51 }
52
53
54 static void StoreError(Isolate* isolate, const Object& obj) { 45 static void StoreError(Isolate* isolate, const Object& obj) {
55 ASSERT(obj.IsError()); 46 ASSERT(obj.IsError());
56 Error& error = Error::Handle(); 47 Error& error = Error::Handle();
57 error ^= obj.raw(); 48 error ^= obj.raw();
58 isolate->object_store()->set_sticky_error(error); 49 isolate->object_store()->set_sticky_error(error);
59 } 50 }
60 51
61 52
62 // TODO(turnidge): Move to DartLibraryCalls. 53 // TODO(turnidge): Move to DartLibraryCalls.
63 RawObject* ReceivePortCreate(intptr_t port_id) { 54 RawObject* ReceivePortCreate(intptr_t port_id) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0)); 128 GET_NATIVE_ARGUMENT(Smi, id, arguments->At(0));
138 PortMap::ClosePort(id.Value()); 129 PortMap::ClosePort(id.Value());
139 } 130 }
140 131
141 132
142 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { 133 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) {
143 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0)); 134 GET_NATIVE_ARGUMENT(Smi, send_id, arguments->At(0));
144 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1)); 135 GET_NATIVE_ARGUMENT(Smi, reply_id, arguments->At(1));
145 // TODO(iposva): Allow for arbitrary messages to be sent. 136 // TODO(iposva): Allow for arbitrary messages to be sent.
146 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2)); 137 GET_NATIVE_ARGUMENT(Instance, obj, arguments->At(2));
147 uint8_t* data = SerializeObject(obj); 138
139 uint8_t* data = NULL;
140 MessageWriter writer(&data, &allocator);
141 writer.WriteMessage(obj);
148 142
149 // TODO(turnidge): Throw an exception when the return value is false? 143 // TODO(turnidge): Throw an exception when the return value is false?
150 PortMap::PostMessage(new Message( 144 PortMap::PostMessage(new Message(send_id.Value(), reply_id.Value(),
151 send_id.Value(), reply_id.Value(), data, Message::kNormalPriority)); 145 data, writer.BytesWritten(),
146 Message::kNormalPriority));
152 } 147 }
153 148
154 149
155 static void ThrowIllegalArgException(const String& message) { 150 static void ThrowIllegalArgException(const String& message) {
156 GrowableArray<const Object*> args(1); 151 GrowableArray<const Object*> args(1);
157 args.Add(&message); 152 args.Add(&message);
158 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 153 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
159 } 154 }
160 155
161 156
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 436
442 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { 437 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) {
443 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); 438 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port()));
444 if (port.IsError()) { 439 if (port.IsError()) {
445 Exceptions::PropagateError(Error::Cast(port)); 440 Exceptions::PropagateError(Error::Cast(port));
446 } 441 }
447 arguments->SetReturn(port); 442 arguments->SetReturn(port);
448 } 443 }
449 444
450 } // namespace dart 445 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698