| OLD | NEW |
| 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/native_message_handler.h" | 5 #include "vm/native_message_handler.h" |
| 6 | 6 |
| 7 #include "vm/dart_api_message.h" | 7 #include "vm/dart_api_message.h" |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/message.h" | 9 #include "vm/message.h" |
| 10 #include "vm/snapshot.h" | 10 #include "vm/snapshot.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 #if defined(DEBUG) | 29 #if defined(DEBUG) |
| 30 void NativeMessageHandler::CheckAccess() { | 30 void NativeMessageHandler::CheckAccess() { |
| 31 ASSERT(Isolate::Current() == NULL); | 31 ASSERT(Isolate::Current() == NULL); |
| 32 } | 32 } |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 | 35 |
| 36 static uint8_t* zone_allocator( | 36 static uint8_t* zone_allocator(uint8_t* ptr, |
| 37 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 37 intptr_t old_size, |
| 38 intptr_t new_size) { |
| 38 ApiZone* zone = ApiNativeScope::Current()->zone(); | 39 ApiZone* zone = ApiNativeScope::Current()->zone(); |
| 39 return reinterpret_cast<uint8_t*>( | 40 return zone->Realloc<uint8_t>(ptr, old_size, new_size); |
| 40 zone->Reallocate(reinterpret_cast<uword>(ptr), old_size, new_size)); | |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 bool NativeMessageHandler::HandleMessage(Message* message) { | 44 bool NativeMessageHandler::HandleMessage(Message* message) { |
| 45 if (message->IsOOB()) { | 45 if (message->IsOOB()) { |
| 46 // We currently do not use OOB messages for native ports. | 46 // We currently do not use OOB messages for native ports. |
| 47 UNREACHABLE(); | 47 UNREACHABLE(); |
| 48 } | 48 } |
| 49 // Enter a native scope for handling the message. This will create a | 49 // Enter a native scope for handling the message. This will create a |
| 50 // zone for allocating the objects for decoding the message. | 50 // zone for allocating the objects for decoding the message. |
| 51 ApiNativeScope scope; | 51 ApiNativeScope scope; |
| 52 | 52 |
| 53 int32_t length = reinterpret_cast<int32_t*>( | 53 int32_t length = reinterpret_cast<int32_t*>( |
| 54 message->data())[Snapshot::kLengthIndex]; | 54 message->data())[Snapshot::kLengthIndex]; |
| 55 ApiMessageReader reader(message->data() + Snapshot::kHeaderSize, | 55 ApiMessageReader reader(message->data() + Snapshot::kHeaderSize, |
| 56 length, | 56 length, |
| 57 zone_allocator); | 57 zone_allocator); |
| 58 Dart_CObject* object = reader.ReadMessage(); | 58 Dart_CObject* object = reader.ReadMessage(); |
| 59 (*func())(message->dest_port(), message->reply_port(), object); | 59 (*func())(message->dest_port(), message->reply_port(), object); |
| 60 delete message; | 60 delete message; |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace dart | 64 } // namespace dart |
| OLD | NEW |