OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/nacl/loader/nacl_ipc_adapter.h" | 5 #include "components/nacl/loader/nacl_ipc_adapter.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/basictypes.h" | |
11 #include "base/bind.h" | 10 #include "base/bind.h" |
12 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
15 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
16 #include "base/tuple.h" | 16 #include "base/tuple.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "ipc/ipc_channel.h" | 18 #include "ipc/ipc_channel.h" |
19 #include "ipc/ipc_platform_file.h" | 19 #include "ipc/ipc_platform_file.h" |
20 #include "native_client/src/public/nacl_desc.h" | 20 #include "native_client/src/public/nacl_desc.h" |
21 #include "native_client/src/public/nacl_desc_custom.h" | 21 #include "native_client/src/public/nacl_desc_custom.h" |
22 #include "native_client/src/trusted/desc/nacl_desc_quota.h" | 22 #include "native_client/src/trusted/desc/nacl_desc_quota.h" |
(...skipping 17 matching lines...) Expand all Loading... |
40 // The buffer contains a full message + extra data. | 40 // The buffer contains a full message + extra data. |
41 MESSAGE_HAS_EXTRA_DATA | 41 MESSAGE_HAS_EXTRA_DATA |
42 }; | 42 }; |
43 | 43 |
44 BufferSizeStatus GetBufferStatus(const char* data, size_t len) { | 44 BufferSizeStatus GetBufferStatus(const char* data, size_t len) { |
45 if (len < sizeof(NaClIPCAdapter::NaClMessageHeader)) | 45 if (len < sizeof(NaClIPCAdapter::NaClMessageHeader)) |
46 return MESSAGE_IS_TRUNCATED; | 46 return MESSAGE_IS_TRUNCATED; |
47 | 47 |
48 const NaClIPCAdapter::NaClMessageHeader* header = | 48 const NaClIPCAdapter::NaClMessageHeader* header = |
49 reinterpret_cast<const NaClIPCAdapter::NaClMessageHeader*>(data); | 49 reinterpret_cast<const NaClIPCAdapter::NaClMessageHeader*>(data); |
50 uint32 message_size = | 50 uint32_t message_size = |
51 sizeof(NaClIPCAdapter::NaClMessageHeader) + header->payload_size; | 51 sizeof(NaClIPCAdapter::NaClMessageHeader) + header->payload_size; |
52 | 52 |
53 if (len == message_size) | 53 if (len == message_size) |
54 return MESSAGE_IS_COMPLETE; | 54 return MESSAGE_IS_COMPLETE; |
55 if (len > message_size) | 55 if (len > message_size) |
56 return MESSAGE_HAS_EXTRA_DATA; | 56 return MESSAGE_HAS_EXTRA_DATA; |
57 return MESSAGE_IS_TRUNCATED; | 57 return MESSAGE_IS_TRUNCATED; |
58 } | 58 } |
59 | 59 |
60 //------------------------------------------------------------------------------ | 60 //------------------------------------------------------------------------------ |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 struct NaClDesc* desc = | 689 struct NaClDesc* desc = |
690 NaClDescCreateWithFilePathMetadata(handle, file_path_str.c_str()); | 690 NaClDescCreateWithFilePathMetadata(handle, file_path_str.c_str()); |
691 rewritten_msg->AddDescriptor(new NaClDescWrapper(desc)); | 691 rewritten_msg->AddDescriptor(new NaClDescWrapper(desc)); |
692 { | 692 { |
693 base::AutoLock lock(lock_); | 693 base::AutoLock lock(lock_); |
694 SaveMessage(*new_msg, rewritten_msg.get()); | 694 SaveMessage(*new_msg, rewritten_msg.get()); |
695 cond_var_.Signal(); | 695 cond_var_.Signal(); |
696 } | 696 } |
697 } | 697 } |
698 | 698 |
699 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { | 699 void NaClIPCAdapter::OnChannelConnected(int32_t peer_pid) {} |
700 } | |
701 | 700 |
702 void NaClIPCAdapter::OnChannelError() { | 701 void NaClIPCAdapter::OnChannelError() { |
703 CloseChannel(); | 702 CloseChannel(); |
704 } | 703 } |
705 | 704 |
706 NaClIPCAdapter::~NaClIPCAdapter() { | 705 NaClIPCAdapter::~NaClIPCAdapter() { |
707 // Make sure the channel is deleted on the IO thread. | 706 // Make sure the channel is deleted on the IO thread. |
708 task_runner_->PostTask(FROM_HERE, | 707 task_runner_->PostTask(FROM_HERE, |
709 base::Bind(&DeleteChannel, io_thread_data_.channel_.release())); | 708 base::Bind(&DeleteChannel, io_thread_data_.channel_.release())); |
710 } | 709 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 826 |
828 void NaClIPCAdapter::SaveMessage(const IPC::Message& msg, | 827 void NaClIPCAdapter::SaveMessage(const IPC::Message& msg, |
829 RewrittenMessage* rewritten_msg) { | 828 RewrittenMessage* rewritten_msg) { |
830 lock_.AssertAcquired(); | 829 lock_.AssertAcquired(); |
831 // There is some padding in this structure (the "padding" member is 16 | 830 // There is some padding in this structure (the "padding" member is 16 |
832 // bits but this then gets padded to 32 bits). We want to be sure not to | 831 // bits but this then gets padded to 32 bits). We want to be sure not to |
833 // leak data to the untrusted plugin, so zero everything out first. | 832 // leak data to the untrusted plugin, so zero everything out first. |
834 NaClMessageHeader header; | 833 NaClMessageHeader header; |
835 memset(&header, 0, sizeof(NaClMessageHeader)); | 834 memset(&header, 0, sizeof(NaClMessageHeader)); |
836 | 835 |
837 header.payload_size = static_cast<uint32>(msg.payload_size()); | 836 header.payload_size = static_cast<uint32_t>(msg.payload_size()); |
838 header.routing = msg.routing_id(); | 837 header.routing = msg.routing_id(); |
839 header.type = msg.type(); | 838 header.type = msg.type(); |
840 header.flags = msg.flags(); | 839 header.flags = msg.flags(); |
841 header.num_fds = static_cast<uint16>(rewritten_msg->desc_count()); | 840 header.num_fds = static_cast<uint16_t>(rewritten_msg->desc_count()); |
842 | 841 |
843 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); | 842 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); |
844 locked_data_.to_be_received_.push(rewritten_msg); | 843 locked_data_.to_be_received_.push(rewritten_msg); |
845 } | 844 } |
846 | 845 |
847 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { | 846 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { |
848 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); | 847 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); |
849 } | 848 } |
OLD | NEW |