Bug 1382251: Part 4 - Init/Shutdown parts of XPCOM needed in plugin process r=erahm
☠☠ backed out by 398fb8533bcb ☠ ☠
authorDavid Parks <dparks@mozilla.com>
Mon, 06 Nov 2017 10:10:43 -0800
changeset 454121 0d82d0b69c9e62cc4923e361b1ac468674d6b7cb
parent 454120 24de376fb860c10fe5a0e47ba89786a8015c7c00
child 454122 37cad137215fa5ef9febbeb9401ff35269a769ab
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1382251
milestone59.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 1382251: Part 4 - Init/Shutdown parts of XPCOM needed in plugin process r=erahm We have not been initializing or shutting down XPCOM in the plugin process. We need the nsThreadManager for this bug but, more importantly, we need to properly shut down XPCOM in order to get things like handlers connected to the ShutdownPhases (e.g. ClearOnShutdown, used to free resources at process end). This patch includes some work to make services that are uninitialized in the plugin process to handle Shutdown calls without failing.
dom/plugins/ipc/PluginProcessChild.cpp
--- a/dom/plugins/ipc/PluginProcessChild.cpp
+++ b/dom/plugins/ipc/PluginProcessChild.cpp
@@ -7,16 +7,18 @@
 #include "mozilla/ipc/IOThreadChild.h"
 #include "mozilla/plugins/PluginProcessChild.h"
 
 #include "prlink.h"
 
 #include "base/command_line.h"
 #include "base/string_util.h"
 #include "nsDebugImpl.h"
+#include "nsThreadManager.h"
+#include "ClearOnShutdown.h"
 
 #if defined(XP_MACOSX)
 #include "nsCocoaFeatures.h"
 // An undocumented CoreGraphics framework method, present in the same form
 // since at least OS X 10.5.
 extern "C" CGError CGSSetDebugOptions(int options);
 #endif
 
@@ -101,16 +103,24 @@ PluginProcessChild::Init(int aArgc, char
 
     if (ShouldProtectPluginCurrentDirectory(values[0].c_str())) {
         SanitizeEnvironmentVariables();
         SetDllDirectory(L"");
     }
 
     pluginFilename = WideToUTF8(values[0]);
 
+    // We don't initialize XPCOM but we need the thread manager and the
+    // logging framework for the FunctionBroker.
+    NS_SetMainThread();
+    mozilla::TimeStamp::Startup();
+    NS_LogInit();
+    mozilla::LogModule::Init();
+    nsThreadManager::get().Init();
+
 #if defined(MOZ_SANDBOX)
     // This is probably the earliest we would want to start the sandbox.
     // As we attempt to tighten the sandbox, we may need to consider moving this
     // to later in the plugin initialization.
     mozilla::SandboxTarget::Instance()->StartSandbox();
 #endif
 #else
 #  error Sorry
@@ -136,13 +146,25 @@ PluginProcessChild::Init(int aArgc, char
     }
 #endif
     return retval;
 }
 
 void
 PluginProcessChild::CleanUp()
 {
+#if defined(OS_WIN)
+    MOZ_ASSERT(NS_IsMainThread());
+
+    // Shutdown components we started in Init.  Note that KillClearOnShutdown
+    // is an event that is regularly part of XPCOM shutdown.  We do not
+    // call XPCOM's shutdown but we need this event to be sent to avoid
+    // leaking objects labeled as ClearOnShutdown.
+    nsThreadManager::get().Shutdown();
+    mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownFinal);
+    NS_LogTerm();
+#endif
+
     nsRegion::ShutdownStatic();
 }
 
 } // namespace plugins
 } // namespace mozilla