| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_buffer_dispatcher.h" | 5 #include "mojo/system/shared_buffer_dispatcher.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "mojo/public/c/system/macros.h" | |
| 12 #include "mojo/system/constants.h" | 11 #include "mojo/system/constants.h" |
| 13 #include "mojo/system/memory.h" | 12 #include "mojo/system/memory.h" |
| 14 #include "mojo/system/raw_shared_buffer.h" | 13 #include "mojo/system/raw_shared_buffer.h" |
| 15 | 14 |
| 16 namespace mojo { | 15 namespace mojo { |
| 17 namespace system { | 16 namespace system { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 struct SerializedSharedBufferDispatcher { | 20 struct SerializedSharedBufferDispatcher { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 shared_buffer.swap(shared_buffer_); | 142 shared_buffer.swap(shared_buffer_); |
| 144 return scoped_refptr<Dispatcher>(new SharedBufferDispatcher(shared_buffer)); | 143 return scoped_refptr<Dispatcher>(new SharedBufferDispatcher(shared_buffer)); |
| 145 } | 144 } |
| 146 | 145 |
| 147 MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( | 146 MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( |
| 148 const MojoDuplicateBufferHandleOptions* options, | 147 const MojoDuplicateBufferHandleOptions* options, |
| 149 scoped_refptr<Dispatcher>* new_dispatcher) { | 148 scoped_refptr<Dispatcher>* new_dispatcher) { |
| 150 lock().AssertAcquired(); | 149 lock().AssertAcquired(); |
| 151 if (options) { | 150 if (options) { |
| 152 // The |struct_size| field must be valid to read. | 151 // The |struct_size| field must be valid to read. |
| 153 if (!VerifyUserPointer<uint32_t>(&options->struct_size)) | 152 if (!VerifyUserPointer<uint32_t>(&options->struct_size, 1)) |
| 154 return MOJO_RESULT_INVALID_ARGUMENT; | 153 return MOJO_RESULT_INVALID_ARGUMENT; |
| 155 // And then |options| must point to at least |options->struct_size| bytes. | 154 // And then |options| must point to at least |options->struct_size| bytes. |
| 156 if (!VerifyUserPointerWithSize<MOJO_ALIGNOF(int64_t)>(options, | 155 if (!VerifyUserPointer<void>(options, options->struct_size)) |
| 157 options->struct_size)) | |
| 158 return MOJO_RESULT_INVALID_ARGUMENT; | 156 return MOJO_RESULT_INVALID_ARGUMENT; |
| 159 | 157 |
| 160 if (options->struct_size < sizeof(*options)) | 158 if (options->struct_size < sizeof(*options)) |
| 161 return MOJO_RESULT_INVALID_ARGUMENT; | 159 return MOJO_RESULT_INVALID_ARGUMENT; |
| 162 // We don't actually do anything with |options|. | 160 // We don't actually do anything with |options|. |
| 163 } | 161 } |
| 164 | 162 |
| 165 *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); | 163 *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); |
| 166 return MOJO_RESULT_OK; | 164 return MOJO_RESULT_OK; |
| 167 } | 165 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return MOJO_WAIT_FLAG_NONE; | 236 return MOJO_WAIT_FLAG_NONE; |
| 239 } | 237 } |
| 240 | 238 |
| 241 MojoWaitFlags SharedBufferDispatcher::SatisfiableFlagsNoLock() const { | 239 MojoWaitFlags SharedBufferDispatcher::SatisfiableFlagsNoLock() const { |
| 242 // TODO(vtl): Add transferrable flag. | 240 // TODO(vtl): Add transferrable flag. |
| 243 return MOJO_WAIT_FLAG_NONE; | 241 return MOJO_WAIT_FLAG_NONE; |
| 244 } | 242 } |
| 245 | 243 |
| 246 } // namespace system | 244 } // namespace system |
| 247 } // namespace mojo | 245 } // namespace mojo |
| OLD | NEW |