From 707d0d4dac6717d46e4d5e82f88dfea19df38c5a Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Fri, 3 Mar 2023 13:34:02 -0500 Subject: [PATCH] Restrict new crash_reporter flag to valid versions Lacros can be up to 2 milestones ahead of ash (and consequently the platform code), so until the crash_reporter change has been in for 2 milestones, we need to manually check version compatibility. BUG=chromium:1420445 TEST=Build, deploy, check that flag is set only on right version Change-Id: Ic99d5ac58840814f7eeecd47c628ea0e8107f675 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4308129 Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- handler/BUILD.gn | 4 +++ .../cros_crash_report_exception_handler.cc | 32 ++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/handler/BUILD.gn b/handler/BUILD.gn index e5d488e2..02bf11a6 100644 --- a/handler/BUILD.gn +++ b/handler/BUILD.gn @@ -49,6 +49,10 @@ static_library("handler") { "linux/cros_crash_report_exception_handler.cc", "linux/cros_crash_report_exception_handler.h", ] + # TODO(https://crbug.com/1420445): Remove this config when M115 branches. + configs += [ + "../build:crashpad_is_in_chromium", + ] } if (crashpad_is_win) { diff --git a/handler/linux/cros_crash_report_exception_handler.cc b/handler/linux/cros_crash_report_exception_handler.cc index 86142883..bfccd1f2 100644 --- a/handler/linux/cros_crash_report_exception_handler.cc +++ b/handler/linux/cros_crash_report_exception_handler.cc @@ -18,6 +18,9 @@ #include "base/logging.h" #include "base/strings/stringprintf.h" +#if defined(CRASHPAD_IS_IN_CHROMIUM) +#include "base/system/sys_info.h" +#endif // CRASHPAD_IS_IN_CHROMIUM #include "client/settings.h" #include "handler/linux/capture_snapshot.h" #include "handler/minidump_to_upload_parameters.h" @@ -247,15 +250,28 @@ bool CrosCrashReportExceptionHandler::HandleExceptionWithConnection( // crash_reporter needs to know the pid and uid of the crashing process. std::vector argv({"/sbin/crash_reporter"}); - // Used to distinguish between non-fatal and fatal crashes. - const ExceptionSnapshot* const exception_snapshot = snapshot->Exception(); - if (exception_snapshot) { - // convert to int32, since crashpad uses -1 as a signal for non-fatal - // crashes. - argv.push_back(base::StringPrintf( - "--chrome_signal=%d", - static_cast(exception_snapshot->Exception()))); +#if defined(CRASHPAD_IS_IN_CHROMIUM) + int32_t major_version = 0, minor_version = 0, bugfix_version = 0; + base::SysInfo::OperatingSystemVersionNumbers( + &major_version, &minor_version, &bugfix_version); + // The version on which https://crrev.com/c/4265753 landed. + constexpr int32_t kFixedVersion = 15363; + // TODO(https://crbug.com/1420445): Remove this check (and the + // CRASHPAD_IS_IN_CHROMIUM defines) when M115 branches. + // (Lacros is guaranteed not to be more than 2 milestones ahead of ash, and + // M113 on ash has the relevant crash_reporter change.) + if (major_version >= kFixedVersion) { + // Used to distinguish between non-fatal and fatal crashes. + const ExceptionSnapshot* const exception_snapshot = snapshot->Exception(); + if (exception_snapshot) { + // convert to int32, since crashpad uses -1 as a signal for non-fatal + // crashes. + argv.push_back(base::StringPrintf( + "--chrome_signal=%d", + static_cast(exception_snapshot->Exception()))); + } } +#endif // CRASHPAD_IS_IN_CHROMIUM argv.push_back("--chrome_memfd=" + std::to_string(file_writer.fd()));