2015-10-20 01:46:46 +03: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 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2013-09-22 07:04:10 +04:00
|
|
|
#include "nsExceptionHandler.h"
|
2017-11-14 16:49:33 +03:00
|
|
|
#include "nsExceptionHandlerUtils.h"
|
2016-03-07 23:48:58 +03:00
|
|
|
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
Bug 1600545 - Remove useless inclusions of header files generated from IDL files in modules/, netwerk/, parser/, security/, startupcache/, storage/, toolkit/, tools/, uriloader/, widget/, xpcom/ and xpfe/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55444
--HG--
extra : moz-landing-system : lando
2019-12-06 12:17:57 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2016-03-07 23:48:58 +03:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2016-10-19 13:51:29 +03:00
|
|
|
#include "nsDirectoryService.h"
|
2021-03-10 13:47:47 +03:00
|
|
|
#include "nsTHashMap.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2018-09-26 14:54:34 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
#include "mozilla/EnumeratedRange.h"
|
2011-10-04 00:26:08 +04:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIObserverService.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2019-05-18 19:19:55 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-12-09 23:30:19 +03:00
|
|
|
#include "mozilla/Printf.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2019-01-09 02:53:37 +03:00
|
|
|
#include "mozilla/StaticMutex.h"
|
2014-07-18 21:31:45 +04:00
|
|
|
#include "mozilla/SyncRunnable.h"
|
2016-02-18 01:44:21 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2011-06-09 00:21:03 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2020-01-20 21:23:48 +03:00
|
|
|
#include "nsThread.h"
|
2014-10-08 23:25:20 +04:00
|
|
|
#include "jsfriendapi.h"
|
2017-02-07 13:57:23 +03:00
|
|
|
#include "ThreadAnnotation.h"
|
2017-11-27 23:37:34 +03:00
|
|
|
#include "private/pprio.h"
|
2020-09-07 19:02:26 +03:00
|
|
|
#include "base/process_util.h"
|
2020-04-08 09:55:40 +03:00
|
|
|
#include "common/basictypes.h"
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_WIN)
|
2007-07-25 05:05:54 +04:00
|
|
|
# ifdef WIN32_LEAN_AND_MEAN
|
|
|
|
# undef WIN32_LEAN_AND_MEAN
|
|
|
|
# endif
|
2019-01-18 12:16:18 +03:00
|
|
|
|
2013-09-22 07:04:10 +04:00
|
|
|
# include "nsXULAppAPI.h"
|
|
|
|
# include "nsIXULAppInfo.h"
|
2010-02-10 04:05:31 +03:00
|
|
|
# include "nsIWindowsRegKey.h"
|
2017-02-08 14:45:38 +03:00
|
|
|
# include "breakpad-client/windows/crash_generation/client_info.h"
|
|
|
|
# include "breakpad-client/windows/crash_generation/crash_generation_server.h"
|
|
|
|
# include "breakpad-client/windows/handler/exception_handler.h"
|
2013-04-05 13:29:50 +04:00
|
|
|
# include <dbghelp.h>
|
2007-07-25 05:05:54 +04:00
|
|
|
# include <string.h>
|
2012-07-11 06:20:05 +04:00
|
|
|
# include "nsDirectoryServiceUtils.h"
|
2019-01-18 12:16:18 +03:00
|
|
|
|
2012-04-20 13:07:55 +04:00
|
|
|
# include "nsWindowsDllInterceptor.h"
|
2019-09-23 23:18:41 +03:00
|
|
|
# include "mozilla/WindowsDllBlocklist.h"
|
2018-01-03 11:06:11 +03:00
|
|
|
# include "mozilla/WindowsVersion.h"
|
2021-04-07 10:55:23 +03:00
|
|
|
# include "psapi.h" // For PERFORMANCE_INFORMATION and K32GetPerformanceInfo()
|
|
|
|
# if defined(__MINGW32__) || defined(__MINGW64__)
|
|
|
|
// Add missing constants and types for mingw builds
|
|
|
|
# define HREPORT HANDLE
|
|
|
|
# define PWER_SUBMIT_RESULT WER_SUBMIT_RESULT*
|
|
|
|
# define WER_MAX_PREFERRED_MODULES_BUFFER (256)
|
2021-05-10 13:03:48 +03:00
|
|
|
# define WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG (256)
|
2021-04-07 10:55:23 +03:00
|
|
|
# endif // defined(__MINGW32__) || defined(__MINGW64__)
|
|
|
|
# include "werapi.h" // For WerRegisterRuntimeExceptionModule()
|
2007-07-25 05:06:00 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
2017-02-08 14:45:38 +03:00
|
|
|
# include "breakpad-client/mac/crash_generation/client_info.h"
|
|
|
|
# include "breakpad-client/mac/crash_generation/crash_generation_server.h"
|
|
|
|
# include "breakpad-client/mac/handler/exception_handler.h"
|
2017-03-15 07:41:49 +03:00
|
|
|
# include <string>
|
2007-07-25 05:06:00 +04:00
|
|
|
# include <Carbon/Carbon.h>
|
2010-06-21 06:07:59 +04:00
|
|
|
# include <CoreFoundation/CoreFoundation.h>
|
2010-10-01 23:56:25 +04:00
|
|
|
# include <crt_externs.h>
|
2007-07-25 05:06:00 +04:00
|
|
|
# include <fcntl.h>
|
2010-08-27 17:32:45 +04:00
|
|
|
# include <mach/mach.h>
|
2019-12-03 14:53:45 +03:00
|
|
|
# include <mach/vm_statistics.h>
|
|
|
|
# include <sys/sysctl.h>
|
2007-07-25 05:06:11 +04:00
|
|
|
# include <sys/types.h>
|
2010-10-01 23:56:25 +04:00
|
|
|
# include <spawn.h>
|
2007-07-25 05:06:11 +04:00
|
|
|
# include <unistd.h>
|
2007-07-25 05:06:09 +04:00
|
|
|
# include "mac_utils.h"
|
2007-07-25 05:06:04 +04:00
|
|
|
#elif defined(XP_LINUX)
|
2010-02-10 04:05:31 +03:00
|
|
|
# include "nsIINIParser.h"
|
2010-07-29 19:31:07 +04:00
|
|
|
# include "common/linux/linux_libc_support.h"
|
2012-09-25 15:52:54 +04:00
|
|
|
# include "third_party/lss/linux_syscall_support.h"
|
2017-02-08 14:45:38 +03:00
|
|
|
# include "breakpad-client/linux/crash_generation/client_info.h"
|
|
|
|
# include "breakpad-client/linux/crash_generation/crash_generation_server.h"
|
|
|
|
# include "breakpad-client/linux/handler/exception_handler.h"
|
2014-12-15 21:13:12 +03:00
|
|
|
# include "common/linux/eintr_wrapper.h"
|
2007-07-25 05:06:04 +04:00
|
|
|
# include <fcntl.h>
|
2007-07-25 05:06:11 +04:00
|
|
|
# include <sys/types.h>
|
2020-01-07 13:06:55 +03:00
|
|
|
# include "sys/sysinfo.h"
|
2014-12-15 21:13:12 +03:00
|
|
|
# include <sys/wait.h>
|
2007-07-25 05:06:11 +04:00
|
|
|
# include <unistd.h>
|
2007-07-25 05:05:55 +04:00
|
|
|
#else
|
|
|
|
# error "Not yet implemented for this platform"
|
2019-03-21 04:28:50 +03:00
|
|
|
#endif // defined(XP_WIN)
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2012-07-02 22:55:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
# include "InjectCrashReporter.h"
|
|
|
|
using mozilla::InjectCrashRunnable;
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 05:05:54 +04:00
|
|
|
#include <stdlib.h>
|
2007-07-25 05:06:15 +04:00
|
|
|
#include <time.h>
|
2007-07-25 05:05:54 +04:00
|
|
|
#include <prenv.h>
|
2007-07-25 05:06:14 +04:00
|
|
|
#include <prio.h>
|
2010-01-15 01:38:00 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2007-07-25 05:05:54 +04:00
|
|
|
#include "nsDebug.h"
|
2007-07-25 05:05:55 +04:00
|
|
|
#include "nsCRT.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2010-11-24 17:15:03 +03:00
|
|
|
#include <map>
|
2010-10-19 23:05:47 +04:00
|
|
|
#include <vector>
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2014-03-15 10:10:39 +04:00
|
|
|
#include "mozilla/IOInterposer.h"
|
2012-01-24 20:08:51 +04:00
|
|
|
#include "mozilla/mozalloc_oom.h"
|
|
|
|
|
2010-06-21 06:07:59 +04:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
|
|
|
|
#endif
|
2013-04-09 16:04:53 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
# include "common/linux/file_id.h"
|
|
|
|
#endif
|
2010-06-21 06:07:59 +04:00
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
using google_breakpad::ClientInfo;
|
|
|
|
using google_breakpad::CrashGenerationServer;
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
using google_breakpad::MinidumpDescriptor;
|
2020-04-30 00:17:50 +03:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
using google_breakpad::ExceptionHandler;
|
2012-09-25 15:52:54 +04:00
|
|
|
#endif
|
2016-10-05 12:46:07 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
using google_breakpad::auto_wasteful_vector;
|
|
|
|
using google_breakpad::FileID;
|
2018-11-09 14:09:03 +03:00
|
|
|
using google_breakpad::kDefaultBuildIdSize;
|
2016-10-05 12:46:07 +03:00
|
|
|
using google_breakpad::PageAllocator;
|
|
|
|
#endif
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
namespace CrashReporter {
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2007-07-25 05:06:00 +04:00
|
|
|
typedef wchar_t XP_CHAR;
|
2010-03-25 00:22:00 +03:00
|
|
|
typedef std::wstring xpstring;
|
2014-08-30 09:21:18 +04:00
|
|
|
# define XP_TEXT(x) L##x
|
2009-04-02 19:41:12 +04:00
|
|
|
# define CONVERT_XP_CHAR_TO_UTF16(x) x
|
2007-07-25 05:06:00 +04:00
|
|
|
# define XP_STRLEN(x) wcslen(x)
|
2010-08-11 18:57:44 +04:00
|
|
|
# define my_strlen strlen
|
2020-01-20 21:23:48 +03:00
|
|
|
# define my_memchr memchr
|
2007-07-25 05:06:00 +04:00
|
|
|
# define CRASH_REPORTER_FILENAME "crashreporter.exe"
|
|
|
|
# define XP_PATH_SEPARATOR L"\\"
|
2016-03-16 21:35:50 +03:00
|
|
|
# define XP_PATH_SEPARATOR_CHAR L'\\'
|
2016-03-07 23:48:58 +03:00
|
|
|
# define XP_PATH_MAX (MAX_PATH + 1)
|
2007-07-25 05:06:00 +04:00
|
|
|
// "<reporter path>" "<minidump path>"
|
|
|
|
# define CMDLINE_SIZE ((XP_PATH_MAX * 2) + 6)
|
2020-11-23 10:25:36 +03:00
|
|
|
# define XP_TTOA(time, buffer) _i64toa((time), (buffer), 10)
|
|
|
|
# define XP_STOA(size, buffer) _ui64toa((size), (buffer), 10)
|
2007-07-25 05:06:00 +04:00
|
|
|
#else
|
|
|
|
typedef char XP_CHAR;
|
2010-03-25 00:22:00 +03:00
|
|
|
typedef std::string xpstring;
|
2014-08-30 09:21:18 +04:00
|
|
|
# define XP_TEXT(x) x
|
2009-04-02 19:41:12 +04:00
|
|
|
# define CONVERT_XP_CHAR_TO_UTF16(x) NS_ConvertUTF8toUTF16(x)
|
2007-07-25 05:06:00 +04:00
|
|
|
# define CRASH_REPORTER_FILENAME "crashreporter"
|
|
|
|
# define XP_PATH_SEPARATOR "/"
|
2016-03-16 21:35:50 +03:00
|
|
|
# define XP_PATH_SEPARATOR_CHAR '/'
|
2007-07-25 05:06:00 +04:00
|
|
|
# define XP_PATH_MAX PATH_MAX
|
2010-07-29 19:31:07 +04:00
|
|
|
# ifdef XP_LINUX
|
|
|
|
# define XP_STRLEN(x) my_strlen(x)
|
2020-11-23 10:25:36 +03:00
|
|
|
# define XP_TTOA(time, buffer) \
|
|
|
|
my_u64tostring(uint64_t(time), (buffer), sizeof(buffer))
|
|
|
|
# define XP_STOA(size, buffer) \
|
|
|
|
my_u64tostring((size), (buffer), sizeof(buffer))
|
2010-07-29 19:31:07 +04:00
|
|
|
# else
|
|
|
|
# define XP_STRLEN(x) strlen(x)
|
2020-11-23 10:25:36 +03:00
|
|
|
# define XP_TTOA(time, buffer) sprintf(buffer, "%" PRIu64, uint64_t(time))
|
|
|
|
# define XP_STOA(size, buffer) sprintf(buffer, "%zu", size_t(size))
|
2010-08-11 18:57:44 +04:00
|
|
|
# define my_strlen strlen
|
2020-01-20 21:23:48 +03:00
|
|
|
# define my_memchr memchr
|
2010-07-29 19:31:07 +04:00
|
|
|
# define sys_close close
|
|
|
|
# define sys_fork fork
|
|
|
|
# define sys_open open
|
2014-08-30 09:21:18 +04:00
|
|
|
# define sys_read read
|
2010-07-29 19:31:07 +04:00
|
|
|
# define sys_write write
|
|
|
|
# endif
|
2019-03-21 04:28:50 +03:00
|
|
|
#endif // XP_WIN
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2016-03-07 23:48:58 +03:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused))
|
|
|
|
#else
|
|
|
|
# define MAYBE_UNUSED
|
|
|
|
#endif // defined(__GNUC__)
|
|
|
|
|
2014-06-23 22:49:09 +04:00
|
|
|
#ifndef XP_LINUX
|
2014-08-30 09:21:18 +04:00
|
|
|
static const XP_CHAR dumpFileExtension[] = XP_TEXT(".dmp");
|
2014-06-23 22:49:09 +04:00
|
|
|
#endif
|
|
|
|
|
2014-08-30 09:21:18 +04:00
|
|
|
static const XP_CHAR extraFileExtension[] = XP_TEXT(".extra");
|
|
|
|
static const XP_CHAR memoryReportExtension[] = XP_TEXT(".memory.json.gz");
|
2016-06-21 21:45:25 +03:00
|
|
|
static xpstring* defaultMemoryReportPath = nullptr;
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
static const char kCrashMainID[] = "crash.main.3\n";
|
2014-02-19 03:58:03 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static google_breakpad::ExceptionHandler* gExceptionHandler = nullptr;
|
2020-04-17 23:08:59 +03:00
|
|
|
static mozilla::Atomic<bool> gEncounteredChildException(false);
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
static xpstring pendingDirectory;
|
|
|
|
static xpstring crashReporterPath;
|
|
|
|
static xpstring memoryReportPath;
|
2017-02-16 09:36:57 +03:00
|
|
|
#ifdef XP_MACOSX
|
2021-02-19 23:50:23 +03:00
|
|
|
static xpstring libraryPath; // Path where the NSS library is
|
2020-11-23 10:25:36 +03:00
|
|
|
#endif
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2014-02-19 03:58:03 +04:00
|
|
|
// Where crash events should go.
|
2021-02-19 23:50:23 +03:00
|
|
|
static xpstring eventsDirectory;
|
2014-02-19 03:58:03 +04:00
|
|
|
|
2012-07-17 03:50:52 +04:00
|
|
|
// If this is false, we don't launch the crash reporter
|
2007-07-25 05:06:02 +04:00
|
|
|
static bool doReport = true;
|
|
|
|
|
2007-07-25 05:06:09 +04:00
|
|
|
// if this is true, we pass the exception on to the OS crash reporter
|
|
|
|
static bool showOSCrashReporter = false;
|
|
|
|
|
2007-08-29 23:46:00 +04: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-11-16 02:56:22 +04: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;
|
2018-07-02 17:32:10 +03:00
|
|
|
|
|
|
|
// Before Android 8 we needed to use "startservice" to start the crash reporting
|
|
|
|
// service. After Android 8 we need to use "start-foreground-service"
|
|
|
|
static const char* androidStartServiceCommand = nullptr;
|
2012-11-16 02:56:22 +04:00
|
|
|
#endif
|
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
// this holds additional data sent via the API
|
2011-10-07 00:33:21 +04:00
|
|
|
static Mutex* crashReporterAPILock;
|
2012-01-25 18:43:52 +04:00
|
|
|
static Mutex* notesFieldLock;
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
static AnnotationTable crashReporterAPIData_Table;
|
2012-07-30 18:20:58 +04:00
|
|
|
static nsCString* notesField = nullptr;
|
2012-08-15 21:47:51 +04:00
|
|
|
static bool isGarbageCollecting;
|
2014-02-13 21:51:09 +04:00
|
|
|
static uint32_t eventloopNestingLevel = 0;
|
2021-10-05 07:41:53 +03:00
|
|
|
static time_t inactiveStateStart = 0;
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2014-01-15 19:03:14 +04:00
|
|
|
// Avoid a race during application termination.
|
|
|
|
static Mutex* dumpSafetyLock;
|
|
|
|
static bool isSafeToDump = false;
|
|
|
|
|
2017-06-20 10:00:32 +03:00
|
|
|
// Whether to include heap regions of the crash context.
|
|
|
|
static bool sIncludeContextHeap = false;
|
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
// OOP crash reporting
|
|
|
|
static CrashGenerationServer* crashServer; // chrome process has this
|
2019-01-09 02:53:37 +03:00
|
|
|
static StaticMutex processMapLock;
|
2017-11-27 23:37:34 +03:00
|
|
|
static std::map<ProcessId, PRFileDesc*> processToCrashFd;
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2017-01-29 10:53:50 +03:00
|
|
|
static std::terminate_handler oldTerminateHandler = nullptr;
|
|
|
|
|
2010-08-16 23:05:09 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-13 00:14:38 +03: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 18:44:10 +03:00
|
|
|
static char* childCrashNotifyPipe;
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2010-01-13 01:00:48 +03:00
|
|
|
#elif defined(XP_LINUX)
|
2010-01-13 00:14:38 +03:00
|
|
|
static int serverSocketFd = -1;
|
|
|
|
static int clientSocketFd = -1;
|
2020-09-07 19:02:26 +03:00
|
|
|
|
|
|
|
// On Linux these file descriptors are created in the parent process and
|
|
|
|
// remapped in the child ones. See PosixProcessLauncher::DoSetup() for more
|
|
|
|
// details.
|
|
|
|
static FileHandle gMagicChildCrashReportFd =
|
2016-11-02 02:11:32 +03:00
|
|
|
# if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// On android the fd is set at the time of child creation.
|
2020-09-07 19:02:26 +03:00
|
|
|
kInvalidFileHandle
|
2016-11-02 02:11:32 +03:00
|
|
|
# else
|
|
|
|
4
|
|
|
|
# endif // defined(MOZ_WIDGET_ANDROID)
|
|
|
|
;
|
2010-01-13 01:00:48 +03:00
|
|
|
#endif
|
2010-01-15 01:38:00 +03:00
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
static FileHandle gChildCrashAnnotationReportFd =
|
|
|
|
#if (defined(XP_LINUX) || defined(XP_MACOSX)) && !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
7
|
|
|
|
#else
|
|
|
|
kInvalidFileHandle
|
2017-11-27 23:37:34 +03:00
|
|
|
#endif
|
2020-09-07 19:02:26 +03:00
|
|
|
;
|
2017-11-27 23:37:34 +03:00
|
|
|
|
2010-01-15 01:38:00 +03:00
|
|
|
// |dumpMapLock| must protect all access to |pidToMinidump|.
|
|
|
|
static Mutex* dumpMapLock;
|
2012-07-11 06:20:05 +04:00
|
|
|
struct ChildProcessData : public nsUint32HashKey {
|
2014-09-03 02:24:24 +04:00
|
|
|
explicit ChildProcessData(KeyTypePointer aKey)
|
2012-07-11 06:20:05 +04:00
|
|
|
: nsUint32HashKey(aKey),
|
2019-05-18 19:19:55 +03:00
|
|
|
sequence(0),
|
2020-05-18 23:34:48 +03:00
|
|
|
annotations(nullptr),
|
|
|
|
minidumpOnly(false)
|
2012-07-11 06:20:05 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-10-11 00:39:09 +04:00
|
|
|
,
|
|
|
|
callback(nullptr)
|
2012-07-11 06:20:05 +04:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
// Each crashing process is assigned an increasing sequence number to
|
|
|
|
// indicate which process crashed first.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t sequence;
|
2019-05-18 19:19:55 +03:00
|
|
|
UniquePtr<AnnotationTable> annotations;
|
2020-05-18 23:34:48 +03:00
|
|
|
bool minidumpOnly; // If true then no annotations are present
|
2012-07-11 06:20:05 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
InjectorCrashCallback* callback;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTHashtable<ChildProcessData> ChildMinidumpMap;
|
2010-01-15 01:38:00 +03:00
|
|
|
static ChildMinidumpMap* pidToMinidump;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t crashSequence;
|
2012-07-11 06:20:05 +04:00
|
|
|
static bool OOPInitialized();
|
2010-01-15 01:38:00 +03:00
|
|
|
|
2012-07-02 22:55:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
static nsIThread* sInjectorThread;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ReportInjectedCrash : public Runnable {
|
2012-07-02 22:55:23 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit ReportInjectedCrash(uint32_t pid)
|
|
|
|
: Runnable("ReportInjectedCrash"), mPID(pid) {}
|
2012-07-02 22:55:23 +04:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2012-07-02 22:55:23 +04:00
|
|
|
|
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mPID;
|
2012-07-02 22:55:23 +04:00
|
|
|
};
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
2012-04-20 13:07:55 +04:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// the following are used to prevent other DLLs reverting the last chance
|
2016-05-17 23:53:15 +03:00
|
|
|
// exception handler to the windows default. Any attempt to change the
|
2012-04-20 13:07:55 +04:00
|
|
|
// 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);
|
2018-06-27 20:51:40 +03:00
|
|
|
static WindowsDllInterceptor::FuncHookType<SetUnhandledExceptionFilter_func>
|
|
|
|
stub_SetUnhandledExceptionFilter;
|
2014-01-30 02:07:35 +04:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER previousUnhandledExceptionFilter = nullptr;
|
2012-04-20 13:07:55 +04:00
|
|
|
static WindowsDllInterceptor gKernel32Intercept;
|
|
|
|
static bool gBlockUnhandledExceptionFilter = true;
|
|
|
|
|
2014-10-08 23:25:20 +04:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER GetUnhandledExceptionFilter() {
|
|
|
|
// Set a dummy value to get the current filter, then restore
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER current = SetUnhandledExceptionFilter(nullptr);
|
|
|
|
SetUnhandledExceptionFilter(current);
|
|
|
|
return current;
|
2014-01-30 02:07:35 +04:00
|
|
|
}
|
|
|
|
|
2012-04-20 13:07:55 +04:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI patched_SetUnhandledExceptionFilter(
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter) {
|
2012-09-25 15:52:54 +04:00
|
|
|
if (!gBlockUnhandledExceptionFilter) {
|
2012-04-20 13:07:55 +04:00
|
|
|
// don't intercept
|
|
|
|
return stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
|
|
|
}
|
|
|
|
|
2014-01-30 02:07:35 +04:00
|
|
|
if (lpTopLevelExceptionFilter == previousUnhandledExceptionFilter) {
|
|
|
|
// OK to swap back and forth between the previous filter
|
|
|
|
previousUnhandledExceptionFilter =
|
|
|
|
stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
|
|
|
|
return previousUnhandledExceptionFilter;
|
|
|
|
}
|
|
|
|
|
2012-04-20 13:07:55 +04:00
|
|
|
// intercept attempts to change the filter
|
2013-10-11 00:39:09 +04:00
|
|
|
return nullptr;
|
2012-04-20 13:07:55 +04:00
|
|
|
}
|
2013-12-06 18:00:06 +04:00
|
|
|
|
2019-01-14 17:06:24 +03:00
|
|
|
# if defined(HAVE_64BIT_BUILD)
|
2014-10-08 23:25:20 +04: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);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:25:19 +03:00
|
|
|
static void SetJitExceptionHandler() {
|
|
|
|
sUnhandledExceptionFilter = GetUnhandledExceptionFilter();
|
|
|
|
if (sUnhandledExceptionFilter)
|
|
|
|
js::SetJitExceptionHandler(JitExceptionHandler);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2013-12-06 18:00:06 +04: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.
|
|
|
|
*/
|
2017-07-21 16:10:00 +03:00
|
|
|
static const SIZE_T kReserveSize = 0x5000000; // 80 MB
|
2013-12-06 18:00:06 +04:00
|
|
|
static void* gBreakpadReservedVM;
|
2012-04-20 13:07:55 +04:00
|
|
|
#endif
|
|
|
|
|
2010-08-11 18:57:44 +04:00
|
|
|
#ifdef XP_LINUX
|
2020-11-23 10:25:36 +03:00
|
|
|
static inline void my_u64tostring(uint64_t aValue, char* aBuffer,
|
|
|
|
size_t aBufferLength) {
|
|
|
|
my_memset(aBuffer, 0, aBufferLength);
|
|
|
|
my_uitos(aBuffer, aValue, my_uint_len(aValue));
|
2010-08-11 18:57:44 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 00:22:00 +03:00
|
|
|
#ifdef XP_WIN
|
2012-06-06 06:08:30 +04:00
|
|
|
static void CreateFileFromPath(const xpstring& path, nsIFile** file) {
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewLocalFile(nsDependentString(path.c_str()), false, file);
|
2010-03-25 00:22:00 +03:00
|
|
|
}
|
2015-08-21 10:01:47 +03:00
|
|
|
|
2016-03-07 23:48:58 +03:00
|
|
|
static xpstring* CreatePathFromFile(nsIFile* file) {
|
|
|
|
nsAutoString path;
|
|
|
|
nsresult rv = file->GetPath(path);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-11-09 19:39:20 +03:00
|
|
|
return new xpstring(static_cast<wchar_t*>(path.get()), path.Length());
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
2010-03-25 00:22:00 +03:00
|
|
|
#else
|
2012-06-06 06:08:30 +04:00
|
|
|
static void CreateFileFromPath(const xpstring& path, nsIFile** file) {
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(path.c_str()), false, file);
|
2010-03-25 00:22:00 +03:00
|
|
|
}
|
2016-03-07 23:48:58 +03:00
|
|
|
|
|
|
|
MAYBE_UNUSED static xpstring* CreatePathFromFile(nsIFile* file) {
|
|
|
|
nsAutoCString path;
|
|
|
|
nsresult rv = file->GetNativePath(path);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new xpstring(path.get(), path.Length());
|
|
|
|
}
|
2010-03-25 00:22:00 +03:00
|
|
|
#endif
|
|
|
|
|
2021-10-05 07:41:53 +03:00
|
|
|
static time_t GetCurrentTimeForCrashTime() {
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
struct kernel_timeval tv;
|
|
|
|
sys_gettimeofday(&tv, nullptr);
|
|
|
|
return tv.tv_sec;
|
|
|
|
#else
|
|
|
|
return time(nullptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-19 13:38:56 +03:00
|
|
|
static XP_CHAR* Concat(XP_CHAR* str, const XP_CHAR* toAppend, size_t* size) {
|
|
|
|
size_t appendLen = XP_STRLEN(toAppend);
|
|
|
|
if (appendLen >= *size) {
|
|
|
|
appendLen = *size - 1;
|
|
|
|
}
|
2007-07-25 05:06:00 +04:00
|
|
|
|
|
|
|
memcpy(str, toAppend, appendLen * sizeof(XP_CHAR));
|
|
|
|
str += appendLen;
|
|
|
|
*str = '\0';
|
|
|
|
*size -= appendLen;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-01-24 20:08:51 +04:00
|
|
|
void AnnotateOOMAllocationSize(size_t size) { gOOMAllocationSize = size; }
|
|
|
|
|
2016-02-03 23:24:47 +03:00
|
|
|
static size_t gTexturesSize = 0;
|
|
|
|
|
|
|
|
void AnnotateTexturesSize(size_t size) { gTexturesSize = size; }
|
|
|
|
|
2014-08-30 09:21:18 +04:00
|
|
|
#ifndef XP_WIN
|
|
|
|
// Like Windows CopyFile for *nix
|
2017-12-08 20:25:40 +03:00
|
|
|
//
|
|
|
|
// This function is not declared static even though it's not used outside of
|
|
|
|
// this file because of an issue in Fennec which prevents breakpad's exception
|
|
|
|
// handler from invoking the MinidumpCallback function. See bug 1424304.
|
2017-10-12 00:33:56 +03:00
|
|
|
bool copy_file(const char* from, const char* to) {
|
2014-08-30 09:21:18 +04:00
|
|
|
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
|
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
/**
|
|
|
|
* The PlatformWriter class provides a tool to create and write to a file that
|
|
|
|
* is safe to call from within an exception handler. To use it this way the
|
2019-12-02 16:18:35 +03:00
|
|
|
* file path needs to be provided as a bare C string.
|
2019-05-18 19:19:55 +03:00
|
|
|
*/
|
2015-04-27 17:49:44 +03:00
|
|
|
class PlatformWriter {
|
|
|
|
public:
|
2020-09-07 19:02:26 +03:00
|
|
|
PlatformWriter() : mBuffer{}, mPos(0), mFD(kInvalidFileHandle) {}
|
|
|
|
explicit PlatformWriter(const XP_CHAR* aPath) : PlatformWriter() {
|
2019-12-02 16:18:35 +03:00
|
|
|
Open(aPath);
|
2019-05-18 19:19:55 +03:00
|
|
|
}
|
|
|
|
|
2015-04-27 17:49:44 +03:00
|
|
|
~PlatformWriter() {
|
|
|
|
if (Valid()) {
|
2020-03-24 14:17:23 +03:00
|
|
|
Flush();
|
2019-12-02 16:18:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
CloseHandle(mFD);
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
sys_close(mFD);
|
|
|
|
#endif
|
2015-04-27 17:49:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
void Open(const XP_CHAR* aPath) {
|
2019-12-02 16:18:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mFD = CreateFile(aPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
mFD = sys_open(aPath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
|
|
|
#endif
|
2015-04-27 17:49:44 +03:00
|
|
|
}
|
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
void OpenHandle(FileHandle aFD) { mFD = aFD; }
|
|
|
|
bool Valid() { return mFD != kInvalidFileHandle; }
|
2015-04-27 17:49:44 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
void WriteBuffer(const char* aBuffer, size_t aLen) {
|
2015-04-27 17:49:44 +03:00
|
|
|
if (!Valid()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-24 14:17:23 +03:00
|
|
|
|
|
|
|
while (aLen-- > 0) {
|
|
|
|
WriteChar(*aBuffer++);
|
|
|
|
}
|
2019-12-02 16:18:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteString(const char* aStr) { WriteBuffer(aStr, my_strlen(aStr)); }
|
|
|
|
|
|
|
|
template <int N>
|
|
|
|
void WriteLiteral(const char (&aStr)[N]) {
|
|
|
|
WriteBuffer(aStr, N - 1);
|
2015-04-27 17:49:44 +03:00
|
|
|
}
|
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
FileHandle FileDesc() { return mFD; }
|
2015-04-27 17:49:44 +03:00
|
|
|
|
|
|
|
private:
|
2020-06-29 17:37:56 +03:00
|
|
|
PlatformWriter(const PlatformWriter&) = delete;
|
|
|
|
|
|
|
|
const PlatformWriter& operator=(const PlatformWriter&) = delete;
|
2020-03-24 14:17:23 +03:00
|
|
|
|
|
|
|
void WriteChar(char aChar) {
|
|
|
|
if (mPos == kBufferSize) {
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
mBuffer[mPos++] = aChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Flush() {
|
|
|
|
if (mPos > 0) {
|
2020-04-08 09:55:40 +03:00
|
|
|
char* buffer = mBuffer;
|
|
|
|
size_t length = mPos;
|
|
|
|
while (length > 0) {
|
2020-12-01 20:32:16 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
DWORD written_bytes = 0;
|
|
|
|
Unused << WriteFile(mFD, buffer, length, &written_bytes, nullptr);
|
2020-03-24 14:17:23 +03:00
|
|
|
#elif defined(XP_UNIX)
|
2020-12-01 20:32:16 +03:00
|
|
|
ssize_t written_bytes = sys_write(mFD, buffer, length);
|
|
|
|
if (written_bytes < 0) {
|
|
|
|
if (errno == EAGAIN) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-03-24 14:17:23 +03:00
|
|
|
#endif
|
2020-12-01 20:32:16 +03:00
|
|
|
buffer += written_bytes;
|
|
|
|
length -= written_bytes;
|
|
|
|
}
|
|
|
|
|
2020-03-24 14:17:23 +03:00
|
|
|
mPos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const size_t kBufferSize = 512;
|
|
|
|
|
|
|
|
char mBuffer[kBufferSize];
|
|
|
|
size_t mPos;
|
2020-09-07 19:02:26 +03:00
|
|
|
FileHandle mFD;
|
2015-04-27 17:49:44 +03:00
|
|
|
};
|
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
class JSONAnnotationWriter : public AnnotationWriter {
|
2019-11-16 14:00:43 +03:00
|
|
|
public:
|
2019-12-02 16:18:35 +03:00
|
|
|
explicit JSONAnnotationWriter(PlatformWriter& aPlatformWriter)
|
|
|
|
: mWriter(aPlatformWriter), mEmpty(true) {
|
|
|
|
mWriter.WriteBuffer("{", 1);
|
2019-11-16 11:29:07 +03:00
|
|
|
}
|
2019-06-18 22:19:33 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
~JSONAnnotationWriter() { mWriter.WriteBuffer("}", 1); }
|
2019-11-16 14:00:43 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
void Write(Annotation aAnnotation, const char* aValue,
|
|
|
|
size_t aLen = 0) override {
|
|
|
|
size_t len = aLen ? aLen : my_strlen(aValue);
|
|
|
|
const char* annotationStr = AnnotationToString(aAnnotation);
|
2019-11-16 14:00:43 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
WritePrefix();
|
|
|
|
mWriter.WriteBuffer(annotationStr, my_strlen(annotationStr));
|
|
|
|
WriteSeparator();
|
|
|
|
WriteEscapedString(aValue, len);
|
|
|
|
WriteSuffix();
|
|
|
|
};
|
2019-11-16 14:00:43 +03:00
|
|
|
|
2020-11-23 10:25:36 +03:00
|
|
|
void Write(Annotation aAnnotation, uint64_t aValue) override {
|
|
|
|
char buffer[32] = {};
|
|
|
|
XP_STOA(aValue, buffer);
|
|
|
|
Write(aAnnotation, buffer);
|
|
|
|
};
|
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
private:
|
|
|
|
void WritePrefix() {
|
|
|
|
if (mEmpty) {
|
|
|
|
mWriter.WriteBuffer("\"", 1);
|
|
|
|
mEmpty = false;
|
|
|
|
} else {
|
|
|
|
mWriter.WriteBuffer(",\"", 2);
|
2019-11-16 14:00:43 +03:00
|
|
|
}
|
2019-11-16 11:29:07 +03:00
|
|
|
}
|
2019-06-18 22:19:33 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
void WriteSeparator() { mWriter.WriteBuffer("\":\"", 3); }
|
|
|
|
void WriteSuffix() { mWriter.WriteBuffer("\"", 1); }
|
|
|
|
void WriteEscapedString(const char* aStr, size_t aLen) {
|
|
|
|
for (size_t i = 0; i < aLen; i++) {
|
|
|
|
uint8_t c = aStr[i];
|
|
|
|
if (c <= 0x1f || c == '\\' || c == '\"') {
|
|
|
|
mWriter.WriteBuffer("\\u00", 4);
|
|
|
|
WriteHexDigitAsAsciiChar((c & 0x00f0) >> 4);
|
|
|
|
WriteHexDigitAsAsciiChar(c & 0x000f);
|
|
|
|
} else {
|
|
|
|
mWriter.WriteBuffer(aStr + i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-16 14:00:43 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
void WriteHexDigitAsAsciiChar(uint8_t u) {
|
|
|
|
char buf[1];
|
|
|
|
buf[0] = static_cast<unsigned>((u < 10) ? '0' + u : 'a' + (u - 10));
|
|
|
|
mWriter.WriteBuffer(buf, 1);
|
|
|
|
}
|
2019-11-16 14:00:43 +03:00
|
|
|
|
2020-02-03 19:08:30 +03:00
|
|
|
PlatformWriter& mWriter;
|
2019-12-02 16:18:35 +03:00
|
|
|
bool mEmpty;
|
2019-06-18 22:19:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class BinaryAnnotationWriter : public AnnotationWriter {
|
|
|
|
public:
|
|
|
|
explicit BinaryAnnotationWriter(PlatformWriter& aPlatformWriter)
|
|
|
|
: mPlatformWriter(aPlatformWriter) {}
|
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
void Write(Annotation aAnnotation, const char* aValue,
|
|
|
|
size_t aLen = 0) override {
|
|
|
|
uint64_t len = aLen ? aLen : my_strlen(aValue);
|
2019-06-18 22:19:33 +03:00
|
|
|
mPlatformWriter.WriteBuffer((const char*)&aAnnotation, sizeof(aAnnotation));
|
|
|
|
mPlatformWriter.WriteBuffer((const char*)&len, sizeof(len));
|
|
|
|
mPlatformWriter.WriteBuffer(aValue, len);
|
|
|
|
};
|
|
|
|
|
2020-11-23 10:25:36 +03:00
|
|
|
void Write(Annotation aAnnotation, uint64_t aValue) override {
|
|
|
|
char buffer[32] = {};
|
|
|
|
XP_STOA(aValue, buffer);
|
|
|
|
Write(aAnnotation, buffer);
|
|
|
|
};
|
|
|
|
|
2019-06-18 22:19:33 +03:00
|
|
|
private:
|
|
|
|
PlatformWriter& mPlatformWriter;
|
2015-04-27 17:49:44 +03:00
|
|
|
};
|
|
|
|
|
2019-07-03 02:26:11 +03:00
|
|
|
#ifdef MOZ_PHC
|
|
|
|
// The stack traces are encoded as a comma-separated list of decimal
|
|
|
|
// (not hexadecimal!) addresses, e.g. "12345678,12345679,12345680".
|
|
|
|
static void WritePHCStackTrace(AnnotationWriter& aWriter,
|
|
|
|
const Annotation aName,
|
2019-08-02 03:33:04 +03:00
|
|
|
const Maybe<phc::StackTrace>& aStack) {
|
|
|
|
if (aStack.isNothing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-03 02:26:11 +03:00
|
|
|
// 21 is the max length of a 64-bit decimal address entry, including the
|
|
|
|
// trailing comma or '\0'. And then we add another 32 just to be safe.
|
|
|
|
char addrsString[mozilla::phc::StackTrace::kMaxFrames * 21 + 32];
|
|
|
|
char addrString[32];
|
|
|
|
char* p = addrsString;
|
|
|
|
*p = 0;
|
|
|
|
for (size_t i = 0; i < aStack->mLength; i++) {
|
|
|
|
if (i != 0) {
|
|
|
|
strcat(addrsString, ",");
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
XP_STOA(uintptr_t(aStack->mPcs[i]), addrString);
|
|
|
|
strcat(addrsString, addrString);
|
|
|
|
}
|
|
|
|
aWriter.Write(aName, addrsString);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WritePHCAddrInfo(AnnotationWriter& writer,
|
|
|
|
const phc::AddrInfo* aAddrInfo) {
|
|
|
|
// Is this a PHC allocation needing special treatment?
|
|
|
|
if (aAddrInfo && aAddrInfo->mKind != phc::AddrInfo::Kind::Unknown) {
|
|
|
|
const char* kindString;
|
|
|
|
switch (aAddrInfo->mKind) {
|
|
|
|
case phc::AddrInfo::Kind::Unknown:
|
|
|
|
kindString = "Unknown(?!)";
|
|
|
|
break;
|
|
|
|
case phc::AddrInfo::Kind::NeverAllocatedPage:
|
|
|
|
kindString = "NeverAllocatedPage";
|
|
|
|
break;
|
|
|
|
case phc::AddrInfo::Kind::InUsePage:
|
|
|
|
kindString = "InUsePage(?!)";
|
|
|
|
break;
|
|
|
|
case phc::AddrInfo::Kind::FreedPage:
|
|
|
|
kindString = "FreedPage";
|
|
|
|
break;
|
|
|
|
case phc::AddrInfo::Kind::GuardPage:
|
|
|
|
kindString = "GuardPage";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
kindString = "Unmatched(?!)";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writer.Write(Annotation::PHCKind, kindString);
|
2020-11-23 10:25:36 +03:00
|
|
|
writer.Write(Annotation::PHCBaseAddress, uintptr_t(aAddrInfo->mBaseAddr));
|
|
|
|
writer.Write(Annotation::PHCUsableSize, aAddrInfo->mUsableSize);
|
2019-07-03 02:26:11 +03:00
|
|
|
|
|
|
|
WritePHCStackTrace(writer, Annotation::PHCAllocStack,
|
2019-08-02 03:33:04 +03:00
|
|
|
aAddrInfo->mAllocStack);
|
|
|
|
WritePHCStackTrace(writer, Annotation::PHCFreeStack, aAddrInfo->mFreeStack);
|
2019-07-03 02:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-07 23:48:58 +03:00
|
|
|
/**
|
|
|
|
* If minidump_id is null, we assume that dump_path contains the full
|
|
|
|
* dump file path.
|
|
|
|
*/
|
|
|
|
static void OpenAPIData(PlatformWriter& aWriter, const XP_CHAR* dump_path,
|
|
|
|
const XP_CHAR* minidump_id = nullptr) {
|
|
|
|
static XP_CHAR extraDataPath[XP_PATH_MAX];
|
2016-10-19 13:38:56 +03:00
|
|
|
size_t size = XP_PATH_MAX;
|
2016-03-07 23:48:58 +03:00
|
|
|
XP_CHAR* p;
|
|
|
|
if (minidump_id) {
|
|
|
|
p = Concat(extraDataPath, dump_path, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
} else {
|
|
|
|
p = Concat(extraDataPath, dump_path, &size);
|
|
|
|
// Skip back past the .dmp extension, if any.
|
|
|
|
if (*(p - 4) == XP_TEXT('.')) {
|
|
|
|
p -= 4;
|
|
|
|
size += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Concat(p, extraFileExtension, &size);
|
|
|
|
aWriter.Open(extraDataPath);
|
|
|
|
}
|
|
|
|
|
2019-12-02 18:45:17 +03:00
|
|
|
#ifdef XP_WIN
|
2020-11-23 10:25:36 +03:00
|
|
|
static void AnnotateMemoryStatus(AnnotationWriter& aWriter) {
|
2016-03-29 14:16:09 +03:00
|
|
|
MEMORYSTATUSEX statex;
|
|
|
|
statex.dwLength = sizeof(statex);
|
|
|
|
if (GlobalMemoryStatusEx(&statex)) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::SystemMemoryUsePercentage, statex.dwMemoryLoad);
|
|
|
|
aWriter.Write(Annotation::TotalVirtualMemory, statex.ullTotalVirtual);
|
|
|
|
aWriter.Write(Annotation::AvailableVirtualMemory, statex.ullAvailVirtual);
|
|
|
|
aWriter.Write(Annotation::TotalPhysicalMemory, statex.ullTotalPhys);
|
|
|
|
aWriter.Write(Annotation::AvailablePhysicalMemory, statex.ullAvailPhys);
|
2016-03-29 14:16:09 +03:00
|
|
|
}
|
2019-06-14 23:56:41 +03:00
|
|
|
|
|
|
|
PERFORMANCE_INFORMATION info;
|
|
|
|
if (K32GetPerformanceInfo(&info, sizeof(info))) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::TotalPageFile, info.CommitLimit * info.PageSize);
|
|
|
|
aWriter.Write(Annotation::AvailablePageFile,
|
|
|
|
(info.CommitLimit - info.CommitTotal) * info.PageSize);
|
2019-06-14 23:56:41 +03:00
|
|
|
}
|
|
|
|
}
|
2019-12-03 14:53:45 +03:00
|
|
|
#elif XP_MACOSX
|
|
|
|
// Extract the total physical memory of the system.
|
2020-11-23 10:25:36 +03:00
|
|
|
static void WritePhysicalMemoryStatus(AnnotationWriter& aWriter) {
|
2019-12-03 14:53:45 +03:00
|
|
|
uint64_t physicalMemoryByteSize = 0;
|
|
|
|
const size_t NAME_LEN = 2;
|
|
|
|
int name[NAME_LEN] = {/* Hardware */ CTL_HW,
|
|
|
|
/* 64-bit physical memory size */ HW_MEMSIZE};
|
|
|
|
size_t infoByteSize = sizeof(physicalMemoryByteSize);
|
|
|
|
if (sysctl(name, NAME_LEN, &physicalMemoryByteSize, &infoByteSize,
|
|
|
|
/* We do not replace data */ nullptr,
|
|
|
|
/* We do not replace data */ 0) != -1) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::TotalPhysicalMemory, physicalMemoryByteSize);
|
2019-12-03 14:53:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract available and purgeable physical memory.
|
2020-11-23 10:25:36 +03:00
|
|
|
static void WriteAvailableMemoryStatus(AnnotationWriter& aWriter) {
|
2019-12-03 14:53:45 +03:00
|
|
|
auto host = mach_host_self();
|
|
|
|
vm_statistics64_data_t stats;
|
|
|
|
unsigned int count = HOST_VM_INFO64_COUNT;
|
|
|
|
if (host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&stats, &count) ==
|
|
|
|
KERN_SUCCESS) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::AvailablePhysicalMemory,
|
|
|
|
stats.free_count * vm_page_size);
|
|
|
|
aWriter.Write(Annotation::PurgeablePhysicalMemory,
|
|
|
|
stats.purgeable_count * vm_page_size);
|
2019-12-03 14:53:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the status of the swap.
|
2020-11-23 10:25:36 +03:00
|
|
|
static void WriteSwapFileStatus(AnnotationWriter& aWriter) {
|
2019-12-03 14:53:45 +03:00
|
|
|
const size_t NAME_LEN = 2;
|
|
|
|
int name[] = {/* Hardware */ CTL_VM,
|
|
|
|
/* 64-bit physical memory size */ VM_SWAPUSAGE};
|
|
|
|
struct xsw_usage swapUsage;
|
|
|
|
size_t infoByteSize = sizeof(swapUsage);
|
|
|
|
if (sysctl(name, NAME_LEN, &swapUsage, &infoByteSize,
|
|
|
|
/* We do not replace data */ nullptr,
|
|
|
|
/* We do not replace data */ 0) != -1) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::AvailableSwapMemory, swapUsage.xsu_avail);
|
2019-12-03 14:53:45 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 10:25:36 +03:00
|
|
|
static void AnnotateMemoryStatus(AnnotationWriter& aWriter) {
|
|
|
|
WritePhysicalMemoryStatus(aWriter);
|
|
|
|
WriteAvailableMemoryStatus(aWriter);
|
|
|
|
WriteSwapFileStatus(aWriter);
|
2019-12-12 19:06:53 +03:00
|
|
|
}
|
2020-01-07 13:06:55 +03:00
|
|
|
|
|
|
|
#elif XP_LINUX
|
|
|
|
|
2020-11-23 10:25:36 +03:00
|
|
|
static void AnnotateMemoryStatus(AnnotationWriter& aWriter) {
|
2020-01-07 13:06:55 +03:00
|
|
|
// We can't simply call `sysinfo` as this requires libc.
|
|
|
|
// So we need to parse /proc/meminfo.
|
|
|
|
|
|
|
|
// We read the entire file to memory prior to parsing
|
|
|
|
// as it makes the parser code a little bit simpler.
|
|
|
|
// As /proc/meminfo is synchronized via `proc_create_single`,
|
|
|
|
// there's no risk of race condition regardless of how we
|
|
|
|
// read it.
|
|
|
|
|
|
|
|
// The buffer in which we're going to load the entire file.
|
2021-02-13 10:13:29 +03:00
|
|
|
// A typical size for /proc/meminfo is 1KiB, so 4KiB should
|
2020-01-07 13:06:55 +03:00
|
|
|
// be large enough until further notice.
|
2021-02-13 10:13:29 +03:00
|
|
|
const size_t BUFFER_SIZE_BYTES = 4096;
|
2020-01-07 13:06:55 +03:00
|
|
|
char buffer[BUFFER_SIZE_BYTES];
|
|
|
|
|
2021-02-13 10:13:29 +03:00
|
|
|
size_t bufferLen = 0;
|
2020-01-07 13:06:55 +03:00
|
|
|
{
|
|
|
|
// Read and load into memory.
|
|
|
|
int fd = sys_open("/proc/meminfo", O_RDONLY, /* chmod */ 0);
|
|
|
|
if (fd == -1) {
|
|
|
|
// No /proc/meminfo? Well, fail silently.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto Guard = MakeScopeExit([fd]() { mozilla::Unused << sys_close(fd); });
|
|
|
|
|
2021-02-13 10:13:29 +03:00
|
|
|
ssize_t bytesRead = 0;
|
|
|
|
do {
|
|
|
|
if ((bytesRead = sys_read(fd, buffer + bufferLen,
|
|
|
|
BUFFER_SIZE_BYTES - bufferLen)) < 0) {
|
|
|
|
if ((errno == EAGAIN) || (errno == EINTR)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cannot read for some reason. Let's give up.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufferLen += bytesRead;
|
|
|
|
|
|
|
|
if (bufferLen == BUFFER_SIZE_BYTES) {
|
|
|
|
// The file is too large, bail out
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (bytesRead != 0);
|
2020-01-07 13:06:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Each line of /proc/meminfo looks like
|
|
|
|
// SomeLabel: number unit
|
|
|
|
// The last line is empty.
|
|
|
|
// Let's write a parser.
|
|
|
|
// Note that we don't care about writing a normative parser, so
|
|
|
|
// we happily skip whitespaces without checking that it's necessary.
|
|
|
|
|
|
|
|
// A stack-allocated structure containing a 0-terminated string.
|
|
|
|
// We could avoid the memory copies and make it a slice at the cost
|
|
|
|
// of a slightly more complicated parser. Since we're not in a
|
|
|
|
// performance-critical section, we didn't.
|
|
|
|
struct DataBuffer {
|
|
|
|
DataBuffer() : data{0}, pos(0) {}
|
|
|
|
// Clear the buffer.
|
|
|
|
void reset() {
|
|
|
|
pos = 0;
|
|
|
|
data[0] = 0;
|
|
|
|
}
|
|
|
|
// Append a character.
|
|
|
|
//
|
|
|
|
// In case of error (if c is '\0' or the buffer is full), does nothing.
|
|
|
|
void append(char c) {
|
|
|
|
if (c == 0 || pos >= sizeof(data) - 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data[pos++] = c;
|
|
|
|
data[pos] = 0;
|
|
|
|
}
|
|
|
|
// Compare the buffer against a nul-terminated string.
|
|
|
|
bool operator==(const char* s) const {
|
|
|
|
for (size_t i = 0; i < pos; ++i) {
|
|
|
|
if (s[i] != data[i]) {
|
|
|
|
// Note: Since `data` never contains a '0' in positions [0,pos)
|
|
|
|
// this will bailout once we have reached the end of `s`.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A NUL-terminated string of `pos + 1` chars (the +1 is for the 0).
|
|
|
|
char data[256];
|
|
|
|
|
|
|
|
// Invariant: < 256.
|
|
|
|
size_t pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A DataBuffer holding the string representation of a non-negative number.
|
|
|
|
struct NumberBuffer : DataBuffer {
|
|
|
|
// If possible, convert the string into a number.
|
|
|
|
// Returns `true` in case of success, `false` in case of failure.
|
|
|
|
bool asNumber(size_t* number) {
|
|
|
|
int result;
|
|
|
|
if (!my_strtoui(&result, data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*number = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// A DataBuffer holding the string representation of a unit. As of this
|
|
|
|
// writing, we only support unit `kB`, which seems to be the only unit used in
|
|
|
|
// `/proc/meminfo`.
|
|
|
|
struct UnitBuffer : DataBuffer {
|
|
|
|
// If possible, convert the string into a multiplier, e.g. `kB => 1024`.
|
|
|
|
// Return `true` in case of success, `false` in case of failure.
|
|
|
|
bool asMultiplier(size_t* multiplier) {
|
|
|
|
if (*this == "kB") {
|
|
|
|
*multiplier = 1024;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Other units don't seem to be specified/used.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The state of the mini-parser.
|
|
|
|
enum class State {
|
|
|
|
// Reading the label, including the trailing ':'.
|
|
|
|
Label,
|
|
|
|
// Reading the number, ignoring any whitespace.
|
|
|
|
Number,
|
|
|
|
// Reading the unit, ignoring any whitespace.
|
|
|
|
Unit,
|
|
|
|
};
|
|
|
|
|
|
|
|
// A single measure being read from /proc/meminfo, e.g.
|
|
|
|
// the total physical memory available on the system.
|
|
|
|
struct Measure {
|
|
|
|
Measure() : state(State::Label) {}
|
|
|
|
// Reset the measure for a new read.
|
|
|
|
void reset() {
|
|
|
|
state = State::Label;
|
|
|
|
label.reset();
|
|
|
|
number.reset();
|
|
|
|
unit.reset();
|
|
|
|
}
|
|
|
|
// Attempt to convert the measure into a number.
|
|
|
|
// Return `true` if both the number and the multiplier could be
|
|
|
|
// converted, `false` otherwise.
|
|
|
|
// In case of overflow, produces the maximal possible `size_t`.
|
|
|
|
bool asValue(size_t* result) {
|
|
|
|
size_t numberAsSize = 0;
|
|
|
|
if (!number.asNumber(&numberAsSize)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
size_t unitAsMultiplier = 0;
|
|
|
|
if (!unit.asMultiplier(&unitAsMultiplier)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (numberAsSize * unitAsMultiplier >= numberAsSize) {
|
|
|
|
*result = numberAsSize * unitAsMultiplier;
|
|
|
|
} else {
|
|
|
|
// Overflow. Unlikely, but just in case, let's return
|
|
|
|
// the maximal possible value.
|
|
|
|
*result = size_t(-1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The label being read, e.g. `MemFree`. Does not include the trailing ':'.
|
|
|
|
DataBuffer label;
|
|
|
|
|
|
|
|
// The number being read, e.g. "1024".
|
|
|
|
NumberBuffer number;
|
|
|
|
|
|
|
|
// The unit being read, e.g. "kB".
|
|
|
|
UnitBuffer unit;
|
|
|
|
|
|
|
|
// What we're reading at the moment.
|
|
|
|
State state;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A value we wish to store for later processing.
|
|
|
|
// e.g. to compute `AvailablePageFile`, we need to
|
|
|
|
// store `CommitLimit` and `Committed_AS`.
|
|
|
|
struct ValueStore {
|
|
|
|
ValueStore() : value(0), found(false) {}
|
|
|
|
size_t value;
|
|
|
|
bool found;
|
|
|
|
};
|
|
|
|
ValueStore commitLimit;
|
|
|
|
ValueStore committedAS;
|
|
|
|
ValueStore memTotal;
|
|
|
|
ValueStore swapTotal;
|
|
|
|
|
|
|
|
// The current measure.
|
|
|
|
Measure measure;
|
|
|
|
|
|
|
|
for (size_t pos = 0; pos < size_t(bufferLen); ++pos) {
|
|
|
|
const char c = buffer[pos];
|
|
|
|
switch (measure.state) {
|
|
|
|
case State::Label:
|
|
|
|
if (c == ':') {
|
|
|
|
// We have finished reading the label.
|
|
|
|
measure.state = State::Number;
|
|
|
|
} else {
|
|
|
|
measure.label.append(c);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case State::Number:
|
|
|
|
if (c == ' ') {
|
|
|
|
// Ignore whitespace
|
|
|
|
} else if ('0' <= c && c <= '9') {
|
|
|
|
// Accumulate numbers.
|
|
|
|
measure.number.append(c);
|
|
|
|
} else {
|
|
|
|
// We have jumped to the unit.
|
|
|
|
measure.unit.append(c);
|
|
|
|
measure.state = State::Unit;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case State::Unit:
|
|
|
|
if (c == ' ') {
|
|
|
|
// Ignore whitespace
|
|
|
|
} else if (c == '\n') {
|
|
|
|
// Flush line.
|
|
|
|
// - If this one of the measures we're interested in, write it.
|
|
|
|
// - Once we're done, reset the parser.
|
|
|
|
auto Guard = MakeScopeExit([&measure]() { measure.reset(); });
|
|
|
|
|
|
|
|
struct PointOfInterest {
|
|
|
|
// The label we're looking for, e.g. "MemTotal".
|
|
|
|
const char* label;
|
|
|
|
// If non-nullptr, store the value at this address.
|
|
|
|
ValueStore* dest;
|
|
|
|
// If other than Annotation::Count, write the value for this
|
|
|
|
// annotation.
|
|
|
|
Annotation annotation;
|
|
|
|
};
|
|
|
|
const PointOfInterest POINTS_OF_INTEREST[] = {
|
|
|
|
{"MemTotal", &memTotal, Annotation::TotalPhysicalMemory},
|
|
|
|
{"MemFree", nullptr, Annotation::AvailablePhysicalMemory},
|
|
|
|
{"MemAvailable", nullptr, Annotation::AvailableVirtualMemory},
|
|
|
|
{"SwapFree", nullptr, Annotation::AvailableSwapMemory},
|
|
|
|
{"SwapTotal", &swapTotal, Annotation::Count},
|
|
|
|
{"CommitLimit", &commitLimit, Annotation::Count},
|
|
|
|
{"Committed_AS", &committedAS, Annotation::Count},
|
|
|
|
};
|
|
|
|
for (const auto& pointOfInterest : POINTS_OF_INTEREST) {
|
|
|
|
if (measure.label == pointOfInterest.label) {
|
|
|
|
size_t value;
|
|
|
|
if (measure.asValue(&value)) {
|
|
|
|
if (pointOfInterest.dest != nullptr) {
|
|
|
|
pointOfInterest.dest->found = true;
|
|
|
|
pointOfInterest.dest->value = value;
|
|
|
|
}
|
|
|
|
if (pointOfInterest.annotation != Annotation::Count) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(pointOfInterest.annotation, value);
|
2020-01-07 13:06:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, ignore.
|
|
|
|
} else {
|
|
|
|
measure.unit.append(c);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commitLimit.found && committedAS.found) {
|
|
|
|
// If available, attempt to determine the available virtual memory.
|
|
|
|
// As `commitLimit` is not guaranteed to be larger than `committedAS`,
|
|
|
|
// we return `0` in case the commit limit has already been exceeded.
|
|
|
|
uint64_t availablePageFile = (committedAS.value <= commitLimit.value)
|
|
|
|
? (commitLimit.value - committedAS.value)
|
|
|
|
: 0;
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::AvailablePageFile, availablePageFile);
|
2020-01-07 13:06:55 +03:00
|
|
|
}
|
|
|
|
if (memTotal.found && swapTotal.found) {
|
|
|
|
// If available, attempt to determine the available virtual memory.
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(Annotation::TotalPageFile, memTotal.value + swapTotal.value);
|
2020-01-07 13:06:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 14:53:45 +03:00
|
|
|
#else
|
|
|
|
|
2020-01-07 13:07:51 +03:00
|
|
|
static void AnnotateMemoryStatus(AnnotationTable&) {
|
2019-12-03 14:53:45 +03:00
|
|
|
// No memory data for other platforms yet.
|
|
|
|
}
|
|
|
|
|
2020-01-07 13:06:55 +03:00
|
|
|
#endif // XP_WIN || XP_MACOSX || XP_LINUX || else
|
2016-03-29 14:16:09 +03:00
|
|
|
|
2016-10-19 13:38:56 +03:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Launches the program specified in aProgramPath with aMinidumpPath as its
|
|
|
|
* sole argument.
|
|
|
|
*
|
|
|
|
* @param aProgramPath The path of the program to be launched
|
|
|
|
* @param aMinidumpPath The path of the minidump file, passed as an argument
|
|
|
|
* to the launched program
|
|
|
|
*/
|
2018-02-26 17:00:58 +03:00
|
|
|
static bool LaunchProgram(const XP_CHAR* aProgramPath,
|
|
|
|
const XP_CHAR* aMinidumpPath) {
|
2016-10-19 13:38:56 +03:00
|
|
|
# ifdef XP_WIN
|
|
|
|
XP_CHAR cmdLine[CMDLINE_SIZE];
|
|
|
|
XP_CHAR* p;
|
|
|
|
|
|
|
|
size_t size = CMDLINE_SIZE;
|
|
|
|
p = Concat(cmdLine, L"\"", &size);
|
|
|
|
p = Concat(p, aProgramPath, &size);
|
2018-02-26 17:00:58 +03:00
|
|
|
p = Concat(p, L"\" \"", &size);
|
2016-10-19 13:38:56 +03:00
|
|
|
p = Concat(p, aMinidumpPath, &size);
|
|
|
|
Concat(p, L"\"", &size);
|
|
|
|
|
2016-10-19 13:51:29 +03:00
|
|
|
PROCESS_INFORMATION pi = {};
|
|
|
|
STARTUPINFO si = {};
|
2016-10-19 13:38:56 +03:00
|
|
|
si.cb = sizeof(si);
|
|
|
|
|
|
|
|
// If CreateProcess() fails don't do anything
|
|
|
|
if (CreateProcess(nullptr, (LPWSTR)cmdLine, nullptr, nullptr, FALSE,
|
|
|
|
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, nullptr, nullptr,
|
|
|
|
&si, &pi)) {
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
2017-06-28 00:39:30 +03:00
|
|
|
# elif defined(XP_MACOSX)
|
|
|
|
// Needed to locate NSS and its dependencies
|
2021-02-19 23:50:23 +03:00
|
|
|
setenv("DYLD_LIBRARY_PATH", libraryPath.c_str(), /* overwrite */ 1);
|
2017-06-28 00:39:30 +03:00
|
|
|
|
|
|
|
pid_t pid = 0;
|
|
|
|
char* const my_argv[] = {const_cast<char*>(aProgramPath),
|
|
|
|
const_cast<char*>(aMinidumpPath), nullptr};
|
|
|
|
|
|
|
|
char** env = nullptr;
|
|
|
|
char*** nsEnv = _NSGetEnviron();
|
|
|
|
if (nsEnv) {
|
|
|
|
env = *nsEnv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rv = posix_spawnp(&pid, my_argv[0], nullptr, nullptr, my_argv, env);
|
|
|
|
|
|
|
|
if (rv != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
# else // !XP_MACOSX
|
2016-10-19 13:38:56 +03:00
|
|
|
pid_t pid = sys_fork();
|
|
|
|
|
|
|
|
if (pid == -1) {
|
|
|
|
return false;
|
|
|
|
} else if (pid == 0) {
|
2018-02-26 17:00:58 +03:00
|
|
|
Unused << execl(aProgramPath, aProgramPath, aMinidumpPath, nullptr);
|
2016-10-19 13:38:56 +03:00
|
|
|
_exit(1);
|
|
|
|
}
|
2017-06-28 00:39:30 +03:00
|
|
|
# endif // XP_MACOSX
|
2016-10-19 13:38:56 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Launch the crash reporter activity on Android
|
|
|
|
*
|
|
|
|
* @param aProgramPath The path of the program to be launched
|
|
|
|
* @param aMinidumpPath The path to the crash minidump file
|
|
|
|
*/
|
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
static bool LaunchCrashHandlerService(const XP_CHAR* aProgramPath,
|
|
|
|
const XP_CHAR* aMinidumpPath) {
|
2018-08-22 20:45:56 +03:00
|
|
|
static XP_CHAR extrasPath[XP_PATH_MAX];
|
|
|
|
size_t size = XP_PATH_MAX;
|
|
|
|
|
|
|
|
XP_CHAR* p = Concat(extrasPath, aMinidumpPath, &size);
|
|
|
|
p = Concat(p - 3, "extra", &size);
|
|
|
|
|
2016-10-19 13:38:56 +03:00
|
|
|
pid_t pid = sys_fork();
|
|
|
|
|
|
|
|
if (pid == -1)
|
|
|
|
return false;
|
|
|
|
else if (pid == 0) {
|
2018-08-22 20:45:56 +03:00
|
|
|
// Invoke the crash handler service using am
|
2016-10-19 13:38:56 +03:00
|
|
|
if (androidUserSerial) {
|
|
|
|
Unused << execlp(
|
2018-07-02 17:32:10 +03:00
|
|
|
"/system/bin/am", "/system/bin/am", androidStartServiceCommand,
|
2018-08-22 20:45:56 +03:00
|
|
|
"--user", androidUserSerial, "-a", "org.mozilla.gecko.ACTION_CRASHED",
|
2016-10-19 13:38:56 +03:00
|
|
|
"-n", aProgramPath, "--es", "minidumpPath", aMinidumpPath, "--es",
|
2019-08-02 11:26:05 +03:00
|
|
|
"extrasPath", extrasPath, "--ez", "fatal", "true", (char*)0);
|
2016-10-19 13:38:56 +03:00
|
|
|
} else {
|
|
|
|
Unused << execlp(
|
2018-07-02 17:32:10 +03:00
|
|
|
"/system/bin/am", "/system/bin/am", androidStartServiceCommand, "-a",
|
2018-08-22 20:45:56 +03:00
|
|
|
"org.mozilla.gecko.ACTION_CRASHED", "-n", aProgramPath, "--es",
|
2016-10-19 13:38:56 +03:00
|
|
|
"minidumpPath", aMinidumpPath, "--es", "extrasPath", extrasPath,
|
2019-08-02 11:26:05 +03:00
|
|
|
"--ez", "fatal", "true", (char*)0);
|
2016-10-19 13:38:56 +03:00
|
|
|
}
|
|
|
|
_exit(1);
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
Unused << HANDLE_EINTR(sys_waitpid(pid, &status, __WALL));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-01-20 21:23:48 +03:00
|
|
|
static void WriteMainThreadRunnableName(AnnotationWriter& aWriter) {
|
|
|
|
#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY
|
|
|
|
// Only try to collect this information if the main thread is crashing.
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Use `my_memchr` over `strlen` to ensure we don't run off the end of
|
|
|
|
// the buffer if it contains no null bytes. This is used instead of `strnlen`,
|
|
|
|
// as breakpad's linux support library doesn't export a `my_strnlen` function.
|
|
|
|
const char* buf = nsThread::sMainThreadRunnableName.begin();
|
|
|
|
size_t len = nsThread::kRunnableNameBufSize;
|
|
|
|
if (const void* end = my_memchr(buf, '\0', len)) {
|
|
|
|
len = static_cast<const char*>(end) - buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0) {
|
|
|
|
aWriter.Write(Annotation::MainThreadRunnableName, buf, len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-04-30 23:10:58 +03:00
|
|
|
static void WriteOOMAllocationSize(AnnotationWriter& aWriter) {
|
|
|
|
if (gOOMAllocationSize) {
|
|
|
|
aWriter.Write(Annotation::OOMAllocationSize, gOOMAllocationSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 22:19:33 +03:00
|
|
|
static void WriteMozCrashReason(AnnotationWriter& aWriter) {
|
|
|
|
if (gMozCrashReason != nullptr) {
|
|
|
|
aWriter.Write(Annotation::MozCrashReason, gMozCrashReason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 10:25:36 +03:00
|
|
|
static void WriteAnnotations(AnnotationWriter& aWriter,
|
2020-04-08 09:55:40 +03:00
|
|
|
const AnnotationTable& aAnnotations) {
|
2019-06-01 00:54:03 +03:00
|
|
|
for (auto key : MakeEnumeratedRange(Annotation::Count)) {
|
2020-04-08 09:55:40 +03:00
|
|
|
const nsCString& value = aAnnotations[key];
|
2019-06-01 00:54:03 +03:00
|
|
|
if (!value.IsEmpty()) {
|
2020-11-23 10:25:36 +03:00
|
|
|
aWriter.Write(key, value.get(), value.Length());
|
2019-06-01 00:54:03 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-08 09:55:40 +03:00
|
|
|
}
|
|
|
|
|
2020-11-23 10:25:36 +03:00
|
|
|
static void WriteSynthesizedAnnotations(AnnotationWriter& aWriter) {
|
|
|
|
AnnotateMemoryStatus(aWriter);
|
|
|
|
}
|
|
|
|
|
2020-04-08 09:55:40 +03:00
|
|
|
static void WriteAnnotationsForMainProcessCrash(PlatformWriter& pw,
|
|
|
|
const phc::AddrInfo* addrInfo,
|
|
|
|
time_t crashTime) {
|
|
|
|
JSONAnnotationWriter writer(pw);
|
|
|
|
WriteAnnotations(writer, crashReporterAPIData_Table);
|
2020-11-23 10:25:36 +03:00
|
|
|
WriteSynthesizedAnnotations(writer);
|
|
|
|
writer.Write(Annotation::CrashTime, uint64_t(crashTime));
|
2019-05-18 19:19:57 +03:00
|
|
|
|
2021-10-05 07:41:53 +03:00
|
|
|
if (inactiveStateStart) {
|
|
|
|
writer.Write(Annotation::LastInteractionDuration,
|
|
|
|
crashTime - inactiveStateStart);
|
|
|
|
}
|
|
|
|
|
2019-05-18 19:19:57 +03:00
|
|
|
double uptimeTS = (TimeStamp::NowLoRes() - TimeStamp::ProcessCreation())
|
|
|
|
.ToSecondsSigDigits();
|
|
|
|
char uptimeTSString[64];
|
|
|
|
SimpleNoCLibDtoA(uptimeTS, uptimeTSString, sizeof(uptimeTSString));
|
2019-06-18 22:19:33 +03:00
|
|
|
writer.Write(Annotation::UptimeTS, uptimeTSString);
|
2019-05-18 19:19:57 +03:00
|
|
|
|
|
|
|
// calculate time since last crash (if possible).
|
|
|
|
if (lastCrashTime != 0) {
|
2020-11-23 10:25:36 +03:00
|
|
|
uint64_t timeSinceLastCrash = crashTime - lastCrashTime;
|
2019-05-18 19:19:57 +03:00
|
|
|
|
|
|
|
if (timeSinceLastCrash != 0) {
|
2020-11-23 10:25:36 +03:00
|
|
|
writer.Write(Annotation::SecondsSinceLastCrash, timeSinceLastCrash);
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isGarbageCollecting) {
|
2019-06-18 22:19:33 +03:00
|
|
|
writer.Write(Annotation::IsGarbageCollecting, "1");
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eventloopNestingLevel > 0) {
|
2020-11-23 10:25:36 +03:00
|
|
|
writer.Write(Annotation::EventLoopNestingLevel, eventloopNestingLevel);
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
|
2021-08-09 23:08:17 +03:00
|
|
|
#if defined(XP_WIN) && defined(HAS_DLL_BLOCKLIST)
|
2019-12-02 16:18:35 +03:00
|
|
|
// HACK: The DLL blocklist code will manually write its annotations as JSON
|
|
|
|
DllBlocklist_WriteNotes(writer);
|
2021-08-09 23:08:17 +03:00
|
|
|
#endif // defined(XP_WIN) && defined(HAS_DLL_BLOCKLIST)
|
2019-05-18 19:19:57 +03:00
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
WriteMozCrashReason(writer);
|
2019-05-18 19:19:57 +03:00
|
|
|
|
2020-01-20 21:23:48 +03:00
|
|
|
WriteMainThreadRunnableName(writer);
|
|
|
|
|
2021-04-30 23:10:58 +03:00
|
|
|
WriteOOMAllocationSize(writer);
|
2019-05-18 19:19:57 +03:00
|
|
|
|
|
|
|
if (gTexturesSize) {
|
2020-11-23 10:25:36 +03:00
|
|
|
writer.Write(Annotation::TextureUsage, gTexturesSize);
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
if (!memoryReportPath.empty()) {
|
2019-06-18 22:19:33 +03:00
|
|
|
writer.Write(Annotation::ContainsMemoryReport, "1");
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 02:26:11 +03:00
|
|
|
#ifdef MOZ_PHC
|
|
|
|
WritePHCAddrInfo(writer, addrInfo);
|
|
|
|
#endif
|
|
|
|
|
2019-05-18 19:19:57 +03:00
|
|
|
std::function<void(const char*)> getThreadAnnotationCB =
|
|
|
|
[&](const char* aValue) -> void {
|
|
|
|
if (aValue) {
|
2019-06-18 22:19:33 +03:00
|
|
|
writer.Write(Annotation::ThreadIdNameMapping, aValue);
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
GetFlatThreadAnnotation(getThreadAnnotationCB, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WriteCrashEventFile(time_t crashTime, const char* crashTimeString,
|
2019-07-03 02:26:11 +03:00
|
|
|
const phc::AddrInfo* addrInfo,
|
2019-05-18 19:19:57 +03:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor
|
|
|
|
#else
|
|
|
|
const XP_CHAR* minidump_id
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
// 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
|
|
|
|
|
|
|
|
PlatformWriter eventFile;
|
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
if (!eventsDirectory.empty()) {
|
2019-05-18 19:19:57 +03:00
|
|
|
static XP_CHAR crashEventPath[XP_PATH_MAX];
|
|
|
|
size_t size = XP_PATH_MAX;
|
|
|
|
XP_CHAR* p;
|
2021-02-19 23:50:23 +03:00
|
|
|
p = Concat(crashEventPath, eventsDirectory.c_str(), &size);
|
2019-05-18 19:19:57 +03:00
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
Concat(p, id_ascii, &size);
|
|
|
|
#else
|
|
|
|
Concat(p, minidump_id, &size);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
eventFile.Open(crashEventPath);
|
2019-12-02 16:18:35 +03:00
|
|
|
eventFile.WriteLiteral(kCrashMainID);
|
|
|
|
eventFile.WriteString(crashTimeString);
|
|
|
|
eventFile.WriteLiteral("\n");
|
|
|
|
eventFile.WriteString(id_ascii);
|
|
|
|
eventFile.WriteLiteral("\n");
|
2019-07-03 02:26:11 +03:00
|
|
|
WriteAnnotationsForMainProcessCrash(eventFile, addrInfo, crashTime);
|
2019-05-18 19:19:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 20:25:40 +03:00
|
|
|
// Callback invoked from breakpad's exception handler, this writes out the
|
|
|
|
// last annotations after a crash occurs and launches the crash reporter client.
|
|
|
|
//
|
|
|
|
// This function is not declared static even though it's not used outside of
|
|
|
|
// this file because of an issue in Fennec which prevents breakpad's exception
|
|
|
|
// handler from invoking it. See bug 1424304.
|
2017-10-12 00:33:56 +03:00
|
|
|
bool MinidumpCallback(
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
2007-07-25 05:06:00 +04:00
|
|
|
const XP_CHAR* dump_path, const XP_CHAR* minidump_id,
|
2012-09-25 15:52:54 +04:00
|
|
|
#endif
|
2007-07-25 05:06:00 +04:00
|
|
|
void* context,
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2007-07-25 05:06:00 +04:00
|
|
|
EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion,
|
|
|
|
#endif
|
2019-07-03 02:26:11 +03:00
|
|
|
const phc::AddrInfo* addrInfo, bool succeeded) {
|
2007-07-25 05:06:09 +04:00
|
|
|
bool returnValue = showOSCrashReporter ? false : succeeded;
|
2007-07-25 05:06:06 +04:00
|
|
|
|
2011-02-02 21:22:32 +03:00
|
|
|
static XP_CHAR minidumpPath[XP_PATH_MAX];
|
2016-10-19 13:38:56 +03:00
|
|
|
size_t size = XP_PATH_MAX;
|
2012-09-25 15:52:54 +04:00
|
|
|
XP_CHAR* p;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
p = Concat(minidumpPath, dump_path, &size);
|
2007-07-25 05:06:00 +04:00
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
Concat(p, dumpFileExtension, &size);
|
2012-09-25 15:52:54 +04:00
|
|
|
#else
|
|
|
|
Concat(minidumpPath, descriptor.path(), &size);
|
|
|
|
#endif
|
2007-07-25 05:06:00 +04:00
|
|
|
|
2014-08-30 09:21:18 +04: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);
|
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
if (!memoryReportPath.empty()) {
|
2014-08-30 09:21:18 +04:00
|
|
|
#ifdef XP_WIN
|
2021-02-19 23:50:23 +03:00
|
|
|
CopyFile(memoryReportPath.c_str(), memoryReportLocalPath, false);
|
2014-08-30 09:21:18 +04:00
|
|
|
#else
|
2021-02-19 23:50:23 +03:00
|
|
|
copy_file(memoryReportPath.c_str(), memoryReportLocalPath);
|
2014-08-30 09:21:18 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-10-05 07:41:53 +03:00
|
|
|
time_t crashTime = GetCurrentTimeForCrashTime();
|
2007-08-29 23:46:00 +04:00
|
|
|
char crashTimeString[32];
|
2019-06-05 09:43:19 +03:00
|
|
|
XP_TTOA(crashTime, crashTimeString);
|
2019-05-18 19:19:57 +03:00
|
|
|
|
2007-08-29 23:46:00 +04:00
|
|
|
// write crash time to file
|
|
|
|
if (lastCrashTimeFilename[0] != 0) {
|
2015-04-27 17:49:44 +03:00
|
|
|
PlatformWriter lastCrashFile(lastCrashTimeFilename);
|
2019-12-02 16:18:35 +03:00
|
|
|
lastCrashFile.WriteString(crashTimeString);
|
2007-08-29 23:46:00 +04:00
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2019-07-03 02:26:11 +03:00
|
|
|
WriteCrashEventFile(crashTime, crashTimeString, addrInfo,
|
2014-02-19 03:58:03 +04:00
|
|
|
#ifdef XP_LINUX
|
2019-05-18 19:19:57 +03:00
|
|
|
descriptor
|
2014-02-19 03:58:03 +04:00
|
|
|
#else
|
2019-05-18 19:19:57 +03:00
|
|
|
minidump_id
|
2014-02-19 03:58:03 +04:00
|
|
|
#endif
|
2019-05-18 19:19:57 +03:00
|
|
|
);
|
2014-02-19 03:58:03 +04:00
|
|
|
|
2020-03-24 14:17:23 +03:00
|
|
|
{
|
|
|
|
PlatformWriter apiData;
|
2016-03-07 23:48:58 +03:00
|
|
|
#ifdef XP_LINUX
|
2020-03-24 14:17:23 +03:00
|
|
|
OpenAPIData(apiData, descriptor.path());
|
2016-03-07 23:48:58 +03:00
|
|
|
#else
|
2020-03-24 14:17:23 +03:00
|
|
|
OpenAPIData(apiData, dump_path, minidump_id);
|
2016-03-07 23:48:58 +03:00
|
|
|
#endif
|
2020-03-24 14:17:23 +03:00
|
|
|
WriteAnnotationsForMainProcessCrash(apiData, addrInfo, crashTime);
|
|
|
|
}
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2007-07-25 05:06:02 +04:00
|
|
|
if (!doReport) {
|
2016-10-19 13:38:56 +03:00
|
|
|
#ifdef XP_WIN
|
2014-10-08 23:25:20 +04:00
|
|
|
TerminateProcess(GetCurrentProcess(), 1);
|
2016-10-19 13:38:56 +03:00
|
|
|
#endif // XP_WIN
|
2007-07-25 05:06:09 +04:00
|
|
|
return returnValue;
|
2007-07-25 05:06:02 +04:00
|
|
|
}
|
|
|
|
|
2016-10-19 13:38:56 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID) // Android
|
2021-02-19 23:50:23 +03:00
|
|
|
returnValue =
|
|
|
|
LaunchCrashHandlerService(crashReporterPath.c_str(), minidumpPath);
|
2016-10-19 13:38:56 +03:00
|
|
|
#else // Windows, Mac, Linux, etc...
|
2021-02-19 23:50:23 +03:00
|
|
|
returnValue = LaunchProgram(crashReporterPath.c_str(), minidumpPath);
|
2016-10-19 13:38:56 +03:00
|
|
|
# ifdef XP_WIN
|
2007-07-25 05:05:54 +04:00
|
|
|
TerminateProcess(GetCurrentProcess(), 1);
|
2010-10-13 22:27:44 +04:00
|
|
|
# endif
|
2014-12-15 21:13:12 +03:00
|
|
|
#endif
|
2007-07-25 05:06:00 +04:00
|
|
|
|
2012-11-16 02:56:22 +04:00
|
|
|
return returnValue;
|
2007-07-25 05:05:55 +04:00
|
|
|
}
|
|
|
|
|
2016-10-06 14:25:13 +03:00
|
|
|
#if defined(XP_MACOSX) || defined(__ANDROID__) || defined(XP_LINUX)
|
2016-03-16 21:35:50 +03:00
|
|
|
static size_t EnsureTrailingSlash(XP_CHAR* aBuf, size_t aBufLen) {
|
2016-03-07 23:48:58 +03:00
|
|
|
size_t len = XP_STRLEN(aBuf);
|
2016-10-06 14:25:13 +03:00
|
|
|
if ((len + 1) < aBufLen && len > 0 &&
|
|
|
|
aBuf[len - 1] != XP_PATH_SEPARATOR_CHAR) {
|
2016-03-16 21:35:50 +03:00
|
|
|
aBuf[len] = XP_PATH_SEPARATOR_CHAR;
|
2016-03-07 23:48:58 +03:00
|
|
|
++len;
|
|
|
|
aBuf[len] = 0;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_WIN)
|
2016-03-07 23:48:58 +03:00
|
|
|
|
|
|
|
static size_t BuildTempPath(wchar_t* aBuf, size_t aBufLen) {
|
|
|
|
// first figure out buffer size
|
|
|
|
DWORD pathLen = GetTempPath(0, nullptr);
|
|
|
|
if (pathLen == 0 || pathLen >= aBufLen) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetTempPath(pathLen, aBuf);
|
|
|
|
}
|
|
|
|
|
2016-03-11 01:25:33 +03:00
|
|
|
static size_t BuildTempPath(char16_t* aBuf, size_t aBufLen) {
|
|
|
|
return BuildTempPath(reinterpret_cast<wchar_t*>(aBuf), aBufLen);
|
|
|
|
}
|
|
|
|
|
2016-03-07 23:48:58 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
|
|
|
|
static size_t BuildTempPath(char* aBuf, size_t aBufLen) {
|
|
|
|
if (aBufLen < PATH_MAX) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSRef fsRef;
|
|
|
|
OSErr err =
|
|
|
|
FSFindFolder(kUserDomain, kTemporaryFolderType, kCreateFolder, &fsRef);
|
|
|
|
if (err != noErr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSStatus status = FSRefMakePath(&fsRef, (UInt8*)aBuf, PATH_MAX);
|
|
|
|
if (status != noErr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EnsureTrailingSlash(aBuf, aBufLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__ANDROID__)
|
|
|
|
|
|
|
|
static size_t BuildTempPath(char* aBuf, size_t aBufLen) {
|
2017-08-12 03:45:18 +03:00
|
|
|
// GeckoAppShell sets this in the environment
|
2016-03-07 23:48:58 +03:00
|
|
|
const char* tempenv = PR_GetEnv("TMPDIR");
|
|
|
|
if (!tempenv) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-19 13:38:56 +03:00
|
|
|
size_t size = aBufLen;
|
2016-03-07 23:48:58 +03:00
|
|
|
Concat(aBuf, tempenv, &size);
|
|
|
|
return EnsureTrailingSlash(aBuf, aBufLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
|
|
|
|
static size_t BuildTempPath(char* aBuf, size_t aBufLen) {
|
2016-10-06 14:25:13 +03:00
|
|
|
const char* tempenv = PR_GetEnv("TMPDIR");
|
|
|
|
const char* tmpPath = "/tmp/";
|
|
|
|
if (!tempenv) {
|
|
|
|
tempenv = tmpPath;
|
|
|
|
}
|
2016-10-19 13:38:56 +03:00
|
|
|
size_t size = aBufLen;
|
2016-10-06 14:25:13 +03:00
|
|
|
Concat(aBuf, tempenv, &size);
|
|
|
|
return EnsureTrailingSlash(aBuf, aBufLen);
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
# error "Implement this for your platform"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <typename CharT, size_t N>
|
|
|
|
static size_t BuildTempPath(CharT (&aBuf)[N]) {
|
|
|
|
static_assert(N >= XP_PATH_MAX, "char array length is too small");
|
|
|
|
return BuildTempPath(&aBuf[0], N);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PathStringT>
|
|
|
|
static bool BuildTempPath(PathStringT& aResult) {
|
|
|
|
aResult.SetLength(XP_PATH_MAX);
|
2016-03-10 02:14:49 +03:00
|
|
|
size_t actualLen = BuildTempPath(aResult.BeginWriting(), XP_PATH_MAX);
|
2016-03-07 23:48:58 +03:00
|
|
|
if (!actualLen) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aResult.SetLength(actualLen);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
FileHandle GetAnnotationTimeCrashFd() { return gChildCrashAnnotationReportFd; }
|
|
|
|
|
2019-07-03 02:26:11 +03:00
|
|
|
static void PrepareChildExceptionTimeAnnotations(
|
2020-09-07 19:02:26 +03:00
|
|
|
const phc::AddrInfo* addrInfo) {
|
2016-03-07 23:48:58 +03:00
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
2018-02-07 22:42:47 +03:00
|
|
|
|
2016-03-07 23:48:58 +03:00
|
|
|
PlatformWriter apiData;
|
2020-09-07 19:02:26 +03:00
|
|
|
apiData.OpenHandle(GetAnnotationTimeCrashFd());
|
2019-06-18 22:19:33 +03:00
|
|
|
BinaryAnnotationWriter writer(apiData);
|
2016-03-07 23:48:58 +03:00
|
|
|
|
2019-06-18 22:19:33 +03:00
|
|
|
WriteMozCrashReason(writer);
|
2016-09-20 09:10:43 +03:00
|
|
|
|
2020-01-20 21:23:48 +03:00
|
|
|
WriteMainThreadRunnableName(writer);
|
|
|
|
|
2021-04-30 23:10:58 +03:00
|
|
|
WriteOOMAllocationSize(writer);
|
|
|
|
|
2019-07-03 02:26:11 +03:00
|
|
|
#ifdef MOZ_PHC
|
|
|
|
WritePHCAddrInfo(writer, addrInfo);
|
|
|
|
#endif
|
|
|
|
|
2017-02-07 13:57:23 +03:00
|
|
|
std::function<void(const char*)> getThreadAnnotationCB =
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
[&](const char* aValue) -> void {
|
|
|
|
if (aValue) {
|
2019-06-18 22:19:33 +03:00
|
|
|
writer.Write(Annotation::ThreadIdNameMapping, aValue);
|
2017-02-07 13:57:23 +03:00
|
|
|
}
|
|
|
|
};
|
2018-04-25 01:59:15 +03:00
|
|
|
GetFlatThreadAnnotation(getThreadAnnotationCB, true);
|
2020-04-08 09:55:40 +03:00
|
|
|
|
|
|
|
WriteAnnotations(writer, crashReporterAPIData_Table);
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
|
|
|
|
2010-01-11 21:16:20 +03:00
|
|
|
#ifdef XP_WIN
|
2020-12-01 20:26:55 +03:00
|
|
|
|
2013-04-13 17:10:28 +04:00
|
|
|
static void ReserveBreakpadVM() {
|
|
|
|
if (!gBreakpadReservedVM) {
|
2013-11-26 22:22:01 +04:00
|
|
|
gBreakpadReservedVM =
|
|
|
|
VirtualAlloc(nullptr, kReserveSize, MEM_RESERVE, PAGE_NOACCESS);
|
2013-04-13 17:10:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FreeBreakpadVM() {
|
|
|
|
if (gBreakpadReservedVM) {
|
2013-11-26 22:22:01 +04:00
|
|
|
VirtualFree(gBreakpadReservedVM, 0, MEM_RELEASE);
|
2013-04-13 17:10:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 23:08:59 +03:00
|
|
|
static bool IsCrashingException(EXCEPTION_POINTERS* exinfo) {
|
2013-04-13 17:10:28 +04:00
|
|
|
if (!exinfo) {
|
2010-05-04 23:34:55 +04:00
|
|
|
return true;
|
2013-04-13 17:10:28 +04:00
|
|
|
}
|
2010-05-04 23:34:55 +04:00
|
|
|
|
2010-01-11 21:16:20 +03: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
|
2020-04-17 23:08:59 +03:00
|
|
|
default:
|
|
|
|
return true;
|
2010-01-11 21:16:20 +03:00
|
|
|
}
|
2020-04-17 23:08:59 +03:00
|
|
|
}
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
#endif // XP_WIN
|
|
|
|
|
2020-04-17 23:08:59 +03:00
|
|
|
// Do various actions to prepare the child process for minidump generation.
|
|
|
|
// This includes disabling the I/O interposer and DLL blocklist which both
|
|
|
|
// would get in the way. We also free the address space we had reserved in
|
|
|
|
// 32-bit builds to free room for the minidump generation to do its work.
|
|
|
|
static void PrepareForMinidump() {
|
2014-04-02 21:49:56 +04:00
|
|
|
mozilla::IOInterposer::Disable();
|
2020-12-01 20:26:55 +03:00
|
|
|
#if defined(XP_WIN)
|
2019-05-18 19:19:55 +03:00
|
|
|
# if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
|
2018-08-29 21:49:49 +03:00
|
|
|
DllBlocklist_Shutdown();
|
2019-05-18 19:19:55 +03:00
|
|
|
# endif
|
2013-04-13 17:10:28 +04:00
|
|
|
FreeBreakpadVM();
|
2020-12-01 20:26:55 +03:00
|
|
|
#endif // XP_WIN
|
2020-04-17 23:08:59 +03:00
|
|
|
}
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
|
2020-04-17 23:08:59 +03:00
|
|
|
/**
|
|
|
|
* Filters out floating point exceptions which are handled by nsSigHandlers.cpp
|
|
|
|
* and should not be handled as crashes.
|
|
|
|
*/
|
2020-12-01 20:26:55 +03:00
|
|
|
static ExceptionHandler::FilterResult Filter(void* context,
|
|
|
|
EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion) {
|
2020-04-30 00:17:50 +03:00
|
|
|
if (!IsCrashingException(exinfo)) {
|
|
|
|
return ExceptionHandler::FilterResult::ContinueSearch;
|
2020-04-17 23:08:59 +03:00
|
|
|
}
|
|
|
|
|
2020-04-30 00:17:50 +03:00
|
|
|
PrepareForMinidump();
|
|
|
|
return ExceptionHandler::FilterResult::HandleException;
|
2010-01-11 21:16:20 +03:00
|
|
|
}
|
2016-03-07 23:48:58 +03:00
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
static ExceptionHandler::FilterResult ChildFilter(
|
2020-04-30 00:17:50 +03:00
|
|
|
void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion) {
|
2020-04-17 23:08:59 +03:00
|
|
|
if (!IsCrashingException(exinfo)) {
|
2020-04-30 00:17:50 +03:00
|
|
|
return ExceptionHandler::FilterResult::ContinueSearch;
|
2020-04-17 23:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gEncounteredChildException.exchange(true)) {
|
2020-04-30 00:17:50 +03:00
|
|
|
return ExceptionHandler::FilterResult::AbortWithoutMinidump;
|
2020-04-17 23:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PrepareForMinidump();
|
2020-04-30 00:17:50 +03:00
|
|
|
return ExceptionHandler::FilterResult::HandleException;
|
2020-04-08 09:55:41 +03:00
|
|
|
}
|
|
|
|
|
2017-10-12 00:33:56 +03:00
|
|
|
static MINIDUMP_TYPE GetMinidumpType() {
|
2018-09-07 19:45:49 +03:00
|
|
|
MINIDUMP_TYPE minidump_type = static_cast<MINIDUMP_TYPE>(
|
|
|
|
MiniDumpWithFullMemoryInfo | MiniDumpWithUnloadedModules);
|
2017-06-06 23:20:29 +03:00
|
|
|
|
2017-02-02 04:33:01 +03:00
|
|
|
# ifdef NIGHTLY_BUILD
|
2017-06-06 23:20:29 +03:00
|
|
|
// This is Nightly only because this doubles the size of minidumps based
|
|
|
|
// on the experimental data.
|
|
|
|
minidump_type =
|
|
|
|
static_cast<MINIDUMP_TYPE>(minidump_type | MiniDumpWithProcessThreadData);
|
2018-01-03 11:06:11 +03:00
|
|
|
|
|
|
|
// dbghelp.dll on Win7 can't handle overlapping memory regions so we only
|
|
|
|
// enable this feature on Win8 or later.
|
|
|
|
if (IsWin8OrLater()) {
|
|
|
|
minidump_type = static_cast<MINIDUMP_TYPE>(
|
|
|
|
minidump_type |
|
|
|
|
// This allows us to examine heap objects referenced from stack objects
|
|
|
|
// at the cost of further doubling the size of minidumps.
|
|
|
|
MiniDumpWithIndirectlyReferencedMemory);
|
|
|
|
}
|
2017-02-02 04:33:01 +03:00
|
|
|
# endif
|
2016-04-13 15:05:46 +03:00
|
|
|
|
|
|
|
const char* e = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
|
|
|
|
if (e && *e) {
|
|
|
|
minidump_type = MiniDumpWithFullMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
return minidump_type;
|
|
|
|
}
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
#else
|
2010-01-11 21:16:20 +03:00
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
static bool Filter(void* context) {
|
|
|
|
PrepareForMinidump();
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-26 23:03:26 +04:00
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
static bool ChildFilter(void* context) {
|
|
|
|
if (gEncounteredChildException.exchange(true)) {
|
2013-02-26 23:03:26 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
PrepareForMinidump();
|
2013-02-26 23:03:26 +04:00
|
|
|
return true;
|
2010-03-25 00:22:00 +03:00
|
|
|
}
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
#endif // !defined(XP_WIN)
|
2018-09-26 14:54:34 +03:00
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
static bool ChildMinidumpCallback(
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
const wchar_t* dump_path, const wchar_t* minidump_id,
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else // defined(XP_MACOSX)
|
|
|
|
const char* dump_dir, const char* minidump_id,
|
|
|
|
#endif
|
|
|
|
void* context,
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion,
|
|
|
|
#endif // defined(XP_WIN)
|
|
|
|
const mozilla::phc::AddrInfo* addr_info, bool succeeded) {
|
|
|
|
|
|
|
|
PrepareChildExceptionTimeAnnotations(addr_info);
|
|
|
|
return succeeded;
|
2012-07-03 17:15:34 +04:00
|
|
|
}
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
static bool ShouldReport() {
|
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
|
|
|
const char* envvar = PR_GetEnv("MOZ_CRASHREPORTER_NO_REPORT");
|
|
|
|
if (envvar && *envvar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
envvar = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
|
|
|
|
if (envvar && *envvar) {
|
2020-04-17 23:08:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-01 00:54:03 +03:00
|
|
|
return true;
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
2012-07-03 17:15:34 +04:00
|
|
|
|
2017-01-29 10:53:50 +03:00
|
|
|
static void TerminateHandler() { MOZ_CRASH("Unhandled exception"); }
|
|
|
|
|
2016-10-19 13:51:29 +03:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
|
|
|
|
// Locate the specified executable and store its path as a native string in
|
|
|
|
// the |aPathPtr| so we can later invoke it from within the exception handler.
|
|
|
|
static nsresult LocateExecutable(nsIFile* aXREDirectory,
|
|
|
|
const nsACString& aName, nsAString& aPath) {
|
|
|
|
nsCOMPtr<nsIFile> exePath;
|
|
|
|
nsresult rv = aXREDirectory->Clone(getter_AddRefs(exePath));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
# ifdef XP_MACOSX
|
|
|
|
exePath->SetNativeLeafName("MacOS"_ns);
|
|
|
|
exePath->Append(u"crashreporter.app"_ns);
|
|
|
|
exePath->Append(u"Contents"_ns);
|
|
|
|
exePath->Append(u"MacOS"_ns);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
exePath->AppendNative(aName);
|
|
|
|
exePath->GetPath(aPath);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
|
|
|
|
DWORD WINAPI FlushContentProcessAnnotationsThreadFunc(LPVOID aContext) {
|
|
|
|
PrepareChildExceptionTimeAnnotations(nullptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static const int kAnnotationSignal = SIGUSR2;
|
|
|
|
|
|
|
|
static void AnnotationSignalHandler(int aSignal, siginfo_t* aInfo,
|
|
|
|
void* aContext) {
|
|
|
|
PrepareChildExceptionTimeAnnotations(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(XP_WIN)
|
|
|
|
|
|
|
|
static void InitChildAnnotationsFlusher() {
|
|
|
|
#if !defined(XP_WIN)
|
|
|
|
struct sigaction oldSigAction = {};
|
|
|
|
struct sigaction sigAction = {};
|
|
|
|
sigAction.sa_sigaction = AnnotationSignalHandler;
|
|
|
|
sigAction.sa_flags = SA_RESTART | SA_SIGINFO;
|
|
|
|
sigemptyset(&sigAction.sa_mask);
|
|
|
|
mozilla::DebugOnly<int> rv =
|
|
|
|
sigaction(kAnnotationSignal, &sigAction, &oldSigAction);
|
|
|
|
MOZ_ASSERT(rv == 0, "Failed to install the crash reporter's SIGUSR2 handler");
|
|
|
|
MOZ_ASSERT(oldSigAction.sa_sigaction == nullptr,
|
|
|
|
"A SIGUSR2 handler was already present");
|
|
|
|
#endif // !defined(XP_WIN)
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool FlushContentProcessAnnotations(ProcessHandle aTargetPid) {
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
nsAutoHandle hThread(CreateRemoteThread(
|
|
|
|
aTargetPid, nullptr, 0, FlushContentProcessAnnotationsThreadFunc, nullptr,
|
|
|
|
0, nullptr));
|
|
|
|
return !!hThread;
|
|
|
|
#else // POSIX platforms
|
|
|
|
return kill(aTargetPid, kAnnotationSignal) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-08 09:55:40 +03:00
|
|
|
static void InitializeAnnotationFacilities() {
|
|
|
|
crashReporterAPILock = new Mutex("crashReporterAPILock");
|
|
|
|
notesFieldLock = new Mutex("notesFieldLock");
|
|
|
|
notesField = new nsCString();
|
|
|
|
InitThreadAnnotation();
|
2020-09-07 19:02:26 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
InitChildAnnotationsFlusher();
|
|
|
|
}
|
2020-04-08 09:55:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TeardownAnnotationFacilities() {
|
|
|
|
std::fill(crashReporterAPIData_Table.begin(),
|
2020-09-23 18:17:15 +03:00
|
|
|
crashReporterAPIData_Table.end(), ""_ns);
|
2020-04-08 09:55:40 +03:00
|
|
|
|
|
|
|
delete crashReporterAPILock;
|
|
|
|
crashReporterAPILock = nullptr;
|
|
|
|
|
|
|
|
delete notesFieldLock;
|
|
|
|
notesFieldLock = nullptr;
|
|
|
|
|
|
|
|
delete notesField;
|
|
|
|
notesField = nullptr;
|
|
|
|
|
|
|
|
ShutdownThreadAnnotation();
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:55:23 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
|
2021-06-11 12:59:49 +03:00
|
|
|
struct InProcessWindowsErrorReportingData {
|
|
|
|
uint32_t mProcessType;
|
2021-06-11 12:59:51 +03:00
|
|
|
size_t* mOOMAllocationSizePtr;
|
2021-06-11 12:59:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static InProcessWindowsErrorReportingData gInProcessWerData = {};
|
|
|
|
|
2021-04-07 10:55:23 +03:00
|
|
|
bool GetRuntimeExceptionModulePath(wchar_t* aPath, const size_t aLength) {
|
|
|
|
const wchar_t* kModuleName = L"mozwer.dll";
|
|
|
|
DWORD res = GetModuleFileName(nullptr, aPath, aLength);
|
|
|
|
if ((res > 0) && (res != aLength)) {
|
|
|
|
wchar_t* last_backslash = wcsrchr(aPath, L'\\');
|
|
|
|
if (last_backslash) {
|
|
|
|
*(last_backslash + 1) = L'\0';
|
|
|
|
if (wcscat_s(aPath, aLength, kModuleName) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // XP_WIN
|
|
|
|
|
2021-06-11 12:59:49 +03:00
|
|
|
static void RegisterRuntimeExceptionModule(
|
|
|
|
GeckoProcessType aProcessType =
|
|
|
|
GeckoProcessType::GeckoProcessType_Default) {
|
2021-04-07 10:55:23 +03:00
|
|
|
#ifdef XP_WIN
|
2021-06-11 12:59:49 +03:00
|
|
|
gInProcessWerData.mProcessType = aProcessType;
|
2021-06-11 12:59:51 +03:00
|
|
|
gInProcessWerData.mOOMAllocationSizePtr = &gOOMAllocationSize;
|
2021-04-07 10:55:23 +03:00
|
|
|
const size_t kPathLength = MAX_PATH + 1;
|
|
|
|
wchar_t path[kPathLength] = {};
|
|
|
|
if (GetRuntimeExceptionModulePath(path, kPathLength)) {
|
2021-06-11 12:59:49 +03:00
|
|
|
Unused << WerRegisterRuntimeExceptionModule(path, &gInProcessWerData);
|
2021-05-07 12:07:47 +03:00
|
|
|
|
2021-06-11 12:59:49 +03:00
|
|
|
DWORD dwFlags = 0;
|
|
|
|
if (WerGetFlags(GetCurrentProcess(), &dwFlags) == S_OK) {
|
|
|
|
Unused << WerSetFlags(dwFlags |
|
|
|
|
WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG);
|
|
|
|
}
|
2021-04-07 10:55:23 +03:00
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult SetExceptionHandler(nsIFile* aXREDirectory, bool force /*=false*/) {
|
2007-07-25 05:05:54 +04:00
|
|
|
if (gExceptionHandler) return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
2019-01-10 01:39:22 +03:00
|
|
|
#if defined(DEBUG)
|
2013-08-30 06:10:57 +04: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;
|
2018-12-14 17:50:30 +03:00
|
|
|
#else
|
|
|
|
// In other builds, enable the crash reporter by default, and allow
|
|
|
|
// disabling it with the MOZ_CRASHREPORTER_DISABLE environment variable.
|
|
|
|
const char* envvar = PR_GetEnv("MOZ_CRASHREPORTER_DISABLE");
|
|
|
|
if (envvar && *envvar && !force) return NS_OK;
|
2013-08-30 06:10:57 +04:00
|
|
|
#endif
|
2007-07-25 05:06:10 +04:00
|
|
|
|
2007-07-25 05:06:02 +04:00
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
2010-03-25 00:22:00 +03:00
|
|
|
doReport = ShouldReport();
|
2007-07-25 05:06:02 +04:00
|
|
|
|
2021-04-07 10:55:23 +03:00
|
|
|
RegisterRuntimeExceptionModule();
|
2020-04-08 09:55:40 +03:00
|
|
|
InitializeAnnotationFacilities();
|
2008-07-27 21:08:03 +04:00
|
|
|
|
2016-10-19 13:51:29 +03:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
2017-11-08 06:49:37 +03:00
|
|
|
// Locate the crash reporter executable
|
|
|
|
nsAutoString crashReporterPath_temp;
|
|
|
|
nsresult rv =
|
|
|
|
LocateExecutable(aXREDirectory, nsLiteralCString(CRASH_REPORTER_FILENAME),
|
|
|
|
crashReporterPath_temp);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-07-25 05:06:06 +04:00
|
|
|
|
2017-02-16 09:36:57 +03:00
|
|
|
# ifdef XP_MACOSX
|
2017-11-08 06:49:37 +03:00
|
|
|
nsCOMPtr<nsIFile> libPath;
|
|
|
|
rv = aXREDirectory->Clone(getter_AddRefs(libPath));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-02-16 09:36:57 +03:00
|
|
|
|
2017-11-08 06:49:37 +03:00
|
|
|
nsAutoString libraryPath_temp;
|
|
|
|
rv = libPath->GetPath(libraryPath_temp);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-02-16 09:36:57 +03:00
|
|
|
# endif // XP_MACOSX
|
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
# ifdef XP_WIN
|
2021-02-19 23:50:23 +03:00
|
|
|
crashReporterPath = xpstring(crashReporterPath_temp.get());
|
2016-10-19 13:51:29 +03:00
|
|
|
# else
|
2021-02-19 23:50:23 +03:00
|
|
|
crashReporterPath =
|
|
|
|
xpstring(NS_ConvertUTF16toUTF8(crashReporterPath_temp).get());
|
2017-02-16 09:36:57 +03:00
|
|
|
# ifdef XP_MACOSX
|
2021-02-19 23:50:23 +03:00
|
|
|
libraryPath = xpstring(NS_ConvertUTF16toUTF8(libraryPath_temp).get());
|
2017-02-16 09:36:57 +03:00
|
|
|
# endif
|
2019-03-21 04:28:50 +03:00
|
|
|
# endif // XP_WIN
|
2010-10-13 22:27:44 +04:00
|
|
|
#else
|
2018-08-22 20:45:56 +03:00
|
|
|
// On Android, we launch a service defined via MOZ_ANDROID_CRASH_HANDLER
|
|
|
|
const char* androidCrashHandler = PR_GetEnv("MOZ_ANDROID_CRASH_HANDLER");
|
|
|
|
if (androidCrashHandler) {
|
2021-02-19 23:50:23 +03:00
|
|
|
crashReporterPath = xpstring(androidCrashHandler);
|
2017-11-08 06:49:37 +03:00
|
|
|
} else {
|
2018-08-22 20:45:56 +03:00
|
|
|
NS_WARNING("No Android crash handler set");
|
2012-07-17 03:50:52 +04:00
|
|
|
}
|
2018-07-02 17:32:10 +03:00
|
|
|
|
|
|
|
const char* deviceAndroidVersion =
|
|
|
|
PR_GetEnv("MOZ_ANDROID_DEVICE_SDK_VERSION");
|
|
|
|
if (deviceAndroidVersion != nullptr) {
|
|
|
|
const int deviceSdkVersion = atol(deviceAndroidVersion);
|
|
|
|
if (deviceSdkVersion >= 26) {
|
|
|
|
androidStartServiceCommand = (char*)"start-foreground-service";
|
|
|
|
} else {
|
|
|
|
androidStartServiceCommand = (char*)"startservice";
|
|
|
|
}
|
|
|
|
}
|
2017-11-08 06:49:37 +03:00
|
|
|
#endif // !defined(MOZ_WIDGET_ANDROID)
|
2007-07-25 05:05:54 +04:00
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
// get temp path to use for minidump path
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_WIN)
|
2007-09-15 17:39:05 +04:00
|
|
|
nsString tempPath;
|
2007-07-25 05:06:00 +04:00
|
|
|
#else
|
2016-03-07 23:48:58 +03:00
|
|
|
nsCString tempPath;
|
2007-07-25 05:06:00 +04:00
|
|
|
#endif
|
2016-03-07 23:48:58 +03:00
|
|
|
if (!BuildTempPath(tempPath)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2013-04-13 17:10:28 +04:00
|
|
|
ReserveBreakpadVM();
|
2018-09-20 12:53:26 +03:00
|
|
|
|
|
|
|
// Pre-load psapi.dll to prevent it from being loaded during exception
|
|
|
|
// handling.
|
|
|
|
::LoadLibraryW(L"psapi.dll");
|
2019-03-21 04:28:50 +03:00
|
|
|
#endif // XP_WIN
|
2011-01-12 22:13:52 +03:00
|
|
|
|
2012-11-16 02:56:22 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
androidUserSerial = getenv("MOZ_ANDROID_USER_SERIAL_NUMBER");
|
|
|
|
#endif
|
|
|
|
|
2014-01-15 19:03:14 +04:00
|
|
|
// Initialize the flag and mutex used to avoid dump processing
|
|
|
|
// once browser termination has begun.
|
|
|
|
NS_ASSERTION(!dumpSafetyLock, "Shouldn't have a lock yet");
|
|
|
|
// Do not deallocate this lock while it is still possible for
|
|
|
|
// isSafeToDump to be tested on another thread.
|
|
|
|
dumpSafetyLock = new Mutex("dumpSafetyLock");
|
|
|
|
MutexAutoLock lock(*dumpSafetyLock);
|
|
|
|
isSafeToDump = true;
|
|
|
|
|
2007-07-25 05:06:03 +04:00
|
|
|
// now set the exception handler
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
MinidumpDescriptor descriptor(tempPath.get());
|
|
|
|
#endif
|
|
|
|
|
2014-01-30 02:07:35 +04:00
|
|
|
#ifdef XP_WIN
|
2014-10-08 23:25:20 +04:00
|
|
|
previousUnhandledExceptionFilter = GetUnhandledExceptionFilter();
|
2014-01-30 02:07:35 +04:00
|
|
|
#endif
|
|
|
|
|
2007-07-25 05:06:00 +04:00
|
|
|
gExceptionHandler = new google_breakpad::ExceptionHandler(
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
descriptor,
|
2015-08-21 10:01:47 +03:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
std::wstring(tempPath.get()),
|
2012-09-25 15:52:54 +04:00
|
|
|
#else
|
|
|
|
tempPath.get(),
|
|
|
|
#endif
|
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
Filter, MinidumpCallback, nullptr,
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2011-01-12 22:13:52 +03:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL, GetMinidumpType(),
|
2013-10-11 00:39:09 +04:00
|
|
|
(const wchar_t*)nullptr, nullptr);
|
2007-07-25 05:06:13 +04:00
|
|
|
#else
|
2010-08-16 23:05:09 +04:00
|
|
|
true
|
2012-09-25 15:52:54 +04:00
|
|
|
# ifdef XP_MACOSX
|
2013-10-11 00:39:09 +04:00
|
|
|
,
|
|
|
|
nullptr
|
2012-09-25 15:52:54 +04:00
|
|
|
# endif
|
|
|
|
# ifdef XP_LINUX
|
|
|
|
,
|
|
|
|
-1
|
2010-08-16 23:05:09 +04:00
|
|
|
# endif
|
|
|
|
);
|
2019-03-21 04:28:50 +03:00
|
|
|
#endif // XP_WIN
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2007-07-25 05:05:54 +04:00
|
|
|
if (!gExceptionHandler) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2011-01-12 01:01:22 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
gExceptionHandler->set_handle_debug_exceptions(true);
|
2016-05-17 23:53:15 +03:00
|
|
|
|
2017-06-20 10:00:32 +03:00
|
|
|
// Initially set sIncludeContextHeap to true for debugging startup crashes
|
|
|
|
// even if the controlling pref value is false.
|
|
|
|
SetIncludeContextHeap(true);
|
2019-01-14 17:06:24 +03:00
|
|
|
# if defined(HAVE_64BIT_BUILD)
|
2014-10-08 23:25:20 +04:00
|
|
|
// Tell JS about the new filter before we disable SetUnhandledExceptionFilter
|
2017-04-22 03:25:19 +03:00
|
|
|
SetJitExceptionHandler();
|
2014-10-08 23:25:20 +04:00
|
|
|
# endif
|
|
|
|
|
2012-04-20 13:07:55 +04:00
|
|
|
// protect the crash reporter from being unloaded
|
2012-09-25 15:52:54 +04:00
|
|
|
gBlockUnhandledExceptionFilter = true;
|
2012-04-20 13:07:55 +04:00
|
|
|
gKernel32Intercept.Init("kernel32.dll");
|
2018-09-26 14:54:34 +03:00
|
|
|
DebugOnly<bool> ok = stub_SetUnhandledExceptionFilter.Set(
|
|
|
|
gKernel32Intercept, "SetUnhandledExceptionFilter",
|
|
|
|
&patched_SetUnhandledExceptionFilter);
|
2012-04-20 13:07:55 +04:00
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
if (!ok)
|
|
|
|
printf_stderr(
|
|
|
|
"SetUnhandledExceptionFilter hook failed; crash reporter is "
|
|
|
|
"vulnerable.\n");
|
|
|
|
# endif
|
2011-01-12 01:01:22 +03:00
|
|
|
#endif
|
|
|
|
|
2007-12-22 00:49:32 +03:00
|
|
|
// store application start time
|
|
|
|
char timeString[32];
|
2013-10-11 00:39:09 +04:00
|
|
|
time_t startupTime = time(nullptr);
|
2019-06-05 09:43:19 +03:00
|
|
|
XP_TTOA(startupTime, timeString);
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
AnnotateCrashReport(Annotation::StartupTime, nsDependentCString(timeString));
|
2007-12-22 00:49:32 +03:00
|
|
|
|
2007-07-25 05:06:09 +04:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// On OS X, many testers like to see the OS crash reporting dialog
|
|
|
|
// since it offers immediate stack traces. We allow them to set
|
|
|
|
// a default to pass exceptions to the OS handler.
|
2010-06-21 06:07:59 +04:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(
|
|
|
|
CFSTR("OSCrashReporter"), kCFPreferencesCurrentApplication,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat) showOSCrashReporter = prefValue;
|
2007-07-25 05:06:09 +04:00
|
|
|
#endif
|
|
|
|
|
2017-01-29 10:53:50 +03:00
|
|
|
oldTerminateHandler = std::set_terminate(&TerminateHandler);
|
|
|
|
|
2007-07-25 05:05:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
bool GetEnabled() { return gExceptionHandler != nullptr; }
|
2009-04-02 19:41:12 +04:00
|
|
|
|
|
|
|
bool GetMinidumpPath(nsAString& aPath) {
|
|
|
|
if (!gExceptionHandler) return false;
|
|
|
|
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifndef XP_LINUX
|
2009-04-02 19:41:12 +04:00
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(gExceptionHandler->dump_path().c_str());
|
2012-09-25 15:52:54 +04:00
|
|
|
#else
|
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(
|
|
|
|
gExceptionHandler->minidump_descriptor().directory().c_str());
|
|
|
|
#endif
|
2009-04-02 19:41:12 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
nsresult SetMinidumpPath(const nsAString& aPath) {
|
2007-07-25 05:05:54 +04:00
|
|
|
if (!gExceptionHandler) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2015-08-21 10:01:47 +03:00
|
|
|
gExceptionHandler->set_dump_path(
|
|
|
|
std::wstring(char16ptr_t(aPath.BeginReading())));
|
2013-12-05 13:52:54 +04:00
|
|
|
#elif defined(XP_LINUX)
|
2012-09-25 15:52:54 +04:00
|
|
|
gExceptionHandler->set_minidump_descriptor(
|
2013-12-05 13:52:54 +04:00
|
|
|
MinidumpDescriptor(NS_ConvertUTF16toUTF8(aPath).BeginReading()));
|
|
|
|
#else
|
|
|
|
gExceptionHandler->set_dump_path(NS_ConvertUTF16toUTF8(aPath).BeginReading());
|
2012-09-25 15:52:54 +04:00
|
|
|
#endif
|
2007-07-25 05:05:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:14 +04:00
|
|
|
static nsresult WriteDataToFile(nsIFile* aFile, const nsACString& data) {
|
2007-09-15 17:39:05 +04:00
|
|
|
PRFileDesc* fd;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 00600, &fd);
|
2007-09-15 17:39:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-25 05:06:14 +04: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 17:39:05 +04:00
|
|
|
PRFileDesc* fd;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
|
2007-09-15 17:39:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-25 05:06:14 +04:00
|
|
|
|
|
|
|
rv = NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t filesize = PR_Available(fd);
|
2007-07-25 05:06:14 +04: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-15 17:39:05 +04:00
|
|
|
static nsresult GetOrInit(nsIFile* aDir, const nsACString& filename,
|
2007-07-25 05:06:15 +04:00
|
|
|
nsACString& aContents, InitDataFunc aInitFunc) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2007-07-25 05:06:15 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> dataFile;
|
|
|
|
nsresult rv = aDir->Clone(getter_AddRefs(dataFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 17:39:05 +04:00
|
|
|
rv = dataFile->AppendNative(filename);
|
2007-07-25 05:06:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = dataFile->Exists(&exists);
|
2007-07-25 05:06:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists) {
|
2007-08-29 23:46:00 +04:00
|
|
|
if (aInitFunc) {
|
|
|
|
// get the initial value and write it to the file
|
|
|
|
rv = aInitFunc(aContents);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = WriteDataToFile(dataFile, aContents);
|
|
|
|
} else {
|
|
|
|
// didn't pass in an init func
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-07-25 05:06:15 +04:00
|
|
|
} else {
|
|
|
|
// just get the file's contents
|
|
|
|
rv = GetFileContents(dataFile, aContents);
|
2007-07-25 05:06:14 +04:00
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:15 +04:00
|
|
|
return rv;
|
2007-07-25 05:06:14 +04:00
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:15 +04: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-11 00:39:09 +04:00
|
|
|
time_t t = time(nullptr);
|
2021-04-07 10:55:23 +03:00
|
|
|
aInstallTime = nsPrintfCString("%" PRIu64, static_cast<uint64_t>(t));
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2007-07-25 05:06:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-19 03:58:03 +04: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 23:48:40 +04:00
|
|
|
return rv;
|
2014-02-19 03:58:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-27 13:38:39 +03:00
|
|
|
// Creates a directory that will be accessible by the crash reporter. The
|
|
|
|
// directory will live under Firefox default data directory and will use the
|
|
|
|
// specified name. The directory path will be passed to the crashreporter via
|
|
|
|
// the specified environment variable.
|
|
|
|
static nsresult SetupCrashReporterDirectory(nsIFile* aAppDataDirectory,
|
|
|
|
const char* aDirName,
|
|
|
|
const XP_CHAR* aEnvVarName,
|
|
|
|
nsIFile** aDirectory = nullptr) {
|
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
nsresult rv = aAppDataDirectory->Clone(getter_AddRefs(directory));
|
2007-08-29 23:46:00 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-03-27 13:38:39 +03:00
|
|
|
rv = directory->AppendNative(nsDependentCString(aDirName));
|
2007-07-25 05:06:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-03-27 13:38:39 +03:00
|
|
|
EnsureDirectoryExists(directory);
|
|
|
|
xpstring* directoryPath = CreatePathFromFile(directory);
|
|
|
|
|
|
|
|
if (!directoryPath) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_WIN)
|
2018-02-26 17:00:58 +03:00
|
|
|
SetEnvironmentVariableW(aEnvVarName, directoryPath->c_str());
|
2007-09-26 22:35:21 +04:00
|
|
|
#else
|
2018-02-26 17:00:58 +03:00
|
|
|
setenv(aEnvVarName, directoryPath->c_str(), /* overwrite */ 1);
|
2017-03-27 13:38:39 +03:00
|
|
|
#endif
|
2008-06-25 00:15:35 +04:00
|
|
|
|
2018-02-26 17:00:58 +03:00
|
|
|
delete directoryPath;
|
|
|
|
|
2017-03-27 13:38:39 +03:00
|
|
|
if (aDirectory) {
|
|
|
|
directory.forget(aDirectory);
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2017-03-27 13:38:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2017-03-27 13:38:39 +03: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.
|
|
|
|
// If any piece of data doesn't exist, initialize it first.
|
2017-10-12 00:33:56 +03:00
|
|
|
nsresult SetupExtraData(nsIFile* aAppDataDirectory,
|
|
|
|
const nsACString& aBuildID) {
|
2017-03-27 13:38:39 +03:00
|
|
|
nsCOMPtr<nsIFile> dataDirectory;
|
|
|
|
nsresult rv =
|
|
|
|
SetupCrashReporterDirectory(aAppDataDirectory, "Crash Reports",
|
|
|
|
XP_TEXT("MOZ_CRASHREPORTER_DATA_DIRECTORY"),
|
|
|
|
getter_AddRefs(dataDirectory));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2017-03-27 13:38:39 +03:00
|
|
|
rv = SetupCrashReporterDirectory(aAppDataDirectory, "Pending Pings",
|
|
|
|
XP_TEXT("MOZ_CRASHREPORTER_PING_DIRECTORY"));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString data;
|
2007-08-29 23:46:00 +04:00
|
|
|
if (NS_SUCCEEDED(GetOrInit(dataDirectory, "InstallTime"_ns + aBuildID, data,
|
2007-07-25 05:06:15 +04:00
|
|
|
InitInstallTime)))
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
AnnotateCrashReport(Annotation::InstallTime, data);
|
2007-07-25 05:06:15 +04:00
|
|
|
|
2007-08-29 23:46:00 +04: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 17:39:05 +04:00
|
|
|
if (NS_SUCCEEDED(GetOrInit(dataDirectory, "LastCrash"_ns, data, nullptr))) {
|
2007-08-29 23:46:00 +04: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 17:39:05 +04:00
|
|
|
rv = lastCrashFile->AppendNative("LastCrash"_ns);
|
2007-08-29 23:46:00 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
memset(lastCrashTimeFilename, 0, sizeof(lastCrashTimeFilename));
|
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_WIN)
|
2007-08-29 23:46:00 +04:00
|
|
|
nsAutoString filename;
|
|
|
|
rv = lastCrashFile->GetPath(filename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (filename.Length() < XP_PATH_MAX)
|
|
|
|
wcsncpy(lastCrashTimeFilename, filename.get(), filename.Length());
|
|
|
|
#else
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString filename;
|
2007-08-29 23:46:00 +04:00
|
|
|
rv = lastCrashFile->GetNativePath(filename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (filename.Length() < XP_PATH_MAX)
|
|
|
|
strncpy(lastCrashTimeFilename, filename.get(), filename.Length());
|
|
|
|
#endif
|
|
|
|
|
2007-07-25 05:06:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-21 05:17:40 +03:00
|
|
|
static void OOPDeinit();
|
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
nsresult UnsetExceptionHandler() {
|
2014-01-15 19:03:14 +04:00
|
|
|
if (isSafeToDump) {
|
|
|
|
MutexAutoLock lock(*dumpSafetyLock);
|
|
|
|
isSafeToDump = false;
|
|
|
|
}
|
|
|
|
|
2012-04-20 13:07:55 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// allow SetUnhandledExceptionFilter
|
|
|
|
gBlockUnhandledExceptionFilter = false;
|
|
|
|
#endif
|
|
|
|
|
2009-07-23 19:23:19 +04:00
|
|
|
delete gExceptionHandler;
|
|
|
|
|
2020-04-08 09:55:40 +03:00
|
|
|
TeardownAnnotationFacilities();
|
2008-07-27 21:08:03 +04:00
|
|
|
|
2007-07-25 05:05:54 +04:00
|
|
|
if (!gExceptionHandler) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gExceptionHandler = nullptr;
|
2007-07-25 05:05:55 +04:00
|
|
|
|
2010-01-21 05:17:40 +03:00
|
|
|
OOPDeinit();
|
|
|
|
|
2014-01-15 19:03:14 +04:00
|
|
|
delete dumpSafetyLock;
|
|
|
|
dumpSafetyLock = nullptr;
|
|
|
|
|
2017-01-29 10:53:50 +03:00
|
|
|
std::set_terminate(oldTerminateHandler);
|
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
nsresult AnnotateCrashReport(Annotation key, bool data) {
|
|
|
|
return AnnotateCrashReport(key, data ? "1"_ns : "0"_ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AnnotateCrashReport(Annotation key, int data) {
|
|
|
|
nsAutoCString dataString;
|
|
|
|
dataString.AppendInt(data);
|
|
|
|
|
|
|
|
return AnnotateCrashReport(key, dataString);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AnnotateCrashReport(Annotation key, unsigned int data) {
|
|
|
|
nsAutoCString dataString;
|
|
|
|
dataString.AppendInt(data);
|
|
|
|
|
|
|
|
return AnnotateCrashReport(key, dataString);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AnnotateCrashReport(Annotation key, const nsACString& data) {
|
2011-06-09 00:21:03 +04:00
|
|
|
if (!GetEnabled()) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2011-10-07 00:33:21 +04:00
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
2019-12-02 16:18:35 +03:00
|
|
|
crashReporterAPIData_Table[key] = data;
|
2007-07-25 05:05:59 +04:00
|
|
|
|
2007-07-25 05:05:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-07-25 05:05:55 +04:00
|
|
|
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
nsresult RemoveCrashReportAnnotation(Annotation key) {
|
2020-09-23 18:17:15 +03:00
|
|
|
return AnnotateCrashReport(key, ""_ns);
|
2014-10-28 19:08:46 +03:00
|
|
|
}
|
|
|
|
|
2020-07-06 16:26:51 +03:00
|
|
|
AutoAnnotateCrashReport::AutoAnnotateCrashReport(Annotation key, bool data)
|
|
|
|
: AutoAnnotateCrashReport(key, data ? "1"_ns : "0"_ns) {}
|
|
|
|
|
|
|
|
AutoAnnotateCrashReport::AutoAnnotateCrashReport(Annotation key, int data)
|
|
|
|
: AutoAnnotateCrashReport(key, nsPrintfCString("%d", data)) {}
|
|
|
|
|
|
|
|
AutoAnnotateCrashReport::AutoAnnotateCrashReport(Annotation key, unsigned data)
|
|
|
|
: AutoAnnotateCrashReport(key, nsPrintfCString("%u", data)) {}
|
|
|
|
|
|
|
|
AutoAnnotateCrashReport::AutoAnnotateCrashReport(Annotation key,
|
|
|
|
const nsACString& data)
|
|
|
|
: mKey(key) {
|
|
|
|
if (GetEnabled()) {
|
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
|
|
|
auto& entry = crashReporterAPIData_Table[mKey];
|
|
|
|
mPrevious = std::move(entry);
|
|
|
|
entry = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoAnnotateCrashReport::~AutoAnnotateCrashReport() {
|
|
|
|
if (GetEnabled()) {
|
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
|
|
|
crashReporterAPIData_Table[mKey] = std::move(mPrevious);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
void MergeCrashAnnotations(AnnotationTable& aDst, const AnnotationTable& aSrc) {
|
|
|
|
for (auto key : MakeEnumeratedRange(Annotation::Count)) {
|
|
|
|
const nsCString& value = aSrc[key];
|
2020-04-09 01:59:15 +03:00
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
aDst[key] = value;
|
2019-05-18 19:19:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 09:55:40 +03:00
|
|
|
static void MergeContentCrashAnnotations(AnnotationTable& aDst) {
|
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
2020-04-09 01:59:15 +03:00
|
|
|
MergeCrashAnnotations(aDst, crashReporterAPIData_Table);
|
2019-05-18 19:19:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adds crash time, uptime and memory report annotations
|
|
|
|
static void AddCommonAnnotations(AnnotationTable& aAnnotations) {
|
2021-10-05 07:41:53 +03:00
|
|
|
const time_t crashTime = time(nullptr);
|
|
|
|
nsAutoCString crashTimeStr;
|
|
|
|
crashTimeStr.AppendInt(static_cast<uint64_t>(crashTime));
|
|
|
|
aAnnotations[Annotation::CrashTime] = crashTimeStr;
|
|
|
|
|
|
|
|
if (inactiveStateStart) {
|
|
|
|
nsAutoCString inactiveDuration;
|
|
|
|
inactiveDuration.AppendInt(
|
|
|
|
static_cast<uint64_t>(crashTime - inactiveStateStart));
|
|
|
|
aAnnotations[Annotation::LastInteractionDuration] = inactiveDuration;
|
|
|
|
}
|
2019-05-18 19:19:55 +03:00
|
|
|
|
|
|
|
double uptimeTS = (TimeStamp::NowLoRes() - TimeStamp::ProcessCreation())
|
|
|
|
.ToSecondsSigDigits();
|
|
|
|
nsAutoCString uptimeStr;
|
|
|
|
uptimeStr.AppendFloat(uptimeTS);
|
|
|
|
aAnnotations[Annotation::UptimeTS] = uptimeStr;
|
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
if (!memoryReportPath.empty()) {
|
2019-05-18 19:19:55 +03:00
|
|
|
aAnnotations[Annotation::ContainsMemoryReport] = "1"_ns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 21:47:51 +04:00
|
|
|
nsresult SetGarbageCollecting(bool collecting) {
|
|
|
|
if (!GetEnabled()) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
isGarbageCollecting = collecting;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:51:09 +04:00
|
|
|
void SetEventloopNestingLevel(uint32_t level) { eventloopNestingLevel = level; }
|
|
|
|
|
2021-10-05 07:41:53 +03:00
|
|
|
void ClearInactiveStateStart() { inactiveStateStart = 0; }
|
|
|
|
void SetInactiveStateStart() {
|
|
|
|
if (!inactiveStateStart) {
|
|
|
|
inactiveStateStart = GetCurrentTimeForCrashTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-18 01:02:18 +03:00
|
|
|
void SetMinidumpAnalysisAllThreads() {
|
2018-02-26 17:00:58 +03:00
|
|
|
char* env = strdup("MOZ_CRASHREPORTER_DUMP_ALL_THREADS=1");
|
|
|
|
PR_SetEnv(env);
|
2017-10-18 01:02:18 +03:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:08:03 +04:00
|
|
|
nsresult AppendAppNotesToCrashReport(const nsACString& data) {
|
|
|
|
if (!GetEnabled()) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2012-01-25 18:43:52 +04:00
|
|
|
MutexAutoLock lock(*notesFieldLock);
|
|
|
|
|
2008-07-27 21:08:03 +04:00
|
|
|
notesField->Append(data);
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
return AnnotateCrashReport(Annotation::Notes, *notesField);
|
2008-07-27 21:08:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if found, false if not found.
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
static bool GetAnnotation(CrashReporter::Annotation key, nsACString& data) {
|
2008-07-27 21:08:03 +04:00
|
|
|
if (!gExceptionHandler) return false;
|
|
|
|
|
2018-06-09 02:31:14 +03:00
|
|
|
MutexAutoLock lock(*crashReporterAPILock);
|
2019-05-18 19:19:55 +03:00
|
|
|
const nsCString& entry = crashReporterAPIData_Table[key];
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
if (entry.IsEmpty()) {
|
2008-07-27 21:08:03 +04:00
|
|
|
return false;
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
}
|
2008-07-27 21:08:03 +04:00
|
|
|
|
|
|
|
data = entry;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-08 04:31:01 +04:00
|
|
|
nsresult RegisterAppMemory(void* ptr, size_t length) {
|
|
|
|
if (!GetEnabled()) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_LINUX) || defined(XP_WIN)
|
2011-07-08 04:31:01 +04:00
|
|
|
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;
|
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_LINUX) || defined(XP_WIN)
|
2011-07-08 04:31:01 +04:00
|
|
|
gExceptionHandler->UnregisterAppMemory(ptr);
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-06-20 10:00:32 +03:00
|
|
|
void SetIncludeContextHeap(bool aValue) {
|
|
|
|
sIncludeContextHeap = aValue;
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (gExceptionHandler) {
|
|
|
|
gExceptionHandler->set_include_context_heap(sIncludeContextHeap);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-04-02 19:41:12 +04:00
|
|
|
bool GetServerURL(nsACString& aServerURL) {
|
|
|
|
if (!gExceptionHandler) return false;
|
|
|
|
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
return GetAnnotation(CrashReporter::Annotation::ServerURL, aServerURL);
|
2009-04-02 19:41:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetServerURL(const nsACString& aServerURL) {
|
|
|
|
// store server URL with the API data
|
|
|
|
// the client knows to handle this specially
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
return AnnotateCrashReport(Annotation::ServerURL, aServerURL);
|
2009-04-02 19:41:12 +04:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:08:03 +04:00
|
|
|
nsresult SetRestartArgs(int argc, char** argv) {
|
2007-07-25 05:06:10 +04:00
|
|
|
if (!gExceptionHandler) return NS_OK;
|
|
|
|
|
2007-07-25 05:06:05 +04:00
|
|
|
int i;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString envVar;
|
2007-07-25 05:06:06 +04:00
|
|
|
char* env;
|
2012-06-20 19:41:34 +04:00
|
|
|
char* argv0 = getenv("MOZ_APP_LAUNCHER");
|
2007-07-25 05:06:05 +04:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
2012-06-20 19:41:34 +04:00
|
|
|
if (argv0 && i == 0) {
|
|
|
|
// Is there a request to suppress default binary launcher?
|
|
|
|
envVar += argv0;
|
|
|
|
} else {
|
2007-12-21 22:40:39 +03:00
|
|
|
envVar += argv[i];
|
|
|
|
}
|
2007-07-25 05:06:06 +04:00
|
|
|
|
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here
|
2020-05-17 09:58:48 +03:00
|
|
|
env = ToNewCString(envVar, mozilla::fallible);
|
2007-07-25 05:06:06 +04:00
|
|
|
if (!env) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2007-07-25 05:06:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the arg list is terminated
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
|
|
|
|
2007-07-25 05:06:06 +04:00
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here
|
2020-05-17 09:58:48 +03:00
|
|
|
env = ToNewCString(envVar, mozilla::fallible);
|
2007-07-25 05:06:06 +04:00
|
|
|
if (!env) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2007-07-25 05:06:05 +04:00
|
|
|
|
2007-07-25 05:06:12 +04:00
|
|
|
// make sure we save the info in XUL_APP_FILE for the reporter
|
|
|
|
const char* appfile = PR_GetEnv("XUL_APP_FILE");
|
|
|
|
if (appfile && *appfile) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_XUL_APP_FILE=";
|
|
|
|
envVar += appfile;
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
PR_SetEnv(env);
|
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-09 05:40:47 +03:00
|
|
|
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2008-02-09 05:40:47 +03:00
|
|
|
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 22:29:51 +04:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
bool WriteMinidumpForSigInfo(int signo, siginfo_t* info, void* uc) {
|
2014-07-22 15:05:00 +04:00
|
|
|
if (!gExceptionHandler) {
|
|
|
|
// Crash reporting is disabled.
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-05 22:29:51 +04:00
|
|
|
return gExceptionHandler->HandleSignal(signo, info, uc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-28 08:41:38 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
nsresult AppendObjCExceptionInfoToAppNotes(void* inException) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString excString;
|
2008-08-28 08:41:38 +04:00
|
|
|
GetObjCExceptionInfo(inException, excString);
|
|
|
|
AppendAppNotesToCrashReport(excString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-10 04:05:31 +03:00
|
|
|
/*
|
|
|
|
* Combined code to get/set the crash reporter submission pref on
|
|
|
|
* different platforms.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static nsresult PrefSubmitReports(bool* aSubmitReports, bool writePref) {
|
2010-02-10 04:05:31 +03:00
|
|
|
nsresult rv;
|
2019-03-21 04:28:50 +03:00
|
|
|
#if defined(XP_WIN)
|
2010-02-10 04:05:31 +03:00
|
|
|
/*
|
|
|
|
* NOTE! This needs to stay in sync with the preference checking code
|
|
|
|
* in toolkit/crashreporter/client/crashreporter_win.cpp
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appinfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString appVendor, appName;
|
2010-02-10 04:05:31 +03:00
|
|
|
rv = appinfo->GetVendor(appVendor);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = appinfo->GetName(appName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey(
|
|
|
|
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString regPath;
|
2010-02-10 04:05:31 +03:00
|
|
|
|
|
|
|
regPath.AppendLiteral("Software\\");
|
2012-07-11 02:31:03 +04:00
|
|
|
|
|
|
|
// We need to ensure the registry keys are created so we can properly
|
|
|
|
// write values to it
|
2016-05-17 23:53:15 +03:00
|
|
|
|
2012-07-17 03:50:52 +04: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 22:54:58 +04:00
|
|
|
regPath.Append('\\');
|
2012-07-17 03:50:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create appName key
|
|
|
|
regPath.Append(appName);
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
2014-05-26 22:54:58 +04:00
|
|
|
regPath.Append('\\');
|
2012-07-17 03:50:52 +04:00
|
|
|
|
|
|
|
// Create Crash Reporter key
|
|
|
|
regPath.AppendLiteral("Crash Reporter");
|
|
|
|
regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
2012-07-11 02:31:03 +04:00
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
2010-02-10 04:05:31 +03: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 19:56:38 +04:00
|
|
|
uint32_t value = *aSubmitReports ? 1 : 0;
|
2010-02-10 04:05:31 +03:00
|
|
|
rv = regKey->WriteIntValue(u"SubmitCrashReport"_ns, 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 19:56:38 +04:00
|
|
|
uint32_t value;
|
2010-02-10 04:05:31 +03:00
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = regKey->ReadIntValue(u"SubmitCrashReport"_ns, &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 18:59:28 +04:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 04:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-05-17 23:53:15 +03:00
|
|
|
|
2010-02-10 04:05:31 +03:00
|
|
|
rv = regKey->ReadIntValue(u"SubmitCrashReport"_ns, &value);
|
|
|
|
// default to true on failure
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
value = 1;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
regKey->Close();
|
|
|
|
|
|
|
|
*aSubmitReports = !!value;
|
|
|
|
return NS_OK;
|
2010-02-10 05:11:08 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
2010-06-21 06:07:59 +04: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 18:59:28 +04:00
|
|
|
*aSubmitReports = true;
|
2010-06-21 06:07:59 +04:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(
|
|
|
|
CFSTR("submitReport"), reporterClientAppID,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat) *aSubmitReports = !!prefValue;
|
|
|
|
}
|
|
|
|
return rv;
|
2010-02-10 04:05:31 +03: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("Crash Reports"_ns);
|
|
|
|
reporterINI->AppendNative("crashreporter.ini"_ns);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool exists;
|
2010-02-10 04:05:31 +03: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 18:59:28 +04:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 04:05:31 +03: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 =
|
2017-10-13 00:20:57 +03:00
|
|
|
do_GetService("@mozilla.org/xpcom/ini-parser-factory;1", &rv);
|
2010-02-10 04:05:31 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIINIParser> iniParser;
|
2012-06-06 06:08:30 +04:00
|
|
|
rv = iniFactory->CreateINIParser(reporterINI, getter_AddRefs(iniParser));
|
2010-02-10 04:05:31 +03:00
|
|
|
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("Crash Reporter"_ns, "SubmitReport"_ns,
|
|
|
|
*aSubmitReports ? "1"_ns : "0"_ns);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-10-13 00:20:57 +03:00
|
|
|
rv = iniWriter->WriteFile(reporterINI);
|
2010-02-10 04:05:31 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2016-05-17 23:53:15 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString submitReportValue;
|
2010-02-10 04:05:31 +03:00
|
|
|
rv = iniParser->GetString("Crash Reporter"_ns, "SubmitReport"_ns,
|
|
|
|
submitReportValue);
|
|
|
|
|
|
|
|
// Default to "true" if the pref can't be found.
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 04:05:31 +03:00
|
|
|
else if (submitReportValue.EqualsASCII("0"))
|
2011-10-17 18:59:28 +04:00
|
|
|
*aSubmitReports = false;
|
2010-02-10 04:05:31 +03:00
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
*aSubmitReports = true;
|
2010-02-10 04:05:31 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult GetSubmitReports(bool* aSubmitReports) {
|
2010-02-10 04:05:31 +03:00
|
|
|
return PrefSubmitReports(aSubmitReports, false);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult SetSubmitReports(bool aSubmitReports) {
|
2011-10-04 00:26:08 +04: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 18:20:58 +04:00
|
|
|
obsServ->NotifyObservers(nullptr, "submit-reports-pref-changed", nullptr);
|
2011-10-04 00:26:08 +04:00
|
|
|
return NS_OK;
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
2014-05-06 23:48:40 +04:00
|
|
|
static void SetCrashEventsDir(nsIFile* aDir) {
|
2018-02-26 17:00:58 +03:00
|
|
|
static const XP_CHAR eventsDirectoryEnv[] =
|
|
|
|
XP_TEXT("MOZ_CRASHREPORTER_EVENTS_DIRECTORY");
|
|
|
|
|
2014-05-06 23:48:40 +04:00
|
|
|
nsCOMPtr<nsIFile> eventsDir = aDir;
|
2014-02-19 03:58:03 +04:00
|
|
|
|
|
|
|
const char* env = PR_GetEnv("CRASHES_EVENTS_DIR");
|
2014-05-06 23:48:40 +04:00
|
|
|
if (env && *env) {
|
|
|
|
NS_NewNativeLocalFile(nsDependentCString(env), false,
|
|
|
|
getter_AddRefs(eventsDir));
|
2014-02-19 03:58:03 +04:00
|
|
|
EnsureDirectoryExists(eventsDir);
|
2014-05-06 23:48:40 +04:00
|
|
|
}
|
|
|
|
|
2018-02-26 17:00:58 +03:00
|
|
|
xpstring* path = CreatePathFromFile(eventsDir);
|
|
|
|
if (!path) {
|
|
|
|
return; // There's no clean failure from this
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:50:23 +03:00
|
|
|
eventsDirectory = xpstring(*path);
|
2014-02-19 03:58:03 +04:00
|
|
|
#ifdef XP_WIN
|
2018-02-26 17:00:58 +03:00
|
|
|
SetEnvironmentVariableW(eventsDirectoryEnv, path->c_str());
|
2014-02-19 03:58:03 +04:00
|
|
|
#else
|
2018-02-26 17:00:58 +03:00
|
|
|
setenv(eventsDirectoryEnv, path->c_str(), /* overwrite */ 1);
|
2014-02-19 03:58:03 +04:00
|
|
|
#endif
|
2018-02-26 17:00:58 +03:00
|
|
|
|
|
|
|
delete path;
|
2014-02-19 03:58:03 +04:00
|
|
|
}
|
|
|
|
|
2014-05-06 23:48:40 +04:00
|
|
|
void SetProfileDirectory(nsIFile* aDir) {
|
|
|
|
nsCOMPtr<nsIFile> dir;
|
|
|
|
aDir->Clone(getter_AddRefs(dir));
|
|
|
|
|
|
|
|
dir->Append(u"crashes"_ns);
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
dir->Append(u"events"_ns);
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
SetCrashEventsDir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUserAppDataDirectory(nsIFile* aDir) {
|
|
|
|
nsCOMPtr<nsIFile> dir;
|
|
|
|
aDir->Clone(getter_AddRefs(dir));
|
|
|
|
|
|
|
|
dir->Append(u"Crash Reports"_ns);
|
|
|
|
EnsureDirectoryExists(dir);
|
|
|
|
dir->Append(u"events"_ns);
|
|
|
|
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-19 03:58:03 +04:00
|
|
|
bool GetCrashEventsDir(nsAString& aPath) {
|
2021-02-19 23:50:23 +03:00
|
|
|
if (eventsDirectory.empty()) {
|
2014-02-19 03:58:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-19 23:50:23 +03:00
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(eventsDirectory.c_str());
|
2014-02-19 03:58:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-30 09:21:09 +04:00
|
|
|
void SetMemoryReportFile(nsIFile* aFile) {
|
|
|
|
if (!gExceptionHandler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsString path;
|
|
|
|
aFile->GetPath(path);
|
2021-02-19 23:50:23 +03:00
|
|
|
memoryReportPath = xpstring(path.get());
|
2014-08-30 09:21:09 +04:00
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
aFile->GetNativePath(path);
|
2021-02-19 23:50:23 +03:00
|
|
|
memoryReportPath = xpstring(path.get());
|
2014-08-30 09:21:09 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-21 21:45:25 +03:00
|
|
|
nsresult GetDefaultMemoryReportFile(nsIFile** aFile) {
|
|
|
|
nsCOMPtr<nsIFile> defaultMemoryReportFile;
|
|
|
|
if (!defaultMemoryReportPath) {
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(
|
|
|
|
NS_APP_PROFILE_DIR_STARTUP, getter_AddRefs(defaultMemoryReportFile));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
defaultMemoryReportFile->AppendNative("memory-report.json.gz"_ns);
|
|
|
|
defaultMemoryReportPath = CreatePathFromFile(defaultMemoryReportFile);
|
|
|
|
if (!defaultMemoryReportPath) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CreateFileFromPath(*defaultMemoryReportPath,
|
|
|
|
getter_AddRefs(defaultMemoryReportFile));
|
|
|
|
if (!defaultMemoryReportFile) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defaultMemoryReportFile.forget(aFile);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-03-14 16:31:19 +03:00
|
|
|
|
2012-07-17 03:50:52 +04:00
|
|
|
static void FindPendingDir() {
|
2021-02-19 23:50:23 +03:00
|
|
|
if (!pendingDirectory.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-17 03:50:52 +04:00
|
|
|
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(u"Crash Reports"_ns);
|
|
|
|
pendingDir->Append(u"pending"_ns);
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsString path;
|
|
|
|
pendingDir->GetPath(path);
|
2021-02-19 23:50:23 +03:00
|
|
|
pendingDirectory = path.get();
|
2012-07-17 03:50:52 +04:00
|
|
|
#else
|
|
|
|
nsCString path;
|
|
|
|
pendingDir->GetNativePath(path);
|
2021-02-19 23:50:23 +03:00
|
|
|
pendingDirectory = xpstring(path.get());
|
2012-07-17 03:50:52 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-25 00:22:01 +03:00
|
|
|
// The "pending" dir is Crash Reports/pending, from which minidumps
|
2012-07-11 06:20:05 +04:00
|
|
|
// can be submitted. Because this method may be called off the main thread,
|
|
|
|
// we store the pending directory as a path.
|
2012-06-06 06:08:30 +04:00
|
|
|
static bool GetPendingDir(nsIFile** dir) {
|
2014-11-01 18:45:25 +03:00
|
|
|
// MOZ_ASSERT(OOPInitialized());
|
2021-02-19 23:50:23 +03:00
|
|
|
if (pendingDirectory.empty()) {
|
2010-03-25 00:22:01 +03:00
|
|
|
return false;
|
2012-07-11 06:20:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> pending = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
2012-07-13 21:43:17 +04:00
|
|
|
if (!pending) {
|
|
|
|
NS_WARNING("Can't set up pending directory during shutdown.");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-11 06:20:05 +04:00
|
|
|
#ifdef XP_WIN
|
2021-02-19 23:50:23 +03:00
|
|
|
pending->InitWithPath(nsDependentString(pendingDirectory.c_str()));
|
2012-07-11 06:20:05 +04:00
|
|
|
#else
|
2021-02-19 23:50:23 +03:00
|
|
|
pending->InitWithNativePath(nsDependentCString(pendingDirectory.c_str()));
|
2012-07-11 06:20:05 +04:00
|
|
|
#endif
|
|
|
|
pending.swap(*dir);
|
2010-03-25 00:22:01 +03:00
|
|
|
return true;
|
|
|
|
}
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2010-03-25 00:22:01 +03: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
|
2016-05-17 23:53:15 +03:00
|
|
|
// a minidump submitter, and they're coming from the
|
2010-03-25 00:22:01 +03:00
|
|
|
// Crash Reports/pending/ dir. Otherwise, we don't know what the
|
|
|
|
// "somthing else" is, but the minidumps stay in [profile]/minidumps/
|
|
|
|
// limbo.
|
2012-06-06 06:08:30 +04:00
|
|
|
static bool GetMinidumpLimboDir(nsIFile** dir) {
|
2010-03-25 00:22:01 +03:00
|
|
|
if (ShouldReport()) {
|
|
|
|
return GetPendingDir(dir);
|
|
|
|
} else {
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifndef XP_LINUX
|
2010-03-25 00:22:01 +03:00
|
|
|
CreateFileFromPath(gExceptionHandler->dump_path(), dir);
|
2012-09-25 15:52:54 +04:00
|
|
|
#else
|
|
|
|
CreateFileFromPath(gExceptionHandler->minidump_descriptor().directory(),
|
|
|
|
dir);
|
|
|
|
#endif
|
2013-10-11 00:39:09 +04:00
|
|
|
return nullptr != *dir;
|
2010-03-25 00:22:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
void DeleteMinidumpFilesForID(const nsAString& id) {
|
|
|
|
nsCOMPtr<nsIFile> minidumpFile;
|
2017-02-16 09:36:57 +03:00
|
|
|
if (GetMinidumpForID(id, getter_AddRefs(minidumpFile))) {
|
2015-06-11 20:25:45 +03:00
|
|
|
minidumpFile->Remove(false);
|
|
|
|
}
|
2019-05-18 19:19:55 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> extraFile;
|
|
|
|
if (GetExtraFileForID(id, getter_AddRefs(extraFile))) {
|
|
|
|
extraFile->Remove(false);
|
|
|
|
}
|
2015-06-11 20:25:45 +03:00
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
bool GetMinidumpForID(const nsAString& id, nsIFile** minidump) {
|
2017-02-16 09:36:57 +03:00
|
|
|
if (!GetMinidumpLimboDir(minidump)) {
|
2010-03-25 00:22:01 +03:00
|
|
|
return false;
|
2017-02-16 09:36:57 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 23:53:15 +03:00
|
|
|
(*minidump)->Append(id + u".dmp"_ns);
|
2017-02-16 09:36:57 +03:00
|
|
|
|
|
|
|
bool exists;
|
|
|
|
if (NS_FAILED((*minidump)->Exists(&exists)) || !exists) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-25 00:22:01 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
bool GetIDFromMinidump(nsIFile* minidump, nsAString& id) {
|
2015-06-11 20:25:45 +03:00
|
|
|
if (minidump && NS_SUCCEEDED(minidump->GetLeafName(id))) {
|
2017-09-16 05:32:55 +03:00
|
|
|
id.ReplaceLiteral(id.Length() - 4, 4, u"");
|
2010-03-25 00:22:01 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
bool GetExtraFileForID(const nsAString& id, nsIFile** extraFile) {
|
2017-02-16 09:36:57 +03:00
|
|
|
if (!GetMinidumpLimboDir(extraFile)) {
|
2010-03-25 00:22:01 +03:00
|
|
|
return false;
|
2017-02-16 09:36:57 +03:00
|
|
|
}
|
|
|
|
|
2010-03-25 00:22:01 +03:00
|
|
|
(*extraFile)->Append(id + u".extra"_ns);
|
2017-02-16 09:36:57 +03:00
|
|
|
|
|
|
|
bool exists;
|
|
|
|
if (NS_FAILED((*extraFile)->Exists(&exists)) || !exists) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-25 00:22:01 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
bool GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile) {
|
2010-03-25 00:22:01 +03: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, u"extra"_ns);
|
2012-06-06 06:08:30 +04:00
|
|
|
rv = extraF->SetLeafName(leafName);
|
2010-03-25 00:22:01 +03:00
|
|
|
if (NS_FAILED(rv)) return false;
|
|
|
|
|
2013-10-11 00:39:09 +04:00
|
|
|
*extraFile = nullptr;
|
2012-06-06 06:08:30 +04:00
|
|
|
extraF.swap(*extraFile);
|
2010-03-25 00:22:01 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-07 23:48:58 +03:00
|
|
|
static void ReadAndValidateExceptionTimeAnnotations(
|
2019-05-18 19:19:55 +03:00
|
|
|
PRFileDesc* aFd, AnnotationTable& aAnnotations) {
|
|
|
|
PRInt32 res;
|
|
|
|
do {
|
2019-06-18 22:19:33 +03:00
|
|
|
uint32_t rawAnnotation;
|
|
|
|
res = PR_Read(aFd, &rawAnnotation, sizeof(rawAnnotation));
|
|
|
|
if ((res != sizeof(rawAnnotation)) ||
|
|
|
|
(rawAnnotation >= static_cast<uint32_t>(Annotation::Count))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t len;
|
|
|
|
res = PR_Read(aFd, &len, sizeof(len));
|
|
|
|
if (res != sizeof(len) || (len == 0)) {
|
|
|
|
return;
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
2019-05-18 19:19:55 +03:00
|
|
|
|
2019-06-18 22:19:33 +03:00
|
|
|
char c;
|
2019-05-18 19:19:55 +03:00
|
|
|
nsAutoCString value;
|
2019-06-18 22:19:33 +03:00
|
|
|
do {
|
|
|
|
res = PR_Read(aFd, &c, 1);
|
|
|
|
if (res != 1) {
|
|
|
|
return;
|
2019-05-18 19:19:55 +03:00
|
|
|
}
|
2019-06-18 22:19:33 +03:00
|
|
|
|
|
|
|
len--;
|
2019-05-18 19:19:55 +03:00
|
|
|
value.Append(c);
|
2019-06-18 22:19:33 +03:00
|
|
|
} while (len > 0);
|
2019-05-18 19:19:55 +03:00
|
|
|
|
2019-06-18 22:19:33 +03:00
|
|
|
// Looks good, save the (annotation, value) pair
|
2019-12-02 16:18:35 +03:00
|
|
|
aAnnotations[static_cast<Annotation>(rawAnnotation)] = value;
|
2019-05-18 19:19:55 +03:00
|
|
|
} while (res > 0);
|
|
|
|
}
|
|
|
|
|
2020-03-24 14:17:23 +03:00
|
|
|
static bool WriteExtraFile(PlatformWriter& pw,
|
2019-05-18 19:19:55 +03:00
|
|
|
const AnnotationTable& aAnnotations) {
|
|
|
|
if (!pw.Valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-02 16:18:35 +03:00
|
|
|
JSONAnnotationWriter writer(pw);
|
2020-04-08 09:55:40 +03:00
|
|
|
WriteAnnotations(writer, aAnnotations);
|
2020-11-23 10:25:36 +03:00
|
|
|
WriteSynthesizedAnnotations(writer);
|
2019-05-18 19:19:55 +03:00
|
|
|
|
|
|
|
return true;
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
bool WriteExtraFile(const nsAString& id, const AnnotationTable& annotations) {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> extra;
|
2019-05-18 19:19:55 +03:00
|
|
|
if (!GetMinidumpLimboDir(getter_AddRefs(extra))) {
|
2010-03-25 00:22:01 +03:00
|
|
|
return false;
|
2016-03-07 23:48:58 +03:00
|
|
|
}
|
2010-03-25 00:22:01 +03:00
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
extra->Append(id + u".extra"_ns);
|
2019-12-02 16:18:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsAutoString path;
|
|
|
|
NS_ENSURE_SUCCESS(extra->GetPath(path), false);
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
nsAutoCString path;
|
|
|
|
NS_ENSURE_SUCCESS(extra->GetNativePath(path), false);
|
|
|
|
#endif
|
2019-05-18 19:19:55 +03:00
|
|
|
|
2020-03-24 14:17:23 +03:00
|
|
|
PlatformWriter pw(path.get());
|
|
|
|
return WriteExtraFile(pw, annotations);
|
2019-05-18 19:19:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ReadExceptionTimeAnnotations(AnnotationTable& aAnnotations,
|
2020-09-07 19:02:26 +03:00
|
|
|
ProcessId aPid) {
|
2019-05-18 19:19:55 +03:00
|
|
|
// Read exception-time annotations
|
|
|
|
StaticMutexAutoLock pidMapLock(processMapLock);
|
|
|
|
if (aPid && processToCrashFd.count(aPid)) {
|
|
|
|
PRFileDesc* prFd = processToCrashFd[aPid];
|
|
|
|
processToCrashFd.erase(aPid);
|
2020-04-08 09:55:40 +03:00
|
|
|
ReadAndValidateExceptionTimeAnnotations(prFd, aAnnotations);
|
2019-05-18 19:19:55 +03:00
|
|
|
PR_Close(prFd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 23:34:48 +03:00
|
|
|
static void PopulateContentProcessAnnotations(AnnotationTable& aAnnotations) {
|
2020-04-08 09:55:40 +03:00
|
|
|
MergeContentCrashAnnotations(aAnnotations);
|
2019-05-18 19:19:55 +03:00
|
|
|
AddCommonAnnotations(aAnnotations);
|
2010-03-25 00:22:00 +03:00
|
|
|
}
|
|
|
|
|
2010-03-25 00:22:01 +03:00
|
|
|
// It really only makes sense to call this function when
|
|
|
|
// ShouldReport() is true.
|
2016-06-21 21:45:25 +03:00
|
|
|
// Uses dumpFile's filename to generate memoryReport's filename (same name with
|
|
|
|
// a different extension)
|
|
|
|
static bool MoveToPending(nsIFile* dumpFile, nsIFile* extraFile,
|
|
|
|
nsIFile* memoryReport) {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> pendingDir;
|
2010-03-25 00:22:01 +03:00
|
|
|
if (!GetPendingDir(getter_AddRefs(pendingDir))) return false;
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2020-09-23 18:17:15 +03:00
|
|
|
if (NS_FAILED(dumpFile->MoveTo(pendingDir, u""_ns))) {
|
2012-09-08 21:20:59 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-23 18:17:15 +03:00
|
|
|
if (extraFile && NS_FAILED(extraFile->MoveTo(pendingDir, u""_ns))) {
|
2012-09-08 21:20:59 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-21 21:45:25 +03:00
|
|
|
if (memoryReport) {
|
|
|
|
nsAutoString leafName;
|
|
|
|
nsresult rv = dumpFile->GetLeafName(leafName);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Generate the correct memory report filename from the dumpFile's name
|
|
|
|
leafName.Replace(
|
|
|
|
leafName.Length() - 4, 4,
|
|
|
|
static_cast<nsString>(CONVERT_XP_CHAR_TO_UTF16(memoryReportExtension)));
|
|
|
|
if (NS_FAILED(memoryReport->MoveTo(pendingDir, leafName))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-08 21:20:59 +04:00
|
|
|
return true;
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
2021-02-10 13:05:37 +03:00
|
|
|
static void MaybeAnnotateDumperError(const ClientInfo& aClientInfo,
|
|
|
|
AnnotationTable& aAnnotations) {
|
|
|
|
#if defined(MOZ_OXIDIZED_BREAKPAD)
|
|
|
|
if (aClientInfo.had_error()) {
|
|
|
|
aAnnotations[Annotation::DumperError] = *aClientInfo.error_msg();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
static void OnChildProcessDumpRequested(void* aContext,
|
2010-08-16 23:05:09 +04:00
|
|
|
const ClientInfo& aClientInfo,
|
|
|
|
const xpstring& aFilePath) {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> minidump;
|
2010-01-15 01:38:00 +03:00
|
|
|
|
2014-01-15 19:03:14 +04: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;
|
|
|
|
|
2019-04-03 21:54:04 +03:00
|
|
|
CreateFileFromPath(aFilePath, getter_AddRefs(minidump));
|
2010-01-15 01:38:00 +03:00
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
ProcessId pid = aClientInfo.pid();
|
2016-06-21 21:45:25 +03:00
|
|
|
if (ShouldReport()) {
|
|
|
|
nsCOMPtr<nsIFile> memoryReport;
|
2021-02-19 23:50:23 +03:00
|
|
|
if (!memoryReportPath.empty()) {
|
2016-06-21 21:45:25 +03:00
|
|
|
CreateFileFromPath(memoryReportPath, getter_AddRefs(memoryReport));
|
|
|
|
MOZ_ASSERT(memoryReport);
|
|
|
|
}
|
2019-05-18 19:19:55 +03:00
|
|
|
MoveToPending(minidump, nullptr, memoryReport);
|
2016-06-21 21:45:25 +03:00
|
|
|
}
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2010-01-15 01:38:00 +03:00
|
|
|
{
|
2012-07-11 06:20:05 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
bool runCallback;
|
|
|
|
#endif
|
2012-07-02 22:55:23 +04:00
|
|
|
{
|
2020-05-18 23:34:48 +03:00
|
|
|
dumpMapLock->Lock();
|
2012-07-11 06:20:05 +04:00
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(pid);
|
|
|
|
MOZ_ASSERT(!pd->minidump);
|
|
|
|
pd->minidump = minidump;
|
|
|
|
pd->sequence = ++crashSequence;
|
2019-05-18 19:19:55 +03:00
|
|
|
pd->annotations = MakeUnique<AnnotationTable>();
|
2020-05-18 23:34:48 +03:00
|
|
|
PopulateContentProcessAnnotations(*(pd->annotations));
|
2021-02-10 13:05:37 +03:00
|
|
|
MaybeAnnotateDumperError(aClientInfo, *(pd->annotations));
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2013-10-11 00:39:09 +04:00
|
|
|
runCallback = nullptr != pd->callback;
|
2012-07-11 06:20:05 +04:00
|
|
|
#endif
|
2012-07-02 22:55:23 +04:00
|
|
|
}
|
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
2012-07-11 06:20:05 +04:00
|
|
|
if (runCallback) NS_DispatchToMainThread(new ReportInjectedCrash(pid));
|
2012-07-02 22:55:23 +04:00
|
|
|
#endif
|
2010-01-15 01:38:00 +03:00
|
|
|
}
|
2010-01-13 00:14:38 +03:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:34:48 +03:00
|
|
|
static void OnChildProcessDumpWritten(void* aContext,
|
|
|
|
const ClientInfo& aClientInfo) {
|
2020-09-07 19:02:26 +03:00
|
|
|
ProcessId pid = aClientInfo.pid();
|
2020-05-18 23:34:48 +03:00
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(pid);
|
|
|
|
MOZ_ASSERT(pd);
|
|
|
|
if (!pd->minidumpOnly) {
|
|
|
|
ReadExceptionTimeAnnotations(*(pd->annotations), pid);
|
|
|
|
}
|
|
|
|
dumpMapLock->Unlock();
|
|
|
|
}
|
|
|
|
|
2013-10-11 00:39:09 +04:00
|
|
|
static bool OOPInitialized() { return pidToMinidump != nullptr; }
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
void OOPInit() {
|
2016-04-26 03:23:21 +03:00
|
|
|
class ProxyToMainThread : public Runnable {
|
2014-07-18 21:31:45 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
ProxyToMainThread() : Runnable("nsExceptionHandler::ProxyToMainThread") {}
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2014-07-18 21:31:45 +04:00
|
|
|
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-11 06:20:05 +04:00
|
|
|
if (OOPInitialized()) return;
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(gExceptionHandler != nullptr,
|
|
|
|
"attempt to initialize OOP crash reporter before in-process "
|
|
|
|
"crashreporter!");
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2010-01-13 18:44:10 +03:00
|
|
|
childCrashNotifyPipe =
|
2016-12-09 23:30:19 +03:00
|
|
|
mozilla::Smprintf("\\\\.\\pipe\\gecko-crash-server-pipe.%i",
|
2017-03-03 18:17:27 +03:00
|
|
|
static_cast<int>(::GetCurrentProcessId()))
|
|
|
|
.release();
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
const std::wstring dumpPath = gExceptionHandler->dump_path();
|
|
|
|
crashServer = new CrashGenerationServer(
|
2015-08-21 10:01:47 +03:00
|
|
|
std::wstring(NS_ConvertASCIItoUTF16(childCrashNotifyPipe).get()),
|
2013-10-11 00:39:09 +04:00
|
|
|
nullptr, // default security attributes
|
|
|
|
nullptr, nullptr, // we don't care about process connect here
|
2020-05-18 23:34:48 +03:00
|
|
|
OnChildProcessDumpRequested, nullptr, OnChildProcessDumpWritten, nullptr,
|
2013-10-11 00:39:09 +04:00
|
|
|
nullptr, // we don't care about process exit here
|
|
|
|
nullptr, nullptr, // we don't care about upload request here
|
2010-01-13 00:14:38 +03:00
|
|
|
true, // automatically generate dumps
|
|
|
|
&dumpPath);
|
|
|
|
|
2017-06-20 10:00:32 +03:00
|
|
|
if (sIncludeContextHeap) {
|
|
|
|
crashServer->set_include_context_heap(sIncludeContextHeap);
|
|
|
|
}
|
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
if (!CrashGenerationServer::CreateReportChannel(&serverSocketFd,
|
|
|
|
&clientSocketFd))
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("can't create crash reporter socketpair()");
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2012-09-25 15:52:54 +04:00
|
|
|
const std::string dumpPath =
|
|
|
|
gExceptionHandler->minidump_descriptor().directory();
|
2010-01-13 00:14:38 +03:00
|
|
|
crashServer = new CrashGenerationServer(
|
2020-05-18 23:34:48 +03:00
|
|
|
serverSocketFd, OnChildProcessDumpRequested, nullptr,
|
|
|
|
OnChildProcessDumpWritten, nullptr, true, &dumpPath);
|
2010-08-16 23:05:09 +04:00
|
|
|
|
|
|
|
#elif defined(XP_MACOSX)
|
2016-12-09 23:30:19 +03:00
|
|
|
childCrashNotifyPipe = mozilla::Smprintf("gecko-crash-server-pipe.%i",
|
2017-03-03 18:17:27 +03:00
|
|
|
static_cast<int>(getpid()))
|
|
|
|
.release();
|
2010-08-16 23:05:09 +04:00
|
|
|
const std::string dumpPath = gExceptionHandler->dump_path();
|
|
|
|
|
2020-05-18 23:34:48 +03:00
|
|
|
crashServer = new CrashGenerationServer(
|
|
|
|
childCrashNotifyPipe, nullptr, nullptr, OnChildProcessDumpRequested,
|
|
|
|
nullptr, OnChildProcessDumpWritten, nullptr,
|
|
|
|
true, // automatically generate dumps
|
|
|
|
dumpPath);
|
2010-01-13 00:14:38 +03:00
|
|
|
#endif
|
|
|
|
|
2016-12-03 00:46:53 +03:00
|
|
|
if (!crashServer->Start()) MOZ_CRASH("can't start crash reporter server()");
|
2010-01-15 01:38:00 +03:00
|
|
|
|
|
|
|
pidToMinidump = new ChildMinidumpMap();
|
|
|
|
|
|
|
|
dumpMapLock = new Mutex("CrashReporter::dumpMapLock");
|
2012-07-11 06:20:05 +04:00
|
|
|
|
2012-07-17 03:50:52 +04:00
|
|
|
FindPendingDir();
|
2014-02-19 03:58:03 +04:00
|
|
|
UpdateCrashEventsDir();
|
2010-01-13 00:14:38 +03:00
|
|
|
}
|
|
|
|
|
2010-01-21 05:17:40 +03:00
|
|
|
static void OOPDeinit() {
|
|
|
|
if (!OOPInitialized()) {
|
|
|
|
NS_WARNING("OOPDeinit() without successful OOPInit()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-02 22:55:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
if (sInjectorThread) {
|
|
|
|
sInjectorThread->Shutdown();
|
|
|
|
NS_RELEASE(sInjectorThread);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-21 05:17:40 +03:00
|
|
|
delete crashServer;
|
2013-10-11 00:39:09 +04:00
|
|
|
crashServer = nullptr;
|
2010-01-21 05:17:40 +03:00
|
|
|
|
|
|
|
delete dumpMapLock;
|
2013-10-11 00:39:09 +04:00
|
|
|
dumpMapLock = nullptr;
|
2010-01-21 05:17:40 +03:00
|
|
|
|
|
|
|
delete pidToMinidump;
|
2013-10-11 00:39:09 +04:00
|
|
|
pidToMinidump = nullptr;
|
2010-01-21 05:17:40 +03:00
|
|
|
|
2017-05-03 22:55:24 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2017-07-25 02:09:25 +03:00
|
|
|
free(childCrashNotifyPipe);
|
2013-10-11 00:39:09 +04:00
|
|
|
childCrashNotifyPipe = nullptr;
|
2010-01-21 05:17:40 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-16 23:05:09 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-13 00:14:38 +03:00
|
|
|
// Parent-side API for children
|
|
|
|
const char* GetChildNotificationPipe() {
|
2010-01-13 18:44:10 +03:00
|
|
|
if (!GetEnabled()) return kNullNotifyPipe;
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2010-01-13 18:44:10 +03:00
|
|
|
return childCrashNotifyPipe;
|
2010-01-13 00:14:38 +03:00
|
|
|
}
|
2010-08-16 23:05:09 +04:00
|
|
|
#endif
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2012-07-02 22:55:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
void InjectCrashReporterIntoProcess(DWORD processID,
|
|
|
|
InjectorCrashCallback* cb) {
|
|
|
|
if (!GetEnabled()) return;
|
|
|
|
|
|
|
|
if (!OOPInitialized()) OOPInit();
|
|
|
|
|
|
|
|
if (!sInjectorThread) {
|
2016-12-21 13:43:50 +03:00
|
|
|
if (NS_FAILED(NS_NewNamedThread("CrashRep Inject", &sInjectorThread)))
|
2012-07-02 22:55:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(processID);
|
|
|
|
MOZ_ASSERT(!pd->minidump && !pd->callback);
|
|
|
|
pd->callback = cb;
|
2020-05-18 23:34:48 +03:00
|
|
|
pd->minidumpOnly = true;
|
2012-07-11 06:20:05 +04:00
|
|
|
}
|
2012-07-02 22:55:23 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = new InjectCrashRunnable(processID);
|
|
|
|
sInjectorThread->Dispatch(r, nsIEventTarget::DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ReportInjectedCrash::Run() {
|
|
|
|
// Crash reporting may have been disabled after this method was dispatched
|
2012-07-11 06:20:05 +04:00
|
|
|
if (!OOPInitialized()) return NS_OK;
|
2012-07-02 22:55:23 +04:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
InjectorCrashCallback* cb;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(mPID);
|
|
|
|
if (!pd || !pd->callback) return NS_OK;
|
2012-07-02 22:55:23 +04:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
MOZ_ASSERT(pd->minidump);
|
2012-07-02 22:55:23 +04:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
cb = pd->callback;
|
|
|
|
}
|
2012-07-02 22:55:23 +04:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
cb->OnCrash(mPID);
|
2012-07-02 22:55:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterInjectorCallback(DWORD processID) {
|
|
|
|
if (!OOPInitialized()) return;
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
pidToMinidump->RemoveEntry(processID);
|
2012-07-02 22:55:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MOZ_CRASHREPORTER_INJECTOR
|
|
|
|
|
2017-11-27 23:37:34 +03:00
|
|
|
void RegisterChildCrashAnnotationFileDescriptor(ProcessId aProcess,
|
|
|
|
PRFileDesc* aFd) {
|
2019-01-09 02:53:37 +03:00
|
|
|
StaticMutexAutoLock pidMapLock(processMapLock);
|
2017-11-27 23:37:34 +03:00
|
|
|
processToCrashFd[aProcess] = aFd;
|
|
|
|
}
|
2017-09-13 18:26:25 +03:00
|
|
|
|
2017-11-27 23:37:34 +03:00
|
|
|
void DeregisterChildCrashAnnotationFileDescriptor(ProcessId aProcess) {
|
2019-01-09 02:53:37 +03:00
|
|
|
StaticMutexAutoLock pidMapLock(processMapLock);
|
2017-11-27 23:37:34 +03:00
|
|
|
auto it = processToCrashFd.find(aProcess);
|
|
|
|
if (it != processToCrashFd.end()) {
|
|
|
|
PR_Close(it->second);
|
|
|
|
processToCrashFd.erase(it);
|
2016-03-16 21:35:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:06:31 +03:00
|
|
|
#if defined(XP_LINUX)
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
// Parent-side API for children
|
|
|
|
bool CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd) {
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
*childCrashFd = -1;
|
|
|
|
*childCrashRemapFd = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
MOZ_ASSERT(OOPInitialized());
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
*childCrashFd = clientSocketFd;
|
2016-11-02 02:11:32 +03:00
|
|
|
*childCrashRemapFd = gMagicChildCrashReportFd;
|
2010-01-13 00:14:38 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:06:31 +03:00
|
|
|
#endif // defined(XP_LINUX)
|
|
|
|
|
|
|
|
bool SetRemoteExceptionHandler(const char* aCrashPipe,
|
2021-06-11 12:59:49 +03:00
|
|
|
FileHandle aCrashTimeAnnotationFile) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
|
2021-06-11 12:59:49 +03:00
|
|
|
RegisterRuntimeExceptionModule(XRE_GetProcessType());
|
2020-04-08 09:55:40 +03:00
|
|
|
InitializeAnnotationFacilities();
|
|
|
|
|
2020-03-19 17:06:31 +03:00
|
|
|
#if defined(XP_WIN)
|
2021-06-11 12:59:49 +03:00
|
|
|
gChildCrashAnnotationReportFd = aCrashTimeAnnotationFile;
|
2020-03-19 17:06:31 +03:00
|
|
|
gExceptionHandler = new google_breakpad::ExceptionHandler(
|
2020-12-01 20:26:55 +03:00
|
|
|
L"", ChildFilter, ChildMinidumpCallback,
|
2020-09-07 19:02:26 +03:00
|
|
|
nullptr, // no callback context
|
2020-03-19 17:06:31 +03:00
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL, GetMinidumpType(),
|
|
|
|
NS_ConvertASCIItoUTF16(aCrashPipe).get(), nullptr);
|
|
|
|
gExceptionHandler->set_handle_debug_exceptions(true);
|
|
|
|
|
|
|
|
# if defined(HAVE_64BIT_BUILD)
|
|
|
|
SetJitExceptionHandler();
|
|
|
|
# endif
|
|
|
|
#elif defined(XP_LINUX)
|
2012-09-25 16:42:57 +04:00
|
|
|
// MinidumpDescriptor requires a non-empty path.
|
|
|
|
google_breakpad::MinidumpDescriptor path(".");
|
2016-03-07 23:48:58 +03:00
|
|
|
|
2020-12-01 20:26:55 +03:00
|
|
|
gExceptionHandler = new google_breakpad::ExceptionHandler(
|
|
|
|
path, ChildFilter, ChildMinidumpCallback,
|
|
|
|
nullptr, // no callback context
|
|
|
|
true, // install signal handlers
|
|
|
|
gMagicChildCrashReportFd);
|
2010-04-13 00:47:47 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
2020-12-01 20:26:55 +03:00
|
|
|
gExceptionHandler = new google_breakpad::ExceptionHandler(
|
|
|
|
"", ChildFilter, ChildMinidumpCallback,
|
|
|
|
nullptr, // no callback context
|
|
|
|
true, // install signal handlers
|
|
|
|
aCrashPipe);
|
2020-03-19 17:06:31 +03:00
|
|
|
#endif
|
2010-08-16 23:05:09 +04:00
|
|
|
|
2017-01-29 10:53:50 +03:00
|
|
|
oldTerminateHandler = std::set_terminate(&TerminateHandler);
|
|
|
|
|
2010-08-16 23:05:09 +04:00
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
2010-04-13 00:47:47 +04:00
|
|
|
}
|
2010-01-13 00:14:38 +03:00
|
|
|
|
2020-02-21 20:40:30 +03:00
|
|
|
void GetAnnotation(uint32_t childPid, Annotation annotation,
|
|
|
|
nsACString& outStr) {
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
|
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(childPid);
|
|
|
|
if (!pd) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
outStr = (*pd->annotations)[annotation];
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool TakeMinidumpForChild(uint32_t childPid, nsIFile** dump,
|
2019-05-18 19:19:55 +03:00
|
|
|
AnnotationTable& aAnnotations, uint32_t* aSequence) {
|
2010-01-15 01:38:00 +03:00
|
|
|
if (!GetEnabled()) return false;
|
|
|
|
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2010-03-19 01:52:36 +03:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
ChildProcessData* pd = pidToMinidump->GetEntry(childPid);
|
|
|
|
if (!pd) return false;
|
2010-03-19 01:52:36 +03:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
NS_IF_ADDREF(*dump = pd->minidump);
|
2019-05-22 16:04:41 +03:00
|
|
|
// Only Flash process minidumps don't have annotations. Once we get rid of
|
|
|
|
// the Flash processes this check will become redundant.
|
2020-05-18 23:34:48 +03:00
|
|
|
if (!pd->minidumpOnly) {
|
2019-05-22 16:04:41 +03:00
|
|
|
aAnnotations = *(pd->annotations);
|
|
|
|
}
|
2012-07-11 06:20:05 +04:00
|
|
|
if (aSequence) {
|
|
|
|
*aSequence = pd->sequence;
|
|
|
|
}
|
2015-09-25 07:38:04 +03:00
|
|
|
|
|
|
|
pidToMinidump->RemoveEntry(pd);
|
2010-03-19 01:52:36 +03:00
|
|
|
|
2012-07-11 06:20:05 +04:00
|
|
|
return !!*dump;
|
2010-01-15 01:38:00 +03:00
|
|
|
}
|
|
|
|
|
2019-12-20 20:50:45 +03:00
|
|
|
bool FinalizeOrphanedMinidump(uint32_t aChildPid, GeckoProcessType aType,
|
|
|
|
nsString* aDumpId) {
|
2019-08-09 17:23:19 +03:00
|
|
|
AnnotationTable annotations;
|
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
|
|
|
|
if (!TakeMinidumpForChild(aChildPid, getter_AddRefs(minidump), annotations)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString id;
|
|
|
|
if (!GetIDFromMinidump(minidump, id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-20 20:50:45 +03:00
|
|
|
if (aDumpId) {
|
|
|
|
*aDumpId = id;
|
|
|
|
}
|
|
|
|
|
2019-08-09 17:23:19 +03:00
|
|
|
annotations[Annotation::ProcessType] =
|
|
|
|
XRE_ChildProcessTypeToAnnotation(aType);
|
|
|
|
|
|
|
|
return WriteExtraFile(id, annotations);
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:59:49 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
|
|
|
|
// Function invoked by the WER runtime exception handler running in an
|
|
|
|
// external process. This function isn't used anywhere inside Gecko directly
|
|
|
|
// but rather invoked via CreateRemoteThread() in the main process.
|
|
|
|
DWORD WINAPI WerNotifyProc(LPVOID aParameter) {
|
|
|
|
const WindowsErrorReportingData* werData =
|
|
|
|
static_cast<const WindowsErrorReportingData*>(aParameter);
|
|
|
|
|
|
|
|
// Hold the mutex until the current dump request is complete, to
|
|
|
|
// prevent UnsetExceptionHandler() from pulling the rug out from
|
|
|
|
// under us.
|
|
|
|
MutexAutoLock safetyLock(*dumpSafetyLock);
|
|
|
|
if (!isSafeToDump || !ShouldReport()) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessId pid = werData->mChildPid;
|
|
|
|
nsCOMPtr<nsIFile> minidump;
|
|
|
|
if (!GetPendingDir(getter_AddRefs(minidump))) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
xpstring minidump_native_name(werData->mMinidumpFile,
|
|
|
|
werData->mMinidumpFile + 40);
|
|
|
|
nsString minidump_name(minidump_native_name.c_str());
|
|
|
|
minidump->Append(minidump_name);
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
|
|
|
ChildProcessData* pd = pidToMinidump->PutEntry(pid);
|
|
|
|
MOZ_ASSERT(!pd->minidump);
|
|
|
|
pd->minidump = minidump;
|
|
|
|
pd->sequence = ++crashSequence;
|
|
|
|
pd->annotations = MakeUnique<AnnotationTable>();
|
2021-06-11 12:59:50 +03:00
|
|
|
(*pd->annotations)[Annotation::WindowsErrorReporting] = "1"_ns;
|
2021-06-11 12:59:51 +03:00
|
|
|
if (werData->mOOMAllocationSize > 0) {
|
|
|
|
char buffer[32] = {};
|
|
|
|
XP_STOA(werData->mOOMAllocationSize, buffer);
|
|
|
|
(*pd->annotations)[Annotation::OOMAllocationSize] = buffer;
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:59:49 +03:00
|
|
|
PopulateContentProcessAnnotations(*(pd->annotations));
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // XP_WIN
|
|
|
|
|
2010-03-25 00:22:00 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2020-09-07 19:02:26 +03:00
|
|
|
// CreateMinidumpsAndPair() and helpers
|
2010-03-25 00:22:00 +03:00
|
|
|
//
|
2012-09-08 21:20:59 +04:00
|
|
|
|
2019-05-15 16:09:31 +03:00
|
|
|
/*
|
|
|
|
* Renames the stand alone dump file aDumpFile to:
|
|
|
|
* |aOwnerDumpFile-aDumpFileProcessType.dmp|
|
|
|
|
* and moves it into the same directory as aOwnerDumpFile. Does not
|
|
|
|
* modify aOwnerDumpFile in any way.
|
|
|
|
*
|
|
|
|
* @param aDumpFile - the dump file to associate with aOwnerDumpFile.
|
|
|
|
* @param aOwnerDumpFile - the new owner of aDumpFile.
|
|
|
|
* @param aDumpFileProcessType - process name associated with aDumpFile.
|
|
|
|
*/
|
|
|
|
static void RenameAdditionalHangMinidump(nsIFile* minidump,
|
|
|
|
nsIFile* childMinidump,
|
|
|
|
const nsACString& name) {
|
2012-09-08 21:20:59 +04: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 + name, leafName.Length() - 4);
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
if (NS_FAILED(minidump->MoveToNative(directory, leafName))) {
|
|
|
|
NS_WARNING("RenameAdditionalHangMinidump failed to move minidump.");
|
|
|
|
}
|
2012-09-08 21:20:59 +04:00
|
|
|
}
|
2010-03-25 00:22:00 +03:00
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
// Stores the minidump in the nsIFile pointed by the |context| parameter.
|
2012-09-25 15:52:54 +04:00
|
|
|
static bool PairedDumpCallback(
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
const MinidumpDescriptor& descriptor,
|
|
|
|
#else
|
2010-03-25 00:22:00 +03:00
|
|
|
const XP_CHAR* dump_path, const XP_CHAR* minidump_id,
|
2012-09-25 15:52:54 +04:00
|
|
|
#endif
|
2010-03-25 00:22:00 +03:00
|
|
|
void* context,
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2010-03-25 00:22:00 +03:00
|
|
|
EXCEPTION_POINTERS* /*unused*/, MDRawAssertionInfo* /*unused*/,
|
|
|
|
#endif
|
2019-07-03 02:26:11 +03:00
|
|
|
const phc::AddrInfo* addrInfo, bool succeeded) {
|
2012-09-08 21:20:59 +04:00
|
|
|
nsCOMPtr<nsIFile>& minidump = *static_cast<nsCOMPtr<nsIFile>*>(context);
|
2010-03-25 00:22:00 +03:00
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
xpstring path;
|
2012-09-25 15:52:54 +04:00
|
|
|
#ifdef XP_LINUX
|
2019-05-18 19:19:55 +03:00
|
|
|
path = descriptor.path();
|
2012-09-25 15:52:54 +04:00
|
|
|
#else
|
2019-05-18 19:19:55 +03:00
|
|
|
path = dump_path;
|
|
|
|
path += XP_PATH_SEPARATOR;
|
|
|
|
path += minidump_id;
|
|
|
|
path += dumpFileExtension;
|
2012-09-25 15:52:54 +04:00
|
|
|
#endif
|
2010-03-25 00:22:00 +03:00
|
|
|
|
2019-05-18 19:19:55 +03:00
|
|
|
CreateFileFromPath(path, getter_AddRefs(minidump));
|
2012-09-08 21:20:59 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-31 04:24:45 +04:00
|
|
|
ThreadId CurrentThreadId() {
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
return ::GetCurrentThreadId();
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
return sys_gettid();
|
|
|
|
#elif defined(XP_MACOSX)
|
2010-08-27 17:32:45 +04: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 22:12:21 +03:00
|
|
|
abort();
|
2010-03-31 04:24:45 +04:00
|
|
|
#else
|
|
|
|
# error "Unsupported platform"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-27 17:32:45 +04:00
|
|
|
#ifdef XP_MACOSX
|
2012-09-27 00:49:20 +04:00
|
|
|
static mach_port_t GetChildThread(ProcessHandle childPid,
|
|
|
|
ThreadId childBlamedThread) {
|
2010-08-27 17:32:45 +04: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-27 00:49:20 +04:00
|
|
|
|
|
|
|
return childThread;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
bool CreateMinidumpsAndPair(ProcessHandle aTargetHandle,
|
2018-09-17 23:51:45 +03:00
|
|
|
ThreadId aTargetBlamedThread,
|
|
|
|
const nsACString& aIncomingPairName,
|
|
|
|
nsIFile* aIncomingDumpToPair,
|
2019-05-18 19:19:55 +03:00
|
|
|
AnnotationTable& aTargetAnnotations,
|
2018-09-17 23:51:45 +03:00
|
|
|
nsIFile** aMainDumpOut) {
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
return false;
|
2015-06-11 20:25:45 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 00:31:25 +03:00
|
|
|
AutoIOInterposerDisable disableIOInterposition;
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
#ifdef XP_MACOSX
|
2020-09-07 19:02:26 +03:00
|
|
|
mach_port_t targetThread = GetChildThread(aTargetHandle, aTargetBlamedThread);
|
2010-08-27 17:32:45 +04:00
|
|
|
#else
|
2015-06-11 20:25:45 +03:00
|
|
|
ThreadId targetThread = aTargetBlamedThread;
|
2010-08-27 17:32:45 +04:00
|
|
|
#endif
|
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
xpstring dump_path;
|
|
|
|
#ifndef XP_LINUX
|
|
|
|
dump_path = gExceptionHandler->dump_path();
|
|
|
|
#else
|
|
|
|
dump_path = gExceptionHandler->minidump_descriptor().directory();
|
|
|
|
#endif
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
// dump the target
|
|
|
|
nsCOMPtr<nsIFile> targetMinidump;
|
2010-03-25 00:22:00 +03:00
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidumpForChild(
|
2020-09-07 19:02:26 +03:00
|
|
|
aTargetHandle, targetThread, dump_path, PairedDumpCallback,
|
2016-06-30 03:59:02 +03:00
|
|
|
static_cast<void*>(&targetMinidump)
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2016-06-30 03:59:02 +03:00
|
|
|
,
|
|
|
|
GetMinidumpType()
|
|
|
|
#endif
|
2017-06-22 13:53:10 +03:00
|
|
|
)) {
|
2018-09-17 23:51:45 +03:00
|
|
|
return false;
|
2017-06-22 13:53:10 +03:00
|
|
|
}
|
2010-03-25 00:22:00 +03:00
|
|
|
|
2017-08-25 06:12:34 +03:00
|
|
|
// If aIncomingDumpToPair isn't valid, create a dump of this process.
|
2018-09-17 23:51:45 +03:00
|
|
|
nsCOMPtr<nsIFile> incomingDump;
|
2017-08-25 06:12:34 +03:00
|
|
|
if (aIncomingDumpToPair == nullptr) {
|
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidump(
|
|
|
|
dump_path,
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
true,
|
|
|
|
#endif
|
2018-09-17 23:51:45 +03:00
|
|
|
PairedDumpCallback, static_cast<void*>(&incomingDump)
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2017-08-25 06:12:34 +03:00
|
|
|
,
|
|
|
|
GetMinidumpType()
|
|
|
|
#endif
|
|
|
|
)) {
|
2018-09-17 23:51:45 +03:00
|
|
|
targetMinidump->Remove(false);
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-25 06:12:34 +03:00
|
|
|
} else {
|
2018-09-17 23:51:45 +03:00
|
|
|
incomingDump = aIncomingDumpToPair;
|
2017-08-25 06:12:34 +03:00
|
|
|
}
|
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
RenameAdditionalHangMinidump(incomingDump, targetMinidump, aIncomingPairName);
|
|
|
|
|
|
|
|
if (ShouldReport()) {
|
2019-05-18 19:19:55 +03:00
|
|
|
MoveToPending(targetMinidump, nullptr, nullptr);
|
2018-09-17 23:51:45 +03:00
|
|
|
MoveToPending(incomingDump, nullptr, nullptr);
|
2017-06-22 13:53:10 +03:00
|
|
|
}
|
2018-09-17 23:51:45 +03:00
|
|
|
#if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
|
|
|
|
DllBlocklist_Shutdown();
|
|
|
|
#endif
|
2010-03-25 00:22:00 +03:00
|
|
|
|
2020-09-07 19:02:26 +03:00
|
|
|
PopulateContentProcessAnnotations(aTargetAnnotations);
|
|
|
|
if (FlushContentProcessAnnotations(aTargetHandle)) {
|
|
|
|
ProcessId targetPid = base::GetProcId(aTargetHandle);
|
|
|
|
ReadExceptionTimeAnnotations(aTargetAnnotations, targetPid);
|
|
|
|
}
|
2019-05-18 19:19:55 +03:00
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
targetMinidump.forget(aMainDumpOut);
|
2017-06-22 13:53:10 +03:00
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
return true;
|
2010-03-25 00:22:00 +03:00
|
|
|
}
|
|
|
|
|
2012-09-27 00:49:20 +04: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,
|
2016-06-30 03:59:02 +03:00
|
|
|
static_cast<void*>(&childMinidump)
|
2019-03-21 04:28:50 +03:00
|
|
|
#ifdef XP_WIN
|
2016-06-30 03:59:02 +03:00
|
|
|
,
|
|
|
|
GetMinidumpType()
|
|
|
|
#endif
|
|
|
|
)) {
|
2012-09-27 00:49:20 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenameAdditionalHangMinidump(childMinidump, parentMinidump, name);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
bool UnsetRemoteExceptionHandler() {
|
2020-03-19 17:06:31 +03:00
|
|
|
// On Linux we don't unset breakpad's exception handler if the sandbox is
|
|
|
|
// enabled because it requires invoking `sigaltstack` and we don't want to
|
|
|
|
// allow that syscall in the sandbox. See bug 1622452.
|
|
|
|
#if !defined(XP_LINUX) || !defined(MOZ_SANDBOX)
|
2017-01-29 10:53:50 +03:00
|
|
|
std::set_terminate(oldTerminateHandler);
|
2010-01-13 00:14:38 +03:00
|
|
|
delete gExceptionHandler;
|
2013-10-11 00:39:09 +04:00
|
|
|
gExceptionHandler = nullptr;
|
2020-03-19 17:06:31 +03:00
|
|
|
#endif
|
2020-04-08 09:55:40 +03:00
|
|
|
TeardownAnnotationFacilities();
|
|
|
|
|
2010-01-13 00:14:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-17 03:50:52 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2016-11-02 02:11:32 +03:00
|
|
|
void SetNotificationPipeForChild(int childCrashFd) {
|
|
|
|
gMagicChildCrashReportFd = childCrashFd;
|
|
|
|
}
|
|
|
|
|
2017-11-27 23:37:34 +03:00
|
|
|
void SetCrashAnnotationPipeForChild(int childCrashAnnotationFd) {
|
|
|
|
gChildCrashAnnotationReportFd = childCrashAnnotationFd;
|
|
|
|
}
|
2010-11-24 17:15:03 +03:00
|
|
|
#endif
|
2010-10-19 23:05:47 +04:00
|
|
|
|
2007-07-25 05:05:55 +04:00
|
|
|
} // namespace CrashReporter
|