Skip to content

Commit 09d783e

Browse files
committed
STRIP_TAG => STRIP_MTE_TAG, move to common
1 parent 8a69c60 commit 09d783e

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

compiler-rt/lib/asan/asan_mapping.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,11 @@ extern uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; // Initialized in __asan_init.
281281

282282
} // namespace __asan
283283

284-
# if SANITIZER_APPLE && SANITIZER_WORDSIZE == 64
285-
# define TAG_MASK ((uptr)0x0f << 56) // Lower half of top byte
286-
# define STRIP_TAG(addr) ((addr) & ~TAG_MASK)
287-
# else
288-
# define STRIP_TAG(addr) (addr)
289-
# endif
290-
291284
# if defined(__sparc__) && SANITIZER_WORDSIZE == 64
292285
# include "asan_mapping_sparc64.h"
293286
# else
294287
# define MEM_TO_SHADOW(mem) \
295-
((STRIP_TAG(mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
288+
((STRIP_MTE_TAG(mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET))
296289
# define SHADOW_TO_MEM(mem) \
297290
(((mem) - (ASAN_SHADOW_OFFSET)) << (ASAN_SHADOW_SCALE))
298291

@@ -384,7 +377,7 @@ static inline uptr MemToShadowSize(uptr size) {
384377

385378
static inline bool AddrIsInMem(uptr a) {
386379
PROFILE_ASAN_MAPPING();
387-
a = STRIP_TAG(a);
380+
a = STRIP_MTE_TAG(a);
388381
return AddrIsInLowMem(a) || AddrIsInMidMem(a) || AddrIsInHighMem(a) ||
389382
(flags()->protect_shadow_gap == 0 && AddrIsInShadowGap(a));
390383
}
@@ -397,7 +390,7 @@ static inline uptr MemToShadow(uptr p) {
397390

398391
static inline bool AddrIsInShadow(uptr a) {
399392
PROFILE_ASAN_MAPPING();
400-
a = STRIP_TAG(a);
393+
a = STRIP_MTE_TAG(a);
401394
return AddrIsInLowShadow(a) || AddrIsInMidShadow(a) || AddrIsInHighShadow(a);
402395
}
403396

compiler-rt/lib/sanitizer_common/sanitizer_platform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,11 @@
497497
# endif
498498
#endif
499499

500+
#if SANITIZER_APPLE && SANITIZER_WORDSIZE == 64
501+
// MTE uses the lower half of the top byte.
502+
# define STRIP_MTE_TAG(addr) ((addr) & ~((uptr)0x0f << 56))
503+
#else
504+
# define STRIP_MTE_TAG(addr) (addr)
505+
#endif
506+
500507
#endif // SANITIZER_PLATFORM_H

compiler-rt/lib/tsan/rtl/tsan_platform.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -947,16 +947,6 @@ uptr MetaShadowBeg(void) { return SelectMapping<MappingField>(kMetaShadowBeg); }
947947
ALWAYS_INLINE
948948
uptr MetaShadowEnd(void) { return SelectMapping<MappingField>(kMetaShadowEnd); }
949949

950-
ALWAYS_INLINE
951-
uptr StripTag(uptr addr) {
952-
#if SANITIZER_APPLE
953-
constexpr uptr kTagMask = ((uptr)0x0f << 56); // Lower half of top byte
954-
return addr & ~kTagMask;
955-
#else
956-
return addr;
957-
#endif
958-
}
959-
960950
struct IsAppMemImpl {
961951
template <typename Mapping>
962952
static bool Apply(uptr mem) {
@@ -968,7 +958,9 @@ struct IsAppMemImpl {
968958
};
969959

970960
ALWAYS_INLINE
971-
bool IsAppMem(uptr mem) { return SelectMapping<IsAppMemImpl>(StripTag(mem)); }
961+
bool IsAppMem(uptr mem) {
962+
return SelectMapping<IsAppMemImpl>(STRIP_MTE_TAG(mem));
963+
}
972964

973965
struct IsShadowMemImpl {
974966
template <typename Mapping>
@@ -1008,7 +1000,7 @@ struct MemToShadowImpl {
10081000
ALWAYS_INLINE
10091001
RawShadow *MemToShadow(uptr x) {
10101002
return reinterpret_cast<RawShadow*>(
1011-
SelectMapping<MemToShadowImpl>(StripTag(x)));
1003+
SelectMapping<MemToShadowImpl>(STRIP_MTE_TAG(x)));
10121004
}
10131005

10141006
struct MemToMetaImpl {
@@ -1022,7 +1014,9 @@ struct MemToMetaImpl {
10221014
};
10231015

10241016
ALWAYS_INLINE
1025-
u32* MemToMeta(uptr x) { return SelectMapping<MemToMetaImpl>(StripTag(x)); }
1017+
u32* MemToMeta(uptr x) {
1018+
return SelectMapping<MemToMetaImpl>(STRIP_MTE_TAG(x));
1019+
}
10261020

10271021
struct ShadowToMemImpl {
10281022
template <typename Mapping>

0 commit comments

Comments
 (0)