aboutsummaryrefslogtreecommitdiff
path: root/kapi/kapi/memory/frame.hpp
blob: bfb0d91a063989525f45daa536701f141e4a26ce (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
#ifndef TEACHOS_KAPI_MEMORY_FRAME_HPP
#define TEACHOS_KAPI_MEMORY_FRAME_HPP

// IWYU pragma: private, include <kapi/memory.hpp>

#include <kapi/memory/address.hpp>
#include <kapi/memory/chunk.hpp>
#include <kapi/memory/layout.hpp>

#include <cstddef>

namespace kapi::memory
{
  //! @addtogroup kapi-memory
  //! @{

  //! A handle to a frame of physical memory.
  //!
  //! @note Contrary to the address types, this type is modeled using inheritance to support future extensions.
  struct frame : chunk<frame, physical_address, frame_size>
  {
    frame() = default;

    explicit frame(std::size_t number)
        : chunk{number}
    {}

    using difference_type = std::ptrdiff_t;

    //! @copydoc chunk::containing
    //!
    //! @note This factory shadows the base factory to aid in type deduction.
    constexpr auto static containing(physical_address address) noexcept -> frame
    {
      return frame{chunk::containing(address)};
    }

    //! Convert a base chunk into a page.
    //!
    //! This constructor allows for conversion from chunk<physical_address, PLATFORM_FRAME_SIZE> to a frame for
    //! convenience. It is deliberately not explicit.
    constexpr frame(chunk other)
        : chunk{other}
    {}
  };

  //! @}

}  // namespace kapi::memory

#endif