release/22.x: [compiler-rt] [Darwin] Move macOS ASAN reservation above 512G (#191039) - #192082
Merged
Merged
Conversation
Member
Author
|
@DanBlackwell What do you think about merging this PR to the release branch? |
Member
Author
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: llvmbot ChangesBackport 857a98e Requested by: @ndrewh Full diff: https://github.com/llvm/llvm-project/pull/192082.diff 2 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 3f8de8dd064a5..940175791f376 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -1288,6 +1288,25 @@ uptr MapDynamicShadow(uptr shadow_size_bytes, uptr shadow_scale,
return shadow_start;
}
+// Returns a list of ranges which must be covered by shadow memory,
+// and cannot overlap with any fixed mappings made by a sanitizer.
+// This can ensure that the sanitizer runtime does not map over
+// platform-reserved regions.
+void GetAppReservedRanges(InternalMmapVector<ReservedRange>& ranges) {
+ ranges.clear();
+
+# if SANITIZER_OSX
+ // On macOS, the first 512GB are platform-reserved (some of which
+ // may also be available to applications).
+ ranges.push_back({0x1000UL, 0x8000000000UL});
+# endif
+
+ VReport(2, "App ranges:\n");
+ for (auto& [range_start, range_end] : ranges) {
+ VReport(2, " [%p, %p]\n", range_start, range_end);
+ }
+}
+
uptr MapDynamicShadowAndAliases(uptr shadow_size, uptr alias_size,
uptr num_aliases, uptr ring_buffer_size) {
CHECK(false && "HWASan aliasing is unimplemented on Mac");
@@ -1300,6 +1319,16 @@ uptr FindAvailableMemoryRange(uptr size, uptr alignment, uptr left_padding,
const mach_vm_address_t max_vm_address = GetMaxVirtualAddress() + 1;
mach_vm_address_t address = GAP_SEARCH_START_ADDRESS;
mach_vm_address_t free_begin = GAP_SEARCH_START_ADDRESS;
+
+ // Restrict the search to be after any reserved ranges
+ InternalMmapVector<ReservedRange> app_ranges;
+ GetAppReservedRanges(app_ranges);
+
+ for (auto& [range_start, range_end] : app_ranges) {
+ address = Max(address, (mach_vm_address_t)range_end);
+ free_begin = Max(free_begin, (mach_vm_address_t)range_end);
+ }
+
kern_return_t kr = KERN_SUCCESS;
if (largest_gap_found) *largest_gap_found = 0;
if (max_occupied_addr) *max_occupied_addr = 0;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
index b0e4ac7f40745..7f9a2b77e7d50 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
@@ -58,8 +58,13 @@ struct DarwinKernelVersion : VersionBase<DarwinKernelVersion> {
DarwinKernelVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
};
+struct ReservedRange {
+ uptr beg, end;
+};
+
MacosVersion GetMacosAlignedVersion();
DarwinKernelVersion GetDarwinKernelVersion();
+void GetAppReservedRanges(InternalMmapVector<ReservedRange>& ranges);
char **GetEnviron();
|
DanBlackwell
approved these changes
Apr 15, 2026
DanBlackwell
left a comment
Contributor
There was a problem hiding this comment.
This is a useful fix for macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 857a98e
Requested by: @ndrewh