MachVMRegion.h revision 1308a9555ad586ff03c8f97bcfe7f3212d06bc86
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
21class MachVMRegion
22{
23public:
24    MachVMRegion(task_t task);
25    ~MachVMRegion();
26
27    void Clear();
28    mach_vm_address_t StartAddress() const { return m_start; }
29    mach_vm_address_t EndAddress() const { return m_start + m_size; }
30    mach_vm_size_t GetByteSize () const { return m_size; }
31    mach_vm_address_t BytesRemaining(mach_vm_address_t addr) const
32    {
33        if (ContainsAddress(addr))
34            return m_size - (addr - m_start);
35        else
36            return 0;
37    }
38    bool ContainsAddress(mach_vm_address_t addr) const
39    {
40        return addr >= StartAddress() && addr < EndAddress();
41    }
42
43    bool SetProtections(mach_vm_address_t addr, mach_vm_size_t size, vm_prot_t prot);
44    bool RestoreProtections();
45    bool GetRegionForAddress(nub_addr_t addr);
46
47    uint32_t
48    GetDNBPermissions () const;
49
50    const DNBError &
51    GetError ()
52    {
53        return m_err;
54    }
55protected:
56#if defined (VM_REGION_SUBMAP_SHORT_INFO_COUNT_64)
57    typedef vm_region_submap_short_info_data_64_t RegionInfo;
58    enum { kRegionInfoSize = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64 };
59#else
60    typedef vm_region_submap_info_data_64_t RegionInfo;
61    enum { kRegionInfoSize = VM_REGION_SUBMAP_INFO_COUNT_64 };
62#endif
63
64    task_t              m_task;
65    mach_vm_address_t   m_addr;
66    DNBError            m_err;
67    mach_vm_address_t   m_start;
68    mach_vm_size_t      m_size;
69    natural_t           m_depth;
70    RegionInfo          m_data;
71    vm_prot_t           m_curr_protection;    // The current, possibly modified protections. Original value is saved in m_data.protections.
72    mach_vm_address_t   m_protection_addr;    // The start address at which protections were changed
73    mach_vm_size_t      m_protection_size;    // The size of memory that had its protections changed
74
75};
76
77#endif    // #ifndef __MachVMRegion_h__
78