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" | 10 #include "base/basictypes.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 #endif | 370 #endif |
371 | 371 |
372 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) { | 372 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) { |
373 { | 373 { |
374 base::AutoLock lock(lock_); | 374 base::AutoLock lock(lock_); |
375 | 375 |
376 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); | 376 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); |
377 | 377 |
378 typedef std::vector<ppapi::proxy::SerializedHandle> Handles; | 378 typedef std::vector<ppapi::proxy::SerializedHandle> Handles; |
379 Handles handles; | 379 Handles handles; |
380 scoped_ptr<IPC::Message> new_msg_ptr; | 380 scoped_ptr<IPC::Message> new_msg; |
381 bool success = locked_data_.handle_converter_.ConvertNativeHandlesToPosix( | 381 if (!locked_data_.nacl_msg_scanner_.ScanMessage(msg, &handles, &new_msg)) |
382 msg, &handles, &new_msg_ptr); | |
383 if (!success) | |
384 return false; | 382 return false; |
385 | 383 |
386 // Now add any descriptors we found to rewritten_msg. |handles| is usually | 384 // Now add any descriptors we found to rewritten_msg. |handles| is usually |
387 // empty, unless we read a message containing a FD or handle. | 385 // empty, unless we read a message containing a FD or handle. |
388 for (Handles::const_iterator iter = handles.begin(); | 386 for (Handles::const_iterator iter = handles.begin(); |
389 iter != handles.end(); | 387 iter != handles.end(); |
390 ++iter) { | 388 ++iter) { |
391 scoped_ptr<NaClDescWrapper> nacl_desc; | 389 scoped_ptr<NaClDescWrapper> nacl_desc; |
392 switch (iter->type()) { | 390 switch (iter->type()) { |
393 case ppapi::proxy::SerializedHandle::SHARED_MEMORY: { | 391 case ppapi::proxy::SerializedHandle::SHARED_MEMORY: { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 case ppapi::proxy::SerializedHandle::INVALID: { | 450 case ppapi::proxy::SerializedHandle::INVALID: { |
453 // Nothing to do. TODO(dmichael): Should we log this? Or is it | 451 // Nothing to do. TODO(dmichael): Should we log this? Or is it |
454 // sometimes okay to pass an INVALID handle? | 452 // sometimes okay to pass an INVALID handle? |
455 break; | 453 break; |
456 } | 454 } |
457 // No default, so the compiler will warn us if new types get added. | 455 // No default, so the compiler will warn us if new types get added. |
458 } | 456 } |
459 if (nacl_desc.get()) | 457 if (nacl_desc.get()) |
460 rewritten_msg->AddDescriptor(nacl_desc.release()); | 458 rewritten_msg->AddDescriptor(nacl_desc.release()); |
461 } | 459 } |
462 if (new_msg_ptr && !handles.empty()) | 460 if (new_msg && !handles.empty()) |
bbudge
2013/10/30 19:01:34
I wonder if we really need to check 'handles' afte
dmichael (off chromium)
2013/10/30 20:57:57
I think the issue is that ScanMessage only writes
| |
463 SaveMessage(*new_msg_ptr, rewritten_msg.get()); | 461 SaveMessage(*new_msg, rewritten_msg.get()); |
464 else | 462 else |
465 SaveMessage(msg, rewritten_msg.get()); | 463 SaveMessage(msg, rewritten_msg.get()); |
466 } | 464 } |
467 cond_var_.Signal(); | 465 cond_var_.Signal(); |
468 return true; | 466 return true; |
469 } | 467 } |
470 | 468 |
471 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { | 469 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { |
472 } | 470 } |
473 | 471 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 reinterpret_cast<const NaClMessageHeader*>(buffer); | 505 reinterpret_cast<const NaClMessageHeader*>(buffer); |
508 | 506 |
509 // Length of the message not including the body. The data passed to us by the | 507 // Length of the message not including the body. The data passed to us by the |
510 // plugin should match that in the message header. This should have already | 508 // plugin should match that in the message header. This should have already |
511 // been validated by GetBufferStatus. | 509 // been validated by GetBufferStatus. |
512 int body_len = static_cast<int>(buffer_len - sizeof(NaClMessageHeader)); | 510 int body_len = static_cast<int>(buffer_len - sizeof(NaClMessageHeader)); |
513 DCHECK(body_len == static_cast<int>(header->payload_size)); | 511 DCHECK(body_len == static_cast<int>(header->payload_size)); |
514 | 512 |
515 // We actually discard the flags and only copy the ones we care about. This | 513 // We actually discard the flags and only copy the ones we care about. This |
516 // is just because message doesn't have a constructor that takes raw flags. | 514 // is just because message doesn't have a constructor that takes raw flags. |
517 scoped_ptr<IPC::Message> msg( | 515 scoped_ptr<IPC::Message> msg(new IPC::Message(header->routing, header->type)); |
518 new IPC::Message(header->routing, header->type)); | |
519 if (header->flags & IPC::Message::SYNC_BIT) | 516 if (header->flags & IPC::Message::SYNC_BIT) |
520 msg->set_sync(); | 517 msg->set_sync(); |
521 if (header->flags & IPC::Message::REPLY_BIT) | 518 if (header->flags & IPC::Message::REPLY_BIT) |
522 msg->set_reply(); | 519 msg->set_reply(); |
523 if (header->flags & IPC::Message::REPLY_ERROR_BIT) | 520 if (header->flags & IPC::Message::REPLY_ERROR_BIT) |
524 msg->set_reply_error(); | 521 msg->set_reply_error(); |
525 if (header->flags & IPC::Message::UNBLOCK_BIT) | 522 if (header->flags & IPC::Message::UNBLOCK_BIT) |
526 msg->set_unblock(true); | 523 msg->set_unblock(true); |
527 | 524 |
528 msg->WriteBytes(&buffer[sizeof(NaClMessageHeader)], body_len); | 525 msg->WriteBytes(&buffer[sizeof(NaClMessageHeader)], body_len); |
529 | 526 |
530 // Technically we didn't have to do any of the previous work in the lock. But | 527 // Technically we didn't have to do any of the previous work in the lock. But |
531 // sometimes our buffer will point to the to_be_sent_ string which is | 528 // sometimes our buffer will point to the to_be_sent_ string which is |
532 // protected by the lock, and it's messier to factor Send() such that it can | 529 // protected by the lock, and it's messier to factor Send() such that it can |
533 // unlock for us. Holding the lock for the message construction, which is | 530 // unlock for us. Holding the lock for the message construction, which is |
534 // just some memcpys, shouldn't be a big deal. | 531 // just some memcpys, shouldn't be a big deal. |
535 lock_.AssertAcquired(); | 532 lock_.AssertAcquired(); |
536 if (locked_data_.channel_closed_) | 533 if (locked_data_.channel_closed_) |
537 return false; // TODO(brettw) clean up handles here when we add support! | 534 return false; // TODO(brettw) clean up handles here when we add support! |
538 | 535 |
539 if (msg->is_sync()) { | 536 if (msg->is_sync()) { |
540 locked_data_.handle_converter_.RegisterSyncMessageForReply(*msg); | 537 locked_data_.nacl_msg_scanner_.RegisterSyncMessageForReply(*msg); |
541 } | 538 } |
542 // Actual send must be done on the I/O thread. | 539 // Actual send must be done on the I/O thread. |
543 task_runner_->PostTask(FROM_HERE, | 540 task_runner_->PostTask(FROM_HERE, |
544 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this, | 541 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this, |
545 base::Passed(&msg))); | 542 base::Passed(&msg))); |
546 return true; | 543 return true; |
547 } | 544 } |
548 | 545 |
549 void NaClIPCAdapter::ClearToBeSent() { | 546 void NaClIPCAdapter::ClearToBeSent() { |
550 lock_.AssertAcquired(); | 547 lock_.AssertAcquired(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 header.flags = msg.flags(); | 579 header.flags = msg.flags(); |
583 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); | 580 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); |
584 | 581 |
585 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); | 582 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); |
586 locked_data_.to_be_received_.push(rewritten_msg); | 583 locked_data_.to_be_received_.push(rewritten_msg); |
587 } | 584 } |
588 | 585 |
589 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { | 586 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { |
590 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); | 587 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); |
591 } | 588 } |
OLD | NEW |