root_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 ROOT_PAGE_TABLE_X64_H
23 #define ROOT_PAGE_TABLE_X64_H
24 
25 #include <gsl/gsl>
26 
27 #include <mutex>
28 #include <vector>
29 
30 #include <memory.h>
31 #include <memory_manager/pat_x64.h>
34 
35 #include <intrinsics/x64.h>
36 
48 {
49 public:
50 
51  using pointer = void *;
52  using integer_pointer = uintptr_t;
53  using cr3_type = uint64_t;
55  using size_type = size_t;
57 
63  root_page_table_x64(bool is_vmm = false);
64 
70  virtual ~root_page_table_x64() = default;
71 
80  virtual cr3_type cr3();
81 
95  { this->map_page(virt, phys, attr, x64::page_table::pdpt::size_bytes); }
96 
110  { this->map_page(virt, phys, attr, x64::page_table::pd::size_bytes); }
111 
125  { this->map_page(virt, phys, attr, x64::page_table::pt::size_bytes); }
126 
136  virtual void unmap(integer_pointer virt) noexcept;
137 
150 
163 
176 
189 
202 
215 
232 
246 
247 private:
248 
250 
251  void map_page(integer_pointer virt, integer_pointer phys, attr_type attr, size_type size);
252  void unmap_page(integer_pointer virt) noexcept;
253 
254 private:
255 
256  bool m_is_vmm;
257 
258  integer_pointer m_cr3;
259  std::unique_ptr<page_table_x64> m_pt;
260 
261  mutable std::mutex m_mutex;
262 
263 public:
264 
265  friend class memory_manager_ut;
266 
269 
270  root_page_table_x64(const root_page_table_x64 &) = delete;
272 };
273 
282 
291 #define g_pt root_pt()
292 
293 #endif
virtual void map_2m(integer_pointer virt, integer_pointer phys, attr_type attr)
std::vector< memory_descriptor > memory_descriptor_list
virtual void map_1g(integer_pointer virt, integer_pointer phys, attr_type attr)
void unmap_identity_map_1g(integer_pointer saddr, integer_pointer eaddr)
void setup_identity_map_1g(integer_pointer saddr, integer_pointer eaddr)
constexpr const auto size_bytes
page_table_x64::memory_descriptor_list memory_descriptor_list
constexpr const auto size
void uint64_t uint64_t uint64_t *rdx noexcept
constexpr const auto size_bytes
x64::memory_attr::attr_type attr_type
constexpr const auto size_bytes
virtual void map_4k(integer_pointer virt, integer_pointer phys, attr_type attr)
virtual void unmap(integer_pointer virt) noexcept
memory_descriptor_list pt_to_mdl() const
uint64_t attr_type
Definition: mem_attr_x64.h:35
void unmap_identity_map_2m(integer_pointer saddr, integer_pointer eaddr)
virtual cr3_type cr3()
constexpr page_table_x64::integer_pointer virt
void setup_identity_map_4k(integer_pointer saddr, integer_pointer eaddr)
page_table_entry_x64 virt_to_pte(integer_pointer virt) const
void setup_identity_map_2m(integer_pointer saddr, integer_pointer eaddr)
root_page_table_x64 & operator=(root_page_table_x64 &&)=default
root_page_table_x64(bool is_vmm=false)
void unmap_identity_map_4k(integer_pointer saddr, integer_pointer eaddr)
virtual ~root_page_table_x64()=default
root_page_table_x64 * root_pt() noexcept