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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Aaron Klotz 2019-04-23 02:17:17 +00:00
Родитель ec489aa170
Коммит 557ff156f6
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -50,9 +50,16 @@ class MOZ_STACK_CLASS EnsureMTA final {
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;