RecordingMemoryManager.h revision 5bac013d617ab3c03cdc9ee034e5efbb03adf3de
1//===- RecordingMemoryManager.h - LLI MCJIT recording memory manager ------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This memory manager allocates local storage and keeps a record of each 11// allocation. Iterators are provided for all data and code allocations. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef RECORDINGMEMORYMANAGER_H 16#define RECORDINGMEMORYMANAGER_H 17 18#include "llvm/ADT/SmallVector.h" 19#include "llvm/ExecutionEngine/JITMemoryManager.h" 20#include "llvm/Support/ErrorHandling.h" 21#include "llvm/Support/Memory.h" 22#include <utility> 23 24namespace llvm { 25 26class RecordingMemoryManager : public JITMemoryManager { 27public: 28 typedef std::pair<sys::MemoryBlock, unsigned> Allocation; 29 30private: 31 SmallVector<Allocation, 16> AllocatedDataMem; 32 SmallVector<Allocation, 16> AllocatedCodeMem; 33 34public: 35 RecordingMemoryManager() {} 36 virtual ~RecordingMemoryManager(); 37 38 typedef SmallVectorImpl<Allocation>::const_iterator const_data_iterator; 39 typedef SmallVectorImpl<Allocation>::const_iterator const_code_iterator; 40 41 const_data_iterator data_begin() const { return AllocatedDataMem.begin(); } 42 const_data_iterator data_end() const { return AllocatedDataMem.end(); } 43 const_code_iterator code_begin() const { return AllocatedCodeMem.begin(); } 44 const_code_iterator code_end() const { return AllocatedCodeMem.end(); } 45 46 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, 47 unsigned SectionID); 48 49 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, 50 unsigned SectionID, bool IsReadOnly); 51 52 void *getPointerToNamedFunction(const std::string &Name, 53 bool AbortOnFailure = true); 54 55 bool applyPermissions(std::string *ErrMsg) { return false; } 56 57 // The following obsolete JITMemoryManager calls are stubbed out for 58 // this model. 59 void setMemoryWritable(); 60 void setMemoryExecutable(); 61 void setPoisonMemory(bool poison); 62 void AllocateGOT(); 63 uint8_t *getGOTBase() const; 64 uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize); 65 uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, 66 unsigned Alignment); 67 void endFunctionBody(const Function *F, uint8_t *FunctionStart, 68 uint8_t *FunctionEnd); 69 uint8_t *allocateSpace(intptr_t Size, unsigned Alignment); 70 uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment); 71 void deallocateFunctionBody(void *Body); 72 uint8_t* startExceptionTable(const Function* F, uintptr_t &ActualSize); 73 void endExceptionTable(const Function *F, uint8_t *TableStart, 74 uint8_t *TableEnd, uint8_t* FrameRegister); 75 void deallocateExceptionTable(void *ET); 76 77}; 78 79} // end namespace llvm 80 81#endif 82