summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Phillips <mitchp@google.com>2020-02-11 17:33:48 -0800
committerMitch Phillips <mitchp@google.com>2020-02-12 11:25:42 -0800
commita6337dbb13503018ae7a6b80ab04384b2537eeee (patch)
treeccd436fd9e25c0382b5e0ebb023762973c6053c3
parent0e3245fdb39ccf2e8a5364084706ce5d6065c5a0 (diff)
downloadextras-a6337dbb13503018ae7a6b80ab04384b2537eeee.tar.gz
[GWP-ASan] Scan GWP-ASan regions in maps.
GWP-ASan is part of the native allocator, and may allocate some memory. If a trace comes from a GWP-ASan sampled process, we need to identify GWP-ASan allocations as from the native heap. Bug: 135634846 Test: atest memory_replay_tests Change-Id: Icd1122130a30af5604554a62d270dc1967117570
-rw-r--r--memory_replay/NativeInfo.cpp3
-rw-r--r--memory_replay/tests/NativeInfoTest.cpp54
2 files changed, 53 insertions, 4 deletions
diff --git a/memory_replay/NativeInfo.cpp b/memory_replay/NativeInfo.cpp
index ec131ddc..3439a29d 100644
--- a/memory_replay/NativeInfo.cpp
+++ b/memory_replay/NativeInfo.cpp
@@ -76,7 +76,8 @@ void NativeGetInfo(int smaps_fd, size_t* rss_bytes, size_t* va_bytes) {
&name_pos) == 2) {
char* map_name = &buf[buf_start + name_pos];
if (strcmp(map_name, "[anon:libc_malloc]") == 0 || strcmp(map_name, "[heap]") == 0 ||
- strncmp(map_name, "[anon:scudo:", 12) == 0) {
+ strncmp(map_name, "[anon:scudo:", 12) == 0 ||
+ strncmp(map_name, "[anon:GWP-ASan", 14) == 0) {
total_va_bytes += end - start;
native_map = true;
} else {
diff --git a/memory_replay/tests/NativeInfoTest.cpp b/memory_replay/tests/NativeInfoTest.cpp
index 845ec043..5c33eb71 100644
--- a/memory_replay/tests/NativeInfoTest.cpp
+++ b/memory_replay/tests/NativeInfoTest.cpp
@@ -269,7 +269,55 @@ TEST_F(NativeInfoTest, mix_heap_anon) {
"KernelPageSize: 4 kB\n"
"MMUPageSize: 4 kB\n"
"Locked: 0 kB\n"
- "Name: [anon:scudo:test]\n";
+ "Name: [anon:scudo:test]\n"
+ "b8f4c000-b8f4d000 rw-p 00000000 00:00 0 [anon:GWP-ASan Guard Page]\n"
+ "Size: 4 kB\n"
+ "Rss: 0 kB\n"
+ "Pss: 0 kB\n"
+ "Shared_Clean: 0 kB\n"
+ "Shared_Dirty: 0 kB\n"
+ "Private_Clean: 0 kB\n"
+ "Private_Dirty: 0 kB\n"
+ "Referenced: 0 kB\n"
+ "Anonymous: 0 kB\n"
+ "AnonHugePages: 0 kB\n"
+ "Swap: 0 kB\n"
+ "KernelPageSize: 4 kB\n"
+ "MMUPageSize: 4 kB\n"
+ "Locked: 0 kB\n"
+ "Name: [anon:GWP-ASan Guard Page]\n"
+ "b8f4d000-b8f4e000 rw-p 00000000 00:00 0 [anon:GWP-ASan Alive Slot]\n"
+ "Size: 4 kB\n"
+ "Rss: 4 kB\n"
+ "Pss: 0 kB\n"
+ "Shared_Clean: 0 kB\n"
+ "Shared_Dirty: 0 kB\n"
+ "Private_Clean: 0 kB\n"
+ "Private_Dirty: 0 kB\n"
+ "Referenced: 0 kB\n"
+ "Anonymous: 0 kB\n"
+ "AnonHugePages: 0 kB\n"
+ "Swap: 0 kB\n"
+ "KernelPageSize: 4 kB\n"
+ "MMUPageSize: 4 kB\n"
+ "Locked: 0 kB\n"
+ "Name: [anon:GWP-ASan Alive Slot]\n"
+ "b8f4e000-b8f4f000 rw-p 00000000 00:00 0 [anon:GWP-ASan Guard Page]\n"
+ "Size: 4 kB\n"
+ "Rss: 0 kB\n"
+ "Pss: 0 kB\n"
+ "Shared_Clean: 0 kB\n"
+ "Shared_Dirty: 0 kB\n"
+ "Private_Clean: 0 kB\n"
+ "Private_Dirty: 0 kB\n"
+ "Referenced: 0 kB\n"
+ "Anonymous: 0 kB\n"
+ "AnonHugePages: 0 kB\n"
+ "Swap: 0 kB\n"
+ "KernelPageSize: 4 kB\n"
+ "MMUPageSize: 4 kB\n"
+ "Locked: 0 kB\n"
+ "Name: [anon:GWP-ASan Guard Page]\n";
ASSERT_TRUE(TEMP_FAILURE_RETRY(
write(tmp_file_->fd, smaps_data.c_str(), smaps_data.size())) != -1);
@@ -278,6 +326,6 @@ TEST_F(NativeInfoTest, mix_heap_anon) {
size_t rss_bytes = 1;
size_t va_bytes = 1;
NativeGetInfo(tmp_file_->fd, &rss_bytes, &va_bytes);
- EXPECT_EQ(126976U, rss_bytes);
- EXPECT_EQ(147456U, va_bytes);
+ EXPECT_EQ(131072U, rss_bytes);
+ EXPECT_EQ(159744U, va_bytes);
}