Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:53

0001 //===-- MemoryRegionInfo.h ---------------------------------------*- C++
0002 //-*-===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef LLDB_TARGET_MEMORYREGIONINFO_H
0011 #define LLDB_TARGET_MEMORYREGIONINFO_H
0012 
0013 #include <optional>
0014 #include <vector>
0015 
0016 #include "lldb/Utility/ConstString.h"
0017 #include "lldb/Utility/RangeMap.h"
0018 #include "llvm/Support/FormatProviders.h"
0019 
0020 namespace lldb_private {
0021 class MemoryRegionInfo {
0022 public:
0023   typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
0024 
0025   enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
0026 
0027   MemoryRegionInfo() = default;
0028   MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
0029                    OptionalBool execute, OptionalBool shared,
0030                    OptionalBool mapped, ConstString name, OptionalBool flash,
0031                    lldb::offset_t blocksize, OptionalBool memory_tagged,
0032                    OptionalBool stack_memory, OptionalBool shadow_stack)
0033       : m_range(range), m_read(read), m_write(write), m_execute(execute),
0034         m_shared(shared), m_mapped(mapped), m_name(name), m_flash(flash),
0035         m_blocksize(blocksize), m_memory_tagged(memory_tagged),
0036         m_is_stack_memory(stack_memory), m_is_shadow_stack(shadow_stack) {}
0037 
0038   RangeType &GetRange() { return m_range; }
0039 
0040   void Clear() { *this = MemoryRegionInfo(); }
0041 
0042   const RangeType &GetRange() const { return m_range; }
0043 
0044   OptionalBool GetReadable() const { return m_read; }
0045 
0046   OptionalBool GetWritable() const { return m_write; }
0047 
0048   OptionalBool GetExecutable() const { return m_execute; }
0049 
0050   OptionalBool GetShared() const { return m_shared; }
0051 
0052   OptionalBool GetMapped() const { return m_mapped; }
0053 
0054   ConstString GetName() const { return m_name; }
0055 
0056   OptionalBool GetMemoryTagged() const { return m_memory_tagged; }
0057 
0058   OptionalBool IsShadowStack() const { return m_is_shadow_stack; }
0059 
0060   void SetReadable(OptionalBool val) { m_read = val; }
0061 
0062   void SetWritable(OptionalBool val) { m_write = val; }
0063 
0064   void SetExecutable(OptionalBool val) { m_execute = val; }
0065 
0066   void SetShared(OptionalBool val) { m_shared = val; }
0067 
0068   void SetMapped(OptionalBool val) { m_mapped = val; }
0069 
0070   void SetName(const char *name) { m_name = ConstString(name); }
0071 
0072   OptionalBool GetFlash() const { return m_flash; }
0073 
0074   void SetFlash(OptionalBool val) { m_flash = val; }
0075 
0076   lldb::offset_t GetBlocksize() const { return m_blocksize; }
0077 
0078   void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
0079 
0080   void SetMemoryTagged(OptionalBool val) { m_memory_tagged = val; }
0081 
0082   void SetIsShadowStack(OptionalBool val) { m_is_shadow_stack = val; }
0083 
0084   // Get permissions as a uint32_t that is a mask of one or more bits from the
0085   // lldb::Permissions
0086   uint32_t GetLLDBPermissions() const {
0087     uint32_t permissions = 0;
0088     if (m_read == eYes)
0089       permissions |= lldb::ePermissionsReadable;
0090     if (m_write == eYes)
0091       permissions |= lldb::ePermissionsWritable;
0092     if (m_execute == eYes)
0093       permissions |= lldb::ePermissionsExecutable;
0094     return permissions;
0095   }
0096 
0097   // Set permissions from a uint32_t that contains one or more bits from the
0098   // lldb::Permissions
0099   void SetLLDBPermissions(uint32_t permissions) {
0100     m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
0101     m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
0102     m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
0103   }
0104 
0105   bool operator==(const MemoryRegionInfo &rhs) const {
0106     return m_range == rhs.m_range && m_read == rhs.m_read &&
0107            m_write == rhs.m_write && m_execute == rhs.m_execute &&
0108            m_shared == rhs.m_shared && m_mapped == rhs.m_mapped &&
0109            m_name == rhs.m_name && m_flash == rhs.m_flash &&
0110            m_blocksize == rhs.m_blocksize &&
0111            m_memory_tagged == rhs.m_memory_tagged &&
0112            m_pagesize == rhs.m_pagesize &&
0113            m_is_stack_memory == rhs.m_is_stack_memory &&
0114            m_is_shadow_stack == rhs.m_is_shadow_stack;
0115   }
0116 
0117   bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
0118 
0119   /// Get the target system's VM page size in bytes.
0120   /// \return
0121   ///     0 is returned if this information is unavailable.
0122   int GetPageSize() const { return m_pagesize; }
0123 
0124   /// Get a vector of target VM pages that are dirty -- that have been
0125   /// modified -- within this memory region.  This is an Optional return
0126   /// value; it will only be available if the remote stub was able to
0127   /// detail this.
0128   const std::optional<std::vector<lldb::addr_t>> &GetDirtyPageList() const {
0129     return m_dirty_pages;
0130   }
0131 
0132   OptionalBool IsStackMemory() const { return m_is_stack_memory; }
0133 
0134   void SetIsStackMemory(OptionalBool val) { m_is_stack_memory = val; }
0135 
0136   void SetPageSize(int pagesize) { m_pagesize = pagesize; }
0137 
0138   void SetDirtyPageList(std::vector<lldb::addr_t> pagelist) {
0139     if (m_dirty_pages)
0140       m_dirty_pages->clear();
0141     m_dirty_pages = std::move(pagelist);
0142   }
0143 
0144 protected:
0145   RangeType m_range;
0146   OptionalBool m_read = eDontKnow;
0147   OptionalBool m_write = eDontKnow;
0148   OptionalBool m_execute = eDontKnow;
0149   OptionalBool m_shared = eDontKnow;
0150   OptionalBool m_mapped = eDontKnow;
0151   ConstString m_name;
0152   OptionalBool m_flash = eDontKnow;
0153   lldb::offset_t m_blocksize = 0;
0154   OptionalBool m_memory_tagged = eDontKnow;
0155   OptionalBool m_is_stack_memory = eDontKnow;
0156   OptionalBool m_is_shadow_stack = eDontKnow;
0157   int m_pagesize = 0;
0158   std::optional<std::vector<lldb::addr_t>> m_dirty_pages;
0159 };
0160 
0161 inline bool operator<(const MemoryRegionInfo &lhs,
0162                       const MemoryRegionInfo &rhs) {
0163   return lhs.GetRange() < rhs.GetRange();
0164 }
0165 
0166 inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
0167   return lhs.GetRange().GetRangeBase() < rhs;
0168 }
0169 
0170 inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
0171   return lhs < rhs.GetRange().GetRangeBase();
0172 }
0173 
0174 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
0175                               const MemoryRegionInfo &Info);
0176 
0177 // Forward-declarable wrapper.
0178 class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
0179 public:
0180   using std::vector<lldb_private::MemoryRegionInfo>::vector;
0181 };
0182 
0183 } // namespace lldb_private
0184 
0185 namespace llvm {
0186 template <>
0187 /// If Options is empty, prints a textual representation of the value. If
0188 /// Options is a single character, it uses that character for the "yes" value,
0189 /// while "no" is printed as "-", and "don't know" as "?". This can be used to
0190 /// print the permissions in the traditional "rwx" form.
0191 struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
0192   static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
0193                      raw_ostream &OS, StringRef Options);
0194 };
0195 } // namespace llvm
0196 
0197 #endif // LLDB_TARGET_MEMORYREGIONINFO_H