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 |
11 #include "mojo/edk/system/local_data_pipe.h" | 11 #include "mojo/edk/system/local_data_pipe_impl.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "mojo/edk/system/configuration.h" | 18 #include "mojo/edk/system/configuration.h" |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 namespace system { | 21 namespace system { |
22 | 22 |
23 LocalDataPipe::LocalDataPipe(const MojoCreateDataPipeOptions& options) | 23 LocalDataPipeImpl::LocalDataPipeImpl(const MojoCreateDataPipeOptions& options) |
24 : DataPipe(true, true, options), start_index_(0), current_num_bytes_(0) { | 24 : DataPipe(true, true, options), start_index_(0), current_num_bytes_(0) { |
25 // Note: |buffer_| is lazily allocated, since a common case will be that one | 25 // Note: |buffer_| is lazily allocated, since a common case will be that one |
26 // of the handles is immediately passed off to another process. | 26 // of the handles is immediately passed off to another process. |
27 } | 27 } |
28 | 28 |
29 LocalDataPipe::~LocalDataPipe() { | 29 LocalDataPipeImpl::~LocalDataPipeImpl() { |
30 } | 30 } |
31 | 31 |
32 void LocalDataPipe::ProducerCloseImplNoLock() { | 32 void LocalDataPipeImpl::ProducerCloseImplNoLock() { |
33 // If the consumer is still open and we still have data, we have to keep the | 33 // If the consumer is still open and we still have data, we have to keep the |
34 // buffer around. Currently, we won't free it even if it empties later. (We | 34 // buffer around. Currently, we won't free it even if it empties later. (We |
35 // could do this -- requiring a check on every read -- but that seems to be | 35 // could do this -- requiring a check on every read -- but that seems to be |
36 // optimizing for the uncommon case.) | 36 // optimizing for the uncommon case.) |
37 if (!consumer_open_no_lock() || !current_num_bytes_) { | 37 if (!consumer_open_no_lock() || !current_num_bytes_) { |
38 // Note: There can only be a two-phase *read* (by the consumer) if we still | 38 // Note: There can only be a two-phase *read* (by the consumer) if we still |
39 // have data. | 39 // have data. |
40 DCHECK(!consumer_in_two_phase_read_no_lock()); | 40 DCHECK(!consumer_in_two_phase_read_no_lock()); |
41 DestroyBufferNoLock(); | 41 DestroyBufferNoLock(); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 MojoResult LocalDataPipe::ProducerWriteDataImplNoLock( | 45 MojoResult LocalDataPipeImpl::ProducerWriteDataImplNoLock( |
46 UserPointer<const void> elements, | 46 UserPointer<const void> elements, |
47 UserPointer<uint32_t> num_bytes, | 47 UserPointer<uint32_t> num_bytes, |
48 uint32_t max_num_bytes_to_write, | 48 uint32_t max_num_bytes_to_write, |
49 uint32_t min_num_bytes_to_write) { | 49 uint32_t min_num_bytes_to_write) { |
50 DCHECK_EQ(max_num_bytes_to_write % element_num_bytes(), 0u); | 50 DCHECK_EQ(max_num_bytes_to_write % element_num_bytes(), 0u); |
51 DCHECK_EQ(min_num_bytes_to_write % element_num_bytes(), 0u); | 51 DCHECK_EQ(min_num_bytes_to_write % element_num_bytes(), 0u); |
52 DCHECK_GT(max_num_bytes_to_write, 0u); | 52 DCHECK_GT(max_num_bytes_to_write, 0u); |
53 DCHECK(consumer_open_no_lock()); | 53 DCHECK(consumer_open_no_lock()); |
54 | 54 |
55 size_t num_bytes_to_write = 0; | 55 size_t num_bytes_to_write = 0; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 elements.At(num_bytes_to_write_first) | 94 elements.At(num_bytes_to_write_first) |
95 .GetArray(buffer_.get(), num_bytes_to_write - num_bytes_to_write_first); | 95 .GetArray(buffer_.get(), num_bytes_to_write - num_bytes_to_write_first); |
96 } | 96 } |
97 | 97 |
98 current_num_bytes_ += num_bytes_to_write; | 98 current_num_bytes_ += num_bytes_to_write; |
99 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); | 99 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); |
100 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_write)); | 100 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_write)); |
101 return MOJO_RESULT_OK; | 101 return MOJO_RESULT_OK; |
102 } | 102 } |
103 | 103 |
104 MojoResult LocalDataPipe::ProducerBeginWriteDataImplNoLock( | 104 MojoResult LocalDataPipeImpl::ProducerBeginWriteDataImplNoLock( |
105 UserPointer<void*> buffer, | 105 UserPointer<void*> buffer, |
106 UserPointer<uint32_t> buffer_num_bytes, | 106 UserPointer<uint32_t> buffer_num_bytes, |
107 uint32_t min_num_bytes_to_write) { | 107 uint32_t min_num_bytes_to_write) { |
108 DCHECK(consumer_open_no_lock()); | 108 DCHECK(consumer_open_no_lock()); |
109 | 109 |
110 // The index we need to start writing at. | 110 // The index we need to start writing at. |
111 size_t write_index = | 111 size_t write_index = |
112 (start_index_ + current_num_bytes_) % capacity_num_bytes(); | 112 (start_index_ + current_num_bytes_) % capacity_num_bytes(); |
113 | 113 |
114 size_t max_num_bytes_to_write = GetMaxNumBytesToWriteNoLock(); | 114 size_t max_num_bytes_to_write = GetMaxNumBytesToWriteNoLock(); |
(...skipping 20 matching lines...) Expand all Loading... |
135 return MOJO_RESULT_SHOULD_WAIT; | 135 return MOJO_RESULT_SHOULD_WAIT; |
136 | 136 |
137 EnsureBufferNoLock(); | 137 EnsureBufferNoLock(); |
138 buffer.Put(buffer_.get() + write_index); | 138 buffer.Put(buffer_.get() + write_index); |
139 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_write)); | 139 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_write)); |
140 set_producer_two_phase_max_num_bytes_written_no_lock( | 140 set_producer_two_phase_max_num_bytes_written_no_lock( |
141 static_cast<uint32_t>(max_num_bytes_to_write)); | 141 static_cast<uint32_t>(max_num_bytes_to_write)); |
142 return MOJO_RESULT_OK; | 142 return MOJO_RESULT_OK; |
143 } | 143 } |
144 | 144 |
145 MojoResult LocalDataPipe::ProducerEndWriteDataImplNoLock( | 145 MojoResult LocalDataPipeImpl::ProducerEndWriteDataImplNoLock( |
146 uint32_t num_bytes_written) { | 146 uint32_t num_bytes_written) { |
147 DCHECK_LE(num_bytes_written, | 147 DCHECK_LE(num_bytes_written, |
148 producer_two_phase_max_num_bytes_written_no_lock()); | 148 producer_two_phase_max_num_bytes_written_no_lock()); |
149 current_num_bytes_ += num_bytes_written; | 149 current_num_bytes_ += num_bytes_written; |
150 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); | 150 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); |
151 set_producer_two_phase_max_num_bytes_written_no_lock(0); | 151 set_producer_two_phase_max_num_bytes_written_no_lock(0); |
152 return MOJO_RESULT_OK; | 152 return MOJO_RESULT_OK; |
153 } | 153 } |
154 | 154 |
155 HandleSignalsState LocalDataPipe::ProducerGetHandleSignalsStateImplNoLock() | 155 HandleSignalsState LocalDataPipeImpl::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 { | 163 } else { |
164 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 164 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
165 } | 165 } |
166 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 166 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
167 return rv; | 167 return rv; |
168 } | 168 } |
169 | 169 |
170 void LocalDataPipe::ProducerStartSerializeImplNoLock( | 170 void LocalDataPipeImpl::ProducerStartSerializeImplNoLock( |
171 Channel* channel, | 171 Channel* channel, |
172 size_t* max_size, | 172 size_t* max_size, |
173 size_t* max_platform_handles) { | 173 size_t* max_platform_handles) { |
174 // TODO(vtl): Support serializing producer data pipe handles. | 174 // TODO(vtl): Support serializing producer data pipe handles. |
175 *max_size = 0; | 175 *max_size = 0; |
176 *max_platform_handles = 0; | 176 *max_platform_handles = 0; |
177 } | 177 } |
178 | 178 |
179 bool LocalDataPipe::ProducerEndSerializeImplNoLock( | 179 bool LocalDataPipeImpl::ProducerEndSerializeImplNoLock( |
180 Channel* channel, | 180 Channel* channel, |
181 void* destination, | 181 void* destination, |
182 size_t* actual_size, | 182 size_t* actual_size, |
183 embedder::PlatformHandleVector* platform_handles) { | 183 embedder::PlatformHandleVector* platform_handles) { |
184 // TODO(vtl): Support serializing producer data pipe handles. | 184 // TODO(vtl): Support serializing producer data pipe handles. |
185 ProducerCloseNoLock(); | 185 ProducerCloseNoLock(); |
186 return false; | 186 return false; |
187 } | 187 } |
188 | 188 |
189 void LocalDataPipe::ConsumerCloseImplNoLock() { | 189 void LocalDataPipeImpl::ConsumerCloseImplNoLock() { |
190 // If the producer is around and in a two-phase write, we have to keep the | 190 // If the producer is around and in a two-phase write, we have to keep the |
191 // buffer around. (We then don't free it until the producer is closed. This | 191 // buffer around. (We then don't free it until the producer is closed. This |
192 // could be rectified, but again seems like optimizing for the uncommon case.) | 192 // could be rectified, but again seems like optimizing for the uncommon case.) |
193 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) | 193 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) |
194 DestroyBufferNoLock(); | 194 DestroyBufferNoLock(); |
195 current_num_bytes_ = 0; | 195 current_num_bytes_ = 0; |
196 } | 196 } |
197 | 197 |
198 MojoResult LocalDataPipe::ConsumerReadDataImplNoLock( | 198 MojoResult LocalDataPipeImpl::ConsumerReadDataImplNoLock( |
199 UserPointer<void> elements, | 199 UserPointer<void> elements, |
200 UserPointer<uint32_t> num_bytes, | 200 UserPointer<uint32_t> num_bytes, |
201 uint32_t max_num_bytes_to_read, | 201 uint32_t max_num_bytes_to_read, |
202 uint32_t min_num_bytes_to_read, | 202 uint32_t min_num_bytes_to_read, |
203 bool peek) { | 203 bool peek) { |
204 DCHECK_EQ(max_num_bytes_to_read % element_num_bytes(), 0u); | 204 DCHECK_EQ(max_num_bytes_to_read % element_num_bytes(), 0u); |
205 DCHECK_EQ(min_num_bytes_to_read % element_num_bytes(), 0u); | 205 DCHECK_EQ(min_num_bytes_to_read % element_num_bytes(), 0u); |
206 DCHECK_GT(max_num_bytes_to_read, 0u); | 206 DCHECK_GT(max_num_bytes_to_read, 0u); |
207 | 207 |
208 if (min_num_bytes_to_read > current_num_bytes_) { | 208 if (min_num_bytes_to_read > current_num_bytes_) { |
(...skipping 20 matching lines...) Expand all Loading... |
229 elements.At(num_bytes_to_read_first) | 229 elements.At(num_bytes_to_read_first) |
230 .PutArray(buffer_.get(), num_bytes_to_read - num_bytes_to_read_first); | 230 .PutArray(buffer_.get(), num_bytes_to_read - num_bytes_to_read_first); |
231 } | 231 } |
232 | 232 |
233 if (!peek) | 233 if (!peek) |
234 MarkDataAsConsumedNoLock(num_bytes_to_read); | 234 MarkDataAsConsumedNoLock(num_bytes_to_read); |
235 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_read)); | 235 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_read)); |
236 return MOJO_RESULT_OK; | 236 return MOJO_RESULT_OK; |
237 } | 237 } |
238 | 238 |
239 MojoResult LocalDataPipe::ConsumerDiscardDataImplNoLock( | 239 MojoResult LocalDataPipeImpl::ConsumerDiscardDataImplNoLock( |
240 UserPointer<uint32_t> num_bytes, | 240 UserPointer<uint32_t> num_bytes, |
241 uint32_t max_num_bytes_to_discard, | 241 uint32_t max_num_bytes_to_discard, |
242 uint32_t min_num_bytes_to_discard) { | 242 uint32_t min_num_bytes_to_discard) { |
243 DCHECK_EQ(max_num_bytes_to_discard % element_num_bytes(), 0u); | 243 DCHECK_EQ(max_num_bytes_to_discard % element_num_bytes(), 0u); |
244 DCHECK_EQ(min_num_bytes_to_discard % element_num_bytes(), 0u); | 244 DCHECK_EQ(min_num_bytes_to_discard % element_num_bytes(), 0u); |
245 DCHECK_GT(max_num_bytes_to_discard, 0u); | 245 DCHECK_GT(max_num_bytes_to_discard, 0u); |
246 | 246 |
247 if (min_num_bytes_to_discard > current_num_bytes_) { | 247 if (min_num_bytes_to_discard > current_num_bytes_) { |
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 // Be consistent with other operations; error if no data available. | 254 // Be consistent with other operations; error if no data available. |
255 if (current_num_bytes_ == 0) { | 255 if (current_num_bytes_ == 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 size_t num_bytes_to_discard = std::min( | 260 size_t num_bytes_to_discard = std::min( |
261 static_cast<size_t>(max_num_bytes_to_discard), current_num_bytes_); | 261 static_cast<size_t>(max_num_bytes_to_discard), current_num_bytes_); |
262 MarkDataAsConsumedNoLock(num_bytes_to_discard); | 262 MarkDataAsConsumedNoLock(num_bytes_to_discard); |
263 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_discard)); | 263 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_discard)); |
264 return MOJO_RESULT_OK; | 264 return MOJO_RESULT_OK; |
265 } | 265 } |
266 | 266 |
267 MojoResult LocalDataPipe::ConsumerQueryDataImplNoLock( | 267 MojoResult LocalDataPipeImpl::ConsumerQueryDataImplNoLock( |
268 UserPointer<uint32_t> num_bytes) { | 268 UserPointer<uint32_t> num_bytes) { |
269 // Note: This cast is safe, since the capacity fits into a |uint32_t|. | 269 // Note: This cast is safe, since the capacity fits into a |uint32_t|. |
270 num_bytes.Put(static_cast<uint32_t>(current_num_bytes_)); | 270 num_bytes.Put(static_cast<uint32_t>(current_num_bytes_)); |
271 return MOJO_RESULT_OK; | 271 return MOJO_RESULT_OK; |
272 } | 272 } |
273 | 273 |
274 MojoResult LocalDataPipe::ConsumerBeginReadDataImplNoLock( | 274 MojoResult LocalDataPipeImpl::ConsumerBeginReadDataImplNoLock( |
275 UserPointer<const void*> buffer, | 275 UserPointer<const void*> buffer, |
276 UserPointer<uint32_t> buffer_num_bytes, | 276 UserPointer<uint32_t> buffer_num_bytes, |
277 uint32_t min_num_bytes_to_read) { | 277 uint32_t min_num_bytes_to_read) { |
278 size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock(); | 278 size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock(); |
279 if (min_num_bytes_to_read > max_num_bytes_to_read) { | 279 if (min_num_bytes_to_read > max_num_bytes_to_read) { |
280 // Don't return "should wait" since you can't wait for a specified amount of | 280 // Don't return "should wait" since you can't wait for a specified amount of |
281 // data. | 281 // data. |
282 return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE | 282 return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE |
283 : MOJO_RESULT_FAILED_PRECONDITION; | 283 : MOJO_RESULT_FAILED_PRECONDITION; |
284 } | 284 } |
285 | 285 |
286 // Don't go into a two-phase read if there's no data. | 286 // Don't go into a two-phase read if there's no data. |
287 if (max_num_bytes_to_read == 0) { | 287 if (max_num_bytes_to_read == 0) { |
288 return producer_open_no_lock() ? MOJO_RESULT_SHOULD_WAIT | 288 return producer_open_no_lock() ? MOJO_RESULT_SHOULD_WAIT |
289 : MOJO_RESULT_FAILED_PRECONDITION; | 289 : MOJO_RESULT_FAILED_PRECONDITION; |
290 } | 290 } |
291 | 291 |
292 buffer.Put(buffer_.get() + start_index_); | 292 buffer.Put(buffer_.get() + start_index_); |
293 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_read)); | 293 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_read)); |
294 set_consumer_two_phase_max_num_bytes_read_no_lock( | 294 set_consumer_two_phase_max_num_bytes_read_no_lock( |
295 static_cast<uint32_t>(max_num_bytes_to_read)); | 295 static_cast<uint32_t>(max_num_bytes_to_read)); |
296 return MOJO_RESULT_OK; | 296 return MOJO_RESULT_OK; |
297 } | 297 } |
298 | 298 |
299 MojoResult LocalDataPipe::ConsumerEndReadDataImplNoLock( | 299 MojoResult LocalDataPipeImpl::ConsumerEndReadDataImplNoLock( |
300 uint32_t num_bytes_read) { | 300 uint32_t num_bytes_read) { |
301 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read_no_lock()); | 301 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read_no_lock()); |
302 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); | 302 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); |
303 MarkDataAsConsumedNoLock(num_bytes_read); | 303 MarkDataAsConsumedNoLock(num_bytes_read); |
304 set_consumer_two_phase_max_num_bytes_read_no_lock(0); | 304 set_consumer_two_phase_max_num_bytes_read_no_lock(0); |
305 return MOJO_RESULT_OK; | 305 return MOJO_RESULT_OK; |
306 } | 306 } |
307 | 307 |
308 HandleSignalsState LocalDataPipe::ConsumerGetHandleSignalsStateImplNoLock() | 308 HandleSignalsState LocalDataPipeImpl::ConsumerGetHandleSignalsStateImplNoLock() |
309 const { | 309 const { |
310 HandleSignalsState rv; | 310 HandleSignalsState rv; |
311 if (current_num_bytes_ > 0) { | 311 if (current_num_bytes_ > 0) { |
312 if (!consumer_in_two_phase_read_no_lock()) | 312 if (!consumer_in_two_phase_read_no_lock()) |
313 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 313 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
314 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 314 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
315 } else if (producer_open_no_lock()) { | 315 } else if (producer_open_no_lock()) { |
316 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 316 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
317 } | 317 } |
318 if (!producer_open_no_lock()) | 318 if (!producer_open_no_lock()) |
319 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 319 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
320 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 320 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
321 return rv; | 321 return rv; |
322 } | 322 } |
323 | 323 |
324 void LocalDataPipe::ConsumerStartSerializeImplNoLock( | 324 void LocalDataPipeImpl::ConsumerStartSerializeImplNoLock( |
325 Channel* channel, | 325 Channel* channel, |
326 size_t* max_size, | 326 size_t* max_size, |
327 size_t* max_platform_handles) { | 327 size_t* max_platform_handles) { |
328 // TODO(vtl): Support serializing consumer data pipe handles. | 328 // TODO(vtl): Support serializing consumer data pipe handles. |
329 *max_size = 0; | 329 *max_size = 0; |
330 *max_platform_handles = 0; | 330 *max_platform_handles = 0; |
331 } | 331 } |
332 | 332 |
333 bool LocalDataPipe::ConsumerEndSerializeImplNoLock( | 333 bool LocalDataPipeImpl::ConsumerEndSerializeImplNoLock( |
334 Channel* channel, | 334 Channel* channel, |
335 void* destination, | 335 void* destination, |
336 size_t* actual_size, | 336 size_t* actual_size, |
337 embedder::PlatformHandleVector* platform_handles) { | 337 embedder::PlatformHandleVector* platform_handles) { |
338 // TODO(vtl): Support serializing consumer data pipe handles. | 338 // TODO(vtl): Support serializing consumer data pipe handles. |
339 ConsumerCloseNoLock(); | 339 ConsumerCloseNoLock(); |
340 return false; | 340 return false; |
341 } | 341 } |
342 | 342 |
343 void LocalDataPipe::EnsureBufferNoLock() { | 343 void LocalDataPipeImpl::EnsureBufferNoLock() { |
344 DCHECK(producer_open_no_lock()); | 344 DCHECK(producer_open_no_lock()); |
345 if (buffer_) | 345 if (buffer_) |
346 return; | 346 return; |
347 buffer_.reset(static_cast<char*>( | 347 buffer_.reset(static_cast<char*>( |
348 base::AlignedAlloc(capacity_num_bytes(), | 348 base::AlignedAlloc(capacity_num_bytes(), |
349 GetConfiguration().data_pipe_buffer_alignment_bytes))); | 349 GetConfiguration().data_pipe_buffer_alignment_bytes))); |
350 } | 350 } |
351 | 351 |
352 void LocalDataPipe::DestroyBufferNoLock() { | 352 void LocalDataPipeImpl::DestroyBufferNoLock() { |
353 #ifndef NDEBUG | 353 #ifndef NDEBUG |
354 // Scribble on the buffer to help detect use-after-frees. (This also helps the | 354 // Scribble on the buffer to help detect use-after-frees. (This also helps the |
355 // unit test detect certain bugs without needing ASAN or similar.) | 355 // unit test detect certain bugs without needing ASAN or similar.) |
356 if (buffer_) | 356 if (buffer_) |
357 memset(buffer_.get(), 0xcd, capacity_num_bytes()); | 357 memset(buffer_.get(), 0xcd, capacity_num_bytes()); |
358 #endif | 358 #endif |
359 buffer_.reset(); | 359 buffer_.reset(); |
360 } | 360 } |
361 | 361 |
362 size_t LocalDataPipe::GetMaxNumBytesToWriteNoLock() { | 362 size_t LocalDataPipeImpl::GetMaxNumBytesToWriteNoLock() { |
363 size_t next_index = start_index_ + current_num_bytes_; | 363 size_t next_index = start_index_ + current_num_bytes_; |
364 if (next_index >= capacity_num_bytes()) { | 364 if (next_index >= capacity_num_bytes()) { |
365 next_index %= capacity_num_bytes(); | 365 next_index %= capacity_num_bytes(); |
366 DCHECK_GE(start_index_, next_index); | 366 DCHECK_GE(start_index_, next_index); |
367 DCHECK_EQ(start_index_ - next_index, | 367 DCHECK_EQ(start_index_ - next_index, |
368 capacity_num_bytes() - current_num_bytes_); | 368 capacity_num_bytes() - current_num_bytes_); |
369 return start_index_ - next_index; | 369 return start_index_ - next_index; |
370 } | 370 } |
371 return capacity_num_bytes() - next_index; | 371 return capacity_num_bytes() - next_index; |
372 } | 372 } |
373 | 373 |
374 size_t LocalDataPipe::GetMaxNumBytesToReadNoLock() { | 374 size_t LocalDataPipeImpl::GetMaxNumBytesToReadNoLock() { |
375 if (start_index_ + current_num_bytes_ > capacity_num_bytes()) | 375 if (start_index_ + current_num_bytes_ > capacity_num_bytes()) |
376 return capacity_num_bytes() - start_index_; | 376 return capacity_num_bytes() - start_index_; |
377 return current_num_bytes_; | 377 return current_num_bytes_; |
378 } | 378 } |
379 | 379 |
380 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { | 380 void LocalDataPipeImpl::MarkDataAsConsumedNoLock(size_t num_bytes) { |
381 DCHECK_LE(num_bytes, current_num_bytes_); | 381 DCHECK_LE(num_bytes, current_num_bytes_); |
382 start_index_ += num_bytes; | 382 start_index_ += num_bytes; |
383 start_index_ %= capacity_num_bytes(); | 383 start_index_ %= capacity_num_bytes(); |
384 current_num_bytes_ -= num_bytes; | 384 current_num_bytes_ -= num_bytes; |
385 } | 385 } |
386 | 386 |
387 } // namespace system | 387 } // namespace system |
388 } // namespace mojo | 388 } // namespace mojo |
OLD | NEW |