refactor: rename the atom directory to shell
This commit is contained in:
parent
4575a4aae3
commit
d7f07e8a80
631 changed files with 0 additions and 0 deletions
153
shell/common/crash_reporter/crash_reporter.cc
Normal file
153
shell/common/crash_reporter/crash_reporter.cc
Normal file
|
@ -0,0 +1,153 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/map_converter.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/electron_version.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
const char kCrashpadProcess[] = "crash-handler";
|
||||
const char kCrashesDirectoryKey[] = "crashes-directory";
|
||||
|
||||
CrashReporter::CrashReporter() {
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
bool run_as_node = base::Environment::Create()->HasVar(atom::kRunAsNode);
|
||||
#else
|
||||
bool run_as_node = false;
|
||||
#endif
|
||||
|
||||
if (run_as_node) {
|
||||
process_type_ = "node";
|
||||
} else {
|
||||
auto* cmd = base::CommandLine::ForCurrentProcess();
|
||||
process_type_ = cmd->GetSwitchValueASCII(switches::kProcessType);
|
||||
}
|
||||
// process_type_ will be empty for browser process
|
||||
}
|
||||
|
||||
CrashReporter::~CrashReporter() {}
|
||||
|
||||
bool CrashReporter::IsInitialized() {
|
||||
return is_initialized_;
|
||||
}
|
||||
|
||||
void CrashReporter::Start(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler,
|
||||
const StringMap& extra_parameters) {
|
||||
is_initialized_ = true;
|
||||
SetUploadParameters(extra_parameters);
|
||||
|
||||
Init(product_name, company_name, submit_url, crashes_dir, upload_to_server,
|
||||
skip_system_crash_handler);
|
||||
}
|
||||
|
||||
void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
||||
upload_parameters_ = parameters;
|
||||
upload_parameters_["process_type"] =
|
||||
process_type_.empty() ? "browser" : process_type_;
|
||||
upload_parameters_["prod"] = ELECTRON_PRODUCT_NAME;
|
||||
upload_parameters_["ver"] = ELECTRON_VERSION_STRING;
|
||||
|
||||
// Setting platform dependent parameters.
|
||||
SetUploadParameters();
|
||||
}
|
||||
|
||||
void CrashReporter::SetUploadToServer(const bool upload_to_server) {}
|
||||
|
||||
bool CrashReporter::GetUploadToServer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<CrashReporter::UploadReportResult>
|
||||
CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) {
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
std::string file_content;
|
||||
std::vector<CrashReporter::UploadReportResult> result;
|
||||
base::FilePath uploads_path =
|
||||
crashes_dir.Append(FILE_PATH_LITERAL("uploads.log"));
|
||||
if (base::ReadFileToString(uploads_path, &file_content)) {
|
||||
std::vector<std::string> reports = base::SplitString(
|
||||
file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
for (const std::string& report : reports) {
|
||||
std::vector<std::string> report_item = base::SplitString(
|
||||
report, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
int report_time = 0;
|
||||
if (report_item.size() >= 2 &&
|
||||
base::StringToInt(report_item[0], &report_time)) {
|
||||
result.push_back(
|
||||
CrashReporter::UploadReportResult(report_time, report_item[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CrashReporter::Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool auto_submit,
|
||||
bool skip_system_crash_handler) {}
|
||||
|
||||
void CrashReporter::SetUploadParameters() {}
|
||||
|
||||
void CrashReporter::AddExtraParameter(const std::string& key,
|
||||
const std::string& value) {}
|
||||
|
||||
void CrashReporter::RemoveExtraParameter(const std::string& key) {}
|
||||
|
||||
std::map<std::string, std::string> CrashReporter::GetParameters() const {
|
||||
return upload_parameters_;
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX) && defined(MAS_BUILD)
|
||||
// static
|
||||
CrashReporter* CrashReporter::GetInstance() {
|
||||
static CrashReporter crash_reporter;
|
||||
return &crash_reporter;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CrashReporter::StartInstance(const mate::Dictionary& options) {
|
||||
auto* reporter = GetInstance();
|
||||
if (!reporter)
|
||||
return;
|
||||
|
||||
std::string product_name;
|
||||
options.Get("productName", &product_name);
|
||||
std::string company_name;
|
||||
options.Get("companyName", &company_name);
|
||||
std::string submit_url;
|
||||
options.Get("submitURL", &submit_url);
|
||||
base::FilePath crashes_dir;
|
||||
options.Get("crashesDirectory", &crashes_dir);
|
||||
StringMap extra_parameters;
|
||||
options.Get("extra", &extra_parameters);
|
||||
|
||||
extra_parameters["_productName"] = product_name;
|
||||
extra_parameters["_companyName"] = company_name;
|
||||
|
||||
reporter->Start(product_name, company_name, submit_url, crashes_dir, true,
|
||||
false, extra_parameters);
|
||||
}
|
||||
|
||||
} // namespace crash_reporter
|
73
shell/common/crash_reporter/crash_reporter.h
Normal file
73
shell/common/crash_reporter/crash_reporter.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
extern const char kCrashpadProcess[];
|
||||
extern const char kCrashesDirectoryKey[];
|
||||
|
||||
class CrashReporter {
|
||||
public:
|
||||
typedef std::map<std::string, std::string> StringMap;
|
||||
typedef std::pair<int, std::string> UploadReportResult; // upload-date, id
|
||||
|
||||
static CrashReporter* GetInstance();
|
||||
static void StartInstance(const mate::Dictionary& options);
|
||||
|
||||
bool IsInitialized();
|
||||
void Start(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler,
|
||||
const StringMap& extra_parameters);
|
||||
|
||||
virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
|
||||
const base::FilePath& crashes_dir);
|
||||
|
||||
virtual void SetUploadToServer(bool upload_to_server);
|
||||
virtual bool GetUploadToServer();
|
||||
virtual void AddExtraParameter(const std::string& key,
|
||||
const std::string& value);
|
||||
virtual void RemoveExtraParameter(const std::string& key);
|
||||
virtual std::map<std::string, std::string> GetParameters() const;
|
||||
|
||||
protected:
|
||||
CrashReporter();
|
||||
virtual ~CrashReporter();
|
||||
|
||||
virtual void Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler);
|
||||
virtual void SetUploadParameters();
|
||||
|
||||
StringMap upload_parameters_;
|
||||
std::string process_type_;
|
||||
|
||||
private:
|
||||
bool is_initialized_ = false;
|
||||
void SetUploadParameters(const StringMap& parameters);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashReporter);
|
||||
};
|
||||
|
||||
} // namespace crash_reporter
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_H_
|
118
shell/common/crash_reporter/crash_reporter_crashpad.cc
Normal file
118
shell/common/crash_reporter/crash_reporter_crashpad.cc
Normal file
|
@ -0,0 +1,118 @@
|
|||
// Copyright (c) 2019 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter_crashpad.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "third_party/crashpad/crashpad/client/settings.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
CrashReporterCrashpad::CrashReporterCrashpad() {}
|
||||
|
||||
CrashReporterCrashpad::~CrashReporterCrashpad() {}
|
||||
|
||||
bool CrashReporterCrashpad::GetUploadToServer() {
|
||||
bool enabled = true;
|
||||
if (database_) {
|
||||
database_->GetSettings()->GetUploadsEnabled(&enabled);
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void CrashReporterCrashpad::SetUploadToServer(const bool upload_to_server) {
|
||||
if (database_) {
|
||||
database_->GetSettings()->SetUploadsEnabled(upload_to_server);
|
||||
}
|
||||
}
|
||||
|
||||
void CrashReporterCrashpad::SetCrashKeyValue(const base::StringPiece& key,
|
||||
const base::StringPiece& value) {
|
||||
simple_string_dictionary_->SetKeyValue(key.data(), value.data());
|
||||
}
|
||||
|
||||
void CrashReporterCrashpad::SetInitialCrashKeyValues() {
|
||||
for (const auto& upload_parameter : upload_parameters_)
|
||||
SetCrashKeyValue(upload_parameter.first, upload_parameter.second);
|
||||
}
|
||||
|
||||
void CrashReporterCrashpad::AddExtraParameter(const std::string& key,
|
||||
const std::string& value) {
|
||||
if (simple_string_dictionary_) {
|
||||
SetCrashKeyValue(key, value);
|
||||
} else {
|
||||
upload_parameters_[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void CrashReporterCrashpad::RemoveExtraParameter(const std::string& key) {
|
||||
if (simple_string_dictionary_)
|
||||
simple_string_dictionary_->RemoveKey(key.data());
|
||||
else
|
||||
upload_parameters_.erase(key);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> CrashReporterCrashpad::GetParameters()
|
||||
const {
|
||||
if (simple_string_dictionary_) {
|
||||
std::map<std::string, std::string> ret;
|
||||
crashpad::SimpleStringDictionary::Iterator iter(*simple_string_dictionary_);
|
||||
for (;;) {
|
||||
auto* const entry = iter.Next();
|
||||
if (!entry)
|
||||
break;
|
||||
ret[entry->key] = entry->value;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return upload_parameters_;
|
||||
}
|
||||
|
||||
std::vector<CrashReporter::UploadReportResult>
|
||||
CrashReporterCrashpad::GetUploadedReports(const base::FilePath& crashes_dir) {
|
||||
std::vector<CrashReporter::UploadReportResult> uploaded_reports;
|
||||
|
||||
{
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
if (!base::PathExists(crashes_dir)) {
|
||||
return uploaded_reports;
|
||||
}
|
||||
}
|
||||
// Load crashpad database.
|
||||
std::unique_ptr<crashpad::CrashReportDatabase> database =
|
||||
crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
DCHECK(database);
|
||||
|
||||
std::vector<crashpad::CrashReportDatabase::Report> completed_reports;
|
||||
crashpad::CrashReportDatabase::OperationStatus status =
|
||||
database->GetCompletedReports(&completed_reports);
|
||||
if (status != crashpad::CrashReportDatabase::kNoError) {
|
||||
return uploaded_reports;
|
||||
}
|
||||
|
||||
for (const crashpad::CrashReportDatabase::Report& completed_report :
|
||||
completed_reports) {
|
||||
if (completed_report.uploaded) {
|
||||
uploaded_reports.push_back(
|
||||
UploadReportResult(static_cast<int>(completed_report.creation_time),
|
||||
completed_report.id));
|
||||
}
|
||||
}
|
||||
|
||||
auto sort_by_time = [](const UploadReportResult& a,
|
||||
const UploadReportResult& b) {
|
||||
return a.first >= b.first;
|
||||
};
|
||||
std::sort(uploaded_reports.begin(), uploaded_reports.end(), sort_by_time);
|
||||
return uploaded_reports;
|
||||
}
|
||||
|
||||
} // namespace crash_reporter
|
50
shell/common/crash_reporter/crash_reporter_crashpad.h
Normal file
50
shell/common/crash_reporter/crash_reporter_crashpad.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_CRASHPAD_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_CRASHPAD_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "third_party/crashpad/crashpad/client/crash_report_database.h"
|
||||
#include "third_party/crashpad/crashpad/client/simple_string_dictionary.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
class CrashReporterCrashpad : public CrashReporter {
|
||||
public:
|
||||
void SetUploadToServer(bool upload_to_server) override;
|
||||
bool GetUploadToServer() override;
|
||||
void AddExtraParameter(const std::string& key,
|
||||
const std::string& value) override;
|
||||
void RemoveExtraParameter(const std::string& key) override;
|
||||
std::map<std::string, std::string> GetParameters() const override;
|
||||
|
||||
protected:
|
||||
CrashReporterCrashpad();
|
||||
~CrashReporterCrashpad() override;
|
||||
|
||||
void SetUploadsEnabled(bool enable_uploads);
|
||||
void SetCrashKeyValue(const base::StringPiece& key,
|
||||
const base::StringPiece& value);
|
||||
void SetInitialCrashKeyValues();
|
||||
|
||||
std::vector<UploadReportResult> GetUploadedReports(
|
||||
const base::FilePath& crashes_dir) override;
|
||||
|
||||
std::unique_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
|
||||
std::unique_ptr<crashpad::CrashReportDatabase> database_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashReporterCrashpad);
|
||||
};
|
||||
|
||||
} // namespace crash_reporter
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_CRASHPAD_H_
|
140
shell/common/crash_reporter/crash_reporter_linux.cc
Normal file
140
shell/common/crash_reporter/crash_reporter_linux.cc
Normal file
|
@ -0,0 +1,140 @@
|
|||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter_linux.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/debug/crash_logging.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/linux_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/singleton.h"
|
||||
#include "base/process/memory.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "breakpad/src/client/linux/handler/exception_handler.h"
|
||||
#include "breakpad/src/common/linux/linux_libc_support.h"
|
||||
|
||||
using google_breakpad::ExceptionHandler;
|
||||
using google_breakpad::MinidumpDescriptor;
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
namespace {
|
||||
|
||||
// Define a preferred limit on minidump sizes, because Crash Server currently
|
||||
// throws away any larger than 1.2MB (1.2 * 1024 * 1024). A value of -1 means
|
||||
// no limit.
|
||||
static const off_t kMaxMinidumpFileSize = 1258291;
|
||||
|
||||
} // namespace
|
||||
|
||||
CrashReporterLinux::CrashReporterLinux() : pid_(getpid()) {
|
||||
// Set the base process start time value.
|
||||
struct timeval tv;
|
||||
if (!gettimeofday(&tv, NULL)) {
|
||||
uint64_t ret = tv.tv_sec;
|
||||
ret *= 1000;
|
||||
ret += tv.tv_usec / 1000;
|
||||
process_start_time_ = ret;
|
||||
}
|
||||
|
||||
// Make base::g_linux_distro work.
|
||||
base::SetLinuxDistro(base::GetLinuxDistro());
|
||||
}
|
||||
|
||||
CrashReporterLinux::~CrashReporterLinux() {}
|
||||
|
||||
void CrashReporterLinux::Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler) {
|
||||
EnableCrashDumping(crashes_dir);
|
||||
|
||||
upload_url_ = submit_url;
|
||||
upload_to_server_ = upload_to_server;
|
||||
|
||||
crash_keys_.reset(new CrashKeyStorage());
|
||||
for (StringMap::const_iterator iter = upload_parameters_.begin();
|
||||
iter != upload_parameters_.end(); ++iter)
|
||||
crash_keys_->SetKeyValue(iter->first.c_str(), iter->second.c_str());
|
||||
}
|
||||
|
||||
void CrashReporterLinux::SetUploadParameters() {
|
||||
upload_parameters_["platform"] = "linux";
|
||||
}
|
||||
|
||||
void CrashReporterLinux::SetUploadToServer(const bool upload_to_server) {
|
||||
upload_to_server_ = upload_to_server;
|
||||
}
|
||||
|
||||
bool CrashReporterLinux::GetUploadToServer() {
|
||||
return upload_to_server_;
|
||||
}
|
||||
|
||||
void CrashReporterLinux::EnableCrashDumping(const base::FilePath& crashes_dir) {
|
||||
{
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
base::CreateDirectory(crashes_dir);
|
||||
}
|
||||
std::string log_file = crashes_dir.Append("uploads.log").value();
|
||||
strncpy(g_crash_log_path, log_file.c_str(), sizeof(g_crash_log_path));
|
||||
|
||||
MinidumpDescriptor minidump_descriptor(crashes_dir.value());
|
||||
minidump_descriptor.set_size_limit(kMaxMinidumpFileSize);
|
||||
|
||||
breakpad_.reset(new ExceptionHandler(minidump_descriptor, NULL, CrashDone,
|
||||
this,
|
||||
true, // Install handlers.
|
||||
-1));
|
||||
}
|
||||
|
||||
bool CrashReporterLinux::CrashDone(const MinidumpDescriptor& minidump,
|
||||
void* context,
|
||||
const bool succeeded) {
|
||||
CrashReporterLinux* self = static_cast<CrashReporterLinux*>(context);
|
||||
|
||||
// WARNING: this code runs in a compromised context. It may not call into
|
||||
// libc nor allocate memory normally.
|
||||
if (!succeeded) {
|
||||
const char msg[] = "Failed to generate minidump.";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
DCHECK(!minidump.IsFD());
|
||||
|
||||
BreakpadInfo info = {0};
|
||||
info.filename = minidump.path();
|
||||
info.fd = minidump.fd();
|
||||
info.distro = base::g_linux_distro;
|
||||
info.distro_length = my_strlen(base::g_linux_distro);
|
||||
info.upload = self->upload_to_server_;
|
||||
info.process_start_time = self->process_start_time_;
|
||||
info.oom_size = base::g_oom_size;
|
||||
info.pid = self->pid_;
|
||||
info.upload_url = self->upload_url_.c_str();
|
||||
info.crash_keys = self->crash_keys_.get();
|
||||
HandleCrashDump(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
// static
|
||||
CrashReporterLinux* CrashReporterLinux::GetInstance() {
|
||||
return base::Singleton<CrashReporterLinux>::get();
|
||||
}
|
||||
|
||||
// static
|
||||
CrashReporter* CrashReporter::GetInstance() {
|
||||
return CrashReporterLinux::GetInstance();
|
||||
}
|
||||
|
||||
} // namespace crash_reporter
|
65
shell/common/crash_reporter/crash_reporter_linux.h
Normal file
65
shell/common/crash_reporter/crash_reporter_linux.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_LINUX_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_LINUX_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter.h"
|
||||
#include "atom/common/crash_reporter/linux/crash_dump_handler.h"
|
||||
#include "base/compiler_specific.h"
|
||||
|
||||
namespace base {
|
||||
template <typename T>
|
||||
struct DefaultSingletonTraits;
|
||||
}
|
||||
|
||||
namespace google_breakpad {
|
||||
class ExceptionHandler;
|
||||
class MinidumpDescriptor;
|
||||
} // namespace google_breakpad
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
class CrashReporterLinux : public CrashReporter {
|
||||
public:
|
||||
static CrashReporterLinux* GetInstance();
|
||||
|
||||
void Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler) override;
|
||||
void SetUploadToServer(bool upload_to_server) override;
|
||||
void SetUploadParameters() override;
|
||||
bool GetUploadToServer() override;
|
||||
|
||||
private:
|
||||
friend struct base::DefaultSingletonTraits<CrashReporterLinux>;
|
||||
|
||||
CrashReporterLinux();
|
||||
~CrashReporterLinux() override;
|
||||
|
||||
void EnableCrashDumping(const base::FilePath& crashes_dir);
|
||||
|
||||
static bool CrashDone(const google_breakpad::MinidumpDescriptor& minidump,
|
||||
void* context,
|
||||
const bool succeeded);
|
||||
|
||||
std::unique_ptr<google_breakpad::ExceptionHandler> breakpad_;
|
||||
std::unique_ptr<CrashKeyStorage> crash_keys_;
|
||||
|
||||
uint64_t process_start_time_ = 0;
|
||||
pid_t pid_ = 0;
|
||||
std::string upload_url_;
|
||||
bool upload_to_server_ = true;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashReporterLinux);
|
||||
};
|
||||
} // namespace crash_reporter
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_LINUX_H_
|
43
shell/common/crash_reporter/crash_reporter_mac.h
Normal file
43
shell/common/crash_reporter/crash_reporter_mac.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_MAC_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_MAC_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter_crashpad.h"
|
||||
|
||||
namespace base {
|
||||
template <typename T>
|
||||
struct DefaultSingletonTraits;
|
||||
}
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
class CrashReporterMac : public CrashReporterCrashpad {
|
||||
public:
|
||||
static CrashReporterMac* GetInstance();
|
||||
|
||||
void Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler) override;
|
||||
void SetUploadParameters() override;
|
||||
|
||||
private:
|
||||
friend struct base::DefaultSingletonTraits<CrashReporterMac>;
|
||||
|
||||
CrashReporterMac();
|
||||
~CrashReporterMac() override;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashReporterMac);
|
||||
};
|
||||
|
||||
} // namespace crash_reporter
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_MAC_H_
|
84
shell/common/crash_reporter/crash_reporter_mac.mm
Normal file
84
shell/common/crash_reporter/crash_reporter_mac.mm
Normal file
|
@ -0,0 +1,84 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter_mac.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/memory/singleton.h"
|
||||
#include "third_party/crashpad/crashpad/client/crashpad_client.h"
|
||||
#include "third_party/crashpad/crashpad/client/crashpad_info.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
CrashReporterMac::CrashReporterMac() {}
|
||||
|
||||
CrashReporterMac::~CrashReporterMac() {}
|
||||
|
||||
void CrashReporterMac::Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler) {
|
||||
// check whether crashpad has been initialized.
|
||||
// Only need to initialize once.
|
||||
if (simple_string_dictionary_)
|
||||
return;
|
||||
|
||||
if (process_type_.empty()) { // browser process
|
||||
@autoreleasepool {
|
||||
base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath();
|
||||
base::FilePath handler_path =
|
||||
framework_bundle_path.Append("Resources").Append("crashpad_handler");
|
||||
|
||||
std::vector<std::string> args = {
|
||||
"--no-rate-limit",
|
||||
"--no-upload-gzip", // not all servers accept gzip
|
||||
};
|
||||
|
||||
crashpad::CrashpadClient crashpad_client;
|
||||
crashpad_client.StartHandler(handler_path, crashes_dir, crashes_dir,
|
||||
submit_url, StringMap(), args, true, false);
|
||||
} // @autoreleasepool
|
||||
}
|
||||
|
||||
crashpad::CrashpadInfo* crashpad_info =
|
||||
crashpad::CrashpadInfo::GetCrashpadInfo();
|
||||
if (skip_system_crash_handler) {
|
||||
crashpad_info->set_system_crash_reporter_forwarding(
|
||||
crashpad::TriState::kDisabled);
|
||||
}
|
||||
|
||||
simple_string_dictionary_.reset(new crashpad::SimpleStringDictionary());
|
||||
crashpad_info->set_simple_annotations(simple_string_dictionary_.get());
|
||||
|
||||
SetInitialCrashKeyValues();
|
||||
if (process_type_.empty()) { // browser process
|
||||
database_ = crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
SetUploadToServer(upload_to_server);
|
||||
}
|
||||
}
|
||||
|
||||
void CrashReporterMac::SetUploadParameters() {
|
||||
upload_parameters_["platform"] = "darwin";
|
||||
}
|
||||
|
||||
// static
|
||||
CrashReporterMac* CrashReporterMac::GetInstance() {
|
||||
return base::Singleton<CrashReporterMac>::get();
|
||||
}
|
||||
|
||||
// static
|
||||
CrashReporter* CrashReporter::GetInstance() {
|
||||
return CrashReporterMac::GetInstance();
|
||||
}
|
||||
|
||||
} // namespace crash_reporter
|
141
shell/common/crash_reporter/crash_reporter_win.cc
Normal file
141
shell/common/crash_reporter/crash_reporter_win.cc
Normal file
|
@ -0,0 +1,141 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter_win.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/ui/inspectable_web_contents_impl.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/memory/singleton.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "electron/atom/common/api/api.mojom.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
||||
#include "third_party/crashpad/crashpad/client/crashpad_client.h"
|
||||
#include "third_party/crashpad/crashpad/client/crashpad_info.h"
|
||||
|
||||
#if defined(_WIN64)
|
||||
#include "gin/public/debug.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(_WIN64)
|
||||
int CrashForException(EXCEPTION_POINTERS* info) {
|
||||
auto* reporter = crash_reporter::CrashReporterWin::GetInstance();
|
||||
if (reporter->IsInitialized())
|
||||
reporter->GetCrashpadClient().DumpAndCrash(info);
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
CrashReporterWin::CrashReporterWin() {}
|
||||
|
||||
CrashReporterWin::~CrashReporterWin() {}
|
||||
|
||||
#if defined(_WIN64)
|
||||
void CrashReporterWin::SetUnhandledExceptionFilter() {
|
||||
gin::Debug::SetUnhandledExceptionCallback(&CrashForException);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CrashReporterWin::Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler) {
|
||||
// check whether crashpad has been initialized.
|
||||
// Only need to initialize once.
|
||||
if (simple_string_dictionary_)
|
||||
return;
|
||||
if (process_type_.empty()) { // browser process
|
||||
base::FilePath handler_path;
|
||||
base::PathService::Get(base::FILE_EXE, &handler_path);
|
||||
|
||||
std::vector<std::string> args = {
|
||||
"--no-rate-limit",
|
||||
"--no-upload-gzip", // not all servers accept gzip
|
||||
};
|
||||
args.push_back(base::StringPrintf("--type=%s", kCrashpadProcess));
|
||||
args.push_back(
|
||||
base::StringPrintf("--%s=%s", kCrashesDirectoryKey,
|
||||
base::UTF16ToUTF8(crashes_dir.value()).c_str()));
|
||||
crashpad_client_.StartHandler(handler_path, crashes_dir, crashes_dir,
|
||||
submit_url, StringMap(), args, true, false);
|
||||
UpdatePipeName();
|
||||
} else {
|
||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||
std::string pipe_name_utf8;
|
||||
if (env->GetVar(atom::kCrashpadPipeName, &pipe_name_utf8)) {
|
||||
base::string16 pipe_name = base::UTF8ToUTF16(pipe_name_utf8);
|
||||
if (!crashpad_client_.SetHandlerIPCPipe(pipe_name))
|
||||
LOG(ERROR) << "Failed to set handler IPC pipe name: " << pipe_name;
|
||||
} else {
|
||||
LOG(ERROR) << "Unable to get pipe name for crashpad";
|
||||
}
|
||||
}
|
||||
crashpad::CrashpadInfo* crashpad_info =
|
||||
crashpad::CrashpadInfo::GetCrashpadInfo();
|
||||
if (skip_system_crash_handler) {
|
||||
crashpad_info->set_system_crash_reporter_forwarding(
|
||||
crashpad::TriState::kDisabled);
|
||||
}
|
||||
simple_string_dictionary_.reset(new crashpad::SimpleStringDictionary());
|
||||
crashpad_info->set_simple_annotations(simple_string_dictionary_.get());
|
||||
|
||||
SetInitialCrashKeyValues();
|
||||
if (process_type_.empty()) { // browser process
|
||||
database_ = crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
SetUploadToServer(upload_to_server);
|
||||
}
|
||||
}
|
||||
|
||||
void CrashReporterWin::SetUploadParameters() {
|
||||
upload_parameters_["platform"] = "win32";
|
||||
}
|
||||
|
||||
crashpad::CrashpadClient& CrashReporterWin::GetCrashpadClient() {
|
||||
return crashpad_client_;
|
||||
}
|
||||
|
||||
void CrashReporterWin::UpdatePipeName() {
|
||||
std::string pipe_name =
|
||||
base::UTF16ToUTF8(crashpad_client_.GetHandlerIPCPipe());
|
||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||
env->SetVar(atom::kCrashpadPipeName, pipe_name);
|
||||
|
||||
// Notify all WebContents of the pipe name.
|
||||
const auto& pages = atom::InspectableWebContentsImpl::GetAll();
|
||||
for (auto* page : pages) {
|
||||
auto* frame_host = page->GetWebContents()->GetMainFrame();
|
||||
if (!frame_host)
|
||||
continue;
|
||||
|
||||
atom::mojom::ElectronRendererAssociatedPtr electron_ptr;
|
||||
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
mojo::MakeRequest(&electron_ptr));
|
||||
electron_ptr->UpdateCrashpadPipeName(pipe_name);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
CrashReporterWin* CrashReporterWin::GetInstance() {
|
||||
return base::Singleton<CrashReporterWin>::get();
|
||||
}
|
||||
|
||||
// static
|
||||
CrashReporter* CrashReporter::GetInstance() {
|
||||
return CrashReporterWin::GetInstance();
|
||||
}
|
||||
|
||||
} // namespace crash_reporter
|
52
shell/common/crash_reporter/crash_reporter_win.h
Normal file
52
shell/common/crash_reporter/crash_reporter_win.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_WIN_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_WIN_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter_crashpad.h"
|
||||
#include "third_party/crashpad/crashpad/client/crashpad_client.h"
|
||||
|
||||
namespace base {
|
||||
template <typename T>
|
||||
struct DefaultSingletonTraits;
|
||||
}
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
class CrashReporterWin : public CrashReporterCrashpad {
|
||||
public:
|
||||
static CrashReporterWin* GetInstance();
|
||||
#if defined(_WIN64)
|
||||
static void SetUnhandledExceptionFilter();
|
||||
#endif
|
||||
|
||||
void Init(const std::string& product_name,
|
||||
const std::string& company_name,
|
||||
const std::string& submit_url,
|
||||
const base::FilePath& crashes_dir,
|
||||
bool upload_to_server,
|
||||
bool skip_system_crash_handler) override;
|
||||
void SetUploadParameters() override;
|
||||
|
||||
crashpad::CrashpadClient& GetCrashpadClient();
|
||||
|
||||
private:
|
||||
friend struct base::DefaultSingletonTraits<CrashReporterWin>;
|
||||
CrashReporterWin();
|
||||
~CrashReporterWin() override;
|
||||
|
||||
void UpdatePipeName();
|
||||
|
||||
crashpad::CrashpadClient crashpad_client_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashReporterWin);
|
||||
};
|
||||
|
||||
} // namespace crash_reporter
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_WIN_H_
|
753
shell/common/crash_reporter/linux/crash_dump_handler.cc
Normal file
753
shell/common/crash_reporter/linux/crash_dump_handler.cc
Normal file
|
@ -0,0 +1,753 @@
|
|||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// For linux_syscall_support.h. This makes it safe to call embedded system
|
||||
// calls when in seccomp mode.
|
||||
|
||||
#include "atom/common/crash_reporter/linux/crash_dump_handler.h"
|
||||
|
||||
#include <poll.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
#include "breakpad/src/client/linux/minidump_writer/directory_reader.h"
|
||||
#include "breakpad/src/common/linux/linux_libc_support.h"
|
||||
#include "breakpad/src/common/memory_allocator.h"
|
||||
|
||||
#include "third_party/lss/linux_syscall_support.h"
|
||||
|
||||
// Some versions of gcc are prone to warn about unused return values. In cases
|
||||
// where we either a) know the call cannot fail, or b) there is nothing we
|
||||
// can do when a call fails, we mark the return code as ignored. This avoids
|
||||
// spurious compiler warnings.
|
||||
#define IGNORE_RET(x) \
|
||||
do { \
|
||||
if (x) \
|
||||
; \
|
||||
} while (0)
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
namespace {
|
||||
|
||||
// String buffer size to use to convert a uint64_t to string.
|
||||
const size_t kUint64StringSize = 21;
|
||||
|
||||
// Writes the value |v| as 16 hex characters to the memory pointed at by
|
||||
// |output|.
|
||||
void write_uint64_hex(char* output, uint64_t v) {
|
||||
static const char hextable[] = "0123456789abcdef";
|
||||
|
||||
for (int i = 15; i >= 0; --i) {
|
||||
output[i] = hextable[v & 15];
|
||||
v >>= 4;
|
||||
}
|
||||
}
|
||||
|
||||
// uint64_t version of my_int_len() from
|
||||
// breakpad/src/common/linux/linux_libc_support.h. Return the length of the
|
||||
// given, non-negative integer when expressed in base 10.
|
||||
unsigned my_uint64_len(uint64_t i) {
|
||||
if (!i)
|
||||
return 1;
|
||||
|
||||
unsigned len = 0;
|
||||
while (i) {
|
||||
len++;
|
||||
i /= 10;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// uint64_t version of my_uitos() from
|
||||
// breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative
|
||||
// integer to a string (not null-terminated).
|
||||
void my_uint64tos(char* output, uint64_t i, unsigned i_len) {
|
||||
for (unsigned index = i_len; index; --index, i /= 10)
|
||||
output[index - 1] = '0' + (i % 10);
|
||||
}
|
||||
|
||||
// Converts a struct timeval to milliseconds.
|
||||
uint64_t kernel_timeval_to_ms(struct kernel_timeval* tv) {
|
||||
uint64_t ret = tv->tv_sec; // Avoid overflow by explicitly using a uint64_t.
|
||||
ret *= 1000;
|
||||
ret += tv->tv_usec / 1000;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool my_isxdigit(char c) {
|
||||
return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
|
||||
}
|
||||
|
||||
size_t LengthWithoutTrailingSpaces(const char* str, size_t len) {
|
||||
while (len > 0 && str[len - 1] == ' ') {
|
||||
len--;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
// MIME substrings.
|
||||
const char g_rn[] = "\r\n";
|
||||
const char g_form_data_msg[] = "Content-Disposition: form-data; name=\"";
|
||||
const char g_quote_msg[] = "\"";
|
||||
const char g_dashdash_msg[] = "--";
|
||||
const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\"";
|
||||
const char g_content_type_msg[] = "Content-Type: application/octet-stream";
|
||||
|
||||
// MimeWriter manages an iovec for writing MIMEs to a file.
|
||||
class MimeWriter {
|
||||
public:
|
||||
static const int kIovCapacity = 30;
|
||||
static const size_t kMaxCrashChunkSize = 64;
|
||||
|
||||
MimeWriter(int fd, const char* const mime_boundary);
|
||||
~MimeWriter();
|
||||
|
||||
// Append boundary.
|
||||
virtual void AddBoundary();
|
||||
|
||||
// Append end of file boundary.
|
||||
virtual void AddEnd();
|
||||
|
||||
// Append key/value pair with specified sizes.
|
||||
virtual void AddPairData(const char* msg_type,
|
||||
size_t msg_type_size,
|
||||
const char* msg_data,
|
||||
size_t msg_data_size);
|
||||
|
||||
// Append key/value pair.
|
||||
void AddPairString(const char* msg_type, const char* msg_data) {
|
||||
AddPairData(msg_type, my_strlen(msg_type), msg_data, my_strlen(msg_data));
|
||||
}
|
||||
|
||||
// Append key/value pair, splitting value into chunks no larger than
|
||||
// |chunk_size|. |chunk_size| cannot be greater than |kMaxCrashChunkSize|.
|
||||
// The msg_type string will have a counter suffix to distinguish each chunk.
|
||||
virtual void AddPairDataInChunks(const char* msg_type,
|
||||
size_t msg_type_size,
|
||||
const char* msg_data,
|
||||
size_t msg_data_size,
|
||||
size_t chunk_size,
|
||||
bool strip_trailing_spaces);
|
||||
|
||||
// Add binary file contents to be uploaded with the specified filename.
|
||||
virtual void AddFileContents(const char* filename_msg,
|
||||
uint8_t* file_data,
|
||||
size_t file_size);
|
||||
|
||||
// Flush any pending iovecs to the output file.
|
||||
void Flush() {
|
||||
IGNORE_RET(sys_writev(fd_, iov_, iov_index_));
|
||||
iov_index_ = 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
void AddItem(const void* base, size_t size);
|
||||
// Minor performance trade-off for easier-to-maintain code.
|
||||
void AddString(const char* str) { AddItem(str, my_strlen(str)); }
|
||||
void AddItemWithoutTrailingSpaces(const void* base, size_t size);
|
||||
|
||||
struct kernel_iovec iov_[kIovCapacity];
|
||||
int iov_index_ = 0;
|
||||
|
||||
// Output file descriptor.
|
||||
int fd_ = -1;
|
||||
|
||||
const char* const mime_boundary_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(MimeWriter);
|
||||
};
|
||||
|
||||
MimeWriter::MimeWriter(int fd, const char* const mime_boundary)
|
||||
: fd_(fd), mime_boundary_(mime_boundary) {}
|
||||
|
||||
MimeWriter::~MimeWriter() {}
|
||||
|
||||
void MimeWriter::AddBoundary() {
|
||||
AddString(mime_boundary_);
|
||||
AddString(g_rn);
|
||||
}
|
||||
|
||||
void MimeWriter::AddEnd() {
|
||||
AddString(mime_boundary_);
|
||||
AddString(g_dashdash_msg);
|
||||
AddString(g_rn);
|
||||
}
|
||||
|
||||
void MimeWriter::AddPairData(const char* msg_type,
|
||||
size_t msg_type_size,
|
||||
const char* msg_data,
|
||||
size_t msg_data_size) {
|
||||
AddString(g_form_data_msg);
|
||||
AddItem(msg_type, msg_type_size);
|
||||
AddString(g_quote_msg);
|
||||
AddString(g_rn);
|
||||
AddString(g_rn);
|
||||
AddItem(msg_data, msg_data_size);
|
||||
AddString(g_rn);
|
||||
}
|
||||
|
||||
void MimeWriter::AddPairDataInChunks(const char* msg_type,
|
||||
size_t msg_type_size,
|
||||
const char* msg_data,
|
||||
size_t msg_data_size,
|
||||
size_t chunk_size,
|
||||
bool strip_trailing_spaces) {
|
||||
if (chunk_size > kMaxCrashChunkSize)
|
||||
return;
|
||||
|
||||
unsigned i = 0;
|
||||
size_t done = 0, msg_length = msg_data_size;
|
||||
|
||||
while (msg_length) {
|
||||
char num[kUint64StringSize];
|
||||
const unsigned num_len = my_uint_len(++i);
|
||||
my_uitos(num, i, num_len);
|
||||
|
||||
size_t chunk_len = std::min(chunk_size, msg_length);
|
||||
|
||||
AddString(g_form_data_msg);
|
||||
AddItem(msg_type, msg_type_size);
|
||||
AddItem(num, num_len);
|
||||
AddString(g_quote_msg);
|
||||
AddString(g_rn);
|
||||
AddString(g_rn);
|
||||
if (strip_trailing_spaces) {
|
||||
AddItemWithoutTrailingSpaces(msg_data + done, chunk_len);
|
||||
} else {
|
||||
AddItem(msg_data + done, chunk_len);
|
||||
}
|
||||
AddString(g_rn);
|
||||
AddBoundary();
|
||||
Flush();
|
||||
|
||||
done += chunk_len;
|
||||
msg_length -= chunk_len;
|
||||
}
|
||||
}
|
||||
|
||||
void MimeWriter::AddFileContents(const char* filename_msg,
|
||||
uint8_t* file_data,
|
||||
size_t file_size) {
|
||||
AddString(g_form_data_msg);
|
||||
AddString(filename_msg);
|
||||
AddString(g_rn);
|
||||
AddString(g_content_type_msg);
|
||||
AddString(g_rn);
|
||||
AddString(g_rn);
|
||||
AddItem(file_data, file_size);
|
||||
AddString(g_rn);
|
||||
}
|
||||
|
||||
void MimeWriter::AddItem(const void* base, size_t size) {
|
||||
// Check if the iovec is full and needs to be flushed to output file.
|
||||
if (iov_index_ == kIovCapacity) {
|
||||
Flush();
|
||||
}
|
||||
iov_[iov_index_].iov_base = const_cast<void*>(base);
|
||||
iov_[iov_index_].iov_len = size;
|
||||
++iov_index_;
|
||||
}
|
||||
|
||||
void MimeWriter::AddItemWithoutTrailingSpaces(const void* base, size_t size) {
|
||||
AddItem(base,
|
||||
LengthWithoutTrailingSpaces(static_cast<const char*>(base), size));
|
||||
}
|
||||
|
||||
void LoadDataFromFD(google_breakpad::PageAllocator* allocator,
|
||||
int fd,
|
||||
bool close_fd,
|
||||
uint8_t** file_data,
|
||||
size_t* size) {
|
||||
struct kernel_stat st;
|
||||
if (sys_fstat(fd, &st) != 0) {
|
||||
static const char msg[] = "Cannot upload crash dump: stat failed\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
if (close_fd)
|
||||
IGNORE_RET(sys_close(fd));
|
||||
return;
|
||||
}
|
||||
|
||||
*file_data = reinterpret_cast<uint8_t*>(allocator->Alloc(st.st_size));
|
||||
if (!(*file_data)) {
|
||||
static const char msg[] = "Cannot upload crash dump: cannot alloc\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
if (close_fd)
|
||||
IGNORE_RET(sys_close(fd));
|
||||
return;
|
||||
}
|
||||
my_memset(*file_data, 0xf, st.st_size);
|
||||
|
||||
*size = st.st_size;
|
||||
int byte_read = sys_read(fd, *file_data, *size);
|
||||
if (byte_read == -1) {
|
||||
static const char msg[] = "Cannot upload crash dump: read failed\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
if (close_fd)
|
||||
IGNORE_RET(sys_close(fd));
|
||||
return;
|
||||
}
|
||||
|
||||
if (close_fd)
|
||||
IGNORE_RET(sys_close(fd));
|
||||
}
|
||||
|
||||
void LoadDataFromFile(google_breakpad::PageAllocator* allocator,
|
||||
const char* filename,
|
||||
int* fd,
|
||||
uint8_t** file_data,
|
||||
size_t* size) {
|
||||
// WARNING: this code runs in a compromised context. It may not call into
|
||||
// libc nor allocate memory normally.
|
||||
*fd = sys_open(filename, O_RDONLY, 0);
|
||||
*size = 0;
|
||||
|
||||
if (*fd < 0) {
|
||||
static const char msg[] = "Cannot upload crash dump: failed to open\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
LoadDataFromFD(allocator, *fd, true, file_data, size);
|
||||
}
|
||||
|
||||
// Spawn the appropriate upload process for the current OS:
|
||||
// - generic Linux invokes wget.
|
||||
// - ChromeOS invokes crash_reporter.
|
||||
// |dumpfile| is the path to the dump data file.
|
||||
// |mime_boundary| is only used on Linux.
|
||||
// |exe_buf| is only used on CrOS and is the crashing process' name.
|
||||
void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
|
||||
const char* dumpfile,
|
||||
const char* mime_boundary,
|
||||
const char* exe_buf,
|
||||
google_breakpad::PageAllocator* allocator) {
|
||||
// The --header argument to wget looks like:
|
||||
// --header=Content-Type: multipart/form-data; boundary=XYZ
|
||||
// where the boundary has two fewer leading '-' chars
|
||||
static const char header_msg[] =
|
||||
"--header=Content-Type: multipart/form-data; boundary=";
|
||||
char* const header = reinterpret_cast<char*>(
|
||||
allocator->Alloc(sizeof(header_msg) - 1 + strlen(mime_boundary) - 2 + 1));
|
||||
memcpy(header, header_msg, sizeof(header_msg) - 1);
|
||||
memcpy(header + sizeof(header_msg) - 1, mime_boundary + 2,
|
||||
strlen(mime_boundary) - 2);
|
||||
// We grab the NUL byte from the end of |mime_boundary|.
|
||||
|
||||
// The --post-file argument to wget looks like:
|
||||
// --post-file=/tmp/...
|
||||
static const char post_file_msg[] = "--post-file=";
|
||||
char* const post_file = reinterpret_cast<char*>(
|
||||
allocator->Alloc(sizeof(post_file_msg) - 1 + strlen(dumpfile) + 1));
|
||||
memcpy(post_file, post_file_msg, sizeof(post_file_msg) - 1);
|
||||
memcpy(post_file + sizeof(post_file_msg) - 1, dumpfile, strlen(dumpfile));
|
||||
|
||||
static const char kWgetBinary[] = "/usr/bin/wget";
|
||||
const char* args[] = {
|
||||
kWgetBinary, header, post_file, info.upload_url,
|
||||
"--timeout=60", // Set a timeout so we don't hang forever.
|
||||
"--tries=1", // Don't retry if the upload fails.
|
||||
"--quiet", // Be silent.
|
||||
"-O", // output reply to /dev/null.
|
||||
"/dev/fd/3", NULL,
|
||||
};
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump: cannot exec "
|
||||
"/usr/bin/wget\n";
|
||||
execve(args[0], const_cast<char**>(args), environ);
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
sys__exit(1);
|
||||
}
|
||||
|
||||
// Runs in the helper process to wait for the upload process running
|
||||
// ExecUploadProcessOrTerminate() to finish. Returns the number of bytes written
|
||||
// to |fd| and save the written contents to |buf|.
|
||||
// |buf| needs to be big enough to hold |bytes_to_read| + 1 characters.
|
||||
size_t WaitForCrashReportUploadProcess(int fd,
|
||||
size_t bytes_to_read,
|
||||
char* buf) {
|
||||
size_t bytes_read = 0;
|
||||
|
||||
// Upload should finish in about 10 seconds. Add a few more 500 ms
|
||||
// internals to account for process startup time.
|
||||
for (size_t wait_count = 0; wait_count < 24; ++wait_count) {
|
||||
struct kernel_pollfd poll_fd;
|
||||
poll_fd.fd = fd;
|
||||
poll_fd.events = POLLIN | POLLPRI | POLLERR;
|
||||
int ret = sys_poll(&poll_fd, 1, 500);
|
||||
if (ret < 0) {
|
||||
// Error
|
||||
break;
|
||||
} else if (ret > 0) {
|
||||
// There is data to read.
|
||||
ssize_t len = HANDLE_EINTR(
|
||||
sys_read(fd, buf + bytes_read, bytes_to_read - bytes_read));
|
||||
if (len < 0)
|
||||
break;
|
||||
bytes_read += len;
|
||||
if (bytes_read == bytes_to_read)
|
||||
break;
|
||||
}
|
||||
// |ret| == 0 -> timed out, continue waiting.
|
||||
// or |bytes_read| < |bytes_to_read| still, keep reading.
|
||||
}
|
||||
buf[bytes_to_read] = 0; // Always NUL terminate the buffer.
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
// |buf| should be |expected_len| + 1 characters in size and NULL terminated.
|
||||
bool IsValidCrashReportId(const char* buf,
|
||||
size_t bytes_read,
|
||||
size_t expected_len) {
|
||||
if (bytes_read != expected_len)
|
||||
return false;
|
||||
for (size_t i = 0; i < bytes_read; ++i) {
|
||||
if (!my_isxdigit(buf[i]) && buf[i] != '-')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// |buf| should be |expected_len| + 1 characters in size and NULL terminated.
|
||||
void HandleCrashReportId(const char* buf,
|
||||
size_t bytes_read,
|
||||
size_t expected_len) {
|
||||
if (!IsValidCrashReportId(buf, bytes_read, expected_len)) {
|
||||
static const char msg[] = "Failed to get crash dump id.";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
WriteNewline();
|
||||
|
||||
static const char id_msg[] = "Report Id: ";
|
||||
WriteLog(id_msg, sizeof(id_msg) - 1);
|
||||
WriteLog(buf, bytes_read);
|
||||
WriteNewline();
|
||||
return;
|
||||
}
|
||||
|
||||
// Write crash dump id to stderr.
|
||||
static const char msg[] = "Crash dump id: ";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
WriteLog(buf, my_strlen(buf));
|
||||
WriteNewline();
|
||||
|
||||
// Write crash dump id to crash log as: seconds_since_epoch,crash_id
|
||||
struct kernel_timeval tv;
|
||||
if (!sys_gettimeofday(&tv, NULL)) {
|
||||
uint64_t time = kernel_timeval_to_ms(&tv) / 1000;
|
||||
char time_str[kUint64StringSize];
|
||||
const unsigned time_len = my_uint64_len(time);
|
||||
my_uint64tos(time_str, time, time_len);
|
||||
|
||||
const int kLogOpenFlags = O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC;
|
||||
int log_fd = sys_open(g_crash_log_path, kLogOpenFlags, 0600);
|
||||
if (log_fd > 0) {
|
||||
sys_write(log_fd, time_str, time_len);
|
||||
sys_write(log_fd, ",", 1);
|
||||
sys_write(log_fd, buf, my_strlen(buf));
|
||||
sys_write(log_fd, "\n", 1);
|
||||
IGNORE_RET(sys_close(log_fd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
char g_crash_log_path[256];
|
||||
|
||||
void HandleCrashDump(const BreakpadInfo& info) {
|
||||
int dumpfd;
|
||||
bool keep_fd = false;
|
||||
size_t dump_size;
|
||||
uint8_t* dump_data;
|
||||
google_breakpad::PageAllocator allocator;
|
||||
const char* exe_buf = NULL;
|
||||
|
||||
if (info.fd != -1) {
|
||||
// Dump is provided with an open FD.
|
||||
keep_fd = true;
|
||||
dumpfd = info.fd;
|
||||
|
||||
// The FD is pointing to the end of the file.
|
||||
// Rewind, we'll read the data next.
|
||||
if (lseek(dumpfd, 0, SEEK_SET) == -1) {
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump: failed to "
|
||||
"reposition minidump FD\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(dumpfd));
|
||||
return;
|
||||
}
|
||||
LoadDataFromFD(&allocator, info.fd, false, &dump_data, &dump_size);
|
||||
} else {
|
||||
// Dump is provided with a path.
|
||||
keep_fd = false;
|
||||
LoadDataFromFile(&allocator, info.filename, &dumpfd, &dump_data,
|
||||
&dump_size);
|
||||
}
|
||||
|
||||
// We need to build a MIME block for uploading to the server. Since we are
|
||||
// going to fork and run wget, it needs to be written to a temp file.
|
||||
const int ufd = sys_open("/dev/urandom", O_RDONLY, 0);
|
||||
if (ufd < 0) {
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump because /dev/urandom"
|
||||
" is missing\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
static const char temp_file_template[] =
|
||||
"/tmp/chromium-upload-XXXXXXXXXXXXXXXX";
|
||||
char temp_file[sizeof(temp_file_template)];
|
||||
int temp_file_fd = -1;
|
||||
if (keep_fd) {
|
||||
temp_file_fd = dumpfd;
|
||||
// Rewind the destination, we are going to overwrite it.
|
||||
if (lseek(dumpfd, 0, SEEK_SET) == -1) {
|
||||
static const char msg[] =
|
||||
"Cannot upload crash dump: failed to "
|
||||
"reposition minidump FD (2)\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(dumpfd));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (info.upload) {
|
||||
memcpy(temp_file, temp_file_template, sizeof(temp_file_template));
|
||||
|
||||
for (unsigned i = 0; i < 10; ++i) {
|
||||
uint64_t t;
|
||||
sys_read(ufd, &t, sizeof(t));
|
||||
write_uint64_hex(temp_file + sizeof(temp_file) - (16 + 1), t);
|
||||
|
||||
temp_file_fd = sys_open(temp_file, O_WRONLY | O_CREAT | O_EXCL, 0600);
|
||||
if (temp_file_fd >= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (temp_file_fd < 0) {
|
||||
static const char msg[] =
|
||||
"Failed to create temporary file in /tmp: "
|
||||
"cannot upload crash dump\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(ufd));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
temp_file_fd = sys_open(info.filename, O_WRONLY, 0600);
|
||||
if (temp_file_fd < 0) {
|
||||
static const char msg[] = "Failed to save crash dump: failed to open\n";
|
||||
WriteLog(msg, sizeof(msg) - 1);
|
||||
IGNORE_RET(sys_close(ufd));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The MIME boundary is 28 hyphens, followed by a 64-bit nonce and a NUL.
|
||||
char mime_boundary[28 + 16 + 1];
|
||||
my_memset(mime_boundary, '-', 28);
|
||||
uint64_t boundary_rand;
|
||||
sys_read(ufd, &boundary_rand, sizeof(boundary_rand));
|
||||
write_uint64_hex(mime_boundary + 28, boundary_rand);
|
||||
mime_boundary[28 + 16] = 0;
|
||||
IGNORE_RET(sys_close(ufd));
|
||||
|
||||
// The MIME block looks like this:
|
||||
// BOUNDARY \r\n
|
||||
// Content-Disposition: form-data; name="prod" \r\n \r\n
|
||||
// Chrome_Linux \r\n
|
||||
// BOUNDARY \r\n
|
||||
// Content-Disposition: form-data; name="ver" \r\n \r\n
|
||||
// 1.2.3.4 \r\n
|
||||
// BOUNDARY \r\n
|
||||
//
|
||||
// zero or one:
|
||||
// Content-Disposition: form-data; name="ptime" \r\n \r\n
|
||||
// abcdef \r\n
|
||||
// BOUNDARY \r\n
|
||||
//
|
||||
// zero or one:
|
||||
// Content-Disposition: form-data; name="ptype" \r\n \r\n
|
||||
// abcdef \r\n
|
||||
// BOUNDARY \r\n
|
||||
//
|
||||
// zero or one:
|
||||
// Content-Disposition: form-data; name="lsb-release" \r\n \r\n
|
||||
// abcdef \r\n
|
||||
// BOUNDARY \r\n
|
||||
//
|
||||
// zero or one:
|
||||
// Content-Disposition: form-data; name="oom-size" \r\n \r\n
|
||||
// 1234567890 \r\n
|
||||
// BOUNDARY \r\n
|
||||
//
|
||||
// zero or more (up to CrashKeyStorage::num_entries = 64):
|
||||
// Content-Disposition: form-data; name=crash-key-name \r\n
|
||||
// crash-key-value \r\n
|
||||
// BOUNDARY \r\n
|
||||
//
|
||||
// Content-Disposition: form-data; name="dump"; filename="dump" \r\n
|
||||
// Content-Type: application/octet-stream \r\n \r\n
|
||||
// <dump contents>
|
||||
// \r\n BOUNDARY -- \r\n
|
||||
|
||||
MimeWriter writer(temp_file_fd, mime_boundary);
|
||||
{
|
||||
writer.AddBoundary();
|
||||
if (info.pid > 0) {
|
||||
char pid_value_buf[kUint64StringSize];
|
||||
uint64_t pid_value_len = my_uint64_len(info.pid);
|
||||
my_uint64tos(pid_value_buf, info.pid, pid_value_len);
|
||||
static const char pid_key_name[] = "pid";
|
||||
writer.AddPairData(pid_key_name, sizeof(pid_key_name) - 1, pid_value_buf,
|
||||
pid_value_len);
|
||||
writer.AddBoundary();
|
||||
}
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
if (info.process_start_time > 0) {
|
||||
struct kernel_timeval tv;
|
||||
if (!sys_gettimeofday(&tv, NULL)) {
|
||||
uint64_t time = kernel_timeval_to_ms(&tv);
|
||||
if (time > info.process_start_time) {
|
||||
time -= info.process_start_time;
|
||||
char time_str[kUint64StringSize];
|
||||
const unsigned time_len = my_uint64_len(time);
|
||||
my_uint64tos(time_str, time, time_len);
|
||||
|
||||
static const char process_time_msg[] = "ptime";
|
||||
writer.AddPairData(process_time_msg, sizeof(process_time_msg) - 1,
|
||||
time_str, time_len);
|
||||
writer.AddBoundary();
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (info.distro_length) {
|
||||
static const char distro_msg[] = "lsb-release";
|
||||
writer.AddPairString(distro_msg, info.distro);
|
||||
writer.AddBoundary();
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
if (info.oom_size) {
|
||||
char oom_size_str[kUint64StringSize];
|
||||
const unsigned oom_size_len = my_uint64_len(info.oom_size);
|
||||
my_uint64tos(oom_size_str, info.oom_size, oom_size_len);
|
||||
static const char oom_size_msg[] = "oom-size";
|
||||
writer.AddPairData(oom_size_msg, sizeof(oom_size_msg) - 1, oom_size_str,
|
||||
oom_size_len);
|
||||
writer.AddBoundary();
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
if (info.crash_keys) {
|
||||
CrashKeyStorage::Iterator crash_key_iterator(*info.crash_keys);
|
||||
const CrashKeyStorage::Entry* entry;
|
||||
while ((entry = crash_key_iterator.Next())) {
|
||||
writer.AddPairString(entry->key, entry->value);
|
||||
writer.AddBoundary();
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
writer.AddFileContents(g_dump_msg, dump_data, dump_size);
|
||||
writer.AddEnd();
|
||||
writer.Flush();
|
||||
|
||||
IGNORE_RET(sys_close(temp_file_fd));
|
||||
|
||||
if (!info.upload)
|
||||
return;
|
||||
|
||||
const pid_t child = sys_fork();
|
||||
if (!child) {
|
||||
// Spawned helper process.
|
||||
//
|
||||
// This code is called both when a browser is crashing (in which case,
|
||||
// nothing really matters any more) and when a renderer/plugin crashes, in
|
||||
// which case we need to continue.
|
||||
//
|
||||
// Since we are a multithreaded app, if we were just to fork(), we might
|
||||
// grab file descriptors which have just been created in another thread and
|
||||
// hold them open for too long.
|
||||
//
|
||||
// Thus, we have to loop and try and close everything.
|
||||
const int fd = sys_open("/proc/self/fd", O_DIRECTORY | O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
for (unsigned i = 3; i < 8192; ++i)
|
||||
IGNORE_RET(sys_close(i));
|
||||
} else {
|
||||
google_breakpad::DirectoryReader reader(fd);
|
||||
const char* name;
|
||||
while (reader.GetNextEntry(&name)) {
|
||||
int i;
|
||||
if (my_strtoui(&i, name) && i > 2 && i != fd)
|
||||
IGNORE_RET(sys_close(i));
|
||||
reader.PopEntry();
|
||||
}
|
||||
|
||||
IGNORE_RET(sys_close(fd));
|
||||
}
|
||||
|
||||
IGNORE_RET(sys_setsid());
|
||||
|
||||
// Leave one end of a pipe in the upload process and watch for it getting
|
||||
// closed by the upload process exiting.
|
||||
int fds[2];
|
||||
if (sys_pipe(fds) >= 0) {
|
||||
const pid_t upload_child = sys_fork();
|
||||
if (!upload_child) {
|
||||
// Upload process.
|
||||
IGNORE_RET(sys_close(fds[0]));
|
||||
IGNORE_RET(sys_dup2(fds[1], 3));
|
||||
ExecUploadProcessOrTerminate(info, temp_file, mime_boundary, exe_buf,
|
||||
&allocator);
|
||||
}
|
||||
|
||||
// Helper process.
|
||||
if (upload_child > 0) {
|
||||
IGNORE_RET(sys_close(fds[1]));
|
||||
|
||||
const size_t kCrashIdLength = 36;
|
||||
char id_buf[kCrashIdLength + 1];
|
||||
size_t bytes_read =
|
||||
WaitForCrashReportUploadProcess(fds[0], kCrashIdLength, id_buf);
|
||||
HandleCrashReportId(id_buf, bytes_read, kCrashIdLength);
|
||||
|
||||
if (sys_waitpid(upload_child, NULL, WNOHANG) == 0) {
|
||||
// Upload process is still around, kill it.
|
||||
sys_kill(upload_child, SIGKILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper process.
|
||||
IGNORE_RET(sys_unlink(info.filename));
|
||||
IGNORE_RET(sys_unlink(temp_file));
|
||||
sys__exit(0);
|
||||
}
|
||||
|
||||
// Main browser process.
|
||||
if (child <= 0)
|
||||
return;
|
||||
(void)HANDLE_EINTR(sys_waitpid(child, NULL, 0));
|
||||
}
|
||||
|
||||
size_t WriteLog(const char* buf, size_t nbytes) {
|
||||
return sys_write(2, buf, nbytes);
|
||||
}
|
||||
|
||||
size_t WriteNewline() {
|
||||
return WriteLog("\n", 1);
|
||||
}
|
||||
|
||||
} // namespace crash_reporter
|
46
shell/common/crash_reporter/linux/crash_dump_handler.h
Normal file
46
shell/common/crash_reporter/linux/crash_dump_handler.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2014 GitHub, Inc.
|
||||
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_LINUX_CRASH_DUMP_HANDLER_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_LINUX_CRASH_DUMP_HANDLER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "breakpad/src/common/simple_string_dictionary.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
||||
typedef google_breakpad::NonAllocatingMap<256, 256, 64> CrashKeyStorage;
|
||||
|
||||
// BreakpadInfo describes a crash report.
|
||||
// The minidump information can either be contained in a file descriptor (fd) or
|
||||
// in a file (whose path is in filename).
|
||||
struct BreakpadInfo {
|
||||
int fd; // File descriptor to the Breakpad dump data.
|
||||
const char* filename; // Path to the Breakpad dump data.
|
||||
const char* distro; // Linux distro string.
|
||||
unsigned distro_length; // Length of |distro|.
|
||||
bool upload; // Whether to upload or save crash dump.
|
||||
uint64_t process_start_time; // Uptime of the crashing process.
|
||||
size_t oom_size; // Amount of memory requested if OOM.
|
||||
uint64_t pid; // PID where applicable.
|
||||
const char* upload_url; // URL to upload the minidump.
|
||||
CrashKeyStorage* crash_keys;
|
||||
};
|
||||
|
||||
void HandleCrashDump(const BreakpadInfo& info);
|
||||
|
||||
size_t WriteLog(const char* buf, size_t nbytes);
|
||||
size_t WriteNewline();
|
||||
|
||||
// Global variable storing the path of upload log.
|
||||
extern char g_crash_log_path[256];
|
||||
|
||||
} // namespace crash_reporter
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_LINUX_CRASH_DUMP_HANDLER_H_
|
508
shell/common/crash_reporter/win/crash_service.cc
Normal file
508
shell/common/crash_reporter/win/crash_service.cc
Normal file
|
@ -0,0 +1,508 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/win/crash_service.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <sddl.h>
|
||||
#include <fstream> // NOLINT
|
||||
#include <map>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/win/windows_version.h"
|
||||
#include "breakpad/src/client/windows/crash_generation/client_info.h"
|
||||
#include "breakpad/src/client/windows/crash_generation/crash_generation_server.h"
|
||||
#include "breakpad/src/client/windows/sender/crash_report_sender.h"
|
||||
|
||||
namespace breakpad {
|
||||
|
||||
namespace {
|
||||
|
||||
const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent";
|
||||
const wchar_t kClassNameFormat[] = L"$1CrashServiceWindow";
|
||||
|
||||
const wchar_t kTestPipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
|
||||
|
||||
const wchar_t kGoogleReportURL[] = L"https://clients2.google.com/cr/report";
|
||||
const wchar_t kCheckPointFile[] = L"crash_checkpoint.txt";
|
||||
|
||||
typedef std::map<std::wstring, std::wstring> CrashMap;
|
||||
|
||||
bool CustomInfoToMap(const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring& reporter_tag,
|
||||
CrashMap* map) {
|
||||
google_breakpad::CustomClientInfo info = client_info->GetCustomInfo();
|
||||
|
||||
for (uintptr_t i = 0; i < info.count; ++i) {
|
||||
(*map)[info.entries[i].name] = info.entries[i].value;
|
||||
}
|
||||
|
||||
(*map)[L"rept"] = reporter_tag;
|
||||
|
||||
return !map->empty();
|
||||
}
|
||||
|
||||
bool WriteCustomInfoToFile(const std::wstring& dump_path, const CrashMap& map) {
|
||||
std::wstring file_path(dump_path);
|
||||
size_t last_dot = file_path.rfind(L'.');
|
||||
if (last_dot == std::wstring::npos)
|
||||
return false;
|
||||
file_path.resize(last_dot);
|
||||
file_path += L".txt";
|
||||
|
||||
std::wofstream file(file_path.c_str(), std::ios_base::out |
|
||||
std::ios_base::app |
|
||||
std::ios::binary);
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
|
||||
CrashMap::const_iterator pos;
|
||||
for (pos = map.begin(); pos != map.end(); ++pos) {
|
||||
std::wstring line = pos->first;
|
||||
line += L':';
|
||||
line += pos->second;
|
||||
line += L'\n';
|
||||
file.write(line.c_str(), static_cast<std::streamsize>(line.length()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteReportIDToFile(const std::wstring& dump_path,
|
||||
const std::wstring& report_id) {
|
||||
std::wstring file_path(dump_path);
|
||||
size_t last_slash = file_path.rfind(L'\\');
|
||||
if (last_slash == std::wstring::npos)
|
||||
return false;
|
||||
file_path.resize(last_slash);
|
||||
file_path += L"\\uploads.log";
|
||||
|
||||
std::wofstream file(file_path.c_str(), std::ios_base::out |
|
||||
std::ios_base::app |
|
||||
std::ios::binary);
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
|
||||
int64_t seconds_since_epoch =
|
||||
(base::Time::Now() - base::Time::UnixEpoch()).InSeconds();
|
||||
std::wstring line = base::NumberToString16(seconds_since_epoch);
|
||||
line += L',';
|
||||
line += report_id;
|
||||
line += L'\n';
|
||||
file.write(line.c_str(), static_cast<std::streamsize>(line.length()));
|
||||
return true;
|
||||
}
|
||||
|
||||
// The window procedure task is to handle when a) the user logs off.
|
||||
// b) the system shuts down or c) when the user closes the window.
|
||||
LRESULT __stdcall CrashSvcWndProc(HWND hwnd,
|
||||
UINT message,
|
||||
WPARAM wparam,
|
||||
LPARAM lparam) {
|
||||
switch (message) {
|
||||
case WM_CLOSE:
|
||||
case WM_ENDSESSION:
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hwnd, message, wparam, lparam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This is the main and only application window.
|
||||
HWND g_top_window = NULL;
|
||||
|
||||
bool CreateTopWindow(HINSTANCE instance,
|
||||
const base::string16& application_name,
|
||||
bool visible) {
|
||||
base::string16 class_name =
|
||||
base::ReplaceStringPlaceholders(kClassNameFormat, application_name, NULL);
|
||||
|
||||
WNDCLASSEXW wcx = {0};
|
||||
wcx.cbSize = sizeof(wcx);
|
||||
wcx.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcx.lpfnWndProc = CrashSvcWndProc;
|
||||
wcx.hInstance = instance;
|
||||
wcx.lpszClassName = class_name.c_str();
|
||||
::RegisterClassExW(&wcx);
|
||||
DWORD style = visible ? WS_POPUPWINDOW | WS_VISIBLE : WS_OVERLAPPED;
|
||||
|
||||
// The window size is zero but being a popup window still shows in the
|
||||
// task bar and can be closed using the system menu or using task manager.
|
||||
HWND window = CreateWindowExW(0, wcx.lpszClassName, L"crash service", style,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL,
|
||||
instance, NULL);
|
||||
if (!window)
|
||||
return false;
|
||||
|
||||
::UpdateWindow(window);
|
||||
VLOG(1) << "window handle is " << window;
|
||||
g_top_window = window;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Simple helper class to keep the process alive until the current request
|
||||
// finishes.
|
||||
class ProcessingLock {
|
||||
public:
|
||||
ProcessingLock() { ::InterlockedIncrement(&op_count_); }
|
||||
~ProcessingLock() { ::InterlockedDecrement(&op_count_); }
|
||||
static bool IsWorking() { return (op_count_ != 0); }
|
||||
|
||||
private:
|
||||
static volatile LONG op_count_;
|
||||
};
|
||||
|
||||
volatile LONG ProcessingLock::op_count_ = 0;
|
||||
|
||||
// This structure contains the information that the worker thread needs to
|
||||
// send a crash dump to the server.
|
||||
struct DumpJobInfo {
|
||||
DWORD pid;
|
||||
CrashService* self;
|
||||
CrashMap map;
|
||||
std::wstring dump_path;
|
||||
|
||||
DumpJobInfo(DWORD process_id,
|
||||
CrashService* service,
|
||||
const CrashMap& crash_map,
|
||||
const std::wstring& path)
|
||||
: pid(process_id), self(service), map(crash_map), dump_path(path) {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Command line switches:
|
||||
const char CrashService::kMaxReports[] = "max-reports";
|
||||
const char CrashService::kNoWindow[] = "no-window";
|
||||
const char CrashService::kReporterTag[] = "reporter";
|
||||
const char CrashService::kDumpsDir[] = "dumps-dir";
|
||||
const char CrashService::kPipeName[] = "pipe-name";
|
||||
const char CrashService::kReporterURL[] = "reporter-url";
|
||||
|
||||
CrashService::CrashService() {}
|
||||
|
||||
CrashService::~CrashService() {
|
||||
base::AutoLock lock(sending_);
|
||||
delete dumper_;
|
||||
delete sender_;
|
||||
}
|
||||
|
||||
bool CrashService::Initialize(const base::string16& application_name,
|
||||
const base::FilePath& operating_dir,
|
||||
const base::FilePath& dumps_path) {
|
||||
using google_breakpad::CrashGenerationServer;
|
||||
using google_breakpad::CrashReportSender;
|
||||
|
||||
std::wstring pipe_name = kTestPipeName;
|
||||
int max_reports = -1;
|
||||
|
||||
// The checkpoint file allows CrashReportSender to enforce the maximum
|
||||
// reports per day quota. Does not seem to serve any other purpose.
|
||||
base::FilePath checkpoint_path = operating_dir.Append(kCheckPointFile);
|
||||
|
||||
base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
|
||||
|
||||
base::FilePath dumps_path_to_use = dumps_path;
|
||||
|
||||
if (cmd_line.HasSwitch(kDumpsDir)) {
|
||||
dumps_path_to_use =
|
||||
base::FilePath(cmd_line.GetSwitchValueNative(kDumpsDir));
|
||||
}
|
||||
|
||||
// We can override the send reports quota with a command line switch.
|
||||
if (cmd_line.HasSwitch(kMaxReports))
|
||||
max_reports = _wtoi(cmd_line.GetSwitchValueNative(kMaxReports).c_str());
|
||||
|
||||
// Allow the global pipe name to be overridden for better testability.
|
||||
if (cmd_line.HasSwitch(kPipeName))
|
||||
pipe_name = cmd_line.GetSwitchValueNative(kPipeName);
|
||||
|
||||
if (max_reports > 0) {
|
||||
// Create the http sender object.
|
||||
sender_ = new CrashReportSender(checkpoint_path.value());
|
||||
sender_->set_max_reports_per_day(max_reports);
|
||||
}
|
||||
|
||||
SECURITY_ATTRIBUTES security_attributes = {0};
|
||||
SECURITY_DESCRIPTOR* security_descriptor =
|
||||
reinterpret_cast<SECURITY_DESCRIPTOR*>(
|
||||
GetSecurityDescriptorForLowIntegrity());
|
||||
DCHECK(security_descriptor != NULL);
|
||||
|
||||
security_attributes.nLength = sizeof(security_attributes);
|
||||
security_attributes.lpSecurityDescriptor = security_descriptor;
|
||||
security_attributes.bInheritHandle = FALSE;
|
||||
|
||||
// Create the OOP crash generator object.
|
||||
dumper_ = new CrashGenerationServer(
|
||||
pipe_name, &security_attributes, &CrashService::OnClientConnected, this,
|
||||
&CrashService::OnClientDumpRequest, this, &CrashService::OnClientExited,
|
||||
this, NULL, NULL, true, &dumps_path_to_use.value());
|
||||
|
||||
if (!dumper_) {
|
||||
LOG(ERROR) << "could not create dumper";
|
||||
if (security_attributes.lpSecurityDescriptor)
|
||||
LocalFree(security_attributes.lpSecurityDescriptor);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CreateTopWindow(::GetModuleHandleW(NULL), application_name,
|
||||
!cmd_line.HasSwitch(kNoWindow))) {
|
||||
LOG(ERROR) << "could not create window";
|
||||
if (security_attributes.lpSecurityDescriptor)
|
||||
LocalFree(security_attributes.lpSecurityDescriptor);
|
||||
return false;
|
||||
}
|
||||
|
||||
reporter_tag_ = L"crash svc";
|
||||
if (cmd_line.HasSwitch(kReporterTag))
|
||||
reporter_tag_ = cmd_line.GetSwitchValueNative(kReporterTag);
|
||||
|
||||
reporter_url_ = kGoogleReportURL;
|
||||
if (cmd_line.HasSwitch(kReporterURL))
|
||||
reporter_url_ = cmd_line.GetSwitchValueNative(kReporterURL);
|
||||
|
||||
// Log basic information.
|
||||
VLOG(1) << "pipe name is " << pipe_name << "\ndumps at "
|
||||
<< dumps_path_to_use.value();
|
||||
|
||||
if (sender_) {
|
||||
VLOG(1) << "checkpoint is " << checkpoint_path.value() << "\nserver is "
|
||||
<< reporter_url_ << "\nmaximum " << sender_->max_reports_per_day()
|
||||
<< " reports/day"
|
||||
<< "\nreporter is " << reporter_tag_;
|
||||
}
|
||||
// Start servicing clients.
|
||||
if (!dumper_->Start()) {
|
||||
LOG(ERROR) << "could not start dumper";
|
||||
if (security_attributes.lpSecurityDescriptor)
|
||||
LocalFree(security_attributes.lpSecurityDescriptor);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (security_attributes.lpSecurityDescriptor)
|
||||
LocalFree(security_attributes.lpSecurityDescriptor);
|
||||
|
||||
// Create or open an event to signal the browser process that the crash
|
||||
// service is initialized.
|
||||
base::string16 wait_name =
|
||||
base::ReplaceStringPlaceholders(kWaitEventFormat, application_name, NULL);
|
||||
HANDLE wait_event = ::CreateEventW(NULL, TRUE, TRUE, wait_name.c_str());
|
||||
::SetEvent(wait_event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CrashService::OnClientConnected(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info) {
|
||||
ProcessingLock lock;
|
||||
VLOG(1) << "client start. pid = " << client_info->pid();
|
||||
CrashService* self = static_cast<CrashService*>(context);
|
||||
::InterlockedIncrement(&self->clients_connected_);
|
||||
}
|
||||
|
||||
void CrashService::OnClientExited(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info) {
|
||||
ProcessingLock processing_lock;
|
||||
VLOG(1) << "client end. pid = " << client_info->pid();
|
||||
CrashService* self = static_cast<CrashService*>(context);
|
||||
::InterlockedIncrement(&self->clients_terminated_);
|
||||
|
||||
if (!self->sender_)
|
||||
return;
|
||||
|
||||
// When we are instructed to send reports we need to exit if there are
|
||||
// no more clients to service. The next client that runs will start us.
|
||||
// Only chrome.exe starts crash_service with a non-zero max_reports.
|
||||
if (self->clients_connected_ > self->clients_terminated_)
|
||||
return;
|
||||
if (self->sender_->max_reports_per_day() > 0) {
|
||||
// Wait for the other thread to send crashes, if applicable. The sender
|
||||
// thread takes the sending_ lock, so the sleep is just to give it a
|
||||
// chance to start.
|
||||
::Sleep(1000);
|
||||
base::AutoLock lock(self->sending_);
|
||||
// Some people can restart chrome very fast, check again if we have
|
||||
// a new client before exiting for real.
|
||||
if (self->clients_connected_ == self->clients_terminated_) {
|
||||
VLOG(1) << "zero clients. exiting";
|
||||
::PostMessage(g_top_window, WM_CLOSE, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CrashService::OnClientDumpRequest(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path) {
|
||||
ProcessingLock lock;
|
||||
|
||||
if (!file_path) {
|
||||
LOG(ERROR) << "dump with no file path";
|
||||
return;
|
||||
}
|
||||
if (!client_info) {
|
||||
LOG(ERROR) << "dump with no client info";
|
||||
return;
|
||||
}
|
||||
|
||||
CrashService* self = static_cast<CrashService*>(context);
|
||||
if (!self) {
|
||||
LOG(ERROR) << "dump with no context";
|
||||
return;
|
||||
}
|
||||
|
||||
CrashMap map;
|
||||
CustomInfoToMap(client_info, self->reporter_tag_, &map);
|
||||
|
||||
// Move dump file to the directory under client breakpad dump location.
|
||||
base::FilePath dump_location = base::FilePath(*file_path);
|
||||
CrashMap::const_iterator it = map.find(L"breakpad-dump-location");
|
||||
if (it != map.end()) {
|
||||
base::FilePath alternate_dump_location = base::FilePath(it->second);
|
||||
base::CreateDirectoryW(alternate_dump_location);
|
||||
alternate_dump_location =
|
||||
alternate_dump_location.Append(dump_location.BaseName());
|
||||
base::Move(dump_location, alternate_dump_location);
|
||||
dump_location = alternate_dump_location;
|
||||
}
|
||||
|
||||
DWORD pid = client_info->pid();
|
||||
VLOG(1) << "dump for pid = " << pid << " is " << dump_location.value();
|
||||
|
||||
if (!WriteCustomInfoToFile(dump_location.value(), map)) {
|
||||
LOG(ERROR) << "could not write custom info file";
|
||||
}
|
||||
|
||||
if (!self->sender_ || map.find(L"skip_upload") != map.end())
|
||||
return;
|
||||
|
||||
// Send the crash dump using a worker thread. This operation has retry
|
||||
// logic in case there is no internet connection at the time.
|
||||
DumpJobInfo* dump_job =
|
||||
new DumpJobInfo(pid, self, map, dump_location.value());
|
||||
if (!::QueueUserWorkItem(&CrashService::AsyncSendDump, dump_job,
|
||||
WT_EXECUTELONGFUNCTION)) {
|
||||
LOG(ERROR) << "could not queue job";
|
||||
}
|
||||
}
|
||||
|
||||
// We are going to try sending the report several times. If we can't send,
|
||||
// we sleep from one minute to several hours depending on the retry round.
|
||||
DWORD CrashService::AsyncSendDump(void* context) {
|
||||
if (!context)
|
||||
return 0;
|
||||
|
||||
DumpJobInfo* info = static_cast<DumpJobInfo*>(context);
|
||||
|
||||
std::wstring report_id = L"<unsent>";
|
||||
|
||||
const DWORD kOneMinute = 60 * 1000;
|
||||
const DWORD kOneHour = 60 * kOneMinute;
|
||||
|
||||
const DWORD kSleepSchedule[] = {24 * kOneHour, 8 * kOneHour, 4 * kOneHour,
|
||||
kOneHour, 15 * kOneMinute, 0};
|
||||
|
||||
int retry_round = base::size(kSleepSchedule) - 1;
|
||||
|
||||
do {
|
||||
::Sleep(kSleepSchedule[retry_round]);
|
||||
{
|
||||
// Take the server lock while sending. This also prevent early
|
||||
// termination of the service object.
|
||||
base::AutoLock lock(info->self->sending_);
|
||||
VLOG(1) << "trying to send report for pid = " << info->pid;
|
||||
std::map<std::wstring, std::wstring> file_map;
|
||||
file_map[L"upload_file_minidump"] = info->dump_path;
|
||||
google_breakpad::ReportResult send_result =
|
||||
info->self->sender_->SendCrashReport(info->self->reporter_url_,
|
||||
info->map, file_map, &report_id);
|
||||
switch (send_result) {
|
||||
case google_breakpad::RESULT_FAILED:
|
||||
report_id = L"<network issue>";
|
||||
break;
|
||||
case google_breakpad::RESULT_REJECTED:
|
||||
report_id = L"<rejected>";
|
||||
++info->self->requests_handled_;
|
||||
retry_round = 0;
|
||||
break;
|
||||
case google_breakpad::RESULT_SUCCEEDED:
|
||||
++info->self->requests_sent_;
|
||||
++info->self->requests_handled_;
|
||||
retry_round = 0;
|
||||
WriteReportIDToFile(info->dump_path, report_id);
|
||||
break;
|
||||
case google_breakpad::RESULT_THROTTLED:
|
||||
report_id = L"<throttled>";
|
||||
break;
|
||||
default:
|
||||
report_id = L"<unknown>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VLOG(1) << "dump for pid =" << info->pid << " crash2 id =" << report_id;
|
||||
--retry_round;
|
||||
} while (retry_round >= 0);
|
||||
|
||||
if (!::DeleteFileW(info->dump_path.c_str()))
|
||||
LOG(WARNING) << "could not delete " << info->dump_path;
|
||||
|
||||
delete info;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CrashService::ProcessingLoop() {
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
VLOG(1) << "session ending..";
|
||||
while (ProcessingLock::IsWorking()) {
|
||||
::Sleep(50);
|
||||
}
|
||||
|
||||
VLOG(1) << "clients connected :" << clients_connected_
|
||||
<< "\nclients terminated :" << clients_terminated_
|
||||
<< "\ndumps serviced :" << requests_handled_
|
||||
<< "\ndumps reported :" << requests_sent_;
|
||||
|
||||
return static_cast<int>(msg.wParam);
|
||||
}
|
||||
|
||||
PSECURITY_DESCRIPTOR CrashService::GetSecurityDescriptorForLowIntegrity() {
|
||||
// Build the SDDL string for the label.
|
||||
std::wstring sddl = L"S:(ML;;NW;;;S-1-16-4096)";
|
||||
|
||||
PSECURITY_DESCRIPTOR sec_desc = NULL;
|
||||
|
||||
PACL sacl = NULL;
|
||||
BOOL sacl_present = FALSE;
|
||||
BOOL sacl_defaulted = FALSE;
|
||||
|
||||
if (::ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||
sddl.c_str(), SDDL_REVISION, &sec_desc, NULL)) {
|
||||
if (::GetSecurityDescriptorSacl(sec_desc, &sacl_present, &sacl,
|
||||
&sacl_defaulted)) {
|
||||
return sec_desc;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace breakpad
|
130
shell/common/crash_reporter/win/crash_service.h
Normal file
130
shell/common/crash_reporter/win/crash_service.h
Normal file
|
@ -0,0 +1,130 @@
|
|||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_WIN_CRASH_SERVICE_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_WIN_CRASH_SERVICE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include <windows.h>
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
namespace google_breakpad {
|
||||
|
||||
class CrashReportSender;
|
||||
class CrashGenerationServer;
|
||||
class ClientInfo;
|
||||
|
||||
} // namespace google_breakpad
|
||||
|
||||
namespace breakpad {
|
||||
|
||||
// This class implements an out-of-process crash server. It uses breakpad's
|
||||
// CrashGenerationServer and CrashReportSender to generate and then send the
|
||||
// crash dumps. Internally, it uses OS specific pipe to allow applications to
|
||||
// register for crash dumps and later on when a registered application crashes
|
||||
// it will signal an event that causes this code to wake up and perform a
|
||||
// crash dump on the signaling process. The dump is then stored on disk and
|
||||
// possibly sent to the crash2 servers.
|
||||
class CrashService {
|
||||
public:
|
||||
CrashService();
|
||||
~CrashService();
|
||||
|
||||
// Starts servicing crash dumps. Returns false if it failed. Do not use
|
||||
// other members in that case. |operating_dir| is where the CrashService
|
||||
// should store breakpad's checkpoint file. |dumps_path| is the directory
|
||||
// where the crash dumps should be stored.
|
||||
bool Initialize(const base::string16& application_name,
|
||||
const base::FilePath& operating_dir,
|
||||
const base::FilePath& dumps_path);
|
||||
|
||||
// Command line switches:
|
||||
//
|
||||
// --max-reports=<number>
|
||||
// Allows to override the maximum number for reports per day. Normally
|
||||
// the crash dumps are never sent so if you want to send any you must
|
||||
// specify a positive number here.
|
||||
static const char kMaxReports[];
|
||||
// --no-window
|
||||
// Does not create a visible window on the desktop. The window does not have
|
||||
// any other functionality other than allowing the crash service to be
|
||||
// gracefully closed.
|
||||
static const char kNoWindow[];
|
||||
// --reporter=<string>
|
||||
// Allows to specify a custom string that appears on the detail crash report
|
||||
// page in the crash server. This should be a 25 chars or less string.
|
||||
// The default tag if not specified is 'crash svc'.
|
||||
static const char kReporterTag[];
|
||||
// --dumps-dir=<directory-path>
|
||||
// Override the directory to which crash dump files will be written.
|
||||
static const char kDumpsDir[];
|
||||
// --pipe-name=<string>
|
||||
// Override the name of the Windows named pipe on which we will
|
||||
// listen for crash dump request messages.
|
||||
static const char kPipeName[];
|
||||
// --reporter-url=<string>
|
||||
// Override the URL to which crash reports will be sent to.
|
||||
static const char kReporterURL[];
|
||||
|
||||
// Returns number of crash dumps handled.
|
||||
int requests_handled() const { return requests_handled_; }
|
||||
// Returns number of crash clients registered.
|
||||
int clients_connected() const { return clients_connected_; }
|
||||
// Returns number of crash clients terminated.
|
||||
int clients_terminated() const { return clients_terminated_; }
|
||||
|
||||
// Starts the processing loop. This function does not return unless the
|
||||
// user is logging off or the user closes the crash service window. The
|
||||
// return value is a good number to pass in ExitProcess().
|
||||
int ProcessingLoop();
|
||||
|
||||
private:
|
||||
static void OnClientConnected(void* context,
|
||||
const google_breakpad::ClientInfo* client_info);
|
||||
|
||||
static void OnClientDumpRequest(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path);
|
||||
|
||||
static void OnClientExited(void* context,
|
||||
const google_breakpad::ClientInfo* client_info);
|
||||
|
||||
// This routine sends the crash dump to the server. It takes the sending_
|
||||
// lock when it is performing the send.
|
||||
static DWORD __stdcall AsyncSendDump(void* context);
|
||||
|
||||
// Returns the security descriptor which access to low integrity processes
|
||||
// The caller is supposed to free the security descriptor by calling
|
||||
// LocalFree.
|
||||
PSECURITY_DESCRIPTOR GetSecurityDescriptorForLowIntegrity();
|
||||
|
||||
google_breakpad::CrashGenerationServer* dumper_ = nullptr;
|
||||
google_breakpad::CrashReportSender* sender_ = nullptr;
|
||||
|
||||
// the extra tag sent to the server with each dump.
|
||||
std::wstring reporter_tag_;
|
||||
|
||||
// receiver URL of crash reports.
|
||||
std::wstring reporter_url_;
|
||||
|
||||
// clients serviced statistics:
|
||||
int requests_handled_ = 0;
|
||||
int requests_sent_ = 0;
|
||||
volatile LONG clients_connected_ = 0;
|
||||
volatile LONG clients_terminated_ = 0;
|
||||
base::Lock sending_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashService);
|
||||
};
|
||||
|
||||
} // namespace breakpad
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_WIN_CRASH_SERVICE_H_
|
81
shell/common/crash_reporter/win/crash_service_main.cc
Normal file
81
shell/common/crash_reporter/win/crash_service_main.cc
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/crash_reporter/win/crash_service_main.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/crash_reporter/crash_reporter.h"
|
||||
#include "atom/common/crash_reporter/win/crash_service.h"
|
||||
#include "base/at_exit.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "third_party/crashpad/crashpad/handler/handler_main.h"
|
||||
|
||||
namespace crash_service {
|
||||
|
||||
namespace {
|
||||
|
||||
const wchar_t kStandardLogFile[] = L"operation_log.txt";
|
||||
|
||||
void InvalidParameterHandler(const wchar_t*,
|
||||
const wchar_t*,
|
||||
const wchar_t*,
|
||||
unsigned int,
|
||||
uintptr_t) {
|
||||
// noop.
|
||||
}
|
||||
|
||||
bool CreateCrashServiceDirectory(const base::FilePath& temp_dir) {
|
||||
if (!base::PathExists(temp_dir)) {
|
||||
if (!base::CreateDirectory(temp_dir))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveArgs(std::vector<char*>* args) {
|
||||
args->erase(
|
||||
std::remove_if(args->begin(), args->end(), [](const std::string& str) {
|
||||
return base::StartsWith(str, "--type", base::CompareCase::SENSITIVE) ||
|
||||
base::StartsWith(
|
||||
str,
|
||||
std::string("--") + crash_reporter::kCrashesDirectoryKey,
|
||||
base::CompareCase::INSENSITIVE_ASCII);
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace.
|
||||
|
||||
int Main(std::vector<char*>* args) {
|
||||
// Ignore invalid parameter errors.
|
||||
_set_invalid_parameter_handler(InvalidParameterHandler);
|
||||
|
||||
// Initialize all Chromium things.
|
||||
base::AtExitManager exit_manager;
|
||||
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
|
||||
// We use/create a directory under the user's temp folder, for logging.
|
||||
base::FilePath operating_dir(
|
||||
cmd_line->GetSwitchValueNative(crash_reporter::kCrashesDirectoryKey));
|
||||
CreateCrashServiceDirectory(operating_dir);
|
||||
base::FilePath log_file = operating_dir.Append(kStandardLogFile);
|
||||
|
||||
// Logging to stderr (to help with debugging failures on the
|
||||
// buildbots) and to a file.
|
||||
logging::LoggingSettings settings;
|
||||
settings.logging_dest = logging::LOG_TO_ALL;
|
||||
settings.log_file = log_file.value().c_str();
|
||||
logging::InitLogging(settings);
|
||||
// Logging with pid, tid and timestamp.
|
||||
logging::SetLogItems(true, true, true, false);
|
||||
|
||||
// Crashpad cannot handle unknown arguments, so we need to remove it
|
||||
RemoveArgs(args);
|
||||
return crashpad::HandlerMain(args->size(), args->data(), nullptr);
|
||||
}
|
||||
|
||||
} // namespace crash_service
|
17
shell/common/crash_reporter/win/crash_service_main.h
Normal file
17
shell/common/crash_reporter/win/crash_service_main.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2013 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_CRASH_REPORTER_WIN_CRASH_SERVICE_MAIN_H_
|
||||
#define ATOM_COMMON_CRASH_REPORTER_WIN_CRASH_SERVICE_MAIN_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace crash_service {
|
||||
|
||||
// Program entry, should be called by main();
|
||||
int Main(std::vector<char*>* args);
|
||||
|
||||
} // namespace crash_service
|
||||
|
||||
#endif // ATOM_COMMON_CRASH_REPORTER_WIN_CRASH_SERVICE_MAIN_H_
|
Loading…
Add table
Add a link
Reference in a new issue