Bug 1485487: Add an assertion to ensure that DllServices::GetBinaryOrgName is not called on the Gecko main thread; r=mhowell
authorAaron Klotz <aklotz@mozilla.com>
Wed, 22 Aug 2018 15:23:04 -0600
changeset 488055 17626f41c0e5bf764b7021f240787bee47d2c393
parent 488054 8c43fcd785b9561d85983d1a4deeee16f8c40887
child 488056 bb407121dfdedbea6672e59419ad74d1b436ab71
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1485487
milestone63.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 1485487: Add an assertion to ensure that DllServices::GetBinaryOrgName is not called on the Gecko main thread; r=mhowell
mozglue/build/WindowsDllServices.h
--- a/mozglue/build/WindowsDllServices.h
+++ b/mozglue/build/WindowsDllServices.h
@@ -2,21 +2,23 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_glue_WindowsDllServices_h
 #define mozilla_glue_WindowsDllServices_h
 
+#include "mozilla/Assertions.h"
 #include "mozilla/Authenticode.h"
 #include "mozilla/WindowsDllBlocklist.h"
 
 #if defined(MOZILLA_INTERNAL_API)
 
+#include "MainThreadUtils.h"
 #include "mozilla/SystemGroup.h"
 #include "nsISupportsImpl.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 
 #endif // defined(MOZILLA_INTERNAL_API)
 
 // For PCUNICODE_STRING
@@ -37,17 +39,24 @@ public:
    */
   virtual void DispatchDllLoadNotification(PCUNICODE_STRING aDllName) = 0;
 
   void SetAuthenticodeImpl(Authenticode* aAuthenticode)
   {
     mAuthenticode = aAuthenticode;
   }
 
+  // In debug builds, we override GetBinaryOrgName to add a Gecko-specific
+  // assertion. OTOH, we normally do not want people overriding this function,
+  // so we'll make it final in the release case, thus covering all bases.
+#if defined(DEBUG)
+  UniquePtr<wchar_t[]> GetBinaryOrgName(const wchar_t* aFilePath) override
+#else
   UniquePtr<wchar_t[]> GetBinaryOrgName(const wchar_t* aFilePath) final
+#endif // defined(DEBUG)
   {
     if (!mAuthenticode) {
       return nullptr;
     }
 
     return mAuthenticode->GetBinaryOrgName(aFilePath);
   }
 
@@ -93,16 +102,26 @@ public:
     nsCOMPtr<nsIRunnable> runnable(
       NewRunnableMethod<bool, nsString>("DllServices::NotifyDllLoad",
                                         this, &DllServices::NotifyDllLoad,
                                         NS_IsMainThread(), strDllName));
 
     SystemGroup::Dispatch(TaskCategory::Other, runnable.forget());
   }
 
+#if defined(DEBUG)
+  UniquePtr<wchar_t[]> GetBinaryOrgName(const wchar_t* aFilePath) final
+  {
+    // This function may perform disk I/O, so we should never call it on the
+    // main thread.
+    MOZ_ASSERT(!NS_IsMainThread());
+    return detail::DllServicesBase::GetBinaryOrgName(aFilePath);
+  }
+#endif // defined(DEBUG)
+
   NS_INLINE_DECL_THREADSAFE_VIRTUAL_REFCOUNTING(DllServices)
 
 protected:
   DllServices() = default;
   ~DllServices() = default;
 
   virtual void NotifyDllLoad(const bool aIsMainThread, const nsString& aDllName) = 0;
 };