Bug 1334665: Eliminate runtime dynamic linking for pre-win7 functions in ipc/mscom; r=jimm
authorAaron Klotz <aklotz@mozilla.com>
Fri, 27 Jan 2017 14:53:20 -0700
changeset 360904 1b4335b1b6e3c56b60b1d5fef40f096b9e7b79c5
parent 360903 3a2600f18ce3272a11f11dc4e01b4187c5f6ee26
child 360905 d6ec1eae0161be48653436dffa7ca0283d833102
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1334665
milestone54.0a1
Bug 1334665: Eliminate runtime dynamic linking for pre-win7 functions in ipc/mscom; r=jimm MozReview-Commit-ID: 7ySl728hdka
ipc/mscom/ProxyStream.cpp
ipc/mscom/Utils.cpp
ipc/mscom/moz.build
--- a/ipc/mscom/ProxyStream.cpp
+++ b/ipc/mscom/ProxyStream.cpp
@@ -1,15 +1,14 @@
 /* -*- 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 "DynamicallyLinkedFunctionPtr.h"
 #include "mozilla/mscom/EnsureMTA.h"
 #include "mozilla/mscom/ProxyStream.h"
 #include "mozilla/mscom/Utils.h"
 
 #include "mozilla/Move.h"
 
 #include <windows.h>
 #include <objbase.h>
@@ -69,23 +68,17 @@ ProxyStream::ProxyStream(const BYTE* aIn
     // When marshaling in child processes, we want to force the MTA.
     EnsureMTA mta(marshalFn);
   }
 }
 
 already_AddRefed<IStream>
 ProxyStream::InitStream(const BYTE* aInitBuf, const UINT aInitBufSize)
 {
-  // Need to link to this as ordinal 12 for Windows XP
-  static DynamicallyLinkedFunctionPtr<decltype(&::SHCreateMemStream)>
-    pSHCreateMemStream(L"shlwapi.dll", reinterpret_cast<const char*>(12));
-  if (!pSHCreateMemStream) {
-    return nullptr;
-  }
-  return already_AddRefed<IStream>(pSHCreateMemStream(aInitBuf, aInitBufSize));
+  return already_AddRefed<IStream>(::SHCreateMemStream(aInitBuf, aInitBufSize));
 }
 
 ProxyStream::ProxyStream(ProxyStream&& aOther)
 {
   *this = mozilla::Move(aOther);
 }
 
 ProxyStream&
--- a/ipc/mscom/Utils.cpp
+++ b/ipc/mscom/Utils.cpp
@@ -1,75 +1,29 @@
 /* -*- 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/. */
 
-// We need Windows 7 headers
-#ifdef NTDDI_VERSION
-#undef NTDDI_VERSION
-#endif
-#define NTDDI_VERSION 0x06010000
-#ifdef _WIN32_WINNT
-#undef _WIN32_WINNT
-#endif
-#define _WIN32_WINNT 0x0601
-
-#include "DynamicallyLinkedFunctionPtr.h"
 #include "mozilla/mscom/Utils.h"
 #include "mozilla/RefPtr.h"
 
+#include <objbase.h>
 #include <objidl.h>
 
-static bool
-IsCurrentThreadMTALegacy()
-{
-  // We don't use RefPtr for token because CoGetContextToken does *not*
-  // increment its refcount!
-  IUnknown* token = nullptr;
-  HRESULT hr =
-    CoGetContextToken(reinterpret_cast<ULONG_PTR*>(&token));
-  if (FAILED(hr)) {
-    return false;
-  }
-
-  RefPtr<IComThreadingInfo> threadingInfo;
-  hr = token->QueryInterface(IID_IComThreadingInfo,
-                             getter_AddRefs(threadingInfo));
-  if (FAILED(hr)) {
-    return false;
-  }
-
-  APTTYPE aptType;
-  hr = threadingInfo->GetCurrentApartmentType(&aptType);
-  if (FAILED(hr)) {
-    return false;
-  }
-
-  return aptType == APTTYPE_MTA;
-}
-
 namespace mozilla {
 namespace mscom {
 
 bool
 IsCurrentThreadMTA()
 {
-  static DynamicallyLinkedFunctionPtr<decltype(&::CoGetApartmentType)>
-    pCoGetApartmentType(L"ole32.dll", "CoGetApartmentType");
-
-  if (!pCoGetApartmentType) {
-    // XP and Vista do not expose the newer API.
-    return IsCurrentThreadMTALegacy();
-  }
-
   APTTYPE aptType;
   APTTYPEQUALIFIER aptTypeQualifier;
-  HRESULT hr = pCoGetApartmentType(&aptType, &aptTypeQualifier);
+  HRESULT hr = CoGetApartmentType(&aptType, &aptTypeQualifier);
   if (FAILED(hr)) {
     return false;
   }
 
   return aptType == APTTYPE_MTA;
 }
 
 bool
--- a/ipc/mscom/moz.build
+++ b/ipc/mscom/moz.build
@@ -9,24 +9,21 @@ EXPORTS.mozilla.mscom += [
     'COMPtrHolder.h',
     'EnsureMTA.h',
     'MainThreadRuntime.h',
     'ProxyStream.h',
     'Ptr.h',
     'Utils.h',
 ]
 
-SOURCES += [
-    'Utils.cpp',
-]
-
 UNIFIED_SOURCES += [
     'EnsureMTA.cpp',
     'MainThreadRuntime.cpp',
     'ProxyStream.cpp',
+    'Utils.cpp',
 ]
 
 if CONFIG['ACCESSIBILITY']:
     EXPORTS.mozilla.mscom += [
         'ActivationContext.h',
         'DispatchForwarder.h',
         'Interceptor.h',
         'InterceptorLog.h',