-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[sanitizer] Add MemCpyAccessible #112794
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
vitalybuka
merged 13 commits into
main
from
users/vitalybuka/spr/sanitizer-add-memcpyaccessible
Oct 18, 2024
Merged
[sanitizer] Add MemCpyAccessible #112794
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9de3ba0
[𝘀𝗽𝗿] changes to main this commit is based on
vitalybuka 14c0f3d
[𝘀𝗽𝗿] initial version
vitalybuka 6acf4c4
[𝘀𝗽𝗿] changes introduced through rebase
vitalybuka 6233ca1
move test into a different pr
vitalybuka b481c38
[𝘀𝗽𝗿] changes introduced through rebase
vitalybuka 199f7b3
EINTR
vitalybuka cb37ecb
[𝘀𝗽𝗿] changes introduced through rebase
vitalybuka fdf1a27
format
vitalybuka 7e8937d
fixes
vitalybuka 9310397
[𝘀𝗽𝗿] changes introduced through rebase
vitalybuka cb1e995
comment
vitalybuka d920ef3
offset
vitalybuka a178445
optional ()
vitalybuka 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
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 |
|---|---|---|
|
|
@@ -127,6 +127,43 @@ TEST(SanitizerCommon, TryMemCpyNull) { | |
| EXPECT_FALSE(TryMemCpy(dst.data(), nullptr, dst.size())); | ||
| } | ||
|
|
||
| TEST(SanitizerCommon, MemCpyAccessible) { | ||
| const int page_num = 1000; | ||
| const int page_size = GetPageSize(); | ||
| InternalMmapVector<char> src(page_num * page_size); | ||
| std::iota(src.begin(), src.end(), 123); | ||
| std::vector<char> dst; | ||
| std::vector<char> exp = {src.begin(), src.end()}; | ||
|
|
||
| // Protect some pages. | ||
| for (int i = 7; i < page_num; i *= 2) { | ||
| mprotect(src.data() + i * page_size, page_size, PROT_NONE); | ||
| std::fill(exp.data() + i * page_size, exp.data() + (i + 1) * page_size, 0); | ||
| } | ||
|
|
||
| dst.assign(src.size(), 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit '\0' |
||
| EXPECT_FALSE(TryMemCpy(dst.data(), src.data(), dst.size())); | ||
|
|
||
| // Full page aligned range with mprotect pages. | ||
| dst.assign(src.size(), 0); | ||
| MemCpyAccessible(dst.data(), src.data(), dst.size()); | ||
| EXPECT_TRUE(std::equal(dst.begin(), dst.end(), exp.begin())); | ||
|
|
||
| // Misaligned range with mprotect pages. | ||
| size_t offb = 3; | ||
| size_t offe = 7; | ||
| dst.assign(src.size() - offb - offe, 0); | ||
| MemCpyAccessible(dst.data(), src.data() + offb, dst.size()); | ||
| EXPECT_TRUE(std::equal(dst.begin(), dst.end(), exp.begin() + offb)); | ||
|
|
||
| // Misaligned range with ends in mprotect pages. | ||
| offb = 3 + 7 * page_size; | ||
| offe = 7 + 14 * page_size; | ||
| dst.assign(src.size() - offb - offe, 0); | ||
| MemCpyAccessible(dst.data(), src.data() + offb, dst.size()); | ||
| EXPECT_TRUE(std::equal(dst.begin(), dst.end(), exp.begin() + offb)); | ||
| } | ||
|
|
||
| } // namespace __sanitizer | ||
|
|
||
| #endif // SANITIZER_POSIX | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fully sure about this optimization. In the case where there are holes this makes it more expensive. Does the caller generally know that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure as well. On some examples fast pass 4x faster than page by page.