diff options
Diffstat (limited to 'ipc/glue')
-rw-r--r-- | ipc/glue/CrashReporterClient.cpp | 66 | ||||
-rw-r--r-- | ipc/glue/CrashReporterClient.h | 76 | ||||
-rw-r--r-- | ipc/glue/CrashReporterHost.cpp | 25 | ||||
-rw-r--r-- | ipc/glue/CrashReporterHost.h | 43 | ||||
-rw-r--r-- | ipc/glue/CrashReporterMetadataShmem.cpp | 212 | ||||
-rw-r--r-- | ipc/glue/CrashReporterMetadataShmem.h | 44 | ||||
-rw-r--r-- | ipc/glue/moz.build | 6 |
7 files changed, 0 insertions, 472 deletions
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> 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 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 <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 - 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<nsIFile> 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<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 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 <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 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', |