Imported Scudo Standalone changes:
- f018246c20481d222af4bab1868e8903c35c73d2 [scudo][standalone] Enabled SCUDO_DEBUG for tests + fixes by Kostya Kortchinsky <kostyak@google.com>
GitOrigin-RevId: f018246c20481d222af4bab1868e8903c35c73d2
Change-Id: Ic74e225f6539cd84df57f8359c70af89aea216e9
diff --git a/standalone/combined.h b/standalone/combined.h
index 2f8d82b..f4fa5d4 100644
--- a/standalone/combined.h
+++ b/standalone/combined.h
@@ -222,7 +222,7 @@
if (UNLIKELY(!isAligned(UserPtr, Alignment))) {
const uptr AlignedUserPtr = roundUpTo(UserPtr, Alignment);
const uptr Offset = AlignedUserPtr - UserPtr;
- DCHECK_GT(Offset, 2 * sizeof(u32));
+ DCHECK_GE(Offset, 2 * sizeof(u32));
// The BlockMarker has no security purpose, but is specifically meant for
// the chunk iteration function that can be used in debugging situations.
// It is the only situation where we have to locate the start of a chunk
diff --git a/standalone/internal_defs.h b/standalone/internal_defs.h
index 64ed238..f80c0f6 100644
--- a/standalone/internal_defs.h
+++ b/standalone/internal_defs.h
@@ -84,12 +84,12 @@
#define CHECK_IMPL(C1, Op, C2) \
do { \
- u64 V1 = (u64)(C1); \
- u64 V2 = (u64)(C2); \
+ scudo::u64 V1 = (scudo::u64)(C1); \
+ scudo::u64 V2 = (scudo::u64)(C2); \
if (UNLIKELY(!(V1 Op V2))) { \
- reportCheckFailed(__FILE__, __LINE__, "(" #C1 ") " #Op " (" #C2 ")", V1, \
- V2); \
- die(); \
+ scudo::reportCheckFailed(__FILE__, __LINE__, \
+ "(" #C1 ") " #Op " (" #C2 ")", V1, V2); \
+ scudo::die(); \
} \
} while (false)
diff --git a/standalone/secondary.h b/standalone/secondary.h
index bca783a..f288fc7 100644
--- a/standalone/secondary.h
+++ b/standalone/secondary.h
@@ -114,7 +114,7 @@
void *MapAllocator<MaxFreeListSize>::allocate(uptr Size, uptr AlignmentHint,
uptr *BlockEnd,
bool ZeroContents) {
- DCHECK_GT(Size, AlignmentHint);
+ DCHECK_GE(Size, AlignmentHint);
const uptr PageSize = getPageSizeCached();
const uptr RoundedSize =
roundUpTo(Size + LargeBlock::getHeaderSize(), PageSize);
diff --git a/standalone/size_class_map.h b/standalone/size_class_map.h
index dfef086..59d6ede 100644
--- a/standalone/size_class_map.h
+++ b/standalone/size_class_map.h
@@ -120,7 +120,8 @@
if (C < LargestClassId)
CHECK_EQ(getClassIdBySize(S + 1), C + 1);
CHECK_EQ(getClassIdBySize(S - 1), C);
- CHECK_GT(getSizeByClassId(C), getSizeByClassId(C - 1));
+ if (C - 1 != BatchClassId)
+ CHECK_GT(getSizeByClassId(C), getSizeByClassId(C - 1));
}
// Do not perform the loop if the maximum size is too large.
if (MaxSizeLog > 19)
@@ -129,7 +130,7 @@
const uptr C = getClassIdBySize(S);
CHECK_LT(C, NumClasses);
CHECK_GE(getSizeByClassId(C), S);
- if (C > 0)
+ if (C - 1 != BatchClassId)
CHECK_LT(getSizeByClassId(C - 1), S);
}
}
diff --git a/standalone/vector.h b/standalone/vector.h
index 3cb4005..6ca350a 100644
--- a/standalone/vector.h
+++ b/standalone/vector.h
@@ -84,7 +84,8 @@
DCHECK_LE(Size, NewCapacity);
const uptr NewCapacityBytes =
roundUpTo(NewCapacity * sizeof(T), getPageSizeCached());
- T *NewData = (T *)map(nullptr, NewCapacityBytes, "scudo:vector");
+ T *NewData =
+ reinterpret_cast<T *>(map(nullptr, NewCapacityBytes, "scudo:vector"));
if (Data) {
memcpy(NewData, Data, Size * sizeof(T));
unmap(Data, CapacityBytes);