Commit 96b9a68c authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich Committed by Commit Bot

GWP-ASan: Refactor CrashAnalyzer::GetAccessAddress

Having seperate files for a single routine is excessive, especially now
that Android and Linux share a common implementation while Android
doesn't pull in _linux suffixed files.

Bug: 973167
Change-Id: If7011917256e20739db84df2f240f96aca4dd8d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1671631
Auto-Submit: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: default avatarVitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671561}
parent 260c1dd4
......@@ -8,9 +8,6 @@ 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",
"crash_handler.h",
]
......
......@@ -8,6 +8,7 @@
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
......@@ -25,6 +26,14 @@
#include "third_party/crashpad/crashpad/snapshot/process_snapshot.h"
#include "third_party/crashpad/crashpad/util/process/process_memory.h"
#if defined(OS_LINUX) || defined(OS_ANDROID)
#include <signal.h>
#elif defined(OS_MACOSX)
#include <mach/exception_types.h>
#elif defined(OS_WIN)
#include <windows.h>
#endif
namespace gwp_asan {
namespace internal {
......@@ -70,6 +79,29 @@ bool CrashAnalyzer::GetExceptionInfo(
return false;
}
crashpad::VMAddress CrashAnalyzer::GetAccessAddress(
const crashpad::ExceptionSnapshot& exception) {
#if defined(OS_LINUX) || defined(OS_ANDROID)
if (exception.Exception() == SIGSEGV || exception.Exception() == SIGBUS)
return exception.ExceptionAddress();
#elif defined(OS_MACOSX)
if (exception.Exception() == EXC_BAD_ACCESS)
return exception.ExceptionAddress();
#elif defined(OS_WIN)
if (exception.Exception() == EXCEPTION_ACCESS_VIOLATION) {
const std::vector<uint64_t>& codes = exception.Codes();
if (codes.size() < 2)
DLOG(FATAL) << "Exception array is too small! " << codes.size();
else
return codes[1];
}
#else
#error "Unknown platform"
#endif
return 0;
}
crashpad::VMAddress CrashAnalyzer::GetAllocatorAddress(
const crashpad::ProcessSnapshot& process_snapshot,
const char* annotation_name) {
......
// 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 <signal.h>
#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
// 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 <mach/exception_types.h>
#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() != EXC_BAD_ACCESS)
return 0;
return exception.ExceptionAddress();
}
} // namespace internal
} // namespace gwp_asan
// Copyright 2018 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 <windows.h>
#include "base/logging.h"
#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() != EXCEPTION_ACCESS_VIOLATION)
return 0;
const std::vector<uint64_t>& codes = exception.Codes();
if (codes.size() < 2) {
DLOG(FATAL) << "Exception array is too small! " << codes.size();
return 0;
}
return codes[1];
}
} // namespace internal
} // namespace gwp_asan
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment