Bug 1723868 - Skip msvp9dec_store.dll in GetInfoForSelf(). r=gerald
authorToshihito Kikuchi <tkikuchi@mozilla.com>
Thu, 05 Aug 2021 02:36:27 +0000
changeset 587865 168c68c7f7e351970e3820a725feafb26d13d072
parent 587864 8b81c3399a9ca1d3736d28637d23ae56a992b6c0
child 587866 14dd483e27af9a55dc8ff7bcea37b52de6e55e59
push id147513
push usertkikuchi@mozilla.com
push dateThu, 05 Aug 2021 02:38:50 +0000
treeherderautoland@168c68c7f7e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1723868
milestone92.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 1723868 - Skip msvp9dec_store.dll in GetInfoForSelf(). r=gerald 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) {