]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/include/llvm/ExecutionEngine/RTDyldMemoryManager.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / include / llvm / ExecutionEngine / RTDyldMemoryManager.h
1 //===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- C++ -*-===//
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 // Interface of the runtime dynamic memory manager base class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTIONENGINE_RT_DYLD_MEMORY_MANAGER_H
15 #define LLVM_EXECUTIONENGINE_RT_DYLD_MEMORY_MANAGER_H
16
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/CBindingWrapping.h"
19 #include "llvm/Support/Memory.h"
20 #include "llvm-c/ExecutionEngine.h"
21
22 namespace llvm {
23
24 class ExecutionEngine;
25 class ObjectImage;
26
27 // RuntimeDyld clients often want to handle the memory management of
28 // what gets placed where. For JIT clients, this is the subset of
29 // JITMemoryManager required for dynamic loading of binaries.
30 //
31 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
32 //        for the varying types of objects to be allocated.
33 class RTDyldMemoryManager {
34   RTDyldMemoryManager(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
35   void operator=(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
36 public:
37   RTDyldMemoryManager() {}
38   virtual ~RTDyldMemoryManager();
39
40   /// Allocate a memory block of (at least) the given size suitable for
41   /// executable code. The SectionID is a unique identifier assigned by the JIT
42   /// engine, and optionally recorded by the memory manager to access a loaded
43   /// section.
44   virtual uint8_t *allocateCodeSection(
45     uintptr_t Size, unsigned Alignment, unsigned SectionID,
46     StringRef SectionName) = 0;
47
48   /// Allocate a memory block of (at least) the given size suitable for data.
49   /// The SectionID is a unique identifier assigned by the JIT engine, and
50   /// optionally recorded by the memory manager to access a loaded section.
51   virtual uint8_t *allocateDataSection(
52     uintptr_t Size, unsigned Alignment, unsigned SectionID,
53     StringRef SectionName, bool IsReadOnly) = 0;
54
55   /// Register the EH frames with the runtime so that c++ exceptions work.
56   ///
57   /// \p Addr parameter provides the local address of the EH frame section
58   /// data, while \p LoadAddr provides the address of the data in the target
59   /// address space.  If the section has not been remapped (which will usually
60   /// be the case for local execution) these two values will be the same.
61   virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size);
62
63   virtual void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size);
64
65   /// This method returns the address of the specified function or variable.
66   /// It is used to resolve symbols during module linking.
67   virtual uint64_t getSymbolAddress(const std::string &Name);
68
69   /// This method returns the address of the specified function. As such it is
70   /// only useful for resolving library symbols, not code generated symbols.
71   ///
72   /// If \p AbortOnFailure is false and no function with the given name is
73   /// found, this function returns a null pointer. Otherwise, it prints a
74   /// message to stderr and aborts.
75   ///
76   /// This function is deprecated for memory managers to be used with
77   /// MCJIT or RuntimeDyld.  Use getSymbolAddress instead.
78   virtual void *getPointerToNamedFunction(const std::string &Name,
79                                           bool AbortOnFailure = true);
80
81   /// This method is called after an object has been loaded into memory but
82   /// before relocations are applied to the loaded sections.  The object load
83   /// may have been initiated by MCJIT to resolve an external symbol for another
84   /// object that is being finalized.  In that case, the object about which
85   /// the memory manager is being notified will be finalized immediately after
86   /// the memory manager returns from this call.
87   ///
88   /// Memory managers which are preparing code for execution in an external
89   /// address space can use this call to remap the section addresses for the
90   /// newly loaded object.
91   virtual void notifyObjectLoaded(ExecutionEngine *EE,
92                                   const ObjectImage *) {}
93
94   /// This method is called when object loading is complete and section page
95   /// permissions can be applied.  It is up to the memory manager implementation
96   /// to decide whether or not to act on this method.  The memory manager will
97   /// typically allocate all sections as read-write and then apply specific
98   /// permissions when this method is called.  Code sections cannot be executed
99   /// until this function has been called.  In addition, any cache coherency
100   /// operations needed to reliably use the memory are also performed.
101   ///
102   /// Returns true if an error occurred, false otherwise.
103   virtual bool finalizeMemory(std::string *ErrMsg = 0) = 0;
104 };
105
106 // Create wrappers for C Binding types (see CBindingWrapping.h).
107 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(
108     RTDyldMemoryManager, LLVMMCJITMemoryManagerRef)
109
110 } // namespace llvm
111
112 #endif // LLVM_EXECUTIONENGINE_RT_DYLD_MEMORY_MANAGER_H