Skip to content

Add opaque context pointer to SwiftRemoteMirror C API Reader API #2299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions include/swift/Remote/CMemoryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,27 @@ class CMemoryReader final : public MemoryReader {
assert(this->Impl.getPointerSize && "No getPointerSize implementation");
assert(this->Impl.getStringLength && "No stringLength implementation");
assert(this->Impl.readBytes && "No readBytes implementation");
assert(this->Impl.getPointerSize() != 0 && "Invalid target pointer size");
assert(this->Impl.getPointerSize(this->Impl.reader_context) != 0 &&
"Invalid target pointer size");
}

uint8_t getPointerSize() override {
return Impl.getPointerSize();
return Impl.getPointerSize(Impl.reader_context);
}

uint8_t getSizeSize() override {
return Impl.getSizeSize();
return Impl.getSizeSize(Impl.reader_context);
}

RemoteAddress getSymbolAddress(const std::string &name) override {
auto addressData = Impl.getSymbolAddress(name.c_str(), name.size());
auto addressData = Impl.getSymbolAddress(Impl.reader_context,
name.c_str(), name.size());
return RemoteAddress(addressData);
}

uint64_t getStringLength(RemoteAddress address) {
return Impl.getStringLength(address.getAddressData());
return Impl.getStringLength(Impl.reader_context,
address.getAddressData());
}

bool readString(RemoteAddress address, std::string &dest) override {
Expand All @@ -68,7 +71,8 @@ class CMemoryReader final : public MemoryReader {
}

bool readBytes(RemoteAddress address, uint8_t *dest, uint64_t size) override {
return Impl.readBytes(address.getAddressData(), dest, size);
return Impl.readBytes(Impl.reader_context,
address.getAddressData(), dest, size);
}
};

Expand Down
18 changes: 13 additions & 5 deletions include/swift/SwiftRemoteMirror/MemoryReaderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ extern "C" {

typedef uint64_t addr_t;

typedef uint8_t (*PointerSizeFunction)();
typedef uint8_t (*SizeSizeFunction)();
typedef bool (*ReadBytesFunction)(addr_t address, uint8_t *dest, uint64_t size);
typedef uint64_t (*GetStringLengthFunction)(addr_t address);
typedef addr_t (*GetSymbolAddressFunction)(const char *name, uint64_t name_length);
typedef uint8_t (*PointerSizeFunction)(void *reader_context);
typedef uint8_t (*SizeSizeFunction)(void * reader_context);
typedef bool (*ReadBytesFunction)(void * reader_context, addr_t address,
uint8_t *dest, uint64_t size);
typedef uint64_t (*GetStringLengthFunction)(void * reader_context,
addr_t address);
typedef addr_t (*GetSymbolAddressFunction)(void * reader_context,
const char *name,
uint64_t name_length);

typedef struct MemoryReaderImpl {
/// An opaque context that the implementor can specify to
/// be passed to each of the APIs below.
void *reader_context;

/// Get the size in bytes of the target's pointer type.
PointerSizeFunction getPointerSize;

Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ using NativeReflectionContext
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>;

SwiftReflectionContextRef
swift_reflection_createReflectionContext(PointerSizeFunction getPointerSize,
swift_reflection_createReflectionContext(void *reader_context,
PointerSizeFunction getPointerSize,
SizeSizeFunction getSizeSize,
ReadBytesFunction readBytes,
GetStringLengthFunction getStringLength,
GetSymbolAddressFunction getSymbolAddress) {
MemoryReaderImpl ReaderImpl {
reader_context,
getPointerSize,
getSizeSize,
readBytes,
Expand Down