Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_channel_nacl.h" | 5 #include "ipc/ipc_channel_nacl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/nacl_imc_api.h> | |
| 10 #include <sys/nacl_syscalls.h> | |
| 11 #include <sys/types.h> | 9 #include <sys/types.h> |
| 12 | 10 |
| 13 #include <algorithm> | 11 #include <algorithm> |
| 14 | 12 |
| 15 #include "base/bind.h" | 13 #include "base/bind.h" |
| 16 #include "base/logging.h" | 14 #include "base/logging.h" |
| 17 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
| 18 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 19 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 20 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 21 #include "base/threading/simple_thread.h" | 19 #include "base/threading/simple_thread.h" |
| 22 #include "ipc/file_descriptor_set_posix.h" | 20 #include "ipc/file_descriptor_set_posix.h" |
| 23 #include "ipc/ipc_logging.h" | 21 #include "ipc/ipc_logging.h" |
| 22 #include "native_client/src/public/imc_syscalls.h" | |
| 23 #include "native_client/src/public/imc_types.h" | |
|
dmichael (off chromium)
2013/06/05 17:08:18
(nit: You'll have to update DEPS for this)
| |
| 24 | 24 |
| 25 namespace IPC { | 25 namespace IPC { |
| 26 | 26 |
| 27 struct MessageContents { | 27 struct MessageContents { |
| 28 std::vector<char> data; | 28 std::vector<char> data; |
| 29 std::vector<int> fds; | 29 std::vector<int> fds; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool ReadDataOnReaderThread(int pipe, MessageContents* contents) { | 34 bool ReadDataOnReaderThread(int pipe, MessageContents* contents) { |
| 35 DCHECK(pipe >= 0); | 35 DCHECK(pipe >= 0); |
| 36 if (pipe < 0) | 36 if (pipe < 0) |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 contents->data.resize(Channel::kReadBufferSize); | 39 contents->data.resize(Channel::kReadBufferSize); |
| 40 contents->fds.resize(FileDescriptorSet::kMaxDescriptorsPerMessage); | 40 contents->fds.resize(FileDescriptorSet::kMaxDescriptorsPerMessage); |
| 41 | 41 |
| 42 NaClImcMsgIoVec iov = { &contents->data[0], contents->data.size() }; | 42 NaClAbiNaClImcMsgIoVec iov = { &contents->data[0], contents->data.size() }; |
| 43 NaClImcMsgHdr msg = { &iov, 1, &contents->fds[0], contents->fds.size() }; | 43 NaClAbiNaClImcMsgHdr msg = { |
| 44 &iov, 1, &contents->fds[0], contents->fds.size() | |
| 45 }; | |
| 44 | 46 |
| 45 int bytes_read = imc_recvmsg(pipe, &msg, 0); | 47 int bytes_read = imc_recvmsg(pipe, &msg, 0); |
| 46 | 48 |
| 47 if (bytes_read <= 0) { | 49 if (bytes_read <= 0) { |
| 48 // NaClIPCAdapter::BlockingReceive returns -1 when the pipe closes (either | 50 // NaClIPCAdapter::BlockingReceive returns -1 when the pipe closes (either |
| 49 // due to error or for regular shutdown). | 51 // due to error or for regular shutdown). |
| 50 contents->data.clear(); | 52 contents->data.clear(); |
| 51 contents->fds.clear(); | 53 contents->fds.clear(); |
| 52 return false; | 54 return false; |
| 53 } | 55 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 // block. See NaClIPCAdapter::Send for the implementation of imc_sendmsg. | 259 // block. See NaClIPCAdapter::Send for the implementation of imc_sendmsg. |
| 258 while (!output_queue_.empty()) { | 260 while (!output_queue_.empty()) { |
| 259 linked_ptr<Message> msg = output_queue_.front(); | 261 linked_ptr<Message> msg = output_queue_.front(); |
| 260 output_queue_.pop_front(); | 262 output_queue_.pop_front(); |
| 261 | 263 |
| 262 int fds[FileDescriptorSet::kMaxDescriptorsPerMessage]; | 264 int fds[FileDescriptorSet::kMaxDescriptorsPerMessage]; |
| 263 const size_t num_fds = msg->file_descriptor_set()->size(); | 265 const size_t num_fds = msg->file_descriptor_set()->size(); |
| 264 DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage); | 266 DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage); |
| 265 msg->file_descriptor_set()->GetDescriptors(fds); | 267 msg->file_descriptor_set()->GetDescriptors(fds); |
| 266 | 268 |
| 267 NaClImcMsgIoVec iov = { const_cast<void*>(msg->data()), msg->size() }; | 269 NaClAbiNaClImcMsgIoVec iov = { |
| 268 NaClImcMsgHdr msgh = { &iov, 1, fds, num_fds }; | 270 const_cast<void*>(msg->data()), msg->size() |
| 271 }; | |
| 272 NaClAbiNaClImcMsgHdr msgh = { &iov, 1, fds, num_fds }; | |
| 269 ssize_t bytes_written = imc_sendmsg(pipe_, &msgh, 0); | 273 ssize_t bytes_written = imc_sendmsg(pipe_, &msgh, 0); |
| 270 | 274 |
| 271 DCHECK(bytes_written); // The trusted side shouldn't return 0. | 275 DCHECK(bytes_written); // The trusted side shouldn't return 0. |
| 272 if (bytes_written < 0) { | 276 if (bytes_written < 0) { |
| 273 // The trusted side should only ever give us an error of EPIPE. We | 277 // The trusted side should only ever give us an error of EPIPE. We |
| 274 // should never be interrupted, nor should we get EAGAIN. | 278 // should never be interrupted, nor should we get EAGAIN. |
| 275 DCHECK(errno == EPIPE); | 279 DCHECK(errno == EPIPE); |
| 276 Close(); | 280 Close(); |
| 277 PLOG(ERROR) << "pipe_ error on " | 281 PLOG(ERROR) << "pipe_ error on " |
| 278 << pipe_ | 282 << pipe_ |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 // This shouldn't actually get used in the untrusted side of the proxy, and we | 376 // This shouldn't actually get used in the untrusted side of the proxy, and we |
| 373 // don't have the real pid anyway. | 377 // don't have the real pid anyway. |
| 374 return -1; | 378 return -1; |
| 375 } | 379 } |
| 376 | 380 |
| 377 bool Channel::Send(Message* message) { | 381 bool Channel::Send(Message* message) { |
| 378 return channel_impl_->Send(message); | 382 return channel_impl_->Send(message); |
| 379 } | 383 } |
| 380 | 384 |
| 381 } // namespace IPC | 385 } // namespace IPC |
| OLD | NEW |