Skip to content

Commit 3f97c66

Browse files
author
Kostya Kortchinsky
committed
[scudo][standalone] Fuchsia related fixes
While attempting to roll the latest Scudo in Fuchsia, some issues arose. While trying to debug them, it appeared that `DCHECK`s were also never exercised in Fuchsia. This CL fixes the following problems: - the size of a block in the TransferBatch class must be a multiple of the compact pointer scale. In some cases, it wasn't true, which lead to obscure crashes. Now, we round up `sizeof(TransferBatch)`. This only materialized in Fuchsia due to the specific parameters of the `DefaultConfig`; - 2 `DCHECK` statements in Fuchsia were incorrect; - `map()` & co. require a size multiple of a page (as enforced in Fuchsia `DCHECK`s), which wasn't the case for `PackedCounters`. - In the Secondary, a parameter was marked as `UNUSED` while it is actually used. Differential Revision: https://reviews.llvm.org/D100524
1 parent 07edd78 commit 3f97c66

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎compiler-rt/lib/scudo/standalone/fuchsia.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void *allocateVmar(uptr Size, MapPlatformData *Data, bool AllowNoMem) {
4949

5050
void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
5151
MapPlatformData *Data) {
52-
DCHECK_EQ(Size % PAGE_SIZE, 0);
52+
DCHECK_EQ(Size % getPageSizeCached(), 0);
5353
const bool AllowNoMem = !!(Flags & MAP_ALLOWNOMEM);
5454

5555
// For MAP_NOACCESS, just allocate a Vmar and return.
@@ -96,8 +96,10 @@ void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
9696
// No need to track the Vmo if we don't intend on resizing it. Close it.
9797
if (Flags & MAP_RESIZABLE) {
9898
DCHECK(Data);
99-
DCHECK_EQ(Data->Vmo, ZX_HANDLE_INVALID);
100-
Data->Vmo = Vmo;
99+
if (Data->Vmo == ZX_HANDLE_INVALID)
100+
Data->Vmo = Vmo;
101+
else
102+
DCHECK_EQ(Data->Vmo, Vmo);
101103
} else {
102104
CHECK_EQ(_zx_handle_close(Vmo), ZX_OK);
103105
}

‎compiler-rt/lib/scudo/standalone/primary64.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ template <typename Config> class SizeClassAllocator64 {
5151

5252
static uptr getSizeByClassId(uptr ClassId) {
5353
return (ClassId == SizeClassMap::BatchClassId)
54-
? sizeof(TransferBatch)
54+
? roundUpTo(sizeof(TransferBatch), 1U << CompactPtrScale)
5555
: SizeClassMap::getSizeByClassId(ClassId);
5656
}
5757

‎compiler-rt/lib/scudo/standalone/release.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class PackedCounterArray {
8181
memset(Buffer, 0, BufferSize);
8282
} else {
8383
Buffer = reinterpret_cast<uptr *>(
84-
map(nullptr, BufferSize, "scudo:counters", MAP_ALLOWNOMEM));
84+
map(nullptr, roundUpTo(BufferSize, getPageSizeCached()),
85+
"scudo:counters", MAP_ALLOWNOMEM));
8586
}
8687
}
8788
~PackedCounterArray() {
@@ -90,7 +91,8 @@ class PackedCounterArray {
9091
if (Buffer == &StaticBuffer[0])
9192
Mutex.unlock();
9293
else
93-
unmap(reinterpret_cast<void *>(Buffer), BufferSize);
94+
unmap(reinterpret_cast<void *>(Buffer),
95+
roundUpTo(BufferSize, getPageSizeCached()));
9496
}
9597

9698
bool isAllocated() const { return !!Buffer; }

‎compiler-rt/lib/scudo/standalone/secondary.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MapAllocatorNoCache {
6969
UNUSED LargeBlock::Header **H, UNUSED bool *Zeroed) {
7070
return false;
7171
}
72-
void store(UNUSED Options Options, UNUSED LargeBlock::Header *H) { unmap(H); }
72+
void store(UNUSED Options Options, LargeBlock::Header *H) { unmap(H); }
7373
bool canCache(UNUSED uptr Size) { return false; }
7474
void disable() {}
7575
void enable() {}

0 commit comments

Comments
 (0)