Bug 1460433: Part 1 - Change BasicDllServices to not do any dll notification callbacks; r=mhowell
authorAaron Klotz <aklotz@mozilla.com>
Wed, 20 Feb 2019 06:18:45 +0000
changeset 518519 0291384ba66074fe5f4344becd87fecbe8c63942
parent 518518 bd5fbc5d0466775347935f0fd74858d5fb157299
child 518520 55d65fdac5ec324e821c68a79931f5743e019519
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1460433
milestone67.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 1460433: Part 1 - Change BasicDllServices to not do any dll notification callbacks; r=mhowell BasicDllServices is used to gain access to the authenticode APIs in non-Gecko contexts. One feature that WinDllServices provides is the ability to register a callback interface to be notified when a DLL has been loaded. This is not particularly useful in the BasicDllServices use case, and in the "handle a launcher process failure on a background thread" use case, would actually be harmful. This patch modifies the DLLServices backend to offer a "basic" option that omits the callback stuff. Differential Revision: https://phabricator.services.mozilla.com/D19696
js/xpconnect/src/XPCShellImpl.cpp
mozglue/build/WindowsDllBlocklist.cpp
mozglue/build/WindowsDllBlocklist.h
mozglue/build/WindowsDllServices.h
toolkit/xre/WinDllServices.cpp
toolkit/xre/nsAppRunner.cpp
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1316,17 +1316,17 @@ int XRE_XPCShellMain(int argc, char** ar
     BrowserTabsRemoteAutostart();
 #ifdef XP_WIN
     // Plugin may require audio session if installed plugin can initialize
     // asynchronized.
     AutoAudioSession audioSession;
 
     // Ensure that DLL Services are running
     RefPtr<DllServices> dllSvc(DllServices::Get());
-    auto dllServicesDisable = MakeScopeExit([&dllSvc]() { dllSvc->Disable(); });
+    auto dllServicesDisable = MakeScopeExit([&dllSvc]() { dllSvc->DisableFull(); });
 
 #  if defined(MOZ_SANDBOX)
     // Required for sandboxed child processes.
     if (aShellData->sandboxBrokerServices) {
       SandboxBroker::Initialize(aShellData->sandboxBrokerServices);
       SandboxBroker::GeckoDependentInitialize();
     } else {
       NS_WARNING(
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -989,17 +989,17 @@ static VOID CALLBACK DllLoadNotification
   PCUNICODE_STRING fullDllName = aNotificationData->Loaded.FullDllName;
   gDllServices->DispatchDllLoadNotification(fullDllName);
 }
 
 namespace mozilla {
 Authenticode* GetAuthenticode();
 }  // namespace mozilla
 
-MFBT_API void DllBlocklist_SetDllServices(
+MFBT_API void DllBlocklist_SetFullDllServices(
     mozilla::glue::detail::DllServicesBase* aSvc) {
   glue::AutoExclusiveLock lock(gDllServicesLock);
   if (aSvc) {
     aSvc->SetAuthenticodeImpl(GetAuthenticode());
 
     if (!gNotificationCookie) {
       auto pLdrRegisterDllNotification =
           reinterpret_cast<decltype(&::LdrRegisterDllNotification)>(
@@ -1018,8 +1018,17 @@ MFBT_API void DllBlocklist_SetDllService
 
   if (IsUntrustedDllsHandlerEnabled() && gDllServices) {
     Vector<glue::ModuleLoadEvent, 0, InfallibleAllocPolicy> events;
     if (glue::UntrustedDllsHandler::TakePendingEvents(events)) {
       gDllServices->NotifyUntrustedModuleLoads(events);
     }
   }
 }
+
+MFBT_API void DllBlocklist_SetBasicDllServices(
+    mozilla::glue::detail::DllServicesBase* aSvc) {
+  if (!aSvc) {
+    return;
+  }
+
+  aSvc->SetAuthenticodeImpl(GetAuthenticode());
+}
--- a/mozglue/build/WindowsDllBlocklist.h
+++ b/mozglue/build/WindowsDllBlocklist.h
@@ -49,13 +49,15 @@ MFBT_API const char* DllBlocklist_TestBl
 namespace mozilla {
 namespace glue {
 namespace detail {
 class DllServicesBase;
 }  // namespace detail
 }  // namespace glue
 }  // namespace mozilla
 
-MFBT_API void DllBlocklist_SetDllServices(
+MFBT_API void DllBlocklist_SetFullDllServices(
+    mozilla::glue::detail::DllServicesBase* aSvc);
+MFBT_API void DllBlocklist_SetBasicDllServices(
     mozilla::glue::detail::DllServicesBase* aSvc);
 
 #endif  // defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
 #endif  // mozilla_windowsdllblocklist_h
--- a/mozglue/build/WindowsDllServices.h
+++ b/mozglue/build/WindowsDllServices.h
@@ -105,29 +105,30 @@ class DllServicesBase : public Authentic
   {
     if (!mAuthenticode) {
       return nullptr;
     }
 
     return mAuthenticode->GetBinaryOrgName(aFilePath);
   }
 
-  void Disable() { DllBlocklist_SetDllServices(nullptr); }
+  void DisableFull() { DllBlocklist_SetFullDllServices(nullptr); }
 
   DllServicesBase(const DllServicesBase&) = delete;
   DllServicesBase(DllServicesBase&&) = delete;
   DllServicesBase& operator=(const DllServicesBase&) = delete;
   DllServicesBase& operator=(DllServicesBase&&) = delete;
 
  protected:
   DllServicesBase() : mAuthenticode(nullptr) {}
 
   virtual ~DllServicesBase() = default;
 
-  void Enable() { DllBlocklist_SetDllServices(this); }
+  void EnableFull() { DllBlocklist_SetFullDllServices(this); }
+  void EnableBasic() { DllBlocklist_SetBasicDllServices(this); }
 
  private:
   Authenticode* mAuthenticode;
 };
 
 }  // namespace detail
 
 #if defined(MOZILLA_INTERNAL_API)
@@ -161,24 +162,27 @@ class DllServices : public detail::DllSe
   ~DllServices() = default;
 
   virtual void NotifyDllLoad(const bool aIsMainThread,
                              const nsString& aDllName) = 0;
 };
 
 #else
 
-class BasicDllServices : public detail::DllServicesBase {
+class BasicDllServices final : public detail::DllServicesBase {
  public:
-  BasicDllServices() { Enable(); }
+  BasicDllServices() {
+    EnableBasic();
+  }
 
-  ~BasicDllServices() { Disable(); }
+  ~BasicDllServices() = default;
 
-  virtual void DispatchDllLoadNotification(PCUNICODE_STRING aDllName) override {
-  }
+  // Not useful in this class, so provide a default implementation
+  virtual void DispatchDllLoadNotification(PCUNICODE_STRING aDllName) override
+      {}
 
   virtual void NotifyUntrustedModuleLoads(
       const Vector<glue::ModuleLoadEvent, 0, InfallibleAllocPolicy>& aEvents)
       override {}
 };
 
 #endif  // defined(MOZILLA_INTERNAL_API)
 
--- a/toolkit/xre/WinDllServices.cpp
+++ b/toolkit/xre/WinDllServices.cpp
@@ -391,20 +391,20 @@ static StaticRefPtr<DllServices> sInstan
 DllServices* DllServices::Get() {
   if (sDllServicesHasBeenSet) {
     return sInstance;
   }
 
   sInstance = new DllServices();
   sDllServicesHasBeenSet = true;
 
-  // Enable() winds up calling NotifyUntrustedModuleLoads which requires
-  // sInstance to be valid. So we must call Enable() here rather than the
+  // EnableFull() winds up calling NotifyUntrustedModuleLoads which requires
+  // sInstance to be valid. So we must call EnableFull() here rather than the
   // DllServices constructor.
-  sInstance->Enable();
+  sInstance->EnableFull();
   ClearOnShutdown(&sInstance);
   return sInstance;
 }
 
 DllServices::DllServices()
     : mUntrustedModulesManager(new UntrustedModulesManager()) {}
 
 bool DllServices::GetUntrustedModuleTelemetryData(
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4384,17 +4384,17 @@ void AddSandboxAnnotations() {
  */
 nsresult XREMain::XRE_mainRun() {
   nsresult rv = NS_OK;
   NS_ASSERTION(mScopedXPCOM, "Scoped xpcom not initialized.");
 
 #if defined(XP_WIN)
   RefPtr<mozilla::DllServices> dllServices(mozilla::DllServices::Get());
   auto dllServicesDisable =
-      MakeScopeExit([&dllServices]() { dllServices->Disable(); });
+      MakeScopeExit([&dllServices]() { dllServices->DisableFull(); });
 #endif  // defined(XP_WIN)
 
 #ifdef NS_FUNCTION_TIMER
   // initialize some common services, so we don't pay the cost for these at odd
   // times later on; SetWindowCreator -> ChromeRegistry -> IOService ->
   // SocketTransportService -> (nspr wspm init), Prefs
   {
     nsCOMPtr<nsISupports> comp;