Remove IPC CrashReporterClient/Host

Tag #20.
This commit is contained in:
wolfbeast 2018-05-22 19:19:56 +02:00 committed by Roy Tam
commit 4f9e1b3147
12 changed files with 1 additions and 502 deletions

View file

@ -14,7 +14,6 @@
#if defined(XP_WIN)
# include "mozilla/gfx/DeviceManagerDx.h"
#endif
#include "mozilla/ipc/CrashReporterHost.h"
namespace mozilla {
namespace gfx {
@ -118,12 +117,6 @@ GPUChild::RecvGraphicsError(const nsCString& aError)
return true;
}
bool
GPUChild::RecvInitCrashReporter(Shmem&& aShmem)
{
return true;
}
bool
GPUChild::RecvNotifyUiObservers(const nsCString& aTopic)
{

View file

@ -12,9 +12,6 @@
#include "mozilla/gfx/gfxVarReceiver.h"
namespace mozilla {
namespace ipc {
class CrashReporterHost;
} // namespace
namespace gfx {
class GPUProcessHost;
@ -37,7 +34,6 @@ public:
// PGPUChild overrides.
bool RecvInitComplete(const GPUDeviceData& aData) override;
bool RecvReportCheckerboard(const uint32_t& aSeverity, const nsCString& aLog) override;
bool RecvInitCrashReporter(Shmem&& shmem) override;
bool RecvAccumulateChildHistogram(InfallibleTArray<Accumulation>&& aAccumulations) override;
bool RecvAccumulateChildKeyedHistogram(InfallibleTArray<KeyedAccumulation>&& aAccumulations) override;
void ActorDestroy(ActorDestroyReason aWhy) override;
@ -49,7 +45,6 @@ public:
private:
GPUProcessHost* mHost;
UniquePtr<ipc::CrashReporterHost> mCrashReporter;
bool mGPUReady;
};

View file

@ -14,7 +14,6 @@
#include "mozilla/Assertions.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/APZCTreeManager.h"

View file

@ -89,8 +89,6 @@ child:
// Graphics errors, analogous to PContent::GraphicsError
async GraphicsError(nsCString aError);
async InitCrashReporter(Shmem shmem);
// Have a message be broadcasted to the UI process by the UI process
// observer service.
async NotifyUiObservers(nsCString aTopic);

View file

@ -1,66 +0,0 @@
/* -*- 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 "CrashReporterClient.h"
#include "CrashReporterMetadataShmem.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace ipc {
StaticMutex CrashReporterClient::sLock;
StaticRefPtr<CrashReporterClient> CrashReporterClient::sClientSingleton;
CrashReporterClient::CrashReporterClient(const Shmem& aShmem)
: mMetadata(new CrashReporterMetadataShmem(aShmem))
{
MOZ_COUNT_CTOR(CrashReporterClient);
}
CrashReporterClient::~CrashReporterClient()
{
MOZ_COUNT_DTOR(CrashReporterClient);
}
void
CrashReporterClient::AnnotateCrashReport(const nsCString& aKey, const nsCString& aData)
{
StaticMutexAutoLock lock(sLock);
mMetadata->AnnotateCrashReport(aKey, aData);
}
void
CrashReporterClient::AppendAppNotes(const nsCString& aData)
{
StaticMutexAutoLock lock(sLock);
mMetadata->AppendAppNotes(aData);
}
/* static */ void
CrashReporterClient::InitSingletonWithShmem(const Shmem& aShmem)
{
StaticMutexAutoLock lock(sLock);
MOZ_ASSERT(!sClientSingleton);
sClientSingleton = new CrashReporterClient(aShmem);
}
/* static */ void
CrashReporterClient::DestroySingleton()
{
StaticMutexAutoLock lock(sLock);
sClientSingleton = nullptr;
}
/* static */ RefPtr<CrashReporterClient>
CrashReporterClient::GetSingleton()
{
StaticMutexAutoLock lock(sLock);
return sClientSingleton;
}
} // namespace ipc
} // namespace mozilla

View file

@ -1,76 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_ipc_CrashReporterClient_h
#define mozilla_ipc_CrashReporterClient_h
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Unused.h"
#include "mozilla/ipc/Shmem.h"
namespace mozilla {
namespace ipc {
class CrashReporterMetadataShmem;
class CrashReporterClient
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CrashReporterClient);
// |aTopLevelProtocol| must be a top-level protocol instance, as sub-actors
// do not have AllocUnsafeShmem. It must also have a child-to-parent message:
//
// async SetCrashReporterClient(Shmem shmem);
//
// The parent-side receive function of this message should save the shmem
// somewhere, and when the top-level actor's ActorDestroy runs (or when the
// crash reporter needs metadata), the shmem should be parsed.
template <typename T>
static bool InitSingleton(T* aToplevelProtocol) {
// 16KB should be enough for most metadata - see bug 1278717 comment #11.
static const size_t kShmemSize = 16 * 1024;
Shmem shmem;
bool rv = aToplevelProtocol->AllocUnsafeShmem(
kShmemSize,
SharedMemory::TYPE_BASIC,
&shmem);
if (!rv) {
return false;
}
InitSingletonWithShmem(shmem);
Unused << aToplevelProtocol->SendInitCrashReporter(shmem);
return true;
}
static void DestroySingleton();
static RefPtr<CrashReporterClient> GetSingleton();
void AnnotateCrashReport(const nsCString& aKey, const nsCString& aData);
void AppendAppNotes(const nsCString& aData);
private:
explicit CrashReporterClient(const Shmem& aShmem);
~CrashReporterClient();
static void InitSingletonWithShmem(const Shmem& aShmem);
private:
static StaticMutex sLock;
static StaticRefPtr<CrashReporterClient> sClientSingleton;
private:
UniquePtr<CrashReporterMetadataShmem> mMetadata;
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_CrashReporterClient_h

View file

@ -1,25 +0,0 @@
/* -*- 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 "CrashReporterHost.h"
#include "CrashReporterMetadataShmem.h"
#include "mozilla/Sprintf.h"
#include "mozilla/SyncRunnable.h"
#include "mozilla/Telemetry.h"
namespace mozilla {
namespace ipc {
CrashReporterHost::CrashReporterHost(GeckoProcessType aProcessType,
const Shmem& aShmem)
: mProcessType(aProcessType),
mShmem(aShmem),
mStartTime(::time(nullptr))
{
}
} // namespace ipc
} // namespace mozilla

View file

@ -1,43 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_ipc_CrashReporterHost_h
#define mozilla_ipc_CrashReporterHost_h
#include "mozilla/UniquePtr.h"
#include "mozilla/ipc/Shmem.h"
#include "base/process.h"
#include "nsExceptionHandler.h"
namespace mozilla {
namespace ipc {
// This is the newer replacement for CrashReporterParent. It is created in
// response to a InitCrashReporter message on a top-level actor, and simply
// holds the metadata shmem alive until the process ends. When the process
// terminates abnormally, the top-level should call GenerateCrashReport to
// automatically integrate metadata.
class CrashReporterHost
{
typedef mozilla::ipc::Shmem Shmem;
typedef CrashReporter::AnnotationTable AnnotationTable;
public:
CrashReporterHost(GeckoProcessType aProcessType, const Shmem& aShmem);
private:
void GenerateCrashReport(RefPtr<nsIFile> aCrashDump);
private:
GeckoProcessType mProcessType;
Shmem mShmem;
time_t mStartTime;
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_CrashReporterHost_h

View file

@ -1,212 +0,0 @@
/* -*- 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 "CrashReporterMetadataShmem.h"
#include "mozilla/Attributes.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace ipc {
enum class EntryType : uint8_t {
None,
Annotation,
};
CrashReporterMetadataShmem::CrashReporterMetadataShmem(const Shmem& aShmem)
: mShmem(aShmem)
{
MOZ_COUNT_CTOR(CrashReporterMetadataShmem);
}
CrashReporterMetadataShmem::~CrashReporterMetadataShmem()
{
MOZ_COUNT_DTOR(CrashReporterMetadataShmem);
}
void
CrashReporterMetadataShmem::AnnotateCrashReport(const nsCString& aKey, const nsCString& aData)
{
mNotes.Put(aKey, aData);
SyncNotesToShmem();
}
void
CrashReporterMetadataShmem::AppendAppNotes(const nsCString& aData)
{
mAppNotes.Append(aData);
mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes);
SyncNotesToShmem();
}
class MOZ_STACK_CLASS MetadataShmemWriter
{
public:
explicit MetadataShmemWriter(const Shmem& aShmem)
: mCursor(aShmem.get<uint8_t>()),
mEnd(mCursor + aShmem.Size<uint8_t>())
{
*mCursor = uint8_t(EntryType::None);
}
MOZ_MUST_USE bool WriteAnnotation(const nsCString& aKey, const nsCString& aValue) {
// This shouldn't happen because Commit() guarantees mCursor < mEnd. But
// we might as well be safe.
if (mCursor >= mEnd) {
return false;
}
// Save the current position so we can write the entry type if the entire
// entry fits.
uint8_t* start = mCursor++;
if (!Write(aKey) || !Write(aValue)) {
return false;
}
return Commit(start, EntryType::Annotation);
}
private:
// On success, append a new terminal byte. On failure, rollback the cursor.
MOZ_MUST_USE bool Commit(uint8_t* aStart, EntryType aType) {
MOZ_ASSERT(aStart < mEnd);
MOZ_ASSERT(EntryType(*aStart) == EntryType::None);
if (mCursor >= mEnd) {
// No room for a terminating byte - rollback.
mCursor = aStart;
return false;
}
// Commit the entry and write a new terminal byte.
*aStart = uint8_t(aType);
*mCursor = uint8_t(EntryType::None);
return true;
}
MOZ_MUST_USE bool Write(const nsCString& aString) {
// 32-bit length is okay since our shmems are very small (16K),
// a huge write would fail anyway.
return Write(static_cast<uint32_t>(aString.Length())) &&
Write(aString.get(), aString.Length());
}
template <typename T>
MOZ_MUST_USE bool Write(const T& aT) {
return Write(&aT, sizeof(T));
}
MOZ_MUST_USE bool Write(const void* aData, size_t aLength) {
if (size_t(mEnd - mCursor) < aLength) {
return false;
}
memcpy(mCursor, aData, aLength);
mCursor += aLength;
return true;
}
private:
// The cursor (beginning at start) always points to a single byte
// representing the next EntryType. An EntryType is either None,
// indicating there are no more entries, or Annotation, meaning
// two strings follow.
//
// Strings are written as a 32-bit length and byte sequence. After each new
// entry, a None entry is always appended, and a subsequent entry will
// overwrite this byte.
uint8_t* mCursor;
uint8_t* mEnd;
};
void
CrashReporterMetadataShmem::SyncNotesToShmem()
{
MetadataShmemWriter writer(mShmem);
for (auto it = mNotes.Iter(); !it.Done(); it.Next()) {
nsCString key = nsCString(it.Key());
nsCString value = nsCString(it.Data());
if (!writer.WriteAnnotation(key, value)) {
return;
}
}
}
// Helper class to iterate over metadata entries encoded in shmem.
class MOZ_STACK_CLASS MetadataShmemReader
{
public:
explicit MetadataShmemReader(const Shmem& aShmem)
: mEntryType(EntryType::None)
{
mCursor = aShmem.get<uint8_t>();
mEnd = mCursor + aShmem.Size<uint8_t>();
// Advance to the first item, if any.
Next();
}
bool Done() const {
return mCursor >= mEnd || Type() == EntryType::None;
}
EntryType Type() const {
return mEntryType;
}
void Next() {
if (mCursor < mEnd) {
mEntryType = EntryType(*mCursor++);
} else {
mEntryType = EntryType::None;
}
}
bool Read(nsCString& aOut) {
uint32_t length = 0;
if (!Read(&length)) {
return false;
}
const uint8_t* src = Read(length);
if (!src) {
return false;
}
aOut.Assign((const char *)src, length);
return true;
}
private:
template <typename T>
bool Read(T* aOut) {
return Read(aOut, sizeof(T));
}
bool Read(void* aOut, size_t aLength) {
const uint8_t* src = Read(aLength);
if (!src) {
return false;
}
memcpy(aOut, src, aLength);
return true;
}
// If buffer has |aLength| bytes, return cursor and then advance it.
// Otherwise, return null.
const uint8_t* Read(size_t aLength) {
if (size_t(mEnd - mCursor) < aLength) {
return nullptr;
}
const uint8_t* result = mCursor;
mCursor += aLength;
return result;
}
private:
const uint8_t* mCursor;
const uint8_t* mEnd;
EntryType mEntryType;
};
} // namespace ipc
} // namespace mozilla

View file

@ -1,44 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_ipc_CrashReporterMetadataShmem_h
#define mozilla_ipc_CrashReporterMetadataShmem_h
#include <stdint.h>
#include "mozilla/ipc/Shmem.h"
#include "nsExceptionHandler.h"
#include "nsString.h"
namespace mozilla {
namespace ipc {
class CrashReporterMetadataShmem
{
typedef mozilla::ipc::Shmem Shmem;
typedef CrashReporter::AnnotationTable AnnotationTable;
public:
explicit CrashReporterMetadataShmem(const Shmem& aShmem);
~CrashReporterMetadataShmem();
// Metadata writers. These must only be called in child processes.
void AnnotateCrashReport(const nsCString& aKey, const nsCString& aData);
void AppendAppNotes(const nsCString& aData);
private:
void SyncNotesToShmem();
private:
Shmem mShmem;
AnnotationTable mNotes;
nsCString mAppNotes;
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_CrashReporterMetadataShmem_h

View file

@ -15,9 +15,6 @@ EXPORTS.mozilla.ipc += [
'BackgroundParent.h',
'BackgroundUtils.h',
'BrowserProcessSubThread.h',
'CrashReporterClient.h',
'CrashReporterHost.h',
'CrashReporterMetadataShmem.h',
'CrossProcessMutex.h',
'FileDescriptor.h',
'FileDescriptorSetChild.h',
@ -122,9 +119,6 @@ UNIFIED_SOURCES += [
'BackgroundImpl.cpp',
'BackgroundUtils.cpp',
'BrowserProcessSubThread.cpp',
'CrashReporterClient.cpp',
'CrashReporterHost.cpp',
'CrashReporterMetadataShmem.cpp',
'FileDescriptor.cpp',
'FileDescriptorUtils.cpp',
'InputStreamUtils.cpp',

View file

@ -10,7 +10,6 @@
#include "nsDirectoryServiceDefs.h"
#include "nsDataHashtable.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
#include "mozilla/Unused.h"
@ -114,8 +113,6 @@ using google_breakpad::FileID;
using google_breakpad::PageAllocator;
#endif
using namespace mozilla;
using mozilla::dom::CrashReporterChild;
using mozilla::ipc::CrashReporterClient;
namespace CrashReporter {
@ -2231,13 +2228,7 @@ nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data)
return rv;
if (!XRE_IsParentProcess()) {
// The newer CrashReporterClient can be used from any thread.
if (RefPtr<CrashReporterClient> client = CrashReporterClient::GetSingleton()) {
client->AnnotateCrashReport(nsCString(key), escapedData);
return NS_OK;
}
// Otherwise, we have to handle this on the main thread since we will go
// We have to handle this on the main thread since we will go
// through IPDL.
if (!NS_IsMainThread()) {
// Child process needs to handle this in the main thread:
@ -2313,11 +2304,6 @@ nsresult AppendAppNotesToCrashReport(const nsACString& data)
if (NS_FAILED(rv))
return rv;
if (RefPtr<CrashReporterClient> client = CrashReporterClient::GetSingleton()) {
client->AppendAppNotes(escapedData);
return NS_OK;
}
if (!NS_IsMainThread()) {
// Child process needs to handle this in the main thread:
nsCOMPtr<nsIRunnable> r = new CrashReporterHelperRunnable(data);