[asan] Faster version of QuickCheckForUnpoisonedRegion

Slightly helps with performance regression after D128146.
This commit is contained in:
Vitaly Buka 2022-08-08 21:38:55 -07:00
parent 2db6b34ea8
commit ea42515dad

View File

@ -26,17 +26,21 @@ namespace __asan {
// Return true if we can quickly decide that the region is unpoisoned.
// We assume that a redzone is at least 16 bytes.
static inline bool QuickCheckForUnpoisonedRegion(uptr beg, uptr size) {
if (UNLIKELY(size == 0))
if (UNLIKELY(size == 0 || size > sizeof(uptr) * ASAN_SHADOW_GRANULARITY))
return !size;
uptr last = beg + size - 1;
uptr shadow_first = MEM_TO_SHADOW(beg);
uptr shadow_last = MEM_TO_SHADOW(last);
uptr uptr_first = RoundDownTo(shadow_first, sizeof(uptr));
uptr uptr_last = RoundDownTo(shadow_last, sizeof(uptr));
if (LIKELY(((*reinterpret_cast<const uptr *>(uptr_first) |
*reinterpret_cast<const uptr *>(uptr_last)) == 0)))
return true;
if (size <= 32)
return !AddressIsPoisoned(beg) && !AddressIsPoisoned(beg + size - 1) &&
!AddressIsPoisoned(beg + size / 2);
if (size <= 64)
return !AddressIsPoisoned(beg) && !AddressIsPoisoned(beg + size / 4) &&
!AddressIsPoisoned(beg + size - 1) &&
!AddressIsPoisoned(beg + 3 * size / 4) &&
!AddressIsPoisoned(beg + size / 2);
return false;
u8 shadow = AddressIsPoisoned(last);
for (; shadow_first < shadow_last; ++shadow_first)
shadow |= *((u8 *)shadow_first);
return !shadow;
}
struct AsanInterceptorContext {