Skip to content

Commit 263bbbb

Browse files
committed
RemoteMirror: Work around flaw in C interface
The CMemoryReader interface relies on a `GetStringLength` callback, which returns zero either if the address is invalid or if a valid zero-length string exists at the given address. We don't want to break ABI with RemoteMirror, but we can work around this by issuing a one-byte read at the address and confirming that a null terminator exists there.
1 parent 5d3ee68 commit 263bbbb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/swift/Remote/CMemoryReader.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ class CMemoryReader final : public MemoryReader {
6666

6767
bool readString(RemoteAddress address, std::string &dest) override {
6868
auto length = getStringLength(address);
69-
if (!length)
70-
return false;
69+
if (length == 0) {
70+
// A length of zero unfortunately might mean either that there's a zero
71+
// length string at the location we're trying to read, or that reading
72+
// failed. We can do a one-byte read to tell them apart.
73+
auto buf = readBytes(address, 1);
74+
return buf && ((const char*)buf.get())[0] == 0;
75+
}
7176

7277
auto Buf = readBytes(address, length);
7378
if (!Buf)

0 commit comments

Comments
 (0)