Bug 1383501: More crash annotation improvements for mscom proxy unmarshaling failures; r=jimm

MozReview-Commit-ID: DIOsFREuhxj

--HG--
rename : ipc/mscom/InterfaceRegistrationAnnotator.cpp => ipc/mscom/RegistrationAnnotator.cpp
rename : ipc/mscom/InterfaceRegistrationAnnotator.h => ipc/mscom/RegistrationAnnotator.h
This commit is contained in:
Aaron Klotz 2017-08-28 15:16:20 -06:00
Родитель 2396e38198
Коммит de44372d1c
7 изменённых файлов: 121 добавлений и 13 удалений

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

@ -93,6 +93,17 @@ ActivationContext::~ActivationContext()
Release(); Release();
} }
/* static */ Result<uintptr_t,HRESULT>
ActivationContext::GetCurrent()
{
HANDLE actCtx;
if (!::GetCurrentActCtx(&actCtx)) {
return Result<uintptr_t,HRESULT>(HRESULT_FROM_WIN32(::GetLastError()));
}
return reinterpret_cast<uintptr_t>(actCtx);
}
ActivationContextRegion::ActivationContextRegion(const ActivationContext& aActCtx) ActivationContextRegion::ActivationContextRegion(const ActivationContext& aActCtx)
: mActCtx(aActCtx) : mActCtx(aActCtx)
, mActCookie(0) , mActCookie(0)

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

@ -9,6 +9,7 @@
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/Move.h" #include "mozilla/Move.h"
#include "mozilla/Result.h"
#include <windows.h> #include <windows.h>
@ -34,6 +35,8 @@ public:
return mActCtx != INVALID_HANDLE_VALUE; return mActCtx != INVALID_HANDLE_VALUE;
} }
static Result<uintptr_t,HRESULT> GetCurrent();
private: private:
void Init(ACTCTX& aActCtx); void Init(ACTCTX& aActCtx);
void AddRef(); void AddRef();

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

@ -13,6 +13,9 @@
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#if defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
#include "nsExceptionHandler.h"
#endif // defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
#include "nsWindowsHelpers.h" #include "nsWindowsHelpers.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
@ -47,6 +50,19 @@ MainThreadRuntime::MainThreadRuntime()
, mActCtxRgn(a11y::Compatibility::GetActCtxResourceId()) , mActCtxRgn(a11y::Compatibility::GetActCtxResourceId())
#endif // defined(ACCESSIBILITY) #endif // defined(ACCESSIBILITY)
{ {
#if defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
auto actctx = ActivationContext::GetCurrent();
nsAutoCString strActCtx;
if (actctx.isOk()) {
strActCtx.AppendPrintf("0x%p", actctx.unwrap());
} else {
strActCtx.AppendPrintf("HRESULT 0x%08X", actctx.unwrapErr());
}
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AssemblyManifestCtx"),
strActCtx);
#endif // defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
// We must be the outermost COM initialization on this thread. The COM runtime // We must be the outermost COM initialization on this thread. The COM runtime
// cannot be configured once we start manipulating objects // cannot be configured once we start manipulating objects
MOZ_ASSERT(mStaRegion.IsValidOutermost()); MOZ_ASSERT(mStaRegion.IsValidOutermost());

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

@ -5,14 +5,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Move.h" #include "mozilla/Move.h"
#if defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
#include "HandlerData.h"
#include "mozilla/a11y/Platform.h"
#include "mozilla/mscom/ActivationContext.h"
#endif // defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
#include "mozilla/mscom/EnsureMTA.h" #include "mozilla/mscom/EnsureMTA.h"
#include "mozilla/mscom/ProxyStream.h" #include "mozilla/mscom/ProxyStream.h"
#include "mozilla/mscom/Utils.h" #include "mozilla/mscom/Utils.h"
#if defined(MOZ_CRASHREPORTER) #if defined(MOZ_CRASHREPORTER)
#include "InterfaceRegistrationAnnotator.h" #include "mozilla/mscom/Objref.h"
#include "nsExceptionHandler.h" #include "nsExceptionHandler.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "RegistrationAnnotator.h"
#endif #endif
#include <windows.h> #include <windows.h>
@ -73,19 +79,30 @@ ProxyStream::ProxyStream(REFIID aIID, const BYTE* aInitBuf,
return; return;
} }
#if defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
const uint32_t expectedStreamLen = GetOBJREFSize(WrapNotNull(mStream));
nsAutoCString strActCtx;
#endif // defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
HRESULT unmarshalResult = S_OK; HRESULT unmarshalResult = S_OK;
// We need to convert to an interface here otherwise we mess up const // We need to convert to an interface here otherwise we mess up const
// correctness with IPDL. We'll request an IUnknown and then QI the // correctness with IPDL. We'll request an IUnknown and then QI the
// actual interface later. // actual interface later.
auto marshalFn = [&]() -> void auto marshalFn = [this, &strActCtx, &unmarshalResult, &aIID]() -> void
{ {
// OK to forget mStream when calling into this function because the stream #if defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
// gets released even if the unmarshaling part fails. auto curActCtx = ActivationContext::GetCurrent();
if (curActCtx.isOk()) {
strActCtx.AppendPrintf("0x%p", curActCtx.unwrap());
} else {
strActCtx.AppendPrintf("HRESULT 0x%08X", curActCtx.unwrapErr());
}
#endif // defined(ACCESSIBILITY) && defined(MOZ_CRASHREPORTER)
unmarshalResult = unmarshalResult =
::CoGetInterfaceAndReleaseStream(mStream.forget().take(), aIID, ::CoUnmarshalInterface(mStream, aIID, getter_AddRefs(mUnmarshaledProxy));
getter_AddRefs(mUnmarshaledProxy));
MOZ_ASSERT(SUCCEEDED(unmarshalResult)); MOZ_ASSERT(SUCCEEDED(unmarshalResult));
}; };
@ -98,12 +115,33 @@ ProxyStream::ProxyStream(REFIID aIID, const BYTE* aInitBuf,
EnsureMTA mta(marshalFn); EnsureMTA mta(marshalFn);
} }
mStream = nullptr;
#if defined(MOZ_CRASHREPORTER) #if defined(MOZ_CRASHREPORTER)
if (FAILED(unmarshalResult)) { if (FAILED(unmarshalResult) || !mUnmarshaledProxy) {
nsPrintfCString hrAsStr("0x%08X", unmarshalResult); nsPrintfCString hrAsStr("0x%08X", unmarshalResult);
CrashReporter::AnnotateCrashReport( CrashReporter::AnnotateCrashReport(
NS_LITERAL_CSTRING("CoGetInterfaceAndReleaseStreamFailure"), hrAsStr); NS_LITERAL_CSTRING("CoUnmarshalInterfaceResult"), hrAsStr);
AnnotateInterfaceRegistration(aIID); AnnotateInterfaceRegistration(aIID);
#if defined(ACCESSIBILITY)
AnnotateClassRegistration(CLSID_AccessibleHandler);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("UnmarshalActCtx"),
strActCtx);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("A11yHandlerRegistered"),
a11y::IsHandlerRegistered() ?
NS_LITERAL_CSTRING("true") :
NS_LITERAL_CSTRING("false"));
nsAutoCString strExpectedStreamLen;
strExpectedStreamLen.AppendInt(expectedStreamLen);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ExpectedStreamLen"),
strExpectedStreamLen);
nsAutoCString actualStreamLen;
actualStreamLen.AppendInt(aInitBufSize);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("ActualStreamLen"),
actualStreamLen);
#endif // defined(ACCESSIBILITY)
} }
#endif // defined(MOZ_CRASHREPORTER) #endif // defined(MOZ_CRASHREPORTER)
} }

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

