2012-01-25 20:05:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2007-07-25 01:05:54 +00:00
|
|
|
|
2013-09-22 03:04:10 +00:00
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-06-08 20:21:03 +00:00
|
|
|
#include "mozilla/dom/CrashReporterChild.h"
|
2011-10-03 20:26:08 +00:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIObserverService.h"
|
2013-10-16 23:46:14 +00:00
|
|
|
#include "mozilla/unused.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2011-06-08 20:21:03 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2013-09-23 21:30:40 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2007-07-25 01:05:54 +00:00
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
#if defined(XP_WIN32)
|
2007-07-25 01:05:54 +00:00
|
|
|
#ifdef WIN32_LEAN_AND_MEAN
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2013-09-22 03:04:10 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
2010-02-10 01:05:31 +00:00
|
|
|
#include "nsIWindowsRegKey.h"
|
2012-09-25 11:52:54 +00:00
|
|
|
#include "client/windows/crash_generation/client_info.h"
|
2011-04-03 02:14:00 +00:00
|
|
|
#include "client/windows/crash_generation/crash_generation_server.h"
|
2007-07-25 01:05:54 +00:00
|
|
|
#include "client/windows/handler/exception_handler.h"
|
2013-04-05 09:29:50 +00:00
|
|
|
#include <dbghelp.h>
|
2007-07-25 01:05:54 +00:00
|
|
|
#include <string.h>
|
2012-07-11 02:20:05 +00:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2012-04-20 09:07:55 +00:00
|
|
|
|
|
|
|
#include "nsWindowsDllInterceptor.h"
|
2007-07-25 01:06:00 +00:00
|
|
|
#elif defined(XP_MACOSX)
|
2011-04-03 02:14:00 +00:00
|
|
|
#include "client/mac/crash_generation/client_info.h"
|
|
|
|
#include "client/mac/crash_generation/crash_generation_server.h"
|
2007-07-25 01:06:00 +00:00
|
|
|
#include "client/mac/handler/exception_handler.h"
|
|
|
|
#include <string>
|
|
|
|
#include <Carbon/Carbon.h>
|
2010-06-21 02:07:59 +00:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2010-10-01 19:56:25 +00:00
|
|
|
#include <crt_externs.h>
|
2007-07-25 01:06:00 +00:00
|
|
|
#include <fcntl.h>
|
2010-08-27 13:32:45 +00:00
|
|
|
#include <mach/mach.h>
|
2007-07-25 01:06:11 +00:00
|
|
|
#include <sys/types.h>
|
2010-10-01 19:56:25 +00:00
|
|
|
#include <spawn.h>
|
2007-07-25 01:06:11 +00:00
|
|
|
#include <unistd.h>
|
2007-07-25 01:06:09 +00:00
|
|
|
#include "mac_utils.h"
|
2007-07-25 01:06:04 +00:00
|
|
|
#elif defined(XP_LINUX)
|
2010-02-10 01:05:31 +00:00
|
|
|
#include "nsIINIParser.h"
|
2010-07-29 15:31:07 +00:00
|
|
|
#include "common/linux/linux_libc_support.h"
|
2012-09-25 11:52:54 +00:00
|
|
|
#include "third_party/lss/linux_syscall_support.h"
|
2011-04-03 02:14:00 +00:00
|
|
|
#include "client/linux/crash_generation/client_info.h"
|
|
|
|
#include "client/linux/crash_generation/crash_generation_server.h"
|
2007-07-25 01:06:04 +00:00
|
|
|
#include "client/linux/handler/exception_handler.h"
|
|
|
|
#include <fcntl.h>
|
2007-07-25 01:06:11 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2008-03-20 01:13:36 +00:00
|
|
|
#elif defined(XP_SOLARIS)
|
|
|
|
#include "client/solaris/handler/exception_handler.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2007-07-25 01:05:55 +00:00
|
|
|
#else
|
|
|
|
#error "Not yet implemented for this platform"
|
2007-07-25 01:06:00 +00:00
|
|
|
#endif // defined(XP_WIN32)
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2012-07-02 18:55:23 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
#include "InjectCrashReporter.h"
|
|
|
|
using mozilla::InjectCrashRunnable;
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 01:05:54 +00:00
|
|
|
#include <stdlib.h>
|
2007-07-25 01:06:15 +00:00
|
|
|
#include <time.h>
|
2007-07-25 01:05:54 +00:00
|
|
|
#include <prenv.h>
|
2007-07-25 01:06:14 +00:00
|
|
|
#include <prio.h>
|
2007-11-12 18:53:52 +00:00
|
|
|
#include <prmem.h>
|
2010-01-14 22:38:00 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2007-07-25 01:05:54 +00:00
|
|
|
#include "nsDebug.h"
|
2007-07-25 01:05:55 +00:00
|
|
|
#include "nsCRT.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2010-01-13 15:44:10 +00:00
|
|
|
#include "prprf.h"
|
2010-11-24 14:15:03 +00:00
|
|
|
#include <map>
|
2010-10-19 19:05:47 +00:00
|
|
|
#include <vector>
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2014-03-15 06:10:39 +00:00
|
|
|
#include "mozilla/IOInterposer.h"
|
2012-01-24 16:08:51 +00:00
|
|
|
#include "mozilla/mozalloc_oom.h"
|
2013-11-12 13:31:32 +00:00
|
|
|
#include "mozilla/WindowsDllBlocklist.h"
|
2012-01-24 16:08:51 +00:00
|
|
|
|
2010-06-21 02:07:59 +00:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
|
|
|
|
#endif
|
2013-04-09 12:04:53 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
#include "common/linux/file_id.h"
|
|
|
|
#endif
|
2010-06-21 02:07:59 +00:00
|
|
|
|
2010-01-12 21:14:38 +00:00
|
|
|
using google_breakpad::CrashGenerationServer;
|
|
|
|
using google_breakpad::ClientInfo;
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
using google_breakpad::MinidumpDescriptor;
|
|
|
|
#endif
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
2011-06-08 20:21:03 +00:00
|
|
|
using mozilla::dom::CrashReporterChild;
|
|
|
|
using mozilla::dom::PCrashReporterChild;
|
2010-01-12 21:14:38 +00:00
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
namespace CrashReporter {
|
2007-07-25 01:05:54 +00:00
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
typedef wchar_t XP_CHAR;
|
2010-03-24 21:22:00 +00:00
|
|
|
typedef std::wstring xpstring;
|
2009-04-02 15:41:12 +00:00
|
|
|
#define CONVERT_XP_CHAR_TO_UTF16(x) x
|
2007-07-25 01:06:00 +00:00
|
|
|
#define XP_STRLEN(x) wcslen(x)
|
2010-08-11 14:57:44 +00:00
|
|
|
#define my_strlen strlen
|
2007-07-25 01:06:00 +00:00
|
|
|
#define CRASH_REPORTER_FILENAME "crashreporter.exe"
|
|
|
|
#define PATH_SEPARATOR "\\"
|
|
|
|
#define XP_PATH_SEPARATOR L"\\"
|
|
|
|
// sort of arbitrary, but MAX_PATH is kinda small
|
|
|
|
#define XP_PATH_MAX 4096
|
|
|
|
// "<reporter path>" "<minidump path>"
|
|
|
|
#define CMDLINE_SIZE ((XP_PATH_MAX * 2) + 6)
|
2007-08-29 19:46:00 +00:00
|
|
|
#ifdef _USE_32BIT_TIME_T
|
|
|
|
#define XP_TTOA(time, buffer, base) ltoa(time, buffer, base)
|
|
|
|
#else
|
|
|
|
#define XP_TTOA(time, buffer, base) _i64toa(time, buffer, base)
|
|
|
|
#endif
|
2012-01-24 16:08:51 +00:00
|
|
|
#define XP_STOA(size, buffer, base) _ui64toa(size, buffer, base)
|
2007-07-25 01:06:00 +00:00
|
|
|
#else
|
|
|
|
typedef char XP_CHAR;
|
2010-03-24 21:22:00 +00:00
|
|
|
typedef std::string xpstring;
|
2009-04-02 15:41:12 +00:00
|
|
|
#define CONVERT_XP_CHAR_TO_UTF16(x) NS_ConvertUTF8toUTF16(x)
|
2007-07-25 01:06:00 +00:00
|
|
|
#define CRASH_REPORTER_FILENAME "crashreporter"
|
|
|
|
#define PATH_SEPARATOR "/"
|
|
|
|
#define XP_PATH_SEPARATOR "/"
|
|
|
|
#define XP_PATH_MAX PATH_MAX
|
2010-07-29 15:31:07 +00:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
#define XP_STRLEN(x) my_strlen(x)
|
2012-01-24 16:08:51 +00:00
|
|
|
#define XP_TTOA(time, buffer, base) my_inttostring(time, buffer, sizeof(buffer))
|
|
|
|
#define XP_STOA(size, buffer, base) my_inttostring(size, buffer, sizeof(buffer))
|
2010-07-29 15:31:07 +00:00
|
|
|
#else
|
|
|
|
#define XP_STRLEN(x) strlen(x)
|
2007-08-29 19:46:00 +00:00
|
|
|
#define XP_TTOA(time, buffer, base) sprintf(buffer, "%ld", time)
|
2012-01-24 16:08:51 +00:00
|
|
|
#define XP_STOA(size, buffer, base) sprintf(buffer, "%zu", size)
|
2010-08-11 14:57:44 +00:00
|
|
|
#define my_strlen strlen
|
2010-07-29 15:31:07 +00:00
|
|
|
#define sys_close close
|
|
|
|
#define sys_fork fork
|
|
|
|
#define sys_open open
|
|
|
|
#define sys_write write
|
|
|
|
#endif
|
2007-07-25 01:06:00 +00:00
|
|
|
#endif // XP_WIN32
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
static const XP_CHAR dumpFileExtension[] = {'.', 'd', 'm', 'p',
|
|
|
|
'\0'}; // .dmp
|
|
|
|
static const XP_CHAR extraFileExtension[] = {'.', 'e', 'x', 't',
|
|
|
|
'r', 'a', '\0'}; // .extra
|
2007-07-25 01:05:54 +00:00
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
static const char kCrashMainID[] = "crash.main.1\n";
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
static google_breakpad::ExceptionHandler* gExceptionHandler = nullptr;
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
static XP_CHAR* pendingDirectory;
|
2007-07-25 01:06:00 +00:00
|
|
|
static XP_CHAR* crashReporterPath;
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
// Where crash events should go.
|
|
|
|
static XP_CHAR* eventsDirectory;
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
// If this is false, we don't launch the crash reporter
|
2007-07-25 01:06:02 +00:00
|
|
|
static bool doReport = true;
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
// If this is true, we don't have a crash reporter
|
|
|
|
static bool headlessClient = false;
|
|
|
|
|
2007-07-25 01:06:09 +00:00
|
|
|
// if this is true, we pass the exception on to the OS crash reporter
|
|
|
|
static bool showOSCrashReporter = false;
|
|
|
|
|
2007-08-29 19:46:00 +00:00
|
|
|
// The time of the last recorded crash, as a time_t value.
|
|
|
|
static time_t lastCrashTime = 0;
|
|
|
|
// The pathname of a file to store the crash time in
|
|
|
|
static XP_CHAR lastCrashTimeFilename[XP_PATH_MAX] = {0};
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
// A marker file to hold the path to the last dump written, which
|
|
|
|
// will be checked on startup.
|
|
|
|
static XP_CHAR crashMarkerFilename[XP_PATH_MAX] = {0};
|
|
|
|
|
|
|
|
// Whether we've already looked for the marker file.
|
|
|
|
static bool lastRunCrashID_checked = false;
|
|
|
|
// The minidump ID contained in the marker file.
|
2012-07-30 14:20:58 +00:00
|
|
|
static nsString* lastRunCrashID = nullptr;
|
2012-07-16 23:50:52 +00:00
|
|
|
|
2012-11-15 22:56:22 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// on Android 4.2 and above there is a user serial number associated
|
|
|
|
// with the current process that gets lost when we fork so we need to
|
|
|
|
// explicitly pass it to am
|
|
|
|
static char* androidUserSerial = nullptr;
|
|
|
|
#endif
|
|
|
|
|
2007-08-29 19:46:00 +00:00
|
|
|
// these are just here for readability
|
|
|
|
static const char kCrashTimeParameter[] = "CrashTime=";
|
|
|
|
static const int kCrashTimeParameterLen = sizeof(kCrashTimeParameter)-1;
|
|
|
|
|
|
|
|
static const char kTimeSinceLastCrashParameter[] = "SecondsSinceLastCrash=";
|
|
|
|
static const int kTimeSinceLastCrashParameterLen =
|
|
|
|
sizeof(kTimeSinceLastCrashParameter)-1;
|
|
|
|
|
2010-12-15 16:35:44 +00:00
|
|
|
static const char kSysMemoryParameter[] = "SystemMemoryUsePercentage=";
|
|
|
|
static const int kSysMemoryParameterLen = sizeof(kSysMemoryParameter)-1;
|
|
|
|
|
|
|
|
static const char kTotalVirtualMemoryParameter[] = "TotalVirtualMemory=";
|
|
|
|
static const int kTotalVirtualMemoryParameterLen =
|
|
|
|
sizeof(kTotalVirtualMemoryParameter)-1;
|
|
|
|
|
|
|
|
static const char kAvailableVirtualMemoryParameter[] = "AvailableVirtualMemory=";
|
|
|
|
static const int kAvailableVirtualMemoryParameterLen =
|
|
|
|
sizeof(kAvailableVirtualMemoryParameter)-1;
|
|
|
|
|
2012-01-24 16:08:51 +00:00
|
|
|
static const char kOOMAllocationSizeParameter[] = "OOMAllocationSize=";
|
|
|
|
static const int kOOMAllocationSizeParameterLen =
|
|
|
|
sizeof(kOOMAllocationSizeParameter)-1;
|
|
|
|
|
2014-04-29 22:32:10 +00:00
|
|
|
static const char kTotalPageFileParameter[] = "TotalPageFile=";
|
|
|
|
static const int kTotalPageFileParameterLen =
|
|
|
|
sizeof(kTotalPageFileParameter)-1;
|
|
|
|
|
2012-01-25 20:05:05 +00:00
|
|
|
static const char kAvailablePageFileParameter[] = "AvailablePageFile=";
|
|
|
|
static const int kAvailablePageFileParameterLen =
|
|
|
|
sizeof(kAvailablePageFileParameter)-1;
|
|
|
|
|
2014-04-29 22:32:10 +00:00
|
|
|
static const char kTotalPhysicalMemoryParameter[] = "TotalPhysicalMemory=";
|
|
|
|
static const int kTotalPhysicalMemoryParameterLen =
|
|
|
|
sizeof(kTotalPhysicalMemoryParameter)-1;
|
|
|
|
|
2012-01-25 20:05:05 +00:00
|
|
|
static const char kAvailablePhysicalMemoryParameter[] = "AvailablePhysicalMemory=";
|
|
|
|
static const int kAvailablePhysicalMemoryParameterLen =
|
|
|
|
sizeof(kAvailablePhysicalMemoryParameter)-1;
|
|
|
|
|
2012-08-15 17:47:51 +00:00
|
|
|
static const char kIsGarbageCollectingParameter[] = "IsGarbageCollecting=";
|
|
|
|
static const int kIsGarbageCollectingParameterLen =
|
|
|
|
sizeof(kIsGarbageCollectingParameter)-1;
|
|
|
|
|
2014-02-13 17:51:09 +00:00
|
|
|
static const char kEventLoopNestingLevelParameter[] = "EventLoopNestingLevel=";
|
|
|
|
static const int kEventLoopNestingLevelParameterLen =
|
|
|
|
sizeof(kEventLoopNestingLevelParameter)-1;
|
|
|
|
|
2013-12-06 14:00:06 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static const char kBreakpadReserveAddressParameter[] = "BreakpadReserveAddress=";
|
|
|
|
static const int kBreakpadReserveAddressParameterLen =
|
|
|
|
sizeof(kBreakpadReserveAddressParameter)-1;
|
|
|
|
|
|
|
|
static const char kBreakpadReserveSizeParameter[] = "BreakpadReserveSize=";
|
|
|
|
static const int kBreakpadReserveSizeParameterLen =
|
|
|
|
sizeof(kBreakpadReserveSizeParameter)-1;
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
// this holds additional data sent via the API
|
2011-10-06 20:33:21 +00:00
|
|
|
static Mutex* crashReporterAPILock;
|
2012-01-25 14:43:52 +00:00
|
|
|
static Mutex* notesFieldLock;
|
2010-03-24 21:22:01 +00:00
|
|
|
static AnnotationTable* crashReporterAPIData_Hash;
|
2012-07-30 14:20:58 +00:00
|
|
|
static nsCString* crashReporterAPIData = nullptr;
|
|
|
|
static nsCString* notesField = nullptr;
|
2012-08-15 17:47:51 +00:00
|
|
|
static bool isGarbageCollecting;
|
2014-02-13 17:51:09 +00:00
|
|
|
static uint32_t eventloopNestingLevel = 0;
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2014-01-15 15:03:14 +00:00
|
|
|
// Avoid a race during application termination.
|
|
|
|
static Mutex* dumpSafetyLock;
|
|
|
|
static bool isSafeToDump = false;
|
|
|
|
|
2010-01-12 21:14:38 +00:00
|
|
|
// OOP crash reporting
|
|
|
|
static CrashGenerationServer* crashServer; // chrome process has this
|
|
|
|
|
2010-08-16 19:05:09 +00:00
|
|
|
# if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-12 21:14:38 +00:00
|
|
|
// If crash reporting is disabled, we hand out this "null" pipe to the
|
|
|
|
// child process and don't attempt to connect to a parent server.
|
|
|
|
static const char kNullNotifyPipe[] = "-";
|
2010-01-13 15:44:10 +00:00
|
|
|
static char* childCrashNotifyPipe;
|
2010-01-12 21:14:38 +00:00
|
|
|
|
2010-01-12 22:00:48 +00:00
|
|
|
# elif defined(XP_LINUX)
|
2010-01-12 21:14:38 +00:00
|
|
|
static int serverSocketFd = -1;
|
|
|
|
static int clientSocketFd = -1;
|
2010-10-29 19:20:43 +00:00
|
|
|
static const int kMagicChildCrashReportFd = 4;
|
2010-08-16 19:05:09 +00:00
|
|
|
|
2010-01-12 22:00:48 +00:00
|
|
|
# endif
|
2010-01-14 22:38:00 +00:00
|
|
|
|
|
|
|
// |dumpMapLock| must protect all access to |pidToMinidump|.
|
|
|
|
static Mutex* dumpMapLock;
|
2012-07-11 02:20:05 +00:00
|
|
|
struct ChildProcessData : public nsUint32HashKey
|
|
|
|
{
|
|
|
|
ChildProcessData(KeyTypePointer aKey)
|
|
|
|
: nsUint32HashKey(aKey)
|
|
|
|
, sequence(0)
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-10-10 20:39:09 +00:00
|
|
|
, callback(nullptr)
|
2012-07-11 02:20:05 +00:00
|
|
|
#endif
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
// Each crashing process is assigned an increasing sequence number to
|
|
|
|
// indicate which process crashed first.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t sequence;
|
2012-07-11 02:20:05 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
InjectorCrashCallback* callback;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTHashtable<ChildProcessData> ChildMinidumpMap;
|
2010-01-14 22:38:00 +00:00
|
|
|
static ChildMinidumpMap* pidToMinidump;
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t crashSequence;
|
2012-07-11 02:20:05 +00:00
|
|
|
static bool OOPInitialized();
|
2010-01-14 22:38:00 +00:00
|
|
|
|
2012-07-02 18:55:23 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
static nsIThread* sInjectorThread;
|
|
|
|
|
|
|
|
class ReportInjectedCrash : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
ReportInjectedCrash(uint32_t pid) : mPID(pid) { }
|
2012-07-02 18:55:23 +00:00
|
|
|
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mPID;
|
2012-07-02 18:55:23 +00:00
|
|
|
};
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
// Crashreporter annotations that we don't send along in subprocess
|
|
|
|
// reports
|
|
|
|
static const char* kSubprocessBlacklist[] = {
|
|
|
|
"FramePoisonBase",
|
|
|
|
"FramePoisonSize",
|
|
|
|
"StartupTime",
|
|
|
|
"URL"
|
|
|
|
};
|
|
|
|
|
2011-06-08 20:21:03 +00:00
|
|
|
// If annotations are attempted before the crash reporter is enabled,
|
|
|
|
// they queue up here.
|
|
|
|
class DelayedNote;
|
|
|
|
nsTArray<nsAutoPtr<DelayedNote> >* gDelayedAnnotations;
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2012-04-20 09:07:55 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// the following are used to prevent other DLLs reverting the last chance
|
|
|
|
// exception handler to the windows default. Any attempt to change the
|
|
|
|
// unhandled exception filter or to reset it is ignored and our crash
|
|
|
|
// reporter is loaded instead (in case it became unloaded somehow)
|
|
|
|
typedef LPTOP_LEVEL_EXCEPTION_FILTER (WINAPI *SetUnhandledExceptionFilter_func)
|
|
|
|
(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
|
|
|
|
static SetUnhandledExceptionFilter_func stub_SetUnhandledExceptionFilter = 0;
|
2014-01-29 22:07:35 +00:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER previousUnhandledExceptionFilter = nullptr;
|
2012-04-20 09:07:55 +00:00
|
|
|
static WindowsDllInterceptor gKernel32Intercept;
|
|
|
|
static bool gBlockUnhandledExceptionFilter = true;
|
|
|
|
|
2014-01-29 22:07:35 +00:00
|
|
|
static void NotePreviousUnhandledExceptionFilter()
|
|
|
|
{
|
|
|
|
// Set a dummy value to get the previous filter, then restore
|
|
|
|
previousUnhandledExceptionFilter = SetUnhandledExceptionFilter(nullptr);
|
|
|
|
SetUnhandledExceptionFilter(previousUnhandledExceptionFilter);
|
|
|
|
}
|
|
|
|
|
2012-04-20 09:07:55 +00:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI
|
|
|
|
patched_SetUnhandledExceptionFilter (LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
|
|
|
|
{
|
2012-09-25 11:52:54 +00:00
|
|
|
if (!gBlockUnhandledExceptionFilter) {
|
2012-04-20 09:07:55 +00:00
|
|
|
// don't intercept
|
|
|
|
return stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
|
|
|
}
|
|
|
|
|
2014-01-29 22:07:35 +00:00
|
|
|
if (lpTopLevelExceptionFilter == previousUnhandledExceptionFilter) {
|
|
|
|
// OK to swap back and forth between the previous filter
|
|
|
|
previousUnhandledExceptionFilter =
|
|
|
|
stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
|
|
|
return previousUnhandledExceptionFilter;
|
|
|
|
}
|
|
|
|
|
2012-04-20 09:07:55 +00:00
|
|
|
// intercept attempts to change the filter
|
2013-10-10 20:39:09 +00:00
|
|
|
return nullptr;
|
2012-04-20 09:07:55 +00:00
|
|
|
}
|
2013-12-06 14:00:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserve some VM space. In the event that we crash because VM space is
|
|
|
|
* being leaked without leaking memory, freeing this space before taking
|
|
|
|
* the minidump will allow us to collect a minidump.
|
|
|
|
*
|
|
|
|
* This size is bigger than xul.dll plus some extra for MinidumpWriteDump
|
|
|
|
* allocations.
|
|
|
|
*/
|
|
|
|
static const SIZE_T kReserveSize = 0x2400000; // 36 MB
|
|
|
|
static void* gBreakpadReservedVM;
|
2012-04-20 09:07:55 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-01 19:56:25 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
static cpu_type_t pref_cpu_types[2] = {
|
|
|
|
#if defined(__i386__)
|
|
|
|
CPU_TYPE_X86,
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
CPU_TYPE_X86_64,
|
|
|
|
#elif defined(__ppc__)
|
|
|
|
CPU_TYPE_POWERPC,
|
|
|
|
#endif
|
|
|
|
CPU_TYPE_ANY };
|
|
|
|
|
|
|
|
static posix_spawnattr_t spawnattr;
|
|
|
|
#endif
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 19:05:47 +00:00
|
|
|
// Android builds use a custom library loader,
|
|
|
|
// so the embedding will provide a list of shared
|
|
|
|
// libraries that are mapped into anonymous mappings.
|
|
|
|
typedef struct {
|
|
|
|
std::string name;
|
|
|
|
uintptr_t start_address;
|
|
|
|
size_t length;
|
|
|
|
size_t file_offset;
|
|
|
|
} mapping_info;
|
|
|
|
static std::vector<mapping_info> library_mappings;
|
2012-08-22 15:56:38 +00:00
|
|
|
typedef std::map<uint32_t,google_breakpad::MappingList> MappingMap;
|
2010-10-19 19:05:47 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-11 14:57:44 +00:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
inline void
|
2012-01-24 16:08:51 +00:00
|
|
|
my_inttostring(intmax_t t, char* buffer, size_t buffer_length)
|
2010-08-11 14:57:44 +00:00
|
|
|
{
|
|
|
|
my_memset(buffer, 0, buffer_length);
|
2012-09-25 11:52:54 +00:00
|
|
|
my_uitos(buffer, t, my_uint_len(t));
|
2010-08-11 14:57:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static void
|
2012-06-06 02:08:30 +00:00
|
|
|
CreateFileFromPath(const xpstring& path, nsIFile** file)
|
2010-03-24 21:22:00 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_NewLocalFile(nsDependentString(path.c_str()), false, file);
|
2010-03-24 21:22:00 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void
|
2012-06-06 02:08:30 +00:00
|
|
|
CreateFileFromPath(const xpstring& path, nsIFile** file)
|
2010-03-24 21:22:00 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(path.c_str()), false, file);
|
2010-03-24 21:22:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
static XP_CHAR*
|
|
|
|
Concat(XP_CHAR* str, const XP_CHAR* toAppend, int* size)
|
|
|
|
{
|
|
|
|
int appendLen = XP_STRLEN(toAppend);
|
|
|
|
if (appendLen >= *size) appendLen = *size - 1;
|
|
|
|
|
|
|
|
memcpy(str, toAppend, appendLen * sizeof(XP_CHAR));
|
|
|
|
str += appendLen;
|
|
|
|
*str = '\0';
|
|
|
|
*size -= appendLen;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:08:51 +00:00
|
|
|
static size_t gOOMAllocationSize = 0;
|
|
|
|
|
|
|
|
void AnnotateOOMAllocationSize(size_t size)
|
|
|
|
{
|
|
|
|
gOOMAllocationSize = size;
|
|
|
|
}
|
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
bool MinidumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
|
|
|
const XP_CHAR* dump_path,
|
2007-07-25 01:06:00 +00:00
|
|
|
const XP_CHAR* minidump_id,
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2007-07-25 01:06:00 +00:00
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion,
|
|
|
|
#endif
|
2007-07-25 01:05:56 +00:00
|
|
|
bool succeeded)
|
2007-07-25 01:05:54 +00:00
|
|
|
{
|
2007-07-25 01:06:09 +00:00
|
|
|
bool returnValue = showOSCrashReporter ? false : succeeded;
|
2007-07-25 01:06:06 +00:00
|
|
|
|
2011-02-02 18:22:32 +00:00
|
|
|
static XP_CHAR minidumpPath[XP_PATH_MAX];
|
2007-07-25 01:06:00 +00:00
|
|
|
int size = XP_PATH_MAX;
|
2012-09-25 11:52:54 +00:00
|
|
|
XP_CHAR* p;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
p = Concat(minidumpPath, dump_path, &size);
|
2007-07-25 01:06:00 +00:00
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
Concat(p, dumpFileExtension, &size);
|
2012-09-25 11:52:54 +00:00
|
|
|
#else
|
|
|
|
Concat(minidumpPath, descriptor.path(), &size);
|
|
|
|
#endif
|
2007-07-25 01:06:00 +00:00
|
|
|
|
2011-02-02 18:22:32 +00:00
|
|
|
static XP_CHAR extraDataPath[XP_PATH_MAX];
|
2007-07-25 01:06:00 +00:00
|
|
|
size = XP_PATH_MAX;
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifndef XP_LINUX
|
2007-07-25 01:06:00 +00:00
|
|
|
p = Concat(extraDataPath, dump_path, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
2012-09-25 11:52:54 +00:00
|
|
|
#else
|
|
|
|
p = Concat(extraDataPath, descriptor.path(), &size);
|
|
|
|
// Skip back past the .dmp extension.
|
|
|
|
p -= 4;
|
|
|
|
#endif
|
2007-07-25 01:06:00 +00:00
|
|
|
Concat(p, extraFileExtension, &size);
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
if (headlessClient) {
|
|
|
|
// Leave a marker indicating that there was a crash.
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
HANDLE hFile = CreateFile(crashMarkerFilename, GENERIC_WRITE, 0,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
nullptr);
|
2012-07-16 23:50:52 +00:00
|
|
|
if(hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD nBytes;
|
2013-10-10 20:39:09 +00:00
|
|
|
WriteFile(hFile, minidumpPath, 2*wcslen(minidumpPath), &nBytes, nullptr);
|
2012-07-16 23:50:52 +00:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
int fd = sys_open(crashMarkerFilename,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
0600);
|
|
|
|
if (fd != -1) {
|
2013-10-16 23:46:14 +00:00
|
|
|
unused << sys_write(fd, minidumpPath, my_strlen(minidumpPath));
|
2012-07-16 23:50:52 +00:00
|
|
|
sys_close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:08:51 +00:00
|
|
|
char oomAllocationSizeBuffer[32];
|
|
|
|
int oomAllocationSizeBufferLen = 0;
|
|
|
|
if (gOOMAllocationSize) {
|
|
|
|
XP_STOA(gOOMAllocationSize, oomAllocationSizeBuffer, 10);
|
|
|
|
oomAllocationSizeBufferLen = my_strlen(oomAllocationSizeBuffer);
|
|
|
|
}
|
|
|
|
|
2007-08-29 19:46:00 +00:00
|
|
|
// calculate time since last crash (if possible), and store
|
|
|
|
// the time of this crash.
|
2010-07-29 15:31:07 +00:00
|
|
|
time_t crashTime;
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
struct kernel_timeval tv;
|
2013-10-10 20:39:09 +00:00
|
|
|
sys_gettimeofday(&tv, nullptr);
|
2010-07-29 15:31:07 +00:00
|
|
|
crashTime = tv.tv_sec;
|
|
|
|
#else
|
2013-10-10 20:39:09 +00:00
|
|
|
crashTime = time(nullptr);
|
2010-07-29 15:31:07 +00:00
|
|
|
#endif
|
2007-08-29 19:46:00 +00:00
|
|
|
time_t timeSinceLastCrash = 0;
|
|
|
|
// stringified versions of the above
|
|
|
|
char crashTimeString[32];
|
|
|
|
int crashTimeStringLen = 0;
|
|
|
|
char timeSinceLastCrashString[32];
|
|
|
|
int timeSinceLastCrashStringLen = 0;
|
|
|
|
|
|
|
|
XP_TTOA(crashTime, crashTimeString, 10);
|
2010-08-11 14:57:44 +00:00
|
|
|
crashTimeStringLen = my_strlen(crashTimeString);
|
2007-08-29 19:46:00 +00:00
|
|
|
if (lastCrashTime != 0) {
|
|
|
|
timeSinceLastCrash = crashTime - lastCrashTime;
|
|
|
|
XP_TTOA(timeSinceLastCrash, timeSinceLastCrashString, 10);
|
2010-08-11 14:57:44 +00:00
|
|
|
timeSinceLastCrashStringLen = my_strlen(timeSinceLastCrashString);
|
2007-08-29 19:46:00 +00:00
|
|
|
}
|
|
|
|
// write crash time to file
|
|
|
|
if (lastCrashTimeFilename[0] != 0) {
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
HANDLE hFile = CreateFile(lastCrashTimeFilename, GENERIC_WRITE, 0,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
nullptr);
|
2007-08-29 19:46:00 +00:00
|
|
|
if(hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD nBytes;
|
2013-10-10 20:39:09 +00:00
|
|
|
WriteFile(hFile, crashTimeString, crashTimeStringLen, &nBytes, nullptr);
|
2007-08-29 19:46:00 +00:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
#elif defined(XP_UNIX)
|
2010-07-29 15:31:07 +00:00
|
|
|
int fd = sys_open(lastCrashTimeFilename,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
0600);
|
2007-08-29 19:46:00 +00:00
|
|
|
if (fd != -1) {
|
2013-10-16 23:46:14 +00:00
|
|
|
unused << sys_write(fd, crashTimeString, crashTimeStringLen);
|
2010-07-29 15:31:07 +00:00
|
|
|
sys_close(fd);
|
2007-08-29 19:46:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2007-09-26 18:35:21 +00:00
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
// Write crash event file.
|
|
|
|
|
|
|
|
// Minidump IDs are UUIDs (36) + NULL.
|
|
|
|
static char id_ascii[37];
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const char * index = strrchr(descriptor.path(), '/');
|
|
|
|
MOZ_ASSERT(index);
|
|
|
|
MOZ_ASSERT(strlen(index) == 1 + 36 + 4); // "/" + UUID + ".dmp"
|
|
|
|
for (uint32_t i = 0; i < 36; i++) {
|
|
|
|
id_ascii[i] = *(index + 1 + i);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MOZ_ASSERT(XP_STRLEN(minidump_id) == 36);
|
|
|
|
for (uint32_t i = 0; i < 36; i++) {
|
|
|
|
id_ascii[i] = *((char *)(minidump_id + i));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (eventsDirectory) {
|
|
|
|
static XP_CHAR crashEventPath[XP_PATH_MAX];
|
|
|
|
int size = XP_PATH_MAX;
|
|
|
|
XP_CHAR* p;
|
|
|
|
p = Concat(crashEventPath, eventsDirectory, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
p = Concat(p, id_ascii, &size);
|
|
|
|
#else
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
HANDLE hFile = CreateFile(crashEventPath, GENERIC_WRITE, 0,
|
|
|
|
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
nullptr);
|
|
|
|
if (hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD nBytes;
|
|
|
|
WriteFile(hFile, kCrashMainID, sizeof(kCrashMainID) - 1, &nBytes,
|
|
|
|
nullptr);
|
|
|
|
WriteFile(hFile, crashTimeString, crashTimeStringLen, &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, id_ascii, strlen(id_ascii), &nBytes, nullptr);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
int fd = sys_open(crashEventPath,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
0600);
|
|
|
|
if (fd != -1) {
|
|
|
|
unused << sys_write(fd, kCrashMainID, sizeof(kCrashMainID) - 1);
|
|
|
|
unused << sys_write(fd, crashTimeString, crashTimeStringLen);
|
|
|
|
unused << sys_write(fd, "\n", 1);
|
|
|
|
unused << sys_write(fd, id_ascii, strlen(id_ascii));
|
|
|
|
sys_close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-08-29 19:46:00 +00:00
|
|
|
#if defined(XP_WIN32)
|
2007-07-25 01:05:58 +00:00
|
|
|
if (!crashReporterAPIData->IsEmpty()) {
|
2007-07-25 01:05:55 +00:00
|
|
|
// write out API data
|
2007-07-25 01:06:00 +00:00
|
|
|
HANDLE hFile = CreateFile(extraDataPath, GENERIC_WRITE, 0,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
nullptr);
|
2007-07-25 01:05:55 +00:00
|
|
|
if(hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD nBytes;
|
2007-07-25 01:05:58 +00:00
|
|
|
WriteFile(hFile, crashReporterAPIData->get(),
|
2013-10-10 20:39:09 +00:00
|
|
|
crashReporterAPIData->Length(), &nBytes, nullptr);
|
2007-08-29 19:46:00 +00:00
|
|
|
WriteFile(hFile, kCrashTimeParameter, kCrashTimeParameterLen,
|
2013-10-10 20:39:09 +00:00
|
|
|
&nBytes, nullptr);
|
|
|
|
WriteFile(hFile, crashTimeString, crashTimeStringLen, &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
2007-08-29 19:46:00 +00:00
|
|
|
if (timeSinceLastCrash != 0) {
|
|
|
|
WriteFile(hFile, kTimeSinceLastCrashParameter,
|
2013-10-10 20:39:09 +00:00
|
|
|
kTimeSinceLastCrashParameterLen, &nBytes, nullptr);
|
2007-08-29 19:46:00 +00:00
|
|
|
WriteFile(hFile, timeSinceLastCrashString, timeSinceLastCrashStringLen,
|
2013-10-10 20:39:09 +00:00
|
|
|
&nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
2007-08-29 19:46:00 +00:00
|
|
|
}
|
2012-08-15 17:47:51 +00:00
|
|
|
if (isGarbageCollecting) {
|
|
|
|
WriteFile(hFile, kIsGarbageCollectingParameter, kIsGarbageCollectingParameterLen,
|
2013-10-10 20:39:09 +00:00
|
|
|
&nBytes, nullptr);
|
|
|
|
WriteFile(hFile, isGarbageCollecting ? "1" : "0", 1, &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
2012-08-15 17:47:51 +00:00
|
|
|
}
|
2013-11-12 13:31:32 +00:00
|
|
|
|
2013-12-06 14:00:06 +00:00
|
|
|
char buffer[128];
|
|
|
|
int bufferLen;
|
|
|
|
|
2014-02-13 17:51:09 +00:00
|
|
|
if (eventloopNestingLevel > 0) {
|
|
|
|
WriteFile(hFile, kEventLoopNestingLevelParameter, kEventLoopNestingLevelParameterLen,
|
|
|
|
&nBytes, nullptr);
|
|
|
|
_ultoa(eventloopNestingLevel, buffer, 10);
|
|
|
|
WriteFile(hFile, buffer, strlen(buffer), &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-12-06 14:00:06 +00:00
|
|
|
if (gBreakpadReservedVM) {
|
|
|
|
WriteFile(hFile, kBreakpadReserveAddressParameter, kBreakpadReserveAddressParameterLen, &nBytes, nullptr);
|
|
|
|
_ui64toa(uintptr_t(gBreakpadReservedVM), buffer, 10);
|
|
|
|
WriteFile(hFile, buffer, strlen(buffer), &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, kBreakpadReserveSizeParameter, kBreakpadReserveSizeParameterLen, &nBytes, nullptr);
|
|
|
|
_ui64toa(kReserveSize, buffer, 10);
|
|
|
|
WriteFile(hFile, buffer, strlen(buffer), &nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:31:32 +00:00
|
|
|
#ifdef HAS_DLL_BLOCKLIST
|
|
|
|
DllBlocklist_WriteNotes(hFile);
|
|
|
|
#endif
|
2012-01-25 20:05:05 +00:00
|
|
|
|
2010-12-15 16:35:44 +00:00
|
|
|
// Try to get some information about memory.
|
|
|
|
MEMORYSTATUSEX statex;
|
|
|
|
statex.dwLength = sizeof(statex);
|
|
|
|
if (GlobalMemoryStatusEx(&statex)) {
|
2012-01-25 20:05:05 +00:00
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
#define WRITE_STATEX_FIELD(field, paramName, conversionFunc) \
|
|
|
|
WriteFile(hFile, k##paramName##Parameter, \
|
|
|
|
k##paramName##ParameterLen, &nBytes, nullptr); \
|
|
|
|
conversionFunc(statex.field, buffer, 10); \
|
|
|
|
bufferLen = strlen(buffer); \
|
|
|
|
WriteFile(hFile, buffer, bufferLen, &nBytes, nullptr); \
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
2012-01-25 20:05:05 +00:00
|
|
|
|
|
|
|
WRITE_STATEX_FIELD(dwMemoryLoad, SysMemory, ltoa);
|
|
|
|
WRITE_STATEX_FIELD(ullTotalVirtual, TotalVirtualMemory, _ui64toa);
|
|
|
|
WRITE_STATEX_FIELD(ullAvailVirtual, AvailableVirtualMemory, _ui64toa);
|
2014-04-29 22:32:10 +00:00
|
|
|
WRITE_STATEX_FIELD(ullTotalPageFile, TotalPageFile, _ui64toa);
|
2012-01-25 20:05:05 +00:00
|
|
|
WRITE_STATEX_FIELD(ullAvailPageFile, AvailablePageFile, _ui64toa);
|
2014-04-29 22:32:10 +00:00
|
|
|
WRITE_STATEX_FIELD(ullTotalPhys, TotalPhysicalMemory, _ui64toa);
|
2012-01-25 20:05:05 +00:00
|
|
|
WRITE_STATEX_FIELD(ullAvailPhys, AvailablePhysicalMemory, _ui64toa);
|
|
|
|
|
|
|
|
#undef WRITE_STATEX_FIELD
|
2010-12-15 16:35:44 +00:00
|
|
|
}
|
2012-01-25 20:05:05 +00:00
|
|
|
|
2012-01-24 16:08:51 +00:00
|
|
|
if (oomAllocationSizeBufferLen) {
|
|
|
|
WriteFile(hFile, kOOMAllocationSizeParameter,
|
2013-10-10 20:39:09 +00:00
|
|
|
kOOMAllocationSizeParameterLen, &nBytes, nullptr);
|
2012-01-24 16:08:51 +00:00
|
|
|
WriteFile(hFile, oomAllocationSizeBuffer, oomAllocationSizeBufferLen,
|
2013-10-10 20:39:09 +00:00
|
|
|
&nBytes, nullptr);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, nullptr);
|
2012-01-24 16:08:51 +00:00
|
|
|
}
|
2007-07-25 01:05:55 +00:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:02 +00:00
|
|
|
if (!doReport) {
|
2007-07-25 01:06:09 +00:00
|
|
|
return returnValue;
|
2007-07-25 01:06:02 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
XP_CHAR cmdLine[CMDLINE_SIZE];
|
|
|
|
size = CMDLINE_SIZE;
|
|
|
|
p = Concat(cmdLine, L"\"", &size);
|
|
|
|
p = Concat(p, crashReporterPath, &size);
|
|
|
|
p = Concat(p, L"\" \"", &size);
|
|
|
|
p = Concat(p, minidumpPath, &size);
|
|
|
|
Concat(p, L"\"", &size);
|
|
|
|
|
2007-07-25 01:05:54 +00:00
|
|
|
STARTUPINFO si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
if (CreateProcess(nullptr, (LPWSTR)cmdLine, nullptr, nullptr, FALSE, 0,
|
|
|
|
nullptr, nullptr, &si, &pi)) {
|
2007-07-25 01:05:54 +00:00
|
|
|
CloseHandle( pi.hProcess );
|
|
|
|
CloseHandle( pi.hThread );
|
|
|
|
}
|
|
|
|
// we're not really in a position to do anything if the CreateProcess fails
|
|
|
|
TerminateProcess(GetCurrentProcess(), 1);
|
2007-07-25 01:06:00 +00:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
if (!crashReporterAPIData->IsEmpty()) {
|
|
|
|
// write out API data
|
2010-07-29 15:31:07 +00:00
|
|
|
int fd = sys_open(extraDataPath,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
0666);
|
2007-07-25 01:06:00 +00:00
|
|
|
|
|
|
|
if (fd != -1) {
|
|
|
|
// not much we can do in case of error
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, crashReporterAPIData->get(),
|
2010-07-29 15:31:07 +00:00
|
|
|
crashReporterAPIData->Length());
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, kCrashTimeParameter, kCrashTimeParameterLen);
|
|
|
|
unused << sys_write(fd, crashTimeString, crashTimeStringLen);
|
|
|
|
unused << sys_write(fd, "\n", 1);
|
2007-08-29 19:46:00 +00:00
|
|
|
if (timeSinceLastCrash != 0) {
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, kTimeSinceLastCrashParameter,
|
2010-01-14 22:38:00 +00:00
|
|
|
kTimeSinceLastCrashParameterLen);
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, timeSinceLastCrashString,
|
2010-01-14 22:38:00 +00:00
|
|
|
timeSinceLastCrashStringLen);
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, "\n", 1);
|
2007-08-29 19:46:00 +00:00
|
|
|
}
|
2012-08-15 17:47:51 +00:00
|
|
|
if (isGarbageCollecting) {
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, kIsGarbageCollectingParameter, kIsGarbageCollectingParameterLen);
|
|
|
|
unused << sys_write(fd, isGarbageCollecting ? "1" : "0", 1);
|
|
|
|
unused << sys_write(fd, "\n", 1);
|
2012-08-15 17:47:51 +00:00
|
|
|
}
|
2014-02-13 17:51:09 +00:00
|
|
|
if (eventloopNestingLevel > 0) {
|
|
|
|
unused << sys_write(fd, kEventLoopNestingLevelParameter, kEventLoopNestingLevelParameterLen);
|
|
|
|
char buffer[16];
|
|
|
|
XP_TTOA(eventloopNestingLevel, buffer, 10);
|
|
|
|
unused << sys_write(fd, buffer, my_strlen(buffer));
|
|
|
|
unused << sys_write(fd, "\n", 1);
|
|
|
|
}
|
2012-01-24 16:08:51 +00:00
|
|
|
if (oomAllocationSizeBufferLen) {
|
2013-10-16 23:46:22 +00:00
|
|
|
unused << sys_write(fd, kOOMAllocationSizeParameter,
|
|
|
|
kOOMAllocationSizeParameterLen);
|
|
|
|
unused << sys_write(fd, oomAllocationSizeBuffer,
|
|
|
|
oomAllocationSizeBufferLen);
|
|
|
|
unused << sys_write(fd, "\n", 1);
|
|
|
|
}
|
2010-07-29 15:31:07 +00:00
|
|
|
sys_close(fd);
|
2007-07-25 01:06:00 +00:00
|
|
|
}
|
2007-07-25 01:05:55 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:02 +00:00
|
|
|
if (!doReport) {
|
2007-07-25 01:06:09 +00:00
|
|
|
return returnValue;
|
2007-07-25 01:06:02 +00:00
|
|
|
}
|
|
|
|
|
2010-10-01 19:56:25 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
char* const my_argv[] = {
|
|
|
|
crashReporterPath,
|
|
|
|
minidumpPath,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr
|
2010-10-01 19:56:25 +00:00
|
|
|
};
|
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
char **env = nullptr;
|
2010-10-01 19:56:25 +00:00
|
|
|
char ***nsEnv = _NSGetEnviron();
|
|
|
|
if (nsEnv)
|
|
|
|
env = *nsEnv;
|
2013-10-10 20:39:09 +00:00
|
|
|
int result = posix_spawnp(nullptr,
|
2010-10-01 19:56:25 +00:00
|
|
|
my_argv[0],
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr,
|
2010-10-01 19:56:25 +00:00
|
|
|
&spawnattr,
|
|
|
|
my_argv,
|
|
|
|
env);
|
|
|
|
|
|
|
|
if (result != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#else // !XP_MACOSX
|
2010-07-29 15:31:07 +00:00
|
|
|
pid_t pid = sys_fork();
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
if (pid == -1)
|
|
|
|
return false;
|
|
|
|
else if (pid == 0) {
|
2012-07-16 23:50:52 +00:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
2007-12-10 18:47:29 +00:00
|
|
|
// need to clobber this, as libcurl might load NSS,
|
|
|
|
// and we want it to load the system NSS.
|
|
|
|
unsetenv("LD_LIBRARY_PATH");
|
2013-10-16 23:46:14 +00:00
|
|
|
unused << execl(crashReporterPath,
|
|
|
|
crashReporterPath, minidumpPath, (char*)0);
|
2010-10-13 18:27:44 +00:00
|
|
|
#else
|
|
|
|
// Invoke the reportCrash activity using am
|
2012-11-15 22:56:22 +00:00
|
|
|
if (androidUserSerial) {
|
2013-10-16 23:46:14 +00:00
|
|
|
unused << execlp("/system/bin/am",
|
|
|
|
"/system/bin/am",
|
|
|
|
"start",
|
|
|
|
"--user", androidUserSerial,
|
|
|
|
"-a", "org.mozilla.gecko.reportCrash",
|
|
|
|
"-n", crashReporterPath,
|
|
|
|
"--es", "minidumpPath", minidumpPath,
|
|
|
|
(char*)0);
|
2012-11-15 22:56:22 +00:00
|
|
|
} else {
|
2013-10-16 23:46:14 +00:00
|
|
|
unused << execlp("/system/bin/am",
|
|
|
|
"/system/bin/am",
|
|
|
|
"start",
|
|
|
|
"-a", "org.mozilla.gecko.reportCrash",
|
|
|
|
"-n", crashReporterPath,
|
|
|
|
"--es", "minidumpPath", minidumpPath,
|
|
|
|
(char*)0);
|
2012-11-15 22:56:22 +00:00
|
|
|
}
|
2010-10-13 18:27:44 +00:00
|
|
|
#endif
|
2007-07-25 01:06:00 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
2010-10-01 19:56:25 +00:00
|
|
|
#endif // XP_MACOSX
|
|
|
|
#endif // XP_UNIX
|
2007-07-25 01:06:00 +00:00
|
|
|
|
2012-11-15 22:56:22 +00:00
|
|
|
return returnValue;
|
2007-07-25 01:05:55 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 18:16:20 +00:00
|
|
|
#ifdef XP_WIN
|
2013-04-13 13:10:28 +00:00
|
|
|
static void
|
|
|
|
ReserveBreakpadVM()
|
|
|
|
{
|
|
|
|
if (!gBreakpadReservedVM) {
|
2013-11-26 18:22:01 +00:00
|
|
|
gBreakpadReservedVM = VirtualAlloc(nullptr, kReserveSize, MEM_RESERVE,
|
|
|
|
PAGE_NOACCESS);
|
2013-04-13 13:10:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeBreakpadVM()
|
|
|
|
{
|
|
|
|
if (gBreakpadReservedVM) {
|
2013-11-26 18:22:01 +00:00
|
|
|
VirtualFree(gBreakpadReservedVM, 0, MEM_RELEASE);
|
2013-04-13 13:10:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-11 18:16:20 +00:00
|
|
|
/**
|
|
|
|
* Filters out floating point exceptions which are handled by nsSigHandlers.cpp
|
|
|
|
* and should not be handled as crashes.
|
2013-04-13 13:10:28 +00:00
|
|
|
*
|
|
|
|
* Also calls FreeBreakpadVM if appropriate.
|
2010-01-11 18:16:20 +00:00
|
|
|
*/
|
|
|
|
static bool FPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion)
|
|
|
|
{
|
2013-04-13 13:10:28 +00:00
|
|
|
if (!exinfo) {
|
2014-04-02 17:49:56 +00:00
|
|
|
mozilla::IOInterposer::Disable();
|
2013-04-13 13:10:28 +00:00
|
|
|
FreeBreakpadVM();
|
2010-05-04 19:34:55 +00:00
|
|
|
return true;
|
2013-04-13 13:10:28 +00:00
|
|
|
}
|
2010-05-04 19:34:55 +00:00
|
|
|
|
2010-01-11 18:16:20 +00:00
|
|
|
PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)exinfo->ExceptionRecord;
|
|
|
|
switch (e->ExceptionCode) {
|
|
|
|
case STATUS_FLOAT_DENORMAL_OPERAND:
|
|
|
|
case STATUS_FLOAT_DIVIDE_BY_ZERO:
|
|
|
|
case STATUS_FLOAT_INEXACT_RESULT:
|
|
|
|
case STATUS_FLOAT_INVALID_OPERATION:
|
|
|
|
case STATUS_FLOAT_OVERFLOW:
|
|
|
|
case STATUS_FLOAT_STACK_CHECK:
|
|
|
|
case STATUS_FLOAT_UNDERFLOW:
|
|
|
|
case STATUS_FLOAT_MULTIPLE_FAULTS:
|
|
|
|
case STATUS_FLOAT_MULTIPLE_TRAPS:
|
|
|
|
return false; // Don't write minidump, continue exception search
|
|
|
|
}
|
2014-04-02 17:49:56 +00:00
|
|
|
mozilla::IOInterposer::Disable();
|
2013-04-13 13:10:28 +00:00
|
|
|
FreeBreakpadVM();
|
2010-01-11 18:16:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
static bool ShouldReport()
|
|
|
|
{
|
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
|
|
|
const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER_NO_REPORT");
|
2013-02-26 19:03:26 +00:00
|
|
|
if (envvar && *envvar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
envvar = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
|
|
|
|
if (envvar && *envvar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-03-24 21:22:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 13:15:34 +00:00
|
|
|
namespace {
|
|
|
|
bool Filter(void* context) {
|
2014-03-15 06:10:39 +00:00
|
|
|
mozilla::IOInterposer::Disable();
|
2012-07-03 13:15:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsresult SetExceptionHandler(nsIFile* aXREDirectory,
|
2009-04-02 15:41:12 +00:00
|
|
|
bool force/*=false*/)
|
2007-07-25 01:05:55 +00:00
|
|
|
{
|
|
|
|
if (gExceptionHandler)
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
2013-11-29 16:15:39 +00:00
|
|
|
#if !defined(DEBUG) || defined(MOZ_WIDGET_GONK)
|
|
|
|
// In non-debug builds, enable the crash reporter by default, and allow
|
|
|
|
// disabling it with the MOZ_CRASHREPORTER_DISABLE environment variable.
|
|
|
|
// Also enable it by default in debug gonk builds as it is difficult to
|
|
|
|
// set environment on startup.
|
|
|
|
const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER_DISABLE");
|
|
|
|
if (envvar && *envvar && !force)
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
2013-08-30 02:10:57 +00:00
|
|
|
// In debug builds, disable the crash reporter by default, and allow to
|
|
|
|
// enable it with the MOZ_CRASHREPORTER environment variable.
|
|
|
|
const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER");
|
|
|
|
if ((!envvar || !*envvar) && !force)
|
|
|
|
return NS_OK;
|
|
|
|
#endif
|
2007-07-25 01:06:10 +00:00
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
|
|
doReport = false;
|
|
|
|
headlessClient = true;
|
2012-07-27 13:06:38 +00:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
|
|
|
|
doReport = ShouldReport();
|
|
|
|
} else {
|
|
|
|
doReport = false;
|
|
|
|
headlessClient = true;
|
|
|
|
}
|
2012-07-16 23:50:52 +00:00
|
|
|
#else
|
2007-07-25 01:06:02 +00:00
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
2010-03-24 21:22:00 +00:00
|
|
|
doReport = ShouldReport();
|
2012-07-16 23:50:52 +00:00
|
|
|
#endif
|
2007-07-25 01:06:02 +00:00
|
|
|
|
2007-07-25 01:05:58 +00:00
|
|
|
// allocate our strings
|
|
|
|
crashReporterAPIData = new nsCString();
|
|
|
|
NS_ENSURE_TRUE(crashReporterAPIData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2011-10-06 20:33:21 +00:00
|
|
|
NS_ASSERTION(!crashReporterAPILock, "Shouldn't have a lock yet");
|
|
|
|
crashReporterAPILock = new Mutex("crashReporterAPILock");
|
2012-01-25 14:43:52 +00:00
|
|
|
NS_ASSERTION(!notesFieldLock, "Shouldn't have a lock yet");
|
|
|
|
notesFieldLock = new Mutex("notesFieldLock");
|
2011-10-06 20:33:21 +00:00
|
|
|
|
2007-07-25 01:05:59 +00:00
|
|
|
crashReporterAPIData_Hash =
|
|
|
|
new nsDataHashtable<nsCStringHashKey,nsCString>();
|
|
|
|
NS_ENSURE_TRUE(crashReporterAPIData_Hash, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2008-07-27 17:08:03 +00:00
|
|
|
notesField = new nsCString();
|
|
|
|
NS_ENSURE_TRUE(notesField, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
if (!headlessClient) {
|
|
|
|
// locate crashreporter executable
|
|
|
|
nsCOMPtr<nsIFile> exePath;
|
|
|
|
nsresult rv = aXREDirectory->Clone(getter_AddRefs(exePath));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-25 01:06:05 +00:00
|
|
|
|
2007-07-25 01:06:06 +00:00
|
|
|
#if defined(XP_MACOSX)
|
2012-07-16 23:50:52 +00:00
|
|
|
exePath->Append(NS_LITERAL_STRING("crashreporter.app"));
|
|
|
|
exePath->Append(NS_LITERAL_STRING("Contents"));
|
|
|
|
exePath->Append(NS_LITERAL_STRING("MacOS"));
|
2007-07-25 01:06:06 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
exePath->AppendNative(NS_LITERAL_CSTRING(CRASH_REPORTER_FILENAME));
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2007-09-15 13:39:05 +00:00
|
|
|
#ifdef XP_WIN32
|
2012-07-16 23:50:52 +00:00
|
|
|
nsString crashReporterPath_temp;
|
2007-07-25 01:05:58 +00:00
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
exePath->GetPath(crashReporterPath_temp);
|
2013-12-05 09:52:54 +00:00
|
|
|
crashReporterPath = reinterpret_cast<wchar_t*>(ToNewUnicode(crashReporterPath_temp));
|
2010-10-13 18:27:44 +00:00
|
|
|
#elif !defined(__ANDROID__)
|
2012-07-16 23:50:52 +00:00
|
|
|
nsCString crashReporterPath_temp;
|
2007-09-15 13:39:05 +00:00
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
exePath->GetNativePath(crashReporterPath_temp);
|
|
|
|
crashReporterPath = ToNewCString(crashReporterPath_temp);
|
2010-10-13 18:27:44 +00:00
|
|
|
#else
|
2012-07-16 23:50:52 +00:00
|
|
|
// On Android, we launch using the application package name
|
|
|
|
// instead of a filename, so use ANDROID_PACKAGE_NAME to do that here.
|
2013-04-10 00:10:47 +00:00
|
|
|
nsCString package(ANDROID_PACKAGE_NAME "/org.mozilla.gecko.CrashReporter");
|
2012-07-16 23:50:52 +00:00
|
|
|
crashReporterPath = ToNewCString(package);
|
2007-09-15 13:39:05 +00:00
|
|
|
#endif
|
2012-07-16 23:50:52 +00:00
|
|
|
}
|
2007-07-25 01:05:54 +00:00
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
// get temp path to use for minidump path
|
2007-07-25 01:06:04 +00:00
|
|
|
#if defined(XP_WIN32)
|
2007-09-15 13:39:05 +00:00
|
|
|
nsString tempPath;
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
// first figure out buffer size
|
2013-10-10 20:39:09 +00:00
|
|
|
int pathLen = GetTempPath(0, nullptr);
|
2007-07-25 01:05:55 +00:00
|
|
|
if (pathLen == 0)
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
tempPath.SetLength(pathLen);
|
|
|
|
GetTempPath(pathLen, (LPWSTR)tempPath.BeginWriting());
|
2007-07-25 01:06:00 +00:00
|
|
|
#elif defined(XP_MACOSX)
|
2007-09-15 13:39:05 +00:00
|
|
|
nsCString tempPath;
|
2007-07-25 01:06:00 +00:00
|
|
|
FSRef fsRef;
|
|
|
|
OSErr err = FSFindFolder(kUserDomain, kTemporaryFolderType,
|
|
|
|
kCreateFolder, &fsRef);
|
|
|
|
if (err != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-07-25 01:05:54 +00:00
|
|
|
|
2007-07-25 01:06:01 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
OSStatus status = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX);
|
2007-07-25 01:06:00 +00:00
|
|
|
if (status != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-09-15 13:39:05 +00:00
|
|
|
|
|
|
|
tempPath = path;
|
2007-07-25 01:06:01 +00:00
|
|
|
|
2010-10-13 18:27:44 +00:00
|
|
|
#elif defined(__ANDROID__)
|
2012-07-16 23:50:52 +00:00
|
|
|
// GeckoAppShell or Gonk's init.rc sets this in the environment
|
2010-10-13 18:27:44 +00:00
|
|
|
const char *tempenv = PR_GetEnv("TMPDIR");
|
|
|
|
if (!tempenv)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCString tempPath(tempenv);
|
2007-07-25 01:06:04 +00:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
// we assume it's always /tmp on unix systems
|
2007-09-15 13:39:05 +00:00
|
|
|
nsCString tempPath = NS_LITERAL_CSTRING("/tmp/");
|
2007-07-25 01:06:00 +00:00
|
|
|
#else
|
2007-09-15 13:39:05 +00:00
|
|
|
#error "Implement this for your platform"
|
2007-07-25 01:06:00 +00:00
|
|
|
#endif
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2010-10-01 19:56:25 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Initialize spawn attributes, since this calls malloc.
|
|
|
|
if (posix_spawnattr_init(&spawnattr) != 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set spawn attributes.
|
2011-10-11 05:50:08 +00:00
|
|
|
size_t attr_count = ArrayLength(pref_cpu_types);
|
2010-10-01 19:56:25 +00:00
|
|
|
size_t attr_ocount = 0;
|
|
|
|
if (posix_spawnattr_setbinpref_np(&spawnattr,
|
|
|
|
attr_count,
|
|
|
|
pref_cpu_types,
|
|
|
|
&attr_ocount) != 0 ||
|
|
|
|
attr_ocount != attr_count) {
|
|
|
|
posix_spawnattr_destroy(&spawnattr);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-02 17:32:19 +00:00
|
|
|
#ifdef XP_WIN32
|
2013-04-13 13:10:28 +00:00
|
|
|
ReserveBreakpadVM();
|
|
|
|
|
2011-02-02 17:32:19 +00:00
|
|
|
MINIDUMP_TYPE minidump_type = MiniDumpNormal;
|
|
|
|
|
2011-01-12 19:13:52 +00:00
|
|
|
// Try to determine what version of dbghelp.dll we're using.
|
|
|
|
// MinidumpWithFullMemoryInfo is only available in 6.1.x or newer.
|
2011-02-02 17:32:19 +00:00
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
DWORD version_size = GetFileVersionInfoSizeW(L"dbghelp.dll", nullptr);
|
2011-01-12 19:13:52 +00:00
|
|
|
if (version_size > 0) {
|
|
|
|
std::vector<BYTE> buffer(version_size);
|
|
|
|
if (GetFileVersionInfoW(L"dbghelp.dll",
|
2011-01-28 16:28:10 +00:00
|
|
|
0,
|
|
|
|
version_size,
|
|
|
|
&buffer[0])) {
|
2011-01-12 19:13:52 +00:00
|
|
|
UINT len;
|
|
|
|
VS_FIXEDFILEINFO* file_info;
|
|
|
|
VerQueryValue(&buffer[0], L"\\", (void**)&file_info, &len);
|
|
|
|
WORD major = HIWORD(file_info->dwFileVersionMS),
|
|
|
|
minor = LOWORD(file_info->dwFileVersionMS),
|
|
|
|
revision = HIWORD(file_info->dwFileVersionLS);
|
|
|
|
if (major > 6 || (major == 6 && minor > 1) ||
|
|
|
|
(major == 6 && minor == 1 && revision >= 7600)) {
|
|
|
|
minidump_type = MiniDumpWithFullMemoryInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-26 19:03:26 +00:00
|
|
|
|
|
|
|
const char* e = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
|
|
|
|
if (e && *e) {
|
|
|
|
minidump_type = MiniDumpWithFullMemory;
|
|
|
|
}
|
2011-02-02 17:32:19 +00:00
|
|
|
#endif // XP_WIN32
|
2011-01-12 19:13:52 +00:00
|
|
|
|
2012-11-15 22:56:22 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
androidUserSerial = getenv("MOZ_ANDROID_USER_SERIAL_NUMBER");
|
|
|
|
#endif
|
|
|
|
|
2014-01-15 15:03:14 +00:00
|
|
|
// Initialize the flag and mutex used to avoid dump processing
|
|
|
|
// once browser termination has begun.
|
|
|
|
NS_ASSERTION(!dumpSafetyLock, "Shouldn't have a lock yet");
|
|
|
|
// Do not deallocate this lock while it is still possible for
|
|
|
|
// isSafeToDump to be tested on another thread.
|
|
|
|
dumpSafetyLock = new Mutex("dumpSafetyLock");
|
|
|
|
MutexAutoLock lock(*dumpSafetyLock);
|
|
|
|
isSafeToDump = true;
|
|
|
|
|
2007-07-25 01:06:03 +00:00
|
|
|
// now set the exception handler
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
MinidumpDescriptor descriptor(tempPath.get());
|
|
|
|
#endif
|
|
|
|
|
2014-01-29 22:07:35 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
NotePreviousUnhandledExceptionFilter();
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
gExceptionHandler = new google_breakpad::
|
2012-09-25 11:52:54 +00:00
|
|
|
ExceptionHandler(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
descriptor,
|
|
|
|
#else
|
|
|
|
tempPath.get(),
|
|
|
|
#endif
|
|
|
|
|
2010-01-11 18:16:20 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
FPEFilter,
|
|
|
|
#else
|
2012-07-03 13:15:34 +00:00
|
|
|
Filter,
|
2010-01-11 18:16:20 +00:00
|
|
|
#endif
|
2007-07-25 01:06:00 +00:00
|
|
|
MinidumpCallback,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr,
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifdef XP_WIN32
|
2011-01-12 19:13:52 +00:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
|
|
|
minidump_type,
|
2013-10-10 20:39:09 +00:00
|
|
|
(const wchar_t*) nullptr,
|
|
|
|
nullptr);
|
2007-07-25 01:06:13 +00:00
|
|
|
#else
|
2010-08-16 19:05:09 +00:00
|
|
|
true
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifdef XP_MACOSX
|
2013-10-10 20:39:09 +00:00
|
|
|
, nullptr
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
, -1
|
2010-08-16 19:05:09 +00:00
|
|
|
#endif
|
|
|
|
);
|
2010-08-16 19:05:09 +00:00
|
|
|
#endif // XP_WIN32
|
2007-07-25 01:05:55 +00:00
|
|
|
|
|
|
|
if (!gExceptionHandler)
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2011-01-11 22:01:22 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
gExceptionHandler->set_handle_debug_exceptions(true);
|
2012-04-20 09:07:55 +00:00
|
|
|
|
|
|
|
// protect the crash reporter from being unloaded
|
2012-09-25 11:52:54 +00:00
|
|
|
gBlockUnhandledExceptionFilter = true;
|
2012-04-20 09:07:55 +00:00
|
|
|
gKernel32Intercept.Init("kernel32.dll");
|
|
|
|
bool ok = gKernel32Intercept.AddHook("SetUnhandledExceptionFilter",
|
|
|
|
reinterpret_cast<intptr_t>(patched_SetUnhandledExceptionFilter),
|
|
|
|
(void**) &stub_SetUnhandledExceptionFilter);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!ok)
|
|
|
|
printf_stderr ("SetUnhandledExceptionFilter hook failed; crash reporter is vulnerable.\n");
|
|
|
|
#endif
|
2011-01-11 22:01:22 +00:00
|
|
|
#endif
|
|
|
|
|
2007-12-21 21:49:32 +00:00
|
|
|
// store application start time
|
|
|
|
char timeString[32];
|
2013-10-10 20:39:09 +00:00
|
|
|
time_t startupTime = time(nullptr);
|
2010-08-11 14:57:44 +00:00
|
|
|
XP_TTOA(startupTime, timeString, 10);
|
2007-12-21 21:49:32 +00:00
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("StartupTime"),
|
|
|
|
nsDependentCString(timeString));
|
|
|
|
|
2007-07-25 01:06:09 +00:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// On OS X, many testers like to see the OS crash reporting dialog
|
|
|
|
// since it offers immediate stack traces. We allow them to set
|
|
|
|
// a default to pass exceptions to the OS handler.
|
2010-06-21 02:07:59 +00:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("OSCrashReporter"),
|
|
|
|
kCFPreferencesCurrentApplication,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat)
|
|
|
|
showOSCrashReporter = prefValue;
|
2007-07-25 01:06:09 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 19:05:47 +00:00
|
|
|
for (unsigned int i = 0; i < library_mappings.size(); i++) {
|
|
|
|
u_int8_t guid[sizeof(MDGUID)];
|
2013-04-09 12:04:53 +00:00
|
|
|
google_breakpad::FileID::ElfFileIdentifierFromMappedFile((void const *)library_mappings[i].start_address, guid);
|
2010-10-19 19:05:47 +00:00
|
|
|
gExceptionHandler->AddMappingInfo(library_mappings[i].name,
|
|
|
|
guid,
|
|
|
|
library_mappings[i].start_address,
|
|
|
|
library_mappings[i].length,
|
|
|
|
library_mappings[i].file_offset);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-01-24 16:08:51 +00:00
|
|
|
mozalloc_set_oom_abort_handler(AnnotateOOMAllocationSize);
|
|
|
|
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-02 15:41:12 +00:00
|
|
|
bool GetEnabled()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return gExceptionHandler != nullptr;
|
2009-04-02 15:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GetMinidumpPath(nsAString& aPath)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return false;
|
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifndef XP_LINUX
|
2009-04-02 15:41:12 +00:00
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(gExceptionHandler->dump_path().c_str());
|
2012-09-25 11:52:54 +00:00
|
|
|
#else
|
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(
|
|
|
|
gExceptionHandler->minidump_descriptor().directory().c_str());
|
|
|
|
#endif
|
2009-04-02 15:41:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
nsresult SetMinidumpPath(const nsAString& aPath)
|
2007-07-25 01:05:54 +00:00
|
|
|
{
|
2007-07-25 01:05:55 +00:00
|
|
|
if (!gExceptionHandler)
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2013-12-05 09:52:54 +00:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
gExceptionHandler->set_dump_path(char16ptr_t(aPath.BeginReading()));
|
|
|
|
#elif defined(XP_LINUX)
|
2012-09-25 11:52:54 +00:00
|
|
|
gExceptionHandler->set_minidump_descriptor(
|
2013-12-05 09:52:54 +00:00
|
|
|
MinidumpDescriptor(NS_ConvertUTF16toUTF8(aPath).BeginReading()));
|
|
|
|
#else
|
|
|
|
gExceptionHandler->set_dump_path(NS_ConvertUTF16toUTF8(aPath).BeginReading());
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:14 +00:00
|
|
|
static nsresult
|
|
|
|
WriteDataToFile(nsIFile* aFile, const nsACString& data)
|
|
|
|
{
|
2007-09-15 13:39:05 +00:00
|
|
|
PRFileDesc* fd;
|
2012-06-06 02:08:30 +00:00
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 00600, &fd);
|
2007-09-15 13:39:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-25 01:06:14 +00:00
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
if (PR_Write(fd, data.Data(), data.Length()) == -1) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
PR_Close(fd);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
GetFileContents(nsIFile* aFile, nsACString& data)
|
|
|
|
{
|
2007-09-15 13:39:05 +00:00
|
|
|
PRFileDesc* fd;
|
2012-06-06 02:08:30 +00:00
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
|
2007-09-15 13:39:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-25 01:06:14 +00:00
|
|
|
|
|
|
|
rv = NS_OK;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t filesize = PR_Available(fd);
|
2007-07-25 01:06:14 +00:00
|
|
|
if (filesize <= 0) {
|
|
|
|
rv = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.SetLength(filesize);
|
|
|
|
if (PR_Read(fd, data.BeginWriting(), filesize) == -1) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PR_Close(fd);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function typedef for initializing a piece of data that we
|
|
|
|
// don't already have.
|
|
|
|
typedef nsresult (*InitDataFunc)(nsACString&);
|
|
|
|
|
|
|
|
// Attempt to read aFile's contents into aContents, if aFile
|
|
|
|
// does not exist, create it and initialize its contents
|
|
|
|
// by calling aInitFunc for the data.
|
2007-09-26 18:35:21 +00:00
|
|
|
static nsresult
|
2007-09-15 13:39:05 +00:00
|
|
|
GetOrInit(nsIFile* aDir, const nsACString& filename,
|
2007-07-25 01:06:15 +00:00
|
|
|
nsACString& aContents, InitDataFunc aInitFunc)
|
2007-07-25 01:06:14 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists;
|
2007-07-25 01:06:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> dataFile;
|
|
|
|
nsresult rv = aDir->Clone(getter_AddRefs(dataFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 13:39:05 +00:00
|
|
|
rv = dataFile->AppendNative(filename);
|
2007-07-25 01:06:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = dataFile->Exists(&exists);
|
2007-07-25 01:06:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists) {
|
2007-08-29 19:46:00 +00:00
|
|
|
if (aInitFunc) {
|
|
|
|
// get the initial value and write it to the file
|
|
|
|
rv = aInitFunc(aContents);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = WriteDataToFile(dataFile, aContents);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// didn't pass in an init func
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-07-25 01:06:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// just get the file's contents
|
|
|
|
rv = GetFileContents(dataFile, aContents);
|
2007-07-25 01:06:14 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:15 +00:00
|
|
|
return rv;
|
2007-07-25 01:06:14 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:15 +00:00
|
|
|
// Init the "install time" data. We're taking an easy way out here
|
|
|
|
// and just setting this to "the time when this version was first run".
|
|
|
|
static nsresult
|
|
|
|
InitInstallTime(nsACString& aInstallTime)
|
|
|
|
{
|
2013-10-10 20:39:09 +00:00
|
|
|
time_t t = time(nullptr);
|
2007-07-25 01:06:15 +00:00
|
|
|
char buf[16];
|
|
|
|
sprintf(buf, "%ld", t);
|
|
|
|
aInstallTime = buf;
|
2007-09-26 18:35:21 +00:00
|
|
|
|
2007-07-25 01:06:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
// Ensure a directory exists and create it if missing.
|
|
|
|
static nsresult
|
|
|
|
EnsureDirectoryExists(nsIFile* dir)
|
|
|
|
{
|
|
|
|
nsresult rv = dir->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS)) {
|
2014-05-06 19:48:40 +00:00
|
|
|
return rv;
|
2014-02-18 23:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-29 19:46:00 +00:00
|
|
|
// Annotate the crash report with a Unique User ID and time
|
|
|
|
// since install. Also do some prep work for recording
|
|
|
|
// time since last crash, which must be calculated at
|
|
|
|
// crash time.
|
2007-07-25 01:06:14 +00:00
|
|
|
// If any piece of data doesn't exist, initialize it first.
|
2012-06-06 02:08:30 +00:00
|
|
|
nsresult SetupExtraData(nsIFile* aAppDataDirectory,
|
2007-07-25 01:06:15 +00:00
|
|
|
const nsACString& aBuildID)
|
2007-07-25 01:06:14 +00:00
|
|
|
{
|
2007-08-29 19:46:00 +00:00
|
|
|
nsCOMPtr<nsIFile> dataDirectory;
|
|
|
|
nsresult rv = aAppDataDirectory->Clone(getter_AddRefs(dataDirectory));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 13:39:05 +00:00
|
|
|
rv = dataDirectory->AppendNative(NS_LITERAL_CSTRING("Crash Reports"));
|
2007-07-25 01:06:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
EnsureDirectoryExists(dataDirectory);
|
2007-09-04 20:38:38 +00:00
|
|
|
|
2007-09-26 18:35:21 +00:00
|
|
|
#if defined(XP_WIN32)
|
2008-06-24 20:15:35 +00:00
|
|
|
nsAutoString dataDirEnv(NS_LITERAL_STRING("MOZ_CRASHREPORTER_DATA_DIRECTORY="));
|
|
|
|
|
2007-09-26 18:35:21 +00:00
|
|
|
nsAutoString dataDirectoryPath;
|
|
|
|
rv = dataDirectory->GetPath(dataDirectoryPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-06-24 20:15:35 +00:00
|
|
|
dataDirEnv.Append(dataDirectoryPath);
|
|
|
|
|
|
|
|
_wputenv(dataDirEnv.get());
|
2007-09-26 18:35:21 +00:00
|
|
|
#else
|
2008-06-24 20:15:35 +00:00
|
|
|
// Save this path in the environment for the crash reporter application.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString dataDirEnv("MOZ_CRASHREPORTER_DATA_DIRECTORY=");
|
2008-06-24 20:15:35 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString dataDirectoryPath;
|
2007-09-26 18:35:21 +00:00
|
|
|
rv = dataDirectory->GetNativePath(dataDirectoryPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
dataDirEnv.Append(dataDirectoryPath);
|
|
|
|
|
|
|
|
char* env = ToNewCString(dataDirEnv);
|
|
|
|
NS_ENSURE_TRUE(env, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2008-06-24 20:15:35 +00:00
|
|
|
#endif
|
2007-09-26 18:35:21 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString data;
|
2007-08-29 19:46:00 +00:00
|
|
|
if(NS_SUCCEEDED(GetOrInit(dataDirectory,
|
2007-09-15 13:39:05 +00:00
|
|
|
NS_LITERAL_CSTRING("InstallTime") + aBuildID,
|
2007-07-25 01:06:15 +00:00
|
|
|
data, InitInstallTime)))
|
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("InstallTime"), data);
|
|
|
|
|
2007-08-29 19:46:00 +00:00
|
|
|
// this is a little different, since we can't init it with anything,
|
|
|
|
// since it's stored at crash time, and we can't annotate the
|
|
|
|
// crash report with the stored value, since we really want
|
|
|
|
// (now - LastCrash), so we just get a value if it exists,
|
|
|
|
// and store it in a time_t value.
|
2007-09-15 13:39:05 +00:00
|
|
|
if(NS_SUCCEEDED(GetOrInit(dataDirectory, NS_LITERAL_CSTRING("LastCrash"),
|
2013-10-10 20:39:09 +00:00
|
|
|
data, nullptr))) {
|
2007-08-29 19:46:00 +00:00
|
|
|
lastCrashTime = (time_t)atol(data.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// not really the best place to init this, but I have the path I need here
|
|
|
|
nsCOMPtr<nsIFile> lastCrashFile;
|
|
|
|
rv = dataDirectory->Clone(getter_AddRefs(lastCrashFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 13:39:05 +00:00
|
|
|
rv = lastCrashFile->AppendNative(NS_LITERAL_CSTRING("LastCrash"));
|
2007-08-29 19:46:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
memset(lastCrashTimeFilename, 0, sizeof(lastCrashTimeFilename));
|
|
|
|
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
nsAutoString filename;
|
|
|
|
rv = lastCrashFile->GetPath(filename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (filename.Length() < XP_PATH_MAX)
|
|
|
|
wcsncpy(lastCrashTimeFilename, filename.get(), filename.Length());
|
|
|
|
#else
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString filename;
|
2007-08-29 19:46:00 +00:00
|
|
|
rv = lastCrashFile->GetNativePath(filename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (filename.Length() < XP_PATH_MAX)
|
|
|
|
strncpy(lastCrashTimeFilename, filename.get(), filename.Length());
|
|
|
|
#endif
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
if (headlessClient) {
|
|
|
|
nsCOMPtr<nsIFile> markerFile;
|
|
|
|
rv = dataDirectory->Clone(getter_AddRefs(markerFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = markerFile->AppendNative(NS_LITERAL_CSTRING("LastCrashFilename"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
memset(crashMarkerFilename, 0, sizeof(crashMarkerFilename));
|
|
|
|
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
nsAutoString markerFilename;
|
|
|
|
rv = markerFile->GetPath(markerFilename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (markerFilename.Length() < XP_PATH_MAX)
|
|
|
|
wcsncpy(crashMarkerFilename, markerFilename.get(),
|
|
|
|
markerFilename.Length());
|
|
|
|
#else
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString markerFilename;
|
2012-07-16 23:50:52 +00:00
|
|
|
rv = markerFile->GetNativePath(markerFilename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (markerFilename.Length() < XP_PATH_MAX)
|
|
|
|
strncpy(crashMarkerFilename, markerFilename.get(),
|
|
|
|
markerFilename.Length());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-21 02:17:40 +00:00
|
|
|
static void OOPDeinit();
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
nsresult UnsetExceptionHandler()
|
2007-07-25 01:05:54 +00:00
|
|
|
{
|
2014-01-15 15:03:14 +00:00
|
|
|
if (isSafeToDump) {
|
|
|
|
MutexAutoLock lock(*dumpSafetyLock);
|
|
|
|
isSafeToDump = false;
|
|
|
|
}
|
|
|
|
|
2012-04-20 09:07:55 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// allow SetUnhandledExceptionFilter
|
|
|
|
gBlockUnhandledExceptionFilter = false;
|
|
|
|
#endif
|
|
|
|
|
2009-07-23 15:23:19 +00:00
|
|
|
delete gExceptionHandler;
|
|
|
|
|
2007-07-25 01:05:58 +00:00
|
|
|
// do this here in the unlikely case that we succeeded in allocating
|
|
|
|
// our strings but failed to allocate gExceptionHandler.
|
2011-10-06 20:33:21 +00:00
|
|
|
delete crashReporterAPIData_Hash;
|
2012-07-30 14:20:58 +00:00
|
|
|
crashReporterAPIData_Hash = nullptr;
|
2007-10-25 00:37:18 +00:00
|
|
|
|
2011-10-06 20:33:21 +00:00
|
|
|
delete crashReporterAPILock;
|
2012-07-30 14:20:58 +00:00
|
|
|
crashReporterAPILock = nullptr;
|
2007-10-25 00:37:18 +00:00
|
|
|
|
2012-01-25 14:43:52 +00:00
|
|
|
delete notesFieldLock;
|
2012-07-30 14:20:58 +00:00
|
|
|
notesFieldLock = nullptr;
|
2012-01-25 14:43:52 +00:00
|
|
|
|
2011-10-06 20:33:21 +00:00
|
|
|
delete crashReporterAPIData;
|
2012-07-30 14:20:58 +00:00
|
|
|
crashReporterAPIData = nullptr;
|
2011-10-06 20:33:21 +00:00
|
|
|
|
|
|
|
delete notesField;
|
2012-07-30 14:20:58 +00:00
|
|
|
notesField = nullptr;
|
2008-07-27 17:08:03 +00:00
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
delete lastRunCrashID;
|
2012-07-30 14:20:58 +00:00
|
|
|
lastRunCrashID = nullptr;
|
2012-07-16 23:50:52 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
if (pendingDirectory) {
|
|
|
|
NS_Free(pendingDirectory);
|
2012-07-30 14:20:58 +00:00
|
|
|
pendingDirectory = nullptr;
|
2012-07-11 02:20:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:00 +00:00
|
|
|
if (crashReporterPath) {
|
|
|
|
NS_Free(crashReporterPath);
|
2012-07-30 14:20:58 +00:00
|
|
|
crashReporterPath = nullptr;
|
2007-07-25 01:06:00 +00:00
|
|
|
}
|
2007-07-25 01:05:58 +00:00
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
if (eventsDirectory) {
|
|
|
|
NS_Free(eventsDirectory);
|
|
|
|
eventsDirectory = nullptr;
|
|
|
|
}
|
|
|
|
|
2010-10-01 19:56:25 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
posix_spawnattr_destroy(&spawnattr);
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
if (!gExceptionHandler)
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gExceptionHandler = nullptr;
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2010-01-21 02:17:40 +00:00
|
|
|
OOPDeinit();
|
|
|
|
|
2014-01-15 15:03:14 +00:00
|
|
|
delete dumpSafetyLock;
|
|
|
|
dumpSafetyLock = nullptr;
|
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReplaceChar(nsCString& str, const nsACString& character,
|
|
|
|
const nsACString& replacement)
|
|
|
|
{
|
|
|
|
nsCString::const_iterator start, end;
|
2007-09-26 18:35:21 +00:00
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
str.BeginReading(start);
|
|
|
|
str.EndReading(end);
|
|
|
|
|
|
|
|
while (FindInReadable(character, start, end)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t pos = end.size_backward();
|
2007-07-25 01:05:55 +00:00
|
|
|
str.Replace(pos - 1, 1, replacement);
|
|
|
|
|
|
|
|
str.BeginReading(start);
|
|
|
|
start.advance(pos + replacement.Length() - 1);
|
|
|
|
str.EndReading(end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool DoFindInReadable(const nsACString& str, const nsACString& value)
|
2007-07-25 01:05:55 +00:00
|
|
|
{
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
str.BeginReading(start);
|
|
|
|
str.EndReading(end);
|
|
|
|
|
|
|
|
return FindInReadable(value, start, end);
|
|
|
|
}
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashOperator EnumerateEntries(const nsACString& key,
|
|
|
|
nsCString entry,
|
|
|
|
void* userData)
|
2007-07-25 01:05:59 +00:00
|
|
|
{
|
|
|
|
crashReporterAPIData->Append(key + NS_LITERAL_CSTRING("=") + entry +
|
|
|
|
NS_LITERAL_CSTRING("\n"));
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2011-09-30 17:02:52 +00:00
|
|
|
// This function is miscompiled with MSVC 2005/2008 when PGO is on.
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma optimize("", off)
|
|
|
|
#endif
|
2011-06-08 20:21:03 +00:00
|
|
|
static nsresult
|
|
|
|
EscapeAnnotation(const nsACString& key, const nsACString& data, nsCString& escapedData)
|
2007-07-25 01:05:55 +00:00
|
|
|
{
|
|
|
|
if (DoFindInReadable(key, NS_LITERAL_CSTRING("=")) ||
|
|
|
|
DoFindInReadable(key, NS_LITERAL_CSTRING("\n")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-25 01:05:57 +00:00
|
|
|
if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-06-08 20:21:03 +00:00
|
|
|
escapedData = data;
|
2007-09-26 18:35:21 +00:00
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
// escape backslashes
|
|
|
|
ReplaceChar(escapedData, NS_LITERAL_CSTRING("\\"),
|
|
|
|
NS_LITERAL_CSTRING("\\\\"));
|
|
|
|
// escape newlines
|
|
|
|
ReplaceChar(escapedData, NS_LITERAL_CSTRING("\n"),
|
|
|
|
NS_LITERAL_CSTRING("\\n"));
|
2011-06-08 20:21:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-30 17:02:52 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma optimize("", on)
|
|
|
|
#endif
|
2011-06-08 20:21:03 +00:00
|
|
|
|
|
|
|
class DelayedNote
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DelayedNote(const nsACString& aKey, const nsACString& aData)
|
|
|
|
: mKey(aKey), mData(aData), mType(Annotation) {}
|
|
|
|
|
|
|
|
DelayedNote(const nsACString& aData)
|
|
|
|
: mData(aData), mType(AppNote) {}
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2011-06-08 20:21:03 +00:00
|
|
|
void Run()
|
|
|
|
{
|
|
|
|
if (mType == Annotation) {
|
|
|
|
AnnotateCrashReport(mKey, mData);
|
|
|
|
} else {
|
|
|
|
AppendAppNotesToCrashReport(mData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString mKey;
|
|
|
|
nsCString mData;
|
|
|
|
enum AnnotationType { Annotation, AppNote } mType;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
EnqueueDelayedNote(DelayedNote* aNote)
|
|
|
|
{
|
|
|
|
if (!gDelayedAnnotations) {
|
|
|
|
gDelayedAnnotations = new nsTArray<nsAutoPtr<DelayedNote> >();
|
|
|
|
}
|
|
|
|
gDelayedAnnotations->AppendElement(aNote);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCString escapedData;
|
|
|
|
nsresult rv = EscapeAnnotation(key, data, escapedData);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
2011-10-06 20:33:21 +00:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_ERROR("Cannot call AnnotateCrashReport in child processes from non-main thread.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-06-08 20:21:03 +00:00
|
|
|
PCrashReporterChild* reporter = CrashReporterChild::GetCrashReporter();
|
|
|
|
if (!reporter) {
|
|
|
|
EnqueueDelayedNote(new DelayedNote(key, data));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!reporter->SendAnnotateCrashReport(nsCString(key), escapedData))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-06 20:33:21 +00:00
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
|
|
|
|
2012-05-18 17:30:49 +00:00
|
|
|
crashReporterAPIData_Hash->Put(key, escapedData);
|
2007-07-25 01:05:59 +00:00
|
|
|
|
|
|
|
// now rebuild the file contents
|
|
|
|
crashReporterAPIData->Truncate(0);
|
|
|
|
crashReporterAPIData_Hash->EnumerateRead(EnumerateEntries,
|
|
|
|
crashReporterAPIData);
|
|
|
|
|
2007-07-25 01:05:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-07-25 01:05:55 +00:00
|
|
|
|
2012-08-15 17:47:51 +00:00
|
|
|
nsresult SetGarbageCollecting(bool collecting)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
isGarbageCollecting = collecting;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:51:09 +00:00
|
|
|
void SetEventloopNestingLevel(uint32_t level)
|
|
|
|
{
|
|
|
|
eventloopNestingLevel = level;
|
|
|
|
}
|
|
|
|
|
2008-07-27 17:08:03 +00:00
|
|
|
nsresult AppendAppNotesToCrashReport(const nsACString& data)
|
|
|
|
{
|
2010-10-14 01:47:43 +00:00
|
|
|
if (!GetEnabled())
|
2008-07-27 17:08:03 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-06-08 20:21:03 +00:00
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
2012-01-25 14:43:52 +00:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_ERROR("Cannot call AnnotateCrashReport in child processes from non-main thread.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-06-08 20:21:03 +00:00
|
|
|
PCrashReporterChild* reporter = CrashReporterChild::GetCrashReporter();
|
|
|
|
if (!reporter) {
|
|
|
|
EnqueueDelayedNote(new DelayedNote(data));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we don't go through AnnotateCrashReport in the parent process,
|
|
|
|
// we must ensure that the data is escaped and valid before the parent
|
|
|
|
// sees it.
|
|
|
|
nsCString escapedData;
|
|
|
|
nsresult rv = EscapeAnnotation(NS_LITERAL_CSTRING("Notes"), data, escapedData);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!reporter->SendAppendAppNotes(escapedData))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-25 14:43:52 +00:00
|
|
|
MutexAutoLock lock(*notesFieldLock);
|
|
|
|
|
2008-07-27 17:08:03 +00:00
|
|
|
notesField->Append(data);
|
|
|
|
return AnnotateCrashReport(NS_LITERAL_CSTRING("Notes"), *notesField);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if found, false if not found.
|
|
|
|
bool GetAnnotation(const nsACString& key, nsACString& data)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
2009-04-02 15:41:12 +00:00
|
|
|
return false;
|
2008-07-27 17:08:03 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString entry;
|
2008-07-27 17:08:03 +00:00
|
|
|
if (!crashReporterAPIData_Hash->Get(key, &entry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
data = entry;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-08 00:31:01 +00:00
|
|
|
nsresult RegisterAppMemory(void* ptr, size_t length)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
#if defined(XP_LINUX) || defined(XP_WIN32)
|
|
|
|
gExceptionHandler->RegisterAppMemory(ptr, length);
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult UnregisterAppMemory(void* ptr)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
#if defined(XP_LINUX) || defined(XP_WIN32)
|
|
|
|
gExceptionHandler->UnregisterAppMemory(ptr);
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-04-02 15:41:12 +00:00
|
|
|
bool GetServerURL(nsACString& aServerURL)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return GetAnnotation(NS_LITERAL_CSTRING("ServerURL"), aServerURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetServerURL(const nsACString& aServerURL)
|
|
|
|
{
|
|
|
|
// store server URL with the API data
|
|
|
|
// the client knows to handle this specially
|
|
|
|
return AnnotateCrashReport(NS_LITERAL_CSTRING("ServerURL"),
|
|
|
|
aServerURL);
|
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:05 +00:00
|
|
|
nsresult
|
2008-07-27 17:08:03 +00:00
|
|
|
SetRestartArgs(int argc, char** argv)
|
2007-07-25 01:06:05 +00:00
|
|
|
{
|
2007-07-25 01:06:10 +00:00
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-25 01:06:05 +00:00
|
|
|
int i;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString envVar;
|
2007-07-25 01:06:06 +00:00
|
|
|
char *env;
|
2012-06-20 15:41:34 +00:00
|
|
|
char *argv0 = getenv("MOZ_APP_LAUNCHER");
|
2007-07-25 01:06:05 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
2012-06-20 15:41:34 +00:00
|
|
|
if (argv0 && i == 0) {
|
|
|
|
// Is there a request to suppress default binary launcher?
|
|
|
|
envVar += argv0;
|
|
|
|
} else {
|
2007-12-21 19:40:39 +00:00
|
|
|
envVar += argv[i];
|
|
|
|
}
|
2007-07-25 01:06:06 +00:00
|
|
|
|
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
if (!env)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2007-07-25 01:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the arg list is terminated
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
|
|
|
|
2007-07-25 01:06:06 +00:00
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
if (!env)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2007-07-25 01:06:05 +00:00
|
|
|
|
2007-07-25 01:06:12 +00:00
|
|
|
// make sure we save the info in XUL_APP_FILE for the reporter
|
|
|
|
const char *appfile = PR_GetEnv("XUL_APP_FILE");
|
|
|
|
if (appfile && *appfile) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_XUL_APP_FILE=";
|
|
|
|
envVar += appfile;
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
PR_SetEnv(env);
|
|
|
|
}
|
|
|
|
|
2007-07-25 01:06:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-09 02:40:47 +00:00
|
|
|
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
return gExceptionHandler->WriteMinidumpForException(aExceptionInfo) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-05 18:29:51 +00:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
bool WriteMinidumpForSigInfo(int signo, siginfo_t* info, void* uc)
|
|
|
|
{
|
|
|
|
return gExceptionHandler->HandleSignal(signo, info, uc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-28 04:41:38 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
nsresult AppendObjCExceptionInfoToAppNotes(void *inException)
|
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString excString;
|
2008-08-28 04:41:38 +00:00
|
|
|
GetObjCExceptionInfo(inException, excString);
|
|
|
|
AppendAppNotesToCrashReport(excString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-10 01:05:31 +00:00
|
|
|
/*
|
|
|
|
* Combined code to get/set the crash reporter submission pref on
|
|
|
|
* different platforms.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static nsresult PrefSubmitReports(bool* aSubmitReports, bool writePref)
|
2010-02-10 01:05:31 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
/*
|
|
|
|
* NOTE! This needs to stay in sync with the preference checking code
|
|
|
|
* in toolkit/crashreporter/client/crashreporter_win.cpp
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appinfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString appVendor, appName;
|
2010-02-10 01:05:31 +00:00
|
|
|
rv = appinfo->GetVendor(appVendor);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = appinfo->GetName(appName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey
|
|
|
|
(do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString regPath;
|
2010-02-10 01:05:31 +00:00
|
|
|
|
|
|
|
regPath.AppendLiteral("Software\\");
|
2012-07-10 22:31:03 +00:00
|
|
|
|
|
|
|
// We need to ensure the registry keys are created so we can properly
|
|
|
|
// write values to it
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
// Create appVendor key
|
|
|
|
if(!appVendor.IsEmpty()) {
|
|
|
|
regPath.Append(appVendor);
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
|
|
|
regPath.AppendLiteral("\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create appName key
|
|
|
|
regPath.Append(appName);
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
|
|
|
regPath.AppendLiteral("\\");
|
|
|
|
|
|
|
|
// Create Crash Reporter key
|
|
|
|
regPath.AppendLiteral("Crash Reporter");
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
2012-07-10 22:31:03 +00:00
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
2010-02-10 01:05:31 +00:00
|
|
|
|
|
|
|
// If we're saving the pref value, just write it to ROOT_KEY_CURRENT_USER
|
|
|
|
// and we're done.
|
|
|
|
if (writePref) {
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t value = *aSubmitReports ? 1 : 0;
|
2010-02-10 01:05:31 +00:00
|
|
|
rv = regKey->WriteIntValue(NS_LITERAL_STRING("SubmitCrashReport"), value);
|
|
|
|
regKey->Close();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're reading the pref value, so we need to first look under
|
|
|
|
// ROOT_KEY_LOCAL_MACHINE to see if it's set there, and then fall back to
|
|
|
|
// ROOT_KEY_CURRENT_USER. If it's not set in either place, the pref defaults
|
|
|
|
// to "true".
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t value;
|
2010-02-10 01:05:31 +00:00
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = regKey->ReadIntValue(NS_LITERAL_STRING("SubmitCrashReport"), &value);
|
|
|
|
regKey->Close();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aSubmitReports = !!value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 01:05:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = regKey->ReadIntValue(NS_LITERAL_STRING("SubmitCrashReport"), &value);
|
|
|
|
// default to true on failure
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
value = 1;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
regKey->Close();
|
|
|
|
|
|
|
|
*aSubmitReports = !!value;
|
|
|
|
return NS_OK;
|
2010-02-10 02:11:08 +00:00
|
|
|
#elif defined(XP_MACOSX)
|
2010-06-21 02:07:59 +00:00
|
|
|
rv = NS_OK;
|
|
|
|
if (writePref) {
|
|
|
|
CFPropertyListRef cfValue = (CFPropertyListRef)(*aSubmitReports ? kCFBooleanTrue : kCFBooleanFalse);
|
|
|
|
::CFPreferencesSetAppValue(CFSTR("submitReport"),
|
|
|
|
cfValue,
|
|
|
|
reporterClientAppID);
|
|
|
|
if (!::CFPreferencesAppSynchronize(reporterClientAppID))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aSubmitReports = true;
|
2010-06-21 02:07:59 +00:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("submitReport"),
|
|
|
|
reporterClientAppID,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat)
|
|
|
|
*aSubmitReports = !!prefValue;
|
|
|
|
}
|
|
|
|
return rv;
|
2010-02-10 01:05:31 +00:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
/*
|
|
|
|
* NOTE! This needs to stay in sync with the preference checking code
|
|
|
|
* in toolkit/crashreporter/client/crashreporter_linux.cpp
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIFile> reporterINI;
|
|
|
|
rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(reporterINI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
reporterINI->AppendNative(NS_LITERAL_CSTRING("Crash Reports"));
|
|
|
|
reporterINI->AppendNative(NS_LITERAL_CSTRING("crashreporter.ini"));
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists;
|
2010-02-10 01:05:31 +00:00
|
|
|
rv = reporterINI->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!exists) {
|
|
|
|
if (!writePref) {
|
|
|
|
// If reading the pref, default to true if .ini doesn't exist.
|
2011-10-17 14:59:28 +00:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 01:05:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Create the file so the INI processor can write to it.
|
|
|
|
rv = reporterINI->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIINIParserFactory> iniFactory =
|
|
|
|
do_GetService("@mozilla.org/xpcom/ini-processor-factory;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIINIParser> iniParser;
|
2012-06-06 02:08:30 +00:00
|
|
|
rv = iniFactory->CreateINIParser(reporterINI,
|
2010-02-10 01:05:31 +00:00
|
|
|
getter_AddRefs(iniParser));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If we're writing the pref, just set and we're done.
|
|
|
|
if (writePref) {
|
|
|
|
nsCOMPtr<nsIINIParserWriter> iniWriter = do_QueryInterface(iniParser);
|
|
|
|
NS_ENSURE_TRUE(iniWriter, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = iniWriter->SetString(NS_LITERAL_CSTRING("Crash Reporter"),
|
|
|
|
NS_LITERAL_CSTRING("SubmitReport"),
|
|
|
|
*aSubmitReports ? NS_LITERAL_CSTRING("1") :
|
|
|
|
NS_LITERAL_CSTRING("0"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-10-10 20:39:09 +00:00
|
|
|
rv = iniWriter->WriteFile(nullptr, 0);
|
2010-02-10 01:05:31 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString submitReportValue;
|
2010-02-10 01:05:31 +00:00
|
|
|
rv = iniParser->GetString(NS_LITERAL_CSTRING("Crash Reporter"),
|
|
|
|
NS_LITERAL_CSTRING("SubmitReport"),
|
|
|
|
submitReportValue);
|
|
|
|
|
|
|
|
// Default to "true" if the pref can't be found.
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 14:59:28 +00:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 01:05:31 +00:00
|
|
|
else if (submitReportValue.EqualsASCII("0"))
|
2011-10-17 14:59:28 +00:00
|
|
|
*aSubmitReports = false;
|
2010-02-10 01:05:31 +00:00
|
|
|
else
|
2011-10-17 14:59:28 +00:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 01:05:31 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult GetSubmitReports(bool* aSubmitReports)
|
2010-02-10 01:05:31 +00:00
|
|
|
{
|
|
|
|
return PrefSubmitReports(aSubmitReports, false);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult SetSubmitReports(bool aSubmitReports)
|
2010-02-10 01:05:31 +00:00
|
|
|
{
|
2011-10-03 20:26:08 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!obsServ) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = PrefSubmitReports(&aSubmitReports, true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
obsServ->NotifyObservers(nullptr, "submit-reports-pref-changed", nullptr);
|
2011-10-03 20:26:08 +00:00
|
|
|
return NS_OK;
|
2010-02-10 01:05:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-06 19:48:40 +00:00
|
|
|
static void
|
|
|
|
SetCrashEventsDir(nsIFile* aDir)
|
2014-02-18 23:58:03 +00:00
|
|
|
{
|
2014-05-06 19:48:40 +00:00
|
|
|
nsCOMPtr<nsIFile> eventsDir = aDir;
|
2014-02-18 23:58:03 +00:00
|
|
|
|
|
|
|
const char *env = PR_GetEnv("CRASHES_EVENTS_DIR");
|
2014-05-06 19:48:40 +00:00
|
|
|
if (env && *env) {
|
|
|
|
NS_NewNativeLocalFile(nsDependentCString(env),
|
|
|
|
false, getter_AddRefs(eventsDir));
|
2014-02-18 23:58:03 +00:00
|
|
|
EnsureDirectoryExists(eventsDir);
|
2014-05-06 19:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eventsDirectory) {
|
|
|
|
NS_Free(eventsDirectory);
|
2014-02-18 23:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsString path;
|
|
|
|
eventsDir->GetPath(path);
|
|
|
|
eventsDirectory = reinterpret_cast<wchar_t*>(ToNewUnicode(path));
|
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
eventsDir->GetNativePath(path);
|
|
|
|
eventsDirectory = ToNewCString(path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-06 19:48:40 +00:00
|
|
|
void
|
|
|
|
SetProfileDirectory(nsIFile* aDir)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> dir;
|
|
|
|
aDir->Clone(getter_AddRefs(dir));
|
|
|
|
|
|
|
|
dir->Append(NS_LITERAL_STRING("crashes"));
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
dir->Append(NS_LITERAL_STRING("events"));
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
SetCrashEventsDir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetUserAppDataDirectory(nsIFile* aDir)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> dir;
|
|
|
|
aDir->Clone(getter_AddRefs(dir));
|
|
|
|
|
|
|
|
dir->Append(NS_LITERAL_STRING("Crash Reports"));
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
dir->Append(NS_LITERAL_STRING("events"));
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
SetCrashEventsDir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateCrashEventsDir()
|
|
|
|
{
|
|
|
|
const char *env = PR_GetEnv("CRASHES_EVENTS_DIR");
|
|
|
|
if (env && *env) {
|
|
|
|
SetCrashEventsDir(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> eventsDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory("ProfD", getter_AddRefs(eventsDir));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetProfileDirectory(eventsDir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(eventsDir));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetUserAppDataDirectory(eventsDir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Couldn't get the user appdata directory. Crash events may not be produced.");
|
|
|
|
}
|
|
|
|
|
2014-02-18 23:58:03 +00:00
|
|
|
bool GetCrashEventsDir(nsAString& aPath)
|
|
|
|
{
|
|
|
|
if (!eventsDirectory) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(eventsDirectory);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
static void
|
|
|
|
FindPendingDir()
|
|
|
|
{
|
|
|
|
if (pendingDirectory)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> pendingDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(pendingDir));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't get the user appdata directory, crash dumps will go in an unusual location");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pendingDir->Append(NS_LITERAL_STRING("Crash Reports"));
|
|
|
|
pendingDir->Append(NS_LITERAL_STRING("pending"));
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsString path;
|
|
|
|
pendingDir->GetPath(path);
|
2013-12-05 09:52:54 +00:00
|
|
|
pendingDirectory = reinterpret_cast<wchar_t*>(ToNewUnicode(path));
|
2012-07-16 23:50:52 +00:00
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
pendingDir->GetNativePath(path);
|
|
|
|
pendingDirectory = ToNewCString(path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
// The "pending" dir is Crash Reports/pending, from which minidumps
|
2012-07-11 02:20:05 +00:00
|
|
|
// can be submitted. Because this method may be called off the main thread,
|
|
|
|
// we store the pending directory as a path.
|
2010-03-24 21:22:01 +00:00
|
|
|
static bool
|
2012-06-06 02:08:30 +00:00
|
|
|
GetPendingDir(nsIFile** dir)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
2012-07-11 02:20:05 +00:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
|
|
|
if (!pendingDirectory) {
|
2010-03-24 21:22:01 +00:00
|
|
|
return false;
|
2012-07-11 02:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> pending = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
2012-07-13 17:43:17 +00:00
|
|
|
if (!pending) {
|
|
|
|
NS_WARNING("Can't set up pending directory during shutdown.");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-11 02:20:05 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
pending->InitWithPath(nsDependentString(pendingDirectory));
|
|
|
|
#else
|
|
|
|
pending->InitWithNativePath(nsDependentCString(pendingDirectory));
|
|
|
|
#endif
|
|
|
|
pending.swap(*dir);
|
2010-03-24 21:22:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-02-10 01:05:31 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
// The "limbo" dir is where minidumps go to wait for something else to
|
|
|
|
// use them. If we're |ShouldReport()|, then the "something else" is
|
|
|
|
// a minidump submitter, and they're coming from the
|
|
|
|
// Crash Reports/pending/ dir. Otherwise, we don't know what the
|
|
|
|
// "somthing else" is, but the minidumps stay in [profile]/minidumps/
|
|
|
|
// limbo.
|
|
|
|
static bool
|
2012-06-06 02:08:30 +00:00
|
|
|
GetMinidumpLimboDir(nsIFile** dir)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
|
|
|
if (ShouldReport()) {
|
|
|
|
return GetPendingDir(dir);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifndef XP_LINUX
|
2010-03-24 21:22:01 +00:00
|
|
|
CreateFileFromPath(gExceptionHandler->dump_path(), dir);
|
2012-09-25 11:52:54 +00:00
|
|
|
#else
|
|
|
|
CreateFileFromPath(gExceptionHandler->minidump_descriptor().directory(),
|
|
|
|
dir);
|
|
|
|
#endif
|
2013-10-10 20:39:09 +00:00
|
|
|
return nullptr != *dir;
|
2010-03-24 21:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-06 02:08:30 +00:00
|
|
|
GetMinidumpForID(const nsAString& id, nsIFile** minidump)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
|
|
|
if (!GetMinidumpLimboDir(minidump))
|
|
|
|
return false;
|
|
|
|
(*minidump)->Append(id + NS_LITERAL_STRING(".dmp"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-06 02:08:30 +00:00
|
|
|
GetIDFromMinidump(nsIFile* minidump, nsAString& id)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(minidump->GetLeafName(id))) {
|
|
|
|
id.Replace(id.Length() - 4, 4, NS_LITERAL_STRING(""));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-06 02:08:30 +00:00
|
|
|
GetExtraFileForID(const nsAString& id, nsIFile** extraFile)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
|
|
|
if (!GetMinidumpLimboDir(extraFile))
|
|
|
|
return false;
|
|
|
|
(*extraFile)->Append(id + NS_LITERAL_STRING(".extra"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-06 02:08:30 +00:00
|
|
|
GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
|
|
|
nsAutoString leafName;
|
|
|
|
nsresult rv = minidump->GetLeafName(leafName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> extraF;
|
|
|
|
rv = minidump->Clone(getter_AddRefs(extraF));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
leafName.Replace(leafName.Length() - 3, 3,
|
|
|
|
NS_LITERAL_STRING("extra"));
|
2012-06-06 02:08:30 +00:00
|
|
|
rv = extraF->SetLeafName(leafName);
|
2010-03-24 21:22:01 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
*extraFile = nullptr;
|
2012-06-06 02:08:30 +00:00
|
|
|
extraF.swap(*extraFile);
|
2010-03-24 21:22:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AppendExtraData(const nsAString& id, const AnnotationTable& data)
|
|
|
|
{
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> extraFile;
|
2010-03-24 21:22:01 +00:00
|
|
|
if (!GetExtraFileForID(id, getter_AddRefs(extraFile)))
|
|
|
|
return false;
|
|
|
|
return AppendExtraData(extraFile, data);
|
|
|
|
}
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helpers for AppendExtraData()
|
|
|
|
//
|
2010-03-24 21:22:00 +00:00
|
|
|
struct Blacklist {
|
2013-10-10 20:39:09 +00:00
|
|
|
Blacklist() : mItems(nullptr), mLen(0) { }
|
2010-03-24 21:22:00 +00:00
|
|
|
Blacklist(const char** items, int len) : mItems(items), mLen(len) { }
|
|
|
|
|
|
|
|
bool Contains(const nsACString& key) const {
|
|
|
|
for (int i = 0; i < mLen; ++i)
|
|
|
|
if (key.EqualsASCII(mItems[i]))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char** mItems;
|
|
|
|
const int mLen;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumerateAnnotationsContext {
|
|
|
|
const Blacklist& blacklist;
|
|
|
|
PRFileDesc* fd;
|
|
|
|
};
|
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
static void
|
|
|
|
WriteAnnotation(PRFileDesc* fd, const nsACString& key, const nsACString& value)
|
|
|
|
{
|
|
|
|
PR_Write(fd, key.BeginReading(), key.Length());
|
|
|
|
PR_Write(fd, "=", 1);
|
|
|
|
PR_Write(fd, value.BeginReading(), value.Length());
|
|
|
|
PR_Write(fd, "\n", 1);
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumerateAnnotations(const nsACString& key,
|
|
|
|
nsCString entry,
|
|
|
|
void* userData)
|
2010-01-14 22:38:00 +00:00
|
|
|
{
|
2010-03-24 21:22:00 +00:00
|
|
|
EnumerateAnnotationsContext* ctx =
|
|
|
|
static_cast<EnumerateAnnotationsContext*>(userData);
|
|
|
|
const Blacklist& blacklist = ctx->blacklist;
|
2010-01-14 22:38:00 +00:00
|
|
|
|
|
|
|
// skip entries in the blacklist
|
2010-03-24 21:22:00 +00:00
|
|
|
if (blacklist.Contains(key))
|
2010-01-14 22:38:00 +00:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
WriteAnnotation(ctx->fd, key, entry);
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-01-14 22:38:00 +00:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
static bool
|
2012-06-06 02:08:30 +00:00
|
|
|
WriteExtraData(nsIFile* extraFile,
|
2010-03-24 21:22:01 +00:00
|
|
|
const AnnotationTable& data,
|
|
|
|
const Blacklist& blacklist,
|
|
|
|
bool writeCrashTime=false,
|
|
|
|
bool truncate=false)
|
2010-03-24 21:22:00 +00:00
|
|
|
{
|
2010-03-24 21:22:01 +00:00
|
|
|
PRFileDesc* fd;
|
2012-08-09 07:09:40 +00:00
|
|
|
int truncOrAppend = truncate ? PR_TRUNCATE : PR_APPEND;
|
2010-03-24 21:22:01 +00:00
|
|
|
nsresult rv =
|
|
|
|
extraFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | truncOrAppend,
|
|
|
|
0600, &fd);
|
2010-03-24 21:22:00 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
EnumerateAnnotationsContext ctx = { blacklist, fd };
|
|
|
|
data.EnumerateRead(EnumerateAnnotations, &ctx);
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
if (writeCrashTime) {
|
2013-10-10 20:39:09 +00:00
|
|
|
time_t crashTime = time(nullptr);
|
2010-03-24 21:22:01 +00:00
|
|
|
char crashTimeString[32];
|
|
|
|
XP_TTOA(crashTime, crashTimeString, 10);
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
WriteAnnotation(fd,
|
|
|
|
nsDependentCString("CrashTime"),
|
|
|
|
nsDependentCString(crashTimeString));
|
|
|
|
}
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
PR_Close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
bool
|
2012-06-06 02:08:30 +00:00
|
|
|
AppendExtraData(nsIFile* extraFile, const AnnotationTable& data)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
|
|
|
return WriteExtraData(extraFile, data, Blacklist());
|
|
|
|
}
|
2010-03-24 21:22:00 +00:00
|
|
|
|
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
static bool
|
2012-06-06 02:08:30 +00:00
|
|
|
WriteExtraForMinidump(nsIFile* minidump,
|
2010-03-24 21:22:01 +00:00
|
|
|
const Blacklist& blacklist,
|
2012-06-06 02:08:30 +00:00
|
|
|
nsIFile** extraFile)
|
2010-03-24 21:22:01 +00:00
|
|
|
{
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> extra;
|
2010-03-24 21:22:01 +00:00
|
|
|
if (!GetExtraFileForMinidump(minidump, getter_AddRefs(extra)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!WriteExtraData(extra, *crashReporterAPIData_Hash,
|
|
|
|
blacklist,
|
|
|
|
true /*write crash time*/,
|
|
|
|
true /*truncate*/))
|
|
|
|
return false;
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
*extraFile = nullptr;
|
2010-03-24 21:22:00 +00:00
|
|
|
extra.swap(*extraFile);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
// It really only makes sense to call this function when
|
|
|
|
// ShouldReport() is true.
|
2010-02-10 01:05:31 +00:00
|
|
|
static bool
|
|
|
|
MoveToPending(nsIFile* dumpFile, nsIFile* extraFile)
|
|
|
|
{
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> pendingDir;
|
2010-03-24 21:22:01 +00:00
|
|
|
if (!GetPendingDir(getter_AddRefs(pendingDir)))
|
|
|
|
return false;
|
2010-02-10 01:05:31 +00:00
|
|
|
|
2012-09-08 17:20:59 +00:00
|
|
|
if (NS_FAILED(dumpFile->MoveTo(pendingDir, EmptyString()))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extraFile && NS_FAILED(extraFile->MoveTo(pendingDir, EmptyString()))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-02-10 01:05:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 21:14:38 +00:00
|
|
|
static void
|
|
|
|
OnChildProcessDumpRequested(void* aContext,
|
2010-08-16 19:05:09 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
const ClientInfo& aClientInfo,
|
|
|
|
const xpstring& aFilePath
|
|
|
|
#else
|
2010-01-12 21:14:38 +00:00
|
|
|
const ClientInfo* aClientInfo,
|
2010-08-16 19:05:09 +00:00
|
|
|
const xpstring* aFilePath
|
|
|
|
#endif
|
|
|
|
)
|
2010-01-12 21:14:38 +00:00
|
|
|
{
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
nsCOMPtr<nsIFile> extraFile;
|
2010-01-14 22:38:00 +00:00
|
|
|
|
2014-01-15 15:03:14 +00:00
|
|
|
// Hold the mutex until the current dump request is complete, to
|
|
|
|
// prevent UnsetExceptionHandler() from pulling the rug out from
|
|
|
|
// under us.
|
|
|
|
MutexAutoLock lock(*dumpSafetyLock);
|
|
|
|
if (!isSafeToDump)
|
|
|
|
return;
|
|
|
|
|
2010-08-16 19:05:09 +00:00
|
|
|
CreateFileFromPath(
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
aFilePath,
|
|
|
|
#else
|
|
|
|
*aFilePath,
|
|
|
|
#endif
|
|
|
|
getter_AddRefs(minidump));
|
2010-01-14 22:38:00 +00:00
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
if (!WriteExtraForMinidump(minidump,
|
|
|
|
Blacklist(kSubprocessBlacklist,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(kSubprocessBlacklist)),
|
2010-03-24 21:22:00 +00:00
|
|
|
getter_AddRefs(extraFile)))
|
2010-01-14 22:38:00 +00:00
|
|
|
return;
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
if (ShouldReport())
|
|
|
|
MoveToPending(minidump, extraFile);
|
2010-02-10 01:05:31 +00:00
|
|
|
|
2010-01-14 22:38:00 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t pid =
|
2010-08-16 19:05:09 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
aClientInfo.pid();
|
|
|
|
#else
|
|
|
|
aClientInfo->pid();
|
|
|
|
#endif
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
bool runCallback;
|
|
|
|
#endif
|
2012-07-02 18:55:23 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2012-07-11 02:20:05 +00:00
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(pid);
|
|
|
|
MOZ_ASSERT(!pd->minidump);
|
|
|
|
pd->minidump = minidump;
|
|
|
|
pd->sequence = ++crashSequence;
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-10-10 20:39:09 +00:00
|
|
|
runCallback = nullptr != pd->callback;
|
2012-07-11 02:20:05 +00:00
|
|
|
#endif
|
2012-07-02 18:55:23 +00:00
|
|
|
}
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2012-07-11 02:20:05 +00:00
|
|
|
if (runCallback)
|
|
|
|
NS_DispatchToMainThread(new ReportInjectedCrash(pid));
|
2012-07-02 18:55:23 +00:00
|
|
|
#endif
|
2010-01-14 22:38:00 +00:00
|
|
|
}
|
2010-01-12 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
OOPInitialized()
|
|
|
|
{
|
2013-10-10 20:39:09 +00:00
|
|
|
return pidToMinidump != nullptr;
|
2010-01-12 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifdef XP_MACOSX
|
2012-07-03 13:15:34 +00:00
|
|
|
static bool ChildFilter(void *context) {
|
2014-03-15 06:10:39 +00:00
|
|
|
mozilla::IOInterposer::Disable();
|
2012-07-03 13:15:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2012-07-03 13:15:34 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
void
|
2010-01-12 21:14:38 +00:00
|
|
|
OOPInit()
|
|
|
|
{
|
2012-07-11 02:20:05 +00:00
|
|
|
if (OOPInitialized())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-10-10 20:39:09 +00:00
|
|
|
NS_ABORT_IF_FALSE(gExceptionHandler != nullptr,
|
2010-01-12 21:14:38 +00:00
|
|
|
"attempt to initialize OOP crash reporter before in-process crashreporter!");
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2010-01-13 15:44:10 +00:00
|
|
|
childCrashNotifyPipe =
|
|
|
|
PR_smprintf("\\\\.\\pipe\\gecko-crash-server-pipe.%i",
|
|
|
|
static_cast<int>(::GetCurrentProcessId()));
|
2010-01-12 21:14:38 +00:00
|
|
|
|
|
|
|
const std::wstring dumpPath = gExceptionHandler->dump_path();
|
|
|
|
crashServer = new CrashGenerationServer(
|
2010-01-13 15:44:10 +00:00
|
|
|
NS_ConvertASCIItoUTF16(childCrashNotifyPipe).get(),
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, // default security attributes
|
|
|
|
nullptr, nullptr, // we don't care about process connect here
|
|
|
|
OnChildProcessDumpRequested, nullptr,
|
|
|
|
nullptr, nullptr, // we don't care about process exit here
|
|
|
|
nullptr, nullptr, // we don't care about upload request here
|
2010-01-12 21:14:38 +00:00
|
|
|
true, // automatically generate dumps
|
|
|
|
&dumpPath);
|
|
|
|
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
if (!CrashGenerationServer::CreateReportChannel(&serverSocketFd,
|
|
|
|
&clientSocketFd))
|
|
|
|
NS_RUNTIMEABORT("can't create crash reporter socketpair()");
|
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
const std::string dumpPath =
|
|
|
|
gExceptionHandler->minidump_descriptor().directory();
|
2010-01-12 21:14:38 +00:00
|
|
|
crashServer = new CrashGenerationServer(
|
|
|
|
serverSocketFd,
|
2013-10-10 20:39:09 +00:00
|
|
|
OnChildProcessDumpRequested, nullptr,
|
|
|
|
nullptr, nullptr, // we don't care about process exit here
|
2012-09-25 11:52:54 +00:00
|
|
|
true,
|
2010-01-12 21:14:38 +00:00
|
|
|
&dumpPath);
|
2010-08-16 19:05:09 +00:00
|
|
|
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
childCrashNotifyPipe =
|
|
|
|
PR_smprintf("gecko-crash-server-pipe.%i",
|
|
|
|
static_cast<int>(getpid()));
|
|
|
|
const std::string dumpPath = gExceptionHandler->dump_path();
|
|
|
|
|
|
|
|
crashServer = new CrashGenerationServer(
|
|
|
|
childCrashNotifyPipe,
|
2012-07-03 13:15:34 +00:00
|
|
|
ChildFilter,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr,
|
|
|
|
OnChildProcessDumpRequested, nullptr,
|
|
|
|
nullptr, nullptr,
|
2010-08-16 19:05:09 +00:00
|
|
|
true, // automatically generate dumps
|
|
|
|
dumpPath);
|
2010-01-12 21:14:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!crashServer->Start())
|
|
|
|
NS_RUNTIMEABORT("can't start crash reporter server()");
|
2010-01-14 22:38:00 +00:00
|
|
|
|
|
|
|
pidToMinidump = new ChildMinidumpMap();
|
|
|
|
|
|
|
|
dumpMapLock = new Mutex("CrashReporter::dumpMapLock");
|
2012-07-11 02:20:05 +00:00
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
FindPendingDir();
|
2014-02-18 23:58:03 +00:00
|
|
|
UpdateCrashEventsDir();
|
2010-01-12 21:14:38 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 02:17:40 +00:00
|
|
|
static void
|
|
|
|
OOPDeinit()
|
|
|
|
{
|
|
|
|
if (!OOPInitialized()) {
|
|
|
|
NS_WARNING("OOPDeinit() without successful OOPInit()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-02 18:55:23 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
if (sInjectorThread) {
|
|
|
|
sInjectorThread->Shutdown();
|
|
|
|
NS_RELEASE(sInjectorThread);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-21 02:17:40 +00:00
|
|
|
delete crashServer;
|
2013-10-10 20:39:09 +00:00
|
|
|
crashServer = nullptr;
|
2010-01-21 02:17:40 +00:00
|
|
|
|
|
|
|
delete dumpMapLock;
|
2013-10-10 20:39:09 +00:00
|
|
|
dumpMapLock = nullptr;
|
2010-01-21 02:17:40 +00:00
|
|
|
|
|
|
|
delete pidToMinidump;
|
2013-10-10 20:39:09 +00:00
|
|
|
pidToMinidump = nullptr;
|
2010-01-21 02:17:40 +00:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
PR_Free(childCrashNotifyPipe);
|
2013-10-10 20:39:09 +00:00
|
|
|
childCrashNotifyPipe = nullptr;
|
2010-01-21 02:17:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-16 19:05:09 +00:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-12 21:14:38 +00:00
|
|
|
// Parent-side API for children
|
2010-01-13 15:44:10 +00:00
|
|
|
const char*
|
2010-01-12 21:14:38 +00:00
|
|
|
GetChildNotificationPipe()
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
2010-01-13 15:44:10 +00:00
|
|
|
return kNullNotifyPipe;
|
2010-01-12 21:14:38 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
2010-01-12 21:14:38 +00:00
|
|
|
|
2010-01-13 15:44:10 +00:00
|
|
|
return childCrashNotifyPipe;
|
2010-01-12 21:14:38 +00:00
|
|
|
}
|
2010-08-16 19:05:09 +00:00
|
|
|
#endif
|
2010-01-12 21:14:38 +00:00
|
|
|
|
2012-07-02 18:55:23 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
void
|
|
|
|
InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!OOPInitialized())
|
|
|
|
OOPInit();
|
|
|
|
|
|
|
|
if (!sInjectorThread) {
|
|
|
|
if (NS_FAILED(NS_NewThread(&sInjectorThread)))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(processID);
|
|
|
|
MOZ_ASSERT(!pd->minidump && !pd->callback);
|
|
|
|
pd->callback = cb;
|
|
|
|
}
|
2012-07-02 18:55:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = new InjectCrashRunnable(processID);
|
|
|
|
sInjectorThread->Dispatch(r, nsIEventTarget::DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ReportInjectedCrash::Run()
|
|
|
|
{
|
|
|
|
// Crash reporting may have been disabled after this method was dispatched
|
2012-07-11 02:20:05 +00:00
|
|
|
if (!OOPInitialized())
|
2012-07-02 18:55:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
InjectorCrashCallback* cb;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(mPID);
|
|
|
|
if (!pd || !pd->callback)
|
|
|
|
return NS_OK;
|
2012-07-02 18:55:23 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
MOZ_ASSERT(pd->minidump);
|
2012-07-02 18:55:23 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
cb = pd->callback;
|
|
|
|
}
|
2012-07-02 18:55:23 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
cb->OnCrash(mPID);
|
2012-07-02 18:55:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterInjectorCallback(DWORD processID)
|
|
|
|
{
|
|
|
|
if (!OOPInitialized())
|
|
|
|
return;
|
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
pidToMinidump->RemoveEntry(processID);
|
2012-07-02 18:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
bool
|
|
|
|
CheckForLastRunCrash()
|
|
|
|
{
|
|
|
|
if (lastRunCrashID)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// The exception handler callback leaves the filename of the
|
|
|
|
// last minidump in a known file.
|
|
|
|
nsCOMPtr<nsIFile> lastCrashFile;
|
|
|
|
CreateFileFromPath(crashMarkerFilename,
|
|
|
|
getter_AddRefs(lastCrashFile));
|
|
|
|
|
|
|
|
bool exists;
|
|
|
|
if (NS_FAILED(lastCrashFile->Exists(&exists)) || !exists) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString lastMinidump_contents;
|
2012-07-16 23:50:52 +00:00
|
|
|
if (NS_FAILED(GetFileContents(lastCrashFile, lastMinidump_contents))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lastCrashFile->Remove(false);
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// Ugly but effective.
|
|
|
|
nsDependentString lastMinidump(
|
2014-01-04 15:02:17 +00:00
|
|
|
reinterpret_cast<const char16_t*>(lastMinidump_contents.get()));
|
2012-07-16 23:50:52 +00:00
|
|
|
#else
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString lastMinidump = lastMinidump_contents;
|
2012-07-16 23:50:52 +00:00
|
|
|
#endif
|
|
|
|
nsCOMPtr<nsIFile> lastMinidumpFile;
|
|
|
|
CreateFileFromPath(lastMinidump.get(),
|
2013-06-21 09:11:43 +00:00
|
|
|
getter_AddRefs(lastMinidumpFile));
|
2012-07-16 23:50:52 +00:00
|
|
|
|
2013-06-21 09:11:43 +00:00
|
|
|
if (!lastMinidumpFile || NS_FAILED(lastMinidumpFile->Exists(&exists)) || !exists) {
|
2012-07-16 23:50:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> lastExtraFile;
|
|
|
|
if (!GetExtraFileForMinidump(lastMinidumpFile,
|
|
|
|
getter_AddRefs(lastExtraFile))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FindPendingDir();
|
|
|
|
|
|
|
|
// Move {dump,extra} to pending folder
|
|
|
|
if (!MoveToPending(lastMinidumpFile, lastExtraFile)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastRunCrashID = new nsString();
|
|
|
|
return GetIDFromMinidump(lastMinidumpFile, *lastRunCrashID);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetLastRunCrashID(nsAString& id)
|
|
|
|
{
|
|
|
|
if (!lastRunCrashID_checked) {
|
|
|
|
CheckForLastRunCrash();
|
|
|
|
lastRunCrashID_checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lastRunCrashID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = *lastRunCrashID;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-16 19:05:09 +00:00
|
|
|
#if defined(XP_WIN)
|
2010-01-12 21:14:38 +00:00
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler(const nsACString& crashPipe)
|
|
|
|
{
|
|
|
|
// crash reporting is disabled
|
|
|
|
if (crashPipe.Equals(kNullNotifyPipe))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(!gExceptionHandler, "crash client already init'd");
|
|
|
|
|
|
|
|
gExceptionHandler = new google_breakpad::
|
|
|
|
ExceptionHandler(L"",
|
2011-06-23 23:30:31 +00:00
|
|
|
FPEFilter,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, // no minidump callback
|
|
|
|
nullptr, // no callback context
|
2010-01-12 21:14:38 +00:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
|
|
|
MiniDumpNormal,
|
2013-12-05 09:52:54 +00:00
|
|
|
NS_ConvertASCIItoUTF16(crashPipe).get(),
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr);
|
2011-01-11 22:01:22 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
gExceptionHandler->set_handle_debug_exceptions(true);
|
|
|
|
#endif
|
2010-01-12 21:14:38 +00:00
|
|
|
|
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
2010-03-30 17:32:53 +00:00
|
|
|
#elif defined(XP_LINUX)
|
2010-01-12 21:14:38 +00:00
|
|
|
|
|
|
|
// Parent-side API for children
|
|
|
|
bool
|
|
|
|
CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd)
|
|
|
|
{
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
*childCrashFd = -1;
|
|
|
|
*childCrashRemapFd = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
2010-01-12 21:14:38 +00:00
|
|
|
|
|
|
|
*childCrashFd = clientSocketFd;
|
|
|
|
*childCrashRemapFd = kMagicChildCrashReportFd;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!gExceptionHandler, "crash client already init'd");
|
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
#ifndef XP_LINUX
|
|
|
|
xpstring path = "";
|
|
|
|
#else
|
2012-09-25 12:42:57 +00:00
|
|
|
// MinidumpDescriptor requires a non-empty path.
|
|
|
|
google_breakpad::MinidumpDescriptor path(".");
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2010-01-12 21:14:38 +00:00
|
|
|
gExceptionHandler = new google_breakpad::
|
2012-09-25 11:52:54 +00:00
|
|
|
ExceptionHandler(path,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, // no filter callback
|
|
|
|
nullptr, // no minidump callback
|
|
|
|
nullptr, // no callback context
|
|
|
|
true, // install signal handlers
|
2010-01-12 21:14:38 +00:00
|
|
|
kMagicChildCrashReportFd);
|
|
|
|
|
2011-06-08 20:21:03 +00:00
|
|
|
if (gDelayedAnnotations) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < gDelayedAnnotations->Length(); i++) {
|
2011-06-08 20:21:03 +00:00
|
|
|
gDelayedAnnotations->ElementAt(i)->Run();
|
|
|
|
}
|
|
|
|
delete gDelayedAnnotations;
|
|
|
|
}
|
|
|
|
|
2010-01-12 21:14:38 +00:00
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:47:47 +00:00
|
|
|
//--------------------------------------------------
|
|
|
|
#elif defined(XP_MACOSX)
|
2010-08-16 19:05:09 +00:00
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler(const nsACString& crashPipe)
|
2010-04-12 20:47:47 +00:00
|
|
|
{
|
2010-08-16 19:05:09 +00:00
|
|
|
// crash reporting is disabled
|
|
|
|
if (crashPipe.Equals(kNullNotifyPipe))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(!gExceptionHandler, "crash client already init'd");
|
|
|
|
|
|
|
|
gExceptionHandler = new google_breakpad::
|
|
|
|
ExceptionHandler("",
|
2012-07-03 13:15:34 +00:00
|
|
|
Filter,
|
2013-10-10 20:39:09 +00:00
|
|
|
nullptr, // no minidump callback
|
|
|
|
nullptr, // no callback context
|
|
|
|
true, // install signal handlers
|
2010-08-16 19:05:09 +00:00
|
|
|
crashPipe.BeginReading());
|
|
|
|
|
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
2010-04-12 20:47:47 +00:00
|
|
|
}
|
2010-01-12 22:00:48 +00:00
|
|
|
#endif // XP_WIN
|
2010-01-12 21:14:38 +00:00
|
|
|
|
|
|
|
|
2010-01-14 22:38:00 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
TakeMinidumpForChild(uint32_t childPid, nsIFile** dump, uint32_t* aSequence)
|
2010-01-14 22:38:00 +00:00
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2010-03-18 22:52:36 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(childPid);
|
|
|
|
if (!pd)
|
|
|
|
return false;
|
2010-03-18 22:52:36 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
NS_IF_ADDREF(*dump = pd->minidump);
|
|
|
|
if (aSequence) {
|
|
|
|
*aSequence = pd->sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
pidToMinidump->RemoveEntry(childPid);
|
2010-03-18 22:52:36 +00:00
|
|
|
|
2012-07-11 02:20:05 +00:00
|
|
|
return !!*dump;
|
2010-01-14 22:38:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// CreatePairedMinidumps() and helpers
|
|
|
|
//
|
2012-09-08 17:20:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
RenameAdditionalHangMinidump(nsIFile* minidump, nsIFile* childMinidump,
|
|
|
|
const nsACString& name)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
childMinidump->GetParent(getter_AddRefs(directory));
|
|
|
|
if (!directory)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoCString leafName;
|
|
|
|
childMinidump->GetNativeLeafName(leafName);
|
|
|
|
|
|
|
|
// turn "<id>.dmp" into "<id>-<name>.dmp
|
|
|
|
leafName.Insert(NS_LITERAL_CSTRING("-") + name, leafName.Length() - 4);
|
|
|
|
|
|
|
|
minidump->MoveToNative(directory, leafName);
|
|
|
|
}
|
2010-03-24 21:22:00 +00:00
|
|
|
|
|
|
|
static bool
|
2012-09-25 11:52:54 +00:00
|
|
|
PairedDumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
|
|
|
const XP_CHAR* dump_path,
|
2010-03-24 21:22:00 +00:00
|
|
|
const XP_CHAR* minidump_id,
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2010-03-24 21:22:00 +00:00
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* /*unused*/,
|
|
|
|
MDRawAssertionInfo* /*unused*/,
|
|
|
|
#endif
|
|
|
|
bool succeeded)
|
|
|
|
{
|
2012-09-08 17:20:59 +00:00
|
|
|
nsCOMPtr<nsIFile>& minidump = *static_cast< nsCOMPtr<nsIFile>* >(context);
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
xpstring dump;
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
dump = descriptor.path();
|
|
|
|
#else
|
|
|
|
dump = dump_path;
|
2010-03-24 21:22:01 +00:00
|
|
|
dump += XP_PATH_SEPARATOR;
|
|
|
|
dump += minidump_id;
|
|
|
|
dump += dumpFileExtension;
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2010-03-24 21:22:00 +00:00
|
|
|
|
2010-03-24 21:22:01 +00:00
|
|
|
CreateFileFromPath(dump, getter_AddRefs(minidump));
|
2012-09-08 17:20:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-09-25 11:52:54 +00:00
|
|
|
PairedDumpCallbackExtra(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
|
|
|
const XP_CHAR* dump_path,
|
2012-09-08 17:20:59 +00:00
|
|
|
const XP_CHAR* minidump_id,
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2012-09-08 17:20:59 +00:00
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* /*unused*/,
|
|
|
|
MDRawAssertionInfo* /*unused*/,
|
|
|
|
#endif
|
|
|
|
bool succeeded)
|
|
|
|
{
|
2012-09-25 11:52:54 +00:00
|
|
|
PairedDumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
descriptor,
|
|
|
|
#else
|
|
|
|
dump_path, minidump_id,
|
|
|
|
#endif
|
|
|
|
context,
|
2012-09-08 17:20:59 +00:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
nullptr, nullptr,
|
|
|
|
#endif
|
|
|
|
succeeded);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile>& minidump = *static_cast< nsCOMPtr<nsIFile>* >(context);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> extra;
|
|
|
|
return WriteExtraForMinidump(minidump, Blacklist(), getter_AddRefs(extra));
|
2010-03-24 21:22:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 00:24:45 +00:00
|
|
|
ThreadId
|
|
|
|
CurrentThreadId()
|
|
|
|
{
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
return ::GetCurrentThreadId();
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
return sys_gettid();
|
|
|
|
#elif defined(XP_MACOSX)
|
2010-08-27 13:32:45 +00:00
|
|
|
// Just return an index, since Mach ports can't be directly serialized
|
|
|
|
thread_act_port_array_t threads_for_task;
|
|
|
|
mach_msg_type_number_t thread_count;
|
|
|
|
|
|
|
|
if (task_threads(mach_task_self(), &threads_for_task, &thread_count))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < thread_count; ++i) {
|
|
|
|
if (threads_for_task[i] == mach_thread_self())
|
|
|
|
return i;
|
|
|
|
}
|
2011-01-21 19:12:21 +00:00
|
|
|
abort();
|
2010-03-31 00:24:45 +00:00
|
|
|
#else
|
|
|
|
# error "Unsupported platform"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-27 13:32:45 +00:00
|
|
|
#ifdef XP_MACOSX
|
2012-09-26 20:49:20 +00:00
|
|
|
static mach_port_t
|
|
|
|
GetChildThread(ProcessHandle childPid, ThreadId childBlamedThread)
|
|
|
|
{
|
2010-08-27 13:32:45 +00:00
|
|
|
mach_port_t childThread = MACH_PORT_NULL;
|
|
|
|
thread_act_port_array_t threads_for_task;
|
|
|
|
mach_msg_type_number_t thread_count;
|
|
|
|
|
|
|
|
if (task_threads(childPid, &threads_for_task, &thread_count)
|
|
|
|
== KERN_SUCCESS && childBlamedThread < thread_count) {
|
|
|
|
childThread = threads_for_task[childBlamedThread];
|
|
|
|
}
|
2012-09-26 20:49:20 +00:00
|
|
|
|
|
|
|
return childThread;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool
|
|
|
|
CreatePairedMinidumps(ProcessHandle childPid,
|
|
|
|
ThreadId childBlamedThread,
|
|
|
|
nsIFile** childDump)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mach_port_t childThread = GetChildThread(childPid, childBlamedThread);
|
2010-08-27 13:32:45 +00:00
|
|
|
#else
|
|
|
|
ThreadId childThread = childBlamedThread;
|
|
|
|
#endif
|
|
|
|
|
2012-09-25 11:52:54 +00:00
|
|
|
xpstring dump_path;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
dump_path = gExceptionHandler->dump_path();
|
|
|
|
#else
|
|
|
|
dump_path = gExceptionHandler->minidump_descriptor().directory();
|
|
|
|
#endif
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
// dump the child
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> childMinidump;
|
2010-03-24 21:22:00 +00:00
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidumpForChild(
|
|
|
|
childPid,
|
2010-08-27 13:32:45 +00:00
|
|
|
childThread,
|
2012-09-25 11:52:54 +00:00
|
|
|
dump_path,
|
2012-09-08 17:20:59 +00:00
|
|
|
PairedDumpCallbackExtra,
|
|
|
|
static_cast<void*>(&childMinidump)))
|
2010-03-24 21:22:00 +00:00
|
|
|
return false;
|
|
|
|
|
2012-09-08 17:20:59 +00:00
|
|
|
nsCOMPtr<nsIFile> childExtra;
|
|
|
|
GetExtraFileForMinidump(childMinidump, getter_AddRefs(childExtra));
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
// dump the parent
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> parentMinidump;
|
2010-03-24 21:22:00 +00:00
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidump(
|
2012-09-25 11:52:54 +00:00
|
|
|
dump_path,
|
|
|
|
#ifdef XP_MACOSX
|
2010-03-31 00:24:48 +00:00
|
|
|
true, // write exception stream
|
2012-09-25 11:52:54 +00:00
|
|
|
#endif
|
2010-03-24 21:22:00 +00:00
|
|
|
PairedDumpCallback,
|
2012-09-08 17:20:59 +00:00
|
|
|
static_cast<void*>(&parentMinidump))) {
|
|
|
|
|
|
|
|
childMinidump->Remove(false);
|
|
|
|
childExtra->Remove(false);
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
return false;
|
2012-09-08 17:20:59 +00:00
|
|
|
}
|
2010-03-24 21:22:00 +00:00
|
|
|
|
|
|
|
// success
|
2012-09-08 17:20:59 +00:00
|
|
|
RenameAdditionalHangMinidump(parentMinidump, childMinidump,
|
|
|
|
NS_LITERAL_CSTRING("browser"));
|
|
|
|
|
2010-03-24 21:22:00 +00:00
|
|
|
if (ShouldReport()) {
|
|
|
|
MoveToPending(childMinidump, childExtra);
|
2012-09-08 17:20:59 +00:00
|
|
|
MoveToPending(parentMinidump, nullptr);
|
2010-03-24 21:22:00 +00:00
|
|
|
}
|
|
|
|
|
2012-09-08 17:20:59 +00:00
|
|
|
childMinidump.forget(childDump);
|
2010-03-24 21:22:00 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-26 20:49:20 +00:00
|
|
|
bool
|
|
|
|
CreateAdditionalChildMinidump(ProcessHandle childPid,
|
|
|
|
ThreadId childBlamedThread,
|
|
|
|
nsIFile* parentMinidump,
|
|
|
|
const nsACString& name)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mach_port_t childThread = GetChildThread(childPid, childBlamedThread);
|
|
|
|
#else
|
|
|
|
ThreadId childThread = childBlamedThread;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
xpstring dump_path;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
dump_path = gExceptionHandler->dump_path();
|
|
|
|
#else
|
|
|
|
dump_path = gExceptionHandler->minidump_descriptor().directory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// dump the child
|
|
|
|
nsCOMPtr<nsIFile> childMinidump;
|
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidumpForChild(
|
|
|
|
childPid,
|
|
|
|
childThread,
|
|
|
|
dump_path,
|
|
|
|
PairedDumpCallback,
|
|
|
|
static_cast<void*>(&childMinidump))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenameAdditionalHangMinidump(childMinidump, parentMinidump, name);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-12 21:14:38 +00:00
|
|
|
bool
|
|
|
|
UnsetRemoteExceptionHandler()
|
|
|
|
{
|
|
|
|
delete gExceptionHandler;
|
2013-10-10 20:39:09 +00:00
|
|
|
gExceptionHandler = nullptr;
|
2010-01-12 21:14:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-16 23:50:52 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 19:05:47 +00:00
|
|
|
void AddLibraryMapping(const char* library_name,
|
|
|
|
uintptr_t start_address,
|
|
|
|
size_t mapping_length,
|
|
|
|
size_t file_offset)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler) {
|
|
|
|
mapping_info info;
|
|
|
|
info.name = library_name;
|
|
|
|
info.start_address = start_address;
|
|
|
|
info.length = mapping_length;
|
|
|
|
info.file_offset = file_offset;
|
|
|
|
library_mappings.push_back(info);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u_int8_t guid[sizeof(MDGUID)];
|
2013-04-09 12:04:53 +00:00
|
|
|
google_breakpad::FileID::ElfFileIdentifierFromMappedFile((void const *)start_address, guid);
|
2010-10-19 19:05:47 +00:00
|
|
|
gExceptionHandler->AddMappingInfo(library_name,
|
|
|
|
guid,
|
|
|
|
start_address,
|
|
|
|
mapping_length,
|
|
|
|
file_offset);
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 14:15:03 +00:00
|
|
|
#endif
|
2010-10-19 19:05:47 +00:00
|
|
|
|
2007-07-25 01:05:55 +00:00
|
|
|
} // namespace CrashReporter
|