Bug 1723868 - Skip msvp9dec_store.dll in GetInfoForSelf(). r=gerald, a=RyanVM
authorToshihito Kikuchi <tkikuchi@mozilla.com>
Thu, 05 Aug 2021 02:36:27 +0000
changeset 656997 38acd685ea4cd57e189b63af3b55c21049d46cd2
parent 656996 272617a59467a26ac4033a21d55991b834ba464e
child 656998 e6ead7489f31347c82461ada7e0618d1652f4d9c
push id26
push userryanvm@gmail.com
push dateThu, 12 Aug 2021 20:27:27 +0000
treeherdermozilla-esr91@fd34cd0543a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, RyanVM
bugs1723868
milestone91.1.0
Bug 1723868 - Skip msvp9dec_store.dll in GetInfoForSelf(). r=gerald, a=RyanVM When mfplat.dll loads msvp9dec_store.dll, it posts a task to unload the module to the work queue even if msvp9dec_store.dll is already loaded and mfplat.dll skips LoadLibrary. Therefore, we cannot safely lock msvp9dec_store.dll by loading it as data. The proposed fix is to skip processing the module. Differential Revision: https://phabricator.services.mozilla.com/D121777
mozglue/baseprofiler/core/shared-libraries-win32.cc
tools/profiler/core/shared-libraries-win32.cc
--- a/mozglue/baseprofiler/core/shared-libraries-win32.cc
+++ b/mozglue/baseprofiler/core/shared-libraries-win32.cc
@@ -43,41 +43,56 @@ static void AppendHex(T aValue, std::str
       // Requested no padding, got first non-zero, pretend we now want padding
       // so we don't skip zeroes anymore.
       aWithPadding = true;
     }
     aOut += digits[nibble];
   }
 }
 
