mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
//===- InProcessMemoryReader.h - Access to local memory ---------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file declares an abstract interface for working with remote memory.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_REMOTE_INPROCESSMEMORYREADER_H
|
|
#define SWIFT_REMOTE_INPROCESSMEMORYREADER_H
|
|
|
|
#include "swift/Remote/MemoryReader.h"
|
|
|
|
#include <memory>
|
|
#include <dlfcn.h>
|
|
|
|
namespace swift {
|
|
namespace remote {
|
|
|
|
/// An implementation of MemoryReader which simply reads from the current
|
|
/// address space.
|
|
class InProcessMemoryReader final : public MemoryReader {
|
|
uint8_t getPointerSize() override {
|
|
return sizeof(uintptr_t);
|
|
}
|
|
|
|
uint8_t getSizeSize() override {
|
|
return sizeof(size_t);
|
|
}
|
|
|
|
RemoteAddress getSymbolAddress(const std::string &name) override {
|
|
auto pointer = dlsym(RTLD_DEFAULT, name.c_str());
|
|
return RemoteAddress(pointer);
|
|
}
|
|
|
|
bool readString(RemoteAddress address, std::string &dest) override {
|
|
dest = address.getLocalPointer<char>();
|
|
return true;
|
|
}
|
|
|
|
bool readBytes(RemoteAddress address, uint8_t *dest, uint64_t size) override {
|
|
std::memcpy(dest, address.getLocalPointer<void>(), (size_t) size);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
}
|
|
}
|
|
|
|
#endif |