-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[sanitizer_common] Add darwin-specific MemoryRangeIsAvailable #167797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+47
−20
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,9 @@ extern "C" { | |
| natural_t *nesting_depth, | ||
| vm_region_recurse_info_t info, | ||
| mach_msg_type_number_t *infoCnt); | ||
| } | ||
|
|
||
| extern const void* _dyld_get_shared_cache_range(size_t* length); | ||
| } | ||
ndrewh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # if !SANITIZER_GO | ||
| // Weak symbol no-op when TSan is not linked | ||
|
|
@@ -1403,15 +1405,27 @@ uptr FindAvailableMemoryRange(uptr size, uptr alignment, uptr left_padding, | |
| return 0; | ||
| } | ||
|
|
||
| // Returns true if the address is definitely mapped, and false if it is not | ||
| // mapped or could not be determined. | ||
| bool IsAddressInMappedRegion(uptr addr) { | ||
| // This function (when used during initialization when there is | ||
| // only a single thread), can be used to verify that a range | ||
| // of memory hasn't already been mapped, and won't be mapped | ||
| // later in the shared cache. | ||
| // | ||
| // If the syscall mach_vm_region_recurse fails (due to sandbox), | ||
| // we assume that the memory is not mapped so that execution can continue. | ||
| // | ||
| // NOTE: range_end is inclusive | ||
| // | ||
| // WARNING: This function should NOT allocate memory, since it is | ||
|
||
| // used in InitializeShadowMemory between where we search for | ||
| // space for shadow and where we actually allocate it. | ||
| bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) { | ||
| mach_vm_size_t vmsize = 0; | ||
| natural_t depth = 0; | ||
| vm_region_submap_short_info_data_64_t vminfo; | ||
| mach_msg_type_number_t count = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64; | ||
| mach_vm_address_t address = addr; | ||
| mach_vm_address_t address = range_start; | ||
|
|
||
| // First, check if the range is already mapped. | ||
| kern_return_t kr = | ||
| mach_vm_region_recurse(mach_task_self(), &address, &vmsize, &depth, | ||
| (vm_region_info_t)&vminfo, &count); | ||
|
|
@@ -1423,7 +1437,24 @@ bool IsAddressInMappedRegion(uptr addr) { | |
| Report("HINT: Is mach_vm_region_recurse allowed by sandbox?\n"); | ||
| } | ||
|
|
||
| return (kr == KERN_SUCCESS && addr >= address && addr < address + vmsize); | ||
| if (kr == KERN_SUCCESS && !IntervalsAreSeparate(address, address + vmsize - 1, | ||
| range_start, range_end)) { | ||
| // Overlaps with already-mapped memory | ||
| return false; | ||
| } | ||
|
|
||
| size_t cacheLength; | ||
| uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength); | ||
|
|
||
| if (cacheStart && | ||
| !IntervalsAreSeparate(cacheStart, cacheStart + cacheLength - 1, | ||
| range_start, range_end)) { | ||
| // Overlaps with shared cache region | ||
| return false; | ||
| } | ||
|
|
||
| // We believe this address is available. | ||
| return true; | ||
| } | ||
|
|
||
| // FIXME implement on this platform. | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.