Bug 1489391: Part 1 - Use 10-byte patch in DLL interceptor for CloseHandle on Win8/8.1 r=aklotz
authorDavid Parks <daparks@mozilla.com>
Thu, 05 Dec 2019 00:41:23 +0000
changeset 505576 bdffefea6e9afbb321c09b953c1153a459b91976
parent 505575 ba237def08d57263dda0232d34526ee3b3b265ca
child 505577 33fef95ff8cfbbccb4d4924323f2f4d32b61ed73
push id102352
push userdaparks@mozilla.com
push dateThu, 05 Dec 2019 02:39:42 +0000
treeherderautoland@33fef95ff8cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1489391
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1489391: Part 1 - Use 10-byte patch in DLL interceptor for CloseHandle on Win8/8.1 r=aklotz CloseHandle has a jump followed by enough `nop`s to fit a 10-byte patch but not enough to fit the default 13-byte patch when running Windows 8 or 8.1. This patch tells the interceptor to use a 10-byte patch on those OSs. Differential Revision: https://phabricator.services.mozilla.com/D55535
mozglue/misc/nsWindowsDllInterceptor.h
--- a/mozglue/misc/nsWindowsDllInterceptor.h
+++ b/mozglue/misc/nsWindowsDllInterceptor.h
@@ -411,19 +411,28 @@ class WindowsDllInterceptor final
   }
 
   bool AddDetour(FARPROC aProc, intptr_t aHookDest, void** aOrigFunc) {
     MOZ_ASSERT(mModule && aProc);
 
     if (!mDetourPatcher.Initialized()) {
       DetourFlags flags = DetourFlags::eDefault;
 #if defined(_M_X64)
-      if (mModule == ::GetModuleHandleW(L"ntdll.dll")) {
-        // NTDLL hooks should attempt to use a 10-byte patch because some
-        // injected DLLs do the same and interfere with our stuff.
+      // NTDLL hooks should attempt to use a 10-byte patch because some
+      // injected DLLs do the same and interfere with our stuff.
+      bool needs10BytePatch = (mModule == ::GetModuleHandleW(L"ntdll.dll"));
+
+      // CloseHandle on Windows 8 only accomodates 10-byte patches.
+      bool isWin8Or81 = IsWin8OrLater() && (!IsWin10OrLater());
+      needs10BytePatch |= isWin8Or81 &&
+                          (mModule == ::GetModuleHandleW(L"kernel32.dll")) &&
+                          (reinterpret_cast<void*>(aProc) ==
+                           reinterpret_cast<void*>(&CloseHandle));
+
+      if (needs10BytePatch) {
         flags |= DetourFlags::eEnable10BytePatch;
       }
 #endif  // defined(_M_X64)
 
       mDetourPatcher.Init(flags);
     }
 
     return mDetourPatcher.AddHook(aProc, aHookDest, aOrigFunc);