Bug 1322554: don't hook BaseThreadInitThunk if WRusr.dll is present on Windows x86; r?dmajor draft
authorCarl Corcoran <carlco@gmail.com>
Mon, 15 May 2017 15:19:31 +0200
changeset 580147 b86738155f66
parent 577978 ee7acd115195
child 629192 b63ee1a985ef
push id59454
push userbmo:ccorcoran@mozilla.com
push dateThu, 18 May 2017 06:47:10 +0000
reviewersdmajor
bugs1322554
milestone55.0a1
Bug 1322554: don't hook BaseThreadInitThunk if WRusr.dll is present on Windows x86; r?dmajor MozReview-Commit-ID: DHIwyNx5zNq
mozglue/build/WindowsDllBlocklist.cpp
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -753,16 +753,26 @@ ShouldBlockThread(void* aStartAddress)
 
 // Allows blocked threads to still run normally through BaseThreadInitThunk, in case there's any magic there that we shouldn't skip.
 static DWORD WINAPI
 NopThreadProc(void* /* aThreadParam */)
 {
   return 0;
 }
 
+static bool
+ShouldHookBaseThreadInitThunk()
+{
+#ifdef HAVE_64BIT_BUILD
+  return false;
+#endif
+  // Bug 1361410: WRusr.dll will overwrite our hook and cause a crash. Workaround: If we detect WRusr.dll, don't hook.
+  return (NULL == GetModuleHandleW(L"WRusr.dll"));
+}
+
 static MOZ_NORETURN void __fastcall
 patched_BaseThreadInitThunk(BOOL aIsInitialThread, void* aStartAddress,
                             void* aThreadParam)
 {
   if (ShouldBlockThread(aStartAddress)) {
     aStartAddress = NopThreadProc;
   }
 
@@ -804,23 +814,26 @@ DllBlocklist_Initialize(uint32_t aInitFl
   if (!ok) {
     sBlocklistInitFailed = true;
 #ifdef DEBUG
     printf_stderr("LdrLoadDll hook failed, no dll blocklisting active\n");
 #endif
   }
 
   Kernel32DllIntercept.Init("kernel32.dll");
-  ok = Kernel32DllIntercept.AddHook("BaseThreadInitThunk",
-                                    reinterpret_cast<intptr_t>(patched_BaseThreadInitThunk),
-                                    (void**) &stub_BaseThreadInitThunk);
-  if (!ok) {
+
+  if (ShouldHookBaseThreadInitThunk()) {
+    ok = Kernel32DllIntercept.AddHook("BaseThreadInitThunk",
+                                      reinterpret_cast<intptr_t>(patched_BaseThreadInitThunk),
+                                      (void**) &stub_BaseThreadInitThunk);
+    if (!ok) {
 #ifdef DEBUG
-    printf_stderr("BaseThreadInitThunk hook failed\n");
+      printf_stderr("BaseThreadInitThunk hook failed\n");
 #endif
+    }
   }
 }
 
 MFBT_API void
 DllBlocklist_WriteNotes(HANDLE file)
 {
   DWORD nBytes;