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

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

Issue 304303006: Mojo: Specify/check alignment of pointers more carefully. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix msvs Created 6 years, 6 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/core_test_base.cc ('k') | mojo/system/data_pipe_producer_dispatcher.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 #include "mojo/system/data_pipe_consumer_dispatcher.h" 5 #include "mojo/system/data_pipe_consumer_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/system/data_pipe.h" 8 #include "mojo/system/data_pipe.h"
9 #include "mojo/system/memory.h" 9 #include "mojo/system/memory.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 data_pipe_ = NULL; 49 data_pipe_ = NULL;
50 return scoped_refptr<Dispatcher>(rv.get()); 50 return scoped_refptr<Dispatcher>(rv.get());
51 } 51 }
52 52
53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock( 53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
54 void* elements, 54 void* elements,
55 uint32_t* num_bytes, 55 uint32_t* num_bytes,
56 MojoReadDataFlags flags) { 56 MojoReadDataFlags flags) {
57 lock().AssertAcquired(); 57 lock().AssertAcquired();
58 58
59 if (!VerifyUserPointer<uint32_t>(num_bytes, 1)) 59 if (!VerifyUserPointer<uint32_t>(num_bytes))
60 return MOJO_RESULT_INVALID_ARGUMENT; 60 return MOJO_RESULT_INVALID_ARGUMENT;
61 61
62 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { 62 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) {
63 // These flags are mutally exclusive. 63 // These flags are mutally exclusive.
64 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) 64 if ((flags & MOJO_READ_DATA_FLAG_QUERY))
65 return MOJO_RESULT_INVALID_ARGUMENT; 65 return MOJO_RESULT_INVALID_ARGUMENT;
66 DVLOG_IF(2, elements) << "Discard mode: ignoring non-null |elements|"; 66 DVLOG_IF(2, elements) << "Discard mode: ignoring non-null |elements|";
67 return data_pipe_->ConsumerDiscardData( 67 return data_pipe_->ConsumerDiscardData(
68 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 68 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
69 } 69 }
70 70
71 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) { 71 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) {
72 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above. 72 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above.
73 DVLOG_IF(2, elements) << "Query mode: ignoring non-null |elements|"; 73 DVLOG_IF(2, elements) << "Query mode: ignoring non-null |elements|";
74 return data_pipe_->ConsumerQueryData(num_bytes); 74 return data_pipe_->ConsumerQueryData(num_bytes);
75 } 75 }
76 76
77 // Only verify |elements| if we're neither discarding nor querying. 77 // Only verify |elements| if we're neither discarding nor querying.
78 if (!VerifyUserPointer<void>(elements, *num_bytes)) 78 if (!VerifyUserPointerWithSize<1>(elements, *num_bytes))
79 return MOJO_RESULT_INVALID_ARGUMENT; 79 return MOJO_RESULT_INVALID_ARGUMENT;
80 80
81 return data_pipe_->ConsumerReadData( 81 return data_pipe_->ConsumerReadData(
82 elements, num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 82 elements, num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
83 } 83 }
84 84
85 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock( 85 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock(
86 const void** buffer, 86 const void** buffer,
87 uint32_t* buffer_num_bytes, 87 uint32_t* buffer_num_bytes,
88 MojoReadDataFlags flags) { 88 MojoReadDataFlags flags) {
89 lock().AssertAcquired(); 89 lock().AssertAcquired();
90 90
91 if (!VerifyUserPointer<const void*>(buffer, 1)) 91 if (!VerifyUserPointerWithCount<const void*>(buffer, 1))
92 return MOJO_RESULT_INVALID_ARGUMENT; 92 return MOJO_RESULT_INVALID_ARGUMENT;
93 if (!VerifyUserPointer<uint32_t>(buffer_num_bytes, 1)) 93 if (!VerifyUserPointer<uint32_t>(buffer_num_bytes))
94 return MOJO_RESULT_INVALID_ARGUMENT; 94 return MOJO_RESULT_INVALID_ARGUMENT;
95 // These flags may not be used in two-phase mode. 95 // These flags may not be used in two-phase mode.
96 if ((flags & MOJO_READ_DATA_FLAG_DISCARD) || 96 if ((flags & MOJO_READ_DATA_FLAG_DISCARD) ||
97 (flags & MOJO_READ_DATA_FLAG_QUERY)) 97 (flags & MOJO_READ_DATA_FLAG_QUERY))
98 return MOJO_RESULT_INVALID_ARGUMENT; 98 return MOJO_RESULT_INVALID_ARGUMENT;
99 99
100 return data_pipe_->ConsumerBeginReadData( 100 return data_pipe_->ConsumerBeginReadData(
101 buffer, buffer_num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 101 buffer, buffer_num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
102 } 102 }
103 103
(...skipping 17 matching lines...) Expand all
121 data_pipe_->ConsumerRemoveWaiter(waiter); 121 data_pipe_->ConsumerRemoveWaiter(waiter);
122 } 122 }
123 123
124 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { 124 bool DataPipeConsumerDispatcher::IsBusyNoLock() const {
125 lock().AssertAcquired(); 125 lock().AssertAcquired();
126 return data_pipe_->ConsumerIsBusy(); 126 return data_pipe_->ConsumerIsBusy();
127 } 127 }
128 128
129 } // namespace system 129 } // namespace system
130 } // namespace mojo 130 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/core_test_base.cc ('k') | mojo/system/data_pipe_producer_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698