Skip to content

Commit 36e0fd3

Browse files
committed
ReflectionContext: Keep read range properly-aligned.
If a Mach-O image got emitted in just the wrong way, the range of `__TEXT,__swift*` sections to read could end up starting at an unaligned address (because things like type refs have only one byte alignment), and this would cause the reflection context to read an unaligned chunk of the remote memory, causing alignment errors when addresses are mapped to the local copy. Keep the ranges at least 8-byte-aligned to stave off the alignment issues we might run into with any metadata structures, which are generally at most pointer aligned. Fixes rdar://problem/54556791
1 parent b8f4481 commit 36e0fd3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ class ReflectionContext
193193
}
194194
RangeStart = std::min(RangeStart, (uint64_t)S->addr + Slide);
195195
RangeEnd = std::max(RangeEnd, (uint64_t)(S->addr + S->size + Slide));
196+
// Keep the range rounded to 8 byte alignment on both ends so we don't
197+
// introduce misaligned pointers mapping between local and remote
198+
// address space.
199+
RangeStart = RangeStart & ~7;
200+
RangeEnd = RangeEnd + 7 & ~7;
196201
}
197202

198203
if (RangeStart == UINT64_MAX && RangeEnd == UINT64_MAX)

0 commit comments

Comments
 (0)