linux: Move Cros crash handling to CrosCrashReportExceptionHandler

Change-Id: I80686ddc35b03fa213481e35dc494a40fbdd551a
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1775222
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Joshua Peraza 2019-08-30 11:51:47 -07:00 committed by Commit Bot
parent 80473094a4
commit cd92fba233
14 changed files with 453 additions and 178 deletions

View File

@ -51,6 +51,13 @@ static_library("handler") {
]
}
if (crashpad_is_linux) {
sources += [
"linux/cros_crash_report_exception_handler.cc",
"linux/cros_crash_report_exception_handler.h",
]
}
if (crashpad_is_win) {
sources += [
"win/crash_report_exception_handler.cc",

View File

@ -56,6 +56,10 @@
#include "util/string/split_string.h"
#include "util/synchronization/semaphore.h"
#if defined(OS_CHROMEOS)
#include "handler/linux/cros_crash_report_exception_handler.h"
#endif
#if defined(OS_LINUX) || defined(OS_ANDROID)
#include <unistd.h>
@ -157,6 +161,9 @@ void Usage(const base::FilePath& me) {
#endif // OS_LINUX || OS_ANDROID
" --url=URL send crash reports to this Breakpad server URL,\n"
" only if uploads are enabled for the database\n"
#if defined(OS_CHROMEOS)
" --use-cros-crash-reporter\n"
#endif // OS_CHROMEOS
" --help display this help and exit\n"
" --version output version information and exit\n",
me.value().c_str());
@ -188,6 +195,9 @@ struct Options {
bool periodic_tasks;
bool rate_limit;
bool upload_gzip;
#if defined(OS_CHROMEOS)
bool use_cros_crash_reporter;
#endif // OS_CHROMEOS
};
// Splits |key_value| on '=' and inserts the resulting key and value into |map|.
@ -559,6 +569,9 @@ int HandlerMain(int argc,
kOptionTraceParentWithException,
#endif
kOptionURL,
#if defined(OS_CHROMEOS)
kOptionUseCrosCrashReporter,
#endif // OS_CHROMEOS
// Standard options.
kOptionHelp = -2,
@ -624,6 +637,12 @@ int HandlerMain(int argc,
kOptionTraceParentWithException},
#endif // OS_LINUX || OS_ANDROID
{"url", required_argument, nullptr, kOptionURL},
#if defined(OS_CHROEMOS)
{"use-cros-crash-reporter",
no_argument,
nullptr,
kOptionUseCrosCrashReporter},
#endif // OS_CHROMEOS
{"help", no_argument, nullptr, kOptionHelp},
{"version", no_argument, nullptr, kOptionVersion},
{nullptr, 0, nullptr, 0},
@ -765,6 +784,12 @@ int HandlerMain(int argc,
options.url = optarg;
break;
}
#if defined(OS_CHROMEOS)
case kOptionUseCrosCrashReporter: {
options.use_cros_crash_reporter = true;
break;
}
#endif // OS_CHROMEOS
case kOptionHelp: {
Usage(me);
MetricsRecordExit(Metrics::LifetimeMilestone::kExitedEarly);
@ -890,7 +915,27 @@ int HandlerMain(int argc,
upload_thread.Get()->Start();
}
CrashReportExceptionHandler exception_handler(
#if defined(OS_LINUX) || defined(OS_ANDROID)
std::unique_ptr<ExceptionHandlerServer::Delegate> exception_handler;
#else
std::unique_ptr<CrashReportExceptionHandler> exception_handler;
#endif
#if defined(OS_CHROMEOS)
if (options.use_cros_crash_reporter) {
exception_handler = std::make_unique<CrosCrashReportExceptionHandler>(
database.get(),
&options.annotations,
user_stream_sources);
} else {
exception_handler = std::make_unique<CrashReportExceptionHandler>(
database.get(),
static_cast<CrashReportUploadThread*>(upload_thread.Get()),
&options.annotations,
user_stream_sources);
}
#else
exception_handler = std::make_unique<CrashReportExceptionHandler>(
database.get(),
static_cast<CrashReportUploadThread*>(upload_thread.Get()),
&options.annotations,
@ -899,14 +944,15 @@ int HandlerMain(int argc,
nullptr,
#endif
user_stream_sources);
#endif // OS_CHROMEOS
#if defined(OS_LINUX) || defined(OS_ANDROID)
#if defined(OS_LINUX) || defined(OS_ANDROID)
if (options.exception_information_address) {
ExceptionHandlerProtocol::ClientInformation info;
info.exception_information_address = options.exception_information_address;
info.sanitization_information_address =
options.sanitization_information_address;
return exception_handler.HandleException(getppid(), geteuid(), info)
return exception_handler->HandleException(getppid(), geteuid(), info)
? EXIT_SUCCESS
: ExitFailure();
}
@ -1012,7 +1058,7 @@ int HandlerMain(int argc,
#if defined(OS_WIN)
if (options.initial_client_data.IsValid()) {
exception_handler_server.InitializeWithInheritedDataForInitialClient(
options.initial_client_data, &exception_handler);
options.initial_client_data, exception_handler.get());
}
#elif defined(OS_LINUX) || defined(OS_ANDROID)
if (options.initial_client_fd == kInvalidFileHandle ||
@ -1023,7 +1069,7 @@ int HandlerMain(int argc,
}
#endif // OS_WIN
exception_handler_server.Run(&exception_handler);
exception_handler_server.Run(exception_handler.get());
return EXIT_SUCCESS;
}

View File

@ -16,7 +16,6 @@
#include <memory>
#include <utility>
#include <vector>
#include "base/logging.h"
#include "client/settings.h"
@ -26,108 +25,10 @@
#include "snapshot/sanitized/process_snapshot_sanitized.h"
#include "util/linux/direct_ptrace_connection.h"
#include "util/linux/ptrace_client.h"
#include "util/misc/implicit_cast.h"
#include "util/misc/metrics.h"
#include "util/misc/uuid.h"
#if defined(OS_CHROMEOS)
#include "handler/minidump_to_upload_parameters.h"
#include "snapshot/minidump/process_snapshot_minidump.h"
#include "util/posix/double_fork_and_exec.h"
namespace {
// Returns the process name for a pid.
const std::string GetProcessNameFromPid(pid_t pid) {
// Symlink to process binary is at /proc/###/exe.
std::string link_path = "/proc/" + std::to_string(pid) + "/exe";
constexpr int kMaxSize = 4096;
std::unique_ptr<char[]> buf(new char[kMaxSize]);
ssize_t size = readlink(link_path.c_str(), buf.get(), kMaxSize);
std::string result;
if (size < 0) {
PLOG(ERROR) << "Failed to readlink " << link_path;
} else {
result.assign(buf.get(), size);
size_t last_slash_pos = result.rfind('/');
if (last_slash_pos != std::string::npos) {
result = result.substr(last_slash_pos + 1);
}
}
return result;
}
bool WriteAnnotationsAndMinidump(
const std::map<std::string, std::string>& parameters,
crashpad::MinidumpFileWriter& minidump,
crashpad::FileWriter& file_writer) {
for (const auto& kv : parameters) {
if (kv.first.find(':') != std::string::npos) {
LOG(ERROR) << "Annotation key cannot have ':' in it " << kv.first;
return false;
}
if (!file_writer.Write(kv.first.c_str(), strlen(kv.first.c_str()))) {
return false;
}
if (!file_writer.Write(":", 1)) {
return false;
}
size_t value_size = strlen(kv.second.c_str());
std::string value_size_str = std::to_string(value_size);
if (!file_writer.Write(value_size_str.c_str(), value_size_str.size())) {
return false;
}
if (!file_writer.Write(":", 1)) {
return false;
}
if (!file_writer.Write(kv.second.c_str(), strlen(kv.second.c_str()))) {
return false;
}
}
static constexpr char kMinidumpName[] =
"upload_file_minidump\"; filename=\"dump\":";
if (!file_writer.Write(kMinidumpName, sizeof(kMinidumpName) - 1)) {
return false;
}
crashpad::FileOffset dump_size_start_offset = file_writer.Seek(0, SEEK_CUR);
if (dump_size_start_offset < 0) {
LOG(ERROR) << "Failed to get minidump size start offset";
return false;
}
static constexpr char kMinidumpLengthFilling[] = "00000000000000000000:";
if (!file_writer.Write(kMinidumpLengthFilling,
sizeof(kMinidumpLengthFilling) - 1)) {
return false;
}
crashpad::FileOffset dump_start_offset = file_writer.Seek(0, SEEK_CUR);
if (dump_start_offset < 0) {
LOG(ERROR) << "Failed to get minidump start offset";
return false;
}
if (!minidump.WriteEverything(&file_writer)) {
return false;
}
crashpad::FileOffset dump_end_offset = file_writer.Seek(0, SEEK_CUR);
if (dump_end_offset < 0) {
LOG(ERROR) << "Failed to get minidump end offset";
return false;
}
size_t dump_data_size = dump_end_offset - dump_start_offset;
std::string dump_data_size_str = std::to_string(dump_data_size);
file_writer.Seek(dump_size_start_offset + strlen(kMinidumpLengthFilling) - 1 -
dump_data_size_str.size(),
SEEK_SET);
if (!file_writer.Write(dump_data_size_str.c_str(),
dump_data_size_str.size())) {
return false;
}
return true;
}
} // namespace
#endif // defined(OS_CHROMEOS)
namespace crashpad {
CrashReportExceptionHandler::CrashReportExceptionHandler(
@ -136,12 +37,9 @@ CrashReportExceptionHandler::CrashReportExceptionHandler(
const std::map<std::string, std::string>* process_annotations,
const UserStreamDataSources* user_stream_data_sources)
: database_(database),
#if !defined(OS_CHROMEOS)
upload_thread_(upload_thread),
#endif
process_annotations_(process_annotations),
user_stream_data_sources_(user_stream_data_sources) {
}
user_stream_data_sources_(user_stream_data_sources) {}
CrashReportExceptionHandler::~CrashReportExceptionHandler() = default;
@ -218,12 +116,6 @@ bool CrashReportExceptionHandler::HandleExceptionWithConnection(
}
process_snapshot->SetClientID(client_id);
UUID uuid;
#if defined(OS_CHROMEOS)
uuid.InitializeWithNew();
process_snapshot->SetReportID(uuid);
#else
std::unique_ptr<CrashReportDatabase::NewReport> new_report;
CrashReportDatabase::OperationStatus database_status =
database_->PrepareNewCrashReport(&new_report);
@ -235,7 +127,6 @@ bool CrashReportExceptionHandler::HandleExceptionWithConnection(
}
process_snapshot->SetReportID(new_report->ReportID());
#endif
ProcessSnapshot* snapshot =
sanitized_snapshot
@ -246,53 +137,6 @@ bool CrashReportExceptionHandler::HandleExceptionWithConnection(
minidump.InitializeFromSnapshot(snapshot);
AddUserExtensionStreams(user_stream_data_sources_, snapshot, &minidump);
#if defined(OS_CHROMEOS)
FileWriter file_writer;
if (!file_writer.OpenMemfd(base::FilePath("/tmp/minidump"))) {
Metrics::ExceptionCaptureResult(Metrics::CaptureResult::kOpenMemfdFailed);
return false;
}
std::map<std::string, std::string> parameters =
BreakpadHTTPFormParametersFromMinidump(snapshot);
// Used to differenciate between breakpad and crashpad while the switch is
// ramping up.
parameters.emplace("crash_library", "crashpad");
if (!WriteAnnotationsAndMinidump(parameters, minidump, file_writer)) {
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kMinidumpWriteFailed);
return false;
}
// CrOS uses crash_reporter instead of Crashpad to report crashes.
// crash_reporter needs to know the pid and uid of the crashing process.
std::vector<std::string> argv({"/sbin/crash_reporter"});
argv.push_back("--chrome_memfd=" + std::to_string(file_writer.fd()));
argv.push_back("--pid=" + std::to_string(*requesting_thread_id));
argv.push_back("--uid=" + std::to_string(client_uid));
std::string process_name = GetProcessNameFromPid(*requesting_thread_id);
argv.push_back("--exe=" + (process_name.empty() ? "chrome" : process_name));
if (info.crash_loop_before_time != 0) {
argv.push_back("--crash_loop_before=" +
std::to_string(info.crash_loop_before_time));
}
if (!DoubleForkAndExec(argv,
nullptr /* envp */,
file_writer.fd() /* preserve_fd */,
false /* use_path */,
nullptr /* child_function */)) {
LOG(ERROR) << "DoubleForkAndExec failed";
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kFinishedWritingCrashReportFailed);
return false;
}
#else
if (!minidump.WriteEverything(new_report->Writer())) {
LOG(ERROR) << "WriteEverything failed";
Metrics::ExceptionCaptureResult(
@ -300,6 +144,7 @@ bool CrashReportExceptionHandler::HandleExceptionWithConnection(
return false;
}
UUID uuid;
database_status =
database_->FinishedWritingCrashReport(std::move(new_report), &uuid);
if (database_status != CrashReportDatabase::kNoError) {
@ -312,7 +157,7 @@ bool CrashReportExceptionHandler::HandleExceptionWithConnection(
if (upload_thread_) {
upload_thread_->ReportPending(uuid);
}
#endif
if (local_report_id != nullptr) {
*local_report_id = uuid;
}

View File

@ -60,7 +60,7 @@ class CrashReportExceptionHandler : public ExceptionHandlerServer::Delegate {
const std::map<std::string, std::string>* process_annotations,
const UserStreamDataSources* user_stream_data_sources);
~CrashReportExceptionHandler();
~CrashReportExceptionHandler() override;
// ExceptionHandlerServer::Delegate:
@ -88,9 +88,7 @@ class CrashReportExceptionHandler : public ExceptionHandlerServer::Delegate {
UUID* local_report_id = nullptr);
CrashReportDatabase* database_; // weak
#if !defined(OS_CHROMEOS)
CrashReportUploadThread* upload_thread_; // weak
#endif
const std::map<std::string, std::string>* process_annotations_; // weak
const UserStreamDataSources* user_stream_data_sources_; // weak

View File

@ -0,0 +1,278 @@
// Copyright 2019 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "handler/linux/cros_crash_report_exception_handler.h"
#include <vector>
#include "base/logging.h"
#include "client/settings.h"
#include "handler/linux/capture_snapshot.h"
#include "handler/minidump_to_upload_parameters.h"
#include "minidump/minidump_file_writer.h"
#include "snapshot/linux/process_snapshot_linux.h"
#include "snapshot/minidump/process_snapshot_minidump.h"
#include "snapshot/sanitized/process_snapshot_sanitized.h"
#include "util/file/file_writer.h"
#include "util/linux/direct_ptrace_connection.h"
#include "util/linux/ptrace_client.h"
#include "util/misc/metrics.h"
#include "util/misc/uuid.h"
#include "util/posix/double_fork_and_exec.h"
namespace crashpad {
namespace {
// Returns the process name for a pid.
const std::string GetProcessNameFromPid(pid_t pid) {
// Symlink to process binary is at /proc/###/exe.
std::string link_path = "/proc/" + std::to_string(pid) + "/exe";
constexpr int kMaxSize = 4096;
std::unique_ptr<char[]> buf(new char[kMaxSize]);
ssize_t size = readlink(link_path.c_str(), buf.get(), kMaxSize);
std::string result;
if (size < 0) {
PLOG(ERROR) << "Failed to readlink " << link_path;
} else {
result.assign(buf.get(), size);
size_t last_slash_pos = result.rfind('/');
if (last_slash_pos != std::string::npos) {
result = result.substr(last_slash_pos + 1);
}
}
return result;
}
bool WriteAnnotationsAndMinidump(
const std::map<std::string, std::string>& parameters,
MinidumpFileWriter& minidump,
FileWriter& file_writer) {
for (const auto& kv : parameters) {
if (kv.first.find(':') != std::string::npos) {
LOG(ERROR) << "Annotation key cannot have ':' in it " << kv.first;
return false;
}
if (!file_writer.Write(kv.first.c_str(), strlen(kv.first.c_str()))) {
return false;
}
if (!file_writer.Write(":", 1)) {
return false;
}
size_t value_size = strlen(kv.second.c_str());
std::string value_size_str = std::to_string(value_size);
if (!file_writer.Write(value_size_str.c_str(), value_size_str.size())) {
return false;
}
if (!file_writer.Write(":", 1)) {
return false;
}
if (!file_writer.Write(kv.second.c_str(), strlen(kv.second.c_str()))) {
return false;
}
}
static constexpr char kMinidumpName[] =
"upload_file_minidump\"; filename=\"dump\":";
if (!file_writer.Write(kMinidumpName, sizeof(kMinidumpName) - 1)) {
return false;
}
crashpad::FileOffset dump_size_start_offset = file_writer.Seek(0, SEEK_CUR);
if (dump_size_start_offset < 0) {
LOG(ERROR) << "Failed to get minidump size start offset";
return false;
}
static constexpr char kMinidumpLengthFilling[] = "00000000000000000000:";
if (!file_writer.Write(kMinidumpLengthFilling,
sizeof(kMinidumpLengthFilling) - 1)) {
return false;
}
crashpad::FileOffset dump_start_offset = file_writer.Seek(0, SEEK_CUR);
if (dump_start_offset < 0) {
LOG(ERROR) << "Failed to get minidump start offset";
return false;
}
if (!minidump.WriteEverything(&file_writer)) {
return false;
}
crashpad::FileOffset dump_end_offset = file_writer.Seek(0, SEEK_CUR);
if (dump_end_offset < 0) {
LOG(ERROR) << "Failed to get minidump end offset";
return false;
}
size_t dump_data_size = dump_end_offset - dump_start_offset;
std::string dump_data_size_str = std::to_string(dump_data_size);
file_writer.Seek(dump_size_start_offset + strlen(kMinidumpLengthFilling) - 1 -
dump_data_size_str.size(),
SEEK_SET);
if (!file_writer.Write(dump_data_size_str.c_str(),
dump_data_size_str.size())) {
return false;
}
return true;
}
} // namespace
CrosCrashReportExceptionHandler::CrosCrashReportExceptionHandler(
CrashReportDatabase* database,
const std::map<std::string, std::string>* process_annotations,
const UserStreamDataSources* user_stream_data_sources)
: database_(database),
process_annotations_(process_annotations),
user_stream_data_sources_(user_stream_data_sources) {}
CrosCrashReportExceptionHandler::~CrosCrashReportExceptionHandler() = default;
bool CrosCrashReportExceptionHandler::HandleException(
pid_t client_process_id,
uid_t client_uid,
const ExceptionHandlerProtocol::ClientInformation& info,
VMAddress requesting_thread_stack_address,
pid_t* requesting_thread_id,
UUID* local_report_id) {
Metrics::ExceptionEncountered();
DirectPtraceConnection connection;
if (!connection.Initialize(client_process_id)) {
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kDirectPtraceFailed);
return false;
}
return HandleExceptionWithConnection(&connection,
info,
client_uid,
requesting_thread_stack_address,
requesting_thread_id,
local_report_id);
}
bool CrosCrashReportExceptionHandler::HandleExceptionWithBroker(
pid_t client_process_id,
uid_t client_uid,
const ExceptionHandlerProtocol::ClientInformation& info,
int broker_sock,
UUID* local_report_id) {
Metrics::ExceptionEncountered();
PtraceClient client;
if (!client.Initialize(broker_sock, client_process_id)) {
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kBrokeredPtraceFailed);
return false;
}
return HandleExceptionWithConnection(
&client, info, client_uid, 0, nullptr, local_report_id);
}
bool CrosCrashReportExceptionHandler::HandleExceptionWithConnection(
PtraceConnection* connection,
const ExceptionHandlerProtocol::ClientInformation& info,
uid_t client_uid,
VMAddress requesting_thread_stack_address,
pid_t* requesting_thread_id,
UUID* local_report_id) {
std::unique_ptr<ProcessSnapshotLinux> process_snapshot;
std::unique_ptr<ProcessSnapshotSanitized> sanitized_snapshot;
if (!CaptureSnapshot(connection,
info,
*process_annotations_,
client_uid,
requesting_thread_stack_address,
requesting_thread_id,
&process_snapshot,
&sanitized_snapshot)) {
return false;
}
UUID client_id;
Settings* const settings = database_->GetSettings();
if (settings) {
// If GetSettings() or GetClientID() fails, something else will log a
// message and client_id will be left at its default value, all zeroes,
// which is appropriate.
settings->GetClientID(&client_id);
}
process_snapshot->SetClientID(client_id);
UUID uuid;
uuid.InitializeWithNew();
process_snapshot->SetReportID(uuid);
ProcessSnapshot* snapshot =
sanitized_snapshot
? implicit_cast<ProcessSnapshot*>(sanitized_snapshot.get())
: implicit_cast<ProcessSnapshot*>(process_snapshot.get());
MinidumpFileWriter minidump;
minidump.InitializeFromSnapshot(snapshot);
AddUserExtensionStreams(user_stream_data_sources_, snapshot, &minidump);
FileWriter file_writer;
if (!file_writer.OpenMemfd(base::FilePath("/tmp/minidump"))) {
Metrics::ExceptionCaptureResult(Metrics::CaptureResult::kOpenMemfdFailed);
return false;
}
std::map<std::string, std::string> parameters =
BreakpadHTTPFormParametersFromMinidump(snapshot);
// Used to differentiate between breakpad and crashpad while the switch is
// ramping up.
parameters.emplace("crash_library", "crashpad");
if (!WriteAnnotationsAndMinidump(parameters, minidump, file_writer)) {
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kMinidumpWriteFailed);
return false;
}
// CrOS uses crash_reporter instead of Crashpad to report crashes.
// crash_reporter needs to know the pid and uid of the crashing process.
std::vector<std::string> argv({"/sbin/crash_reporter"});
argv.push_back("--chrome_memfd=" + std::to_string(file_writer.fd()));
argv.push_back("--pid=" + std::to_string(*requesting_thread_id));
argv.push_back("--uid=" + std::to_string(client_uid));
std::string process_name = GetProcessNameFromPid(*requesting_thread_id);
argv.push_back("--exe=" + (process_name.empty() ? "chrome" : process_name));
if (info.crash_loop_before_time != 0) {
argv.push_back("--crash_loop_before=" +
std::to_string(info.crash_loop_before_time));
}
if (!DoubleForkAndExec(argv,
nullptr /* envp */,
file_writer.fd() /* preserve_fd */,
false /* use_path */,
nullptr /* child_function */)) {
LOG(ERROR) << "DoubleForkAndExec failed";
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kFinishedWritingCrashReportFailed);
return false;
}
if (local_report_id != nullptr) {
*local_report_id = uuid;
}
Metrics::ExceptionCaptureResult(Metrics::CaptureResult::kSuccess);
return true;
}
} // namespace crashpad

View File

@ -0,0 +1,97 @@
// Copyright 2019 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_HANDLER_LINUX_CROS_CRASH_REPORT_EXCEPTION_HANDLER_H_
#define CRASHPAD_HANDLER_LINUX_CROS_CRASH_REPORT_EXCEPTION_HANDLER_H_
#include <map>
#include <string>
#include "base/macros.h"
#include "client/crash_report_database.h"
#include "handler/linux/exception_handler_server.h"
#include "handler/user_stream_data_source.h"
#include "util/linux/exception_handler_protocol.h"
#include "util/linux/ptrace_connection.h"
#include "util/misc/address_types.h"
#include "util/misc/uuid.h"
namespace crashpad {
//! \brief An exception handler that writes crash reports to the ChromeOS
//! crash_reporter.
class CrosCrashReportExceptionHandler
: public ExceptionHandlerServer::Delegate {
public:
//! \brief Creates a new object that will pass reports to
//! `/sbin/crash_reporter`.
//!
//! \param[in] database The database that supplies settings for this client.
//! This object does not write its reports to this database.
//! \param[in] process_annotations A map of annotations to insert as
//! process-level annotations into each crash report that is written. Do
//! not confuse this with module-level annotations, which are under the
//! control of the crashing process, and are used to implement Chromes
//! “crash keys.” Process-level annotations are those that are beyond the
//! control of the crashing process, which must reliably be set even if
//! the process crashes before its able to establish its own annotations.
//! To interoperate with Breakpad servers, the recommended practice is to
//! specify values for the `"prod"` and `"ver"` keys as process
//! annotations.
//! \param[in] user_stream_data_sources Data sources to be used to extend
//! crash reports. For each crash report that is written, the data sources
//! are called in turn. These data sources may contribute additional
//! minidump streams. `nullptr` if not required.
CrosCrashReportExceptionHandler(
CrashReportDatabase* database,
const std::map<std::string, std::string>* process_annotations,
const UserStreamDataSources* user_stream_data_sources);
~CrosCrashReportExceptionHandler() override;
// ExceptionHandlerServer::Delegate:
bool HandleException(pid_t client_process_id,
uid_t client_uid,
const ExceptionHandlerProtocol::ClientInformation& info,
VMAddress requesting_thread_stack_address = 0,
pid_t* requesting_thread_id = nullptr,
UUID* local_report_id = nullptr) override;
bool HandleExceptionWithBroker(
pid_t client_process_id,
uid_t client_uid,
const ExceptionHandlerProtocol::ClientInformation& info,
int broker_sock,
UUID* local_report_id = nullptr) override;
private:
bool HandleExceptionWithConnection(
PtraceConnection* connection,
const ExceptionHandlerProtocol::ClientInformation& info,
uid_t client_uid,
VMAddress requesting_thread_stack_address,
pid_t* requesting_thread_id,
UUID* local_report_id = nullptr);
CrashReportDatabase* database_; // weak
const std::map<std::string, std::string>* process_annotations_; // weak
const UserStreamDataSources* user_stream_data_sources_; // weak
DISALLOW_COPY_AND_ASSIGN(CrosCrashReportExceptionHandler);
};
} // namespace crashpad
#endif // CRASHPAD_HANDLER_LINUX_CROS_CRASH_REPORT_EXCEPTION_HANDLER_H_

View File

@ -112,8 +112,7 @@ class ExceptionHandlerServer {
int broker_sock,
UUID* local_report_id = nullptr) = 0;
protected:
~Delegate() {}
virtual ~Delegate() {}
};
ExceptionHandlerServer();

View File

@ -30,7 +30,8 @@ namespace crashpad {
//! \brief An exception handler that writes crash reports for exception messages
//! to a CrashReportDatabase.
class CrashReportExceptionHandler : public UniversalMachExcServer::Interface {
class CrashReportExceptionHandler final
: public UniversalMachExcServer::Interface {
public:
//! \brief Creates a new object that will store crash reports in \a database.
//!

View File

@ -31,7 +31,8 @@ class CrashReportUploadThread;
//! \brief An exception handler that writes crash reports for exception messages
//! to a CrashReportDatabase.
class CrashReportExceptionHandler : public ExceptionHandlerServer::Delegate {
class CrashReportExceptionHandler final
: public ExceptionHandlerServer::Delegate {
public:
//! \brief Creates a new object that will store crash reports in \a database.
//!

View File

@ -398,7 +398,7 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
FileWriteMode mode,
FilePermissions permissions);
#if defined(OS_CHROMEOS)
#if defined(OS_LINUX)
//! \brief Wraps memfd_create(), logging an error if the operation fails.
//! Unlike other file open operations, this doesn't set `O_CLOEXEC`.
//!
@ -409,7 +409,7 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
//! \sa LoggingOpenFileForWrite
//! \sa LoggingOpenFileForReadAndWrite
FileHandle LoggingOpenMemFileForWrite(const base::FilePath& path);
#endif
#endif // OS_LINUX
//! \brief Wraps OpenFileForReadAndWrite(), logging an error if the operation
//! fails.

View File

@ -99,7 +99,7 @@ FileHandle OpenFileForOutput(int rdwr_or_wronly,
permissions == FilePermissions::kWorldReadable ? 0644 : 0600));
}
#if defined(OS_CHROMEOS)
#if defined(OS_LINUX)
FileHandle OpenMemFileForOutput(const base::FilePath& path) {
return HANDLE_EINTR(memfd_create(path.value().c_str(), 0));
}
@ -156,7 +156,7 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path,
return fd;
}
#if defined(OS_CHROMEOS)
#if defined(OS_LINUX)
FileHandle LoggingOpenMemFileForWrite(const base::FilePath& path) {
FileHandle fd = OpenMemFileForOutput(path);
PLOG_IF(ERROR, fd < 0) << "memfd_create " << path.value();

View File

@ -171,7 +171,7 @@ bool FileWriter::Open(const base::FilePath& path,
return true;
}
#if defined(OS_CHROMEOS)
#if defined(OS_LINUX)
bool FileWriter::OpenMemfd(const base::FilePath& path) {
CHECK(!file_.is_valid());
file_.reset(LoggingOpenMemFileForWrite(path));

View File

@ -131,7 +131,7 @@ class FileWriter : public FileWriterInterface {
FileWriteMode write_mode,
FilePermissions permissions);
#if defined(OS_CHROMEOS)
#if defined(OS_LINUX)
//! \brief Wraps LoggingOpenMemFileForWrite().
//!
//! \return `true` if the operation succeeded, `false` if it failed, with an

View File

@ -51,7 +51,10 @@ class ExceptionHandlerProtocol {
//! SanitizationInformation struct, or 0 if there is no such struct.
VMAddress sanitization_information_address;
#if defined(OS_CHROMEOS)
#if defined(OS_LINUX)
//! \brief Indicates that the client is likely in a crash loop if a crash
//! occurs before this timestamp. This value is only used by ChromeOS's
//! `/sbin/crash_reporter`.
uint64_t crash_loop_before_time;
#endif
};