Skip to content

Commit d7a42a0

Browse files
authored
Merge pull request #85091 from augusto2112/remote-mirr-indirect-addr
[RemoteMirrors] Add hook for resolving indirect addresses
2 parents a4eb591 + 266adaf commit d7a42a0

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
@@ -192,6 +192,20 @@ class MemoryReader {
192192
return ReadObjResult<T>(reinterpret_cast<const T *>(ptr), deleter);
193193
}
194194

195+
/// Resolves an indirect address at the given relative offset.
196+
///
197+
/// \param address The base address which contains the relative offset.
198+
/// \param offset The offset read.
199+
/// \param directnessEncodedInOffset Whether the relative offset encodes the
200+
/// directness as the last bit. Note that this is not the offset passed in as
201+
/// a parameter, but whether the offset read at address would have the last
202+
/// bit set.
203+
virtual RemoteAddress
204+
resolveIndirectAddressAtOffset(RemoteAddress address, uint64_t offset,
205+
bool directnessEncodedInOffset) {
206+
return address + offset;
207+
}
208+
195209
/// Attempts to read 'size' bytes from the given address in the remote process.
196210
///
197211
/// 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
@@ -457,18 +457,20 @@ class MetadataReader {
457457
swift::Demangle::NodePointer {
458458
// Resolve the reference to a remote address.
459459
auto offsetInMangledName =
460-
(const char *)base - mangledName.getLocalBuffer();
461-
auto remoteAddress =
462-
mangledName.getRemoteAddress() + offsetInMangledName + offset;
460+
(const char *)base - mangledName.getLocalBuffer();
461+
auto offsetAddress = mangledName.getRemoteAddress() + offsetInMangledName;
463462

464463
RemoteAbsolutePointer resolved;
465464
if (directness == Directness::Indirect) {
465+
auto remoteAddress = Reader->resolveIndirectAddressAtOffset(
466+
offsetAddress, offset, /*directnessEncodedInOffset=*/false);
466467
if (auto indirectAddress = readPointer(remoteAddress)) {
467468
resolved = stripSignedPointer(*indirectAddress);
468469
} else {
469470
return nullptr;
470471
}
471472
} else {
473+
auto remoteAddress = offsetAddress + offset;
472474
resolved = Reader->getSymbol(remoteAddress);
473475
}
474476

@@ -2084,17 +2086,19 @@ class MetadataReader {
20842086

20852087
using SignedPointer = typename std::make_signed<StoredPointer>::type;
20862088

2087-
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
2088-
20892089
// Low bit set in the offset indicates that the offset leads to the absolute
20902090
// address in memory.
20912091
if (indirect) {
2092+
RemoteAddress resultAddress = Reader->resolveIndirectAddressAtOffset(
2093+
getAddress(fieldRef), (SignedPointer)offset,
2094+
/*directnessEncodedInOffset=*/true);
20922095
if (auto ptr = readPointer(resultAddress)) {
20932096
return stripSignedPointer(*ptr);
20942097
}
20952098
return std::nullopt;
20962099
}
20972100

2101+
RemoteAddress resultAddress = getAddress(fieldRef) + (SignedPointer)offset;
20982102
return RemoteAbsolutePointer(resultAddress);
20992103
}
21002104

0 commit comments

Comments
 (0)