| 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 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
| 15 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 16 #include "base/tuple.h" | 17 #include "base/tuple.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // to the owning scoped_refptr, which is supposed to give us our first | 359 // to the owning scoped_refptr, which is supposed to give us our first |
| 359 // ref-count. | 360 // ref-count. |
| 360 } | 361 } |
| 361 | 362 |
| 362 NaClIPCAdapter::NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, | 363 NaClIPCAdapter::NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, |
| 363 base::TaskRunner* runner) | 364 base::TaskRunner* runner) |
| 364 : lock_(), | 365 : lock_(), |
| 365 cond_var_(&lock_), | 366 cond_var_(&lock_), |
| 366 task_runner_(runner), | 367 task_runner_(runner), |
| 367 locked_data_() { | 368 locked_data_() { |
| 368 io_thread_data_.channel_ = channel.Pass(); | 369 io_thread_data_.channel_ = std::move(channel); |
| 369 } | 370 } |
| 370 | 371 |
| 371 void NaClIPCAdapter::ConnectChannel() { | 372 void NaClIPCAdapter::ConnectChannel() { |
| 372 task_runner_->PostTask(FROM_HERE, | 373 task_runner_->PostTask(FROM_HERE, |
| 373 base::Bind(&NaClIPCAdapter::ConnectChannelOnIOThread, this)); | 374 base::Bind(&NaClIPCAdapter::ConnectChannelOnIOThread, this)); |
| 374 } | 375 } |
| 375 | 376 |
| 376 // Note that this message is controlled by the untrusted code. So we should be | 377 // Note that this message is controlled by the untrusted code. So we should be |
| 377 // skeptical of anything it contains and quick to give up if anything is fishy. | 378 // skeptical of anything it contains and quick to give up if anything is fishy. |
| 378 int NaClIPCAdapter::Send(const NaClImcTypedMsgHdr* msg) { | 379 int NaClIPCAdapter::Send(const NaClImcTypedMsgHdr* msg) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 new_msg.get()); | 630 new_msg.get()); |
| 630 new_msg->WriteBool(true); // valid == true | 631 new_msg->WriteBool(true); // valid == true |
| 631 new_msg->WriteBool(false); // brokerable == false | 632 new_msg->WriteBool(false); // brokerable == false |
| 632 // The file descriptor is at index 0. There's only ever one file | 633 // The file descriptor is at index 0. There's only ever one file |
| 633 // descriptor provided for this message type, so this will be correct. | 634 // descriptor provided for this message type, so this will be correct. |
| 634 new_msg->WriteInt(0); | 635 new_msg->WriteInt(0); |
| 635 | 636 |
| 636 // Write empty file tokens. | 637 // Write empty file tokens. |
| 637 new_msg->WriteUInt64(0); // token_lo | 638 new_msg->WriteUInt64(0); // token_lo |
| 638 new_msg->WriteUInt64(0); // token_hi | 639 new_msg->WriteUInt64(0); // token_hi |
| 639 return new_msg.Pass(); | 640 return new_msg; |
| 640 } | 641 } |
| 641 | 642 |
| 642 void NaClIPCAdapter::SaveOpenResourceMessage( | 643 void NaClIPCAdapter::SaveOpenResourceMessage( |
| 643 const IPC::Message& orig_msg, | 644 const IPC::Message& orig_msg, |
| 644 IPC::PlatformFileForTransit ipc_fd, | 645 IPC::PlatformFileForTransit ipc_fd, |
| 645 base::FilePath file_path) { | 646 base::FilePath file_path) { |
| 646 // The path where an invalid ipc_fd is returned isn't currently | 647 // The path where an invalid ipc_fd is returned isn't currently |
| 647 // covered by any tests. | 648 // covered by any tests. |
| 648 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) { | 649 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) { |
| 649 // The file token didn't resolve successfully, so we give the | 650 // The file token didn't resolve successfully, so we give the |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 header.flags = msg.flags(); | 840 header.flags = msg.flags(); |
| 840 header.num_fds = static_cast<uint16_t>(rewritten_msg->desc_count()); | 841 header.num_fds = static_cast<uint16_t>(rewritten_msg->desc_count()); |
| 841 | 842 |
| 842 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); | 843 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); |
| 843 locked_data_.to_be_received_.push(rewritten_msg); | 844 locked_data_.to_be_received_.push(rewritten_msg); |
| 844 } | 845 } |
| 845 | 846 |
| 846 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { | 847 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { |
| 847 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); | 848 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); |
| 848 } | 849 } |
| OLD | NEW |