Skip to content

[RemoteMirrors] Interop header fixes and library lookup caching. #15395

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
Show file tree
Hide file tree
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
27 changes: 15 additions & 12 deletions include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ReflectionContext
/// All buffers we need to keep around long term. This will automatically free them
/// when this object is destroyed.
std::vector<MemoryReader::ReadBytesResult> savedBuffers;
std::vector<std::tuple<RemoteAddress, RemoteAddress>> dataSegments;
std::vector<std::tuple<RemoteAddress, RemoteAddress>> imageRanges;

public:
using super::getBuilder;
Expand Down Expand Up @@ -183,8 +183,7 @@ class ReflectionContext
auto DataSegmentStart = DataSegment - reinterpret_cast<const uint8_t *>(Buf.get())
+ ImageStart.getAddressData();
auto DataSegmentEnd = DataSegmentStart + DataSize;
dataSegments.push_back(std::make_tuple(RemoteAddress(DataSegmentStart),
RemoteAddress(DataSegmentEnd)));
imageRanges.push_back(std::make_tuple(ImageStart, RemoteAddress(DataSegmentEnd)));
}

savedBuffers.push_back(std::move(Buf));
Expand All @@ -200,17 +199,21 @@ class ReflectionContext
bool ownsObject(RemoteAddress ObjectAddress) {
auto MetadataAddress = readMetadataFromInstance(ObjectAddress.getAddressData());
if (!MetadataAddress)
return 0;

for (auto Segment : dataSegments) {
auto Start = std::get<0>(Segment);
auto End = std::get<1>(Segment);
if (Start.getAddressData() <= *MetadataAddress
&& *MetadataAddress < End.getAddressData())
return 1;
return true;
return ownsAddress(RemoteAddress(*MetadataAddress));
}

/// Returns true if the address falls within a registered image.
bool ownsAddress(RemoteAddress Address) {
for (auto Range : imageRanges) {
auto Start = std::get<0>(Range);
auto End = std::get<1>(Range);
if (Start.getAddressData() <= Address.getAddressData()
&& Address.getAddressData() < End.getAddressData())
return true;
}

return 0;
return false;
}

/// Return a description of the layout of a class instance with the given
Expand Down
9 changes: 9 additions & 0 deletions include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ SWIFT_REMOTE_MIRROR_LINKAGE
int
swift_reflection_ownsObject(SwiftReflectionContextRef ContextRef, uintptr_t Object);

/// Returns whether the given address is within an image added to this
/// library. Images must be added using swift_reflection_addImage, not
/// swift_reflection_addReflectionInfo, for this function to work
/// properly. If addReflectionInfo is used, the return value will always
/// be false.
SWIFT_REMOTE_MIRROR_LINKAGE
int
swift_reflection_ownsAddress(SwiftReflectionContextRef ContextRef, uintptr_t Address);

/// Returns the metadata pointer for a given object.
SWIFT_REMOTE_MIRROR_LINKAGE
uintptr_t
Expand Down
Loading