Skip to content

Commit 3d0ceb7

Browse files
authored
Merge pull request #82997 from augusto2112/change-remote-addr-6.2-3
[NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
2 parents 187b1ee + 79824f5 commit 3d0ceb7

File tree

18 files changed

+1047
-769
lines changed

18 files changed

+1047
-769
lines changed

include/swift/Basic/RelativePointer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@
132132
#ifndef SWIFT_BASIC_RELATIVEPOINTER_H
133133
#define SWIFT_BASIC_RELATIVEPOINTER_H
134134

135+
#include <cassert>
135136
#include <cstdint>
137+
#include <type_traits>
138+
#include <utility>
136139

137140
namespace swift {
138141

include/swift/Remote/CMemoryReader.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CMemoryReader final : public MemoryReader {
6969
// that we're likely failing to strip a signed pointer when reading from it.
7070
bool hasSignatureBits(RemoteAddress address) {
7171
return false;
72-
uint64_t addressData = address.getAddressData();
72+
uint64_t addressData = address.getRawAddress();
7373
return addressData != (addressData & getPtrauthMask());
7474
}
7575

@@ -89,13 +89,12 @@ class CMemoryReader final : public MemoryReader {
8989
RemoteAddress getSymbolAddress(const std::string &name) override {
9090
auto addressData = Impl.getSymbolAddress(Impl.reader_context,
9191
name.c_str(), name.size());
92-
return RemoteAddress(addressData);
92+
return RemoteAddress(addressData, RemoteAddress::DefaultAddressSpace);
9393
}
9494

9595
uint64_t getStringLength(RemoteAddress address) {
9696
assert(!hasSignatureBits(address));
97-
return Impl.getStringLength(Impl.reader_context,
98-
address.getAddressData());
97+
return Impl.getStringLength(Impl.reader_context, address.getRawAddress());
9998
}
10099

101100
bool readString(RemoteAddress address, std::string &dest) override {
@@ -120,7 +119,7 @@ class CMemoryReader final : public MemoryReader {
120119
ReadBytesResult readBytes(RemoteAddress address, uint64_t size) override {
121120
assert(!hasSignatureBits(address));
122121
void *FreeContext;
123-
auto Ptr = Impl.readBytes(Impl.reader_context, address.getAddressData(),
122+
auto Ptr = Impl.readBytes(Impl.reader_context, address.getRawAddress(),
124123
size, &FreeContext);
125124

126125
auto Free = Impl.free;
@@ -134,8 +133,7 @@ class CMemoryReader final : public MemoryReader {
134133
return ReadBytesResult(Ptr, freeLambda);
135134
}
136135
};
137-
138-
}
139-
}
136+
} // namespace remote
137+
} // namespace swift
140138

141139
#endif

include/swift/Remote/Failure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class Failure {
288288
case ArgStorageKind::Address: {
289289
result += '0';
290290
result += 'x';
291-
uint64_t address = Args[argIndex].Address.getAddressData();
291+
uint64_t address = Args[argIndex].Address.getRawAddress();
292292
unsigned max = ((address >> 32) != 0 ? 16 : 8);
293293
for (unsigned i = 0; i != max; ++i) {
294294
result += "0123456789abcdef"[(address >> (max - 1 - i) * 4) & 0xF];

include/swift/Remote/InProcessMemoryReader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class InProcessMemoryReader final : public MemoryReader {
105105
return ReadBytesResult(address.getLocalPointer<void>(), [](const void *) {});
106106
}
107107
};
108-
109-
}
110-
}
108+
109+
} // namespace remote
110+
} // namespace swift
111111

112112
#endif

include/swift/Remote/MemoryReader.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,31 @@ class MemoryReader {
5757
///
5858
/// Returns false if the operation failed.
5959
virtual bool readString(RemoteAddress address, std::string &dest) = 0;
60-
60+
61+
/// Attempts to read a remote address from the given address in the remote
62+
/// process.
63+
///
64+
/// Returns false if the operator failed.
65+
template <typename IntegerType>
66+
bool readRemoteAddress(RemoteAddress address, RemoteAddress &out) {
67+
IntegerType buf;
68+
if (!readInteger(address, &buf))
69+
return false;
70+
71+
out = RemoteAddress((uint64_t)buf, address.getAddressSpace());
72+
return true;
73+
}
74+
6175
/// Attempts to read an integer from the given address in the remote
6276
/// process.
6377
///
6478
/// Returns false if the operation failed.
6579
template <typename IntegerType>
6680
bool readInteger(RemoteAddress address, IntegerType *dest) {
81+
static_assert(!std::is_same<RemoteAddress, IntegerType>(),
82+
"RemoteAddress cannot be read in directly, use "
83+
"readRemoteAddress instead.");
84+
6785
return readBytes(address, reinterpret_cast<uint8_t*>(dest),
6886
sizeof(IntegerType));
6987
}
@@ -147,7 +165,8 @@ class MemoryReader {
147165
virtual RemoteAbsolutePointer resolvePointer(RemoteAddress address,
148166
uint64_t readValue) {
149167
// Default implementation returns the read value as is.
150-
return RemoteAbsolutePointer("", readValue);
168+
return RemoteAbsolutePointer(
169+
RemoteAddress(readValue, address.getAddressSpace()));
151170
}
152171

153172
/// Performs the inverse operation of \ref resolvePointer.
@@ -166,7 +185,7 @@ class MemoryReader {
166185
virtual RemoteAbsolutePointer getSymbol(RemoteAddress address) {
167186
if (auto symbol = resolvePointerAsSymbol(address))
168187
return *symbol;
169-
return RemoteAbsolutePointer("", address.getAddressData());
188+
return RemoteAbsolutePointer(address);
170189
}
171190

172191
/// Lookup a dynamic symbol name (ie dynamic loader binding) for the given
@@ -263,7 +282,7 @@ class MemoryReader {
263282
virtual ~MemoryReader() = default;
264283
};
265284

266-
} // end namespace reflection
285+
} // end namespace remote
267286
} // end namespace swift
268287

269288
#endif // SWIFT_REFLECTION_READER_H

0 commit comments

Comments
 (0)