-// Hackaround for Bug 1607574.  Nvidia's shim driver nvd3d9wrap[x].dll detours
-// LoadLibraryExW and it causes AV when the following conditions are met.
-//   1. LoadLibraryExW was called for "detoured.dll"
-//   2. nvinit[x].dll was unloaded
-//   3. OS version is older than 6.2
 static bool IsModuleUnsafeToLoad(const std::string& aModuleName) {
-#if defined(_M_ARM64)
-  return false;
-#else
+  auto LowerCaseEqualsLiteral = [](char aModuleChar, char aDetouredChar) {
+    return std::tolower(aModuleChar) == aDetouredChar;
+  };
+
+#if defined(_M_AMD64) || defined(_M_IX86)
+  // Hackaround for Bug 1607574.  Nvidia's shim driver nvd3d9wrap[x].dll detours
+  // LoadLibraryExW and it causes AV when the following conditions are met.
+  //   1. LoadLibraryExW was called for "detoured.dll"
+  //   2. nvinit[x].dll was unloaded
+  //   3. OS version is older than 6.2
 #  if defined(_M_AMD64)
   LPCWSTR kNvidiaShimDriver = L"nvd3d9wrapx.dll";
   LPCWSTR kNvidiaInitDriver = L"nvinitx.dll";
 #  elif defined(_M_IX86)
   LPCWSTR kNvidiaShimDriver = L"nvd3d9wrap.dll";
   LPCWSTR kNvidiaInitDriver = L"nvinit.dll";
 #  endif
   constexpr std::string_view detoured_dll = "detoured.dll";
-  return std::equal(aModuleName.cbegin(), aModuleName.cend(),
-                    detoured_dll.cbegin(), detoured_dll.cend(),
-                    [](char aModuleChar, char aDetouredChar) {
-                      return std::tolower(aModuleChar) == aDetouredChar;
-                    }) &&
-         !mozilla::IsWin8OrLater() && ::GetModuleHandleW(kNvidiaShimDriver) &&
-         !::GetModuleHandleW(kNvidiaInitDriver);
-#endif  // defined(_M_ARM64)
+  if (std::equal(aModuleName.cbegin(), aModuleName.cend(),
+                 detoured_dll.cbegin(), detoured_dll.cend(),
+                 LowerCaseEqualsLiteral) &&
+      !mozilla::IsWin8OrLater() && ::GetModuleHandleW(kNvidiaShimDriver) &&
+      !::GetModuleHandleW(kNvidiaInitDriver)) {
+    return true;
+  }
+#endif  // defined(_M_AMD64) || defined(_M_IX86)
+
+  // Hackaround for Bug 1723868.  There is no safe way to prevent the module
+  // Microsoft's VP9 Video Decoder from being unloaded because mfplat.dll may
+  // have posted more than one task to unload the module in the work queue
+  // without calling LoadLibrary.
+  constexpr std::string_view vp9_decoder_dll = "msvp9dec_store.dll";
+  if (std::equal(aModuleName.cbegin(), aModuleName.cend(),
+                 vp9_decoder_dll.cbegin(), vp9_decoder_dll.cend(),
+                 LowerCaseEqualsLiteral)) {
+    return true;
+  }
+
+  return false;
 }
 
 SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
   SharedLibraryInfo sharedLibraryInfo;
 
   auto addSharedLibraryFromModuleInfo =
       [&sharedLibraryInfo](const wchar_t* aModulePath, HMODULE aModule) {
         mozilla::UniquePtr<char[]> utf8ModulePath(
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/tools/profiler/core/shared-libraries-win32.cc
@@ -8,36 +8,46 @@
 #include "shared-libraries.h"
 #include "nsWindowsHelpers.h"
 #include "mozilla/NativeNt.h"
 #include "mozilla/WindowsEnumProcessModules.h"
 #include "mozilla/WindowsProcessMitigations.h"
 #include "mozilla/WindowsVersion.h"
 #include "nsPrintfCString.h"
 
-// Hackaround for Bug 1607574.  Nvidia's shim driver nvd3d9wrap[x].dll detours
-// LoadLibraryExW and it causes AV when the following conditions are met.
-//   1. LoadLibraryExW was called for "detoured.dll"
-//   2. nvinit[x].dll was unloaded
-//   3. OS version is older than 6.2
 static bool IsModuleUnsafeToLoad(const nsAString& aModuleName) {
-#if defined(_M_ARM64)
-  return false;
-#else
+#if defined(_M_AMD64) || defined(_M_IX86)
+  // Hackaround for Bug 1607574.  Nvidia's shim driver nvd3d9wrap[x].dll detours
+  // LoadLibraryExW and it causes AV when the following conditions are met.
+  //   1. LoadLibraryExW was called for "detoured.dll"
+  //   2. nvinit[x].dll was unloaded
+  //   3. OS version is older than 6.2
 #  if defined(_M_AMD64)
   LPCWSTR kNvidiaShimDriver = L"nvd3d9wrapx.dll";
   LPCWSTR kNvidiaInitDriver = L"nvinitx.dll";
 #  elif defined(_M_IX86)
   LPCWSTR kNvidiaShimDriver = L"nvd3d9wrap.dll";
   LPCWSTR kNvidiaInitDriver = L"nvinit.dll";
 #  endif
-  return aModuleName.LowerCaseEqualsLiteral("detoured.dll") &&
-         !mozilla::IsWin8OrLater() && ::GetModuleHandleW(kNvidiaShimDriver) &&
-         !::GetModuleHandleW(kNvidiaInitDriver);
-#endif  // defined(_M_ARM64)
+  if (aModuleName.LowerCaseEqualsLiteral("detoured.dll") &&
+      !mozilla::IsWin8OrLater() && ::GetModuleHandleW(kNvidiaShimDriver) &&
+      !::GetModuleHandleW(kNvidiaInitDriver)) {
+    return true;
+  }
+#endif  // defined(_M_AMD64) || defined(_M_IX86)
+
+  // Hackaround for Bug 1723868.  There is no safe way to prevent the module
+  // Microsoft's VP9 Video Decoder from being unloaded because mfplat.dll may
+  // have posted more than one task to unload the module in the work queue
+  // without calling LoadLibrary.
+  if (aModuleName.LowerCaseEqualsLiteral("msvp9dec_store.dll")) {
+    return true;
+  }
+
+  return false;
 }
 
 SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
   SharedLibraryInfo sharedLibraryInfo;
 
   auto addSharedLibraryFromModuleInfo = [&sharedLibraryInfo](
                                             const wchar_t* aModulePath,
                                             HMODULE aModule) {