| 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 "mojo/system/message_pipe_dispatcher.h" | 5 #include "mojo/system/message_pipe_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/system/limits.h" | 8 #include "mojo/system/limits.h" |
| 9 #include "mojo/system/memory.h" | 9 #include "mojo/system/memory.h" |
| 10 #include "mojo/system/message_pipe.h" | 10 #include "mojo/system/message_pipe.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 MojoResult MessagePipeDispatcher::CloseImplNoLock() { | 37 MojoResult MessagePipeDispatcher::CloseImplNoLock() { |
| 38 lock().AssertAcquired(); | 38 lock().AssertAcquired(); |
| 39 message_pipe_->Close(port_); | 39 message_pipe_->Close(port_); |
| 40 message_pipe_ = NULL; | 40 message_pipe_ = NULL; |
| 41 return MOJO_RESULT_OK; | 41 return MOJO_RESULT_OK; |
| 42 } | 42 } |
| 43 | 43 |
| 44 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( | 44 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( |
| 45 const void* bytes, uint32_t num_bytes, | 45 const void* bytes, uint32_t num_bytes, |
| 46 const MojoHandle* handles, uint32_t num_handles, | 46 const std::vector<Dispatcher*>* dispatchers, |
| 47 MojoWriteMessageFlags flags) { | 47 MojoWriteMessageFlags flags) { |
| 48 lock().AssertAcquired(); | 48 lock().AssertAcquired(); |
| 49 | 49 |
| 50 if (!VerifyUserPointer<void>(bytes, num_bytes)) | 50 if (!VerifyUserPointer<void>(bytes, num_bytes)) |
| 51 return MOJO_RESULT_INVALID_ARGUMENT; | 51 return MOJO_RESULT_INVALID_ARGUMENT; |
| 52 if (num_bytes > kMaxMessageNumBytes) | 52 if (num_bytes > kMaxMessageNumBytes) |
| 53 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 53 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 54 | 54 |
| 55 if (!VerifyUserPointer<MojoHandle>(handles, num_handles)) | 55 if (dispatchers) { |
| 56 return MOJO_RESULT_INVALID_ARGUMENT; | 56 DCHECK_GT(dispatchers->size(), 0u); |
| 57 if (num_handles > kMaxMessageNumHandles) | 57 DCHECK_LE(dispatchers->size(), kMaxMessageNumHandles); |
| 58 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 58 |
| 59 if (num_handles > 0) { | 59 // TODO(vtl) |
| 60 // TODO(vtl): Verify each handle. | |
| 61 NOTIMPLEMENTED(); | 60 NOTIMPLEMENTED(); |
| 62 return MOJO_RESULT_UNIMPLEMENTED; | 61 return MOJO_RESULT_UNIMPLEMENTED; |
| 63 } | 62 } |
| 64 | 63 |
| 65 return message_pipe_->WriteMessage(port_, | 64 return message_pipe_->WriteMessage(port_, |
| 66 bytes, num_bytes, | 65 bytes, num_bytes, |
| 67 handles, num_handles, | 66 dispatchers, |
| 68 flags); | 67 flags); |
| 69 } | 68 } |
| 70 | 69 |
| 71 MojoResult MessagePipeDispatcher::ReadMessageImplNoLock( | 70 MojoResult MessagePipeDispatcher::ReadMessageImplNoLock( |
| 72 void* bytes, uint32_t* num_bytes, | 71 void* bytes, uint32_t* num_bytes, |
| 73 MojoHandle* handles, uint32_t* num_handles, | 72 uint32_t max_num_dispatchers, |
| 73 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
| 74 MojoReadMessageFlags flags) { | 74 MojoReadMessageFlags flags) { |
| 75 lock().AssertAcquired(); | 75 lock().AssertAcquired(); |
| 76 | 76 |
| 77 // TODO(vtl): I suppose we should verify |num_bytes| and |num_handles| (i.e., | 77 if (num_bytes) { |
| 78 // those pointers themselves). Hmmm. | 78 if (!VerifyUserPointer<uint32_t>(num_bytes, 1)) |
| 79 | 79 return MOJO_RESULT_INVALID_ARGUMENT; |
| 80 if (num_bytes && !VerifyUserPointer<void>(bytes, *num_bytes)) | 80 if (!VerifyUserPointer<void>(bytes, *num_bytes)) |
| 81 return MOJO_RESULT_INVALID_ARGUMENT; | 81 return MOJO_RESULT_INVALID_ARGUMENT; |
| 82 | 82 } |
| 83 if (num_handles && !VerifyUserPointer<MojoHandle>(handles, *num_handles)) | |
| 84 return MOJO_RESULT_INVALID_ARGUMENT; | |
| 85 | 83 |
| 86 return message_pipe_->ReadMessage(port_, | 84 return message_pipe_->ReadMessage(port_, |
| 87 bytes, num_bytes, | 85 bytes, num_bytes, |
| 88 handles, num_handles, | 86 max_num_dispatchers, dispatchers, |
| 89 flags); | 87 flags); |
| 90 } | 88 } |
| 91 | 89 |
| 92 MojoResult MessagePipeDispatcher::AddWaiterImplNoLock(Waiter* waiter, | 90 MojoResult MessagePipeDispatcher::AddWaiterImplNoLock(Waiter* waiter, |
| 93 MojoWaitFlags flags, | 91 MojoWaitFlags flags, |
| 94 MojoResult wake_result) { | 92 MojoResult wake_result) { |
| 95 lock().AssertAcquired(); | 93 lock().AssertAcquired(); |
| 96 return message_pipe_->AddWaiter(port_, waiter, flags, wake_result); | 94 return message_pipe_->AddWaiter(port_, waiter, flags, wake_result); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void MessagePipeDispatcher::RemoveWaiterImplNoLock(Waiter* waiter) { | 97 void MessagePipeDispatcher::RemoveWaiterImplNoLock(Waiter* waiter) { |
| 100 lock().AssertAcquired(); | 98 lock().AssertAcquired(); |
| 101 message_pipe_->RemoveWaiter(port_, waiter); | 99 message_pipe_->RemoveWaiter(port_, waiter); |
| 102 } | 100 } |
| 103 | 101 |
| 104 } // namespace system | 102 } // namespace system |
| 105 } // namespace mojo | 103 } // namespace mojo |
| OLD | NEW |