Skip to content

Commit 48ac5b4

Browse files
committed
[NFC][Asan] Reformat some allocator code
1 parent e2fc6a3 commit 48ac5b4

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ static const uptr kAllocBegMagic = 0xCC6E96B9;
7373
struct ChunkHeader {
7474
// 1-st 8 bytes.
7575
atomic_uint8_t chunk_state;
76-
u32 alloc_tid : 24;
76+
u32 alloc_tid : 24;
7777

78-
u32 free_tid : 24;
79-
u32 from_memalign : 1;
80-
u32 alloc_type : 2;
81-
u32 rz_log : 3;
82-
u32 lsan_tag : 2;
78+
u32 free_tid : 24;
79+
u32 from_memalign : 1;
80+
u32 alloc_type : 2;
81+
u32 rz_log : 3;
82+
u32 lsan_tag : 2;
8383
// 2-nd 8 bytes
8484
// This field is used for small sizes. For large sizes it is equal to
8585
// SizeClassMap::kMaxSize and the actual size is stored in the
@@ -109,7 +109,7 @@ enum {
109109
// The chunk is allocated and not yet freed.
110110
CHUNK_ALLOCATED = 2,
111111
// The chunk was freed and put into quarantine zone.
112-
CHUNK_QUARANTINE = 3
112+
CHUNK_QUARANTINE = 3,
113113
};
114114

115115
struct AsanChunk: ChunkBase {
@@ -118,7 +118,7 @@ struct AsanChunk: ChunkBase {
118118
if (user_requested_size != SizeClassMap::kMaxSize)
119119
return user_requested_size;
120120
return *reinterpret_cast<uptr *>(
121-
get_allocator().GetMetaData(AllocBeg(locked_version)));
121+
get_allocator().GetMetaData(AllocBeg(locked_version)));
122122
}
123123
void *AllocBeg(bool locked_version = false) {
124124
if (from_memalign) {
@@ -519,7 +519,7 @@ struct Allocator {
519519
m->free_tid = kInvalidTid;
520520
m->from_memalign = user_beg != beg_plus_redzone;
521521
if (alloc_beg != chunk_beg) {
522-
CHECK_LE(alloc_beg+ 2 * sizeof(uptr), chunk_beg);
522+
CHECK_LE(alloc_beg + 2 * sizeof(uptr), chunk_beg);
523523
reinterpret_cast<uptr *>(alloc_beg)[0] = kAllocBegMagic;
524524
reinterpret_cast<uptr *>(alloc_beg)[1] = chunk_beg;
525525
}
@@ -735,7 +735,8 @@ struct Allocator {
735735

736736
// Assumes alloc_beg == allocator.GetBlockBegin(alloc_beg).
737737
AsanChunk *GetAsanChunk(void *alloc_beg) {
738-
if (!alloc_beg) return nullptr;
738+
if (!alloc_beg)
739+
return nullptr;
739740
if (!allocator.FromPrimary(alloc_beg)) {
740741
uptr *meta = reinterpret_cast<uptr *>(allocator.GetMetaData(alloc_beg));
741742
AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
@@ -751,11 +752,13 @@ struct Allocator {
751752
}
752753

753754
AsanChunk *GetAsanChunkDebug(void *alloc_beg) {
754-
if (!alloc_beg) return nullptr;
755+
if (!alloc_beg)
756+
return nullptr;
755757
if (!allocator.FromPrimary(alloc_beg)) {
756758
uptr *meta = reinterpret_cast<uptr *>(allocator.GetMetaData(alloc_beg));
757759
AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
758-
Printf("GetAsanChunkDebug1 alloc_beg %p meta %p m %p\n", alloc_beg, meta, m);
760+
Printf("GetAsanChunkDebug1 alloc_beg %p meta %p m %p\n", alloc_beg, meta,
761+
m);
759762
return m;
760763
}
761764
uptr *alloc_magic = reinterpret_cast<uptr *>(alloc_beg);
@@ -768,7 +771,6 @@ struct Allocator {
768771
return reinterpret_cast<AsanChunk *>(alloc_beg);
769772
}
770773

771-
772774
AsanChunk *GetAsanChunkByAddr(uptr p) {
773775
void *alloc_beg = allocator.GetBlockBegin(reinterpret_cast<void *>(p));
774776
return GetAsanChunk(alloc_beg);
@@ -784,7 +786,8 @@ struct Allocator {
784786
AsanChunk *GetAsanChunkByAddrFastLockedDebug(uptr p) {
785787
void *alloc_beg =
786788
allocator.GetBlockBeginFastLockedDebug(reinterpret_cast<void *>(p));
787-
Printf("GetAsanChunkByAddrFastLockedDebug p %p alloc_beg %p\n", p, alloc_beg);
789+
Printf("GetAsanChunkByAddrFastLockedDebug p %p alloc_beg %p\n", p,
790+
alloc_beg);
788791
return GetAsanChunkDebug(alloc_beg);
789792
}
790793

@@ -1055,7 +1058,7 @@ void AsanSoftRssLimitExceededCallback(bool limit_exceeded) {
10551058
instance.SetRssLimitExceeded(limit_exceeded);
10561059
}
10571060

1058-
} // namespace __asan
1061+
} // namespace __asan
10591062

10601063
// --- Implementation of LSan-specific functions --- {{{1
10611064
namespace __lsan {
@@ -1092,7 +1095,8 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE const char *__lsan_current_stage;
10921095

10931096
void GetUserBeginDebug(uptr chunk) {
10941097
Printf("GetUserBeginDebug1 chunk %p\n", chunk);
1095-
__asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddrFastLockedDebug(chunk);
1098+
__asan::AsanChunk *m =
1099+
__asan::instance.GetAsanChunkByAddrFastLockedDebug(chunk);
10961100
Printf("GetUserBeginDebug2 m %p\n", m);
10971101
}
10981102

compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ class CombinedAllocator {
148148
return secondary_.GetBlockBeginFastLocked(p);
149149
}
150150

151-
152151
uptr GetActuallyAllocatedSize(void *p) {
153152
if (primary_.PointerIsMine(p))
154153
return primary_.GetActuallyAllocatedSize(p);

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ class SizeClassAllocator64 {
203203
uptr class_id = GetSizeClass(p);
204204
uptr size = ClassIdToSize(class_id);
205205
Printf("GetBlockBeginDebug1 p %p class_id %p size %p\n", p, class_id, size);
206-
if (!size) return nullptr;
206+
if (!size)
207+
return nullptr;
207208
uptr chunk_idx = GetChunkIdx((uptr)p, size);
208209
uptr reg_beg = GetRegionBegin(p);
209210
uptr beg = chunk_idx * size;
@@ -212,16 +213,16 @@ class SizeClassAllocator64 {
212213
"GetBlockBeginDebug2 chunk_idx %p reg_beg %p beg %p next_beg %p "
213214
"kNumClasses %p\n",
214215
chunk_idx, reg_beg, beg, next_beg, kNumClasses);
215-
if (class_id >= kNumClasses) return nullptr;
216+
if (class_id >= kNumClasses)
217+
return nullptr;
216218
const RegionInfo *region = AddressSpaceView::Load(GetRegionInfo(class_id));
217219
Printf("GetBlockBeginDebug3 region %p region->mapped_user %p\n", region,
218220
region->mapped_user);
219221
if (region->mapped_user >= next_beg)
220-
return reinterpret_cast<void*>(reg_beg + beg);
222+
return reinterpret_cast<void *>(reg_beg + beg);
221223
return nullptr;
222224
}
223225

224-
225226
uptr GetActuallyAllocatedSize(void *p) {
226227
CHECK(PointerIsMine(p));
227228
return ClassIdToSize(GetSizeClass(p));

0 commit comments

Comments
 (0)