Skip to content

Commit 2133870

Browse files
committed
[DRAFT][RemoteInspection] Replace StoredPointer with RemoteAddress
This patch is still in a draft stage.
1 parent 5eb85ac commit 2133870

File tree

16 files changed

+969
-751
lines changed

16 files changed

+969
-751
lines changed

include/swift/Basic/RelativePointer.h

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

135+
#include <cassert>
135136
#include <cstdint>
137+
#include <type_traits>
136138

137139
namespace swift {
138140

include/swift/Remote/CMemoryReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class CMemoryReader final : public MemoryReader {
6868
// Check to see if an address has bits outside the ptrauth mask. This suggests
6969
// that we're likely failing to strip a signed pointer when reading from it.
7070
bool hasSignatureBits(RemoteAddress address) {
71+
return false;
7172
uint64_t addressData = address.getAddressData();
7273
return addressData != (addressData & getPtrauthMask());
7374
}
@@ -88,7 +89,7 @@ class CMemoryReader final : public MemoryReader {
8889
RemoteAddress getSymbolAddress(const std::string &name) override {
8990
auto addressData = Impl.getSymbolAddress(Impl.reader_context,
9091
name.c_str(), name.size());
91-
return RemoteAddress(addressData);
92+
return RemoteAddress::makeAddress(addressData);
9293
}
9394

9495
uint64_t getStringLength(RemoteAddress address) {

include/swift/Remote/MemoryReader.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,20 @@ class MemoryReader {
5757
///
5858
/// Returns false if the operation failed.
5959
virtual bool readString(RemoteAddress address, std::string &dest) = 0;
60-
60+
61+
virtual bool readRemoteAddress(RemoteAddress address, RemoteAddress &out) {
62+
return readInteger(address, &out.getDataReference());
63+
}
6164
/// Attempts to read an integer from the given address in the remote
6265
/// process.
6366
///
6467
/// Returns false if the operation failed.
6568
template <typename IntegerType>
6669
bool readInteger(RemoteAddress address, IntegerType *dest) {
70+
static_assert(!std::is_same<RemoteAddress, IntegerType>(),
71+
"RemoteAddress cannot be read in directly, use "
72+
"readRemoteAddress instead.");
73+
6774
return readBytes(address, reinterpret_cast<uint8_t*>(dest),
6875
sizeof(IntegerType));
6976
}
@@ -147,7 +154,7 @@ class MemoryReader {
147154
virtual RemoteAbsolutePointer resolvePointer(RemoteAddress address,
148155
uint64_t readValue) {
149156
// Default implementation returns the read value as is.
150-
return RemoteAbsolutePointer("", readValue);
157+
return RemoteAbsolutePointer("", address.fromThis(readValue));
151158
}
152159

153160
/// Performs the inverse operation of \ref resolvePointer.
@@ -166,7 +173,7 @@ class MemoryReader {
166173
virtual RemoteAbsolutePointer getSymbol(RemoteAddress address) {
167174
if (auto symbol = resolvePointerAsSymbol(address))
168175
return *symbol;
169-
return RemoteAbsolutePointer("", address.getAddressData());
176+
return RemoteAbsolutePointer("", address);
170177
}
171178

172179
/// Lookup a dynamic symbol name (ie dynamic loader binding) for the given
@@ -263,7 +270,7 @@ class MemoryReader {
263270
virtual ~MemoryReader() = default;
264271
};
265272

266-
} // end namespace reflection
273+
} // end namespace remote
267274
} // end namespace swift
268275

269276
#endif // SWIFT_REFLECTION_READER_H

0 commit comments

Comments
 (0)