Bug 1489317: Part 4 - Add asssertion that COM is initialized on the thread that is resolving an agile reference; r=mhowell a=pascalc
authorAaron Klotz <aklotz@mozilla.com>
Wed, 12 Sep 2018 18:56:10 +0000
changeset 489849 fe879d96c14b
parent 489848 e7f051b7650e
child 489850 ec22c8843396
push id9801
push userncsoregi@mozilla.com
push date2018-09-14 19:35 +0000
treeherdermozilla-beta@fe879d96c14b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell, pascalc
bugs1489317
milestone63.0
Bug 1489317: Part 4 - Add asssertion that COM is initialized on the thread that is resolving an agile reference; r=mhowell a=pascalc Depends on D5321 Differential Revision: https://phabricator.services.mozilla.com/D5323
ipc/mscom/AgileReference.cpp
ipc/mscom/Utils.cpp
ipc/mscom/Utils.h
--- a/ipc/mscom/AgileReference.cpp
+++ b/ipc/mscom/AgileReference.cpp
@@ -1,20 +1,21 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/mscom/AgileReference.h"
 
+#include "mozilla/Assertions.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/DynamicallyLinkedFunctionPtr.h"
-#include "mozilla/Assertions.h"
 #include "mozilla/Move.h"
+#include "mozilla/mscom/Utils.h"
 
 #if NTDDI_VERSION < NTDDI_WINBLUE
 
 // Declarations from Windows SDK specific to Windows 8.1
 
 enum AgileReferenceOptions
 {
     AGILEREFERENCE_DEFAULT        = 0,
@@ -132,16 +133,17 @@ AgileReference::operator=(AgileReference
   return *this;
 }
 
 HRESULT
 AgileReference::Resolve(REFIID aIid, void** aOutInterface) const
 {
   MOZ_ASSERT(aOutInterface);
   MOZ_ASSERT(mAgileRef || mGitCookie);
+  MOZ_ASSERT(IsCOMInitializedOnCurrentThread());
 
   if (!aOutInterface) {
     return E_INVALIDARG;
   }
 
   *aOutInterface = nullptr;
 
   if (mAgileRef) {
--- a/ipc/mscom/Utils.cpp
+++ b/ipc/mscom/Utils.cpp
@@ -28,16 +28,25 @@
 #if defined(_MSC_VER)
 extern "C" IMAGE_DOS_HEADER __ImageBase;
 #endif
 
 namespace mozilla {
 namespace mscom {
 
 bool
+IsCOMInitializedOnCurrentThread()
+{
+  APTTYPE aptType;
+  APTTYPEQUALIFIER aptTypeQualifier;
+  HRESULT hr = CoGetApartmentType(&aptType, &aptTypeQualifier);
+  return hr != CO_E_NOTINITIALIZED;
+}
+
+bool
 IsCurrentThreadMTA()
 {
   APTTYPE aptType;
   APTTYPEQUALIFIER aptTypeQualifier;
   HRESULT hr = CoGetApartmentType(&aptType, &aptTypeQualifier);
   if (FAILED(hr)) {
     return false;
   }
--- a/ipc/mscom/Utils.h
+++ b/ipc/mscom/Utils.h
@@ -15,16 +15,17 @@
 #include <guiddef.h>
 
 struct IStream;
 struct IUnknown;
 
 namespace mozilla {
 namespace mscom {
 
+bool IsCOMInitializedOnCurrentThread();
 bool IsCurrentThreadMTA();
 bool IsProxy(IUnknown* aUnknown);
 bool IsValidGUID(REFGUID aCheckGuid);
 uintptr_t GetContainingModuleHandle();
 
 /**
  * Given a buffer, create a new IStream object.
  * @param aBuf Buffer containing data to initialize the stream. This parameter