| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/edk/system/channel.h" | 5 #include "mojo/edk/system/channel.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 for (size_t i = 0; i < num_handles; ++i) { | 329 for (size_t i = 0; i < num_handles; ++i) { |
| 330 if (!handles[i].is_valid()) { | 330 if (!handles[i].is_valid()) { |
| 331 DLOG(ERROR) << "Refusing to duplicate invalid handle."; | 331 DLOG(ERROR) << "Refusing to duplicate invalid handle."; |
| 332 continue; | 332 continue; |
| 333 } | 333 } |
| 334 DCHECK_EQ(handles[i].owning_process, from_process); | 334 DCHECK_EQ(handles[i].owning_process, from_process); |
| 335 BOOL result = DuplicateHandle( | 335 BOOL result = DuplicateHandle( |
| 336 from_process, handles[i].handle, to_process, | 336 from_process, handles[i].handle, to_process, |
| 337 &handles[i].handle, 0, FALSE, | 337 &handles[i].handle, 0, FALSE, |
| 338 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); | 338 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); |
| 339 if (result) | 339 if (result) { |
| 340 handles[i].owning_process = to_process; | 340 handles[i].owning_process = to_process; |
| 341 else | 341 } else { |
| 342 success = false; | 342 success = false; |
| 343 |
| 344 // If handle duplication fails, the source handle will already be closed |
| 345 // due to DUPLICATE_CLOSE_SOURCE. Replace the handle in the message with |
| 346 // an invalid handle. |
| 347 handles[i].handle = INVALID_HANDLE_VALUE; |
| 348 handles[i].owning_process = base::GetCurrentProcessHandle(); |
| 349 } |
| 343 } | 350 } |
| 344 return success; | 351 return success; |
| 345 } | 352 } |
| 346 #endif | 353 #endif |
| 347 | 354 |
| 348 // Helper class for managing a Channel's read buffer allocations. This maintains | 355 // Helper class for managing a Channel's read buffer allocations. This maintains |
| 349 // a single contiguous buffer with the layout: | 356 // a single contiguous buffer with the layout: |
| 350 // | 357 // |
| 351 // [discarded bytes][occupied bytes][unoccupied bytes] | 358 // [discarded bytes][occupied bytes][unoccupied bytes] |
| 352 // | 359 // |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 return true; | 568 return true; |
| 562 } | 569 } |
| 563 | 570 |
| 564 void Channel::OnError() { | 571 void Channel::OnError() { |
| 565 if (delegate_) | 572 if (delegate_) |
| 566 delegate_->OnChannelError(); | 573 delegate_->OnChannelError(); |
| 567 } | 574 } |
| 568 | 575 |
| 569 } // namespace edk | 576 } // namespace edk |
| 570 } // namespace mojo | 577 } // namespace mojo |
| OLD | NEW |