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

Side by Side Diff: mojo/edk/system/channel.cc

Issue 1914053003: [mojo-edk] Fix lifetime management of rewritten Windows HANDLEs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « mojo/edk/embedder/platform_handle.cc ('k') | mojo/edk/system/node_channel.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 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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/aligned_memory.h" 14 #include "base/memory/aligned_memory.h"
15 #include "base/process/process_handle.h"
15 #include "mojo/edk/embedder/platform_handle.h" 16 #include "mojo/edk/embedder/platform_handle.h"
16 17
17 #if defined(OS_MACOSX) && !defined(OS_IOS) 18 #if defined(OS_MACOSX) && !defined(OS_IOS)
18 #include "base/mac/mach_logging.h" 19 #include "base/mac/mach_logging.h"
19 #endif 20 #endif
20 21
21 namespace mojo { 22 namespace mojo {
22 namespace edk { 23 namespace edk {
23 24
24 namespace { 25 namespace {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process, 324 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process,
324 base::ProcessHandle to_process, 325 base::ProcessHandle to_process,
325 PlatformHandle* handles, 326 PlatformHandle* handles,
326 size_t num_handles) { 327 size_t num_handles) {
327 bool success = true; 328 bool success = true;
328 for (size_t i = 0; i < num_handles; ++i) { 329 for (size_t i = 0; i < num_handles; ++i) {
329 if (!handles[i].is_valid()) { 330 if (!handles[i].is_valid()) {
330 DLOG(ERROR) << "Refusing to duplicate invalid handle."; 331 DLOG(ERROR) << "Refusing to duplicate invalid handle.";
331 continue; 332 continue;
332 } 333 }
334 DCHECK_EQ(handles[i].owning_process, from_process);
333 BOOL result = DuplicateHandle( 335 BOOL result = DuplicateHandle(
334 from_process, handles[i].handle, to_process, 336 from_process, handles[i].handle, to_process,
335 reinterpret_cast<HANDLE*>(handles + i), 0, FALSE, 337 &handles[i].handle, 0, FALSE,
336 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); 338 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
337 if (!result) 339 if (result)
340 handles[i].owning_process = to_process;
341 else
338 success = false; 342 success = false;
339 } 343 }
340 return success; 344 return success;
341 } 345 }
342 #endif 346 #endif
343 347
344 // Helper class for managing a Channel's read buffer allocations. This maintains 348 // Helper class for managing a Channel's read buffer allocations. This maintains
345 // a single contiguous buffer with the layout: 349 // a single contiguous buffer with the layout:
346 // 350 //
347 // [discarded bytes][occupied bytes][unoccupied bytes] 351 // [discarded bytes][occupied bytes][unoccupied bytes]
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 return true; 544 return true;
541 } 545 }
542 546
543 void Channel::OnError() { 547 void Channel::OnError() {
544 if (delegate_) 548 if (delegate_)
545 delegate_->OnChannelError(); 549 delegate_->OnChannelError();
546 } 550 }
547 551
548 } // namespace edk 552 } // namespace edk
549 } // namespace mojo 553 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_handle.cc ('k') | mojo/edk/system/node_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698