From 01ac087bd0f6614b1586cdfb7a7b0f16c97f10b7 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Tue, 8 Jul 2025 23:50:37 -0400 Subject: [PATCH 1/2] Introduce SANITIZER_MMAP_BEGIN --- compiler-rt/lib/asan/asan_allocator.h | 2 +- compiler-rt/lib/lsan/lsan_allocator.h | 2 +- compiler-rt/lib/msan/msan_allocator.cpp | 2 +- .../lib/sanitizer_common/sanitizer_allocator_internal.h | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_platform.h | 3 +++ compiler-rt/lib/tsan/rtl/tsan_rtl.h | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h index a94ef958aa75e..247d8bb77c984 100644 --- a/compiler-rt/lib/asan/asan_allocator.h +++ b/compiler-rt/lib/asan/asan_allocator.h @@ -239,7 +239,7 @@ using PrimaryAllocator = PrimaryAllocatorASVT; typedef CompactSizeClassMap SizeClassMap; template struct AP32 { - static const uptr kSpaceBeg = 0; + static const uptr kSpaceBeg = SANITIZER_MMAP_BEGIN; static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = 0; typedef __asan::SizeClassMap SizeClassMap; diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h index 2342f11fb5d0d..556b9f56a4a4a 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -53,7 +53,7 @@ struct ChunkMetadata { #if !SANITIZER_CAN_USE_ALLOCATOR64 template struct AP32 { - static const uptr kSpaceBeg = 0; + static const uptr kSpaceBeg = SANITIZER_MMAP_BEGIN; static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = sizeof(ChunkMetadata); typedef __sanitizer::CompactSizeClassMap SizeClassMap; diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp index d7d4967c94985..2b543db49d36e 100644 --- a/compiler-rt/lib/msan/msan_allocator.cpp +++ b/compiler-rt/lib/msan/msan_allocator.cpp @@ -56,7 +56,7 @@ struct MsanMapUnmapCallback { const uptr kMaxAllowedMallocSize = 2UL << 30; struct AP32 { - static const uptr kSpaceBeg = 0; + static const uptr kSpaceBeg = SANITIZER_MMAP_BEGIN; static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = sizeof(Metadata); using SizeClassMap = __sanitizer::CompactSizeClassMap; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h index 62523c7ae187c..6c2020e6373c0 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h @@ -23,7 +23,7 @@ namespace __sanitizer { typedef CompactSizeClassMap InternalSizeClassMap; struct AP32 { - static const uptr kSpaceBeg = 0; + static const uptr kSpaceBeg = SANITIZER_MMAP_BEGIN; static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = 0; typedef InternalSizeClassMap SizeClassMap; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h index 4c8d9a9b86bed..484006bf851a6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -318,6 +318,9 @@ # endif #endif +// The beginning of mmap range of addresses. +#define SANITIZER_MMAP_BEGIN 0 + // The range of addresses which can be returned my mmap. // FIXME: this value should be different on different platforms. Larger values // will still work but will consume more memory for TwoLevelByteMap. diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index 0be53599b6a49..dc32980e905f2 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -62,7 +62,7 @@ struct MapUnmapCallback; defined(__powerpc__) || SANITIZER_RISCV64 struct AP32 { - static const uptr kSpaceBeg = 0; + static const uptr kSpaceBeg = SANITIZER_MMAP_BEGIN; static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; static const uptr kMetadataSize = 0; typedef __sanitizer::CompactSizeClassMap SizeClassMap; From f43c06c83baf44cb56af952114fb4818991e5628 Mon Sep 17 00:00:00 2001 From: Jake Egan Date: Wed, 9 Jul 2025 11:42:49 -0400 Subject: [PATCH 2/2] Update comment Co-authored-by: David Justo --- compiler-rt/lib/sanitizer_common/sanitizer_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h index 484006bf851a6..196c0a988478e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -318,7 +318,7 @@ # endif #endif -// The beginning of mmap range of addresses. +// The first address that can be returned by mmap. #define SANITIZER_MMAP_BEGIN 0 // The range of addresses which can be returned my mmap.