| 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/edk/system/shared_buffer_dispatcher.h" | 5 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 MojoDuplicateBufferHandleOptions validated_options; | 225 MojoDuplicateBufferHandleOptions validated_options; |
| 226 MojoResult result = ValidateDuplicateOptions(options, &validated_options); | 226 MojoResult result = ValidateDuplicateOptions(options, &validated_options); |
| 227 if (result != MOJO_RESULT_OK) | 227 if (result != MOJO_RESULT_OK) |
| 228 return result; | 228 return result; |
| 229 | 229 |
| 230 // Note: Since this is "duplicate", we keep our ref to |shared_buffer_|. | 230 // Note: Since this is "duplicate", we keep our ref to |shared_buffer_|. |
| 231 *new_dispatcher = CreateInternal(shared_buffer_.Clone()); | 231 *new_dispatcher = CreateInternal(shared_buffer_.Clone()); |
| 232 return MOJO_RESULT_OK; | 232 return MOJO_RESULT_OK; |
| 233 } | 233 } |
| 234 | 234 |
| 235 MojoResult SharedBufferDispatcher::GetBufferInformationImplNoLock( |
| 236 UserPointer<MojoBufferInformation> info, |
| 237 uint32_t info_num_bytes) { |
| 238 mutex().AssertHeld(); |
| 239 |
| 240 // Note: If/when |MojoBufferInformation| is extended beyond its initial |
| 241 // definition, more work will be necessary. (See the definition of |
| 242 // |MojoGetBufferInformation()| in mojo/public/c/system/buffer.h.) |
| 243 static_assert(sizeof(MojoBufferInformation) == 16u, |
| 244 "MojoBufferInformation has been extended!"); |
| 245 |
| 246 if (info_num_bytes < sizeof(MojoBufferInformation)) |
| 247 return MOJO_RESULT_INVALID_ARGUMENT; |
| 248 |
| 249 MojoBufferInformation model_info = { |
| 250 sizeof(MojoBufferInformation), // |struct_size|. |
| 251 MOJO_BUFFER_INFORMATION_FLAG_NONE, // |flags|. |
| 252 static_cast<uint64_t>(shared_buffer_->GetNumBytes()), // |num_bytes|. |
| 253 }; |
| 254 info.Put(model_info); |
| 255 return MOJO_RESULT_OK; |
| 256 } |
| 257 |
| 235 MojoResult SharedBufferDispatcher::MapBufferImplNoLock( | 258 MojoResult SharedBufferDispatcher::MapBufferImplNoLock( |
| 236 uint64_t offset, | 259 uint64_t offset, |
| 237 uint64_t num_bytes, | 260 uint64_t num_bytes, |
| 238 MojoMapBufferFlags flags, | 261 MojoMapBufferFlags flags, |
| 239 std::unique_ptr<PlatformSharedBufferMapping>* mapping) { | 262 std::unique_ptr<PlatformSharedBufferMapping>* mapping) { |
| 240 mutex().AssertHeld(); | 263 mutex().AssertHeld(); |
| 241 DCHECK(shared_buffer_); | 264 DCHECK(shared_buffer_); |
| 242 | 265 |
| 243 if (offset > static_cast<uint64_t>(std::numeric_limits<size_t>::max())) | 266 if (offset > static_cast<uint64_t>(std::numeric_limits<size_t>::max())) |
| 244 return MOJO_RESULT_INVALID_ARGUMENT; | 267 return MOJO_RESULT_INVALID_ARGUMENT; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 platform_handles->push_back(std::move(platform_handle)); | 316 platform_handles->push_back(std::move(platform_handle)); |
| 294 *actual_size = sizeof(SerializedSharedBufferDispatcher); | 317 *actual_size = sizeof(SerializedSharedBufferDispatcher); |
| 295 | 318 |
| 296 shared_buffer_ = nullptr; | 319 shared_buffer_ = nullptr; |
| 297 | 320 |
| 298 return true; | 321 return true; |
| 299 } | 322 } |
| 300 | 323 |
| 301 } // namespace system | 324 } // namespace system |
| 302 } // namespace mojo | 325 } // namespace mojo |
| OLD | NEW |