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.
5 #include "chrome_frame/pin_module.h"
9 #include "base/logging.h"
10 #include "chrome_frame/utils.h"
12 extern "C" IMAGE_DOS_HEADER __ImageBase
;
14 namespace chrome_frame
{
18 PinModuleCallbackFn g_pin_module_callback
= NULL
;
22 void SetPinModuleCallback(PinModuleCallbackFn callback
) {
23 g_pin_module_callback
= callback
;
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
);
32 if (GetModuleFileName(this_module
, system_buffer
,
33 arraysize(system_buffer
)) != 0) {
35 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN
, system_buffer
,
37 DPLOG(FATAL
) << "Failed to pin module " << system_buffer
;
40 if (g_pin_module_callback
)
41 g_pin_module_callback();
44 DPLOG(FATAL
) << "Could not get module path.";
49 } // namespace chrome_frame