[ASan] Show memory rather than tag addresses in tag dump

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D133391
This commit is contained in:
Florian Mayer 2022-09-06 17:44:20 -07:00
parent 482aff4576
commit 178554f3c8
3 changed files with 29 additions and 1 deletions

View File

@ -539,7 +539,8 @@ static void PrintShadowBytes(InternalScopedString *str, const char *before,
u8 *bytes, u8 *guilty, uptr n) {
Decorator d;
if (before)
str->append("%s%p:", before, (void *)bytes);
str->append("%s%p:", before,
(void *)ShadowToMem(reinterpret_cast<uptr>(bytes)));
for (uptr i = 0; i < n; i++) {
u8 *p = bytes + i;
const char *before =

View File

@ -272,6 +272,8 @@ extern uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; // Initialized in __asan_init.
# else
# define MEM_TO_SHADOW(mem) \
(((mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
# define SHADOW_TO_MEM(mem) \
(((mem) - (ASAN_SHADOW_OFFSET)) << (ASAN_SHADOW_SCALE))
# define kLowMemBeg 0
# define kLowMemEnd (ASAN_SHADOW_OFFSET ? ASAN_SHADOW_OFFSET - 1 : 0)
@ -376,6 +378,12 @@ static inline bool AddrIsInShadow(uptr a) {
return AddrIsInLowShadow(a) || AddrIsInMidShadow(a) || AddrIsInHighShadow(a);
}
static inline uptr ShadowToMem(uptr p) {
PROFILE_ASAN_MAPPING();
CHECK(AddrIsInShadow(p));
return SHADOW_TO_MEM(p);
}
static inline bool AddrIsAlignedByGranularity(uptr a) {
PROFILE_ASAN_MAPPING();
return (a & (ASAN_SHADOW_GRANULARITY - 1)) == 0;

View File

@ -28,6 +28,7 @@
#define MEM_TO_SHADOW(mem) \
((((mem) << HIGH_BITS) >> (HIGH_BITS + (ASAN_SHADOW_SCALE))) + \
(ASAN_SHADOW_OFFSET))
#define SHADOW_TO_MEM(ptr) (__asan::ShadowToMemSparc64(ptr))
#define kLowMemBeg 0
#define kLowMemEnd (ASAN_SHADOW_OFFSET - 1)
@ -97,6 +98,24 @@ static inline bool AddrIsInShadowGap(uptr a) {
return a >= kShadowGapBeg && a <= kShadowGapEnd;
}
static inline constexpr uptr ShadowToMemSparc64(uptr p) {
PROFILE_ASAN_MAPPING();
p -= ASAN_SHADOW_OFFSET;
p <<= ASAN_SHADOW_SCALE;
if (p >= 0x8000000000000) {
p |= (~0ULL) << VMA_BITS;
}
return p;
}
static_assert(ShadowToMemSparc64(MEM_TO_SHADOW(0x0000000000000000)) ==
0x0000000000000000);
static_assert(ShadowToMemSparc64(MEM_TO_SHADOW(0xfff8000000000000)) ==
0xfff8000000000000);
// Gets aligned down.
static_assert(ShadowToMemSparc64(MEM_TO_SHADOW(0x0007ffffffffffff)) ==
0x0007fffffffffff8);
} // namespace __asan
#endif // ASAN_MAPPING_SPARC64_H