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

Side by Side Diff: runtime/bin/vmservice_impl.cc

Issue 131973007: Allow root level requests in the vm service. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "bin/vmservice_impl.h" 5 #include "bin/vmservice_impl.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
11 #include "bin/isolate_data.h" 11 #include "bin/isolate_data.h"
12 #include "bin/resources.h" 12 #include "bin/resources.h"
13 #include "bin/thread.h" 13 #include "bin/thread.h"
14 14
15 #include "vm/dart_api_impl.h" 15 #include "vm/dart_api_impl.h"
16 #include "vm/dart_entry.h" 16 #include "vm/dart_entry.h"
17 #include "vm/isolate.h" 17 #include "vm/isolate.h"
18 #include "vm/message.h" 18 #include "vm/message.h"
19 #include "vm/native_entry.h" 19 #include "vm/native_entry.h"
20 #include "vm/native_arguments.h" 20 #include "vm/native_arguments.h"
21 #include "vm/object.h" 21 #include "vm/object.h"
22 #include "vm/port.h" 22 #include "vm/port.h"
23 #include "vm/service.h"
23 #include "vm/snapshot.h" 24 #include "vm/snapshot.h"
24 25
25 namespace dart { 26 namespace dart {
26 namespace bin { 27 namespace bin {
27 28
28 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise 29 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise
29 // it is initialized to NULL. 30 // it is initialized to NULL.
30 extern const uint8_t* snapshot_buffer; 31 extern const uint8_t* snapshot_buffer;
31 #define RETURN_ERROR_HANDLE(handle) \ 32 #define RETURN_ERROR_HANDLE(handle) \
32 if (Dart_IsError(handle)) { \ 33 if (Dart_IsError(handle)) { \
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 Dart_ExitScope(); 480 Dart_ExitScope();
480 } 481 }
481 482
482 483
483 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 484 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
484 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 485 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
485 return reinterpret_cast<uint8_t*>(new_ptr); 486 return reinterpret_cast<uint8_t*>(new_ptr);
486 } 487 }
487 488
488 489
489 static void SendServiceMessage(Dart_NativeArguments args) { 490 static void SendIsolateServiceMessage(Dart_NativeArguments args) {
490 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 491 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
491 Isolate* isolate = arguments->isolate(); 492 Isolate* isolate = arguments->isolate();
492 StackZone zone(isolate); 493 StackZone zone(isolate);
493 HANDLESCOPE(isolate); 494 HANDLESCOPE(isolate);
494 GET_NON_NULL_NATIVE_ARGUMENT(Instance, sp, arguments->NativeArgAt(0)); 495 GET_NON_NULL_NATIVE_ARGUMENT(Instance, sp, arguments->NativeArgAt(0));
495 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(1)); 496 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(1));
496 497
497 // Extract SendPort port id. 498 // Extract SendPort port id.
498 const Object& sp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(sp)); 499 const Object& sp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(sp));
499 if (sp_id_obj.IsError()) { 500 if (sp_id_obj.IsError()) {
500 Exceptions::PropagateError(Error::Cast(sp_id_obj)); 501 Exceptions::PropagateError(Error::Cast(sp_id_obj));
501 } 502 }
502 Integer& id = Integer::Handle(); 503 Integer& id = Integer::Handle(isolate);
503 id ^= sp_id_obj.raw(); 504 id ^= sp_id_obj.raw();
504 Dart_Port sp_id = static_cast<Dart_Port>(id.AsInt64Value()); 505 Dart_Port sp_id = static_cast<Dart_Port>(id.AsInt64Value());
505 ASSERT(sp_id != ILLEGAL_PORT); 506 ASSERT(sp_id != ILLEGAL_PORT);
506 507
507 // Serialize message. 508 // Serialize message.
508 uint8_t* data = NULL; 509 uint8_t* data = NULL;
509 MessageWriter writer(&data, &allocator); 510 MessageWriter writer(&data, &allocator);
510 writer.WriteMessage(message); 511 writer.WriteMessage(message);
511 512
512 // TODO(turnidge): Throw an exception when the return value is false? 513 // TODO(turnidge): Throw an exception when the return value is false?
513 PortMap::PostMessage(new Message(sp_id, data, writer.BytesWritten(), 514 PortMap::PostMessage(new Message(sp_id, data, writer.BytesWritten(),
514 Message::kOOBPriority)); 515 Message::kOOBPriority));
515 } 516 }
516 517
517 518
519 static void SendRootServiceMessage(Dart_NativeArguments args) {
520 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
521 Isolate* isolate = arguments->isolate();
522 StackZone zone(isolate);
523 HANDLESCOPE(isolate);
524 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0));
525 Service::HandleRootMessage(message);
526 }
527
528
518 struct VmServiceNativeEntry { 529 struct VmServiceNativeEntry {
519 const char* name; 530 const char* name;
520 int num_arguments; 531 int num_arguments;
521 Dart_NativeFunction function; 532 Dart_NativeFunction function;
522 }; 533 };
523 534
524 535
525 static VmServiceNativeEntry _VmServiceNativeEntries[] = { 536 static VmServiceNativeEntry _VmServiceNativeEntries[] = {
526 {"VMService_SendServiceMessage", 2, SendServiceMessage} 537 {"VMService_SendServiceMessage", 2, SendIsolateServiceMessage},
538 {"VMService_SendRootServiceMessage", 1, SendRootServiceMessage}
527 }; 539 };
528 540
529 541
530 static Dart_NativeFunction VmServiceNativeResolver(Dart_Handle name, 542 static Dart_NativeFunction VmServiceNativeResolver(Dart_Handle name,
531 int num_arguments, 543 int num_arguments,
532 bool* auto_setup_scope) { 544 bool* auto_setup_scope) {
533 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); 545 const Object& obj = Object::Handle(Api::UnwrapHandle(name));
534 if (!obj.IsString()) { 546 if (!obj.IsString()) {
535 return NULL; 547 return NULL;
536 } 548 }
537 const char* function_name = obj.ToCString(); 549 const char* function_name = obj.ToCString();
538 ASSERT(function_name != NULL); 550 ASSERT(function_name != NULL);
539 ASSERT(auto_setup_scope != NULL); 551 ASSERT(auto_setup_scope != NULL);
540 *auto_setup_scope = true; 552 *auto_setup_scope = true;
541 intptr_t n = 553 intptr_t n =
542 sizeof(_VmServiceNativeEntries) / sizeof(_VmServiceNativeEntries[0]); 554 sizeof(_VmServiceNativeEntries) / sizeof(_VmServiceNativeEntries[0]);
543 for (intptr_t i = 0; i < n; i++) { 555 for (intptr_t i = 0; i < n; i++) {
544 VmServiceNativeEntry entry = _VmServiceNativeEntries[i]; 556 VmServiceNativeEntry entry = _VmServiceNativeEntries[i];
545 if (!strcmp(function_name, entry.name) && 557 if (!strcmp(function_name, entry.name) &&
546 (num_arguments == entry.num_arguments)) { 558 (num_arguments == entry.num_arguments)) {
547 return entry.function; 559 return entry.function;
548 } 560 }
549 } 561 }
550 return NULL; 562 return NULL;
551 } 563 }
552 564
553 } // namespace bin 565 } // namespace bin
554 } // namespace dart 566 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698