From 7003473458c8bcb10fc2acf13e3709cc1a1eb484 Mon Sep 17 00:00:00 2001 From: Vlad Tsyrklevich Date: Tue, 14 May 2019 00:20:08 +0000 Subject: [PATCH] GWP-ASan: Add Linux crash handler support Linux crashpad support is now sufficiently enabled to allow running the GWP-ASan crash handler unit tests under Linux. (The client tests are still blocked on allocator shim updates.) Change-Id: I409cebaa9cdaed5da546266d0af470d2b25a09ab Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610605 Auto-Submit: Vlad Tsyrklevich Commit-Queue: Vitaly Buka Reviewed-by: Vitaly Buka Cr-Commit-Position: refs/heads/master@{#659296} --- components/gwp_asan/BUILD.gn | 8 +++---- components/gwp_asan/crash_handler/BUILD.gn | 1 + .../crash_handler/crash_analyzer_linux.cc | 23 +++++++++++++++++++ .../crash_handler/crash_handler_unittest.cc | 6 +++-- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 components/gwp_asan/crash_handler/crash_analyzer_linux.cc diff --git a/components/gwp_asan/BUILD.gn b/components/gwp_asan/BUILD.gn index 5176c8cef6e27b..6c6df8a6c69e6e 100644 --- a/components/gwp_asan/BUILD.gn +++ b/components/gwp_asan/BUILD.gn @@ -8,9 +8,9 @@ source_set("unit_tests") { "//components/gwp_asan/common:unit_tests", ] if (is_win || is_mac) { - deps += [ - "//components/gwp_asan/client:unit_tests", - "//components/gwp_asan/crash_handler:unit_tests", - ] + deps += [ "//components/gwp_asan/client:unit_tests" ] + } + if (is_win || is_mac || is_linux) { + deps += [ "//components/gwp_asan/crash_handler:unit_tests" ] } } diff --git a/components/gwp_asan/crash_handler/BUILD.gn b/components/gwp_asan/crash_handler/BUILD.gn index 3757ab0873efc9..1152d51f3a3482 100644 --- a/components/gwp_asan/crash_handler/BUILD.gn +++ b/components/gwp_asan/crash_handler/BUILD.gn @@ -8,6 +8,7 @@ static_library("crash_handler") { sources = [ "crash_analyzer.cc", "crash_analyzer.h", + "crash_analyzer_linux.cc", "crash_analyzer_mac.cc", "crash_analyzer_win.cc", "crash_handler.cc", diff --git a/components/gwp_asan/crash_handler/crash_analyzer_linux.cc b/components/gwp_asan/crash_handler/crash_analyzer_linux.cc new file mode 100644 index 00000000000000..4f44f0e881264d --- /dev/null +++ b/components/gwp_asan/crash_handler/crash_analyzer_linux.cc @@ -0,0 +1,23 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/gwp_asan/crash_handler/crash_analyzer.h" + +#include + +#include "third_party/crashpad/crashpad/snapshot/exception_snapshot.h" + +namespace gwp_asan { +namespace internal { + +crashpad::VMAddress CrashAnalyzer::GetAccessAddress( + const crashpad::ExceptionSnapshot& exception) { + if (exception.Exception() != SIGSEGV && exception.Exception() != SIGBUS) + return 0; + + return exception.ExceptionAddress(); +} + +} // namespace internal +} // namespace gwp_asan diff --git a/components/gwp_asan/crash_handler/crash_handler_unittest.cc b/components/gwp_asan/crash_handler/crash_handler_unittest.cc index 80e86a2542340a..7a9973122c02c7 100644 --- a/components/gwp_asan/crash_handler/crash_handler_unittest.cc +++ b/components/gwp_asan/crash_handler/crash_handler_unittest.cc @@ -270,13 +270,15 @@ class CrashHandlerTest : public base::MultiProcessTest, EXPECT_TRUE(proto_.has_allocation()); EXPECT_TRUE(proto_.allocation().has_thread_id()); - EXPECT_NE(proto_.allocation().thread_id(), base::kInvalidThreadId); + EXPECT_NE(proto_.allocation().thread_id(), + static_cast(base::kInvalidThreadId)); EXPECT_GT(proto_.allocation().stack_trace_size(), 0); EXPECT_EQ(proto_.has_deallocation(), has_deallocation); if (has_deallocation) { EXPECT_TRUE(proto_.deallocation().has_thread_id()); - EXPECT_NE(proto_.deallocation().thread_id(), base::kInvalidThreadId); + EXPECT_NE(proto_.deallocation().thread_id(), + static_cast(base::kInvalidThreadId)); EXPECT_EQ(proto_.allocation().thread_id(), proto_.deallocation().thread_id()); EXPECT_GT(proto_.deallocation().stack_trace_size(), 0);