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
This commit is contained in:
Benjamin Peterson
2023-12-23 03:36:53 +00:00
parent f94d735749
commit ca85c591b9
2 changed files with 15 additions and 29 deletions

View File

@@ -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<uintptr_t>(aPtr);
uintptr_t end = addr + aLength;
uintptr_t addrRounded = addr & mozilla::GetPageMask();
const void* ptrRounded = reinterpret_cast<const void*>(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<uintptr_t>(aPtr);
uintptr_t end = addr + aLength;
uintptr_t addrRounded = addr & mozilla::GetPageMask();
const void* ptrRounded = reinterpret_cast<const void*>(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;

View File

@@ -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