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/lldb-public.h"
14 #include "lldb/Core/DataBufferHeap.h"
15 #include "lldb/Core/UserID.h"
19 namespace lldb_private
22 //----------------------------------------------------------------------
23 /// @class IRMemoryMap IRMemoryMap.h "lldb/Expression/IRMemoryMap.h"
24 /// @brief Encapsulates memory that may exist in the process but must
25 /// also be available in the host process.
27 /// This class encapsulates a group of memory objects that must be readable
28 /// or writable from the host process regardless of whether the process
29 /// exists. This allows the IR interpreter as well as JITted code to access
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
34 /// exist, allocations still get made-up addresses. If an inferior appears
35 /// at some point, then those addresses need to be re-mapped.
36 //----------------------------------------------------------------------
40 IRMemoryMap (lldb::TargetSP target_sp);
43 enum AllocationPolicy {
44 eAllocationPolicyInvalid = 0, ///< It is an error for an allocation to have this policy.
45 eAllocationPolicyHostOnly, ///< This allocation was created in the host and will never make it into the process.
46 ///< It is an error to create other types of allocations while such allocations exist.
47 eAllocationPolicyMirror, ///< The intent is that this allocation exist both in the host and the process and have
48 ///< the same content in both.
49 eAllocationPolicyProcessOnly ///< The intent is that this allocation exist only in the process.
52 lldb::addr_t Malloc (size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, Error &error);
53 void Leak (lldb::addr_t process_address, Error &error);
54 void Free (lldb::addr_t process_address, Error &error);
56 void WriteMemory (lldb::addr_t process_address, const uint8_t *bytes, size_t size, Error &error);
57 void WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Error &error);
58 void WritePointerToMemory (lldb::addr_t process_address, lldb::addr_t address, Error &error);
59 void ReadMemory (uint8_t *bytes, lldb::addr_t process_address, size_t size, Error &error);
60 void ReadScalarFromMemory (Scalar &scalar, lldb::addr_t process_address, size_t size, Error &error);
61 void ReadPointerFromMemory (lldb::addr_t *address, lldb::addr_t process_address, Error &error);
63 void GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Error &error);
65 lldb::ByteOrder GetByteOrder();
66 uint32_t GetAddressByteSize();
68 // This function can return NULL.
69 ExecutionContextScope *GetBestExecutionContextScope();
72 // This function should only be used if you know you are using the JIT.
73 // Any other cases should use GetBestExecutionContextScope().
74 lldb::ProcessWP GetProcessWP ()
82 lldb::addr_t m_process_alloc; ///< The (unaligned) base for the remote allocation
83 lldb::addr_t m_process_start; ///< The base address of the allocation in the process
84 size_t m_size; ///< The size of the requested allocation
85 uint32_t m_permissions; ///< The access permissions on the memory in the process. In the host, the memory is always read/write.
86 uint8_t m_alignment; ///< The alignment of the requested allocation
87 DataBufferHeap m_data;
90 AllocationPolicy m_policy;
93 Allocation (lldb::addr_t process_alloc,
94 lldb::addr_t process_start,
98 AllocationPolicy m_policy);
101 m_process_alloc (LLDB_INVALID_ADDRESS),
102 m_process_start (LLDB_INVALID_ADDRESS),
107 m_policy (eAllocationPolicyInvalid),
113 lldb::ProcessWP m_process_wp;
114 lldb::TargetWP m_target_wp;
115 typedef std::map<lldb::addr_t, Allocation> AllocationMap;
116 AllocationMap m_allocations;
118 lldb::addr_t FindSpace (size_t size);
119 bool ContainsHostOnlyAllocations ();
120 AllocationMap::iterator FindAllocation (lldb::addr_t addr, size_t size);
121 bool IntersectsAllocation (lldb::addr_t addr, size_t size);