OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/app/close_handle_hook_win.h" | 5 #include "chrome/app/close_handle_hook_win.h" |
6 | 6 |
7 #include <Windows.h> | 7 #include <Windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/win/iat_patch_function.h" | 14 #include "base/win/iat_patch_function.h" |
15 #include "base/win/pe_image.h" | 15 #include "base/win/pe_image.h" |
16 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/channel_info.h" |
| 18 #include "components/version_info/version_info.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); | 22 typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); |
22 CloseHandleType g_close_function = NULL; | 23 CloseHandleType g_close_function = NULL; |
23 | 24 |
24 // The entry point for CloseHandle interception. This function notifies the | 25 // The entry point for CloseHandle interception. This function notifies the |
25 // verifier about the handle that is being closed, and calls the original | 26 // verifier about the handle that is being closed, and calls the original |
26 // function. | 27 // function. |
27 BOOL WINAPI CloseHandleHook(HANDLE handle) { | 28 BOOL WINAPI CloseHandleHook(HANDLE handle) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 it != hooks_.end(); ++it) { | 178 it != hooks_.end(); ++it) { |
178 (*it)->Unpatch(); | 179 (*it)->Unpatch(); |
179 delete *it; | 180 delete *it; |
180 } | 181 } |
181 } | 182 } |
182 | 183 |
183 bool UseHooks() { | 184 bool UseHooks() { |
184 #if defined(ARCH_CPU_X86_64) | 185 #if defined(ARCH_CPU_X86_64) |
185 return false; | 186 return false; |
186 #elif defined(NDEBUG) | 187 #elif defined(NDEBUG) |
187 version_info::Channel channel = chrome::VersionInfo::GetChannel(); | 188 version_info::Channel channel = chrome::GetChannel(); |
188 if (channel == version_info::Channel::CANARY || | 189 if (channel == version_info::Channel::CANARY || |
189 channel == version_info::Channel::DEV || | 190 channel == version_info::Channel::DEV || |
190 channel == version_info::Channel::UNKNOWN) { | 191 channel == version_info::Channel::UNKNOWN) { |
191 return true; | 192 return true; |
192 } | 193 } |
193 | 194 |
194 return false; | 195 return false; |
195 #else // NDEBUG | 196 #else // NDEBUG |
196 return true; | 197 return true; |
197 #endif | 198 #endif |
(...skipping 25 matching lines...) Expand all Loading... |
223 // threads attempting to call CloseHandle. | 224 // threads attempting to call CloseHandle. |
224 hooks->AddEATPatch(); | 225 hooks->AddEATPatch(); |
225 PatchLoadedModules(hooks); | 226 PatchLoadedModules(hooks); |
226 } | 227 } |
227 } | 228 } |
228 | 229 |
229 void RemoveCloseHandleHooks() { | 230 void RemoveCloseHandleHooks() { |
230 // We are partching all loaded modules without forcing them to stay in memory, | 231 // We are partching all loaded modules without forcing them to stay in memory, |
231 // removing patches is not safe. | 232 // removing patches is not safe. |
232 } | 233 } |
OLD | NEW |