| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read()); | 307 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read()); |
| 308 DCHECK_EQ(num_bytes_read % element_num_bytes(), 0u); | 308 DCHECK_EQ(num_bytes_read % element_num_bytes(), 0u); |
| 309 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); | 309 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); |
| 310 MarkDataAsConsumed(num_bytes_read); | 310 MarkDataAsConsumed(num_bytes_read); |
| 311 set_consumer_two_phase_max_num_bytes_read(0); | 311 set_consumer_two_phase_max_num_bytes_read(0); |
| 312 return MOJO_RESULT_OK; | 312 return MOJO_RESULT_OK; |
| 313 } | 313 } |
| 314 | 314 |
| 315 HandleSignalsState LocalDataPipeImpl::ConsumerGetHandleSignalsState() const { | 315 HandleSignalsState LocalDataPipeImpl::ConsumerGetHandleSignalsState() const { |
| 316 HandleSignalsState rv; | 316 HandleSignalsState rv; |
| 317 if (current_num_bytes_ > 0) { | 317 // |consumer_read_threshold_num_bytes()| is always at least 1. |
| 318 if (current_num_bytes_ >= consumer_read_threshold_num_bytes()) { |
| 319 if (!consumer_in_two_phase_read()) { |
| 320 rv.satisfied_signals |= |
| 321 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READ_THRESHOLD; |
| 322 } |
| 323 rv.satisfiable_signals |= |
| 324 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READ_THRESHOLD; |
| 325 } else if (current_num_bytes_ > 0u) { |
| 318 if (!consumer_in_two_phase_read()) | 326 if (!consumer_in_two_phase_read()) |
| 319 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 327 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 320 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 328 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 321 } else if (producer_open()) { | |
| 322 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | |
| 323 } | 329 } |
| 324 if (!producer_open()) | 330 if (producer_open()) { |
| 331 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE | |
| 332 MOJO_HANDLE_SIGNAL_PEER_CLOSED | |
| 333 MOJO_HANDLE_SIGNAL_READ_THRESHOLD; |
| 334 } else { |
| 325 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 335 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 326 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 336 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 337 } |
| 327 return rv; | 338 return rv; |
| 328 } | 339 } |
| 329 | 340 |
| 330 void LocalDataPipeImpl::ConsumerStartSerialize(Channel* channel, | 341 void LocalDataPipeImpl::ConsumerStartSerialize(Channel* channel, |
| 331 size_t* max_size, | 342 size_t* max_size, |
| 332 size_t* max_platform_handles) { | 343 size_t* max_platform_handles) { |
| 333 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 344 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
| 334 channel->GetSerializedEndpointSize(); | 345 channel->GetSerializedEndpointSize(); |
| 335 *max_platform_handles = 0; | 346 *max_platform_handles = 0; |
| 336 } | 347 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 444 |
| 434 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { | 445 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { |
| 435 DCHECK_LE(num_bytes, current_num_bytes_); | 446 DCHECK_LE(num_bytes, current_num_bytes_); |
| 436 start_index_ += num_bytes; | 447 start_index_ += num_bytes; |
| 437 start_index_ %= capacity_num_bytes(); | 448 start_index_ %= capacity_num_bytes(); |
| 438 current_num_bytes_ -= num_bytes; | 449 current_num_bytes_ -= num_bytes; |
| 439 } | 450 } |
| 440 | 451 |
| 441 } // namespace system | 452 } // namespace system |
| 442 } // namespace mojo | 453 } // namespace mojo |
| OLD | NEW |