Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler-rt/lib/asan/asan_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ extern uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; // Initialized in __asan_init.
# include "asan_mapping_sparc64.h"
# else
# define MEM_TO_SHADOW(mem) \
(((mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
((STRIP_MTE_TAG(mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
# define SHADOW_TO_MEM(mem) \
(((mem) - (ASAN_SHADOW_OFFSET)) << (ASAN_SHADOW_SCALE))

Expand Down Expand Up @@ -377,6 +377,7 @@ static inline uptr MemToShadowSize(uptr size) {

static inline bool AddrIsInMem(uptr a) {
PROFILE_ASAN_MAPPING();
a = STRIP_MTE_TAG(a);
return AddrIsInLowMem(a) || AddrIsInMidMem(a) || AddrIsInHighMem(a) ||
(flags()->protect_shadow_gap == 0 && AddrIsInShadowGap(a));
}
Expand All @@ -389,6 +390,7 @@ static inline uptr MemToShadow(uptr p) {

static inline bool AddrIsInShadow(uptr a) {
PROFILE_ASAN_MAPPING();
a = STRIP_MTE_TAG(a);
return AddrIsInLowShadow(a) || AddrIsInMidShadow(a) || AddrIsInHighShadow(a);
}

Expand Down
7 changes: 7 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,11 @@
# endif
#endif

#if SANITIZER_APPLE && SANITIZER_WORDSIZE == 64
// MTE uses the lower half of the top byte.
# define STRIP_MTE_TAG(addr) ((addr) & ~((uptr)0x0f << 56))
#else
# define STRIP_MTE_TAG(addr) (addr)
#endif

#endif // SANITIZER_PLATFORM_H
11 changes: 8 additions & 3 deletions compiler-rt/lib/tsan/rtl/tsan_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,9 @@ struct IsAppMemImpl {
};

ALWAYS_INLINE
bool IsAppMem(uptr mem) { return SelectMapping<IsAppMemImpl>(mem); }
bool IsAppMem(uptr mem) {
return SelectMapping<IsAppMemImpl>(STRIP_MTE_TAG(mem));
}

struct IsShadowMemImpl {
template <typename Mapping>
Expand Down Expand Up @@ -997,7 +999,8 @@ struct MemToShadowImpl {

ALWAYS_INLINE
RawShadow *MemToShadow(uptr x) {
return reinterpret_cast<RawShadow *>(SelectMapping<MemToShadowImpl>(x));
return reinterpret_cast<RawShadow*>(
SelectMapping<MemToShadowImpl>(STRIP_MTE_TAG(x)));
}

struct MemToMetaImpl {
Expand All @@ -1011,7 +1014,9 @@ struct MemToMetaImpl {
};

ALWAYS_INLINE
u32 *MemToMeta(uptr x) { return SelectMapping<MemToMetaImpl>(x); }
u32* MemToMeta(uptr x) {
return SelectMapping<MemToMetaImpl>(STRIP_MTE_TAG(x));
}

struct ShadowToMemImpl {
template <typename Mapping>
Expand Down