blob: c436ee50ad1d2ff333e7e465ae5bdf95a21c0267 (
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
|
#include "x86_64/memory/scoped_mapping.hpp"
#include "kapi/memory.hpp"
#include "kapi/system.hpp"
#include "x86_64/memory/mmu.hpp"
#include <utility>
namespace teachos::memory::x86_64
{
scoped_mapping::scoped_mapping(scoped_mapping && other)
: m_address{std::exchange(other.m_address, linear_address{})}
, m_allocator{std::exchange(other.m_allocator, nullptr)}
, m_mapped{std::exchange(other.m_mapped, false)}
{}
scoped_mapping::scoped_mapping(linear_address address, frame_allocator & allocator)
: m_address{address}
, m_allocator{&allocator}
, m_mapped{false}
{}
scoped_mapping::~scoped_mapping()
{
if (m_mapped)
{
unmap();
x86_64::tlb_flush(m_address);
}
}
auto scoped_mapping::operator=(scoped_mapping && other) -> scoped_mapping &
{
if (&other == this)
{
return *this;
}
using std::swap;
swap(m_address, other.m_address);
swap(m_allocator, other.m_allocator);
swap(m_mapped, other.m_mapped);
return *this;
}
auto scoped_mapping::map(frame frame, page_table::entry::flags flags) -> std::byte *
{
static_cast<void>(frame);
static_cast<void>(flags);
m_mapped = true;
return nullptr;
}
auto scoped_mapping::unmap() -> void
{
if (!m_mapped)
{
system::panic("[MEM] Tried to release an unmapped temporary mapping!");
}
// TODO: scan pages
// TODO: remove mapping
// TODO: release temporary table frames
m_mapped = false;
}
} // namespace teachos::memory::x86_64
|