summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2019-12-04 17:28:45 -0800
committerPeter Collingbourne <peter@pcc.me.uk>2019-12-10 12:09:47 -0800
commit9fbfdd2bfe42a6d0a8e680c64a968e9cfc065fd3 (patch)
tree6bb599f4de4fde58e8ed17e1ee65cd61f880cdb0
parente966416ff15178bf982430085be9ae69e5a511fa (diff)
downloadbcm5719-llvm-9fbfdd2bfe42a6d0a8e680c64a968e9cfc065fd3.tar.gz
bcm5719-llvm-9fbfdd2bfe42a6d0a8e680c64a968e9cfc065fd3.zip
scudo: Tweak how we align UserPtr. NFCI.
Instead of testing whether the pointer is aligned, just align it unconditionally and compare it to the original pointer. This moves the computation of UserPtr up to before we start preparing the header, so that the memory tagging code will be able to read the original header containing the bounds of the previous allocation before it gets potentially clobbered by the pointer realignment code. Differential Revision: https://reviews.llvm.org/D71292
-rw-r--r--compiler-rt/lib/scudo/standalone/combined.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 02c998e666d..53e0bf7d730 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -221,11 +221,13 @@ public:
if (UNLIKELY(ZeroContents && ClassId))
memset(Block, 0, PrimaryT::getSizeByClassId(ClassId));
+ const uptr UnalignedUserPtr =
+ reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();
+ const uptr UserPtr = roundUpTo(UnalignedUserPtr, Alignment);
+
Chunk::UnpackedHeader Header = {};
- uptr UserPtr = reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();
- if (UNLIKELY(!isAligned(UserPtr, Alignment))) {
- const uptr AlignedUserPtr = roundUpTo(UserPtr, Alignment);
- const uptr Offset = AlignedUserPtr - UserPtr;
+ if (UNLIKELY(UnalignedUserPtr != UserPtr)) {
+ const uptr Offset = UserPtr - UnalignedUserPtr;
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.
@@ -233,7 +235,6 @@ public:
// based on its block address.
reinterpret_cast<u32 *>(Block)[0] = BlockMarker;
reinterpret_cast<u32 *>(Block)[1] = static_cast<u32>(Offset);
- UserPtr = AlignedUserPtr;
Header.Offset = (Offset >> MinAlignmentLog) & Chunk::OffsetMask;
}
Header.ClassId = ClassId & Chunk::ClassIdMask;
OpenPOWER on IntegriCloud