SectionMemoryManager.hpp
1 #pragma once
2 
3 #include <llvm/ExecutionEngine/SectionMemoryManager.h>
4 
5 #if LLVM_VERSION_MAJOR < 16
6 namespace llvm_helper {
7  using Align = uint32_t;
8 }
9 #else
10 namespace llvm_helper {
11  using Align = llvm::Align;
12 }
13 #endif
14 class SingleSectionMemoryManager : public llvm::SectionMemoryManager
15 {
16  struct Block
17  {
18  uint8_t *Addr = nullptr, *End = nullptr;
19  void Reset(uint8_t* Ptr, uintptr_t Size);
20  uint8_t* Next(uintptr_t Size, unsigned Alignment);
21  };
22  Block Code, ROData, RWData;
23 
24 public:
25  uint8_t* allocateCodeSection(
26  uintptr_t Size, unsigned Align, unsigned ID, llvm::StringRef Name) final;
27 
28  uint8_t* allocateDataSection(
29  uintptr_t Size, unsigned Align, unsigned ID, llvm::StringRef Name, bool RO) final;
30 
31  void reserveAllocationSpace(
32  uintptr_t CodeSize, llvm_helper::Align CodeAlign, uintptr_t ROSize, llvm_helper::Align ROAlign,
33  uintptr_t RWSize, llvm_helper::Align RWAlign) final;
34 
35  bool needsToReserveAllocationSpace() override { return true; }
36 
37  using llvm::SectionMemoryManager::EHFrameInfos;
38 
40 
41  void deregisterEHFrames() override;
42 
43  bool finalizeMemory(std::string* ErrMsg) override;
44 
45 private:
46  uintptr_t ImageBase = 0;
47 };
Definition: SectionMemoryManager.hpp:15