| 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.h" | 5 #include "mojo/system/message_pipe.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "mojo/system/limits.h" | 9 #include "mojo/system/limits.h" |
| 10 #include "mojo/system/memory.h" | 10 #include "mojo/system/memory.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 MojoResult MessagePipe::WriteMessage( | 74 MojoResult MessagePipe::WriteMessage( |
| 75 unsigned port, | 75 unsigned port, |
| 76 const void* bytes, uint32_t num_bytes, | 76 const void* bytes, uint32_t num_bytes, |
| 77 const MojoHandle* handles, uint32_t num_handles, | 77 const MojoHandle* handles, uint32_t num_handles, |
| 78 MojoWriteMessageFlags /*flags*/) { | 78 MojoWriteMessageFlags /*flags*/) { |
| 79 DCHECK(port == 0 || port == 1); | 79 DCHECK(port == 0 || port == 1); |
| 80 | 80 |
| 81 unsigned destination_port = DestinationPortFromSourcePort(port); | 81 unsigned destination_port = DestinationPortFromSourcePort(port); |
| 82 | 82 |
| 83 if (!VerifyUserPointer(bytes, num_bytes, 1)) | 83 if (!VerifyUserPointer<void>(bytes, num_bytes)) |
| 84 return MOJO_RESULT_INVALID_ARGUMENT; | 84 return MOJO_RESULT_INVALID_ARGUMENT; |
| 85 if (num_bytes > kMaxMessageNumBytes) | 85 if (num_bytes > kMaxMessageNumBytes) |
| 86 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 86 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 87 | 87 |
| 88 if (!VerifyUserPointer(handles, num_handles, sizeof(handles[0]))) | 88 if (!VerifyUserPointer<MojoHandle>(handles, num_handles)) |
| 89 return MOJO_RESULT_INVALID_ARGUMENT; | 89 return MOJO_RESULT_INVALID_ARGUMENT; |
| 90 if (num_handles > kMaxMessageNumHandles) | 90 if (num_handles > kMaxMessageNumHandles) |
| 91 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 91 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 92 if (num_handles > 0) { | 92 if (num_handles > 0) { |
| 93 // TODO(vtl): Verify each handle. | 93 // TODO(vtl): Verify each handle. |
| 94 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
| 95 return MOJO_RESULT_UNIMPLEMENTED; | 95 return MOJO_RESULT_UNIMPLEMENTED; |
| 96 } | 96 } |
| 97 | 97 |
| 98 // TODO(vtl): Handle flags. | 98 // TODO(vtl): Handle flags. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 122 return MOJO_RESULT_OK; | 122 return MOJO_RESULT_OK; |
| 123 } | 123 } |
| 124 | 124 |
| 125 MojoResult MessagePipe::ReadMessage(unsigned port, | 125 MojoResult MessagePipe::ReadMessage(unsigned port, |
| 126 void* bytes, uint32_t* num_bytes, | 126 void* bytes, uint32_t* num_bytes, |
| 127 MojoHandle* handles, uint32_t* num_handles, | 127 MojoHandle* handles, uint32_t* num_handles, |
| 128 MojoReadMessageFlags flags) { | 128 MojoReadMessageFlags flags) { |
| 129 DCHECK(port == 0 || port == 1); | 129 DCHECK(port == 0 || port == 1); |
| 130 | 130 |
| 131 const size_t max_bytes = num_bytes ? *num_bytes : 0; | 131 const size_t max_bytes = num_bytes ? *num_bytes : 0; |
| 132 if (!VerifyUserPointer(bytes, max_bytes, 1)) | 132 if (!VerifyUserPointer<void>(bytes, max_bytes)) |
| 133 return MOJO_RESULT_INVALID_ARGUMENT; | 133 return MOJO_RESULT_INVALID_ARGUMENT; |
| 134 | 134 |
| 135 const size_t max_handles = num_handles ? *num_handles : 0; | 135 const size_t max_handles = num_handles ? *num_handles : 0; |
| 136 if (!VerifyUserPointer(handles, max_handles, sizeof(handles[0]))) | 136 if (!VerifyUserPointer<MojoHandle>(handles, max_handles)) |
| 137 return MOJO_RESULT_INVALID_ARGUMENT; | 137 return MOJO_RESULT_INVALID_ARGUMENT; |
| 138 | 138 |
| 139 base::AutoLock locker(lock_); | 139 base::AutoLock locker(lock_); |
| 140 DCHECK(is_open_[port]); | 140 DCHECK(is_open_[port]); |
| 141 | 141 |
| 142 if (message_queues_[port].empty()) | 142 if (message_queues_[port].empty()) |
| 143 return MOJO_RESULT_NOT_FOUND; | 143 return MOJO_RESULT_NOT_FOUND; |
| 144 | 144 |
| 145 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop | 145 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop |
| 146 // and release the lock immediately. | 146 // and release the lock immediately. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 if (!message_queues_[port].empty() || is_open_[destination_port]) | 239 if (!message_queues_[port].empty() || is_open_[destination_port]) |
| 240 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; | 240 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; |
| 241 if (is_open_[destination_port]) | 241 if (is_open_[destination_port]) |
| 242 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; | 242 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; |
| 243 | 243 |
| 244 return satisfiable_flags; | 244 return satisfiable_flags; |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace system | 247 } // namespace system |
| 248 } // namespace mojo | 248 } // namespace mojo |
| OLD | NEW |