Skip to content

Commit

Permalink
Make exegesis annotator work with mappings that aren't page aligned
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 committed Jan 27, 2024
1 parent 47f0a6f commit d050085
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 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,8 @@ Expected<AccessedAddrs> ExegesisAnnotator::findAccessedAddrs(
handleAllErrors(std::move(std::get<0>(BenchmarkResultOrErr)),
[&](SnippetSegmentationFault &CrashInfo) {
MemoryMapping MemMap;
MemMap.Address = CrashInfo.getAddress();
uintptr_t MapAddress = (CrashInfo.getAddress() / 4096) * 4096;
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 d050085

Please sign in to comment.