Skip to content

Commit ce0ef07

Browse files
authored
Merge pull request #15395 from mikeash/remotemirror-hide-reflection-sections
[RemoteMirrors] Interop header fixes and library lookup caching.
2 parents cc8e6e2 + 979b756 commit ce0ef07

File tree

6 files changed

+228
-106
lines changed

6 files changed

+228
-106
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ReflectionContext
7979
/// All buffers we need to keep around long term. This will automatically free them
8080
/// when this object is destroyed.
8181
std::vector<MemoryReader::ReadBytesResult> savedBuffers;
82-
std::vector<std::tuple<RemoteAddress, RemoteAddress>> dataSegments;
82+
std::vector<std::tuple<RemoteAddress, RemoteAddress>> imageRanges;
8383

8484
public:
8585
using super::getBuilder;
@@ -183,8 +183,7 @@ class ReflectionContext
183183
auto DataSegmentStart = DataSegment - reinterpret_cast<const uint8_t *>(Buf.get())
184184
+ ImageStart.getAddressData();
185185
auto DataSegmentEnd = DataSegmentStart + DataSize;
186-
dataSegments.push_back(std::make_tuple(RemoteAddress(DataSegmentStart),
187-
RemoteAddress(DataSegmentEnd)));
186+
imageRanges.push_back(std::make_tuple(ImageStart, RemoteAddress(DataSegmentEnd)));
188187
}
189188

190189
savedBuffers.push_back(std::move(Buf));
@@ -200,17 +199,21 @@ class ReflectionContext
200199
bool ownsObject(RemoteAddress ObjectAddress) {
201200
auto MetadataAddress = readMetadataFromInstance(ObjectAddress.getAddressData());
202201
if (!MetadataAddress)
203-
return 0;
204-
205-
for (auto Segment : dataSegments) {
206-
auto Start = std::get<0>(Segment);
207-
auto End = std::get<1>(Segment);
208-
if (Start.getAddressData() <= *MetadataAddress
209-
&& *MetadataAddress < End.getAddressData())
210-
return 1;
202+
return true;
203+
return ownsAddress(RemoteAddress(*MetadataAddress));
204+
}
205+
206+
/// Returns true if the address falls within a registered image.
207+
bool ownsAddress(RemoteAddress Address) {
208+
for (auto Range : imageRanges) {
209+
auto Start = std::get<0>(Range);
210+
auto End = std::get<1>(Range);
211+
if (Start.getAddressData() <= Address.getAddressData()
212+
&& Address.getAddressData() < End.getAddressData())
213+
return true;
211214
}
212215

213-
return 0;
216+
return false;
214217
}
215218

216219
/// Return a description of the layout of a class instance with the given

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ SWIFT_REMOTE_MIRROR_LINKAGE
110110
int
111111
swift_reflection_ownsObject(SwiftReflectionContextRef ContextRef, uintptr_t Object);
112112

113+
/// Returns whether the given address is within an image added to this
114+
/// library. Images must be added using swift_reflection_addImage, not
115+
/// swift_reflection_addReflectionInfo, for this function to work
116+
/// properly. If addReflectionInfo is used, the return value will always
117+
/// be false.
118+
SWIFT_REMOTE_MIRROR_LINKAGE
119+
int
120+
swift_reflection_ownsAddress(SwiftReflectionContextRef ContextRef, uintptr_t Address);
121+
113122
/// Returns the metadata pointer for a given object.
114123
SWIFT_REMOTE_MIRROR_LINKAGE
115124
uintptr_t

0 commit comments

Comments
 (0)