diff --git a/ipc/mscom/ActivationContext.h b/ipc/mscom/ActivationContext.h index 2368027841d4..2365c5e49628 100644 --- a/ipc/mscom/ActivationContext.h +++ b/ipc/mscom/ActivationContext.h @@ -23,15 +23,10 @@ namespace mscom { class ActivationContext final { public: - // This is the default resource ID that the Windows dynamic linker searches - // for when seeking a manifest while loading a DLL. - static constexpr WORD kDllManifestDefaultResourceId = 2; - ActivationContext() : mActCtx(INVALID_HANDLE_VALUE) {} explicit ActivationContext(WORD aResourceId); - explicit ActivationContext(HMODULE aLoadFromModule, - WORD aResourceId = kDllManifestDefaultResourceId); + explicit ActivationContext(HMODULE aLoadFromModule, WORD aResourceId = 2); ActivationContext(ActivationContext&& aOther); ActivationContext& operator=(ActivationContext&& aOther); diff --git a/ipc/mscom/ApartmentRegion.h b/ipc/mscom/ApartmentRegion.h index aa4d3e6d418f..dc56e3fc9676 100644 --- a/ipc/mscom/ApartmentRegion.h +++ b/ipc/mscom/ApartmentRegion.h @@ -15,14 +15,14 @@ namespace mozilla { namespace mscom { -class MOZ_NON_TEMPORARY_CLASS ApartmentRegion final { +class MOZ_NON_TEMPORARY_CLASS ApartmentRegion { public: /** * This constructor is to be used when we want to instantiate the object but * we do not yet know which type of apartment we want. Call Init() to * complete initialization. */ - constexpr ApartmentRegion() : mInitResult(CO_E_NOTINITIALIZED) {} + ApartmentRegion() : mInitResult(CO_E_NOTINITIALIZED) {} explicit ApartmentRegion(COINIT aAptType) : mInitResult(::CoInitializeEx(nullptr, aAptType)) { @@ -62,7 +62,7 @@ class MOZ_NON_TEMPORARY_CLASS ApartmentRegion final { }; template -class MOZ_NON_TEMPORARY_CLASS ApartmentRegionT final { +class MOZ_NON_TEMPORARY_CLASS ApartmentRegionT { public: ApartmentRegionT() : mAptRgn(T) {} diff --git a/ipc/mscom/Objref.cpp b/ipc/mscom/Objref.cpp index 37108c71ac1f..c0e8e98b162d 100644 --- a/ipc/mscom/Objref.cpp +++ b/ipc/mscom/Objref.cpp @@ -262,7 +262,8 @@ bool StripHandlerFromOBJREF(NotNull aStream, const uint64_t aStartPos, // The difference between a OBJREF_STANDARD and an OBJREF_HANDLER is // sizeof(CLSID), so we'll zero out the remaining bytes. - hr = aStream->Write(&CLSID_NULL, sizeof(CLSID), &bytesWritten); + CLSID zeroClsid = {0}; + hr = aStream->Write(&zeroClsid, sizeof(CLSID), &bytesWritten); if (FAILED(hr) || bytesWritten != sizeof(CLSID)) { return false; } diff --git a/ipc/mscom/Ptr.h b/ipc/mscom/Ptr.h index e800d4f568bf..fd4bd9c91ffc 100644 --- a/ipc/mscom/Ptr.h +++ b/ipc/mscom/Ptr.h @@ -37,7 +37,6 @@ struct MainThreadRelease { if (!aPtr) { return; } - if (NS_IsMainThread()) { aPtr->Release(); return; @@ -57,8 +56,7 @@ struct MTADelete { return; } - EnsureMTA::AsyncOperation( - [ptr = std::move(aPtr)]() -> void { delete ptr; }); + EnsureMTA::AsyncOperation([aPtr]() -> void { delete aPtr; }); } }; @@ -69,8 +67,11 @@ struct MTARelease { return; } + // Static analysis doesn't recognize that, even though aPtr escapes the + // current scope, we are in effect moving our strong ref into the lambda. + void* ptr = aPtr; EnsureMTA::AsyncOperation( - [ptr = std::move(aPtr)]() -> void { ptr->Release(); }); + [ptr]() -> void { reinterpret_cast(ptr)->Release(); }); } }; @@ -87,8 +88,11 @@ struct MTAReleaseInChildProcess { return; } + // Static analysis doesn't recognize that, even though aPtr escapes the + // current scope, we are in effect moving our strong ref into the lambda. + void* ptr = aPtr; EnsureMTA::AsyncOperation( - [ptr = std::move(aPtr)]() -> void { ptr->Release(); }); + [ptr]() -> void { reinterpret_cast(ptr)->Release(); }); } }; @@ -104,10 +108,14 @@ struct PreservedStreamDeleter { return; } - auto cleanup = [ptr = std::move(aPtr)]() -> void { - DebugOnly hr = ::CoReleaseMarshalData(ptr); + // Static analysis doesn't recognize that, even though aPtr escapes the + // current scope, we are in effect moving our strong ref into the lambda. + void* ptr = aPtr; + auto cleanup = [ptr]() -> void { + DebugOnly hr = + ::CoReleaseMarshalData(reinterpret_cast(ptr)); MOZ_ASSERT(SUCCEEDED(hr)); - ptr->Release(); + reinterpret_cast(ptr)->Release(); }; if (XRE_IsParentProcess()) { @@ -116,7 +124,7 @@ struct PreservedStreamDeleter { return; } - EnsureMTA::AsyncOperation(std::move(cleanup)); + EnsureMTA::AsyncOperation(cleanup); } }; @@ -184,7 +192,6 @@ inline STAUniquePtr ToSTAUniquePtr(T* aRawPtr) { if (aRawPtr) { aRawPtr->AddRef(); } - return STAUniquePtr(aRawPtr); } @@ -212,7 +219,6 @@ inline MTAUniquePtr ToMTAUniquePtr(T* aRawPtr) { if (aRawPtr) { aRawPtr->AddRef(); } - return MTAUniquePtr(aRawPtr); } @@ -239,7 +245,6 @@ inline ProxyUniquePtr ToProxyUniquePtr(T* aRawPtr) { if (aRawPtr) { aRawPtr->AddRef(); } - return ProxyUniquePtr(aRawPtr); } diff --git a/ipc/mscom/Utils.cpp b/ipc/mscom/Utils.cpp index e87b35c45c7c..ab6ac719696b 100644 --- a/ipc/mscom/Utils.cpp +++ b/ipc/mscom/Utils.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #if defined(MOZILLA_INTERNAL_API) -# include "MainThreadUtils.h" # include "mozilla/dom/ContentChild.h" #endif @@ -75,16 +74,6 @@ bool IsCurrentThreadImplicitMTA() { aptTypeQualifier == APTTYPEQUALIFIER_IMPLICIT_MTA; } -#if defined(MOZILLA_INTERNAL_API) -bool IsCurrentThreadNonMainMTA() { - if (NS_IsMainThread()) { - return false; - } - - return IsCurrentThreadMTA(); -} -#endif // defined(MOZILLA_INTERNAL_API) - bool IsProxy(IUnknown* aUnknown) { if (!aUnknown) { return false; @@ -139,8 +128,8 @@ uintptr_t GetContainingModuleHandle() { return reinterpret_cast(thisModule); } -long CreateStream(const uint8_t* aInitBuf, const uint32_t aInitBufSize, - IStream** aOutStream) { +uint32_t CreateStream(const uint8_t* aInitBuf, const uint32_t aInitBufSize, + IStream** aOutStream) { if (!aInitBufSize || !aOutStream) { return E_INVALIDARG; } @@ -219,7 +208,7 @@ long CreateStream(const uint8_t* aInitBuf, const uint32_t aInitBufSize, return S_OK; } -long CopySerializedProxy(IStream* aInStream, IStream** aOutStream) { +uint32_t CopySerializedProxy(IStream* aInStream, IStream** aOutStream) { if (!aInStream || !aOutStream) { return E_INVALIDARG; } diff --git a/ipc/mscom/Utils.h b/ipc/mscom/Utils.h index ddc9979b8146..d93740fe7425 100644 --- a/ipc/mscom/Utils.h +++ b/ipc/mscom/Utils.h @@ -24,9 +24,6 @@ bool IsCOMInitializedOnCurrentThread(); bool IsCurrentThreadMTA(); bool IsCurrentThreadExplicitMTA(); bool IsCurrentThreadImplicitMTA(); -#if defined(MOZILLA_INTERNAL_API) -bool IsCurrentThreadNonMainMTA(); -#endif // defined(MOZILLA_INTERNAL_API) bool IsProxy(IUnknown* aUnknown); bool IsValidGUID(REFGUID aCheckGuid); uintptr_t GetContainingModuleHandle(); @@ -41,8 +38,8 @@ uintptr_t GetContainingModuleHandle(); * @param aOutStream Outparam to receive the newly created stream. * @return HRESULT error code. */ -long CreateStream(const uint8_t* aBuf, const uint32_t aBufLen, - IStream** aOutStream); +uint32_t CreateStream(const uint8_t* aBuf, const uint32_t aBufLen, + IStream** aOutStream); /** * Creates a deep copy of a proxy contained in a stream. @@ -51,7 +48,7 @@ long CreateStream(const uint8_t* aBuf, const uint32_t aBufLen, * @param aOutStream Outparam to receive the newly created stream. * @return HRESULT error code. */ -long CopySerializedProxy(IStream* aInStream, IStream** aOutStream); +uint32_t CopySerializedProxy(IStream* aInStream, IStream** aOutStream); #if defined(MOZILLA_INTERNAL_API) /**