~satchmo/libvmm

ref: 61e03036da7a9ff558521293c3aa7197a32c50dc libvmm/vmm/memory/detail/guest.hpp -rw-r--r-- 2.7 KiB
61e03036Jason Phan memory: Remove redundant comments for GuestAddress/MemoryRegionAddress 3 months ago
                                                                                
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
75
//
// guest.hpp -
//

#pragma once

#include <cassert> // assert
#include <cstdint> // uint*_t
#include <filesystem> // path
#include <fstream> // fstream
#include <ios> // ios_base
#include <iostream> // ostream
#include <limits> // numeric_limits
#include <memory> // shared_ptr
#include <string> // string

#include "vmm/memory/detail/address.hpp" // Address, AddressValue

namespace vmm::memory::detail {

// A guest physical address.
//
// On aarch64, a 32-bit hypervisor may be used to support a 64-bit guest. For
// simplicity, uint64_t is used to store the raw value regardless of whether
// the guest is 32-bit or 64-bit.
class GuestAddress : public Address<GuestAddress, uint64_t>
{
    public:
        using value_type = GuestAddress;
        using size_type = uint64_t;
        using reference = value_type&;
        using const_reference = const value_type&;

        explicit GuestAddress(size_type addr=0) noexcept : m_addr{addr} {}

        auto data() const noexcept -> size_type override;

        auto operator&(const size_type mask) const noexcept -> size_type override;
        auto operator|(const size_type mask) const noexcept -> size_type override;
        auto operator+(const size_type val) const noexcept -> value_type override;
        auto operator+(const_reference addr) const noexcept -> value_type override;
        auto operator-(const size_type val) const noexcept -> value_type override;
        auto operator-(const_reference addr) const noexcept -> value_type override;

        auto align(const size_type alignment) noexcept -> reference override;
    private:
        size_type m_addr{};
};

// An offset into a memory region.
class MemoryRegionAddress : public Address<MemoryRegionAddress, uint64_t>
{
    public:
        using value_type = MemoryRegionAddress;
        using size_type = uint64_t;
        using reference = value_type&;
        using const_reference = const value_type&;

        explicit MemoryRegionAddress(size_type addr=0) noexcept : m_addr{addr} {}

        auto data() const noexcept -> size_type override;

        auto operator&(const size_type mask) const noexcept -> size_type override;
        auto operator|(const size_type mask) const noexcept -> size_type override;
        auto operator+(const size_type val) const noexcept -> value_type override;
        auto operator+(const_reference addr) const noexcept -> value_type override;
        auto operator-(const size_type val) const noexcept -> value_type override;
        auto operator-(const_reference addr) const noexcept -> value_type override;

        auto align(const size_type alignment) noexcept -> reference override;
    private:
        size_type m_addr{};
};

}  // vmm::memory::detail