Skip to content

Commit e681aa2

Browse files
committed
[scudo] Small cleanup of memory tagging code.
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 th function. Make systemSupportsMemoryTagging() cache the getauxval return value instead of calling the function every time. Updated the code that calls systemSupportsMemoryTagging().
1 parent bd9030e commit e681aa2

File tree

5 files changed

+6
-12
lines changed

5 files changed

+6
-12
lines changed

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

Lines changed: 1 addition & 2 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 =

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ inline bool systemSupportsMemoryTagging() {
6666
#ifndef HWCAP2_MTE
6767
#define HWCAP2_MTE (1 << 18)
6868
#endif
69-
return getauxval(AT_HWCAP2) & HWCAP2_MTE;
69+
static bool SupportsMemoryTagging = getauxval(AT_HWCAP2) & HWCAP2_MTE;
70+
return SupportsMemoryTagging;
7071
}
7172

7273
inline bool systemDetectsMemoryTagFaultsTestOnly() {
@@ -261,9 +262,7 @@ inline uptr loadTag(uptr Ptr) {
261262

262263
#else
263264

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

268267
inline NORETURN bool systemDetectsMemoryTagFaultsTestOnly() {
269268
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);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ TEST_F(ScudoWrappersCppTest, ThreadedNew) {
187187
// TODO: Investigate why libc sometimes crashes with tag missmatch in
188188
// __pthread_clockjoin_ex.
189189
std::unique_ptr<scudo::ScopedDisableMemoryTagChecks> NoTags;
190-
if (!SCUDO_ANDROID && scudo::archSupportsMemoryTagging() &&
191-
scudo::systemSupportsMemoryTagging())
190+
if (!SCUDO_ANDROID && scudo::systemSupportsMemoryTagging())
192191
NoTags = std::make_unique<scudo::ScopedDisableMemoryTagChecks>();
193192

194193
Ready = false;

0 commit comments

Comments
 (0)