1 //===-- IRExecutionUnit.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_IRMemoryMap_h_
11 #define lldb_IRMemoryMap_h_
13 #include "lldb/Utility/DataBufferHeap.h"
14 #include "lldb/Utility/UserID.h"
15 #include "lldb/lldb-public.h"
19 namespace lldb_private {
21 //----------------------------------------------------------------------
22 /// @class IRMemoryMap IRMemoryMap.h "lldb/Expression/IRMemoryMap.h"
23 /// Encapsulates memory that may exist in the process but must
24 /// also be available in the host process.
26 /// This class encapsulates a group of memory objects that must be readable or
27 /// writable from the host process regardless of whether the process exists.
28 /// This allows the IR interpreter as well as JITted code to access the same
29 /// memory. All allocations made by this class are represented as disjoint
32 /// Point queries against this group of memory objects can be made by the
33 /// address in the tar at which they reside. If the inferior does not exist,
34 /// allocations still get made-up addresses. If an inferior appears at some
35 /// point, then those addresses need to be re-mapped.
36 //----------------------------------------------------------------------
39 IRMemoryMap(lldb::TargetSP target_sp);
42 enum AllocationPolicy {
43 eAllocationPolicyInvalid =
44 0, ///< It is an error for an allocation to have this policy.
45 eAllocationPolicyHostOnly, ///< This allocation was created in the host and
46 ///will never make it into the process.
47 ///< It is an error to create other types of allocations while such
49 eAllocationPolicyMirror, ///< The intent is that this allocation exist both
50 ///in the host and the process and have
51 ///< the same content in both.
52 eAllocationPolicyProcessOnly ///< The intent is that this allocation exist
53 ///only in the process.
56 lldb::addr_t Malloc(size_t size, uint8_t alignment, uint32_t permissions,
57 AllocationPolicy policy, bool zero_memory, Status &error);
58 void Leak(lldb::addr_t process_address, Status &error);
59 void Free(lldb::addr_t process_address, Status &error);
61 void WriteMemory(lldb::addr_t process_address, const uint8_t *bytes,
62 size_t size, Status &error);
63 void WriteScalarToMemory(lldb::addr_t process_address, Scalar &scalar,
64 size_t size, Status &error);
65 void WritePointerToMemory(lldb::addr_t process_address, lldb::addr_t address,
67 void ReadMemory(uint8_t *bytes, lldb::addr_t process_address, size_t size,
69 void ReadScalarFromMemory(Scalar &scalar, lldb::addr_t process_address,
70 size_t size, Status &error);
71 void ReadPointerFromMemory(lldb::addr_t *address,
72 lldb::addr_t process_address, Status &error);
73 bool GetAllocSize(lldb::addr_t address, size_t &size);
74 void GetMemoryData(DataExtractor &extractor, lldb::addr_t process_address,
75 size_t size, Status &error);
77 lldb::ByteOrder GetByteOrder();
78 uint32_t GetAddressByteSize();
80 // This function can return NULL.
81 ExecutionContextScope *GetBestExecutionContextScope() const;
83 lldb::TargetSP GetTarget() { return m_target_wp.lock(); }
86 // This function should only be used if you know you are using the JIT. Any
87 // other cases should use GetBestExecutionContextScope().
89 lldb::ProcessWP &GetProcessWP() { return m_process_wp; }
94 m_process_alloc; ///< The (unaligned) base for the remote allocation
96 m_process_start; ///< The base address of the allocation in the process
97 size_t m_size; ///< The size of the requested allocation
98 uint32_t m_permissions; ///< The access permissions on the memory in the
99 ///process. In the host, the memory is always
101 uint8_t m_alignment; ///< The alignment of the requested allocation
102 DataBufferHeap m_data;
105 AllocationPolicy m_policy;
109 Allocation(lldb::addr_t process_alloc, lldb::addr_t process_start,
110 size_t size, uint32_t permissions, uint8_t alignment,
111 AllocationPolicy m_policy);
114 : m_process_alloc(LLDB_INVALID_ADDRESS),
115 m_process_start(LLDB_INVALID_ADDRESS), m_size(0), m_permissions(0),
116 m_alignment(0), m_data(), m_policy(eAllocationPolicyInvalid),
120 lldb::ProcessWP m_process_wp;
121 lldb::TargetWP m_target_wp;
122 typedef std::map<lldb::addr_t, Allocation> AllocationMap;
123 AllocationMap m_allocations;
125 lldb::addr_t FindSpace(size_t size);
126 bool ContainsHostOnlyAllocations();
127 AllocationMap::iterator FindAllocation(lldb::addr_t addr, size_t size);
129 // Returns true if the given allocation intersects any allocation in the
131 bool IntersectsAllocation(lldb::addr_t addr, size_t size) const;
133 // Returns true if the two given allocations intersect each other.
134 static bool AllocationsIntersect(lldb::addr_t addr1, size_t size1,
135 lldb::addr_t addr2, size_t size2);