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_impl.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 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | |
20 #include "mojo/edk/system/channel.h" | 19 #include "mojo/edk/system/channel.h" |
21 #include "mojo/edk/system/configuration.h" | 20 #include "mojo/edk/system/configuration.h" |
22 #include "mojo/edk/system/data_pipe.h" | 21 #include "mojo/edk/system/data_pipe.h" |
23 #include "mojo/edk/system/message_in_transit.h" | 22 #include "mojo/edk/system/message_in_transit.h" |
24 #include "mojo/edk/system/message_in_transit_queue.h" | 23 #include "mojo/edk/system/message_in_transit_queue.h" |
25 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" | 24 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" |
26 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" | 25 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" |
| 26 #include "mojo/edk/util/make_unique.h" |
27 | 27 |
28 namespace mojo { | 28 namespace mojo { |
29 namespace system { | 29 namespace system { |
30 | 30 |
31 // Assert some things about some things defined in data_pipe_impl.h (don't make | 31 // Assert some things about some things defined in data_pipe_impl.h (don't make |
32 // the assertions there, to avoid including message_in_transit.h). | 32 // the assertions there, to avoid including message_in_transit.h). |
33 static_assert(MOJO_ALIGNOF(SerializedDataPipeConsumerDispatcher) == | 33 static_assert(MOJO_ALIGNOF(SerializedDataPipeConsumerDispatcher) == |
34 MessageInTransit::kMessageAlignment, | 34 MessageInTransit::kMessageAlignment, |
35 "Wrong alignment"); | 35 "Wrong alignment"); |
36 static_assert(sizeof(SerializedDataPipeConsumerDispatcher) % | 36 static_assert(sizeof(SerializedDataPipeConsumerDispatcher) % |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // Case 2: The consumer isn't closed. We'll replace ourselves with a | 186 // Case 2: The consumer isn't closed. We'll replace ourselves with a |
187 // |RemoteProducerDataPipeImpl|. | 187 // |RemoteProducerDataPipeImpl|. |
188 | 188 |
189 s->consumer_num_bytes = current_num_bytes_; | 189 s->consumer_num_bytes = current_num_bytes_; |
190 // Note: We don't use |port|. | 190 // Note: We don't use |port|. |
191 scoped_refptr<ChannelEndpoint> channel_endpoint = | 191 scoped_refptr<ChannelEndpoint> channel_endpoint = |
192 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, nullptr, | 192 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, nullptr, |
193 channel_endpoint_client(), 0); | 193 channel_endpoint_client(), 0); |
194 // Note: Keep |*this| alive until the end of this method, to make things | 194 // Note: Keep |*this| alive until the end of this method, to make things |
195 // slightly easier on ourselves. | 195 // slightly easier on ourselves. |
196 scoped_ptr<DataPipeImpl> self(ReplaceImpl(make_scoped_ptr( | 196 std::unique_ptr<DataPipeImpl> self( |
197 new RemoteProducerDataPipeImpl(channel_endpoint.get(), std::move(buffer_), | 197 ReplaceImpl(util::MakeUnique<RemoteProducerDataPipeImpl>( |
198 start_index_, current_num_bytes_)))); | 198 channel_endpoint.get(), std::move(buffer_), start_index_, |
| 199 current_num_bytes_))); |
199 | 200 |
200 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) + | 201 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) + |
201 channel->GetSerializedEndpointSize(); | 202 channel->GetSerializedEndpointSize(); |
202 return true; | 203 return true; |
203 } | 204 } |
204 | 205 |
205 void LocalDataPipeImpl::ConsumerClose() { | 206 void LocalDataPipeImpl::ConsumerClose() { |
206 // If the producer is around and in a two-phase write, we have to keep the | 207 // If the producer is around and in a two-phase write, we have to keep the |
207 // buffer around. (We then don't free it until the producer is closed. This | 208 // buffer around. (We then don't free it until the producer is closed. This |
208 // could be rectified, but again seems like optimizing for the uncommon case.) | 209 // could be rectified, but again seems like optimizing for the uncommon case.) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 // Case 2: The producer isn't closed. We'll replace ourselves with a | 374 // Case 2: The producer isn't closed. We'll replace ourselves with a |
374 // |RemoteConsumerDataPipeImpl|. | 375 // |RemoteConsumerDataPipeImpl|. |
375 | 376 |
376 // Note: We don't use |port|. | 377 // Note: We don't use |port|. |
377 scoped_refptr<ChannelEndpoint> channel_endpoint = | 378 scoped_refptr<ChannelEndpoint> channel_endpoint = |
378 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, | 379 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, |
379 &message_queue, | 380 &message_queue, |
380 channel_endpoint_client(), 0); | 381 channel_endpoint_client(), 0); |
381 // Note: Keep |*this| alive until the end of this method, to make things | 382 // Note: Keep |*this| alive until the end of this method, to make things |
382 // slightly easier on ourselves. | 383 // slightly easier on ourselves. |
383 scoped_ptr<DataPipeImpl> self(ReplaceImpl(make_scoped_ptr( | 384 std::unique_ptr<DataPipeImpl> self( |
384 new RemoteConsumerDataPipeImpl(channel_endpoint.get(), old_num_bytes)))); | 385 ReplaceImpl(util::MakeUnique<RemoteConsumerDataPipeImpl>( |
| 386 channel_endpoint.get(), old_num_bytes))); |
385 | 387 |
386 *actual_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 388 *actual_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
387 channel->GetSerializedEndpointSize(); | 389 channel->GetSerializedEndpointSize(); |
388 return true; | 390 return true; |
389 } | 391 } |
390 | 392 |
391 bool LocalDataPipeImpl::OnReadMessage(unsigned /*port*/, | 393 bool LocalDataPipeImpl::OnReadMessage(unsigned /*port*/, |
392 MessageInTransit* /*message*/) { | 394 MessageInTransit* /*message*/) { |
393 NOTREACHED(); | 395 NOTREACHED(); |
394 return false; | 396 return false; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 439 |
438 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { | 440 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { |
439 DCHECK_LE(num_bytes, current_num_bytes_); | 441 DCHECK_LE(num_bytes, current_num_bytes_); |
440 start_index_ += num_bytes; | 442 start_index_ += num_bytes; |
441 start_index_ %= capacity_num_bytes(); | 443 start_index_ %= capacity_num_bytes(); |
442 current_num_bytes_ -= num_bytes; | 444 current_num_bytes_ -= num_bytes; |
443 } | 445 } |
444 | 446 |
445 } // namespace system | 447 } // namespace system |
446 } // namespace mojo | 448 } // namespace mojo |
OLD | NEW |