Skip to content

[scudo] Compute the default aligned pointer without tag #92989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions compiler-rt/lib/scudo/standalone/combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ class Allocator {
void *Block, const uptr UserPtr,
const uptr SizeOrUnusedBytes,
const FillContentsMode FillContents) {
// Compute the default pointer before adding the header tag
const uptr DefaultAlignedPtr =
reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();

Block = addHeaderTag(Block);
// Only do content fill when it's from primary allocator because secondary
// allocator has filled the content.
Expand All @@ -1064,8 +1068,6 @@ class Allocator {

Chunk::UnpackedHeader Header = {};

const uptr DefaultAlignedPtr =
reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();
if (UNLIKELY(DefaultAlignedPtr != UserPtr)) {
const uptr Offset = UserPtr - DefaultAlignedPtr;
DCHECK_GE(Offset, 2 * sizeof(u32));
Expand Down Expand Up @@ -1096,6 +1098,10 @@ class Allocator {
const Options Options = Primary.Options.load();
DCHECK(useMemoryTagging<AllocatorConfig>(Options));

// Compute the default pointer before adding the header tag
const uptr DefaultAlignedPtr =
reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();

void *Ptr = reinterpret_cast<void *>(UserPtr);
void *TaggedPtr = Ptr;

Expand Down Expand Up @@ -1194,8 +1200,6 @@ class Allocator {

Chunk::UnpackedHeader Header = {};

const uptr DefaultAlignedPtr =
reinterpret_cast<uptr>(Block) + Chunk::getHeaderSize();
if (UNLIKELY(DefaultAlignedPtr != UserPtr)) {
const uptr Offset = UserPtr - DefaultAlignedPtr;
DCHECK_GE(Offset, 2 * sizeof(u32));
Expand Down
Loading