Commit b70a3647 authored by Siddhartha's avatar Siddhartha Committed by Commit Bot

Fix crash on unwinder while trying to unwind java frames

Remove java mapped regions so that the unwinder does not try unwinding
these frames at all.

BUG=888434

Change-Id: Ic5999652ec85a4a3ed04aa7e8030d0a3faf11fbd
Reviewed-on: https://chromium-review.googlesource.com/c/1327424
Commit-Queue: ssid <ssid@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607002}
parent c5358e29
......@@ -17,6 +17,8 @@
#include "base/debug/proc_maps_linux.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/trace_event/cfi_backtrace_android.h"
#include "libunwind.h"
......@@ -370,16 +372,26 @@ void StackUnwinderAndroid::Initialize() {
// Parses /proc/self/maps.
std::string contents;
if (!base::debug::ReadProcMaps(&contents)) {
if (!base::debug::ReadProcMaps(&contents))
NOTREACHED();
}
if (!base::debug::ParseProcMaps(contents, &regions_)) {
std::vector<base::debug::MappedMemoryRegion> regions;
if (!base::debug::ParseProcMaps(contents, &regions))
NOTREACHED();
}
std::sort(regions_.begin(), regions_.end(),
// Remove any regions mapped to art java code, so that unwinder doesn't try to
// walk past java frames. Walking java frames causes crashes, crbug/888434.
base::EraseIf(regions, [](const base::debug::MappedMemoryRegion& region) {
return region.path.empty() ||
base::EndsWith(region.path, ".art", base::CompareCase::SENSITIVE) ||
base::EndsWith(region.path, ".oat", base::CompareCase::SENSITIVE) ||
base::EndsWith(region.path, ".jar", base::CompareCase::SENSITIVE) ||
base::EndsWith(region.path, ".vdex", base::CompareCase::SENSITIVE);
});
std::sort(regions.begin(), regions.end(),
[](const MappedMemoryRegion& a, const MappedMemoryRegion& b) {
return a.start < b.start;
});
regions_.swap(regions);
}
size_t StackUnwinderAndroid::TraceStack(const void** out_trace,
......
......@@ -74,7 +74,8 @@ TEST_F(StackUnwinderTest, UnwindOtherThread) {
bool current_function_found = false;
for (size_t i = 0; i < result; ++i) {
uintptr_t addr = reinterpret_cast<uintptr_t>(frames[i]);
EXPECT_TRUE(unwinder->IsAddressMapped(addr));
if (addr != 0)
EXPECT_TRUE(unwinder->IsAddressMapped(addr));
if (addr >= test_pc && addr < test_pc + 100)
current_function_found = true;
}
......
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