Skip to content

Commit 555cdc9

Browse files
cferris1000Priyanshu3820
authored andcommitted
[scudo] Small cleanup of memory tagging code part 2. (llvm#168807)
Make the systemSupportsMemoryTagging() function return even on system that don't support memory tagging. This avoids the need to always check if memory tagging is supported before calling the function. Modify iterateOverChunks() to call useMemoryTagging<>(Options) to determine if mte is supported. This already uses the cached check of systemSupportsMemoryTagging() rather than directly calling that function. Updated the code that calls systemSupportsMemoryTagging().
1 parent bddb7df commit 555cdc9

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

compiler-rt/lib/scudo/standalone/combined.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ class Allocator {
171171
Primary.Options.set(OptionBit::DeallocTypeMismatch);
172172
if (getFlags()->delete_size_mismatch)
173173
Primary.Options.set(OptionBit::DeleteSizeMismatch);
174-
if (allocatorSupportsMemoryTagging<AllocatorConfig>() &&
175-
systemSupportsMemoryTagging())
174+
if (systemSupportsMemoryTagging())
176175
Primary.Options.set(OptionBit::UseMemoryTagging);
177176

178177
QuarantineMaxChunkSize =
@@ -689,16 +688,15 @@ class Allocator {
689688
Base = untagPointer(Base);
690689
const uptr From = Base;
691690
const uptr To = Base + Size;
692-
bool MayHaveTaggedPrimary =
693-
allocatorSupportsMemoryTagging<AllocatorConfig>() &&
694-
systemSupportsMemoryTagging();
691+
const Options Options = Primary.Options.load();
692+
bool MayHaveTaggedPrimary = useMemoryTagging<AllocatorConfig>(Options);
695693
auto Lambda = [this, From, To, MayHaveTaggedPrimary, Callback,
696694
Arg](uptr Block) {
697695
if (Block < From || Block >= To)
698696
return;
699697
uptr Chunk;
700698
Chunk::UnpackedHeader Header;
701-
if (MayHaveTaggedPrimary) {
699+
if (UNLIKELY(MayHaveTaggedPrimary)) {
702700
// A chunk header can either have a zero tag (tagged primary) or the
703701
// header tag (secondary, or untagged primary). We don't know which so
704702
// try both.

compiler-rt/lib/scudo/standalone/memtag.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ inline void enableSystemMemoryTaggingTestOnly() {
108108

109109
#else // !SCUDO_CAN_USE_MTE
110110

111-
inline bool systemSupportsMemoryTagging() { return false; }
111+
inline constexpr bool systemSupportsMemoryTagging() { return false; }
112112

113113
inline NORETURN bool systemDetectsMemoryTagFaultsTestOnly() {
114114
UNREACHABLE("memory tagging not supported");
@@ -261,9 +261,7 @@ inline uptr loadTag(uptr Ptr) {
261261

262262
#else
263263

264-
inline NORETURN bool systemSupportsMemoryTagging() {
265-
UNREACHABLE("memory tagging not supported");
266-
}
264+
inline constexpr bool systemSupportsMemoryTagging() { return false; }
267265

268266
inline NORETURN bool systemDetectsMemoryTagFaultsTestOnly() {
269267
UNREACHABLE("memory tagging not supported");

compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ TEST(MemtagBasicDeathTest, Unsupported) {
2828
EXPECT_DEATH(untagPointer((uptr)0), "not supported");
2929
EXPECT_DEATH(extractTag((uptr)0), "not supported");
3030

31-
EXPECT_DEATH(systemSupportsMemoryTagging(), "not supported");
3231
EXPECT_DEATH(systemDetectsMemoryTagFaultsTestOnly(), "not supported");
3332
EXPECT_DEATH(enableSystemMemoryTaggingTestOnly(), "not supported");
3433

compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
const scudo::uptr PageSize = scudo::getPageSizeCached();
2828

2929
template <typename Config> static scudo::Options getOptionsForConfig() {
30-
if (!Config::getMaySupportMemoryTagging() ||
31-
!scudo::archSupportsMemoryTagging() ||
32-
!scudo::systemSupportsMemoryTagging())
30+
if (!scudo::systemSupportsMemoryTagging())
3331
return {};
3432
scudo::AtomicOptions AO;
3533
AO.set(scudo::OptionBit::UseMemoryTagging);

0 commit comments

Comments
 (0)