Bug 1382251: Part 4 - Init/Shutdown parts of XPCOM needed in plugin process r=erahm
☠☠ backed out by 6159c8eb5442 ☠ ☠
authorDavid Parks <dparks@mozilla.com>
Mon, 06 Nov 2017 10:10:43 -0800
changeset 453106 e8262c37dfaca6409a2df0bc5146efbb331c73a2
parent 453105 5dc95b140fd75283c58a86793791759b98550937
child 453107 e6056433a119d8342d416826930bfcdf2f4c5d88
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.
+    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,23 @@ PluginProcessChild::Init(int aArgc, char
     }
 #endif
     return retval;
 }
 
 void
 PluginProcessChild::CleanUp()
 {
+    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();
+
     nsRegion::ShutdownStatic();
 }
 
 } // namespace plugins
 } // namespace mozilla