LLVM  10.0.0svn
JITLinkMemoryManager.h
Go to the documentation of this file.
1 //===-- JITLinkMemoryManager.h - JITLink mem manager interface --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Contains the JITLinkMemoryManager interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
15 
16 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/Support/Error.h"
19 #include "llvm/Support/Memory.h"
20 #include <cstdint>
21 
22 namespace llvm {
23 namespace jitlink {
24 
25 /// Manages allocations of JIT memory.
26 ///
27 /// Instances of this class may be accessed concurrently from multiple threads
28 /// and their implemetations should include any necessary synchronization.
30 public:
32 
34  public:
35  SegmentRequest() = default;
36  SegmentRequest(size_t ContentSize, unsigned ContentAlign,
37  uint64_t ZeroFillSize, unsigned ZeroFillAlign)
38  : ContentSize(ContentSize), ZeroFillSize(ZeroFillSize),
39  ContentAlign(ContentAlign), ZeroFillAlign(ZeroFillAlign) {}
40  size_t getContentSize() const { return ContentSize; }
41  unsigned getContentAlignment() const { return ContentAlign; }
42  uint64_t getZeroFillSize() const { return ZeroFillSize; }
43  unsigned getZeroFillAlignment() const { return ZeroFillAlign; }
44 
45  private:
46  size_t ContentSize = 0;
47  uint64_t ZeroFillSize = 0;
48  unsigned ContentAlign = 0;
49  unsigned ZeroFillAlign = 0;
50  };
51 
53 
54  /// Represents an allocation created by the memory manager.
55  ///
56  /// An allocation object is responsible for allocating and owning jit-linker
57  /// working and target memory, and for transfering from working to target
58  /// memory.
59  ///
60  class Allocation {
61  public:
62  using FinalizeContinuation = std::function<void(Error)>;
63 
64  virtual ~Allocation();
65 
66  /// Should return the address of linker working memory for the segment with
67  /// the given protection flags.
68  virtual MutableArrayRef<char> getWorkingMemory(ProtectionFlags Seg) = 0;
69 
70  /// Should return the final address in the target process where the segment
71  /// will reside.
72  virtual JITTargetAddress getTargetMemory(ProtectionFlags Seg) = 0;
73 
74  /// Should transfer from working memory to target memory, and release
75  /// working memory.
76  virtual void finalizeAsync(FinalizeContinuation OnFinalize) = 0;
77 
78  /// Should deallocate target memory.
79  virtual Error deallocate() = 0;
80  };
81 
82  virtual ~JITLinkMemoryManager();
83 
84  /// Create an Allocation object.
86  allocate(const SegmentsRequestMap &Request) = 0;
87 };
88 
89 /// A JITLinkMemoryManager that allocates in-process memory.
91 public:
93  allocate(const SegmentsRequestMap &Request) override;
94 };
95 
96 } // end namespace jitlink
97 } // end namespace llvm
98 
99 #endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
uint64_t JITTargetAddress
Represents an address in the target process&#39;s address space.
Definition: JITSymbol.h:40
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:290
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157