This changes comes with several different refactorings all rolled into one, unfotunately I couldn't find a way to pull them apart: - First of all annotations now can either recorded (that is, we copy the value and have the crash reporting code own the copy) or registered. Several annotations are changed to use this functionality so that we don't need to update them as their value change. - The code in the exception handler is modified to read the annotations from the mozannotation_client crate. This has the unfortunate side-effect that we need three different bits of code to serialize them: one for annotations read from a child process, one for reading annotations from the main process outside of the exception handler and one for reading annotations from the main process within the exception handler. As we move to fully out-of-process crash reporting the last two methods will go away. - The mozannotation_client crate now doesn't record annotation types anymore. I realized as I was working on this that storing types at runtime has two issues: the first one is that buggy code might change the type of an annotation (that is record it under two different types at two different moments), the second issue is that types might become corrupt during a crash, so better enforce them at annotation-writing time. The end result is that the mozannotation_* crates now only store byte buffers, track the format the data is stored in (null-terminated string, fixed size buffer, etc...) but not the type of data each annotation is supposed to contain. - Which brings us to the next change: concrete types for annotations are now enforced when they're written out. If an annotation doesn't match the expected type it's skipped. Storing an annotation with the wrong type will also trigger an assertion in debug builds. Differential Revision: https://phabricator.services.mozilla.com/D195248
85 lines
2.3 KiB
C++
85 lines
2.3 KiB
C++
/* -*- 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_ProcessChild_h
|
|
#define mozilla_ipc_ProcessChild_h
|
|
|
|
#include "Endpoint.h"
|
|
#include "base/message_loop.h"
|
|
#include "base/process.h"
|
|
|
|
#include "chrome/common/child_process.h"
|
|
|
|
#include "mozilla/ipc/ProcessUtils.h"
|
|
|
|
// ProcessChild is the base class for all subprocesses of the main
|
|
// browser process. Its code runs on the thread that started in
|
|
// main().
|
|
|
|
namespace mozilla {
|
|
namespace ipc {
|
|
|
|
class ProcessChild : public ChildProcess {
|
|
protected:
|
|
typedef base::ProcessId ProcessId;
|
|
|
|
public:
|
|
explicit ProcessChild(ProcessId aParentPid, const nsID& aMessageChannelId);
|
|
|
|
ProcessChild(const ProcessChild&) = delete;
|
|
ProcessChild& operator=(const ProcessChild&) = delete;
|
|
|
|
virtual ~ProcessChild();
|
|
|
|
virtual bool Init(int aArgc, char* aArgv[]) = 0;
|
|
|
|
static void AddPlatformBuildID(std::vector<std::string>& aExtraArgs);
|
|
|
|
static bool InitPrefs(int aArgc, char* aArgv[]);
|
|
|
|
virtual void CleanUp() {}
|
|
|
|
static MessageLoop* message_loop() { return gProcessChild->mUILoop; }
|
|
|
|
static void NotifiedImpendingShutdown();
|
|
|
|
static bool ExpectingShutdown();
|
|
|
|
static void AppendToIPCShutdownStateAnnotation(const nsCString& aStr) {
|
|
StaticMutexAutoLock lock(gIPCShutdownStateLock);
|
|
gIPCShutdownStateAnnotation.Append(" - "_ns);
|
|
gIPCShutdownStateAnnotation.Append(aStr);
|
|
}
|
|
|
|
/**
|
|
* Exit *now*. Do not shut down XPCOM, do not pass Go, do not run
|
|
* static destructors, do not collect $200.
|
|
*/
|
|
static void QuickExit();
|
|
|
|
protected:
|
|
static ProcessChild* current() { return gProcessChild; }
|
|
|
|
ProcessId ParentPid() { return mParentPid; }
|
|
|
|
UntypedEndpoint TakeInitialEndpoint();
|
|
|
|
private:
|
|
static ProcessChild* gProcessChild;
|
|
static StaticMutex gIPCShutdownStateLock;
|
|
static nsCString gIPCShutdownStateAnnotation
|
|
MOZ_GUARDED_BY(gIPCShutdownStateLock);
|
|
|
|
MessageLoop* mUILoop;
|
|
ProcessId mParentPid;
|
|
nsID mMessageChannelId;
|
|
};
|
|
|
|
} // namespace ipc
|
|
} // namespace mozilla
|
|
|
|
#endif // ifndef mozilla_ipc_ProcessChild_h
|