| 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 "chrome/nacl/nacl_ipc_adapter.h" | 5 #include "chrome/nacl/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" | 10 #include "base/basictypes.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return -1; | 67 return -1; |
| 68 return static_cast<ssize_t>( | 68 return static_cast<ssize_t>( |
| 69 ToAdapter(handle)->Send(static_cast<char*>(msg->iov[0].base), | 69 ToAdapter(handle)->Send(static_cast<char*>(msg->iov[0].base), |
| 70 msg->iov[0].length)); | 70 msg->iov[0].length)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ssize_t NaClDescCustomRecvMsg(void* handle, NaClImcTypedMsgHdr* msg, | 73 ssize_t NaClDescCustomRecvMsg(void* handle, NaClImcTypedMsgHdr* msg, |
| 74 int /* flags */) { | 74 int /* flags */) { |
| 75 if (msg->iov_length != 1) | 75 if (msg->iov_length != 1) |
| 76 return -1; | 76 return -1; |
| 77 msg->ndesc_length = 0; // Messages with descriptors aren't supported yet. |
| 77 return static_cast<ssize_t>( | 78 return static_cast<ssize_t>( |
| 78 ToAdapter(handle)->BlockingReceive(static_cast<char*>(msg->iov[0].base), | 79 ToAdapter(handle)->BlockingReceive(static_cast<char*>(msg->iov[0].base), |
| 79 msg->iov[0].length)); | 80 msg->iov[0].length)); |
| 80 } | 81 } |
| 81 | 82 |
| 82 NaClDesc* MakeNaClDescCustom(NaClIPCAdapter* adapter) { | 83 NaClDesc* MakeNaClDescCustom(NaClIPCAdapter* adapter) { |
| 83 NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER; | 84 NaClDescCustomFuncs funcs = NACL_DESC_CUSTOM_FUNCS_INITIALIZER; |
| 84 funcs.Destroy = NaClDescCustomDestroy; | 85 funcs.Destroy = NaClDescCustomDestroy; |
| 85 funcs.SendMsg = NaClDescCustomSendMsg; | 86 funcs.SendMsg = NaClDescCustomSendMsg; |
| 86 funcs.RecvMsg = NaClDescCustomRecvMsg; | 87 funcs.RecvMsg = NaClDescCustomRecvMsg; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 cond_var_.Signal(); | 275 cond_var_.Signal(); |
| 275 | 276 |
| 276 task_runner_->PostTask(FROM_HERE, | 277 task_runner_->PostTask(FROM_HERE, |
| 277 base::Bind(&NaClIPCAdapter::CloseChannelOnIOThread, this)); | 278 base::Bind(&NaClIPCAdapter::CloseChannelOnIOThread, this)); |
| 278 } | 279 } |
| 279 | 280 |
| 280 NaClDesc* NaClIPCAdapter::MakeNaClDesc() { | 281 NaClDesc* NaClIPCAdapter::MakeNaClDesc() { |
| 281 return MakeNaClDescCustom(this); | 282 return MakeNaClDescCustom(this); |
| 282 } | 283 } |
| 283 | 284 |
| 285 #if defined(OS_POSIX) |
| 286 int NaClIPCAdapter::TakeClientFileDescriptor() { |
| 287 return io_thread_data_.channel_->TakeClientFileDescriptor(); |
| 288 } |
| 289 #endif |
| 290 |
| 284 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& message) { | 291 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& message) { |
| 285 { | 292 { |
| 286 base::AutoLock lock(lock_); | 293 base::AutoLock lock(lock_); |
| 287 | 294 |
| 288 // There is some padding in this structure (the "padding" member is 16 | 295 // There is some padding in this structure (the "padding" member is 16 |
| 289 // bits but this then gets padded to 32 bits). We want to be sure not to | 296 // bits but this then gets padded to 32 bits). We want to be sure not to |
| 290 // leak data to the untrusted plugin, so zero everything out first. | 297 // leak data to the untrusted plugin, so zero everything out first. |
| 291 NaClMessageHeader header; | 298 NaClMessageHeader header; |
| 292 memset(&header, 0, sizeof(NaClMessageHeader)); | 299 memset(&header, 0, sizeof(NaClMessageHeader)); |
| 293 | 300 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 NOTREACHED(); | 400 NOTREACHED(); |
| 394 } | 401 } |
| 395 | 402 |
| 396 void NaClIPCAdapter::CloseChannelOnIOThread() { | 403 void NaClIPCAdapter::CloseChannelOnIOThread() { |
| 397 io_thread_data_.channel_->Close(); | 404 io_thread_data_.channel_->Close(); |
| 398 } | 405 } |
| 399 | 406 |
| 400 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) { | 407 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) { |
| 401 io_thread_data_.channel_->Send(message.release()); | 408 io_thread_data_.channel_->Send(message.release()); |
| 402 } | 409 } |
| OLD | NEW |