2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2018 The Crashpad Authors
|
2018-02-01 10:39:32 -08:00
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
#include <errno.h>
|
2018-02-01 10:39:32 -08:00
|
|
|
#include <fcntl.h>
|
2022-01-20 09:45:58 -08:00
|
|
|
#include <limits.h>
|
|
|
|
#include <linux/futex.h>
|
2020-07-15 11:26:08 -07:00
|
|
|
#include <pthread.h>
|
2018-02-01 10:39:32 -08:00
|
|
|
#include <stdlib.h>
|
2020-07-15 11:26:08 -07:00
|
|
|
#include <sys/mman.h>
|
2019-12-17 12:16:44 -08:00
|
|
|
#include <sys/prctl.h>
|
2018-02-01 10:39:32 -08:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-01-20 11:36:38 -08:00
|
|
|
#include <atomic>
|
|
|
|
|
2023-10-18 12:08:10 -07:00
|
|
|
#include "base/check_op.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
2022-01-19 15:00:24 -05:00
|
|
|
#include "build/build_config.h"
|
2021-01-12 13:45:14 -08:00
|
|
|
#include "build/chromeos_buildflags.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"
|
2019-11-07 19:49:23 -08:00
|
|
|
#include "util/file/filesystem.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
#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"
|
2020-07-20 13:29:44 -07:00
|
|
|
#include "util/misc/address_sanitizer.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
#include "util/misc/from_pointer_cast.h"
|
2020-07-15 11:26:08 -07:00
|
|
|
#include "util/posix/scoped_mmap.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
#include "util/posix/signals.h"
|
2022-06-24 19:20:54 +05:30
|
|
|
#include "util/posix/spawn_subprocess.h"
|
2018-02-01 10:39:32 -08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2018-08-29 09:00:15 -07:00
|
|
|
|
|
|
|
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) {
|
2019-01-11 11:29:31 -08:00
|
|
|
#if defined(ARCH_CPU_64_BITS)
|
2019-10-04 12:13:16 -07:00
|
|
|
static constexpr char kAppProcess[] = "/system/bin/app_process64";
|
2018-08-29 09:00:15 -07:00
|
|
|
#else
|
2019-10-04 12:13:16 -07:00
|
|
|
static constexpr char kAppProcess[] = "/system/bin/app_process32";
|
2018-08-29 09:00:15 -07:00
|
|
|
#endif
|
2019-10-04 12:13:16 -07:00
|
|
|
|
|
|
|
std::vector<std::string> argv;
|
|
|
|
argv.push_back(kAppProcess);
|
2018-08-29 09:00:15 -07:00
|
|
|
argv.push_back("/system/bin");
|
|
|
|
argv.push_back("--application");
|
|
|
|
argv.push_back(class_name);
|
|
|
|
|
2019-10-04 12:13:16 -07:00
|
|
|
std::vector<std::string> handler_argv =
|
|
|
|
BuildHandlerArgvStrings(base::FilePath(kAppProcess),
|
|
|
|
database,
|
|
|
|
metrics_dir,
|
|
|
|
url,
|
|
|
|
annotations,
|
|
|
|
arguments);
|
2018-08-29 09:00:15 -07:00
|
|
|
|
|
|
|
if (socket != kInvalidFileHandle) {
|
|
|
|
handler_argv.push_back(FormatArgumentInt("initial-client-fd", socket));
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:13:16 -07:00
|
|
|
argv.insert(argv.end(), handler_argv.begin(), handler_argv.end());
|
2018-08-29 09:00:15 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#endif // BUILDFLAG(IS_ANDROID)
|
2018-08-29 09:00:15 -07:00
|
|
|
|
2023-08-31 17:27:07 +00:00
|
|
|
using LastChanceHandler = bool (*)(int, siginfo_t*, ucontext_t*);
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
// A base class for Crashpad signal handler implementations.
|
|
|
|
class SignalHandler {
|
|
|
|
public:
|
2021-09-20 12:55:12 -07:00
|
|
|
SignalHandler(const SignalHandler&) = delete;
|
|
|
|
SignalHandler& operator=(const SignalHandler&) = delete;
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
// Returns the currently installed signal hander. May be `nullptr` if no
|
|
|
|
// handler has been installed.
|
|
|
|
static SignalHandler* Get() { return handler_; }
|
|
|
|
|
2022-01-20 09:45:58 -08:00
|
|
|
// Disables any installed Crashpad signal handler. If a crash signal is
|
|
|
|
// received, any previously installed (non-Crashpad) signal handler will be
|
|
|
|
// restored and the signal reraised.
|
|
|
|
static void Disable() {
|
|
|
|
if (!handler_->disabled_.test_and_set()) {
|
|
|
|
handler_->WakeThreads();
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 22:19:21 -07:00
|
|
|
|
|
|
|
void SetFirstChanceHandler(CrashpadClient::FirstChanceHandler handler) {
|
|
|
|
first_chance_handler_ = handler;
|
|
|
|
}
|
|
|
|
|
2023-08-31 17:27:07 +00:00
|
|
|
void SetLastChanceExceptionHandler(LastChanceHandler handler) {
|
|
|
|
last_chance_handler_ = handler;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
// The base implementation for all signal handlers, suitable for calling
|
|
|
|
// directly to simulate signal delivery.
|
2022-01-20 08:57:13 -08:00
|
|
|
void HandleCrash(int signo, siginfo_t* siginfo, void* context) {
|
2019-05-01 22:19:21 -07:00
|
|
|
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();
|
|
|
|
|
2019-10-09 11:00:00 -07:00
|
|
|
ScopedPrSetDumpable set_dumpable(false);
|
2019-05-01 22:19:21 -07:00
|
|
|
HandleCrashImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SignalHandler() = default;
|
2020-06-23 10:01:53 -04:00
|
|
|
~SignalHandler() = default;
|
2019-05-01 22:19:21 -07:00
|
|
|
|
2019-09-09 14:07:42 -07:00
|
|
|
bool Install(const std::set<int>* unhandled_signals) {
|
2020-07-15 11:26:08 -07:00
|
|
|
bool signal_stack_initialized =
|
|
|
|
CrashpadClient::InitializeSignalStackForThread();
|
|
|
|
DCHECK(signal_stack_initialized);
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
DCHECK(!handler_);
|
|
|
|
handler_ = this;
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
return Signals::InstallCrashHandlers(HandleOrReraiseSignal,
|
|
|
|
SA_ONSTACK | SA_EXPOSE_TAGBITS,
|
|
|
|
&old_actions_,
|
|
|
|
unhandled_signals);
|
2019-05-01 22:19:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const ExceptionInformation& GetExceptionInfo() {
|
|
|
|
return exception_information_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void HandleCrashImpl() = 0;
|
|
|
|
|
|
|
|
private:
|
2022-01-20 09:45:58 -08:00
|
|
|
static constexpr int32_t kDumpNotDone = 0;
|
|
|
|
static constexpr int32_t kDumpDone = 1;
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
// The signal handler installed at OS-level.
|
|
|
|
static void HandleOrReraiseSignal(int signo,
|
|
|
|
siginfo_t* siginfo,
|
|
|
|
void* context) {
|
2022-01-20 08:57:13 -08:00
|
|
|
if (handler_->first_chance_handler_ &&
|
|
|
|
handler_->first_chance_handler_(
|
|
|
|
signo, siginfo, static_cast<ucontext_t*>(context))) {
|
2019-05-01 22:19:21 -07:00
|
|
|
return;
|
|
|
|
}
|
2022-01-20 08:57:13 -08:00
|
|
|
|
2022-01-20 09:45:58 -08:00
|
|
|
// Only handle the first fatal signal observed. If another thread receives a
|
|
|
|
// crash signal, it waits for the first dump to complete instead of
|
|
|
|
// requesting another.
|
|
|
|
if (!handler_->disabled_.test_and_set()) {
|
2022-01-20 08:57:13 -08:00
|
|
|
handler_->HandleCrash(signo, siginfo, context);
|
2022-01-20 09:45:58 -08:00
|
|
|
handler_->WakeThreads();
|
2023-08-31 17:27:07 +00:00
|
|
|
if (handler_->last_chance_handler_ &&
|
|
|
|
handler_->last_chance_handler_(
|
|
|
|
signo, siginfo, static_cast<ucontext_t*>(context))) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-20 09:45:58 -08:00
|
|
|
} else {
|
|
|
|
// Processes on Android normally have several chained signal handlers that
|
|
|
|
// co-operate to report crashes. e.g. WebView will have this signal
|
|
|
|
// handler installed, the app embedding WebView may have a signal handler
|
|
|
|
// installed, and Bionic will have a signal handler. Each signal handler
|
|
|
|
// runs in succession, possibly managed by libsigchain. This wait is
|
|
|
|
// intended to avoid ill-effects from multiple signal handlers from
|
|
|
|
// different layers (possibly all trying to use ptrace()) from running
|
|
|
|
// simultaneously. It does not block forever so that in most conditions,
|
|
|
|
// those signal handlers will still have a chance to run and ensures
|
|
|
|
// process termination in case the first crashing thread crashes again in
|
|
|
|
// its signal handler. Though less typical, this situation also occurs on
|
|
|
|
// other Linuxes, e.g. to produce in-process stack traces for debug
|
|
|
|
// builds.
|
|
|
|
handler_->WaitForDumpDone();
|
2022-01-20 08:57:13 -08:00
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(
|
|
|
|
siginfo, handler_->old_actions_.ActionForSignal(signo));
|
|
|
|
}
|
|
|
|
|
2022-01-20 09:45:58 -08:00
|
|
|
void WaitForDumpDone() {
|
|
|
|
kernel_timespec timeout;
|
|
|
|
timeout.tv_sec = 5;
|
|
|
|
timeout.tv_nsec = 0;
|
|
|
|
sys_futex(&dump_done_futex_,
|
|
|
|
FUTEX_WAIT_PRIVATE,
|
|
|
|
kDumpNotDone,
|
|
|
|
&timeout,
|
|
|
|
nullptr,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WakeThreads() {
|
|
|
|
dump_done_futex_ = kDumpDone;
|
|
|
|
sys_futex(
|
|
|
|
&dump_done_futex_, FUTEX_WAKE_PRIVATE, INT_MAX, nullptr, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
Signals::OldActions old_actions_ = {};
|
|
|
|
ExceptionInformation exception_information_ = {};
|
|
|
|
CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr;
|
2023-08-31 17:27:07 +00:00
|
|
|
LastChanceHandler last_chance_handler_ = nullptr;
|
2022-01-20 09:45:58 -08:00
|
|
|
int32_t dump_done_futex_ = kDumpNotDone;
|
2022-05-21 16:18:10 +00:00
|
|
|
#if !defined(__cpp_lib_atomic_value_initialization) || \
|
|
|
|
__cpp_lib_atomic_value_initialization < 201911L
|
2022-01-20 09:45:58 -08:00
|
|
|
std::atomic_flag disabled_ = ATOMIC_FLAG_INIT;
|
2022-05-21 16:18:10 +00:00
|
|
|
#else
|
|
|
|
std::atomic_flag disabled_;
|
|
|
|
#endif
|
2019-05-01 22:19:21 -07:00
|
|
|
|
|
|
|
static SignalHandler* handler_;
|
|
|
|
};
|
|
|
|
SignalHandler* SignalHandler::handler_ = nullptr;
|
|
|
|
|
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:
|
2021-09-20 12:55:12 -07:00
|
|
|
LaunchAtCrashHandler(const LaunchAtCrashHandler&) = delete;
|
|
|
|
LaunchAtCrashHandler& operator=(const LaunchAtCrashHandler&) = delete;
|
|
|
|
|
2018-02-01 10:39:32 -08:00
|
|
|
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-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
|
|
|
};
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
class RequestCrashDumpHandler : public SignalHandler {
|
|
|
|
public:
|
2021-09-20 12:55:12 -07:00
|
|
|
RequestCrashDumpHandler(const RequestCrashDumpHandler&) = delete;
|
|
|
|
RequestCrashDumpHandler& operator=(const RequestCrashDumpHandler&) = delete;
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
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;
|
|
|
|
}
|
2022-03-03 10:13:48 -08:00
|
|
|
if (pid > 0) {
|
|
|
|
pthread_atfork(nullptr, nullptr, SetPtracerAtFork);
|
|
|
|
if (prctl(PR_SET_PTRACER, pid, 0, 0, 0) != 0) {
|
|
|
|
PLOG(WARNING) << "prctl";
|
|
|
|
}
|
2019-05-01 22:19:21 -07:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2019-10-03 10:25:00 -07:00
|
|
|
if (sock) {
|
|
|
|
*sock = sock_to_handler_.get();
|
|
|
|
}
|
|
|
|
if (pid) {
|
|
|
|
*pid = handler_pid_;
|
|
|
|
}
|
2019-08-19 11:30:12 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
void HandleCrashImpl() override {
|
2022-03-03 10:13:48 -08:00
|
|
|
// Attempt to set the ptracer again, in case a crash occurs after a fork,
|
|
|
|
// before SetPtracerAtFork() has been called. Ignore errors because the
|
|
|
|
// system call may be disallowed if the sandbox is engaged.
|
|
|
|
if (handler_pid_ > 0) {
|
|
|
|
sys_prctl(PR_SET_PTRACER, handler_pid_, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
ExceptionHandlerProtocol::ClientInformation info = {};
|
|
|
|
info.exception_information_address =
|
|
|
|
FromPointerCast<VMAddress>(&GetExceptionInfo());
|
2021-01-12 13:45:14 -08:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
2019-08-19 15:43:02 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-12 13:45:14 -08:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
2019-08-19 15:43:02 -07:00
|
|
|
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;
|
|
|
|
|
2022-03-03 10:13:48 -08:00
|
|
|
static void SetPtracerAtFork() {
|
|
|
|
auto handler = RequestCrashDumpHandler::Get();
|
|
|
|
if (handler->handler_pid_ > 0 &&
|
|
|
|
prctl(PR_SET_PTRACER, handler->handler_pid_, 0, 0, 0) != 0) {
|
|
|
|
PLOG(WARNING) << "prctl";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
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
|
|
|
|
2021-01-12 13:45:14 -08:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
2019-08-19 15:43:02 -07:00
|
|
|
// 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
|
|
|
};
|
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,
|
2020-06-24 09:03:47 +02:00
|
|
|
bool asynchronous_start,
|
|
|
|
const std::vector<base::FilePath>& attachments) {
|
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(
|
2020-06-24 09:03:47 +02:00
|
|
|
handler, database, metrics_dir, url, annotations, arguments, attachments);
|
2019-05-01 22:19:21 -07:00
|
|
|
|
|
|
|
argv.push_back(FormatArgumentInt("initial-client-fd", handler_sock.get()));
|
|
|
|
argv.push_back("--shared-client-connection");
|
2022-06-24 19:20:54 +05:30
|
|
|
if (!SpawnSubprocess(argv, nullptr, handler_sock.get(), false, nullptr)) {
|
2019-05-01 22:19:21 -07:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-25 12:47:53 -07:00
|
|
|
handler_sock.reset();
|
2019-05-01 22:19:21 -07:00
|
|
|
|
2019-11-07 19:49:23 -08:00
|
|
|
pid_t handler_pid = -1;
|
|
|
|
if (!IsRegularFile(base::FilePath("/proc/sys/kernel/yama/ptrace_scope"))) {
|
|
|
|
handler_pid = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
auto signal_handler = RequestCrashDumpHandler::Get();
|
2019-09-09 14:07:42 -07:00
|
|
|
return signal_handler->Initialize(
|
2019-11-07 19:49:23 -08:00
|
|
|
std::move(client_sock), handler_pid, &unhandled_signals_);
|
2018-02-01 10:39:32 -08:00
|
|
|
}
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
2019-08-19 11:30:12 -07:00
|
|
|
// 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
|
|
|
}
|
2020-07-15 11:26:08 -07:00
|
|
|
|
|
|
|
// static
|
|
|
|
bool CrashpadClient::InitializeSignalStackForThread() {
|
|
|
|
stack_t stack;
|
|
|
|
if (sigaltstack(nullptr, &stack) != 0) {
|
|
|
|
PLOG(ERROR) << "sigaltstack";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_EQ(stack.ss_flags & SS_ONSTACK, 0);
|
|
|
|
|
|
|
|
const size_t page_size = getpagesize();
|
2020-07-20 13:29:44 -07:00
|
|
|
#if defined(ADDRESS_SANITIZER)
|
|
|
|
const size_t kStackSize = 2 * ((SIGSTKSZ + page_size - 1) & ~(page_size - 1));
|
|
|
|
#else
|
2020-07-15 11:26:08 -07:00
|
|
|
const size_t kStackSize = (SIGSTKSZ + page_size - 1) & ~(page_size - 1);
|
2020-07-20 13:29:44 -07:00
|
|
|
#endif // ADDRESS_SANITIZER
|
2020-07-15 11:26:08 -07:00
|
|
|
if (stack.ss_flags & SS_DISABLE || stack.ss_size < kStackSize) {
|
|
|
|
const size_t kGuardPageSize = page_size;
|
|
|
|
const size_t kStackAllocSize = kStackSize + 2 * kGuardPageSize;
|
|
|
|
|
|
|
|
static void (*stack_destructor)(void*) = [](void* stack_mem) {
|
|
|
|
const size_t page_size = getpagesize();
|
|
|
|
const size_t kGuardPageSize = page_size;
|
2020-07-20 13:29:44 -07:00
|
|
|
#if defined(ADDRESS_SANITIZER)
|
|
|
|
const size_t kStackSize =
|
|
|
|
2 * ((SIGSTKSZ + page_size - 1) & ~(page_size - 1));
|
|
|
|
#else
|
2020-07-15 11:26:08 -07:00
|
|
|
const size_t kStackSize = (SIGSTKSZ + page_size - 1) & ~(page_size - 1);
|
2020-07-20 13:29:44 -07:00
|
|
|
#endif // ADDRESS_SANITIZER
|
2020-07-15 11:26:08 -07:00
|
|
|
const size_t kStackAllocSize = kStackSize + 2 * kGuardPageSize;
|
|
|
|
|
|
|
|
stack_t stack;
|
|
|
|
stack.ss_flags = SS_DISABLE;
|
|
|
|
if (sigaltstack(&stack, &stack) != 0) {
|
|
|
|
PLOG(ERROR) << "sigaltstack";
|
|
|
|
} else if (stack.ss_sp !=
|
|
|
|
static_cast<char*>(stack_mem) + kGuardPageSize) {
|
|
|
|
PLOG_IF(ERROR, sigaltstack(&stack, nullptr) != 0) << "sigaltstack";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (munmap(stack_mem, kStackAllocSize) != 0) {
|
|
|
|
PLOG(ERROR) << "munmap";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static pthread_key_t stack_key;
|
|
|
|
static int key_error = []() {
|
|
|
|
errno = pthread_key_create(&stack_key, stack_destructor);
|
|
|
|
PLOG_IF(ERROR, errno) << "pthread_key_create";
|
|
|
|
return errno;
|
|
|
|
}();
|
|
|
|
if (key_error) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto old_stack = static_cast<char*>(pthread_getspecific(stack_key));
|
|
|
|
if (old_stack) {
|
|
|
|
stack.ss_sp = old_stack + kGuardPageSize;
|
|
|
|
} else {
|
|
|
|
ScopedMmap stack_mem;
|
|
|
|
if (!stack_mem.ResetMmap(nullptr,
|
|
|
|
kStackAllocSize,
|
|
|
|
PROT_NONE,
|
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS,
|
|
|
|
-1,
|
|
|
|
0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mprotect(stack_mem.addr_as<char*>() + kGuardPageSize,
|
|
|
|
kStackSize,
|
|
|
|
PROT_READ | PROT_WRITE) != 0) {
|
|
|
|
PLOG(ERROR) << "mprotect";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.ss_sp = stack_mem.addr_as<char*>() + kGuardPageSize;
|
|
|
|
|
|
|
|
errno = pthread_setspecific(stack_key, stack_mem.release());
|
|
|
|
PCHECK(errno == 0) << "pthread_setspecific";
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.ss_size = kStackSize;
|
|
|
|
stack.ss_flags =
|
|
|
|
(stack.ss_flags & SS_DISABLE) ? 0 : stack.ss_flags & SS_AUTODISARM;
|
|
|
|
if (sigaltstack(&stack, nullptr) != 0) {
|
|
|
|
PLOG(ERROR) << "sigaltstack";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2022-01-19 15:00:24 -05:00
|
|
|
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) ||
|
|
|
|
// BUILDFLAG(IS_CHROMEOS)
|
2019-08-19 11:30:12 -07:00
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2018-08-29 09:00:15 -07:00
|
|
|
|
|
|
|
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);
|
2022-06-24 19:20:54 +05:30
|
|
|
return SpawnSubprocess(argv, env, socket, false, nullptr);
|
2018-08-29 09:00:15 -07:00
|
|
|
}
|
|
|
|
|
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);
|
2022-06-24 19:20:54 +05:30
|
|
|
return SpawnSubprocess(argv, env, socket, false, nullptr);
|
2019-02-21 17:26:25 -08:00
|
|
|
}
|
|
|
|
|
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,
|
2020-06-24 09:03:47 +02:00
|
|
|
const std::vector<std::string>& arguments,
|
|
|
|
const std::vector<base::FilePath>& attachments) {
|
2018-07-20 15:56:49 -04:00
|
|
|
std::vector<std::string> argv = BuildHandlerArgvStrings(
|
2020-06-24 09:03:47 +02:00
|
|
|
handler, database, metrics_dir, url, annotations, arguments, attachments);
|
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
|
|
|
|
2022-06-24 19:20:54 +05:30
|
|
|
return SpawnSubprocess(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) {
|
2022-01-20 09:45:58 -08:00
|
|
|
SignalHandler::Disable();
|
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
|
|
|
}
|
|
|
|
|
2023-08-31 17:27:07 +00:00
|
|
|
// static
|
|
|
|
void CrashpadClient::SetLastChanceExceptionHandler(LastChanceHandler handler) {
|
|
|
|
DCHECK(SignalHandler::Get());
|
|
|
|
SignalHandler::Get()->SetLastChanceExceptionHandler(handler);
|
|
|
|
}
|
|
|
|
|
2019-09-09 14:07:42 -07:00
|
|
|
void CrashpadClient::SetUnhandledSignals(const std::set<int>& signals) {
|
|
|
|
DCHECK(!SignalHandler::Get());
|
|
|
|
unhandled_signals_ = signals;
|
|
|
|
}
|
|
|
|
|
2021-01-12 13:45:14 -08:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
2019-08-19 15:43:02 -07:00
|
|
|
// 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
|