Bug 1546158: Add option to mscom::EnsureMTA to forcibly dispatch events to its thread; r=Jamie
authorAaron Klotz <aklotz@mozilla.com>
Tue, 23 Apr 2019 02:17:17 +0000
changeset 470435 3e3a2ecafdaafb3ef75009b7662be7e84451d70b
parent 470434 831918f009f63596fde1e532cc0f026d2e53cf78
child 470436 6f0320a8555580db1b9c8cc7e2c7452b30bc157b
push id35906
push useraciure@mozilla.com
push dateTue, 23 Apr 2019 22:14:56 +0000
treeherdermozilla-central@0ce3633f8b80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1546158
milestone68.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 1546158: Add option to mscom::EnsureMTA to forcibly dispatch events to its thread; r=Jamie In sandboxed processes with Win32k lockdown, when we initialize COM using an MTA on a background thread, the main thread is automatically initialized by the COM runtime as having an implicit MTA. This is fine, except for the fact that if we want to enqueue any work that needs to operate specifically on the EnsureMTA thread, it won't happen. This patch adds a flag to EnsureMTA's constructor that ensures that, even if the current thread is in an MTA (implicit or otherwise), we still forcibly enqueue the closure specifically to the EnsureMTA thread. Differential Revision: https://phabricator.services.mozilla.com/D28391
ipc/mscom/EnsureMTA.h
--- a/ipc/mscom/EnsureMTA.h
+++ b/ipc/mscom/EnsureMTA.h
@@ -45,19 +45,26 @@ class MOZ_STACK_CLASS EnsureMTA final {
    */
   EnsureMTA() {
     MOZ_ASSERT(NS_IsMainThread());
     nsCOMPtr<nsIThread> thread = GetMTAThread();
     MOZ_ASSERT(thread);
     Unused << thread;
   }
 
+  enum class Option {
+    Default,
+    // Forcibly dispatch to the thread returned by GetMTAThread(), even if the
+    // current thread is already inside a MTA.
+    ForceDispatch,
+  };
+
   template <typename FuncT>
-  explicit EnsureMTA(const FuncT& aClosure) {
-    if (IsCurrentThreadMTA()) {
+  explicit EnsureMTA(const FuncT& aClosure, Option aOpt = Option::Default) {
+    if (aOpt != Option::ForceDispatch && IsCurrentThreadMTA()) {
       // We're already on the MTA, we can run aClosure directly
       aClosure();
       return;
     }
 
     MOZ_ASSERT(NS_IsMainThread());
 
     // In this case we need to run aClosure on a background thread in the MTA