Skip to content

Commit 136b2b8

Browse files
committed
[win/asan] GetInstructionSize: Add a test explicitly for this function.
1 parent aaf1235 commit 136b2b8

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

compiler-rt/lib/interception/interception_win.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,11 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
917917
return 0;
918918
}
919919

920+
// Unfortunately size_t is not known when compiling asan_allocator.cpp
921+
SIZE_T test_GetInstructionSize(uptr address, SIZE_T* rel_offset) {
922+
return GetInstructionSize(address, rel_offset);
923+
}
924+
920925
// Returns 0 on error.
921926
static size_t RoundUpToInstrBoundary(size_t size, uptr address) {
922927
size_t cursor = 0;

compiler-rt/lib/interception/interception_win.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ bool OverrideFunctionWithTrampoline(
6363
// Exposed for unittests
6464
void TestOnlyReleaseTrampolineRegions();
6565

66+
// Exposed for unittests
67+
SIZE_T test_GetInstructionSize(uptr address, SIZE_T* rel_offset);
68+
6669
} // namespace __interception
6770

6871
#if defined(INTERCEPTION_DYNAMIC_CRT)

compiler-rt/lib/interception/tests/interception_win_test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,38 @@ TEST(Interception, EmptyExportTable) {
799799
EXPECT_EQ(0U, FunPtr);
800800
}
801801

802+
TEST(Interception, GetInstructionSize) {
803+
804+
struct {
805+
SIZE_T size;
806+
u8 instr[16];
807+
SIZE_T rel_offset;
808+
} data[] = {
809+
/* sort list */
810+
{ 1, { 0x50 }, 0 }, // 50 : push eax / rax
811+
};
812+
813+
SIZE_T size;
814+
SIZE_T rel_offset;
815+
816+
for (unsigned int i = 0; i < sizeof(data)/sizeof(*data); i++) {
817+
rel_offset = ~0L;
818+
size = __interception::test_GetInstructionSize((uptr)data[i].instr, &rel_offset);
819+
EXPECT_EQ(data[i].size, size)
820+
<< " with i=" << i << " ( "
821+
<< std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data[i].instr[0] << " "
822+
<< std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data[i].instr[1] << " "
823+
<< std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data[i].instr[2] << " "
824+
<< ")";
825+
EXPECT_EQ(data[i].rel_offset, rel_offset)
826+
<< " with i=" << i << " ( "
827+
<< std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data[i].instr[0] << " "
828+
<< std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data[i].instr[1] << " "
829+
<< std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data[i].instr[2] << " "
830+
<< ")";
831+
}
832+
}
833+
802834
} // namespace __interception
803835

804836
# endif // !SANITIZER_WINDOWS_ARM64

0 commit comments

Comments
 (0)