2015-10-19 15:46:46 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07: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-24 18:05:54 -07:00
|
|
|
|
2013-09-21 20:04:10 -07:00
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-06-08 13:21:03 -07:00
|
|
|
#include "mozilla/dom/CrashReporterChild.h"
|
2011-10-03 13:26:08 -07:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIObserverService.h"
|
2013-10-16 16:46:14 -07:00
|
|
|
#include "mozilla/unused.h"
|
2015-05-26 11:33:55 -07:00
|
|
|
#include "mozilla/Snprintf.h"
|
2014-07-18 10:31:45 -07:00
|
|
|
#include "mozilla/SyncRunnable.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2011-06-08 13:21:03 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2013-09-23 14:30:40 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2014-10-08 12:25:20 -07:00
|
|
|
#include "jsfriendapi.h"
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
#if defined(XP_WIN32)
|
2007-07-24 18:05:54 -07:00
|
|
|
#ifdef WIN32_LEAN_AND_MEAN
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2013-09-21 20:04:10 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
2010-02-09 17:05:31 -08:00
|
|
|
#include "nsIWindowsRegKey.h"
|
2012-09-25 04:52:54 -07:00
|
|
|
#include "client/windows/crash_generation/client_info.h"
|
2011-04-02 19:14:00 -07:00
|
|
|
#include "client/windows/crash_generation/crash_generation_server.h"
|
2007-07-24 18:05:54 -07:00
|
|
|
#include "client/windows/handler/exception_handler.h"
|
2013-04-05 02:29:50 -07:00
|
|
|
#include <dbghelp.h>
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <string.h>
|
2012-07-10 19:20:05 -07:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2012-04-20 02:07:55 -07:00
|
|
|
|
|
|
|
#include "nsWindowsDllInterceptor.h"
|
2007-07-24 18:06:00 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
2011-04-02 19:14:00 -07:00
|
|
|
#include "client/mac/crash_generation/client_info.h"
|
|
|
|
#include "client/mac/crash_generation/crash_generation_server.h"
|
2007-07-24 18:06:00 -07:00
|
|
|
#include "client/mac/handler/exception_handler.h"
|
|
|
|
#include <string>
|
|
|
|
#include <Carbon/Carbon.h>
|
2010-06-20 19:07:59 -07:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2010-10-01 12:56:25 -07:00
|
|
|
#include <crt_externs.h>
|
2007-07-24 18:06:00 -07:00
|
|
|
#include <fcntl.h>
|
2010-08-27 06:32:45 -07:00
|
|
|
#include <mach/mach.h>
|
2007-07-24 18:06:11 -07:00
|
|
|
#include <sys/types.h>
|
2010-10-01 12:56:25 -07:00
|
|
|
#include <spawn.h>
|
2007-07-24 18:06:11 -07:00
|
|
|
#include <unistd.h>
|
2007-07-24 18:06:09 -07:00
|
|
|
#include "mac_utils.h"
|
2007-07-24 18:06:04 -07:00
|
|
|
#elif defined(XP_LINUX)
|
2010-02-09 17:05:31 -08:00
|
|
|
#include "nsIINIParser.h"
|
2010-07-29 08:31:07 -07:00
|
|
|
#include "common/linux/linux_libc_support.h"
|
2012-09-25 04:52:54 -07:00
|
|
|
#include "third_party/lss/linux_syscall_support.h"
|
2011-04-02 19:14:00 -07:00
|
|
|
#include "client/linux/crash_generation/client_info.h"
|
|
|
|
#include "client/linux/crash_generation/crash_generation_server.h"
|
2007-07-24 18:06:04 -07:00
|
|
|
#include "client/linux/handler/exception_handler.h"
|
2014-12-15 10:13:12 -08:00
|
|
|
#include "common/linux/eintr_wrapper.h"
|
2007-07-24 18:06:04 -07:00
|
|
|
#include <fcntl.h>
|
2007-07-24 18:06:11 -07:00
|
|
|
#include <sys/types.h>
|
2014-12-15 10:13:12 -08:00
|
|
|
#include <sys/wait.h>
|
2007-07-24 18:06:11 -07:00
|
|
|
#include <unistd.h>
|
2008-03-19 18:13:36 -07:00
|
|
|
#elif defined(XP_SOLARIS)
|
|
|
|
#include "client/solaris/handler/exception_handler.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2007-07-24 18:05:55 -07:00
|
|
|
#else
|
|
|
|
#error "Not yet implemented for this platform"
|
2007-07-24 18:06:00 -07:00
|
|
|
#endif // defined(XP_WIN32)
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2012-07-02 11:55:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
#include "InjectCrashReporter.h"
|
|
|
|
using mozilla::InjectCrashRunnable;
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <stdlib.h>
|
2007-07-24 18:06:15 -07:00
|
|
|
#include <time.h>
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <prenv.h>
|
2007-07-24 18:06:14 -07:00
|
|
|
#include <prio.h>
|
2007-11-12 10:53:52 -08:00
|
|
|
#include <prmem.h>
|
2010-01-14 14:38:00 -08:00
|
|
|
#include "mozilla/Mutex.h"
|
2007-07-24 18:05:54 -07:00
|
|
|
#include "nsDebug.h"
|
2007-07-24 18:05:55 -07:00
|
|
|
#include "nsCRT.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2010-01-13 07:44:10 -08:00
|
|
|
#include "prprf.h"
|
2010-11-24 06:15:03 -08:00
|
|
|
#include <map>
|
2010-10-19 12:05:47 -07:00
|
|
|
#include <vector>
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2014-03-14 23:10:39 -07:00
|
|
|
#include "mozilla/IOInterposer.h"
|
2012-01-24 08:08:51 -08:00
|
|
|
#include "mozilla/mozalloc_oom.h"
|
2013-11-12 05:31:32 -08:00
|
|
|
#include "mozilla/WindowsDllBlocklist.h"
|
2012-01-24 08:08:51 -08:00
|
|
|
|
2010-06-20 19:07:59 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
|
|
|
|
#endif
|
2013-04-09 05:04:53 -07:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
#include "common/linux/file_id.h"
|
|
|
|
#endif
|
2010-06-20 19:07:59 -07:00
|
|
|
|
2010-01-12 13:14:38 -08:00
|
|
|
using google_breakpad::CrashGenerationServer;
|
|
|
|
using google_breakpad::ClientInfo;
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
using google_breakpad::MinidumpDescriptor;
|
|
|
|
#endif
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
2011-06-08 13:21:03 -07:00
|
|
|
using mozilla::dom::CrashReporterChild;
|
|
|
|
using mozilla::dom::PCrashReporterChild;
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
namespace CrashReporter {
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
typedef wchar_t XP_CHAR;
|
2010-03-24 14:22:00 -07:00
|
|
|
typedef std::wstring xpstring;
|
2014-08-29 22:21:18 -07:00
|
|
|
#define XP_TEXT(x) L##x
|
2009-04-02 08:41:12 -07:00
|
|
|
#define CONVERT_XP_CHAR_TO_UTF16(x) x
|
2007-07-24 18:06:00 -07:00
|
|
|
#define XP_STRLEN(x) wcslen(x)
|
2010-08-11 07:57:44 -07:00
|
|
|
#define my_strlen strlen
|
2007-07-24 18:06:00 -07: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 12:46:00 -07: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 08:08:51 -08:00
|
|
|
#define XP_STOA(size, buffer, base) _ui64toa(size, buffer, base)
|
2007-07-24 18:06:00 -07:00
|
|
|
#else
|
|
|
|
typedef char XP_CHAR;
|
2010-03-24 14:22:00 -07:00
|
|
|
typedef std::string xpstring;
|
2014-08-29 22:21:18 -07:00
|
|
|
#define XP_TEXT(x) x
|
2009-04-02 08:41:12 -07:00
|
|
|
#define CONVERT_XP_CHAR_TO_UTF16(x) NS_ConvertUTF8toUTF16(x)
|
2007-07-24 18:06:00 -07:00
|
|
|
#define CRASH_REPORTER_FILENAME "crashreporter"
|
|
|
|
#define PATH_SEPARATOR "/"
|
|
|
|
#define XP_PATH_SEPARATOR "/"
|
|
|
|
#define XP_PATH_MAX PATH_MAX
|
2010-07-29 08:31:07 -07:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
#define XP_STRLEN(x) my_strlen(x)
|
2012-01-24 08:08:51 -08: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 08:31:07 -07:00
|
|
|
#else
|
|
|
|
#define XP_STRLEN(x) strlen(x)
|
2007-08-29 12:46:00 -07:00
|
|
|
#define XP_TTOA(time, buffer, base) sprintf(buffer, "%ld", time)
|
2015-04-27 07:49:44 -07:00
|
|
|
#define XP_STOA(size, buffer, base) sprintf(buffer, "%zu", (size_t) size)
|
2010-08-11 07:57:44 -07:00
|
|
|
#define my_strlen strlen
|
2010-07-29 08:31:07 -07:00
|
|
|
#define sys_close close
|
|
|
|
#define sys_fork fork
|
|
|
|
#define sys_open open
|
2014-08-29 22:21:18 -07:00
|
|
|
#define sys_read read
|
2010-07-29 08:31:07 -07:00
|
|
|
#define sys_write write
|
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
#endif // XP_WIN32
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2014-06-23 11:49:09 -07:00
|
|
|
#ifndef XP_LINUX
|
2014-08-29 22:21:18 -07:00
|
|
|
static const XP_CHAR dumpFileExtension[] = XP_TEXT(".dmp");
|
2014-06-23 11:49:09 -07:00
|
|
|
#endif
|
|
|
|
|
2014-08-29 22:21:18 -07:00
|
|
|
static const XP_CHAR extraFileExtension[] = XP_TEXT(".extra");
|
|
|
|
static const XP_CHAR memoryReportExtension[] = XP_TEXT(".memory.json.gz");
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
// A whitelist of crash annotations which do not contain sensitive data
|
|
|
|
// and are saved in the crash record and sent with Firefox Health Report.
|
|
|
|
static char const * const kCrashEventAnnotations[] = {
|
|
|
|
"AsyncShutdownTimeout",
|
|
|
|
"BuildID",
|
|
|
|
"TelemetryEnvironment",
|
|
|
|
"ProductID",
|
|
|
|
"ProductName",
|
|
|
|
"ReleaseChannel",
|
|
|
|
"SecondsSinceLastCrash",
|
|
|
|
"ShutdownProgress",
|
|
|
|
"Version"
|
|
|
|
// The following entries are not normal annotations but are included
|
|
|
|
// in the crash record/FHR:
|
|
|
|
// "ContainsMemoryReport"
|
|
|
|
// "EventLoopNestingLevel"
|
|
|
|
// "IsGarbageCollecting"
|
|
|
|
// "AvailablePageFile"
|
|
|
|
// "AvailableVirtualMemory"
|
|
|
|
// "SystemMemoryUsePercentage"
|
|
|
|
// "OOMAllocationSize"
|
|
|
|
// "TotalPageFile"
|
|
|
|
// "TotalPhysicalMemory"
|
|
|
|
// "TotalVirtualMemory"
|
2015-09-29 08:14:50 -07:00
|
|
|
// "MozCrashReason"
|
2015-04-27 07:49:44 -07:00
|
|
|
};
|
|
|
|
|
2015-03-13 22:54:36 -07:00
|
|
|
static const char kCrashMainID[] = "crash.main.2\n";
|
2014-02-18 15:58:03 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
static google_breakpad::ExceptionHandler* gExceptionHandler = nullptr;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
static XP_CHAR* pendingDirectory;
|
2007-07-24 18:06:00 -07:00
|
|
|
static XP_CHAR* crashReporterPath;
|
2014-08-29 22:21:09 -07:00
|
|
|
static XP_CHAR* memoryReportPath;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2014-02-18 15:58:03 -08:00
|
|
|
// Where crash events should go.
|
|
|
|
static XP_CHAR* eventsDirectory;
|
2014-07-03 14:51:08 -07:00
|
|
|
static char* eventsEnv = nullptr;
|
2014-02-18 15:58:03 -08:00
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
// If this is false, we don't launch the crash reporter
|
2007-07-24 18:06:02 -07:00
|
|
|
static bool doReport = true;
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
// If this is true, we don't have a crash reporter
|
|
|
|
static bool headlessClient = false;
|
|
|
|
|
2007-07-24 18:06:09 -07:00
|
|
|
// if this is true, we pass the exception on to the OS crash reporter
|
|
|
|
static bool showOSCrashReporter = false;
|
|
|
|
|
2007-08-29 12:46:00 -07: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 16:50:52 -07: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 07:20:58 -07:00
|
|
|
static nsString* lastRunCrashID = nullptr;
|
2012-07-16 16:50:52 -07:00
|
|
|
|
2012-11-15 14:56:22 -08: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 12:46:00 -07:00
|
|
|
// these are just here for readability
|
|
|
|
static const char kTimeSinceLastCrashParameter[] = "SecondsSinceLastCrash=";
|
|
|
|
static const int kTimeSinceLastCrashParameterLen =
|
|
|
|
sizeof(kTimeSinceLastCrashParameter)-1;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// this holds additional data sent via the API
|
2011-10-06 13:33:21 -07:00
|
|
|
static Mutex* crashReporterAPILock;
|
2012-01-25 06:43:52 -08:00
|
|
|
static Mutex* notesFieldLock;
|
2010-03-24 14:22:01 -07:00
|
|
|
static AnnotationTable* crashReporterAPIData_Hash;
|
2012-07-30 07:20:58 -07:00
|
|
|
static nsCString* crashReporterAPIData = nullptr;
|
2015-04-27 07:49:44 -07:00
|
|
|
static nsCString* crashEventAPIData = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
static nsCString* notesField = nullptr;
|
2012-08-15 10:47:51 -07:00
|
|
|
static bool isGarbageCollecting;
|
2014-02-13 09:51:09 -08:00
|
|
|
static uint32_t eventloopNestingLevel = 0;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2014-01-15 07:03:14 -08:00
|
|
|
// Avoid a race during application termination.
|
|
|
|
static Mutex* dumpSafetyLock;
|
|
|
|
static bool isSafeToDump = false;
|
|
|
|
|
2010-01-12 13:14:38 -08:00
|
|
|
// OOP crash reporting
|
|
|
|
static CrashGenerationServer* crashServer; // chrome process has this
|
|
|
|
|
2010-08-16 12:05:09 -07:00
|
|
|
# if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08: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 07:44:10 -08:00
|
|
|
static char* childCrashNotifyPipe;
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
# elif defined(XP_LINUX)
|
2010-01-12 13:14:38 -08:00
|
|
|
static int serverSocketFd = -1;
|
|
|
|
static int clientSocketFd = -1;
|
2010-10-29 12:20:43 -07:00
|
|
|
static const int kMagicChildCrashReportFd = 4;
|
2010-08-16 12:05:09 -07:00
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
# endif
|
2010-01-14 14:38:00 -08:00
|
|
|
|
|
|
|
// |dumpMapLock| must protect all access to |pidToMinidump|.
|
|
|
|
static Mutex* dumpMapLock;
|
2012-07-10 19:20:05 -07:00
|
|
|
struct ChildProcessData : public nsUint32HashKey
|
|
|
|
{
|
2014-09-02 15:24:24 -07:00
|
|
|
explicit ChildProcessData(KeyTypePointer aKey)
|
2012-07-10 19:20:05 -07:00
|
|
|
: nsUint32HashKey(aKey)
|
|
|
|
, sequence(0)
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-10-10 13:39:09 -07:00
|
|
|
, callback(nullptr)
|
2012-07-10 19:20:05 -07:00
|
|
|
#endif
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
// Each crashing process is assigned an increasing sequence number to
|
|
|
|
// indicate which process crashed first.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t sequence;
|
2012-07-10 19:20:05 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
InjectorCrashCallback* callback;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTHashtable<ChildProcessData> ChildMinidumpMap;
|
2010-01-14 14:38:00 -08:00
|
|
|
static ChildMinidumpMap* pidToMinidump;
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t crashSequence;
|
2012-07-10 19:20:05 -07:00
|
|
|
static bool OOPInitialized();
|
2010-01-14 14:38:00 -08:00
|
|
|
|
2012-07-02 11:55:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
static nsIThread* sInjectorThread;
|
|
|
|
|
|
|
|
class ReportInjectedCrash : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 15:24:24 -07:00
|
|
|
explicit ReportInjectedCrash(uint32_t pid) : mPID(pid) { }
|
2012-07-02 11:55:23 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mPID;
|
2012-07-02 11:55:23 -07:00
|
|
|
};
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
// Crashreporter annotations that we don't send along in subprocess
|
|
|
|
// reports
|
|
|
|
static const char* kSubprocessBlacklist[] = {
|
|
|
|
"FramePoisonBase",
|
|
|
|
"FramePoisonSize",
|
|
|
|
"StartupTime",
|
|
|
|
"URL"
|
|
|
|
};
|
|
|
|
|
2011-06-08 13:21:03 -07:00
|
|
|
// If annotations are attempted before the crash reporter is enabled,
|
|
|
|
// they queue up here.
|
|
|
|
class DelayedNote;
|
|
|
|
nsTArray<nsAutoPtr<DelayedNote> >* gDelayedAnnotations;
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2012-04-20 02:07:55 -07: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 14:07:35 -08:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER previousUnhandledExceptionFilter = nullptr;
|
2012-04-20 02:07:55 -07:00
|
|
|
static WindowsDllInterceptor gKernel32Intercept;
|
|
|
|
static bool gBlockUnhandledExceptionFilter = true;
|
|
|
|
|
2014-10-08 12:25:20 -07:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER GetUnhandledExceptionFilter()
|
2014-01-29 14:07:35 -08:00
|
|
|
{
|
2014-10-08 12:25:20 -07:00
|
|
|
// Set a dummy value to get the current filter, then restore
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER current = SetUnhandledExceptionFilter(nullptr);
|
|
|
|
SetUnhandledExceptionFilter(current);
|
|
|
|
return current;
|
2014-01-29 14:07:35 -08:00
|
|
|
}
|
|
|
|
|
2012-04-20 02:07:55 -07:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI
|
|
|
|
patched_SetUnhandledExceptionFilter (LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
|
|
|
|
{
|
2012-09-25 04:52:54 -07:00
|
|
|
if (!gBlockUnhandledExceptionFilter) {
|
2012-04-20 02:07:55 -07:00
|
|
|
// don't intercept
|
|
|
|
return stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:07:35 -08:00
|
|
|
if (lpTopLevelExceptionFilter == previousUnhandledExceptionFilter) {
|
|
|
|
// OK to swap back and forth between the previous filter
|
|
|
|
previousUnhandledExceptionFilter =
|
|
|
|
stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
|
|
|
return previousUnhandledExceptionFilter;
|
|
|
|
}
|
|
|
|
|
2012-04-20 02:07:55 -07:00
|
|
|
// intercept attempts to change the filter
|
2013-10-10 13:39:09 -07:00
|
|
|
return nullptr;
|
2012-04-20 02:07:55 -07:00
|
|
|
}
|
2013-12-06 06:00:06 -08:00
|
|
|
|
2014-10-08 12:25:20 -07:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER sUnhandledExceptionFilter = nullptr;
|
|
|
|
|
|
|
|
static long
|
|
|
|
JitExceptionHandler(void *exceptionRecord, void *context)
|
|
|
|
{
|
|
|
|
EXCEPTION_POINTERS pointers = {
|
|
|
|
(PEXCEPTION_RECORD)exceptionRecord,
|
|
|
|
(PCONTEXT)context
|
|
|
|
};
|
|
|
|
return sUnhandledExceptionFilter(&pointers);
|
|
|
|
}
|
|
|
|
|
2013-12-06 06:00:06 -08: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.
|
|
|
|
*/
|
2015-01-31 19:09:13 -08:00
|
|
|
static const SIZE_T kReserveSize = 0x4000000; // 64 MB
|
2013-12-06 06:00:06 -08:00
|
|
|
static void* gBreakpadReservedVM;
|
2012-04-20 02:07:55 -07:00
|
|
|
#endif
|
|
|
|
|
2010-10-01 12:56:25 -07: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 16:50:52 -07:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 12:05:47 -07: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 08:56:38 -07:00
|
|
|
typedef std::map<uint32_t,google_breakpad::MappingList> MappingMap;
|
2010-10-19 12:05:47 -07:00
|
|
|
#endif
|
|
|
|
|
2010-08-11 07:57:44 -07:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
inline void
|
2012-01-24 08:08:51 -08:00
|
|
|
my_inttostring(intmax_t t, char* buffer, size_t buffer_length)
|
2010-08-11 07:57:44 -07:00
|
|
|
{
|
|
|
|
my_memset(buffer, 0, buffer_length);
|
2012-09-25 04:52:54 -07:00
|
|
|
my_uitos(buffer, t, my_uint_len(t));
|
2010-08-11 07:57:44 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static void
|
2012-06-05 19:08:30 -07:00
|
|
|
CreateFileFromPath(const xpstring& path, nsIFile** file)
|
2010-03-24 14:22:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_NewLocalFile(nsDependentString(path.c_str()), false, file);
|
2010-03-24 14:22:00 -07:00
|
|
|
}
|
2015-08-21 00:01:47 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
CreateFileFromPath(const wchar_t* path, nsIFile** file)
|
|
|
|
{
|
|
|
|
CreateFileFromPath(std::wstring(path), file);
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
#else
|
|
|
|
static void
|
2012-06-05 19:08:30 -07:00
|
|
|
CreateFileFromPath(const xpstring& path, nsIFile** file)
|
2010-03-24 14:22:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(path.c_str()), false, file);
|
2010-03-24 14:22:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:00 -07: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;
|
|
|
|
}
|
|
|
|
|
2015-09-29 08:14:50 -07:00
|
|
|
static const char* gMozCrashReason = nullptr;
|
|
|
|
|
|
|
|
void AnnotateMozCrashReason(const char* aReason)
|
|
|
|
{
|
|
|
|
gMozCrashReason = aReason;
|
|
|
|
}
|
|
|
|
|
2012-01-24 08:08:51 -08:00
|
|
|
static size_t gOOMAllocationSize = 0;
|
|
|
|
|
|
|
|
void AnnotateOOMAllocationSize(size_t size)
|
|
|
|
{
|
|
|
|
gOOMAllocationSize = size;
|
|
|
|
}
|
|
|
|
|
2014-08-29 22:21:18 -07:00
|
|
|
#ifndef XP_WIN
|
|
|
|
// Like Windows CopyFile for *nix
|
|
|
|
bool copy_file(const char* from, const char* to)
|
|
|
|
{
|
|
|
|
const int kBufSize = 4096;
|
|
|
|
int fdfrom = sys_open(from, O_RDONLY, 0);
|
|
|
|
if (fdfrom < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
int fdto = sys_open(to, O_WRONLY | O_CREAT, 0666);
|
|
|
|
if (fdto < 0) {
|
|
|
|
sys_close(fdfrom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[kBufSize];
|
|
|
|
while (true) {
|
|
|
|
int r = sys_read(fdfrom, buf, kBufSize);
|
|
|
|
if (r == 0) {
|
|
|
|
ok = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (r < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
char* wbuf = buf;
|
|
|
|
while (r) {
|
|
|
|
int w = sys_write(fdto, wbuf, r);
|
|
|
|
if (w > 0) {
|
|
|
|
r -= w;
|
|
|
|
wbuf += w;
|
|
|
|
} else if (errno != EINTR) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sys_close(fdfrom);
|
|
|
|
sys_close(fdto);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
class PlatformWriter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PlatformWriter()
|
|
|
|
: mHandle(INVALID_HANDLE_VALUE)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
explicit PlatformWriter(const wchar_t* path)
|
|
|
|
: PlatformWriter()
|
|
|
|
{
|
|
|
|
Open(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
~PlatformWriter() {
|
|
|
|
if (Valid()) {
|
|
|
|
CloseHandle(mHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Open(const wchar_t* path) {
|
|
|
|
mHandle = CreateFile(path, GENERIC_WRITE, 0,
|
|
|
|
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Valid() {
|
|
|
|
return mHandle != INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteBuffer(const char* buffer, size_t len)
|
|
|
|
{
|
|
|
|
if (!Valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DWORD nBytes;
|
|
|
|
WriteFile(mHandle, buffer, len, &nBytes, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE Handle() {
|
|
|
|
return mHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
HANDLE mHandle;
|
|
|
|
};
|
|
|
|
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
|
|
|
|
class PlatformWriter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PlatformWriter()
|
|
|
|
: mFD(-1)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
explicit PlatformWriter(const char* path)
|
|
|
|
: PlatformWriter()
|
|
|
|
{
|
|
|
|
Open(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
~PlatformWriter() {
|
|
|
|
if (Valid()) {
|
|
|
|
sys_close(mFD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Open(const char* path) {
|
|
|
|
mFD = sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Valid() {
|
|
|
|
return mFD != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteBuffer(const char* buffer, size_t len) {
|
|
|
|
if (!Valid()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-01 21:53:26 -08:00
|
|
|
Unused << sys_write(mFD, buffer, len);
|
2015-04-27 07:49:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int mFD;
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Need implementation of PlatformWrite for this platform"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
void
|
|
|
|
WriteLiteral(PlatformWriter& pw, const char (&str)[N])
|
|
|
|
{
|
|
|
|
pw.WriteBuffer(str, N - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
WriteString(PlatformWriter& pw, const char* str) {
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
size_t len = my_strlen(str);
|
|
|
|
#else
|
|
|
|
size_t len = strlen(str);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pw.WriteBuffer(str, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
static void
|
|
|
|
WriteAnnotation(PlatformWriter& pw, const char (&name)[N],
|
|
|
|
const char* value) {
|
|
|
|
WriteLiteral(pw, name);
|
|
|
|
WriteLiteral(pw, "=");
|
|
|
|
WriteString(pw, value);
|
|
|
|
WriteLiteral(pw, "\n");
|
|
|
|
};
|
|
|
|
|
2012-09-25 04:52:54 -07:00
|
|
|
bool MinidumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
|
|
|
const XP_CHAR* dump_path,
|
2007-07-24 18:06:00 -07:00
|
|
|
const XP_CHAR* minidump_id,
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion,
|
|
|
|
#endif
|
2007-07-24 18:05:56 -07:00
|
|
|
bool succeeded)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:09 -07:00
|
|
|
bool returnValue = showOSCrashReporter ? false : succeeded;
|
2007-07-24 18:06:06 -07:00
|
|
|
|
2011-02-02 10:22:32 -08:00
|
|
|
static XP_CHAR minidumpPath[XP_PATH_MAX];
|
2007-07-24 18:06:00 -07:00
|
|
|
int size = XP_PATH_MAX;
|
2012-09-25 04:52:54 -07:00
|
|
|
XP_CHAR* p;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
p = Concat(minidumpPath, dump_path, &size);
|
2007-07-24 18:06:00 -07:00
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
Concat(p, dumpFileExtension, &size);
|
2012-09-25 04:52:54 -07:00
|
|
|
#else
|
|
|
|
Concat(minidumpPath, descriptor.path(), &size);
|
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
|
2011-02-02 10:22:32 -08:00
|
|
|
static XP_CHAR extraDataPath[XP_PATH_MAX];
|
2007-07-24 18:06:00 -07:00
|
|
|
size = XP_PATH_MAX;
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifndef XP_LINUX
|
2007-07-24 18:06:00 -07:00
|
|
|
p = Concat(extraDataPath, dump_path, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
2012-09-25 04:52:54 -07:00
|
|
|
#else
|
|
|
|
p = Concat(extraDataPath, descriptor.path(), &size);
|
|
|
|
// Skip back past the .dmp extension.
|
|
|
|
p -= 4;
|
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
Concat(p, extraFileExtension, &size);
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2014-08-29 22:21:18 -07:00
|
|
|
static XP_CHAR memoryReportLocalPath[XP_PATH_MAX];
|
|
|
|
size = XP_PATH_MAX;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
p = Concat(memoryReportLocalPath, dump_path, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
#else
|
|
|
|
p = Concat(memoryReportLocalPath, descriptor.path(), &size);
|
|
|
|
// Skip back past the .dmp extension
|
|
|
|
p -= 4;
|
|
|
|
#endif
|
|
|
|
Concat(p, memoryReportExtension, &size);
|
|
|
|
|
|
|
|
if (memoryReportPath) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
CopyFile(memoryReportPath, memoryReportLocalPath, false);
|
|
|
|
#else
|
|
|
|
copy_file(memoryReportPath, memoryReportLocalPath);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
if (headlessClient) {
|
|
|
|
// Leave a marker indicating that there was a crash.
|
2015-04-27 07:49:44 -07:00
|
|
|
PlatformWriter markerFile(crashMarkerFilename);
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
markerFile.WriteBuffer(reinterpret_cast<const char*>(minidumpPath),
|
|
|
|
2*wcslen(minidumpPath));
|
2012-07-16 16:50:52 -07:00
|
|
|
#elif defined(XP_UNIX)
|
2015-04-27 07:49:44 -07:00
|
|
|
markerFile.WriteBuffer(minidumpPath, my_strlen(minidumpPath));
|
2012-07-16 16:50:52 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
char oomAllocationSizeBuffer[32] = "";
|
2012-01-24 08:08:51 -08:00
|
|
|
if (gOOMAllocationSize) {
|
|
|
|
XP_STOA(gOOMAllocationSize, oomAllocationSizeBuffer, 10);
|
|
|
|
}
|
|
|
|
|
2007-08-29 12:46:00 -07:00
|
|
|
// calculate time since last crash (if possible), and store
|
|
|
|
// the time of this crash.
|
2010-07-29 08:31:07 -07:00
|
|
|
time_t crashTime;
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
struct kernel_timeval tv;
|
2013-10-10 13:39:09 -07:00
|
|
|
sys_gettimeofday(&tv, nullptr);
|
2010-07-29 08:31:07 -07:00
|
|
|
crashTime = tv.tv_sec;
|
|
|
|
#else
|
2013-10-10 13:39:09 -07:00
|
|
|
crashTime = time(nullptr);
|
2010-07-29 08:31:07 -07:00
|
|
|
#endif
|
2007-08-29 12:46:00 -07:00
|
|
|
time_t timeSinceLastCrash = 0;
|
|
|
|
// stringified versions of the above
|
|
|
|
char crashTimeString[32];
|
|
|
|
char timeSinceLastCrashString[32];
|
|
|
|
|
|
|
|
XP_TTOA(crashTime, crashTimeString, 10);
|
|
|
|
if (lastCrashTime != 0) {
|
|
|
|
timeSinceLastCrash = crashTime - lastCrashTime;
|
|
|
|
XP_TTOA(timeSinceLastCrash, timeSinceLastCrashString, 10);
|
|
|
|
}
|
|
|
|
// write crash time to file
|
|
|
|
if (lastCrashTimeFilename[0] != 0) {
|
2015-04-27 07:49:44 -07:00
|
|
|
PlatformWriter lastCrashFile(lastCrashTimeFilename);
|
|
|
|
WriteString(lastCrashFile, crashTimeString);
|
2007-08-29 12:46:00 -07:00
|
|
|
}
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2014-02-18 15:58:03 -08: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
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
{
|
|
|
|
PlatformWriter apiData;
|
|
|
|
PlatformWriter eventFile;
|
|
|
|
|
|
|
|
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);
|
2014-02-18 15:58:03 -08:00
|
|
|
#ifdef XP_LINUX
|
2015-04-27 07:49:44 -07:00
|
|
|
p = Concat(p, id_ascii, &size);
|
2014-02-18 15:58:03 -08:00
|
|
|
#else
|
2015-04-27 07:49:44 -07:00
|
|
|
p = Concat(p, minidump_id, &size);
|
2014-02-18 15:58:03 -08:00
|
|
|
#endif
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
eventFile.Open(crashEventPath);
|
|
|
|
WriteLiteral(eventFile, kCrashMainID);
|
|
|
|
WriteString(eventFile, crashTimeString);
|
|
|
|
WriteLiteral(eventFile, "\n");
|
|
|
|
WriteString(eventFile, id_ascii);
|
|
|
|
WriteLiteral(eventFile, "\n");
|
|
|
|
if (crashEventAPIData) {
|
|
|
|
eventFile.WriteBuffer(crashEventAPIData->get(), crashEventAPIData->Length());
|
2015-03-13 22:54:36 -07:00
|
|
|
}
|
2014-02-18 15:58:03 -08:00
|
|
|
}
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
if (!crashReporterAPIData->IsEmpty()) {
|
|
|
|
// write out API data
|
|
|
|
apiData.Open(extraDataPath);
|
|
|
|
apiData.WriteBuffer(crashReporterAPIData->get(), crashReporterAPIData->Length());
|
|
|
|
}
|
|
|
|
WriteAnnotation(apiData, "CrashTime", crashTimeString);
|
|
|
|
if (timeSinceLastCrash != 0) {
|
|
|
|
WriteAnnotation(apiData, "SecondsSinceLastCrash",
|
|
|
|
timeSinceLastCrashString);
|
|
|
|
WriteAnnotation(eventFile, "SecondsSinceLastCrash",
|
|
|
|
timeSinceLastCrashString);
|
|
|
|
}
|
|
|
|
if (isGarbageCollecting) {
|
|
|
|
WriteAnnotation(apiData, "IsGarbageCollecting",
|
|
|
|
isGarbageCollecting ? "1" : "0");
|
|
|
|
WriteAnnotation(eventFile, "IsGarbageCollecting",
|
|
|
|
isGarbageCollecting ? "1" : "0");
|
|
|
|
}
|
2013-11-12 05:31:32 -08:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
char buffer[128];
|
2013-12-06 06:00:06 -08:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
if (eventloopNestingLevel > 0) {
|
|
|
|
XP_STOA(eventloopNestingLevel, buffer, 10);
|
|
|
|
WriteAnnotation(apiData, "EventLoopNestingLevel", buffer);
|
|
|
|
WriteAnnotation(eventFile, "EventLoopNestingLevel", buffer);
|
|
|
|
}
|
2014-02-13 09:51:09 -08:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (gBreakpadReservedVM) {
|
|
|
|
_ui64toa(uintptr_t(gBreakpadReservedVM), buffer, 10);
|
|
|
|
WriteAnnotation(apiData, "BreakpadReserveAddress", buffer);
|
|
|
|
_ui64toa(kReserveSize, buffer, 10);
|
|
|
|
WriteAnnotation(apiData, "BreakpadReserveSize", buffer);
|
|
|
|
}
|
2013-12-06 06:00:06 -08:00
|
|
|
|
2013-11-12 05:31:32 -08:00
|
|
|
#ifdef HAS_DLL_BLOCKLIST
|
2015-04-27 07:49:44 -07:00
|
|
|
if (apiData.Valid()) {
|
|
|
|
DllBlocklist_WriteNotes(apiData.Handle());
|
|
|
|
DllBlocklist_WriteNotes(eventFile.Handle());
|
|
|
|
}
|
2013-11-12 05:31:32 -08:00
|
|
|
#endif
|
2012-01-25 12:05:05 -08:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
// Try to get some information about memory.
|
|
|
|
MEMORYSTATUSEX statex;
|
|
|
|
statex.dwLength = sizeof(statex);
|
|
|
|
if (GlobalMemoryStatusEx(&statex)) {
|
2012-01-25 12:05:05 -08:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
#define WRITE_STATEX_FIELD(field, name, conversionFunc) \
|
|
|
|
conversionFunc(statex.field, buffer, 10); \
|
|
|
|
WriteAnnotation(apiData, name, buffer); \
|
|
|
|
WriteAnnotation(eventFile, name, buffer);
|
2012-01-25 12:05:05 -08:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
WRITE_STATEX_FIELD(dwMemoryLoad, "SystemMemoryUsePercentage", ltoa);
|
|
|
|
WRITE_STATEX_FIELD(ullTotalVirtual, "TotalVirtualMemory", _ui64toa);
|
|
|
|
WRITE_STATEX_FIELD(ullAvailVirtual, "AvailableVirtualMemory", _ui64toa);
|
|
|
|
WRITE_STATEX_FIELD(ullTotalPageFile, "TotalPageFile", _ui64toa);
|
|
|
|
WRITE_STATEX_FIELD(ullAvailPageFile, "AvailablePageFile", _ui64toa);
|
|
|
|
WRITE_STATEX_FIELD(ullTotalPhys, "TotalPhysicalMemory", _ui64toa);
|
|
|
|
WRITE_STATEX_FIELD(ullAvailPhys, "AvailablePhysicalMemory", _ui64toa);
|
2014-08-29 22:21:18 -07:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
#undef WRITE_STATEX_FIELD
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
2015-09-29 08:14:50 -07:00
|
|
|
|
|
|
|
if (gMozCrashReason) {
|
|
|
|
WriteAnnotation(apiData, "MozCrashReason", gMozCrashReason);
|
|
|
|
WriteAnnotation(eventFile, "MozCrashReason", gMozCrashReason);
|
|
|
|
}
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
if (oomAllocationSizeBuffer[0]) {
|
|
|
|
WriteAnnotation(apiData, "OOMAllocationSize", oomAllocationSizeBuffer);
|
|
|
|
WriteAnnotation(eventFile, "OOMAllocationSize", oomAllocationSizeBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memoryReportPath) {
|
|
|
|
WriteLiteral(apiData, "ContainsMemoryReport=1\n");
|
|
|
|
WriteLiteral(eventFile, "ContainsMemoryReport=1\n");
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
#ifdef XP_WIN
|
2007-07-24 18:06:02 -07:00
|
|
|
if (!doReport) {
|
2014-10-08 12:25:20 -07:00
|
|
|
TerminateProcess(GetCurrentProcess(), 1);
|
2007-07-24 18:06:09 -07:00
|
|
|
return returnValue;
|
2007-07-24 18:06:02 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 16:50:52 -07: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-24 18:05:54 -07: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 13:39:09 -07:00
|
|
|
if (CreateProcess(nullptr, (LPWSTR)cmdLine, nullptr, nullptr, FALSE, 0,
|
|
|
|
nullptr, nullptr, &si, &pi)) {
|
2007-07-24 18:05:54 -07: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-24 18:06:00 -07:00
|
|
|
#elif defined(XP_UNIX)
|
2007-07-24 18:06:02 -07:00
|
|
|
if (!doReport) {
|
2007-07-24 18:06:09 -07:00
|
|
|
return returnValue;
|
2007-07-24 18:06:02 -07:00
|
|
|
}
|
|
|
|
|
2010-10-01 12:56:25 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
char* const my_argv[] = {
|
|
|
|
crashReporterPath,
|
|
|
|
minidumpPath,
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr
|
2010-10-01 12:56:25 -07:00
|
|
|
};
|
|
|
|
|
2013-10-10 13:39:09 -07:00
|
|
|
char **env = nullptr;
|
2010-10-01 12:56:25 -07:00
|
|
|
char ***nsEnv = _NSGetEnviron();
|
|
|
|
if (nsEnv)
|
|
|
|
env = *nsEnv;
|
2013-10-10 13:39:09 -07:00
|
|
|
int result = posix_spawnp(nullptr,
|
2010-10-01 12:56:25 -07:00
|
|
|
my_argv[0],
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr,
|
2010-10-01 12:56:25 -07:00
|
|
|
&spawnattr,
|
|
|
|
my_argv,
|
|
|
|
env);
|
|
|
|
|
|
|
|
if (result != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#else // !XP_MACOSX
|
2010-07-29 08:31:07 -07:00
|
|
|
pid_t pid = sys_fork();
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
if (pid == -1)
|
|
|
|
return false;
|
|
|
|
else if (pid == 0) {
|
2012-07-16 16:50:52 -07:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
2007-12-10 10:47:29 -08:00
|
|
|
// need to clobber this, as libcurl might load NSS,
|
|
|
|
// and we want it to load the system NSS.
|
|
|
|
unsetenv("LD_LIBRARY_PATH");
|
2015-11-01 21:53:26 -08:00
|
|
|
Unused << execl(crashReporterPath,
|
2013-10-16 16:46:14 -07:00
|
|
|
crashReporterPath, minidumpPath, (char*)0);
|
2010-10-13 11:27:44 -07:00
|
|
|
#else
|
|
|
|
// Invoke the reportCrash activity using am
|
2012-11-15 14:56:22 -08:00
|
|
|
if (androidUserSerial) {
|
2015-11-01 21:53:26 -08:00
|
|
|
Unused << execlp("/system/bin/am",
|
2013-10-16 16:46:14 -07:00
|
|
|
"/system/bin/am",
|
|
|
|
"start",
|
|
|
|
"--user", androidUserSerial,
|
|
|
|
"-a", "org.mozilla.gecko.reportCrash",
|
|
|
|
"-n", crashReporterPath,
|
|
|
|
"--es", "minidumpPath", minidumpPath,
|
|
|
|
(char*)0);
|
2012-11-15 14:56:22 -08:00
|
|
|
} else {
|
2015-11-01 21:53:26 -08:00
|
|
|
Unused << execlp("/system/bin/am",
|
2013-10-16 16:46:14 -07:00
|
|
|
"/system/bin/am",
|
|
|
|
"start",
|
|
|
|
"-a", "org.mozilla.gecko.reportCrash",
|
|
|
|
"-n", crashReporterPath,
|
|
|
|
"--es", "minidumpPath", minidumpPath,
|
|
|
|
(char*)0);
|
2012-11-15 14:56:22 -08:00
|
|
|
}
|
2010-10-13 11:27:44 -07:00
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
_exit(1);
|
2014-12-15 10:13:12 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
} else {
|
|
|
|
// We need to wait on the 'am start' command above to finish, otherwise everything will
|
|
|
|
// be killed by the ActivityManager as soon as the signal handler exits
|
|
|
|
int status;
|
2015-11-01 21:53:26 -08:00
|
|
|
Unused << HANDLE_EINTR(sys_waitpid(pid, &status, __WALL));
|
2014-12-15 10:13:12 -08:00
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
}
|
2010-10-01 12:56:25 -07:00
|
|
|
#endif // XP_MACOSX
|
|
|
|
#endif // XP_UNIX
|
2007-07-24 18:06:00 -07:00
|
|
|
|
2012-11-15 14:56:22 -08:00
|
|
|
return returnValue;
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
|
|
|
|
2010-01-11 10:16:20 -08:00
|
|
|
#ifdef XP_WIN
|
2013-04-13 06:10:28 -07:00
|
|
|
static void
|
|
|
|
ReserveBreakpadVM()
|
|
|
|
{
|
|
|
|
if (!gBreakpadReservedVM) {
|
2013-11-26 10:22:01 -08:00
|
|
|
gBreakpadReservedVM = VirtualAlloc(nullptr, kReserveSize, MEM_RESERVE,
|
|
|
|
PAGE_NOACCESS);
|
2013-04-13 06:10:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeBreakpadVM()
|
|
|
|
{
|
|
|
|
if (gBreakpadReservedVM) {
|
2013-11-26 10:22:01 -08:00
|
|
|
VirtualFree(gBreakpadReservedVM, 0, MEM_RELEASE);
|
2013-04-13 06:10:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-11 10:16:20 -08:00
|
|
|
/**
|
|
|
|
* Filters out floating point exceptions which are handled by nsSigHandlers.cpp
|
|
|
|
* and should not be handled as crashes.
|
2013-04-13 06:10:28 -07:00
|
|
|
*
|
|
|
|
* Also calls FreeBreakpadVM if appropriate.
|
2010-01-11 10:16:20 -08:00
|
|
|
*/
|
|
|
|
static bool FPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion)
|
|
|
|
{
|
2013-04-13 06:10:28 -07:00
|
|
|
if (!exinfo) {
|
2014-04-02 10:49:56 -07:00
|
|
|
mozilla::IOInterposer::Disable();
|
2013-04-13 06:10:28 -07:00
|
|
|
FreeBreakpadVM();
|
2010-05-04 12:34:55 -07:00
|
|
|
return true;
|
2013-04-13 06:10:28 -07:00
|
|
|
}
|
2010-05-04 12:34:55 -07:00
|
|
|
|
2010-01-11 10:16:20 -08: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 10:49:56 -07:00
|
|
|
mozilla::IOInterposer::Disable();
|
2013-04-13 06:10:28 -07:00
|
|
|
FreeBreakpadVM();
|
2010-01-11 10:16:20 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
|
|
|
|
2010-03-24 14:22:00 -07: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 11:03:26 -08:00
|
|
|
if (envvar && *envvar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
envvar = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
|
|
|
|
if (envvar && *envvar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-03-24 14:22:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 06:15:34 -07:00
|
|
|
namespace {
|
|
|
|
bool Filter(void* context) {
|
2014-03-14 23:10:39 -07:00
|
|
|
mozilla::IOInterposer::Disable();
|
2012-07-03 06:15:34 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult SetExceptionHandler(nsIFile* aXREDirectory,
|
2009-04-02 08:41:12 -07:00
|
|
|
bool force/*=false*/)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
|
|
|
if (gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
2013-11-29 08:15:39 -08: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-29 19:10:57 -07: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-24 18:06:10 -07:00
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
|
|
doReport = false;
|
|
|
|
headlessClient = true;
|
2012-07-27 06:06:38 -07:00
|
|
|
#elif defined(XP_WIN)
|
2015-04-23 12:10:30 -07:00
|
|
|
doReport = ShouldReport();
|
2012-07-16 16:50:52 -07:00
|
|
|
#else
|
2007-07-24 18:06:02 -07:00
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
2010-03-24 14:22:00 -07:00
|
|
|
doReport = ShouldReport();
|
2012-07-16 16:50:52 -07:00
|
|
|
#endif
|
2007-07-24 18:06:02 -07:00
|
|
|
|
2007-07-24 18:05:58 -07:00
|
|
|
// allocate our strings
|
|
|
|
crashReporterAPIData = new nsCString();
|
2015-04-27 07:49:44 -07:00
|
|
|
crashEventAPIData = new nsCString();
|
2007-07-24 18:05:58 -07:00
|
|
|
|
2011-10-06 13:33:21 -07:00
|
|
|
NS_ASSERTION(!crashReporterAPILock, "Shouldn't have a lock yet");
|
|
|
|
crashReporterAPILock = new Mutex("crashReporterAPILock");
|
2012-01-25 06:43:52 -08:00
|
|
|
NS_ASSERTION(!notesFieldLock, "Shouldn't have a lock yet");
|
|
|
|
notesFieldLock = new Mutex("notesFieldLock");
|
2011-10-06 13:33:21 -07:00
|
|
|
|
2007-07-24 18:05:59 -07:00
|
|
|
crashReporterAPIData_Hash =
|
|
|
|
new nsDataHashtable<nsCStringHashKey,nsCString>();
|
|
|
|
NS_ENSURE_TRUE(crashReporterAPIData_Hash, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
notesField = new nsCString();
|
|
|
|
NS_ENSURE_TRUE(notesField, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
if (!headlessClient) {
|
|
|
|
// locate crashreporter executable
|
|
|
|
nsCOMPtr<nsIFile> exePath;
|
|
|
|
nsresult rv = aXREDirectory->Clone(getter_AddRefs(exePath));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-24 18:06:05 -07:00
|
|
|
|
2007-07-24 18:06:06 -07:00
|
|
|
#if defined(XP_MACOSX)
|
2014-10-10 12:07:01 -07:00
|
|
|
exePath->SetNativeLeafName(NS_LITERAL_CSTRING("MacOS"));
|
2012-07-16 16:50:52 -07:00
|
|
|
exePath->Append(NS_LITERAL_STRING("crashreporter.app"));
|
|
|
|
exePath->Append(NS_LITERAL_STRING("Contents"));
|
|
|
|
exePath->Append(NS_LITERAL_STRING("MacOS"));
|
2007-07-24 18:06:06 -07:00
|
|
|
#endif
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
exePath->AppendNative(NS_LITERAL_CSTRING(CRASH_REPORTER_FILENAME));
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
#ifdef XP_WIN32
|
2012-07-16 16:50:52 -07:00
|
|
|
nsString crashReporterPath_temp;
|
2007-07-24 18:05:58 -07:00
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
exePath->GetPath(crashReporterPath_temp);
|
2013-12-05 01:52:54 -08:00
|
|
|
crashReporterPath = reinterpret_cast<wchar_t*>(ToNewUnicode(crashReporterPath_temp));
|
2010-10-13 11:27:44 -07:00
|
|
|
#elif !defined(__ANDROID__)
|
2012-07-16 16:50:52 -07:00
|
|
|
nsCString crashReporterPath_temp;
|
2007-09-15 06:39:05 -07:00
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
exePath->GetNativePath(crashReporterPath_temp);
|
|
|
|
crashReporterPath = ToNewCString(crashReporterPath_temp);
|
2010-10-13 11:27:44 -07:00
|
|
|
#else
|
2012-07-16 16:50:52 -07: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-09 17:10:47 -07:00
|
|
|
nsCString package(ANDROID_PACKAGE_NAME "/org.mozilla.gecko.CrashReporter");
|
2012-07-16 16:50:52 -07:00
|
|
|
crashReporterPath = ToNewCString(package);
|
2007-09-15 06:39:05 -07:00
|
|
|
#endif
|
2012-07-16 16:50:52 -07:00
|
|
|
}
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// get temp path to use for minidump path
|
2007-07-24 18:06:04 -07:00
|
|
|
#if defined(XP_WIN32)
|
2007-09-15 06:39:05 -07:00
|
|
|
nsString tempPath;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// first figure out buffer size
|
2013-10-10 13:39:09 -07:00
|
|
|
int pathLen = GetTempPath(0, nullptr);
|
2007-07-24 18:05:55 -07:00
|
|
|
if (pathLen == 0)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
tempPath.SetLength(pathLen);
|
|
|
|
GetTempPath(pathLen, (LPWSTR)tempPath.BeginWriting());
|
2007-07-24 18:06:00 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
2007-09-15 06:39:05 -07:00
|
|
|
nsCString tempPath;
|
2007-07-24 18:06:00 -07:00
|
|
|
FSRef fsRef;
|
|
|
|
OSErr err = FSFindFolder(kUserDomain, kTemporaryFolderType,
|
|
|
|
kCreateFolder, &fsRef);
|
|
|
|
if (err != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:01 -07:00
|
|
|
char path[PATH_MAX];
|
|
|
|
OSStatus status = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX);
|
2007-07-24 18:06:00 -07:00
|
|
|
if (status != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-09-15 06:39:05 -07:00
|
|
|
|
|
|
|
tempPath = path;
|
2007-07-24 18:06:01 -07:00
|
|
|
|
2010-10-13 11:27:44 -07:00
|
|
|
#elif defined(__ANDROID__)
|
2012-07-16 16:50:52 -07:00
|
|
|
// GeckoAppShell or Gonk's init.rc sets this in the environment
|
2010-10-13 11:27:44 -07:00
|
|
|
const char *tempenv = PR_GetEnv("TMPDIR");
|
|
|
|
if (!tempenv)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCString tempPath(tempenv);
|
2007-07-24 18:06:04 -07:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
// we assume it's always /tmp on unix systems
|
2007-09-15 06:39:05 -07:00
|
|
|
nsCString tempPath = NS_LITERAL_CSTRING("/tmp/");
|
2007-07-24 18:06:00 -07:00
|
|
|
#else
|
2007-09-15 06:39:05 -07:00
|
|
|
#error "Implement this for your platform"
|
2007-07-24 18:06:00 -07:00
|
|
|
#endif
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2010-10-01 12:56:25 -07: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-10 22:50:08 -07:00
|
|
|
size_t attr_count = ArrayLength(pref_cpu_types);
|
2010-10-01 12:56:25 -07: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 09:32:19 -08:00
|
|
|
#ifdef XP_WIN32
|
2013-04-13 06:10:28 -07:00
|
|
|
ReserveBreakpadVM();
|
|
|
|
|
2011-02-02 09:32:19 -08:00
|
|
|
MINIDUMP_TYPE minidump_type = MiniDumpNormal;
|
|
|
|
|
2011-01-12 11:13:52 -08: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 09:32:19 -08:00
|
|
|
|
2013-10-10 13:39:09 -07:00
|
|
|
DWORD version_size = GetFileVersionInfoSizeW(L"dbghelp.dll", nullptr);
|
2011-01-12 11:13:52 -08:00
|
|
|
if (version_size > 0) {
|
|
|
|
std::vector<BYTE> buffer(version_size);
|
|
|
|
if (GetFileVersionInfoW(L"dbghelp.dll",
|
2011-01-28 08:28:10 -08:00
|
|
|
0,
|
|
|
|
version_size,
|
|
|
|
&buffer[0])) {
|
2011-01-12 11:13:52 -08: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 11:03:26 -08:00
|
|
|
|
|
|
|
const char* e = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
|
|
|
|
if (e && *e) {
|
|
|
|
minidump_type = MiniDumpWithFullMemory;
|
|
|
|
}
|
2011-02-02 09:32:19 -08:00
|
|
|
#endif // XP_WIN32
|
2011-01-12 11:13:52 -08:00
|
|
|
|
2012-11-15 14:56:22 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
androidUserSerial = getenv("MOZ_ANDROID_USER_SERIAL_NUMBER");
|
|
|
|
#endif
|
|
|
|
|
2014-01-15 07:03:14 -08: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-24 18:06:03 -07:00
|
|
|
// now set the exception handler
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
MinidumpDescriptor descriptor(tempPath.get());
|
|
|
|
#endif
|
|
|
|
|
2014-01-29 14:07:35 -08:00
|
|
|
#ifdef XP_WIN
|
2014-10-08 12:25:20 -07:00
|
|
|
previousUnhandledExceptionFilter = GetUnhandledExceptionFilter();
|
2014-01-29 14:07:35 -08:00
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
gExceptionHandler = new google_breakpad::
|
2012-09-25 04:52:54 -07:00
|
|
|
ExceptionHandler(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
descriptor,
|
2015-08-21 00:01:47 -07:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
std::wstring(tempPath.get()),
|
2012-09-25 04:52:54 -07:00
|
|
|
#else
|
|
|
|
tempPath.get(),
|
|
|
|
#endif
|
|
|
|
|
2010-01-11 10:16:20 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
FPEFilter,
|
|
|
|
#else
|
2012-07-03 06:15:34 -07:00
|
|
|
Filter,
|
2010-01-11 10:16:20 -08:00
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
MinidumpCallback,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifdef XP_WIN32
|
2011-01-12 11:13:52 -08:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
|
|
|
minidump_type,
|
2013-10-10 13:39:09 -07:00
|
|
|
(const wchar_t*) nullptr,
|
|
|
|
nullptr);
|
2007-07-24 18:06:13 -07:00
|
|
|
#else
|
2010-08-16 12:05:09 -07:00
|
|
|
true
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifdef XP_MACOSX
|
2013-10-10 13:39:09 -07:00
|
|
|
, nullptr
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
, -1
|
2010-08-16 12:05:09 -07:00
|
|
|
#endif
|
|
|
|
);
|
2010-08-16 12:05:09 -07:00
|
|
|
#endif // XP_WIN32
|
2007-07-24 18:05:55 -07:00
|
|
|
|
|
|
|
if (!gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2011-01-11 14:01:22 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
gExceptionHandler->set_handle_debug_exceptions(true);
|
2012-04-20 02:07:55 -07:00
|
|
|
|
2014-10-08 12:25:20 -07:00
|
|
|
#ifdef _WIN64
|
|
|
|
// Tell JS about the new filter before we disable SetUnhandledExceptionFilter
|
|
|
|
sUnhandledExceptionFilter = GetUnhandledExceptionFilter();
|
|
|
|
if (sUnhandledExceptionFilter)
|
|
|
|
js::SetJitExceptionHandler(JitExceptionHandler);
|
|
|
|
#endif
|
|
|
|
|
2012-04-20 02:07:55 -07:00
|
|
|
// protect the crash reporter from being unloaded
|
2012-09-25 04:52:54 -07:00
|
|
|
gBlockUnhandledExceptionFilter = true;
|
2012-04-20 02:07:55 -07: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 14:01:22 -08:00
|
|
|
#endif
|
|
|
|
|
2007-12-21 13:49:32 -08:00
|
|
|
// store application start time
|
|
|
|
char timeString[32];
|
2013-10-10 13:39:09 -07:00
|
|
|
time_t startupTime = time(nullptr);
|
2010-08-11 07:57:44 -07:00
|
|
|
XP_TTOA(startupTime, timeString, 10);
|
2007-12-21 13:49:32 -08:00
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("StartupTime"),
|
|
|
|
nsDependentCString(timeString));
|
|
|
|
|
2007-07-24 18:06:09 -07: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-20 19:07:59 -07:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("OSCrashReporter"),
|
|
|
|
kCFPreferencesCurrentApplication,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat)
|
|
|
|
showOSCrashReporter = prefValue;
|
2007-07-24 18:06:09 -07:00
|
|
|
#endif
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 12:05:47 -07:00
|
|
|
for (unsigned int i = 0; i < library_mappings.size(); i++) {
|
|
|
|
u_int8_t guid[sizeof(MDGUID)];
|
2013-04-09 05:04:53 -07:00
|
|
|
google_breakpad::FileID::ElfFileIdentifierFromMappedFile((void const *)library_mappings[i].start_address, guid);
|
2010-10-19 12:05:47 -07: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 08:08:51 -08:00
|
|
|
mozalloc_set_oom_abort_handler(AnnotateOOMAllocationSize);
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-02 08:41:12 -07:00
|
|
|
bool GetEnabled()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return gExceptionHandler != nullptr;
|
2009-04-02 08:41:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GetMinidumpPath(nsAString& aPath)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return false;
|
|
|
|
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifndef XP_LINUX
|
2009-04-02 08:41:12 -07:00
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(gExceptionHandler->dump_path().c_str());
|
2012-09-25 04:52:54 -07:00
|
|
|
#else
|
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(
|
|
|
|
gExceptionHandler->minidump_descriptor().directory().c_str());
|
|
|
|
#endif
|
2009-04-02 08:41:12 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
nsresult SetMinidumpPath(const nsAString& aPath)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:05:55 -07:00
|
|
|
if (!gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2013-12-05 01:52:54 -08:00
|
|
|
#ifdef XP_WIN32
|
2015-08-21 00:01:47 -07:00
|
|
|
gExceptionHandler->set_dump_path(std::wstring(char16ptr_t(aPath.BeginReading())));
|
2013-12-05 01:52:54 -08:00
|
|
|
#elif defined(XP_LINUX)
|
2012-09-25 04:52:54 -07:00
|
|
|
gExceptionHandler->set_minidump_descriptor(
|
2013-12-05 01:52:54 -08:00
|
|
|
MinidumpDescriptor(NS_ConvertUTF16toUTF8(aPath).BeginReading()));
|
|
|
|
#else
|
|
|
|
gExceptionHandler->set_dump_path(NS_ConvertUTF16toUTF8(aPath).BeginReading());
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:14 -07:00
|
|
|
static nsresult
|
|
|
|
WriteDataToFile(nsIFile* aFile, const nsACString& data)
|
|
|
|
{
|
2007-09-15 06:39:05 -07:00
|
|
|
PRFileDesc* fd;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 00600, &fd);
|
2007-09-15 06:39:05 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-24 18:06:14 -07: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 06:39:05 -07:00
|
|
|
PRFileDesc* fd;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
|
2007-09-15 06:39:05 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-24 18:06:14 -07:00
|
|
|
|
|
|
|
rv = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t filesize = PR_Available(fd);
|
2007-07-24 18:06:14 -07: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 11:35:21 -07:00
|
|
|
static nsresult
|
2007-09-15 06:39:05 -07:00
|
|
|
GetOrInit(nsIFile* aDir, const nsACString& filename,
|
2007-07-24 18:06:15 -07:00
|
|
|
nsACString& aContents, InitDataFunc aInitFunc)
|
2007-07-24 18:06:14 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool exists;
|
2007-07-24 18:06:15 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> dataFile;
|
|
|
|
nsresult rv = aDir->Clone(getter_AddRefs(dataFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
rv = dataFile->AppendNative(filename);
|
2007-07-24 18:06:15 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = dataFile->Exists(&exists);
|
2007-07-24 18:06:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists) {
|
2007-08-29 12:46:00 -07: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-24 18:06:15 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// just get the file's contents
|
|
|
|
rv = GetFileContents(dataFile, aContents);
|
2007-07-24 18:06:14 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:15 -07:00
|
|
|
return rv;
|
2007-07-24 18:06:14 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:15 -07: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 13:39:09 -07:00
|
|
|
time_t t = time(nullptr);
|
2007-07-24 18:06:15 -07:00
|
|
|
char buf[16];
|
2015-05-26 11:33:55 -07:00
|
|
|
snprintf_literal(buf, "%ld", t);
|
2007-07-24 18:06:15 -07:00
|
|
|
aInstallTime = buf;
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:06:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-18 15:58:03 -08: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 12:48:40 -07:00
|
|
|
return rv;
|
2014-02-18 15:58:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-29 12:46:00 -07: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-24 18:06:14 -07:00
|
|
|
// If any piece of data doesn't exist, initialize it first.
|
2012-06-05 19:08:30 -07:00
|
|
|
nsresult SetupExtraData(nsIFile* aAppDataDirectory,
|
2007-07-24 18:06:15 -07:00
|
|
|
const nsACString& aBuildID)
|
2007-07-24 18:06:14 -07:00
|
|
|
{
|
2007-08-29 12:46:00 -07:00
|
|
|
nsCOMPtr<nsIFile> dataDirectory;
|
|
|
|
nsresult rv = aAppDataDirectory->Clone(getter_AddRefs(dataDirectory));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
rv = dataDirectory->AppendNative(NS_LITERAL_CSTRING("Crash Reports"));
|
2007-07-24 18:06:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-02-18 15:58:03 -08:00
|
|
|
EnsureDirectoryExists(dataDirectory);
|
2007-09-04 13:38:38 -07:00
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
#if defined(XP_WIN32)
|
2008-06-24 13:15:35 -07:00
|
|
|
nsAutoString dataDirEnv(NS_LITERAL_STRING("MOZ_CRASHREPORTER_DATA_DIRECTORY="));
|
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
nsAutoString dataDirectoryPath;
|
|
|
|
rv = dataDirectory->GetPath(dataDirectoryPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-06-24 13:15:35 -07:00
|
|
|
dataDirEnv.Append(dataDirectoryPath);
|
|
|
|
|
|
|
|
_wputenv(dataDirEnv.get());
|
2007-09-26 11:35:21 -07:00
|
|
|
#else
|
2008-06-24 13:15:35 -07:00
|
|
|
// Save this path in the environment for the crash reporter application.
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString dataDirEnv("MOZ_CRASHREPORTER_DATA_DIRECTORY=");
|
2008-06-24 13:15:35 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString dataDirectoryPath;
|
2007-09-26 11:35:21 -07: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 13:15:35 -07:00
|
|
|
#endif
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString data;
|
2007-08-29 12:46:00 -07:00
|
|
|
if(NS_SUCCEEDED(GetOrInit(dataDirectory,
|
2007-09-15 06:39:05 -07:00
|
|
|
NS_LITERAL_CSTRING("InstallTime") + aBuildID,
|
2007-07-24 18:06:15 -07:00
|
|
|
data, InitInstallTime)))
|
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("InstallTime"), data);
|
|
|
|
|
2007-08-29 12:46:00 -07: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 06:39:05 -07:00
|
|
|
if(NS_SUCCEEDED(GetOrInit(dataDirectory, NS_LITERAL_CSTRING("LastCrash"),
|
2013-10-10 13:39:09 -07:00
|
|
|
data, nullptr))) {
|
2007-08-29 12:46:00 -07: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 06:39:05 -07:00
|
|
|
rv = lastCrashFile->AppendNative(NS_LITERAL_CSTRING("LastCrash"));
|
2007-08-29 12:46:00 -07: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-01 19:35:17 -07:00
|
|
|
nsAutoCString filename;
|
2007-08-29 12:46:00 -07: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 16:50:52 -07: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-01 19:35:17 -07:00
|
|
|
nsAutoCString markerFilename;
|
2012-07-16 16:50:52 -07: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-24 18:06:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
static void OOPDeinit();
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
nsresult UnsetExceptionHandler()
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2014-01-15 07:03:14 -08:00
|
|
|
if (isSafeToDump) {
|
|
|
|
MutexAutoLock lock(*dumpSafetyLock);
|
|
|
|
isSafeToDump = false;
|
|
|
|
}
|
|
|
|
|
2012-04-20 02:07:55 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// allow SetUnhandledExceptionFilter
|
|
|
|
gBlockUnhandledExceptionFilter = false;
|
|
|
|
#endif
|
|
|
|
|
2009-07-23 08:23:19 -07:00
|
|
|
delete gExceptionHandler;
|
|
|
|
|
2007-07-24 18:05:58 -07:00
|
|
|
// do this here in the unlikely case that we succeeded in allocating
|
|
|
|
// our strings but failed to allocate gExceptionHandler.
|
2011-10-06 13:33:21 -07:00
|
|
|
delete crashReporterAPIData_Hash;
|
2012-07-30 07:20:58 -07:00
|
|
|
crashReporterAPIData_Hash = nullptr;
|
2007-10-24 17:37:18 -07:00
|
|
|
|
2011-10-06 13:33:21 -07:00
|
|
|
delete crashReporterAPILock;
|
2012-07-30 07:20:58 -07:00
|
|
|
crashReporterAPILock = nullptr;
|
2007-10-24 17:37:18 -07:00
|
|
|
|
2012-01-25 06:43:52 -08:00
|
|
|
delete notesFieldLock;
|
2012-07-30 07:20:58 -07:00
|
|
|
notesFieldLock = nullptr;
|
2012-01-25 06:43:52 -08:00
|
|
|
|
2011-10-06 13:33:21 -07:00
|
|
|
delete crashReporterAPIData;
|
2012-07-30 07:20:58 -07:00
|
|
|
crashReporterAPIData = nullptr;
|
2011-10-06 13:33:21 -07:00
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
delete crashEventAPIData;
|
|
|
|
crashEventAPIData = nullptr;
|
|
|
|
|
2011-10-06 13:33:21 -07:00
|
|
|
delete notesField;
|
2012-07-30 07:20:58 -07:00
|
|
|
notesField = nullptr;
|
2008-07-27 10:08:03 -07:00
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
delete lastRunCrashID;
|
2012-07-30 07:20:58 -07:00
|
|
|
lastRunCrashID = nullptr;
|
2012-07-16 16:50:52 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
if (pendingDirectory) {
|
2015-03-31 22:29:55 -07:00
|
|
|
free(pendingDirectory);
|
2012-07-30 07:20:58 -07:00
|
|
|
pendingDirectory = nullptr;
|
2012-07-10 19:20:05 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
if (crashReporterPath) {
|
2015-03-31 22:29:55 -07:00
|
|
|
free(crashReporterPath);
|
2012-07-30 07:20:58 -07:00
|
|
|
crashReporterPath = nullptr;
|
2007-07-24 18:06:00 -07:00
|
|
|
}
|
2007-07-24 18:05:58 -07:00
|
|
|
|
2014-02-18 15:58:03 -08:00
|
|
|
if (eventsDirectory) {
|
2015-03-31 22:29:55 -07:00
|
|
|
free(eventsDirectory);
|
2014-02-18 15:58:03 -08:00
|
|
|
eventsDirectory = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-29 22:21:09 -07:00
|
|
|
if (memoryReportPath) {
|
2015-03-31 22:29:55 -07:00
|
|
|
free(memoryReportPath);
|
2014-08-29 22:21:09 -07:00
|
|
|
memoryReportPath = nullptr;
|
|
|
|
}
|
|
|
|
|
2010-10-01 12:56:25 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
posix_spawnattr_destroy(&spawnattr);
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
if (!gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gExceptionHandler = nullptr;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
OOPDeinit();
|
|
|
|
|
2014-01-15 07:03:14 -08:00
|
|
|
delete dumpSafetyLock;
|
|
|
|
dumpSafetyLock = nullptr;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReplaceChar(nsCString& str, const nsACString& character,
|
|
|
|
const nsACString& replacement)
|
|
|
|
{
|
|
|
|
nsCString::const_iterator start, end;
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
str.BeginReading(start);
|
|
|
|
str.EndReading(end);
|
|
|
|
|
|
|
|
while (FindInReadable(character, start, end)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pos = end.size_backward();
|
2007-07-24 18:05:55 -07:00
|
|
|
str.Replace(pos - 1, 1, replacement);
|
|
|
|
|
|
|
|
str.BeginReading(start);
|
|
|
|
start.advance(pos + replacement.Length() - 1);
|
|
|
|
str.EndReading(end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool DoFindInReadable(const nsACString& str, const nsACString& value)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
str.BeginReading(start);
|
|
|
|
str.EndReading(end);
|
|
|
|
|
|
|
|
return FindInReadable(value, start, end);
|
|
|
|
}
|
|
|
|
|
2015-04-27 07:49:44 -07:00
|
|
|
static bool
|
|
|
|
IsInWhitelist(const nsACString& key)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < ArrayLength(kCrashEventAnnotations); ++i) {
|
|
|
|
if (key.EqualsASCII(kCrashEventAnnotations[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-30 10:02:52 -07:00
|
|
|
// This function is miscompiled with MSVC 2005/2008 when PGO is on.
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma optimize("", off)
|
|
|
|
#endif
|
2011-06-08 13:21:03 -07:00
|
|
|
static nsresult
|
|
|
|
EscapeAnnotation(const nsACString& key, const nsACString& data, nsCString& escapedData)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
|
|
|
if (DoFindInReadable(key, NS_LITERAL_CSTRING("=")) ||
|
|
|
|
DoFindInReadable(key, NS_LITERAL_CSTRING("\n")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-24 18:05:57 -07:00
|
|
|
if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-06-08 13:21:03 -07:00
|
|
|
escapedData = data;
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:05:55 -07: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 13:21:03 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-30 10:02:52 -07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma optimize("", on)
|
|
|
|
#endif
|
2011-06-08 13:21:03 -07:00
|
|
|
|
|
|
|
class DelayedNote
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DelayedNote(const nsACString& aKey, const nsACString& aData)
|
|
|
|
: mKey(aKey), mData(aData), mType(Annotation) {}
|
|
|
|
|
2014-09-02 15:24:24 -07:00
|
|
|
explicit DelayedNote(const nsACString& aData)
|
2011-06-08 13:21:03 -07:00
|
|
|
: mData(aData), mType(AppNote) {}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2011-06-08 13:21:03 -07: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;
|
|
|
|
|
2015-07-03 18:29:00 -07:00
|
|
|
if (!XRE_IsParentProcess()) {
|
2011-10-06 13:33:21 -07:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_ERROR("Cannot call AnnotateCrashReport in child processes from non-main thread.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-06-08 13:21:03 -07: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 13:33:21 -07:00
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
crashReporterAPIData_Hash->Put(key, escapedData);
|
2007-07-24 18:05:59 -07:00
|
|
|
|
|
|
|
// now rebuild the file contents
|
|
|
|
crashReporterAPIData->Truncate(0);
|
2015-04-27 07:49:44 -07:00
|
|
|
crashEventAPIData->Truncate(0);
|
2015-10-19 15:46:46 -07:00
|
|
|
for (auto it = crashReporterAPIData_Hash->Iter(); !it.Done(); it.Next()) {
|
|
|
|
const nsACString& key = it.Key();
|
|
|
|
nsCString entry = it.Data();
|
|
|
|
if (!entry.IsEmpty()) {
|
|
|
|
NS_NAMED_LITERAL_CSTRING(kEquals, "=");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(kNewline, "\n");
|
|
|
|
nsAutoCString line = key + kEquals + entry + kNewline;
|
|
|
|
|
|
|
|
crashReporterAPIData->Append(line);
|
|
|
|
if (IsInWhitelist(key)) {
|
|
|
|
crashEventAPIData->Append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-24 18:05:59 -07:00
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2014-10-28 09:08:46 -07:00
|
|
|
nsresult RemoveCrashReportAnnotation(const nsACString& key)
|
|
|
|
{
|
|
|
|
return AnnotateCrashReport(key, NS_LITERAL_CSTRING(""));
|
|
|
|
}
|
|
|
|
|
2012-08-15 10:47:51 -07:00
|
|
|
nsresult SetGarbageCollecting(bool collecting)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
isGarbageCollecting = collecting;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-13 09:51:09 -08:00
|
|
|
void SetEventloopNestingLevel(uint32_t level)
|
|
|
|
{
|
|
|
|
eventloopNestingLevel = level;
|
|
|
|
}
|
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
nsresult AppendAppNotesToCrashReport(const nsACString& data)
|
|
|
|
{
|
2010-10-13 18:47:43 -07:00
|
|
|
if (!GetEnabled())
|
2008-07-27 10:08:03 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2015-07-03 18:29:00 -07:00
|
|
|
if (!XRE_IsParentProcess()) {
|
2012-01-25 06:43:52 -08:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_ERROR("Cannot call AnnotateCrashReport in child processes from non-main thread.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-06-08 13:21:03 -07: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 06:43:52 -08:00
|
|
|
MutexAutoLock lock(*notesFieldLock);
|
|
|
|
|
2008-07-27 10:08:03 -07: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 08:41:12 -07:00
|
|
|
return false;
|
2008-07-27 10:08:03 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString entry;
|
2008-07-27 10:08:03 -07:00
|
|
|
if (!crashReporterAPIData_Hash->Get(key, &entry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
data = entry;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:31:01 -07: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 08:41:12 -07: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-24 18:06:05 -07:00
|
|
|
nsresult
|
2008-07-27 10:08:03 -07:00
|
|
|
SetRestartArgs(int argc, char** argv)
|
2007-07-24 18:06:05 -07:00
|
|
|
{
|
2007-07-24 18:06:10 -07:00
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
int i;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString envVar;
|
2007-07-24 18:06:06 -07:00
|
|
|
char *env;
|
2012-06-20 08:41:34 -07:00
|
|
|
char *argv0 = getenv("MOZ_APP_LAUNCHER");
|
2007-07-24 18:06:05 -07:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
2012-06-20 08:41:34 -07:00
|
|
|
if (argv0 && i == 0) {
|
|
|
|
// Is there a request to suppress default binary launcher?
|
|
|
|
envVar += argv0;
|
|
|
|
} else {
|
2007-12-21 11:40:39 -08:00
|
|
|
envVar += argv[i];
|
|
|
|
}
|
2007-07-24 18:06:06 -07: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-24 18:06:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the arg list is terminated
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
|
|
|
|
2007-07-24 18:06:06 -07: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-24 18:06:05 -07:00
|
|
|
|
2007-07-24 18:06:12 -07: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-24 18:06:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-08 18:40:47 -08: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 10:29:51 -08:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
bool WriteMinidumpForSigInfo(int signo, siginfo_t* info, void* uc)
|
|
|
|
{
|
2014-07-22 04:05:00 -07:00
|
|
|
if (!gExceptionHandler) {
|
|
|
|
// Crash reporting is disabled.
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-05 10:29:51 -08:00
|
|
|
return gExceptionHandler->HandleSignal(signo, info, uc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-27 21:41:38 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
nsresult AppendObjCExceptionInfoToAppNotes(void *inException)
|
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString excString;
|
2008-08-27 21:41:38 -07:00
|
|
|
GetObjCExceptionInfo(inException, excString);
|
|
|
|
AppendAppNotesToCrashReport(excString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-09 17:05:31 -08:00
|
|
|
/*
|
|
|
|
* Combined code to get/set the crash reporter submission pref on
|
|
|
|
* different platforms.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static nsresult PrefSubmitReports(bool* aSubmitReports, bool writePref)
|
2010-02-09 17:05:31 -08: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-01 19:35:17 -07:00
|
|
|
nsAutoCString appVendor, appName;
|
2010-02-09 17:05:31 -08: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-01 19:35:17 -07:00
|
|
|
nsAutoCString regPath;
|
2010-02-09 17:05:31 -08:00
|
|
|
|
|
|
|
regPath.AppendLiteral("Software\\");
|
2012-07-10 15:31:03 -07:00
|
|
|
|
|
|
|
// We need to ensure the registry keys are created so we can properly
|
|
|
|
// write values to it
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
// Create appVendor key
|
|
|
|
if(!appVendor.IsEmpty()) {
|
|
|
|
regPath.Append(appVendor);
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
2014-05-26 11:54:58 -07:00
|
|
|
regPath.Append('\\');
|
2012-07-16 16:50:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create appName key
|
|
|
|
regPath.Append(appName);
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
2014-05-26 11:54:58 -07:00
|
|
|
regPath.Append('\\');
|
2012-07-16 16:50:52 -07:00
|
|
|
|
|
|
|
// Create Crash Reporter key
|
|
|
|
regPath.AppendLiteral("Crash Reporter");
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
2012-07-10 15:31:03 -07:00
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
2010-02-09 17:05:31 -08: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 08:56:38 -07:00
|
|
|
uint32_t value = *aSubmitReports ? 1 : 0;
|
2010-02-09 17:05:31 -08: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 08:56:38 -07:00
|
|
|
uint32_t value;
|
2010-02-09 17:05:31 -08: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 07:59:28 -07:00
|
|
|
*aSubmitReports = true;
|
2010-02-09 17:05:31 -08: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-09 18:11:08 -08:00
|
|
|
#elif defined(XP_MACOSX)
|
2010-06-20 19:07:59 -07: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 07:59:28 -07:00
|
|
|
*aSubmitReports = true;
|
2010-06-20 19:07:59 -07:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("submitReport"),
|
|
|
|
reporterClientAppID,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat)
|
|
|
|
*aSubmitReports = !!prefValue;
|
|
|
|
}
|
|
|
|
return rv;
|
2010-02-09 17:05:31 -08: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-28 23:19:26 -07:00
|
|
|
bool exists;
|
2010-02-09 17:05:31 -08: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 07:59:28 -07:00
|
|
|
*aSubmitReports = true;
|
2010-02-09 17:05:31 -08: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-05 19:08:30 -07:00
|
|
|
rv = iniFactory->CreateINIParser(reporterINI,
|
2010-02-09 17:05:31 -08: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 13:39:09 -07:00
|
|
|
rv = iniWriter->WriteFile(nullptr, 0);
|
2010-02-09 17:05:31 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString submitReportValue;
|
2010-02-09 17:05:31 -08: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 07:59:28 -07:00
|
|
|
*aSubmitReports = true;
|
2010-02-09 17:05:31 -08:00
|
|
|
else if (submitReportValue.EqualsASCII("0"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*aSubmitReports = false;
|
2010-02-09 17:05:31 -08:00
|
|
|
else
|
2011-10-17 07:59:28 -07:00
|
|
|
*aSubmitReports = true;
|
2010-02-09 17:05:31 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult GetSubmitReports(bool* aSubmitReports)
|
2010-02-09 17:05:31 -08:00
|
|
|
{
|
|
|
|
return PrefSubmitReports(aSubmitReports, false);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SetSubmitReports(bool aSubmitReports)
|
2010-02-09 17:05:31 -08:00
|
|
|
{
|
2011-10-03 13:26:08 -07: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 07:20:58 -07:00
|
|
|
obsServ->NotifyObservers(nullptr, "submit-reports-pref-changed", nullptr);
|
2011-10-03 13:26:08 -07:00
|
|
|
return NS_OK;
|
2010-02-09 17:05:31 -08:00
|
|
|
}
|
|
|
|
|
2014-05-06 12:48:40 -07:00
|
|
|
static void
|
|
|
|
SetCrashEventsDir(nsIFile* aDir)
|
2014-02-18 15:58:03 -08:00
|
|
|
{
|
2014-05-06 12:48:40 -07:00
|
|
|
nsCOMPtr<nsIFile> eventsDir = aDir;
|
2014-02-18 15:58:03 -08:00
|
|
|
|
|
|
|
const char *env = PR_GetEnv("CRASHES_EVENTS_DIR");
|
2014-05-06 12:48:40 -07:00
|
|
|
if (env && *env) {
|
|
|
|
NS_NewNativeLocalFile(nsDependentCString(env),
|
|
|
|
false, getter_AddRefs(eventsDir));
|
2014-02-18 15:58:03 -08:00
|
|
|
EnsureDirectoryExists(eventsDir);
|
2014-05-06 12:48:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eventsDirectory) {
|
2015-03-31 22:29:55 -07:00
|
|
|
free(eventsDirectory);
|
2014-02-18 15:58:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsString path;
|
|
|
|
eventsDir->GetPath(path);
|
|
|
|
eventsDirectory = reinterpret_cast<wchar_t*>(ToNewUnicode(path));
|
2014-07-03 14:51:08 -07:00
|
|
|
|
|
|
|
// Save the path in the environment for the crash reporter application.
|
|
|
|
nsAutoString eventsDirEnv(NS_LITERAL_STRING("MOZ_CRASHREPORTER_EVENTS_DIRECTORY="));
|
|
|
|
eventsDirEnv.Append(path);
|
|
|
|
_wputenv(eventsDirEnv.get());
|
2014-02-18 15:58:03 -08:00
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
eventsDir->GetNativePath(path);
|
|
|
|
eventsDirectory = ToNewCString(path);
|
2014-07-03 14:51:08 -07:00
|
|
|
|
|
|
|
// Save the path in the environment for the crash reporter application.
|
|
|
|
nsAutoCString eventsDirEnv("MOZ_CRASHREPORTER_EVENTS_DIRECTORY=");
|
|
|
|
eventsDirEnv.Append(path);
|
|
|
|
|
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here.
|
|
|
|
char* oldEventsEnv = eventsEnv;
|
|
|
|
eventsEnv = ToNewCString(eventsDirEnv);
|
|
|
|
PR_SetEnv(eventsEnv);
|
|
|
|
|
|
|
|
if (oldEventsEnv) {
|
2015-03-31 22:29:55 -07:00
|
|
|
free(oldEventsEnv);
|
2014-07-03 14:51:08 -07:00
|
|
|
}
|
2014-02-18 15:58:03 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:48:40 -07: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 15:58:03 -08:00
|
|
|
bool GetCrashEventsDir(nsAString& aPath)
|
|
|
|
{
|
|
|
|
if (!eventsDirectory) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(eventsDirectory);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-29 22:21:09 -07:00
|
|
|
void
|
|
|
|
SetMemoryReportFile(nsIFile* aFile)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsString path;
|
|
|
|
aFile->GetPath(path);
|
2014-11-03 05:15:17 -08:00
|
|
|
memoryReportPath = reinterpret_cast<wchar_t*>(ToNewUnicode(path));
|
2014-08-29 22:21:09 -07:00
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
aFile->GetNativePath(path);
|
|
|
|
memoryReportPath = ToNewCString(path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-07-16 16:50:52 -07: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 01:52:54 -08:00
|
|
|
pendingDirectory = reinterpret_cast<wchar_t*>(ToNewUnicode(path));
|
2012-07-16 16:50:52 -07:00
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
pendingDir->GetNativePath(path);
|
|
|
|
pendingDirectory = ToNewCString(path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
// The "pending" dir is Crash Reports/pending, from which minidumps
|
2012-07-10 19:20:05 -07: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 14:22:01 -07:00
|
|
|
static bool
|
2012-06-05 19:08:30 -07:00
|
|
|
GetPendingDir(nsIFile** dir)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
2014-11-01 08:45:25 -07:00
|
|
|
// MOZ_ASSERT(OOPInitialized());
|
2012-07-10 19:20:05 -07:00
|
|
|
if (!pendingDirectory) {
|
2010-03-24 14:22:01 -07:00
|
|
|
return false;
|
2012-07-10 19:20:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> pending = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
2012-07-13 10:43:17 -07:00
|
|
|
if (!pending) {
|
|
|
|
NS_WARNING("Can't set up pending directory during shutdown.");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-10 19:20:05 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
pending->InitWithPath(nsDependentString(pendingDirectory));
|
|
|
|
#else
|
|
|
|
pending->InitWithNativePath(nsDependentCString(pendingDirectory));
|
|
|
|
#endif
|
|
|
|
pending.swap(*dir);
|
2010-03-24 14:22:01 -07:00
|
|
|
return true;
|
|
|
|
}
|
2010-02-09 17:05:31 -08:00
|
|
|
|
2010-03-24 14:22:01 -07: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-05 19:08:30 -07:00
|
|
|
GetMinidumpLimboDir(nsIFile** dir)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
|
|
|
if (ShouldReport()) {
|
|
|
|
return GetPendingDir(dir);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifndef XP_LINUX
|
2010-03-24 14:22:01 -07:00
|
|
|
CreateFileFromPath(gExceptionHandler->dump_path(), dir);
|
2012-09-25 04:52:54 -07:00
|
|
|
#else
|
|
|
|
CreateFileFromPath(gExceptionHandler->minidump_descriptor().directory(),
|
|
|
|
dir);
|
|
|
|
#endif
|
2013-10-10 13:39:09 -07:00
|
|
|
return nullptr != *dir;
|
2010-03-24 14:22:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
void
|
|
|
|
DeleteMinidumpFilesForID(const nsAString& id)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> minidumpFile;
|
|
|
|
GetMinidumpForID(id, getter_AddRefs(minidumpFile));
|
|
|
|
bool exists = false;
|
|
|
|
if (minidumpFile && NS_SUCCEEDED(minidumpFile->Exists(&exists)) && exists) {
|
|
|
|
nsCOMPtr<nsIFile> childExtraFile;
|
|
|
|
GetExtraFileForMinidump(minidumpFile, getter_AddRefs(childExtraFile));
|
|
|
|
if (childExtraFile) {
|
|
|
|
childExtraFile->Remove(false);
|
|
|
|
}
|
|
|
|
minidumpFile->Remove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
bool
|
2012-06-05 19:08:30 -07:00
|
|
|
GetMinidumpForID(const nsAString& id, nsIFile** minidump)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
|
|
|
if (!GetMinidumpLimboDir(minidump))
|
|
|
|
return false;
|
|
|
|
(*minidump)->Append(id + NS_LITERAL_STRING(".dmp"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-05 19:08:30 -07:00
|
|
|
GetIDFromMinidump(nsIFile* minidump, nsAString& id)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
2015-06-11 10:25:45 -07:00
|
|
|
if (minidump && NS_SUCCEEDED(minidump->GetLeafName(id))) {
|
2010-03-24 14:22:01 -07:00
|
|
|
id.Replace(id.Length() - 4, 4, NS_LITERAL_STRING(""));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-05 19:08:30 -07:00
|
|
|
GetExtraFileForID(const nsAString& id, nsIFile** extraFile)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
|
|
|
if (!GetMinidumpLimboDir(extraFile))
|
|
|
|
return false;
|
|
|
|
(*extraFile)->Append(id + NS_LITERAL_STRING(".extra"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-05 19:08:30 -07:00
|
|
|
GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile)
|
2010-03-24 14:22:01 -07: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-05 19:08:30 -07:00
|
|
|
rv = extraF->SetLeafName(leafName);
|
2010-03-24 14:22:01 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
2013-10-10 13:39:09 -07:00
|
|
|
*extraFile = nullptr;
|
2012-06-05 19:08:30 -07:00
|
|
|
extraF.swap(*extraFile);
|
2010-03-24 14:22:01 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AppendExtraData(const nsAString& id, const AnnotationTable& data)
|
|
|
|
{
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> extraFile;
|
2010-03-24 14:22:01 -07:00
|
|
|
if (!GetExtraFileForID(id, getter_AddRefs(extraFile)))
|
|
|
|
return false;
|
|
|
|
return AppendExtraData(extraFile, data);
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helpers for AppendExtraData()
|
|
|
|
//
|
2010-03-24 14:22:00 -07:00
|
|
|
struct Blacklist {
|
2013-10-10 13:39:09 -07:00
|
|
|
Blacklist() : mItems(nullptr), mLen(0) { }
|
2010-03-24 14:22:00 -07: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;
|
|
|
|
};
|
|
|
|
|
2010-03-24 14:22:01 -07: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 14:22:00 -07:00
|
|
|
static bool
|
2012-06-05 19:08:30 -07:00
|
|
|
WriteExtraData(nsIFile* extraFile,
|
2010-03-24 14:22:01 -07:00
|
|
|
const AnnotationTable& data,
|
|
|
|
const Blacklist& blacklist,
|
|
|
|
bool writeCrashTime=false,
|
|
|
|
bool truncate=false)
|
2010-03-24 14:22:00 -07:00
|
|
|
{
|
2010-03-24 14:22:01 -07:00
|
|
|
PRFileDesc* fd;
|
2012-08-09 00:09:40 -07:00
|
|
|
int truncOrAppend = truncate ? PR_TRUNCATE : PR_APPEND;
|
2015-10-19 15:46:46 -07:00
|
|
|
nsresult rv =
|
2010-03-24 14:22:01 -07:00
|
|
|
extraFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | truncOrAppend,
|
|
|
|
0600, &fd);
|
2010-03-24 14:22:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
2015-10-19 15:46:46 -07:00
|
|
|
for (auto iter = data.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
// Skip entries in the blacklist.
|
|
|
|
const nsACString& key = iter.Key();
|
|
|
|
if (blacklist.Contains(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WriteAnnotation(fd, key, iter.Data());
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
if (writeCrashTime) {
|
2013-10-10 13:39:09 -07:00
|
|
|
time_t crashTime = time(nullptr);
|
2010-03-24 14:22:01 -07:00
|
|
|
char crashTimeString[32];
|
|
|
|
XP_TTOA(crashTime, crashTimeString, 10);
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
WriteAnnotation(fd,
|
|
|
|
nsDependentCString("CrashTime"),
|
|
|
|
nsDependentCString(crashTimeString));
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
PR_Close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
bool
|
2012-06-05 19:08:30 -07:00
|
|
|
AppendExtraData(nsIFile* extraFile, const AnnotationTable& data)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
|
|
|
return WriteExtraData(extraFile, data, Blacklist());
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
static bool
|
2012-06-05 19:08:30 -07:00
|
|
|
WriteExtraForMinidump(nsIFile* minidump,
|
2010-03-24 14:22:01 -07:00
|
|
|
const Blacklist& blacklist,
|
2012-06-05 19:08:30 -07:00
|
|
|
nsIFile** extraFile)
|
2010-03-24 14:22:01 -07:00
|
|
|
{
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> extra;
|
2010-03-24 14:22:01 -07: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 14:22:00 -07:00
|
|
|
|
2013-10-10 13:39:09 -07:00
|
|
|
*extraFile = nullptr;
|
2010-03-24 14:22:00 -07:00
|
|
|
extra.swap(*extraFile);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
// It really only makes sense to call this function when
|
|
|
|
// ShouldReport() is true.
|
2010-02-09 17:05:31 -08:00
|
|
|
static bool
|
|
|
|
MoveToPending(nsIFile* dumpFile, nsIFile* extraFile)
|
|
|
|
{
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> pendingDir;
|
2010-03-24 14:22:01 -07:00
|
|
|
if (!GetPendingDir(getter_AddRefs(pendingDir)))
|
|
|
|
return false;
|
2010-02-09 17:05:31 -08:00
|
|
|
|
2012-09-08 10:20:59 -07:00
|
|
|
if (NS_FAILED(dumpFile->MoveTo(pendingDir, EmptyString()))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extraFile && NS_FAILED(extraFile->MoveTo(pendingDir, EmptyString()))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-02-09 17:05:31 -08:00
|
|
|
}
|
|
|
|
|
2010-01-12 13:14:38 -08:00
|
|
|
static void
|
|
|
|
OnChildProcessDumpRequested(void* aContext,
|
2010-08-16 12:05:09 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
const ClientInfo& aClientInfo,
|
|
|
|
const xpstring& aFilePath
|
|
|
|
#else
|
2010-01-12 13:14:38 -08:00
|
|
|
const ClientInfo* aClientInfo,
|
2010-08-16 12:05:09 -07:00
|
|
|
const xpstring* aFilePath
|
|
|
|
#endif
|
|
|
|
)
|
2010-01-12 13:14:38 -08:00
|
|
|
{
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
nsCOMPtr<nsIFile> extraFile;
|
2010-01-14 14:38:00 -08:00
|
|
|
|
2014-01-15 07:03:14 -08: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 12:05:09 -07:00
|
|
|
CreateFileFromPath(
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
aFilePath,
|
|
|
|
#else
|
|
|
|
*aFilePath,
|
|
|
|
#endif
|
|
|
|
getter_AddRefs(minidump));
|
2010-01-14 14:38:00 -08:00
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
if (!WriteExtraForMinidump(minidump,
|
|
|
|
Blacklist(kSubprocessBlacklist,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(kSubprocessBlacklist)),
|
2010-03-24 14:22:00 -07:00
|
|
|
getter_AddRefs(extraFile)))
|
2010-01-14 14:38:00 -08:00
|
|
|
return;
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
if (ShouldReport())
|
|
|
|
MoveToPending(minidump, extraFile);
|
2010-02-09 17:05:31 -08:00
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t pid =
|
2010-08-16 12:05:09 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
aClientInfo.pid();
|
|
|
|
#else
|
|
|
|
aClientInfo->pid();
|
|
|
|
#endif
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
bool runCallback;
|
|
|
|
#endif
|
2012-07-02 11:55:23 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2012-07-10 19:20:05 -07:00
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(pid);
|
|
|
|
MOZ_ASSERT(!pd->minidump);
|
|
|
|
pd->minidump = minidump;
|
|
|
|
pd->sequence = ++crashSequence;
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-10-10 13:39:09 -07:00
|
|
|
runCallback = nullptr != pd->callback;
|
2012-07-10 19:20:05 -07:00
|
|
|
#endif
|
2012-07-02 11:55:23 -07:00
|
|
|
}
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2012-07-10 19:20:05 -07:00
|
|
|
if (runCallback)
|
|
|
|
NS_DispatchToMainThread(new ReportInjectedCrash(pid));
|
2012-07-02 11:55:23 -07:00
|
|
|
#endif
|
2010-01-14 14:38:00 -08:00
|
|
|
}
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
OOPInitialized()
|
|
|
|
{
|
2013-10-10 13:39:09 -07:00
|
|
|
return pidToMinidump != nullptr;
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifdef XP_MACOSX
|
2012-07-03 06:15:34 -07:00
|
|
|
static bool ChildFilter(void *context) {
|
2014-03-14 23:10:39 -07:00
|
|
|
mozilla::IOInterposer::Disable();
|
2012-07-03 06:15:34 -07:00
|
|
|
return true;
|
|
|
|
}
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2012-07-03 06:15:34 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
void
|
2010-01-12 13:14:38 -08:00
|
|
|
OOPInit()
|
|
|
|
{
|
2014-07-18 10:31:45 -07:00
|
|
|
class ProxyToMainThread : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
OOPInit();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// This logic needs to run on the main thread
|
|
|
|
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
|
|
|
|
mozilla::SyncRunnable::DispatchToThread(mainThread, new ProxyToMainThread());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
if (OOPInitialized())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(gExceptionHandler != nullptr,
|
|
|
|
"attempt to initialize OOP crash reporter before in-process crashreporter!");
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2010-01-13 07:44:10 -08:00
|
|
|
childCrashNotifyPipe =
|
|
|
|
PR_smprintf("\\\\.\\pipe\\gecko-crash-server-pipe.%i",
|
|
|
|
static_cast<int>(::GetCurrentProcessId()));
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
const std::wstring dumpPath = gExceptionHandler->dump_path();
|
|
|
|
crashServer = new CrashGenerationServer(
|
2015-08-21 00:01:47 -07:00
|
|
|
std::wstring(NS_ConvertASCIItoUTF16(childCrashNotifyPipe).get()),
|
2013-10-10 13:39:09 -07: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 13:14:38 -08: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 04:52:54 -07:00
|
|
|
const std::string dumpPath =
|
|
|
|
gExceptionHandler->minidump_descriptor().directory();
|
2010-01-12 13:14:38 -08:00
|
|
|
crashServer = new CrashGenerationServer(
|
|
|
|
serverSocketFd,
|
2013-10-10 13:39:09 -07:00
|
|
|
OnChildProcessDumpRequested, nullptr,
|
|
|
|
nullptr, nullptr, // we don't care about process exit here
|
2012-09-25 04:52:54 -07:00
|
|
|
true,
|
2010-01-12 13:14:38 -08:00
|
|
|
&dumpPath);
|
2010-08-16 12:05:09 -07: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 06:15:34 -07:00
|
|
|
ChildFilter,
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr,
|
|
|
|
OnChildProcessDumpRequested, nullptr,
|
|
|
|
nullptr, nullptr,
|
2010-08-16 12:05:09 -07:00
|
|
|
true, // automatically generate dumps
|
|
|
|
dumpPath);
|
2010-01-12 13:14:38 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!crashServer->Start())
|
|
|
|
NS_RUNTIMEABORT("can't start crash reporter server()");
|
2010-01-14 14:38:00 -08:00
|
|
|
|
|
|
|
pidToMinidump = new ChildMinidumpMap();
|
|
|
|
|
|
|
|
dumpMapLock = new Mutex("CrashReporter::dumpMapLock");
|
2012-07-10 19:20:05 -07:00
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
FindPendingDir();
|
2014-02-18 15:58:03 -08:00
|
|
|
UpdateCrashEventsDir();
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
static void
|
|
|
|
OOPDeinit()
|
|
|
|
{
|
|
|
|
if (!OOPInitialized()) {
|
|
|
|
NS_WARNING("OOPDeinit() without successful OOPInit()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-02 11:55:23 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
if (sInjectorThread) {
|
|
|
|
sInjectorThread->Shutdown();
|
|
|
|
NS_RELEASE(sInjectorThread);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
delete crashServer;
|
2013-10-10 13:39:09 -07:00
|
|
|
crashServer = nullptr;
|
2010-01-20 18:17:40 -08:00
|
|
|
|
|
|
|
delete dumpMapLock;
|
2013-10-10 13:39:09 -07:00
|
|
|
dumpMapLock = nullptr;
|
2010-01-20 18:17:40 -08:00
|
|
|
|
|
|
|
delete pidToMinidump;
|
2013-10-10 13:39:09 -07:00
|
|
|
pidToMinidump = nullptr;
|
2010-01-20 18:17:40 -08:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
PR_Free(childCrashNotifyPipe);
|
2013-10-10 13:39:09 -07:00
|
|
|
childCrashNotifyPipe = nullptr;
|
2010-01-20 18:17:40 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-16 12:05:09 -07:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
// Parent-side API for children
|
2010-01-13 07:44:10 -08:00
|
|
|
const char*
|
2010-01-12 13:14:38 -08:00
|
|
|
GetChildNotificationPipe()
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
2010-01-13 07:44:10 -08:00
|
|
|
return kNullNotifyPipe;
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2010-01-13 07:44:10 -08:00
|
|
|
return childCrashNotifyPipe;
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
2010-08-16 12:05:09 -07:00
|
|
|
#endif
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2012-07-02 11:55:23 -07: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-10 19:20:05 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(processID);
|
|
|
|
MOZ_ASSERT(!pd->minidump && !pd->callback);
|
|
|
|
pd->callback = cb;
|
|
|
|
}
|
2012-07-02 11:55:23 -07: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-10 19:20:05 -07:00
|
|
|
if (!OOPInitialized())
|
2012-07-02 11:55:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
InjectorCrashCallback* cb;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(mPID);
|
|
|
|
if (!pd || !pd->callback)
|
|
|
|
return NS_OK;
|
2012-07-02 11:55:23 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
MOZ_ASSERT(pd->minidump);
|
2012-07-02 11:55:23 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
cb = pd->callback;
|
|
|
|
}
|
2012-07-02 11:55:23 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
cb->OnCrash(mPID);
|
2012-07-02 11:55:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterInjectorCallback(DWORD processID)
|
|
|
|
{
|
|
|
|
if (!OOPInitialized())
|
|
|
|
return;
|
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
pidToMinidump->RemoveEntry(processID);
|
2012-07-02 11:55:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
2012-07-16 16:50:52 -07: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-01 19:35:17 -07:00
|
|
|
nsAutoCString lastMinidump_contents;
|
2012-07-16 16:50:52 -07:00
|
|
|
if (NS_FAILED(GetFileContents(lastCrashFile, lastMinidump_contents))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lastCrashFile->Remove(false);
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// Ugly but effective.
|
|
|
|
nsDependentString lastMinidump(
|
2014-01-04 07:02:17 -08:00
|
|
|
reinterpret_cast<const char16_t*>(lastMinidump_contents.get()));
|
2012-07-16 16:50:52 -07:00
|
|
|
#else
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString lastMinidump = lastMinidump_contents;
|
2012-07-16 16:50:52 -07:00
|
|
|
#endif
|
|
|
|
nsCOMPtr<nsIFile> lastMinidumpFile;
|
|
|
|
CreateFileFromPath(lastMinidump.get(),
|
2013-06-21 02:11:43 -07:00
|
|
|
getter_AddRefs(lastMinidumpFile));
|
2012-07-16 16:50:52 -07:00
|
|
|
|
2013-06-21 02:11:43 -07:00
|
|
|
if (!lastMinidumpFile || NS_FAILED(lastMinidumpFile->Exists(&exists)) || !exists) {
|
2012-07-16 16:50:52 -07: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 12:05:09 -07:00
|
|
|
#if defined(XP_WIN)
|
2010-01-12 13:14:38 -08:00
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler(const nsACString& crashPipe)
|
|
|
|
{
|
|
|
|
// crash reporting is disabled
|
|
|
|
if (crashPipe.Equals(kNullNotifyPipe))
|
|
|
|
return true;
|
|
|
|
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
gExceptionHandler = new google_breakpad::
|
|
|
|
ExceptionHandler(L"",
|
2011-06-23 16:30:31 -07:00
|
|
|
FPEFilter,
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr, // no minidump callback
|
|
|
|
nullptr, // no callback context
|
2010-01-12 13:14:38 -08:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
|
|
|
MiniDumpNormal,
|
2013-12-05 01:52:54 -08:00
|
|
|
NS_ConvertASCIItoUTF16(crashPipe).get(),
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr);
|
2011-01-11 14:01:22 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
gExceptionHandler->set_handle_debug_exceptions(true);
|
|
|
|
#endif
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
2010-03-30 10:32:53 -07:00
|
|
|
#elif defined(XP_LINUX)
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
// Parent-side API for children
|
|
|
|
bool
|
|
|
|
CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd)
|
|
|
|
{
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
*childCrashFd = -1;
|
|
|
|
*childCrashRemapFd = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
*childCrashFd = clientSocketFd;
|
|
|
|
*childCrashRemapFd = kMagicChildCrashReportFd;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler()
|
|
|
|
{
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifndef XP_LINUX
|
|
|
|
xpstring path = "";
|
|
|
|
#else
|
2012-09-25 05:42:57 -07:00
|
|
|
// MinidumpDescriptor requires a non-empty path.
|
|
|
|
google_breakpad::MinidumpDescriptor path(".");
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2010-01-12 13:14:38 -08:00
|
|
|
gExceptionHandler = new google_breakpad::
|
2012-09-25 04:52:54 -07:00
|
|
|
ExceptionHandler(path,
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr, // no filter callback
|
|
|
|
nullptr, // no minidump callback
|
|
|
|
nullptr, // no callback context
|
|
|
|
true, // install signal handlers
|
2010-01-12 13:14:38 -08:00
|
|
|
kMagicChildCrashReportFd);
|
|
|
|
|
2011-06-08 13:21:03 -07:00
|
|
|
if (gDelayedAnnotations) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < gDelayedAnnotations->Length(); i++) {
|
2011-06-08 13:21:03 -07:00
|
|
|
gDelayedAnnotations->ElementAt(i)->Run();
|
|
|
|
}
|
|
|
|
delete gDelayedAnnotations;
|
|
|
|
}
|
|
|
|
|
2010-01-12 13:14:38 -08:00
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
|
|
|
}
|
|
|
|
|
2010-04-12 13:47:47 -07:00
|
|
|
//--------------------------------------------------
|
|
|
|
#elif defined(XP_MACOSX)
|
2010-08-16 12:05:09 -07:00
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler(const nsACString& crashPipe)
|
2010-04-12 13:47:47 -07:00
|
|
|
{
|
2010-08-16 12:05:09 -07:00
|
|
|
// crash reporting is disabled
|
|
|
|
if (crashPipe.Equals(kNullNotifyPipe))
|
|
|
|
return true;
|
|
|
|
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
|
2010-08-16 12:05:09 -07:00
|
|
|
|
|
|
|
gExceptionHandler = new google_breakpad::
|
|
|
|
ExceptionHandler("",
|
2012-07-03 06:15:34 -07:00
|
|
|
Filter,
|
2013-10-10 13:39:09 -07:00
|
|
|
nullptr, // no minidump callback
|
|
|
|
nullptr, // no callback context
|
|
|
|
true, // install signal handlers
|
2010-08-16 12:05:09 -07:00
|
|
|
crashPipe.BeginReading());
|
|
|
|
|
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
2010-04-12 13:47:47 -07:00
|
|
|
}
|
2010-01-12 14:00:48 -08:00
|
|
|
#endif // XP_WIN
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
TakeMinidumpForChild(uint32_t childPid, nsIFile** dump, uint32_t* aSequence)
|
2010-01-14 14:38:00 -08:00
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2010-03-18 15:52:36 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(childPid);
|
|
|
|
if (!pd)
|
|
|
|
return false;
|
2010-03-18 15:52:36 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
NS_IF_ADDREF(*dump = pd->minidump);
|
|
|
|
if (aSequence) {
|
|
|
|
*aSequence = pd->sequence;
|
|
|
|
}
|
2015-09-24 21:38:04 -07:00
|
|
|
|
|
|
|
pidToMinidump->RemoveEntry(pd);
|
2010-03-18 15:52:36 -07:00
|
|
|
|
2012-07-10 19:20:05 -07:00
|
|
|
return !!*dump;
|
2010-01-14 14:38:00 -08:00
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// CreatePairedMinidumps() and helpers
|
|
|
|
//
|
2012-09-08 10:20:59 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
RenameAdditionalHangMinidump(nsIFile* minidump, nsIFile* childMinidump,
|
2015-06-11 10:25:45 -07:00
|
|
|
const nsACString& name)
|
2012-09-08 10:20:59 -07:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
if (NS_FAILED(minidump->MoveToNative(directory, leafName))) {
|
|
|
|
NS_WARNING("RenameAdditionalHangMinidump failed to move minidump.");
|
|
|
|
}
|
2012-09-08 10:20:59 -07:00
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
|
|
|
static bool
|
2012-09-25 04:52:54 -07:00
|
|
|
PairedDumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
|
|
|
const XP_CHAR* dump_path,
|
2010-03-24 14:22:00 -07:00
|
|
|
const XP_CHAR* minidump_id,
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2010-03-24 14:22:00 -07:00
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* /*unused*/,
|
|
|
|
MDRawAssertionInfo* /*unused*/,
|
|
|
|
#endif
|
|
|
|
bool succeeded)
|
|
|
|
{
|
2012-09-08 10:20:59 -07:00
|
|
|
nsCOMPtr<nsIFile>& minidump = *static_cast< nsCOMPtr<nsIFile>* >(context);
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2012-09-25 04:52:54 -07:00
|
|
|
xpstring dump;
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
dump = descriptor.path();
|
|
|
|
#else
|
|
|
|
dump = dump_path;
|
2010-03-24 14:22:01 -07:00
|
|
|
dump += XP_PATH_SEPARATOR;
|
|
|
|
dump += minidump_id;
|
|
|
|
dump += dumpFileExtension;
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
CreateFileFromPath(dump, getter_AddRefs(minidump));
|
2012-09-08 10:20:59 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-09-25 04:52:54 -07:00
|
|
|
PairedDumpCallbackExtra(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
|
|
|
const XP_CHAR* dump_path,
|
2012-09-08 10:20:59 -07:00
|
|
|
const XP_CHAR* minidump_id,
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2012-09-08 10:20:59 -07:00
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* /*unused*/,
|
|
|
|
MDRawAssertionInfo* /*unused*/,
|
|
|
|
#endif
|
|
|
|
bool succeeded)
|
|
|
|
{
|
2012-09-25 04:52:54 -07:00
|
|
|
PairedDumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
descriptor,
|
|
|
|
#else
|
|
|
|
dump_path, minidump_id,
|
|
|
|
#endif
|
|
|
|
context,
|
2012-09-08 10:20:59 -07: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 14:22:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-30 17:24:45 -07:00
|
|
|
ThreadId
|
|
|
|
CurrentThreadId()
|
|
|
|
{
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
return ::GetCurrentThreadId();
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
return sys_gettid();
|
|
|
|
#elif defined(XP_MACOSX)
|
2010-08-27 06:32:45 -07: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 11:12:21 -08:00
|
|
|
abort();
|
2010-03-30 17:24:45 -07:00
|
|
|
#else
|
|
|
|
# error "Unsupported platform"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-27 06:32:45 -07:00
|
|
|
#ifdef XP_MACOSX
|
2012-09-26 13:49:20 -07:00
|
|
|
static mach_port_t
|
|
|
|
GetChildThread(ProcessHandle childPid, ThreadId childBlamedThread)
|
|
|
|
{
|
2010-08-27 06:32:45 -07: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 13:49:20 -07:00
|
|
|
|
|
|
|
return childThread;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
bool TakeMinidump(nsIFile** aResult, bool aMoveToPending)
|
2012-09-26 13:49:20 -07:00
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
xpstring dump_path;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
dump_path = gExceptionHandler->dump_path();
|
|
|
|
#else
|
|
|
|
dump_path = gExceptionHandler->minidump_descriptor().directory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// capture the dump
|
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidump(
|
|
|
|
dump_path,
|
2012-09-26 13:49:20 -07:00
|
|
|
#ifdef XP_MACOSX
|
2015-06-11 10:25:45 -07:00
|
|
|
true,
|
|
|
|
#endif
|
|
|
|
PairedDumpCallback,
|
|
|
|
static_cast<void*>(aResult))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMoveToPending) {
|
|
|
|
MoveToPending(*aResult, nullptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CreateMinidumpsAndPair(ProcessHandle aTargetPid,
|
|
|
|
ThreadId aTargetBlamedThread,
|
|
|
|
const nsACString& aIncomingPairName,
|
|
|
|
nsIFile* aIncomingDumpToPair,
|
|
|
|
nsIFile** aMainDumpOut)
|
|
|
|
{
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mach_port_t targetThread = GetChildThread(aTargetPid, aTargetBlamedThread);
|
2010-08-27 06:32:45 -07:00
|
|
|
#else
|
2015-06-11 10:25:45 -07:00
|
|
|
ThreadId targetThread = aTargetBlamedThread;
|
2010-08-27 06:32:45 -07:00
|
|
|
#endif
|
|
|
|
|
2012-09-25 04:52:54 -07:00
|
|
|
xpstring dump_path;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
dump_path = gExceptionHandler->dump_path();
|
|
|
|
#else
|
|
|
|
dump_path = gExceptionHandler->minidump_descriptor().directory();
|
|
|
|
#endif
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
// dump the target
|
|
|
|
nsCOMPtr<nsIFile> targetMinidump;
|
2010-03-24 14:22:00 -07:00
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidumpForChild(
|
2015-06-11 10:25:45 -07:00
|
|
|
aTargetPid,
|
|
|
|
targetThread,
|
2012-09-25 04:52:54 -07:00
|
|
|
dump_path,
|
2012-09-08 10:20:59 -07:00
|
|
|
PairedDumpCallbackExtra,
|
2015-06-11 10:25:45 -07:00
|
|
|
static_cast<void*>(&targetMinidump)))
|
2010-03-24 14:22:00 -07:00
|
|
|
return false;
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
nsCOMPtr<nsIFile> targetExtra;
|
|
|
|
GetExtraFileForMinidump(targetMinidump, getter_AddRefs(targetExtra));
|
2012-09-08 10:20:59 -07:00
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
// If aIncomingDumpToPair isn't valid, create a dump of this process.
|
|
|
|
nsCOMPtr<nsIFile> incomingDump;
|
|
|
|
if (aIncomingDumpToPair == nullptr) {
|
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidump(
|
|
|
|
dump_path,
|
2012-09-25 04:52:54 -07:00
|
|
|
#ifdef XP_MACOSX
|
2015-06-11 10:25:45 -07:00
|
|
|
true,
|
2012-09-25 04:52:54 -07:00
|
|
|
#endif
|
2015-06-11 10:25:45 -07:00
|
|
|
PairedDumpCallback,
|
|
|
|
static_cast<void*>(&incomingDump))) {
|
2012-09-08 10:20:59 -07:00
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
targetMinidump->Remove(false);
|
|
|
|
targetExtra->Remove(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
incomingDump = aIncomingDumpToPair;
|
2012-09-08 10:20:59 -07:00
|
|
|
}
|
2015-06-11 10:25:45 -07:00
|
|
|
|
|
|
|
RenameAdditionalHangMinidump(incomingDump, targetMinidump, aIncomingPairName);
|
2012-09-08 10:20:59 -07:00
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
if (ShouldReport()) {
|
2015-06-11 10:25:45 -07:00
|
|
|
MoveToPending(targetMinidump, targetExtra);
|
|
|
|
MoveToPending(incomingDump, nullptr);
|
2010-03-24 14:22:00 -07:00
|
|
|
}
|
|
|
|
|
2015-06-11 10:25:45 -07:00
|
|
|
targetMinidump.forget(aMainDumpOut);
|
2010-03-24 14:22:00 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-26 13:49:20 -07: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 13:14:38 -08:00
|
|
|
bool
|
|
|
|
UnsetRemoteExceptionHandler()
|
|
|
|
{
|
|
|
|
delete gExceptionHandler;
|
2013-10-10 13:39:09 -07:00
|
|
|
gExceptionHandler = nullptr;
|
2010-01-12 13:14:38 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-16 16:50:52 -07:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-10-19 12:05:47 -07: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 05:04:53 -07:00
|
|
|
google_breakpad::FileID::ElfFileIdentifierFromMappedFile((void const *)start_address, guid);
|
2010-10-19 12:05:47 -07:00
|
|
|
gExceptionHandler->AddMappingInfo(library_name,
|
|
|
|
guid,
|
|
|
|
start_address,
|
|
|
|
mapping_length,
|
|
|
|
file_offset);
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 06:15:03 -08:00
|
|
|
#endif
|
2010-10-19 12:05:47 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
} // namespace CrashReporter
|