From f77c0e8c25fd0c4469f767b1c7687ac2e4395c1d Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Fri, 1 Apr 2016 14:33:52 +0800 Subject: [PATCH] Bug 1258663 - Crash annotate system call failures in the IPC transport. r=gabor --- ipc/glue/ProtocolUtils.cpp | 21 +++++++++++++++++++++ ipc/glue/ProtocolUtils.h | 10 ++++++++++ ipc/glue/Transport_posix.cpp | 4 ++++ ipc/glue/Transport_win.cpp | 6 ++++++ 4 files changed, 41 insertions(+) diff --git a/ipc/glue/ProtocolUtils.cpp b/ipc/glue/ProtocolUtils.cpp index f6df3b014977..e359170e3bdd 100644 --- a/ipc/glue/ProtocolUtils.cpp +++ b/ipc/glue/ProtocolUtils.cpp @@ -7,6 +7,10 @@ #include "base/process_util.h" +#ifdef OS_POSIX +#include +#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 { diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index 36bc3bf5b94f..cdd7498aeb80 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -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: diff --git a/ipc/glue/Transport_posix.cpp b/ipc/glue/Transport_posix.cpp index 95be9bb4eed7..bd131a5e52ff 100644 --- a/ipc/glue/Transport_posix.cpp +++ b/ipc/glue/Transport_posix.cpp @@ -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; } diff --git a/ipc/glue/Transport_win.cpp b/ipc/glue/Transport_win.cpp index a79b1bdb7f4d..aeeaa8352ef8 100644 --- a/ipc/glue/Transport_win.cpp +++ b/ipc/glue/Transport_win.cpp @@ -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;