| 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" | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 64 SharedBufferDispatcher::SharedBufferDispatcher( | 64 SharedBufferDispatcher::SharedBufferDispatcher( | 
| 65     scoped_refptr<RawSharedBuffer> shared_buffer) | 65     scoped_refptr<RawSharedBuffer> shared_buffer) | 
| 66     : shared_buffer_(shared_buffer) { | 66     : shared_buffer_(shared_buffer) { | 
| 67   DCHECK(shared_buffer_); | 67   DCHECK(shared_buffer_); | 
| 68 } | 68 } | 
| 69 | 69 | 
| 70 SharedBufferDispatcher::~SharedBufferDispatcher() { | 70 SharedBufferDispatcher::~SharedBufferDispatcher() { | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 void SharedBufferDispatcher::CloseImplNoLock() { | 73 void SharedBufferDispatcher::CloseImplNoLock() { | 
|  | 74   lock().AssertAcquired(); | 
| 74   DCHECK(shared_buffer_); | 75   DCHECK(shared_buffer_); | 
| 75   shared_buffer_ = NULL; | 76   shared_buffer_ = NULL; | 
| 76 } | 77 } | 
| 77 | 78 | 
| 78 scoped_refptr<Dispatcher> | 79 scoped_refptr<Dispatcher> | 
| 79     SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 80     SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 
|  | 81   lock().AssertAcquired(); | 
| 80   DCHECK(shared_buffer_); | 82   DCHECK(shared_buffer_); | 
| 81   scoped_refptr<RawSharedBuffer> shared_buffer; | 83   scoped_refptr<RawSharedBuffer> shared_buffer; | 
| 82   shared_buffer.swap(shared_buffer_); | 84   shared_buffer.swap(shared_buffer_); | 
| 83   return scoped_refptr<Dispatcher>(new SharedBufferDispatcher(shared_buffer)); | 85   return scoped_refptr<Dispatcher>(new SharedBufferDispatcher(shared_buffer)); | 
| 84 } | 86 } | 
| 85 | 87 | 
| 86 MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( | 88 MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( | 
| 87     const MojoDuplicateBufferHandleOptions* options, | 89     const MojoDuplicateBufferHandleOptions* options, | 
| 88     scoped_refptr<Dispatcher>* new_dispatcher) { | 90     scoped_refptr<Dispatcher>* new_dispatcher) { | 
|  | 91   lock().AssertAcquired(); | 
| 89   if (options) { | 92   if (options) { | 
| 90     // The |struct_size| field must be valid to read. | 93     // The |struct_size| field must be valid to read. | 
| 91     if (!VerifyUserPointer<uint32_t>(&options->struct_size, 1)) | 94     if (!VerifyUserPointer<uint32_t>(&options->struct_size, 1)) | 
| 92       return MOJO_RESULT_INVALID_ARGUMENT; | 95       return MOJO_RESULT_INVALID_ARGUMENT; | 
| 93     // And then |options| must point to at least |options->struct_size| bytes. | 96     // And then |options| must point to at least |options->struct_size| bytes. | 
| 94     if (!VerifyUserPointer<void>(options, options->struct_size)) | 97     if (!VerifyUserPointer<void>(options, options->struct_size)) | 
| 95       return MOJO_RESULT_INVALID_ARGUMENT; | 98       return MOJO_RESULT_INVALID_ARGUMENT; | 
| 96 | 99 | 
| 97     if (options->struct_size < sizeof(*options)) | 100     if (options->struct_size < sizeof(*options)) | 
| 98       return MOJO_RESULT_INVALID_ARGUMENT; | 101       return MOJO_RESULT_INVALID_ARGUMENT; | 
| 99     // We don't actually do anything with |options|. | 102     // We don't actually do anything with |options|. | 
| 100   } | 103   } | 
| 101 | 104 | 
| 102   *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); | 105   *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); | 
| 103   return MOJO_RESULT_OK; | 106   return MOJO_RESULT_OK; | 
| 104 } | 107 } | 
| 105 | 108 | 
| 106 MojoResult SharedBufferDispatcher::MapBufferImplNoLock( | 109 MojoResult SharedBufferDispatcher::MapBufferImplNoLock( | 
| 107     uint64_t offset, | 110     uint64_t offset, | 
| 108     uint64_t num_bytes, | 111     uint64_t num_bytes, | 
| 109     MojoMapBufferFlags flags, | 112     MojoMapBufferFlags flags, | 
| 110     scoped_ptr<RawSharedBufferMapping>* mapping) { | 113     scoped_ptr<RawSharedBufferMapping>* mapping) { | 
|  | 114   lock().AssertAcquired(); | 
| 111   DCHECK(shared_buffer_); | 115   DCHECK(shared_buffer_); | 
| 112 | 116 | 
| 113   if (offset > static_cast<uint64_t>(std::numeric_limits<size_t>::max())) | 117   if (offset > static_cast<uint64_t>(std::numeric_limits<size_t>::max())) | 
| 114     return MOJO_RESULT_INVALID_ARGUMENT; | 118     return MOJO_RESULT_INVALID_ARGUMENT; | 
| 115   if (num_bytes > static_cast<uint64_t>(std::numeric_limits<size_t>::max())) | 119   if (num_bytes > static_cast<uint64_t>(std::numeric_limits<size_t>::max())) | 
| 116     return MOJO_RESULT_INVALID_ARGUMENT; | 120     return MOJO_RESULT_INVALID_ARGUMENT; | 
| 117 | 121 | 
| 118   if (!shared_buffer_->IsValidMap(static_cast<size_t>(offset), | 122   if (!shared_buffer_->IsValidMap(static_cast<size_t>(offset), | 
| 119                                   static_cast<size_t>(num_bytes))) | 123                                   static_cast<size_t>(num_bytes))) | 
| 120     return MOJO_RESULT_INVALID_ARGUMENT; | 124     return MOJO_RESULT_INVALID_ARGUMENT; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 133   return MOJO_WAIT_FLAG_NONE; | 137   return MOJO_WAIT_FLAG_NONE; | 
| 134 } | 138 } | 
| 135 | 139 | 
| 136 MojoWaitFlags SharedBufferDispatcher::SatisfiableFlagsNoLock() const { | 140 MojoWaitFlags SharedBufferDispatcher::SatisfiableFlagsNoLock() const { | 
| 137   // TODO(vtl): Add transferrable flag. | 141   // TODO(vtl): Add transferrable flag. | 
| 138   return MOJO_WAIT_FLAG_NONE; | 142   return MOJO_WAIT_FLAG_NONE; | 
| 139 } | 143 } | 
| 140 | 144 | 
| 141 }  // namespace system | 145 }  // namespace system | 
| 142 }  // namespace mojo | 146 }  // namespace mojo | 
| OLD | NEW | 
|---|