[NFC][asan] Rename variables in __sanitizer_annotate_contiguous_container

This commit is contained in:
Vitaly Buka 2022-11-27 00:29:38 -08:00
parent 0ea3386d7b
commit b6c5875146
1 changed files with 36 additions and 35 deletions

View File

@ -378,71 +378,72 @@ void __sanitizer_annotate_contiguous_container(const void *beg_p,
return;
VPrintf(2, "contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p,
new_mid_p);
uptr beg = reinterpret_cast<uptr>(beg_p);
uptr end = reinterpret_cast<uptr>(end_p);
uptr old_mid = reinterpret_cast<uptr>(old_mid_p);
uptr new_mid = reinterpret_cast<uptr>(new_mid_p);
uptr storage_beg = reinterpret_cast<uptr>(beg_p);
uptr storage_end = reinterpret_cast<uptr>(end_p);
uptr old_end = reinterpret_cast<uptr>(old_mid_p);
uptr new_end = reinterpret_cast<uptr>(new_mid_p);
uptr granularity = ASAN_SHADOW_GRANULARITY;
if (!(beg <= old_mid && beg <= new_mid && old_mid <= end && new_mid <= end)) {
if (!(storage_beg <= old_end && storage_beg <= new_end &&
old_end <= storage_end && new_end <= storage_end)) {
GET_STACK_TRACE_FATAL_HERE;
ReportBadParamsToAnnotateContiguousContainer(beg, end, old_mid, new_mid,
&stack);
ReportBadParamsToAnnotateContiguousContainer(storage_beg, storage_end,
old_end, new_end, &stack);
}
CHECK_LE(end - beg,
CHECK_LE(storage_end - storage_beg,
FIRST_32_SECOND_64(1UL << 30, 1ULL << 40)); // Sanity check.
if (old_mid == new_mid)
if (old_end == new_end)
return; // Nothing to do here.
// Handle misaligned end and cut it off.
if (UNLIKELY(!AddrIsAlignedByGranularity(end))) {
uptr end_down = RoundDownTo(end, granularity);
if (UNLIKELY(!AddrIsAlignedByGranularity(storage_end))) {
uptr end_down = RoundDownTo(storage_end, granularity);
// Either new or old mid must be in the granule to affect it.
if (new_mid > end_down || old_mid > end_down) {
if (new_end > end_down || old_end > end_down) {
// Do nothing if the byte after the container is unpoisoned. Asan can't
// poison only the begining of the granule.
if (AddressIsPoisoned(end)) {
*(u8 *)MemToShadow(end_down) = new_mid > end_down
? static_cast<u8>(new_mid - end_down)
if (AddressIsPoisoned(storage_end)) {
*(u8 *)MemToShadow(end_down) = new_end > end_down
? static_cast<u8>(new_end - end_down)
: kAsanContiguousContainerOOBMagic;
}
old_mid = Min(end_down, old_mid);
new_mid = Min(end_down, new_mid);
old_end = Min(end_down, old_end);
new_end = Min(end_down, new_end);
if (old_mid == new_mid)
if (old_end == new_end)
return;
}
if (beg >= end_down)
if (storage_beg >= end_down)
return; // Same granule.
end = end_down;
storage_end = end_down;
}
// Handle misaligned begin and cut it off.
if (UNLIKELY(!AddrIsAlignedByGranularity(beg))) {
uptr beg_up = RoundUpTo(beg, granularity);
if (UNLIKELY(!AddrIsAlignedByGranularity(storage_beg))) {
uptr beg_up = RoundUpTo(storage_beg, granularity);
// As soon as we add first byte into container we will not be able to
// determine the state of the byte before the container. So we assume it's
// always unpoison.
// Either new or old mid must be in the granule to affect it.
if (new_mid < beg_up || old_mid < beg_up) {
uptr beg_down = RoundDownTo(beg, granularity);
if (new_end < beg_up || old_end < beg_up) {
uptr beg_down = RoundDownTo(storage_beg, granularity);
*(u8 *)MemToShadow(beg_down) =
new_mid < beg_up ? static_cast<u8>(new_mid - beg_down) : 0;
old_mid = Max(beg_up, old_mid);
new_mid = Max(beg_up, new_mid);
if (old_mid == new_mid)
new_end < beg_up ? static_cast<u8>(new_end - beg_down) : 0;
old_end = Max(beg_up, old_end);
new_end = Max(beg_up, new_end);
if (old_end == new_end)
return;
}
beg = beg_up;
storage_beg = beg_up;
}
uptr a = RoundDownTo(Min(old_mid, new_mid), granularity);
uptr c = RoundUpTo(Max(old_mid, new_mid), granularity);
uptr d1 = RoundDownTo(old_mid, granularity);
uptr a = RoundDownTo(Min(old_end, new_end), granularity);
uptr c = RoundUpTo(Max(old_end, new_end), granularity);
uptr d1 = RoundDownTo(old_end, granularity);
// uptr d2 = RoundUpTo(old_mid, granularity);
// Currently we should be in this state:
// [a, d1) is good, [d2, c) is bad, [d1, d2) is partially good.
@ -458,8 +459,8 @@ void __sanitizer_annotate_contiguous_container(const void *beg_p,
// CHECK_EQ(*(u8 *)MemToShadow(c - granularity),
// kAsanContiguousContainerOOBMagic);
uptr b1 = RoundDownTo(new_mid, granularity);
uptr b2 = RoundUpTo(new_mid, granularity);
uptr b1 = RoundDownTo(new_end, granularity);
uptr b2 = RoundUpTo(new_end, granularity);
// New state:
// [a, b1) is good, [b2, c) is bad, [b1, b2) is partially good.
if (b1 > a)
@ -468,7 +469,7 @@ void __sanitizer_annotate_contiguous_container(const void *beg_p,
PoisonShadow(b2, c - b2, kAsanContiguousContainerOOBMagic);
if (b1 != b2) {
CHECK_EQ(b2 - b1, granularity);
*(u8 *)MemToShadow(b1) = static_cast<u8>(new_mid - b1);
*(u8 *)MemToShadow(b1) = static_cast<u8>(new_end - b1);
}
}