summaryrefslogtreecommitdiff
path: root/src/debug/createdump/memoryregion.h
blob: 1332ab14164caa37770de10e49733104e297849c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

struct MemoryRegion 
{
private:
    uint32_t m_permissions;
    uint64_t m_startAddress;
    uint64_t m_endAddress;
    uint64_t m_offset;

    // The name used for NT_FILE output
    char* m_fileName;

public:
    MemoryRegion(uint64_t start, uint64_t end) : 
        m_permissions(PF_R | PF_W | PF_X),
        m_startAddress(start),
        m_endAddress(end),
        m_offset(0),
        m_fileName(nullptr)
    {
        assert((start & ~PAGE_MASK) == 0);
        assert((end & ~PAGE_MASK) == 0);
    }

    MemoryRegion(uint32_t permissions, uint64_t start, uint64_t end, uint64_t offset, char* filename) : 
        m_permissions(permissions),
        m_startAddress(start),
        m_endAddress(end),
        m_offset(offset),
        m_fileName(filename)
    {
        assert((start & ~PAGE_MASK) == 0);
        assert((end & ~PAGE_MASK) == 0);
    }

    const uint32_t Permissions() const { return m_permissions; }
    const uint64_t StartAddress() const { return m_startAddress; }
    const uint64_t EndAddress() const { return m_endAddress; }
    const uint64_t Size() const { return m_endAddress - m_startAddress; }
    const uint64_t Offset() const { return m_offset; }
    const char* FileName() const { return m_fileName; }

    bool operator<(const MemoryRegion& rhs) const
    {
        return (m_startAddress < rhs.m_startAddress) && (m_endAddress <= rhs.m_startAddress);
    }

    bool Contains(const MemoryRegion& rhs) const
    {
        return (m_startAddress <= rhs.m_startAddress) && (m_endAddress >= rhs.m_endAddress);
    }

    void Cleanup()
    {
        if (m_fileName != nullptr)
        {
            free(m_fileName);
            m_fileName = nullptr;
        }
    }

    void Print() const
    {
        if (m_fileName != nullptr) {
            TRACE("%016lx - %016lx (%06ld) %016lx %x %s\n", m_startAddress, m_endAddress, (Size() >> PAGE_SHIFT), m_offset, m_permissions, m_fileName);
        }
        else {
            TRACE("%016lx - %016lx (%06ld) %x\n", m_startAddress, m_endAddress, (Size() >> PAGE_SHIFT), m_permissions);
        }
    }
};