]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/debugserver/source/MacOSX/MachVMRegion.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / tools / debugserver / source / MacOSX / MachVMRegion.h
1 //===-- MachVMRegion.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  Created by Greg Clayton on 6/26/07.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef __MachVMRegion_h__
15 #define __MachVMRegion_h__
16
17 #include "DNBDefs.h"
18 #include "DNBError.h"
19 #include <mach/mach.h>
20
21 class MachVMRegion {
22 public:
23   MachVMRegion(task_t task);
24   ~MachVMRegion();
25
26   void Clear();
27   mach_vm_address_t StartAddress() const { return m_start; }
28   mach_vm_address_t EndAddress() const { return m_start + m_size; }
29   mach_vm_size_t GetByteSize() const { return m_size; }
30   mach_vm_address_t BytesRemaining(mach_vm_address_t addr) const {
31     if (ContainsAddress(addr))
32       return m_size - (addr - m_start);
33     else
34       return 0;
35   }
36   bool ContainsAddress(mach_vm_address_t addr) const {
37     return addr >= StartAddress() && addr < EndAddress();
38   }
39
40   bool SetProtections(mach_vm_address_t addr, mach_vm_size_t size,
41                       vm_prot_t prot);
42   bool RestoreProtections();
43   bool GetRegionForAddress(nub_addr_t addr);
44
45   uint32_t GetDNBPermissions() const;
46
47   const DNBError &GetError() { return m_err; }
48
49 protected:
50 #if defined(VM_REGION_SUBMAP_SHORT_INFO_COUNT_64)
51   typedef vm_region_submap_short_info_data_64_t RegionInfo;
52   enum { kRegionInfoSize = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64 };
53 #else
54   typedef vm_region_submap_info_data_64_t RegionInfo;
55   enum { kRegionInfoSize = VM_REGION_SUBMAP_INFO_COUNT_64 };
56 #endif
57
58   task_t m_task;
59   mach_vm_address_t m_addr;
60   DNBError m_err;
61   mach_vm_address_t m_start;
62   mach_vm_size_t m_size;
63   natural_t m_depth;
64   RegionInfo m_data;
65   vm_prot_t m_curr_protection; // The current, possibly modified protections.
66                                // Original value is saved in m_data.protections.
67   mach_vm_address_t
68       m_protection_addr; // The start address at which protections were changed
69   mach_vm_size_t
70       m_protection_size; // The size of memory that had its protections changed
71 };
72
73 #endif // #ifndef __MachVMRegion_h__