[compiler-rt] d5d09d9 - [NFC][Asan] Reformat some allocator code
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 5 15:56:40 PDT 2020
Author: Vitaly Buka
Date: 2020-09-05T15:56:02-07:00
New Revision: d5d09d93ee1494630654c487d9464771dba4e4d2
URL: https://github.com/llvm/llvm-project/commit/d5d09d93ee1494630654c487d9464771dba4e4d2
DIFF: https://github.com/llvm/llvm-project/commit/d5d09d93ee1494630654c487d9464771dba4e4d2.diff
LOG: [NFC][Asan] Reformat some allocator code
Added:
Modified:
compiler-rt/lib/asan/asan_allocator.cpp
compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 81c22e7a213f..d6792b38a69d 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -72,14 +72,14 @@ static const uptr kAllocBegMagic = 0xCC6E96B9;
struct ChunkHeader {
// 1-st 8 bytes.
- u32 chunk_state : 8; // Must be first.
- u32 alloc_tid : 24;
-
- u32 free_tid : 24;
- u32 from_memalign : 1;
- u32 alloc_type : 2;
- u32 rz_log : 3;
- u32 lsan_tag : 2;
+ u32 chunk_state : 8; // Must be first.
+ u32 alloc_tid : 24;
+
+ u32 free_tid : 24;
+ u32 from_memalign : 1;
+ u32 alloc_type : 2;
+ u32 rz_log : 3;
+ u32 lsan_tag : 2;
// 2-nd 8 bytes
// This field is used for small sizes. For large sizes it is equal to
// SizeClassMap::kMaxSize and the actual size is stored in the
@@ -109,7 +109,7 @@ enum {
// The chunk is allocated and not yet freed.
CHUNK_ALLOCATED = 2,
// The chunk was freed and put into quarantine zone.
- CHUNK_QUARANTINE = 3
+ CHUNK_QUARANTINE = 3,
};
struct AsanChunk: ChunkBase {
@@ -118,7 +118,7 @@ struct AsanChunk: ChunkBase {
if (user_requested_size != SizeClassMap::kMaxSize)
return user_requested_size;
return *reinterpret_cast<uptr *>(
- get_allocator().GetMetaData(AllocBeg(locked_version)));
+ get_allocator().GetMetaData(AllocBeg(locked_version)));
}
void *AllocBeg(bool locked_version = false) {
if (from_memalign) {
@@ -508,7 +508,7 @@ struct Allocator {
m->free_tid = kInvalidTid;
m->from_memalign = user_beg != beg_plus_redzone;
if (alloc_beg != chunk_beg) {
- CHECK_LE(alloc_beg+ 2 * sizeof(uptr), chunk_beg);
+ CHECK_LE(alloc_beg + 2 * sizeof(uptr), chunk_beg);
reinterpret_cast<uptr *>(alloc_beg)[0] = kAllocBegMagic;
reinterpret_cast<uptr *>(alloc_beg)[1] = chunk_beg;
}
@@ -722,7 +722,8 @@ struct Allocator {
// Assumes alloc_beg == allocator.GetBlockBegin(alloc_beg).
AsanChunk *GetAsanChunk(void *alloc_beg) {
- if (!alloc_beg) return nullptr;
+ if (!alloc_beg)
+ return nullptr;
if (!allocator.FromPrimary(alloc_beg)) {
uptr *meta = reinterpret_cast<uptr *>(allocator.GetMetaData(alloc_beg));
AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
@@ -738,11 +739,13 @@ struct Allocator {
}
AsanChunk *GetAsanChunkDebug(void *alloc_beg) {
- if (!alloc_beg) return nullptr;
+ if (!alloc_beg)
+ return nullptr;
if (!allocator.FromPrimary(alloc_beg)) {
uptr *meta = reinterpret_cast<uptr *>(allocator.GetMetaData(alloc_beg));
AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);
- Printf("GetAsanChunkDebug1 alloc_beg %p meta %p m %p\n", alloc_beg, meta, m);
+ Printf("GetAsanChunkDebug1 alloc_beg %p meta %p m %p\n", alloc_beg, meta,
+ m);
return m;
}
uptr *alloc_magic = reinterpret_cast<uptr *>(alloc_beg);
@@ -755,7 +758,6 @@ struct Allocator {
return reinterpret_cast<AsanChunk *>(alloc_beg);
}
-
AsanChunk *GetAsanChunkByAddr(uptr p) {
void *alloc_beg = allocator.GetBlockBegin(reinterpret_cast<void *>(p));
return GetAsanChunk(alloc_beg);
@@ -771,7 +773,8 @@ struct Allocator {
AsanChunk *GetAsanChunkByAddrFastLockedDebug(uptr p) {
void *alloc_beg =
allocator.GetBlockBeginFastLockedDebug(reinterpret_cast<void *>(p));
- Printf("GetAsanChunkByAddrFastLockedDebug p %p alloc_beg %p\n", p, alloc_beg);
+ Printf("GetAsanChunkByAddrFastLockedDebug p %p alloc_beg %p\n", p,
+ alloc_beg);
return GetAsanChunkDebug(alloc_beg);
}
@@ -1036,7 +1039,7 @@ void AsanSoftRssLimitExceededCallback(bool limit_exceeded) {
instance.SetRssLimitExceeded(limit_exceeded);
}
-} // namespace __asan
+} // namespace __asan
// --- Implementation of LSan-specific functions --- {{{1
namespace __lsan {
@@ -1073,7 +1076,8 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE const char *__lsan_current_stage;
void GetUserBeginDebug(uptr chunk) {
Printf("GetUserBeginDebug1 chunk %p\n", chunk);
- __asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddrFastLockedDebug(chunk);
+ __asan::AsanChunk *m =
+ __asan::instance.GetAsanChunkByAddrFastLockedDebug(chunk);
Printf("GetUserBeginDebug2 m %p\n", m);
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h
index 6d73784d77d0..0cf483da1e5c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h
@@ -148,7 +148,6 @@ class CombinedAllocator {
return secondary_.GetBlockBeginFastLocked(p);
}
-
uptr GetActuallyAllocatedSize(void *p) {
if (primary_.PointerIsMine(p))
return primary_.GetActuallyAllocatedSize(p);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 7af469c56fd6..a6126fc6265e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -203,7 +203,8 @@ class SizeClassAllocator64 {
uptr class_id = GetSizeClass(p);
uptr size = ClassIdToSize(class_id);
Printf("GetBlockBeginDebug1 p %p class_id %p size %p\n", p, class_id, size);
- if (!size) return nullptr;
+ if (!size)
+ return nullptr;
uptr chunk_idx = GetChunkIdx((uptr)p, size);
uptr reg_beg = GetRegionBegin(p);
uptr beg = chunk_idx * size;
@@ -212,16 +213,16 @@ class SizeClassAllocator64 {
"GetBlockBeginDebug2 chunk_idx %p reg_beg %p beg %p next_beg %p "
"kNumClasses %p\n",
chunk_idx, reg_beg, beg, next_beg, kNumClasses);
- if (class_id >= kNumClasses) return nullptr;
+ if (class_id >= kNumClasses)
+ return nullptr;
const RegionInfo *region = AddressSpaceView::Load(GetRegionInfo(class_id));
Printf("GetBlockBeginDebug3 region %p region->mapped_user %p\n", region,
region->mapped_user);
if (region->mapped_user >= next_beg)
- return reinterpret_cast<void*>(reg_beg + beg);
+ return reinterpret_cast<void *>(reg_beg + beg);
return nullptr;
}
-
uptr GetActuallyAllocatedSize(void *p) {
CHECK(PointerIsMine(p));
return ClassIdToSize(GetSizeClass(p));
More information about the llvm-commits
mailing list