From ca85c591b98fe1e30b15c2035ab93dbe4db2d79c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 23 Dec 2023 03:36:53 +0000 Subject: [PATCH] Bug 1866606 - Remove MozTaggedMemoryIsSupported. r=jld MozTaggedMemoryIsSupported doesn't work under ASAN because it tries to prctl the nullptr page. It should be harmless to simply call prctl and ignore the error. Depends on D195064 Differential Revision: https://phabricator.services.mozilla.com/D195065 --- mfbt/TaggedAnonymousMemory.cpp | 40 +++++++++++++--------------------- mfbt/TaggedAnonymousMemory.h | 4 ---- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/mfbt/TaggedAnonymousMemory.cpp b/mfbt/TaggedAnonymousMemory.cpp index 9e66a56c5094..382b9cef7ad3 100644 --- a/mfbt/TaggedAnonymousMemory.cpp +++ b/mfbt/TaggedAnonymousMemory.cpp @@ -53,38 +53,28 @@ static uintptr_t GetPageMask() { } // namespace mozilla -int MozTaggedMemoryIsSupported(void) { - static int supported = -1; - - if (supported == -1) { - // Tagging an empty range always "succeeds" if the feature is supported, - // regardless of the start pointer. - supported = mozilla::TagAnonymousMemoryAligned(nullptr, 0, nullptr) == 0; - } - return supported; -} - void MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag) { - if (MozTaggedMemoryIsSupported()) { - // The kernel will round up the end of the range to the next page - // boundary if it's not aligned (comments indicate this behavior - // is based on that of madvise), but it will reject the request if - // the start is not aligned. We therefore round down the start - // address and adjust the length accordingly. - uintptr_t addr = reinterpret_cast(aPtr); - uintptr_t end = addr + aLength; - uintptr_t addrRounded = addr & mozilla::GetPageMask(); - const void* ptrRounded = reinterpret_cast(addrRounded); + // The kernel will round up the end of the range to the next page + // boundary if it's not aligned (comments indicate this behavior is + // based on that of madvise), but it will reject the request if the + // start is not aligned. We therefore round down the start address + // and adjust the length accordingly. + uintptr_t addr = reinterpret_cast(aPtr); + uintptr_t end = addr + aLength; + uintptr_t addrRounded = addr & mozilla::GetPageMask(); + const void* ptrRounded = reinterpret_cast(addrRounded); - mozilla::TagAnonymousMemoryAligned(ptrRounded, end - addrRounded, aTag); - } + // Ignore the return value. TagAnonymousMemoryAligned will harmlessly fail on + // kernels without CONFIG_ANON_VMA_NAME. + mozilla::TagAnonymousMemoryAligned(ptrRounded, end - addrRounded, aTag); } void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, int aFd, off_t aOffset, const char* aTag) { void* mapped = mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset); - if (MozTaggedMemoryIsSupported() && - (aFlags & MAP_ANONYMOUS) == MAP_ANONYMOUS && mapped != MAP_FAILED) { + if ((aFlags & MAP_ANONYMOUS) == MAP_ANONYMOUS && mapped != MAP_FAILED) { + // Ignore the return value. TagAnonymousMemoryAligned will harmlessly fail + // on kernels without CONFIG_ANON_VMA_NAME. mozilla::TagAnonymousMemoryAligned(mapped, aLength, aTag); } return mapped; diff --git a/mfbt/TaggedAnonymousMemory.h b/mfbt/TaggedAnonymousMemory.h index ddd4713a7800..7ca5e60c9d08 100644 --- a/mfbt/TaggedAnonymousMemory.h +++ b/mfbt/TaggedAnonymousMemory.h @@ -55,8 +55,6 @@ MFBT_API void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags, int aFd, off_t aOffset, const char* aTag); -MFBT_API int MozTaggedMemoryIsSupported(void); - # ifdef __cplusplus } // extern "C" # endif @@ -77,8 +75,6 @@ static inline void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength, # endif } -static inline int MozTaggedMemoryIsSupported(void) { return 0; } - # endif // XP_LINUX #endif // !XP_WIN