| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 HandleSignalsState LocalDataPipe::ProducerGetHandleSignalsStateImplNoLock() | 155 HandleSignalsState LocalDataPipe::ProducerGetHandleSignalsStateImplNoLock() |
| 156 const { | 156 const { |
| 157 HandleSignalsState rv; | 157 HandleSignalsState rv; |
| 158 if (consumer_open_no_lock()) { | 158 if (consumer_open_no_lock()) { |
| 159 if ((may_discard() || current_num_bytes_ < capacity_num_bytes()) && | 159 if ((may_discard() || current_num_bytes_ < capacity_num_bytes()) && |
| 160 !producer_in_two_phase_write_no_lock()) | 160 !producer_in_two_phase_write_no_lock()) |
| 161 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 161 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
| 162 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 162 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
| 163 } else { |
| 164 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 163 } | 165 } |
| 166 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 164 return rv; | 167 return rv; |
| 165 } | 168 } |
| 166 | 169 |
| 167 void LocalDataPipe::ConsumerCloseImplNoLock() { | 170 void LocalDataPipe::ConsumerCloseImplNoLock() { |
| 168 // If the producer is around and in a two-phase write, we have to keep the | 171 // If the producer is around and in a two-phase write, we have to keep the |
| 169 // buffer around. (We then don't free it until the producer is closed. This | 172 // buffer around. (We then don't free it until the producer is closed. This |
| 170 // could be rectified, but again seems like optimizing for the uncommon case.) | 173 // could be rectified, but again seems like optimizing for the uncommon case.) |
| 171 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) | 174 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) |
| 172 DestroyBufferNoLock(); | 175 DestroyBufferNoLock(); |
| 173 current_num_bytes_ = 0; | 176 current_num_bytes_ = 0; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 HandleSignalsState LocalDataPipe::ConsumerGetHandleSignalsStateImplNoLock() | 289 HandleSignalsState LocalDataPipe::ConsumerGetHandleSignalsStateImplNoLock() |
| 287 const { | 290 const { |
| 288 HandleSignalsState rv; | 291 HandleSignalsState rv; |
| 289 if (current_num_bytes_ > 0) { | 292 if (current_num_bytes_ > 0) { |
| 290 if (!consumer_in_two_phase_read_no_lock()) | 293 if (!consumer_in_two_phase_read_no_lock()) |
| 291 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 294 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 292 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 295 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 293 } else if (producer_open_no_lock()) { | 296 } else if (producer_open_no_lock()) { |
| 294 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 297 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 295 } | 298 } |
| 299 if (!producer_open_no_lock()) |
| 300 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 301 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 296 return rv; | 302 return rv; |
| 297 } | 303 } |
| 298 | 304 |
| 299 void LocalDataPipe::EnsureBufferNoLock() { | 305 void LocalDataPipe::EnsureBufferNoLock() { |
| 300 DCHECK(producer_open_no_lock()); | 306 DCHECK(producer_open_no_lock()); |
| 301 if (buffer_) | 307 if (buffer_) |
| 302 return; | 308 return; |
| 303 buffer_.reset(static_cast<char*>( | 309 buffer_.reset(static_cast<char*>( |
| 304 base::AlignedAlloc(capacity_num_bytes(), | 310 base::AlignedAlloc(capacity_num_bytes(), |
| 305 GetConfiguration().data_pipe_buffer_alignment_bytes))); | 311 GetConfiguration().data_pipe_buffer_alignment_bytes))); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 335 | 341 |
| 336 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { | 342 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { |
| 337 DCHECK_LE(num_bytes, current_num_bytes_); | 343 DCHECK_LE(num_bytes, current_num_bytes_); |
| 338 start_index_ += num_bytes; | 344 start_index_ += num_bytes; |
| 339 start_index_ %= capacity_num_bytes(); | 345 start_index_ %= capacity_num_bytes(); |
| 340 current_num_bytes_ -= num_bytes; | 346 current_num_bytes_ -= num_bytes; |
| 341 } | 347 } |
| 342 | 348 |
| 343 } // namespace system | 349 } // namespace system |
| 344 } // namespace mojo | 350 } // namespace mojo |
| OLD | NEW |