Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.8 KiB

  1. //===-- RuntimeDyld.h - Run-time dynamic linker 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 for the runtime dynamic linker facilities of the MC-JIT.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
  14. #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/ExecutionEngine/ObjectBuffer.h"
  17. #include "llvm/Support/Memory.h"
  18. namespace llvm {
  19. class RuntimeDyldImpl;
  20. class ObjectImage;
  21. // RuntimeDyld clients often want to handle the memory management of
  22. // what gets placed where. For JIT clients, this is the subset of
  23. // JITMemoryManager required for dynamic loading of binaries.
  24. //
  25. // FIXME: As the RuntimeDyld fills out, additional routines will be needed
  26. // for the varying types of objects to be allocated.
  27. class RTDyldMemoryManager {
  28. RTDyldMemoryManager(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
  29. void operator=(const RTDyldMemoryManager&) LLVM_DELETED_FUNCTION;
  30. public:
  31. RTDyldMemoryManager() {}
  32. virtual ~RTDyldMemoryManager();
  33. /// Allocate a memory block of (at least) the given size suitable for
  34. /// executable code. The SectionID is a unique identifier assigned by the JIT
  35. /// engine, and optionally recorded by the memory manager to access a loaded
  36. /// section.
  37. virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
  38. unsigned SectionID) = 0;
  39. /// Allocate a memory block of (at least) the given size suitable for data.
  40. /// The SectionID is a unique identifier assigned by the JIT engine, and
  41. /// optionally recorded by the memory manager to access a loaded section.
  42. virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
  43. unsigned SectionID, bool IsReadOnly) = 0;
  44. /// This method returns the address of the specified function. As such it is
  45. /// only useful for resolving library symbols, not code generated symbols.
  46. ///
  47. /// If AbortOnFailure is false and no function with the given name is
  48. /// found, this function returns a null pointer. Otherwise, it prints a
  49. /// message to stderr and aborts.
  50. virtual void *getPointerToNamedFunction(const std::string &Name,
  51. bool AbortOnFailure = true) = 0;
  52. /// This method is called when object loading is complete and section page
  53. /// permissions can be applied. It is up to the memory manager implementation
  54. /// to decide whether or not to act on this method. The memory manager will
  55. /// typically allocate all sections as read-write and then apply specific
  56. /// permissions when this method is called.
  57. ///
  58. /// Returns true if an error occurred, false otherwise.
  59. virtual bool applyPermissions(std::string *ErrMsg = 0) = 0;
  60. };
  61. class RuntimeDyld {
  62. RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
  63. void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
  64. // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
  65. // interface.
  66. RuntimeDyldImpl *Dyld;
  67. RTDyldMemoryManager *MM;
  68. protected:
  69. // Change the address associated with a section when resolving relocations.
  70. // Any relocations already associated with the symbol will be re-resolved.
  71. void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
  72. public:
  73. RuntimeDyld(RTDyldMemoryManager *);
  74. ~RuntimeDyld();
  75. /// Prepare the object contained in the input buffer for execution.
  76. /// Ownership of the input buffer is transferred to the ObjectImage
  77. /// instance returned from this function if successful. In the case of load
  78. /// failure, the input buffer will be deleted.
  79. ObjectImage *loadObject(ObjectBuffer *InputBuffer);
  80. /// Get the address of our local copy of the symbol. This may or may not
  81. /// be the address used for relocation (clients can copy the data around
  82. /// and resolve relocatons based on where they put it).
  83. void *getSymbolAddress(StringRef Name);
  84. /// Get the address of the target copy of the symbol. This is the address
  85. /// used for relocation.
  86. uint64_t getSymbolLoadAddress(StringRef Name);
  87. /// Resolve the relocations for all symbols we currently know about.
  88. void resolveRelocations();
  89. /// Map a section to its target address space value.
  90. /// Map the address of a JIT section as returned from the memory manager
  91. /// to the address in the target process as the running code will see it.
  92. /// This is the address which will be used for relocation resolution.
  93. void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
  94. StringRef getErrorString();
  95. };
  96. } // end namespace llvm
  97. #endif