summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus <scherkus@chromium.org>2014-11-20 17:36:04 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-21 01:37:09 +0000
commitaff972d18bdd0dae7ec54bdae71c14baacbc868f (patch)
treeccb6339398a5a50d4189bc428b28b26d4709f2e5
parent2c16c6099f1f799509a19bacf6b04add78410e55 (diff)
downloadchromium_src-aff972d18bdd0dae7ec54bdae71c14baacbc868f.zip
chromium_src-aff972d18bdd0dae7ec54bdae71c14baacbc868f.tar.gz
chromium_src-aff972d18bdd0dae7ec54bdae71c14baacbc868f.tar.bz2
Fix ProcMapsTest.ReadProcMaps to handle stacks created by Valgrind.
Valgrind uses its own stacks without calling prctl(PR_SET_MM_START_STACK). This makes the kernel use the "[stack:TID]" format when reading from /proc/self/maps. Update the test to explicitly handle this case as well as checking for the executable bit on Valgrind-created stacks. BUG=431702 Review URL: https://codereview.chromium.org/730683002 Cr-Commit-Position: refs/heads/master@{#305135}
-rw-r--r--base/debug/proc_maps_linux_unittest.cc29
1 files changed, 22 insertions, 7 deletions
diff --git a/base/debug/proc_maps_linux_unittest.cc b/base/debug/proc_maps_linux_unittest.cc
index d5d1b83..142f891 100644
--- a/base/debug/proc_maps_linux_unittest.cc
+++ b/base/debug/proc_maps_linux_unittest.cc
@@ -7,6 +7,7 @@
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
+#include "base/threading/platform_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -197,6 +198,14 @@ TEST(ProcMapsTest, ReadProcMaps) {
bool found_exe = false;
bool found_stack = false;
bool found_address = false;
+
+ // Valgrind uses its own allocated stacks instead of the kernel-provided stack
+ // without letting the kernel know via prctl(PR_SET_MM_START_STACK). This
+ // causes the kernel to use [stack:TID] format. See http://crbug.com/431702
+ // for details.
+ std::string stack_with_tid =
+ StringPrintf("[stack:%d]", PlatformThread::CurrentId());
+
for (size_t i = 0; i < regions.size(); ++i) {
if (regions[i].path == exe_path.value()) {
// It's OK to find the executable mapped multiple times as there'll be
@@ -204,17 +213,23 @@ TEST(ProcMapsTest, ReadProcMaps) {
found_exe = true;
}
+ bool is_correct_stack = false;
if (regions[i].path == "[stack]") {
- // Only check if |address| lies within the real stack when not running
- // Valgrind, otherwise |address| will be on a stack that Valgrind creates.
- if (!RunningOnValgrind()) {
- EXPECT_GE(address, regions[i].start);
- EXPECT_LT(address, regions[i].end);
- }
+ is_correct_stack = true;
+ EXPECT_FALSE(RunningOnValgrind());
+ EXPECT_GE(address, regions[i].start);
+ EXPECT_LT(address, regions[i].end);
+ } else if (regions[i].path == stack_with_tid) {
+ is_correct_stack = true;
+ EXPECT_TRUE(RunningOnValgrind());
+ }
+ if (is_correct_stack) {
+ // Note that the stack is executable when it is created by Valgrind.
EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::READ);
EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::WRITE);
- EXPECT_FALSE(regions[i].permissions & MappedMemoryRegion::EXECUTE);
+ EXPECT_EQ(RunningOnValgrind(),
+ (regions[i].permissions & MappedMemoryRegion::EXECUTE) != 0);
EXPECT_TRUE(regions[i].permissions & MappedMemoryRegion::PRIVATE);
EXPECT_FALSE(found_stack) << "Found duplicate stacks";
found_stack = true;