Skip to content

Commit 6fd0ddc

Browse files
authored
Merge pull request #75454 from tbkka/tbkka-reflection-performance-asan
When ASAN is visible, do not use page-aligned requests
2 parents 840198e + 9214ebd commit 6fd0ddc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

stdlib/tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ static
208208
const void *PipeMemoryReader_readBytes(void *Context, swift_addr_t Address,
209209
uint64_t Size, void **outFreeContext) {
210210
PipeMemoryReader *Reader = (PipeMemoryReader *)Context;
211+
212+
#if __has_feature(address_sanitizer)
213+
// ASAN dislikes reading arbitrary pages of memory, so
214+
// be more conservative and only read exactly the requested bytes.
215+
uintptr_t TargetAddress = Address;
216+
size_t TargetSize = Size;
217+
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
218+
write(WriteFD, REQUEST_READ_BYTES, 2);
219+
write(WriteFD, &TargetAddress, sizeof(TargetAddress));
220+
write(WriteFD, &TargetSize, sizeof(size_t));
221+
222+
void *Buf = malloc(TargetSize);
223+
PipeMemoryReader_collectBytesFromPipe(Reader, Buf, TargetSize);
224+
*outFreeContext = NULL;
225+
return Buf;
226+
227+
#else
211228
PipeMemoryReaderPage *Page = Reader->Pages;
212229

213230
// Try to find an existing page with the requested bytes
@@ -249,8 +266,8 @@ const void *PipeMemoryReader_readBytes(void *Context, swift_addr_t Address,
249266
void *Buf = malloc(Size);
250267
memcpy(Buf, Page->Data + Address - Page->BaseAddress, Size);
251268
*outFreeContext = NULL;
252-
253269
return Buf;
270+
#endif
254271
}
255272

256273
static

0 commit comments

Comments
 (0)