Skip to content

Commit 40e4010

Browse files
authored
Merge pull request #27418 from jckarter/reflection-symbolic-absolute-pointer
MetadataReader: Add an API for reading absolute pointers.
2 parents ea81fdc + 4012a20 commit 40e4010

File tree

6 files changed

+305
-95
lines changed

6 files changed

+305
-95
lines changed

include/swift/Basic/ExternalUnion.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -433,27 +433,27 @@ struct MembersHelper<> {
433433

434434
LLVM_ATTRIBUTE_ALWAYS_INLINE
435435
static void copyConstruct(void *self, int index, const void *other) {
436-
llvm_unreachable("bad index");
436+
assert(false && "bad index");
437437
}
438438

439439
LLVM_ATTRIBUTE_ALWAYS_INLINE
440440
static void moveConstruct(void *self, int index, void *other) {
441-
llvm_unreachable("bad index");
441+
assert(false && "bad index");
442442
}
443443

444444
LLVM_ATTRIBUTE_ALWAYS_INLINE
445445
static void copyAssignSame(int index, void *self, const void *other) {
446-
llvm_unreachable("bad index");
446+
assert(false && "bad index");
447447
}
448448

449449
LLVM_ATTRIBUTE_ALWAYS_INLINE
450450
static void moveAssignSame(int index, void *self, void *other) {
451-
llvm_unreachable("bad index");
451+
assert(false && "bad index");
452452
}
453453

454454
LLVM_ATTRIBUTE_ALWAYS_INLINE
455455
static void destruct(int index, void *self) {
456-
llvm_unreachable("bad index");
456+
assert(false && "bad index");
457457
}
458458
};
459459

include/swift/Reflection/ReflectionContext.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,17 @@ class ReflectionContext
608608
auto CDAddr = this->readCaptureDescriptorFromMetadata(*MetadataAddress);
609609
if (!CDAddr)
610610
return nullptr;
611+
if (!CDAddr->isResolved())
612+
return nullptr;
611613

612614
// FIXME: Non-generic SIL boxes also use the HeapLocalVariable metadata
613615
// kind, but with a null capture descriptor right now (see
614616
// FixedBoxTypeInfoBase::allocate).
615617
//
616618
// Non-generic SIL boxes share metadata among types with compatible
617619
// layout, but we need some way to get an outgoing pointer map for them.
618-
auto CD = getBuilder().getCaptureDescriptor(*CDAddr);
620+
auto CD = getBuilder().getCaptureDescriptor(
621+
CDAddr->getResolvedAddress().getAddressData());
619622
if (CD == nullptr)
620623
return nullptr;
621624

include/swift/Remote/MemoryReader.h

+29-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MemoryReader {
6969
/// NOTE: subclasses MUST override at least one of the readBytes functions. The default
7070
/// implementation calls through to the other one.
7171
virtual ReadBytesResult
72-
readBytes(RemoteAddress address, uint64_t size) {
72+
readBytes(RemoteAddress address, uint64_t size) {
7373
auto *Buf = malloc(size);
7474
ReadBytesResult Result(Buf, [](const void *ptr) {
7575
free(const_cast<void *>(ptr));
@@ -96,6 +96,34 @@ class MemoryReader {
9696
memcpy(dest, Ptr.get(), size);
9797
return true;
9898
}
99+
100+
/// Attempts to resolve a pointer value read from the given remote address.
101+
virtual RemoteAbsolutePointer resolvePointer(RemoteAddress address,
102+
uint64_t readValue) {
103+
// Default implementation returns the read value as is.
104+
return RemoteAbsolutePointer("", readValue);
105+
}
106+
107+
/// Attempt to read and resolve a pointer value at the given remote address.
108+
llvm::Optional<RemoteAbsolutePointer> readPointer(RemoteAddress address,
109+
unsigned pointerSize) {
110+
auto result = readBytes(address, pointerSize);
111+
if (!result)
112+
return llvm::None;
113+
114+
uint64_t pointerData;
115+
if (pointerSize == 4) {
116+
uint32_t theData;
117+
memcpy(&theData, result.get(), 4);
118+
pointerData = theData;
119+
} else if (pointerSize == 8) {
120+
memcpy(&pointerData, result.get(), 8);
121+
} else {
122+
return llvm::None;
123+
}
124+
125+
return resolvePointer(address, pointerData);
126+
}
99127

100128
virtual ~MemoryReader() = default;
101129
};

0 commit comments

Comments
 (0)