| 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 #include "mojo/edk/embedder/platform_handle.h" | 5 #include "mojo/edk/embedder/platform_handle.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #if defined(OS_POSIX) | 8 #if defined(OS_POSIX) |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #elif defined(OS_WIN) | 10 #elif defined(OS_WIN) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 handle = -1; | 29 handle = -1; |
| 30 } | 30 } |
| 31 #if defined(OS_MACOSX) && !defined(OS_IOS) | 31 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 32 else if (type == Type::MACH) { | 32 else if (type == Type::MACH) { |
| 33 kern_return_t rv = mach_port_deallocate(mach_task_self(), port); | 33 kern_return_t rv = mach_port_deallocate(mach_task_self(), port); |
| 34 DPCHECK(rv == KERN_SUCCESS); | 34 DPCHECK(rv == KERN_SUCCESS); |
| 35 port = MACH_PORT_NULL; | 35 port = MACH_PORT_NULL; |
| 36 } | 36 } |
| 37 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 37 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 38 #elif defined(OS_WIN) | 38 #elif defined(OS_WIN) |
| 39 if (owning_process != base::GetCurrentProcessHandle()) { |
| 40 // This handle may have been duplicated to a new target process but not yet |
| 41 // sent there. In this case CloseHandle should NOT be called. From MSDN |
| 42 // documentation for DuplicateHandle[1]: |
| 43 // |
| 44 // Normally the target process closes a duplicated handle when that |
| 45 // process is finished using the handle. To close a duplicated handle |
| 46 // from the source process, call DuplicateHandle with the following |
| 47 // parameters: |
| 48 // |
| 49 // * Set hSourceProcessHandle to the target process from the |
| 50 // call that created the handle. |
| 51 // * Set hSourceHandle to the duplicated handle to close. |
| 52 // * Set lpTargetHandle to NULL. |
| 53 // * Set dwOptions to DUPLICATE_CLOSE_SOURCE. |
| 54 // |
| 55 // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms724251 |
| 56 // |
| 57 // NOTE: It's possible for this operation to fail if the owning process |
| 58 // was terminated or is in the process of being terminated. Either way, |
| 59 // there is nothing we can reasonably do about failure, so we ignore it. |
| 60 DuplicateHandle(owning_process, handle, NULL, &handle, 0, FALSE, |
| 61 DUPLICATE_CLOSE_SOURCE); |
| 62 return; |
| 63 } |
| 64 |
| 39 bool success = !!CloseHandle(handle); | 65 bool success = !!CloseHandle(handle); |
| 40 DPCHECK(success); | 66 DPCHECK(success); |
| 41 handle = INVALID_HANDLE_VALUE; | 67 handle = INVALID_HANDLE_VALUE; |
| 42 #else | 68 #else |
| 43 #error "Platform not yet supported." | 69 #error "Platform not yet supported." |
| 44 #endif | 70 #endif |
| 45 } | 71 } |
| 46 | 72 |
| 47 } // namespace edk | 73 } // namespace edk |
| 48 } // namespace mojo | 74 } // namespace mojo |
| OLD | NEW |