Skip to content

Commit 49953ed

Browse files
Merge pull request #85195 from augusto2112/remote-mirr-indirect-addr-6.2
[RemoteMirrors] Add hook for resolving indirect addresses
2 parents 678ec6e + 98a0a3f commit 49953ed

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

include/swift/Remote/MemoryReader.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ class MemoryReader {
121121
return ReadObjResult<T>(reinterpret_cast<const T *>(ptr), deleter);
122122
}
123123

124+
/// Resolves an indirect address at the given relative offset.
125+
///
126+
/// \param address The base address which contains the relative offset.
127+
/// \param offset The offset read.
128+
/// \param directnessEncodedInOffset Whether the relative offset encodes the
129+
/// directness as the last bit. Note that this is not the offset passed in as
130+
/// a parameter, but whether the offset read at address would have the last
131+
/// bit set.
132+
virtual RemoteAddress
133+
resolveIndirectAddressAtOffset(RemoteAddress address, uint64_t offset,
134+
bool directnessEncodedInOffset) {
135+
return address + offset;
136+
}
137+
124138
/// Attempts to read 'size' bytes from the given address in the remote process.
125139
///
126140
/// Returns a pointer to the requested data and a function that must be called to

include/swift/Remote/MetadataReader.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,20 @@ class MetadataReader {
461461
swift::Demangle::NodePointer {
462462
// Resolve the reference to a remote address.
463463
auto offsetInMangledName =
464-
(const char *)base - mangledName.getLocalBuffer();
465-
auto remoteAddress =
466-
mangledName.getRemoteAddress() + offsetInMangledName + offset;
464+
(const char *)base - mangledName.getLocalBuffer();
465+
auto offsetAddress = mangledName.getRemoteAddress() + offsetInMangledName;
467466

468467
RemoteAbsolutePointer resolved;
469468
if (directness == Directness::Indirect) {
469+
auto remoteAddress = Reader->resolveIndirectAddressAtOffset(
470+
offsetAddress, offset, /*directnessEncodedInOffset=*/false);
470471
if (auto indirectAddress = readPointer(remoteAddress)) {
471472
resolved = stripSignedPointer(*indirectAddress);
472473
} else {
473474
return nullptr;
474475
}
475476
} else {
477+
auto remoteAddress = offsetAddress + offset;
476478
resolved = Reader->getSymbol(remoteAddress);
477479
}
478480

@@ -2078,17 +2080,19 @@ class MetadataReader {
20782080

20792081
using SignedPointer = typename std::make_signed<StoredPointer>::type;
20802082

2081-
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
2082-
20832083
// Low bit set in the offset indicates that the offset leads to the absolute
20842084
// address in memory.
20852085
if (indirect) {
2086+
RemoteAddress resultAddress = Reader->resolveIndirectAddressAtOffset(
2087+
getAddress(fieldRef), (SignedPointer)offset,
2088+
/*directnessEncodedInOffset=*/true);
20862089
if (auto ptr = readPointer(resultAddress)) {
20872090
return stripSignedPointer(*ptr);
20882091
}
20892092
return std::nullopt;
20902093
}
20912094

2095+
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
20922096
return RemoteAbsolutePointer(resultAddress);
20932097
}
20942098

0 commit comments

Comments
 (0)