summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2019-07-11 19:55:53 +0000
committerKostya Kortchinsky <kostyak@google.com>2019-07-11 19:55:53 +0000
commit5ec1a38f6ce0aeca2fbd4a79cac4ef10aef061a5 (patch)
tree2de88d363b0d3fe4f20164b0d84e0db6ac64e4bc
parent449e644b30b34b5ec2bd5d264663268d8bb5971a (diff)
downloadcompiler-rt-5ec1a38f6ce0aeca2fbd4a79cac4ef10aef061a5.tar.gz
[scudo][standalone] NFC corrections
Summary: A few corrections: - rename `TransferBatch::MaxCached` to `getMaxCached` to conform with the style guide; - move `getBlockBegin` from `Chunk::` to `Allocator::`: I believe it was a fallacy to have this be a `Chunk` method, as chunks' relationship to backend blocks are up to the frontend allocator. It makes more sense now, particularly with regard to the offset. Update the associated chunk test as the method isn't available there anymore; - add a forgotten `\n` to a log string; - for `releaseToOs`, instead of starting at `1`, start at `0` and `continue` on `BatchClassId`: in the end it's identical but doesn't assume a particular class id for batches; - change a `CHECK` to a `reportOutOfMemory`: it's a clearer message Reviewers: hctim, morehouse, eugenis, vitalybuka Reviewed By: hctim Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64570 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@365816 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/scudo/standalone/chunk.h6
-rw-r--r--lib/scudo/standalone/combined.h13
-rw-r--r--lib/scudo/standalone/local_cache.h9
-rw-r--r--lib/scudo/standalone/primary32.h6
-rw-r--r--lib/scudo/standalone/primary64.h6
-rw-r--r--lib/scudo/standalone/report.cc2
-rw-r--r--lib/scudo/standalone/tests/chunk_test.cc2
7 files changed, 25 insertions, 19 deletions
diff --git a/lib/scudo/standalone/chunk.h b/lib/scudo/standalone/chunk.h
index ec0b0ee8b..76ef661b0 100644
--- a/lib/scudo/standalone/chunk.h
+++ b/lib/scudo/standalone/chunk.h
@@ -97,12 +97,6 @@ const AtomicPackedHeader *getConstAtomicHeader(const void *Ptr) {
reinterpret_cast<uptr>(Ptr) - getHeaderSize());
}
-INLINE void *getBlockBegin(const void *Ptr, UnpackedHeader *Header) {
- return reinterpret_cast<void *>(reinterpret_cast<uptr>(Ptr) -
- getHeaderSize() -
- (Header->Offset << SCUDO_MIN_ALIGNMENT_LOG));
-}
-
// We do not need a cryptographically strong hash for the checksum, but a CRC
// type function that can alert us in the event a header is invalid or
// corrupted. Ideally slightly better than a simple xor of all fields.
diff --git a/lib/scudo/standalone/combined.h b/lib/scudo/standalone/combined.h
index fbbc7c8d2..4c1c1196b 100644
--- a/lib/scudo/standalone/combined.h
+++ b/lib/scudo/standalone/combined.h
@@ -45,7 +45,7 @@ public:
NewHeader.State = Chunk::State::Available;
Chunk::compareExchangeHeader(Allocator.Cookie, Ptr, &NewHeader, &Header);
- void *BlockBegin = Chunk::getBlockBegin(Ptr, &Header);
+ void *BlockBegin = Allocator::getBlockBegin(Ptr, &NewHeader);
const uptr ClassId = Header.ClassId;
if (ClassId)
Cache.deallocate(ClassId, BlockBegin);
@@ -482,12 +482,19 @@ private:
reportSanityCheckError("class ID");
}
+ static INLINE void *getBlockBegin(const void *Ptr,
+ Chunk::UnpackedHeader *Header) {
+ return reinterpret_cast<void *>(reinterpret_cast<uptr>(Ptr) -
+ Chunk::getHeaderSize() -
+ (Header->Offset << MinAlignmentLog));
+ }
+
// Return the size of a chunk as requested during its allocation.
INLINE uptr getSize(const void *Ptr, Chunk::UnpackedHeader *Header) {
const uptr SizeOrUnusedBytes = Header->SizeOrUnusedBytes;
if (Header->ClassId)
return SizeOrUnusedBytes;
- return SecondaryT::getBlockEnd(Chunk::getBlockBegin(Ptr, Header)) -
+ return SecondaryT::getBlockEnd(getBlockBegin(Ptr, Header)) -
reinterpret_cast<uptr>(Ptr) - SizeOrUnusedBytes;
}
@@ -505,7 +512,7 @@ private:
if (BypassQuarantine) {
NewHeader.State = Chunk::State::Available;
Chunk::compareExchangeHeader(Cookie, Ptr, &NewHeader, Header);
- void *BlockBegin = Chunk::getBlockBegin(Ptr, Header);
+ void *BlockBegin = getBlockBegin(Ptr, &NewHeader);
const uptr ClassId = NewHeader.ClassId;
if (ClassId) {
bool UnlockRequired;
diff --git a/lib/scudo/standalone/local_cache.h b/lib/scudo/standalone/local_cache.h
index 6d51019be..2acc28874 100644
--- a/lib/scudo/standalone/local_cache.h
+++ b/lib/scudo/standalone/local_cache.h
@@ -10,6 +10,7 @@
#define SCUDO_LOCAL_CACHE_H_
#include "internal_defs.h"
+#include "report.h"
#include "stats.h"
namespace scudo {
@@ -39,7 +40,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
DCHECK_LE(I, Count);
return Batch[I];
}
- static u32 MaxCached(uptr Size) {
+ static u32 getMaxCached(uptr Size) {
return Min(MaxNumCached, SizeClassMap::getMaxCachedHint(Size));
}
TransferBatch *Next;
@@ -140,7 +141,7 @@ private:
for (uptr I = 0; I < NumClasses; I++) {
PerClass *P = &PerClassArray[I];
const uptr Size = SizeClassAllocator::getSizeByClassId(I);
- P->MaxCount = 2 * TransferBatch::MaxCached(Size);
+ P->MaxCount = 2 * TransferBatch::getMaxCached(Size);
P->ClassSize = Size;
}
}
@@ -166,7 +167,9 @@ private:
const u32 Count = Min(C->MaxCount / 2, C->Count);
const uptr FirstIndexToDrain = C->Count - Count;
TransferBatch *B = createBatch(ClassId, C->Chunks[FirstIndexToDrain]);
- CHECK(B);
+ if (UNLIKELY(!B))
+ reportOutOfMemory(
+ SizeClassAllocator::getSizeByClassId(SizeClassMap::BatchClassId));
B->setFromArray(&C->Chunks[FirstIndexToDrain], Count);
C->Count -= Count;
Allocator->pushBatch(ClassId, B);
diff --git a/lib/scudo/standalone/primary32.h b/lib/scudo/standalone/primary32.h
index eade88a45..2b2fa8b3d 100644
--- a/lib/scudo/standalone/primary32.h
+++ b/lib/scudo/standalone/primary32.h
@@ -162,7 +162,9 @@ public:
}
void releaseToOS() {
- for (uptr I = 1; I < NumClasses; I++) {
+ for (uptr I = 0; I < NumClasses; I++) {
+ if (I == SizeClassMap::BatchClassId)
+ continue;
SizeClassInfo *Sci = getSizeClassInfo(I);
ScopedLock L(Sci->Mutex);
releaseToOSMaybe(Sci, I, /*Force=*/true);
@@ -291,7 +293,7 @@ private:
return nullptr;
C->getStats().add(StatMapped, RegionSize);
const uptr Size = getSizeByClassId(ClassId);
- const u32 MaxCount = TransferBatch::MaxCached(Size);
+ const u32 MaxCount = TransferBatch::getMaxCached(Size);
DCHECK_GT(MaxCount, 0);
const uptr NumberOfBlocks = RegionSize / Size;
DCHECK_GT(NumberOfBlocks, 0);
diff --git a/lib/scudo/standalone/primary64.h b/lib/scudo/standalone/primary64.h
index 89a43cce3..035182b33 100644
--- a/lib/scudo/standalone/primary64.h
+++ b/lib/scudo/standalone/primary64.h
@@ -166,7 +166,9 @@ public:
}
void releaseToOS() {
- for (uptr I = 1; I < NumClasses; I++) {
+ for (uptr I = 0; I < NumClasses; I++) {
+ if (I == SizeClassMap::BatchClassId)
+ continue;
RegionInfo *Region = getRegionInfo(I);
ScopedLock L(Region->Mutex);
releaseToOSMaybe(Region, I, /*Force=*/true);
@@ -249,7 +251,7 @@ private:
NOINLINE TransferBatch *populateFreeList(CacheT *C, uptr ClassId,
RegionInfo *Region) {
const uptr Size = getSizeByClassId(ClassId);
- const u32 MaxCount = TransferBatch::MaxCached(Size);
+ const u32 MaxCount = TransferBatch::getMaxCached(Size);
const uptr RegionBeg = Region->RegionBeg;
const uptr MappedUser = Region->MappedUser;
diff --git a/lib/scudo/standalone/report.cc b/lib/scudo/standalone/report.cc
index 2e453a10a..47cd951e8 100644
--- a/lib/scudo/standalone/report.cc
+++ b/lib/scudo/standalone/report.cc
@@ -52,7 +52,7 @@ void NORETURN reportCheckFailed(const char *File, int Line,
// Generic string fatal error message.
void NORETURN reportError(const char *Message) {
ScopedErrorReport Report;
- Report.append("%s", Message);
+ Report.append("%s\n", Message);
}
void NORETURN reportInvalidFlag(const char *FlagType, const char *Value) {
diff --git a/lib/scudo/standalone/tests/chunk_test.cc b/lib/scudo/standalone/tests/chunk_test.cc
index fea975b84..c3a21e41b 100644
--- a/lib/scudo/standalone/tests/chunk_test.cc
+++ b/lib/scudo/standalone/tests/chunk_test.cc
@@ -30,7 +30,6 @@ TEST(ScudoChunkTest, ChunkBasic) {
HeaderSize);
scudo::Chunk::storeHeader(Cookie, P, &Header);
memset(P, 'A', Size);
- EXPECT_EQ(scudo::Chunk::getBlockBegin(P, &Header), Block);
scudo::Chunk::loadHeader(Cookie, P, &Header);
EXPECT_TRUE(scudo::Chunk::isValid(Cookie, P, &Header));
EXPECT_FALSE(scudo::Chunk::isValid(InvalidCookie, P, &Header));
@@ -70,7 +69,6 @@ TEST(ScudoChunkTest, CorruptHeader) {
HeaderSize);
scudo::Chunk::storeHeader(Cookie, P, &Header);
memset(P, 'A', Size);
- EXPECT_EQ(scudo::Chunk::getBlockBegin(P, &Header), Block);
scudo::Chunk::loadHeader(Cookie, P, &Header);
// Simulate a couple of corrupted bits per byte of header data.
for (scudo::uptr I = 0; I < sizeof(scudo::Chunk::PackedHeader); I++) {