1 //===- RecordingMemoryManager.cpp - Recording memory manager --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This memory manager allocates local storage and keeps a record of each
11 // allocation. Iterators are provided for all data and code allocations.
13 //===----------------------------------------------------------------------===//
15 #include "RecordingMemoryManager.h"
18 RecordingMemoryManager::~RecordingMemoryManager() {
19 for (SmallVectorImpl<Allocation>::iterator
20 I = AllocatedCodeMem.begin(), E = AllocatedCodeMem.end();
22 free(I->first.base());
23 for (SmallVectorImpl<Allocation>::iterator
24 I = AllocatedDataMem.begin(), E = AllocatedDataMem.end();
26 free(I->first.base());
29 uint8_t *RecordingMemoryManager::
30 allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) {
31 // The recording memory manager is just a local copy of the remote target.
32 // The alignment requirement is just stored here for later use. Regular
33 // heap storage is sufficient here.
34 void *Addr = malloc(Size);
35 assert(Addr && "malloc() failure!");
36 sys::MemoryBlock Block(Addr, Size);
37 AllocatedCodeMem.push_back(Allocation(Block, Alignment));
38 return (uint8_t*)Addr;
41 uint8_t *RecordingMemoryManager::
42 allocateDataSection(uintptr_t Size, unsigned Alignment,
43 unsigned SectionID, bool IsReadOnly) {
44 // The recording memory manager is just a local copy of the remote target.
45 // The alignment requirement is just stored here for later use. Regular
46 // heap storage is sufficient here.
47 void *Addr = malloc(Size);
48 assert(Addr && "malloc() failure!");
49 sys::MemoryBlock Block(Addr, Size);
50 AllocatedDataMem.push_back(Allocation(Block, Alignment));
51 return (uint8_t*)Addr;
53 void RecordingMemoryManager::setMemoryWritable() { llvm_unreachable("Unexpected!"); }
54 void RecordingMemoryManager::setMemoryExecutable() { llvm_unreachable("Unexpected!"); }
55 void RecordingMemoryManager::setPoisonMemory(bool poison) { llvm_unreachable("Unexpected!"); }
56 void RecordingMemoryManager::AllocateGOT() { llvm_unreachable("Unexpected!"); }
57 uint8_t *RecordingMemoryManager::getGOTBase() const {
58 llvm_unreachable("Unexpected!");
61 uint8_t *RecordingMemoryManager::startFunctionBody(const Function *F, uintptr_t &ActualSize){
62 llvm_unreachable("Unexpected!");
65 uint8_t *RecordingMemoryManager::allocateStub(const GlobalValue* F, unsigned StubSize,
67 llvm_unreachable("Unexpected!");
70 void RecordingMemoryManager::endFunctionBody(const Function *F, uint8_t *FunctionStart,
71 uint8_t *FunctionEnd) {
72 llvm_unreachable("Unexpected!");
74 uint8_t *RecordingMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment) {
75 llvm_unreachable("Unexpected!");
78 uint8_t *RecordingMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment) {
79 llvm_unreachable("Unexpected!");
82 void RecordingMemoryManager::deallocateFunctionBody(void *Body) {
83 llvm_unreachable("Unexpected!");
85 uint8_t* RecordingMemoryManager::startExceptionTable(const Function* F, uintptr_t &ActualSize) {
86 llvm_unreachable("Unexpected!");
89 void RecordingMemoryManager::endExceptionTable(const Function *F, uint8_t *TableStart,
90 uint8_t *TableEnd, uint8_t* FrameRegister) {
91 llvm_unreachable("Unexpected!");
93 void RecordingMemoryManager::deallocateExceptionTable(void *ET) {
94 llvm_unreachable("Unexpected!");
97 static int jit_noop() {
101 void *RecordingMemoryManager::getPointerToNamedFunction(const std::string &Name,
102 bool AbortOnFailure) {
103 // We should not invoke parent's ctors/dtors from generated main()!
104 // On Mingw and Cygwin, the symbol __main is resolved to
105 // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
106 // (and register wrong callee's dtors with atexit(3)).
107 // We expect ExecutionEngine::runStaticConstructorsDestructors()
108 // is called before ExecutionEngine::runFunctionAsMain() is called.
109 if (Name == "__main") return (void*)(intptr_t)&jit_noop;