Skip to content

Commit

Permalink
[scudo] Use DefaultSizeClassMap for 32-bit
Browse files Browse the repository at this point in the history
Summary:
With the recent changes to the Secondary, we use less bits for UnusedBytes,
which allows us in return to increase the bits used for Offset. That means
that we can use a Primary SizeClassMap allowing for a larger maximum size.

Reviewers: kcc, alekseyshl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27816

llvm-svn: 289838
  • Loading branch information
Kostya Kortchinsky committed Dec 15, 2016
1 parent a0d8a27 commit 47be0ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions compiler-rt/lib/scudo/scudo_allocator.cpp
Expand Up @@ -68,7 +68,7 @@ typedef FlatByteMap<NumRegions> ByteMap;
# elif SANITIZER_WORDSIZE == 64
typedef TwoLevelByteMap<(NumRegions >> 12), 1 << 12> ByteMap;
# endif // SANITIZER_WORDSIZE
typedef SizeClassMap<3, 4, 8, 16, 64, 14> SizeClassMap;
typedef DefaultSizeClassMap SizeClassMap;
typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE, 0, SizeClassMap,
RegionSizeLog, ByteMap> PrimaryAllocator;
#endif // SANITIZER_CAN_USE_ALLOCATOR64
Expand Down Expand Up @@ -354,11 +354,11 @@ struct Allocator {
"header\n");
}
// Verify that we can fit the maximum amount of unused bytes in the header.
// The worst case scenario would be when allocating 1 byte on a MaxAlignment
// alignment. Since the combined allocator currently rounds the size up to
// the alignment before passing it to the secondary, we end up with
// MaxAlignment - 1 extra bytes.
uptr MaxUnusedBytes = MaxAlignment - 1;
// Given that the Secondary fits the allocation to a page, the worst case
// scenario happens in the Primary. It will depend on the second to last
// and last class sizes, as well as the dynamic base for the Primary. The
// following is an over-approximation that works for our needs.
uptr MaxUnusedBytes = SizeClassMap::kMaxSize - 1 - AlignedChunkHeaderSize;
Header.UnusedBytes = MaxUnusedBytes;
if (Header.UnusedBytes != MaxUnusedBytes) {
dieWithMessage("ERROR: the maximum possible unused bytes doesn't fit in "
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/scudo/scudo_allocator.h
Expand Up @@ -44,10 +44,10 @@ enum ChunkState : u8 {
typedef u64 PackedHeader;
struct UnpackedHeader {
u64 Checksum : 16;
u64 UnusedBytes : 24; // Needed for reallocation purposes.
u64 UnusedBytes : 20; // Needed for reallocation purposes.
u64 State : 2; // available, allocated, or quarantined
u64 AllocType : 2; // malloc, new, new[], or memalign
u64 Offset : 12; // Offset from the beginning of the backend
u64 Offset : 16; // Offset from the beginning of the backend
// allocation to the beginning of the chunk itself,
// in multiples of MinAlignment. See comment about
// its maximum value and test in init().
Expand Down

0 comments on commit 47be0ed

Please sign in to comment.