@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "InterfaceRegistrationAnnotator.h" #include "RegistrationAnnotator.h"
#include "mozilla/JSONWriter.h" #include "mozilla/JSONWriter.h"
#include "mozilla/mscom/Utils.h" #include "mozilla/mscom/Utils.h"
@ -363,6 +363,45 @@ AnnotateInterfaceRegistration(REFIID aIid)
} else { } else {
annotationKey.AppendLiteral("Child"); annotationKey.AppendLiteral("Child");
} }
CrashReporter::AnnotateCrashReport(annotationKey,
static_cast<CStringWriter*>(json.WriteFunc())->Get());
}
void
AnnotateClassRegistration(REFCLSID aClsid)
{
#if defined(DEBUG)
const JSONWriter::CollectionStyle style = JSONWriter::MultiLineStyle;
#else
const JSONWriter::CollectionStyle style = JSONWriter::SingleLineStyle;
#endif
nsAutoString strClsid;
GUIDToString(aClsid, strClsid);
JSONWriter json(MakeUnique<CStringWriter>());
json.Start(style);
json.StartObjectProperty("HKLM", style);
AnnotateClsidRegistrationForHive(json, HKEY_LOCAL_MACHINE, strClsid, style);
json.EndObject();
json.StartObjectProperty("HKCU", style);
AnnotateClsidRegistrationForHive(json, HKEY_CURRENT_USER, strClsid, style);
json.EndObject();
json.End();
nsAutoCString annotationKey;
annotationKey.AppendLiteral("ClassRegistrationInfo");
if (XRE_IsParentProcess()) {
annotationKey.AppendLiteral("Parent");
} else {
annotationKey.AppendLiteral("Child");
}
CrashReporter::AnnotateCrashReport(annotationKey, CrashReporter::AnnotateCrashReport(annotationKey,
static_cast<CStringWriter*>(json.WriteFunc())->Get()); static_cast<CStringWriter*>(json.WriteFunc())->Get());
} }

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

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_mscom_InterfaceRegistrationAnnotator_h #ifndef mozilla_mscom_RegistrationAnnotator_h
#define mozilla_mscom_InterfaceRegistrationAnnotator_h #define mozilla_mscom_RegistrationAnnotator_h
#if !defined(MOZ_CRASHREPORTER) #if !defined(MOZ_CRASHREPORTER)
#error "This header requires crash reporting to be enabled" #error "This header requires crash reporting to be enabled"
@ -15,8 +15,9 @@ namespace mozilla {
namespace mscom { namespace mscom {
void AnnotateInterfaceRegistration(REFIID aIid); void AnnotateInterfaceRegistration(REFIID aIid);
void AnnotateClassRegistration(REFCLSID aClsid);
} // namespace mscom } // namespace mscom
} // namespace mozilla } // namespace mozilla
#endif // mozilla_mscom_InterfaceRegistrationAnnotator_h #endif // mozilla_mscom_RegistrationAnnotator_h

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

@ -39,7 +39,7 @@ UNIFIED_SOURCES += [
if CONFIG['MOZ_CRASHREPORTER']: if CONFIG['MOZ_CRASHREPORTER']:
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
'InterfaceRegistrationAnnotator.cpp', 'RegistrationAnnotator.cpp',
] ]
if CONFIG['ACCESSIBILITY']: if CONFIG['ACCESSIBILITY']: