1061da546Spatrick //===-- MachVMRegion.h ------------------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick // 9061da546Spatrick // Created by Greg Clayton on 6/26/07. 10061da546Spatrick // 11061da546Spatrick //===----------------------------------------------------------------------===// 12061da546Spatrick 13dda28197Spatrick #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHVMREGION_H 14dda28197Spatrick #define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHVMREGION_H 15061da546Spatrick 16061da546Spatrick #include "DNBDefs.h" 17061da546Spatrick #include "DNBError.h" 18061da546Spatrick #include <mach/mach.h> 19061da546Spatrick 20061da546Spatrick class MachVMRegion { 21061da546Spatrick public: 22061da546Spatrick MachVMRegion(task_t task); 23061da546Spatrick ~MachVMRegion(); 24061da546Spatrick 25061da546Spatrick void Clear(); StartAddress()26061da546Spatrick mach_vm_address_t StartAddress() const { return m_start; } EndAddress()27061da546Spatrick mach_vm_address_t EndAddress() const { return m_start + m_size; } GetByteSize()28061da546Spatrick mach_vm_size_t GetByteSize() const { return m_size; } BytesRemaining(mach_vm_address_t addr)29061da546Spatrick mach_vm_address_t BytesRemaining(mach_vm_address_t addr) const { 30061da546Spatrick if (ContainsAddress(addr)) 31061da546Spatrick return m_size - (addr - m_start); 32061da546Spatrick else 33061da546Spatrick return 0; 34061da546Spatrick } ContainsAddress(mach_vm_address_t addr)35061da546Spatrick bool ContainsAddress(mach_vm_address_t addr) const { 36061da546Spatrick return addr >= StartAddress() && addr < EndAddress(); 37061da546Spatrick } 38061da546Spatrick 39061da546Spatrick bool SetProtections(mach_vm_address_t addr, mach_vm_size_t size, 40061da546Spatrick vm_prot_t prot); 41061da546Spatrick bool RestoreProtections(); 42061da546Spatrick bool GetRegionForAddress(nub_addr_t addr); 43*f6aab3d8Srobert std::vector<std::string> GetMemoryTypes() const; 44061da546Spatrick 45061da546Spatrick uint32_t GetDNBPermissions() const; 46061da546Spatrick GetError()47061da546Spatrick const DNBError &GetError() { return m_err; } 48061da546Spatrick 49061da546Spatrick protected: 50061da546Spatrick #if defined(VM_REGION_SUBMAP_SHORT_INFO_COUNT_64) 51061da546Spatrick typedef vm_region_submap_short_info_data_64_t RegionInfo; 52061da546Spatrick enum { kRegionInfoSize = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64 }; 53061da546Spatrick #else 54061da546Spatrick typedef vm_region_submap_info_data_64_t RegionInfo; 55061da546Spatrick enum { kRegionInfoSize = VM_REGION_SUBMAP_INFO_COUNT_64 }; 56061da546Spatrick #endif 57061da546Spatrick 58061da546Spatrick task_t m_task; 59061da546Spatrick mach_vm_address_t m_addr; 60061da546Spatrick DNBError m_err; 61061da546Spatrick mach_vm_address_t m_start; 62061da546Spatrick mach_vm_size_t m_size; 63061da546Spatrick natural_t m_depth; 64061da546Spatrick RegionInfo m_data; 65061da546Spatrick vm_prot_t m_curr_protection; // The current, possibly modified protections. 66061da546Spatrick // Original value is saved in m_data.protections. 67061da546Spatrick mach_vm_address_t 68061da546Spatrick m_protection_addr; // The start address at which protections were changed 69061da546Spatrick mach_vm_size_t 70061da546Spatrick m_protection_size; // The size of memory that had its protections changed 71061da546Spatrick }; 72061da546Spatrick 73dda28197Spatrick #endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHVMREGION_H 74