Bug 1258663 - Crash annotate system call failures in the IPC transport. r=gabor

This commit is contained in:
Cervantes Yu 2016-04-01 14:33:52 +08:00
parent 2b277c167c
commit f77c0e8c25
4 changed files with 41 additions and 0 deletions

View File

@ -7,6 +7,10 @@
#include "base/process_util.h"
#ifdef OS_POSIX
#include <errno.h>
#endif
#include "mozilla/ipc/MessageChannel.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/Transport.h"
@ -295,6 +299,22 @@ bool DuplicateHandle(HANDLE aSourceHandle,
}
#endif
#ifdef MOZ_CRASHREPORTER
void AnnotateSystemError()
{
int64_t error = 0;
#if defined(XP_WIN)
error = ::GetLastError();
#elif defined(OS_POSIX)
error = errno;
#endif
if (error) {
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("SystemError"),
nsPrintfCString("%lld", error));
}
}
#endif
void
ProtocolErrorBreakpoint(const char* aMsg)
{
@ -325,6 +345,7 @@ FatalError(const char* aProtocolName, const char* aMsg,
nsDependentCString(aProtocolName));
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("IPCFatalErrorMsg"),
nsDependentCString(aMsg));
AnnotateSystemError();
#endif
MOZ_CRASH("IPC FatalError in the parent process!");
} else {

View File

@ -333,6 +333,16 @@ DuplicateHandle(HANDLE aSourceHandle,
DWORD aOptions);
#endif
/**
* Annotate the crash reporter with the error error code from the most recent
* system call.
*/
#ifdef MOZ_CRASHREPORTER
void AnnotateSystemError();
#else
#define AnnotateSystemError() do { } while (0)
#endif
/**
* An endpoint represents one end of a partially initialized IPDL channel. To
* set up a new top-level protocol:

View File

@ -15,6 +15,7 @@
#include "mozilla/ipc/Transport.h"
#include "mozilla/ipc/FileDescriptor.h"
#include "ProtocolUtils.h"
using namespace std;
@ -70,6 +71,9 @@ DuplicateDescriptor(const TransportDescriptor& aTd)
{
TransportDescriptor result = aTd;
result.mFd.fd = dup(aTd.mFd.fd);
if (result.mFd.fd == -1) {
AnnotateSystemError();
}
MOZ_RELEASE_ASSERT(result.mFd.fd != -1, "DuplicateDescriptor failed");
return result;
}

View File

@ -64,6 +64,9 @@ TransferHandleToProcess(HANDLE source, base::ProcessId pid)
DWORD access = 0;
DWORD options = DUPLICATE_SAME_ACCESS;
bool ok = DuplicateHandle(source, pid, &handleDup, access, options);
if (!ok) {
AnnotateSystemError();
}
MOZ_RELEASE_ASSERT(ok);
// Now close our own copy of the handle (we're supposed to be transferring,
@ -103,6 +106,9 @@ DuplicateDescriptor(const TransportDescriptor& aTd)
DWORD options = DUPLICATE_SAME_ACCESS;
bool ok = DuplicateHandle(aTd.mServerPipeHandle, base::GetCurrentProcId(),
&serverDup, access, options);
if (!ok) {
AnnotateSystemError();
}
MOZ_RELEASE_ASSERT(ok);
TransportDescriptor desc = aTd;