[scudo] Small cleanup of memory tagging code. (#166860)
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().
This commit is contained in:
parent
a1934ee500
commit
046ae85536
@ -171,8 +171,7 @@ public:
|
||||
Primary.Options.set(OptionBit::DeallocTypeMismatch);
|
||||
if (getFlags()->delete_size_mismatch)
|
||||
Primary.Options.set(OptionBit::DeleteSizeMismatch);
|
||||
if (allocatorSupportsMemoryTagging<AllocatorConfig>() &&
|
||||
systemSupportsMemoryTagging())
|
||||
if (systemSupportsMemoryTagging())
|
||||
Primary.Options.set(OptionBit::UseMemoryTagging);
|
||||
|
||||
QuarantineMaxChunkSize =
|
||||
|
||||
@ -66,7 +66,8 @@ inline bool systemSupportsMemoryTagging() {
|
||||
#ifndef HWCAP2_MTE
|
||||
#define HWCAP2_MTE (1 << 18)
|
||||
#endif
|
||||
return getauxval(AT_HWCAP2) & HWCAP2_MTE;
|
||||
static bool SupportsMemoryTagging = getauxval(AT_HWCAP2) & HWCAP2_MTE;
|
||||
return SupportsMemoryTagging;
|
||||
}
|
||||
|
||||
inline bool systemDetectsMemoryTagFaultsTestOnly() {
|
||||
@ -261,9 +262,7 @@ inline uptr loadTag(uptr Ptr) {
|
||||
|
||||
#else
|
||||
|
||||
inline NORETURN bool systemSupportsMemoryTagging() {
|
||||
UNREACHABLE("memory tagging not supported");
|
||||
}
|
||||
inline bool systemSupportsMemoryTagging() { return false; }
|
||||
|
||||
inline NORETURN bool systemDetectsMemoryTagFaultsTestOnly() {
|
||||
UNREACHABLE("memory tagging not supported");
|
||||
|
||||
@ -28,7 +28,6 @@ TEST(MemtagBasicDeathTest, Unsupported) {
|
||||
EXPECT_DEATH(untagPointer((uptr)0), "not supported");
|
||||
EXPECT_DEATH(extractTag((uptr)0), "not supported");
|
||||
|
||||
EXPECT_DEATH(systemSupportsMemoryTagging(), "not supported");
|
||||
EXPECT_DEATH(systemDetectsMemoryTagFaultsTestOnly(), "not supported");
|
||||
EXPECT_DEATH(enableSystemMemoryTaggingTestOnly(), "not supported");
|
||||
|
||||
|
||||
@ -27,9 +27,7 @@
|
||||
const scudo::uptr PageSize = scudo::getPageSizeCached();
|
||||
|
||||
template <typename Config> static scudo::Options getOptionsForConfig() {
|
||||
if (!Config::getMaySupportMemoryTagging() ||
|
||||
!scudo::archSupportsMemoryTagging() ||
|
||||
!scudo::systemSupportsMemoryTagging())
|
||||
if (!scudo::systemSupportsMemoryTagging())
|
||||
return {};
|
||||
scudo::AtomicOptions AO;
|
||||
AO.set(scudo::OptionBit::UseMemoryTagging);
|
||||
|
||||
@ -187,8 +187,7 @@ TEST_F(ScudoWrappersCppTest, ThreadedNew) {
|
||||
// TODO: Investigate why libc sometimes crashes with tag missmatch in
|
||||
// __pthread_clockjoin_ex.
|
||||
std::unique_ptr<scudo::ScopedDisableMemoryTagChecks> NoTags;
|
||||
if (!SCUDO_ANDROID && scudo::archSupportsMemoryTagging() &&
|
||||
scudo::systemSupportsMemoryTagging())
|
||||
if (!SCUDO_ANDROID && scudo::systemSupportsMemoryTagging())
|
||||
NoTags = std::make_unique<scudo::ScopedDisableMemoryTagChecks>();
|
||||
|
||||
Ready = false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user