#ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
#define LLVM_EXECUTIONENGINE_ORC_EPCGENERICRTDYLDMEMORYMANAGER_H
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#define DEBUG_TYPE "orc"
namespace llvm {
namespace orc {
class EPCGenericRTDyldMemoryManager : public RuntimeDyld::MemoryManager {
public:
struct SymbolAddrs {
ExecutorAddr Instance;
ExecutorAddr Reserve;
ExecutorAddr Finalize;
ExecutorAddr Deallocate;
ExecutorAddr RegisterEHFrame;
ExecutorAddr DeregisterEHFrame;
};
static Expected<std::unique_ptr<EPCGenericRTDyldMemoryManager>>
CreateWithDefaultBootstrapSymbols(ExecutorProcessControl &EPC);
EPCGenericRTDyldMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs);
EPCGenericRTDyldMemoryManager(const EPCGenericRTDyldMemoryManager &) = delete;
EPCGenericRTDyldMemoryManager &
operator=(const EPCGenericRTDyldMemoryManager &) = delete;
EPCGenericRTDyldMemoryManager(EPCGenericRTDyldMemoryManager &&) = delete;
EPCGenericRTDyldMemoryManager &
operator=(EPCGenericRTDyldMemoryManager &&) = delete;
~EPCGenericRTDyldMemoryManager();
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) override;
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID, StringRef SectionName,
bool IsReadOnly) override;
void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
uintptr_t RODataSize, uint32_t RODataAlign,
uintptr_t RWDataSize,
uint32_t RWDataAlign) override;
bool needsToReserveAllocationSpace() override;
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override;
void deregisterEHFrames() override;
void notifyObjectLoaded(RuntimeDyld &Dyld,
const object::ObjectFile &Obj) override;
bool finalizeMemory(std::string *ErrMsg = nullptr) override;
private:
struct Alloc {
public:
Alloc(uint64_t Size, unsigned Align)
: Size(Size), Align(Align),
Contents(std::make_unique<uint8_t[]>(Size + Align - 1)) {}
uint64_t Size;
unsigned Align;
std::unique_ptr<uint8_t[]> Contents;
ExecutorAddr RemoteAddr;
};
struct AllocGroup {
AllocGroup() = default;
AllocGroup(const AllocGroup &) = delete;
AllocGroup &operator=(const AllocGroup &) = delete;
AllocGroup(AllocGroup &&) = default;
AllocGroup &operator=(AllocGroup &&) = default;
ExecutorAddrRange RemoteCode;
ExecutorAddrRange RemoteROData;
ExecutorAddrRange RemoteRWData;
std::vector<ExecutorAddrRange> UnfinalizedEHFrames;
std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
};
void mapAllocsToRemoteAddrs(RuntimeDyld &Dyld, std::vector<Alloc> &Allocs,
ExecutorAddr NextAddr);
ExecutorProcessControl &EPC;
SymbolAddrs SAs;
std::mutex M;
std::vector<AllocGroup> Unmapped;
std::vector<AllocGroup> Unfinalized;
std::vector<ExecutorAddr> FinalizedAllocs;
std::string ErrMsg;
};
} }
#undef DEBUG_TYPE
#endif