2018-02-01 10:39:32 -08:00
|
|
|
// Copyright 2018 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 "client/crashpad_client.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
2018-04-09 14:21:06 -07:00
|
|
|
#include "client/client_argv_handling.h"
|
2019-04-08 17:28:18 -07:00
|
|
|
#include "third_party/lss/lss.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
#include "util/file/file_io.h"
|
|
|
|
#include "util/linux/exception_handler_client.h"
|
|
|
|
#include "util/linux/exception_information.h"
|
2018-12-18 09:17:52 -08:00
|
|
|
#include "util/linux/scoped_pr_set_dumpable.h"
|
2018-02-20 16:16:22 -08:00
|
|
|
#include "util/linux/scoped_pr_set_ptracer.h"
|
2019-05-01 22:19:21 -07:00
|
|
|
#include "util/linux/socket.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
#include "util/misc/from_pointer_cast.h"
|
|
|
|
#include "util/posix/double_fork_and_exec.h"
|
|
|
|
#include "util/posix/signals.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::string FormatArgumentInt(const std::string& name, int value) {
|
|
|
|
return base::StringPrintf("--%s=%d", name.c_str(), value);
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
std::string FormatArgumentAddress(const std::string& name, const void* addr) {
|
2018-02-01 10:39:32 -08:00
|
|
|
return base::StringPrintf("--%s=%p", name.c_str(), addr);
|
|
|
|
}
|
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
#if defined(OS_ANDROID)
|
|
|
|
|
|
|
|
std::vector<std::string> BuildAppProcessArgs(
|
|
|
|
const std::string& class_name,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
int socket) {
|
|
|
|
std::vector<std::string> argv;
|
2019-01-11 11:29:31 -08:00
|
|
|
#if defined(ARCH_CPU_64_BITS)
|
2018-08-29 09:00:15 -07:00
|
|
|
argv.push_back("/system/bin/app_process64");
|
|
|
|
#else
|
|
|
|
argv.push_back("/system/bin/app_process32");
|
|
|
|
#endif
|
|
|
|
argv.push_back("/system/bin");
|
|
|
|
argv.push_back("--application");
|
|
|
|
argv.push_back(class_name);
|
|
|
|
|
|
|
|
std::vector<std::string> handler_argv = BuildHandlerArgvStrings(
|
|
|
|
base::FilePath(), database, metrics_dir, url, annotations, arguments);
|
|
|
|
|
|
|
|
if (socket != kInvalidFileHandle) {
|
|
|
|
handler_argv.push_back(FormatArgumentInt("initial-client-fd", socket));
|
|
|
|
}
|
|
|
|
|
|
|
|
argv.insert(argv.end(), handler_argv.begin() + 1, handler_argv.end());
|
|
|
|
return argv;
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:26:25 -08:00
|
|
|
std::vector<std::string> BuildArgsToLaunchWithLinker(
|
|
|
|
const std::string& handler_trampoline,
|
|
|
|
const std::string& handler_library,
|
|
|
|
bool is_64_bit,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
int socket) {
|
|
|
|
std::vector<std::string> argv;
|
|
|
|
if (is_64_bit) {
|
|
|
|
argv.push_back("/system/bin/linker64");
|
|
|
|
} else {
|
|
|
|
argv.push_back("/system/bin/linker");
|
|
|
|
}
|
|
|
|
argv.push_back(handler_trampoline);
|
|
|
|
argv.push_back(handler_library);
|
|
|
|
|
|
|
|
std::vector<std::string> handler_argv = BuildHandlerArgvStrings(
|
|
|
|
base::FilePath(), database, metrics_dir, url, annotations, arguments);
|
|
|
|
|
|
|
|
if (socket != kInvalidFileHandle) {
|
|
|
|
handler_argv.push_back(FormatArgumentInt("initial-client-fd", socket));
|
|
|
|
}
|
|
|
|
|
|
|
|
argv.insert(argv.end(), handler_argv.begin() + 1, handler_argv.end());
|
|
|
|
return argv;
|
|
|
|
}
|
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
#endif // OS_ANDROID
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
// A base class for Crashpad signal handler implementations.
|
|
|
|
class SignalHandler {
|
|
|
|
public:
|
|
|
|
// Returns the currently installed signal hander. May be `nullptr` if no
|
|
|
|
// handler has been installed.
|
|
|
|
static SignalHandler* Get() { return handler_; }
|
|
|
|
|
|
|
|
// Disables any installed Crashpad signal handler for the calling thread. If a
|
|
|
|
// crash signal is received, any previously installed (non-Crashpad) signal
|
|
|
|
// handler will be restored and the signal reraised.
|
|
|
|
static void DisableForThread() { disabled_for_thread_ = true; }
|
|
|
|
|
|
|
|
void SetFirstChanceHandler(CrashpadClient::FirstChanceHandler handler) {
|
|
|
|
first_chance_handler_ = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The base implementation for all signal handlers, suitable for calling
|
|
|
|
// directly to simulate signal delivery.
|
|
|
|
bool HandleCrash(int signo, siginfo_t* siginfo, void* context) {
|
|
|
|
if (disabled_for_thread_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first_chance_handler_ &&
|
|
|
|
first_chance_handler_(
|
|
|
|
signo, siginfo, static_cast<ucontext_t*>(context))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exception_information_.siginfo_address =
|
|
|
|
FromPointerCast<decltype(exception_information_.siginfo_address)>(
|
|
|
|
siginfo);
|
|
|
|
exception_information_.context_address =
|
|
|
|
FromPointerCast<decltype(exception_information_.context_address)>(
|
|
|
|
context);
|
|
|
|
exception_information_.thread_id = sys_gettid();
|
|
|
|
|
|
|
|
HandleCrashImpl();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SignalHandler() = default;
|
|
|
|
|
2019-09-09 14:07:42 -07:00
|
|
|
bool Install(const std::set<int>* unhandled_signals) {
|
2019-05-01 22:19:21 -07:00
|
|
|
DCHECK(!handler_);
|
|
|
|
handler_ = this;
|
|
|
|
return Signals::InstallCrashHandlers(
|
2019-09-09 14:07:42 -07:00
|
|
|
HandleOrReraiseSignal, 0, &old_actions_, unhandled_signals);
|
2019-05-01 22:19:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const ExceptionInformation& GetExceptionInfo() {
|
|
|
|
return exception_information_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void HandleCrashImpl() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// The signal handler installed at OS-level.
|
|
|
|
static void HandleOrReraiseSignal(int signo,
|
|
|
|
siginfo_t* siginfo,
|
|
|
|
void* context) {
|
|
|
|
if (handler_->HandleCrash(signo, siginfo, context)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(
|
|
|
|
siginfo, handler_->old_actions_.ActionForSignal(signo));
|
|
|
|
}
|
|
|
|
|
|
|
|
Signals::OldActions old_actions_ = {};
|
|
|
|
ExceptionInformation exception_information_ = {};
|
|
|
|
CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr;
|
|
|
|
|
|
|
|
static SignalHandler* handler_;
|
|
|
|
|
|
|
|
static thread_local bool disabled_for_thread_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SignalHandler);
|
|
|
|
};
|
|
|
|
SignalHandler* SignalHandler::handler_ = nullptr;
|
|
|
|
thread_local bool SignalHandler::disabled_for_thread_ = false;
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
// Launches a single use handler to snapshot this process.
|
2019-05-01 22:19:21 -07:00
|
|
|
class LaunchAtCrashHandler : public SignalHandler {
|
2018-02-01 10:39:32 -08:00
|
|
|
public:
|
|
|
|
static LaunchAtCrashHandler* Get() {
|
|
|
|
static LaunchAtCrashHandler* instance = new LaunchAtCrashHandler();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
bool Initialize(std::vector<std::string>* argv_in,
|
2019-09-09 14:07:42 -07:00
|
|
|
const std::vector<std::string>* envp,
|
|
|
|
const std::set<int>* unhandled_signals) {
|
2018-02-01 10:39:32 -08:00
|
|
|
argv_strings_.swap(*argv_in);
|
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
if (envp) {
|
|
|
|
envp_strings_ = *envp;
|
|
|
|
StringVectorToCStringVector(envp_strings_, &envp_);
|
|
|
|
set_envp_ = true;
|
|
|
|
}
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
argv_strings_.push_back(FormatArgumentAddress("trace-parent-with-exception",
|
2019-05-01 22:19:21 -07:00
|
|
|
&GetExceptionInfo()));
|
2018-02-01 10:39:32 -08:00
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
StringVectorToCStringVector(argv_strings_, &argv_);
|
2019-09-09 14:07:42 -07:00
|
|
|
return Install(unhandled_signals);
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
void HandleCrashImpl() override {
|
2019-04-08 17:28:18 -07:00
|
|
|
ScopedPrSetPtracer set_ptracer(sys_getpid(), /* may_log= */ false);
|
2018-12-18 09:17:52 -08:00
|
|
|
ScopedPrSetDumpable set_dumpable(/* may_log= */ false);
|
2018-02-01 10:39:32 -08:00
|
|
|
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0) {
|
2019-05-01 22:19:21 -07:00
|
|
|
return;
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
if (pid == 0) {
|
2018-08-29 09:00:15 -07:00
|
|
|
if (set_envp_) {
|
|
|
|
execve(argv_[0],
|
|
|
|
const_cast<char* const*>(argv_.data()),
|
|
|
|
const_cast<char* const*>(envp_.data()));
|
|
|
|
} else {
|
|
|
|
execv(argv_[0], const_cast<char* const*>(argv_.data()));
|
|
|
|
}
|
2018-02-20 16:16:22 -08:00
|
|
|
_exit(EXIT_FAILURE);
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int status;
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:16:22 -08:00
|
|
|
private:
|
|
|
|
LaunchAtCrashHandler() = default;
|
|
|
|
|
|
|
|
~LaunchAtCrashHandler() = delete;
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
std::vector<std::string> argv_strings_;
|
|
|
|
std::vector<const char*> argv_;
|
2018-08-29 09:00:15 -07:00
|
|
|
std::vector<std::string> envp_strings_;
|
|
|
|
std::vector<const char*> envp_;
|
2018-10-02 15:19:32 -07:00
|
|
|
bool set_envp_ = false;
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(LaunchAtCrashHandler);
|
|
|
|
};
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
class RequestCrashDumpHandler : public SignalHandler {
|
|
|
|
public:
|
|
|
|
static RequestCrashDumpHandler* Get() {
|
|
|
|
static RequestCrashDumpHandler* instance = new RequestCrashDumpHandler();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pid < 0 indicates the handler pid should be determined by communicating
|
|
|
|
// over the socket.
|
|
|
|
// pid == 0 indicates it is not necessary to set the handler as this process'
|
|
|
|
// ptracer. e.g. if the handler has CAP_SYS_PTRACE or if this process is in a
|
|
|
|
// user namespace and the handler's uid matches the uid of the process that
|
|
|
|
// created the namespace.
|
|
|
|
// pid > 0 directly indicates what the handler's pid is expected to be, so
|
|
|
|
// retrieving this information from the handler is not necessary.
|
2019-09-09 14:07:42 -07:00
|
|
|
bool Initialize(ScopedFileHandle sock,
|
|
|
|
pid_t pid,
|
|
|
|
const std::set<int>* unhandled_signals) {
|
2019-05-01 22:19:21 -07:00
|
|
|
ExceptionHandlerClient client(sock.get(), true);
|
|
|
|
if (pid < 0) {
|
|
|
|
ucred creds;
|
|
|
|
if (!client.GetHandlerCredentials(&creds)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pid = creds.pid;
|
|
|
|
}
|
|
|
|
if (pid > 0 && client.SetPtracer(pid) != 0) {
|
|
|
|
LOG(ERROR) << "failed to set ptracer";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sock_to_handler_.reset(sock.release());
|
2019-08-19 11:30:12 -07:00
|
|
|
handler_pid_ = pid;
|
2019-09-09 14:07:42 -07:00
|
|
|
return Install(unhandled_signals);
|
2019-05-01 22:19:21 -07:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:30:12 -07:00
|
|
|
bool GetHandlerSocket(int* sock, pid_t* pid) {
|
|
|
|
if (!sock_to_handler_.is_valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*sock = sock_to_handler_.get();
|
|
|
|
*pid = handler_pid_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
void HandleCrashImpl() override {
|
|
|
|
ExceptionHandlerProtocol::ClientInformation info = {};
|
|
|
|
info.exception_information_address =
|
|
|
|
FromPointerCast<VMAddress>(&GetExceptionInfo());
|
2019-08-19 15:43:02 -07:00
|
|
|
#if defined(OS_CHROMEOS)
|
|
|
|
info.crash_loop_before_time = crash_loop_before_time_;
|
|
|
|
#endif
|
2019-05-01 22:19:21 -07:00
|
|
|
|
|
|
|
ExceptionHandlerClient client(sock_to_handler_.get(), true);
|
|
|
|
client.RequestCrashDump(info);
|
|
|
|
}
|
|
|
|
|
2019-08-19 15:43:02 -07:00
|
|
|
#if defined(OS_CHROMEOS)
|
|
|
|
void SetCrashLoopBefore(uint64_t crash_loop_before_time) {
|
|
|
|
crash_loop_before_time_ = crash_loop_before_time;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
private:
|
|
|
|
RequestCrashDumpHandler() = default;
|
|
|
|
|
|
|
|
~RequestCrashDumpHandler() = delete;
|
|
|
|
|
|
|
|
ScopedFileHandle sock_to_handler_;
|
2019-08-19 11:30:12 -07:00
|
|
|
pid_t handler_pid_ = -1;
|
2019-05-01 22:19:21 -07:00
|
|
|
|
2019-08-19 15:43:02 -07:00
|
|
|
#if defined(OS_CHROMEOS)
|
|
|
|
// An optional UNIX timestamp passed to us from Chrome.
|
|
|
|
// This will pass to crashpad_handler and then to Chrome OS crash_reporter.
|
|
|
|
// This should really be a time_t, but it's basically an opaque value (we
|
|
|
|
// don't anything with it except pass it along).
|
|
|
|
uint64_t crash_loop_before_time_ = 0;
|
|
|
|
#endif
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RequestCrashDumpHandler);
|
|
|
|
};
|
2018-02-20 16:16:22 -08:00
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CrashpadClient::CrashpadClient() {}
|
|
|
|
|
|
|
|
CrashpadClient::~CrashpadClient() {}
|
|
|
|
|
|
|
|
bool CrashpadClient::StartHandler(
|
|
|
|
const base::FilePath& handler,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
bool restartable,
|
|
|
|
bool asynchronous_start) {
|
2019-05-01 22:19:21 -07:00
|
|
|
DCHECK(!asynchronous_start);
|
|
|
|
|
|
|
|
ScopedFileHandle client_sock, handler_sock;
|
|
|
|
if (!UnixCredentialSocket::CreateCredentialSocketpair(&client_sock,
|
|
|
|
&handler_sock)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> argv = BuildHandlerArgvStrings(
|
|
|
|
handler, database, metrics_dir, url, annotations, arguments);
|
|
|
|
|
|
|
|
argv.push_back(FormatArgumentInt("initial-client-fd", handler_sock.get()));
|
|
|
|
argv.push_back("--shared-client-connection");
|
|
|
|
if (!DoubleForkAndExec(argv, nullptr, handler_sock.get(), false, nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto signal_handler = RequestCrashDumpHandler::Get();
|
2019-09-09 14:07:42 -07:00
|
|
|
return signal_handler->Initialize(
|
|
|
|
std::move(client_sock), -1, &unhandled_signals_);
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:30:12 -07:00
|
|
|
#if defined(OS_ANDROID) || defined(OS_LINUX)
|
|
|
|
// static
|
|
|
|
bool CrashpadClient::GetHandlerSocket(int* sock, pid_t* pid) {
|
|
|
|
auto signal_handler = RequestCrashDumpHandler::Get();
|
|
|
|
return signal_handler->GetHandlerSocket(sock, pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CrashpadClient::SetHandlerSocket(ScopedFileHandle sock, pid_t pid) {
|
|
|
|
auto signal_handler = RequestCrashDumpHandler::Get();
|
2019-09-09 14:07:42 -07:00
|
|
|
return signal_handler->Initialize(std::move(sock), pid, &unhandled_signals_);
|
2019-08-19 11:30:12 -07:00
|
|
|
}
|
|
|
|
#endif // OS_ANDROID || OS_LINUX
|
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
#if defined(OS_ANDROID)
|
|
|
|
|
|
|
|
bool CrashpadClient::StartJavaHandlerAtCrash(
|
|
|
|
const std::string& class_name,
|
|
|
|
const std::vector<std::string>* env,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments) {
|
|
|
|
std::vector<std::string> argv = BuildAppProcessArgs(class_name,
|
|
|
|
database,
|
|
|
|
metrics_dir,
|
|
|
|
url,
|
|
|
|
annotations,
|
|
|
|
arguments,
|
|
|
|
kInvalidFileHandle);
|
|
|
|
|
|
|
|
auto signal_handler = LaunchAtCrashHandler::Get();
|
2019-09-09 14:07:42 -07:00
|
|
|
return signal_handler->Initialize(&argv, env, &unhandled_signals_);
|
2018-08-29 09:00:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool CrashpadClient::StartJavaHandlerForClient(
|
|
|
|
const std::string& class_name,
|
|
|
|
const std::vector<std::string>* env,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
int socket) {
|
|
|
|
std::vector<std::string> argv = BuildAppProcessArgs(
|
|
|
|
class_name, database, metrics_dir, url, annotations, arguments, socket);
|
|
|
|
return DoubleForkAndExec(argv, env, socket, false, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:26:25 -08:00
|
|
|
bool CrashpadClient::StartHandlerWithLinkerAtCrash(
|
|
|
|
const std::string& handler_trampoline,
|
|
|
|
const std::string& handler_library,
|
|
|
|
bool is_64_bit,
|
|
|
|
const std::vector<std::string>* env,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments) {
|
|
|
|
std::vector<std::string> argv =
|
|
|
|
BuildArgsToLaunchWithLinker(handler_trampoline,
|
|
|
|
handler_library,
|
|
|
|
is_64_bit,
|
|
|
|
database,
|
|
|
|
metrics_dir,
|
|
|
|
url,
|
|
|
|
annotations,
|
|
|
|
arguments,
|
|
|
|
kInvalidFileHandle);
|
|
|
|
auto signal_handler = LaunchAtCrashHandler::Get();
|
2019-09-09 14:07:42 -07:00
|
|
|
return signal_handler->Initialize(&argv, env, &unhandled_signals_);
|
2019-02-21 17:26:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool CrashpadClient::StartHandlerWithLinkerForClient(
|
|
|
|
const std::string& handler_trampoline,
|
|
|
|
const std::string& handler_library,
|
|
|
|
bool is_64_bit,
|
|
|
|
const std::vector<std::string>* env,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
int socket) {
|
|
|
|
std::vector<std::string> argv =
|
|
|
|
BuildArgsToLaunchWithLinker(handler_trampoline,
|
|
|
|
handler_library,
|
|
|
|
is_64_bit,
|
|
|
|
database,
|
|
|
|
metrics_dir,
|
|
|
|
url,
|
|
|
|
annotations,
|
|
|
|
arguments,
|
|
|
|
socket);
|
|
|
|
return DoubleForkAndExec(argv, env, socket, false, nullptr);
|
|
|
|
}
|
|
|
|
|
2018-08-29 09:00:15 -07:00
|
|
|
#endif
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
bool CrashpadClient::StartHandlerAtCrash(
|
|
|
|
const base::FilePath& handler,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments) {
|
2018-07-20 15:56:49 -04:00
|
|
|
std::vector<std::string> argv = BuildHandlerArgvStrings(
|
|
|
|
handler, database, metrics_dir, url, annotations, arguments);
|
2018-02-01 10:39:32 -08:00
|
|
|
|
|
|
|
auto signal_handler = LaunchAtCrashHandler::Get();
|
2019-09-09 14:07:42 -07:00
|
|
|
return signal_handler->Initialize(&argv, nullptr, &unhandled_signals_);
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
|
2018-03-16 10:52:55 -07:00
|
|
|
// static
|
2018-02-01 10:39:32 -08:00
|
|
|
bool CrashpadClient::StartHandlerForClient(
|
|
|
|
const base::FilePath& handler,
|
|
|
|
const base::FilePath& database,
|
|
|
|
const base::FilePath& metrics_dir,
|
|
|
|
const std::string& url,
|
|
|
|
const std::map<std::string, std::string>& annotations,
|
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
int socket) {
|
2018-07-20 15:56:49 -04:00
|
|
|
std::vector<std::string> argv = BuildHandlerArgvStrings(
|
|
|
|
handler, database, metrics_dir, url, annotations, arguments);
|
2018-02-01 10:39:32 -08:00
|
|
|
|
2018-08-13 15:10:45 -07:00
|
|
|
argv.push_back(FormatArgumentInt("initial-client-fd", socket));
|
2018-02-01 10:39:32 -08:00
|
|
|
|
2018-08-29 07:28:10 -07:00
|
|
|
return DoubleForkAndExec(argv, nullptr, socket, true, nullptr);
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
|
2018-02-20 16:16:22 -08:00
|
|
|
// static
|
|
|
|
void CrashpadClient::DumpWithoutCrash(NativeCPUContext* context) {
|
2019-05-01 22:19:21 -07:00
|
|
|
if (!SignalHandler::Get()) {
|
2019-04-08 15:29:04 -07:00
|
|
|
DLOG(ERROR) << "Crashpad isn't enabled";
|
|
|
|
return;
|
|
|
|
}
|
2018-02-20 16:16:22 -08:00
|
|
|
|
2018-04-12 16:45:35 -07:00
|
|
|
#if defined(ARCH_CPU_ARMEL)
|
2018-02-20 16:16:22 -08:00
|
|
|
memset(context->uc_regspace, 0, sizeof(context->uc_regspace));
|
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
|
|
|
memset(context->uc_mcontext.__reserved,
|
|
|
|
0,
|
|
|
|
sizeof(context->uc_mcontext.__reserved));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
siginfo_t siginfo;
|
|
|
|
siginfo.si_signo = Signals::kSimulatedSigno;
|
|
|
|
siginfo.si_errno = 0;
|
|
|
|
siginfo.si_code = 0;
|
2019-05-01 22:19:21 -07:00
|
|
|
SignalHandler::Get()->HandleCrash(
|
2018-02-20 16:16:22 -08:00
|
|
|
siginfo.si_signo, &siginfo, reinterpret_cast<void*>(context));
|
|
|
|
}
|
|
|
|
|
2018-10-02 15:19:32 -07:00
|
|
|
// static
|
|
|
|
void CrashpadClient::CrashWithoutDump(const std::string& message) {
|
2019-05-01 22:19:21 -07:00
|
|
|
SignalHandler::DisableForThread();
|
2018-10-02 15:19:32 -07:00
|
|
|
LOG(FATAL) << message;
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:32:06 -08:00
|
|
|
// static
|
|
|
|
void CrashpadClient::SetFirstChanceExceptionHandler(
|
|
|
|
FirstChanceHandler handler) {
|
2019-05-01 22:19:21 -07:00
|
|
|
DCHECK(SignalHandler::Get());
|
|
|
|
SignalHandler::Get()->SetFirstChanceHandler(handler);
|
2018-02-23 11:32:06 -08:00
|
|
|
}
|
|
|
|
|
2019-09-09 14:07:42 -07:00
|
|
|
void CrashpadClient::SetUnhandledSignals(const std::set<int>& signals) {
|
|
|
|
DCHECK(!SignalHandler::Get());
|
|
|
|
unhandled_signals_ = signals;
|
|
|
|
}
|
|
|
|
|
2019-08-19 15:43:02 -07:00
|
|
|
#if defined(OS_CHROMEOS)
|
|
|
|
// static
|
|
|
|
void CrashpadClient::SetCrashLoopBefore(uint64_t crash_loop_before_time) {
|
|
|
|
auto request_crash_dump_handler = RequestCrashDumpHandler::Get();
|
|
|
|
request_crash_dump_handler->SetCrashLoopBefore(crash_loop_before_time);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
} // namespace crashpad
|