Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: base/win/delay_load_hook.cc

Issue 12295040: Stop delay loading user32.dll from chrome.dll on x86/Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build config sketch, mostly works for x86 and x64. Move the hook back to base." Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/win/delay_load_hook.cc
diff --git a/base/win/delay_load_hook.cc b/base/win/delay_load_hook.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6050405a12011832848da4850c7d35a4d83b0c50
--- /dev/null
+++ b/base/win/delay_load_hook.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/win/delay_load_hook.h"
+
+#if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700
+// The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h, and in
+// delayimp.h previous to VS2012.
+#undef FACILITY_VISUALCPP
+#endif
+#include <DelayIMP.h>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+
+// So long as these symbols are supplied to the final binary through an
+// object file (as opposed to indirectly thruogh a library), these pointers
+// will override the CRT's symbols and direct the notifications to our hook.
+PfnDliHook __pfnDliNotifyHook2 = base::win::DelayLoadHook;
+PfnDliHook __pfnDliFailureHook2 = base::win::DelayLoadHook;
+
+
+namespace base {
+namespace win {
+
+namespace {
+
+FARPROC OnPreLoadLibrary(DelayLoadInfo* info) {
+ // If the DLL name ends with "-delay.dll", this call is about one of our
+ // custom import libraries. In this case we need to snip the suffix off,
+ // and bind to the real DLL.
+ std::string dll_name(info->szDll);
+ const char kDelaySuffix[] = "-delay.dll";
cpu_(ooo_6.6-7.5) 2013/03/04 02:18:53 any way to see if we get 8dot3 ~1 madness here? A
Sigurður Ásgeirsson 2013/03/25 20:43:29 You'll get whatever you put into the binary here,
+ if (EndsWith(dll_name, kDelaySuffix, false)) {
+ // Trim the "-delay.dll" suffix from the string.
+ dll_name.resize(dll_name.length() - (sizeof(kDelaySuffix) - 1));
+ dll_name.append(".dll");
+
+ HMODULE dll = ::LoadLibraryA(dll_name.c_str());
+
+ return reinterpret_cast<FARPROC>(dll);
+ }
+
+ return NULL;
+}
+
+} // namespace
+
+FARPROC WINAPI DelayLoadHook(unsigned reason, DelayLoadInfo* info) {
+ switch (reason) {
+ case dliNoteStartProcessing:
+ // Nothing to do here.
+ break;
+
+ case dliNotePreLoadLibrary:
+ return OnPreLoadLibrary(info);
+ break;
+
+ case dliNotePreGetProcAddress:
+ case dliFailLoadLib:
+ case dliFailGetProc:
+ case dliNoteEndProcessing:
+ // Nothing to do here.
cpu_(ooo_6.6-7.5) 2013/03/04 02:18:53 How about this here? // By returning NULL the del
Sigurður Ásgeirsson 2013/03/25 20:43:29 Done.
+ break;
+
+ default:
+ NOTREACHED() << "Impossible delay load notification.";
+ break;
+ }
+
+ return NULL;
+}
+
+} // namespace win
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698