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