page_table_x64.h
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef PAGE_TABLE_X64_H
23 #define PAGE_TABLE_X64_H
24 
25 #include <gsl/gsl>
26 
27 #include <vector>
28 #include <memory>
29 
30 #include <memory.h>
32 
34 {
35 public:
36 
37  using pointer = uintptr_t *;
38  using integer_pointer = uintptr_t;
39  using size_type = std::size_t;
40  using memory_descriptor_list = std::vector<memory_descriptor>;
41 
53  page_table_x64(gsl::not_null<pointer> pte);
54 
60  ~page_table_x64() = default;
61 
78  { return add_page(addr, x64::page_table::pml4::from, x64::page_table::pdpt::from); }
79 
96  { return add_page(addr, x64::page_table::pml4::from, x64::page_table::pd::from); }
97 
114  { return add_page(addr, x64::page_table::pml4::from, x64::page_table::pt::from); }
115 
131 
143  { return virt_to_pte(addr, x64::page_table::pml4::from); }
144 
158  { memory_descriptor_list mdl; return pt_to_mdl(mdl); }
159 
160 private:
161 
166 
167  bool empty() const noexcept;
168  size_type global_size() const noexcept;
169  size_type global_capacity() const noexcept;
170 
171 private:
172 
173  friend class memory_manager_ut;
174 
175  std::unique_ptr<integer_pointer[]> m_pt;
176  std::vector<std::unique_ptr<page_table_x64>> m_pts;
177 
178 public:
179 
180  page_table_x64(page_table_x64 &&) noexcept = default;
181  page_table_x64 &operator=(page_table_x64 &&) noexcept = default;
182 
183  page_table_x64(const page_table_x64 &) = delete;
184  page_table_x64 &operator=(const page_table_x64 &) = delete;
185 };
186 
187 #endif
page_table_x64(gsl::not_null< pointer > pte)
~page_table_x64()=default
std::vector< memory_descriptor > memory_descriptor_list
page_table_entry_x64 virt_to_pte(integer_pointer addr) const
page_table_entry_x64 add_page_2m(integer_pointer addr)
void remove_page(integer_pointer addr)
constexpr const auto from
memory_descriptor_list pt_to_mdl() const
void uint64_t uint64_t uint64_t *rdx noexcept
constexpr const auto from
constexpr const auto addr
Definition: cpuid_x64.h:80
page_table_entry_x64 add_page_1g(integer_pointer addr)
auto end(reversed_container< T > container) -> decltype(container.container.rend())
Definition: reverse.h:43
uintptr_t * pointer
uintptr_t integer_pointer
constexpr const auto from
std::size_t size_type
constexpr const auto from
page_table_entry_x64 add_page_4k(integer_pointer addr)