2013-10-04 00:49:38 +00:00
|
|
|
//===- RemoteMemoryManager.h - LLI MCJIT recording memory manager ------===//
|
2012-09-05 16:50:34 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This memory manager allocates local storage and keeps a record of each
|
|
|
|
// allocation. Iterators are provided for all data and code allocations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-10-04 00:49:38 +00:00
|
|
|
#ifndef REMOTEMEMORYMANAGER_H
|
|
|
|
#define REMOTEMEMORYMANAGER_H
|
2012-09-05 16:50:34 +00:00
|
|
|
|
2014-01-13 08:04:33 +00:00
|
|
|
#include "RemoteTarget.h"
|
2013-10-04 00:49:38 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-09-05 16:50:34 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITMemoryManager.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/Memory.h"
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2013-10-04 00:49:38 +00:00
|
|
|
class RemoteMemoryManager : public JITMemoryManager {
|
2012-09-05 16:50:34 +00:00
|
|
|
public:
|
2013-10-04 00:49:38 +00:00
|
|
|
// Notice that this structure takes ownership of the memory allocated.
|
|
|
|
struct Allocation {
|
2013-10-04 20:09:36 +00:00
|
|
|
Allocation() {}
|
2013-10-04 00:49:38 +00:00
|
|
|
Allocation(sys::MemoryBlock mb, unsigned a, bool code)
|
|
|
|
: MB(mb), Alignment(a), IsCode(code) {}
|
|
|
|
|
|
|
|
sys::MemoryBlock MB;
|
|
|
|
unsigned Alignment;
|
|
|
|
bool IsCode;
|
|
|
|
};
|
2012-09-05 16:50:34 +00:00
|
|
|
|
|
|
|
private:
|
2013-10-04 00:49:38 +00:00
|
|
|
// This vector contains Allocation objects for all sections which we have
|
|
|
|
// allocated. This vector effectively owns the memory associated with the
|
|
|
|
// allocations.
|
|
|
|
SmallVector<Allocation, 2> AllocatedSections;
|
|
|
|
|
|
|
|
// This vector contains pointers to Allocation objects for any sections we
|
|
|
|
// have allocated locally but have not yet remapped for the remote target.
|
|
|
|
// When we receive notification of a completed module load, we will map
|
|
|
|
// these sections into the remote target.
|
2013-10-04 20:09:36 +00:00
|
|
|
SmallVector<Allocation, 2> UnmappedSections;
|
2013-10-04 00:49:38 +00:00
|
|
|
|
|
|
|
// This map tracks the sections we have remapped for the remote target
|
|
|
|
// but have not yet copied to the target.
|
2013-10-04 20:09:36 +00:00
|
|
|
DenseMap<uint64_t, Allocation> MappedSections;
|
2012-09-05 16:50:34 +00:00
|
|
|
|
2013-02-25 23:00:19 +00:00
|
|
|
// FIXME: This is part of a work around to keep sections near one another
|
|
|
|
// when MCJIT performs relocations after code emission but before
|
|
|
|
// the generated code is moved to the remote target.
|
|
|
|
sys::MemoryBlock Near;
|
|
|
|
sys::MemoryBlock allocateSection(uintptr_t Size);
|
|
|
|
|
2013-10-04 00:49:38 +00:00
|
|
|
RemoteTarget *Target;
|
2012-09-05 16:50:34 +00:00
|
|
|
|
2013-10-04 00:49:38 +00:00
|
|
|
public:
|
2014-04-28 04:05:08 +00:00
|
|
|
RemoteMemoryManager() : Target(nullptr) {}
|
2013-10-04 00:49:38 +00:00
|
|
|
virtual ~RemoteMemoryManager();
|
2012-09-05 16:50:34 +00:00
|
|
|
|
|
|
|
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
|
2014-03-08 08:27:28 +00:00
|
|
|
unsigned SectionID,
|
|
|
|
StringRef SectionName) override;
|
2012-09-05 16:50:34 +00:00
|
|
|
|
|
|
|
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
|
2013-10-02 00:59:25 +00:00
|
|
|
unsigned SectionID, StringRef SectionName,
|
2014-03-08 08:27:28 +00:00
|
|
|
bool IsReadOnly) override;
|
2012-09-05 16:50:34 +00:00
|
|
|
|
2013-10-11 21:25:48 +00:00
|
|
|
// For now, remote symbol resolution is not support in lli. The MCJIT
|
|
|
|
// interface does support this, but clients must provide their own
|
|
|
|
// mechanism for finding remote symbol addresses. MCJIT will resolve
|
|
|
|
// symbols from Modules it contains.
|
2014-03-08 08:27:28 +00:00
|
|
|
uint64_t getSymbolAddress(const std::string &Name) override { return 0; }
|
2012-11-15 23:50:01 +00:00
|
|
|
|
2014-03-08 08:27:28 +00:00
|
|
|
void notifyObjectLoaded(ExecutionEngine *EE, const ObjectImage *Obj) override;
|
2013-10-04 00:49:38 +00:00
|
|
|
|
2014-03-08 08:27:28 +00:00
|
|
|
bool finalizeMemory(std::string *ErrMsg) override;
|
2013-10-04 00:49:38 +00:00
|
|
|
|
2013-10-11 21:25:48 +00:00
|
|
|
// For now, remote EH frame registration isn't supported. Remote symbol
|
|
|
|
// resolution is a prerequisite to supporting remote EH frame registration.
|
2014-03-08 08:27:28 +00:00
|
|
|
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
|
|
|
|
size_t Size) override {}
|
|
|
|
void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr,
|
|
|
|
size_t Size) override {}
|
2013-10-11 21:25:48 +00:00
|
|
|
|
2013-10-04 00:49:38 +00:00
|
|
|
// This is a non-interface function used by lli
|
|
|
|
void setRemoteTarget(RemoteTarget *T) { Target = T; }
|
2012-11-15 23:50:01 +00:00
|
|
|
|
2012-09-05 16:50:34 +00:00
|
|
|
// The following obsolete JITMemoryManager calls are stubbed out for
|
|
|
|
// this model.
|
2014-03-08 08:27:28 +00:00
|
|
|
void setMemoryWritable() override;
|
|
|
|
void setMemoryExecutable() override;
|
|
|
|
void setPoisonMemory(bool poison) override;
|
|
|
|
void AllocateGOT() override;
|
|
|
|
uint8_t *getGOTBase() const override;
|
|
|
|
uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize) override;
|
2012-09-05 16:50:34 +00:00
|
|
|
uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
|
2014-03-08 08:27:28 +00:00
|
|
|
unsigned Alignment) override;
|
2012-09-05 16:50:34 +00:00
|
|
|
void endFunctionBody(const Function *F, uint8_t *FunctionStart,
|
2014-03-08 08:27:28 +00:00
|
|
|
uint8_t *FunctionEnd) override;
|
|
|
|
uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) override;
|
|
|
|
uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) override;
|
|
|
|
void deallocateFunctionBody(void *Body) override;
|
2012-09-05 16:50:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|