OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome_frame/pin_module.h" | |
6 | |
7 #include <windows.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "chrome_frame/utils.h" | |
11 | |
12 extern "C" IMAGE_DOS_HEADER __ImageBase; | |
13 | |
14 namespace chrome_frame { | |
15 | |
16 namespace { | |
17 | |
18 PinModuleCallbackFn g_pin_module_callback = NULL; | |
19 | |
20 } // namespace | |
21 | |
22 void SetPinModuleCallback(PinModuleCallbackFn callback) { | |
23 g_pin_module_callback = callback; | |
24 } | |
25 | |
26 void PinModule() { | |
27 static bool s_pinned = false; | |
28 if (!s_pinned && !IsUnpinnedMode()) { | |
29 wchar_t system_buffer[MAX_PATH]; | |
30 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); | |
31 system_buffer[0] = 0; | |
32 if (GetModuleFileName(this_module, system_buffer, | |
33 arraysize(system_buffer)) != 0) { | |
34 HMODULE unused; | |
35 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, system_buffer, | |
36 &unused)) { | |
37 DPLOG(FATAL) << "Failed to pin module " << system_buffer; | |
38 } else { | |
39 s_pinned = true; | |
40 if (g_pin_module_callback) | |
41 g_pin_module_callback(); | |
42 } | |
43 } else { | |
44 DPLOG(FATAL) << "Could not get module path."; | |
45 } | |
46 } | |
47 } | |
48 | |
49 } // namespace chrome_frame | |
OLD | NEW |