Skip to content

Commit

Permalink
Make exegesis annotator work with mappings that aren't page aligned (#33
Browse files Browse the repository at this point in the history
)

This patch makes the exegesis annotator work with mappings that are not
page aligned. Currently if a segfault occurs at an address that isn't
page aligned, Exegesis will try and map an address at that address and
then the mmap call will silently fail as there is no error handling
wired up for that and it will segfault again, thus creating a loop
within the annotator.
  • Loading branch information
boomanaiden154 authored Feb 3, 2024
1 parent 671d245 commit 1cc6a50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gematria/datasets/find_accessed_addrs_exegesis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ Expected<AccessedAddrs> ExegesisAnnotator::findAccessedAddrs(
handleAllErrors(std::move(std::get<0>(BenchmarkResultOrErr)),
[&](SnippetSegmentationFault &CrashInfo) {
MemoryMapping MemMap;
MemMap.Address = CrashInfo.getAddress();
// Zero out the last twelve bits of the address to align
// the address to a page boundary.
uintptr_t MapAddress = (CrashInfo.getAddress() & ~0xfff);
MemMap.Address = MapAddress;
MemMap.MemoryValueName = "memdef1";
BenchCode.Key.MemoryMappings.push_back(MemMap);
});
Expand Down
11 changes: 11 additions & 0 deletions gematria/datasets/find_accessed_addrs_exegesis_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,16 @@ TEST_F(FindAccessedAddrsExegesisTest, ExegesisOneAccess) {
EXPECT_EQ(Result.accessed_blocks[0], 0x10000);
}

TEST_F(FindAccessedAddrsExegesisTest, ExegesisNotPageAligned) {
auto AddrsOrErr = FindAccessedAddrsExegesis(R"asm(
movq $0x10001, %rax
movq (%rax), %rax
)asm");
ASSERT_TRUE(static_cast<bool>(AddrsOrErr));
AccessedAddrs Result = *AddrsOrErr;
EXPECT_EQ(Result.accessed_blocks.size(), 1);
EXPECT_EQ(Result.accessed_blocks[0], 0x10000);
}

} // namespace
} // namespace gematria

0 comments on commit 1cc6a50

Please sign in to comment.