summaryrefslogtreecommitdiffstats
path: root/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2017-11-09 06:31:33 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2017-11-09 06:31:33 +0000
commite3992c6328002659110f668f70cbba2c80e551fa (patch)
tree1b65adfb563e4c0b4c81d3190011395c2a592344 /llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
parent7a6e294a6c02b5670d1906331b7d8e923a6d92de (diff)
downloadbcm5719-llvm-e3992c6328002659110f668f70cbba2c80e551fa.tar.gz
bcm5719-llvm-e3992c6328002659110f668f70cbba2c80e551fa.zip
[SectionMemoryManager] Abstract out mmap, munmap, mprotect even more ; NFC
Summary: This will let ORC JIT clients plug in custom logic for the mmap, munmap and mprotect paths. Reviewers: loladiro, dblaikie Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D39300 llvm-svn: 317770
Diffstat (limited to 'llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h')
-rw-r--r--llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h75
1 files changed, 71 insertions, 4 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
index 3b2af11cdaf..d76e37113c6 100644
--- a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
+++ b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
@@ -40,9 +40,75 @@ namespace llvm {
/// directly. Clients of MCJIT should call MCJIT::finalizeObject.
class SectionMemoryManager : public RTDyldMemoryManager {
public:
- SectionMemoryManager() = default;
- SectionMemoryManager(const SectionMemoryManager&) = delete;
- void operator=(const SectionMemoryManager&) = delete;
+ /// This enum describes the various reasons to allocate pages from
+ /// allocateMappedMemory.
+ enum class AllocationPurpose {
+ Code,
+ ROData,
+ RWData,
+ };
+
+ /// Implementations of this interface are used by SectionMemoryManager to
+ /// request pages from the operating system.
+ class MemoryMapper {
+ public:
+ /// This method attempts to allocate \p NumBytes bytes of virtual memory for
+ /// \p Purpose. \p NearBlock may point to an existing allocation, in which
+ /// case an attempt is made to allocate more memory near the existing block.
+ /// The actual allocated address is not guaranteed to be near the requested
+ /// address. \p Flags is used to set the initial protection flags for the
+ /// block of the memory. \p EC [out] returns an object describing any error
+ /// that occurs.
+ ///
+ /// This method may allocate more than the number of bytes requested. The
+ /// actual number of bytes allocated is indicated in the returned
+ /// MemoryBlock.
+ ///
+ /// The start of the allocated block must be aligned with the system
+ /// allocation granularity (64K on Windows, page size on Linux). If the
+ /// address following \p NearBlock is not so aligned, it will be rounded up
+ /// to the next allocation granularity boundary.
+ ///
+ /// \r a non-null MemoryBlock if the function was successful, otherwise a
+ /// null MemoryBlock with \p EC describing the error.
+ virtual sys::MemoryBlock
+ allocateMappedMemory(AllocationPurpose Purpose, size_t NumBytes,
+ const sys::MemoryBlock *const NearBlock,
+ unsigned Flags, std::error_code &EC) = 0;
+
+ /// This method sets the protection flags for a block of memory to the state
+ /// specified by \p Flags. The behavior is not specified if the memory was
+ /// not allocated using the allocateMappedMemory method.
+ /// \p Block describes the memory block to be protected.
+ /// \p Flags specifies the new protection state to be assigned to the block.
+ ///
+ /// If \p Flags is MF_WRITE, the actual behavior varies with the operating
+ /// system (i.e. MF_READ | MF_WRITE on Windows) and the target architecture
+ /// (i.e. MF_WRITE -> MF_READ | MF_WRITE on i386).
+ ///
+ /// \r error_success if the function was successful, or an error_code
+ /// describing the failure if an error occurred.
+ virtual std::error_code protectMappedMemory(const sys::MemoryBlock &Block,
+ unsigned Flags) = 0;
+
+ /// This method releases a block of memory that was allocated with the
+ /// allocateMappedMemory method. It should not be used to release any memory
+ /// block allocated any other way.
+ /// \p Block describes the memory to be released.
+ ///
+ /// \r error_success if the function was successful, or an error_code
+ /// describing the failure if an error occurred.
+ virtual std::error_code releaseMappedMemory(sys::MemoryBlock &M) = 0;
+
+ virtual ~MemoryMapper();
+ };
+
+ /// Creates a SectionMemoryManager instance with \p MM as the associated
+ /// memory mapper. If \p MM is nullptr then a default memory mapper is used
+ /// that directly calls into the operating system.
+ SectionMemoryManager(MemoryMapper *MM = nullptr);
+ SectionMemoryManager(const SectionMemoryManager &) = delete;
+ void operator=(const SectionMemoryManager &) = delete;
~SectionMemoryManager() override;
/// \brief Allocates a memory block of (at least) the given size suitable for
@@ -110,7 +176,7 @@ private:
sys::MemoryBlock Near;
};
- uint8_t *allocateSection(MemoryGroup &MemGroup, uintptr_t Size,
+ uint8_t *allocateSection(AllocationPurpose Purpose, uintptr_t Size,
unsigned Alignment);
std::error_code applyMemoryGroupPermissions(MemoryGroup &MemGroup,
@@ -119,6 +185,7 @@ private:
MemoryGroup CodeMem;
MemoryGroup RWDataMem;
MemoryGroup RODataMem;
+ MemoryMapper &MMapper;
};
} // end namespace llvm
OpenPOWER on IntegriCloud