Skip to content

Conversation

@ndrewh
Copy link
Contributor

@ndrewh ndrewh commented Nov 21, 2025

This fixes a bug in #167797 where an upper-bound was mistaken to be exclusive when it was actually inclusive. MemoryRangeIsAvailable takes an inclusive upper bound, and if beginning == end it will check for overlap with a range of size 1.

Here, we want to check if HiAppMemEnd() - 1 is mapped. If it is, the memory layout should be marked unsupported.

rdar://164815619

@ndrewh ndrewh changed the title [TSan] [Darwin] Fix off by one in TSAN init due to MemoryRangeIsAvailable call [TSan] [Darwin] Fix off by one in TSAN init due to MemoryRangeIsAvailable Nov 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Andrew Haberlandt (ndrewh)

Changes

This fixes a bug in #167797 where an upper-bound was mistaken to be exclusive when it was actually inclusive. MemoryRangeIsAvailable takes an inclusive upper bound, and if beginning == end it will check for overlap with a range of size 1.

Here, we want to check if HiAppMemEnd() - 1 is mapped. If it is, the memory layout should be marked unsupported.

rdar://164815619


Full diff: https://github.com/llvm/llvm-project/pull/169008.diff

1 Files Affected:

  • (modified) compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp (+1-1)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
index f6fe2405254e7..da735fba663aa 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
@@ -235,7 +235,7 @@ void InitializePlatformEarly() {
   }
   // In some configurations, the max_vm is expanded, but much of this space is
   // already mapped. TSAN will not work in this configuration.
-  if (!MemoryRangeIsAvailable(HiAppMemEnd() - 1, HiAppMemEnd())) {
+  if (!MemoryRangeIsAvailable(HiAppMemEnd() - 1, HiAppMemEnd() - 1)) {
     Report(
         "ThreadSanitizer: Unsupported virtual memory layout: Address %p is "
         "already mapped.\n",

@github-actions
Copy link

🐧 Linux x64 Test Results

  • 5820 tests passed
  • 1323 tests skipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants