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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); | 149 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); |
150 set_producer_two_phase_max_num_bytes_written_no_lock(0); | 150 set_producer_two_phase_max_num_bytes_written_no_lock(0); |
151 return MOJO_RESULT_OK; | 151 return MOJO_RESULT_OK; |
152 } | 152 } |
153 | 153 |
154 WaitFlagsState LocalDataPipe::ProducerGetWaitFlagsStateNoLock() const { | 154 WaitFlagsState LocalDataPipe::ProducerGetWaitFlagsStateNoLock() const { |
155 WaitFlagsState rv; | 155 WaitFlagsState rv; |
156 if (consumer_open_no_lock()) { | 156 if (consumer_open_no_lock()) { |
157 if ((may_discard() || current_num_bytes_ < capacity_num_bytes()) && | 157 if ((may_discard() || current_num_bytes_ < capacity_num_bytes()) && |
158 !producer_in_two_phase_write_no_lock()) | 158 !producer_in_two_phase_write_no_lock()) |
159 rv.satisfied_flags |= MOJO_WAIT_FLAG_WRITABLE; | 159 rv.satisfied_signals |= MOJO_WAIT_FLAG_WRITABLE; |
160 rv.satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; | 160 rv.satisfiable_signals |= MOJO_WAIT_FLAG_WRITABLE; |
161 } | 161 } |
162 return rv; | 162 return rv; |
163 } | 163 } |
164 | 164 |
165 void LocalDataPipe::ConsumerCloseImplNoLock() { | 165 void LocalDataPipe::ConsumerCloseImplNoLock() { |
166 // If the producer is around and in a two-phase write, we have to keep the | 166 // If the producer is around and in a two-phase write, we have to keep the |
167 // buffer around. (We then don't free it until the producer is closed. This | 167 // buffer around. (We then don't free it until the producer is closed. This |
168 // could be rectified, but again seems like optimizing for the uncommon case.) | 168 // could be rectified, but again seems like optimizing for the uncommon case.) |
169 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) | 169 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) |
170 DestroyBufferNoLock(); | 170 DestroyBufferNoLock(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); | 270 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); |
271 MarkDataAsConsumedNoLock(num_bytes_read); | 271 MarkDataAsConsumedNoLock(num_bytes_read); |
272 set_consumer_two_phase_max_num_bytes_read_no_lock(0); | 272 set_consumer_two_phase_max_num_bytes_read_no_lock(0); |
273 return MOJO_RESULT_OK; | 273 return MOJO_RESULT_OK; |
274 } | 274 } |
275 | 275 |
276 WaitFlagsState LocalDataPipe::ConsumerGetWaitFlagsStateNoLock() const { | 276 WaitFlagsState LocalDataPipe::ConsumerGetWaitFlagsStateNoLock() const { |
277 WaitFlagsState rv; | 277 WaitFlagsState rv; |
278 if (current_num_bytes_ > 0) { | 278 if (current_num_bytes_ > 0) { |
279 if (!consumer_in_two_phase_read_no_lock()) | 279 if (!consumer_in_two_phase_read_no_lock()) |
280 rv.satisfied_flags |= MOJO_WAIT_FLAG_READABLE; | 280 rv.satisfied_signals |= MOJO_WAIT_FLAG_READABLE; |
281 rv.satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; | 281 rv.satisfiable_signals |= MOJO_WAIT_FLAG_READABLE; |
282 } else if (producer_open_no_lock()) { | 282 } else if (producer_open_no_lock()) { |
283 rv.satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; | 283 rv.satisfiable_signals |= MOJO_WAIT_FLAG_READABLE; |
284 } | 284 } |
285 return rv; | 285 return rv; |
286 } | 286 } |
287 | 287 |
288 void LocalDataPipe::EnsureBufferNoLock() { | 288 void LocalDataPipe::EnsureBufferNoLock() { |
289 DCHECK(producer_open_no_lock()); | 289 DCHECK(producer_open_no_lock()); |
290 if (buffer_.get()) | 290 if (buffer_.get()) |
291 return; | 291 return; |
292 buffer_.reset(static_cast<char*>( | 292 buffer_.reset(static_cast<char*>( |
293 base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes))); | 293 base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes))); |
(...skipping 29 matching lines...) Expand all Loading... |
323 | 323 |
324 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { | 324 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { |
325 DCHECK_LE(num_bytes, current_num_bytes_); | 325 DCHECK_LE(num_bytes, current_num_bytes_); |
326 start_index_ += num_bytes; | 326 start_index_ += num_bytes; |
327 start_index_ %= capacity_num_bytes(); | 327 start_index_ %= capacity_num_bytes(); |
328 current_num_bytes_ -= num_bytes; | 328 current_num_bytes_ -= num_bytes; |
329 } | 329 } |
330 | 330 |
331 } // namespace system | 331 } // namespace system |
332 } // namespace mojo | 332 } // namespace mojo |
OLD | NEW |