Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/win/scoped_process_information.h" | 5 #include "base/win/scoped_process_information.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/win/scoped_handle.h" | 8 #include "base/win/scoped_handle.h" |
| 9 #include "base/win/windows_version.h" | |
| 9 | 10 |
| 10 namespace base { | 11 namespace base { |
| 11 namespace win { | 12 namespace win { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Duplicates source into target, returning true upon success. |target| is | 16 // Duplicates source into target, returning true upon success. |target| is |
| 16 // guaranteed to be untouched in case of failure. Succeeds with no side-effects | 17 // guaranteed to be untouched in case of failure. Succeeds with no side-effects |
| 17 // if source is NULL. | 18 // if source is NULL. |
| 18 bool CheckAndDuplicateHandle(HANDLE source, ScopedHandle* target) { | 19 bool CheckAndDuplicateHandle(HANDLE source, ScopedHandle* target) { |
| 19 if (!source) | 20 if (!source) |
| 20 return true; | 21 return true; |
| 21 | 22 |
| 22 HANDLE temp = NULL; | 23 HANDLE temp = NULL; |
| 23 if (!::DuplicateHandle(::GetCurrentProcess(), source, | 24 |
| 24 ::GetCurrentProcess(), &temp, 0, FALSE, | 25 // TODO(shrikant): Remove following code as soon as we gather some |
| 25 DUPLICATE_SAME_ACCESS)) { | 26 // information regarding AppContainer related DuplicateHandle failures that |
| 26 DPLOG(ERROR) << "Failed to duplicate a handle."; | 27 // only seem to happen on certain machine and only random launches (normally |
| 27 return false; | 28 // renderer launches seem to succeed even on those machines.) |
| 29 if (base::win::GetVersion() == base::win::VERSION_WIN8 || | |
| 30 base::win::GetVersion() == base::win::VERSION_WIN8_1) { | |
| 31 typedef LONG NTSTATUS; | |
|
cpu_(ooo_6.6-7.5)
2015/04/24 02:39:56
just do LONG w/o typedef
Shrikant Kelkar
2015/04/24 18:31:26
Done.
| |
| 32 typedef NTSTATUS (WINAPI *NtDuplicateObject)( | |
| 33 IN HANDLE SourceProcess, | |
| 34 IN HANDLE SourceHandle, | |
| 35 IN HANDLE TargetProcess, | |
| 36 OUT PHANDLE TargetHandle, | |
| 37 IN ACCESS_MASK DesiredAccess, | |
| 38 IN ULONG Attributes, | |
| 39 IN ULONG Options); | |
| 40 | |
| 41 typedef ULONG (WINAPI *RtlNtStatusToDosError)(IN NTSTATUS Status); | |
| 42 | |
| 43 NtDuplicateObject nt_duplicate_object = | |
| 44 reinterpret_cast<NtDuplicateObject>(::GetProcAddress( | |
| 45 GetModuleHandle(L"ntdll.dll"), "NtDuplicateObject")); | |
| 46 if (nt_duplicate_object != NULL) { | |
| 47 NTSTATUS status = nt_duplicate_object(::GetCurrentProcess(), source, | |
| 48 ::GetCurrentProcess(), &temp, | |
| 49 0, FALSE, DUPLICATE_SAME_ACCESS); | |
| 50 if (status < 0) { | |
| 51 DPLOG(ERROR) << "Failed to duplicate a handle."; | |
| 52 RtlNtStatusToDosError ntstatus_to_doserror = | |
|
cpu_(ooo_6.6-7.5)
2015/04/24 02:39:56
do we need this? I don't where?
Shrikant Kelkar
2015/04/24 18:31:26
kernelbase::DuplicateHandle calls NtDupliateObject
| |
| 53 reinterpret_cast<RtlNtStatusToDosError>(::GetProcAddress( | |
| 54 GetModuleHandle(L"ntdll.dll"), "RtlNtStatusToDosError")); | |
| 55 if (ntstatus_to_doserror != NULL) { | |
| 56 ::SetLastError(ntstatus_to_doserror(status)); | |
| 57 } | |
| 58 return false; | |
| 59 } | |
| 60 } | |
| 61 } else { | |
| 62 if (!::DuplicateHandle(::GetCurrentProcess(), source, | |
| 63 ::GetCurrentProcess(), &temp, 0, FALSE, | |
| 64 DUPLICATE_SAME_ACCESS)) { | |
| 65 DPLOG(ERROR) << "Failed to duplicate a handle."; | |
| 66 return false; | |
| 67 } | |
| 28 } | 68 } |
| 29 target->Set(temp); | 69 target->Set(temp); |
| 30 return true; | 70 return true; |
| 31 } | 71 } |
| 32 | 72 |
| 33 } // namespace | 73 } // namespace |
| 34 | 74 |
| 35 ScopedProcessInformation::ScopedProcessInformation() | 75 ScopedProcessInformation::ScopedProcessInformation() |
| 36 : process_id_(0), thread_id_(0) { | 76 : process_id_(0), thread_id_(0) { |
| 37 } | 77 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 return process_handle_.Take(); | 139 return process_handle_.Take(); |
| 100 } | 140 } |
| 101 | 141 |
| 102 HANDLE ScopedProcessInformation::TakeThreadHandle() { | 142 HANDLE ScopedProcessInformation::TakeThreadHandle() { |
| 103 thread_id_ = 0; | 143 thread_id_ = 0; |
| 104 return thread_handle_.Take(); | 144 return thread_handle_.Take(); |
| 105 } | 145 } |
| 106 | 146 |
| 107 } // namespace win | 147 } // namespace win |
| 108 } // namespace base | 148 } // namespace base |
| OLD | NEW |