Skip to content

When ASAN is visible, do not use page-aligned requests #75454

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
Jul 25, 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
19 changes: 18 additions & 1 deletion stdlib/tools/swift-reflection-test/swift-reflection-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ static
const void *PipeMemoryReader_readBytes(void *Context, swift_addr_t Address,
uint64_t Size, void **outFreeContext) {
PipeMemoryReader *Reader = (PipeMemoryReader *)Context;

#if __has_feature(address_sanitizer)
// ASAN dislikes reading arbitrary pages of memory, so
// be more conservative and only read exactly the requested bytes.
uintptr_t TargetAddress = Address;
size_t TargetSize = Size;
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
write(WriteFD, REQUEST_READ_BYTES, 2);
write(WriteFD, &TargetAddress, sizeof(TargetAddress));
write(WriteFD, &TargetSize, sizeof(size_t));

void *Buf = malloc(TargetSize);
PipeMemoryReader_collectBytesFromPipe(Reader, Buf, TargetSize);
*outFreeContext = NULL;
return Buf;

#else
PipeMemoryReaderPage *Page = Reader->Pages;

// Try to find an existing page with the requested bytes
Expand Down Expand Up @@ -249,8 +266,8 @@ const void *PipeMemoryReader_readBytes(void *Context, swift_addr_t Address,
void *Buf = malloc(Size);
memcpy(Buf, Page->Data + Address - Page->BaseAddress, Size);
*outFreeContext = NULL;

return Buf;
#endif
}

static
Expand Down