Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: mojo/system/local_data_pipe.cc

Issue 416203002: Convert BeginReadData...() to use the new user pointer handling (see r285350). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/system/local_data_pipe.h ('k') | mojo/system/local_data_pipe_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 return MOJO_RESULT_OK; 233 return MOJO_RESULT_OK;
234 } 234 }
235 235
236 MojoResult LocalDataPipe::ConsumerQueryDataImplNoLock(uint32_t* num_bytes) { 236 MojoResult LocalDataPipe::ConsumerQueryDataImplNoLock(uint32_t* num_bytes) {
237 // Note: This cast is safe, since the capacity fits into a |uint32_t|. 237 // Note: This cast is safe, since the capacity fits into a |uint32_t|.
238 *num_bytes = static_cast<uint32_t>(current_num_bytes_); 238 *num_bytes = static_cast<uint32_t>(current_num_bytes_);
239 return MOJO_RESULT_OK; 239 return MOJO_RESULT_OK;
240 } 240 }
241 241
242 MojoResult LocalDataPipe::ConsumerBeginReadDataImplNoLock( 242 MojoResult LocalDataPipe::ConsumerBeginReadDataImplNoLock(
243 const void** buffer, 243 UserPointer<const void*> buffer,
244 uint32_t* buffer_num_bytes, 244 UserPointer<uint32_t> buffer_num_bytes,
245 bool all_or_none) { 245 uint32_t min_num_bytes_to_read) {
246 size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock(); 246 size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock();
247 if (all_or_none && *buffer_num_bytes > max_num_bytes_to_read) { 247 if (min_num_bytes_to_read > max_num_bytes_to_read) {
248 // Don't return "should wait" since you can't wait for a specified amount of 248 // Don't return "should wait" since you can't wait for a specified amount of
249 // data. 249 // data.
250 return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE : 250 return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE :
251 MOJO_RESULT_FAILED_PRECONDITION; 251 MOJO_RESULT_FAILED_PRECONDITION;
252 } 252 }
253 253
254 // Don't go into a two-phase read if there's no data. 254 // Don't go into a two-phase read if there's no data.
255 if (max_num_bytes_to_read == 0) { 255 if (max_num_bytes_to_read == 0) {
256 return producer_open_no_lock() ? MOJO_RESULT_SHOULD_WAIT : 256 return producer_open_no_lock() ? MOJO_RESULT_SHOULD_WAIT :
257 MOJO_RESULT_FAILED_PRECONDITION; 257 MOJO_RESULT_FAILED_PRECONDITION;
258 } 258 }
259 259
260 *buffer = buffer_.get() + start_index_; 260 buffer.Put(buffer_.get() + start_index_);
261 *buffer_num_bytes = static_cast<uint32_t>(max_num_bytes_to_read); 261 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_read));
262 set_consumer_two_phase_max_num_bytes_read_no_lock( 262 set_consumer_two_phase_max_num_bytes_read_no_lock(
263 static_cast<uint32_t>(max_num_bytes_to_read)); 263 static_cast<uint32_t>(max_num_bytes_to_read));
264 return MOJO_RESULT_OK; 264 return MOJO_RESULT_OK;
265 } 265 }
266 266
267 MojoResult LocalDataPipe::ConsumerEndReadDataImplNoLock( 267 MojoResult LocalDataPipe::ConsumerEndReadDataImplNoLock(
268 uint32_t num_bytes_read) { 268 uint32_t num_bytes_read) {
269 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read_no_lock()); 269 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read_no_lock());
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);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « mojo/system/local_data_pipe.h ('k') | mojo/system/local_data_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698