| 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 // TODO(vtl): I currently potentially overflow in doing index calculations. | 5 // TODO(vtl): I currently potentially overflow in doing index calculations. |
| 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but | 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but |
| 7 // their sum may not. This is bad and poses a security risk. (We're currently | 7 // their sum may not. This is bad and poses a security risk. (We're currently |
| 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in | 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in |
| 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.) | 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.) |
| 10 | 10 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 *max_size = 0; | 175 *max_size = 0; |
| 176 *max_platform_handles = 0; | 176 *max_platform_handles = 0; |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool LocalDataPipe::ProducerEndSerializeImplNoLock( | 179 bool LocalDataPipe::ProducerEndSerializeImplNoLock( |
| 180 Channel* channel, | 180 Channel* channel, |
| 181 void* destination, | 181 void* destination, |
| 182 size_t* actual_size, | 182 size_t* actual_size, |
| 183 embedder::PlatformHandleVector* platform_handles) { | 183 embedder::PlatformHandleVector* platform_handles) { |
| 184 // TODO(vtl): Support serializing producer data pipe handles. | 184 // TODO(vtl): Support serializing producer data pipe handles. |
| 185 ProducerCloseImplNoLock(); | 185 ProducerCloseNoLock(); |
| 186 return false; | 186 return false; |
| 187 } | 187 } |
| 188 | 188 |
| 189 void LocalDataPipe::ConsumerCloseImplNoLock() { | 189 void LocalDataPipe::ConsumerCloseImplNoLock() { |
| 190 // If the producer is around and in a two-phase write, we have to keep the | 190 // If the producer is around and in a two-phase write, we have to keep the |
| 191 // buffer around. (We then don't free it until the producer is closed. This | 191 // buffer around. (We then don't free it until the producer is closed. This |
| 192 // could be rectified, but again seems like optimizing for the uncommon case.) | 192 // could be rectified, but again seems like optimizing for the uncommon case.) |
| 193 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) | 193 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) |
| 194 DestroyBufferNoLock(); | 194 DestroyBufferNoLock(); |
| 195 current_num_bytes_ = 0; | 195 current_num_bytes_ = 0; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 *max_size = 0; | 329 *max_size = 0; |
| 330 *max_platform_handles = 0; | 330 *max_platform_handles = 0; |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool LocalDataPipe::ConsumerEndSerializeImplNoLock( | 333 bool LocalDataPipe::ConsumerEndSerializeImplNoLock( |
| 334 Channel* channel, | 334 Channel* channel, |
| 335 void* destination, | 335 void* destination, |
| 336 size_t* actual_size, | 336 size_t* actual_size, |
| 337 embedder::PlatformHandleVector* platform_handles) { | 337 embedder::PlatformHandleVector* platform_handles) { |
| 338 // TODO(vtl): Support serializing consumer data pipe handles. | 338 // TODO(vtl): Support serializing consumer data pipe handles. |
| 339 ConsumerCloseImplNoLock(); | 339 ConsumerCloseNoLock(); |
| 340 return false; | 340 return false; |
| 341 } | 341 } |
| 342 | 342 |
| 343 void LocalDataPipe::EnsureBufferNoLock() { | 343 void LocalDataPipe::EnsureBufferNoLock() { |
| 344 DCHECK(producer_open_no_lock()); | 344 DCHECK(producer_open_no_lock()); |
| 345 if (buffer_) | 345 if (buffer_) |
| 346 return; | 346 return; |
| 347 buffer_.reset(static_cast<char*>( | 347 buffer_.reset(static_cast<char*>( |
| 348 base::AlignedAlloc(capacity_num_bytes(), | 348 base::AlignedAlloc(capacity_num_bytes(), |
| 349 GetConfiguration().data_pipe_buffer_alignment_bytes))); | 349 GetConfiguration().data_pipe_buffer_alignment_bytes))); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 379 | 379 |
| 380 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { | 380 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { |
| 381 DCHECK_LE(num_bytes, current_num_bytes_); | 381 DCHECK_LE(num_bytes, current_num_bytes_); |
| 382 start_index_ += num_bytes; | 382 start_index_ += num_bytes; |
| 383 start_index_ %= capacity_num_bytes(); | 383 start_index_ %= capacity_num_bytes(); |
| 384 current_num_bytes_ -= num_bytes; | 384 current_num_bytes_ -= num_bytes; |
| 385 } | 385 } |
| 386 | 386 |
| 387 } // namespace system | 387 } // namespace system |
| 388 } // namespace mojo | 388 } // namespace mojo |
| OLD | NEW |