Skip to content

Commit 271fbb0

Browse files
vitalybukaAdvenamTacet
authored andcommitted
Shorten function name
1 parent 74bf44a commit 271fbb0

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

compiler-rt/lib/asan/asan_poisoning.cpp

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -576,31 +576,13 @@ void __sanitizer_annotate_double_ended_contiguous_container(
576576
}
577577
}
578578

579-
// Checks if a buffer [p; q) falls into a single granule.
580-
static bool WithinOneGranule(uptr p, uptr q) {
581-
constexpr uptr granularity = ASAN_SHADOW_GRANULARITY;
582-
if (p == q)
583-
return true;
584-
return RoundDownTo(p, granularity) == RoundDownTo(q - 1, granularity);
585-
}
586-
587-
// Copies ASan memory annotation (a shadow memory value)
588-
// from one granule to another.
589-
static void CopyGranuleAnnotation(uptr dst, uptr src) {
590-
*(u8 *)MemToShadow(dst) = *(u8 *)MemToShadow(src);
591-
}
592579

593580
// Marks the specified number of bytes in a granule as accessible or
594581
// poisones the whole granule with kAsanContiguousContainerOOBMagic value.
595-
static void AnnotateContainerGranuleAccessibleBytes(uptr ptr, u8 n) {
582+
static void SetContainerGranule(uptr ptr, u8 n) {
596583
constexpr uptr granularity = ASAN_SHADOW_GRANULARITY;
597-
if (n == granularity) {
598-
*(u8 *)MemToShadow(ptr) = 0;
599-
} else if (n == 0) {
600-
*(u8 *)MemToShadow(ptr) = static_cast<u8>(kAsanContiguousContainerOOBMagic);
601-
} else {
602-
*(u8 *)MemToShadow(ptr) = n;
603-
}
584+
u8 s = (n == granularity) ? 0 : (n ? n : kAsanContiguousContainerOOBMagic);
585+
*(u8 *)MemToShadow(ptr) = s;
604586
}
605587

606588
// Performs a byte-by-byte copy of ASan annotations (shadow memory values).
@@ -629,11 +611,9 @@ static void SlowCopyContainerAnnotations(uptr src_storage_beg,
629611
if (dst_ptr < dst_storage_end || dst_ptr == dst_internal_end ||
630612
AddressIsPoisoned(dst_storage_end)) {
631613
if (unpoisoned_bytes != 0 || granule_begin >= dst_storage_beg) {
632-
AnnotateContainerGranuleAccessibleBytes(granule_begin,
633-
unpoisoned_bytes);
614+
SetContainerGranule(granule_begin, unpoisoned_bytes);
634615
} else if (!AddressIsPoisoned(dst_storage_beg)) {
635-
AnnotateContainerGranuleAccessibleBytes(
636-
granule_begin, dst_storage_beg - granule_begin);
616+
SetContainerGranule(granule_begin, dst_storage_beg - granule_begin);
637617
}
638618
}
639619
}
@@ -669,10 +649,9 @@ static void SlowReversedCopyContainerAnnotations(uptr src_storage_beg,
669649
}
670650

671651
if (granule_begin == dst_ptr || unpoisoned_bytes != 0) {
672-
AnnotateContainerGranuleAccessibleBytes(granule_begin, unpoisoned_bytes);
652+
SetContainerGranule(granule_begin, unpoisoned_bytes);
673653
} else if (!AddressIsPoisoned(dst_storage_beg)) {
674-
AnnotateContainerGranuleAccessibleBytes(granule_begin,
675-
dst_storage_beg - granule_begin);
654+
SetContainerGranule(granule_begin, dst_storage_beg - granule_begin);
676655
}
677656
}
678657
}
@@ -687,10 +666,11 @@ static void CopyContainerFirstGranuleAnnotation(uptr src_storage_begin,
687666
uptr dst_external_begin = RoundDownTo(dst_storage_begin, granularity);
688667
uptr src_external_begin = RoundDownTo(src_storage_begin, granularity);
689668
if (!AddressIsPoisoned(src_storage_begin)) {
690-
CopyGranuleAnnotation(dst_external_begin, src_external_begin);
669+
*(u8 *)MemToShadow(dst_external_begin) =
670+
*(u8 *)MemToShadow(src_external_begin);
691671
} else if (!AddressIsPoisoned(dst_storage_begin)) {
692-
AnnotateContainerGranuleAccessibleBytes(
693-
dst_external_begin, dst_storage_begin - dst_external_begin);
672+
SetContainerGranule(dst_external_begin,
673+
dst_storage_begin - dst_external_begin);
694674
}
695675
}
696676

@@ -703,10 +683,9 @@ static void CopyContainerLastGranuleAnnotation(uptr src_storage_end,
703683
// Last granule
704684
uptr src_internal_end = RoundDownTo(src_storage_end, granularity);
705685
if (AddressIsPoisoned(src_storage_end)) {
706-
CopyGranuleAnnotation(dst_internal_end, src_internal_end);
686+
*(u8 *)MemToShadow(dst_internal_end) = *(u8 *)MemToShadow(src_internal_end);
707687
} else {
708-
AnnotateContainerGranuleAccessibleBytes(dst_internal_end,
709-
src_storage_end - src_internal_end);
688+
SetContainerGranule(dst_internal_end, src_storage_end - src_internal_end);
710689
}
711690
}
712691

@@ -763,7 +742,7 @@ void __sanitizer_copy_contiguous_container_annotations(const void *src_begin_p,
763742
bool copy_in_reversed_order = src_storage_begin < dst_storage_begin &&
764743
dst_storage_begin <= src_external_end;
765744
if (src_storage_begin % granularity != dst_storage_begin % granularity ||
766-
WithinOneGranule(dst_storage_begin, dst_storage_end)) {
745+
RoundDownTo(dst_storage_end - 1, granularity) <= dst_storage_begin) {
767746
if (copy_in_reversed_order) {
768747
SlowReversedCopyContainerAnnotations(src_storage_begin, src_storage_end,
769748
dst_storage_begin, dst_storage_end);

0 commit comments

Comments
 (0)