@@ -208,6 +208,23 @@ static
208
208
const void * PipeMemoryReader_readBytes (void * Context , swift_addr_t Address ,
209
209
uint64_t Size , void * * outFreeContext ) {
210
210
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
211
228
PipeMemoryReaderPage * Page = Reader -> Pages ;
212
229
213
230
// Try to find an existing page with the requested bytes
@@ -249,8 +266,8 @@ const void *PipeMemoryReader_readBytes(void *Context, swift_addr_t Address,
249
266
void * Buf = malloc (Size );
250
267
memcpy (Buf , Page -> Data + Address - Page -> BaseAddress , Size );
251
268
* outFreeContext = NULL ;
252
-
253
269
return Buf ;
270
+ #endif
254
271
}
255
272
256
273
static
0 commit comments