Skip to content

Commit 5670ef4

Browse files
committed
[NFC][hwasan] Extract a few BaseReport::Copy methods (#66682)
1 parent 1c91b1e commit 5670ef4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

compiler-rt/lib/hwasan/hwasan_report.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,8 @@ class BaseReport {
390390
if (MemIsShadow(untagged_addr))
391391
return;
392392

393-
HwasanChunkView chunk = FindHeapChunkByAddress(untagged_addr);
394-
heap.begin = chunk.Beg();
395-
if (heap.begin) {
396-
heap.size = chunk.ActualSize();
397-
heap.from_small_heap = chunk.FromSmallHeap();
398-
heap.is_allocated = chunk.IsAllocated();
399-
}
400-
401-
hwasanThreadList().VisitAllLiveThreads([&](Thread *t) {
402-
if (stack_allocations_count < ARRAY_SIZE(stack_allocations) &&
403-
t->AddrIsInStack(untagged_addr)) {
404-
stack_allocations[stack_allocations_count++].CopyFrom(t);
405-
}
406-
});
407-
393+
CopyHeapChunk();
394+
CopyStackAllocations();
408395
candidate = FindBufferOverflowCandidate();
409396
}
410397

@@ -423,6 +410,8 @@ class BaseReport {
423410
} heap;
424411
};
425412

413+
void CopyHeapChunk();
414+
void CopyStackAllocations();
426415
OverflowCandidate FindBufferOverflowCandidate() const;
427416
void PrintAddressDescription() const;
428417
void PrintHeapOrGlobalCandidate() const;
@@ -447,6 +436,25 @@ class BaseReport {
447436
OverflowCandidate candidate;
448437
};
449438

439+
void BaseReport::CopyHeapChunk() {
440+
HwasanChunkView chunk = FindHeapChunkByAddress(untagged_addr);
441+
heap.begin = chunk.Beg();
442+
if (heap.begin) {
443+
heap.size = chunk.ActualSize();
444+
heap.from_small_heap = chunk.FromSmallHeap();
445+
heap.is_allocated = chunk.IsAllocated();
446+
}
447+
}
448+
449+
void BaseReport::CopyStackAllocations() {
450+
hwasanThreadList().VisitAllLiveThreads([&](Thread *t) {
451+
if (stack_allocations_count < ARRAY_SIZE(stack_allocations) &&
452+
t->AddrIsInStack(untagged_addr)) {
453+
stack_allocations[stack_allocations_count++].CopyFrom(t);
454+
}
455+
});
456+
}
457+
450458
BaseReport::OverflowCandidate BaseReport::FindBufferOverflowCandidate() const {
451459
// Check if this looks like a heap buffer overflow by scanning
452460
// the shadow left and right and looking for the first adjacent

0 commit comments

Comments
 (0)