[windows] Register an absl abort hook in the same fashion as OOM termination
Previously, the abort hook was only being registered for the copy of absl linked into chrome_elf.dll. Move registration out of the crash handler and into the various modules that may contain crashy code (a la EnableTerminationOnOutOfMemory). This ensures that it's registered in chrome.exe and chrome.dll so that we get nice crashes from FATAL absl errors in all modules. Fixed: 41494817 Change-Id: I2435e989cedae37bd950a463a6748fc16e8cfc73 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5692058 Auto-Submit: Greg Thompson <grt@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Reviewed-by: Avi Drissman <avi@chromium.org> Commit-Queue: Avi Drissman <avi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1325462}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
00438166bb
commit
0f08354422
base
chrome
app
credential_provider
elevation_service
installer
setup
notification_helper
updater
components
content/app
@ -60,6 +60,7 @@
|
||||
#include "base/vlog.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "third_party/abseil-cpp/absl/base/internal/raw_logging.h"
|
||||
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
|
||||
|
||||
#if !BUILDFLAG(IS_NACL)
|
||||
@ -644,6 +645,30 @@ void SetShowErrorDialogs(bool enable_dialogs) {
|
||||
show_error_dialogs = enable_dialogs;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
[[noreturn]] void AbslAbortHook(const char* file,
|
||||
int line,
|
||||
const char* buf_start,
|
||||
const char* prefix_end,
|
||||
const char* buf_end) {
|
||||
// This simulates a CHECK(false) at file:line instead of here. This is used
|
||||
// instead of base::ImmediateCrash() to give better error messages locally
|
||||
// (printed stack for one).
|
||||
LogMessageFatal(file, line, LOGGING_FATAL).stream()
|
||||
<< "Check failed: false. " << prefix_end;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void RegisterAbslAbortHook() {
|
||||
// TODO(pbos): Update this to not rely on a _internal namespace once there's
|
||||
// a public API in absl::.
|
||||
// Note: If this fails to compile because of an absl roll, this is fair to
|
||||
// remove if you file a crbug.com/new and assign it to pbos@.
|
||||
::absl::raw_log_internal::RegisterAbortHook(&AbslAbortHook);
|
||||
}
|
||||
|
||||
ScopedLogAssertHandler::ScopedLogAssertHandler(
|
||||
LogAssertHandlerFunction handler) {
|
||||
GetLogAssertHandlerStack().push(std::move(handler));
|
||||
|
@ -334,6 +334,11 @@ BASE_EXPORT void SetLogPrefix(const char* prefix);
|
||||
// Dialogs are not shown by default.
|
||||
BASE_EXPORT void SetShowErrorDialogs(bool enable_dialogs);
|
||||
|
||||
// Registers an abort hook with absl that will crash the process similarly to a
|
||||
// `CHECK` failure in case of a FATAL error in absl (e.g., any operation that
|
||||
// would throw an exception).
|
||||
BASE_EXPORT void RegisterAbslAbortHook();
|
||||
|
||||
// Sets the Log Assert Handler that will be used to notify of check failures.
|
||||
// Resets Log Assert Handler on object destruction.
|
||||
// The default handler shows a dialog box and then terminate the process,
|
||||
|
@ -255,6 +255,7 @@ int main() {
|
||||
// Done here to ensure that OOMs that happen early in process initialization
|
||||
// are correctly signaled to the OS.
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
|
||||
// Initialize the CommandLine singleton from the environment.
|
||||
base::CommandLine::Init(0, nullptr);
|
||||
|
@ -95,6 +95,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
// Make sure the process exits cleanly on unexpected errors.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(*base::CommandLine::ForCurrentProcess());
|
||||
|
||||
|
@ -115,6 +115,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
// Make sure the process exits cleanly on unexpected errors.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(*base::CommandLine::ForCurrentProcess());
|
||||
|
||||
|
@ -43,6 +43,7 @@ extern "C" int WINAPI wWinMain(HINSTANCE instance,
|
||||
// Make sure the process exits cleanly on unexpected errors.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(*base::CommandLine::ForCurrentProcess());
|
||||
|
||||
|
@ -1396,6 +1396,7 @@ int SetupMain() {
|
||||
// Make sure the process exits cleanly on unexpected errors.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(cmd_line);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "base/at_exit.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/metrics/histogram_functions.h"
|
||||
#include "base/metrics/persistent_histogram_storage.h"
|
||||
#include "base/process/memory.h"
|
||||
@ -67,6 +68,7 @@ extern "C" int WINAPI wWinMain(HINSTANCE instance,
|
||||
// Make sure the process exits cleanly on unexpected errors.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(*base::CommandLine::ForCurrentProcess());
|
||||
|
||||
|
@ -125,6 +125,7 @@ int HandleUpdaterCommands(UpdaterScope updater_scope,
|
||||
// Make the process more resilient to memory allocation issues.
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
|
||||
InitializeThreadPool("updater");
|
||||
const base::ScopedClosureRunner shutdown_thread_pool(base::BindOnce([] {
|
||||
|
@ -15,10 +15,10 @@
|
||||
|
||||
#include "base/auto_reset.h"
|
||||
#include "base/base_paths.h"
|
||||
#include "base/check.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/debug/crash_logging.h"
|
||||
#include "base/debug/dump_without_crashing.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
@ -29,7 +29,6 @@
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "components/crash/core/app/crash_reporter_client.h"
|
||||
#include "components/crash/core/common/crash_key.h"
|
||||
#include "third_party/abseil-cpp/absl/base/internal/raw_logging.h"
|
||||
#include "third_party/crashpad/crashpad/client/annotation.h"
|
||||
#include "third_party/crashpad/crashpad/client/annotation_list.h"
|
||||
#include "third_party/crashpad/crashpad/client/crash_report_database.h"
|
||||
@ -57,18 +56,6 @@ crashpad::StringAnnotation<24>& PlatformStorage() {
|
||||
|
||||
namespace {
|
||||
|
||||
void AbslAbortHook(const char* file,
|
||||
int line,
|
||||
const char* buf_start,
|
||||
const char* prefix_end,
|
||||
const char* buf_end) {
|
||||
// This simulates that a CHECK(false) was done at file:line instead of here.
|
||||
// This is used instead of base::ImmediateCrash() to give better error
|
||||
// messages locally (printed stack for one).
|
||||
logging::LogMessageFatal check_failure(file, line, logging::LOGGING_FATAL);
|
||||
check_failure.stream() << "Check failed: false. " << prefix_end;
|
||||
}
|
||||
|
||||
base::FilePath* g_database_path;
|
||||
|
||||
crashpad::CrashReportDatabase* g_database;
|
||||
@ -170,12 +157,6 @@ bool InitializeCrashpadImpl(bool initial_client,
|
||||
// the same file and line.
|
||||
base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing);
|
||||
|
||||
// TODO(pbos): Update this to not rely on a _internal namespace once there's
|
||||
// a public API in absl::.
|
||||
// Note: If this fails to compile because of an absl roll, this is fair to
|
||||
// remove if you file a crbug.com/new and assign it to pbos@.
|
||||
absl::raw_log_internal::RegisterAbortHook(&AbslAbortHook);
|
||||
|
||||
#if BUILDFLAG(IS_APPLE)
|
||||
// On Mac, we only want the browser to initialize the database, but not the
|
||||
// relauncher.
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/process/memory.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
@ -35,6 +36,7 @@ int RunAsCrashpadHandler(const base::CommandLine& command_line,
|
||||
// Make sure this process terminates on OOM in the same mode as other Chrome
|
||||
// processes.
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
|
||||
base::PlatformThread::SetName("CrashpadMainThread");
|
||||
|
||||
|
@ -29,6 +29,7 @@ void InitLogging() {
|
||||
void InitErrorHandling(const base::CommandLine& command_line) {
|
||||
base::EnableTerminationOnHeapCorruption();
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
base::win::RegisterInvalidParamHandler();
|
||||
base::win::SetupCRT(command_line);
|
||||
|
@ -205,6 +205,7 @@ RunContentProcess(ContentMainParams params,
|
||||
allocator_shim::InitializeAllocatorShim();
|
||||
#endif
|
||||
base::EnableTerminationOnOutOfMemory();
|
||||
logging::RegisterAbslAbortHook();
|
||||
|
||||
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
||||
// The various desktop environments set this environment variable that
|
||||
|
Reference in New Issue
Block a user