From 612459488e5810335c493c467c239c40787cc1d3 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 22 May 2018 19:19:56 +0200 Subject: Remove IPC CrashReporterClient/Host Tag #20. --- ipc/glue/CrashReporterClient.cpp | 66 ---------- ipc/glue/CrashReporterClient.h | 76 ------------ ipc/glue/CrashReporterHost.cpp | 25 ---- ipc/glue/CrashReporterHost.h | 43 ------- ipc/glue/CrashReporterMetadataShmem.cpp | 212 -------------------------------- ipc/glue/CrashReporterMetadataShmem.h | 44 ------- ipc/glue/moz.build | 6 - 7 files changed, 472 deletions(-) delete mode 100644 ipc/glue/CrashReporterClient.cpp delete mode 100644 ipc/glue/CrashReporterClient.h delete mode 100644 ipc/glue/CrashReporterHost.cpp delete mode 100644 ipc/glue/CrashReporterHost.h delete mode 100644 ipc/glue/CrashReporterMetadataShmem.cpp delete mode 100644 ipc/glue/CrashReporterMetadataShmem.h (limited to 'ipc/glue') diff --git a/ipc/glue/CrashReporterClient.cpp b/ipc/glue/CrashReporterClient.cpp deleted file mode 100644 index 004ca3b57..000000000 --- a/ipc/glue/CrashReporterClient.cpp +++ /dev/null @@ -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::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::GetSingleton() -{ - StaticMutexAutoLock lock(sLock); - return sClientSingleton; -} - -} // namespace ipc -} // namespace mozilla diff --git a/ipc/glue/CrashReporterClient.h b/ipc/glue/CrashReporterClient.h deleted file mode 100644 index 512533da8..000000000 --- a/ipc/glue/CrashReporterClient.h +++ /dev/null @@ -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 - 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 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 sClientSingleton; - -private: - UniquePtr mMetadata; -}; - -} // namespace ipc -} // namespace mozilla - -#endif // mozilla_ipc_CrashReporterClient_h - diff --git a/ipc/glue/CrashReporterHost.cpp b/ipc/glue/CrashReporterHost.cpp deleted file mode 100644 index 85552cba5..000000000 --- a/ipc/glue/CrashReporterHost.cpp +++ /dev/null @@ -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 diff --git a/ipc/glue/CrashReporterHost.h b/ipc/glue/CrashReporterHost.h deleted file mode 100644 index 1089781c5..000000000 --- a/ipc/glue/CrashReporterHost.h +++ /dev/null @@ -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 aCrashDump); - -private: - GeckoProcessType mProcessType; - Shmem mShmem; - time_t mStartTime; -}; - -} // namespace ipc -} // namespace mozilla - -#endif // mozilla_ipc_CrashReporterHost_h diff --git a/ipc/glue/CrashReporterMetadataShmem.cpp b/ipc/glue/CrashReporterMetadataShmem.cpp deleted file mode 100644 index 5b889948b..000000000 --- a/ipc/glue/CrashReporterMetadataShmem.cpp +++ /dev/null @@ -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()), - mEnd(mCursor + aShmem.Size()) - { - *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(aString.Length())) && - Write(aString.get(), aString.Length()); - } - - template - 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(); - mEnd = mCursor + aShmem.Size(); - - // 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 - 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 diff --git a/ipc/glue/CrashReporterMetadataShmem.h b/ipc/glue/CrashReporterMetadataShmem.h deleted file mode 100644 index ad67c6d75..000000000 --- a/ipc/glue/CrashReporterMetadataShmem.h +++ /dev/null @@ -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 -#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 diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build index 8caee1ffe..d0d9f9937 100644 --- a/ipc/glue/moz.build +++ b/ipc/glue/moz.build @@ -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', -- cgit v1.2.3